Skip to content

Commit

Permalink
improve(finalizer): Inject addresses into L1ToL2 finalizer (#1335)
Browse files Browse the repository at this point in the history
* improve(linea): add outstanding contracts

* improve: finish WETH contracts

* nit: use null coalesce operator

Co-authored-by: Paul <[email protected]>

* nit: use null coalesce operator

Co-authored-by: Paul <[email protected]>

* 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 <[email protected]>

* Update LineaAdapter.ts

* Update LineaAdapter.ts

* tweak

* Update Constants.ts

* Fix

* Update LineaAdapter.ts

* Update LineaAdapter.ts

* Revert "Update LineaAdapter.ts"

This reverts commit a1a4943.

---------

Co-authored-by: Paul <[email protected]>
Co-authored-by: nicholaspai <[email protected]>
Co-authored-by: nicholaspai <[email protected]>

* 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 <[email protected]>

---------

Co-authored-by: james-a-morris <[email protected]>
Co-authored-by: James Morris, MS <[email protected]>
Co-authored-by: Paul <[email protected]>
  • Loading branch information
4 people authored Mar 21, 2024
1 parent efcc47c commit 3c9cc20
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
30 changes: 30 additions & 0 deletions src/finalizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -16,6 +17,7 @@ import {
import { DataworkerConfig } from "../dataworker/DataworkerConfig";
import { SpokePoolClientsByChain } from "../interfaces";
import {
CHAIN_IDs,
Signer,
blockExplorerLink,
config,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 1 addition & 8 deletions src/finalizer/utils/linea/l1ToL2.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -24,7 +23,7 @@ export async function lineaL1ToL2Finalizer(
_spokePoolClient: SpokePoolClient,
l1ToL2AddressesToFinalize: string[]
): Promise<FinalizerPromise> {
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();
Expand All @@ -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.
Expand Down

0 comments on commit 3c9cc20

Please sign in to comment.