From 663c6a48946899124710c9467109f77b5eca1fa6 Mon Sep 17 00:00:00 2001 From: Jason-Wanxt Date: Tue, 18 Mar 2025 17:00:54 +0800 Subject: [PATCH 1/4] add native token supports --- .../scripts/exec.js | 26 +++++++++++++++- packages/eth-deposit/README.md | 2 +- packages/eth-deposit/scripts/exec.js | 26 +++++++++++++++- packages/token-deposit/scripts/exec.js | 30 ++++++++++++++++++- 4 files changed, 80 insertions(+), 4 deletions(-) diff --git a/packages/eth-deposit-to-different-address/scripts/exec.js b/packages/eth-deposit-to-different-address/scripts/exec.js index 8bd44d8..6e395c0 100644 --- a/packages/eth-deposit-to-different-address/scripts/exec.js +++ b/packages/eth-deposit-to-different-address/scripts/exec.js @@ -1,4 +1,4 @@ -const { utils, providers, Wallet } = require('ethers'); +const { utils, providers, Wallet, constants } = require('ethers'); const { getArbitrumNetwork, EthBridger, EthDepositMessageStatus } = require('@arbitrum/sdk'); const { arbLog, @@ -38,12 +38,36 @@ const main = async () => { */ const childChainNetwork = await getArbitrumNetwork(childChainProvider); const ethBridger = new EthBridger(childChainNetwork); + const isCustomGasTokenChain = + ethBridger.nativeToken && ethBridger.nativeToken !== constants.AddressZero; /** * First, let's check the balance of the destination address */ const destinationAddressInitialEthBalance = await childChainProvider.getBalance(destAddress); + /** + * For chains that use a custom gas token, we'll have to approve the transfer of native tokens + * to pay for the execution of the retryable tickets on the child chain + */ + if (isCustomGasTokenChain) { + console.log('Custom gas token chain detected'); + console.log('Giving allowance to the deployed token to transfer the chain native token'); + const approvalTransactionRequest = await ethBridger.getApproveGasTokenRequest({ + erc20ParentAddress: ethBridger.nativeToken, + parentProvider: parentChainProvider, + }); + const approvalTransaction = await ethBridger.approveGasToken({ + txRequest: approvalTransactionRequest, + parentSigner: parentChainWallet, + }); + + const approvalTransactionReceipt = await approvalTransaction.wait(); + console.log( + `Native token approval transaction receipt is: ${approvalTransactionReceipt.transactionHash}`, + ); + } + /** * Transfer ether (or native token) from parent chain to a different address on child chain * This convenience method automatically queries for the retryable's max submission cost and forwards the appropriate amount to the specified address on the child chain diff --git a/packages/eth-deposit/README.md b/packages/eth-deposit/README.md index 5300d67..2cef30d 100644 --- a/packages/eth-deposit/README.md +++ b/packages/eth-deposit/README.md @@ -27,7 +27,7 @@ Note that you can also set the environment variables in an `.env` file in the ro ## Run ``` -yarn run depositETH +yarn run depositNative ```

diff --git a/packages/eth-deposit/scripts/exec.js b/packages/eth-deposit/scripts/exec.js index 8cf1d91..46f98ae 100644 --- a/packages/eth-deposit/scripts/exec.js +++ b/packages/eth-deposit/scripts/exec.js @@ -1,4 +1,4 @@ -const { utils, providers, Wallet } = require('ethers'); +const { utils, providers, Wallet, constants } = require('ethers'); const { getArbitrumNetwork, EthBridger, EthDepositMessageStatus } = require('@arbitrum/sdk'); const { arbLog, @@ -38,12 +38,36 @@ const main = async () => { */ const childChainNetwork = await getArbitrumNetwork(childChainProvider); const ethBridger = new EthBridger(childChainNetwork); + const isCustomGasTokenChain = + ethBridger.nativeToken && ethBridger.nativeToken !== constants.AddressZero; /** * First, let's check the wallet's initial balance in the child chain */ const initialEthBalance = await childChainWallet.getBalance(); + /** + * For chains that use a custom gas token, we'll have to approve the transfer of native tokens + * to pay for the execution of the retryable tickets on the child chain + */ + if (isCustomGasTokenChain) { + console.log('Custom gas token chain detected'); + console.log('Giving allowance to the deployed token to transfer the chain native token'); + const approvalTransactionRequest = await ethBridger.getApproveGasTokenRequest({ + erc20ParentAddress: ethBridger.nativeToken, + parentProvider: parentChainProvider, + }); + const approvalTransaction = await ethBridger.approveGasToken({ + txRequest: approvalTransactionRequest, + parentSigner: parentChainWallet, + }); + + const approvalTransactionReceipt = await approvalTransaction.wait(); + console.log( + `Native token approval transaction receipt is: ${approvalTransactionReceipt.transactionHash}`, + ); + } + /** * Transfer ether (or native token) from parent to child chain * This convenience method automatically queries for the retryable's max submission cost and forwards the appropriate amount to the child chain diff --git a/packages/token-deposit/scripts/exec.js b/packages/token-deposit/scripts/exec.js index 252657e..1d57cd6 100644 --- a/packages/token-deposit/scripts/exec.js +++ b/packages/token-deposit/scripts/exec.js @@ -1,5 +1,5 @@ const { ethers } = require('hardhat'); -const { BigNumber, providers, Wallet } = require('ethers'); +const { BigNumber, providers, Wallet, constants } = require('ethers'); const { getArbitrumNetwork, ParentToChildMessageStatus, Erc20Bridger } = require('@arbitrum/sdk'); const { arbLog, @@ -50,6 +50,12 @@ const main = async () => { */ const childChainNetwork = await getArbitrumNetwork(childChainProvider); const erc20Bridger = new Erc20Bridger(childChainNetwork); + const isCustomGasTokenChain = + erc20Bridger.nativeToken && erc20Bridger.nativeToken !== constants.AddressZero; + + if (isCustomGasTokenChain) { + console.log('Custom gas token chain detected'); + } /** * We get the address of the parent-chain gateway for our DappToken, @@ -101,6 +107,28 @@ const main = async () => { * (4) childProvider: A provider for the child chain */ console.log('Transferring DappToken to the child chain:'); + + /** + * For chains that use a custom gas token, we'll have to approve the transfer of native tokens + * to pay for the execution of the retryable tickets on the child chain + */ + if (isCustomGasTokenChain) { + console.log('Giving allowance to the deployed token to transfer the chain native token'); + const approvalTransactionRequest = await erc20Bridger.getApproveGasTokenRequest({ + erc20ParentAddress: erc20Bridger.nativeToken, + parentProvider: parentChainProvider, + }); + const approvalTransaction = await erc20Bridger.approveGasToken({ + txRequest: approvalTransactionRequest, + parentSigner: parentChainWallet, + }); + + const approvalTransactionReceipt = await approvalTransaction.wait(); + console.log( + `Native token approval transaction receipt is: ${approvalTransactionReceipt.transactionHash}`, + ); + } + const depositTransaction = await erc20Bridger.deposit({ amount: tokenDepositAmount, erc20ParentAddress: tokenAddress, From 282aff57151ad6beb9ed1a9d2e6f5b68fbd5a63c Mon Sep 17 00:00:00 2001 From: Jason-Wanxt Date: Tue, 18 Mar 2025 17:05:07 +0800 Subject: [PATCH 2/4] fix --- packages/eth-deposit-to-different-address/scripts/exec.js | 5 ++++- packages/eth-deposit/README.md | 2 +- packages/eth-deposit/scripts/exec.js | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/eth-deposit-to-different-address/scripts/exec.js b/packages/eth-deposit-to-different-address/scripts/exec.js index 6e395c0..50253f9 100644 --- a/packages/eth-deposit-to-different-address/scripts/exec.js +++ b/packages/eth-deposit-to-different-address/scripts/exec.js @@ -41,6 +41,10 @@ const main = async () => { const isCustomGasTokenChain = ethBridger.nativeToken && ethBridger.nativeToken !== constants.AddressZero; + if (isCustomGasTokenChain) { + console.log('Custom gas token chain detected'); + } + /** * First, let's check the balance of the destination address */ @@ -51,7 +55,6 @@ const main = async () => { * to pay for the execution of the retryable tickets on the child chain */ if (isCustomGasTokenChain) { - console.log('Custom gas token chain detected'); console.log('Giving allowance to the deployed token to transfer the chain native token'); const approvalTransactionRequest = await ethBridger.getApproveGasTokenRequest({ erc20ParentAddress: ethBridger.nativeToken, diff --git a/packages/eth-deposit/README.md b/packages/eth-deposit/README.md index 2cef30d..5300d67 100644 --- a/packages/eth-deposit/README.md +++ b/packages/eth-deposit/README.md @@ -27,7 +27,7 @@ Note that you can also set the environment variables in an `.env` file in the ro ## Run ``` -yarn run depositNative +yarn run depositETH ```

diff --git a/packages/eth-deposit/scripts/exec.js b/packages/eth-deposit/scripts/exec.js index 46f98ae..fbceb7d 100644 --- a/packages/eth-deposit/scripts/exec.js +++ b/packages/eth-deposit/scripts/exec.js @@ -41,6 +41,10 @@ const main = async () => { const isCustomGasTokenChain = ethBridger.nativeToken && ethBridger.nativeToken !== constants.AddressZero; + if (isCustomGasTokenChain) { + console.log('Custom gas token chain detected'); + } + /** * First, let's check the wallet's initial balance in the child chain */ @@ -51,7 +55,6 @@ const main = async () => { * to pay for the execution of the retryable tickets on the child chain */ if (isCustomGasTokenChain) { - console.log('Custom gas token chain detected'); console.log('Giving allowance to the deployed token to transfer the chain native token'); const approvalTransactionRequest = await ethBridger.getApproveGasTokenRequest({ erc20ParentAddress: ethBridger.nativeToken, From e16ddd2670287c275226313646d005714ae79255 Mon Sep 17 00:00:00 2001 From: Jason-Wanxt Date: Tue, 25 Mar 2025 15:59:21 +0800 Subject: [PATCH 3/4] resolve request changes --- .../eth-deposit-to-different-address/scripts/exec.js | 10 +--------- packages/eth-deposit/scripts/exec.js | 10 +--------- packages/token-deposit/scripts/exec.js | 12 ++---------- 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/packages/eth-deposit-to-different-address/scripts/exec.js b/packages/eth-deposit-to-different-address/scripts/exec.js index 50253f9..726b3c4 100644 --- a/packages/eth-deposit-to-different-address/scripts/exec.js +++ b/packages/eth-deposit-to-different-address/scripts/exec.js @@ -41,10 +41,6 @@ const main = async () => { const isCustomGasTokenChain = ethBridger.nativeToken && ethBridger.nativeToken !== constants.AddressZero; - if (isCustomGasTokenChain) { - console.log('Custom gas token chain detected'); - } - /** * First, let's check the balance of the destination address */ @@ -56,12 +52,8 @@ const main = async () => { */ if (isCustomGasTokenChain) { console.log('Giving allowance to the deployed token to transfer the chain native token'); - const approvalTransactionRequest = await ethBridger.getApproveGasTokenRequest({ - erc20ParentAddress: ethBridger.nativeToken, - parentProvider: parentChainProvider, - }); const approvalTransaction = await ethBridger.approveGasToken({ - txRequest: approvalTransactionRequest, + erc20ParentAddress: ethBridger.nativeToken, parentSigner: parentChainWallet, }); diff --git a/packages/eth-deposit/scripts/exec.js b/packages/eth-deposit/scripts/exec.js index fbceb7d..0680b70 100644 --- a/packages/eth-deposit/scripts/exec.js +++ b/packages/eth-deposit/scripts/exec.js @@ -41,10 +41,6 @@ const main = async () => { const isCustomGasTokenChain = ethBridger.nativeToken && ethBridger.nativeToken !== constants.AddressZero; - if (isCustomGasTokenChain) { - console.log('Custom gas token chain detected'); - } - /** * First, let's check the wallet's initial balance in the child chain */ @@ -56,12 +52,8 @@ const main = async () => { */ if (isCustomGasTokenChain) { console.log('Giving allowance to the deployed token to transfer the chain native token'); - const approvalTransactionRequest = await ethBridger.getApproveGasTokenRequest({ - erc20ParentAddress: ethBridger.nativeToken, - parentProvider: parentChainProvider, - }); const approvalTransaction = await ethBridger.approveGasToken({ - txRequest: approvalTransactionRequest, + erc20ParentAddress: ethBridger.nativeToken, parentSigner: parentChainWallet, }); diff --git a/packages/token-deposit/scripts/exec.js b/packages/token-deposit/scripts/exec.js index 1d57cd6..bb922fc 100644 --- a/packages/token-deposit/scripts/exec.js +++ b/packages/token-deposit/scripts/exec.js @@ -53,10 +53,6 @@ const main = async () => { const isCustomGasTokenChain = erc20Bridger.nativeToken && erc20Bridger.nativeToken !== constants.AddressZero; - if (isCustomGasTokenChain) { - console.log('Custom gas token chain detected'); - } - /** * We get the address of the parent-chain gateway for our DappToken, * which will later help us get the initial token balance of the bridge (before deposit) @@ -114,12 +110,8 @@ const main = async () => { */ if (isCustomGasTokenChain) { console.log('Giving allowance to the deployed token to transfer the chain native token'); - const approvalTransactionRequest = await erc20Bridger.getApproveGasTokenRequest({ - erc20ParentAddress: erc20Bridger.nativeToken, - parentProvider: parentChainProvider, - }); - const approvalTransaction = await erc20Bridger.approveGasToken({ - txRequest: approvalTransactionRequest, + const approvalTransaction = await ethBridger.approveGasToken({ + erc20ParentAddress: ethBridger.nativeToken, parentSigner: parentChainWallet, }); From 31e1edf2287a96a0215d93eebfb8b98e352ab035 Mon Sep 17 00:00:00 2001 From: Jason-Wanxt Date: Tue, 25 Mar 2025 16:06:02 +0800 Subject: [PATCH 4/4] resolve request changes --- packages/token-deposit/scripts/exec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/token-deposit/scripts/exec.js b/packages/token-deposit/scripts/exec.js index bb922fc..3919818 100644 --- a/packages/token-deposit/scripts/exec.js +++ b/packages/token-deposit/scripts/exec.js @@ -110,8 +110,8 @@ const main = async () => { */ if (isCustomGasTokenChain) { console.log('Giving allowance to the deployed token to transfer the chain native token'); - const approvalTransaction = await ethBridger.approveGasToken({ - erc20ParentAddress: ethBridger.nativeToken, + const approvalTransaction = await erc20Bridger.approveGasToken({ + erc20ParentAddress: erc20Bridger.nativeToken, parentSigner: parentChainWallet, });