@across-protocol/sdk 4.3.129 → 4.3.131-alpha.0
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/cjs/src/caching/Arweave/ArweaveClient.d.ts +2 -0
- package/dist/cjs/src/caching/Arweave/ArweaveClient.js +20 -16
- package/dist/cjs/src/caching/Arweave/ArweaveClient.js.map +1 -1
- package/dist/cjs/src/gasPriceOracle/adapters/ethereum.d.ts +1 -0
- package/dist/cjs/src/gasPriceOracle/adapters/ethereum.js +44 -0
- package/dist/cjs/src/gasPriceOracle/adapters/ethereum.js.map +1 -1
- package/dist/cjs/src/gasPriceOracle/oracle.d.ts +8 -3
- package/dist/cjs/src/gasPriceOracle/oracle.js +21 -40
- package/dist/cjs/src/gasPriceOracle/oracle.js.map +1 -1
- package/dist/esm/src/caching/Arweave/ArweaveClient.d.ts +2 -0
- package/dist/esm/src/caching/Arweave/ArweaveClient.js +20 -18
- package/dist/esm/src/caching/Arweave/ArweaveClient.js.map +1 -1
- package/dist/esm/src/gasPriceOracle/adapters/ethereum.d.ts +6 -0
- package/dist/esm/src/gasPriceOracle/adapters/ethereum.js +50 -1
- package/dist/esm/src/gasPriceOracle/adapters/ethereum.js.map +1 -1
- package/dist/esm/src/gasPriceOracle/oracle.d.ts +8 -10
- package/dist/esm/src/gasPriceOracle/oracle.js +24 -41
- package/dist/esm/src/gasPriceOracle/oracle.js.map +1 -1
- package/dist/types/src/caching/Arweave/ArweaveClient.d.ts +2 -0
- package/dist/types/src/caching/Arweave/ArweaveClient.d.ts.map +1 -1
- package/dist/types/src/gasPriceOracle/adapters/ethereum.d.ts +6 -0
- package/dist/types/src/gasPriceOracle/adapters/ethereum.d.ts.map +1 -1
- package/dist/types/src/gasPriceOracle/oracle.d.ts +8 -10
- package/dist/types/src/gasPriceOracle/oracle.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/caching/Arweave/ArweaveClient.ts +8 -16
- package/src/gasPriceOracle/adapters/ethereum.ts +52 -1
- package/src/gasPriceOracle/oracle.ts +18 -26
|
@@ -16,6 +16,8 @@ var ArweaveClient = (function () {
|
|
|
16
16
|
if (retryDelaySeconds === void 0) { retryDelaySeconds = 1; }
|
|
17
17
|
this.arweaveJWT = arweaveJWT;
|
|
18
18
|
this.logger = logger;
|
|
19
|
+
this.gatewayURL = gatewayURL;
|
|
20
|
+
this.protocol = protocol;
|
|
19
21
|
this.retries = retries;
|
|
20
22
|
this.retryDelaySeconds = retryDelaySeconds;
|
|
21
23
|
this.gatewayUrl = "".concat(protocol, "://").concat(gatewayURL, ":").concat(port);
|
|
@@ -90,24 +92,26 @@ var ArweaveClient = (function () {
|
|
|
90
92
|
};
|
|
91
93
|
ArweaveClient.prototype.get = function (transactionID, validator) {
|
|
92
94
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
93
|
-
var transactionUrl,
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
var transactionUrl, request, data;
|
|
96
|
+
var _this = this;
|
|
97
|
+
return tslib_1.__generator(this, function (_a) {
|
|
98
|
+
switch (_a.label) {
|
|
96
99
|
case 0:
|
|
97
100
|
transactionUrl = "".concat(this.gatewayUrl, "/").concat(transactionID);
|
|
98
|
-
return
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
data: data,
|
|
101
|
+
request = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
102
|
+
var requestData;
|
|
103
|
+
return tslib_1.__generator(this, function (_a) {
|
|
104
|
+
switch (_a.label) {
|
|
105
|
+
case 0: return [4, axios_1.default.get(transactionUrl)];
|
|
106
|
+
case 1:
|
|
107
|
+
requestData = (_a.sent()).data;
|
|
108
|
+
return [2, requestData];
|
|
109
|
+
}
|
|
108
110
|
});
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
}); };
|
|
112
|
+
return [4, this._retryRequest(request, 0)];
|
|
113
|
+
case 1:
|
|
114
|
+
data = _a.sent();
|
|
111
115
|
try {
|
|
112
116
|
return [2, (0, superstruct_1.create)(data, validator)];
|
|
113
117
|
}
|
|
@@ -221,7 +225,7 @@ var ArweaveClient = (function () {
|
|
|
221
225
|
baseDelay = this.retryDelaySeconds * Math.pow(2, retryCount);
|
|
222
226
|
delayS = baseDelay + baseDelay * Math.random();
|
|
223
227
|
this.logger.debug({
|
|
224
|
-
at: "ArweaveClient:
|
|
228
|
+
at: "ArweaveClient:retryRequest",
|
|
225
229
|
message: "Arweave request failed, retrying after waiting ".concat(delayS, " seconds: ").concat(e_2),
|
|
226
230
|
retryCount: retryCount,
|
|
227
231
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArweaveClient.js","sourceRoot":"","sources":["../../../../../src/caching/Arweave/ArweaveClient.ts"],"names":[],"mappings":";;;;AAAA,4DAA8B;AAE9B,wDAA0B;AAC1B,2CAA6C;AAE7C,6CAAiH;AACjH,qCAA4F;AAE5F;IAIE,uBACU,UAAwB,EACxB,MAAsB,
|
|
1
|
+
{"version":3,"file":"ArweaveClient.js","sourceRoot":"","sources":["../../../../../src/caching/Arweave/ArweaveClient.ts"],"names":[],"mappings":";;;;AAAA,4DAA8B;AAE9B,wDAA0B;AAC1B,2CAA6C;AAE7C,6CAAiH;AACjH,qCAA4F;AAE5F;IAIE,uBACU,UAAwB,EACxB,MAAsB,EACvB,UAA0B,EAC1B,QAAkB,EACzB,IAAU,EACO,OAAW,EACX,iBAAqB;QAJ/B,2BAAA,EAAA,0BAA0B;QAC1B,yBAAA,EAAA,kBAAkB;QACzB,qBAAA,EAAA,UAAU;QACO,wBAAA,EAAA,WAAW;QACX,kCAAA,EAAA,qBAAqB;QAN9B,eAAU,GAAV,UAAU,CAAc;QACxB,WAAM,GAAN,MAAM,CAAgB;QACvB,eAAU,GAAV,UAAU,CAAgB;QAC1B,aAAQ,GAAR,QAAQ,CAAU;QAER,YAAO,GAAP,OAAO,C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MK,kCAAU,GAAhB;;;;;;4BACkB,WAAM,IAAI,CAAC,UAAU,EAAE,EAAA;;wBAAjC,OAAO,GAAG,SAAuB;wBACjC,OAAO,GAAG;;;;4CACS,WAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,EAAA;;wCAA9D,cAAc,GAAG,SAA6C;wCAMpE,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;4CAC3B,KAAsB,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,EAA9C,OAAO,QAAA,EAAE,QAAQ,QAAA,CAA8B;4CAChD,WAAW,GAAG,iBAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,IAAA,YAAI,EAAC,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;4CACzF,WAAO,iBAAS,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,EAAC;wCAChD,CAAC;6CAAM,CAAC;4CACN,WAAO,iBAAS,CAAC,IAAI,CAAC,cAAc,CAAC,EAAC;wCACxC,CAAC;;;;6BACF,CAAC;wBACK,WAAM,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC,EAAA;4BAA3C,WAAO,SAAoC,EAAC;;;;KAC7C;IACH,oBAAC;AAAD,CAAC,AAvQD,IAuQC;AAvQY,sCAAa"}
|
|
@@ -4,4 +4,5 @@ import { EvmGasPriceEstimate } from "../types";
|
|
|
4
4
|
import { GasPriceEstimateOptions } from "../oracle";
|
|
5
5
|
export declare function eip1559(provider: providers.Provider, opts: GasPriceEstimateOptions): Promise<EvmGasPriceEstimate>;
|
|
6
6
|
export declare function eip1559Raw(provider: providers.Provider, chainId: number, baseFeeMultiplier: BigNumber, priorityFeeMultiplier: BigNumber): Promise<EvmGasPriceEstimate>;
|
|
7
|
+
export declare function feeHistory(provider: providers.Provider, opts: GasPriceEstimateOptions): Promise<EvmGasPriceEstimate>;
|
|
7
8
|
export declare function legacy(provider: providers.Provider, opts: GasPriceEstimateOptions): Promise<EvmGasPriceEstimate>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.eip1559 = eip1559;
|
|
4
4
|
exports.eip1559Raw = eip1559Raw;
|
|
5
|
+
exports.feeHistory = feeHistory;
|
|
5
6
|
exports.legacy = legacy;
|
|
6
7
|
var tslib_1 = require("tslib");
|
|
7
8
|
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
@@ -33,6 +34,49 @@ function eip1559Raw(provider, chainId, baseFeeMultiplier, priorityFeeMultiplier)
|
|
|
33
34
|
});
|
|
34
35
|
});
|
|
35
36
|
}
|
|
37
|
+
function feeHistory(provider, opts) {
|
|
38
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
39
|
+
var baseFeeMultiplier, feeHistoryOptions, _a, percentile, _b, blockLookback, _c, minimumPriority, _d, baseFeePerGas, feeHistory, defaultEstimator, _e, estimator, maxPriorityFeePerGas, scaledBaseFee;
|
|
40
|
+
return tslib_1.__generator(this, function (_f) {
|
|
41
|
+
switch (_f.label) {
|
|
42
|
+
case 0:
|
|
43
|
+
baseFeeMultiplier = opts.baseFeeMultiplier, feeHistoryOptions = opts.feeHistoryOptions;
|
|
44
|
+
(0, assert_1.default)((0, utils_1.isDefined)(feeHistoryOptions));
|
|
45
|
+
_a = feeHistoryOptions.percentile, percentile = _a === void 0 ? 20 : _a, _b = feeHistoryOptions.blockLookback, blockLookback = _b === void 0 ? 10 : _b, _c = feeHistoryOptions.minimumPriority, minimumPriority = _c === void 0 ? utils_1.bnOne : _c;
|
|
46
|
+
return [4, Promise.all([
|
|
47
|
+
provider.getBlock("latest"),
|
|
48
|
+
provider.send("eth_feeHistory", [blockLookback, "latest", [percentile]]),
|
|
49
|
+
])];
|
|
50
|
+
case 1:
|
|
51
|
+
_d = _f.sent(), baseFeePerGas = _d[0].baseFeePerGas, feeHistory = _d[1];
|
|
52
|
+
(0, assert_1.default)(utils_1.BigNumber.isBigNumber(baseFeePerGas), "No baseFeePerGas received on latest block query.");
|
|
53
|
+
defaultEstimator = function (rewards) {
|
|
54
|
+
var sortedRewards = rewards
|
|
55
|
+
.filter(function (reward) { return reward.gt(utils_1.bnZero); })
|
|
56
|
+
.sort(function (r1, r2) {
|
|
57
|
+
if (r1.gt(r2)) {
|
|
58
|
+
return 1;
|
|
59
|
+
}
|
|
60
|
+
return r1.eq(r2) ? 0 : -1;
|
|
61
|
+
});
|
|
62
|
+
if (sortedRewards.length === 0) {
|
|
63
|
+
return minimumPriority;
|
|
64
|
+
}
|
|
65
|
+
var n = sortedRewards.length;
|
|
66
|
+
var median = n % 2 === 0 ? sortedRewards[n / 2 - 1].add(sortedRewards[n / 2].div(2)) : sortedRewards[n / 2];
|
|
67
|
+
return median.gt(minimumPriority) ? median : minimumPriority;
|
|
68
|
+
};
|
|
69
|
+
_e = feeHistoryOptions.estimator, estimator = _e === void 0 ? defaultEstimator : _e;
|
|
70
|
+
maxPriorityFeePerGas = estimator(feeHistory.rewards);
|
|
71
|
+
scaledBaseFee = baseFeePerGas.mul(baseFeeMultiplier).div(utils_1.fixedPointAdjustment);
|
|
72
|
+
return [2, {
|
|
73
|
+
maxFeePerGas: scaledBaseFee.add(maxPriorityFeePerGas),
|
|
74
|
+
maxPriorityFeePerGas: maxPriorityFeePerGas,
|
|
75
|
+
}];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
36
80
|
function legacy(provider, opts) {
|
|
37
81
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
38
82
|
var chainId, baseFeeMultiplier, gasPrice;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethereum.js","sourceRoot":"","sources":["../../../../../src/gasPriceOracle/adapters/ethereum.ts"],"names":[],"mappings":";;A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AQ,CAAC,CAAC;oBAE/G,WAAO;4BACL,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,4BAAoB,CAAC;4BACvE,oBAAoB,EAAE,cAAM;yBAC7B,EAAC;;;;CACH"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Transport } from "viem";
|
|
2
|
-
import { providers } from "ethers";
|
|
3
2
|
import { BigNumber } from "../utils";
|
|
4
3
|
import { SVMProvider as SolanaProvider } from "../arch/svm";
|
|
5
|
-
import { EvmGasPriceEstimate,
|
|
4
|
+
import { EvmGasPriceEstimate, SvmGasPriceEstimate } from "./types";
|
|
6
5
|
import { EvmProvider } from "../arch/evm/types";
|
|
7
6
|
export interface GasPriceEstimateOptions {
|
|
8
7
|
baseFeeMultiplier: BigNumber;
|
|
@@ -10,8 +9,14 @@ export interface GasPriceEstimateOptions {
|
|
|
10
9
|
legacyFallback: boolean;
|
|
11
10
|
chainId: number;
|
|
12
11
|
unsignedTx?: unknown;
|
|
12
|
+
feeHistoryOptions?: FeeHistoryOptions;
|
|
13
13
|
transport?: Transport;
|
|
14
14
|
}
|
|
15
|
+
export interface FeeHistoryOptions {
|
|
16
|
+
estimator?: (rewards: BigNumber[]) => BigNumber;
|
|
17
|
+
percentile?: number;
|
|
18
|
+
blockLookback?: number;
|
|
19
|
+
minimumPriority?: BigNumber;
|
|
20
|
+
}
|
|
15
21
|
export declare function getGasPriceEstimate(provider: EvmProvider, opts?: Partial<GasPriceEstimateOptions>): Promise<EvmGasPriceEstimate>;
|
|
16
22
|
export declare function getGasPriceEstimate(provider: SolanaProvider, opts?: Partial<GasPriceEstimateOptions>): Promise<SvmGasPriceEstimate>;
|
|
17
|
-
export declare function _getViemGasPriceEstimate(providerOrChainId: providers.Provider | number, opts: GasPriceEstimateOptions): Promise<GasPriceEstimate>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getGasPriceEstimate = getGasPriceEstimate;
|
|
4
|
-
exports._getViemGasPriceEstimate = _getViemGasPriceEstimate;
|
|
5
4
|
var tslib_1 = require("tslib");
|
|
6
5
|
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
7
6
|
var constants_1 = require("../constants");
|
|
@@ -41,72 +40,54 @@ function getGasPriceEstimate(provider_1) {
|
|
|
41
40
|
chainId = _a;
|
|
42
41
|
optsWithDefaults = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, GAS_PRICE_ESTIMATE_DEFAULTS), { baseFeeMultiplier: baseFeeMultiplier, priorityFeeMultiplier: priorityFeeMultiplier }), opts), { chainId: chainId });
|
|
43
42
|
useViem = VIEM_CHAINS.includes(chainId);
|
|
44
|
-
return [2, useViem
|
|
45
|
-
? _getViemGasPriceEstimate(chainId, optsWithDefaults)
|
|
46
|
-
: _getEthersGasPriceEstimate(provider, optsWithDefaults)];
|
|
43
|
+
return [2, useViem ? getGasPriceViem(chainId, optsWithDefaults) : getGasPriceEthers(provider, optsWithDefaults)];
|
|
47
44
|
}
|
|
48
45
|
});
|
|
49
46
|
});
|
|
50
47
|
}
|
|
51
|
-
function
|
|
48
|
+
function getGasPriceEthers(provider, opts) {
|
|
52
49
|
var _a;
|
|
53
50
|
var chainId = opts.chainId, legacyFallback = opts.legacyFallback;
|
|
54
51
|
(0, assert_1.default)(!VIEM_CHAINS.includes(chainId), "Chain ID ".concat(chainId, " will use Viem gas price estimation"));
|
|
55
52
|
var gasPriceFeeds = (_a = {},
|
|
56
53
|
_a[constants_1.CHAIN_IDs.ARBITRUM] = arbitrum.eip1559,
|
|
57
|
-
_a[constants_1.CHAIN_IDs.BSC] = ethereum.eip1559,
|
|
58
|
-
_a[constants_1.CHAIN_IDs.MAINNET] = ethereum.eip1559,
|
|
59
|
-
_a[constants_1.CHAIN_IDs.MEGAETH] = ethereum.eip1559,
|
|
60
|
-
_a[constants_1.CHAIN_IDs.MONAD] = ethereum.eip1559,
|
|
61
|
-
_a[constants_1.CHAIN_IDs.PLASMA] = ethereum.eip1559,
|
|
62
54
|
_a[constants_1.CHAIN_IDs.POLYGON] = polygon.gasStation,
|
|
63
55
|
_a[constants_1.CHAIN_IDs.SCROLL] = ethereum.legacy,
|
|
64
56
|
_a[constants_1.CHAIN_IDs.TEMPO] = ethereum.eip1559,
|
|
65
57
|
_a[constants_1.CHAIN_IDs.ZK_SYNC] = ethereum.legacy,
|
|
66
|
-
_a[constants_1.CHAIN_IDs.ARBITRUM_SEPOLIA] = arbitrum.eip1559,
|
|
67
58
|
_a[constants_1.CHAIN_IDs.POLYGON_AMOY] = polygon.gasStation,
|
|
68
|
-
_a[constants_1.CHAIN_IDs.SEPOLIA] = ethereum.eip1559,
|
|
69
59
|
_a);
|
|
70
|
-
var gasPriceFeed = gasPriceFeeds[chainId];
|
|
60
|
+
var gasPriceFeed = (0, utils_1.isDefined)(opts.feeHistoryOptions) ? ethereum.feeHistory : gasPriceFeeds[chainId];
|
|
71
61
|
(0, assert_1.default)(gasPriceFeed || legacyFallback, "No suitable gas price oracle for Chain ID ".concat(chainId));
|
|
72
|
-
gasPriceFeed !== null && gasPriceFeed !== void 0 ? gasPriceFeed : (gasPriceFeed =
|
|
62
|
+
gasPriceFeed !== null && gasPriceFeed !== void 0 ? gasPriceFeed : (gasPriceFeed = ethereum.eip1559);
|
|
73
63
|
return gasPriceFeed(provider, opts);
|
|
74
64
|
}
|
|
75
|
-
function
|
|
65
|
+
function getGasPriceViem(chainId, opts) {
|
|
76
66
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
77
|
-
var baseFeeMultiplier, transport,
|
|
78
|
-
var _b, _c
|
|
79
|
-
return tslib_1.__generator(this, function (
|
|
80
|
-
switch (
|
|
67
|
+
var baseFeeMultiplier, transport, viemProvider, gasPriceFeeds, maxFeePerGas, maxPriorityFeePerGas, gasPrice;
|
|
68
|
+
var _a, _b, _c;
|
|
69
|
+
return tslib_1.__generator(this, function (_d) {
|
|
70
|
+
switch (_d.label) {
|
|
81
71
|
case 0:
|
|
82
72
|
baseFeeMultiplier = opts.baseFeeMultiplier, transport = opts.transport;
|
|
83
|
-
if (!(typeof providerOrChainId === "number")) return [3, 1];
|
|
84
|
-
_a = providerOrChainId;
|
|
85
|
-
return [3, 3];
|
|
86
|
-
case 1: return [4, providerOrChainId.getNetwork()];
|
|
87
|
-
case 2:
|
|
88
|
-
_a = (_e.sent()).chainId;
|
|
89
|
-
_e.label = 3;
|
|
90
|
-
case 3:
|
|
91
|
-
chainId = _a;
|
|
92
73
|
viemProvider = (0, util_1.getPublicClient)(chainId, transport);
|
|
93
|
-
gasPriceFeeds = (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (!gasPriceFeeds[chainId]) return [3,
|
|
74
|
+
gasPriceFeeds = (_a = {},
|
|
75
|
+
_a[constants_1.CHAIN_IDs.LINEA] = lineaViem.eip1559,
|
|
76
|
+
_a);
|
|
77
|
+
if (!gasPriceFeeds[chainId]) return [3, 2];
|
|
97
78
|
return [4, gasPriceFeeds[chainId](viemProvider, opts)];
|
|
98
|
-
case
|
|
99
|
-
(
|
|
100
|
-
return [3,
|
|
101
|
-
case
|
|
79
|
+
case 1:
|
|
80
|
+
(_b = _d.sent(), maxFeePerGas = _b.maxFeePerGas, maxPriorityFeePerGas = _b.maxPriorityFeePerGas);
|
|
81
|
+
return [3, 4];
|
|
82
|
+
case 2:
|
|
102
83
|
gasPrice = void 0;
|
|
103
84
|
return [4, viemProvider.estimateFeesPerGas()];
|
|
104
|
-
case
|
|
105
|
-
(
|
|
85
|
+
case 3:
|
|
86
|
+
(_c = _d.sent(), maxFeePerGas = _c.maxFeePerGas, maxPriorityFeePerGas = _c.maxPriorityFeePerGas, gasPrice = _c.gasPrice);
|
|
106
87
|
maxFeePerGas !== null && maxFeePerGas !== void 0 ? maxFeePerGas : (maxFeePerGas = (gasPrice * BigInt(baseFeeMultiplier.toString())) / BigInt(utils_1.fixedPointAdjustment.toString()));
|
|
107
88
|
maxPriorityFeePerGas !== null && maxPriorityFeePerGas !== void 0 ? maxPriorityFeePerGas : (maxPriorityFeePerGas = BigInt(0));
|
|
108
|
-
|
|
109
|
-
case
|
|
89
|
+
_d.label = 4;
|
|
90
|
+
case 4: return [2, {
|
|
110
91
|
maxFeePerGas: utils_1.BigNumber.from(maxFeePerGas.toString()),
|
|
111
92
|
maxPriorityFeePerGas: utils_1.BigNumber.from(maxPriorityFeePerGas.toString()),
|
|
112
93
|
}];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oracle.js","sourceRoot":"","sources":["../../../../src/gasPriceOracle/oracle.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"oracle.js","sourceRoot":"","sources":["../../../../src/gasPriceOracle/oracle.ts"],"names":[],"mappings":";;AAgEA,kDAgCC;;AAhGD,0DAA4B;AAG5B,0CAAyC;AACzC,kCAA8F;AAG9F,+BAAyC;AACzC,oEAAgD;AAChD,oEAAgD;AAChD,kEAA8C;AAC9C,uEAAmD;AACnD,gEAA4C;AA2B5C,IAAM,2BAA2B,GAAG;IAClC,cAAc,EAAE,IAAI;CACrB,CAAC;AAGF,IAAM,WAAW,GAAG,CAAC,qBAAS,CAAC,KAAK,CAAC,CAAC;AAoBtC,SAAsB,mBAAmB;gEACvC,QAAsC,EACtC,IAA2C;;;QAA3C,qBAAA,EAAA,SAA2C;;;;oBAErC,iBAAiB,GAAG,MAAA,IAAI,CAAC,iBAAiB,mCAAI,IAAA,eAAO,EAAC,GAAG,CAAC,CAAC;oBAC3D,qBAAqB,GAAG,MAAA,IAAI,CAAC,qBAAqB,mCAAI,IAAA,eAAO,EAAC,GAAG,CAAC,CAAC;oBAGzE,IAAI,CAAC,IAAA,qBAAa,EAAC,QAAQ,CAAC,EAAE,CAAC;wBACvB,6FACD,2BAA2B,KAC9B,iBAAiB,mBAAA,EACjB,qBAAqB,uBAAA,KAClB,IAAI,KACP,OAAO,EAAE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Q,EAAE,CAAC,EAAC;oBAC9G,oBAAoB,aAApB,oBAAoB,cAApB,oBAAoB,IAApB,oBAAoB,GAAK,MAAM,CAAC,CAAC,CAAC,EAAC;;wBAGrC,WAAO;wBACL,YAAY,EAAE,iBAAS,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;wBACrD,oBAAoB,EAAE,iBAAS,CAAC,IAAI,CAAC,oBAAoB,CAAC,QAAQ,EAAE,CAAC;qBACtE,EAAC;;;;CACH"}
|
|
@@ -13,6 +13,8 @@ var ArweaveClient = /** @class */ (function () {
|
|
|
13
13
|
if (retryDelaySeconds === void 0) { retryDelaySeconds = 1; }
|
|
14
14
|
this.arweaveJWT = arweaveJWT;
|
|
15
15
|
this.logger = logger;
|
|
16
|
+
this.gatewayURL = gatewayURL;
|
|
17
|
+
this.protocol = protocol;
|
|
16
18
|
this.retries = retries;
|
|
17
19
|
this.retryDelaySeconds = retryDelaySeconds;
|
|
18
20
|
this.gatewayUrl = "".concat(protocol, "://").concat(gatewayURL, ":").concat(port);
|
|
@@ -106,26 +108,26 @@ var ArweaveClient = /** @class */ (function () {
|
|
|
106
108
|
*/
|
|
107
109
|
ArweaveClient.prototype.get = function (transactionID, validator) {
|
|
108
110
|
return __awaiter(this, void 0, void 0, function () {
|
|
109
|
-
var transactionUrl,
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
var transactionUrl, request, data;
|
|
112
|
+
var _this = this;
|
|
113
|
+
return __generator(this, function (_a) {
|
|
114
|
+
switch (_a.label) {
|
|
112
115
|
case 0:
|
|
113
116
|
transactionUrl = "".concat(this.gatewayUrl, "/").concat(transactionID);
|
|
114
|
-
return
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
transactionID: transactionID,
|
|
124
|
-
responseStatus: responseStatus,
|
|
125
|
-
data: data,
|
|
117
|
+
request = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
118
|
+
var requestData;
|
|
119
|
+
return __generator(this, function (_a) {
|
|
120
|
+
switch (_a.label) {
|
|
121
|
+
case 0: return [4 /*yield*/, axios.get(transactionUrl)];
|
|
122
|
+
case 1:
|
|
123
|
+
requestData = (_a.sent()).data;
|
|
124
|
+
return [2 /*return*/, requestData];
|
|
125
|
+
}
|
|
126
126
|
});
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
}); };
|
|
128
|
+
return [4 /*yield*/, this._retryRequest(request, 0)];
|
|
129
|
+
case 1:
|
|
130
|
+
data = _a.sent();
|
|
129
131
|
try {
|
|
130
132
|
// We should validate the data and perform any logical coercion here.
|
|
131
133
|
return [2 /*return*/, create(data, validator)];
|
|
@@ -262,7 +264,7 @@ var ArweaveClient = /** @class */ (function () {
|
|
|
262
264
|
baseDelay = this.retryDelaySeconds * Math.pow(2, retryCount);
|
|
263
265
|
delayS = baseDelay + baseDelay * Math.random();
|
|
264
266
|
this.logger.debug({
|
|
265
|
-
at: "ArweaveClient:
|
|
267
|
+
at: "ArweaveClient:retryRequest",
|
|
266
268
|
message: "Arweave request failed, retrying after waiting ".concat(delayS, " seconds: ").concat(e_2),
|
|
267
269
|
retryCount: retryCount,
|
|
268
270
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArweaveClient.js","sourceRoot":"","sources":["../../../../../src/caching/Arweave/ArweaveClient.ts"],"names":[],"mappings":";AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAU,MAAM,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AACjH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,0BAA0B,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAE5F;IAIE,uBACU,UAAwB,EACxB,M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B,0EAA0E;wCAC1E,4BAA4B;wCAC5B,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;4CAC3B,KAAsB,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,EAA9C,OAAO,QAAA,EAAE,QAAQ,QAAA,CAA8B;4CAChD,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;4CACzF,sBAAO,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,EAAC;wCAChD,CAAC;6CAAM,CAAC;4CACN,sBAAO,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,EAAC;wCACxC,CAAC;;;;6BACF,CAAC;wBACK,qBAAM,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC,EAAA;4BAA3C,sBAAO,SAAoC,EAAC;;;;KAC7C;IACH,oBAAC;AAAD,CAAC,AAvQD,IAuQC"}
|
|
@@ -19,6 +19,12 @@ export declare function eip1559(provider: providers.Provider, opts: GasPriceEsti
|
|
|
19
19
|
* @returns Promise of gas price estimate object.
|
|
20
20
|
*/
|
|
21
21
|
export declare function eip1559Raw(provider: providers.Provider, chainId: number, baseFeeMultiplier: BigNumber, priorityFeeMultiplier: BigNumber): Promise<EvmGasPriceEstimate>;
|
|
22
|
+
/**
|
|
23
|
+
* @notice Derives an appropriate maxPriorityFeePerGas by applying a predicate to historical rewards specified by eth_feeHistory.
|
|
24
|
+
* @param provider ethers RPC provider instance.
|
|
25
|
+
* @param {GasPriceEstimateOptions} Gas scaling options.
|
|
26
|
+
*/
|
|
27
|
+
export declare function feeHistory(provider: providers.Provider, opts: GasPriceEstimateOptions): Promise<EvmGasPriceEstimate>;
|
|
22
28
|
/**
|
|
23
29
|
* @notice Returns result of eth_gasPrice RPC call
|
|
24
30
|
* @dev Its recommended to use the eip1559Raw method over this one where possible as it will be more accurate.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter, __generator } from "tslib";
|
|
2
2
|
import assert from "assert";
|
|
3
|
-
import { BigNumber, bnZero, fixedPointAdjustment, getNetworkName } from "../../utils";
|
|
3
|
+
import { BigNumber, bnZero, fixedPointAdjustment, getNetworkName, bnOne, isDefined } from "../../utils";
|
|
4
4
|
import { gasPriceError } from "../util";
|
|
5
5
|
/**
|
|
6
6
|
* @dev Constructs total fee by adding eth_getBlock("pending").baseFee to eth_maxPriorityFeePerGas
|
|
@@ -43,6 +43,55 @@ export function eip1559Raw(provider, chainId, baseFeeMultiplier, priorityFeeMult
|
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* @notice Derives an appropriate maxPriorityFeePerGas by applying a predicate to historical rewards specified by eth_feeHistory.
|
|
48
|
+
* @param provider ethers RPC provider instance.
|
|
49
|
+
* @param {GasPriceEstimateOptions} Gas scaling options.
|
|
50
|
+
*/
|
|
51
|
+
export function feeHistory(provider, opts) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
+
var baseFeeMultiplier, feeHistoryOptions, _a, percentile, _b, blockLookback, _c, minimumPriority, _d, baseFeePerGas, feeHistory, defaultEstimator, _e, estimator, maxPriorityFeePerGas, scaledBaseFee;
|
|
54
|
+
return __generator(this, function (_f) {
|
|
55
|
+
switch (_f.label) {
|
|
56
|
+
case 0:
|
|
57
|
+
baseFeeMultiplier = opts.baseFeeMultiplier, feeHistoryOptions = opts.feeHistoryOptions;
|
|
58
|
+
assert(isDefined(feeHistoryOptions)); // We can only get here normally if feeHistoryOptions is defined.
|
|
59
|
+
_a = feeHistoryOptions.percentile, percentile = _a === void 0 ? 20 : _a, _b = feeHistoryOptions.blockLookback, blockLookback = _b === void 0 ? 10 : _b, _c = feeHistoryOptions.minimumPriority, minimumPriority = _c === void 0 ? bnOne : _c;
|
|
60
|
+
return [4 /*yield*/, Promise.all([
|
|
61
|
+
provider.getBlock("latest"),
|
|
62
|
+
provider.send("eth_feeHistory", [blockLookback, "latest", [percentile]]),
|
|
63
|
+
])];
|
|
64
|
+
case 1:
|
|
65
|
+
_d = _f.sent(), baseFeePerGas = _d[0].baseFeePerGas, feeHistory = _d[1];
|
|
66
|
+
assert(BigNumber.isBigNumber(baseFeePerGas), "No baseFeePerGas received on latest block query.");
|
|
67
|
+
defaultEstimator = function (rewards) {
|
|
68
|
+
var sortedRewards = rewards
|
|
69
|
+
.filter(function (reward) { return reward.gt(bnZero); })
|
|
70
|
+
.sort(function (r1, r2) {
|
|
71
|
+
if (r1.gt(r2)) {
|
|
72
|
+
return 1;
|
|
73
|
+
}
|
|
74
|
+
return r1.eq(r2) ? 0 : -1;
|
|
75
|
+
});
|
|
76
|
+
// If all historical rewards are 0, then return the specified minimum.
|
|
77
|
+
if (sortedRewards.length === 0) {
|
|
78
|
+
return minimumPriority;
|
|
79
|
+
}
|
|
80
|
+
var n = sortedRewards.length;
|
|
81
|
+
var median = n % 2 === 0 ? sortedRewards[n / 2 - 1].add(sortedRewards[n / 2].div(2)) : sortedRewards[n / 2];
|
|
82
|
+
return median.gt(minimumPriority) ? median : minimumPriority;
|
|
83
|
+
};
|
|
84
|
+
_e = feeHistoryOptions.estimator, estimator = _e === void 0 ? defaultEstimator : _e;
|
|
85
|
+
maxPriorityFeePerGas = estimator(feeHistory.rewards);
|
|
86
|
+
scaledBaseFee = baseFeePerGas.mul(baseFeeMultiplier).div(fixedPointAdjustment);
|
|
87
|
+
return [2 /*return*/, {
|
|
88
|
+
maxFeePerGas: scaledBaseFee.add(maxPriorityFeePerGas),
|
|
89
|
+
maxPriorityFeePerGas: maxPriorityFeePerGas,
|
|
90
|
+
}];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
46
95
|
/**
|
|
47
96
|
* @notice Returns result of eth_gasPrice RPC call
|
|
48
97
|
* @dev Its recommended to use the eip1559Raw method over this one where possible as it will be more accurate.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethereum.js","sourceRoot":"","sources":["../../../../../src/gasPriceOracle/adapters/ethereum.ts"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"ethereum.js","sourceRoot":"","sources":["../../../../../src/gasPriceOracle/adapters/ethereum.ts"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,oBAAoB,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExG,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CAAC,QAA4B,EAAE,IAA6B;IACjF,OAAO,UAAU,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;AAChG,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAgB,UAAU,CAC9B,QAA4B,EAC5B,OAAe,EACf,iBAA4B,EAC5B,qBAAgC;;;;;wBAEmB,qBAAM,OAAO,CAAC,GAAG,CAAC;wBACnE,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC;wBAC1B,QAAsC,CAAC,IAAI,CAAC,0BAA0B,EAAE,EAAE,CAAC;qBAC7E,CAAC,EAAA;;oBAHI,KAA6C,SAGjD,EAHO,aAAa,sBAAA,EAAI,qBAAqB,QAAA;oBAIzC,oBAAoB,GAAG,SAAS,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;oBACnE,MAAM,CAAC,SAA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GAAG,CAAC,oBAAoB,CAAC;4BACrD,oBAAoB,sBAAA;yBACrB,EAAC;;;;CACH;AAED;;;;GAIG;AACH,MAAM,UAAgB,MAAM,CAC1B,QAA4B,EAC5B,IAA6B;;;;;;oBAErB,OAAO,GAAwB,IAAI,QAA5B,EAAE,iBAAiB,GAAK,IAAI,kBAAT,CAAU;oBAC3B,qBAAM,QAAQ,CAAC,WAAW,EAAE,EAAA;;oBAAvC,QAAQ,GAAG,SAA4B;oBAE7C,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC;wBAAE,aAAa,CAAC,eAAe,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;oBAE/G,sBAAO;4BACL,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,oBAAoB,CAAC;4BACvE,oBAAoB,EAAE,MAAM;yBAC7B,EAAC;;;;CACH"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Transport } from "viem";
|
|
2
|
-
import { providers } from "ethers";
|
|
3
2
|
import { BigNumber } from "../utils";
|
|
4
3
|
import { SVMProvider as SolanaProvider } from "../arch/svm";
|
|
5
|
-
import { EvmGasPriceEstimate,
|
|
4
|
+
import { EvmGasPriceEstimate, SvmGasPriceEstimate } from "./types";
|
|
6
5
|
import { EvmProvider } from "../arch/evm/types";
|
|
7
6
|
export interface GasPriceEstimateOptions {
|
|
8
7
|
baseFeeMultiplier: BigNumber;
|
|
@@ -10,15 +9,14 @@ export interface GasPriceEstimateOptions {
|
|
|
10
9
|
legacyFallback: boolean;
|
|
11
10
|
chainId: number;
|
|
12
11
|
unsignedTx?: unknown;
|
|
12
|
+
feeHistoryOptions?: FeeHistoryOptions;
|
|
13
13
|
transport?: Transport;
|
|
14
14
|
}
|
|
15
|
+
export interface FeeHistoryOptions {
|
|
16
|
+
estimator?: (rewards: BigNumber[]) => BigNumber;
|
|
17
|
+
percentile?: number;
|
|
18
|
+
blockLookback?: number;
|
|
19
|
+
minimumPriority?: BigNumber;
|
|
20
|
+
}
|
|
15
21
|
export declare function getGasPriceEstimate(provider: EvmProvider, opts?: Partial<GasPriceEstimateOptions>): Promise<EvmGasPriceEstimate>;
|
|
16
22
|
export declare function getGasPriceEstimate(provider: SolanaProvider, opts?: Partial<GasPriceEstimateOptions>): Promise<SvmGasPriceEstimate>;
|
|
17
|
-
/**
|
|
18
|
-
* Provide an estimate for the current gas price for a particular chain.
|
|
19
|
-
* @param providerOrChainId A valid ethers provider or a chain ID.
|
|
20
|
-
* @param transport An optional Viem Transport object for custom gas price retrieval.
|
|
21
|
-
* @param unsignedTx Only used in Linea provider to estimate priority gas fee.
|
|
22
|
-
* @returns An object of type GasPriceEstimate.
|
|
23
|
-
*/
|
|
24
|
-
export declare function _getViemGasPriceEstimate(providerOrChainId: providers.Provider | number, opts: GasPriceEstimateOptions): Promise<GasPriceEstimate>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
2
|
import assert from "assert";
|
|
3
3
|
import { CHAIN_IDs } from "../constants";
|
|
4
|
-
import { BigNumber,
|
|
4
|
+
import { BigNumber, fixedPointAdjustment, isEvmProvider, toBNWei, isDefined } from "../utils";
|
|
5
5
|
import { getPublicClient } from "./util";
|
|
6
6
|
import * as arbitrum from "./adapters/arbitrum";
|
|
7
7
|
import * as ethereum from "./adapters/ethereum";
|
|
@@ -45,9 +45,7 @@ export function getGasPriceEstimate(provider_1) {
|
|
|
45
45
|
chainId = _a;
|
|
46
46
|
optsWithDefaults = __assign(__assign(__assign(__assign({}, GAS_PRICE_ESTIMATE_DEFAULTS), { baseFeeMultiplier: baseFeeMultiplier, priorityFeeMultiplier: priorityFeeMultiplier }), opts), { chainId: chainId });
|
|
47
47
|
useViem = VIEM_CHAINS.includes(chainId);
|
|
48
|
-
return [2 /*return*/, useViem
|
|
49
|
-
? _getViemGasPriceEstimate(chainId, optsWithDefaults)
|
|
50
|
-
: _getEthersGasPriceEstimate(provider, optsWithDefaults)];
|
|
48
|
+
return [2 /*return*/, useViem ? getGasPriceViem(chainId, optsWithDefaults) : getGasPriceEthers(provider, optsWithDefaults)];
|
|
51
49
|
}
|
|
52
50
|
});
|
|
53
51
|
});
|
|
@@ -59,30 +57,24 @@ export function getGasPriceEstimate(provider_1) {
|
|
|
59
57
|
* @param legacyFallback In the case of an unrecognised chain, fall back to type 0 gas estimation.
|
|
60
58
|
* @returns An object of type GasPriceEstimate.
|
|
61
59
|
*/
|
|
62
|
-
function
|
|
60
|
+
function getGasPriceEthers(provider, opts) {
|
|
63
61
|
var _a;
|
|
64
62
|
var chainId = opts.chainId, legacyFallback = opts.legacyFallback;
|
|
65
63
|
// There shouldn't be any chains in here that we have a Viem adapter for because we'll always use Viem in that case.
|
|
66
64
|
assert(!VIEM_CHAINS.includes(chainId), "Chain ID ".concat(chainId, " will use Viem gas price estimation"));
|
|
67
65
|
var gasPriceFeeds = (_a = {},
|
|
68
66
|
_a[CHAIN_IDs.ARBITRUM] = arbitrum.eip1559,
|
|
69
|
-
_a[CHAIN_IDs.BSC] = ethereum.eip1559,
|
|
70
|
-
_a[CHAIN_IDs.MAINNET] = ethereum.eip1559,
|
|
71
|
-
_a[CHAIN_IDs.MEGAETH] = ethereum.eip1559,
|
|
72
|
-
_a[CHAIN_IDs.MONAD] = ethereum.eip1559,
|
|
73
|
-
_a[CHAIN_IDs.PLASMA] = ethereum.eip1559,
|
|
74
67
|
_a[CHAIN_IDs.POLYGON] = polygon.gasStation,
|
|
75
68
|
_a[CHAIN_IDs.SCROLL] = ethereum.legacy,
|
|
76
69
|
_a[CHAIN_IDs.TEMPO] = ethereum.eip1559,
|
|
77
70
|
_a[CHAIN_IDs.ZK_SYNC] = ethereum.legacy,
|
|
78
|
-
// Testnet
|
|
79
|
-
_a[CHAIN_IDs.ARBITRUM_SEPOLIA] = arbitrum.eip1559,
|
|
71
|
+
// Testnet
|
|
80
72
|
_a[CHAIN_IDs.POLYGON_AMOY] = polygon.gasStation,
|
|
81
|
-
_a[CHAIN_IDs.SEPOLIA] = ethereum.eip1559,
|
|
82
73
|
_a);
|
|
83
|
-
|
|
74
|
+
// If we have specified feeHistory parameters, then assume we want to take the feeHistory estimation path.
|
|
75
|
+
var gasPriceFeed = isDefined(opts.feeHistoryOptions) ? ethereum.feeHistory : gasPriceFeeds[chainId];
|
|
84
76
|
assert(gasPriceFeed || legacyFallback, "No suitable gas price oracle for Chain ID ".concat(chainId));
|
|
85
|
-
gasPriceFeed !== null && gasPriceFeed !== void 0 ? gasPriceFeed : (gasPriceFeed =
|
|
77
|
+
gasPriceFeed !== null && gasPriceFeed !== void 0 ? gasPriceFeed : (gasPriceFeed = ethereum.eip1559);
|
|
86
78
|
return gasPriceFeed(provider, opts);
|
|
87
79
|
}
|
|
88
80
|
/**
|
|
@@ -92,41 +84,32 @@ function _getEthersGasPriceEstimate(provider, opts) {
|
|
|
92
84
|
* @param unsignedTx Only used in Linea provider to estimate priority gas fee.
|
|
93
85
|
* @returns An object of type GasPriceEstimate.
|
|
94
86
|
*/
|
|
95
|
-
|
|
87
|
+
function getGasPriceViem(chainId, opts) {
|
|
96
88
|
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
-
var baseFeeMultiplier, transport,
|
|
98
|
-
var _b, _c
|
|
99
|
-
return __generator(this, function (
|
|
100
|
-
switch (
|
|
89
|
+
var baseFeeMultiplier, transport, viemProvider, gasPriceFeeds, maxFeePerGas, maxPriorityFeePerGas, gasPrice;
|
|
90
|
+
var _a, _b, _c;
|
|
91
|
+
return __generator(this, function (_d) {
|
|
92
|
+
switch (_d.label) {
|
|
101
93
|
case 0:
|
|
102
94
|
baseFeeMultiplier = opts.baseFeeMultiplier, transport = opts.transport;
|
|
103
|
-
if (!(typeof providerOrChainId === "number")) return [3 /*break*/, 1];
|
|
104
|
-
_a = providerOrChainId;
|
|
105
|
-
return [3 /*break*/, 3];
|
|
106
|
-
case 1: return [4 /*yield*/, providerOrChainId.getNetwork()];
|
|
107
|
-
case 2:
|
|
108
|
-
_a = (_e.sent()).chainId;
|
|
109
|
-
_e.label = 3;
|
|
110
|
-
case 3:
|
|
111
|
-
chainId = _a;
|
|
112
95
|
viemProvider = getPublicClient(chainId, transport);
|
|
113
|
-
gasPriceFeeds = (
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (!gasPriceFeeds[chainId]) return [3 /*break*/,
|
|
96
|
+
gasPriceFeeds = (_a = {},
|
|
97
|
+
_a[CHAIN_IDs.LINEA] = lineaViem.eip1559,
|
|
98
|
+
_a);
|
|
99
|
+
if (!gasPriceFeeds[chainId]) return [3 /*break*/, 2];
|
|
117
100
|
return [4 /*yield*/, gasPriceFeeds[chainId](viemProvider, opts)];
|
|
118
|
-
case
|
|
119
|
-
(
|
|
120
|
-
return [3 /*break*/,
|
|
121
|
-
case
|
|
101
|
+
case 1:
|
|
102
|
+
(_b = _d.sent(), maxFeePerGas = _b.maxFeePerGas, maxPriorityFeePerGas = _b.maxPriorityFeePerGas);
|
|
103
|
+
return [3 /*break*/, 4];
|
|
104
|
+
case 2:
|
|
122
105
|
gasPrice = void 0;
|
|
123
106
|
return [4 /*yield*/, viemProvider.estimateFeesPerGas()];
|
|
124
|
-
case
|
|
125
|
-
(
|
|
107
|
+
case 3:
|
|
108
|
+
(_c = _d.sent(), maxFeePerGas = _c.maxFeePerGas, maxPriorityFeePerGas = _c.maxPriorityFeePerGas, gasPrice = _c.gasPrice);
|
|
126
109
|
maxFeePerGas !== null && maxFeePerGas !== void 0 ? maxFeePerGas : (maxFeePerGas = (gasPrice * BigInt(baseFeeMultiplier.toString())) / BigInt(fixedPointAdjustment.toString()));
|
|
127
110
|
maxPriorityFeePerGas !== null && maxPriorityFeePerGas !== void 0 ? maxPriorityFeePerGas : (maxPriorityFeePerGas = BigInt(0));
|
|
128
|
-
|
|
129
|
-
case
|
|
111
|
+
_d.label = 4;
|
|
112
|
+
case 4: return [2 /*return*/, {
|
|
130
113
|
maxFeePerGas: BigNumber.from(maxFeePerGas.toString()),
|
|
131
114
|
maxPriorityFeePerGas: BigNumber.from(maxPriorityFeePerGas.toString()),
|
|
132
115
|
}];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oracle.js","sourceRoot":"","sources":["../../../../src/gasPriceOracle/oracle.ts"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"oracle.js","sourceRoot":"","sources":["../../../../src/gasPriceOracle/oracle.ts"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG9F,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AA2B5C,IAAM,2BAA2B,GAAG;IAClC,cAAc,EAAE,IAAI;CACrB,CAAC;AAEF,6CAA6C;AAC7C,IAAM,WAAW,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AActC;;;;;GAKG;AACH,MAAM,UAAgB,mBAAmB;wDACvC,QAAsC,EACtC,IAA2C;;;QAA3C,qBAAA,EAAA,SAA2C;;;;oBAErC,iBAAiB,GAAG,MAAA,IAAI,CAAC,iBAAiB,mCAAI,OAAO,CAAC,GA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B,qBAAM,YAAY,CAAC,kBAAkB,EAAE,EAAA;;oBAA3F,CAAC,KAAmD,SAAuC,EAAxF,YAAY,kBAAA,EAAE,oBAAoB,0BAAA,EAAE,QAAQ,cAAA,CAA6C,CAAC;oBAE7F,YAAY,aAAZ,YAAY,cAAZ,YAAY,IAAZ,YAAY,GAAK,CAAC,QAAS,GAAG,MAAM,CAAC,iBAAiB,CAAC,QAAQ,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,oBAAoB,CAAC,QAAQ,EAAE,CAAC,EAAC;oBAC9G,oBAAoB,aAApB,oBAAoB,cAApB,oBAAoB,IAApB,oBAAoB,GAAK,MAAM,CAAC,CAAC,CAAC,EAAC;;wBAGrC,sBAAO;wBACL,YAAY,EAAE,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;wBACrD,oBAAoB,EAAE,SAAS,CAAC,IAAI,CAAC,oBAAoB,CAAC,QAAQ,EAAE,CAAC;qBACtE,EAAC;;;;CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArweaveClient.d.ts","sourceRoot":"","sources":["../../../../../src/caching/Arweave/ArweaveClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAU,MAAM,aAAa,CAAC;AAC7C,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,SAAS,EAAsD,MAAM,aAAa,CAAC;AAE5F,qBAAa,aAAa;IAKtB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,MAAM;
|
|
1
|
+
{"version":3,"file":"ArweaveClient.d.ts","sourceRoot":"","sources":["../../../../../src/caching/Arweave/ArweaveClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAU,MAAM,aAAa,CAAC;AAC7C,OAAO,OAAO,MAAM,SA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,OAAO,CAAC,SAAS,CAAC;CAmBvC"}
|
|
@@ -19,6 +19,12 @@ export declare function eip1559(provider: providers.Provider, opts: GasPriceEsti
|
|
|
19
19
|
* @returns Promise of gas price estimate object.
|
|
20
20
|
*/
|
|
21
21
|
export declare function eip1559Raw(provider: providers.Provider, chainId: number, baseFeeMultiplier: BigNumber, priorityFeeMultiplier: BigNumber): Promise<EvmGasPriceEstimate>;
|
|
22
|
+
/**
|
|
23
|
+
* @notice Derives an appropriate maxPriorityFeePerGas by applying a predicate to historical rewards specified by eth_feeHistory.
|
|
24
|
+
* @param provider ethers RPC provider instance.
|
|
25
|
+
* @param {GasPriceEstimateOptions} Gas scaling options.
|
|
26
|
+
*/
|
|
27
|
+
export declare function feeHistory(provider: providers.Provider, opts: GasPriceEstimateOptions): Promise<EvmGasPriceEstimate>;
|
|
22
28
|
/**
|
|
23
29
|
* @notice Returns result of eth_gasPrice RPC call
|
|
24
30
|
* @dev Its recommended to use the eip1559Raw method over this one where possible as it will be more accurate.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethereum.d.ts","sourceRoot":"","sources":["../../../../../src/gasPriceOracle/adapters/ethereum.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"ethereum.d.ts","sourceRoot":"","sources":["../../../../../src/gasPriceOracle/adapters/ethereum.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,SAAS,EAAkE,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAEpD;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,uBAAuB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAEjH;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAC5B,OAAO,EAAE,MAAM,EACf,iBAAiB,EAAE,SAAS,EAC5B,qBAAqB,EAAE,SAAS,GAC/B,OAAO,CAAC,mBAAmB,CAAC,CAc9B;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAC5B,IAAI,EAAE,uBAAuB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CAyC9B;AAED;;;;GAIG;AACH,wBAAsB,MAAM,CAC1B,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAC5B,IAAI,EAAE,uBAAuB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CAU9B"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Transport } from "viem";
|
|
2
|
-
import { providers } from "ethers";
|
|
3
2
|
import { BigNumber } from "../utils";
|
|
4
3
|
import { SVMProvider as SolanaProvider } from "../arch/svm";
|
|
5
|
-
import { EvmGasPriceEstimate,
|
|
4
|
+
import { EvmGasPriceEstimate, SvmGasPriceEstimate } from "./types";
|
|
6
5
|
import { EvmProvider } from "../arch/evm/types";
|
|
7
6
|
export interface GasPriceEstimateOptions {
|
|
8
7
|
baseFeeMultiplier: BigNumber;
|
|
@@ -10,16 +9,15 @@ export interface GasPriceEstimateOptions {
|
|
|
10
9
|
legacyFallback: boolean;
|
|
11
10
|
chainId: number;
|
|
12
11
|
unsignedTx?: unknown;
|
|
12
|
+
feeHistoryOptions?: FeeHistoryOptions;
|
|
13
13
|
transport?: Transport;
|
|
14
14
|
}
|
|
15
|
+
export interface FeeHistoryOptions {
|
|
16
|
+
estimator?: (rewards: BigNumber[]) => BigNumber;
|
|
17
|
+
percentile?: number;
|
|
18
|
+
blockLookback?: number;
|
|
19
|
+
minimumPriority?: BigNumber;
|
|
20
|
+
}
|
|
15
21
|
export declare function getGasPriceEstimate(provider: EvmProvider, opts?: Partial<GasPriceEstimateOptions>): Promise<EvmGasPriceEstimate>;
|
|
16
22
|
export declare function getGasPriceEstimate(provider: SolanaProvider, opts?: Partial<GasPriceEstimateOptions>): Promise<SvmGasPriceEstimate>;
|
|
17
|
-
/**
|
|
18
|
-
* Provide an estimate for the current gas price for a particular chain.
|
|
19
|
-
* @param providerOrChainId A valid ethers provider or a chain ID.
|
|
20
|
-
* @param transport An optional Viem Transport object for custom gas price retrieval.
|
|
21
|
-
* @param unsignedTx Only used in Linea provider to estimate priority gas fee.
|
|
22
|
-
* @returns An object of type GasPriceEstimate.
|
|
23
|
-
*/
|
|
24
|
-
export declare function _getViemGasPriceEstimate(providerOrChainId: providers.Provider | number, opts: GasPriceEstimateOptions): Promise<GasPriceEstimate>;
|
|
25
23
|
//# sourceMappingURL=oracle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oracle.d.ts","sourceRoot":"","sources":["../../../../src/gasPriceOracle/oracle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"oracle.d.ts","sourceRoot":"","sources":["../../../../src/gasPriceOracle/oracle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAGjC,OAAO,EAAE,SAAS,EAA2D,MAAM,UAAU,CAAC;AAC9F,OAAO,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAoB,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAOrF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,WAAW,uBAAuB;IAEtC,iBAAiB,EAAE,SAAS,CAAC;IAE7B,qBAAqB,EAAE,SAAS,CAAC;IAEjC,cAAc,EAAE,OAAO,CAAC;IAExB,OAAO,EAAE,MAAM,CAAC;IAEhB,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IAEtC,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,CAAC;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,SAAS,CAAC;CAC7B;AAUD,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,WAAW,EACrB,IAAI,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GACtC,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAGhC,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,cAAc,EACxB,IAAI,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GACtC,OAAO,CAAC,mBAAmB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -13,8 +13,8 @@ export class ArweaveClient {
|
|
|
13
13
|
public constructor(
|
|
14
14
|
private arweaveJWT: JWKInterface,
|
|
15
15
|
private logger: winston.Logger,
|
|
16
|
-
gatewayURL = "arweave.net",
|
|
17
|
-
protocol = "https",
|
|
16
|
+
public gatewayURL = "arweave.net",
|
|
17
|
+
public protocol = "https",
|
|
18
18
|
port = 443,
|
|
19
19
|
private readonly retries = 2,
|
|
20
20
|
private readonly retryDelaySeconds = 1
|
|
@@ -102,19 +102,11 @@ export class ArweaveClient {
|
|
|
102
102
|
// We should query in via Axios directly to the gateway URL. The reasoning behind this is
|
|
103
103
|
// that the Arweave SDK's `getData` method is too slow and does not provide a way to set a timeout.
|
|
104
104
|
// Therefore, something that could take milliseconds to complete could take tens of minutes.
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
at: "ArweaveClient:get",
|
|
111
|
-
message: "Failed to retrieve value from Arweave - network error or invalid response status",
|
|
112
|
-
transactionID,
|
|
113
|
-
responseStatus,
|
|
114
|
-
data,
|
|
115
|
-
});
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
105
|
+
const request = async () => {
|
|
106
|
+
const { data: requestData } = await axios.get(transactionUrl);
|
|
107
|
+
return requestData;
|
|
108
|
+
};
|
|
109
|
+
const data = await this._retryRequest(request, 0);
|
|
118
110
|
try {
|
|
119
111
|
// We should validate the data and perform any logical coercion here.
|
|
120
112
|
return create(data, validator);
|
|
@@ -242,7 +234,7 @@ export class ArweaveClient {
|
|
|
242
234
|
const baseDelay = this.retryDelaySeconds * Math.pow(2, retryCount); // ms; attempt = [0, 1, 2, ...]
|
|
243
235
|
const delayS = baseDelay + baseDelay * Math.random();
|
|
244
236
|
this.logger.debug({
|
|
245
|
-
at: "ArweaveClient:
|
|
237
|
+
at: "ArweaveClient:retryRequest",
|
|
246
238
|
message: `Arweave request failed, retrying after waiting ${delayS} seconds: ${e}`,
|
|
247
239
|
retryCount,
|
|
248
240
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
2
|
import { providers } from "ethers";
|
|
3
|
-
import { BigNumber, bnZero, fixedPointAdjustment, getNetworkName } from "../../utils";
|
|
3
|
+
import { BigNumber, bnZero, fixedPointAdjustment, getNetworkName, bnOne, isDefined } from "../../utils";
|
|
4
4
|
import { EvmGasPriceEstimate } from "../types";
|
|
5
5
|
import { gasPriceError } from "../util";
|
|
6
6
|
import { GasPriceEstimateOptions } from "../oracle";
|
|
@@ -45,6 +45,57 @@ export async function eip1559Raw(
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @notice Derives an appropriate maxPriorityFeePerGas by applying a predicate to historical rewards specified by eth_feeHistory.
|
|
50
|
+
* @param provider ethers RPC provider instance.
|
|
51
|
+
* @param {GasPriceEstimateOptions} Gas scaling options.
|
|
52
|
+
*/
|
|
53
|
+
export async function feeHistory(
|
|
54
|
+
provider: providers.Provider,
|
|
55
|
+
opts: GasPriceEstimateOptions
|
|
56
|
+
): Promise<EvmGasPriceEstimate> {
|
|
57
|
+
// Get the fee history options and populate unspecified properties with defaults.
|
|
58
|
+
const { baseFeeMultiplier, feeHistoryOptions } = opts;
|
|
59
|
+
assert(isDefined(feeHistoryOptions)); // We can only get here normally if feeHistoryOptions is defined.
|
|
60
|
+
const { percentile = 20, blockLookback = 10, minimumPriority = bnOne } = feeHistoryOptions;
|
|
61
|
+
|
|
62
|
+
const [{ baseFeePerGas }, feeHistory] = await Promise.all([
|
|
63
|
+
provider.getBlock("latest"),
|
|
64
|
+
(provider as providers.JsonRpcProvider).send("eth_feeHistory", [blockLookback, "latest", [percentile]]),
|
|
65
|
+
]);
|
|
66
|
+
assert(BigNumber.isBigNumber(baseFeePerGas), "No baseFeePerGas received on latest block query.");
|
|
67
|
+
|
|
68
|
+
// Default estimator based on https://github.com/alloy-rs/alloy/blob/6f20815b657f60de454bed5010e3b9a6883ac70f/crates/provider/src/utils.rs#L90
|
|
69
|
+
const defaultEstimator = (rewards: BigNumber[]): BigNumber => {
|
|
70
|
+
const sortedRewards = rewards
|
|
71
|
+
.filter((reward) => reward.gt(bnZero))
|
|
72
|
+
.sort((r1, r2) => {
|
|
73
|
+
if (r1.gt(r2)) {
|
|
74
|
+
return 1;
|
|
75
|
+
}
|
|
76
|
+
return r1.eq(r2) ? 0 : -1;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// If all historical rewards are 0, then return the specified minimum.
|
|
80
|
+
if (sortedRewards.length === 0) {
|
|
81
|
+
return minimumPriority;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const n = sortedRewards.length;
|
|
85
|
+
const median = n % 2 === 0 ? sortedRewards[n / 2 - 1].add(sortedRewards[n / 2].div(2)) : sortedRewards[n / 2];
|
|
86
|
+
return median.gt(minimumPriority) ? median : minimumPriority;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const { estimator = defaultEstimator } = feeHistoryOptions;
|
|
90
|
+
const maxPriorityFeePerGas = estimator(feeHistory.rewards);
|
|
91
|
+
const scaledBaseFee = baseFeePerGas.mul(baseFeeMultiplier).div(fixedPointAdjustment);
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
maxFeePerGas: scaledBaseFee.add(maxPriorityFeePerGas),
|
|
95
|
+
maxPriorityFeePerGas,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
48
99
|
/**
|
|
49
100
|
* @notice Returns result of eth_gasPrice RPC call
|
|
50
101
|
* @dev Its recommended to use the eip1559Raw method over this one where possible as it will be more accurate.
|
|
@@ -2,7 +2,7 @@ import assert from "assert";
|
|
|
2
2
|
import { Transport } from "viem";
|
|
3
3
|
import { providers } from "ethers";
|
|
4
4
|
import { CHAIN_IDs } from "../constants";
|
|
5
|
-
import { BigNumber,
|
|
5
|
+
import { BigNumber, fixedPointAdjustment, isEvmProvider, toBNWei, isDefined } from "../utils";
|
|
6
6
|
import { SVMProvider as SolanaProvider } from "../arch/svm";
|
|
7
7
|
import { EvmGasPriceEstimate, GasPriceEstimate, SvmGasPriceEstimate } from "./types";
|
|
8
8
|
import { getPublicClient } from "./util";
|
|
@@ -24,10 +24,19 @@ export interface GasPriceEstimateOptions {
|
|
|
24
24
|
chainId: number;
|
|
25
25
|
// unsignedTx The unsigned transaction used for simulation by Linea's Viem provider to produce the priority gas fee, or alternatively, by Solana's provider to determine the base/priority fee.
|
|
26
26
|
unsignedTx?: unknown;
|
|
27
|
+
// feeHistoryOptions A set of configuration used to derive an appropriate gas price based on fee history rewiards.
|
|
28
|
+
feeHistoryOptions?: FeeHistoryOptions;
|
|
27
29
|
// transport Viem Transport object to use for querying gas fees used for testing.
|
|
28
30
|
transport?: Transport;
|
|
29
31
|
}
|
|
30
32
|
|
|
33
|
+
export interface FeeHistoryOptions {
|
|
34
|
+
estimator?: (rewards: BigNumber[]) => BigNumber;
|
|
35
|
+
percentile?: number;
|
|
36
|
+
blockLookback?: number;
|
|
37
|
+
minimumPriority?: BigNumber;
|
|
38
|
+
}
|
|
39
|
+
|
|
31
40
|
const GAS_PRICE_ESTIMATE_DEFAULTS = {
|
|
32
41
|
legacyFallback: true,
|
|
33
42
|
};
|
|
@@ -84,9 +93,7 @@ export async function getGasPriceEstimate(
|
|
|
84
93
|
|
|
85
94
|
// We only use the unsignedTx in the viem flow.
|
|
86
95
|
const useViem = VIEM_CHAINS.includes(chainId);
|
|
87
|
-
return useViem
|
|
88
|
-
? _getViemGasPriceEstimate(chainId, optsWithDefaults)
|
|
89
|
-
: _getEthersGasPriceEstimate(provider, optsWithDefaults);
|
|
96
|
+
return useViem ? getGasPriceViem(chainId, optsWithDefaults) : getGasPriceEthers(provider, optsWithDefaults);
|
|
90
97
|
}
|
|
91
98
|
|
|
92
99
|
/**
|
|
@@ -96,35 +103,26 @@ export async function getGasPriceEstimate(
|
|
|
96
103
|
* @param legacyFallback In the case of an unrecognised chain, fall back to type 0 gas estimation.
|
|
97
104
|
* @returns An object of type GasPriceEstimate.
|
|
98
105
|
*/
|
|
99
|
-
function
|
|
100
|
-
provider: providers.Provider,
|
|
101
|
-
opts: GasPriceEstimateOptions
|
|
102
|
-
): Promise<GasPriceEstimate> {
|
|
106
|
+
function getGasPriceEthers(provider: providers.Provider, opts: GasPriceEstimateOptions): Promise<GasPriceEstimate> {
|
|
103
107
|
const { chainId, legacyFallback } = opts;
|
|
104
108
|
|
|
105
109
|
// There shouldn't be any chains in here that we have a Viem adapter for because we'll always use Viem in that case.
|
|
106
110
|
assert(!VIEM_CHAINS.includes(chainId), `Chain ID ${chainId} will use Viem gas price estimation`);
|
|
107
111
|
const gasPriceFeeds = {
|
|
108
112
|
[CHAIN_IDs.ARBITRUM]: arbitrum.eip1559,
|
|
109
|
-
[CHAIN_IDs.BSC]: ethereum.eip1559,
|
|
110
|
-
[CHAIN_IDs.MAINNET]: ethereum.eip1559,
|
|
111
|
-
[CHAIN_IDs.MEGAETH]: ethereum.eip1559,
|
|
112
|
-
[CHAIN_IDs.MONAD]: ethereum.eip1559,
|
|
113
|
-
[CHAIN_IDs.PLASMA]: ethereum.eip1559,
|
|
114
113
|
[CHAIN_IDs.POLYGON]: polygon.gasStation,
|
|
115
114
|
[CHAIN_IDs.SCROLL]: ethereum.legacy,
|
|
116
115
|
[CHAIN_IDs.TEMPO]: ethereum.eip1559,
|
|
117
116
|
[CHAIN_IDs.ZK_SYNC]: ethereum.legacy,
|
|
118
|
-
|
|
119
|
-
// Testnet Chains
|
|
120
|
-
[CHAIN_IDs.ARBITRUM_SEPOLIA]: arbitrum.eip1559,
|
|
117
|
+
// Testnet
|
|
121
118
|
[CHAIN_IDs.POLYGON_AMOY]: polygon.gasStation,
|
|
122
|
-
[CHAIN_IDs.SEPOLIA]: ethereum.eip1559,
|
|
123
119
|
} as const;
|
|
124
120
|
|
|
125
|
-
|
|
121
|
+
// If we have specified feeHistory parameters, then assume we want to take the feeHistory estimation path.
|
|
122
|
+
let gasPriceFeed = isDefined(opts.feeHistoryOptions) ? ethereum.feeHistory : gasPriceFeeds[chainId];
|
|
123
|
+
|
|
126
124
|
assert(gasPriceFeed || legacyFallback, `No suitable gas price oracle for Chain ID ${chainId}`);
|
|
127
|
-
gasPriceFeed ??=
|
|
125
|
+
gasPriceFeed ??= ethereum.eip1559;
|
|
128
126
|
|
|
129
127
|
return gasPriceFeed(provider, opts);
|
|
130
128
|
}
|
|
@@ -136,16 +134,10 @@ function _getEthersGasPriceEstimate(
|
|
|
136
134
|
* @param unsignedTx Only used in Linea provider to estimate priority gas fee.
|
|
137
135
|
* @returns An object of type GasPriceEstimate.
|
|
138
136
|
*/
|
|
139
|
-
|
|
140
|
-
providerOrChainId: providers.Provider | number,
|
|
141
|
-
opts: GasPriceEstimateOptions
|
|
142
|
-
): Promise<GasPriceEstimate> {
|
|
137
|
+
async function getGasPriceViem(chainId: number, opts: GasPriceEstimateOptions): Promise<GasPriceEstimate> {
|
|
143
138
|
const { baseFeeMultiplier, transport } = opts;
|
|
144
139
|
|
|
145
|
-
const chainId =
|
|
146
|
-
typeof providerOrChainId === "number" ? providerOrChainId : (await providerOrChainId.getNetwork()).chainId;
|
|
147
140
|
const viemProvider = getPublicClient(chainId, transport);
|
|
148
|
-
|
|
149
141
|
const gasPriceFeeds = {
|
|
150
142
|
[CHAIN_IDs.LINEA]: lineaViem.eip1559,
|
|
151
143
|
};
|