Skip to content

Commit e21f255

Browse files
authored
Merge pull request #139 from OffchainLabs/add-native-support
Add native support
2 parents d6f2fd0 + 72fb020 commit e21f255

File tree

3 files changed

+61
-3
lines changed
  • packages

3 files changed

+61
-3
lines changed

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

Lines changed: 20 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,31 @@ 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('Giving allowance to the deployed token to transfer the chain native token');
55+
const approvalTransaction = await ethBridger.approveGasToken({
56+
erc20ParentAddress: ethBridger.nativeToken,
57+
parentSigner: parentChainWallet,
58+
});
59+
60+
const approvalTransactionReceipt = await approvalTransaction.wait();
61+
console.log(
62+
`Native token approval transaction receipt is: ${approvalTransactionReceipt.transactionHash}`,
63+
);
64+
}
65+
4766
/**
4867
* Transfer ether (or native token) from parent chain to a different address on child chain
4968
* 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/scripts/exec.js

Lines changed: 20 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,31 @@ 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('Giving allowance to the deployed token to transfer the chain native token');
55+
const approvalTransaction = await ethBridger.approveGasToken({
56+
erc20ParentAddress: ethBridger.nativeToken,
57+
parentSigner: parentChainWallet,
58+
});
59+
60+
const approvalTransactionReceipt = await approvalTransaction.wait();
61+
console.log(
62+
`Native token approval transaction receipt is: ${approvalTransactionReceipt.transactionHash}`,
63+
);
64+
}
65+
4766
/**
4867
* Transfer ether (or native token) from parent to child chain
4968
* 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: 21 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,8 @@ 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;
5355

5456
/**
5557
* We get the address of the parent-chain gateway for our DappToken,
@@ -101,6 +103,24 @@ const main = async () => {
101103
* (4) childProvider: A provider for the child chain
102104
*/
103105
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+
104124
const depositTransaction = await erc20Bridger.deposit({
105125
amount: tokenDepositAmount,
106126
erc20ParentAddress: tokenAddress,

0 commit comments

Comments
 (0)