Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
29 changes: 28 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,39 @@ const main = async () => {
*/
const childChainNetwork = await getArbitrumNetwork(childChainProvider);
const ethBridger = new EthBridger(childChainNetwork);
const isCustomGasTokenChain =
ethBridger.nativeToken && ethBridger.nativeToken !== constants.AddressZero;

if (isCustomGasTokenChain) {
console.log('Custom gas token chain detected');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok not to log this

}

/**
* 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 approvalTransactionRequest = await ethBridger.getApproveGasTokenRequest({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should either use getApproveGasTokenRequest (which doesn't need await) and then sendTransaction (like here), or just approveGasToken.

erc20ParentAddress: ethBridger.nativeToken,
parentProvider: parentChainProvider,
});
const approvalTransaction = await ethBridger.approveGasToken({
txRequest: approvalTransactionRequest,
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
29 changes: 28 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,39 @@ const main = async () => {
*/
const childChainNetwork = await getArbitrumNetwork(childChainProvider);
const ethBridger = new EthBridger(childChainNetwork);
const isCustomGasTokenChain =
ethBridger.nativeToken && ethBridger.nativeToken !== constants.AddressZero;

if (isCustomGasTokenChain) {
console.log('Custom gas token chain detected');
}

/**
* 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 approvalTransactionRequest = await ethBridger.getApproveGasTokenRequest({
erc20ParentAddress: ethBridger.nativeToken,
parentProvider: parentChainProvider,
});
const approvalTransaction = await ethBridger.approveGasToken({
txRequest: approvalTransactionRequest,
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
30 changes: 29 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,12 @@ const main = async () => {
*/
const childChainNetwork = await getArbitrumNetwork(childChainProvider);
const erc20Bridger = new Erc20Bridger(childChainNetwork);
const isCustomGasTokenChain =
erc20Bridger.nativeToken && erc20Bridger.nativeToken !== constants.AddressZero;

if (isCustomGasTokenChain) {
console.log('Custom gas token chain detected');
}

/**
* We get the address of the parent-chain gateway for our DappToken,
Expand Down Expand Up @@ -101,6 +107,28 @@ 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 approvalTransactionRequest = await erc20Bridger.getApproveGasTokenRequest({
erc20ParentAddress: erc20Bridger.nativeToken,
parentProvider: parentChainProvider,
});
const approvalTransaction = await erc20Bridger.approveGasToken({
txRequest: approvalTransactionRequest,
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