From 6d3a7402d79eca5b3383b1925cd09648cdf33513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Paradelo?= Date: Fri, 11 Jul 2025 12:13:09 -0300 Subject: [PATCH 1/3] feat: add token-l1 and token-l2 to witdraw* commands --- cli/src/commands/l2.rs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/cli/src/commands/l2.rs b/cli/src/commands/l2.rs index 30b3f7b..1aaffcd 100644 --- a/cli/src/commands/l2.rs +++ b/cli/src/commands/l2.rs @@ -64,6 +64,19 @@ pub(crate) enum Command { #[clap(value_parser = parse_u256)] claimed_amount: U256, l2_withdrawal_tx_hash: H256, + #[clap( + long = "token-l1", + help = "ERC20 token address on L1", + long_help = "Specify the token address, the base token is used as default." + )] + token_l1: Option
, + #[clap( + long = "token-l2", + help = "ERC20 token address on L2", + long_help = "Specify the token address, it is required if you specify a token on L1.", + requires("token-l1") + )] + token_l2: Option
, #[clap( long, short = 'c', @@ -208,11 +221,18 @@ pub(crate) enum Command { #[clap(long = "nonce")] nonce: Option, #[clap( - long = "token", - help = "ERC20 token address", + long = "token-l1", + help = "ERC20 token address on L1", long_help = "Specify the token address, the base token is used as default." )] - token_address: Option
, + token_l1: Option
, + #[clap( + long = "token-l2", + help = "ERC20 token address on L2", + long_help = "Specify the token address, it is required if you specify a token on L1.", + requires("token-l1") + )] + token_l2: Option
, #[clap( long, short = 'c', @@ -316,6 +336,8 @@ impl Command { Command::ClaimWithdraw { claimed_amount, l2_withdrawal_tx_hash, + token_l1, + token_l2, cast, silent, private_key, @@ -356,7 +378,8 @@ impl Command { Command::Withdraw { amount, nonce, - token_address, + token_l1, + token_l2, cast, silent, explorer_url, @@ -371,7 +394,7 @@ impl Command { todo!("Display transaction URL in the explorer") } - if token_address.is_some() { + if token_l1.is_some() { // withdraw_erc20(..) todo!("Handle ERC20 withdrawals") } From 0c8e63bc23a80229072635405d5da40dd78647ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Paradelo?= Date: Fri, 11 Jul 2025 12:18:09 -0300 Subject: [PATCH 2/3] feat: support withdraw l2 on cli --- cli/src/commands/l2.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cli/src/commands/l2.rs b/cli/src/commands/l2.rs index 1aaffcd..64eb437 100644 --- a/cli/src/commands/l2.rs +++ b/cli/src/commands/l2.rs @@ -9,7 +9,7 @@ use rex_sdk::{ client::{EthClient, eth::get_address_from_secret_key}, l2::{ deposit::{deposit_erc20, deposit_through_contract_call}, - withdraw::{claim_withdraw, get_withdraw_merkle_proof, withdraw}, + withdraw::{claim_withdraw, get_withdraw_merkle_proof, withdraw, withdraw_erc20}, }, wait_for_transaction_receipt, }; @@ -394,12 +394,14 @@ impl Command { todo!("Display transaction URL in the explorer") } - if token_l1.is_some() { - // withdraw_erc20(..) - todo!("Handle ERC20 withdrawals") - } - - let tx_hash = withdraw(amount, from, private_key, &client, nonce).await?; + let tx_hash = if let Some(token_l1) = token_l1 { + let token_l2 = token_l2.expect( + "Token address on L2 is required if token address on L1 is specified", + ); + withdraw_erc20(amount, from, private_key, token_l1, token_l2, &client).await? + } else { + withdraw(amount, from, private_key, &client, nonce).await? + }; println!("Withdrawal sent: {tx_hash:#x}"); From d388b4a7b178a6f6980c955dc4b68b3b3195606b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Paradelo?= Date: Fri, 11 Jul 2025 12:23:13 -0300 Subject: [PATCH 3/3] feat: support claim withdraw erc20 --- cli/src/commands/l2.rs | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/cli/src/commands/l2.rs b/cli/src/commands/l2.rs index 64eb437..b3f6d7a 100644 --- a/cli/src/commands/l2.rs +++ b/cli/src/commands/l2.rs @@ -9,7 +9,10 @@ use rex_sdk::{ client::{EthClient, eth::get_address_from_secret_key}, l2::{ deposit::{deposit_erc20, deposit_through_contract_call}, - withdraw::{claim_withdraw, get_withdraw_merkle_proof, withdraw, withdraw_erc20}, + withdraw::{ + claim_erc20withdraw, claim_withdraw, get_withdraw_merkle_proof, withdraw, + withdraw_erc20, + }, }, wait_for_transaction_receipt, }; @@ -359,15 +362,31 @@ impl Command { "No withdrawal proof found for transaction {l2_withdrawal_tx_hash:#x}" ))?; - let tx_hash = claim_withdraw( - claimed_amount, - from, - private_key, - ð_client, - &withdrawal_proof, - bridge_address, - ) - .await?; + let tx_hash = if let Some(token_l1) = token_l1 { + let token_l2 = token_l2.expect( + "Token address on L2 is required if token address on L1 is specified", + ); + claim_erc20withdraw( + token_l1, + token_l2, + claimed_amount, + private_key, + ð_client, + &withdrawal_proof, + bridge_address, + ) + .await? + } else { + claim_withdraw( + claimed_amount, + from, + private_key, + ð_client, + &withdrawal_proof, + bridge_address, + ) + .await? + }; println!("Withdrawal claim sent: {tx_hash:#x}");