Skip to content

Commit

Permalink
feat: Permit querying SpokePool relayFills mapping directly (#484)
Browse files Browse the repository at this point in the history
Can be useful as an RPC polygraph test.
  • Loading branch information
pxrl authored Jan 3, 2024
1 parent a2d6651 commit b62c83c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/utils/SpokeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Contract } from "ethers";
import { getRelayHash } from "@across-protocol/contracts-v2/dist/test-utils";
import { BigNumber, Contract } from "ethers";
import { RelayData } from "../interfaces";
import { SpokePoolClient } from "../clients";

/**
Expand Down Expand Up @@ -155,3 +157,23 @@ export async function getDepositIdAtBlock(contract: Contract, blockTag: number):
}
return depositIdAtBlock;
}

export function relayFilledAmount(
spokePool: Contract,
relayData: RelayData,
blockTag?: number | "latest"
): Promise<BigNumber> {
const hash = getRelayHash(
relayData.depositor,
relayData.recipient,
relayData.depositId,
relayData.originChainId,
relayData.destinationChainId,
relayData.destinationToken,
relayData.amount,
relayData.realizedLpFeePct,
relayData.relayerFeePct
).relayHash;

return spokePool.relayFills(hash, { blockTag });
}
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export * from "./ReviverUtils";
export * from "./DepositUtils";
export * from "./ValidatorUtils";
export * from "./AddressUtils";
export * from "./SpokeUtils";
14 changes: 13 additions & 1 deletion test/SpokePoolClient.ValidateFill.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RelayData } from "../src/interfaces";
import {
expect,
toBNWei,
Expand Down Expand Up @@ -28,7 +29,7 @@ import {

import { SpokePoolClient } from "../src/clients";
import { MockConfigStoreClient, MockHubPoolClient, MockSpokePoolClient } from "./mocks";
import { validateFillForDeposit, queryHistoricalDepositForFill } from "../src/utils";
import { relayFilledAmount, validateFillForDeposit, queryHistoricalDepositForFill } from "../src/utils";
import { CHAIN_ID_TEST_LIST, repaymentChainId } from "./constants";

let spokePool_1: Contract, erc20_1: Contract, spokePool_2: Contract, erc20_2: Contract, hubPool: Contract;
Expand Down Expand Up @@ -103,6 +104,17 @@ describe("SpokePoolClient: Fill Validation", function () {
await spokePool_1.setCurrentTime(await getLastBlockTime(spokePool_1.provider));
});

it("Tracks fill status", async function () {
const deposit = await buildDeposit(hubPoolClient, spokePool_1, erc20_1, depositor, destinationChainId);

let filled = await relayFilledAmount(spokePool_2, deposit as RelayData);
expect(filled.eq(0)).is.true;

await buildFill(spokePool_2, erc20_2, depositor, relayer, deposit, 1);
filled = await relayFilledAmount(spokePool_2, deposit as RelayData);
expect(filled.eq(deposit.amount)).is.true;
});

it("Accepts valid fills", async function () {
const deposit = await buildDeposit(hubPoolClient, spokePool_1, erc20_1, depositor, destinationChainId);
await buildFill(spokePool_2, erc20_2, depositor, relayer, deposit, 1);
Expand Down

0 comments on commit b62c83c

Please sign in to comment.