Skip to content

Commit

Permalink
change checkParentChain/checkChildChain to network
Browse files Browse the repository at this point in the history
  • Loading branch information
douglance committed Jul 10, 2024
1 parent 8b9938b commit 4986158
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/lib/assetBridger/assetBridger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ export abstract class AssetBridger<DepositParams, WithdrawParams> {
}

/**
* Check the signer/provider matches the parentChain, throws if not
* Check the signer/provider matches the parent network, throws if not
* @param sop
*/
protected async checkParentChain(sop: SignerOrProvider): Promise<void> {
protected async checkParentNetwork(sop: SignerOrProvider): Promise<void> {
await SignerProviderUtils.checkNetworkMatches(
sop,
this.childNetwork.parentChainId
)
}

/**
* Check the signer/provider matches the childNetwork, throws if not
* Check the signer/provider matches the child network, throws if not
* @param sop
*/
protected async checkChildChain(sop: SignerOrProvider): Promise<void> {
protected async checkChildNetwork(sop: SignerOrProvider): Promise<void> {
await SignerProviderUtils.checkNetworkMatches(
sop,
this.childNetwork.chainId
Expand Down
38 changes: 19 additions & 19 deletions src/lib/assetBridger/erc20Bridger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class Erc20Bridger extends AssetBridger<
erc20ParentAddress: string,
parentProvider: Provider
): Promise<string> {
await this.checkParentChain(parentProvider)
await this.checkParentNetwork(parentProvider)

return await L1GatewayRouter__factory.connect(
this.childNetwork.tokenBridge.parentGatewayRouter,
Expand All @@ -241,7 +241,7 @@ export class Erc20Bridger extends AssetBridger<
erc20ParentAddress: string,
childProvider: Provider
): Promise<string> {
await this.checkChildChain(childProvider)
await this.checkChildNetwork(childProvider)

return await L2GatewayRouter__factory.connect(
this.childNetwork.tokenBridge.childGatewayRouter,
Expand Down Expand Up @@ -276,7 +276,7 @@ export class Erc20Bridger extends AssetBridger<
throw new Error('chain uses ETH as its native/gas token')
}

await this.checkParentChain(params.parentSigner)
await this.checkParentNetwork(params.parentSigner)

const approveGasTokenRequest = this.isApproveParams(params)
? await this.getApproveGasTokenRequest({
Expand Down Expand Up @@ -335,7 +335,7 @@ export class Erc20Bridger extends AssetBridger<
public async approveToken(
params: ApproveParamsOrTxRequest
): Promise<ethers.ContractTransaction> {
await this.checkParentChain(params.parentSigner)
await this.checkParentNetwork(params.parentSigner)

const approveRequest = this.isApproveParams(params)
? await this.getApproveTokenRequest({
Expand Down Expand Up @@ -368,7 +368,7 @@ export class Erc20Bridger extends AssetBridger<
fromAddress?: string,
toAddress?: string
): Promise<(EventArgs<WithdrawalInitiatedEvent> & { txHash: string })[]> {
await this.checkChildChain(childProvider)
await this.checkChildNetwork(childProvider)

const eventFetcher = new EventFetcher(childProvider)
const events = (
Expand Down Expand Up @@ -488,7 +488,7 @@ export class Erc20Bridger extends AssetBridger<
erc20ParentAddress: string,
parentProvider: Provider
): Promise<string> {
await this.checkParentChain(parentProvider)
await this.checkParentNetwork(parentProvider)

const parentGatewayRouter = L1GatewayRouter__factory.connect(
this.childNetwork.tokenBridge.parentGatewayRouter,
Expand All @@ -511,7 +511,7 @@ export class Erc20Bridger extends AssetBridger<
erc20ChildChainAddress: string,
childProvider: Provider
): Promise<string> {
await this.checkChildChain(childProvider)
await this.checkChildNetwork(childProvider)

// child network WETH contract doesn't have the parentAddress method on it
if (
Expand Down Expand Up @@ -557,7 +557,7 @@ export class Erc20Bridger extends AssetBridger<
parentTokenAddress: string,
parentProvider: Provider
): Promise<boolean> {
await this.checkParentChain(parentProvider)
await this.checkParentNetwork(parentProvider)

const parentGatewayRouter = L1GatewayRouter__factory.connect(
this.childNetwork.tokenBridge.parentGatewayRouter,
Expand Down Expand Up @@ -647,8 +647,8 @@ export class Erc20Bridger extends AssetBridger<
public async getDepositRequest(
params: DepositRequest
): Promise<ParentToChildTransactionRequest> {
await this.checkParentChain(params.parentProvider)
await this.checkChildChain(params.childProvider)
await this.checkParentNetwork(params.parentProvider)
await this.checkChildNetwork(params.childProvider)
const defaultedParams = this.applyDefaults(params)
const {
amount,
Expand Down Expand Up @@ -754,7 +754,7 @@ export class Erc20Bridger extends AssetBridger<
public async deposit(
params: Erc20DepositParams | ParentToChildTxReqAndSignerProvider
): Promise<ParentContractCallTransaction> {
await this.checkParentChain(params.parentSigner)
await this.checkParentNetwork(params.parentSigner)

// Although the types prevent should alert callers that value is not
// a valid override, it is possible that they pass it in anyway as it's a common override
Expand Down Expand Up @@ -879,7 +879,7 @@ export class Erc20Bridger extends AssetBridger<
if (!SignerProviderUtils.signerHasProvider(params.childSigner)) {
throw new MissingProviderArbSdkError('childSigner')
}
await this.checkChildChain(params.childSigner)
await this.checkChildNetwork(params.childSigner)

const withdrawalRequest = isChildToParentTransactionRequest<
OmitTyped<Erc20WithdrawParams, 'from'> & { childSigner: Signer }
Expand Down Expand Up @@ -989,7 +989,7 @@ export class AdminErc20Bridger extends Erc20Bridger {
throw new Error('chain uses ETH as its native/gas token')
}

await this.checkParentChain(params.parentSigner)
await this.checkParentNetwork(params.parentSigner)

const approveGasTokenRequest = this.isApproveParams(params)
? this.getApproveGasTokenForCustomTokenRegistrationRequest({
Expand Down Expand Up @@ -1024,8 +1024,8 @@ export class AdminErc20Bridger extends Erc20Bridger {
if (!SignerProviderUtils.signerHasProvider(parentSigner)) {
throw new MissingProviderArbSdkError('parentSigner')
}
await this.checkParentChain(parentSigner)
await this.checkChildChain(childProvider)
await this.checkParentNetwork(parentSigner)
await this.checkChildNetwork(childProvider)

const parentProvider = parentSigner.provider!
const parentSenderAddress = await parentSigner.getAddress()
Expand Down Expand Up @@ -1178,7 +1178,7 @@ export class AdminErc20Bridger extends Erc20Bridger {
parentProvider: Provider,
filter: { fromBlock: BlockTag; toBlock: BlockTag }
): Promise<EventArgs<GatewaySetEvent>[]> {
await this.checkParentChain(parentProvider)
await this.checkParentNetwork(parentProvider)

const parentGatewayRouterAddress =
this.childNetwork.tokenBridge.parentGatewayRouter
Expand Down Expand Up @@ -1208,7 +1208,7 @@ export class AdminErc20Bridger extends Erc20Bridger {
'Must supply customNetworkL2GatewayRouter for custom network '
)
}
await this.checkChildChain(childProvider)
await this.checkChildNetwork(childProvider)

const childGatewayRouterAddress =
customNetworkL2GatewayRouter ||
Expand Down Expand Up @@ -1240,8 +1240,8 @@ export class AdminErc20Bridger extends Erc20Bridger {
if (!SignerProviderUtils.signerHasProvider(parentSigner)) {
throw new MissingProviderArbSdkError('parentSigner')
}
await this.checkParentChain(parentSigner)
await this.checkChildChain(childProvider)
await this.checkParentNetwork(parentSigner)
await this.checkChildNetwork(childProvider)

const from = await parentSigner.getAddress()

Expand Down
8 changes: 4 additions & 4 deletions src/lib/assetBridger/ethBridger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export class EthBridger extends AssetBridger<
public async deposit(
params: EthDepositParams | ParentToChildTxReqAndSigner
): Promise<ParentEthDepositTransaction> {
await this.checkParentChain(params.parentSigner)
await this.checkParentNetwork(params.parentSigner)

const ethDeposit = isParentToChildTransactionRequest(params)
? params
Expand Down Expand Up @@ -341,8 +341,8 @@ export class EthBridger extends AssetBridger<
| EthDepositToParams
| (ParentToChildTxReqAndSigner & { childProvider: Provider })
): Promise<ParentContractCallTransaction> {
await this.checkParentChain(params.parentSigner)
await this.checkChildChain(params.childProvider)
await this.checkParentNetwork(params.parentSigner)
await this.checkChildNetwork(params.childProvider)

const retryableTicketRequest = isParentToChildTransactionRequest(params)
? params
Expand Down Expand Up @@ -413,7 +413,7 @@ export class EthBridger extends AssetBridger<
if (!SignerProviderUtils.signerHasProvider(params.childSigner)) {
throw new MissingProviderArbSdkError('childSigner')
}
await this.checkChildChain(params.childSigner)
await this.checkChildNetwork(params.childSigner)

const request = isChildToParentTransactionRequest<
EthWithdrawParams & { childSigner: Signer }
Expand Down

0 comments on commit 4986158

Please sign in to comment.