-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve(GasPriceOracle): Standardize gas price oracle usage
- Removes special case in `src/utils/common.ts#estimateTotalGasRequiredByUnsignedTransaction` that handles Linea gas price estimates by avoiding the gasPriceOracle call - Implements `eip1559()` function in `linea-viem.ts` gas price oracle adapter file so that gas price oracle users now get access to Linea EIP1559 gas price estimates via viem. This requires callers to pass in an optional `unsignedTx` object - Refactors gas price oracle `getGasPriceEstimate()` function and consolidates all optional parameters into a single `GasPriceEstimateOptions` object which will be easier to maintain
- Loading branch information
1 parent
a2e7b41
commit 71c12b1
Showing
7 changed files
with
134 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
import { PublicClient } from "viem"; | ||
import { InternalGasPriceEstimate } from "../types"; | ||
import { eip1559 as ethereumEip1559 } from "./ethereum-viem"; | ||
|
||
const MAX_PRIORITY_FEE_PER_GAS = BigInt(1); | ||
|
||
// Arbitrum Nitro implements EIP-1559 pricing, but the priority fee is always refunded to the caller. | ||
// Swap it for 1 Wei to avoid inaccurate transaction cost estimates. | ||
// Reference: https://developer.arbitrum.io/faqs/gas-faqs#q-priority | ||
export async function eip1559(provider: PublicClient, _chainId: number): Promise<InternalGasPriceEstimate> { | ||
const { maxFeePerGas: _maxFeePerGas, maxPriorityFeePerGas } = await provider.estimateFeesPerGas(); | ||
const maxFeePerGas = BigInt(_maxFeePerGas) - maxPriorityFeePerGas + MAX_PRIORITY_FEE_PER_GAS; | ||
export async function eip1559( | ||
provider: PublicClient, | ||
_chainId: number, | ||
baseFeeMultiplier: number | ||
): Promise<InternalGasPriceEstimate> { | ||
const { maxFeePerGas: _maxFeePerGas, maxPriorityFeePerGas } = await ethereumEip1559( | ||
provider, | ||
_chainId, | ||
baseFeeMultiplier | ||
); | ||
const maxFeePerGas = _maxFeePerGas - maxPriorityFeePerGas + MAX_PRIORITY_FEE_PER_GAS; | ||
return { maxFeePerGas, maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
import { PublicClient } from "viem"; | ||
import { Address, PublicClient } from "viem"; | ||
import { estimateGas } from "viem/linea"; | ||
import { DEFAULT_SIMULATED_RELAYER_ADDRESS as account } from "../../constants"; | ||
import { InternalGasPriceEstimate } from "../types"; | ||
import { PopulatedTransaction } from "ethers"; | ||
|
||
export async function eip1559(provider: PublicClient, _chainId?: number): Promise<InternalGasPriceEstimate> { | ||
export async function eip1559( | ||
provider: PublicClient, | ||
_chainId: number, | ||
baseFeeMultiplier: number, | ||
_unsignedTx?: PopulatedTransaction | ||
): Promise<InternalGasPriceEstimate> { | ||
const { baseFeePerGas, priorityFeePerGas } = await estimateGas(provider, { | ||
account, | ||
to: account, | ||
value: BigInt(1), | ||
account: (_unsignedTx?.from as Address) ?? account, | ||
to: (_unsignedTx?.to as Address) ?? account, | ||
value: BigInt(_unsignedTx?.value?.toString() || "1"), | ||
}); | ||
|
||
return { | ||
maxFeePerGas: baseFeePerGas + priorityFeePerGas, | ||
maxFeePerGas: baseFeePerGas * BigInt(baseFeeMultiplier) + priorityFeePerGas, | ||
maxPriorityFeePerGas: priorityFeePerGas, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters