@gearbox-protocol/sdk 3.0.0-vfour.341 → 3.0.0-vfour.342
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/sdk/market/oracle/PriceOracleBaseContract.js +27 -4
- package/dist/cjs/sdk/utils/AddressMap.js +6 -2
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +27 -4
- package/dist/esm/sdk/utils/AddressMap.js +6 -2
- package/dist/types/sdk/base/types.d.ts +1 -0
- package/dist/types/sdk/utils/AddressMap.d.ts +2 -2
- package/package.json +1 -1
|
@@ -21,6 +21,7 @@ __export(PriceOracleBaseContract_exports, {
|
|
|
21
21
|
PriceOracleBaseContract: () => PriceOracleBaseContract
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(PriceOracleBaseContract_exports);
|
|
24
|
+
var import_date_fns = require("date-fns");
|
|
24
25
|
var import_viem = require("viem");
|
|
25
26
|
var import_compressors = require("../../../abi/compressors.js");
|
|
26
27
|
var import_iUpdatablePriceFeed = require("../../../abi/iUpdatablePriceFeed.js");
|
|
@@ -52,6 +53,10 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
52
53
|
* Mapping Token => Price in underlying
|
|
53
54
|
*/
|
|
54
55
|
mainPrices = new import_utils.AddressMap(void 0, "mainPrices");
|
|
56
|
+
/**
|
|
57
|
+
* Same, but with details
|
|
58
|
+
*/
|
|
59
|
+
#mainPrices = new import_utils.AddressMap();
|
|
55
60
|
/**
|
|
56
61
|
* Mapping Token => Price in underlying
|
|
57
62
|
*/
|
|
@@ -59,6 +64,10 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
59
64
|
void 0,
|
|
60
65
|
"reservePrices"
|
|
61
66
|
);
|
|
67
|
+
/**
|
|
68
|
+
* Same, but with debug details
|
|
69
|
+
*/
|
|
70
|
+
#reservePrices = new import_utils.AddressMap();
|
|
62
71
|
#priceFeedTree = [];
|
|
63
72
|
constructor(sdk, args, data, underlying) {
|
|
64
73
|
super(sdk, args);
|
|
@@ -244,6 +253,7 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
244
253
|
`answer not found for reserve price feed ${this.labelAddress(priceFeed)}`
|
|
245
254
|
);
|
|
246
255
|
}
|
|
256
|
+
this.#reservePrices.upsert(token, node?.answer);
|
|
247
257
|
} else {
|
|
248
258
|
this.mainPriceFeeds.upsert(token, ref);
|
|
249
259
|
if (price !== void 0) {
|
|
@@ -255,6 +265,7 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
255
265
|
`answer not found for main price feed ${this.labelAddress(priceFeed)}`
|
|
256
266
|
);
|
|
257
267
|
}
|
|
268
|
+
this.#mainPrices.upsert(token, node?.answer);
|
|
258
269
|
}
|
|
259
270
|
this.#labelPriceFeed(priceFeed, reserve ? "Reserve" : "Main", token);
|
|
260
271
|
});
|
|
@@ -304,15 +315,15 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
304
315
|
this.reservePriceFeeds.entries().map(([token, v]) => [this.labelAddress(token), v.stateHuman(raw)])
|
|
305
316
|
),
|
|
306
317
|
mainPrices: Object.fromEntries(
|
|
307
|
-
this
|
|
318
|
+
this.#mainPrices.entries().map(([token, answer]) => [
|
|
308
319
|
this.labelAddress(token),
|
|
309
|
-
(
|
|
320
|
+
formatAnswer(answer, raw)
|
|
310
321
|
])
|
|
311
322
|
),
|
|
312
323
|
reservePrices: Object.fromEntries(
|
|
313
|
-
this
|
|
324
|
+
this.#reservePrices.entries().map(([token, answer]) => [
|
|
314
325
|
this.labelAddress(token),
|
|
315
|
-
(
|
|
326
|
+
formatAnswer(answer, raw)
|
|
316
327
|
])
|
|
317
328
|
)
|
|
318
329
|
};
|
|
@@ -321,6 +332,18 @@ class PriceOracleBaseContract extends import_base.BaseContract {
|
|
|
321
332
|
return this.#priceFeedTree;
|
|
322
333
|
}
|
|
323
334
|
}
|
|
335
|
+
function formatAnswer({ price, success, updatedAt }, raw = true) {
|
|
336
|
+
if (!success) {
|
|
337
|
+
return "failed";
|
|
338
|
+
}
|
|
339
|
+
let priceS = (0, import_utils.formatBN)(price, 8);
|
|
340
|
+
let updated = (0, import_date_fns.format)(new Date(Number(updatedAt) * 1e3), "PPppp");
|
|
341
|
+
if (raw) {
|
|
342
|
+
priceS = `${priceS} (${price.toString(10)})`;
|
|
343
|
+
updated = `${updated} (${updatedAt.toString(10)})`;
|
|
344
|
+
}
|
|
345
|
+
return `${priceS} at ${updated}`;
|
|
346
|
+
}
|
|
324
347
|
// Annotate the CommonJS export names for ESM import in node:
|
|
325
348
|
0 && (module.exports = {
|
|
326
349
|
PriceOracleBaseContract
|
|
@@ -37,7 +37,7 @@ class AddressMap {
|
|
|
37
37
|
this.#name = name;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
* Adds or updates value
|
|
40
|
+
* Adds or updates value, undefined removes value
|
|
41
41
|
* @param address
|
|
42
42
|
* @param value
|
|
43
43
|
*/
|
|
@@ -46,7 +46,11 @@ class AddressMap {
|
|
|
46
46
|
throw new Error(`AddressMap ${this.#name} is frozen`);
|
|
47
47
|
}
|
|
48
48
|
const key = (0, import_viem.getAddress)(address);
|
|
49
|
-
|
|
49
|
+
if (value === void 0) {
|
|
50
|
+
this.#map.delete(key);
|
|
51
|
+
} else {
|
|
52
|
+
this.#map.set(key, value);
|
|
53
|
+
}
|
|
50
54
|
}
|
|
51
55
|
/**
|
|
52
56
|
* Adds value, throws if this address is already used
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { format } from "date-fns";
|
|
1
2
|
import { decodeFunctionData, stringToHex } from "viem";
|
|
2
3
|
import { iPriceFeedCompressorAbi } from "../../../abi/compressors.js";
|
|
3
4
|
import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
|
|
@@ -29,6 +30,10 @@ class PriceOracleBaseContract extends BaseContract {
|
|
|
29
30
|
* Mapping Token => Price in underlying
|
|
30
31
|
*/
|
|
31
32
|
mainPrices = new AddressMap(void 0, "mainPrices");
|
|
33
|
+
/**
|
|
34
|
+
* Same, but with details
|
|
35
|
+
*/
|
|
36
|
+
#mainPrices = new AddressMap();
|
|
32
37
|
/**
|
|
33
38
|
* Mapping Token => Price in underlying
|
|
34
39
|
*/
|
|
@@ -36,6 +41,10 @@ class PriceOracleBaseContract extends BaseContract {
|
|
|
36
41
|
void 0,
|
|
37
42
|
"reservePrices"
|
|
38
43
|
);
|
|
44
|
+
/**
|
|
45
|
+
* Same, but with debug details
|
|
46
|
+
*/
|
|
47
|
+
#reservePrices = new AddressMap();
|
|
39
48
|
#priceFeedTree = [];
|
|
40
49
|
constructor(sdk, args, data, underlying) {
|
|
41
50
|
super(sdk, args);
|
|
@@ -221,6 +230,7 @@ class PriceOracleBaseContract extends BaseContract {
|
|
|
221
230
|
`answer not found for reserve price feed ${this.labelAddress(priceFeed)}`
|
|
222
231
|
);
|
|
223
232
|
}
|
|
233
|
+
this.#reservePrices.upsert(token, node?.answer);
|
|
224
234
|
} else {
|
|
225
235
|
this.mainPriceFeeds.upsert(token, ref);
|
|
226
236
|
if (price !== void 0) {
|
|
@@ -232,6 +242,7 @@ class PriceOracleBaseContract extends BaseContract {
|
|
|
232
242
|
`answer not found for main price feed ${this.labelAddress(priceFeed)}`
|
|
233
243
|
);
|
|
234
244
|
}
|
|
245
|
+
this.#mainPrices.upsert(token, node?.answer);
|
|
235
246
|
}
|
|
236
247
|
this.#labelPriceFeed(priceFeed, reserve ? "Reserve" : "Main", token);
|
|
237
248
|
});
|
|
@@ -281,15 +292,15 @@ class PriceOracleBaseContract extends BaseContract {
|
|
|
281
292
|
this.reservePriceFeeds.entries().map(([token, v]) => [this.labelAddress(token), v.stateHuman(raw)])
|
|
282
293
|
),
|
|
283
294
|
mainPrices: Object.fromEntries(
|
|
284
|
-
this
|
|
295
|
+
this.#mainPrices.entries().map(([token, answer]) => [
|
|
285
296
|
this.labelAddress(token),
|
|
286
|
-
|
|
297
|
+
formatAnswer(answer, raw)
|
|
287
298
|
])
|
|
288
299
|
),
|
|
289
300
|
reservePrices: Object.fromEntries(
|
|
290
|
-
this
|
|
301
|
+
this.#reservePrices.entries().map(([token, answer]) => [
|
|
291
302
|
this.labelAddress(token),
|
|
292
|
-
|
|
303
|
+
formatAnswer(answer, raw)
|
|
293
304
|
])
|
|
294
305
|
)
|
|
295
306
|
};
|
|
@@ -298,6 +309,18 @@ class PriceOracleBaseContract extends BaseContract {
|
|
|
298
309
|
return this.#priceFeedTree;
|
|
299
310
|
}
|
|
300
311
|
}
|
|
312
|
+
function formatAnswer({ price, success, updatedAt }, raw = true) {
|
|
313
|
+
if (!success) {
|
|
314
|
+
return "failed";
|
|
315
|
+
}
|
|
316
|
+
let priceS = formatBN(price, 8);
|
|
317
|
+
let updated = format(new Date(Number(updatedAt) * 1e3), "PPppp");
|
|
318
|
+
if (raw) {
|
|
319
|
+
priceS = `${priceS} (${price.toString(10)})`;
|
|
320
|
+
updated = `${updated} (${updatedAt.toString(10)})`;
|
|
321
|
+
}
|
|
322
|
+
return `${priceS} at ${updated}`;
|
|
323
|
+
}
|
|
301
324
|
export {
|
|
302
325
|
PriceOracleBaseContract
|
|
303
326
|
};
|
|
@@ -14,7 +14,7 @@ class AddressMap {
|
|
|
14
14
|
this.#name = name;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* Adds or updates value
|
|
17
|
+
* Adds or updates value, undefined removes value
|
|
18
18
|
* @param address
|
|
19
19
|
* @param value
|
|
20
20
|
*/
|
|
@@ -23,7 +23,11 @@ class AddressMap {
|
|
|
23
23
|
throw new Error(`AddressMap ${this.#name} is frozen`);
|
|
24
24
|
}
|
|
25
25
|
const key = getAddress(address);
|
|
26
|
-
|
|
26
|
+
if (value === void 0) {
|
|
27
|
+
this.#map.delete(key);
|
|
28
|
+
} else {
|
|
29
|
+
this.#map.set(key, value);
|
|
30
|
+
}
|
|
27
31
|
}
|
|
28
32
|
/**
|
|
29
33
|
* Adds value, throws if this address is already used
|
|
@@ -30,6 +30,7 @@ export type RateKeeperData = MarketData["rateKeeper"];
|
|
|
30
30
|
export type PriceOracleData = MarketData["priceOracleData"];
|
|
31
31
|
export type PriceFeedMapEntry = Unarray<PriceOracleData["priceFeedMapping"]>;
|
|
32
32
|
export type PriceFeedTreeNode = Unarray<PriceOracleData["priceFeedStructure"]>;
|
|
33
|
+
export type PriceFeedAnswer = PriceFeedTreeNode["answer"];
|
|
33
34
|
export type CreditManagerDebtParams = Unarray<PoolData["creditManagerDebtParams"]>;
|
|
34
35
|
export declare enum VotingContractStatus {
|
|
35
36
|
NOT_ALLOWED = 0,
|
|
@@ -3,11 +3,11 @@ export declare class AddressMap<T> {
|
|
|
3
3
|
#private;
|
|
4
4
|
constructor(entries?: Array<[string, T]>, name?: string);
|
|
5
5
|
/**
|
|
6
|
-
* Adds or updates value
|
|
6
|
+
* Adds or updates value, undefined removes value
|
|
7
7
|
* @param address
|
|
8
8
|
* @param value
|
|
9
9
|
*/
|
|
10
|
-
upsert(address: string, value: T): void;
|
|
10
|
+
upsert(address: string, value: T | undefined): void;
|
|
11
11
|
/**
|
|
12
12
|
* Adds value, throws if this address is already used
|
|
13
13
|
* @param address
|