🚑 ability to configure min maxPriorityFeePerGas
This commit is contained in:
parent
06b380b488
commit
4861f36c56
@ -90,6 +90,7 @@ const options: GasOracleOptions = {
|
||||
blockTime: 10, // seconds
|
||||
shouldCache: false,
|
||||
timeout: 10000, // specifies the number of milliseconds before the request times out.
|
||||
minPriority: 0, // specifies the min maxPriorityFeePerGas.
|
||||
fallbackGasPrices: {
|
||||
gasPrices: {
|
||||
instant: 28,
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gas-price-oracle",
|
||||
"version": "0.5.1",
|
||||
"version": "0.5.2",
|
||||
"description": "Gas Price Oracle library for Ethereum dApps.",
|
||||
"homepage": "https://github.com/peppersec/gas-price-oracle",
|
||||
"main": "./lib/index.js",
|
||||
|
@ -16,6 +16,7 @@ export class Eip1559GasPriceOracle implements EstimateOracle {
|
||||
shouldCache: false,
|
||||
chainId: ChainId.MAINNET,
|
||||
fallbackGasPrices: undefined,
|
||||
minPriority: DEFAULT_PRIORITY_FEE,
|
||||
blockTime: DEFAULT_BLOCK_DURATION,
|
||||
blocksCount: NETWORKS[ChainId.MAINNET].blocksCount,
|
||||
percentile: NETWORKS[ChainId.MAINNET].percentile,
|
||||
@ -135,8 +136,10 @@ export class Eip1559GasPriceOracle implements EstimateOracle {
|
||||
private async calculateFees({ baseFee, feeHistory }: CalculateFeesParams): Promise<EstimatedGasPrice> {
|
||||
const estimatedPriorityFee = await this.getPriorityFromChain(feeHistory)
|
||||
|
||||
const { highest: maxPriorityFeePerGas } = findMax([estimatedPriorityFee ?? BG_ZERO, new BigNumber(DEFAULT_PRIORITY_FEE)])
|
||||
|
||||
const { highest: maxPriorityFeePerGas } = findMax([
|
||||
estimatedPriorityFee ?? BG_ZERO,
|
||||
new BigNumber(this.configuration.minPriority),
|
||||
])
|
||||
const maxFeePerGas = baseFee.plus(maxPriorityFeePerGas)
|
||||
|
||||
if (this.checkIsGreaterThanMax(maxFeePerGas) || this.checkIsGreaterThanMax(maxPriorityFeePerGas)) {
|
||||
|
@ -32,7 +32,7 @@ export type GasEstimationOptionsPayload = Options & {
|
||||
fetcher: RpcFetcher
|
||||
}
|
||||
|
||||
export type Config = Required<Options> & { fallbackGasPrices?: EstimatedGasPrice }
|
||||
export type Config = Required<Options> & { fallbackGasPrices?: EstimatedGasPrice; minPriority: number }
|
||||
export abstract class EstimateOracle {
|
||||
public configuration: Config
|
||||
public abstract estimateFees(fallbackGasPrices?: EstimatedGasPrice): Promise<EstimatedGasPrice>
|
||||
|
@ -38,6 +38,7 @@ export type GasOracleOptions = {
|
||||
percentile?: number
|
||||
blockTime?: number
|
||||
shouldCache?: boolean
|
||||
minPriority?: number
|
||||
fallbackGasPrices?: FallbackGasPrices
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,9 @@ const DEFAULT_GAS_PRICE = { instant: 0, fast: 0, standard: 0, low: 0 }
|
||||
|
||||
const MULTIPLIERS = {
|
||||
instant: 1.3,
|
||||
standard: 0.85,
|
||||
low: 0.5,
|
||||
fast: 1,
|
||||
fast: 1.2,
|
||||
standard: 1.1,
|
||||
low: 1,
|
||||
}
|
||||
|
||||
export { MULTIPLIERS, DEFAULT_GAS_PRICE }
|
||||
|
@ -33,7 +33,7 @@ beforeEach('beforeEach', function () {
|
||||
oracle = new GasPriceOracle()
|
||||
})
|
||||
|
||||
const INJECTED_RPC_URL = 'https://ethereum-rpc.trustwalletapp.com'
|
||||
const INJECTED_RPC_URL = 'https://cloudflare-eth.com'
|
||||
describe('eip-1559 gasOracle', function () {
|
||||
describe('eip constructor', function () {
|
||||
it('should set default values', function () {
|
||||
@ -62,14 +62,14 @@ describe('eip-1559 gasOracle', function () {
|
||||
|
||||
describe(`estimateGas ${chainId}`, function () {
|
||||
it('should return error if not eip-1559 not supported', async function () {
|
||||
if (chainId === ChainId.OPTIMISM || chainId === ChainId.ARBITRUM || chainId === ChainId.BSC) {
|
||||
if (chainId === ChainId.OPTIMISM || chainId === ChainId.BSC) {
|
||||
await eipOracle.eip1559
|
||||
.estimateFees()
|
||||
.should.be.rejectedWith('An error occurred while fetching current base fee, falling back')
|
||||
}
|
||||
})
|
||||
|
||||
if (chainId === ChainId.OPTIMISM || chainId === ChainId.ARBITRUM || chainId === ChainId.BSC) {
|
||||
if (chainId === ChainId.OPTIMISM || chainId === ChainId.BSC) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -143,6 +143,16 @@ describe('eip-1559 gasOracle', function () {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('estimate ARBITRUM', function () {
|
||||
it('should be priority 0', async function () {
|
||||
const eipOracle = new GasPriceOracle({ minPriority: 0, chainId: ChainId.ARBITRUM })
|
||||
const estimateGas: EstimatedGasPrice = await eipOracle.eip1559.estimateFees(FALLBACK_ESTIMATE)
|
||||
|
||||
console.log('estimateGas.maxPriorityFeePerGas', estimateGas.maxPriorityFeePerGas)
|
||||
estimateGas.maxPriorityFeePerGas.should.be.at.equal(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
after('after', function () {
|
||||
|
@ -42,7 +42,7 @@ beforeEach('beforeEach', function () {
|
||||
;({ onChainOracles, offChainOracles } = oracle.legacy)
|
||||
})
|
||||
|
||||
const INJECTED_RPC_URL = 'https://ethereum-rpc.trustwalletapp.com'
|
||||
const INJECTED_RPC_URL = 'https://cloudflare-eth.com'
|
||||
|
||||
describe('legacy gasOracle', function () {
|
||||
describe('legacy constructor', function () {
|
||||
@ -191,7 +191,7 @@ describe('legacy gasOracle', function () {
|
||||
|
||||
const gas = (await oracle.gasPrices({ isLegacy: true })) as unknown as GasPrice
|
||||
|
||||
const shouldBe = LegacyGasPriceOracle.getMultipliedPrices(NETWORKS[ChainId.MAINNET].defaultGasPrice)
|
||||
const shouldBe = LegacyGasPriceOracle.getCategorize(NETWORKS[ChainId.MAINNET].defaultGasPrice)
|
||||
|
||||
gas.instant.should.be.equal(shouldBe.instant)
|
||||
gas.fast.should.be.equal(shouldBe.fast)
|
||||
|
Loading…
Reference in New Issue
Block a user