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

feat: update ethers v5 utilities to ethers v6 #455

Draft
wants to merge 13 commits into
base: v4-ethers-v6
Choose a base branch
from
Next Next commit
chore: renames ParentChainTx to ParentTx and similar
  • Loading branch information
douglance committed Apr 15, 2024
commit 958560b89563eb41b21aaee8ea6a5bc16ea7facf
2 changes: 1 addition & 1 deletion scripts/deployStandard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const main = async () => {
}

/* check token not yet deployed */
const l2TokenAddress = await erc20Bridger.getL2ERC20Address(
const l2TokenAddress = await erc20Bridger.getChildERC20Address(
l1TokenAddress,
l1Provider
)
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export {
ChildToParentMessageReader,
} from './lib/message/ChildToParentMessage'
export {
ParentChainContractTransaction,
ParentChainTransactionReceipt,
ParentContractTransaction,
ParentTransactionReceipt,
} from './lib/message/ParentTransaction'
export {
ParentToChildMessageStatus,
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 @@ -18,7 +18,7 @@

import { constants } from 'ethers'

import { ParentChainContractTransaction } from '../message/ParentTransaction'
import { ParentContractTransaction } from '../message/ParentTransaction'
import { ChildContractTransaction } from '../message/ChildTransaction'

import {
Expand Down Expand Up @@ -82,7 +82,7 @@ export abstract class AssetBridger<DepositParams, WithdrawParams> {
*/
public abstract deposit(
params: DepositParams
): Promise<ParentChainContractTransaction>
): Promise<ParentContractTransaction>

/**
* Transfer assets from child-to-parent
Expand Down
66 changes: 33 additions & 33 deletions src/lib/assetBridger/erc20Bridger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ import { EventFetcher } from '../utils/eventFetcher'
import { EthDepositParams, EthWithdrawParams } from './ethBridger'
import { AssetBridger } from './assetBridger'
import {
ParentChainContractCallTransaction,
ParentChainContractTransaction,
ParentChainTransactionReceipt,
ParentContractCallTransaction,
ParentContractTransaction,
ParentTransactionReceipt,
} from '../message/ParentTransaction'
import {
ChildContractTransaction,
Expand All @@ -75,7 +75,7 @@ import { isArbitrumChain } from '../utils/lib'

export interface TokenApproveParams {
/**
* L1 address of the ERC20 token contract
* Parent chain address of the ERC20 token contract
*/
erc20ParentAddress: string
/**
Expand All @@ -94,11 +94,11 @@ export interface Erc20DepositParams extends EthDepositParams {
*/
childProvider: Provider
/**
* L1 address of the token ERC20 contract
* Parent chain address of the token ERC20 contract
*/
erc20ParentAddress: string
/**
* L2 address of the entity receiving the funds. Defaults to the l1FromAddress
* Child chain address of the entity receiving the funds. Defaults to the l1FromAddress
*/
destinationAddress?: string
/**
Expand All @@ -125,7 +125,7 @@ export interface Erc20DepositParams extends EthDepositParams {

export interface Erc20WithdrawParams extends EthWithdrawParams {
/**
* L1 address of the token ERC20 contract
* Parent chain address of the token ERC20 contract
*/
erc20ParentAddress: string
}
Expand Down Expand Up @@ -341,7 +341,7 @@ export class Erc20Bridger extends AssetBridger<
* Get the child chain events created by a withdrawal
* @param childProvider
* @param gatewayAddress
* @param parentChainTokenAddress
* @param parentTokenAddress
* @param fromAddress
* @param filter
* @returns
Expand All @@ -350,7 +350,7 @@ export class Erc20Bridger extends AssetBridger<
childProvider: Provider,
gatewayAddress: string,
filter: { fromBlock: BlockTag; toBlock: BlockTag },
parentChainTokenAddress?: string,
parentTokenAddress?: string,
fromAddress?: string,
toAddress?: string
): Promise<(EventArgs<WithdrawalInitiatedEvent> & { txHash: string })[]> {
Expand All @@ -370,11 +370,11 @@ export class Erc20Bridger extends AssetBridger<
)
).map(a => ({ txHash: a.transactionHash, ...a.event }))

