Skip to content

feat(sdk): add function to withdraw erc20 tokens #162

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

Merged
merged 14 commits into from
Jul 28, 2025

Conversation

tomip01
Copy link
Contributor

@tomip01 tomip01 commented Jul 11, 2025

Motivation

We want to add support for the withdraw of erc20 tokens in the sdk.

Description

  • Added the withdraw_erc20 and the claim_erc20withdraw function in sdk/src/l2/withdraw.rs to handle ERC20 token withdrawals.
  • Introduced L2_WITHDRAW_SIGNATURE_ERC20 and CLAIM_WITHDRAWAL_ERC20_SIGNATURE in sdk/src/l2/constants.rs to define the signature for ERC20 withdrawal calldata encoding.

Closes #157

@tomip01 tomip01 self-assigned this Jul 11, 2025
@tomip01 tomip01 requested a review from a team as a code owner July 11, 2025 14:38
@tomip01 tomip01 added the enhancement New feature or request label Jul 11, 2025
@tomip01 tomip01 marked this pull request as draft July 11, 2025 14:48
@tomip01 tomip01 marked this pull request as ready for review July 11, 2025 14:59
@Mechanix97 Mechanix97 linked an issue Jul 14, 2025 that may be closed by this pull request
Base automatically changed from feat/cli/support-erc20-deposits to main July 15, 2025 15:07
@tomip01 tomip01 requested review from iovoid and MegaRedHand July 24, 2025 12:16
@tomip01 tomip01 merged commit ad723e5 into main Jul 28, 2025
10 checks passed
@tomip01 tomip01 deleted the feat/sdk/support-erc20-withdraw branch July 28, 2025 15:48
tomip01 added a commit that referenced this pull request Jul 28, 2025
…tokens (#163)

**Motivation**

> [!IMPORTANT]
> Merge after #162 

We want to add an interface on the cli for the withdraw of erc20 tokens

**Description**

- Introduced new parameters `token_l1` and `token_l2` in the `Command`
enum for both `Withdraw` and `ClaimWithdraw` commands. These parameters
allow specifying ERC20 token addresses on L1 and L2, respectively, with
validation to ensure `token_l2` is required when `token_l1` is provided.
- Modified the `ClaimWithdraw` command logic to handle ERC20 claims
using the new `claim_erc20withdraw` function when `token_l1` is
specified. Otherwise, it defaults to the existing `claim_withdraw`
function.
- Updated the `Withdraw` command logic to support ERC20 withdrawals
using the `withdraw_erc20` function when `token_l1` is specified.
Otherwise, it defaults to the existing `withdraw` function.

**How to test**

- Deploy contracts on L1 an L2 for the tokens.
- You could use the same for the integration tests in `ethrex`
repository. You can use the test `test_erc20_roundtrip`. Comment the
parts of the withdrawals
- Then run `rex l2 withdraw <AMOUNT> <PRIVATE_KEY> --token-l1
<TOKEN_L1_ADDRESS> --token-l2 <TOKEN_L2_ADDRESS>`
  - This will print a hash for a tx `WITHDRAW_TX_HASH`
- Lastly, run `rex l2 claim-withdraw <AMOUNT> <WITHDRAW_TX_HASH>
<PRIVATE_KEY> <BRIDGE_ADDRESS> --token-l1 <TOKEN_L1_ADDRESS> --token-l2
<TOKEN_L2_ADDRESS>`
- You can check balances with:
  - `rex l2 balance <ADDRESS> --token <L2_TOKEN_ADDRESS>` for L2
  - `rex balance <ADDRESS> --token <L1_TOKEN_ADDRESS>` for L1

> [!NOTE]
> verifying the batches is needed for claiming the withdraws
> On `ethrex` run `make init-prover` on `crates/l2`

Closes #158 
Closes #156

---------

Co-authored-by: Ivan Litteri <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support ERC20 withdrawals in rex-sdk
4 participants