diff --git a/packages/eth-deposit-to-different-address/scripts/exec.js b/packages/eth-deposit-to-different-address/scripts/exec.js index 8bd44d8..726b3c4 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,31 @@ 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('Giving allowance to the deployed token to transfer the chain native token'); + const approvalTransaction = await ethBridger.approveGasToken({ + erc20ParentAddress: ethBridger.nativeToken, + 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/scripts/exec.js b/packages/eth-deposit/scripts/exec.js index 8cf1d91..0680b70 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,31 @@ 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('Giving allowance to the deployed token to transfer the chain native token'); + const approvalTransaction = await ethBridger.approveGasToken({ + erc20ParentAddress: ethBridger.nativeToken, + 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..3919818 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,8 @@ const main = async () => { */ const childChainNetwork = await getArbitrumNetwork(childChainProvider); const erc20Bridger = new Erc20Bridger(childChainNetwork); + const isCustomGasTokenChain = + erc20Bridger.nativeToken && erc20Bridger.nativeToken !== constants.AddressZero; /** * We get the address of the parent-chain gateway for our DappToken, @@ -101,6 +103,24 @@ 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 approvalTransaction = await erc20Bridger.approveGasToken({ + erc20ParentAddress: erc20Bridger.nativeToken, + 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,