dkg.js 8.2.1 → 8.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -4727,7 +4727,8 @@ class BlockchainServiceBase {
4727
4727
  try {
4728
4728
  // eth_feeHistory params: blockCount, newestBlock, rewardPercentiles
4729
4729
  // [50] = median priority fee per block
4730
- const feeHistory = await web3Instance.eth.getFeeHistory(blockCount, 'latest', [50]);
4730
+ const priorityFeePercentile = blockchain.priorityFeePercentile ?? 80;
4731
+ const feeHistory = await web3Instance.eth.getFeeHistory(blockCount, 'latest', [priorityFeePercentile]);
4731
4732
 
4732
4733
  // Extract median priority fees from each block (reward[blockIndex][percentileIndex])
4733
4734
  const priorityFees = feeHistory.reward
@@ -4751,13 +4752,14 @@ class BlockchainServiceBase {
4751
4752
 
4752
4753
  /**
4753
4754
  * Apply buffer percentage to a gas price
4754
- * @param {BigInt} gasPrice - Gas price in wei
4755
+ * @param {BigInt} maxBaseFee - base fee in wei
4756
+ * @param {BigInt} maxPriorityFee - priority fee in wei
4755
4757
  * @param {number} gasPriceBufferPercent - Buffer percentage to add
4756
4758
  * @returns {BigInt} Gas price with buffer applied
4757
4759
  */
4758
- applyGasPriceBuffer(gasPrice, gasPriceBufferPercent) {
4759
- if (!gasPriceBufferPercent) return gasPrice;
4760
- return (gasPrice * BigInt(100 + Number(gasPriceBufferPercent))) / 100n;
4760
+ applyGasPriceBuffer(maxBaseFee, maxPriorityFee, gasPriceBufferPercent) {
4761
+ if (!gasPriceBufferPercent) return maxBaseFee + maxPriorityFee;
4762
+ return ((maxBaseFee * BigInt(100 + Number(gasPriceBufferPercent))) / 100n) + maxPriorityFee;
4761
4763
  }
4762
4764
 
4763
4765
  /**
@@ -4774,6 +4776,7 @@ class BlockchainServiceBase {
4774
4776
  // Fallback to network gas price if feeHistory not supported or empty
4775
4777
  if (!feeHistory.supported) {
4776
4778
  return this.applyGasPriceBuffer(
4779
+ 0n,
4777
4780
  BigInt(await this.getNetworkGasPrice(blockchain)),
4778
4781
  gasPriceBufferPercent,
4779
4782
  );
@@ -4784,6 +4787,7 @@ class BlockchainServiceBase {
4784
4787
 
4785
4788
  if (baseFees.length === 0 || priorityFees.length === 0) {
4786
4789
  return this.applyGasPriceBuffer(
4790
+ 0n,
4787
4791
  BigInt(await this.getNetworkGasPrice(blockchain)),
4788
4792
  gasPriceBufferPercent,
4789
4793
  );
@@ -4793,7 +4797,7 @@ class BlockchainServiceBase {
4793
4797
  const maxBaseFee = baseFees.reduce((max, bf) => (bf > max ? bf : max), 0n);
4794
4798
  const maxPriorityFee = priorityFees.reduce((max, pf) => (pf > max ? pf : max), 0n);
4795
4799
 
4796
- return this.applyGasPriceBuffer(maxBaseFee + maxPriorityFee, gasPriceBufferPercent);
4800
+ return this.applyGasPriceBuffer(maxBaseFee, maxPriorityFee, gasPriceBufferPercent);
4797
4801
  }
4798
4802
 
4799
4803
  /**
@@ -6237,6 +6241,10 @@ class InputService {
6237
6241
  options.blockchain?.gasPriceBufferPercent ??
6238
6242
  this.config.blockchain?.gasPriceBufferPercent ??
6239
6243
  undefined;
6244
+ const priorityFeePercentile =
6245
+ options.blockchain?.priorityFeePercentile ??
6246
+ this.config.blockchain?.priorityFeePercentile ??
6247
+ undefined;
6240
6248
  const retryTxGasPriceMultiplier =
6241
6249
  options.blockchain?.retryTxGasPriceMultiplier ??
6242
6250
  this.config.blockchain?.retryTxGasPriceMultiplier ??
@@ -6257,6 +6265,7 @@ class InputService {
6257
6265
  gasPriceOracleLink,
6258
6266
  maxAllowance,
6259
6267
  gasPriceBufferPercent,
6268
+ priorityFeePercentile,
6260
6269
  retryTxGasPriceMultiplier,
6261
6270
  };
6262
6271
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dkg.js",
3
- "version": "8.2.1",
3
+ "version": "8.2.2",
4
4
  "description": "Javascript library for interaction with the OriginTrail Decentralized Knowledge Graph",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -63,7 +63,7 @@
63
63
  "os-browserify": "^0.3.0",
64
64
  "prettier": "^2.7.1",
65
65
  "rollup": "^4.28.1",
66
- "@rollup/rollup-linux-x64-gnu": "^4.53.1",
66
+ "@rollup/rollup-linux-x64-gnu": "^4.28.1",
67
67
  "stream-browserify": "^3.0.0",
68
68
  "stream-http": "^3.2.0",
69
69
  "terser-webpack-plugin": "^5.3.6",
@@ -1402,7 +1402,8 @@ export default class BlockchainServiceBase {
1402
1402
  try {
1403
1403
  // eth_feeHistory params: blockCount, newestBlock, rewardPercentiles
1404
1404
  // [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]);
1406
1407
 
1407
1408
  // Extract median priority fees from each block (reward[blockIndex][percentileIndex])
1408
1409
  const priorityFees = feeHistory.reward
@@ -1426,13 +1427,14 @@ export default class BlockchainServiceBase {
1426
1427
 
1427
1428
  /**
1428
1429
  * 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
1430
1432
  * @param {number} gasPriceBufferPercent - Buffer percentage to add
1431
1433
  * @returns {BigInt} Gas price with buffer applied
1432
1434
  */
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;
1436
1438
  }
1437
1439
 
1438
1440
  /**
@@ -1449,6 +1451,7 @@ export default class BlockchainServiceBase {
1449
1451
  // Fallback to network gas price if feeHistory not supported or empty
1450
1452
  if (!feeHistory.supported) {
1451
1453
  return this.applyGasPriceBuffer(
1454
+ 0n,
1452
1455
  BigInt(await this.getNetworkGasPrice(blockchain)),
1453
1456
  gasPriceBufferPercent,
1454
1457
  );
@@ -1459,6 +1462,7 @@ export default class BlockchainServiceBase {
1459
1462
 
1460
1463
  if (baseFees.length === 0 || priorityFees.length === 0) {
1461
1464
  return this.applyGasPriceBuffer(
1465
+ 0n,
1462
1466
  BigInt(await this.getNetworkGasPrice(blockchain)),
1463
1467
  gasPriceBufferPercent,
1464
1468
  );
@@ -1468,7 +1472,7 @@ export default class BlockchainServiceBase {
1468
1472
  const maxBaseFee = baseFees.reduce((max, bf) => (bf > max ? bf : max), 0n);
1469
1473
  const maxPriorityFee = priorityFees.reduce((max, pf) => (pf > max ? pf : max), 0n);
1470
1474
 
1471
- return this.applyGasPriceBuffer(maxBaseFee + maxPriorityFee, gasPriceBufferPercent);
1475
+ return this.applyGasPriceBuffer(maxBaseFee, maxPriorityFee, gasPriceBufferPercent);
1472
1476
  }
1473
1477
 
1474
1478
  /**
@@ -198,6 +198,10 @@ export default class InputService {
198
198
  options.blockchain?.gasPriceBufferPercent ??
199
199
  this.config.blockchain?.gasPriceBufferPercent ??
200
200
  undefined;
201
+ const priorityFeePercentile =
202
+ options.blockchain?.priorityFeePercentile ??
203
+ this.config.blockchain?.priorityFeePercentile ??
204
+ undefined;
201
205
  const retryTxGasPriceMultiplier =
202
206
  options.blockchain?.retryTxGasPriceMultiplier ??
203
207
  this.config.blockchain?.retryTxGasPriceMultiplier ??
@@ -218,6 +222,7 @@ export default class InputService {
218
222
  gasPriceOracleLink,
219
223
  maxAllowance,
220
224
  gasPriceBufferPercent,
225
+ priorityFeePercentile,
221
226
  retryTxGasPriceMultiplier,
222
227
  };
223
228