@across-protocol/sdk 3.2.13 → 3.2.14-beta.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 +30 -30
- package/dist/cjs/coingecko/Coingecko.d.ts +9 -1
- package/dist/cjs/coingecko/Coingecko.js +94 -46
- package/dist/cjs/coingecko/Coingecko.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/arbitrum-viem.d.ts +3 -0
- package/dist/cjs/gasPriceOracle/adapters/arbitrum-viem.js +21 -0
- package/dist/cjs/gasPriceOracle/adapters/arbitrum-viem.js.map +1 -0
- package/dist/cjs/gasPriceOracle/adapters/ethereum-viem.d.ts +4 -0
- package/dist/cjs/gasPriceOracle/adapters/ethereum-viem.js +26 -0
- package/dist/cjs/gasPriceOracle/adapters/ethereum-viem.js.map +1 -0
- package/dist/cjs/gasPriceOracle/adapters/polygon-viem.d.ts +3 -0
- package/dist/cjs/gasPriceOracle/adapters/polygon-viem.js +84 -0
- package/dist/cjs/gasPriceOracle/adapters/polygon-viem.js.map +1 -0
- package/dist/cjs/gasPriceOracle/oracle.d.ts +3 -1
- package/dist/cjs/gasPriceOracle/oracle.js +71 -4
- package/dist/cjs/gasPriceOracle/oracle.js.map +1 -1
- package/dist/cjs/gasPriceOracle/types.d.ts +3 -2
- package/dist/cjs/gasPriceOracle/util.d.ts +3 -3
- package/dist/cjs/gasPriceOracle/util.js +12 -1
- package/dist/cjs/gasPriceOracle/util.js.map +1 -1
- package/dist/cjs/providers/types.d.ts +3 -3
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +7 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +13 -8
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +8 -2
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +4 -2
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/cjs/utils/common.d.ts +6 -1
- package/dist/cjs/utils/common.js +21 -17
- package/dist/cjs/utils/common.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +30 -30
- package/dist/esm/coingecko/Coingecko.d.ts +9 -1
- package/dist/esm/coingecko/Coingecko.js +96 -46
- package/dist/esm/coingecko/Coingecko.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/arbitrum-viem.d.ts +3 -0
- package/dist/esm/gasPriceOracle/adapters/arbitrum-viem.js +20 -0
- package/dist/esm/gasPriceOracle/adapters/arbitrum-viem.js.map +1 -0
- package/dist/esm/gasPriceOracle/adapters/ethereum-viem.d.ts +4 -0
- package/dist/esm/gasPriceOracle/adapters/ethereum-viem.js +21 -0
- package/dist/esm/gasPriceOracle/adapters/ethereum-viem.js.map +1 -0
- package/dist/esm/gasPriceOracle/adapters/polygon-viem.d.ts +3 -0
- package/dist/esm/gasPriceOracle/adapters/polygon-viem.js +82 -0
- package/dist/esm/gasPriceOracle/adapters/polygon-viem.js.map +1 -0
- package/dist/esm/gasPriceOracle/oracle.d.ts +9 -1
- package/dist/esm/gasPriceOracle/oracle.js +82 -3
- package/dist/esm/gasPriceOracle/oracle.js.map +1 -1
- package/dist/esm/gasPriceOracle/types.d.ts +3 -2
- package/dist/esm/gasPriceOracle/util.d.ts +3 -3
- package/dist/esm/gasPriceOracle/util.js +9 -0
- package/dist/esm/gasPriceOracle/util.js.map +1 -1
- package/dist/esm/providers/types.d.ts +3 -3
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +12 -3
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +18 -10
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +8 -2
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +4 -2
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/esm/utils/common.d.ts +10 -3
- package/dist/esm/utils/common.js +25 -19
- package/dist/esm/utils/common.js.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +30 -30
- package/dist/types/coingecko/Coingecko.d.ts +9 -1
- package/dist/types/coingecko/Coingecko.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/adapters/arbitrum-viem.d.ts +4 -0
- package/dist/types/gasPriceOracle/adapters/arbitrum-viem.d.ts.map +1 -0
- package/dist/types/gasPriceOracle/adapters/ethereum-viem.d.ts +5 -0
- package/dist/types/gasPriceOracle/adapters/ethereum-viem.d.ts.map +1 -0
- package/dist/types/gasPriceOracle/adapters/polygon-viem.d.ts +4 -0
- package/dist/types/gasPriceOracle/adapters/polygon-viem.d.ts.map +1 -0
- package/dist/types/gasPriceOracle/oracle.d.ts +9 -1
- package/dist/types/gasPriceOracle/oracle.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/types.d.ts +3 -2
- package/dist/types/gasPriceOracle/types.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/util.d.ts +3 -3
- package/dist/types/gasPriceOracle/util.d.ts.map +1 -1
- package/dist/types/providers/types.d.ts +3 -3
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +12 -3
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +8 -2
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
- package/dist/types/utils/common.d.ts +10 -3
- package/dist/types/utils/common.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/coingecko/Coingecko.ts +94 -47
- package/src/gasPriceOracle/adapters/arbitrum-viem.ts +13 -0
- package/src/gasPriceOracle/adapters/ethereum-viem.ts +19 -0
- package/src/gasPriceOracle/adapters/polygon-viem.ts +86 -0
- package/src/gasPriceOracle/oracle.ts +69 -5
- package/src/gasPriceOracle/types.ts +4 -2
- package/src/gasPriceOracle/util.ts +12 -3
- package/src/relayFeeCalculator/chain-queries/baseQuery.ts +19 -7
- package/src/relayFeeCalculator/relayFeeCalculator.ts +15 -12
- package/src/utils/common.ts +15 -6
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { BigNumber } from "../../../utils";
|
|
2
2
|
export declare const BundleDataSS: import("superstruct").Struct<{
|
|
3
3
|
bundleDepositsV3: Record<string, Record<string, {
|
|
4
|
-
depositId: number;
|
|
5
|
-
originChainId: number;
|
|
6
4
|
blockNumber: number;
|
|
7
5
|
transactionIndex: number;
|
|
8
|
-
logIndex: number;
|
|
9
6
|
transactionHash: string;
|
|
7
|
+
logIndex: number;
|
|
10
8
|
message: string;
|
|
9
|
+
depositId: number;
|
|
10
|
+
originChainId: number;
|
|
11
11
|
inputToken: string;
|
|
12
12
|
inputAmount: BigNumber;
|
|
13
13
|
quoteTimestamp: number;
|
|
@@ -30,13 +30,13 @@ export declare const BundleDataSS: import("superstruct").Struct<{
|
|
|
30
30
|
}[]>>;
|
|
31
31
|
bundleFillsV3: Record<string, Record<string, {
|
|
32
32
|
fills: {
|
|
33
|
-
depositId: number;
|
|
34
|
-
originChainId: number;
|
|
35
33
|
blockNumber: number;
|
|
36
34
|
transactionIndex: number;
|
|
37
|
-
logIndex: number;
|
|
38
35
|
transactionHash: string;
|
|
36
|
+
logIndex: number;
|
|
39
37
|
message: string;
|
|
38
|
+
depositId: number;
|
|
39
|
+
originChainId: number;
|
|
40
40
|
inputToken: string;
|
|
41
41
|
inputAmount: BigNumber;
|
|
42
42
|
quoteTimestamp: number;
|
|
@@ -63,13 +63,13 @@ export declare const BundleDataSS: import("superstruct").Struct<{
|
|
|
63
63
|
totalRefundAmount: BigNumber;
|
|
64
64
|
}>>;
|
|
65
65
|
bundleSlowFillsV3: Record<string, Record<string, {
|
|
66
|
-
depositId: number;
|
|
67
|
-
originChainId: number;
|
|
68
66
|
blockNumber: number;
|
|
69
67
|
transactionIndex: number;
|
|
70
|
-
logIndex: number;
|
|
71
68
|
transactionHash: string;
|
|
69
|
+
logIndex: number;
|
|
72
70
|
message: string;
|
|
71
|
+
depositId: number;
|
|
72
|
+
originChainId: number;
|
|
73
73
|
inputToken: string;
|
|
74
74
|
inputAmount: BigNumber;
|
|
75
75
|
quoteTimestamp: number;
|
|
@@ -92,13 +92,13 @@ export declare const BundleDataSS: import("superstruct").Struct<{
|
|
|
92
92
|
relayerFeePct?: BigNumber | undefined;
|
|
93
93
|
}[]>>;
|
|
94
94
|
expiredDepositsToRefundV3: Record<string, Record<string, {
|
|
95
|
-
depositId: number;
|
|
96
|
-
originChainId: number;
|
|
97
95
|
blockNumber: number;
|
|
98
96
|
transactionIndex: number;
|
|
99
|
-
logIndex: number;
|
|
100
97
|
transactionHash: string;
|
|
98
|
+
logIndex: number;
|
|
101
99
|
message: string;
|
|
100
|
+
depositId: number;
|
|
101
|
+
originChainId: number;
|
|
102
102
|
inputToken: string;
|
|
103
103
|
inputAmount: BigNumber;
|
|
104
104
|
quoteTimestamp: number;
|
|
@@ -120,13 +120,13 @@ export declare const BundleDataSS: import("superstruct").Struct<{
|
|
|
120
120
|
relayerFeePct?: BigNumber | undefined;
|
|
121
121
|
}[]>>;
|
|
122
122
|
unexecutableSlowFills: Record<string, Record<string, {
|
|
123
|
-
depositId: number;
|
|
124
|
-
originChainId: number;
|
|
125
123
|
blockNumber: number;
|
|
126
124
|
transactionIndex: number;
|
|
127
|
-
logIndex: number;
|
|
128
125
|
transactionHash: string;
|
|
126
|
+
logIndex: number;
|
|
129
127
|
message: string;
|
|
128
|
+
depositId: number;
|
|
129
|
+
originChainId: number;
|
|
130
130
|
inputToken: string;
|
|
131
131
|
inputAmount: BigNumber;
|
|
132
132
|
quoteTimestamp: number;
|
|
@@ -152,13 +152,13 @@ export declare const BundleDataSS: import("superstruct").Struct<{
|
|
|
152
152
|
}, {
|
|
153
153
|
bundleBlockRanges: import("superstruct").Struct<number[][], import("superstruct").Struct<number[], import("superstruct").Struct<number, null>>>;
|
|
154
154
|
bundleDepositsV3: import("superstruct").Struct<Record<string, Record<string, {
|
|
155
|
-
depositId: number;
|
|
156
|
-
originChainId: number;
|
|
157
155
|
blockNumber: number;
|
|
158
156
|
transactionIndex: number;
|
|
159
|
-
logIndex: number;
|
|
160
157
|
transactionHash: string;
|
|
158
|
+
logIndex: number;
|
|
161
159
|
message: string;
|
|
160
|
+
depositId: number;
|
|
161
|
+
originChainId: number;
|
|
162
162
|
inputToken: string;
|
|
163
163
|
inputAmount: BigNumber;
|
|
164
164
|
quoteTimestamp: number;
|
|
@@ -180,13 +180,13 @@ export declare const BundleDataSS: import("superstruct").Struct<{
|
|
|
180
180
|
relayerFeePct?: BigNumber | undefined;
|
|
181
181
|
}[]>>, null>;
|
|
182
182
|
expiredDepositsToRefundV3: import("superstruct").Struct<Record<string, Record<string, {
|
|
183
|
-
depositId: number;
|
|
184
|
-
originChainId: number;
|
|
185
183
|
blockNumber: number;
|
|
186
184
|
transactionIndex: number;
|
|
187
|
-
logIndex: number;
|
|
188
185
|
transactionHash: string;
|
|
186
|
+
logIndex: number;
|
|
189
187
|
message: string;
|
|
188
|
+
depositId: number;
|
|
189
|
+
originChainId: number;
|
|
190
190
|
inputToken: string;
|
|
191
191
|
inputAmount: BigNumber;
|
|
192
192
|
quoteTimestamp: number;
|
|
@@ -208,13 +208,13 @@ export declare const BundleDataSS: import("superstruct").Struct<{
|
|
|
208
208
|
relayerFeePct?: BigNumber | undefined;
|
|
209
209
|
}[]>>, null>;
|
|
210
210
|
unexecutableSlowFills: import("superstruct").Struct<Record<string, Record<string, {
|
|
211
|
-
depositId: number;
|
|
212
|
-
originChainId: number;
|
|
213
211
|
blockNumber: number;
|
|
214
212
|
transactionIndex: number;
|
|
215
|
-
logIndex: number;
|
|
216
213
|
transactionHash: string;
|
|
214
|
+
logIndex: number;
|
|
217
215
|
message: string;
|
|
216
|
+
depositId: number;
|
|
217
|
+
originChainId: number;
|
|
218
218
|
inputToken: string;
|
|
219
219
|
inputAmount: BigNumber;
|
|
220
220
|
quoteTimestamp: number;
|
|
@@ -237,13 +237,13 @@ export declare const BundleDataSS: import("superstruct").Struct<{
|
|
|
237
237
|
relayerFeePct?: BigNumber | undefined;
|
|
238
238
|
}[]>>, null>;
|
|
239
239
|
bundleSlowFillsV3: import("superstruct").Struct<Record<string, Record<string, {
|
|
240
|
-
depositId: number;
|
|
241
|
-
originChainId: number;
|
|
242
240
|
blockNumber: number;
|
|
243
241
|
transactionIndex: number;
|
|
244
|
-
logIndex: number;
|
|
245
242
|
transactionHash: string;
|
|
243
|
+
logIndex: number;
|
|
246
244
|
message: string;
|
|
245
|
+
depositId: number;
|
|
246
|
+
originChainId: number;
|
|
247
247
|
inputToken: string;
|
|
248
248
|
inputAmount: BigNumber;
|
|
249
249
|
quoteTimestamp: number;
|
|
@@ -267,13 +267,13 @@ export declare const BundleDataSS: import("superstruct").Struct<{
|
|
|
267
267
|
}[]>>, null>;
|
|
268
268
|
bundleFillsV3: import("superstruct").Struct<Record<string, Record<string, {
|
|
269
269
|
fills: {
|
|
270
|
-
depositId: number;
|
|
271
|
-
originChainId: number;
|
|
272
270
|
blockNumber: number;
|
|
273
271
|
transactionIndex: number;
|
|
274
|
-
logIndex: number;
|
|
275
272
|
transactionHash: string;
|
|
273
|
+
logIndex: number;
|
|
276
274
|
message: string;
|
|
275
|
+
depositId: number;
|
|
276
|
+
originChainId: number;
|
|
277
277
|
inputToken: string;
|
|
278
278
|
inputAmount: BigNumber;
|
|
279
279
|
quoteTimestamp: number;
|
|
@@ -11,6 +11,10 @@ export type CoinGeckoPrice = {
|
|
|
11
11
|
timestamp: number;
|
|
12
12
|
price: number;
|
|
13
13
|
};
|
|
14
|
+
type CGTokenPrice = {
|
|
15
|
+
[currency: string]: number;
|
|
16
|
+
last_updated_at: number;
|
|
17
|
+
};
|
|
14
18
|
export declare class Coingecko {
|
|
15
19
|
private readonly host;
|
|
16
20
|
private readonly proHost;
|
|
@@ -29,13 +33,17 @@ export declare class Coingecko {
|
|
|
29
33
|
getHistoricContractPrices(contract: string, from: number, to: number, currency?: string): Promise<any>;
|
|
30
34
|
getContractHistoricDayPrice(contractAddress: string, date: string, currency?: string): Promise<number>;
|
|
31
35
|
getContractDetails(contract_address: string, platform_id?: string): Promise<any>;
|
|
32
|
-
getCurrentPriceByContract(
|
|
36
|
+
getCurrentPriceByContract(contractAddress: string, currency?: string, platform_id?: string): Promise<[string, number]>;
|
|
37
|
+
getCurrentPriceById(contractAddress: string, currency?: string, platform_id?: string): Promise<[string, number]>;
|
|
33
38
|
getContractPrices(addresses: Array<string>, currency?: string, platform_id?: string): Promise<CoinGeckoPrice[]>;
|
|
34
39
|
getPlatforms(): Promise<CoinGeckoAssetPlatform[]>;
|
|
35
40
|
call(path: string): Promise<any>;
|
|
36
41
|
protected getPriceCache(currency: string, platform_id: string): {
|
|
37
42
|
[addr: string]: CoinGeckoPrice;
|
|
38
43
|
};
|
|
44
|
+
protected getCachedAddressPrice(contractAddress: string, currency: string, platform_id: string): CoinGeckoPrice | undefined;
|
|
45
|
+
protected updatePriceCache(cgPrice: CGTokenPrice, contractAddress: string, currency: string, platform_id: string): void;
|
|
39
46
|
private _callBasic;
|
|
40
47
|
private _callPro;
|
|
41
48
|
}
|
|
49
|
+
export {};
|
|
@@ -94,39 +94,59 @@ var Coingecko = (function () {
|
|
|
94
94
|
if (platform_id === void 0) { platform_id = "ethereum"; }
|
|
95
95
|
return this.call("coins/".concat(platform_id, "/contract/").concat(contract_address.toLowerCase()));
|
|
96
96
|
};
|
|
97
|
-
Coingecko.prototype.getCurrentPriceByContract = function (
|
|
97
|
+
Coingecko.prototype.getCurrentPriceByContract = function (contractAddress, currency, platform_id) {
|
|
98
98
|
if (currency === void 0) { currency = "usd"; }
|
|
99
99
|
if (platform_id === void 0) { platform_id = "ethereum"; }
|
|
100
100
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
101
|
-
var priceCache,
|
|
101
|
+
var priceCache, tokenPrice;
|
|
102
102
|
return tslib_1.__generator(this, function (_a) {
|
|
103
103
|
switch (_a.label) {
|
|
104
104
|
case 0:
|
|
105
105
|
priceCache = this.getPriceCache(currency, platform_id);
|
|
106
|
-
|
|
107
|
-
tokenPrice
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
tokenPrice = this.getCachedAddressPrice(contractAddress, currency, platform_id);
|
|
107
|
+
if (!(tokenPrice === undefined)) return [3, 2];
|
|
108
|
+
return [4, this.getContractPrices([contractAddress], currency, platform_id)];
|
|
109
|
+
case 1:
|
|
110
|
+
_a.sent();
|
|
111
|
+
tokenPrice = priceCache[contractAddress];
|
|
112
|
+
_a.label = 2;
|
|
113
|
+
case 2:
|
|
114
|
+
(0, assert_1.default)(tokenPrice !== undefined);
|
|
115
|
+
return [2, [tokenPrice.timestamp.toString(), tokenPrice.price]];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
Coingecko.prototype.getCurrentPriceById = function (contractAddress, currency, platform_id) {
|
|
121
|
+
if (currency === void 0) { currency = "usd"; }
|
|
122
|
+
if (platform_id === void 0) { platform_id = "ethereum"; }
|
|
123
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
124
|
+
var priceCache, tokenPrice, coingeckoId, result, cgPrice, errMsg;
|
|
125
|
+
return tslib_1.__generator(this, function (_a) {
|
|
126
|
+
switch (_a.label) {
|
|
127
|
+
case 0:
|
|
128
|
+
priceCache = this.getPriceCache(currency, platform_id);
|
|
129
|
+
tokenPrice = this.getCachedAddressPrice(contractAddress, currency, platform_id);
|
|
130
|
+
if (!(tokenPrice === undefined)) return [3, 2];
|
|
131
|
+
coingeckoId = (0, utils_1.getCoingeckoTokenIdByAddress)(contractAddress);
|
|
132
|
+
return [4, this.call("simple/price?ids=".concat(coingeckoId, "&vs_currencies=").concat(currency, "&include_last_updated_at=true"))];
|
|
133
|
+
case 1:
|
|
134
|
+
result = _a.sent();
|
|
135
|
+
cgPrice = result === null || result === void 0 ? void 0 : result[coingeckoId];
|
|
136
|
+
if (cgPrice === undefined || !(cgPrice === null || cgPrice === void 0 ? void 0 : cgPrice[currency])) {
|
|
137
|
+
errMsg = "No price found for ".concat(coingeckoId);
|
|
110
138
|
this.logger.debug({
|
|
111
|
-
at: "Coingecko#
|
|
112
|
-
message:
|
|
113
|
-
maxPriceAge: this.maxPriceAge,
|
|
114
|
-
tokenPrice: tokenPrice,
|
|
139
|
+
at: "Coingecko#getCurrentPriceById",
|
|
140
|
+
message: errMsg,
|
|
115
141
|
});
|
|
142
|
+
throw new Error(errMsg);
|
|
116
143
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return [3, 3];
|
|
144
|
+
else {
|
|
145
|
+
this.updatePriceCache(cgPrice, contractAddress, currency, platform_id);
|
|
146
|
+
}
|
|
147
|
+
_a.label = 2;
|
|
122
148
|
case 2:
|
|
123
|
-
|
|
124
|
-
at: "Coingecko#getCurrentPriceByContract",
|
|
125
|
-
message: "Cache hit on token ".concat(contract_address, " (age ").concat(now - tokenPrice.timestamp, " S)."),
|
|
126
|
-
price: tokenPrice,
|
|
127
|
-
});
|
|
128
|
-
_a.label = 3;
|
|
129
|
-
case 3:
|
|
149
|
+
tokenPrice = priceCache[contractAddress];
|
|
130
150
|
(0, assert_1.default)(tokenPrice !== undefined);
|
|
131
151
|
return [2, [tokenPrice.timestamp.toString(), tokenPrice.price]];
|
|
132
152
|
}
|
|
@@ -137,7 +157,7 @@ var Coingecko = (function () {
|
|
|
137
157
|
if (currency === void 0) { currency = "usd"; }
|
|
138
158
|
if (platform_id === void 0) { platform_id = "ethereum"; }
|
|
139
159
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
140
|
-
var priceCache, contract_addresses, result, err_1, errMsg
|
|
160
|
+
var priceCache, contract_addresses, result, err_1, errMsg;
|
|
141
161
|
var _this = this;
|
|
142
162
|
return tslib_1.__generator(this, function (_a) {
|
|
143
163
|
switch (_a.label) {
|
|
@@ -167,13 +187,12 @@ var Coingecko = (function () {
|
|
|
167
187
|
err_1 = _a.sent();
|
|
168
188
|
errMsg = "Failed to retrieve ".concat(platform_id, "/").concat(currency, " prices (").concat(err_1, ")");
|
|
169
189
|
this.logger.debug({
|
|
170
|
-
at: "Coingecko#
|
|
190
|
+
at: "Coingecko#getContractPrices",
|
|
171
191
|
message: errMsg,
|
|
172
192
|
tokens: contract_addresses,
|
|
173
193
|
});
|
|
174
194
|
throw new Error(errMsg);
|
|
175
195
|
case 4:
|
|
176
|
-
updated = [];
|
|
177
196
|
contract_addresses.forEach(function (addr) {
|
|
178
197
|
var cgPrice = result[addr.toLowerCase()];
|
|
179
198
|
if (cgPrice === undefined) {
|
|
@@ -182,29 +201,10 @@ var Coingecko = (function () {
|
|
|
182
201
|
message: "Token ".concat(addr, " not included in CoinGecko response."),
|
|
183
202
|
});
|
|
184
203
|
}
|
|
185
|
-
else
|
|
186
|
-
|
|
187
|
-
address: addr,
|
|
188
|
-
price: cgPrice[currency],
|
|
189
|
-
timestamp: cgPrice.last_updated_at,
|
|
190
|
-
};
|
|
191
|
-
updated.push(addr);
|
|
192
|
-
}
|
|
193
|
-
else if (cgPrice.last_updated_at === priceCache[addr].timestamp) {
|
|
194
|
-
_this.logger.debug({
|
|
195
|
-
at: "Coingecko#getContractPrices",
|
|
196
|
-
message: "No new price available for token ".concat(addr, "."),
|
|
197
|
-
token: cgPrice,
|
|
198
|
-
});
|
|
204
|
+
else {
|
|
205
|
+
_this.updatePriceCache(cgPrice, addr, currency, platform_id);
|
|
199
206
|
}
|
|
200
207
|
});
|
|
201
|
-
if (updated.length > 0) {
|
|
202
|
-
this.logger.debug({
|
|
203
|
-
at: "Coingecko#updatePriceCache",
|
|
204
|
-
message: "Updated ".concat(platform_id, "/").concat(currency, " token price cache."),
|
|
205
|
-
tokens: updated,
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
208
|
return [2, addresses.map(function (addr) { return priceCache[addr]; })];
|
|
209
209
|
}
|
|
210
210
|
});
|
|
@@ -250,6 +250,54 @@ var Coingecko = (function () {
|
|
|
250
250
|
this.prices[platform_id][currency] = {};
|
|
251
251
|
return this.prices[platform_id][currency];
|
|
252
252
|
};
|
|
253
|
+
Coingecko.prototype.getCachedAddressPrice = function (contractAddress, currency, platform_id) {
|
|
254
|
+
var priceCache = this.getPriceCache(currency, platform_id);
|
|
255
|
+
var now = msToS(Date.now());
|
|
256
|
+
var tokenPrice = priceCache[contractAddress];
|
|
257
|
+
if (tokenPrice === undefined || tokenPrice.timestamp + this.maxPriceAge <= now) {
|
|
258
|
+
if (this.maxPriceAge > 0) {
|
|
259
|
+
this.logger.debug({
|
|
260
|
+
at: "Coingecko#getCachedAddressPrice",
|
|
261
|
+
message: "Cache miss on ".concat(platform_id, "/").concat(currency, " for ").concat(contractAddress),
|
|
262
|
+
maxPriceAge: this.maxPriceAge,
|
|
263
|
+
tokenPrice: tokenPrice,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
this.logger.debug({
|
|
270
|
+
at: "Coingecko#getCachedAddressPrice",
|
|
271
|
+
message: "Cache hit on token ".concat(contractAddress, " (age ").concat(now - tokenPrice.timestamp, " S)."),
|
|
272
|
+
price: tokenPrice,
|
|
273
|
+
});
|
|
274
|
+
return tokenPrice;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
Coingecko.prototype.updatePriceCache = function (cgPrice, contractAddress, currency, platform_id) {
|
|
278
|
+
var priceCache = this.getPriceCache(currency, platform_id);
|
|
279
|
+
if (priceCache[contractAddress] === undefined) {
|
|
280
|
+
priceCache[contractAddress] = { address: contractAddress, price: 0, timestamp: 0 };
|
|
281
|
+
}
|
|
282
|
+
if (cgPrice.last_updated_at > priceCache[contractAddress].timestamp) {
|
|
283
|
+
priceCache[contractAddress] = {
|
|
284
|
+
address: contractAddress,
|
|
285
|
+
price: cgPrice[currency],
|
|
286
|
+
timestamp: cgPrice.last_updated_at,
|
|
287
|
+
};
|
|
288
|
+
this.logger.debug({
|
|
289
|
+
at: "Coingecko#updatePriceCache",
|
|
290
|
+
message: "Updated ".concat(platform_id, "/").concat(currency, "/").concat(contractAddress, " token price cache."),
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
this.logger.debug({
|
|
295
|
+
at: "Coingecko#updatePriceCache",
|
|
296
|
+
message: "No new price available for token ".concat(contractAddress, "."),
|
|
297
|
+
token: cgPrice,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
};
|
|
253
301
|
Coingecko.prototype._callBasic = function (path, timeout) {
|
|
254
302
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
255
303
|
var url, result, err_3, msg;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Coingecko.js","sourceRoot":"","sources":["../../../src/coingecko/Coingecko.ts"],"names":[],"mappings":";;;;AAAA,wDAA0C;AAC1C,0DAA4B;AAC5B,kEAA6B;AAC7B,kCAA+D;AAG/D,SAAgB,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;AAC/B,CAAC;AAFD,sBAEC;
|
|
1
|
+
{"version":3,"file":"Coingecko.js","sourceRoot":"","sources":["../../../src/coingecko/Coingecko.ts"],"names":[],"mappings":";;;;AAAA,wDAA0C;AAC1C,0DAA4B;AAC5B,kEAA6B;AAC7B,kCAA+D;AAG/D,SAAgB,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;AAC/B,CAAC;AAFD,sBAEC;AA6BD;IAkCE,mBACmB,IAAY,EACZ,OAAe,EACf,MAAc,EACd,MAAe;QAHf,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAQ;QACf,WAAM,GAAN,MAAM,CAA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AAG,UAAG,IAAI,CAAC,OAAO,cAAI,IAAI,CAAE,CAAC;;;;wBAIrB,WAAM,IAAA,eAAK,EAAC,GAAG,EAAE,EAAE,MAAM,EAAE,EAAE,gBAAgB,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAA;;wBAAxE,MAAM,GAAG,SAA+D;wBAC9E,WAAO,MAAM,CAAC,IAAI,EAAC;;;wBAEb,GAAG,GAAG,IAAA,oBAAG,EAAC,KAAG,EAAE,qBAAqB,EAAE,IAAA,oBAAG,EAAC,KAAG,EAAE,qBAAqB,EAAG,KAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;wBAC1G,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;;;;;KAExB;IACH,gBAAC;AAAD,CAAC,AAxTD,IAwTC;AAxTY,8BAAS"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eip1559 = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var MAX_PRIORITY_FEE_PER_GAS = BigInt(1);
|
|
6
|
+
function eip1559(provider, _chainId) {
|
|
7
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
8
|
+
var _a, _maxFeePerGas, maxPriorityFeePerGas, maxFeePerGas;
|
|
9
|
+
return tslib_1.__generator(this, function (_b) {
|
|
10
|
+
switch (_b.label) {
|
|
11
|
+
case 0: return [4, provider.estimateFeesPerGas()];
|
|
12
|
+
case 1:
|
|
13
|
+
_a = _b.sent(), _maxFeePerGas = _a.maxFeePerGas, maxPriorityFeePerGas = _a.maxPriorityFeePerGas;
|
|
14
|
+
maxFeePerGas = BigInt(_maxFeePerGas) - maxPriorityFeePerGas + MAX_PRIORITY_FEE_PER_GAS;
|
|
15
|
+
return [2, { maxFeePerGas: maxFeePerGas, maxPriorityFeePerGas: MAX_PRIORITY_FEE_PER_GAS }];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
exports.eip1559 = eip1559;
|
|
21
|
+
//# sourceMappingURL=arbitrum-viem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arbitrum-viem.js","sourceRoot":"","sources":["../../../../src/gasPriceOracle/adapters/arbitrum-viem.ts"],"names":[],"mappings":";;;;AAGA,IAAM,wBAAwB,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAK3C,SAAsB,OAAO,CAAC,QAAsB,EAAE,QAAgB;;;;;wBACN,WAAM,QAAQ,CAAC,kBAAkB,EAAE,EAAA;;oBAA3F,KAAwD,SAAmC,EAA3E,aAAa,kBAAA,EAAE,oBAAoB,0BAAA;oBACnD,YAAY,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,oBAAoB,GAAG,wBAAwB,CAAC;oBAC7F,WAAO,EAAE,YAAY,cAAA,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,EAAC;;;;CACzE;AAJD,0BAIC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PublicClient } from "viem";
|
|
2
|
+
import { InternalGasPriceEstimate } from "../types";
|
|
3
|
+
export declare function eip1559(provider: PublicClient, _chainId: number): Promise<InternalGasPriceEstimate>;
|
|
4
|
+
export declare function legacy(provider: PublicClient, _chainId: number, _test?: number): Promise<InternalGasPriceEstimate>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.legacy = exports.eip1559 = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
function eip1559(provider, _chainId) {
|
|
6
|
+
return provider.estimateFeesPerGas();
|
|
7
|
+
}
|
|
8
|
+
exports.eip1559 = eip1559;
|
|
9
|
+
function legacy(provider, _chainId, _test) {
|
|
10
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
11
|
+
var gasPrice;
|
|
12
|
+
return tslib_1.__generator(this, function (_a) {
|
|
13
|
+
switch (_a.label) {
|
|
14
|
+
case 0: return [4, provider.getGasPrice()];
|
|
15
|
+
case 1:
|
|
16
|
+
gasPrice = _a.sent();
|
|
17
|
+
return [2, {
|
|
18
|
+
maxFeePerGas: gasPrice,
|
|
19
|
+
maxPriorityFeePerGas: BigInt(0),
|
|
20
|
+
}];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.legacy = legacy;
|
|
26
|
+
//# sourceMappingURL=ethereum-viem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ethereum-viem.js","sourceRoot":"","sources":["../../../../src/gasPriceOracle/adapters/ethereum-viem.ts"],"names":[],"mappings":";;;;AAGA,SAAgB,OAAO,CAAC,QAAsB,EAAE,QAAgB;IAC9D,OAAO,QAAQ,CAAC,kBAAkB,EAAE,CAAC;AACvC,CAAC;AAFD,0BAEC;AAED,SAAsB,MAAM,CAC1B,QAAsB,EACtB,QAAgB,EAChB,KAAc;;;;;wBAEG,WAAM,QAAQ,CAAC,WAAW,EAAE,EAAA;;oBAAvC,QAAQ,GAAG,SAA4B;oBAE7C,WAAO;4BACL,YAAY,EAAE,QAAQ;4BACtB,oBAAoB,EAAE,MAAM,CAAC,CAAC,CAAC;yBAChC,EAAC;;;;CACH;AAXD,wBAWC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gasStation = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var baseAdapter_1 = require("../../priceClient/adapters/baseAdapter");
|
|
6
|
+
var utils_1 = require("../../utils");
|
|
7
|
+
var constants_1 = require("../../constants");
|
|
8
|
+
var util_1 = require("../util");
|
|
9
|
+
var ethereum_viem_1 = require("./ethereum-viem");
|
|
10
|
+
var POLYGON = constants_1.CHAIN_IDs.POLYGON;
|
|
11
|
+
var GWEI = BigInt(1000000000);
|
|
12
|
+
var PolygonGasStation = (function (_super) {
|
|
13
|
+
tslib_1.__extends(PolygonGasStation, _super);
|
|
14
|
+
function PolygonGasStation(_a) {
|
|
15
|
+
var _this = this;
|
|
16
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.chainId, chainId = _c === void 0 ? POLYGON : _c, host = _b.host, _d = _b.timeout, timeout = _d === void 0 ? 1500 : _d, _e = _b.retries, retries = _e === void 0 ? 1 : _e;
|
|
17
|
+
host = (host !== null && host !== void 0 ? host : chainId === POLYGON) ? "gasstation.polygon.technology" : "gasstation-testnet.polygon.technology";
|
|
18
|
+
_this = _super.call(this, "Polygon Gas Station", host, { timeout: timeout, retries: retries }) || this;
|
|
19
|
+
_this.chainId = chainId;
|
|
20
|
+
return _this;
|
|
21
|
+
}
|
|
22
|
+
PolygonGasStation.prototype.getFeeData = function (strategy) {
|
|
23
|
+
if (strategy === void 0) { strategy = "fast"; }
|
|
24
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
25
|
+
var gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas;
|
|
26
|
+
return tslib_1.__generator(this, function (_a) {
|
|
27
|
+
switch (_a.label) {
|
|
28
|
+
case 0: return [4, this.query("v2", {})];
|
|
29
|
+
case 1:
|
|
30
|
+
gas = _a.sent();
|
|
31
|
+
gasPrice = gas === null || gas === void 0 ? void 0 : gas[strategy];
|
|
32
|
+
if (!this.isPolygon1559GasPrice(gasPrice)) {
|
|
33
|
+
(0, util_1.gasPriceError)("getFeeData()", this.chainId, gasPrice);
|
|
34
|
+
}
|
|
35
|
+
maxPriorityFeePerGas = BigInt(gasPrice.maxPriorityFee) * GWEI;
|
|
36
|
+
maxFeePerGas = BigInt(gasPrice.maxFee) * GWEI;
|
|
37
|
+
return [2, { maxPriorityFeePerGas: maxPriorityFeePerGas, maxFeePerGas: maxFeePerGas }];
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
PolygonGasStation.prototype.isPolygon1559GasPrice = function (gasPrice) {
|
|
43
|
+
if (!(0, utils_1.isDefined)(gasPrice)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
var _gasPrice = gasPrice;
|
|
47
|
+
return [_gasPrice.maxPriorityFee, _gasPrice.maxFee].every(function (field) { return ["number", "string"].includes(typeof field); });
|
|
48
|
+
};
|
|
49
|
+
return PolygonGasStation;
|
|
50
|
+
}(baseAdapter_1.BaseHTTPAdapter));
|
|
51
|
+
function gasStation(provider, chainId) {
|
|
52
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
53
|
+
var gasStation, maxPriorityFeePerGas, maxFeePerGas, err_1, minPriorityFee, priorityDelta;
|
|
54
|
+
var _a, _b;
|
|
55
|
+
return tslib_1.__generator(this, function (_c) {
|
|
56
|
+
switch (_c.label) {
|
|
57
|
+
case 0:
|
|
58
|
+
gasStation = new PolygonGasStation({ chainId: chainId, timeout: 2000, retries: 0 });
|
|
59
|
+
_c.label = 1;
|
|
60
|
+
case 1:
|
|
61
|
+
_c.trys.push([1, 3, , 5]);
|
|
62
|
+
return [4, gasStation.getFeeData()];
|
|
63
|
+
case 2:
|
|
64
|
+
(_a = _c.sent(), maxPriorityFeePerGas = _a.maxPriorityFeePerGas, maxFeePerGas = _a.maxFeePerGas);
|
|
65
|
+
return [3, 5];
|
|
66
|
+
case 3:
|
|
67
|
+
err_1 = _c.sent();
|
|
68
|
+
return [4, (0, ethereum_viem_1.eip1559)(provider, chainId)];
|
|
69
|
+
case 4:
|
|
70
|
+
(_b = _c.sent(), maxPriorityFeePerGas = _b.maxPriorityFeePerGas, maxFeePerGas = _b.maxFeePerGas);
|
|
71
|
+
minPriorityFee = BigInt(30) * GWEI;
|
|
72
|
+
if (minPriorityFee > maxPriorityFeePerGas) {
|
|
73
|
+
priorityDelta = minPriorityFee - maxPriorityFeePerGas;
|
|
74
|
+
maxPriorityFeePerGas = minPriorityFee;
|
|
75
|
+
maxFeePerGas = maxFeePerGas + priorityDelta;
|
|
76
|
+
}
|
|
77
|
+
return [3, 5];
|
|
78
|
+
case 5: return [2, { maxPriorityFeePerGas: maxPriorityFeePerGas, maxFeePerGas: maxFeePerGas }];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
exports.gasStation = gasStation;
|
|
84
|
+
//# sourceMappingURL=polygon-viem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polygon-viem.js","sourceRoot":"","sources":["../../../../src/gasPriceOracle/adapters/polygon-viem.ts"],"names":[],"mappings":";;;;AACA,sEAA8F;AAC9F,qCAAwC;AACxC,6CAA4C;AAE5C,gCAAwC;AACxC,iDAA0C;AAqBlC,IAAA,OAAO,GAAK,qBAAS,QAAd,CAAe;AAE9B,IAAM,IAAI,GAAG,MAAM,CAAC,UAAa,CAAC,CAAC;AACnC;IAAgC,6CAAe;IAG7C,2BAAY,EAA6E;QAAzF,iBAKC;YALW,qBAA2E,EAAE,KAAA,EAA3E,eAAiB,EAAjB,OAAO,mBAAG,OAAO,KAAA,EAAE,IAAI,UAAA,EAAE,eAAc,EAAd,OAAO,mBAAG,IAAI,KAAA,EAAE,eAAW,EAAX,OAAO,mBAAG,CAAC,KAAA;QAChE,IAAI,GAAG,CAAA,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,OAAO,KAAK,OAAO,EAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,uCAAuC,CAAC;gBAE/G,kBAAM,qBAAqB,EAAE,IAAI,EAAE,EAAE,OAAO,SAAA,EAAE,OAAO,SAAA,EAAE,CAAC;QACxD,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;;IACzB,CAAC;IAEK,sCAAU,GAAhB,UAAiB,QAAkD;QAAlD,yBAAA,EAAA,iBAAkD;;;;;4BACrD,WAAM,IAAI,CAAC,KAAK,CAAC,I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E,YAAY,kBAAA,CAAmC,CAAC;;;;oBAG/B,WAAM,IAAA,uBAAO,EAAC,QAAQ,EAAE,OAAO,CAAC,EAAA;;oBAA1E,CAAC,KAAyC,SAAgC,EAAvE,oBAAoB,0BAAA,EAAE,YAAY,kBAAA,CAAsC,CAAC;oBAItE,cAAc,GAAG,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;oBACzC,IAAI,cAAc,GAAG,oBAAoB,EAAE;wBACnC,aAAa,GAAG,cAAc,GAAG,oBAAoB,CAAC;wBAC5D,oBAAoB,GAAG,cAAc,CAAC;wBACtC,YAAY,GAAG,YAAY,GAAG,aAAa,CAAC;qBAC7C;;wBAGH,WAAO,EAAE,oBAAoB,sBAAA,EAAE,YAAY,cAAA,EAAE,EAAC;;;;CAC/C;AArBD,gCAqBC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Transport } from "viem";
|
|
1
2
|
import { providers } from "ethers";
|
|
2
3
|
import { GasPriceEstimate } from "./types";
|
|
3
|
-
export declare function getGasPriceEstimate(provider: providers.Provider, chainId?: number, legacyFallback?: boolean): Promise<GasPriceEstimate>;
|
|
4
|
+
export declare function getGasPriceEstimate(provider: providers.Provider, chainId?: number, transport?: Transport, legacyFallback?: boolean): Promise<GasPriceEstimate>;
|
|
5
|
+
export declare function getViemGasPriceEstimate(providerOrChainId: providers.Provider | number, transport?: Transport): Promise<GasPriceEstimate>;
|