Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 5 additions & 9 deletions src/clients/BundleDataClient/BundleDataClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,7 @@ export class BundleDataClient {
fill,
this.spokePoolClients[fill.destinationChainId].spokePool.provider,
matchingDeposit,
// @dev: to get valid repayment chain ID's, get all chain IDs for the bundle block range and remove
// disabled block ranges.
this.clients.configStoreClient
.getChainIdIndicesForBlock(blockRanges[0][1])
.filter((_chainId, i) => !isChainDisabled(blockRanges[i]))
this.clients.hubPoolClient
);
if (!isDefined(validRepayment)) {
return false;
Expand Down Expand Up @@ -919,7 +915,7 @@ export class BundleDataClient {
fill,
destinationClient.spokePool.provider,
v3RelayHashes[relayDataHash].deposits![0],
allChainIds
this.clients.hubPoolClient
);
if (!isDefined(fillToRefund)) {
bundleUnrepayableFillsV3.push(fill);
Expand Down Expand Up @@ -1013,7 +1009,7 @@ export class BundleDataClient {
fill,
destinationClient.spokePool.provider,
matchedDeposit,
allChainIds
this.clients.hubPoolClient
);
if (!isDefined(fillToRefund)) {
bundleUnrepayableFillsV3.push(fill);
Expand Down Expand Up @@ -1187,7 +1183,7 @@ export class BundleDataClient {
fill,
destinationClient.spokePool.provider,
v3RelayHashes[relayDataHash].deposits![0],
allChainIds
this.clients.hubPoolClient
);
if (!isDefined(fillToRefund)) {
bundleUnrepayableFillsV3.push(fill);
Expand Down Expand Up @@ -1241,7 +1237,7 @@ export class BundleDataClient {
prefill!,
destinationClient.spokePool.provider,
deposit,
allChainIds
this.clients.hubPoolClient
);
if (!isDefined(verifiedFill)) {
bundleUnrepayableFillsV3.push(prefill!);
Expand Down
27 changes: 15 additions & 12 deletions src/clients/BundleDataClient/utils/FillUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,11 @@ export function getRepaymentChainId(fill: Fill, matchedDeposit: Deposit): number
return matchedDeposit.fromLiteChain ? fill.originChainId : fill.repaymentChainId;
}

export function isEvmRepaymentValid(
fill: Fill,
repaymentChainId: number,
possibleRepaymentChainIds: number[] = []
): boolean {
export function isEvmRepaymentValid(fill: Fill, repaymentChainId: number): boolean {
// Slow fills don't result in repayments so they're always valid.
if (isSlowFill(fill)) {
return true;
}
// Return undefined if the requested repayment chain ID is not in a passed in set of eligible chains. This can
// be used by the caller to narrow the chains to those that are not disabled in the config store.
if (possibleRepaymentChainIds.length > 0 && !possibleRepaymentChainIds.includes(repaymentChainId)) {
return false;
}
return chainIsEvm(repaymentChainId) && isValidEvmAddress(fill.relayer);
}

Expand All @@ -75,12 +66,24 @@ export async function verifyFillRepayment(
_fill: FillWithBlock,
destinationChainProvider: providers.Provider,
matchedDeposit: DepositWithBlock,
possibleRepaymentChainIds: number[] = []
hubPoolClient: HubPoolClient
): Promise<FillWithBlock | undefined> {
const fill = _.cloneDeep(_fill);

const repaymentChainId = getRepaymentChainId(fill, matchedDeposit);
const validEvmRepayment = isEvmRepaymentValid(fill, repaymentChainId, possibleRepaymentChainIds);
const validEvmRepayment = isEvmRepaymentValid(fill, repaymentChainId);
try {
const l1TokenCounterpart = hubPoolClient.getL1TokenForL2TokenAtBlock(
fill.inputToken,
fill.originChainId,
matchedDeposit.quoteBlockNumber
);
hubPoolClient.getL2TokenForL1TokenAtBlock(l1TokenCounterpart, repaymentChainId, matchedDeposit.quoteBlockNumber);
// Repayment token could be found, this is a valid repayment chain.
} catch {
// Repayment token doesn't exist on repayment chain via PoolRebalanceRoutes, impossible to repay filler.
Copy link
Collaborator

@pxrl pxrl Feb 5, 2025

Choose a reason for hiding this comment

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

Do we want to log this via unpayable-repayments? The HubPoolClient has a logger instance you could piggyback on.

return undefined;
}

// Case 1: Repayment chain is EVM and repayment address is valid EVM address.
if (validEvmRepayment) {
Expand Down
Loading