@across-protocol/sdk 4.3.130 → 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/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 +7 -0
- package/dist/cjs/src/gasPriceOracle/oracle.js +1 -1
- package/dist/cjs/src/gasPriceOracle/oracle.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 +7 -0
- package/dist/esm/src/gasPriceOracle/oracle.js +3 -2
- package/dist/esm/src/gasPriceOracle/oracle.js.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 +7 -0
- package/dist/types/src/gasPriceOracle/oracle.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/gasPriceOracle/adapters/ethereum.ts +52 -1
- package/src/gasPriceOracle/oracle.ts +13 -2
|
@@ -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":";;AAeA,0BAEC;AASD,gCAmBC;AAOD,w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BACL,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,4BAAoB,CAAC;4BACvE,oBAAoB,EAAE,cAAM;yBAC7B,EAAC;;;;CACH"}
|
|
@@ -9,7 +9,14 @@ export interface GasPriceEstimateOptions {
|
|
|
9
9
|
legacyFallback: boolean;
|
|
10
10
|
chainId: number;
|
|
11
11
|
unsignedTx?: unknown;
|
|
12
|
+
feeHistoryOptions?: FeeHistoryOptions;
|
|
12
13
|
transport?: Transport;
|
|
13
14
|
}
|
|
15
|
+
export interface FeeHistoryOptions {
|
|
16
|
+
estimator?: (rewards: BigNumber[]) => BigNumber;
|
|
17
|
+
percentile?: number;
|
|
18
|
+
blockLookback?: number;
|
|
19
|
+
minimumPriority?: BigNumber;
|
|
20
|
+
}
|
|
14
21
|
export declare function getGasPriceEstimate(provider: EvmProvider, opts?: Partial<GasPriceEstimateOptions>): Promise<EvmGasPriceEstimate>;
|
|
15
22
|
export declare function getGasPriceEstimate(provider: SolanaProvider, opts?: Partial<GasPriceEstimateOptions>): Promise<SvmGasPriceEstimate>;
|
|
@@ -57,7 +57,7 @@ function getGasPriceEthers(provider, opts) {
|
|
|
57
57
|
_a[constants_1.CHAIN_IDs.ZK_SYNC] = ethereum.legacy,
|
|
58
58
|
_a[constants_1.CHAIN_IDs.POLYGON_AMOY] = polygon.gasStation,
|
|
59
59
|
_a);
|
|
60
|
-
var gasPriceFeed = gasPriceFeeds[chainId];
|
|
60
|
+
var gasPriceFeed = (0, utils_1.isDefined)(opts.feeHistoryOptions) ? ethereum.feeHistory : gasPriceFeeds[chainId];
|
|
61
61
|
(0, assert_1.default)(gasPriceFeed || legacyFallback, "No suitable gas price oracle for Chain ID ".concat(chainId));
|
|
62
62
|
gasPriceFeed !== null && gasPriceFeed !== void 0 ? gasPriceFeed : (gasPriceFeed = ethereum.eip1559);
|
|
63
63
|
return gasPriceFeed(provider, opts);
|
|
@@ -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,MAAA,IAAI,CAAC,OAAO,mCAAI,qBAAS,CAAC,MAAM,GAC1C,CAAC;wBACF,WAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,kBAAgB,CAAC,EAAC;oBACvD,CAAC;gCAGe,IAAI,CAAC,OAAO;;;wBAAK,WAAM,QAAQ,CAAC,UAAU,EAAE,EAAA;;oBAA5B,KAAA,CAAC,SAA2B,CAAC,CAAC,OAAO,CAAA;;;oBAA/D,OAAO,KAAwD;oBAC/D,gBAAgB,2EACjB,2BAA2B,KAC9B,iBAAiB,mBAAA,EACjB,qB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ts: 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,iBA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istoryOptions?: FeeHistoryOptions;
|
|
12
13
|
transport?: Transport;
|
|
13
14
|
}
|
|
15
|
+
export interface FeeHistoryOptions {
|
|
16
|
+
estimator?: (rewards: BigNumber[]) => BigNumber;
|
|
17
|
+
percentile?: number;
|
|
18
|
+
blockLookback?: number;
|
|
19
|
+
minimumPriority?: BigNumber;
|
|
20
|
+
}
|
|
14
21
|
export declare function getGasPriceEstimate(provider: EvmProvider, opts?: Partial<GasPriceEstimateOptions>): Promise<EvmGasPriceEstimate>;
|
|
15
22
|
export declare function getGasPriceEstimate(provider: SolanaProvider, opts?: Partial<GasPriceEstimateOptions>): Promise<SvmGasPriceEstimate>;
|
|
@@ -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, fixedPointAdjustment, isEvmProvider, toBNWei } from "../utils";
|
|
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";
|
|
@@ -71,7 +71,8 @@ function getGasPriceEthers(provider, opts) {
|
|
|
71
71
|
// Testnet
|
|
72
72
|
_a[CHAIN_IDs.POLYGON_AMOY] = polygon.gasStation,
|
|
73
73
|
_a);
|
|
74
|
-
|
|
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];
|
|
75
76
|
assert(gasPriceFeed || legacyFallback, "No suitable gas price oracle for Chain ID ".concat(chainId));
|
|
76
77
|
gasPriceFeed !== null && gasPriceFeed !== void 0 ? gasPriceFeed : (gasPriceFeed = ethereum.eip1559);
|
|
77
78
|
return gasPriceFeed(provider, opts);
|
|
@@ -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,oBAAoB,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;
|
|
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,GAAG,CAAC,CAAC;oBAC3D,qBAAqB,GAAG,MAAA,IAAI,CAAC,qBAAqB,mCAAI,OAAO,CAAC,GA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BAAA,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"}
|
|
@@ -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"}
|
|
@@ -9,8 +9,15 @@ export interface GasPriceEstimateOptions {
|
|
|
9
9
|
legacyFallback: boolean;
|
|
10
10
|
chainId: number;
|
|
11
11
|
unsignedTx?: unknown;
|
|
12
|
+
feeHistoryOptions?: FeeHistoryOptions;
|
|
12
13
|
transport?: Transport;
|
|
13
14
|
}
|
|
15
|
+
export interface FeeHistoryOptions {
|
|
16
|
+
estimator?: (rewards: BigNumber[]) => BigNumber;
|
|
17
|
+
percentile?: number;
|
|
18
|
+
blockLookback?: number;
|
|
19
|
+
minimumPriority?: BigNumber;
|
|
20
|
+
}
|
|
14
21
|
export declare function getGasPriceEstimate(provider: EvmProvider, opts?: Partial<GasPriceEstimateOptions>): Promise<EvmGasPriceEstimate>;
|
|
15
22
|
export declare function getGasPriceEstimate(provider: SolanaProvider, opts?: Partial<GasPriceEstimateOptions>): Promise<SvmGasPriceEstimate>;
|
|
16
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;AAGjC,OAAO,EAAE,SAAS,
|
|
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
|
@@ -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, fixedPointAdjustment, isEvmProvider, toBNWei } from "../utils";
|
|
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
|
};
|
|
@@ -109,7 +118,9 @@ function getGasPriceEthers(provider: providers.Provider, opts: GasPriceEstimateO
|
|
|
109
118
|
[CHAIN_IDs.POLYGON_AMOY]: polygon.gasStation,
|
|
110
119
|
} as const;
|
|
111
120
|
|
|
112
|
-
|
|
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
|
+
|
|
113
124
|
assert(gasPriceFeed || legacyFallback, `No suitable gas price oracle for Chain ID ${chainId}`);
|
|
114
125
|
gasPriceFeed ??= ethereum.eip1559;
|
|
115
126
|
|