@across-protocol/sdk 3.3.32 → 3.4.1
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/clients/BundleDataClient/utils/SuperstructUtils.d.ts +10 -10
- package/dist/cjs/gasPriceOracle/adapters/arbitrum.d.ts +2 -1
- package/dist/cjs/gasPriceOracle/adapters/arbitrum.js +2 -2
- package/dist/cjs/gasPriceOracle/adapters/arbitrum.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/ethereum.d.ts +6 -4
- package/dist/cjs/gasPriceOracle/adapters/ethereum.js +21 -13
- package/dist/cjs/gasPriceOracle/adapters/ethereum.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/linea-viem.d.ts +2 -1
- package/dist/cjs/gasPriceOracle/adapters/linea-viem.js +16 -10
- package/dist/cjs/gasPriceOracle/adapters/linea-viem.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/linea.d.ts +2 -1
- package/dist/cjs/gasPriceOracle/adapters/linea.js +2 -2
- package/dist/cjs/gasPriceOracle/adapters/linea.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/polygon.d.ts +21 -1
- package/dist/cjs/gasPriceOracle/adapters/polygon.js +45 -5
- package/dist/cjs/gasPriceOracle/adapters/polygon.js.map +1 -1
- package/dist/cjs/gasPriceOracle/oracle.d.ts +11 -3
- package/dist/cjs/gasPriceOracle/oracle.js +29 -27
- package/dist/cjs/gasPriceOracle/oracle.js.map +1 -1
- package/dist/cjs/providers/types.d.ts +3 -3
- package/dist/cjs/relayFeeCalculator/chain-queries/alephZero.d.ts +0 -229
- package/dist/cjs/relayFeeCalculator/chain-queries/alephZero.js +2 -12
- package/dist/cjs/relayFeeCalculator/chain-queries/alephZero.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +10 -5
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +55 -11
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/factory.d.ts +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +4 -5
- package/dist/cjs/relayFeeCalculator/chain-queries/factory.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/polygon.d.ts +0 -229
- package/dist/cjs/relayFeeCalculator/chain-queries/polygon.js +2 -12
- package/dist/cjs/relayFeeCalculator/chain-queries/polygon.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/cjs/utils/common.d.ts +1 -8
- package/dist/cjs/utils/common.js +1 -83
- package/dist/cjs/utils/common.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +10 -10
- package/dist/esm/gasPriceOracle/adapters/arbitrum.d.ts +10 -1
- package/dist/esm/gasPriceOracle/adapters/arbitrum.js +10 -4
- package/dist/esm/gasPriceOracle/adapters/arbitrum.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/ethereum.d.ts +19 -6
- package/dist/esm/gasPriceOracle/adapters/ethereum.js +38 -16
- package/dist/esm/gasPriceOracle/adapters/ethereum.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/linea-viem.d.ts +19 -1
- package/dist/esm/gasPriceOracle/adapters/linea-viem.js +33 -10
- package/dist/esm/gasPriceOracle/adapters/linea-viem.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/linea.d.ts +2 -1
- package/dist/esm/gasPriceOracle/adapters/linea.js +6 -2
- package/dist/esm/gasPriceOracle/adapters/linea.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/polygon.d.ts +27 -1
- package/dist/esm/gasPriceOracle/adapters/polygon.js +49 -5
- package/dist/esm/gasPriceOracle/adapters/polygon.js.map +1 -1
- package/dist/esm/gasPriceOracle/oracle.d.ts +16 -8
- package/dist/esm/gasPriceOracle/oracle.js +35 -33
- package/dist/esm/gasPriceOracle/oracle.js.map +1 -1
- package/dist/esm/providers/types.d.ts +3 -3
- package/dist/esm/relayFeeCalculator/chain-queries/alephZero.d.ts +0 -229
- package/dist/esm/relayFeeCalculator/chain-queries/alephZero.js +3 -13
- package/dist/esm/relayFeeCalculator/chain-queries/alephZero.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +21 -7
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +68 -15
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/factory.d.ts +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/factory.js +4 -5
- package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/polygon.d.ts +0 -229
- package/dist/esm/relayFeeCalculator/chain-queries/polygon.js +3 -13
- package/dist/esm/relayFeeCalculator/chain-queries/polygon.js.map +1 -1
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/esm/utils/common.d.ts +1 -19
- package/dist/esm/utils/common.js +3 -95
- package/dist/esm/utils/common.js.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +10 -10
- package/dist/types/gasPriceOracle/adapters/arbitrum.d.ts +10 -1
- package/dist/types/gasPriceOracle/adapters/arbitrum.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/adapters/ethereum.d.ts +19 -6
- package/dist/types/gasPriceOracle/adapters/ethereum.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/adapters/linea-viem.d.ts +19 -1
- package/dist/types/gasPriceOracle/adapters/linea-viem.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/adapters/linea.d.ts +2 -1
- package/dist/types/gasPriceOracle/adapters/linea.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/adapters/polygon.d.ts +27 -1
- package/dist/types/gasPriceOracle/adapters/polygon.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/oracle.d.ts +16 -8
- package/dist/types/gasPriceOracle/oracle.d.ts.map +1 -1
- package/dist/types/providers/types.d.ts +3 -3
- package/dist/types/relayFeeCalculator/chain-queries/alephZero.d.ts +0 -229
- package/dist/types/relayFeeCalculator/chain-queries/alephZero.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +21 -7
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/polygon.d.ts +0 -229
- package/dist/types/relayFeeCalculator/chain-queries/polygon.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
- package/dist/types/utils/common.d.ts +1 -19
- package/dist/types/utils/common.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/gasPriceOracle/adapters/arbitrum.ts +13 -6
- package/src/gasPriceOracle/adapters/ethereum.ts +43 -12
- package/src/gasPriceOracle/adapters/linea-viem.ts +32 -6
- package/src/gasPriceOracle/adapters/linea.ts +7 -2
- package/src/gasPriceOracle/adapters/polygon.ts +46 -5
- package/src/gasPriceOracle/oracle.ts +53 -28
- package/src/relayFeeCalculator/chain-queries/alephZero.ts +1 -29
- package/src/relayFeeCalculator/chain-queries/baseQuery.ts +73 -20
- package/src/relayFeeCalculator/chain-queries/factory.ts +6 -6
- package/src/relayFeeCalculator/chain-queries/polygon.ts +1 -29
- package/src/relayFeeCalculator/relayFeeCalculator.ts +6 -1
- package/src/utils/common.ts +2 -92
- package/dist/cjs/gasPriceOracle/adapters/arbitrum-viem.d.ts +0 -3
- package/dist/cjs/gasPriceOracle/adapters/arbitrum-viem.js +0 -21
- package/dist/cjs/gasPriceOracle/adapters/arbitrum-viem.js.map +0 -1
- package/dist/cjs/gasPriceOracle/adapters/ethereum-viem.d.ts +0 -4
- package/dist/cjs/gasPriceOracle/adapters/ethereum-viem.js +0 -26
- package/dist/cjs/gasPriceOracle/adapters/ethereum-viem.js.map +0 -1
- package/dist/cjs/gasPriceOracle/adapters/polygon-viem.d.ts +0 -3
- package/dist/cjs/gasPriceOracle/adapters/polygon-viem.js +0 -84
- package/dist/cjs/gasPriceOracle/adapters/polygon-viem.js.map +0 -1
- package/dist/esm/gasPriceOracle/adapters/arbitrum-viem.d.ts +0 -3
- package/dist/esm/gasPriceOracle/adapters/arbitrum-viem.js +0 -20
- package/dist/esm/gasPriceOracle/adapters/arbitrum-viem.js.map +0 -1
- package/dist/esm/gasPriceOracle/adapters/ethereum-viem.d.ts +0 -4
- package/dist/esm/gasPriceOracle/adapters/ethereum-viem.js +0 -21
- package/dist/esm/gasPriceOracle/adapters/ethereum-viem.js.map +0 -1
- package/dist/esm/gasPriceOracle/adapters/polygon-viem.d.ts +0 -3
- package/dist/esm/gasPriceOracle/adapters/polygon-viem.js +0 -82
- package/dist/esm/gasPriceOracle/adapters/polygon-viem.js.map +0 -1
- package/dist/types/gasPriceOracle/adapters/arbitrum-viem.d.ts +0 -4
- package/dist/types/gasPriceOracle/adapters/arbitrum-viem.d.ts.map +0 -1
- package/dist/types/gasPriceOracle/adapters/ethereum-viem.d.ts +0 -5
- package/dist/types/gasPriceOracle/adapters/ethereum-viem.d.ts.map +0 -1
- package/dist/types/gasPriceOracle/adapters/polygon-viem.d.ts +0 -4
- package/dist/types/gasPriceOracle/adapters/polygon-viem.d.ts.map +0 -1
- package/src/gasPriceOracle/adapters/arbitrum-viem.ts +0 -13
- package/src/gasPriceOracle/adapters/ethereum-viem.ts +0 -19
- package/src/gasPriceOracle/adapters/polygon-viem.ts +0 -86
|
@@ -1,234 +1,5 @@
|
|
|
1
|
-
import { Logger } from "../relayFeeCalculator";
|
|
2
|
-
import { providers } from "ethers";
|
|
3
1
|
import { QueryBase } from "./baseQuery";
|
|
4
2
|
export declare class PolygonQueries extends QueryBase {
|
|
5
|
-
constructor(provider: providers.Provider, symbolMapping?: {
|
|
6
|
-
ACX: {
|
|
7
|
-
name: string;
|
|
8
|
-
symbol: string;
|
|
9
|
-
decimals: number;
|
|
10
|
-
addresses: {
|
|
11
|
-
[x: number]: string;
|
|
12
|
-
};
|
|
13
|
-
coingeckoId: string;
|
|
14
|
-
};
|
|
15
|
-
ARB: {
|
|
16
|
-
name: string;
|
|
17
|
-
symbol: string;
|
|
18
|
-
decimals: number;
|
|
19
|
-
addresses: {
|
|
20
|
-
[x: number]: string;
|
|
21
|
-
};
|
|
22
|
-
coingeckoId: string;
|
|
23
|
-
};
|
|
24
|
-
AZERO: {
|
|
25
|
-
name: string;
|
|
26
|
-
symbol: string;
|
|
27
|
-
decimals: number;
|
|
28
|
-
addresses: {
|
|
29
|
-
[x: number]: string;
|
|
30
|
-
};
|
|
31
|
-
coingeckoId: string;
|
|
32
|
-
};
|
|
33
|
-
BAL: {
|
|
34
|
-
name: string;
|
|
35
|
-
symbol: string;
|
|
36
|
-
decimals: number;
|
|
37
|
-
addresses: {
|
|
38
|
-
[x: number]: string;
|
|
39
|
-
};
|
|
40
|
-
coingeckoId: string;
|
|
41
|
-
};
|
|
42
|
-
BADGER: {
|
|
43
|
-
name: string;
|
|
44
|
-
symbol: string;
|
|
45
|
-
decimals: number;
|
|
46
|
-
addresses: {
|
|
47
|
-
[x: number]: string;
|
|
48
|
-
};
|
|
49
|
-
coingeckoId: string;
|
|
50
|
-
};
|
|
51
|
-
BOBA: {
|
|
52
|
-
name: string;
|
|
53
|
-
symbol: string;
|
|
54
|
-
decimals: number;
|
|
55
|
-
addresses: {
|
|
56
|
-
[x: number]: string;
|
|
57
|
-
};
|
|
58
|
-
coingeckoId: string;
|
|
59
|
-
};
|
|
60
|
-
DAI: {
|
|
61
|
-
name: string;
|
|
62
|
-
symbol: string;
|
|
63
|
-
decimals: number;
|
|
64
|
-
addresses: {
|
|
65
|
-
[x: number]: string;
|
|
66
|
-
};
|
|
67
|
-
coingeckoId: string;
|
|
68
|
-
};
|
|
69
|
-
ETH: {
|
|
70
|
-
name: string;
|
|
71
|
-
symbol: string;
|
|
72
|
-
decimals: number;
|
|
73
|
-
addresses: {
|
|
74
|
-
[x: number]: string;
|
|
75
|
-
};
|
|
76
|
-
coingeckoId: string;
|
|
77
|
-
};
|
|
78
|
-
GHO: {
|
|
79
|
-
name: string;
|
|
80
|
-
symbol: string;
|
|
81
|
-
decimals: number;
|
|
82
|
-
addresses: {
|
|
83
|
-
[x: number]: string;
|
|
84
|
-
};
|
|
85
|
-
coingeckoId: string;
|
|
86
|
-
};
|
|
87
|
-
LSK: {
|
|
88
|
-
name: string;
|
|
89
|
-
symbol: string;
|
|
90
|
-
decimals: number;
|
|
91
|
-
addresses: {
|
|
92
|
-
[x: number]: string;
|
|
93
|
-
};
|
|
94
|
-
coingeckoId: string;
|
|
95
|
-
};
|
|
96
|
-
MATIC: {
|
|
97
|
-
name: string;
|
|
98
|
-
symbol: string;
|
|
99
|
-
decimals: number;
|
|
100
|
-
addresses: {
|
|
101
|
-
[x: number]: string;
|
|
102
|
-
};
|
|
103
|
-
coingeckoId: string;
|
|
104
|
-
};
|
|
105
|
-
OP: {
|
|
106
|
-
name: string;
|
|
107
|
-
symbol: string;
|
|
108
|
-
decimals: number;
|
|
109
|
-
addresses: {
|
|
110
|
-
[x: number]: string;
|
|
111
|
-
};
|
|
112
|
-
coingeckoId: string;
|
|
113
|
-
};
|
|
114
|
-
POOL: {
|
|
115
|
-
name: string;
|
|
116
|
-
symbol: string;
|
|
117
|
-
decimals: number;
|
|
118
|
-
addresses: {
|
|
119
|
-
[x: number]: string;
|
|
120
|
-
};
|
|
121
|
-
coingeckoId: string;
|
|
122
|
-
};
|
|
123
|
-
SNX: {
|
|
124
|
-
name: string;
|
|
125
|
-
symbol: string;
|
|
126
|
-
decimals: number;
|
|
127
|
-
addresses: {
|
|
128
|
-
[x: number]: string;
|
|
129
|
-
};
|
|
130
|
-
coingeckoId: string;
|
|
131
|
-
};
|
|
132
|
-
UMA: {
|
|
133
|
-
name: string;
|
|
134
|
-
symbol: string;
|
|
135
|
-
decimals: number;
|
|
136
|
-
addresses: {
|
|
137
|
-
[x: number]: string;
|
|
138
|
-
};
|
|
139
|
-
coingeckoId: string;
|
|
140
|
-
};
|
|
141
|
-
USDB: {
|
|
142
|
-
name: string;
|
|
143
|
-
symbol: string;
|
|
144
|
-
decimals: number;
|
|
145
|
-
addresses: {
|
|
146
|
-
[x: number]: string;
|
|
147
|
-
};
|
|
148
|
-
coingeckoId: string;
|
|
149
|
-
};
|
|
150
|
-
USDC: {
|
|
151
|
-
name: string;
|
|
152
|
-
symbol: string;
|
|
153
|
-
decimals: number;
|
|
154
|
-
addresses: {
|
|
155
|
-
[x: number]: string;
|
|
156
|
-
};
|
|
157
|
-
coingeckoId: string;
|
|
158
|
-
};
|
|
159
|
-
"USDC.e": {
|
|
160
|
-
name: string;
|
|
161
|
-
symbol: string;
|
|
162
|
-
decimals: number;
|
|
163
|
-
addresses: {
|
|
164
|
-
[x: number]: string;
|
|
165
|
-
};
|
|
166
|
-
coingeckoId: string;
|
|
167
|
-
};
|
|
168
|
-
USDbC: {
|
|
169
|
-
name: string;
|
|
170
|
-
symbol: string;
|
|
171
|
-
decimals: number;
|
|
172
|
-
addresses: {
|
|
173
|
-
[x: number]: string;
|
|
174
|
-
};
|
|
175
|
-
coingeckoId: string;
|
|
176
|
-
};
|
|
177
|
-
USDzC: {
|
|
178
|
-
name: string;
|
|
179
|
-
symbol: string;
|
|
180
|
-
decimals: number;
|
|
181
|
-
addresses: {
|
|
182
|
-
[x: number]: string;
|
|
183
|
-
};
|
|
184
|
-
coingeckoId: string;
|
|
185
|
-
};
|
|
186
|
-
USDT: {
|
|
187
|
-
name: string;
|
|
188
|
-
symbol: string;
|
|
189
|
-
decimals: number;
|
|
190
|
-
addresses: {
|
|
191
|
-
[x: number]: string;
|
|
192
|
-
};
|
|
193
|
-
coingeckoId: string;
|
|
194
|
-
};
|
|
195
|
-
WAZERO: {
|
|
196
|
-
name: string;
|
|
197
|
-
symbol: string;
|
|
198
|
-
decimals: number;
|
|
199
|
-
addresses: {
|
|
200
|
-
[x: number]: string;
|
|
201
|
-
};
|
|
202
|
-
coingeckoId: string;
|
|
203
|
-
};
|
|
204
|
-
WBTC: {
|
|
205
|
-
name: string;
|
|
206
|
-
symbol: string;
|
|
207
|
-
decimals: number;
|
|
208
|
-
addresses: {
|
|
209
|
-
[x: number]: string;
|
|
210
|
-
};
|
|
211
|
-
coingeckoId: string;
|
|
212
|
-
};
|
|
213
|
-
WETH: {
|
|
214
|
-
name: string;
|
|
215
|
-
symbol: string;
|
|
216
|
-
decimals: number;
|
|
217
|
-
addresses: {
|
|
218
|
-
[x: number]: string;
|
|
219
|
-
};
|
|
220
|
-
coingeckoId: string;
|
|
221
|
-
};
|
|
222
|
-
WMATIC: {
|
|
223
|
-
name: string;
|
|
224
|
-
symbol: string;
|
|
225
|
-
decimals: number;
|
|
226
|
-
addresses: {
|
|
227
|
-
[x: number]: string;
|
|
228
|
-
};
|
|
229
|
-
coingeckoId: string;
|
|
230
|
-
};
|
|
231
|
-
}, spokePoolAddress?: string | undefined, simulatedRelayerAddress?: string, coingeckoProApiKey?: string, logger?: Logger, gasMarkup?: number);
|
|
232
3
|
getTokenPrice(tokenSymbol: string): Promise<number>;
|
|
233
4
|
}
|
|
234
5
|
//# sourceMappingURL=polygon.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polygon.d.ts","sourceRoot":"","sources":["../../../../src/relayFeeCalculator/chain-queries/polygon.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"polygon.d.ts","sourceRoot":"","sources":["../../../../src/relayFeeCalculator/chain-queries/polygon.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,qBAAa,cAAe,SAAQ,SAAS;IAC5B,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAcnE"}
|
|
@@ -5,7 +5,7 @@ export interface QueryInterface {
|
|
|
5
5
|
getGasCosts: (deposit: Deposit, relayer: string, options?: Partial<{
|
|
6
6
|
gasPrice: BigNumberish;
|
|
7
7
|
gasUnits: BigNumberish;
|
|
8
|
-
|
|
8
|
+
baseFeeMultiplier: BigNumber;
|
|
9
9
|
transport: Transport;
|
|
10
10
|
}>) => Promise<TransactionCostEstimate>;
|
|
11
11
|
getTokenPrice: (tokenSymbol: string) => Promise<number>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relayFeeCalculator.d.ts","sourceRoot":"","sources":["../../../src/relayFeeCalculator/relayFeeCalculator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EACL,SAAS,EACT,YAAY,EAEZ,uBAAuB,EAWxB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAGjC,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,CACX,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"relayFeeCalculator.d.ts","sourceRoot":"","sources":["../../../src/relayFeeCalculator/relayFeeCalculator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EACL,SAAS,EACT,YAAY,EAEZ,uBAAuB,EAWxB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAGjC,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,CACX,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE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AAa,CAAC,EAAE,YAAY,EAC5B,gBAAgB,UAAQ,EACxB,cAAc,SAAoC,EAClD,WAAW,CAAC,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,YAAY,EACvB,QAAQ,CAAC,EAAE,YAAY,GACtB,OAAO,CAAC,iBAAiB,CAAC;CAkE9B"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { L2Provider } from "@eth-optimism/sdk/dist/interfaces/l2-provider";
|
|
2
1
|
import Decimal from "decimal.js";
|
|
3
|
-
import { ethers
|
|
2
|
+
import { ethers } from "ethers";
|
|
4
3
|
import { BigNumber, BigNumberish, BN } from "./BigNumberUtils";
|
|
5
|
-
import { Transport } from "viem";
|
|
6
4
|
export type Decimalish = string | number | Decimal;
|
|
7
5
|
export declare const AddressZero = "0x0000000000000000000000000000000000000000";
|
|
8
6
|
export declare const MAX_BIG_INT: ethers.BigNumber;
|
|
@@ -131,21 +129,5 @@ export type TransactionCostEstimate = {
|
|
|
131
129
|
tokenGasCost: BigNumber;
|
|
132
130
|
gasPrice: BigNumber;
|
|
133
131
|
};
|
|
134
|
-
/**
|
|
135
|
-
* Estimates the total gas cost required to submit an unsigned (populated) transaction on-chain.
|
|
136
|
-
* @param unsignedTx The unsigned transaction that this function will estimate.
|
|
137
|
-
* @param senderAddress The address that the transaction will be submitted from.
|
|
138
|
-
* @param provider A valid ethers provider - will be used to reason the gas price.
|
|
139
|
-
* @param options
|
|
140
|
-
* @param options.gasPrice A manually provided gas price - if set, this function will not resolve the current gas price.
|
|
141
|
-
* @param options.gasUnits A manually provided gas units - if set, this function will not estimate the gas units.
|
|
142
|
-
* @param options.transport A custom transport object for custom gas price retrieval.
|
|
143
|
-
* @returns Estimated cost in units of gas and the underlying gas token (gasPrice * estimatedGasUnits).
|
|
144
|
-
*/
|
|
145
|
-
export declare function estimateTotalGasRequiredByUnsignedTransaction(unsignedTx: PopulatedTransaction, senderAddress: string, provider: providers.Provider | L2Provider<providers.Provider>, options?: Partial<{
|
|
146
|
-
gasPrice: BigNumberish;
|
|
147
|
-
gasUnits: BigNumberish;
|
|
148
|
-
transport: Transport;
|
|
149
|
-
}>): Promise<TransactionCostEstimate>;
|
|
150
132
|
export declare function randomAddress(): string;
|
|
151
133
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/utils/common.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/utils/common.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,EAAE,EAAiC,MAAM,kBAAkB,CAAC;AAG9F,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AACnD,eAAO,MAAM,WAAW,+CAA+B,CAAC;AACxD,eAAO,MAAM,WAAW,kBAAqD,CAAC;AAE9E;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,QAAS,YAAY,aAAa,MAAM,KAAG,EAA0C,CAAC;AAE1G;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,QAAS,YAAY,aAAa,MAAM,KAAG,MAA+C,CAAC;AAE/G;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,EAAE,CAIxD;AACD;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,EAAE,CAIxD;AAED,eAAO,MAAM,oBAAoB,kBAAe,CAAC;AAEjD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,YAAY,EACxB,KAAK,GAAE,MAAM,GAAG,MAAU,EAC1B,UAAU,SAAK,EACf,cAAc,SAAK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
@@ -2,14 +2,21 @@ import { providers } from "ethers";
|
|
|
2
2
|
import { bnOne } from "../../utils";
|
|
3
3
|
import { GasPriceEstimate } from "../types";
|
|
4
4
|
import * as ethereum from "./ethereum";
|
|
5
|
+
import { GasPriceEstimateOptions } from "../oracle";
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @notice Return Arbitrum orbit gas fees
|
|
9
|
+
* @dev Arbitrum Nitro implements EIP-1559 pricing, but the priority fee is always refunded to the caller.
|
|
10
|
+
* Reference: https://docs.arbitrum.io/how-arbitrum-works/gas-fees so we hardcode the priority fee
|
|
11
|
+
* to 1 wei.
|
|
12
|
+
* @param provider Ethers Provider
|
|
13
|
+
* @returns GasPriceEstimate
|
|
14
|
+
*/
|
|
15
|
+
export async function eip1559(provider: providers.Provider, opts: GasPriceEstimateOptions): Promise<GasPriceEstimate> {
|
|
16
|
+
const { maxFeePerGas: _maxFeePerGas, maxPriorityFeePerGas } = await ethereum.eip1559(provider, opts);
|
|
10
17
|
|
|
11
|
-
// eip1559() sets maxFeePerGas = lastBaseFeePerGas + maxPriorityFeePerGas, so
|
|
12
|
-
// The
|
|
18
|
+
// eip1559() sets maxFeePerGas = lastBaseFeePerGas + maxPriorityFeePerGas, so back out priority fee.
|
|
19
|
+
// The remaining maxFeePerGas should be scaled already.
|
|
13
20
|
const maxFeePerGas = _maxFeePerGas.sub(maxPriorityFeePerGas).add(bnOne);
|
|
14
21
|
|
|
15
22
|
return { maxPriorityFeePerGas: bnOne, maxFeePerGas };
|
|
@@ -1,26 +1,40 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
2
|
import { providers } from "ethers";
|
|
3
|
-
import { BigNumber, bnZero, getNetworkName } from "../../utils";
|
|
3
|
+
import { BigNumber, bnZero, fixedPointAdjustment, getNetworkName } from "../../utils";
|
|
4
4
|
import { GasPriceEstimate } from "../types";
|
|
5
5
|
import { gasPriceError } from "../util";
|
|
6
|
+
import { GasPriceEstimateOptions } from "../oracle";
|
|
7
|
+
|
|
8
|
+
// TODO: We intend to remove `eip1559Bad()` as an option and make eip1559Raw the only option eventually. The reason
|
|
9
|
+
// they both exist currently is because eip1559Raw is new and untested on production so we will slowly roll it out
|
|
10
|
+
// by using the convenient environment variable safety guard.
|
|
6
11
|
|
|
7
12
|
/**
|
|
13
|
+
* @dev If GAS_PRICE_EIP1559_RAW_${chainId}=true, then constructs total fee by adding
|
|
14
|
+
* eth_getBlock("pending").baseFee to eth_maxPriorityFeePerGas, otherwise calls the ethers provider's
|
|
15
|
+
* getFeeData() method which adds eth_getBlock("latest").baseFee to a hardcoded priority fee of 1.5 gwei.
|
|
8
16
|
* @param provider ethers RPC provider instance.
|
|
9
|
-
* @param chainId Chain ID of provider instance.
|
|
10
17
|
* @returns Promise of gas price estimate object.
|
|
11
18
|
*/
|
|
12
|
-
export function eip1559(provider: providers.Provider,
|
|
13
|
-
const useRaw = process.env[`GAS_PRICE_EIP1559_RAW_${chainId}`] === "true";
|
|
14
|
-
return useRaw
|
|
19
|
+
export function eip1559(provider: providers.Provider, opts: GasPriceEstimateOptions): Promise<GasPriceEstimate> {
|
|
20
|
+
const useRaw = process.env[`GAS_PRICE_EIP1559_RAW_${opts.chainId}`] === "true";
|
|
21
|
+
return useRaw
|
|
22
|
+
? eip1559Raw(provider, opts.chainId, opts.baseFeeMultiplier)
|
|
23
|
+
: eip1559Bad(provider, opts.chainId, opts.baseFeeMultiplier);
|
|
15
24
|
}
|
|
16
25
|
|
|
17
26
|
/**
|
|
18
27
|
* @note Performs direct RPC calls to retrieve the RPC-suggested priority fee for the next block.
|
|
28
|
+
* @dev Constructs total fee by adding eth_getBlock("pending").baseFee to eth_maxPriorityFeePerGas
|
|
19
29
|
* @param provider ethers RPC provider instance.
|
|
20
30
|
* @param chainId Chain ID of the provider instance.
|
|
21
31
|
* @returns Promise of gas price estimate object.
|
|
22
32
|
*/
|
|
23
|
-
export async function eip1559Raw(
|
|
33
|
+
export async function eip1559Raw(
|
|
34
|
+
provider: providers.Provider,
|
|
35
|
+
chainId: number,
|
|
36
|
+
baseFeeMultiplier: BigNumber
|
|
37
|
+
): Promise<GasPriceEstimate> {
|
|
24
38
|
const [{ baseFeePerGas }, _maxPriorityFeePerGas] = await Promise.all([
|
|
25
39
|
provider.getBlock("pending"),
|
|
26
40
|
(provider as providers.JsonRpcProvider).send("eth_maxPriorityFeePerGas", []),
|
|
@@ -28,19 +42,27 @@ export async function eip1559Raw(provider: providers.Provider, chainId: number):
|
|
|
28
42
|
const maxPriorityFeePerGas = BigNumber.from(_maxPriorityFeePerGas);
|
|
29
43
|
assert(BigNumber.isBigNumber(baseFeePerGas), `No baseFeePerGas received on ${getNetworkName(chainId)}`);
|
|
30
44
|
|
|
45
|
+
const scaledBaseFee = baseFeePerGas.mul(baseFeeMultiplier).div(fixedPointAdjustment);
|
|
31
46
|
return {
|
|
32
|
-
maxFeePerGas: maxPriorityFeePerGas.add(
|
|
47
|
+
maxFeePerGas: maxPriorityFeePerGas.add(scaledBaseFee),
|
|
33
48
|
maxPriorityFeePerGas,
|
|
34
49
|
};
|
|
35
50
|
}
|
|
36
51
|
|
|
37
52
|
/**
|
|
38
|
-
* @
|
|
53
|
+
* @notice Returns fee data using provider's getFeeData() method.
|
|
54
|
+
* @note Resolves priority gas pricing poorly, because the priority fee is hardcoded to 1.5 Gwei in ethers v5's
|
|
55
|
+
* getFeeData() method
|
|
56
|
+
* @dev TODO: Remove this function soon. See note above about slowly rolling out eip1559Raw.
|
|
39
57
|
* @param provider ethers RPC provider instance.
|
|
40
58
|
* @param chainId Chain ID of the provider instance.
|
|
41
59
|
* @returns Promise of gas price estimate object.
|
|
42
60
|
*/
|
|
43
|
-
export async function eip1559Bad(
|
|
61
|
+
export async function eip1559Bad(
|
|
62
|
+
provider: providers.Provider,
|
|
63
|
+
chainId: number,
|
|
64
|
+
baseFeeMultiplier: BigNumber
|
|
65
|
+
): Promise<GasPriceEstimate> {
|
|
44
66
|
const feeData = await provider.getFeeData();
|
|
45
67
|
|
|
46
68
|
[feeData.lastBaseFeePerGas, feeData.maxPriorityFeePerGas].forEach((field: BigNumber | null) => {
|
|
@@ -48,18 +70,27 @@ export async function eip1559Bad(provider: providers.Provider, chainId: number):
|
|
|
48
70
|
});
|
|
49
71
|
|
|
50
72
|
const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas as BigNumber;
|
|
51
|
-
const
|
|
73
|
+
const scaledLastBaseFeePerGas = (feeData.lastBaseFeePerGas as BigNumber)
|
|
74
|
+
.mul(baseFeeMultiplier)
|
|
75
|
+
.div(fixedPointAdjustment);
|
|
76
|
+
const maxFeePerGas = maxPriorityFeePerGas.add(scaledLastBaseFeePerGas);
|
|
52
77
|
|
|
53
78
|
return { maxPriorityFeePerGas, maxFeePerGas };
|
|
54
79
|
}
|
|
55
80
|
|
|
56
|
-
|
|
81
|
+
/**
|
|
82
|
+
* @notice Returns result of eth_gasPrice RPC call
|
|
83
|
+
* @dev Its recommended to use the eip1559Raw method over this one where possible as it will be more accurate.
|
|
84
|
+
* @returns GasPriceEstimate
|
|
85
|
+
*/
|
|
86
|
+
export async function legacy(provider: providers.Provider, opts: GasPriceEstimateOptions): Promise<GasPriceEstimate> {
|
|
87
|
+
const { chainId, baseFeeMultiplier } = opts;
|
|
57
88
|
const gasPrice = await provider.getGasPrice();
|
|
58
89
|
|
|
59
90
|
if (!BigNumber.isBigNumber(gasPrice) || gasPrice.lt(bnZero)) gasPriceError("getGasPrice()", chainId, gasPrice);
|
|
60
91
|
|
|
61
92
|
return {
|
|
62
|
-
maxFeePerGas: gasPrice,
|
|
93
|
+
maxFeePerGas: gasPrice.mul(baseFeeMultiplier).div(fixedPointAdjustment),
|
|
63
94
|
maxPriorityFeePerGas: bnZero,
|
|
64
95
|
};
|
|
65
96
|
}
|
|
@@ -1,14 +1,40 @@
|
|
|
1
|
-
import { PublicClient } from "viem";
|
|
1
|
+
import { Address, Hex, PublicClient } from "viem";
|
|
2
2
|
import { estimateGas } from "viem/linea";
|
|
3
3
|
import { DEFAULT_SIMULATED_RELAYER_ADDRESS as account } from "../../constants";
|
|
4
4
|
import { InternalGasPriceEstimate } from "../types";
|
|
5
|
+
import { GasPriceEstimateOptions } from "../oracle";
|
|
6
|
+
import { fixedPointAdjustment } from "../../utils";
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @notice The Linea viem provider calls the linea_estimateGas RPC endpoint to estimate gas. Linea is unique
|
|
10
|
+
* in that the recommended fee per gas is hardcoded to 7 wei while the priority fee is dynamic based on the
|
|
11
|
+
* compressed transaction size, layer 1 verification costs and capacity, gas price ratio between layer 1 and layer 2,
|
|
12
|
+
* the transaction's gas usage, the minimum gas price on layer 2,
|
|
13
|
+
* and a minimum margin (for error) for gas price estimation.
|
|
14
|
+
* Source: https://docs.linea.build/get-started/how-to/gas-fees#how-gas-works-on-linea
|
|
15
|
+
* @dev Because the Linea priority fee is more volatile than the base fee, the base fee multiplier will be applied
|
|
16
|
+
* to the priority fee.
|
|
17
|
+
* @param provider Viem PublicClient
|
|
18
|
+
* @param _chainId Unused in this adapter
|
|
19
|
+
* @param baseFeeMultiplier Amount to multiply priority fee, since Linea's base fee is hardcoded while its priority
|
|
20
|
+
* fee is dynamic
|
|
21
|
+
* @param _unsignedTx Should contain any params passed to linea_estimateGas, which are listed
|
|
22
|
+
* here: https://docs.linea.build/api/reference/linea-estimategas#parameters
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export async function eip1559(
|
|
26
|
+
provider: PublicClient,
|
|
27
|
+
opts: GasPriceEstimateOptions
|
|
28
|
+
): Promise<InternalGasPriceEstimate> {
|
|
29
|
+
const { unsignedTx, baseFeeMultiplier } = opts;
|
|
30
|
+
const { baseFeePerGas, priorityFeePerGas: _priorityFeePerGas } = await estimateGas(provider, {
|
|
31
|
+
account: (unsignedTx?.from as Address) ?? account,
|
|
32
|
+
to: (unsignedTx?.to as Address) ?? account,
|
|
33
|
+
value: BigInt(unsignedTx?.value?.toString() ?? "1"),
|
|
34
|
+
data: (unsignedTx?.data as Hex) ?? "0x",
|
|
11
35
|
});
|
|
36
|
+
const priorityFeePerGas =
|
|
37
|
+
(_priorityFeePerGas * BigInt(baseFeeMultiplier.toString())) / BigInt(fixedPointAdjustment.toString());
|
|
12
38
|
|
|
13
39
|
return {
|
|
14
40
|
maxFeePerGas: baseFeePerGas + priorityFeePerGas,
|
|
@@ -5,7 +5,12 @@
|
|
|
5
5
|
import { providers } from "ethers";
|
|
6
6
|
import { GasPriceEstimate } from "../types";
|
|
7
7
|
import * as ethereum from "./ethereum";
|
|
8
|
+
import { GasPriceEstimateOptions } from "../oracle";
|
|
8
9
|
|
|
9
|
-
export function eip1559(provider: providers.Provider,
|
|
10
|
-
|
|
10
|
+
export function eip1559(provider: providers.Provider, opts: GasPriceEstimateOptions): Promise<GasPriceEstimate> {
|
|
11
|
+
// We use the legacy method to call `eth_gasPrice` which empirically returns a more accurate
|
|
12
|
+
// gas price estimate than `eth_maxPriorityFeePerGas` or ethersProvider.getFeeData in the EIP1559 "raw" or "bad"
|
|
13
|
+
// cases. Based on testing, `eth_gasPrice` returns the closest price to the Linea-specific `linea_estimateGas`
|
|
14
|
+
// endpoint which the Viem Linea adapter queries.
|
|
15
|
+
return ethereum.legacy(provider, opts);
|
|
11
16
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { providers } from "ethers";
|
|
2
2
|
import { BaseHTTPAdapter, BaseHTTPAdapterArgs } from "../../priceClient/adapters/baseAdapter";
|
|
3
|
-
import { BigNumber, bnZero, isDefined, parseUnits } from "../../utils";
|
|
3
|
+
import { BigNumber, bnZero, fixedPointAdjustment, isDefined, parseUnits } from "../../utils";
|
|
4
4
|
import { CHAIN_IDs } from "../../constants";
|
|
5
5
|
import { GasPriceEstimate } from "../types";
|
|
6
6
|
import { gasPriceError } from "../util";
|
|
7
7
|
import { eip1559 } from "./ethereum";
|
|
8
|
+
import { GasPriceEstimateOptions } from "../oracle";
|
|
8
9
|
|
|
9
10
|
type Polygon1559GasPrice = {
|
|
10
11
|
maxPriorityFee: number | string;
|
|
@@ -27,7 +28,7 @@ type GasStationArgs = BaseHTTPAdapterArgs & {
|
|
|
27
28
|
|
|
28
29
|
const { POLYGON } = CHAIN_IDs;
|
|
29
30
|
|
|
30
|
-
class PolygonGasStation extends BaseHTTPAdapter {
|
|
31
|
+
export class PolygonGasStation extends BaseHTTPAdapter {
|
|
31
32
|
readonly chainId: number;
|
|
32
33
|
|
|
33
34
|
constructor({ chainId = POLYGON, host, timeout = 1500, retries = 1 }: GasStationArgs = {}) {
|
|
@@ -67,15 +68,55 @@ class PolygonGasStation extends BaseHTTPAdapter {
|
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
class MockRevertingPolygonGasStation extends PolygonGasStation {
|
|
72
|
+
getFeeData(): Promise<GasPriceEstimate> {
|
|
73
|
+
throw new Error();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const MockPolygonGasStationBaseFee = () => parseUnits("12", 9);
|
|
78
|
+
export const MockPolygonGasStationPriorityFee = () => parseUnits("1", 9);
|
|
79
|
+
|
|
80
|
+
class MockPolygonGasStation extends PolygonGasStation {
|
|
81
|
+
getFeeData(): Promise<GasPriceEstimate> {
|
|
82
|
+
return Promise.resolve({
|
|
83
|
+
maxPriorityFeePerGas: MockPolygonGasStationPriorityFee(),
|
|
84
|
+
maxFeePerGas: MockPolygonGasStationBaseFee().add(MockPolygonGasStationPriorityFee()),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @notice Returns the gas price suggested by the Polygon GasStation API or reconstructs it using
|
|
91
|
+
* the eip1559() method as a fallback.
|
|
92
|
+
* @param provider Ethers Provider.
|
|
93
|
+
* @returns GasPriceEstimate
|
|
94
|
+
*/
|
|
95
|
+
export async function gasStation(
|
|
96
|
+
provider: providers.Provider,
|
|
97
|
+
opts: GasPriceEstimateOptions
|
|
98
|
+
): Promise<GasPriceEstimate> {
|
|
99
|
+
const { chainId, baseFeeMultiplier } = opts;
|
|
100
|
+
let gasStation: PolygonGasStation;
|
|
101
|
+
if (process.env.TEST_POLYGON_GAS_STATION === "true") {
|
|
102
|
+
gasStation = new MockPolygonGasStation();
|
|
103
|
+
} else if (process.env.TEST_REVERTING_POLYGON_GAS_STATION === "true") {
|
|
104
|
+
gasStation = new MockRevertingPolygonGasStation();
|
|
105
|
+
} else {
|
|
106
|
+
gasStation = new PolygonGasStation({ chainId: chainId, timeout: 2000, retries: 0 });
|
|
107
|
+
}
|
|
72
108
|
let maxPriorityFeePerGas: BigNumber;
|
|
73
109
|
let maxFeePerGas: BigNumber;
|
|
74
110
|
try {
|
|
75
111
|
({ maxPriorityFeePerGas, maxFeePerGas } = await gasStation.getFeeData());
|
|
112
|
+
// Assume that the maxFeePerGas already includes the priority fee, so back out the priority fee before applying
|
|
113
|
+
// the baseFeeMultiplier.
|
|
114
|
+
const baseFeeMinusPriorityFee = maxFeePerGas.sub(maxPriorityFeePerGas);
|
|
115
|
+
const scaledBaseFee = baseFeeMinusPriorityFee.mul(baseFeeMultiplier).div(fixedPointAdjustment);
|
|
116
|
+
maxFeePerGas = scaledBaseFee.add(maxPriorityFeePerGas);
|
|
76
117
|
} catch (err) {
|
|
77
118
|
// Fall back to the RPC provider. May be less accurate.
|
|
78
|
-
({ maxPriorityFeePerGas, maxFeePerGas } = await eip1559(provider,
|
|
119
|
+
({ maxPriorityFeePerGas, maxFeePerGas } = await eip1559(provider, opts));
|
|
79
120
|
|
|
80
121
|
// Per the GasStation docs, the minimum priority fee on Polygon is 30 Gwei.
|
|
81
122
|
// https://docs.polygon.technology/tools/gas/polygon-gas-station/#interpretation
|