|
1 | 1 | const { ethers } = require('hardhat');
|
2 |
| -const { BigNumber, providers, Wallet } = require('ethers'); |
| 2 | +const { BigNumber, providers, Wallet, constants } = require('ethers'); |
3 | 3 | const { getArbitrumNetwork, ParentToChildMessageStatus, Erc20Bridger } = require('@arbitrum/sdk');
|
4 | 4 | const {
|
5 | 5 | arbLog,
|
@@ -50,6 +50,8 @@ const main = async () => {
|
50 | 50 | */
|
51 | 51 | const childChainNetwork = await getArbitrumNetwork(childChainProvider);
|
52 | 52 | const erc20Bridger = new Erc20Bridger(childChainNetwork);
|
| 53 | + const isCustomGasTokenChain = |
| 54 | + erc20Bridger.nativeToken && erc20Bridger.nativeToken !== constants.AddressZero; |
53 | 55 |
|
54 | 56 | /**
|
55 | 57 | * We get the address of the parent-chain gateway for our DappToken,
|
@@ -101,6 +103,24 @@ const main = async () => {
|
101 | 103 | * (4) childProvider: A provider for the child chain
|
102 | 104 | */
|
103 | 105 | console.log('Transferring DappToken to the child chain:');
|
| 106 | + |
| 107 | + /** |
| 108 | + * For chains that use a custom gas token, we'll have to approve the transfer of native tokens |
| 109 | + * to pay for the execution of the retryable tickets on the child chain |
| 110 | + */ |
| 111 | + if (isCustomGasTokenChain) { |
| 112 | + console.log('Giving allowance to the deployed token to transfer the chain native token'); |
| 113 | + const approvalTransaction = await erc20Bridger.approveGasToken({ |
| 114 | + erc20ParentAddress: erc20Bridger.nativeToken, |
| 115 | + parentSigner: parentChainWallet, |
| 116 | + }); |
| 117 | + |
| 118 | + const approvalTransactionReceipt = await approvalTransaction.wait(); |
| 119 | + console.log( |
| 120 | + `Native token approval transaction receipt is: ${approvalTransactionReceipt.transactionHash}`, |
| 121 | + ); |
| 122 | + } |
| 123 | + |
104 | 124 | const depositTransaction = await erc20Bridger.deposit({
|
105 | 125 | amount: tokenDepositAmount,
|
106 | 126 | erc20ParentAddress: tokenAddress,
|
|
0 commit comments