From 995f2fa4c9294c6d2526e5334a888c18a8c94a1c Mon Sep 17 00:00:00 2001 From: gzeon <95478735+gzeoneth@users.noreply.github.com> Date: Tue, 28 Mar 2023 01:30:49 +0800 Subject: [PATCH 1/6] feat: opt-in skip validation --- src/lib/assetBridger/erc20Bridger.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/assetBridger/erc20Bridger.ts b/src/lib/assetBridger/erc20Bridger.ts index 45040a7a4b..2114390bd5 100644 --- a/src/lib/assetBridger/erc20Bridger.ts +++ b/src/lib/assetBridger/erc20Bridger.ts @@ -433,12 +433,14 @@ export class Erc20Bridger extends AssetBridger< */ public async getL1ERC20Address( erc20L2Address: string, - l2Provider: Provider + l2Provider: Provider, + skipValidation = false ): Promise { await this.checkL2Network(l2Provider) const arbERC20 = L2GatewayToken__factory.connect(erc20L2Address, l2Provider) const l1Address = await arbERC20.functions.l1Address().then(([res]) => res) + if (skipValidation) return l1Address // check that this l1 address is indeed registered to this l2 token const l2GatewayRouter = L2GatewayRouter__factory.connect( From 2911e3eb7a49eea548ef9060badae6be67fd9c51 Mon Sep 17 00:00:00 2001 From: gzeon <95478735+gzeoneth@users.noreply.github.com> Date: Tue, 28 Mar 2023 01:47:48 +0800 Subject: [PATCH 2/6] feat: allow forceUseGateway --- src/lib/assetBridger/erc20Bridger.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/assetBridger/erc20Bridger.ts b/src/lib/assetBridger/erc20Bridger.ts index 2114390bd5..5a2e34b66c 100644 --- a/src/lib/assetBridger/erc20Bridger.ts +++ b/src/lib/assetBridger/erc20Bridger.ts @@ -688,7 +688,8 @@ export class Erc20Bridger extends AssetBridger< public async withdraw( params: | (OmitTyped & { l2Signer: Signer }) - | L2ToL1TxReqAndSigner + | L2ToL1TxReqAndSigner, + forceUseGateway?: string ): Promise { if (!SignerProviderUtils.signerHasProvider(params.l2Signer)) { throw new MissingProviderArbSdkError('l2Signer') @@ -703,6 +704,7 @@ export class Erc20Bridger extends AssetBridger< ...params, from: await params.l2Signer.getAddress(), }) + if (forceUseGateway) withdrawalRequest.txRequest.to = forceUseGateway const tx = await params.l2Signer.sendTransaction({ ...withdrawalRequest.txRequest, From cd1dced85a6781edeffeefa33bdcfc6d49e80f36 Mon Sep 17 00:00:00 2001 From: gzeon <95478735+gzeoneth@users.noreply.github.com> Date: Tue, 28 Mar 2023 01:57:49 +0800 Subject: [PATCH 3/6] Revert "feat: opt-in skip validation" This reverts commit 995f2fa4c9294c6d2526e5334a888c18a8c94a1c. --- src/lib/assetBridger/erc20Bridger.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib/assetBridger/erc20Bridger.ts b/src/lib/assetBridger/erc20Bridger.ts index 5a2e34b66c..cb36b09e7d 100644 --- a/src/lib/assetBridger/erc20Bridger.ts +++ b/src/lib/assetBridger/erc20Bridger.ts @@ -433,14 +433,12 @@ export class Erc20Bridger extends AssetBridger< */ public async getL1ERC20Address( erc20L2Address: string, - l2Provider: Provider, - skipValidation = false + l2Provider: Provider ): Promise { await this.checkL2Network(l2Provider) const arbERC20 = L2GatewayToken__factory.connect(erc20L2Address, l2Provider) const l1Address = await arbERC20.functions.l1Address().then(([res]) => res) - if (skipValidation) return l1Address // check that this l1 address is indeed registered to this l2 token const l2GatewayRouter = L2GatewayRouter__factory.connect( From aa9c699c8b30157d22a333820b7d9e09ac7e1e0f Mon Sep 17 00:00:00 2001 From: gzeon <95478735+gzeoneth@users.noreply.github.com> Date: Tue, 28 Mar 2023 01:58:14 +0800 Subject: [PATCH 4/6] feat: getL1ERC20AddressFromGateway --- src/lib/assetBridger/erc20Bridger.ts | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/lib/assetBridger/erc20Bridger.ts b/src/lib/assetBridger/erc20Bridger.ts index cb36b09e7d..64fd266e8c 100644 --- a/src/lib/assetBridger/erc20Bridger.ts +++ b/src/lib/assetBridger/erc20Bridger.ts @@ -456,6 +456,32 @@ export class Erc20Bridger extends AssetBridger< return l1Address } + public async getL1ERC20AddressFromGateway( + erc20L2Address: string, + l2Provider: Provider, + l2GatewayAddress: string + ): Promise { + await this.checkL2Network(l2Provider) + + const arbERC20 = L2GatewayToken__factory.connect(erc20L2Address, l2Provider) + const l1Address = await arbERC20.functions.l1Address().then(([res]) => res) + + // check that this l1 address is indeed registered to this l2 token + const l2Gateway = L2ArbitrumGateway__factory.connect( + l2GatewayAddress, + l2Provider + ) + + const l2Address = await l2Gateway.calculateL2TokenAddress(l1Address) + if (l2Address.toLowerCase() !== erc20L2Address.toLowerCase()) { + throw new ArbSdkError( + `Unexpected l1 address. L1 address from token is not registered to the provided l2 address. ${l1Address} ${l2Address} ${erc20L2Address}` + ) + } + + return l1Address + } + /** * Whether the token has been disabled on the router * @param l1TokenAddress @@ -702,7 +728,7 @@ export class Erc20Bridger extends AssetBridger< ...params, from: await params.l2Signer.getAddress(), }) - if (forceUseGateway) withdrawalRequest.txRequest.to = forceUseGateway + if (forceUseGateway) withdrawalRequest.txRequest.to = forceUseGateway const tx = await params.l2Signer.sendTransaction({ ...withdrawalRequest.txRequest, From 358818b39812a6288f40c661236d6486e5867f1d Mon Sep 17 00:00:00 2001 From: gzeon <95478735+gzeoneth@users.noreply.github.com> Date: Tue, 28 Mar 2023 02:17:18 +0800 Subject: [PATCH 5/6] refactor: code reuse --- src/lib/assetBridger/erc20Bridger.ts | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/lib/assetBridger/erc20Bridger.ts b/src/lib/assetBridger/erc20Bridger.ts index 64fd266e8c..39a39616fd 100644 --- a/src/lib/assetBridger/erc20Bridger.ts +++ b/src/lib/assetBridger/erc20Bridger.ts @@ -435,25 +435,11 @@ export class Erc20Bridger extends AssetBridger< erc20L2Address: string, l2Provider: Provider ): Promise { - await this.checkL2Network(l2Provider) - - const arbERC20 = L2GatewayToken__factory.connect(erc20L2Address, l2Provider) - const l1Address = await arbERC20.functions.l1Address().then(([res]) => res) - - // check that this l1 address is indeed registered to this l2 token - const l2GatewayRouter = L2GatewayRouter__factory.connect( - this.l2Network.tokenBridge.l2GatewayRouter, - l2Provider + return this.getL1ERC20AddressFromGateway( + erc20L2Address, + l2Provider, + this.l2Network.tokenBridge.l2GatewayRouter ) - - const l2Address = await l2GatewayRouter.calculateL2TokenAddress(l1Address) - if (l2Address.toLowerCase() !== erc20L2Address.toLowerCase()) { - throw new ArbSdkError( - `Unexpected l1 address. L1 address from token is not registered to the provided l2 address. ${l1Address} ${l2Address} ${erc20L2Address}` - ) - } - - return l1Address } public async getL1ERC20AddressFromGateway( From 5beb81e79ff07c34cc98d9407c3edff8c5aebe0c Mon Sep 17 00:00:00 2001 From: gzeon <95478735+gzeoneth@users.noreply.github.com> Date: Tue, 28 Mar 2023 17:21:38 +0800 Subject: [PATCH 6/6] v3.1.3-beta.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index acb8fe191a..e7f42b0726 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@arbitrum/sdk", - "version": "3.1.2", + "version": "3.1.3-beta.0", "description": "Typescript library client-side interactions with Arbitrum", "author": "Offchain Labs, Inc.", "license": "Apache-2.0",