Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
14 changes: 8 additions & 6 deletions services/blockchain-service/blockchain-service-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,8 @@ export default class BlockchainServiceBase {
try {
// eth_feeHistory params: blockCount, newestBlock, rewardPercentiles
// [50] = median priority fee per block
const feeHistory = await web3Instance.eth.getFeeHistory(blockCount, 'latest', [50]);
const priorityFeePercentile = blockchain.priorityFeePercentile ?? 80;
const feeHistory = await web3Instance.eth.getFeeHistory(blockCount, 'latest', [priorityFeePercentile]);

// Extract median priority fees from each block (reward[blockIndex][percentileIndex])
const priorityFees = feeHistory.reward
Expand All @@ -1426,13 +1427,14 @@ export default class BlockchainServiceBase {

/**
* Apply buffer percentage to a gas price
* @param {BigInt} gasPrice - Gas price in wei
* @param {BigInt} maxBaseFee - base fee in wei
* @param {BigInt} maxPriorityFee - priority fee in wei
* @param {number} gasPriceBufferPercent - Buffer percentage to add
* @returns {BigInt} Gas price with buffer applied
*/
applyGasPriceBuffer(gasPrice, gasPriceBufferPercent) {
if (!gasPriceBufferPercent) return gasPrice;
return (gasPrice * BigInt(100 + Number(gasPriceBufferPercent))) / 100n;
applyGasPriceBuffer(maxBaseFee, maxPriorityFee, gasPriceBufferPercent) {
if (!gasPriceBufferPercent) return maxBaseFee + maxPriorityFee;
return ((maxBaseFee * BigInt(100 + Number(gasPriceBufferPercent))) / 100n) + maxPriorityFee;
}

/**
Expand Down Expand Up @@ -1468,7 +1470,7 @@ export default class BlockchainServiceBase {
const maxBaseFee = baseFees.reduce((max, bf) => (bf > max ? bf : max), 0n);
const maxPriorityFee = priorityFees.reduce((max, pf) => (pf > max ? pf : max), 0n);

return this.applyGasPriceBuffer(maxBaseFee + maxPriorityFee, gasPriceBufferPercent);
return this.applyGasPriceBuffer(maxBaseFee, maxPriorityFee, gasPriceBufferPercent);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions services/input-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ export default class InputService {
options.blockchain?.gasPriceBufferPercent ??
this.config.blockchain?.gasPriceBufferPercent ??
undefined;
const priorityFeePercentile =
options.blockchain?.priorityFeePercentile ??
this.config.blockchain?.priorityFeePercentile ??
undefined;
const retryTxGasPriceMultiplier =
options.blockchain?.retryTxGasPriceMultiplier ??
this.config.blockchain?.retryTxGasPriceMultiplier ??
Expand All @@ -218,6 +222,7 @@ export default class InputService {
gasPriceOracleLink,
maxAllowance,
gasPriceBufferPercent,
priorityFeePercentile,
retryTxGasPriceMultiplier,
};

Expand Down