diff --git a/src/clients/ProfitClient.ts b/src/clients/ProfitClient.ts index 59e282d9c..bdaa26e9e 100644 --- a/src/clients/ProfitClient.ts +++ b/src/clients/ProfitClient.ts @@ -33,7 +33,7 @@ import { Deposit, DepositWithBlock, L1Token, SpokePoolClientsByChain } from "../ import { getAcrossHost } from "./AcrossAPIClient"; import { HubPoolClient } from "./HubPoolClient"; -type TransactionCostEstimate = sdkUtils.TransactionCostEstimate & { gasPrice?: BigNumber }; +export type ProfitClientTransactionCostEstimate = sdkUtils.TransactionCostEstimate & { gasPrice: BigNumber }; const { isError, isEthersError } = typeguards; const { formatEther } = ethersUtils; @@ -92,7 +92,7 @@ export class ProfitClient { private unprofitableFills: { [chainId: number]: UnprofitableFill[] } = {}; // Track total gas costs of a relay on each chain. - protected totalGasCosts: { [chainId: number]: TransactionCostEstimate } = {}; + protected totalGasCosts: { [chainId: number]: ProfitClientTransactionCostEstimate } = {}; // Queries needed to fetch relay gas costs. private relayerFeeQueries: { [chainId: number]: relayFeeCalculator.QueryInterface } = {}; @@ -201,9 +201,14 @@ export class ProfitClient { return price; } - private async _getTotalGasCost(deposit: Deposit, relayer: string): Promise { + private async _getTotalGasCost(deposit: Deposit, relayer: string): Promise { try { - return await this.relayerFeeQueries[deposit.destinationChainId].getGasCosts(deposit, relayer); + const totalGasCosts = await this.relayerFeeQueries[deposit.destinationChainId].getGasCosts(deposit, relayer); + const gasPrice = totalGasCosts.tokenGasCost.div(totalGasCosts.nativeGasCost); + return { + ...totalGasCosts, + gasPrice, + } } catch (err) { const reason = isEthersError(err) ? err.reason : isError(err) ? err.message : "unknown error"; this.logger.warn({ @@ -213,11 +218,11 @@ export class ProfitClient { deposit, notificationPath: "across-unprofitable-fills", }); - return { nativeGasCost: uint256Max, tokenGasCost: uint256Max }; + return { nativeGasCost: uint256Max, tokenGasCost: uint256Max, gasPrice: uint256Max }; } } - async getTotalGasCost(deposit: Deposit): Promise { + async getTotalGasCost(deposit: Deposit): Promise { const { destinationChainId: chainId } = deposit; // If there's no attached message, gas consumption from previous fills can be used in most cases. @@ -229,6 +234,10 @@ export class ProfitClient { return this._getTotalGasCost(deposit, this.relayerAddress); } + getGasCostsForChain(chainId: number): ProfitClientTransactionCostEstimate { + return this.totalGasCosts[chainId]; + } + // Estimate the gas cost of filling this relay. async estimateFillCost( deposit: Deposit diff --git a/test/mocks/MockProfitClient.ts b/test/mocks/MockProfitClient.ts index e20a31a21..f9d9ff4b8 100644 --- a/test/mocks/MockProfitClient.ts +++ b/test/mocks/MockProfitClient.ts @@ -1,12 +1,9 @@ -import { utils as sdkUtils } from "@across-protocol/sdk"; -import { ProfitClient } from "../../src/clients"; +import { ProfitClient, ProfitClientTransactionCostEstimate } from "../../src/clients"; import { SpokePoolClientsByChain } from "../../src/interfaces"; import { bnOne, isDefined, TOKEN_SYMBOLS_MAP } from "../../src/utils"; import { BigNumber, toBN, toBNWei, winston } from "../utils"; import { MockHubPoolClient } from "./MockHubPoolClient"; -type TransactionCostEstimate = sdkUtils.TransactionCostEstimate; - const defaultFillCost = toBN(100_000); // gas const defaultGasPrice = bnOne; // wei per gas @@ -57,6 +54,7 @@ export class MockProfitClient extends ProfitClient { const defaultGasCost = { nativeGasCost: defaultFillCost, tokenGasCost: defaultGasPrice.mul(defaultFillCost), + gasPrice: defaultGasPrice, }; Object.values(spokePoolClients).map(({ chainId }) => { this.setGasCost(chainId, defaultGasCost); // gas/fill @@ -93,7 +91,7 @@ export class MockProfitClient extends ProfitClient { }); } - setGasCost(chainId: number, gas?: TransactionCostEstimate): void { + setGasCost(chainId: number, gas?: ProfitClientTransactionCostEstimate): void { if (gas) { this.totalGasCosts[chainId] = gas; } else { @@ -101,7 +99,7 @@ export class MockProfitClient extends ProfitClient { } } - setGasCosts(gasCosts: { [chainId: number]: TransactionCostEstimate }): void { + setGasCosts(gasCosts: { [chainId: number]: ProfitClientTransactionCostEstimate }): void { this.totalGasCosts = gasCosts; }