diff --git a/scripts/atomicTokenBridgeDeployer.ts b/scripts/atomicTokenBridgeDeployer.ts index beb19b0eda..4c96de3c34 100644 --- a/scripts/atomicTokenBridgeDeployer.ts +++ b/scripts/atomicTokenBridgeDeployer.ts @@ -44,6 +44,7 @@ import { ContractVerifier } from './contractVerifier' import { OmitTyped } from '@arbitrum/sdk/dist/lib/utils/types' import { L1ToL2MessageGasParams } from '@arbitrum/sdk/dist/lib/message/L1ToL2MessageCreator' import { L1ContractCallTransactionReceipt } from '@arbitrum/sdk/dist/lib/message/L1Transaction' +import { _getScaledAmount } from './local-deployment/localDeploymentLib' /** * Dummy non-zero address which is provided to logic contracts initializers @@ -112,10 +113,12 @@ export const createTokenBridge = async ( const maxSubmissionCostForContracts = deployFactoryGasParams.maxSubmissionCost.mul(2) - let retryableFee = maxSubmissionCostForFactory - .add(maxSubmissionCostForContracts) - .add(maxGasForFactory.mul(gasPrice)) - .add(maxGasForContracts.mul(gasPrice)) + let retryableFeeForFactory = maxSubmissionCostForFactory.add( + maxGasForFactory.mul(gasPrice) + ) + let retryableFeeForContracts = maxSubmissionCostForContracts.add( + maxGasForContracts.mul(gasPrice) + ) // get inbox from rollup contract const inbox = await RollupAdminLogic__factory.connect( @@ -126,20 +129,24 @@ export const createTokenBridge = async ( // if fee token is used approve the fee const feeToken = await _getFeeToken(inbox, l1Signer.provider!) if (feeToken != ethers.constants.AddressZero) { - // scale the retryable fee to the fee token decimals denomination - const scaledRetryableFee = await _getScaledAmount( + // scale the retryable fees to the fee token decimals denomination + let scaledRetryableFeeForFactory = await _getScaledAmount( + feeToken, + retryableFeeForFactory, + l1Signer.provider! + ) + let scaledRetryableFeeForContracts = await _getScaledAmount( feeToken, - retryableFee, + retryableFeeForContracts, l1Signer.provider! ) await ( await IERC20__factory.connect(feeToken, l1Signer).approve( l1TokenBridgeCreator.address, - scaledRetryableFee + scaledRetryableFeeForFactory.add(scaledRetryableFeeForContracts) ) ).wait() - retryableFee = BigNumber.from(0) } /// do it - create token bridge @@ -149,7 +156,12 @@ export const createTokenBridge = async ( rollupOwnerAddress, maxGasForContracts, gasPrice, - { value: retryableFee } + { + value: + feeToken == ethers.constants.AddressZero + ? retryableFeeForFactory.add(retryableFeeForContracts) + : BigNumber.from(0), + } ) ).wait() @@ -708,29 +720,6 @@ const _getFeeToken = async ( return feeToken } -/** - * Scale the amount from 18-denomination to the fee token decimals denomination - */ -async function _getScaledAmount( - feeToken: string, - amount: BigNumber, - provider: ethers.providers.Provider -): Promise { - const decimals = await ERC20__factory.connect(feeToken, provider).decimals() - if (decimals == 18) { - return amount - } else if (decimals < 18) { - let scaledAmount = amount.div(BigNumber.from(10).pow(18 - decimals)) - // round up if necessary - if (scaledAmount.mul(BigNumber.from(10).pow(18 - decimals)).lt(amount)) { - scaledAmount = scaledAmount.add(1) - } - return scaledAmount - } else { - return amount.mul(BigNumber.from(10).pow(decimals - 18)) - } -} - export function sleep(ms: number) { return new Promise(resolve => setTimeout(resolve, ms)) } diff --git a/scripts/local-deployment/localDeploymentLib.ts b/scripts/local-deployment/localDeploymentLib.ts index fcc40a08d3..6f93120e3d 100644 --- a/scripts/local-deployment/localDeploymentLib.ts +++ b/scripts/local-deployment/localDeploymentLib.ts @@ -1,4 +1,4 @@ -import { ethers } from 'ethers' +import { BigNumber, ethers } from 'ethers' import { JsonRpcProvider } from '@ethersproject/providers' import { L1Network, L2Network, addCustomNetwork } from '@arbitrum/sdk' import { Bridge__factory } from '@arbitrum/sdk/dist/lib/abi/factories/Bridge__factory' @@ -11,6 +11,7 @@ import { getEstimateForDeployingFactory, } from '../atomicTokenBridgeDeployer' import { l2Networks } from '@arbitrum/sdk/dist/lib/dataEntities/networks' +import { ERC20__factory } from '../../build/types' const LOCALHOST_L2_RPC = 'http://localhost:8547' const LOCALHOST_L3_RPC = 'http://localhost:3347' @@ -258,3 +259,26 @@ export const getLocalNetworks = async ( l2Network, } } + +/** + * Scale the amount from 18-denomination to the fee token decimals denomination + */ +export async function _getScaledAmount( + feeToken: string, + amount: BigNumber, + provider: ethers.providers.Provider +): Promise { + const decimals = await ERC20__factory.connect(feeToken, provider).decimals() + if (decimals == 18) { + return amount + } else if (decimals < 18) { + let scaledAmount = amount.div(BigNumber.from(10).pow(18 - decimals)) + // round up if necessary + if (scaledAmount.mul(BigNumber.from(10).pow(18 - decimals)).lt(amount)) { + scaledAmount = scaledAmount.add(1) + } + return scaledAmount + } else { + return amount.mul(BigNumber.from(10).pow(decimals - 18)) + } +}