diff --git a/src/clients/HubPoolClient.ts b/src/clients/HubPoolClient.ts index 5f54dd81c..bd5df59b3 100644 --- a/src/clients/HubPoolClient.ts +++ b/src/clients/HubPoolClient.ts @@ -1,8 +1,9 @@ import { clients } from "@across-protocol/sdk-v2"; -import { Contract } from "ethers"; +import { BigNumber, Contract } from "ethers"; import winston from "winston"; import { MakeOptional, EventSearchConfig } from "../utils"; import { IGNORED_HUB_EXECUTED_BUNDLES, IGNORED_HUB_PROPOSED_BUNDLES } from "../common"; +import { DepositWithBlock } from "../interfaces"; export class HubPoolClient extends clients.HubPoolClient { constructor( @@ -18,4 +19,20 @@ export class HubPoolClient extends clients.HubPoolClient { ignoredHubProposedBundles: IGNORED_HUB_PROPOSED_BUNDLES, }); } + + async computeRealizedLpFeePct( + deposit: Pick< + DepositWithBlock, + "quoteTimestamp" | "amount" | "destinationChainId" | "originChainId" | "blockNumber" + >, + l1Token: string + ): Promise<{ realizedLpFeePct: BigNumber | undefined; quoteBlock: number }> { + if (deposit.quoteTimestamp > this.currentTime) { + throw new Error( + `Cannot compute lp fee percent for quote timestamp ${deposit.quoteTimestamp} in the future. Current time: ${this.currentTime}.` + ); + } + + return await super.computeRealizedLpFeePct(deposit, l1Token); + } } diff --git a/src/clients/SpokePoolClient.ts b/src/clients/SpokePoolClient.ts index 09c2c796e..ea662d36d 100644 --- a/src/clients/SpokePoolClient.ts +++ b/src/clients/SpokePoolClient.ts @@ -1,3 +1,13 @@ import { clients } from "@across-protocol/sdk-v2"; +import { FundsDepositedEvent } from "../interfaces"; +import { isDefined } from "../utils/TypeGuards"; -export class SpokePoolClient extends clients.SpokePoolClient {} +export class SpokePoolClient extends clients.SpokePoolClient { + _isEarlyDeposit(depositEvent: FundsDepositedEvent, currentTime: number): boolean { + const hubCurrentTime = this.hubPoolClient?.currentTime; + if (!isDefined(hubCurrentTime)) { + throw new Error("HubPoolClient's currentTime is not defined"); + } + return depositEvent.args.quoteTimestamp > currentTime || depositEvent.args.quoteTimestamp > hubCurrentTime; + } +} diff --git a/test/HubPoolClient.Utilization.ts b/test/HubPoolClient.Utilization.ts index a2f96f6b0..0f92ada21 100644 --- a/test/HubPoolClient.Utilization.ts +++ b/test/HubPoolClient.Utilization.ts @@ -1,4 +1,4 @@ -import { HubPoolClient } from "../src/clients"; +import { clients } from "@across-protocol/sdk-v2"; import { amountToLp, destinationChainId, @@ -29,7 +29,7 @@ import { let configStore: Contract, hubPool: Contract; let l1Token: Contract, l2Token: Contract, timer: Contract, weth: Contract; -let configStoreClient: MockConfigStoreClient, hubPoolClient: HubPoolClient; +let configStoreClient: MockConfigStoreClient, hubPoolClient: clients.HubPoolClient; let owner: SignerWithAddress; // Same rate model used for across-v1 tests: @@ -96,7 +96,11 @@ describe("HubPool Utilization", async function () { await configStoreClient.update(); - hubPoolClient = new HubPoolClient(createSpyLogger().spyLogger, hubPool, configStoreClient); + hubPoolClient = new clients.HubPoolClient( + createSpyLogger().spyLogger, + hubPool, + configStoreClient as unknown as clients.AcrossConfigStoreClient + ); await configStoreClient.update(); await hubPoolClient.update(); }); diff --git a/test/Relayer.BasicFill.ts b/test/Relayer.BasicFill.ts index d33c06899..ecad12c18 100644 --- a/test/Relayer.BasicFill.ts +++ b/test/Relayer.BasicFill.ts @@ -1,12 +1,5 @@ import { random } from "lodash"; -import { - AcrossApiClient, - ConfigStoreClient, - HubPoolClient, - MultiCallerClient, - SpokePoolClient, - TokenClient, -} from "../src/clients"; +import { AcrossApiClient, ConfigStoreClient, MultiCallerClient, TokenClient } from "../src/clients"; import { CONFIG_STORE_VERSION, UBA_MIN_CONFIG_STORE_VERSION } from "../src/common"; import { Deposit } from "../src/interfaces"; import { Relayer } from "../src/relayer/Relayer"; @@ -45,15 +38,16 @@ import { winston, } from "./utils"; import { generateNoOpSpokePoolClientsForDefaultChainIndices } from "./utils/UBAUtils"; +import { clients } from "@across-protocol/sdk-v2"; let spokePool_1: Contract, erc20_1: Contract, spokePool_2: Contract, erc20_2: Contract; let hubPool: Contract, configStore: Contract, l1Token: Contract; let owner: SignerWithAddress, depositor: SignerWithAddress, relayer: SignerWithAddress; let spy: sinon.SinonSpy, spyLogger: winston.Logger; -let spokePoolClient_1: SpokePoolClient, spokePoolClient_2: SpokePoolClient; -let spokePoolClients: { [chainId: number]: SpokePoolClient }; -let configStoreClient: ConfigStoreClient, hubPoolClient: HubPoolClient, tokenClient: TokenClient; +let spokePoolClient_1: clients.SpokePoolClient, spokePoolClient_2: clients.SpokePoolClient; +let spokePoolClients: { [chainId: number]: clients.SpokePoolClient }; +let configStoreClient: ConfigStoreClient, hubPoolClient: clients.HubPoolClient, tokenClient: TokenClient; let relayerInstance: Relayer; let multiCallerClient: MultiCallerClient, profitClient: MockProfitClient; let spokePool1DeploymentBlock: number, spokePool2DeploymentBlock: number; @@ -99,19 +93,19 @@ describe("Relayer: Check for Unfilled Deposits and Fill", async function () { ) as unknown as ConfigStoreClient; await configStoreClient.update(); - hubPoolClient = new HubPoolClient(spyLogger, hubPool, configStoreClient); + hubPoolClient = new clients.HubPoolClient(spyLogger, hubPool, configStoreClient); await hubPoolClient.update(); multiCallerClient = new MockedMultiCallerClient(spyLogger); - spokePoolClient_1 = new SpokePoolClient( + spokePoolClient_1 = new clients.SpokePoolClient( spyLogger, spokePool_1.connect(relayer), hubPoolClient, originChainId, spokePool1DeploymentBlock ); - spokePoolClient_2 = new SpokePoolClient( + spokePoolClient_2 = new clients.SpokePoolClient( spyLogger, spokePool_2.connect(relayer), hubPoolClient, @@ -477,7 +471,11 @@ describe("Relayer: Check for Unfilled Deposits and Fill", async function () { const version = UBA_MIN_CONFIG_STORE_VERSION; configStoreClient = new ConfigStoreClient(spyLogger, configStore, { fromBlock: 0 }, version); await configStoreClient.update(); - hubPoolClient = new HubPoolClient(spyLogger, hubPool, configStoreClient); + hubPoolClient = new clients.HubPoolClient( + spyLogger, + hubPool, + configStoreClient as unknown as clients.AcrossConfigStoreClient + ); relayerInstance = new Relayer( relayer.address, spyLogger, diff --git a/test/Relayer.UnfilledDeposits.ts b/test/Relayer.UnfilledDeposits.ts index ae7958382..077d5881b 100644 --- a/test/Relayer.UnfilledDeposits.ts +++ b/test/Relayer.UnfilledDeposits.ts @@ -1,12 +1,4 @@ -import { - AcrossApiClient, - ConfigStoreClient, - HubPoolClient, - MultiCallerClient, - SpokePoolClient, - TokenClient, - UBAClient, -} from "../src/clients"; +import { AcrossApiClient, ConfigStoreClient, MultiCallerClient, TokenClient, UBAClient } from "../src/clients"; import { CHAIN_ID_TEST_LIST, amountToLp, @@ -35,6 +27,7 @@ import { simpleDeposit, toBNWei, } from "./utils"; +import { clients } from "@across-protocol/sdk-v2"; // Tested import { Relayer } from "../src/relayer/Relayer"; @@ -46,8 +39,8 @@ let hubPool: Contract, l1Token: Contract, configStore: Contract; let owner: SignerWithAddress, depositor: SignerWithAddress, relayer: SignerWithAddress; const { spy, spyLogger } = createSpyLogger(); -let spokePoolClient_1: SpokePoolClient, spokePoolClient_2: SpokePoolClient; -let configStoreClient: MockConfigStoreClient, hubPoolClient: HubPoolClient; +let spokePoolClient_1: clients.SpokePoolClient, spokePoolClient_2: clients.SpokePoolClient; +let configStoreClient: MockConfigStoreClient, hubPoolClient: clients.HubPoolClient; let multiCallerClient: MultiCallerClient, tokenClient: TokenClient; let profitClient: MockProfitClient; let spokePool1DeploymentBlock: number, spokePool2DeploymentBlock: number; @@ -93,17 +86,17 @@ describe("Relayer: Unfilled Deposits", async function () { configStoreClient = new MockConfigStoreClient(spyLogger, configStore, undefined, undefined, CHAIN_ID_TEST_LIST); await configStoreClient.update(); - hubPoolClient = new HubPoolClient(spyLogger, hubPool, configStoreClient); + hubPoolClient = new clients.HubPoolClient(spyLogger, hubPool, configStoreClient); await hubPoolClient.update(); - spokePoolClient_1 = new SpokePoolClient( + spokePoolClient_1 = new clients.SpokePoolClient( spyLogger, spokePool_1, hubPoolClient, originChainId, spokePool1DeploymentBlock ); - spokePoolClient_2 = new SpokePoolClient( + spokePoolClient_2 = new clients.SpokePoolClient( spyLogger, spokePool_2, hubPoolClient, diff --git a/test/SpokePoolClient.SpeedUp.ts b/test/SpokePoolClient.SpeedUp.ts index c808aa483..45afdc31b 100644 --- a/test/SpokePoolClient.SpeedUp.ts +++ b/test/SpokePoolClient.SpeedUp.ts @@ -14,14 +14,14 @@ import { toBNWei, } from "./utils"; -import { SpokePoolClient } from "../src/clients"; +import { clients } from "@across-protocol/sdk-v2"; import { DepositWithBlock } from "../src/interfaces"; let spokePool: Contract, erc20: Contract, destErc20: Contract, weth: Contract; let depositor: SignerWithAddress, deploymentBlock: number; const destinationChainId2 = destinationChainId + 1; -let spokePoolClient: SpokePoolClient; +let spokePoolClient: clients.SpokePoolClient; describe("SpokePoolClient: SpeedUp", async function () { const ignoredFields = [ @@ -37,7 +37,13 @@ describe("SpokePoolClient: SpeedUp", async function () { [, depositor] = await ethers.getSigners(); ({ spokePool, erc20, destErc20, weth, deploymentBlock } = await deploySpokePoolWithToken(originChainId)); await enableRoutes(spokePool, [{ originToken: erc20.address, destinationChainId: destinationChainId2 }]); - spokePoolClient = new SpokePoolClient(createSpyLogger().spyLogger, spokePool, null, originChainId, deploymentBlock); + spokePoolClient = new clients.SpokePoolClient( + createSpyLogger().spyLogger, + spokePool, + null, + originChainId, + deploymentBlock + ); await setupTokensForWallet(spokePool, depositor, [erc20, destErc20], weth, 10); }); diff --git a/test/SpokePoolClient.ValidateFill.ts b/test/SpokePoolClient.ValidateFill.ts index a2b1a9ec5..83ca7dbbd 100644 --- a/test/SpokePoolClient.ValidateFill.ts +++ b/test/SpokePoolClient.ValidateFill.ts @@ -27,10 +27,10 @@ import { sinon, } from "./utils"; -import { ConfigStoreClient, HubPoolClient, SpokePoolClient } from "../src/clients"; +import { ConfigStoreClient } from "../src/clients"; import { queryHistoricalDepositForFill } from "../src/utils"; import { MockConfigStoreClient, MockSpokePoolClient } from "./mocks"; -import { utils } from "@across-protocol/sdk-v2"; +import { utils, clients } from "@across-protocol/sdk-v2"; import { CHAIN_ID_TEST_LIST, repaymentChainId } from "./constants"; const { validateFillForDeposit } = utils; @@ -40,8 +40,8 @@ let spokePool1DeploymentBlock: number, spokePool2DeploymentBlock: number; let l1Token: Contract, configStore: Contract; let spy: sinon.SinonSpy, spyLogger: winston.Logger; -let spokePoolClient2: SpokePoolClient, hubPoolClient: HubPoolClient; -let spokePoolClient1: SpokePoolClient, configStoreClient: ConfigStoreClient; +let spokePoolClient2: clients.SpokePoolClient, hubPoolClient: clients.HubPoolClient; +let spokePoolClient1: clients.SpokePoolClient, configStoreClient: ConfigStoreClient; describe("SpokePoolClient: Fill Validation", async function () { beforeEach(async function () { @@ -81,17 +81,21 @@ describe("SpokePoolClient: Fill Validation", async function () { ) as unknown as ConfigStoreClient; await configStoreClient.update(); - hubPoolClient = new HubPoolClient(spyLogger, hubPool, configStoreClient); + hubPoolClient = new clients.HubPoolClient( + spyLogger, + hubPool, + configStoreClient as unknown as clients.AcrossConfigStoreClient + ); await hubPoolClient.update(); - spokePoolClient1 = new SpokePoolClient( + spokePoolClient1 = new clients.SpokePoolClient( spyLogger, spokePool_1, hubPoolClient, originChainId, spokePool1DeploymentBlock ); - spokePoolClient2 = new SpokePoolClient( + spokePoolClient2 = new clients.SpokePoolClient( createSpyLogger().spyLogger, spokePool_2, null, @@ -132,7 +136,7 @@ describe("SpokePoolClient: Fill Validation", async function () { it("Returns deposit matched with fill", async function () { const deposit_1 = await buildDeposit(hubPoolClient, spokePool_1, erc20_1, l1Token, depositor, destinationChainId); const fill_1 = await buildFill(spokePool_2, erc20_2, depositor, relayer, deposit_1, 0.5); - const spokePoolClientForDestinationChain = new SpokePoolClient( + const spokePoolClientForDestinationChain = new clients.SpokePoolClient( createSpyLogger().spyLogger, spokePool_1, null, @@ -488,7 +492,7 @@ describe("SpokePoolClient: Fill Validation", async function () { const fill_1 = await buildFill(spokePool_2, erc20_2, depositor, relayer, expectedDeposit, 0.2); const fill_2 = await buildModifiedFill(spokePool_2, depositor, relayer, fill_1, 2, 0.2, relayer.address, "0x12"); // Fill same % of deposit with 2x larger relayer fee pct. - const spokePoolClientForDestinationChain = new SpokePoolClient( + const spokePoolClientForDestinationChain = new clients.SpokePoolClient( createSpyLogger().spyLogger, spokePool_1, null, diff --git a/test/SpokePoolClient.deposits.ts b/test/SpokePoolClient.deposits.ts index ae493e27b..299628476 100644 --- a/test/SpokePoolClient.deposits.ts +++ b/test/SpokePoolClient.deposits.ts @@ -1,4 +1,4 @@ -import { SpokePoolClient } from "../src/clients"; +import { clients } from "@across-protocol/sdk-v2"; import { Contract, SignerWithAddress, @@ -18,14 +18,20 @@ let depositor1: SignerWithAddress, depositor2: SignerWithAddress; let deploymentBlock: number; const destinationChainId2 = destinationChainId + 1; -let spokePoolClient: SpokePoolClient; +let spokePoolClient: clients.SpokePoolClient; describe("SpokePoolClient: Deposits", async function () { beforeEach(async function () { [, depositor1, depositor2] = await ethers.getSigners(); ({ spokePool, erc20, destErc20, weth, deploymentBlock } = await deploySpokePoolWithToken(originChainId)); await enableRoutes(spokePool, [{ originToken: erc20.address, destinationChainId: destinationChainId2 }]); - spokePoolClient = new SpokePoolClient(createSpyLogger().spyLogger, spokePool, null, originChainId, deploymentBlock); + spokePoolClient = new clients.SpokePoolClient( + createSpyLogger().spyLogger, + spokePool, + null, + originChainId, + deploymentBlock + ); await setupTokensForWallet(spokePool, depositor1, [erc20, destErc20], weth, 10); await setupTokensForWallet(spokePool, depositor2, [erc20, destErc20], weth, 10); diff --git a/test/fixtures/Dataworker.Fixture.ts b/test/fixtures/Dataworker.Fixture.ts index 41767f949..718062a55 100644 --- a/test/fixtures/Dataworker.Fixture.ts +++ b/test/fixtures/Dataworker.Fixture.ts @@ -29,20 +29,21 @@ import { BundleDataClient, TokenClient } from "../../src/clients"; import { DataworkerClients } from "../../src/dataworker/DataworkerClientHelper"; import { MockConfigStoreClient, MockedMultiCallerClient } from "../mocks"; import { EthersTestLibrary } from "../types"; +import { clients as sdkClients } from "@across-protocol/sdk-v2"; async function _constructSpokePoolClientsWithLookback( spokePools: Contract[], spokePoolChains: number[], spyLogger: winston.Logger, signer: SignerWithAddress, - hubPoolClient: clients.HubPoolClient, + hubPoolClient: sdkClients.HubPoolClient, lookbackForAllChains?: number, deploymentBlocks?: { [chainId: number]: number } ) { await hubPoolClient.update(); const latestBlocks = await Promise.all(spokePools.map((x) => x.provider.getBlockNumber())); return spokePools.map((pool, i) => { - return new clients.SpokePoolClient( + return new sdkClients.SpokePoolClient( spyLogger, pool.connect(signer), hubPoolClient, @@ -72,14 +73,14 @@ export async function setupDataworker( l1Token_2: Contract; configStore: Contract; timer: Contract; - spokePoolClient_1: clients.SpokePoolClient; - spokePoolClient_2: clients.SpokePoolClient; - spokePoolClient_3: clients.SpokePoolClient; - spokePoolClient_4: clients.SpokePoolClient; - spokePoolClients: { [chainId: number]: clients.SpokePoolClient }; + spokePoolClient_1: sdkClients.SpokePoolClient; + spokePoolClient_2: sdkClients.SpokePoolClient; + spokePoolClient_3: sdkClients.SpokePoolClient; + spokePoolClient_4: sdkClients.SpokePoolClient; + spokePoolClients: { [chainId: number]: sdkClients.SpokePoolClient }; mockedConfigStoreClient: MockConfigStoreClient; - configStoreClient: clients.ConfigStoreClient; - hubPoolClient: clients.HubPoolClient; + configStoreClient: sdkClients.AcrossConfigStoreClient; + hubPoolClient: sdkClients.HubPoolClient; dataworkerInstance: Dataworker; spyLogger: winston.Logger; spy: sinon.SinonSpy; @@ -168,7 +169,7 @@ export async function setupDataworker( await configStoreClient.update(); - const hubPoolClient = new clients.HubPoolClient( + const hubPoolClient = new sdkClients.HubPoolClient( spyLogger, hubPool, configStoreClient, @@ -202,7 +203,7 @@ export async function setupDataworker( const bundleDataClient = new BundleDataClient( spyLogger, { - configStoreClient: configStoreClient as unknown as clients.ConfigStoreClient, + configStoreClient: configStoreClient as unknown as sdkClients.AcrossConfigStoreClient, multiCallerClient, hubPoolClient, }, @@ -215,7 +216,7 @@ export async function setupDataworker( tokenClient, hubPoolClient, multiCallerClient, - configStoreClient: configStoreClient as unknown as clients.ConfigStoreClient, + configStoreClient: configStoreClient as unknown as sdkClients.AcrossConfigStoreClient, profitClient, }; const dataworkerInstance = new Dataworker( @@ -262,7 +263,7 @@ export async function setupDataworker( spokePoolClient_3, spokePoolClient_4, spokePoolClients, - configStoreClient: configStoreClient as unknown as clients.ConfigStoreClient, + configStoreClient: configStoreClient as unknown as sdkClients.AcrossConfigStoreClient, mockedConfigStoreClient: configStoreClient, hubPoolClient, dataworkerInstance, @@ -301,14 +302,14 @@ export async function setupFastDataworker( l1Token_2: Contract; configStore: Contract; timer: Contract; - spokePoolClient_1: clients.SpokePoolClient; - spokePoolClient_2: clients.SpokePoolClient; - spokePoolClient_3: clients.SpokePoolClient; - spokePoolClient_4: clients.SpokePoolClient; - spokePoolClients: { [chainId: number]: clients.SpokePoolClient }; + spokePoolClient_1: sdkClients.SpokePoolClient; + spokePoolClient_2: sdkClients.SpokePoolClient; + spokePoolClient_3: sdkClients.SpokePoolClient; + spokePoolClient_4: sdkClients.SpokePoolClient; + spokePoolClients: { [chainId: number]: sdkClients.SpokePoolClient }; mockedConfigStoreClient: MockConfigStoreClient; - configStoreClient: clients.ConfigStoreClient; - hubPoolClient: clients.HubPoolClient; + configStoreClient: sdkClients.AcrossConfigStoreClient; + hubPoolClient: sdkClients.HubPoolClient; dataworkerInstance: Dataworker; spyLogger: winston.Logger; spy: sinon.SinonSpy;