@requestnetwork/utils 0.36.1-next.1846 → 0.36.1-next.1848
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/dist/estimate-gas-fees.d.ts +21 -0
- package/dist/estimate-gas-fees.d.ts.map +1 -0
- package/dist/estimate-gas-fees.js +34 -0
- package/dist/estimate-gas-fees.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BigNumber, providers } from 'ethers';
|
|
2
|
+
/**
|
|
3
|
+
* The function estimates gas fee with EIP-1559.
|
|
4
|
+
* @param provider Generic provider.
|
|
5
|
+
* @param gasPriceMin Minimum gas price to return.
|
|
6
|
+
* @returns an object containing:
|
|
7
|
+
* - maxFeePerGas: The maximum fee per unit of gas for this transaction.
|
|
8
|
+
* maxFeePerGas = baseFeePerGas + maxPriorityFeePerGas
|
|
9
|
+
* The baseFeePerGas depends on how full the previous blocks were.
|
|
10
|
+
* - maxPriorityFeePerGas: The maximum priority fee per unit of gas for this transaction.
|
|
11
|
+
* - gasPrice: Optional fallback: the gas price for this transaction.
|
|
12
|
+
*/
|
|
13
|
+
declare function estimateGasFees({ provider, gasPriceMin, }: {
|
|
14
|
+
provider: providers.Provider | providers.JsonRpcProvider;
|
|
15
|
+
gasPriceMin?: BigNumber;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
maxFeePerGas?: BigNumber;
|
|
18
|
+
maxPriorityFeePerGas?: BigNumber;
|
|
19
|
+
}>;
|
|
20
|
+
export default estimateGasFees;
|
|
21
|
+
//# sourceMappingURL=estimate-gas-fees.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"estimate-gas-fees.d.ts","sourceRoot":"","sources":["../src/estimate-gas-fees.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,SAAS,EAAE,MAAM,QAAQ,CAAC;AAIzD;;;;;;;;;;GAUG;AACH,iBAAe,eAAe,CAAC,EAC7B,QAAQ,EACR,WAAW,GACZ,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,eAAe,CAAC;IACzD,WAAW,CAAC,EAAE,SAAS,CAAC;CACzB,GAAG,OAAO,CAAC;IACV,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,oBAAoB,CAAC,EAAE,SAAS,CAAC;CAClC,CAAC,CAmBD;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const eip1559_fee_suggestions_ethers_1 = require("eip1559-fee-suggestions-ethers");
|
|
6
|
+
const index_1 = require("./index");
|
|
7
|
+
/**
|
|
8
|
+
* The function estimates gas fee with EIP-1559.
|
|
9
|
+
* @param provider Generic provider.
|
|
10
|
+
* @param gasPriceMin Minimum gas price to return.
|
|
11
|
+
* @returns an object containing:
|
|
12
|
+
* - maxFeePerGas: The maximum fee per unit of gas for this transaction.
|
|
13
|
+
* maxFeePerGas = baseFeePerGas + maxPriorityFeePerGas
|
|
14
|
+
* The baseFeePerGas depends on how full the previous blocks were.
|
|
15
|
+
* - maxPriorityFeePerGas: The maximum priority fee per unit of gas for this transaction.
|
|
16
|
+
* - gasPrice: Optional fallback: the gas price for this transaction.
|
|
17
|
+
*/
|
|
18
|
+
function estimateGasFees({ provider, gasPriceMin, }) {
|
|
19
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
20
|
+
const suggestedFee = yield (0, eip1559_fee_suggestions_ethers_1.suggestFees)(provider);
|
|
21
|
+
const baseFee = index_1.default.max(suggestedFee.baseFeeSuggestion, gasPriceMin || ethers_1.constants.Zero);
|
|
22
|
+
const maxPriorityFeePerGas = index_1.default.max(suggestedFee.maxPriorityFeeSuggestions.urgent, gasPriceMin || ethers_1.constants.Zero);
|
|
23
|
+
const maxFeePerGas = baseFee.add(maxPriorityFeePerGas);
|
|
24
|
+
if (maxPriorityFeePerGas.eq(0) || maxFeePerGas.eq(0)) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
maxPriorityFeePerGas,
|
|
29
|
+
maxFeePerGas,
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.default = estimateGasFees;
|
|
34
|
+
//# sourceMappingURL=estimate-gas-fees.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"estimate-gas-fees.js","sourceRoot":"","sources":["../src/estimate-gas-fees.ts"],"names":[],"mappings":";;;AAAA,mCAAyD;AACzD,mFAA6D;AAC7D,mCAA4B;AAE5B;;;;;;;;;;GAUG;AACH,SAAe,eAAe,CAAC,EAC7B,QAAQ,EACR,WAAW,GAIZ;;QAIC,MAAM,YAAY,GAAG,MAAM,IAAA,4CAAW,EAAC,QAAqC,CAAC,CAAC;QAE9E,MAAM,OAAO,GAAG,eAAK,CAAC,GAAG,CAAC,YAAY,CAAC,iBAAiB,EAAE,WAAW,IAAI,kBAAS,CAAC,IAAI,CAAC,CAAC;QAEzF,MAAM,oBAAoB,GAAG,eAAK,CAAC,GAAG,CACpC,YAAY,CAAC,yBAAyB,CAAC,MAAM,EAC7C,WAAW,IAAI,kBAAS,CAAC,IAAI,CAC9B,CAAC;QACF,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAEvD,IAAI,oBAAoB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;YACpD,OAAO,EAAE,CAAC;SACX;QAED,OAAO;YACL,oBAAoB;YACpB,YAAY;SACb,CAAC;IACJ,CAAC;CAAA;AAED,kBAAe,eAAe,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import SimpleLogger from './simple-logger';
|
|
3
|
+
import estimateGasFees from './estimate-gas-fees';
|
|
3
4
|
declare const _default: {
|
|
5
|
+
estimateGasFees: typeof estimateGasFees;
|
|
4
6
|
min: (a: import("ethers").BigNumberish, b: import("ethers").BigNumberish) => import("ethers").BigNumber;
|
|
5
7
|
max: (a: import("ethers").BigNumberish, b: import("ethers").BigNumberish) => import("ethers").BigNumber;
|
|
6
8
|
deepCopy: <T>(variable: T) => T;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAOA,OAAO,YAAY,MAAM,iBAAiB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAOA,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAI3C,OAAO,eAAe,MAAM,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAElD;;GAEG;AACH,wBAaE"}
|
package/dist/index.js
CHANGED
|
@@ -11,15 +11,16 @@ const simple_logger_1 = require("./simple-logger");
|
|
|
11
11
|
const utils_1 = require("./utils");
|
|
12
12
|
const providers_1 = require("./providers");
|
|
13
13
|
const bignumber_1 = require("./bignumber");
|
|
14
|
+
const estimate_gas_fees_1 = require("./estimate-gas-fees");
|
|
14
15
|
/**
|
|
15
16
|
* Collection of general purpose utility function
|
|
16
17
|
*/
|
|
17
|
-
exports.default = Object.assign(Object.assign(Object.assign({ SimpleLogger: simple_logger_1.default,
|
|
18
|
+
exports.default = Object.assign(Object.assign(Object.assign(Object.assign({ SimpleLogger: simple_logger_1.default,
|
|
18
19
|
amount: amount_1.default,
|
|
19
20
|
cachedThrottle: cached_throttle_1.default,
|
|
20
21
|
crypto: crypto_1.default,
|
|
21
22
|
encryption: encryption_1.default,
|
|
22
23
|
identity: identity_1.default,
|
|
23
24
|
retry: retry_1.default,
|
|
24
|
-
signature: signature_1.default }, providers_1.default), utils_1.default), bignumber_1.default);
|
|
25
|
+
signature: signature_1.default }, providers_1.default), utils_1.default), bignumber_1.default), { estimateGasFees: estimate_gas_fees_1.default });
|
|
25
26
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,qCAA8B;AAC9B,uDAA+C;AAC/C,qCAA8B;AAC9B,6CAAsC;AACtC,yCAAkC;AAClC,mCAA4B;AAC5B,2CAAoC;AACpC,mDAA2C;AAC3C,mCAA4B;AAC5B,2CAAoC;AACpC,2CAAqC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,qCAA8B;AAC9B,uDAA+C;AAC/C,qCAA8B;AAC9B,6CAAsC;AACtC,yCAAkC;AAClC,mCAA4B;AAC5B,2CAAoC;AACpC,mDAA2C;AAC3C,mCAA4B;AAC5B,2CAAoC;AACpC,2CAAqC;AACrC,2DAAkD;AAElD;;GAEG;AACH,4EACE,YAAY,EAAZ,uBAAY;IACZ,MAAM,EAAN,gBAAM;IACN,cAAc,EAAd,yBAAc;IACd,MAAM,EAAN,gBAAM;IACN,UAAU,EAAV,oBAAU;IACV,QAAQ,EAAR,kBAAQ;IACR,KAAK,EAAL,eAAK;IACL,SAAS,EAAT,mBAAS,IACN,mBAAS,GACT,eAAK,GACL,mBAAU,KACb,eAAe,EAAf,2BAAe,IACf"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@requestnetwork/utils",
|
|
3
|
-
"version": "0.36.1-next.
|
|
3
|
+
"version": "0.36.1-next.1848+47bf2d83",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -40,8 +40,9 @@
|
|
|
40
40
|
"test:watch": "yarn test --watch"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@requestnetwork/types": "0.36.1-next.
|
|
43
|
+
"@requestnetwork/types": "0.36.1-next.1848+47bf2d83",
|
|
44
44
|
"eccrypto": "1.1.6",
|
|
45
|
+
"eip1559-fee-suggestions-ethers": "1.3.3",
|
|
45
46
|
"ethers": "5.5.1",
|
|
46
47
|
"secp256k1": "4.0.2",
|
|
47
48
|
"tslib": "2.3.1"
|
|
@@ -56,5 +57,5 @@
|
|
|
56
57
|
"ts-node": "9.0.0",
|
|
57
58
|
"typescript": "4.4.4"
|
|
58
59
|
},
|
|
59
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "47bf2d830677f19270505cd883c97ac5a99ad095"
|
|
60
61
|
}
|