diff --git a/src/dataworker/DataworkerUtils.ts b/src/dataworker/DataworkerUtils.ts index ecd47dda3..82d6b3cab 100644 --- a/src/dataworker/DataworkerUtils.ts +++ b/src/dataworker/DataworkerUtils.ts @@ -343,7 +343,11 @@ export function _buildRelayerRefundRoot( return; } - const l2TokenCounterpart = clients.hubPoolClient.getL2TokenForL1TokenAtBlock(leaf.l1Tokens[index], leaf.chainId); + const l2TokenCounterpart = clients.hubPoolClient.getL2TokenForL1TokenAtBlock( + leaf.l1Tokens[index], + leaf.chainId, + endBlockForMainnet + ); // If we've already seen this leaf, then skip. const existingLeaf = relayerRefundLeaves.find( (relayerRefundLeaf) => @@ -420,7 +424,7 @@ export async function _buildPoolRebalanceRoot( const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock( l2TokenAddress, repaymentChainId, - latestMainnetBlock + mainnetBundleEndBlock ); updateRunningBalance(runningBalances, repaymentChainId, l1TokenCounterpart, totalRefundAmount); @@ -443,7 +447,7 @@ export async function _buildPoolRebalanceRoot( const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock( outputToken, destinationChainId, - latestMainnetBlock + mainnetBundleEndBlock ); const lpFee = deposit.lpFeePct.mul(deposit.inputAmount).div(fixedPointAdjustment); updateRunningBalance(runningBalances, destinationChainId, l1TokenCounterpart, deposit.inputAmount.sub(lpFee)); @@ -467,7 +471,7 @@ export async function _buildPoolRebalanceRoot( const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock( outputToken, destinationChainId, - latestMainnetBlock + mainnetBundleEndBlock ); const lpFee = deposit.lpFeePct.mul(deposit.inputAmount).div(fixedPointAdjustment); updateRunningBalance(runningBalances, destinationChainId, l1TokenCounterpart, lpFee.sub(deposit.inputAmount)); @@ -503,7 +507,7 @@ export async function _buildPoolRebalanceRoot( const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock( inputToken, originChainId, - latestMainnetBlock + mainnetBundleEndBlock ); updateRunningBalance(runningBalances, originChainId, l1TokenCounterpart, deposit.inputAmount); }); diff --git a/src/finalizer/utils/arbitrum.ts b/src/finalizer/utils/arbitrum.ts index 52aa72343..2f7e178d6 100644 --- a/src/finalizer/utils/arbitrum.ts +++ b/src/finalizer/utils/arbitrum.ts @@ -10,6 +10,7 @@ import { getCurrentTime, getRedisCache, getBlockForTimestamp, + getL1TokenInfo, } from "../../utils"; import { TokensBridged } from "../../interfaces"; import { HubPoolClient, SpokePoolClient } from "../../clients"; @@ -55,12 +56,7 @@ async function multicallArbitrumFinalizations( const finalizableMessages = await getFinalizableMessages(logger, tokensBridged, hubSigner); const callData = await Promise.all(finalizableMessages.map((message) => finalizeArbitrum(message.message))); const crossChainTransfers = finalizableMessages.map(({ info: { l2TokenAddress, amountToReturn } }) => { - const l1TokenCounterpart = hubPoolClient.getL1TokenForL2TokenAtBlock( - l2TokenAddress, - CHAIN_ID, - hubPoolClient.latestBlockSearched - ); - const l1TokenInfo = hubPoolClient.getTokenInfo(1, l1TokenCounterpart); + const l1TokenInfo = getL1TokenInfo(l2TokenAddress, CHAIN_ID); const amountFromWei = convertFromWei(amountToReturn.toString(), l1TokenInfo.decimals); const withdrawal: CrossChainMessage = { originationChainId: CHAIN_ID, diff --git a/src/finalizer/utils/linea/l2ToL1.ts b/src/finalizer/utils/linea/l2ToL1.ts index c4d68c4f9..f5affc139 100644 --- a/src/finalizer/utils/linea/l2ToL1.ts +++ b/src/finalizer/utils/linea/l2ToL1.ts @@ -3,7 +3,7 @@ import { Wallet } from "ethers"; import { groupBy } from "lodash"; import { HubPoolClient, SpokePoolClient } from "../../../clients"; -import { Signer, winston, convertFromWei } from "../../../utils"; +import { Signer, winston, convertFromWei, getL1TokenInfo } from "../../../utils"; import { FinalizerPromise, CrossChainMessage } from "../../types"; import { TokensBridged } from "../../../interfaces"; import { @@ -103,12 +103,7 @@ export async function lineaL2ToL1Finalizer( // Populate cross chain transfers for claimed messages const transfers = claimable.map(({ tokensBridged }) => { const { l2TokenAddress, amountToReturn } = tokensBridged; - const l1TokenCounterpart = hubPoolClient.getL1TokenForL2TokenAtBlock( - l2TokenAddress, - l2ChainId, - hubPoolClient.latestBlockSearched - ); - const { decimals, symbol: l1TokenSymbol } = hubPoolClient.getTokenInfo(l1ChainId, l1TokenCounterpart); + const { decimals, symbol: l1TokenSymbol } = getL1TokenInfo(l2TokenAddress, l2ChainId); const amountFromWei = convertFromWei(amountToReturn.toString(), decimals); const transfer: CrossChainMessage = { originationChainId: l2ChainId, diff --git a/src/finalizer/utils/opStack.ts b/src/finalizer/utils/opStack.ts index fc24f91fd..414adcbcb 100644 --- a/src/finalizer/utils/opStack.ts +++ b/src/finalizer/utils/opStack.ts @@ -2,7 +2,7 @@ import assert from "assert"; import { groupBy } from "lodash"; import * as optimismSDK from "@eth-optimism/sdk"; import { HubPoolClient, SpokePoolClient } from "../../clients"; -import { L1Token, TokensBridged } from "../../interfaces"; +import { TokensBridged } from "../../interfaces"; import { BigNumber, chainIsOPStack, @@ -10,6 +10,7 @@ import { getBlockForTimestamp, getCachedProvider, getCurrentTime, + getL1TokenInfo, getNetworkName, getRedisCache, getUniqueLogIndex, @@ -217,13 +218,6 @@ async function getOptimismFinalizableMessages( ); } -function getL1TokenInfoForOptimismToken(chainId: OVM_CHAIN_ID, hubPoolClient: HubPoolClient, l2Token: string): L1Token { - return hubPoolClient.getL1TokenInfoForL2Token( - SpokePoolClient.getExecutedRefundLeafL2Token(chainId, l2Token), - chainId - ); -} - async function finalizeOptimismMessage( _chainId: OVM_CHAIN_ID, crossChainMessenger: OVM_CROSS_CHAIN_MESSENGER, @@ -274,7 +268,7 @@ async function multicallOptimismFinalizations( ) ); const withdrawals = finalizableMessages.map((message) => { - const l1TokenInfo = getL1TokenInfoForOptimismToken(chainId, hubPoolClient, message.event.l2TokenAddress); + const l1TokenInfo = getL1TokenInfo(message.event.l2TokenAddress, chainId); const amountFromWei = convertFromWei(message.event.amountToReturn.toString(), l1TokenInfo.decimals); const withdrawal: CrossChainMessage = { originationChainId: chainId, @@ -306,7 +300,7 @@ async function multicallOptimismL1Proofs( provableMessages.map((message) => proveOptimismMessage(chainId, crossChainMessenger, message, message.logIndex)) ); const withdrawals = provableMessages.map((message) => { - const l1TokenInfo = getL1TokenInfoForOptimismToken(chainId, hubPoolClient, message.event.l2TokenAddress); + const l1TokenInfo = getL1TokenInfo(message.event.l2TokenAddress, chainId); const amountFromWei = convertFromWei(message.event.amountToReturn.toString(), l1TokenInfo.decimals); const proof: CrossChainMessage = { originationChainId: chainId, diff --git a/src/finalizer/utils/polygon.ts b/src/finalizer/utils/polygon.ts index 61560be44..5b6212278 100644 --- a/src/finalizer/utils/polygon.ts +++ b/src/finalizer/utils/polygon.ts @@ -12,6 +12,7 @@ import { getCurrentTime, getRedisCache, getBlockForTimestamp, + getL1TokenInfo, } from "../../utils"; import { EthersError, TokensBridged } from "../../interfaces"; import { HubPoolClient, SpokePoolClient } from "../../clients"; @@ -204,9 +205,7 @@ async function resolvePolygonRetrievalFinalizations( }) ); const callData = await Promise.all( - tokensInFinalizableMessages.map((l2Token) => - retrieveTokenFromMainnetTokenBridger(l2Token, hubSigner, hubPoolClient) - ) + tokensInFinalizableMessages.map((l2Token) => retrieveTokenFromMainnetTokenBridger(l2Token, hubSigner)) ); const crossChainMessages = finalizableMessages.map((finalizableMessage) => resolveCrossChainTransferStructure(finalizableMessage, "misc", hubPoolClient) @@ -223,12 +222,7 @@ function resolveCrossChainTransferStructure( hubPoolClient: HubPoolClient ): CrossChainMessage { const { l2TokenAddress, amountToReturn } = finalizableMessage; - const l1TokenCounterpart = hubPoolClient.getL1TokenForL2TokenAtBlock( - l2TokenAddress, - CHAIN_ID, - hubPoolClient.latestBlockSearched - ); - const l1TokenInfo = hubPoolClient.getTokenInfo(1, l1TokenCounterpart); + const l1TokenInfo = getL1TokenInfo(l2TokenAddress, CHAIN_ID); const amountFromWei = convertFromWei(amountToReturn.toString(), l1TokenInfo.decimals); const transferBase = { originationChainId: CHAIN_ID, @@ -246,12 +240,8 @@ function getMainnetTokenBridger(mainnetSigner: Signer): Contract { return getDeployedContract("PolygonTokenBridger", 1, mainnetSigner); } -async function retrieveTokenFromMainnetTokenBridger( - l2Token: string, - mainnetSigner: Signer, - hubPoolClient: HubPoolClient -): Promise { - const l1Token = hubPoolClient.getL1TokenForL2TokenAtBlock(l2Token, CHAIN_ID, hubPoolClient.latestBlockSearched); +async function retrieveTokenFromMainnetTokenBridger(l2Token: string, mainnetSigner: Signer): Promise { + const l1Token = getL1TokenInfo(l2Token, CHAIN_ID).address; const mainnetTokenBridger = getMainnetTokenBridger(mainnetSigner); const callData = await mainnetTokenBridger.populateTransaction.retrieve(l1Token); return { diff --git a/src/finalizer/utils/zkSync.ts b/src/finalizer/utils/zkSync.ts index 010807d5e..7326f6f15 100644 --- a/src/finalizer/utils/zkSync.ts +++ b/src/finalizer/utils/zkSync.ts @@ -9,6 +9,7 @@ import { getBlockForTimestamp, getCurrentTime, getEthAddressForChain, + getL1TokenInfo, getRedisCache, getUniqueLogIndex, winston, @@ -65,12 +66,7 @@ export async function zkSyncFinalizer( const txns = await prepareFinalizations(l1ChainId, l2ChainId, withdrawalParams); const withdrawals = candidates.map(({ l2TokenAddress, amountToReturn }) => { - const l1TokenCounterpart = hubPoolClient.getL1TokenForL2TokenAtBlock( - l2TokenAddress, - l2ChainId, - hubPoolClient.latestBlockSearched - ); - const { decimals, symbol: l1TokenSymbol } = hubPoolClient.getTokenInfo(l1ChainId, l1TokenCounterpart); + const { decimals, symbol: l1TokenSymbol } = getL1TokenInfo(l2TokenAddress, l2ChainId); const amountFromWei = convertFromWei(amountToReturn.toString(), decimals); const withdrawal: CrossChainMessage = { originationChainId: l2ChainId, diff --git a/src/libexec/RelayerSpokePoolIndexer.ts b/src/libexec/RelayerSpokePoolIndexer.ts index 32c6c4a49..10f25db00 100644 --- a/src/libexec/RelayerSpokePoolIndexer.ts +++ b/src/libexec/RelayerSpokePoolIndexer.ts @@ -248,12 +248,12 @@ async function run(argv: string[]): Promise { const spokePool = await utils.getSpokePoolContract(chainId); process.on("SIGHUP", () => { - logger.debug({ at: "Relayer#run", message: "Received SIGHUP, stopping..." }); + logger.debug({ at: "Relayer#run", message: `Received SIGHUP in ${chain} listener, stopping...` }); stop = true; }); process.on("disconnect", () => { - logger.debug({ at: "Relayer::run", message: "Parent disconnected, stopping..." }); + logger.debug({ at: "Relayer::run", message: `${chain} parent disconnected, stopping...` }); stop = true; }); @@ -310,11 +310,12 @@ if (require.main === module) { process.exitCode = NODE_SUCCESS; }) .catch((error) => { - logger.error({ at: "RelayerSpokePoolIndexer", message: "Process exited with error.", error }); + logger.error({ at: "RelayerSpokePoolIndexer", message: `${chain} listener exited with error.`, error }); process.exitCode = NODE_APP_ERR; }) .finally(async () => { await disconnectRedisClients(); + logger.debug({ at: "RelayerSpokePoolIndexer", message: `Exiting ${chain} listener.` }); exit(process.exitCode); }); }