Skip to content

Commit

Permalink
feat(Dataworker): Support pre-fill refunds and duplicate deposits (ac…
Browse files Browse the repository at this point in the history
…ross-protocol#2010)

* feat(Dataworker): Support pre-fill refunds

This PR should be backwards compatible and deployable to production today

to be paired with across-protocol/sdk#835

* Finish new tests

* Update Dataworker.buildRoots.ts

* Revert "Update Dataworker.buildRoots.ts"

This reverts commit 40ad15f.

* Add test against duplicate deposits

* Add unit tests for duplicate deposits

* Import beta sdk

* import sdk

* update import

* Update package.json

* Update config.yml

* wip

* Fix tests

* Update SpokePoolUtils.ts

* Update SpokePoolUtils.ts

* Update Dataworker.loadData.prefill.ts

* Add tests for zero value deposits

* Split up tests to speed up CI

* import

* Update package.json

* Update yarn.lock

* import

* Fix tests

* fix

* bump

* Remove mocked version bump in non-prefill tests

* wip

* lint

* bump

* bump

* fix

* import

* fix

* Update Dataworker.loadData.fill.ts

* Fix tests

* move some bytes32 invalid test cases to pre-fills because they hit pre-fill logic

* WIP

* Update Dataworker.loadData.prefill.ts

* update

* WIP

* fix

* wip

* update

* fix

* Update Dataworker.loadData.prefill.ts

* fix

* bump package to new duplicate refund version

* Add test cases for historical deposit query when matched deposit is in future bundle

* fix

* Update Dataworker.loadData.fill.ts

* Update Dataworker.loadData.fill.ts

* pay refunds to pre-filler unless slow fill

* Update Dataworker.loadData.prefill.ts

* Update Dataworker.loadData.prefill.ts

* fix

* Add verifyFillRepayment test for pre fills

* add asserts

* wip

* 34

* fix test

* 4.0.0

* Update Constants.ts
  • Loading branch information
nicholaspai authored Feb 3, 2025
1 parent c5fb4a3 commit 14f6d60
Show file tree
Hide file tree
Showing 10 changed files with 2,360 additions and 821 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@across-protocol/constants": "^3.1.30",
"@across-protocol/contracts": "^3.0.25",
"@across-protocol/sdk": "^3.4.20",
"@across-protocol/sdk": "^4.0.0",
"@arbitrum/sdk": "^4.0.2",
"@consensys/linea-sdk": "^0.2.1",
"@defi-wonderland/smock": "^2.3.5",
Expand Down
7 changes: 3 additions & 4 deletions scripts/withdrawFromOpStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ export async function run(): Promise<void> {
"0x", // _data
];

const functionNameToCall = l1TokenInfo.symbol === "ETH" ? "bridgeETHTo" : "bridgeERC20To";
console.log(
`Submitting bridgeETHTo on the OVM standard bridge @ ${ovmStandardBridge.address} with the following args: `,
`Submitting ${functionNameToCall} on the OVM standard bridge @ ${ovmStandardBridge.address} with the following args: `,
...bridgeArgs
);

Expand All @@ -122,9 +123,7 @@ export async function run(): Promise<void> {
if (!(await askYesNoQuestion("\nDo you want to proceed?"))) {
return;
}
const withdrawal = await ovmStandardBridge[l1TokenInfo.symbol === "ETH" ? "bridgeETHTo" : "bridgeERC20To"](
...bridgeArgs
);
const withdrawal = await ovmStandardBridge[functionNameToCall](...bridgeArgs);
console.log(`Submitted withdrawal: ${blockExplorerLink(withdrawal.hash, chainId)}.`);
const receipt = await withdrawal.wait();
console.log("Receipt", receipt);
Expand Down
559 changes: 559 additions & 0 deletions test/Dataworker.loadData.deposit.ts

Large diffs are not rendered by default.

627 changes: 268 additions & 359 deletions test/Dataworker.loadData.fill.ts

Large diffs are not rendered by default.

775 changes: 775 additions & 0 deletions test/Dataworker.loadData.prefill.ts

Large diffs are not rendered by default.

585 changes: 134 additions & 451 deletions test/Dataworker.loadData.slowFill.ts

Large diffs are not rendered by default.

580 changes: 580 additions & 0 deletions test/Dataworker.loadData.unexecutableSlowFill.ts

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion test/mocks/MockBundleDataClient.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { BundleDataClient } from "../../src/clients";
import { BundleDataClient, SpokePoolClient } from "../../src/clients";
import { CombinedRefunds } from "../../src/dataworker/DataworkerUtils";
import { DepositWithBlock, FillWithBlock } from "../../src/interfaces";

export class MockBundleDataClient extends BundleDataClient {
private pendingBundleRefunds: CombinedRefunds = {};
private nextBundleRefunds: CombinedRefunds = {};
private matchingFillEvents: Record<string, FillWithBlock> = {};

async getPendingRefundsFromValidBundles(): Promise<CombinedRefunds[]> {
return [this.pendingBundleRefunds];
Expand All @@ -28,4 +30,19 @@ export class MockBundleDataClient extends BundleDataClient {
getPersistedNextBundleRefunds(): Promise<CombinedRefunds | undefined> {
return Promise.resolve(undefined);
}

setMatchingFillEvent(deposit: DepositWithBlock, fill: FillWithBlock): void {
const relayDataHash = this.getRelayHashFromEvent(deposit);
this.matchingFillEvents[relayDataHash] = fill;
}

findMatchingFillEvent(
deposit: DepositWithBlock,
spokePoolClient: SpokePoolClient
): Promise<FillWithBlock | undefined> {
const relayDataHash = this.getRelayHashFromEvent(deposit);
return this.matchingFillEvents[relayDataHash]
? Promise.resolve(this.matchingFillEvents[relayDataHash])
: super.findMatchingFillEvent(deposit, spokePoolClient);
}
}
19 changes: 18 additions & 1 deletion test/mocks/MockSpokePoolClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { clients } from "@across-protocol/sdk";
import { clients, interfaces } from "@across-protocol/sdk";
import { Deposit } from "../../src/interfaces";
export class MockSpokePoolClient extends clients.mocks.MockSpokePoolClient {
public maxFillDeadlineOverride?: number;
public oldestBlockTimestampOverride?: number;
private relayFillStatuses: Record<string, interfaces.FillStatus> = {};

public setMaxFillDeadlineOverride(maxFillDeadlineOverride?: number): void {
this.maxFillDeadlineOverride = maxFillDeadlineOverride;
Expand All @@ -18,4 +20,19 @@ export class MockSpokePoolClient extends clients.mocks.MockSpokePoolClient {
public getOldestTime(): number {
return this.oldestBlockTimestampOverride ?? super.getOldestTime();
}

public setRelayFillStatus(deposit: Deposit, fillStatus: interfaces.FillStatus): void {
const relayDataHash = deposit.depositId.toString();
this.relayFillStatuses[relayDataHash] = fillStatus;
}
public relayFillStatus(
relayData: interfaces.RelayData,
blockTag?: number | "latest",
destinationChainId?: number
): Promise<interfaces.FillStatus> {
const relayDataHash = relayData.depositId.toString();
return this.relayFillStatuses[relayDataHash]
? Promise.resolve(this.relayFillStatuses[relayDataHash])
: super.relayFillStatus(relayData, blockTag, destinationChainId);
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
yargs "^17.7.2"
zksync-web3 "^0.14.3"

"@across-protocol/sdk@^3.4.20":
version "3.4.20"
resolved "https://registry.yarnpkg.com/@across-protocol/sdk/-/sdk-3.4.20.tgz#0fa2b223e264fc8ff9ea47ab9e65ad9cd176848d"
integrity sha512-HUgWYfbH0haa2r9nl892IE6U+z+QtowcYwHzcimiBlux2+tn6Ztq80CEOpp1367GB4gBiWz1stL5TQfRi+vxtg==
"@across-protocol/sdk@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@across-protocol/sdk/-/sdk-4.0.0.tgz#83242907471577a8fe670dcee3d633b2338d15b9"
integrity sha512-qDkOYHlQy8KhT5WStRXJybp84pFuxQc4MgMwZzOOBTvvrGWtklSpWY9NT8Uu3Rd9v9Yn+oa/MRURdFmeMsJnrg==
dependencies:
"@across-protocol/across-token" "^1.0.0"
"@across-protocol/constants" "^3.1.30"
Expand Down

0 comments on commit 14f6d60

Please sign in to comment.