Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gasPriceOracle): Allow caller to pass in base fee multiplier #801

Merged
merged 64 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
79ba3b2
feat(gasPriceOracle): Allow caller to pass in base fee multiplier
nicholaspai Dec 19, 2024
6226eee
lint
nicholaspai Dec 19, 2024
deedb53
add e2e test
nicholaspai Dec 19, 2024
5c72afd
Remove from relay gas fee calculator
nicholaspai Dec 19, 2024
5ced7f1
Update oracle.e2e.ts
nicholaspai Dec 19, 2024
cad60ed
Update common.ts
nicholaspai Dec 19, 2024
78b1565
Update common.ts
nicholaspai Dec 19, 2024
4adfeb1
Update common.ts
nicholaspai Dec 19, 2024
4d76862
Update polygon.ts
nicholaspai Dec 19, 2024
c63f328
floor multiplier at 1.0
nicholaspai Dec 19, 2024
fa361d3
Update arbitrum.ts
nicholaspai Dec 19, 2024
38d6ab0
fix
nicholaspai Dec 19, 2024
e6a0fb7
fix e2e test
nicholaspai Dec 19, 2024
b4d4847
Update polygon.ts
nicholaspai Dec 20, 2024
f19ad1a
Merge branch 'master' into base-fee-multiplier
pxrl Dec 21, 2024
957b009
Apply suggestions from code review
pxrl Dec 21, 2024
a5d6a1a
fix?
pxrl Dec 21, 2024
15b8040
Fix merge
pxrl Dec 21, 2024
4a0858a
Update common.ts
nicholaspai Dec 21, 2024
e56073a
Update ethereum.ts
nicholaspai Dec 21, 2024
ae02e89
Update common.ts
nicholaspai Dec 24, 2024
3e245ba
Remove gasMarkup from QueryBase parents
nicholaspai Dec 24, 2024
e541b25
fix
nicholaspai Dec 24, 2024
a2e7b41
apply multipier to linea
nicholaspai Dec 24, 2024
71c12b1
improve(GasPriceOracle): Standardize gas price oracle usage
nicholaspai Dec 24, 2024
4961d48
fix
nicholaspai Dec 24, 2024
bda4843
Add unit test
nicholaspai Dec 24, 2024
33e36a4
Remove arbitrum viem provider; add unit tests
nicholaspai Dec 25, 2024
de2a339
lint
nicholaspai Dec 25, 2024
e16f9fe
improve(GasPriceOracle): Standardize gas price oracle usage (#807)
nicholaspai Dec 25, 2024
cf9a867
Update src/gasPriceOracle/adapters/linea-viem.ts
nicholaspai Dec 26, 2024
e913c75
gwei to wei
nicholaspai Dec 26, 2024
e701089
Update src/gasPriceOracle/oracle.ts
nicholaspai Dec 26, 2024
33470b1
Update src/utils/common.ts
nicholaspai Dec 26, 2024
ea1ee66
Add unit tests, refactor all methods
nicholaspai Dec 26, 2024
3f31537
Merge branch 'master' into viem-scaler
nicholaspai Dec 26, 2024
bcd10bb
add baseFeeMultiplier assertion test
nicholaspai Dec 27, 2024
2d4caee
add linea ethers notes
nicholaspai Dec 27, 2024
e6919f3
Merge branch 'base-fee-multiplier' into viem-scaler
nicholaspai Dec 27, 2024
ca45734
Add baseFeeMultiplier test, add linea ethers comment
nicholaspai Dec 27, 2024
86610a6
Merge branch 'viem-scaler' into base-fee-multiplier
nicholaspai Dec 27, 2024
a9448e6
Fix comments
nicholaspai Dec 27, 2024
b0f297e
fix merge
nicholaspai Dec 27, 2024
ec0a623
Update GasPriceOracle.test.ts
nicholaspai Dec 27, 2024
281f9f7
Add comment about why chain-queries classes exist
nicholaspai Dec 27, 2024
f88e927
Revert "Add comment about why chain-queries classes exist"
nicholaspai Dec 27, 2024
35a0420
Add comments about planned deprecation of eip1559Bad
nicholaspai Dec 31, 2024
20461a6
Update oracle.ts
nicholaspai Jan 2, 2025
576dac6
Remove polygonGasStation from type
nicholaspai Jan 2, 2025
a232f05
Update oracle.ts
nicholaspai Jan 2, 2025
515ec15
fix
nicholaspai Jan 2, 2025
765ef85
refactor(QueryBase): Remove constructors in derived classes (#808)
nicholaspai Jan 2, 2025
90c9e89
Merge branch 'master' into base-fee-multiplier
nicholaspai Jan 2, 2025
4980b22
Update package.json
nicholaspai Jan 2, 2025
21821ca
refactor
nicholaspai Jan 2, 2025
c9740a3
fix
nicholaspai Jan 2, 2025
128767e
remove omitMarkup
nicholaspai Jan 2, 2025
d0d52bd
add baseFeeMultiplier to getGasCosts optional params
nicholaspai Jan 2, 2025
ca24cfc
Update oracle.ts
nicholaspai Jan 3, 2025
192ac16
Make baseFeeMultiplier a bignumber
nicholaspai Jan 3, 2025
04f3664
Update oracle.ts
nicholaspai Jan 3, 2025
74261cf
Refactor estimateTotalGasRequiredByUnsignedTransaction into QueryBase
nicholaspai Jan 3, 2025
17c0abb
Add test for QueryBase's usage of GasPriceOracle
nicholaspai Jan 3, 2025
6c82762
Apply suggestions from code review
pxrl Jan 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions e2e/oracle.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ describe("Gas Price Oracle", function () {
for (const chainId of chainIds) {
const chainKey = `NEW_GAS_PRICE_ORACLE_${chainId}`;
process.env[chainKey] = "true";
const { maxFeePerGas, maxPriorityFeePerGas } = await getGasPriceEstimate(provider, chainId, customTransport);
const { maxFeePerGas, maxPriorityFeePerGas } = await getGasPriceEstimate(provider, chainId, 1, customTransport);
dummyLogger.debug({
at: "Gas Price Oracle#Gas Price Retrieval",
message: `Retrieved gas price estimate for chain ID ${chainId}`,
maxFeePerGas,
maxPriorityFeePerGas,
maxFeePerGas: maxFeePerGas.toString(),
maxPriorityFeePerGas: maxPriorityFeePerGas.toString(),
});

expect(BigNumber.isBigNumber(maxFeePerGas)).to.be.true;
Expand All @@ -54,4 +54,21 @@ describe("Gas Price Oracle", function () {
delete process.env[chainKey];
}
});
it("Ethers: applies markup to maxFeePerGas", async function () {
for (const chainId of chainIds) {
const { maxFeePerGas: markedUpMaxFeePerGas, maxPriorityFeePerGas: markedUpMaxPriorityFeePerGas } =
await getGasPriceEstimate(provider, chainId, 2, customTransport);
const { maxFeePerGas, maxPriorityFeePerGas } = await getGasPriceEstimate(provider, chainId, 1, customTransport);
dummyLogger.debug({
at: "Gas Price Oracle#Gas Price Retrieval",
message: `Retrieved gas price estimate for chain ID ${chainId}`,
maxFeePerGas: maxFeePerGas.toString(),
maxPriorityFeePerGas: maxPriorityFeePerGas.toString(),
markedUpMaxFeePerGas: markedUpMaxFeePerGas.toString(),
markedUpMaxPriorityFeePerGas: markedUpMaxPriorityFeePerGas.toString(),
});
expect(markedUpMaxFeePerGas.gt(maxFeePerGas)).to.be.true;
expect(markedUpMaxPriorityFeePerGas).to.equal(maxPriorityFeePerGas);
}
});
});
12 changes: 10 additions & 2 deletions src/gasPriceOracle/adapters/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ import * as ethereum from "./ethereum";

// Arbitrum Nitro implements EIP-1559 pricing, but the priority fee is always refunded to the caller.
// Reference: https://docs.arbitrum.io/how-arbitrum-works/gas-fees
export async function eip1559(provider: providers.Provider, chainId: number): Promise<GasPriceEstimate> {
const { maxFeePerGas: _maxFeePerGas, maxPriorityFeePerGas } = await ethereum.eip1559(provider, chainId);
export async function eip1559(
provider: providers.Provider,
chainId: number,
baseFeeMultiplier: number
): Promise<GasPriceEstimate> {
const { maxFeePerGas: _maxFeePerGas, maxPriorityFeePerGas } = await ethereum.eip1559(
provider,
chainId,
baseFeeMultiplier
);

// eip1559() sets maxFeePerGas = lastBaseFeePerGas + maxPriorityFeePerGas, so revert that.
// The caller may apply scaling as they wish afterwards.
Expand Down
17 changes: 13 additions & 4 deletions src/gasPriceOracle/adapters/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
* @param chainId Chain ID of provider instance.
* @returns Promise of gas price estimate object.
*/
export function eip1559(provider: providers.Provider, chainId: number): Promise<GasPriceEstimate> {
export async function eip1559(

Check failure on line 12 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Lint

Async function 'eip1559' has no 'await' expression
provider: providers.Provider,
chainId: number,
baseFeeMultiplier: number

Check failure on line 15 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Lint

'baseFeeMultiplier' is declared but its value is never read.

Check failure on line 15 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Lint

'baseFeeMultiplier' is declared but its value is never read.

Check failure on line 15 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Lint

'baseFeeMultiplier' is defined but never used. Allowed unused args must match /^_/u

Check failure on line 15 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Builds

'baseFeeMultiplier' is declared but its value is never read.

Check failure on line 15 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Builds

'baseFeeMultiplier' is declared but its value is never read.

Check failure on line 15 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Builds

'baseFeeMultiplier' is declared but its value is never read.

Check failure on line 15 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Builds

'baseFeeMultiplier' is declared but its value is never read.

Check failure on line 15 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Test

'baseFeeMultiplier' is declared but its value is never read.

Check failure on line 15 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Test

'baseFeeMultiplier' is declared but its value is never read.
): Promise<GasPriceEstimate> {
const useRaw = process.env[`GAS_PRICE_EIP1559_RAW_${chainId}`] === "true";
return useRaw ? eip1559Raw(provider, chainId) : eip1559Bad(provider, chainId);
}
Expand Down Expand Up @@ -48,18 +52,23 @@
});

const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas as BigNumber;
const maxFeePerGas = maxPriorityFeePerGas.add(feeData.lastBaseFeePerGas as BigNumber);
const scaledLastBaseFeePerGas = (feeData.lastBaseFeePerGas as BigNumber).mul(baseFeeMultiplier);

Check failure on line 55 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Lint

Cannot find name 'baseFeeMultiplier'.

Check failure on line 55 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Lint

Cannot find name 'baseFeeMultiplier'.

Check failure on line 55 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Builds

Cannot find name 'baseFeeMultiplier'.

Check failure on line 55 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Builds

Cannot find name 'baseFeeMultiplier'.

Check failure on line 55 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Builds

Cannot find name 'baseFeeMultiplier'.

Check failure on line 55 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Builds

Cannot find name 'baseFeeMultiplier'.

Check failure on line 55 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Test

Cannot find name 'baseFeeMultiplier'.

Check failure on line 55 in src/gasPriceOracle/adapters/ethereum.ts

View workflow job for this annotation

GitHub Actions / Test

Cannot find name 'baseFeeMultiplier'.
const maxFeePerGas = maxPriorityFeePerGas.add(scaledLastBaseFeePerGas);

return { maxPriorityFeePerGas, maxFeePerGas };
}

export async function legacy(provider: providers.Provider, chainId: number): Promise<GasPriceEstimate> {
export async function legacy(
provider: providers.Provider,
chainId: number,
baseFeeMultiplier: number
): Promise<GasPriceEstimate> {
const gasPrice = await provider.getGasPrice();

if (!BigNumber.isBigNumber(gasPrice) || gasPrice.lt(bnZero)) gasPriceError("getGasPrice()", chainId, gasPrice);

return {
maxFeePerGas: gasPrice,
maxFeePerGas: gasPrice.mul(baseFeeMultiplier),
maxPriorityFeePerGas: bnZero,
};
}
8 changes: 6 additions & 2 deletions src/gasPriceOracle/adapters/linea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { providers } from "ethers";
import { GasPriceEstimate } from "../types";
import * as ethereum from "./ethereum";

export function eip1559(provider: providers.Provider, chainId: number): Promise<GasPriceEstimate> {
return ethereum.legacy(provider, chainId);
export function eip1559(
provider: providers.Provider,
chainId: number,
baseFeeMultiplier: number
): Promise<GasPriceEstimate> {
return ethereum.legacy(provider, chainId, baseFeeMultiplier);
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved
}
10 changes: 8 additions & 2 deletions src/gasPriceOracle/adapters/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,21 @@ class PolygonGasStation extends BaseHTTPAdapter {
}
}

export async function gasStation(provider: providers.Provider, chainId: number): Promise<GasPriceEstimate> {
export async function gasStation(
provider: providers.Provider,
chainId: number,
baseFeeMultiplier: number
): Promise<GasPriceEstimate> {
const gasStation = new PolygonGasStation({ chainId: chainId, timeout: 2000, retries: 0 });
let maxPriorityFeePerGas: BigNumber;
let maxFeePerGas: BigNumber;
try {
({ maxPriorityFeePerGas, maxFeePerGas } = await gasStation.getFeeData());
maxFeePerGas = maxFeePerGas.mul(baseFeeMultiplier);
} catch (err) {
// Fall back to the RPC provider. May be less accurate.
({ maxPriorityFeePerGas, maxFeePerGas } = await eip1559(provider, chainId));
// @dev Don't incorporate multiplier until after catch statement
({ maxPriorityFeePerGas, maxFeePerGas } = await eip1559(provider, chainId, baseFeeMultiplier));

// Per the GasStation docs, the minimum priority fee on Polygon is 30 Gwei.
// https://docs.polygon.technology/tools/gas/polygon-gas-station/#interpretation
Expand Down
24 changes: 17 additions & 7 deletions src/gasPriceOracle/oracle.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import assert from "assert";

Check failure on line 1 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Lint

Duplicate identifier 'assert'.

Check failure on line 1 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Lint

Duplicate identifier 'assert'.

Check failure on line 1 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Builds

Duplicate identifier 'assert'.

Check failure on line 1 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Builds

Duplicate identifier 'assert'.

Check failure on line 1 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Builds

Duplicate identifier 'assert'.

Check failure on line 1 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Builds

Duplicate identifier 'assert'.

Check failure on line 1 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Test

Duplicate identifier 'assert'.

Check failure on line 1 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Test

Duplicate identifier 'assert'.
import { Transport } from "viem";
import { providers } from "ethers";
import { CHAIN_IDs } from "../constants";
import { BigNumber, chainIsOPStack } from "../utils";
import { assert, BigNumber, chainIsOPStack } from "../utils";

Check failure on line 5 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Lint

Duplicate identifier 'assert'.

Check failure on line 5 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Lint

Duplicate identifier 'assert'.

Check failure on line 5 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Builds

Duplicate identifier 'assert'.

Check failure on line 5 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Builds

Duplicate identifier 'assert'.

Check failure on line 5 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Builds

Duplicate identifier 'assert'.

Check failure on line 5 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Builds

Duplicate identifier 'assert'.

Check failure on line 5 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Test

Duplicate identifier 'assert'.

Check failure on line 5 in src/gasPriceOracle/oracle.ts

View workflow job for this annotation

GitHub Actions / Test

Duplicate identifier 'assert'.
import { GasPriceEstimate } from "./types";
import { getPublicClient } from "./util";
import * as arbitrum from "./adapters/arbitrum";
Expand All @@ -18,20 +18,27 @@
* @param chainId The chain ID to query for gas prices.
* @param provider A valid ethers provider.
* @param legacyFallback In the case of an unrecognised chain, fall back to type 0 gas estimation.
* @parm baseFeeMarkup Multiplier applied to base fee for EIP1559 gas prices (or total fee for legacy).
* @returns Am object of type GasPriceEstimate.
*/
export async function getGasPriceEstimate(
provider: providers.Provider,
chainId?: number,
baseFeeMultiplier = 1.0,
transport?: Transport,
legacyFallback = true
): Promise<GasPriceEstimate> {
assert(
baseFeeMultiplier >= 1.0 && baseFeeMultiplier <= 5,
`Require 1.0 < base fee multiplier (${baseFeeMultiplier}) <= 5.0 for a total gas multiplier within [+1.0, +5.0]`
);

chainId ?? ({ chainId } = await provider.getNetwork());

const useViem = process.env[`NEW_GAS_PRICE_ORACLE_${chainId}`] === "true";
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved
return useViem
? getViemGasPriceEstimate(chainId, transport)
: getEthersGasPriceEstimate(provider, chainId, legacyFallback);
? getViemGasPriceEstimate(chainId, transport, baseFeeMultiplier)
: getEthersGasPriceEstimate(provider, chainId, legacyFallback, baseFeeMultiplier);
}

/**
Expand All @@ -44,7 +51,8 @@
function getEthersGasPriceEstimate(
provider: providers.Provider,
chainId: number,
legacyFallback = true
legacyFallback = true,
baseFeeMultiplier = 1.0
pxrl marked this conversation as resolved.
Show resolved Hide resolved
): Promise<GasPriceEstimate> {
const gasPriceFeeds = {
[CHAIN_IDs.ALEPH_ZERO]: arbitrum.eip1559,
Expand All @@ -60,7 +68,7 @@
assert(gasPriceFeed || legacyFallback, `No suitable gas price oracle for Chain ID ${chainId}`);
gasPriceFeed ??= chainIsOPStack(chainId) ? ethereum.eip1559 : ethereum.legacy;

return gasPriceFeed(provider, chainId);
return gasPriceFeed(provider, chainId, baseFeeMultiplier);
}

/**
Expand All @@ -71,7 +79,8 @@
*/
export async function getViemGasPriceEstimate(
providerOrChainId: providers.Provider | number,
transport?: Transport
transport?: Transport,
baseFeeMultiplier = 1.0
pxrl marked this conversation as resolved.
Show resolved Hide resolved
): Promise<GasPriceEstimate> {
const chainId =
typeof providerOrChainId === "number" ? providerOrChainId : (await providerOrChainId.getNetwork()).chainId;
Expand All @@ -96,8 +105,9 @@
maxPriorityFeePerGas ??= BigInt(0);
}

// Apply markup to base fee which will be more volatile than priority fee.
return {
maxFeePerGas: BigNumber.from(maxFeePerGas.toString()),
maxFeePerGas: BigNumber.from(maxFeePerGas.toString()).mul(baseFeeMultiplier),
maxPriorityFeePerGas: BigNumber.from(maxPriorityFeePerGas.toString()),
};
}
19 changes: 3 additions & 16 deletions src/relayFeeCalculator/chain-queries/baseQuery.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { L2Provider } from "@eth-optimism/sdk/dist/interfaces/l2-provider";
import { providers } from "ethers";
import assert from "assert";
import { Coingecko } from "../../coingecko";
import { CHAIN_IDs, DEFAULT_SIMULATED_RELAYER_ADDRESS } from "../../constants";
import { Deposit } from "../../interfaces";
Expand All @@ -9,9 +8,7 @@ import {
BigNumberish,
TransactionCostEstimate,
estimateTotalGasRequiredByUnsignedTransaction,
fixedPointAdjustment,
populateV3Relay,
toBNWei,
} from "../../utils";
import { Logger, QueryInterface } from "../relayFeeCalculator";
import { Transport } from "viem";
Expand All @@ -38,7 +35,6 @@ export class QueryBase implements QueryInterface {
* @param symbolMapping A mapping to valid ERC20 tokens and their respective characteristics
* @param spokePoolAddress The valid address of the Spoke Pool deployment
* @param simulatedRelayerAddress The address that these queries will reference as the sender. Note: This address must be approved for USDC
* @param gasMarkup A multiplier that is applied to the total gas estimate
* @param logger A logging utility to report logs
* @param coingeckoProApiKey An optional CoinGecko API key that links to a PRO account
* @param fixedGasPrice Overrides the gas price with a fixed value. Note: primarily used for the Boba blockchain
Expand All @@ -49,7 +45,6 @@ export class QueryBase implements QueryInterface {
readonly symbolMapping: SymbolMappingType,
readonly spokePoolAddress: string,
readonly simulatedRelayerAddress: string,
readonly gasMarkup: number,
readonly logger: Logger,
readonly coingeckoProApiKey?: string,
readonly fixedGasPrice?: BigNumberish,
Expand All @@ -75,18 +70,10 @@ export class QueryBase implements QueryInterface {
options: Partial<{
gasPrice: BigNumberish;
gasUnits: BigNumberish;
omitMarkup: boolean;
transport: Transport;
}> = {}
): Promise<TransactionCostEstimate> {
const { gasPrice = this.fixedGasPrice, gasUnits, omitMarkup, transport } = options;

const gasMarkup = omitMarkup ? 0 : this.gasMarkup;
assert(
gasMarkup > -1 && gasMarkup <= 4,
`Require -1.0 < Gas Markup (${gasMarkup}) <= 4.0 for a total gas multiplier within (0, +5.0]`
);
const gasTotalMultiplier = toBNWei(1.0 + gasMarkup);
const { gasPrice = this.fixedGasPrice, gasUnits, transport } = options;

const tx = await populateV3Relay(this.spokePool, deposit, relayer);
const {
Expand All @@ -100,8 +87,8 @@ export class QueryBase implements QueryInterface {
});

return {
nativeGasCost: nativeGasCost.mul(gasTotalMultiplier).div(fixedPointAdjustment),
tokenGasCost: tokenGasCost.mul(gasTotalMultiplier).div(fixedPointAdjustment),
nativeGasCost,
tokenGasCost,
gasPrice: impliedGasPrice,
};
}
Expand Down
8 changes: 2 additions & 6 deletions src/relayFeeCalculator/chain-queries/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export class QueryBase__factory {
simulatedRelayerAddress = DEFAULT_SIMULATED_RELAYER_ADDRESS,
coingeckoProApiKey?: string,
logger: Logger = DEFAULT_LOGGER,
gasMarkup = 0,
coingeckoBaseCurrency = "eth"
): QueryBase {
assert(isDefined(spokePoolAddress));
Expand All @@ -39,8 +38,7 @@ export class QueryBase__factory {
spokePoolAddress,
simulatedRelayerAddress,
coingeckoProApiKey,
logger,
gasMarkup
logger
);
}

Expand All @@ -51,8 +49,7 @@ export class QueryBase__factory {
spokePoolAddress,
simulatedRelayerAddress,
coingeckoProApiKey,
logger,
gasMarkup
logger
);
}

Expand All @@ -64,7 +61,6 @@ export class QueryBase__factory {
symbolMapping,
spokePoolAddress,
simulatedRelayerAddress,
gasMarkup,
logger,
coingeckoProApiKey,
fixedGasPrice[chainId],
Expand Down
3 changes: 2 additions & 1 deletion src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@
const voidSigner = new VoidSigner(senderAddress, provider);

// Estimate the Gas units required to submit this transaction.
const gasMultiplier = 1.0; // Don't apply any multiplier to the gas price.
const queries = [
gasUnits ? Promise.resolve(BigNumber.from(gasUnits)) : voidSigner.estimateGas(unsignedTx),
_gasPrice ? Promise.resolve({ maxFeePerGas: _gasPrice }) : getGasPriceEstimate(provider, chainId, transport),
_gasPrice ? Promise.resolve({ maxFeePerGas: _gasPrice }) : getGasPriceEstimate(provider, chainId, gasMultiplier, transport),

Check warning on line 271 in src/utils/common.ts

View workflow job for this annotation

GitHub Actions / Lint

Replace `·?·Promise.resolve({·maxFeePerGas:·_gasPrice·})` with `⏎······?·Promise.resolve({·maxFeePerGas:·_gasPrice·})⏎·····`
pxrl marked this conversation as resolved.
Show resolved Hide resolved
] as const;
let [nativeGasCost, { maxFeePerGas: gasPrice }] = await Promise.all(queries);
assert(nativeGasCost.gt(bnZero), "Gas cost should not be 0");
Expand Down
Loading