From 8948983a22027067999de8eca29e79a00aac167b Mon Sep 17 00:00:00 2001 From: Doug Lance Date: Fri, 22 Sep 2023 09:18:40 -0400 Subject: [PATCH 01/12] chore: renames L1/2 to parentChain/chain in inbox --- scripts/sendL2SignedMsg.ts | 4 +- src/lib/inbox/inbox.ts | 136 +++++++++++++++------------- tests/integration/sendL2msg.test.ts | 4 +- 3 files changed, 76 insertions(+), 68 deletions(-) diff --git a/scripts/sendL2SignedMsg.ts b/scripts/sendL2SignedMsg.ts index 10ac03e9e7..088b19c0cf 100644 --- a/scripts/sendL2SignedMsg.ts +++ b/scripts/sendL2SignedMsg.ts @@ -29,8 +29,8 @@ const sendSignedMsg = async () => { value: BigNumber.from(0), data: '0x12', } - const signedTx = await inbox.signL2Tx(message, l2Deployer) - await inbox.sendL2SignedTx(signedTx) + const signedTx = await inbox.signChainTx(message, l2Deployer) + await inbox.sendChainSignedTx(signedTx) } sendSignedMsg() diff --git a/src/lib/inbox/inbox.ts b/src/lib/inbox/inbox.ts index 240bfb61b6..c6d28d74a0 100644 --- a/src/lib/inbox/inbox.ts +++ b/src/lib/inbox/inbox.ts @@ -28,7 +28,10 @@ import { SequencerInbox__factory } from '../abi/factories/SequencerInbox__factor import { IInbox__factory } from '../abi/factories/IInbox__factory' import { RequiredPick } from '../utils/types' import { MessageDeliveredEvent } from '../abi/Bridge' -import { l1Networks, L2Network } from '../dataEntities/networks' +import { + l1Networks as parentChainNetworks, + L2Network as ChainNetwork, +} from '../dataEntities/networks' import { SignerProviderUtils } from '../dataEntities/signerOrProvider' import { FetchedEvent, EventFetcher } from '../utils/eventFetcher' import { MultiCaller, CallInput } from '../utils/multicall' @@ -42,12 +45,12 @@ type ForceInclusionParams = FetchedEvent & { delayedAcc: string } -type GasComponentsWithL2Part = { +type GasComponentsWithChainPart = { gasEstimate: BigNumber gasEstimateForL1: BigNumber baseFee: BigNumber l1BaseFeeEstimate: BigNumber - gasEstimateForL2: BigNumber + gasEstimateForChain: BigNumber } type RequiredTransactionRequestType = RequiredPick< TransactionRequest, @@ -57,18 +60,20 @@ type RequiredTransactionRequestType = RequiredPick< * Tools for interacting with the inbox and bridge contracts */ export class InboxTools { - private readonly l1Provider - private readonly l1Network + private readonly parentChainProvider + private readonly parentChainNetwork constructor( - private readonly l1Signer: Signer, - private readonly l2Network: L2Network + private readonly parentChainSigner: Signer, + private readonly chainNetwork: ChainNetwork ) { - this.l1Provider = SignerProviderUtils.getProviderOrThrow(this.l1Signer) - this.l1Network = l1Networks[l2Network.partnerChainID] - if (!this.l1Network) + this.parentChainProvider = SignerProviderUtils.getProviderOrThrow( + this.parentChainSigner + ) + this.parentChainNetwork = parentChainNetworks[chainNetwork.partnerChainID] + if (!this.parentChainNetwork) throw new ArbSdkError( - `L1Network not found for chain id: ${l2Network.partnerChainID}.` + `ParentChainNetwork not found for chain id: ${chainNetwork.partnerChainID}.` ) } @@ -84,13 +89,16 @@ export class InboxTools { blockNumber: number, blockTimestamp: number ): Promise { - const block = await this.l1Provider.getBlock(blockNumber) + const block = await this.parentChainProvider.getBlock(blockNumber) const diff = block.timestamp - blockTimestamp if (diff < 0) return block // we take a long average block time of 14s // and always move at least 10 blocks - const diffBlocks = Math.max(Math.ceil(diff / this.l1Network.blockTime), 10) + const diffBlocks = Math.max( + Math.ceil(diff / this.parentChainNetwork.blockTime), + 10 + ) return await this.findFirstBlockBelow( blockNumber - diffBlocks, @@ -100,12 +108,12 @@ export class InboxTools { //Check if this request is contract creation or not. private isContractCreation( - transactionl2Request: TransactionRequest + transactionChainRequest: TransactionRequest ): boolean { if ( - transactionl2Request.to === '0x' || - !isDefined(transactionl2Request.to) || - transactionl2Request.to === ethers.constants.AddressZero + transactionChainRequest.to === '0x' || + !isDefined(transactionChainRequest.to) || + transactionChainRequest.to === ethers.constants.AddressZero ) { return true } @@ -114,32 +122,32 @@ export class InboxTools { /** * We should use nodeInterface to get the gas estimate is because we - * are making a delayed inbox message which doesn't need l1 calldata + * are making a delayed inbox message which doesn't need parentChain calldata * gas fee part. */ private async estimateArbitrumGas( - transactionl2Request: RequiredTransactionRequestType, - l2Provider: Provider - ): Promise { + transactionChainRequest: RequiredTransactionRequestType, + chainProvider: Provider + ): Promise { const nodeInterface = NodeInterface__factory.connect( NODE_INTERFACE_ADDRESS, - l2Provider + chainProvider ) - const contractCreation = this.isContractCreation(transactionl2Request) + const contractCreation = this.isContractCreation(transactionChainRequest) const gasComponents = await nodeInterface.callStatic.gasEstimateComponents( - transactionl2Request.to || ethers.constants.AddressZero, + transactionChainRequest.to || ethers.constants.AddressZero, contractCreation, - transactionl2Request.data, + transactionChainRequest.data, { - from: transactionl2Request.from, - value: transactionl2Request.value, + from: transactionChainRequest.from, + value: transactionChainRequest.value, } ) - const gasEstimateForL2: BigNumber = gasComponents.gasEstimate.sub( + const gasEstimateForChain: BigNumber = gasComponents.gasEstimate.sub( gasComponents.gasEstimateForL1 ) - return { ...gasComponents, gasEstimateForL2 } + return { ...gasComponents, gasEstimateForChain } } /** @@ -149,11 +157,11 @@ export class InboxTools { */ private async getForceIncludableBlockRange(blockNumberRangeSize: number) { const sequencerInbox = SequencerInbox__factory.connect( - this.l2Network.ethBridge.sequencerInbox, - this.l1Provider + this.chainNetwork.ethBridge.sequencerInbox, + this.parentChainProvider ) - const multicall = await MultiCaller.fromProvider(this.l1Provider) + const multicall = await MultiCaller.fromProvider(this.parentChainProvider) const multicallInput: [ CallInput>>, ReturnType, @@ -207,7 +215,7 @@ export class InboxTools { maxSearchRangeBlocks: number, rangeMultiplier: number ): Promise[]> { - const eFetcher = new EventFetcher(this.l1Provider) + const eFetcher = new EventFetcher(this.parentChainProvider) // events don't become eligible until they pass a delay // find a block range which will emit eligible events @@ -245,7 +253,7 @@ export class InboxTools { /** * Find the event of the latest message that can be force include * @param maxSearchRangeBlocks The max range of blocks to search in. - * Defaults to 3 * 6545 ( = ~3 days) prior to the first eligble block + * Defaults to 3 * 6545 ( = ~3 days) prior to the first eligible block * @param startSearchRangeBlocks The start range of block to search in. * Moves incrementally up to the maxSearchRangeBlocks. Defaults to 100; * @param rangeMultiplier The multiplier to use when increasing the block range @@ -255,11 +263,11 @@ export class InboxTools { public async getForceIncludableEvent( maxSearchRangeBlocks: number = 3 * 6545, startSearchRangeBlocks = 100, - rangeMultipler = 2 + rangeMultiplier = 2 ): Promise { const bridge = Bridge__factory.connect( - this.l2Network.ethBridge.bridge, - this.l1Provider + this.chainNetwork.ethBridge.bridge, + this.parentChainProvider ) // events dont become eligible until they pass a delay @@ -268,7 +276,7 @@ export class InboxTools { bridge, startSearchRangeBlocks, maxSearchRangeBlocks, - rangeMultipler + rangeMultiplier ) // no events appeared within that time period @@ -277,8 +285,8 @@ export class InboxTools { // take the last event - as including this one will include all previous events const eventInfo = events[events.length - 1] const sequencerInbox = SequencerInbox__factory.connect( - this.l2Network.ethBridge.sequencerInbox, - this.l1Provider + this.chainNetwork.ethBridge.sequencerInbox, + this.parentChainProvider ) // has the sequencer inbox already read this latest message const totalDelayedRead = await sequencerInbox.totalDelayedMessagesRead() @@ -317,14 +325,14 @@ export class InboxTools { overrides?: Overrides ): Promise { const sequencerInbox = SequencerInbox__factory.connect( - this.l2Network.ethBridge.sequencerInbox, - this.l1Signer + this.chainNetwork.ethBridge.sequencerInbox, + this.parentChainSigner ) const eventInfo = messageDeliveredEvent || (await this.getForceIncludableEvent()) if (!eventInfo) return null - const block = await this.l1Provider.getBlock(eventInfo.blockHash) + const block = await this.parentChainProvider.getBlock(eventInfo.blockHash) return await sequencerInbox.functions.forceInclusion( eventInfo.event.messageIndex.add(1), @@ -339,19 +347,19 @@ export class InboxTools { } /** - * Send l2 signed tx using delayed inox, which won't alias the sender's adddress - * It will be automatically included by the sequencer on l2, if it isn't included + * Send Chain signed tx using delayed inbox, which won't alias the sender's address + * It will be automatically included by the sequencer on Chain, if it isn't included * within 24 hours, you can force include it * @param signedTx A signed transaction which can be sent directly to network, - * you can call inboxTools.signL2Message to get. - * @returns The l1 delayed inbox's transaction itself. + * you can call inboxTools.signChainMessage to get. + * @returns The parentChain delayed inbox's transaction itself. */ - public async sendL2SignedTx( + public async sendChainSignedTx( signedTx: string ): Promise { const delayedInbox = IInbox__factory.connect( - this.l2Network.ethBridge.inbox, - this.l1Signer + this.chainNetwork.ethBridge.inbox, + this.parentChainSigner ) const sendData = ethers.utils.solidityPack( @@ -364,43 +372,43 @@ export class InboxTools { /** * Sign a transaction with msg.to, msg.value and msg.data. - * You can use this as a helper to call inboxTools.sendL2SignedMessage + * You can use this as a helper to call inboxTools.sendChainSignedMessage * above. * @param message A signed transaction which can be sent directly to network, * tx.to, tx.data, tx.value must be provided when not contract creation, if * contractCreation is true, no need provide tx.to. tx.gasPrice and tx.nonce * can be overrided. (You can also send contract creation transaction by set tx.to * to zero address or null) - * @param l2Signer ethers Signer type, used to sign l2 transaction - * @returns The l1 delayed inbox's transaction signed data. + * @param chainSigner ethers Signer type, used to sign Chain transaction + * @returns The parentChain delayed inbox's transaction signed data. */ - public async signL2Tx( + public async signChainTx( txRequest: RequiredTransactionRequestType, - l2Signer: Signer + chainSigner: Signer ): Promise { const tx: RequiredTransactionRequestType = { ...txRequest } const contractCreation = this.isContractCreation(tx) if (!isDefined(tx.nonce)) { - tx.nonce = await l2Signer.getTransactionCount() + tx.nonce = await chainSigner.getTransactionCount() } //check transaction type (if no transaction type or gasPrice provided, use eip1559 type) if (tx.type === 1 || tx.gasPrice) { if (tx.gasPrice) { - tx.gasPrice = await l2Signer.getGasPrice() + tx.gasPrice = await chainSigner.getGasPrice() } } else { if (!isDefined(tx.maxFeePerGas)) { - const feeData = await l2Signer.getFeeData() + const feeData = await chainSigner.getFeeData() tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas! tx.maxFeePerGas = feeData.maxFeePerGas! } tx.type = 2 } - tx.from = await l2Signer.getAddress() - tx.chainId = await l2Signer.getChainId() + tx.from = await chainSigner.getAddress() + tx.chainId = await chainSigner.getChainId() // if this is contract creation, user might not input the to address, // however, it is needed when we call to estimateArbitrumGas, so @@ -409,17 +417,17 @@ export class InboxTools { tx.to = ethers.constants.AddressZero } - //estimate gas on l2 + //estimate gas on Chain try { tx.gasLimit = ( - await this.estimateArbitrumGas(tx, l2Signer.provider!) - ).gasEstimateForL2 + await this.estimateArbitrumGas(tx, chainSigner.provider!) + ).gasEstimateForChain } catch (error) { throw new ArbSdkError('execution failed (estimate gas failed)') } if (contractCreation) { delete tx.to } - return await l2Signer.signTransaction(tx) + return await chainSigner.signTransaction(tx) } } diff --git a/tests/integration/sendL2msg.test.ts b/tests/integration/sendL2msg.test.ts index e704ab0faa..6c1aeda558 100644 --- a/tests/integration/sendL2msg.test.ts +++ b/tests/integration/sendL2msg.test.ts @@ -33,9 +33,9 @@ const sendSignedTx = async (testState: any, info?: any) => { ...info, value: BigNumber.from(0), } - const signedTx = await inbox.signL2Tx(message, l2Deployer) + const signedTx = await inbox.signChainTx(message, l2Deployer) - const l1Tx = await inbox.sendL2SignedTx(signedTx) + const l1Tx = await inbox.sendChainSignedTx(signedTx) return { signedMsg: signedTx, l1TransactionReceipt: await l1Tx?.wait(), From 448b9590319cb386c24e4b8b2b0178bcf1c1b854 Mon Sep 17 00:00:00 2001 From: Doug Lance Date: Wed, 11 Oct 2023 12:00:15 -0400 Subject: [PATCH 02/12] update to use new childChain name with ArbitrumChain type --- src/lib/inbox/inbox.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lib/inbox/inbox.ts b/src/lib/inbox/inbox.ts index c6d28d74a0..f477037bff 100644 --- a/src/lib/inbox/inbox.ts +++ b/src/lib/inbox/inbox.ts @@ -30,7 +30,7 @@ import { RequiredPick } from '../utils/types' import { MessageDeliveredEvent } from '../abi/Bridge' import { l1Networks as parentChainNetworks, - L2Network as ChainNetwork, + L2Network as ArbitrumChain, } from '../dataEntities/networks' import { SignerProviderUtils } from '../dataEntities/signerOrProvider' import { FetchedEvent, EventFetcher } from '../utils/eventFetcher' @@ -65,15 +65,15 @@ export class InboxTools { constructor( private readonly parentChainSigner: Signer, - private readonly chainNetwork: ChainNetwork + private readonly childChain: ArbitrumChain ) { this.parentChainProvider = SignerProviderUtils.getProviderOrThrow( this.parentChainSigner ) - this.parentChainNetwork = parentChainNetworks[chainNetwork.partnerChainID] + this.parentChainNetwork = parentChainNetworks[childChain.partnerChainID] if (!this.parentChainNetwork) throw new ArbSdkError( - `ParentChainNetwork not found for chain id: ${chainNetwork.partnerChainID}.` + `ParentChainNetwork not found for chain id: ${childChain.partnerChainID}.` ) } @@ -157,7 +157,7 @@ export class InboxTools { */ private async getForceIncludableBlockRange(blockNumberRangeSize: number) { const sequencerInbox = SequencerInbox__factory.connect( - this.chainNetwork.ethBridge.sequencerInbox, + this.childChain.ethBridge.sequencerInbox, this.parentChainProvider ) @@ -266,7 +266,7 @@ export class InboxTools { rangeMultiplier = 2 ): Promise { const bridge = Bridge__factory.connect( - this.chainNetwork.ethBridge.bridge, + this.childChain.ethBridge.bridge, this.parentChainProvider ) @@ -285,7 +285,7 @@ export class InboxTools { // take the last event - as including this one will include all previous events const eventInfo = events[events.length - 1] const sequencerInbox = SequencerInbox__factory.connect( - this.chainNetwork.ethBridge.sequencerInbox, + this.childChain.ethBridge.sequencerInbox, this.parentChainProvider ) // has the sequencer inbox already read this latest message @@ -325,7 +325,7 @@ export class InboxTools { overrides?: Overrides ): Promise { const sequencerInbox = SequencerInbox__factory.connect( - this.chainNetwork.ethBridge.sequencerInbox, + this.childChain.ethBridge.sequencerInbox, this.parentChainSigner ) const eventInfo = @@ -358,7 +358,7 @@ export class InboxTools { signedTx: string ): Promise { const delayedInbox = IInbox__factory.connect( - this.chainNetwork.ethBridge.inbox, + this.childChain.ethBridge.inbox, this.parentChainSigner ) From 8391400af1f21452e68a09f649381f425eb21774 Mon Sep 17 00:00:00 2001 From: Doug Lance Date: Wed, 11 Oct 2023 12:16:25 -0400 Subject: [PATCH 03/12] updates name of methods on inbox to use childChain --- scripts/sendL2SignedMsg.ts | 4 ++-- src/lib/inbox/inbox.ts | 4 ++-- tests/integration/sendL2msg.test.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/sendL2SignedMsg.ts b/scripts/sendL2SignedMsg.ts index 088b19c0cf..d117247518 100644 --- a/scripts/sendL2SignedMsg.ts +++ b/scripts/sendL2SignedMsg.ts @@ -29,8 +29,8 @@ const sendSignedMsg = async () => { value: BigNumber.from(0), data: '0x12', } - const signedTx = await inbox.signChainTx(message, l2Deployer) - await inbox.sendChainSignedTx(signedTx) + const signedTx = await inbox.signChildChainTx(message, l2Deployer) + await inbox.sendChildChainSignedTx(signedTx) } sendSignedMsg() diff --git a/src/lib/inbox/inbox.ts b/src/lib/inbox/inbox.ts index f477037bff..98acd719b0 100644 --- a/src/lib/inbox/inbox.ts +++ b/src/lib/inbox/inbox.ts @@ -354,7 +354,7 @@ export class InboxTools { * you can call inboxTools.signChainMessage to get. * @returns The parentChain delayed inbox's transaction itself. */ - public async sendChainSignedTx( + public async sendChildChainSignedTx( signedTx: string ): Promise { const delayedInbox = IInbox__factory.connect( @@ -382,7 +382,7 @@ export class InboxTools { * @param chainSigner ethers Signer type, used to sign Chain transaction * @returns The parentChain delayed inbox's transaction signed data. */ - public async signChainTx( + public async signChildChainTx( txRequest: RequiredTransactionRequestType, chainSigner: Signer ): Promise { diff --git a/tests/integration/sendL2msg.test.ts b/tests/integration/sendL2msg.test.ts index 6c1aeda558..e9bcdd97ae 100644 --- a/tests/integration/sendL2msg.test.ts +++ b/tests/integration/sendL2msg.test.ts @@ -33,9 +33,9 @@ const sendSignedTx = async (testState: any, info?: any) => { ...info, value: BigNumber.from(0), } - const signedTx = await inbox.signChainTx(message, l2Deployer) + const signedTx = await inbox.signChildChainTx(message, l2Deployer) - const l1Tx = await inbox.sendChainSignedTx(signedTx) + const l1Tx = await inbox.sendChildChainSignedTx(signedTx) return { signedMsg: signedTx, l1TransactionReceipt: await l1Tx?.wait(), From 6e77e7516c69c3afae8c9fabd696de23de4984d0 Mon Sep 17 00:00:00 2001 From: Doug Lance Date: Wed, 11 Oct 2023 13:26:04 -0400 Subject: [PATCH 04/12] Update childChainTransactionRequest --- src/lib/inbox/inbox.ts | 56 ++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/lib/inbox/inbox.ts b/src/lib/inbox/inbox.ts index 98acd719b0..af2a34d51d 100644 --- a/src/lib/inbox/inbox.ts +++ b/src/lib/inbox/inbox.ts @@ -50,7 +50,7 @@ type GasComponentsWithChainPart = { gasEstimateForL1: BigNumber baseFee: BigNumber l1BaseFeeEstimate: BigNumber - gasEstimateForChain: BigNumber + gasEstimateForChildChain: BigNumber } type RequiredTransactionRequestType = RequiredPick< TransactionRequest, @@ -106,14 +106,14 @@ export class InboxTools { ) } - //Check if this request is contract creation or not. + // Check if this request is contract creation or not. private isContractCreation( - transactionChainRequest: TransactionRequest + childChainTransactionRequest: TransactionRequest ): boolean { if ( - transactionChainRequest.to === '0x' || - !isDefined(transactionChainRequest.to) || - transactionChainRequest.to === ethers.constants.AddressZero + childChainTransactionRequest.to === '0x' || + !isDefined(childChainTransactionRequest.to) || + childChainTransactionRequest.to === ethers.constants.AddressZero ) { return true } @@ -126,7 +126,7 @@ export class InboxTools { * gas fee part. */ private async estimateArbitrumGas( - transactionChainRequest: RequiredTransactionRequestType, + childChainTransactionRequest: RequiredTransactionRequestType, chainProvider: Provider ): Promise { const nodeInterface = NodeInterface__factory.connect( @@ -134,20 +134,22 @@ export class InboxTools { chainProvider ) - const contractCreation = this.isContractCreation(transactionChainRequest) + const contractCreation = this.isContractCreation( + childChainTransactionRequest + ) const gasComponents = await nodeInterface.callStatic.gasEstimateComponents( - transactionChainRequest.to || ethers.constants.AddressZero, + childChainTransactionRequest.to || ethers.constants.AddressZero, contractCreation, - transactionChainRequest.data, + childChainTransactionRequest.data, { - from: transactionChainRequest.from, - value: transactionChainRequest.value, + from: childChainTransactionRequest.from, + value: childChainTransactionRequest.value, } ) - const gasEstimateForChain: BigNumber = gasComponents.gasEstimate.sub( + const gasEstimateForChildChain: BigNumber = gasComponents.gasEstimate.sub( gasComponents.gasEstimateForL1 ) - return { ...gasComponents, gasEstimateForChain } + return { ...gasComponents, gasEstimateForChildChain } } /** @@ -304,7 +306,7 @@ export class InboxTools { /** * Force includes all eligible messages in the delayed inbox. - * The inbox contract doesnt allow a message to be force-included + * The inbox contract doesn't allow a message to be force-included * until after a delay period has been completed. * @param messageDeliveredEvent Provide this to include all messages up to this one. Responsibility is on the caller to check the eligibility of this event. * @returns The force include transaction, or null if no eligible message were found for inclusion @@ -347,7 +349,7 @@ export class InboxTools { } /** - * Send Chain signed tx using delayed inbox, which won't alias the sender's address + * Send Child Chain signed tx using delayed inbox, which won't alias the sender's address * It will be automatically included by the sequencer on Chain, if it isn't included * within 24 hours, you can force include it * @param signedTx A signed transaction which can be sent directly to network, @@ -379,36 +381,36 @@ export class InboxTools { * contractCreation is true, no need provide tx.to. tx.gasPrice and tx.nonce * can be overrided. (You can also send contract creation transaction by set tx.to * to zero address or null) - * @param chainSigner ethers Signer type, used to sign Chain transaction + * @param childChainSigner ethers Signer type, used to sign Chain transaction * @returns The parentChain delayed inbox's transaction signed data. */ public async signChildChainTx( txRequest: RequiredTransactionRequestType, - chainSigner: Signer + childChainSigner: Signer ): Promise { const tx: RequiredTransactionRequestType = { ...txRequest } const contractCreation = this.isContractCreation(tx) if (!isDefined(tx.nonce)) { - tx.nonce = await chainSigner.getTransactionCount() + tx.nonce = await childChainSigner.getTransactionCount() } //check transaction type (if no transaction type or gasPrice provided, use eip1559 type) if (tx.type === 1 || tx.gasPrice) { if (tx.gasPrice) { - tx.gasPrice = await chainSigner.getGasPrice() + tx.gasPrice = await childChainSigner.getGasPrice() } } else { if (!isDefined(tx.maxFeePerGas)) { - const feeData = await chainSigner.getFeeData() + const feeData = await childChainSigner.getFeeData() tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas! tx.maxFeePerGas = feeData.maxFeePerGas! } tx.type = 2 } - tx.from = await chainSigner.getAddress() - tx.chainId = await chainSigner.getChainId() + tx.from = await childChainSigner.getAddress() + tx.chainId = await childChainSigner.getChainId() // if this is contract creation, user might not input the to address, // however, it is needed when we call to estimateArbitrumGas, so @@ -417,17 +419,17 @@ export class InboxTools { tx.to = ethers.constants.AddressZero } - //estimate gas on Chain + //estimate gas on child chain try { tx.gasLimit = ( - await this.estimateArbitrumGas(tx, chainSigner.provider!) - ).gasEstimateForChain + await this.estimateArbitrumGas(tx, childChainSigner.provider!) + ).gasEstimateForChildChain } catch (error) { throw new ArbSdkError('execution failed (estimate gas failed)') } if (contractCreation) { delete tx.to } - return await chainSigner.signTransaction(tx) + return await childChainSigner.signTransaction(tx) } } From 7e23cad91d8d3d8262e11a9493f8df3016377ffb Mon Sep 17 00:00:00 2001 From: Doug Lance Date: Wed, 18 Oct 2023 13:42:30 -0400 Subject: [PATCH 05/12] remove `network` --- src/lib/inbox/inbox.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lib/inbox/inbox.ts b/src/lib/inbox/inbox.ts index af2a34d51d..11c71f97a0 100644 --- a/src/lib/inbox/inbox.ts +++ b/src/lib/inbox/inbox.ts @@ -29,8 +29,8 @@ import { IInbox__factory } from '../abi/factories/IInbox__factory' import { RequiredPick } from '../utils/types' import { MessageDeliveredEvent } from '../abi/Bridge' import { - l1Networks as parentChainNetworks, - L2Network as ArbitrumChain, + l1Networks as parentChains, + L2Network as ChildChain, } from '../dataEntities/networks' import { SignerProviderUtils } from '../dataEntities/signerOrProvider' import { FetchedEvent, EventFetcher } from '../utils/eventFetcher' @@ -61,17 +61,17 @@ type RequiredTransactionRequestType = RequiredPick< */ export class InboxTools { private readonly parentChainProvider - private readonly parentChainNetwork + private readonly parentChain constructor( private readonly parentChainSigner: Signer, - private readonly childChain: ArbitrumChain + private readonly childChain: ChildChain ) { this.parentChainProvider = SignerProviderUtils.getProviderOrThrow( this.parentChainSigner ) - this.parentChainNetwork = parentChainNetworks[childChain.partnerChainID] - if (!this.parentChainNetwork) + this.parentChain = parentChains[childChain.partnerChainID] + if (!this.parentChain) throw new ArbSdkError( `ParentChainNetwork not found for chain id: ${childChain.partnerChainID}.` ) @@ -96,7 +96,7 @@ export class InboxTools { // we take a long average block time of 14s // and always move at least 10 blocks const diffBlocks = Math.max( - Math.ceil(diff / this.parentChainNetwork.blockTime), + Math.ceil(diff / this.parentChain.blockTime), 10 ) @@ -352,7 +352,7 @@ export class InboxTools { * Send Child Chain signed tx using delayed inbox, which won't alias the sender's address * It will be automatically included by the sequencer on Chain, if it isn't included * within 24 hours, you can force include it - * @param signedTx A signed transaction which can be sent directly to network, + * @param signedTx A signed transaction which can be sent directly to chain, * you can call inboxTools.signChainMessage to get. * @returns The parentChain delayed inbox's transaction itself. */ @@ -376,7 +376,7 @@ export class InboxTools { * Sign a transaction with msg.to, msg.value and msg.data. * You can use this as a helper to call inboxTools.sendChainSignedMessage * above. - * @param message A signed transaction which can be sent directly to network, + * @param message A signed transaction which can be sent directly to chain, * tx.to, tx.data, tx.value must be provided when not contract creation, if * contractCreation is true, no need provide tx.to. tx.gasPrice and tx.nonce * can be overrided. (You can also send contract creation transaction by set tx.to From 3684f80564dd0166b58977f0efabcb7f76258ab8 Mon Sep 17 00:00:00 2001 From: Doug Lance Date: Thu, 19 Oct 2023 08:53:51 -0400 Subject: [PATCH 06/12] update names with from pr feedback --- src/lib/inbox/inbox.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/inbox/inbox.ts b/src/lib/inbox/inbox.ts index 11c71f97a0..5f2759164c 100644 --- a/src/lib/inbox/inbox.ts +++ b/src/lib/inbox/inbox.ts @@ -45,7 +45,7 @@ type ForceInclusionParams = FetchedEvent & { delayedAcc: string } -type GasComponentsWithChainPart = { +type GasComponentsWithChildChainPart = { gasEstimate: BigNumber gasEstimateForL1: BigNumber baseFee: BigNumber @@ -127,11 +127,11 @@ export class InboxTools { */ private async estimateArbitrumGas( childChainTransactionRequest: RequiredTransactionRequestType, - chainProvider: Provider - ): Promise { + childChainProvider: Provider + ): Promise { const nodeInterface = NodeInterface__factory.connect( NODE_INTERFACE_ADDRESS, - chainProvider + childChainProvider ) const contractCreation = this.isContractCreation( From 6608b9788e8c1b9e9a834c58ff2bd19690a010fd Mon Sep 17 00:00:00 2001 From: Doug Lance Date: Mon, 25 Sep 2023 13:06:17 -0400 Subject: [PATCH 07/12] chore: update l1/2 name for dataEntities --- scripts/testSetup.ts | 40 ++++---- src/index.ts | 12 +-- src/lib/assetBridger/assetBridger.ts | 12 ++- src/lib/assetBridger/erc20Bridger.ts | 6 +- src/lib/assetBridger/ethBridger.ts | 4 +- src/lib/dataEntities/networks.ts | 102 ++++++++++--------- src/lib/inbox/inbox.ts | 4 +- src/lib/message/L1ToL2Message.ts | 8 +- src/lib/message/L1ToL2MessageCreator.ts | 4 +- src/lib/message/L1ToL2MessageGasEstimator.ts | 4 +- src/lib/message/L1Transaction.ts | 8 +- src/lib/message/L2ToL1Message.ts | 4 +- src/lib/message/L2ToL1MessageClassic.ts | 4 +- src/lib/message/L2ToL1MessageNitro.ts | 10 +- src/lib/utils/lib.ts | 4 +- src/lib/utils/multicall.ts | 20 ++-- tests/fork/inbox.test.ts | 5 +- tests/integration/ethBridgeAddresses.test.ts | 2 +- tests/integration/sendL2msg.test.ts | 5 +- tests/integration/testHelpers.ts | 2 +- tests/unit/l2toL1MessageEvents.test.ts | 2 +- tests/unit/multicall.test.ts | 2 +- 22 files changed, 142 insertions(+), 122 deletions(-) diff --git a/scripts/testSetup.ts b/scripts/testSetup.ts index 5558054297..eb0272fe89 100644 --- a/scripts/testSetup.ts +++ b/scripts/testSetup.ts @@ -22,10 +22,10 @@ import { Wallet } from '@ethersproject/wallet' import dotenv from 'dotenv' import { EthBridger, InboxTools, Erc20Bridger } from '../src' import { - L1Network, - L2Network, - getL1Network, - getL2Network, + ParentChainNetwork, + ChainNetwork, + getParentChainNetwork, + getChainNetwork, addCustomNetwork, } from '../src/lib/dataEntities/networks' import { Signer } from 'ethers' @@ -70,8 +70,8 @@ export const getCustomNetworks = async ( l1Url: string, l2Url: string ): Promise<{ - l1Network: L1Network - l2Network: Omit + l1Network: ParentChainNetwork + l2Network: Omit }> => { const l1Provider = new JsonRpcProvider(l1Url) const l2Provider = new JsonRpcProvider(l2Url) @@ -98,7 +98,7 @@ export const getCustomNetworks = async ( const l1NetworkInfo = await l1Provider.getNetwork() const l2NetworkInfo = await l2Provider.getNetwork() - const l1Network: L1Network = { + const l1Network: ParentChainNetwork = { blockTime: 10, chainID: l1NetworkInfo.chainId, explorerUrl: '', @@ -108,7 +108,7 @@ export const getCustomNetworks = async ( isArbitrum: false, } - const l2Network: Omit = { + const l2Network: Omit = { chainID: l2NetworkInfo.chainId, confirmPeriodBlocks: confirmPeriodBlocks.toNumber(), ethBridge: { @@ -149,7 +149,7 @@ export const setupNetworks = async ( l2Deployer, coreL2Network.ethBridge.inbox ) - const l2Network: L2Network = { + const l2Network: ChainNetwork = { ...coreL2Network, tokenBridge: { l1CustomGateway: l1Contracts.customGateway.address, @@ -171,8 +171,8 @@ export const setupNetworks = async ( } addCustomNetwork({ - customL1Network: l1Network, - customL2Network: l2Network, + customParentChainNetwork: l1Network, + customChainNetwork: l2Network, }) // also register the weth gateway @@ -204,8 +204,8 @@ export const getSigner = (provider: JsonRpcProvider, key?: string) => { } export const testSetup = async (): Promise<{ - l1Network: L1Network - l2Network: L2Network + l1Network: ParentChainNetwork + l2Network: ChainNetwork l1Signer: Signer l2Signer: Signer erc20Bridger: Erc20Bridger @@ -225,10 +225,10 @@ export const testSetup = async (): Promise<{ const l1Signer = seed.connect(ethProvider) const l2Signer = seed.connect(arbProvider) - let setL1Network: L1Network, setL2Network: L2Network + let setL1Network: ParentChainNetwork, setL2Network: ChainNetwork try { - const l1Network = await getL1Network(l1Deployer) - const l2Network = await getL2Network(l2Deployer) + const l1Network = await getParentChainNetwork(l1Deployer) + const l2Network = await getChainNetwork(l2Deployer) setL1Network = l1Network setL2Network = l2Network } catch (err) { @@ -240,12 +240,12 @@ export const testSetup = async (): Promise<{ const { l1Network, l2Network } = JSON.parse( fs.readFileSync(localNetworkFile).toString() ) as { - l1Network: L1Network - l2Network: L2Network + l1Network: ParentChainNetwork + l2Network: ChainNetwork } addCustomNetwork({ - customL1Network: l1Network, - customL2Network: l2Network, + customParentChainNetwork: l1Network, + customChainNetwork: l2Network, }) setL1Network = l1Network setL2Network = l2Network diff --git a/src/index.ts b/src/index.ts index 99056afc27..6ad13a8124 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,12 +43,12 @@ export { L1ToL2MessageGasEstimator } from './lib/message/L1ToL2MessageGasEstimat export { argSerializerConstructor } from './lib/utils/byte_serialize_params' export { CallInput, MultiCaller } from './lib/utils/multicall' export { - L1Networks, - L2Networks, - L1Network, - L2Network, - getL1Network, - getL2Network, + ParentChainNetworks as L1Networks, + ChainNetworks as L2Networks, + ParentChainNetwork, + ChainNetwork as L2Network, + getParentChainNetwork as getL1Network, + getChainNetwork as getL2Network, addCustomNetwork, addDefaultLocalNetwork, } from './lib/dataEntities/networks' diff --git a/src/lib/assetBridger/assetBridger.ts b/src/lib/assetBridger/assetBridger.ts index ea3f72162b..8afc6f1ce9 100644 --- a/src/lib/assetBridger/assetBridger.ts +++ b/src/lib/assetBridger/assetBridger.ts @@ -20,7 +20,11 @@ import { ArbSdkError } from '../dataEntities/errors' import { L1ContractTransaction } from '../message/L1Transaction' import { L2ContractTransaction } from '../message/L2Transaction' -import { l1Networks, L1Network, L2Network } from '../dataEntities/networks' +import { + parentChainNetworks, + ParentChainNetwork, + ChainNetwork, +} from '../dataEntities/networks' import { SignerOrProvider, SignerProviderUtils, @@ -30,10 +34,10 @@ import { * Base for bridging assets from l1 to l2 and back */ export abstract class AssetBridger { - public readonly l1Network: L1Network + public readonly l1Network: ParentChainNetwork - public constructor(public readonly l2Network: L2Network) { - this.l1Network = l1Networks[l2Network.partnerChainID] + public constructor(public readonly l2Network: ChainNetwork) { + this.l1Network = parentChainNetworks[l2Network.partnerChainID] if (!this.l1Network) { throw new ArbSdkError( `Unknown l1 network chain id: ${l2Network.partnerChainID}` diff --git a/src/lib/assetBridger/erc20Bridger.ts b/src/lib/assetBridger/erc20Bridger.ts index d4883ac22f..c8f0fae5fc 100644 --- a/src/lib/assetBridger/erc20Bridger.ts +++ b/src/lib/assetBridger/erc20Bridger.ts @@ -45,7 +45,7 @@ import { L1ToL2MessageGasEstimator, } from '../message/L1ToL2MessageGasEstimator' import { SignerProviderUtils } from '../dataEntities/signerOrProvider' -import { L2Network, getL2Network } from '../dataEntities/networks' +import { ChainNetwork, getChainNetwork } from '../dataEntities/networks' import { ArbSdkError, MissingProviderArbSdkError } from '../dataEntities/errors' import { DISABLED_GATEWAY } from '../dataEntities/constants' import { EventFetcher } from '../utils/eventFetcher' @@ -178,7 +178,7 @@ export class Erc20Bridger extends AssetBridger< /** * Bridger for moving ERC20 tokens back and forth between L1 to L2 */ - public constructor(l2Network: L2Network) { + public constructor(l2Network: ChainNetwork) { super(l2Network) } @@ -188,7 +188,7 @@ export class Erc20Bridger extends AssetBridger< * @returns */ public static async fromProvider(l2Provider: Provider) { - return new Erc20Bridger(await getL2Network(l2Provider)) + return new Erc20Bridger(await getChainNetwork(l2Provider)) } /** diff --git a/src/lib/assetBridger/ethBridger.ts b/src/lib/assetBridger/ethBridger.ts index 4441f3d7f6..0373b1e11e 100644 --- a/src/lib/assetBridger/ethBridger.ts +++ b/src/lib/assetBridger/ethBridger.ts @@ -45,7 +45,7 @@ import { import { OmitTyped } from '../utils/types' import { SignerProviderUtils } from '../dataEntities/signerOrProvider' import { MissingProviderArbSdkError } from '../dataEntities/errors' -import { getL2Network } from '../dataEntities/networks' +import { getChainNetwork } from '../dataEntities/networks' export interface EthWithdrawParams { /** @@ -138,7 +138,7 @@ export class EthBridger extends AssetBridger< * @returns */ public static async fromProvider(l2Provider: Provider) { - return new EthBridger(await getL2Network(l2Provider)) + return new EthBridger(await getChainNetwork(l2Provider)) } /** diff --git a/src/lib/dataEntities/networks.ts b/src/lib/dataEntities/networks.ts index 8199dae1b8..158aef9ffe 100644 --- a/src/lib/dataEntities/networks.ts +++ b/src/lib/dataEntities/networks.ts @@ -21,13 +21,13 @@ import { ArbSdkError } from '../dataEntities/errors' import { SEVEN_DAYS_IN_SECONDS } from './constants' import { RollupAdminLogic__factory } from '../abi/factories/RollupAdminLogic__factory' -export interface L1Network extends Network { +export interface ParentChainNetwork extends Network { partnerChainIDs: number[] blockTime: number //seconds isArbitrum: false } -export interface L2Network extends Network { +export interface ChainNetwork extends Network { tokenBridge: TokenBridge ethBridge: EthBridge partnerChainID: number @@ -77,12 +77,12 @@ export interface EthBridge { } } -export interface L1Networks { - [id: string]: L1Network +export interface ParentChainNetworks { + [id: string]: ParentChainNetwork } -export interface L2Networks { - [id: string]: L2Network +export interface ChainNetworks { + [id: string]: ChainNetwork } const mainnetTokenBridge: TokenBridge = { @@ -114,7 +114,7 @@ const mainnetETHBridge: EthBridge = { }, } -export const l1Networks: L1Networks = { +export const parentChainNetworks: ParentChainNetworks = { 1: { chainID: 1, name: 'Mainnet', @@ -153,7 +153,7 @@ export const l1Networks: L1Networks = { }, } -export const l2Networks: L2Networks = { +export const chainNetworks: ChainNetworks = { 42161: { chainID: 42161, name: 'Arbitrum One', @@ -345,7 +345,7 @@ const getNetwork = async ( return chainId })() - const networks = layer === 1 ? l1Networks : l2Networks + const networks = layer === 1 ? parentChainNetworks : chainNetworks if (networks[chainID]) { return networks[chainID] } else { @@ -353,15 +353,15 @@ const getNetwork = async ( } } -export const getL1Network = ( +export const getParentChainNetwork = ( signerOrProviderOrChainID: SignerOrProvider | number -): Promise => { - return getNetwork(signerOrProviderOrChainID, 1) as Promise +): Promise => { + return getNetwork(signerOrProviderOrChainID, 1) as Promise } -export const getL2Network = ( +export const getChainNetwork = ( signerOrProviderOrChainID: SignerOrProvider | number -): Promise => { - return getNetwork(signerOrProviderOrChainID, 2) as Promise +): Promise => { + return getNetwork(signerOrProviderOrChainID, 2) as Promise } /** @@ -396,44 +396,52 @@ export const getEthBridgeInformation = async ( } export const addCustomNetwork = ({ - customL1Network, - customL2Network, + customParentChainNetwork, + customChainNetwork, }: { - customL1Network?: L1Network - customL2Network: L2Network + customParentChainNetwork?: ParentChainNetwork + customChainNetwork: ChainNetwork }): void => { - if (customL1Network) { - if (l1Networks[customL1Network.chainID]) { + if (customParentChainNetwork) { + if (parentChainNetworks[customParentChainNetwork.chainID]) { throw new ArbSdkError( - `Network ${customL1Network.chainID} already included` + `Network ${customParentChainNetwork.chainID} already included` ) - } else if (!customL1Network.isCustom) { + } else if (!customParentChainNetwork.isCustom) { throw new ArbSdkError( - `Custom network ${customL1Network.chainID} must have isCustom flag set to true` + `Custom network ${customParentChainNetwork.chainID} must have isCustom flag set to true` ) } else { - l1Networks[customL1Network.chainID] = customL1Network + parentChainNetworks[customParentChainNetwork.chainID] = + customParentChainNetwork } } - if (l2Networks[customL2Network.chainID]) - throw new ArbSdkError(`Network ${customL2Network.chainID} already included`) - else if (!customL2Network.isCustom) { + if (chainNetworks[customChainNetwork.chainID]) throw new ArbSdkError( - `Custom network ${customL2Network.chainID} must have isCustom flag set to true` + `Network ${customChainNetwork.chainID} already included` + ) + else if (!customChainNetwork.isCustom) { + throw new ArbSdkError( + `Custom network ${customChainNetwork.chainID} must have isCustom flag set to true` ) } - l2Networks[customL2Network.chainID] = customL2Network + chainNetworks[customChainNetwork.chainID] = customChainNetwork - const l1PartnerChain = l1Networks[customL2Network.partnerChainID] - if (!l1PartnerChain) + const parentChainPartnerChain = + parentChainNetworks[customChainNetwork.partnerChainID] + if (!parentChainPartnerChain) throw new ArbSdkError( - `Network ${customL2Network.chainID}'s partner network, ${customL2Network.partnerChainID}, not recognized` + `Network ${customChainNetwork.chainID}'s partner network, ${customChainNetwork.partnerChainID}, not recognized` ) - if (!l1PartnerChain.partnerChainIDs.includes(customL2Network.chainID)) { - l1PartnerChain.partnerChainIDs.push(customL2Network.chainID) + if ( + !parentChainPartnerChain.partnerChainIDs.includes( + customChainNetwork.chainID + ) + ) { + parentChainPartnerChain.partnerChainIDs.push(customChainNetwork.chainID) } } @@ -443,10 +451,10 @@ export const addCustomNetwork = ({ * @see {@link https://github.com/OffchainLabs/nitro} */ export const addDefaultLocalNetwork = (): { - l1Network: L1Network - l2Network: L2Network + parentChainNetwork: ParentChainNetwork + chainNetwork: ChainNetwork } => { - const defaultLocalL1Network: L1Network = { + const defaultLocalParentChainNetwork: ParentChainNetwork = { blockTime: 10, chainID: 1337, explorerUrl: '', @@ -456,7 +464,7 @@ export const addDefaultLocalNetwork = (): { isArbitrum: false, } - const defaultLocalL2Network: L2Network = { + const defaultLocalChainNetwork: ChainNetwork = { chainID: 412346, confirmPeriodBlocks: 20, ethBridge: { @@ -494,19 +502,19 @@ export const addDefaultLocalNetwork = (): { } addCustomNetwork({ - customL1Network: defaultLocalL1Network, - customL2Network: defaultLocalL2Network, + customParentChainNetwork: defaultLocalParentChainNetwork, + customChainNetwork: defaultLocalChainNetwork, }) return { - l1Network: defaultLocalL1Network, - l2Network: defaultLocalL2Network, + parentChainNetwork: defaultLocalParentChainNetwork, + chainNetwork: defaultLocalChainNetwork, } } -export const isL1Network = ( - network: L1Network | L2Network -): network is L1Network => { - if ((network as L1Network).partnerChainIDs) return true +export const isParentChainNetwork = ( + network: ParentChainNetwork | ChainNetwork +): network is ParentChainNetwork => { + if ((network as ParentChainNetwork).partnerChainIDs) return true else return false } diff --git a/src/lib/inbox/inbox.ts b/src/lib/inbox/inbox.ts index 5f2759164c..91d09cbf11 100644 --- a/src/lib/inbox/inbox.ts +++ b/src/lib/inbox/inbox.ts @@ -29,8 +29,8 @@ import { IInbox__factory } from '../abi/factories/IInbox__factory' import { RequiredPick } from '../utils/types' import { MessageDeliveredEvent } from '../abi/Bridge' import { - l1Networks as parentChains, - L2Network as ChildChain, + parentChainNetworks as parentChains, + ChainNetwork as ChildChain, } from '../dataEntities/networks' import { SignerProviderUtils } from '../dataEntities/signerOrProvider' import { FetchedEvent, EventFetcher } from '../utils/eventFetcher' diff --git a/src/lib/message/L1ToL2Message.ts b/src/lib/message/L1ToL2Message.ts index 2339c77576..e0ef44d007 100644 --- a/src/lib/message/L1ToL2Message.ts +++ b/src/lib/message/L1ToL2Message.ts @@ -34,7 +34,7 @@ import { import { ArbSdkError } from '../dataEntities/errors' import { ethers, Overrides } from 'ethers' import { L2TransactionReceipt, RedeemTransaction } from './L2Transaction' -import { getL2Network } from '../../lib/dataEntities/networks' +import { getChainNetwork } from '../../lib/dataEntities/networks' import { RetryableMessageParams } from '../dataEntities/message' import { getTransactionReceipt, isDefined } from '../utils/lib' import { EventFetcher } from '../utils/eventFetcher' @@ -307,7 +307,7 @@ export class L1ToL2MessageReader extends L1ToL2Message { * @returns TransactionReceipt of the first successful redeem if exists, otherwise the current status of the message. */ public async getSuccessfulRedeem(): Promise { - const l2Network = await getL2Network(this.l2Provider) + const l2Network = await getChainNetwork(this.l2Provider) const eventFetcher = new EventFetcher(this.l2Provider) const creationReceipt = await this.getRetryableCreationReceipt() @@ -472,7 +472,7 @@ export class L1ToL2MessageReader extends L1ToL2Message { confirmations?: number, timeout?: number ): Promise { - const l2Network = await getL2Network(this.chainId) + const l2Network = await getChainNetwork(this.chainId) const chosenTimeout = isDefined(timeout) ? timeout @@ -846,7 +846,7 @@ export class EthDepositMessage { } public async wait(confirmations?: number, timeout?: number) { - const l2Network = await getL2Network(this.l2ChainId) + const l2Network = await getChainNetwork(this.l2ChainId) const chosenTimeout = isDefined(timeout) ? timeout diff --git a/src/lib/message/L1ToL2MessageCreator.ts b/src/lib/message/L1ToL2MessageCreator.ts index d930e2b22f..71f60da3fd 100644 --- a/src/lib/message/L1ToL2MessageCreator.ts +++ b/src/lib/message/L1ToL2MessageCreator.ts @@ -7,7 +7,7 @@ import { } from './L1ToL2MessageGasEstimator' import { L1ContractTransaction, L1TransactionReceipt } from './L1Transaction' import { Inbox__factory } from '../abi/factories/Inbox__factory' -import { getL2Network } from '../dataEntities/networks' +import { getChainNetwork } from '../dataEntities/networks' import { PayableOverrides } from '@ethersproject/contracts' import { SignerProviderUtils } from '../dataEntities/signerOrProvider' import { MissingProviderArbSdkError } from '../dataEntities/errors' @@ -96,7 +96,7 @@ export class L1ToL2MessageCreator { options ) - const l2Network = await getL2Network(l2Provider) + const l2Network = await getChainNetwork(l2Provider) const inboxInterface = Inbox__factory.createInterface() const functionData = inboxInterface.encodeFunctionData( 'createRetryableTicket', diff --git a/src/lib/message/L1ToL2MessageGasEstimator.ts b/src/lib/message/L1ToL2MessageGasEstimator.ts index 99c7686fc1..acd58a47fc 100644 --- a/src/lib/message/L1ToL2MessageGasEstimator.ts +++ b/src/lib/message/L1ToL2MessageGasEstimator.ts @@ -5,7 +5,7 @@ import { Inbox__factory } from '../abi/factories/Inbox__factory' import { NodeInterface__factory } from '../abi/factories/NodeInterface__factory' import { NODE_INTERFACE_ADDRESS } from '../dataEntities/constants' import { ArbSdkError } from '../dataEntities/errors' -import { getL2Network } from '../dataEntities/networks' +import { getChainNetwork } from '../dataEntities/networks' import { RetryableData, RetryableDataTools, @@ -125,7 +125,7 @@ export class L1ToL2MessageGasEstimator { ): Promise { const defaultedOptions = this.applySubmissionPriceDefaults(options) - const network = await getL2Network(this.l2Provider) + const network = await getChainNetwork(this.l2Provider) const inbox = Inbox__factory.connect(network.ethBridge.inbox, l1Provider) return this.percentIncrease( diff --git a/src/lib/message/L1Transaction.ts b/src/lib/message/L1Transaction.ts index d2b79b3e4b..054428a8ad 100644 --- a/src/lib/message/L1Transaction.ts +++ b/src/lib/message/L1Transaction.ts @@ -46,7 +46,7 @@ import { MessageDeliveredEvent } from '../abi/Bridge' import { EventArgs, parseTypedLogs } from '../dataEntities/event' import { isDefined } from '../utils/lib' import { SubmitRetryableMessageDataParser } from './messageDataParser' -import { getL2Network } from '../dataEntities/networks' +import { getChainNetwork } from '../dataEntities/networks' export interface L1ContractTransaction< TReceipt extends L1TransactionReceipt = L1TransactionReceipt @@ -106,7 +106,7 @@ export class L1TransactionReceipt implements TransactionReceipt { l2SignerOrProvider: T ): Promise { const provider = SignerProviderUtils.getProviderOrThrow(l2SignerOrProvider) - const network = await getL2Network(provider) + const network = await getChainNetwork(provider) return this.blockNumber < network.nitroGenesisL1Block } @@ -207,7 +207,7 @@ export class L1TransactionReceipt implements TransactionReceipt { public async getL1ToL2MessagesClassic( l2Provider: Provider ): Promise { - const network = await getL2Network(l2Provider) + const network = await getChainNetwork(l2Provider) const chainID = network.chainID.toString() const isClassic = await this.isClassic(l2Provider) @@ -243,7 +243,7 @@ export class L1TransactionReceipt implements TransactionReceipt { l2SignerOrProvider: T ): Promise { const provider = SignerProviderUtils.getProviderOrThrow(l2SignerOrProvider) - const network = await getL2Network(provider) + const network = await getChainNetwork(provider) const chainID = network.chainID.toString() const isClassic = await this.isClassic(provider) diff --git a/src/lib/message/L2ToL1Message.ts b/src/lib/message/L2ToL1Message.ts index 1b3d1a4bce..94451924a9 100644 --- a/src/lib/message/L2ToL1Message.ts +++ b/src/lib/message/L2ToL1Message.ts @@ -35,7 +35,7 @@ import { import { isDefined } from '../utils/lib' import { EventArgs } from '../dataEntities/event' import { L2ToL1MessageStatus } from '../dataEntities/message' -import { getL2Network } from '../dataEntities/networks' +import { getChainNetwork } from '../dataEntities/networks' import { ArbSdkError } from '../dataEntities/errors' export type L2ToL1TransactionEvent = @@ -107,7 +107,7 @@ export class L2ToL1Message { hash?: BigNumber, indexInBatch?: BigNumber ): Promise<(L2ToL1TransactionEvent & { transactionHash: string })[]> { - const l2Network = await getL2Network(l2Provider) + const l2Network = await getChainNetwork(l2Provider) const inClassicRange = (blockTag: BlockTag, nitroGenBlock: number) => { if (typeof blockTag === 'string') { diff --git a/src/lib/message/L2ToL1MessageClassic.ts b/src/lib/message/L2ToL1MessageClassic.ts index 1edba7fc1d..5967a83545 100644 --- a/src/lib/message/L2ToL1MessageClassic.ts +++ b/src/lib/message/L2ToL1MessageClassic.ts @@ -40,7 +40,7 @@ import { isDefined, wait } from '../utils/lib' import { ArbSdkError } from '../dataEntities/errors' import { EventArgs } from '../dataEntities/event' import { L2ToL1MessageStatus } from '../dataEntities/message' -import { getL2Network } from '../dataEntities/networks' +import { getChainNetwork } from '../dataEntities/networks' export interface MessageBatchProofInfo { /** @@ -205,7 +205,7 @@ export class L2ToL1MessageReaderClassic extends L2ToL1MessageClassic { */ protected async getOutboxAddress(l2Provider: Provider, batchNumber: number) { if (!isDefined(this.outboxAddress)) { - const l2Network = await getL2Network(l2Provider) + const l2Network = await getChainNetwork(l2Provider) // find the outbox where the activation batch number of the next outbox // is greater than the supplied batch diff --git a/src/lib/message/L2ToL1MessageNitro.ts b/src/lib/message/L2ToL1MessageNitro.ts index a744061ec8..cb002ab223 100644 --- a/src/lib/message/L2ToL1MessageNitro.ts +++ b/src/lib/message/L2ToL1MessageNitro.ts @@ -40,7 +40,7 @@ import { SignerOrProvider, } from '../dataEntities/signerOrProvider' import { getBlockRangesForL1Block, isArbitrumChain, wait } from '../utils/lib' -import { getL2Network } from '../dataEntities/networks' +import { getChainNetwork } from '../dataEntities/networks' import { NodeCreatedEvent, RollupUserLogic } from '../abi/RollupUserLogic' import { ArbitrumProvider } from '../utils/arbProvider' import { ArbBlock } from '../dataEntities/rpc' @@ -205,7 +205,7 @@ export class L2ToL1MessageReaderNitro extends L2ToL1MessageNitro { * Check if this message has already been executed in the Outbox */ protected async hasExecuted(l2Provider: Provider): Promise { - const l2Network = await getL2Network(l2Provider) + const l2Network = await getChainNetwork(l2Provider) const outbox = Outbox__factory.connect( l2Network.ethBridge.outbox, this.l1Provider @@ -331,7 +331,7 @@ export class L2ToL1MessageReaderNitro extends L2ToL1MessageNitro { protected async getSendProps(l2Provider: Provider) { if (!this.sendRootConfirmed) { - const l2Network = await getL2Network(l2Provider) + const l2Network = await getChainNetwork(l2Provider) const rollup = RollupUserLogic__factory.connect( l2Network.ethBridge.rollup, @@ -409,7 +409,7 @@ export class L2ToL1MessageReaderNitro extends L2ToL1MessageNitro { public async getFirstExecutableBlock( l2Provider: Provider ): Promise { - const l2Network = await getL2Network(l2Provider) + const l2Network = await getChainNetwork(l2Provider) const rollup = RollupUserLogic__factory.connect( l2Network.ethBridge.rollup, @@ -526,7 +526,7 @@ export class L2ToL1MessageWriterNitro extends L2ToL1MessageReaderNitro { ) } const proof = await this.getOutboxProof(l2Provider) - const l2Network = await getL2Network(l2Provider) + const l2Network = await getChainNetwork(l2Provider) const outbox = Outbox__factory.connect( l2Network.ethBridge.outbox, this.l1Signer diff --git a/src/lib/utils/lib.ts b/src/lib/utils/lib.ts index c40341e1e6..133ac470f3 100644 --- a/src/lib/utils/lib.ts +++ b/src/lib/utils/lib.ts @@ -2,7 +2,7 @@ import { Provider } from '@ethersproject/abstract-provider' import { TransactionReceipt, JsonRpcProvider } from '@ethersproject/providers' import { ArbSdkError } from '../dataEntities/errors' import { ArbitrumProvider } from './arbProvider' -import { l2Networks } from '../dataEntities/networks' +import { chainNetworks } from '../dataEntities/networks' import { ArbSys__factory } from '../abi/factories/ArbSys__factory' import { ARB_SYS_ADDRESS } from '../dataEntities/constants' @@ -100,7 +100,7 @@ export async function getFirstBlockForL1Block({ const arbProvider = new ArbitrumProvider(provider) const currentArbBlock = await arbProvider.getBlockNumber() const arbitrumChainId = (await arbProvider.getNetwork()).chainId - const { nitroGenesisBlock } = l2Networks[arbitrumChainId] + const { nitroGenesisBlock } = chainNetworks[arbitrumChainId] async function getL1Block(forL2Block: number) { const { l1BlockNumber } = await arbProvider.getBlock(forL2Block) diff --git a/src/lib/utils/multicall.ts b/src/lib/utils/multicall.ts index 187b170c1f..16631031fc 100644 --- a/src/lib/utils/multicall.ts +++ b/src/lib/utils/multicall.ts @@ -24,11 +24,11 @@ import { Multicall2 } from '../abi/Multicall2' import { Multicall2__factory } from '../abi/factories/Multicall2__factory' import { ArbSdkError } from '../dataEntities/errors' import { - isL1Network, - L1Network, - l1Networks, - L2Network, - l2Networks, + isParentChainNetwork, + ParentChainNetwork, + parentChainNetworks, + ChainNetwork, + chainNetworks, } from '../dataEntities/networks' /** @@ -131,8 +131,10 @@ export class MultiCaller { */ public static async fromProvider(provider: Provider): Promise { const chainId = (await provider.getNetwork()).chainId - const l2Network = l2Networks[chainId] as L2Network | undefined - const l1Network = l1Networks[chainId] as L1Network | undefined + const l2Network = chainNetworks[chainId] as ChainNetwork | undefined + const l1Network = parentChainNetworks[chainId] as + | ParentChainNetwork + | undefined const network = l2Network || l1Network if (!network) { @@ -142,8 +144,8 @@ export class MultiCaller { } let multiCallAddr: string - if (isL1Network(network)) { - const firstL2 = l2Networks[network.partnerChainIDs[0]] + if (isParentChainNetwork(network)) { + const firstL2 = chainNetworks[network.partnerChainIDs[0]] if (!firstL2) throw new ArbSdkError( `No partner chain found l1 network: ${network.chainID} : partner chain ids ${network.partnerChainIDs}` diff --git a/tests/fork/inbox.test.ts b/tests/fork/inbox.test.ts index d91c238ee2..990e14cee7 100644 --- a/tests/fork/inbox.test.ts +++ b/tests/fork/inbox.test.ts @@ -30,7 +30,10 @@ import { InboxTools } from '../../src' import { ethers, network } from 'hardhat' import { hexZeroPad } from '@ethersproject/bytes' -import { L2Network, getL2Network } from '../../src/lib/dataEntities/networks' +import { + ChainNetwork as L2Network, + getChainNetwork as getL2Network, +} from '../../src/lib/dataEntities/networks' import { solidityKeccak256 } from 'ethers/lib/utils' import { ContractTransaction, Signer } from 'ethers' diff --git a/tests/integration/ethBridgeAddresses.test.ts b/tests/integration/ethBridgeAddresses.test.ts index 5d9db19974..ce3455bbbe 100644 --- a/tests/integration/ethBridgeAddresses.test.ts +++ b/tests/integration/ethBridgeAddresses.test.ts @@ -3,7 +3,7 @@ import { expect } from 'chai' import { EthBridge, getEthBridgeInformation, - getL2Network, + getChainNetwork as getL2Network, } from '../../src/lib/dataEntities/networks' import dotenv from 'dotenv' dotenv.config() diff --git a/tests/integration/sendL2msg.test.ts b/tests/integration/sendL2msg.test.ts index e9bcdd97ae..99b3b539a1 100644 --- a/tests/integration/sendL2msg.test.ts +++ b/tests/integration/sendL2msg.test.ts @@ -19,7 +19,10 @@ import { BigNumber, ethers, Signer } from 'ethers' import { InboxTools } from '../../src/lib/inbox/inbox' -import { getL2Network, L2Network } from '../../src/lib/dataEntities/networks' +import { + getChainNetwork as getL2Network, + ChainNetwork as L2Network, +} from '../../src/lib/dataEntities/networks' import { testSetup } from '../../scripts/testSetup' import { greeter } from './helper/greeter' import { expect } from 'chai' diff --git a/tests/integration/testHelpers.ts b/tests/integration/testHelpers.ts index a258c96daf..dc6453590f 100644 --- a/tests/integration/testHelpers.ts +++ b/tests/integration/testHelpers.ts @@ -31,7 +31,7 @@ import { L1ToL2MessageStatus, L2ToL1MessageStatus, } from '../../src' -import { L2Network } from '../../src/lib/dataEntities/networks' +import { ChainNetwork as L2Network } from '../../src/lib/dataEntities/networks' import { GasOverrides } from '../../src/lib/message/L1ToL2MessageGasEstimator' import { ArbSdkError } from '../../src/lib/dataEntities/errors' import { ERC20 } from '../../src/lib/abi/ERC20' diff --git a/tests/unit/l2toL1MessageEvents.test.ts b/tests/unit/l2toL1MessageEvents.test.ts index 8fff9e597b..2921c8813f 100644 --- a/tests/unit/l2toL1MessageEvents.test.ts +++ b/tests/unit/l2toL1MessageEvents.test.ts @@ -19,7 +19,7 @@ import { Logger, LogLevel } from '@ethersproject/logger' Logger.setLogLevel(LogLevel.ERROR) import { L2ToL1Message } from '../../src' -import { getL2Network } from '../../src/lib/dataEntities/networks' +import { getChainNetwork as getL2Network } from '../../src/lib/dataEntities/networks' import { providers } from 'ethers' import { anything, deepEqual, instance, mock, verify, when } from 'ts-mockito' diff --git a/tests/unit/multicall.test.ts b/tests/unit/multicall.test.ts index 8db7e1dd6a..f114bbfa0b 100644 --- a/tests/unit/multicall.test.ts +++ b/tests/unit/multicall.test.ts @@ -1,6 +1,6 @@ 'use strict' -import { getL2Network } from '../../src/lib/dataEntities/networks' +import { getChainNetwork as getL2Network } from '../../src/lib/dataEntities/networks' import { providers } from 'ethers' import { mock, when, anything, instance, deepEqual } from 'ts-mockito' import { expect } from 'chai' From 9c023f231079d6dedfce7f64e916535dc422c528 Mon Sep 17 00:00:00 2001 From: Doug Lance Date: Wed, 18 Oct 2023 12:52:38 -0400 Subject: [PATCH 08/12] removes network --- src/index.ts | 12 ++-- src/lib/dataEntities/networks.ts | 100 ++++++++++++++----------------- src/lib/inbox/inbox.ts | 4 +- 3 files changed, 54 insertions(+), 62 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6ad13a8124..e44085fda0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,12 +43,12 @@ export { L1ToL2MessageGasEstimator } from './lib/message/L1ToL2MessageGasEstimat export { argSerializerConstructor } from './lib/utils/byte_serialize_params' export { CallInput, MultiCaller } from './lib/utils/multicall' export { - ParentChainNetworks as L1Networks, - ChainNetworks as L2Networks, - ParentChainNetwork, - ChainNetwork as L2Network, - getParentChainNetwork as getL1Network, - getChainNetwork as getL2Network, + ParentChains as L1Networks, + Chains as L2Networks, + ParentChain as L1Network, + Chain as L2Network, + getParentChain as getL1Network, + getChain as getL2Network, addCustomNetwork, addDefaultLocalNetwork, } from './lib/dataEntities/networks' diff --git a/src/lib/dataEntities/networks.ts b/src/lib/dataEntities/networks.ts index 158aef9ffe..461119f871 100644 --- a/src/lib/dataEntities/networks.ts +++ b/src/lib/dataEntities/networks.ts @@ -21,13 +21,13 @@ import { ArbSdkError } from '../dataEntities/errors' import { SEVEN_DAYS_IN_SECONDS } from './constants' import { RollupAdminLogic__factory } from '../abi/factories/RollupAdminLogic__factory' -export interface ParentChainNetwork extends Network { +export interface ParentChain extends Network { partnerChainIDs: number[] blockTime: number //seconds isArbitrum: false } -export interface ChainNetwork extends Network { +export interface Chain extends Network { tokenBridge: TokenBridge ethBridge: EthBridge partnerChainID: number @@ -77,12 +77,12 @@ export interface EthBridge { } } -export interface ParentChainNetworks { - [id: string]: ParentChainNetwork +export interface ParentChains { + [id: string]: ParentChain } -export interface ChainNetworks { - [id: string]: ChainNetwork +export interface Chains { + [id: string]: Chain } const mainnetTokenBridge: TokenBridge = { @@ -114,7 +114,7 @@ const mainnetETHBridge: EthBridge = { }, } -export const parentChainNetworks: ParentChainNetworks = { +export const parentChain: ParentChains = { 1: { chainID: 1, name: 'Mainnet', @@ -153,7 +153,7 @@ export const parentChainNetworks: ParentChainNetworks = { }, } -export const chainNetworks: ChainNetworks = { +export const chains: Chains = { 42161: { chainID: 42161, name: 'Arbitrum One', @@ -345,7 +345,7 @@ const getNetwork = async ( return chainId })() - const networks = layer === 1 ? parentChainNetworks : chainNetworks + const networks = layer === 1 ? parentChain : chains if (networks[chainID]) { return networks[chainID] } else { @@ -353,15 +353,15 @@ const getNetwork = async ( } } -export const getParentChainNetwork = ( +export const getParentChain = ( signerOrProviderOrChainID: SignerOrProvider | number -): Promise => { - return getNetwork(signerOrProviderOrChainID, 1) as Promise +): Promise => { + return getNetwork(signerOrProviderOrChainID, 1) as Promise } -export const getChainNetwork = ( +export const getChain = ( signerOrProviderOrChainID: SignerOrProvider | number -): Promise => { - return getNetwork(signerOrProviderOrChainID, 2) as Promise +): Promise => { + return getNetwork(signerOrProviderOrChainID, 2) as Promise } /** @@ -396,52 +396,44 @@ export const getEthBridgeInformation = async ( } export const addCustomNetwork = ({ - customParentChainNetwork, - customChainNetwork, + customParentChain, + customChain, }: { - customParentChainNetwork?: ParentChainNetwork - customChainNetwork: ChainNetwork + customParentChain?: ParentChain + customChain: Chain }): void => { - if (customParentChainNetwork) { - if (parentChainNetworks[customParentChainNetwork.chainID]) { + if (customParentChain) { + if (parentChain[customParentChain.chainID]) { throw new ArbSdkError( - `Network ${customParentChainNetwork.chainID} already included` + `Network ${customParentChain.chainID} already included` ) - } else if (!customParentChainNetwork.isCustom) { + } else if (!customParentChain.isCustom) { throw new ArbSdkError( - `Custom network ${customParentChainNetwork.chainID} must have isCustom flag set to true` + `Custom network ${customParentChain.chainID} must have isCustom flag set to true` ) } else { - parentChainNetworks[customParentChainNetwork.chainID] = - customParentChainNetwork + parentChain[customParentChain.chainID] = customParentChain } } - if (chainNetworks[customChainNetwork.chainID]) + if (chains[customChain.chainID]) + throw new ArbSdkError(`Network ${customChain.chainID} already included`) + else if (!customChain.isCustom) { throw new ArbSdkError( - `Network ${customChainNetwork.chainID} already included` - ) - else if (!customChainNetwork.isCustom) { - throw new ArbSdkError( - `Custom network ${customChainNetwork.chainID} must have isCustom flag set to true` + `Custom network ${customChain.chainID} must have isCustom flag set to true` ) } - chainNetworks[customChainNetwork.chainID] = customChainNetwork + chains[customChain.chainID] = customChain - const parentChainPartnerChain = - parentChainNetworks[customChainNetwork.partnerChainID] + const parentChainPartnerChain = parentChain[customChain.partnerChainID] if (!parentChainPartnerChain) throw new ArbSdkError( - `Network ${customChainNetwork.chainID}'s partner network, ${customChainNetwork.partnerChainID}, not recognized` + `Network ${customChain.chainID}'s partner network, ${customChain.partnerChainID}, not recognized` ) - if ( - !parentChainPartnerChain.partnerChainIDs.includes( - customChainNetwork.chainID - ) - ) { - parentChainPartnerChain.partnerChainIDs.push(customChainNetwork.chainID) + if (!parentChainPartnerChain.partnerChainIDs.includes(customChain.chainID)) { + parentChainPartnerChain.partnerChainIDs.push(customChain.chainID) } } @@ -451,10 +443,10 @@ export const addCustomNetwork = ({ * @see {@link https://github.com/OffchainLabs/nitro} */ export const addDefaultLocalNetwork = (): { - parentChainNetwork: ParentChainNetwork - chainNetwork: ChainNetwork + parentChain: ParentChain + chain: Chain } => { - const defaultLocalParentChainNetwork: ParentChainNetwork = { + const defaultLocalParentChain: ParentChain = { blockTime: 10, chainID: 1337, explorerUrl: '', @@ -464,7 +456,7 @@ export const addDefaultLocalNetwork = (): { isArbitrum: false, } - const defaultLocalChainNetwork: ChainNetwork = { + const defaultLocalChain: Chain = { chainID: 412346, confirmPeriodBlocks: 20, ethBridge: { @@ -502,19 +494,19 @@ export const addDefaultLocalNetwork = (): { } addCustomNetwork({ - customParentChainNetwork: defaultLocalParentChainNetwork, - customChainNetwork: defaultLocalChainNetwork, + customParentChain: defaultLocalParentChain, + customChain: defaultLocalChain, }) return { - parentChainNetwork: defaultLocalParentChainNetwork, - chainNetwork: defaultLocalChainNetwork, + parentChain: defaultLocalParentChain, + chain: defaultLocalChain, } } -export const isParentChainNetwork = ( - network: ParentChainNetwork | ChainNetwork -): network is ParentChainNetwork => { - if ((network as ParentChainNetwork).partnerChainIDs) return true +export const isParentChain = ( + network: ParentChain | Chain +): network is ParentChain => { + if ((network as ParentChain).partnerChainIDs) return true else return false } diff --git a/src/lib/inbox/inbox.ts b/src/lib/inbox/inbox.ts index 91d09cbf11..21985fdc3c 100644 --- a/src/lib/inbox/inbox.ts +++ b/src/lib/inbox/inbox.ts @@ -29,8 +29,8 @@ import { IInbox__factory } from '../abi/factories/IInbox__factory' import { RequiredPick } from '../utils/types' import { MessageDeliveredEvent } from '../abi/Bridge' import { - parentChainNetworks as parentChains, - ChainNetwork as ChildChain, + parentChain as parentChains, + Chain as ChildChain, } from '../dataEntities/networks' import { SignerProviderUtils } from '../dataEntities/signerOrProvider' import { FetchedEvent, EventFetcher } from '../utils/eventFetcher' From b3527f3e9919e8c8abe5062a74fbecb5092c3320 Mon Sep 17 00:00:00 2001 From: Doug Lance Date: Wed, 18 Oct 2023 13:20:24 -0400 Subject: [PATCH 09/12] fix child renaming --- scripts/testSetup.ts | 38 ++++++++++---------- src/index.ts | 6 ++-- src/lib/assetBridger/assetBridger.ts | 12 +++---- src/lib/assetBridger/erc20Bridger.ts | 9 +++-- src/lib/assetBridger/ethBridger.ts | 4 +-- src/lib/dataEntities/networks.ts | 36 +++++++++---------- src/lib/inbox/inbox.ts | 5 +-- src/lib/message/L1ToL2Message.ts | 8 ++--- src/lib/message/L1ToL2MessageCreator.ts | 4 +-- src/lib/message/L1ToL2MessageGasEstimator.ts | 4 +-- src/lib/message/L1Transaction.ts | 8 ++--- src/lib/message/L2ToL1Message.ts | 4 +-- src/lib/message/L2ToL1MessageClassic.ts | 4 +-- src/lib/message/L2ToL1MessageNitro.ts | 10 +++--- src/lib/utils/lib.ts | 4 +-- src/lib/utils/multicall.ts | 20 +++++------ 16 files changed, 87 insertions(+), 89 deletions(-) diff --git a/scripts/testSetup.ts b/scripts/testSetup.ts index eb0272fe89..2cf3ea7f79 100644 --- a/scripts/testSetup.ts +++ b/scripts/testSetup.ts @@ -22,10 +22,10 @@ import { Wallet } from '@ethersproject/wallet' import dotenv from 'dotenv' import { EthBridger, InboxTools, Erc20Bridger } from '../src' import { - ParentChainNetwork, - ChainNetwork, - getParentChainNetwork, - getChainNetwork, + ParentChain as L1Network, + ChildChain as L2Network, + getParentChain as getL1Network, + getChain as getL2Network, addCustomNetwork, } from '../src/lib/dataEntities/networks' import { Signer } from 'ethers' @@ -70,8 +70,8 @@ export const getCustomNetworks = async ( l1Url: string, l2Url: string ): Promise<{ - l1Network: ParentChainNetwork - l2Network: Omit + l1Network: L1Network + l2Network: Omit }> => { const l1Provider = new JsonRpcProvider(l1Url) const l2Provider = new JsonRpcProvider(l2Url) @@ -98,7 +98,7 @@ export const getCustomNetworks = async ( const l1NetworkInfo = await l1Provider.getNetwork() const l2NetworkInfo = await l2Provider.getNetwork() - const l1Network: ParentChainNetwork = { + const l1Network: L1Network = { blockTime: 10, chainID: l1NetworkInfo.chainId, explorerUrl: '', @@ -108,7 +108,7 @@ export const getCustomNetworks = async ( isArbitrum: false, } - const l2Network: Omit = { + const l2Network: Omit = { chainID: l2NetworkInfo.chainId, confirmPeriodBlocks: confirmPeriodBlocks.toNumber(), ethBridge: { @@ -149,7 +149,7 @@ export const setupNetworks = async ( l2Deployer, coreL2Network.ethBridge.inbox ) - const l2Network: ChainNetwork = { + const l2Network: L2Network = { ...coreL2Network, tokenBridge: { l1CustomGateway: l1Contracts.customGateway.address, @@ -171,7 +171,7 @@ export const setupNetworks = async ( } addCustomNetwork({ - customParentChainNetwork: l1Network, + customL1Network: l1Network, customChainNetwork: l2Network, }) @@ -204,8 +204,8 @@ export const getSigner = (provider: JsonRpcProvider, key?: string) => { } export const testSetup = async (): Promise<{ - l1Network: ParentChainNetwork - l2Network: ChainNetwork + l1Network: L1Network + l2Network: L2Network l1Signer: Signer l2Signer: Signer erc20Bridger: Erc20Bridger @@ -225,10 +225,10 @@ export const testSetup = async (): Promise<{ const l1Signer = seed.connect(ethProvider) const l2Signer = seed.connect(arbProvider) - let setL1Network: ParentChainNetwork, setL2Network: ChainNetwork + let setL1Network: L1Network, setL2Network: L2Network try { - const l1Network = await getParentChainNetwork(l1Deployer) - const l2Network = await getChainNetwork(l2Deployer) + const l1Network = await getL1Network(l1Deployer) + const l2Network = await getL2Network(l2Deployer) setL1Network = l1Network setL2Network = l2Network } catch (err) { @@ -240,12 +240,12 @@ export const testSetup = async (): Promise<{ const { l1Network, l2Network } = JSON.parse( fs.readFileSync(localNetworkFile).toString() ) as { - l1Network: ParentChainNetwork - l2Network: ChainNetwork + l1Network: L1Network + l2Network: L2Network } addCustomNetwork({ - customParentChainNetwork: l1Network, - customChainNetwork: l2Network, + customParentChain: l1Network, + customChain: l2Network, }) setL1Network = l1Network setL2Network = l2Network diff --git a/src/index.ts b/src/index.ts index e44085fda0..5b5ec58fad 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,11 +44,11 @@ export { argSerializerConstructor } from './lib/utils/byte_serialize_params' export { CallInput, MultiCaller } from './lib/utils/multicall' export { ParentChains as L1Networks, - Chains as L2Networks, + ChildChains as L2Networks, ParentChain as L1Network, - Chain as L2Network, + ChildChain as L2Network, getParentChain as getL1Network, - getChain as getL2Network, + getChildChain as getL2Network, addCustomNetwork, addDefaultLocalNetwork, } from './lib/dataEntities/networks' diff --git a/src/lib/assetBridger/assetBridger.ts b/src/lib/assetBridger/assetBridger.ts index 8afc6f1ce9..a46859b6db 100644 --- a/src/lib/assetBridger/assetBridger.ts +++ b/src/lib/assetBridger/assetBridger.ts @@ -21,9 +21,9 @@ import { L1ContractTransaction } from '../message/L1Transaction' import { L2ContractTransaction } from '../message/L2Transaction' import { - parentChainNetworks, - ParentChainNetwork, - ChainNetwork, + parentChains as l1Networks, + ParentChain as L1Network, + ChildChain as L2Network, } from '../dataEntities/networks' import { SignerOrProvider, @@ -34,10 +34,10 @@ import { * Base for bridging assets from l1 to l2 and back */ export abstract class AssetBridger { - public readonly l1Network: ParentChainNetwork + public readonly l1Network: L1Network - public constructor(public readonly l2Network: ChainNetwork) { - this.l1Network = parentChainNetworks[l2Network.partnerChainID] + public constructor(public readonly l2Network: L2Network) { + this.l1Network = l1Networks[l2Network.partnerChainID] if (!this.l1Network) { throw new ArbSdkError( `Unknown l1 network chain id: ${l2Network.partnerChainID}` diff --git a/src/lib/assetBridger/erc20Bridger.ts b/src/lib/assetBridger/erc20Bridger.ts index c8f0fae5fc..1504a03420 100644 --- a/src/lib/assetBridger/erc20Bridger.ts +++ b/src/lib/assetBridger/erc20Bridger.ts @@ -45,7 +45,10 @@ import { L1ToL2MessageGasEstimator, } from '../message/L1ToL2MessageGasEstimator' import { SignerProviderUtils } from '../dataEntities/signerOrProvider' -import { ChainNetwork, getChainNetwork } from '../dataEntities/networks' +import { + ChildChain as L2Network, + getChildChain as getL2Network, +} from '../dataEntities/networks' import { ArbSdkError, MissingProviderArbSdkError } from '../dataEntities/errors' import { DISABLED_GATEWAY } from '../dataEntities/constants' import { EventFetcher } from '../utils/eventFetcher' @@ -178,7 +181,7 @@ export class Erc20Bridger extends AssetBridger< /** * Bridger for moving ERC20 tokens back and forth between L1 to L2 */ - public constructor(l2Network: ChainNetwork) { + public constructor(l2Network: L2Network) { super(l2Network) } @@ -188,7 +191,7 @@ export class Erc20Bridger extends AssetBridger< * @returns */ public static async fromProvider(l2Provider: Provider) { - return new Erc20Bridger(await getChainNetwork(l2Provider)) + return new Erc20Bridger(await getL2Network(l2Provider)) } /** diff --git a/src/lib/assetBridger/ethBridger.ts b/src/lib/assetBridger/ethBridger.ts index 0373b1e11e..204b22fee4 100644 --- a/src/lib/assetBridger/ethBridger.ts +++ b/src/lib/assetBridger/ethBridger.ts @@ -45,7 +45,7 @@ import { import { OmitTyped } from '../utils/types' import { SignerProviderUtils } from '../dataEntities/signerOrProvider' import { MissingProviderArbSdkError } from '../dataEntities/errors' -import { getChainNetwork } from '../dataEntities/networks' +import { getChildChain as getL2Network } from '../dataEntities/networks' export interface EthWithdrawParams { /** @@ -138,7 +138,7 @@ export class EthBridger extends AssetBridger< * @returns */ public static async fromProvider(l2Provider: Provider) { - return new EthBridger(await getChainNetwork(l2Provider)) + return new EthBridger(await getL2Network(l2Provider)) } /** diff --git a/src/lib/dataEntities/networks.ts b/src/lib/dataEntities/networks.ts index 461119f871..620af314ae 100644 --- a/src/lib/dataEntities/networks.ts +++ b/src/lib/dataEntities/networks.ts @@ -27,7 +27,7 @@ export interface ParentChain extends Network { isArbitrum: false } -export interface Chain extends Network { +export interface ChildChain extends Network { tokenBridge: TokenBridge ethBridge: EthBridge partnerChainID: number @@ -81,8 +81,8 @@ export interface ParentChains { [id: string]: ParentChain } -export interface Chains { - [id: string]: Chain +export interface ChildChains { + [id: string]: ChildChain } const mainnetTokenBridge: TokenBridge = { @@ -114,7 +114,7 @@ const mainnetETHBridge: EthBridge = { }, } -export const parentChain: ParentChains = { +export const parentChains: ParentChains = { 1: { chainID: 1, name: 'Mainnet', @@ -153,7 +153,7 @@ export const parentChain: ParentChains = { }, } -export const chains: Chains = { +export const childChains: ChildChains = { 42161: { chainID: 42161, name: 'Arbitrum One', @@ -345,7 +345,7 @@ const getNetwork = async ( return chainId })() - const networks = layer === 1 ? parentChain : chains + const networks = layer === 1 ? parentChains : childChains if (networks[chainID]) { return networks[chainID] } else { @@ -358,10 +358,10 @@ export const getParentChain = ( ): Promise => { return getNetwork(signerOrProviderOrChainID, 1) as Promise } -export const getChain = ( +export const getChildChain = ( signerOrProviderOrChainID: SignerOrProvider | number -): Promise => { - return getNetwork(signerOrProviderOrChainID, 2) as Promise +): Promise => { + return getNetwork(signerOrProviderOrChainID, 2) as Promise } /** @@ -400,10 +400,10 @@ export const addCustomNetwork = ({ customChain, }: { customParentChain?: ParentChain - customChain: Chain + customChain: ChildChain }): void => { if (customParentChain) { - if (parentChain[customParentChain.chainID]) { + if (parentChains[customParentChain.chainID]) { throw new ArbSdkError( `Network ${customParentChain.chainID} already included` ) @@ -412,11 +412,11 @@ export const addCustomNetwork = ({ `Custom network ${customParentChain.chainID} must have isCustom flag set to true` ) } else { - parentChain[customParentChain.chainID] = customParentChain + parentChains[customParentChain.chainID] = customParentChain } } - if (chains[customChain.chainID]) + if (childChains[customChain.chainID]) throw new ArbSdkError(`Network ${customChain.chainID} already included`) else if (!customChain.isCustom) { throw new ArbSdkError( @@ -424,9 +424,9 @@ export const addCustomNetwork = ({ ) } - chains[customChain.chainID] = customChain + childChains[customChain.chainID] = customChain - const parentChainPartnerChain = parentChain[customChain.partnerChainID] + const parentChainPartnerChain = parentChains[customChain.partnerChainID] if (!parentChainPartnerChain) throw new ArbSdkError( `Network ${customChain.chainID}'s partner network, ${customChain.partnerChainID}, not recognized` @@ -444,7 +444,7 @@ export const addCustomNetwork = ({ */ export const addDefaultLocalNetwork = (): { parentChain: ParentChain - chain: Chain + chain: ChildChain } => { const defaultLocalParentChain: ParentChain = { blockTime: 10, @@ -456,7 +456,7 @@ export const addDefaultLocalNetwork = (): { isArbitrum: false, } - const defaultLocalChain: Chain = { + const defaultLocalChain: ChildChain = { chainID: 412346, confirmPeriodBlocks: 20, ethBridge: { @@ -505,7 +505,7 @@ export const addDefaultLocalNetwork = (): { } export const isParentChain = ( - network: ParentChain | Chain + network: ParentChain | ChildChain ): network is ParentChain => { if ((network as ParentChain).partnerChainIDs) return true else return false diff --git a/src/lib/inbox/inbox.ts b/src/lib/inbox/inbox.ts index 21985fdc3c..7b2abc4b71 100644 --- a/src/lib/inbox/inbox.ts +++ b/src/lib/inbox/inbox.ts @@ -28,10 +28,7 @@ import { SequencerInbox__factory } from '../abi/factories/SequencerInbox__factor import { IInbox__factory } from '../abi/factories/IInbox__factory' import { RequiredPick } from '../utils/types' import { MessageDeliveredEvent } from '../abi/Bridge' -import { - parentChain as parentChains, - Chain as ChildChain, -} from '../dataEntities/networks' +import { parentChains, ChildChain } from '../dataEntities/networks' import { SignerProviderUtils } from '../dataEntities/signerOrProvider' import { FetchedEvent, EventFetcher } from '../utils/eventFetcher' import { MultiCaller, CallInput } from '../utils/multicall' diff --git a/src/lib/message/L1ToL2Message.ts b/src/lib/message/L1ToL2Message.ts index e0ef44d007..7fcc3adabb 100644 --- a/src/lib/message/L1ToL2Message.ts +++ b/src/lib/message/L1ToL2Message.ts @@ -34,7 +34,7 @@ import { import { ArbSdkError } from '../dataEntities/errors' import { ethers, Overrides } from 'ethers' import { L2TransactionReceipt, RedeemTransaction } from './L2Transaction' -import { getChainNetwork } from '../../lib/dataEntities/networks' +import { getChildChain as getL2Network } from '../../lib/dataEntities/networks' import { RetryableMessageParams } from '../dataEntities/message' import { getTransactionReceipt, isDefined } from '../utils/lib' import { EventFetcher } from '../utils/eventFetcher' @@ -307,7 +307,7 @@ export class L1ToL2MessageReader extends L1ToL2Message { * @returns TransactionReceipt of the first successful redeem if exists, otherwise the current status of the message. */ public async getSuccessfulRedeem(): Promise { - const l2Network = await getChainNetwork(this.l2Provider) + const l2Network = await getL2Network(this.l2Provider) const eventFetcher = new EventFetcher(this.l2Provider) const creationReceipt = await this.getRetryableCreationReceipt() @@ -472,7 +472,7 @@ export class L1ToL2MessageReader extends L1ToL2Message { confirmations?: number, timeout?: number ): Promise { - const l2Network = await getChainNetwork(this.chainId) + const l2Network = await getL2Network(this.chainId) const chosenTimeout = isDefined(timeout) ? timeout @@ -846,7 +846,7 @@ export class EthDepositMessage { } public async wait(confirmations?: number, timeout?: number) { - const l2Network = await getChainNetwork(this.l2ChainId) + const l2Network = await getL2Network(this.l2ChainId) const chosenTimeout = isDefined(timeout) ? timeout diff --git a/src/lib/message/L1ToL2MessageCreator.ts b/src/lib/message/L1ToL2MessageCreator.ts index 71f60da3fd..7823cc9aae 100644 --- a/src/lib/message/L1ToL2MessageCreator.ts +++ b/src/lib/message/L1ToL2MessageCreator.ts @@ -7,7 +7,7 @@ import { } from './L1ToL2MessageGasEstimator' import { L1ContractTransaction, L1TransactionReceipt } from './L1Transaction' import { Inbox__factory } from '../abi/factories/Inbox__factory' -import { getChainNetwork } from '../dataEntities/networks' +import { getChildChain as getL2Network } from '../dataEntities/networks' import { PayableOverrides } from '@ethersproject/contracts' import { SignerProviderUtils } from '../dataEntities/signerOrProvider' import { MissingProviderArbSdkError } from '../dataEntities/errors' @@ -96,7 +96,7 @@ export class L1ToL2MessageCreator { options ) - const l2Network = await getChainNetwork(l2Provider) + const l2Network = await getL2Network(l2Provider) const inboxInterface = Inbox__factory.createInterface() const functionData = inboxInterface.encodeFunctionData( 'createRetryableTicket', diff --git a/src/lib/message/L1ToL2MessageGasEstimator.ts b/src/lib/message/L1ToL2MessageGasEstimator.ts index acd58a47fc..128ecb9e59 100644 --- a/src/lib/message/L1ToL2MessageGasEstimator.ts +++ b/src/lib/message/L1ToL2MessageGasEstimator.ts @@ -5,7 +5,7 @@ import { Inbox__factory } from '../abi/factories/Inbox__factory' import { NodeInterface__factory } from '../abi/factories/NodeInterface__factory' import { NODE_INTERFACE_ADDRESS } from '../dataEntities/constants' import { ArbSdkError } from '../dataEntities/errors' -import { getChainNetwork } from '../dataEntities/networks' +import { getChildChain as getL2Network } from '../dataEntities/networks' import { RetryableData, RetryableDataTools, @@ -125,7 +125,7 @@ export class L1ToL2MessageGasEstimator { ): Promise { const defaultedOptions = this.applySubmissionPriceDefaults(options) - const network = await getChainNetwork(this.l2Provider) + const network = await getL2Network(this.l2Provider) const inbox = Inbox__factory.connect(network.ethBridge.inbox, l1Provider) return this.percentIncrease( diff --git a/src/lib/message/L1Transaction.ts b/src/lib/message/L1Transaction.ts index 054428a8ad..d2ab95eb0f 100644 --- a/src/lib/message/L1Transaction.ts +++ b/src/lib/message/L1Transaction.ts @@ -46,7 +46,7 @@ import { MessageDeliveredEvent } from '../abi/Bridge' import { EventArgs, parseTypedLogs } from '../dataEntities/event' import { isDefined } from '../utils/lib' import { SubmitRetryableMessageDataParser } from './messageDataParser' -import { getChainNetwork } from '../dataEntities/networks' +import { getChildChain as getL2Network } from '../dataEntities/networks' export interface L1ContractTransaction< TReceipt extends L1TransactionReceipt = L1TransactionReceipt @@ -106,7 +106,7 @@ export class L1TransactionReceipt implements TransactionReceipt { l2SignerOrProvider: T ): Promise { const provider = SignerProviderUtils.getProviderOrThrow(l2SignerOrProvider) - const network = await getChainNetwork(provider) + const network = await getL2Network(provider) return this.blockNumber < network.nitroGenesisL1Block } @@ -207,7 +207,7 @@ export class L1TransactionReceipt implements TransactionReceipt { public async getL1ToL2MessagesClassic( l2Provider: Provider ): Promise { - const network = await getChainNetwork(l2Provider) + const network = await getL2Network(l2Provider) const chainID = network.chainID.toString() const isClassic = await this.isClassic(l2Provider) @@ -243,7 +243,7 @@ export class L1TransactionReceipt implements TransactionReceipt { l2SignerOrProvider: T ): Promise { const provider = SignerProviderUtils.getProviderOrThrow(l2SignerOrProvider) - const network = await getChainNetwork(provider) + const network = await getL2Network(provider) const chainID = network.chainID.toString() const isClassic = await this.isClassic(provider) diff --git a/src/lib/message/L2ToL1Message.ts b/src/lib/message/L2ToL1Message.ts index 94451924a9..fcde6086c6 100644 --- a/src/lib/message/L2ToL1Message.ts +++ b/src/lib/message/L2ToL1Message.ts @@ -35,7 +35,7 @@ import { import { isDefined } from '../utils/lib' import { EventArgs } from '../dataEntities/event' import { L2ToL1MessageStatus } from '../dataEntities/message' -import { getChainNetwork } from '../dataEntities/networks' +import { getChildChain as getL2Network } from '../dataEntities/networks' import { ArbSdkError } from '../dataEntities/errors' export type L2ToL1TransactionEvent = @@ -107,7 +107,7 @@ export class L2ToL1Message { hash?: BigNumber, indexInBatch?: BigNumber ): Promise<(L2ToL1TransactionEvent & { transactionHash: string })[]> { - const l2Network = await getChainNetwork(l2Provider) + const l2Network = await getL2Network(l2Provider) const inClassicRange = (blockTag: BlockTag, nitroGenBlock: number) => { if (typeof blockTag === 'string') { diff --git a/src/lib/message/L2ToL1MessageClassic.ts b/src/lib/message/L2ToL1MessageClassic.ts index 5967a83545..e04c050a27 100644 --- a/src/lib/message/L2ToL1MessageClassic.ts +++ b/src/lib/message/L2ToL1MessageClassic.ts @@ -40,7 +40,7 @@ import { isDefined, wait } from '../utils/lib' import { ArbSdkError } from '../dataEntities/errors' import { EventArgs } from '../dataEntities/event' import { L2ToL1MessageStatus } from '../dataEntities/message' -import { getChainNetwork } from '../dataEntities/networks' +import { getChildChain as getL2Network } from '../dataEntities/networks' export interface MessageBatchProofInfo { /** @@ -205,7 +205,7 @@ export class L2ToL1MessageReaderClassic extends L2ToL1MessageClassic { */ protected async getOutboxAddress(l2Provider: Provider, batchNumber: number) { if (!isDefined(this.outboxAddress)) { - const l2Network = await getChainNetwork(l2Provider) + const l2Network = await getL2Network(l2Provider) // find the outbox where the activation batch number of the next outbox // is greater than the supplied batch diff --git a/src/lib/message/L2ToL1MessageNitro.ts b/src/lib/message/L2ToL1MessageNitro.ts index cb002ab223..4e8892e5cf 100644 --- a/src/lib/message/L2ToL1MessageNitro.ts +++ b/src/lib/message/L2ToL1MessageNitro.ts @@ -40,7 +40,7 @@ import { SignerOrProvider, } from '../dataEntities/signerOrProvider' import { getBlockRangesForL1Block, isArbitrumChain, wait } from '../utils/lib' -import { getChainNetwork } from '../dataEntities/networks' +import { getChildChain as getL2Network } from '../dataEntities/networks' import { NodeCreatedEvent, RollupUserLogic } from '../abi/RollupUserLogic' import { ArbitrumProvider } from '../utils/arbProvider' import { ArbBlock } from '../dataEntities/rpc' @@ -205,7 +205,7 @@ export class L2ToL1MessageReaderNitro extends L2ToL1MessageNitro { * Check if this message has already been executed in the Outbox */ protected async hasExecuted(l2Provider: Provider): Promise { - const l2Network = await getChainNetwork(l2Provider) + const l2Network = await getL2Network(l2Provider) const outbox = Outbox__factory.connect( l2Network.ethBridge.outbox, this.l1Provider @@ -331,7 +331,7 @@ export class L2ToL1MessageReaderNitro extends L2ToL1MessageNitro { protected async getSendProps(l2Provider: Provider) { if (!this.sendRootConfirmed) { - const l2Network = await getChainNetwork(l2Provider) + const l2Network = await getL2Network(l2Provider) const rollup = RollupUserLogic__factory.connect( l2Network.ethBridge.rollup, @@ -409,7 +409,7 @@ export class L2ToL1MessageReaderNitro extends L2ToL1MessageNitro { public async getFirstExecutableBlock( l2Provider: Provider ): Promise { - const l2Network = await getChainNetwork(l2Provider) + const l2Network = await getL2Network(l2Provider) const rollup = RollupUserLogic__factory.connect( l2Network.ethBridge.rollup, @@ -526,7 +526,7 @@ export class L2ToL1MessageWriterNitro extends L2ToL1MessageReaderNitro { ) } const proof = await this.getOutboxProof(l2Provider) - const l2Network = await getChainNetwork(l2Provider) + const l2Network = await getL2Network(l2Provider) const outbox = Outbox__factory.connect( l2Network.ethBridge.outbox, this.l1Signer diff --git a/src/lib/utils/lib.ts b/src/lib/utils/lib.ts index 133ac470f3..40bf2b26cc 100644 --- a/src/lib/utils/lib.ts +++ b/src/lib/utils/lib.ts @@ -2,7 +2,7 @@ import { Provider } from '@ethersproject/abstract-provider' import { TransactionReceipt, JsonRpcProvider } from '@ethersproject/providers' import { ArbSdkError } from '../dataEntities/errors' import { ArbitrumProvider } from './arbProvider' -import { chainNetworks } from '../dataEntities/networks' +import { childChains } from '../dataEntities/networks' import { ArbSys__factory } from '../abi/factories/ArbSys__factory' import { ARB_SYS_ADDRESS } from '../dataEntities/constants' @@ -100,7 +100,7 @@ export async function getFirstBlockForL1Block({ const arbProvider = new ArbitrumProvider(provider) const currentArbBlock = await arbProvider.getBlockNumber() const arbitrumChainId = (await arbProvider.getNetwork()).chainId - const { nitroGenesisBlock } = chainNetworks[arbitrumChainId] + const { nitroGenesisBlock } = childChains[arbitrumChainId] async function getL1Block(forL2Block: number) { const { l1BlockNumber } = await arbProvider.getBlock(forL2Block) diff --git a/src/lib/utils/multicall.ts b/src/lib/utils/multicall.ts index 16631031fc..afab791d74 100644 --- a/src/lib/utils/multicall.ts +++ b/src/lib/utils/multicall.ts @@ -24,11 +24,11 @@ import { Multicall2 } from '../abi/Multicall2' import { Multicall2__factory } from '../abi/factories/Multicall2__factory' import { ArbSdkError } from '../dataEntities/errors' import { - isParentChainNetwork, - ParentChainNetwork, - parentChainNetworks, - ChainNetwork, - chainNetworks, + isParentChain as isL1Network, + ParentChain as L1Network, + parentChains as l1Networks, + ChildChain as L2Network, + childChains as l2Networks, } from '../dataEntities/networks' /** @@ -131,10 +131,8 @@ export class MultiCaller { */ public static async fromProvider(provider: Provider): Promise { const chainId = (await provider.getNetwork()).chainId - const l2Network = chainNetworks[chainId] as ChainNetwork | undefined - const l1Network = parentChainNetworks[chainId] as - | ParentChainNetwork - | undefined + const l2Network = l2Networks[chainId] as L2Network | undefined + const l1Network = l1Networks[chainId] as L1Network | undefined const network = l2Network || l1Network if (!network) { @@ -144,8 +142,8 @@ export class MultiCaller { } let multiCallAddr: string - if (isParentChainNetwork(network)) { - const firstL2 = chainNetworks[network.partnerChainIDs[0]] + if (isL1Network(network)) { + const firstL2 = l2Networks[network.partnerChainIDs[0]] if (!firstL2) throw new ArbSdkError( `No partner chain found l1 network: ${network.chainID} : partner chain ids ${network.partnerChainIDs}` From 96e1848dbe7f95feee703e896caa9f212752805c Mon Sep 17 00:00:00 2001 From: Doug Lance Date: Wed, 18 Oct 2023 13:30:43 -0400 Subject: [PATCH 10/12] fix getChildChain --- tests/fork/inbox.test.ts | 2 +- tests/integration/ethBridgeAddresses.test.ts | 2 +- tests/integration/sendL2msg.test.ts | 2 +- tests/unit/l2toL1MessageEvents.test.ts | 2 +- tests/unit/multicall.test.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/fork/inbox.test.ts b/tests/fork/inbox.test.ts index 990e14cee7..f5b0772019 100644 --- a/tests/fork/inbox.test.ts +++ b/tests/fork/inbox.test.ts @@ -32,7 +32,7 @@ import { ethers, network } from 'hardhat' import { hexZeroPad } from '@ethersproject/bytes' import { ChainNetwork as L2Network, - getChainNetwork as getL2Network, + getChildChain as getL2Network, } from '../../src/lib/dataEntities/networks' import { solidityKeccak256 } from 'ethers/lib/utils' import { ContractTransaction, Signer } from 'ethers' diff --git a/tests/integration/ethBridgeAddresses.test.ts b/tests/integration/ethBridgeAddresses.test.ts index ce3455bbbe..57c9eb8b62 100644 --- a/tests/integration/ethBridgeAddresses.test.ts +++ b/tests/integration/ethBridgeAddresses.test.ts @@ -3,7 +3,7 @@ import { expect } from 'chai' import { EthBridge, getEthBridgeInformation, - getChainNetwork as getL2Network, + getChildChain as getL2Network, } from '../../src/lib/dataEntities/networks' import dotenv from 'dotenv' dotenv.config() diff --git a/tests/integration/sendL2msg.test.ts b/tests/integration/sendL2msg.test.ts index 99b3b539a1..2fe9fc62ac 100644 --- a/tests/integration/sendL2msg.test.ts +++ b/tests/integration/sendL2msg.test.ts @@ -20,7 +20,7 @@ import { BigNumber, ethers, Signer } from 'ethers' import { InboxTools } from '../../src/lib/inbox/inbox' import { - getChainNetwork as getL2Network, + getChildChain as getL2Network, ChainNetwork as L2Network, } from '../../src/lib/dataEntities/networks' import { testSetup } from '../../scripts/testSetup' diff --git a/tests/unit/l2toL1MessageEvents.test.ts b/tests/unit/l2toL1MessageEvents.test.ts index 2921c8813f..d17bc71018 100644 --- a/tests/unit/l2toL1MessageEvents.test.ts +++ b/tests/unit/l2toL1MessageEvents.test.ts @@ -19,7 +19,7 @@ import { Logger, LogLevel } from '@ethersproject/logger' Logger.setLogLevel(LogLevel.ERROR) import { L2ToL1Message } from '../../src' -import { getChainNetwork as getL2Network } from '../../src/lib/dataEntities/networks' +import { getChildChain as getL2Network } from '../../src/lib/dataEntities/networks' import { providers } from 'ethers' import { anything, deepEqual, instance, mock, verify, when } from 'ts-mockito' diff --git a/tests/unit/multicall.test.ts b/tests/unit/multicall.test.ts index f114bbfa0b..94b8cdf22d 100644 --- a/tests/unit/multicall.test.ts +++ b/tests/unit/multicall.test.ts @@ -1,6 +1,6 @@ 'use strict' -import { getChainNetwork as getL2Network } from '../../src/lib/dataEntities/networks' +import { getChildChain as getL2Network } from '../../src/lib/dataEntities/networks' import { providers } from 'ethers' import { mock, when, anything, instance, deepEqual } from 'ts-mockito' import { expect } from 'chai' From 4cb843fa62e57bd10b78d431ca3e094edf0d82cf Mon Sep 17 00:00:00 2001 From: Doug Lance Date: Wed, 18 Oct 2023 13:33:34 -0400 Subject: [PATCH 11/12] fix integration test --- scripts/testSetup.ts | 8 ++++---- src/lib/dataEntities/networks.ts | 28 ++++++++++++++++------------ src/lib/inbox/inbox.ts | 2 +- tests/fork/inbox.test.ts | 2 +- tests/integration/sendL2msg.test.ts | 2 +- tests/integration/testHelpers.ts | 2 +- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/scripts/testSetup.ts b/scripts/testSetup.ts index 2cf3ea7f79..c3b1762844 100644 --- a/scripts/testSetup.ts +++ b/scripts/testSetup.ts @@ -25,7 +25,7 @@ import { ParentChain as L1Network, ChildChain as L2Network, getParentChain as getL1Network, - getChain as getL2Network, + getChildChain as getL2Network, addCustomNetwork, } from '../src/lib/dataEntities/networks' import { Signer } from 'ethers' @@ -171,8 +171,8 @@ export const setupNetworks = async ( } addCustomNetwork({ - customL1Network: l1Network, - customChainNetwork: l2Network, + customParentChain: l1Network, + customChildChain: l2Network, }) // also register the weth gateway @@ -245,7 +245,7 @@ export const testSetup = async (): Promise<{ } addCustomNetwork({ customParentChain: l1Network, - customChain: l2Network, + customChildChain: l2Network, }) setL1Network = l1Network setL2Network = l2Network diff --git a/src/lib/dataEntities/networks.ts b/src/lib/dataEntities/networks.ts index 620af314ae..bda1cff8af 100644 --- a/src/lib/dataEntities/networks.ts +++ b/src/lib/dataEntities/networks.ts @@ -397,10 +397,10 @@ export const getEthBridgeInformation = async ( export const addCustomNetwork = ({ customParentChain, - customChain, + customChildChain, }: { customParentChain?: ParentChain - customChain: ChildChain + customChildChain: ChildChain }): void => { if (customParentChain) { if (parentChains[customParentChain.chainID]) { @@ -416,24 +416,28 @@ export const addCustomNetwork = ({ } } - if (childChains[customChain.chainID]) - throw new ArbSdkError(`Network ${customChain.chainID} already included`) - else if (!customChain.isCustom) { + if (childChains[customChildChain.chainID]) throw new ArbSdkError( - `Custom network ${customChain.chainID} must have isCustom flag set to true` + `Network ${customChildChain.chainID} already included` + ) + else if (!customChildChain.isCustom) { + throw new ArbSdkError( + `Custom network ${customChildChain.chainID} must have isCustom flag set to true` ) } - childChains[customChain.chainID] = customChain + childChains[customChildChain.chainID] = customChildChain - const parentChainPartnerChain = parentChains[customChain.partnerChainID] + const parentChainPartnerChain = parentChains[customChildChain.partnerChainID] if (!parentChainPartnerChain) throw new ArbSdkError( - `Network ${customChain.chainID}'s partner network, ${customChain.partnerChainID}, not recognized` + `Network ${customChildChain.chainID}'s partner network, ${customChildChain.partnerChainID}, not recognized` ) - if (!parentChainPartnerChain.partnerChainIDs.includes(customChain.chainID)) { - parentChainPartnerChain.partnerChainIDs.push(customChain.chainID) + if ( + !parentChainPartnerChain.partnerChainIDs.includes(customChildChain.chainID) + ) { + parentChainPartnerChain.partnerChainIDs.push(customChildChain.chainID) } } @@ -495,7 +499,7 @@ export const addDefaultLocalNetwork = (): { addCustomNetwork({ customParentChain: defaultLocalParentChain, - customChain: defaultLocalChain, + customChildChain: defaultLocalChain, }) return { diff --git a/src/lib/inbox/inbox.ts b/src/lib/inbox/inbox.ts index 7b2abc4b71..a6093a020d 100644 --- a/src/lib/inbox/inbox.ts +++ b/src/lib/inbox/inbox.ts @@ -70,7 +70,7 @@ export class InboxTools { this.parentChain = parentChains[childChain.partnerChainID] if (!this.parentChain) throw new ArbSdkError( - `ParentChainNetwork not found for chain id: ${childChain.partnerChainID}.` + `ParentChain not found for chain id: ${childChain.partnerChainID}.` ) } diff --git a/tests/fork/inbox.test.ts b/tests/fork/inbox.test.ts index f5b0772019..7ed76a4790 100644 --- a/tests/fork/inbox.test.ts +++ b/tests/fork/inbox.test.ts @@ -31,7 +31,7 @@ import { InboxTools } from '../../src' import { ethers, network } from 'hardhat' import { hexZeroPad } from '@ethersproject/bytes' import { - ChainNetwork as L2Network, + ChildChain as L2Network, getChildChain as getL2Network, } from '../../src/lib/dataEntities/networks' import { solidityKeccak256 } from 'ethers/lib/utils' diff --git a/tests/integration/sendL2msg.test.ts b/tests/integration/sendL2msg.test.ts index 2fe9fc62ac..591d4f994c 100644 --- a/tests/integration/sendL2msg.test.ts +++ b/tests/integration/sendL2msg.test.ts @@ -21,7 +21,7 @@ import { BigNumber, ethers, Signer } from 'ethers' import { InboxTools } from '../../src/lib/inbox/inbox' import { getChildChain as getL2Network, - ChainNetwork as L2Network, + ChildChain as L2Network, } from '../../src/lib/dataEntities/networks' import { testSetup } from '../../scripts/testSetup' import { greeter } from './helper/greeter' diff --git a/tests/integration/testHelpers.ts b/tests/integration/testHelpers.ts index dc6453590f..dea1b93d19 100644 --- a/tests/integration/testHelpers.ts +++ b/tests/integration/testHelpers.ts @@ -31,7 +31,7 @@ import { L1ToL2MessageStatus, L2ToL1MessageStatus, } from '../../src' -import { ChainNetwork as L2Network } from '../../src/lib/dataEntities/networks' +import { ChildChain as L2Network } from '../../src/lib/dataEntities/networks' import { GasOverrides } from '../../src/lib/message/L1ToL2MessageGasEstimator' import { ArbSdkError } from '../../src/lib/dataEntities/errors' import { ERC20 } from '../../src/lib/abi/ERC20' From 908fa857cec68847580420ea6d664ca1abf1a029 Mon Sep 17 00:00:00 2001 From: Doug Lance Date: Mon, 23 Oct 2023 13:28:47 -0400 Subject: [PATCH 12/12] renames partner to parent/child --- scripts/instantiate_bridge.ts | 6 ++-- scripts/testSetup.ts | 4 +-- src/lib/assetBridger/assetBridger.ts | 4 +-- src/lib/dataEntities/networks.ts | 41 ++++++++++++++-------------- src/lib/inbox/inbox.ts | 4 +-- src/lib/utils/multicall.ts | 4 +-- 6 files changed, 30 insertions(+), 33 deletions(-) diff --git a/scripts/instantiate_bridge.ts b/scripts/instantiate_bridge.ts index 7d5887ef61..1c8b91ecf4 100644 --- a/scripts/instantiate_bridge.ts +++ b/scripts/instantiate_bridge.ts @@ -78,12 +78,10 @@ export const instantiateBridge = ( } const l2Network = l2Networks[l2NetworkID] - const l1Network = l1Networks[l2Network.partnerChainID] + const l1Network = l1Networks[l2Network.parentChainId] if (!l1Network) { - throw new Error( - `Unrecognised partner chain id: ${l2Network.partnerChainID}` - ) + throw new Error(`Unrecognised parent chain id: ${l2Network.parentChainId}`) } const l1Rpc = (() => { diff --git a/scripts/testSetup.ts b/scripts/testSetup.ts index c3b1762844..e53b06d0c4 100644 --- a/scripts/testSetup.ts +++ b/scripts/testSetup.ts @@ -104,7 +104,7 @@ export const getCustomNetworks = async ( explorerUrl: '', isCustom: true, name: 'EthLocal', - partnerChainIDs: [l2NetworkInfo.chainId], + childChainIds: [l2NetworkInfo.chainId], isArbitrum: false, } @@ -122,7 +122,7 @@ export const getCustomNetworks = async ( isArbitrum: true, isCustom: true, name: 'ArbLocal', - partnerChainID: l1NetworkInfo.chainId, + parentChainId: l1NetworkInfo.chainId, retryableLifetimeSeconds: 7 * 24 * 60 * 60, nitroGenesisBlock: 0, nitroGenesisL1Block: 0, diff --git a/src/lib/assetBridger/assetBridger.ts b/src/lib/assetBridger/assetBridger.ts index a46859b6db..6895b8ecb3 100644 --- a/src/lib/assetBridger/assetBridger.ts +++ b/src/lib/assetBridger/assetBridger.ts @@ -37,10 +37,10 @@ export abstract class AssetBridger { public readonly l1Network: L1Network public constructor(public readonly l2Network: L2Network) { - this.l1Network = l1Networks[l2Network.partnerChainID] + this.l1Network = l1Networks[l2Network.parentChainId] if (!this.l1Network) { throw new ArbSdkError( - `Unknown l1 network chain id: ${l2Network.partnerChainID}` + `Unknown l1 network chain id: ${l2Network.parentChainId}` ) } } diff --git a/src/lib/dataEntities/networks.ts b/src/lib/dataEntities/networks.ts index bda1cff8af..ce0bb72f41 100644 --- a/src/lib/dataEntities/networks.ts +++ b/src/lib/dataEntities/networks.ts @@ -22,7 +22,7 @@ import { SEVEN_DAYS_IN_SECONDS } from './constants' import { RollupAdminLogic__factory } from '../abi/factories/RollupAdminLogic__factory' export interface ParentChain extends Network { - partnerChainIDs: number[] + childChainIds: number[] blockTime: number //seconds isArbitrum: false } @@ -30,7 +30,7 @@ export interface ParentChain extends Network { export interface ChildChain extends Network { tokenBridge: TokenBridge ethBridge: EthBridge - partnerChainID: number + parentChainId: number isArbitrum: true confirmPeriodBlocks: number retryableLifetimeSeconds: number @@ -119,7 +119,7 @@ export const parentChains: ParentChains = { chainID: 1, name: 'Mainnet', explorerUrl: 'https://etherscan.io', - partnerChainIDs: [42161, 42170], + childChainIds: [42161, 42170], blockTime: 14, isCustom: false, isArbitrum: false, @@ -128,7 +128,7 @@ export const parentChains: ParentChains = { chainID: 1338, name: 'Hardhat_Mainnet_Fork', explorerUrl: 'https://etherscan.io', - partnerChainIDs: [42161], + childChainIds: [42161], blockTime: 1, isCustom: false, isArbitrum: false, @@ -139,14 +139,14 @@ export const parentChains: ParentChains = { explorerUrl: 'https://goerli.etherscan.io', isCustom: false, name: 'Goerli', - partnerChainIDs: [421613], + childChainIds: [421613], isArbitrum: false, }, 11155111: { chainID: 11155111, name: 'Sepolia', explorerUrl: 'https://sepolia.etherscan.io', - partnerChainIDs: [421614], + childChainIds: [421614], blockTime: 12, isCustom: false, isArbitrum: false, @@ -158,7 +158,7 @@ export const childChains: ChildChains = { chainID: 42161, name: 'Arbitrum One', explorerUrl: 'https://arbiscan.io', - partnerChainID: 1, + parentChainId: 1, isArbitrum: true, tokenBridge: mainnetTokenBridge, ethBridge: mainnetETHBridge, @@ -189,7 +189,7 @@ export const childChains: ChildChains = { isArbitrum: true, isCustom: false, name: 'Arbitrum Rollup Goerli Testnet', - partnerChainID: 5, + parentChainId: 5, tokenBridge: { l1CustomGateway: '0x9fDD1C4E4AA24EEc1d913FABea925594a20d43C7', l1ERC20Gateway: '0x715D99480b77A8d9D603638e593a539E21345FdF', @@ -228,7 +228,7 @@ export const childChains: ChildChains = { isArbitrum: true, isCustom: false, name: 'Arbitrum Nova', - partnerChainID: 1, + parentChainId: 1, retryableLifetimeSeconds: SEVEN_DAYS_IN_SECONDS, tokenBridge: { l1CustomGateway: '0x23122da8C581AA7E0d07A36Ff1f16F799650232f', @@ -269,7 +269,7 @@ export const childChains: ChildChains = { isArbitrum: true, isCustom: false, name: 'Arbitrum Rollup Sepolia Testnet', - partnerChainID: 11155111, + parentChainId: 11155111, retryableLifetimeSeconds: SEVEN_DAYS_IN_SECONDS, tokenBridge: { l1CustomGateway: '0xba2F7B6eAe1F9d174199C5E4867b563E0eaC40F3', @@ -305,7 +305,7 @@ export const childChains: ChildChains = { isArbitrum: true, isCustom: false, name: 'Stylus Testnet', - partnerChainID: 421614, + parentChainId: 421614, retryableLifetimeSeconds: SEVEN_DAYS_IN_SECONDS, tokenBridge: { l1CustomGateway: '0xd624D491A5Bc32de52a2e1481846752213bF7415', @@ -402,6 +402,7 @@ export const addCustomNetwork = ({ customParentChain?: ParentChain customChildChain: ChildChain }): void => { + console.log({ customChildChain }) if (customParentChain) { if (parentChains[customParentChain.chainID]) { throw new ArbSdkError( @@ -428,16 +429,14 @@ export const addCustomNetwork = ({ childChains[customChildChain.chainID] = customChildChain - const parentChainPartnerChain = parentChains[customChildChain.partnerChainID] - if (!parentChainPartnerChain) + const parentChainChildChain = parentChains[customChildChain.parentChainId] + if (!parentChainChildChain) throw new ArbSdkError( - `Network ${customChildChain.chainID}'s partner network, ${customChildChain.partnerChainID}, not recognized` + `Network ${customChildChain.chainID}'s parent chain, ${customChildChain.parentChainId}, not recognized` ) - if ( - !parentChainPartnerChain.partnerChainIDs.includes(customChildChain.chainID) - ) { - parentChainPartnerChain.partnerChainIDs.push(customChildChain.chainID) + if (!parentChainChildChain.childChainIds.includes(customChildChain.chainID)) { + parentChainChildChain.childChainIds.push(customChildChain.chainID) } } @@ -456,7 +455,7 @@ export const addDefaultLocalNetwork = (): { explorerUrl: '', isCustom: true, name: 'EthLocal', - partnerChainIDs: [412346], + childChainIds: [412346], isArbitrum: false, } @@ -474,7 +473,7 @@ export const addDefaultLocalNetwork = (): { isArbitrum: true, isCustom: true, name: 'ArbLocal', - partnerChainID: 1337, + parentChainId: 1337, retryableLifetimeSeconds: 604800, nitroGenesisBlock: 0, nitroGenesisL1Block: 0, @@ -511,6 +510,6 @@ export const addDefaultLocalNetwork = (): { export const isParentChain = ( network: ParentChain | ChildChain ): network is ParentChain => { - if ((network as ParentChain).partnerChainIDs) return true + if ((network as ParentChain).childChainIds) return true else return false } diff --git a/src/lib/inbox/inbox.ts b/src/lib/inbox/inbox.ts index a6093a020d..3e629b2c21 100644 --- a/src/lib/inbox/inbox.ts +++ b/src/lib/inbox/inbox.ts @@ -67,10 +67,10 @@ export class InboxTools { this.parentChainProvider = SignerProviderUtils.getProviderOrThrow( this.parentChainSigner ) - this.parentChain = parentChains[childChain.partnerChainID] + this.parentChain = parentChains[childChain.parentChainId] if (!this.parentChain) throw new ArbSdkError( - `ParentChain not found for chain id: ${childChain.partnerChainID}.` + `ParentChain not found for chain id: ${childChain.parentChainId}.` ) } diff --git a/src/lib/utils/multicall.ts b/src/lib/utils/multicall.ts index afab791d74..b100b74b85 100644 --- a/src/lib/utils/multicall.ts +++ b/src/lib/utils/multicall.ts @@ -143,10 +143,10 @@ export class MultiCaller { let multiCallAddr: string if (isL1Network(network)) { - const firstL2 = l2Networks[network.partnerChainIDs[0]] + const firstL2 = l2Networks[network.childChainIds[0]] if (!firstL2) throw new ArbSdkError( - `No partner chain found l1 network: ${network.chainID} : partner chain ids ${network.partnerChainIDs}` + `No child chain found l1 network: ${network.chainID} : child chain ids ${network.childChainIds}` ) multiCallAddr = firstL2.tokenBridge.l1MultiCall } else {