return parentChainTokenAddress
return parentTokenAddress
? events.filter(
log =>
log.l1Token.toLocaleLowerCase() ===
parentChainTokenAddress.toLocaleLowerCase()
parentTokenAddress.toLocaleLowerCase()
)
: events
}
Expand Down Expand Up @@ -433,7 +433,7 @@ export class Erc20Bridger extends AssetBridger<
}

/**
* Get the L2 token contract at the provided address
* Get the child chain token contract at the provided address
* Note: This function just returns a typed ethers object for the provided address, it doesnt
* check the underlying form of the contract bytecode to see if it's an erc20, and doesn't ensure the validity
* of any of the underlying functions on that contract.
Expand All @@ -454,14 +454,14 @@ export class Erc20Bridger extends AssetBridger<
* check the underlying form of the contract bytecode to see if it's an erc20, and doesn't ensure the validity
* of any of the underlying functions on that contract.
* @param parentProvider
* @param parentChainTokenAddr
* @param parentTokenAddr
* @returns
*/
public getParentChainTokenContract(
public getParentTokenContract(
parentProvider: Provider,
parentChainTokenAddr: string
parentTokenAddr: string
): ERC20 {
return ERC20__factory.connect(parentChainTokenAddr, parentProvider)
return ERC20__factory.connect(parentTokenAddr, parentProvider)
}

/**
Expand All @@ -470,7 +470,7 @@ export class Erc20Bridger extends AssetBridger<
* @param parentProvider
* @returns
*/
public async getL2ERC20Address(
public async getChildERC20Address(
erc20ParentAddress: string,
parentProvider: Provider
): Promise<string> {
Expand All @@ -493,7 +493,7 @@ export class Erc20Bridger extends AssetBridger<
* @param childProvider
* @returns
*/
public async getL1ERC20Address(
public async getParentERC20Address(
erc20ChildChainAddress: string,
childProvider: Provider
): Promise<string> {
Expand Down Expand Up @@ -531,12 +531,12 @@ export class Erc20Bridger extends AssetBridger<

/**
* Whether the token has been disabled on the router
* @param parentChainTokenAddress
* @param parentTokenAddress
* @param parentProvider
* @returns
*/
public async parentChainTokenIsDisabled(
parentChainTokenAddress: string,
public async parentTokenIsDisabled(
parentTokenAddress: string,
parentProvider: Provider
): Promise<boolean> {
await this.checkParentChain(parentProvider)
Expand All @@ -547,7 +547,7 @@ export class Erc20Bridger extends AssetBridger<
)

return (
(await l1GatewayRouter.l1TokenToGateway(parentChainTokenAddress)) ===
(await l1GatewayRouter.l1TokenToGateway(parentTokenAddress)) ===
DISABLED_GATEWAY
)
}
Expand Down Expand Up @@ -733,7 +733,7 @@ export class Erc20Bridger extends AssetBridger<
*/
public async deposit(
params: Erc20DepositParams | ParentToChildTxReqAndSignerProvider
): Promise<ParentChainContractCallTransaction> {
): Promise<ParentContractCallTransaction> {
await this.checkParentChain(params.parentSigner)

// Although the types prevent should alert callers that value is not
Expand Down Expand Up @@ -762,7 +762,7 @@ export class Erc20Bridger extends AssetBridger<
...params.overrides,
})

return ParentChainTransactionReceipt.monkeyPatchContractCallWait(tx)
return ParentTransactionReceipt.monkeyPatchContractCallWait(tx)
}

/**
Expand Down Expand Up @@ -875,18 +875,18 @@ export class AdminErc20Bridger extends Erc20Bridger {
/**
* Register a custom token on the Arbitrum bridge
* See https://developer.offchainlabs.com/docs/bridging_assets#the-arbitrum-generic-custom-gateway for more details
* @param parentChainTokenAddress Address of the already deployed l1 token. Must inherit from https://developer.offchainlabs.com/docs/sol_contract_docs/md_docs/arb-bridge-peripherals/tokenbridge/ethereum/icustomtoken.
* @param parentTokenAddress Address of the already deployed l1 token. Must inherit from https://developer.offchainlabs.com/docs/sol_contract_docs/md_docs/arb-bridge-peripherals/tokenbridge/ethereum/icustomtoken.
* @param l2TokenAddress Address of the already deployed l2 token. Must inherit from https://developer.offchainlabs.com/docs/sol_contract_docs/md_docs/arb-bridge-peripherals/tokenbridge/arbitrum/iarbtoken.
* @param parentSigner The signer with the rights to call registerTokenOnL2 on the l1 token
* @param childProvider Arbitrum rpc provider
* @returns
*/
public async registerCustomToken(
parentChainTokenAddress: string,
parentTokenAddress: string,
l2TokenAddress: string,
parentSigner: Signer,
childProvider: Provider
): Promise<ParentChainContractTransaction> {
): Promise<ParentContractTransaction> {
if (!SignerProviderUtils.signerHasProvider(parentSigner)) {
throw new MissingProviderArbSdkError('parentSigner')
}
Expand All @@ -896,7 +896,7 @@ export class AdminErc20Bridger extends Erc20Bridger {
const l1SenderAddress = await parentSigner.getAddress()

const l1Token = ICustomToken__factory.connect(
parentChainTokenAddress,
parentTokenAddress,
parentSigner
)
const l2Token = IArbToken__factory.connect(l2TokenAddress, childProvider)
Expand All @@ -906,9 +906,9 @@ export class AdminErc20Bridger extends Erc20Bridger {
await l2Token.deployed()

const l1AddressFromL2 = await l2Token.l1Address()
if (l1AddressFromL2 !== parentChainTokenAddress) {
if (l1AddressFromL2 !== parentTokenAddress) {
throw new ArbSdkError(
`L2 token does not have l1 address set. Set address: ${l1AddressFromL2}, expected address: ${parentChainTokenAddress}.`
`L2 token does not have l1 address set. Set address: ${l1AddressFromL2}, expected address: ${parentTokenAddress}.`
)
}

Expand Down Expand Up @@ -997,7 +997,7 @@ export class AdminErc20Bridger extends Erc20Bridger {
value: setGatewayEstimates2.value,
})

return ParentChainTransactionReceipt.monkeyPatchWait(registerTx)
return ParentTransactionReceipt.monkeyPatchWait(registerTx)
}

/**
Expand Down Expand Up @@ -1067,7 +1067,7 @@ export class AdminErc20Bridger extends Erc20Bridger {
childProvider: Provider,
tokenGateways: TokenAndGateway[],
options?: GasOverrides
): Promise<ParentChainContractCallTransaction> {
): Promise<ParentContractCallTransaction> {
if (!SignerProviderUtils.signerHasProvider(parentSigner)) {
throw new MissingProviderArbSdkError('parentSigner')
}
Expand Down Expand Up @@ -1112,6 +1112,6 @@ export class AdminErc20Bridger extends Erc20Bridger {
value: estimates.estimates.deposit,
})

return ParentChainTransactionReceipt.monkeyPatchContractCallWait(res)
return ParentTransactionReceipt.monkeyPatchContractCallWait(res)
}
}
20 changes: 10 additions & 10 deletions src/lib/assetBridger/ethBridger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import { ArbSys__factory } from '../abi/factories/ArbSys__factory'
import { ARB_SYS_ADDRESS } from '../dataEntities/constants'
import { AssetBridger } from './assetBridger'
import {
ParentChainEthDepositTransaction,
ParentChainContractCallTransaction,
ParentChainTransactionReceipt,
ParentEthDepositTransaction,
ParentContractCallTransaction,
ParentTransactionReceipt,
} from '../message/ParentTransaction'
import {
ChildContractTransaction,
Expand Down Expand Up @@ -76,7 +76,7 @@ export type ApproveGasTokenParamsOrTxRequest =
| ApproveGasTokenParams
| ApproveGasTokenTxRequest

type WithL1Signer<T extends ApproveGasTokenParamsOrTxRequest> = T & {
type WithParentSigner<T extends ApproveGasTokenParamsOrTxRequest> = T & {
parentSigner: Signer
}

Expand Down Expand Up @@ -180,7 +180,7 @@ export class EthBridger extends AssetBridger<
*/
private isApproveGasTokenParams(
params: ApproveGasTokenParamsOrTxRequest
): params is WithL1Signer<ApproveGasTokenParams> {
): params is WithParentSigner<ApproveGasTokenParams> {
return typeof (params as ApproveGasTokenTxRequest).txRequest === 'undefined'
}

Expand Down Expand Up @@ -217,7 +217,7 @@ export class EthBridger extends AssetBridger<
* @param params
*/
public async approveGasToken(
params: WithL1Signer<ApproveGasTokenParamsOrTxRequest>
params: WithParentSigner<ApproveGasTokenParamsOrTxRequest>
) {
if (this.nativeTokenIsEth) {
throw new Error('chain uses ETH as its native/gas token')
Expand Down Expand Up @@ -286,7 +286,7 @@ export class EthBridger extends AssetBridger<
*/
public async deposit(
params: EthDepositParams | ParentToChildTxReqAndSigner
): Promise<ParentChainEthDepositTransaction> {
): Promise<ParentEthDepositTransaction> {
await this.checkParentChain(params.parentSigner)

const ethDeposit = isParentToChildTransactionRequest(params)
Expand All @@ -301,7 +301,7 @@ export class EthBridger extends AssetBridger<
...params.overrides,
})

return ParentChainTransactionReceipt.monkeyPatchEthDepositWait(tx)
return ParentTransactionReceipt.monkeyPatchEthDepositWait(tx)
}

/**
Expand Down Expand Up @@ -340,7 +340,7 @@ export class EthBridger extends AssetBridger<
params:
| EthDepositToParams
| (ParentToChildTxReqAndSigner & { childProvider: Provider })
): Promise<ParentChainContractCallTransaction> {
): Promise<ParentContractCallTransaction> {
await this.checkParentChain(params.parentSigner)
await this.checkChildChain(params.childProvider)

Expand All @@ -357,7 +357,7 @@ export class EthBridger extends AssetBridger<
...params.overrides,
})

return ParentChainTransactionReceipt.monkeyPatchContractCallWait(tx)
return ParentTransactionReceipt.monkeyPatchContractCallWait(tx)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/lib/message/ChildToParentMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export class ChildToParentMessageReader extends ChildToParentMessage {
public async status(
childChainProvider: Provider
): Promise<ChildToParentMessageStatus> {
// can we create an ChildToParentmessage here, we need to - the constructor is what we need
// can we create a ChildToParentMessage here, we need to - the constructor is what we need
if (this.nitroReader)
return await this.nitroReader.status(childChainProvider)
else return await this.classicReader!.status(childChainProvider)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/message/ChildToParentMessageNitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export type ChildToParentChainMessageReaderOrWriterNitro<

// expected number of parent chain blocks that it takes for a Child chain tx to be included in a parent chain assertion
const ASSERTION_CREATED_PADDING = 50
// expected number of parent chain blocks that it takes for a validator to confirm an parent chain block after the node deadline is passed
// expected number of parent chain blocks that it takes for a validator to confirm a parent chain block after the node deadline is passed
const ASSERTION_CONFIRMED_PADDING = 20

const childChainBlockRangeCache: { [key in string]: (number | undefined)[] } =
Expand Down
2 changes: 1 addition & 1 deletion src/lib/message/ChildTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class ChildTransactionReceipt implements TransactionReceipt {
}

/**
* Get an ChildToParentTxEvent events created by this transaction
* Get {@link ChildToParentTransactionEvent} events created by this transaction
* @returns
*/
public getChildToParentEvents(): ChildToParentTransactionEvent[] {
Expand Down
Loading