Skip to content

Commit

Permalink
Merge branch 'master' into pxrl/relayerRefactorEvaluate
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl authored Mar 21, 2024
2 parents 89cf27b + ed9c43f commit 5a246b9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
6 changes: 0 additions & 6 deletions src/clients/bridges/BaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,6 @@ export abstract class BaseAdapter {
*/
isSupportedToken(l1Token: string): l1Token is SupportedL1Token {
const relevantSymbols = matchTokenSymbol(l1Token, this.hubChainId);

// If we don't have a symbol for this token, return that the token is not supported
if (relevantSymbols.length === 0) {
return false;
}

// if the symbol is not in the supported tokens list, it's not supported
return relevantSymbols.some((symbol) => this.supportedTokens.includes(symbol));
}
Expand Down
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 5a246b9

Please sign in to comment.