From 479adfd6277b1cb2aac63834cbfaa1023882d29e Mon Sep 17 00:00:00 2001 From: Paul <108695806+pxrl@users.noreply.github.com> Date: Thu, 16 May 2024 19:04:25 +0200 Subject: [PATCH 1/2] refactor(TokenClient): Skip token resolution on HubChain There's no need to query the HubPoolClient for L2 token addresses when the target chain is the hub chain itself. Also, remove a redundant Promise.all(). --- src/clients/TokenClient.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/clients/TokenClient.ts b/src/clients/TokenClient.ts index 9d919855d..62b58be0c 100644 --- a/src/clients/TokenClient.ts +++ b/src/clients/TokenClient.ts @@ -174,6 +174,10 @@ export class TokenClient { resolveRemoteTokens(chainId: number, hubPoolTokens: L1Token[]): Contract[] { const { signer } = this.hubPoolClient.hubPool; + if (chainId === this.hubPoolClient.chainId) { + return hubPoolTokens.map(({ address }) => new Contract(address, ERC20.abi, signer)); + } + const tokens = hubPoolTokens .map(({ symbol, address }) => { let tokenAddrs: string[] = []; @@ -282,13 +286,11 @@ export class TokenClient { const { relayerAddress } = this; const tokenData = Object.fromEntries( - await Promise.all( - await sdkUtils.mapAsync(this.resolveRemoteTokens(chainId, hubPoolTokens), async (token: Contract) => { - const balance: BigNumber = await token.balanceOf(relayerAddress); - const allowance = await this._getAllowance(spokePoolClient, token); - return [token.address, { balance, allowance }]; - }) - ) + await sdkUtils.mapAsync(this.resolveRemoteTokens(chainId, hubPoolTokens), async (token: Contract) => { + const balance: BigNumber = await token.balanceOf(relayerAddress); + const allowance = await this._getAllowance(spokePoolClient, token); + return [token.address, { balance, allowance }]; + }) ); return tokenData; From 2073a4df0fa63895831d6dcdb797fc8feb4268ab Mon Sep 17 00:00:00 2001 From: Paul <108695806+pxrl@users.noreply.github.com> Date: Thu, 16 May 2024 19:21:14 +0200 Subject: [PATCH 2/2] Use correct signer --- src/clients/TokenClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clients/TokenClient.ts b/src/clients/TokenClient.ts index 62b58be0c..dee189cb2 100644 --- a/src/clients/TokenClient.ts +++ b/src/clients/TokenClient.ts @@ -172,7 +172,7 @@ export class TokenClient { } resolveRemoteTokens(chainId: number, hubPoolTokens: L1Token[]): Contract[] { - const { signer } = this.hubPoolClient.hubPool; + const { signer } = this.spokePoolClients[chainId].spokePool; if (chainId === this.hubPoolClient.chainId) { return hubPoolTokens.map(({ address }) => new Contract(address, ERC20.abi, signer));