Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/eth-deposit-to-different-address/scripts/exec.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion packages/eth-deposit/scripts/exec.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion packages/token-deposit/scripts/exec.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down