Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deposit erc20 tokens #80

Merged
merged 82 commits into from
Aug 29, 2023
Merged

Deposit erc20 tokens #80

merged 82 commits into from
Aug 29, 2023

Conversation

jpcenteno
Copy link
Contributor

@jpcenteno jpcenteno commented Jul 6, 2023

closes #65

src/zks_provider/mod.rs Outdated Show resolved Hide resolved
src/abi/IL1Bridge.json Outdated Show resolved Hide resolved
src/zks_wallet/DepositERC20GasLimit.json Outdated Show resolved Hide resolved
@jpcenteno jpcenteno marked this pull request as ready for review July 26, 2023 21:10
@jpcenteno jpcenteno self-assigned this Jul 27, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jul 27, 2023

Codecov Report

Merging #80 (4d2ff44) into main (e0ef89e) will decrease coverage by 5.08%.
The diff coverage is 13.01%.

@@            Coverage Diff             @@
##             main      #80      +/-   ##
==========================================
- Coverage   73.22%   68.15%   -5.08%     
==========================================
  Files          16       18       +2     
  Lines        2024     2179     +155     
==========================================
+ Hits         1482     1485       +3     
- Misses        542      694     +152     
Files Changed Coverage Δ
src/abi/mod.rs 0.00% <0.00%> (ø)
src/contracts/l1_bridge_contract.rs 0.00% <0.00%> (ø)
src/zks_utils.rs 31.03% <ø> (ø)
src/zks_wallet/wallet.rs 54.87% <14.18%> (-17.35%) ⬇️
src/zks_wallet/requests/deposit_request.rs 43.93% <16.66%> (-6.07%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

src/zks_wallet/wallet.rs Outdated Show resolved Hide resolved
src/zks_wallet/wallet.rs Outdated Show resolved Hide resolved
src/zks_wallet/wallet.rs Outdated Show resolved Hide resolved
src/zks_wallet/wallet.rs Outdated Show resolved Hide resolved
src/abi/mod.rs Outdated Show resolved Hide resolved
src/zks_wallet/wallet.rs Show resolved Hide resolved
src/zks_wallet/wallet.rs Outdated Show resolved Hide resolved
Comment on lines +380 to +383
#[allow(clippy::expect_used)]
let contract_function = bridge_contract
.function("deposit")
.expect("failed to get deposit function parameters");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid using expect here. The function already returns a Result so bubble up the error might be the best option

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to use expect in this case, because the error state should be unreachable. That's why I consciously included #[allow(clippy::expect_used)].

In this case, bubbling up this error would force the function user to take into account an unreachable type of error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right in pointing out that the error seems to be unreachable, as the only possible way it could fail is if the function name isn't correct. From my perspective, it's a good idea to avoid using expect. The rationale behind this is that there might be potential for ethers to introduce a bug in the future connected to that specific function or something closely related, causing a panic on our end. Besides that the function is already returning a result so, from the user side, they will have to handle the error anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rationale behind this is that there might be potential for ethers to introduce a bug in the future connected to that specific function or something closely related, causing a panic on our end

This should be covered on testing.

Besides that the function is already returning a result so, from the user side, they will have to handle the error anyways.

But this adds another possible error state, forcing the user to write a handler somewhere for an unreachable state.

I think that this piece of code should be refactored in the future by doing this in a completely different way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that my code in this PR sucks. It was all done in a rush.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay no worries, we'll keep the expects/unwraps in mind. We can merge and create an issue for address this in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created issue #103 to track this one

Comment on lines +393 to +398
#[allow(clippy::expect_used)]
contract_function
.encode_input(&params.into_tokens())
.expect("failed to encode deposit function parameters")
.into()
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid using expect here. The function already returns a Result so bubble up the error might be the best option

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to use expect in this case, because the error state should be unreachable. That's why I consciously included #[allow(clippy::expect_used)].

In this case, bubbling up this error would force the function user to take into account an unreachable type of error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The discussion moved to #80 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created issue #103 to track this one

src/zks_wallet/wallet.rs Outdated Show resolved Hide resolved
- Why private?
  - This functionality is out of scope for our SDK.
  - It wasn't being used outside this module.
- I think that it is ok to go with the simplest solution right now. We
  could refactor this to emit an error in the future if necessary.
  - It makes sense to use `expect`/`unwrap` here because the
    `include_str!` macro ensures that the ABI JSON string is present.
@jpcenteno jpcenteno force-pushed the deposit-erc20-tokens branch from 4022f0f to 392ef65 Compare August 28, 2023 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support to deposit ERC20 tokens
5 participants