Skip to content

Commit 663c6a4

Browse files
committed
add native token supports
1 parent d0291ff commit 663c6a4

File tree

4 files changed

+80
-4
lines changed

4 files changed

+80
-4
lines changed

packages/eth-deposit-to-different-address/scripts/exec.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { utils, providers, Wallet } = require('ethers');
1+
const { utils, providers, Wallet, constants } = require('ethers');
22
const { getArbitrumNetwork, EthBridger, EthDepositMessageStatus } = require('@arbitrum/sdk');
33
const {
44
arbLog,
@@ -38,12 +38,36 @@ const main = async () => {
3838
*/
3939
const childChainNetwork = await getArbitrumNetwork(childChainProvider);
4040
const ethBridger = new EthBridger(childChainNetwork);
41+
const isCustomGasTokenChain =
42+
ethBridger.nativeToken && ethBridger.nativeToken !== constants.AddressZero;
4143

4244
/**
4345
* First, let's check the balance of the destination address
4446
*/
4547
const destinationAddressInitialEthBalance = await childChainProvider.getBalance(destAddress);
4648

49+
/**
50+
* For chains that use a custom gas token, we'll have to approve the transfer of native tokens
51+
* to pay for the execution of the retryable tickets on the child chain
52+
*/
53+
if (isCustomGasTokenChain) {
54+
console.log('Custom gas token chain detected');
55+
console.log('Giving allowance to the deployed token to transfer the chain native token');
56+
const approvalTransactionRequest = await ethBridger.getApproveGasTokenRequest({
57+
erc20ParentAddress: ethBridger.nativeToken,
58+
parentProvider: parentChainProvider,
59+
});
60+
const approvalTransaction = await ethBridger.approveGasToken({
61+
txRequest: approvalTransactionRequest,
62+
parentSigner: parentChainWallet,
63+
});
64+
65+
const approvalTransactionReceipt = await approvalTransaction.wait();
66+
console.log(
67+
`Native token approval transaction receipt is: ${approvalTransactionReceipt.transactionHash}`,
68+
);
69+
}
70+
4771
/**
4872
* Transfer ether (or native token) from parent chain to a different address on child chain
4973
* 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

packages/eth-deposit/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Note that you can also set the environment variables in an `.env` file in the ro
2727
## Run
2828

2929
```
30-
yarn run depositETH
30+
yarn run depositNative
3131
```
3232

3333
<p align="left">

packages/eth-deposit/scripts/exec.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { utils, providers, Wallet } = require('ethers');
1+
const { utils, providers, Wallet, constants } = require('ethers');
22
const { getArbitrumNetwork, EthBridger, EthDepositMessageStatus } = require('@arbitrum/sdk');
33
const {
44
arbLog,
@@ -38,12 +38,36 @@ const main = async () => {
3838
*/
3939
const childChainNetwork = await getArbitrumNetwork(childChainProvider);
4040
const ethBridger = new EthBridger(childChainNetwork);
41+
const isCustomGasTokenChain =
42+
ethBridger.nativeToken && ethBridger.nativeToken !== constants.AddressZero;
4143

4244
/**
4345
* First, let's check the wallet's initial balance in the child chain
4446
*/
4547
const initialEthBalance = await childChainWallet.getBalance();
4648

49+
/**
50+
* For chains that use a custom gas token, we'll have to approve the transfer of native tokens
51+
* to pay for the execution of the retryable tickets on the child chain
52+
*/
53+
if (isCustomGasTokenChain) {
54+
console.log('Custom gas token chain detected');
55+
console.log('Giving allowance to the deployed token to transfer the chain native token');
56+
const approvalTransactionRequest = await ethBridger.getApproveGasTokenRequest({
57+
erc20ParentAddress: ethBridger.nativeToken,
58+
parentProvider: parentChainProvider,
59+
});
60+
const approvalTransaction = await ethBridger.approveGasToken({
61+
txRequest: approvalTransactionRequest,
62+
parentSigner: parentChainWallet,
63+
});
64+
65+
const approvalTransactionReceipt = await approvalTransaction.wait();
66+
console.log(
67+
`Native token approval transaction receipt is: ${approvalTransactionReceipt.transactionHash}`,
68+
);
69+
}
70+
4771
/**
4872
* Transfer ether (or native token) from parent to child chain
4973
* This convenience method automatically queries for the retryable's max submission cost and forwards the appropriate amount to the child chain

packages/token-deposit/scripts/exec.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { ethers } = require('hardhat');
2-
const { BigNumber, providers, Wallet } = require('ethers');
2+
const { BigNumber, providers, Wallet, constants } = require('ethers');
33
const { getArbitrumNetwork, ParentToChildMessageStatus, Erc20Bridger } = require('@arbitrum/sdk');
44
const {
55
arbLog,
@@ -50,6 +50,12 @@ const main = async () => {
5050
*/
5151
const childChainNetwork = await getArbitrumNetwork(childChainProvider);
5252
const erc20Bridger = new Erc20Bridger(childChainNetwork);
53+
const isCustomGasTokenChain =
54+
erc20Bridger.nativeToken && erc20Bridger.nativeToken !== constants.AddressZero;
55+
56+
if (isCustomGasTokenChain) {
57+
console.log('Custom gas token chain detected');
58+
}
5359

5460
/**
5561
* We get the address of the parent-chain gateway for our DappToken,
@@ -101,6 +107,28 @@ const main = async () => {
101107
* (4) childProvider: A provider for the child chain
102108
*/
103109
console.log('Transferring DappToken to the child chain:');
110+
111+
/**
112+
* For chains that use a custom gas token, we'll have to approve the transfer of native tokens
113+
* to pay for the execution of the retryable tickets on the child chain
114+
*/
115+
if (isCustomGasTokenChain) {
116+
console.log('Giving allowance to the deployed token to transfer the chain native token');
117+
const approvalTransactionRequest = await erc20Bridger.getApproveGasTokenRequest({
118+
erc20ParentAddress: erc20Bridger.nativeToken,
119+
parentProvider: parentChainProvider,
120+
});
121+
const approvalTransaction = await erc20Bridger.approveGasToken({
122+
txRequest: approvalTransactionRequest,
123+
parentSigner: parentChainWallet,
124+
});
125+
126+
const approvalTransactionReceipt = await approvalTransaction.wait();
127+
console.log(
128+
`Native token approval transaction receipt is: ${approvalTransactionReceipt.transactionHash}`,
129+
);
130+
}
131+
104132
const depositTransaction = await erc20Bridger.deposit({
105133
amount: tokenDepositAmount,
106134
erc20ParentAddress: tokenAddress,

0 commit comments

Comments
 (0)