Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve(finalizer): Filter USDC from arbitrum and op stack finalizers #1539

Merged
merged 9 commits into from
May 20, 2024
15 changes: 10 additions & 5 deletions src/finalizer/utils/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
getRedisCache,
getBlockForTimestamp,
getL1TokenInfo,
compareAddressesSimple,
TOKEN_SYMBOLS_MAP,
} from "../../utils";
import { TokensBridged } from "../../interfaces";
import { HubPoolClient, SpokePoolClient } from "../../clients";
Expand Down Expand Up @@ -138,18 +140,21 @@ async function getAllMessageStatuses(
// For each token bridge event, store a unique log index for the event within the arbitrum transaction hash.
// This is important for bridge transactions containing multiple events.
const logIndexesForMessage = getUniqueLogIndex(tokensBridged);
return (
await Promise.all(
tokensBridged.map((e, i) => getMessageOutboxStatusAndProof(logger, e, mainnetSigner, logIndexesForMessage[i]))
)
return await Promise.all(
tokensBridged.map((e, i) => getMessageOutboxStatusAndProof(logger, e, mainnetSigner, logIndexesForMessage[i]))
)
.map((result, i) => {
return {
...result,
info: tokensBridged[i],
};
})
.filter((result) => result.message !== undefined);
// USDC withdrawals for Arbitrum should be finalized via the CCTP Finalizer.
.filter(
(result) =>
result.message !== undefined &&
!compareAddressesSimple(result.info.l2TokenAddress, TOKEN_SYMBOLS_MAP["_USDC"].addresses[CHAIN_ID])
);
}

async function getMessageOutboxStatusAndProof(
Expand Down
4 changes: 1 addition & 3 deletions src/finalizer/utils/linea/l1ToL2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ export async function lineaL1ToL2Finalizer(
);

// 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.
const { fromBlock, toBlock } = await getBlockRangeByHoursOffsets(l1ChainId, 24, 0);
const { fromBlock, toBlock } = await getBlockRangeByHoursOffsets(l1ChainId, 24 * 7, 0);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to add this longer look back in #1535

logger.debug({
at: "Finalizer#LineaL1ToL2Finalizer",
message: "Linea MessageSent event filter",
Expand Down
5 changes: 2 additions & 3 deletions src/finalizer/utils/linea/l2ToL1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ export async function lineaL2ToL1Finalizer(
const getMessagesWithStatusByTxHash = makeGetMessagesWithStatusByTxHash(l2Contract, l1ClaimingService);

// Optimize block range for querying relevant source events on L2.
// We want to conservatively query for events that are between 8 and 72 hours old
// because Linea L2->L1 messages are claimable after 6 - 32 hours
const { fromBlock, toBlock } = await getBlockRangeByHoursOffsets(l2ChainId, 72, 8);
// Linea L2->L1 messages are claimable after 6 - 32 hours
const { fromBlock, toBlock } = await getBlockRangeByHoursOffsets(l2ChainId, 24 * 8, 6);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to add this in #1535

logger.debug({
at: "Finalizer#LineaL2ToL1Finalizer",
message: "Linea TokensBridged event filter",
Expand Down
40 changes: 26 additions & 14 deletions src/finalizer/utils/opStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { HubPoolClient, SpokePoolClient } from "../../clients";
import { TokensBridged } from "../../interfaces";
import {
BigNumber,
CHAIN_IDs,
chainIsOPStack,
compareAddressesSimple,
convertFromWei,
getBlockForTimestamp,
getCachedProvider,
Expand All @@ -16,6 +18,7 @@ import {
getUniqueLogIndex,
groupObjectCountsByProp,
Signer,
TOKEN_SYMBOLS_MAP,
winston,
} from "../../utils";
import { Multicall2Call } from "../../common";
Expand Down Expand Up @@ -129,22 +132,31 @@ async function getCrossChainMessages(
const logIndexesForMessage = getUniqueLogIndex(tokensBridged);

return (
await Promise.all(
tokensBridged.map(
async (l2Event, i) =>
(
await crossChainMessenger.getMessagesByTransaction(l2Event.transactionHash, {
direction: optimismSDK.MessageDirection.L2_TO_L1,
})
)[logIndexesForMessage[i]]
(
await Promise.all(
tokensBridged.map(
async (l2Event, i) =>
(
await crossChainMessenger.getMessagesByTransaction(l2Event.transactionHash, {
direction: optimismSDK.MessageDirection.L2_TO_L1,
})
)[logIndexesForMessage[i]]
)
)
)
).map((message, i) => {
return {
message,
event: tokensBridged[i],
};
});
.map((message, i) => {
return {
message,
event: tokensBridged[i],
};
})
// USDC withdrawals for Base and Optimism should be finalized via the CCTP Finalizer.
.filter(
(e) =>
!compareAddressesSimple(e.event.l2TokenAddress, TOKEN_SYMBOLS_MAP["_USDC"].addresses[_chainId]) ||
!(_chainId === CHAIN_IDs.BASE || _chainId === CHAIN_IDs.OPTIMISM)
)
);
}

async function getMessageStatuses(
Expand Down
Loading