Skip to content

improve: Handle deposits referencing input/output/repayment tokens that do not map to PoolRebalanceRoutes #970

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

Merged
merged 36 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
480c57f
improve(BundleDataClient): Ignore refunds for L2 tokens that do not m…
nicholaspai Apr 8, 2025
18cbb49
Add more cases
nicholaspai Apr 8, 2025
f7b0c0a
refactor into forceOriginChainRepayment
nicholaspai Apr 8, 2025
bb63534
Update FillUtils.ts
nicholaspai Apr 8, 2025
fb6b015
Update BundleDataClient.ts
nicholaspai Apr 8, 2025
d0e6ffc
Add block to l2TokenHasPoolRebalanceRoute call
nicholaspai Apr 9, 2025
10a7073
Simplify getValidUnfilledAmountForDeposit
nicholaspai Apr 9, 2025
7fa238f
Revert "Simplify getValidUnfilledAmountForDeposit"
nicholaspai Apr 9, 2025
a194052
Refactor
nicholaspai Apr 9, 2025
57615b1
check for destination chain as well as origin chain pool rebalance ro…
nicholaspai Apr 10, 2025
e7e53c3
Add spoke pool client check
nicholaspai Apr 10, 2025
819fa76
Update FillUtils.ts
nicholaspai Apr 10, 2025
3545cd3
Update HubPoolClient.ts
nicholaspai Apr 10, 2025
820847b
Update HubPoolClient.ts
nicholaspai Apr 10, 2025
bf93c5f
Use destination chain if it can be mapped to a pool rebalance route
nicholaspai Apr 10, 2025
01f67d7
Update FillUtils.ts
nicholaspai Apr 10, 2025
d1d63e6
Update FillUtils.ts
nicholaspai Apr 10, 2025
b12324c
repay to origin chain if repayment chain is invalid, change to destin…
nicholaspai Apr 11, 2025
47d6124
refactor spoke pool client
nicholaspai Apr 11, 2025
c789c27
Update SpokePoolClient.ts
nicholaspai Apr 11, 2025
c0dd4a6
Add comments on solana
nicholaspai Apr 11, 2025
a9b3100
Refactor
nicholaspai Apr 11, 2025
674364f
Keep deposit with outputToken = 0x0 that we cannot resolve
nicholaspai Apr 11, 2025
7c232d1
Update DepositUtils.ts
nicholaspai Apr 11, 2025
6b4d6da
refactor isZeroValueFillOrSlowFillRequest for clarity
nicholaspai Apr 11, 2025
dd9c6f9
Merge branch 'master' into deposit-whitelist-removal
nicholaspai Apr 11, 2025
cfabc9b
Update DepositUtils.ts
nicholaspai Apr 15, 2025
45103b4
remove assert in `getRefundInformationFromFill` and try-catch in Hub…
nicholaspai Apr 15, 2025
065a850
Update DepositUtils.ts
nicholaspai Apr 15, 2025
7d6c9fd
fix mock hub pool client
nicholaspai Apr 15, 2025
8653045
Update package.json
nicholaspai Apr 22, 2025
4a2ecca
Read repayment validity using bundle end block instead of quote block
nicholaspai Apr 22, 2025
08d88a3
Update PoolRebalanceUtils.ts
nicholaspai Apr 22, 2025
e86745e
Protect or remove functions that use deposit.quoteBlock to lookup a p…
nicholaspai Apr 22, 2025
ac67532
Update MockHubPoolClient.ts
nicholaspai Apr 22, 2025
28669bf
Update MockHubPoolClient.ts
nicholaspai Apr 22, 2025
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
46 changes: 28 additions & 18 deletions src/clients/BundleDataClient/BundleDataClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
chainIsEvm,
isValidEvmAddress,
duplicateEvent,
invalidOutputToken,
} from "../../utils";
import winston from "winston";
import {
Expand Down Expand Up @@ -372,7 +373,8 @@ export class BundleDataClient {
if (
fill.blockNumber < blockRanges[chainIndex][0] ||
fill.blockNumber > blockRanges[chainIndex][1] ||
isZeroValueFillOrSlowFillRequest(fill)
isZeroValueFillOrSlowFillRequest(fill) ||
invalidOutputToken(fill)
) {
return false;
}
Expand Down Expand Up @@ -405,11 +407,12 @@ export class BundleDataClient {
return;
}
const { chainToSendRefundTo, repaymentToken } = getRefundInformationFromFill(
fill,
this.clients.hubPoolClient,
blockRanges,
this.chainIdListForBundleEvaluationBlockNumbers,
matchingDeposit.fromLiteChain
{
...fill,
fromLiteChain: matchingDeposit.fromLiteChain,
quoteBlockNumber: matchingDeposit.quoteBlockNumber,
},
this.clients.hubPoolClient
);
// Assume that lp fees are 0 for the sake of speed. In the future we could batch compute
// these or make hardcoded assumptions based on the origin-repayment chain direction. This might result
Expand Down Expand Up @@ -885,7 +888,10 @@ export class BundleDataClient {
// tokens to the filler. We can't remove non-empty message deposit here in case there is a slow fill
// request for the deposit, we'd want to see the fill took place.
.filter(
(fill) => fill.blockNumber <= destinationChainBlockRange[1] && !isZeroValueFillOrSlowFillRequest(fill)
(fill) =>
fill.blockNumber <= destinationChainBlockRange[1] &&
!isZeroValueFillOrSlowFillRequest(fill) &&
!invalidOutputToken(fill)
),
async (fill) => {
fillCounter++;
Expand Down Expand Up @@ -1054,7 +1060,9 @@ export class BundleDataClient {
.getSlowFillRequestsForOriginChain(originChainId)
.filter(
(request) =>
request.blockNumber <= destinationChainBlockRange[1] && !isZeroValueFillOrSlowFillRequest(request)
request.blockNumber <= destinationChainBlockRange[1] &&
!isZeroValueFillOrSlowFillRequest(request) &&
!invalidOutputToken(request)
),
async (slowFillRequest: SlowFillRequestWithBlock) => {
const relayDataHash = getRelayEventKey(slowFillRequest);
Expand Down Expand Up @@ -1376,11 +1384,12 @@ export class BundleDataClient {
const matchedDeposit = deposits[0];
assert(isDefined(matchedDeposit), "Deposit should exist in relay hash dictionary.");
const { chainToSendRefundTo: paymentChainId } = getRefundInformationFromFill(
fill,
this.clients.hubPoolClient,
blockRangesForChains,
chainIds,
matchedDeposit.fromLiteChain
{
...fill,
fromLiteChain: matchedDeposit.fromLiteChain,
quoteBlockNumber: matchedDeposit.quoteBlockNumber,
},
this.clients.hubPoolClient
);
return {
...fill,
Expand Down Expand Up @@ -1422,11 +1431,12 @@ export class BundleDataClient {
const associatedDeposit = deposits[0];
assert(isDefined(associatedDeposit), "Deposit should exist in relay hash dictionary.");
const { chainToSendRefundTo, repaymentToken } = getRefundInformationFromFill(
fill,
this.clients.hubPoolClient,
blockRangesForChains,
chainIds,
associatedDeposit.fromLiteChain
{
...fill,
fromLiteChain: associatedDeposit.fromLiteChain,
quoteBlockNumber: associatedDeposit.quoteBlockNumber,
},
this.clients.hubPoolClient
);
updateBundleFillsV3(bundleFillsV3, fill, realizedLpFeePct, chainToSendRefundTo, repaymentToken, fill.relayer);
});
Expand Down
29 changes: 29 additions & 0 deletions src/clients/BundleDataClient/utils/DataworkerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ export function _buildPoolRebalanceRoot(
const repaymentChainId = Number(_repaymentChainId);
Object.entries(fillsForChain).forEach(
([l2TokenAddress, { realizedLpFees: totalRealizedLpFee, totalRefundAmount }]) => {
// If the repayment token and repayment chain ID do not map to a PoolRebalanceRoute graph, then
// there are no relevant L1 running balances.
if (
!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(l2TokenAddress, repaymentChainId, mainnetBundleEndBlock)
) {
return;
}
const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
l2TokenAddress,
repaymentChainId,
Expand Down Expand Up @@ -215,6 +222,17 @@ export function _buildPoolRebalanceRoot(
Object.entries(bundleV3Deposits).forEach(([, depositsForChain]) => {
Object.entries(depositsForChain).forEach(([, deposits]) => {
deposits.forEach((deposit) => {
// If the repayment token and repayment chain ID do not map to a PoolRebalanceRoute graph, then
// there are no relevant L1 running balances.
if (
!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(
deposit.inputToken,
deposit.originChainId,
mainnetBundleEndBlock
)
) {
return;
}
updateRunningBalanceForDeposit(runningBalances, clients.hubPoolClient, deposit, deposit.inputAmount.mul(-1));
});
});
Expand All @@ -229,6 +247,17 @@ export function _buildPoolRebalanceRoot(
const originChainId = Number(_originChainId);
Object.entries(depositsForChain).forEach(([inputToken, deposits]) => {
deposits.forEach((deposit) => {
// If the repayment token and repayment chain ID do not map to a PoolRebalanceRoute graph, then
// there are no relevant L1 running balances.
if (
!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(
deposit.inputToken,
deposit.originChainId,
mainnetBundleEndBlock
)
) {
return;
}
const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
inputToken,
originChainId,
Expand Down
Loading