From 3c9cc202b2b3b139ce8342d500732f48597678e5 Mon Sep 17 00:00:00 2001 From: nicholaspai <9457025+nicholaspai@users.noreply.github.com> Date: Thu, 21 Mar 2024 12:30:58 -0400 Subject: [PATCH] improve(finalizer): Inject addresses into L1ToL2 finalizer (#1335) * improve(linea): add outstanding contracts * improve: finish WETH contracts * nit: use null coalesce operator Co-authored-by: Paul <108695806+pxrl@users.noreply.github.com> * nit: use null coalesce operator Co-authored-by: Paul <108695806+pxrl@users.noreply.github.com> * fixes * nit: clean adapter * improve: code style * fix: use l1Token * fix * feat(finalizer): make l1l2 routes generic (#1328) * feat(finalizer): make l1l2 routes generic * chore: revert index * nit: include linea in non-overrides * wip * improve: overhaul generic finalizer * nit * Exclude missing SpokePoolClient instances * nit: also compare positive `_value` * nit: remove unneeded type * feat: Activate linea adapter manager (#1325) Co-authored-by: Paul <108695806+pxrl@users.noreply.github.com> * Update LineaAdapter.ts * Update LineaAdapter.ts * tweak * Update Constants.ts * Fix * Update LineaAdapter.ts * Update LineaAdapter.ts * Revert "Update LineaAdapter.ts" This reverts commit a1a4943275a6eaff0a8cc8f2ff72a87469f881f7. --------- Co-authored-by: Paul <108695806+pxrl@users.noreply.github.com> Co-authored-by: nicholaspai <9457025+nicholaspai@users.noreply.github.com> Co-authored-by: nicholaspai * Update common.ts * improve(lineaFinalizer): Force atomic depositor and spoke pool to be included Force these contracts to be in list of finalizable origins * fix * Update index.ts * Update src/finalizer/index.ts Co-authored-by: James Morris, MS <96435344+james-a-morris@users.noreply.github.com> --------- Co-authored-by: james-a-morris Co-authored-by: James Morris, MS <96435344+james-a-morris@users.noreply.github.com> Co-authored-by: Paul <108695806+pxrl@users.noreply.github.com> --- src/finalizer/index.ts | 30 +++++++++++++++++++++++++++++ src/finalizer/utils/linea/l1ToL2.ts | 9 +-------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/finalizer/index.ts b/src/finalizer/index.ts index c8c1fca53..3dcacbae8 100644 --- a/src/finalizer/index.ts +++ b/src/finalizer/index.ts @@ -5,6 +5,7 @@ import { getAddress } from "ethers/lib/utils"; import { groupBy, uniq } from "lodash"; import { AugmentedTransaction, HubPoolClient, MultiCallerClient, TransactionClient } from "../clients"; import { + CONTRACT_ADDRESSES, Clients, FINALIZER_TOKENBRIDGE_LOOKBACK, Multicall2Call, @@ -16,6 +17,7 @@ import { import { DataworkerConfig } from "../dataworker/DataworkerConfig"; import { SpokePoolClientsByChain } from "../interfaces"; import { + CHAIN_IDs, Signer, blockExplorerLink, config, @@ -72,6 +74,17 @@ const chainFinalizerOverrides: { [chainId: number]: ChainFinalizer[] } = { 59140: [lineaL2ToL1Finalizer], }; +function enrichL1ToL2AddressesToFinalize(l1ToL2AddressesToFinalize: string[], addressesToEnsure: string[]): string[] { + const resultingAddresses = l1ToL2AddressesToFinalize.slice().map(getAddress); + for (const address of addressesToEnsure) { + const checksummedAddress = getAddress(address); + if (!resultingAddresses.includes(checksummedAddress)) { + resultingAddresses.push(checksummedAddress); + } + } + return resultingAddresses; +} + export async function finalize( logger: winston.Logger, hubSigner: Signer, @@ -109,6 +122,23 @@ export async function finalize( const network = getNetworkName(chainId); + // For certain chains we always want to track certain addresses for finalization: + // LineaL1ToL2: Always track HubPool, AtomicDepositor, LineaSpokePool. HubPool sends messages and tokens to the + // SpokePool, while the relayer rebalances ETH via the AtomicDepositor + if (chainId === hubChainId) { + if (chainId !== CHAIN_IDs.MAINNET) { + logger.warn({ + at: "Finalizer", + message: "Testnet Finalizer: skipping finalizations where from or to address is set to AtomicDepositor", + }); + } + l1ToL2AddressesToFinalize = enrichL1ToL2AddressesToFinalize(l1ToL2AddressesToFinalize, [ + hubPoolClient.hubPool.address, + spokePoolClients[hubChainId === CHAIN_IDs.MAINNET ? CHAIN_IDs.LINEA : CHAIN_IDs.LINEA_GOERLI].spokePool.address, + CONTRACT_ADDRESSES[hubChainId]?.atomicDepositor?.address, + ]); + } + // We can subloop through the finalizers for each chain, and then execute the finalizer. For now, the // main reason for this is related to CCTP finalizations. We want to run the CCTP finalizer AND the // normal finalizer for each chain. This is going to cause an overlap of finalization attempts on USDC. diff --git a/src/finalizer/utils/linea/l1ToL2.ts b/src/finalizer/utils/linea/l1ToL2.ts index a14658e2d..c2575ccc7 100644 --- a/src/finalizer/utils/linea/l1ToL2.ts +++ b/src/finalizer/utils/linea/l1ToL2.ts @@ -1,7 +1,6 @@ import { utils as sdkUtils } from "@across-protocol/sdk-v2"; import { OnChainMessageStatus } from "@consensys/linea-sdk"; import { Contract } from "ethers"; -import { getAddress } from "ethers/lib/utils"; import { groupBy } from "lodash"; import { HubPoolClient, SpokePoolClient } from "../../../clients"; import { CHAIN_MAX_BLOCK_LOOKBACK, CONTRACT_ADDRESSES } from "../../../common"; @@ -24,7 +23,7 @@ export async function lineaL1ToL2Finalizer( _spokePoolClient: SpokePoolClient, l1ToL2AddressesToFinalize: string[] ): Promise { - const [l1ChainId, hubPoolAddress] = [hubPoolClient.chainId, hubPoolClient.hubPool.address]; + const [l1ChainId] = [hubPoolClient.chainId, hubPoolClient.hubPool.address]; const l2ChainId = l1ChainId === 1 ? 59144 : 59140; const lineaSdk = initLineaSdk(l1ChainId, l2ChainId); const l2MessageServiceContract = lineaSdk.getL2Contract(); @@ -40,12 +39,6 @@ export async function lineaL1ToL2Finalizer( hubPoolClient.hubPool.provider ); - // We always want to make sure that the l1ToL2AddressesToFinalize array contains - // the HubPool address, so we can finalize any pending messages sent from the HubPool. - if (!l1ToL2AddressesToFinalize.includes(getAddress(hubPoolAddress))) { - l1ToL2AddressesToFinalize.push(hubPoolAddress); - } - // Optimize block range for querying Linea's MessageSent events on L1. // We want to conservatively query for events that are between 0 and 24 hours old // because Linea L1->L2 messages are claimable after ~20 mins.