diff --git a/src/createTokenBridge-ethers.ts b/src/createTokenBridge-ethers.ts index 5ad5d6ee..ad712142 100644 --- a/src/createTokenBridge-ethers.ts +++ b/src/createTokenBridge-ethers.ts @@ -1,10 +1,14 @@ /* eslint-disable no-empty */ +import { Address } from 'viem'; import { BigNumber, ContractFactory, ethers } from 'ethers'; import { JsonRpcProvider } from '@ethersproject/providers'; import { L1Network, L1ToL2MessageGasEstimator, L2Network, addCustomNetwork } from '@arbitrum/sdk'; import { getBaseFee } from '@arbitrum/sdk/dist/lib/utils/lib'; import { RollupAdminLogic__factory } from '@arbitrum/sdk/dist/lib/abi/factories/RollupAdminLogic__factory'; -import { Address } from 'viem'; +import { GasOverrides } from '@arbitrum/sdk/dist/lib/message/L1ToL2MessageGasEstimator'; +import L1AtomicTokenBridgeCreator from '@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/ethereum/L1AtomicTokenBridgeCreator.sol/L1AtomicTokenBridgeCreator.json'; +import L2AtomicTokenBridgeFactory from '@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/arbitrum/L2AtomicTokenBridgeFactory.sol/L2AtomicTokenBridgeFactory.json'; +import { TransactionRequestRetryableGasOverrides } from './utils/gasOverrides'; type NamedFactory = ContractFactory & { contractName: string }; const NamedFactoryInstance = (contractJson: { @@ -18,11 +22,7 @@ const NamedFactoryInstance = (contractJson: { }; // import from token-bridge-contracts directly to make sure the bytecode is the same -import L1AtomicTokenBridgeCreator from '@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/ethereum/L1AtomicTokenBridgeCreator.sol/L1AtomicTokenBridgeCreator.json'; -import L2AtomicTokenBridgeFactory from '@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/arbitrum/L2AtomicTokenBridgeFactory.sol/L2AtomicTokenBridgeFactory.json'; const L2AtomicTokenBridgeFactory__factory = NamedFactoryInstance(L2AtomicTokenBridgeFactory); -import { TransactionRequestGasOverrides } from './types/TransactionRequestGasOverrides'; -import { GasOverrides } from '@arbitrum/sdk/dist/lib/message/L1ToL2MessageGasEstimator'; export type CreateTokenBridgeGetInputsResult = { @@ -135,28 +135,28 @@ export const getEstimateForSettingGateway = async ( setGatewaysCalldata: `0x${string}`, l1Provider: ethers.providers.Provider, l2Provider: ethers.providers.Provider, - gasOverrides?: TransactionRequestGasOverrides, + retryableGasOverrides?: TransactionRequestRetryableGasOverrides, ) => { //// run retryable estimate for setting a token gateway in the router const l1ToL2MsgGasEstimate = new L1ToL2MessageGasEstimator(l2Provider); // applying gas overrides const gasOverridesForEstimation: GasOverrides = {}; - if (gasOverrides && gasOverrides.retryableTicketGasLimit) { + if (retryableGasOverrides && retryableGasOverrides.gasLimit) { gasOverridesForEstimation.gasLimit = { min: undefined, percentIncrease: undefined, }; - if (gasOverrides.retryableTicketGasLimit.minimum) { + if (retryableGasOverrides.gasLimit.base) { gasOverridesForEstimation.gasLimit.min = BigNumber.from( - gasOverrides.retryableTicketGasLimit.minimum, + retryableGasOverrides.gasLimit.base, ); } - if (gasOverrides.retryableTicketGasLimit.percentIncrease) { + if (retryableGasOverrides.gasLimit.percentIncrease) { gasOverridesForEstimation.gasLimit.percentIncrease = BigNumber.from( - gasOverrides.retryableTicketGasLimit.percentIncrease, + retryableGasOverrides.gasLimit.percentIncrease, ); } } @@ -183,40 +183,6 @@ export const getEstimateForSettingGateway = async ( }; }; -export const getSigner = (provider: JsonRpcProvider, key?: string) => { - if (!key && !provider) throw new Error('Provide at least one of key or provider.'); - if (key) return new Wallet(key).connect(provider); - else return provider.getSigner(0); -}; - -export const getParsedLogs = ( - logs: ethers.providers.Log[], - iface: ethers.utils.Interface, - eventName: string, -) => { - const eventFragment = iface.getEvent(eventName); - const parsedLogs = logs - .filter((curr: any) => curr.topics[0] === iface.getEventTopic(eventFragment)) - .map((curr: any) => iface.parseLog(curr)); - return parsedLogs; -}; - -const _getFeeToken = async (inbox: string, l1Provider: ethers.providers.Provider) => { - const bridge = await IInbox__factory.attach(inbox).connect(l1Provider).bridge(); - - let feeToken = ethers.constants.AddressZero; - - try { - feeToken = await IERC20Bridge__factory.attach(bridge).connect(l1Provider).nativeToken(); - } catch {} - - return feeToken; -}; - -export function sleep(ms: number) { - return new Promise((resolve) => setTimeout(resolve, ms)); -} - const registerNewNetwork = async ( l1Provider: JsonRpcProvider, l2Provider: JsonRpcProvider, diff --git a/src/createTokenBridge.integration.test.ts b/src/createTokenBridge.integration.test.ts index ffde9d76..6319272b 100644 --- a/src/createTokenBridge.integration.test.ts +++ b/src/createTokenBridge.integration.test.ts @@ -160,11 +160,11 @@ it(`successfully deploys token bridge contracts through token bridge creator`, a const setWethGatewayTxRequest = await createTokenBridgePrepareSetWethGatewayTransactionRequest({ rollup: testnodeInformation.rollup, parentChainPublicClient: nitroTestnodeL1Client, - childChainPublicClient: nitroTestnodeL2Client, + orbitChainPublicClient: nitroTestnodeL2Client, account: l2RollupOwner.address, - gasOverrides: { - retryableTicketGasLimit: { - minimum: 100_000n, + retryableGasOverrides: { + gasLimit: { + base: 100_000n, }, }, }); diff --git a/src/createTokenBridgePrepareSetWethGatewayTransactionRequest.ts b/src/createTokenBridgePrepareSetWethGatewayTransactionRequest.ts index f2338c70..9374a184 100644 --- a/src/createTokenBridgePrepareSetWethGatewayTransactionRequest.ts +++ b/src/createTokenBridgePrepareSetWethGatewayTransactionRequest.ts @@ -7,14 +7,14 @@ import { createTokenBridgeFetchTokenBridgeContracts } from './createTokenBridgeF import { createRollupFetchCoreContracts } from './createRollupFetchCoreContracts'; import { publicClientToProvider } from './ethers-compat/publicClientToProvider'; import { getEstimateForSettingGateway } from './createTokenBridge-ethers'; -import { TransactionRequestGasOverrides } from './types/TransactionRequestGasOverrides'; +import { TransactionRequestRetryableGasOverrides } from './utils/gasOverrides'; export type CreateTokenBridgePrepareRegisterWethGatewayTransactionRequestParams = { rollup: Address; parentChainPublicClient: PublicClient; - childChainPublicClient: PublicClient; + orbitChainPublicClient: PublicClient; account: Address; - gasOverrides?: TransactionRequestGasOverrides; + retryableGasOverrides?: TransactionRequestRetryableGasOverrides; }; const parentChainGatewayRouterAbi = [ @@ -81,9 +81,9 @@ const parentChainGatewayRouterAbi = [ export async function createTokenBridgePrepareSetWethGatewayTransactionRequest({ rollup, parentChainPublicClient, - childChainPublicClient, + orbitChainPublicClient, account, - gasOverrides, + retryableGasOverrides, }: CreateTokenBridgePrepareRegisterWethGatewayTransactionRequestParams) { const chainId = parentChainPublicClient.chain?.id; @@ -132,7 +132,7 @@ export async function createTokenBridgePrepareSetWethGatewayTransactionRequest({ // ethers providers const parentChainProvider = publicClientToProvider(parentChainPublicClient); - const childChainProvider = publicClientToProvider(childChainPublicClient); + const orbitChainProvider = publicClientToProvider(orbitChainPublicClient); // encode data for the setGateways call // (we first encode dummy data, to get the retryable message estimates) @@ -153,8 +153,8 @@ export async function createTokenBridgePrepareSetWethGatewayTransactionRequest({ tokenBridgeContracts.parentChainContracts.router, setGatewaysDummyCalldata, parentChainProvider, - childChainProvider, - gasOverrides, + orbitChainProvider, + retryableGasOverrides, ); // (and then we encode the real data, to send the transaction) diff --git a/src/types/TransactionRequestGasOverrides.ts b/src/types/TransactionRequestGasOverrides.ts deleted file mode 100644 index 05514fcc..00000000 --- a/src/types/TransactionRequestGasOverrides.ts +++ /dev/null @@ -1,10 +0,0 @@ -type GasOverrideOptions = { - minimum?: bigint; - percentIncrease?: bigint; -}; - -export type TransactionRequestGasOverrides = { - gasLimit?: GasOverrideOptions; - retryableTicketGasLimit?: GasOverrideOptions; - retryableTicketFees?: GasOverrideOptions; -}; diff --git a/src/utils/gasOverrides.ts b/src/utils/gasOverrides.ts index 2d3ee1b7..1af42609 100644 --- a/src/utils/gasOverrides.ts +++ b/src/utils/gasOverrides.ts @@ -8,6 +8,7 @@ export type TransactionRequestGasOverrides = { }; export type TransactionRequestRetryableGasOverrides = { + gasLimit?: GasOverrideOptions; deposit?: GasOverrideOptions; };