Skip to content

Commit 53d7f99

Browse files
authored
Merge pull request #267 from OriginTrail/patch/percentile-constant-change-and-only-buffer-multiply
percentile 80, bufferPercent multiply
2 parents 88aaddc + 0e6a648 commit 53d7f99

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

services/blockchain-service/blockchain-service-base.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,8 @@ export default class BlockchainServiceBase {
14021402
try {
14031403
// eth_feeHistory params: blockCount, newestBlock, rewardPercentiles
14041404
// [50] = median priority fee per block
1405-
const feeHistory = await web3Instance.eth.getFeeHistory(blockCount, 'latest', [50]);
1405+
const priorityFeePercentile = blockchain.priorityFeePercentile ?? 80;
1406+
const feeHistory = await web3Instance.eth.getFeeHistory(blockCount, 'latest', [priorityFeePercentile]);
14061407

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

14271428
/**
14281429
* Apply buffer percentage to a gas price
1429-
* @param {BigInt} gasPrice - Gas price in wei
1430+
* @param {BigInt} maxBaseFee - base fee in wei
1431+
* @param {BigInt} maxPriorityFee - priority fee in wei
14301432
* @param {number} gasPriceBufferPercent - Buffer percentage to add
14311433
* @returns {BigInt} Gas price with buffer applied
14321434
*/
1433-
applyGasPriceBuffer(gasPrice, gasPriceBufferPercent) {
1434-
if (!gasPriceBufferPercent) return gasPrice;
1435-
return (gasPrice * BigInt(100 + Number(gasPriceBufferPercent))) / 100n;
1435+
applyGasPriceBuffer(maxBaseFee, maxPriorityFee, gasPriceBufferPercent) {
1436+
if (!gasPriceBufferPercent) return maxBaseFee + maxPriorityFee;
1437+
return ((maxBaseFee * BigInt(100 + Number(gasPriceBufferPercent))) / 100n) + maxPriorityFee;
14361438
}
14371439

14381440
/**
@@ -1449,6 +1451,7 @@ export default class BlockchainServiceBase {
14491451
// Fallback to network gas price if feeHistory not supported or empty
14501452
if (!feeHistory.supported) {
14511453
return this.applyGasPriceBuffer(
1454+
0n,
14521455
BigInt(await this.getNetworkGasPrice(blockchain)),
14531456
gasPriceBufferPercent,
14541457
);
@@ -1459,6 +1462,7 @@ export default class BlockchainServiceBase {
14591462

14601463
if (baseFees.length === 0 || priorityFees.length === 0) {
14611464
return this.applyGasPriceBuffer(
1465+
0n,
14621466
BigInt(await this.getNetworkGasPrice(blockchain)),
14631467
gasPriceBufferPercent,
14641468
);
@@ -1468,7 +1472,7 @@ export default class BlockchainServiceBase {
14681472
const maxBaseFee = baseFees.reduce((max, bf) => (bf > max ? bf : max), 0n);
14691473
const maxPriorityFee = priorityFees.reduce((max, pf) => (pf > max ? pf : max), 0n);
14701474

1471-
return this.applyGasPriceBuffer(maxBaseFee + maxPriorityFee, gasPriceBufferPercent);
1475+
return this.applyGasPriceBuffer(maxBaseFee, maxPriorityFee, gasPriceBufferPercent);
14721476
}
14731477

14741478
/**

services/input-service.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ export default class InputService {
198198
options.blockchain?.gasPriceBufferPercent ??
199199
this.config.blockchain?.gasPriceBufferPercent ??
200200
undefined;
201+
const priorityFeePercentile =
202+
options.blockchain?.priorityFeePercentile ??
203+
this.config.blockchain?.priorityFeePercentile ??
204+
undefined;
201205
const retryTxGasPriceMultiplier =
202206
options.blockchain?.retryTxGasPriceMultiplier ??
203207
this.config.blockchain?.retryTxGasPriceMultiplier ??
@@ -218,6 +222,7 @@ export default class InputService {
218222
gasPriceOracleLink,
219223
maxAllowance,
220224
gasPriceBufferPercent,
225+
priorityFeePercentile,
221226
retryTxGasPriceMultiplier,
222227
};
223228

0 commit comments

Comments
 (0)