Skip to content

Commit b62c83c

Browse files
authored
feat: Permit querying SpokePool relayFills mapping directly (#484)
Can be useful as an RPC polygraph test.
1 parent a2d6651 commit b62c83c

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/utils/SpokeUtils.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { Contract } from "ethers";
1+
import { getRelayHash } from "@across-protocol/contracts-v2/dist/test-utils";
2+
import { BigNumber, Contract } from "ethers";
3+
import { RelayData } from "../interfaces";
24
import { SpokePoolClient } from "../clients";
35

46
/**
@@ -155,3 +157,23 @@ export async function getDepositIdAtBlock(contract: Contract, blockTag: number):
155157
}
156158
return depositIdAtBlock;
157159
}
160+
161+
export function relayFilledAmount(
162+
spokePool: Contract,
163+
relayData: RelayData,
164+
blockTag?: number | "latest"
165+
): Promise<BigNumber> {
166+
const hash = getRelayHash(
167+
relayData.depositor,
168+
relayData.recipient,
169+
relayData.depositId,
170+
relayData.originChainId,
171+
relayData.destinationChainId,
172+
relayData.destinationToken,
173+
relayData.amount,
174+
relayData.realizedLpFeePct,
175+
relayData.relayerFeePct
176+
).relayHash;
177+
178+
return spokePool.relayFills(hash, { blockTag });
179+
}

src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ export * from "./ReviverUtils";
2525
export * from "./DepositUtils";
2626
export * from "./ValidatorUtils";
2727
export * from "./AddressUtils";
28+
export * from "./SpokeUtils";

test/SpokePoolClient.ValidateFill.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { RelayData } from "../src/interfaces";
12
import {
23
expect,
34
toBNWei,
@@ -28,7 +29,7 @@ import {
2829

2930
import { SpokePoolClient } from "../src/clients";
3031
import { MockConfigStoreClient, MockHubPoolClient, MockSpokePoolClient } from "./mocks";
31-
import { validateFillForDeposit, queryHistoricalDepositForFill } from "../src/utils";
32+
import { relayFilledAmount, validateFillForDeposit, queryHistoricalDepositForFill } from "../src/utils";
3233
import { CHAIN_ID_TEST_LIST, repaymentChainId } from "./constants";
3334

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

107+
it("Tracks fill status", async function () {
108+
const deposit = await buildDeposit(hubPoolClient, spokePool_1, erc20_1, depositor, destinationChainId);
109+
110+
let filled = await relayFilledAmount(spokePool_2, deposit as RelayData);
111+
expect(filled.eq(0)).is.true;
112+
113+
await buildFill(spokePool_2, erc20_2, depositor, relayer, deposit, 1);
114+
filled = await relayFilledAmount(spokePool_2, deposit as RelayData);
115+
expect(filled.eq(deposit.amount)).is.true;
116+
});
117+
106118
it("Accepts valid fills", async function () {
107119
const deposit = await buildDeposit(hubPoolClient, spokePool_1, erc20_1, depositor, destinationChainId);
108120
await buildFill(spokePool_2, erc20_2, depositor, relayer, deposit, 1);

0 commit comments

Comments
 (0)