diff --git a/src/clients/ProfitClient.ts b/src/clients/ProfitClient.ts index 6ba204268..303dd92b2 100644 --- a/src/clients/ProfitClient.ts +++ b/src/clients/ProfitClient.ts @@ -97,9 +97,9 @@ export class ProfitClient { readonly hubPoolClient: HubPoolClient, spokePoolClients: SpokePoolClientsByChain, readonly enabledChainIds: number[], - readonly defaultMinRelayerFeePct: BigNumber = toBNWei(constants.RELAYER_MIN_FEE_PCT), - readonly debugProfitability: boolean = false, - protected gasMultiplier: BigNumber = toBNWei(1) + readonly defaultMinRelayerFeePct = toBNWei(constants.RELAYER_MIN_FEE_PCT), + readonly debugProfitability = false, + protected gasMultiplier = toBNWei(1) ) { // Require 1% <= gasMultiplier <= 400% assert( diff --git a/test/ProfitClient.ConsiderProfitability.ts b/test/ProfitClient.ConsiderProfitability.ts index 97431c878..6b8455a33 100644 --- a/test/ProfitClient.ConsiderProfitability.ts +++ b/test/ProfitClient.ConsiderProfitability.ts @@ -1,3 +1,4 @@ +import { assert } from "chai"; import { utils as sdkUtils } from "@across-protocol/sdk-v2"; import { ConfigStoreClient, @@ -24,11 +25,18 @@ import { winston, } from "./utils"; -const { fixedPointAdjustment: fixedPoint } = sdkUtils; +const { bnZero, fixedPointAdjustment: fixedPoint, toGWei } = sdkUtils; const { formatEther } = ethers.utils; -const chainIds: number[] = [1, 10, 137, 288, 42161]; -const zeroRefundFee = toBN(0); +const chainIds = [originChainId, destinationChainId]; +const zeroRefundFee = bnZero; + +const minRelayerFeeBps = 3; +const minRelayerFeePct = toBNWei(minRelayerFeeBps).div(1e4); + +// relayerFeePct clamped at 50 bps by each SpokePool. +const maxRelayerFeeBps = 50; +const maxRelayerFeePct = toBNWei(maxRelayerFeeBps).div(1e4); const tokens: { [symbol: string]: L1Token } = { MATIC: { address: MATIC, decimals: 18, symbol: "MATIC" }, @@ -47,8 +55,8 @@ const tokenPrices: { [symbol: string]: BigNumber } = { // Quirk: Use the chainId as the gas price in Gwei. This gives a range of // gas prices to test with, since there's a spread in the chainId numbers. const gasCost: { [chainId: number]: BigNumber } = Object.fromEntries( - chainIds.map((chainId: number) => { - const nativeGasPrice = toBN(chainId).mul(1e9); // Gwei + chainIds.map((chainId) => { + const nativeGasPrice = toGWei(chainId); const gasConsumed = toBN(100_000); // Assume 100k gas for a single fill return [chainId, gasConsumed.mul(nativeGasPrice)]; }) @@ -61,17 +69,6 @@ function setDefaultTokenPrices(profitClient: MockProfitClient): void { ); } -const minRelayerFeeBps = 3; -const minRelayerFeePct = toBNWei(minRelayerFeeBps).div(1e4); - -// relayerFeePct clamped at 50 bps by each SpokePool. -const maxRelayerFeeBps = 50; -const maxRelayerFeePct = toBNWei(maxRelayerFeeBps).div(1e4); - -// Define LOG_IN_TEST for logging to console. -const { spyLogger }: { spyLogger: winston.Logger } = createSpyLogger(); -let hubPoolClient: MockHubPoolClient, profitClient: MockProfitClient; - function testProfitability( deposit: Deposit, fillAmountUsd: BigNumber, @@ -98,8 +95,12 @@ function testProfitability( } as FillProfit; } -describe("ProfitClient: Consider relay profit", async function () { - beforeEach(async function () { +describe("ProfitClient: Consider relay profit", () => { + // Define LOG_IN_TEST for logging to console. + const { spyLogger }: { spyLogger: winston.Logger } = createSpyLogger(); + let hubPoolClient: MockHubPoolClient, profitClient: MockProfitClient; + + beforeEach(async () => { const [owner] = await ethers.getSigners(); const logger = createSpyLogger().spyLogger; @@ -113,33 +114,27 @@ describe("ProfitClient: Consider relay profit", async function () { await hubPoolClient.update(); - const { spokePool: spokePool_1, deploymentBlock: spokePool1DeploymentBlock } = await deploySpokePoolWithToken( - originChainId, - destinationChainId - ); - const { spokePool: spokePool_2, deploymentBlock: spokePool2DeploymentBlock } = await deploySpokePoolWithToken( - destinationChainId, - originChainId - ); - - const spokePoolClient_1 = new SpokePoolClient( - spyLogger, - spokePool_1.connect(owner), - null, - originChainId, - spokePool1DeploymentBlock - ); - const spokePoolClient_2 = new SpokePoolClient( - spyLogger, - spokePool_2.connect(owner), - null, - destinationChainId, - spokePool2DeploymentBlock + const chainIds = [originChainId, destinationChainId]; + assert(chainIds.length === 2, "SpokePool deployment requires only 2 chainIds"); + const spokePoolClients = Object.fromEntries( + await sdkUtils.mapAsync(chainIds, async (spokeChainId, idx) => { + const { spokePool, deploymentBlock } = await deploySpokePoolWithToken( + spokeChainId, + chainIds[(idx + 1) % 2] // @dev Only works for 2 chainIds. + ); + const spokePoolClient = new SpokePoolClient( + spyLogger, + spokePool.connect(owner), + null, + spokeChainId, + deploymentBlock + ); + + return [spokeChainId, spokePoolClient]; + }) ); - const spokePoolClients = { [originChainId]: spokePoolClient_1, [destinationChainId]: spokePoolClient_2 }; const debugProfitability = true; - profitClient = new MockProfitClient( spyLogger, hubPoolClient, @@ -151,35 +146,35 @@ describe("ProfitClient: Consider relay profit", async function () { // Load per-chain gas cost (gas consumed * gas price in Wei), in native gas token. profitClient.setGasCosts(gasCost); - setDefaultTokenPrices(profitClient); }); // Verify gas cost calculation first, so we can leverage it in all subsequent tests. - it("Verify gas cost estimation", function () { - chainIds.forEach((chainId: number) => { + it("Verify gas cost estimation", () => { + chainIds.forEach((chainId) => { spyLogger.debug({ message: `Verifying USD fill cost calculation for chain ${chainId}.` }); const nativeGasCost = profitClient.getTotalGasCost(chainId); expect(nativeGasCost.eq(0)).to.be.false; expect(nativeGasCost.eq(gasCost[chainId])).to.be.true; - const gasTokenAddr: string = GAS_TOKEN_BY_CHAIN_ID[chainId]; - const gasToken: L1Token = Object.values(tokens).find((token: L1Token) => gasTokenAddr === token.address); + const gasTokenAddr = GAS_TOKEN_BY_CHAIN_ID[chainId]; + let gasToken = Object.values(tokens).find((token) => gasTokenAddr === token.address); expect(gasToken).to.not.be.undefined; + gasToken = gasToken as L1Token; const gasPriceUsd = tokenPrices[gasToken.symbol]; expect(gasPriceUsd.eq(tokenPrices[gasToken.symbol])).to.be.true; - const estimate: { [key: string]: BigNumber } = profitClient.estimateFillCost(chainId); + const estimate = profitClient.estimateFillCost(chainId); expect(estimate.nativeGasCost.eq(gasCost[chainId])).to.be.true; expect(estimate.gasPriceUsd.eq(tokenPrices[gasToken.symbol])).to.be.true; expect(estimate.gasCostUsd.eq(gasPriceUsd.mul(nativeGasCost).div(toBN(10).pow(gasToken.decimals)))).to.be.true; }); }); - it("Verify gas multiplier", function () { - chainIds.forEach((chainId: number) => { + it("Verify gas multiplier", () => { + chainIds.forEach((chainId) => { spyLogger.debug({ message: `Verifying gas multiplier for chainId ${chainId}.` }); const nativeGasCost = profitClient.getTotalGasCost(chainId); @@ -190,7 +185,9 @@ describe("ProfitClient: Consider relay profit", async function () { profitClient.setGasMultiplier(toBNWei(gasMultiplier)); const gasTokenAddr = GAS_TOKEN_BY_CHAIN_ID[chainId]; - const gasToken: L1Token = Object.values(tokens).find((token: L1Token) => gasTokenAddr === token.address); + let gasToken = Object.values(tokens).find((token) => gasTokenAddr === token.address); + expect(gasToken).to.not.be.undefined; + gasToken = gasToken as L1Token; const expectedFillCostUsd = nativeGasCost .mul(tokenPrices[gasToken.symbol]) @@ -203,43 +200,42 @@ describe("ProfitClient: Consider relay profit", async function () { }); }); - it("Return 0 when gas cost fails to be fetched", async function () { - profitClient.setGasCosts({ 137: undefined }); - expect(profitClient.getTotalGasCost(137)).to.equal(toBN(0)); + it("Return 0 when gas cost fails to be fetched", () => { + const destinationChainId = 137; + profitClient.setGasCost(destinationChainId, undefined); + expect(profitClient.getTotalGasCost(destinationChainId)).to.equal(bnZero); }); - it("Verify token price and gas cost lookup failures", function () { - const l1Token: L1Token = tokens["WETH"]; + it("Verify token price and gas cost lookup failures", () => { const fillAmount = toBNWei(1); - + const l1Token = tokens["WETH"]; hubPoolClient.setTokenInfoToReturn(l1Token); - chainIds.forEach((_chainId: number) => { - const chainId = Number(_chainId); - const deposit = { - relayerFeePct: toBNWei("0.0003"), - destinationChainId: chainId, - } as Deposit; + chainIds.forEach((destinationChainId) => { + const deposit = { destinationChainId, relayerFeePct: toBNWei("0.0003") } as Deposit; // Verify that it works before we break it. expect(() => profitClient.calculateFillProfitability(deposit, fillAmount, zeroRefundFee, l1Token, minRelayerFeePct) ).to.not.throw(); - spyLogger.debug({ message: `Verifying exception on gas cost estimation lookup failure on chain ${chainId}.` }); - profitClient.setGasCosts({}); + spyLogger.debug({ message: `Verify exception on chain ${destinationChainId} gas cost estimation failure.` }); + const destinationGasCost = profitClient.getTotalGasCost(destinationChainId); + profitClient.setGasCost(destinationChainId, undefined); expect(() => profitClient.calculateFillProfitability(deposit, fillAmount, zeroRefundFee, l1Token, minRelayerFeePct) ).to.throw(); - profitClient.setGasCosts(gasCost); + profitClient.setGasCost(destinationChainId, destinationGasCost); + + spyLogger.debug({ message: `Verifying exception on chain ${destinationChainId} token price lookup failure.` }); + const l1TokenPrice = profitClient.getPriceOfToken(l1Token.address); + profitClient.setTokenPrice(l1Token.address, undefined); - spyLogger.debug({ message: `Verifying exception on token price lookup failure on chain ${chainId}.` }); - profitClient.setTokenPrices({ [l1Token.address]: toBN(0) }); // Setting price to 0 causes a downstream error in calculateFillProfitability. expect(() => profitClient.calculateFillProfitability(deposit, fillAmount, zeroRefundFee, l1Token, minRelayerFeePct) ).to.throw(); - setDefaultTokenPrices(profitClient); + profitClient.setTokenPrice(l1Token.address, l1TokenPrice); // Verify we left everything as we found it. expect(() => @@ -262,17 +258,17 @@ describe("ProfitClient: Consider relay profit", async function () { * corner cases. This approach does however require fairly careful analysis of * the test results to make sure that they are sane. Sampling is recommended. */ - it("Considers gas cost when computing profitability", async function () { + it("Considers gas cost when computing profitability", () => { const fillAmounts = [".001", "0.1", 1, 10, 100, 1_000, 100_000]; - chainIds.forEach((destinationChainId: number) => { + chainIds.forEach((destinationChainId) => { const { gasCostUsd } = profitClient.estimateFillCost(destinationChainId); - Object.values(tokens).forEach((l1Token: L1Token) => { + Object.values(tokens).forEach((l1Token) => { const tokenPriceUsd = profitClient.getPriceOfToken(l1Token.address); hubPoolClient.setTokenInfoToReturn(l1Token); - fillAmounts.forEach((_fillAmount: number | string) => { + fillAmounts.forEach((_fillAmount) => { const fillAmount = toBNWei(_fillAmount); const nativeFillAmount = toBNWei(_fillAmount, l1Token.decimals); spyLogger.debug({ message: `Testing fillAmount ${formatEther(fillAmount)}.` }); @@ -280,9 +276,9 @@ describe("ProfitClient: Consider relay profit", async function () { const fillAmountUsd = fillAmount.mul(tokenPriceUsd).div(fixedPoint); const gasCostPct = gasCostUsd.mul(fixedPoint).div(fillAmountUsd); - const relayerFeePcts: BigNumber[] = [ + const relayerFeePcts = [ toBNWei(-1), - toBNWei(0), + bnZero, minRelayerFeePct.div(4), minRelayerFeePct.div(2), minRelayerFeePct, @@ -291,7 +287,7 @@ describe("ProfitClient: Consider relay profit", async function () { minRelayerFeePct.add(gasCostPct).add(toBNWei(1)), ]; - relayerFeePcts.forEach((_relayerFeePct: BigNumber) => { + relayerFeePcts.forEach((_relayerFeePct) => { const relayerFeePct = _relayerFeePct.gt(maxRelayerFeePct) ? maxRelayerFeePct : _relayerFeePct; const deposit = { relayerFeePct, destinationChainId } as Deposit; @@ -318,14 +314,14 @@ describe("ProfitClient: Consider relay profit", async function () { }); }); - it("Considers refund fees when computing profitability", async function () { + it("Considers refund fees when computing profitability", () => { const fillAmounts = [".001", "0.1", 1, 10, 100, 1_000, 100_000]; const refundFeeMultipliers = ["-0.1", "-0.01", "-0.001", "-0.0001", 0.0001, 0.001, 0.01, 0.1, 1]; - chainIds.forEach((destinationChainId: number) => { + chainIds.forEach((destinationChainId) => { const { gasCostUsd } = profitClient.estimateFillCost(destinationChainId); - Object.values(tokens).forEach((l1Token: L1Token) => { + Object.values(tokens).forEach((l1Token) => { const tokenPriceUsd = profitClient.getPriceOfToken(l1Token.address); hubPoolClient.setTokenInfoToReturn(l1Token); @@ -372,7 +368,7 @@ describe("ProfitClient: Consider relay profit", async function () { }); }); - it("Allows per-route and per-token fee configuration", async function () { + it("Allows per-route and per-token fee configuration", () => { // Setup custom USDC pricing to Optimism. chainIds.forEach((srcChainId) => { process.env[`MIN_RELAYER_FEE_PCT_USDC_${srcChainId}_10`] = Math.random().toPrecision(10).toString(); @@ -382,44 +378,39 @@ describe("ProfitClient: Consider relay profit", async function () { const envPrefix = "MIN_RELAYER_FEE_PCT"; ["USDC", "DAI", "WETH", "WBTC"].forEach((symbol) => { chainIds.forEach((srcChainId) => { - chainIds.forEach((dstChainId) => { - if (srcChainId === dstChainId) { - return; - } - - const envVar = `${envPrefix}_${symbol}_${srcChainId}_${dstChainId}`; - const routeFee = process.env[envVar]; - const routeMinRelayerFeePct = routeFee ? toBNWei(routeFee) : minRelayerFeePct; - const computedMinRelayerFeePct = profitClient.minRelayerFeePct(symbol, srcChainId, dstChainId); - spyLogger.debug({ - message: `Expect relayerFeePct === ${routeMinRelayerFeePct}`, - routeFee, - symbol, - srcChainId, - dstChainId, - computedMinRelayerFeePct, - }); + chainIds + .filter((chainId) => chainId !== srcChainId) + .forEach((dstChainId) => { + const envVar = `${envPrefix}_${symbol}_${srcChainId}_${dstChainId}`; + const routeFee = process.env[envVar]; + const routeMinRelayerFeePct = routeFee ? toBNWei(routeFee) : minRelayerFeePct; + const computedMinRelayerFeePct = profitClient.minRelayerFeePct(symbol, srcChainId, dstChainId); + spyLogger.debug({ + message: `Expect relayerFeePct === ${routeMinRelayerFeePct}`, + routeFee, + symbol, + srcChainId, + dstChainId, + computedMinRelayerFeePct, + }); - // Cleanup env as we go. - if (routeFee) { - process.env[envVar] = undefined; - } + // Cleanup env as we go. + if (routeFee) { + process.env[envVar] = undefined; + } - expect(computedMinRelayerFeePct.eq(routeMinRelayerFeePct)).to.be.true; - }); + expect(computedMinRelayerFeePct.eq(routeMinRelayerFeePct)).to.be.true; + }); }); }); }); - it("Considers deposits with newRelayerFeePct", async function () { - const l1Token: L1Token = tokens["WETH"]; + it("Considers deposits with newRelayerFeePct", async () => { + const l1Token = tokens["WETH"]; hubPoolClient.setTokenInfoToReturn(l1Token); const fillAmount = toBNWei(1); - const deposit = { - relayerFeePct: toBNWei("0.001"), - destinationChainId: 1, - } as Deposit; + const deposit = { relayerFeePct: toBNWei("0.001"), destinationChainId } as Deposit; let fill: FillProfit; fill = profitClient.calculateFillProfitability(deposit, fillAmount, zeroRefundFee, l1Token, minRelayerFeePct); @@ -430,14 +421,14 @@ describe("ProfitClient: Consider relay profit", async function () { expect(fill.grossRelayerFeePct.eq(deposit.newRelayerFeePct)).to.be.true; }); - it("Ignores newRelayerFeePct if it's lower than original relayerFeePct", async function () { - const l1Token: L1Token = tokens["WETH"]; + it("Ignores newRelayerFeePct if it's lower than original relayerFeePct", async () => { + const l1Token = tokens["WETH"]; hubPoolClient.setTokenInfoToReturn(l1Token); const deposit = { relayerFeePct: toBNWei("0.1"), newRelayerFeePct: toBNWei("0.01"), - destinationChainId: 1, + destinationChainId, } as Deposit; const fillAmount = toBNWei(1); @@ -446,12 +437,12 @@ describe("ProfitClient: Consider relay profit", async function () { expect(fill.grossRelayerFeePct.eq(deposit.relayerFeePct)).to.be.true; deposit.relayerFeePct = toBNWei(".001"); - expect(deposit.relayerFeePct.lt(deposit.newRelayerFeePct)).to.be.true; // Sanity check + expect(deposit.relayerFeePct.lt(deposit.newRelayerFeePct as BigNumber)).to.be.true; // Sanity check fill = profitClient.calculateFillProfitability(deposit, fillAmount, zeroRefundFee, l1Token, minRelayerFeePct); - expect(fill.grossRelayerFeePct.eq(deposit.newRelayerFeePct)).to.be.true; + expect(fill.grossRelayerFeePct.eq(deposit.newRelayerFeePct as BigNumber)).to.be.true; }); - it("Captures unprofitable fills", async function () { + it("Captures unprofitable fills", () => { const deposit = { relayerFeePct: toBNWei("0.003"), originChainId: 1, depositId: 42 } as DepositWithBlock; profitClient.captureUnprofitableFill(deposit, toBNWei(1)); expect(profitClient.getUnprofitableFills()).to.deep.equal({ 1: [{ deposit, fillAmount: toBNWei(1) }] }); diff --git a/test/Relayer.BasicFill.ts b/test/Relayer.BasicFill.ts index ecad12c18..4402f5ec3 100644 --- a/test/Relayer.BasicFill.ts +++ b/test/Relayer.BasicFill.ts @@ -38,7 +38,9 @@ import { winston, } from "./utils"; import { generateNoOpSpokePoolClientsForDefaultChainIndices } from "./utils/UBAUtils"; -import { clients } from "@across-protocol/sdk-v2"; +import { clients, utils as sdkUtils } from "@across-protocol/sdk-v2"; + +const { bnOne } = sdkUtils; let spokePool_1: Contract, erc20_1: Contract, spokePool_2: Contract, erc20_2: Contract; let hubPool: Contract, configStore: Contract, l1Token: Contract; @@ -117,9 +119,8 @@ describe("Relayer: Check for Unfilled Deposits and Fill", async function () { [destinationChainId]: spokePoolClient_2, }; - for (const spokePoolClient of Object.values(spokePoolClients)) { - await spokePoolClient.update(); - } + // Update all SpokePoolClient instances. + await Promise.all(Object.values(spokePoolClients).map((spokePoolClient) => spokePoolClient.update())); // We will need to update the config store client at least once await configStoreClient.update(); @@ -131,7 +132,8 @@ describe("Relayer: Check for Unfilled Deposits and Fill", async function () { ); tokenClient = new TokenClient(spyLogger, relayer.address, spokePoolClients, hubPoolClient); profitClient = new MockProfitClient(spyLogger, hubPoolClient, spokePoolClients, []); - profitClient.testInit(); + profitClient.setTokenPrice(l1Token.address, bnOne); + Object.values(spokePoolClients).map((spokePoolClient) => profitClient.setGasCost(spokePoolClient.chainId, bnOne)); relayerInstance = new Relayer( relayer.address, diff --git a/test/Relayer.RefundRequests.ts b/test/Relayer.RefundRequests.ts index 0e113079a..14f59bd0f 100644 --- a/test/Relayer.RefundRequests.ts +++ b/test/Relayer.RefundRequests.ts @@ -161,7 +161,6 @@ describe("Relayer: Request refunds for cross-chain repayments", async function ( ); tokenClient = new TokenClient(spyLogger, relayer.address, spokePoolClients, hubPoolClient); profitClient = new MockProfitClient(spyLogger, hubPoolClient, spokePoolClients, []); - profitClient.testInit(); relayerInstance = new Relayer( relayer.address, diff --git a/test/Relayer.TokenShortfall.ts b/test/Relayer.TokenShortfall.ts index 3adfa6a88..8e106453b 100644 --- a/test/Relayer.TokenShortfall.ts +++ b/test/Relayer.TokenShortfall.ts @@ -109,7 +109,6 @@ describe("Relayer: Token balance shortfall", async function () { const spokePoolClients = { [originChainId]: spokePoolClient_1, [destinationChainId]: spokePoolClient_2 }; tokenClient = new TokenClient(spyLogger, relayer.address, spokePoolClients, hubPoolClient); profitClient = new MockProfitClient(spyLogger, hubPoolClient, spokePoolClients, []); - profitClient.testInit(); relayerInstance = new Relayer( relayer.address, diff --git a/test/Relayer.UnfilledDeposits.ts b/test/Relayer.UnfilledDeposits.ts index 077d5881b..8314de9a7 100644 --- a/test/Relayer.UnfilledDeposits.ts +++ b/test/Relayer.UnfilledDeposits.ts @@ -109,7 +109,6 @@ describe("Relayer: Unfilled Deposits", async function () { multiCallerClient = new MockedMultiCallerClient(spyLogger); tokenClient = new TokenClient(spyLogger, relayer.address, spokePoolClients, hubPoolClient); profitClient = new MockProfitClient(spyLogger, hubPoolClient, spokePoolClients, []); - profitClient.testInit(); relayerInstance = new Relayer( relayer.address, spyLogger, diff --git a/test/mocks/MockProfitClient.ts b/test/mocks/MockProfitClient.ts index a104d44c4..eef920c81 100644 --- a/test/mocks/MockProfitClient.ts +++ b/test/mocks/MockProfitClient.ts @@ -1,16 +1,54 @@ -import { BigNumber, toBN, toBNWei } from "../utils"; -import { GAS_TOKEN_BY_CHAIN_ID, ProfitClient, WETH } from "../../src/clients"; +import { utils as sdkUtils } from "@across-protocol/sdk-v2"; +import { GAS_TOKEN_BY_CHAIN_ID, HubPoolClient, ProfitClient, WETH } from "../../src/clients"; +import { SpokePoolClientsByChain } from "../../src/interfaces"; +import { BigNumber, toBNWei, winston } from "../utils"; export class MockProfitClient extends ProfitClient { + constructor( + logger: winston.Logger, + hubPoolClient: HubPoolClient, + spokePoolClients: SpokePoolClientsByChain, + enabledChainIds: number[], + defaultMinRelayerFeePct?: BigNumber, + debugProfitability?: boolean, + gasMultiplier?: BigNumber + ) { + super( + logger, + hubPoolClient, + spokePoolClients, + enabledChainIds, + defaultMinRelayerFeePct, + debugProfitability, + gasMultiplier + ); + + // Some tests run against mocked chains, so hack in the necessary parts + const chainIds = [666, 1337]; + chainIds.forEach((chainId) => { + GAS_TOKEN_BY_CHAIN_ID[chainId] = WETH; + this.setGasCost(chainId, toBNWei(chainId)); + }); + this.setTokenPrice(WETH, sdkUtils.bnOne); + } + + setTokenPrice(l1Token: string, price: BigNumber | undefined): void { + if (price) { + this.tokenPrices[l1Token] = price; + } else { + delete this.tokenPrices[l1Token]; + } + } + setTokenPrices(tokenPrices: { [l1Token: string]: BigNumber }): void { this.tokenPrices = tokenPrices; } - getPriceOfToken(l1Token: string): BigNumber { - if (this.tokenPrices[l1Token] === undefined) { - return toBNWei(1); + setGasCost(chainId: number, gas: BigNumber | undefined): void { + if (gas) { + this.totalGasCosts[chainId] = gas; } else { - return this.tokenPrices[l1Token]; + delete this.totalGasCosts[chainId]; } } @@ -22,17 +60,6 @@ export class MockProfitClient extends ProfitClient { this.gasMultiplier = gasMultiplier; } - // Some tests run against mocked chains, so hack in the necessary parts - testInit(): void { - GAS_TOKEN_BY_CHAIN_ID[666] = WETH; - GAS_TOKEN_BY_CHAIN_ID[1337] = WETH; - - this.setGasCosts({ - 666: toBN(100_000), - 1337: toBN(100_000), - }); - } - // eslint-disable-next-line @typescript-eslint/no-empty-function async update(): Promise {} }