Skip to content

Commit

Permalink
feat(BundleDataClient): Remove 0-value deposits and fills and 0-value…
Browse files Browse the repository at this point in the history
… empty-message slow fills (#800)
  • Loading branch information
nicholaspai authored Jan 2, 2025
1 parent 72bd17f commit a7615d0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@across-protocol/sdk",
"author": "UMA Team",
"version": "3.3.31",
"version": "3.3.32",
"license": "AGPL-3.0",
"homepage": "https://docs.across.to/reference/sdk",
"files": [
Expand Down
19 changes: 17 additions & 2 deletions src/clients/BundleDataClient/BundleDataClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
isSlowFill,
mapAsync,
bnUint32Max,
isZeroValueDeposit,
} from "../../utils";
import winston from "winston";
import {
Expand Down Expand Up @@ -778,6 +779,9 @@ export class BundleDataClient {
continue;
}
originClient.getDepositsForDestinationChain(destinationChainId).forEach((deposit) => {
if (isZeroValueDeposit(deposit)) {
return;
}
depositCounter++;
const relayDataHash = this.getRelayHashFromEvent(deposit);
if (v3RelayHashes[relayDataHash]) {
Expand All @@ -793,6 +797,14 @@ export class BundleDataClient {
slowFillRequest: undefined,
};

// Once we've saved the deposit hash into v3RelayHashes, then we can exit early here if the inputAmount
// is 0 because there can be no expired amount to refund and no unexecutable slow fill amount to return
// if this deposit did expire. Input amount can only be zero at this point if the message is non-empty,
// but the message doesn't matter for expired deposits and unexecutable slow fills.
if (deposit.inputAmount.eq(0)) {
return;
}

// If deposit block is within origin chain bundle block range, then save as bundle deposit.
// If deposit is in bundle and it has expired, additionally save it as an expired deposit.
// If deposit is not in the bundle block range, then save it as an older deposit that
Expand Down Expand Up @@ -840,7 +852,10 @@ export class BundleDataClient {
await forEachAsync(
destinationClient
.getFillsForOriginChain(originChainId)
.filter((fill) => fill.blockNumber <= destinationChainBlockRange[1]),
// We can remove fills for deposits with input amount equal to zero because these will result in 0 refunded
// 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] && !isZeroValueDeposit(fill)),
async (fill) => {
const relayDataHash = this.getRelayHashFromEvent(fill);
fillCounter++;
Expand Down Expand Up @@ -933,7 +948,7 @@ export class BundleDataClient {
await forEachAsync(
destinationClient
.getSlowFillRequestsForOriginChain(originChainId)
.filter((request) => request.blockNumber <= destinationChainBlockRange[1]),
.filter((request) => request.blockNumber <= destinationChainBlockRange[1] && !isZeroValueDeposit(request)),
async (slowFillRequest: SlowFillRequestWithBlock) => {
const relayDataHash = this.getRelayHashFromEvent(slowFillRequest);

Expand Down
12 changes: 12 additions & 0 deletions src/utils/DepositUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ export async function queryHistoricalDepositForFill(
};
}

/**
* Returns true if filling this deposit (as a slow or fast fill) or refunding it would not change any state
* on-chain. The dataworker functions can use this to conveniently filter out useless deposits.
* @dev The reason we allow a 0-input deposit to have a non-empty message is that the message might be used
* to pay the filler in an indirect way so it might have economic value as a fast or slow fill.
* @param deposit Deposit to check.
* @returns True if deposit's input amount is 0 and message is empty.
*/
export function isZeroValueDeposit(deposit: Pick<Deposit, "inputAmount" | "message">): boolean {
return deposit.inputAmount.eq(0) && isMessageEmpty(deposit.message);
}

/**
* Determines if a message is empty or not.
* @param message The message to check.
Expand Down

0 comments on commit a7615d0

Please sign in to comment.