Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: renames L1ToL2Message to parentChain/Chain #344

Merged
merged 13 commits into from
Dec 4, 2023
32 changes: 16 additions & 16 deletions scripts/testSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import { Wallet } from '@ethersproject/wallet'
import dotenv from 'dotenv'
import { EthBridger, InboxTools, Erc20Bridger } from '../src'
import {
ParentChain as L1Network,
ChildChain as L2Network,
getParentChain as getL1Network,
getChildChain as getL2Network,
ParentChain,
ChildChain,
getParentChain,
getChildChain,
addCustomNetwork,
} from '../src/lib/dataEntities/networks'
import { Signer } from 'ethers'
Expand Down Expand Up @@ -70,8 +70,8 @@ export const getCustomNetworks = async (
l1Url: string,
l2Url: string
): Promise<{
l1Network: L1Network
l2Network: Omit<L2Network, 'tokenBridge'>
l1Network: ParentChain
Copy link
Contributor

Choose a reason for hiding this comment

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

should we rename the vars too - parentChain and childChain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should. I think we should do that in a separate PR because that will change ~200 uses in the test files.

l2Network: Omit<ChildChain, 'tokenBridge'>
}> => {
const l1Provider = new JsonRpcProvider(l1Url)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we rename these inner vars too - eg childProvider, childNetworkInfo etc. I guess the general pattern is just get rid of l1/l2 everywhere. So my comments are the same for this throughout.

Copy link
Contributor Author

@douglance douglance Dec 4, 2023

Choose a reason for hiding this comment

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

I'll change those in a future PR because they're exported out of this function and used in the tests.

const l2Provider = new JsonRpcProvider(l2Url)
Expand All @@ -98,7 +98,7 @@ export const getCustomNetworks = async (
const l1NetworkInfo = await l1Provider.getNetwork()
const l2NetworkInfo = await l2Provider.getNetwork()

const l1Network: L1Network = {
const l1Network: ParentChain = {
blockTime: 10,
chainID: l1NetworkInfo.chainId,
explorerUrl: '',
Expand All @@ -108,7 +108,7 @@ export const getCustomNetworks = async (
isArbitrum: false,
}

const l2Network: Omit<L2Network, 'tokenBridge'> = {
const l2Network: Omit<ChildChain, 'tokenBridge'> = {
chainID: l2NetworkInfo.chainId,
confirmPeriodBlocks: confirmPeriodBlocks.toNumber(),
ethBridge: {
Expand Down Expand Up @@ -149,7 +149,7 @@ export const setupNetworks = async (
l2Deployer,
coreL2Network.ethBridge.inbox
)
const l2Network: L2Network = {
const l2Network: ChildChain = {
...coreL2Network,
tokenBridge: {
l1CustomGateway: l1Contracts.customGateway.address,
Expand Down Expand Up @@ -204,8 +204,8 @@ export const getSigner = (provider: JsonRpcProvider, key?: string) => {
}

export const testSetup = async (): Promise<{
l1Network: L1Network
l2Network: L2Network
l1Network: ParentChain
l2Network: ChildChain
l1Signer: Signer
l2Signer: Signer
erc20Bridger: Erc20Bridger
Expand All @@ -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: ParentChain, setL2Network: ChildChain
try {
const l1Network = await getL1Network(l1Deployer)
const l2Network = await getL2Network(l2Deployer)
const l1Network = await getParentChain(l1Deployer)
const l2Network = await getChildChain(l2Deployer)
setL1Network = l1Network
setL2Network = l2Network
} catch (err) {
Expand All @@ -240,8 +240,8 @@ export const testSetup = async (): Promise<{
const { l1Network, l2Network } = JSON.parse(
fs.readFileSync(localNetworkFile).toString()
) as {
l1Network: L1Network
l2Network: L2Network
l1Network: ParentChain
l2Network: ChildChain
}
addCustomNetwork({
customParentChain: l1Network,
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export {
L1TransactionReceipt,
} from './lib/message/L1Transaction'
export {
L1ToL2MessageStatus,
ParentToChildMessageStatus as L1ToL2MessageStatus,
EthDepositStatus,
L1ToL2Message,
L1ToL2MessageReader,
L1ToL2MessageReaderClassic,
L1ToL2MessageWriter,
ParentToChildMessage as L1ToL2Message,
ParentToChildMessageReader as L1ToL2MessageReader,
ParentToChildMessageReaderClassic as L1ToL2MessageReaderClassic,
ParentToChildMessageWriter as L1ToL2MessageWriter,
} from './lib/message/L1ToL2Message'
export { L1ToL2MessageGasEstimator } from './lib/message/L1ToL2MessageGasEstimator'
export { argSerializerConstructor } from './lib/utils/byte_serialize_params'
Expand Down
4 changes: 2 additions & 2 deletions src/lib/assetBridger/assetBridger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { L2ContractTransaction } from '../message/L2Transaction'

import {
parentChains as l1Networks,
ParentChain as L1Network,
ChildChain as L2Network,
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these renamings happening in another PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes sir. All the import as assertions created in these PRs.

ParentChain,
} from '../dataEntities/networks'
import {
SignerOrProvider,
Expand All @@ -34,7 +34,7 @@ import {
* Base for bridging assets from l1 to l2 and back
*/
export abstract class AssetBridger<DepositParams, WithdrawParams> {
public readonly l1Network: L1Network
public readonly l1Network: ParentChain

public constructor(public readonly l2Network: L2Network) {
this.l1Network = l1Networks[l2Network.parentChainId]
Expand Down
9 changes: 3 additions & 6 deletions src/lib/assetBridger/erc20Bridger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ import {
L1ToL2MessageGasEstimator,
} from '../message/L1ToL2MessageGasEstimator'
import { SignerProviderUtils } from '../dataEntities/signerOrProvider'
import {
ChildChain as L2Network,
getChildChain as getL2Network,
} from '../dataEntities/networks'
import { ChildChain, getChildChain } from '../dataEntities/networks'
import { ArbSdkError, MissingProviderArbSdkError } from '../dataEntities/errors'
import { DISABLED_GATEWAY } from '../dataEntities/constants'
import { EventFetcher } from '../utils/eventFetcher'
Expand Down Expand Up @@ -181,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: ChildChain) {
super(l2Network)
}

Expand All @@ -191,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 getChildChain(l2Provider))
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/lib/assetBridger/ethBridger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
import { OmitTyped } from '../utils/types'
import { SignerProviderUtils } from '../dataEntities/signerOrProvider'
import { MissingProviderArbSdkError } from '../dataEntities/errors'
import { getChildChain as getL2Network } from '../dataEntities/networks'
import { getChildChain } from '../dataEntities/networks'

export interface EthWithdrawParams {
/**
Expand Down Expand Up @@ -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 getChildChain(l2Provider))
}

/**
Expand Down
16 changes: 15 additions & 1 deletion src/lib/dataEntities/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,18 @@ export const addCustomNetwork = ({
customParentChain?: ParentChain
customChildChain: ChildChain
}): void => {
console.log({ customChildChain })
//@ts-expect-error - Nitro returns this value with partnerChainID
if (customChildChain.partnerChainID) {
//@ts-expect-error - Nitro returns this value with partnerChainID
customChildChain.parentChainId = customChildChain.partnerChainID
}

//@ts-expect-error - Nitro returns this value with partnerChainID
if (customParentChain.partnerChainIDs?.length > 0) {
//@ts-expect-error - Nitro returns this value with partnerChainID
customParentChain.childChainIds = customParentChain.partnerChainIDs
}

if (customParentChain) {
if (parentChains[customParentChain.chainID]) {
throw new ArbSdkError(
Expand All @@ -429,11 +440,14 @@ export const addCustomNetwork = ({

childChains[customChildChain.chainID] = customChildChain

console.log({ customChildChain })

const parentChainChildChain = parentChains[customChildChain.parentChainId]
if (!parentChainChildChain)
throw new ArbSdkError(
`Network ${customChildChain.chainID}'s parent chain, ${customChildChain.parentChainId}, not recognized`
)
console.log({ parentChainChildChain })

if (!parentChainChildChain.childChainIds.includes(customChildChain.chainID)) {
parentChainChildChain.childChainIds.push(customChildChain.chainID)
Expand Down
Loading