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

fix(finalizer): polygon #1538

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 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 @@ -139,17 +141,24 @@ async function getAllMessageStatuses(
// 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]))
(
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);
.map((result, i) => {
return {
...result,
info: tokensBridged[i],
};
})
// 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);
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);
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
8 changes: 8 additions & 0 deletions src/finalizer/utils/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
getRedisCache,
getBlockForTimestamp,
getL1TokenInfo,
compareAddressesSimple,
TOKEN_SYMBOLS_MAP,
} from "../../utils";
import { EthersError, TokensBridged } from "../../interfaces";
import { HubPoolClient, SpokePoolClient } from "../../clients";
Expand Down Expand Up @@ -110,6 +112,12 @@ async function getFinalizableTransactions(
const exitStatus = await Promise.all(
checkpointedTokensBridged.map(async (_, i) => {
const payload = payloads[i];
const { chainId, l2TokenAddress } = tokensBridged[i];

if (compareAddressesSimple(l2TokenAddress, TOKEN_SYMBOLS_MAP._USDC.addresses[chainId])) {
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved
return { status: "NON_CANONICAL_BRIDGE" };
}

try {
// If we can estimate gas for exit transaction call, then we can exit the burn tx, otherwise its likely
// been processed. Note this will capture mislabel some exit txns that fail for other reasons as "exit
Expand Down
Loading