Skip to content

Commit

Permalink
Merge branch 'master' into pxrl/invalidFillReason
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl authored Jan 3, 2024
2 parents 24aa21a + b62c83c commit de11a60
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 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-v2",
"author": "UMA Team",
"version": "0.18.1",
"version": "0.19.0",
"license": "AGPL-3.0",
"homepage": "https://docs.across.to/v/developer-docs/developers/across-sdk",
"files": [
Expand Down
9 changes: 1 addition & 8 deletions src/clients/SpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,20 +677,13 @@ export class SpokePoolClient extends BaseAbstractClient {
}
});
this.earlyDeposits = earlyDeposits;

const dataForQuoteTime = await this.batchComputeRealizedLpFeePct(depositEvents);
this.logger.debug({
at: "SpokePoolClient",
message: `Computed ${dataForQuoteTime.length} realizedLpFees on ${this.chainId}!`,
});

// Now add any newly fetched events from RPC.
if (depositEvents.length > 0) {
this.log("debug", `Using ${depositEvents.length} newly queried deposit events for chain ${this.chainId}`, {
earliestEvent: depositEvents[0].blockNumber,
});
}

const dataForQuoteTime = await this.batchComputeRealizedLpFeePct(depositEvents);
for (const [index, event] of Array.from(depositEvents.entries())) {
const rawDeposit = spreadEventWithBlockNumber(event) as DepositWithBlock;

Expand Down
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 { InvalidFill, validateFillForDeposit, queryHistoricalDepositForFill } from "../src/utils";
import { InvalidFill, 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 de11a60

Please sign in to comment.