@gearbox-protocol/sdk 8.1.6 → 8.2.0-next.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/plugins/degen-distributors/DegenDistributorsPlugin.js +3 -1
- package/dist/cjs/plugins/pools-history/Pools7DAgoPlugin.js +6 -1
- package/dist/cjs/sdk/GearboxSDK.js +20 -8
- package/dist/cjs/sdk/abi/oracles.js +141 -0
- package/dist/cjs/sdk/chain/chains.js +4 -4
- package/dist/cjs/sdk/market/pricefeeds/AbstractPriceFeed.js +2 -1
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +17 -23
- package/dist/cjs/sdk/market/pricefeeds/PythPriceFeed.js +9 -1
- package/dist/cjs/sdk/market/pricefeeds/RedstonePriceFeed.js +9 -7
- package/dist/cjs/sdk/market/pricefeeds/index.js +2 -0
- package/dist/cjs/sdk/market/pricefeeds/isUpdatablePriceFeed.js +30 -0
- package/dist/cjs/sdk/market/pricefeeds/updates/PriceUpdateTx.js +52 -0
- package/dist/cjs/sdk/market/pricefeeds/{RedstoneCache.js → updates/PriceUpdatesCache.js} +12 -12
- package/dist/cjs/sdk/market/pricefeeds/updates/PythUpdater.js +189 -0
- package/dist/cjs/sdk/market/pricefeeds/{RedstoneUpdater.js → updates/RedstoneUpdater.js} +21 -45
- package/dist/cjs/sdk/market/pricefeeds/updates/index.js +31 -0
- package/dist/cjs/sdk/market/pricefeeds/updates/types.js +16 -0
- package/dist/cjs/sdk/sdk-legacy/tokens/tokenData.js +1 -2
- package/dist/cjs/sdk/utils/retry.js +4 -2
- package/dist/cjs/sdk/utils/viem/cast.js +5 -2
- package/dist/cjs/sdk/utils/viem/simulateMulticall.js +3 -1
- package/dist/cjs/sdk/utils/viem/simulateWithPriceUpdates.js +2 -2
- package/dist/esm/plugins/degen-distributors/DegenDistributorsPlugin.js +3 -1
- package/dist/esm/plugins/pools-history/Pools7DAgoPlugin.js +6 -1
- package/dist/esm/sdk/GearboxSDK.js +20 -8
- package/dist/esm/sdk/abi/oracles.js +140 -0
- package/dist/esm/sdk/chain/chains.js +4 -4
- package/dist/esm/sdk/market/pricefeeds/AbstractPriceFeed.js +2 -1
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +18 -24
- package/dist/esm/sdk/market/pricefeeds/PythPriceFeed.js +9 -1
- package/dist/esm/sdk/market/pricefeeds/RedstonePriceFeed.js +8 -5
- package/dist/esm/sdk/market/pricefeeds/index.js +1 -0
- package/dist/esm/sdk/market/pricefeeds/isUpdatablePriceFeed.js +6 -0
- package/dist/esm/sdk/market/pricefeeds/updates/PriceUpdateTx.js +28 -0
- package/dist/esm/sdk/market/pricefeeds/{RedstoneCache.js → updates/PriceUpdatesCache.js} +8 -8
- package/dist/esm/sdk/market/pricefeeds/updates/PythUpdater.js +169 -0
- package/dist/esm/sdk/market/pricefeeds/{RedstoneUpdater.js → updates/RedstoneUpdater.js} +21 -44
- package/dist/esm/sdk/market/pricefeeds/updates/index.js +6 -0
- package/dist/esm/sdk/market/pricefeeds/updates/types.js +0 -0
- package/dist/esm/sdk/sdk-legacy/tokens/tokenData.js +1 -2
- package/dist/esm/sdk/utils/retry.js +4 -2
- package/dist/esm/sdk/utils/viem/cast.js +5 -2
- package/dist/esm/sdk/utils/viem/simulateMulticall.js +3 -1
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +2 -2
- package/dist/types/sdk/GearboxSDK.d.ts +5 -1
- package/dist/types/sdk/abi/oracles.d.ts +212 -0
- package/dist/types/sdk/chain/chains.d.ts +1 -1
- package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +2 -2
- package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +4 -4
- package/dist/types/sdk/market/pricefeeds/PythPriceFeed.d.ts +218 -4
- package/dist/types/sdk/market/pricefeeds/RedstonePriceFeed.d.ts +4 -4
- package/dist/types/sdk/market/pricefeeds/index.d.ts +1 -0
- package/dist/types/sdk/market/pricefeeds/isUpdatablePriceFeed.d.ts +2 -0
- package/dist/types/sdk/market/pricefeeds/types.d.ts +5 -2
- package/dist/types/sdk/market/pricefeeds/updates/PriceUpdateTx.d.ts +10 -0
- package/dist/types/sdk/market/pricefeeds/updates/PriceUpdatesCache.d.ts +17 -0
- package/dist/types/sdk/market/pricefeeds/updates/PythUpdater.d.ts +40 -0
- package/dist/types/sdk/market/pricefeeds/{RedstoneUpdater.d.ts → updates/RedstoneUpdater.d.ts} +11 -18
- package/dist/types/sdk/market/pricefeeds/updates/RedstoneUpdater.test.d.ts +1 -0
- package/dist/types/sdk/market/pricefeeds/updates/index.d.ts +3 -0
- package/dist/types/sdk/market/pricefeeds/updates/types.d.ts +21 -0
- package/dist/types/sdk/utils/retry.d.ts +1 -0
- package/dist/types/sdk/utils/viem/cast.d.ts +1 -1
- package/dist/types/sdk/utils/viem/simulateMulticall.d.ts +1 -1
- package/dist/types/sdk/utils/viem/simulateWithPriceUpdates.d.ts +1 -1
- package/package.json +4 -1
- package/dist/types/sdk/market/pricefeeds/RedstoneCache.d.ts +0 -25
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var PythUpdater_exports = {};
|
|
20
|
+
__export(PythUpdater_exports, {
|
|
21
|
+
PythUpdater: () => PythUpdater
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(PythUpdater_exports);
|
|
24
|
+
var import_price_service_sdk = require("@pythnetwork/price-service-sdk");
|
|
25
|
+
var import_viem = require("viem");
|
|
26
|
+
var import_base = require("../../../base/index.js");
|
|
27
|
+
var import_utils = require("../../../utils/index.js");
|
|
28
|
+
var import_PriceUpdatesCache = require("./PriceUpdatesCache.js");
|
|
29
|
+
var import_PriceUpdateTx = require("./PriceUpdateTx.js");
|
|
30
|
+
class PythUpdateTx extends import_PriceUpdateTx.PriceUpdateTx {
|
|
31
|
+
name = "pyth";
|
|
32
|
+
}
|
|
33
|
+
class PythUpdater extends import_base.SDKConstruct {
|
|
34
|
+
#logger;
|
|
35
|
+
#cache;
|
|
36
|
+
#historicalTimestamp;
|
|
37
|
+
#api;
|
|
38
|
+
#ignoreMissingFeeds;
|
|
39
|
+
constructor(sdk, opts = {}) {
|
|
40
|
+
super(sdk);
|
|
41
|
+
this.#logger = (0, import_utils.childLogger)("PythUpdater", sdk.logger);
|
|
42
|
+
this.#ignoreMissingFeeds = opts.ignoreMissingFeeds;
|
|
43
|
+
this.#api = opts.apiProxy ?? "https://hermes.pyth.network/v2/updates/price/";
|
|
44
|
+
this.#api = this.#api.endsWith("/") ? this.#api : this.#api + "/";
|
|
45
|
+
let ts = opts.historicTimestamp;
|
|
46
|
+
if (ts) {
|
|
47
|
+
this.#historicalTimestamp = ts === true ? Number(this.sdk.timestamp) : ts;
|
|
48
|
+
}
|
|
49
|
+
this.#cache = new import_PriceUpdatesCache.PriceUpdatesCache({
|
|
50
|
+
// currently staleness period is 240 seconds on all networks, add some buffer
|
|
51
|
+
// this period of 4 minutes is selected based on time that is required for user to sign transaction with wallet
|
|
52
|
+
// so it's unlikely to decrease
|
|
53
|
+
ttl: opts.cacheTTL ?? 225 * 1e3,
|
|
54
|
+
historical: !!ts
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async getUpdateTxs(feeds, logContext = {}) {
|
|
58
|
+
this.#logger?.debug(
|
|
59
|
+
logContext,
|
|
60
|
+
`generating update transactions for ${feeds.length} pyth price feeds`
|
|
61
|
+
);
|
|
62
|
+
const pythFeeds = new Map(
|
|
63
|
+
feeds.filter(isPyth).map((f) => [f.priceFeedId, f])
|
|
64
|
+
);
|
|
65
|
+
const payloads = await this.#getPayloads(new Set(pythFeeds.keys()));
|
|
66
|
+
const results = payloads.map((p) => {
|
|
67
|
+
const priceFeed = pythFeeds.get(p.dataFeedId);
|
|
68
|
+
if (!priceFeed) {
|
|
69
|
+
throw new Error(`cannot find price feed for ${p.dataFeedId}`);
|
|
70
|
+
}
|
|
71
|
+
const { dataFeedId, timestamp, cached, data } = p;
|
|
72
|
+
return new PythUpdateTx(priceFeed.createPriceUpdateTx(data), {
|
|
73
|
+
dataFeedId,
|
|
74
|
+
priceFeed: priceFeed.address,
|
|
75
|
+
timestamp,
|
|
76
|
+
cached
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
this.#logger?.debug(
|
|
80
|
+
logContext,
|
|
81
|
+
`generated ${results.length} update transactions for pyth price feeds`
|
|
82
|
+
);
|
|
83
|
+
return results;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Gets pyth payloads
|
|
87
|
+
* @param dataFeedsIds
|
|
88
|
+
* @returns
|
|
89
|
+
*/
|
|
90
|
+
async #getPayloads(dataFeedsIds) {
|
|
91
|
+
this.#logger?.debug(
|
|
92
|
+
`getting pyth payloads for ${dataFeedsIds.size} price feeds: ${Array.from(dataFeedsIds).join(", ")}`
|
|
93
|
+
);
|
|
94
|
+
const fromCache = [];
|
|
95
|
+
const uncached = [];
|
|
96
|
+
for (const priceFeedsId of dataFeedsIds) {
|
|
97
|
+
const cached = this.#cache.get(priceFeedsId);
|
|
98
|
+
if (cached) {
|
|
99
|
+
fromCache.push({ ...cached, cached: true });
|
|
100
|
+
} else {
|
|
101
|
+
uncached.push(priceFeedsId);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const fromPyth = await this.#fetchPayloads(
|
|
105
|
+
new Set(uncached)
|
|
106
|
+
);
|
|
107
|
+
for (const resp of fromPyth) {
|
|
108
|
+
this.#cache.set(resp, resp.dataFeedId);
|
|
109
|
+
}
|
|
110
|
+
this.#logger?.debug(
|
|
111
|
+
`got ${fromPyth.length} new pyth updates and ${fromCache.length} from cache`
|
|
112
|
+
);
|
|
113
|
+
return [...fromCache, ...fromPyth];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Fetches pyth payloads from Hermes API
|
|
117
|
+
* @param dataFeedsIds
|
|
118
|
+
* @returns
|
|
119
|
+
*/
|
|
120
|
+
async #fetchPayloads(dataFeedsIds) {
|
|
121
|
+
if (dataFeedsIds.size === 0) {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
const ids = Array.from(dataFeedsIds);
|
|
125
|
+
const tsStr = this.#historicalTimestamp ? ` with historical timestamp ${this.#historicalTimestamp}` : "";
|
|
126
|
+
this.#logger?.debug(
|
|
127
|
+
`fetching pyth payloads for ${dataFeedsIds.size} price feeds: ${ids.join(", ")}${tsStr}`
|
|
128
|
+
);
|
|
129
|
+
const url = new URL(this.#api + (this.#historicalTimestamp ?? "latest"));
|
|
130
|
+
url.searchParams.append("parsed", "false");
|
|
131
|
+
if (this.#ignoreMissingFeeds) {
|
|
132
|
+
url.searchParams.append("ignore_invalid_price_ids", "true");
|
|
133
|
+
}
|
|
134
|
+
for (const id of dataFeedsIds) {
|
|
135
|
+
url.searchParams.append("ids[]", id);
|
|
136
|
+
}
|
|
137
|
+
const resp = await (0, import_utils.retry)(
|
|
138
|
+
async () => {
|
|
139
|
+
const resp2 = await fetch(url.toString());
|
|
140
|
+
if (!resp2.ok) {
|
|
141
|
+
const body = await resp2.text();
|
|
142
|
+
throw new Error(
|
|
143
|
+
`failed to fetch pyth payloads: ${resp2.statusText}: ${body}`
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
const data = await resp2.json();
|
|
147
|
+
return data;
|
|
148
|
+
},
|
|
149
|
+
{ attempts: 3, exponent: 2, interval: 200 }
|
|
150
|
+
);
|
|
151
|
+
return respToCalldata(resp);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function isPyth(pf) {
|
|
155
|
+
return pf.contractType === "PRICE_FEED::PYTH";
|
|
156
|
+
}
|
|
157
|
+
function respToCalldata(resp) {
|
|
158
|
+
const updates = splitAccumulatorUpdates(resp.binary.data[0]);
|
|
159
|
+
return updates.map(({ data, dataFeedId, timestamp }) => {
|
|
160
|
+
return {
|
|
161
|
+
dataFeedId,
|
|
162
|
+
data: (0, import_viem.encodeAbiParameters)(
|
|
163
|
+
[{ type: "uint256" }, { type: "bytes[]" }],
|
|
164
|
+
[BigInt(timestamp), [data]]
|
|
165
|
+
),
|
|
166
|
+
timestamp,
|
|
167
|
+
cached: false
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function splitAccumulatorUpdates(binary) {
|
|
172
|
+
const data = Buffer.from(binary, "hex");
|
|
173
|
+
const parsed = (0, import_price_service_sdk.parseAccumulatorUpdateData)(data);
|
|
174
|
+
const results = [];
|
|
175
|
+
for (let i = 0; i < parsed.updates.length; i++) {
|
|
176
|
+
const upd = parsed.updates[i].message;
|
|
177
|
+
const msg = (0, import_price_service_sdk.parsePriceFeedMessage)(upd);
|
|
178
|
+
results.push({
|
|
179
|
+
dataFeedId: (0, import_viem.toHex)(msg.feedId),
|
|
180
|
+
timestamp: msg.publishTime.toNumber(),
|
|
181
|
+
data: (0, import_viem.toHex)((0, import_price_service_sdk.sliceAccumulatorUpdateData)(data, i, i + 1))
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return results;
|
|
185
|
+
}
|
|
186
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
187
|
+
0 && (module.exports = {
|
|
188
|
+
PythUpdater
|
|
189
|
+
});
|
|
@@ -18,40 +18,18 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var RedstoneUpdater_exports = {};
|
|
20
20
|
__export(RedstoneUpdater_exports, {
|
|
21
|
-
RedstoneUpdateTx: () => RedstoneUpdateTx,
|
|
22
21
|
RedstoneUpdater: () => RedstoneUpdater
|
|
23
22
|
});
|
|
24
23
|
module.exports = __toCommonJS(RedstoneUpdater_exports);
|
|
25
24
|
var import_evm_connector = require("@redstone-finance/evm-connector");
|
|
26
25
|
var import_protocol = require("@redstone-finance/protocol");
|
|
27
26
|
var import_viem = require("viem");
|
|
28
|
-
var import_base = require("
|
|
29
|
-
var import_utils = require("
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
raw;
|
|
35
|
-
data;
|
|
36
|
-
constructor(raw, data) {
|
|
37
|
-
this.raw = raw;
|
|
38
|
-
this.data = data;
|
|
39
|
-
}
|
|
40
|
-
get pretty() {
|
|
41
|
-
const cached = this.data.cached ? " (cached)" : "";
|
|
42
|
-
return `redstone feed ${this.data.dataFeedId} at ${this.data.priceFeed} with timestamp ${this.data.timestamp}${cached}`;
|
|
43
|
-
}
|
|
44
|
-
validateTimestamp(blockTimestamp) {
|
|
45
|
-
const { timestamp: expectedPayloadTimestamp } = this.data;
|
|
46
|
-
if (blockTimestamp < expectedPayloadTimestamp) {
|
|
47
|
-
if (BigInt(expectedPayloadTimestamp) - blockTimestamp > MAX_DATA_TIMESTAMP_AHEAD_SECONDS) {
|
|
48
|
-
return "in future";
|
|
49
|
-
}
|
|
50
|
-
} else if (blockTimestamp - BigInt(expectedPayloadTimestamp) > MAX_DATA_TIMESTAMP_DELAY_SECONDS) {
|
|
51
|
-
return "too old";
|
|
52
|
-
}
|
|
53
|
-
return "valid";
|
|
54
|
-
}
|
|
27
|
+
var import_base = require("../../../base/index.js");
|
|
28
|
+
var import_utils = require("../../../utils/index.js");
|
|
29
|
+
var import_PriceUpdatesCache = require("./PriceUpdatesCache.js");
|
|
30
|
+
var import_PriceUpdateTx = require("./PriceUpdateTx.js");
|
|
31
|
+
class RedstoneUpdateTx extends import_PriceUpdateTx.PriceUpdateTx {
|
|
32
|
+
name = "redstone";
|
|
55
33
|
}
|
|
56
34
|
class RedstoneUpdater extends import_base.SDKConstruct {
|
|
57
35
|
#logger;
|
|
@@ -71,7 +49,7 @@ class RedstoneUpdater extends import_base.SDKConstruct {
|
|
|
71
49
|
ts = ts === true ? Number(this.sdk.timestamp) * 1e3 : ts;
|
|
72
50
|
this.#historicalTimestampMs = 6e4 * Math.floor(ts / 6e4);
|
|
73
51
|
}
|
|
74
|
-
this.#cache = new
|
|
52
|
+
this.#cache = new import_PriceUpdatesCache.PriceUpdatesCache({
|
|
75
53
|
// currently staleness period is 240 seconds on all networks, add some buffer
|
|
76
54
|
// this period of 4 minutes is selected based on time that is required for user to sign transaction with wallet
|
|
77
55
|
// so it's unlikely to decrease
|
|
@@ -87,6 +65,9 @@ class RedstoneUpdater extends import_base.SDKConstruct {
|
|
|
87
65
|
const groupedFeeds = {};
|
|
88
66
|
const priceFeeds = /* @__PURE__ */ new Map();
|
|
89
67
|
for (const feed of feeds) {
|
|
68
|
+
if (!isRedstone(feed)) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
90
71
|
const key = `${feed.dataServiceId}:${feed.signersThreshold}`;
|
|
91
72
|
if (!groupedFeeds[key]) {
|
|
92
73
|
groupedFeeds[key] = /* @__PURE__ */ new Set();
|
|
@@ -112,20 +93,13 @@ class RedstoneUpdater extends import_base.SDKConstruct {
|
|
|
112
93
|
}
|
|
113
94
|
for (const priceFeed of pfsForDataId.values()) {
|
|
114
95
|
results.push(
|
|
115
|
-
new RedstoneUpdateTx(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
dataFeedId,
|
|
123
|
-
dataServiceId,
|
|
124
|
-
priceFeed: priceFeed.address,
|
|
125
|
-
timestamp,
|
|
126
|
-
cached
|
|
127
|
-
}
|
|
128
|
-
)
|
|
96
|
+
new RedstoneUpdateTx(priceFeed.createPriceUpdateTx(data), {
|
|
97
|
+
dataFeedId,
|
|
98
|
+
dataServiceId,
|
|
99
|
+
priceFeed: priceFeed.address,
|
|
100
|
+
timestamp,
|
|
101
|
+
cached
|
|
102
|
+
})
|
|
129
103
|
);
|
|
130
104
|
}
|
|
131
105
|
}
|
|
@@ -168,7 +142,7 @@ class RedstoneUpdater extends import_base.SDKConstruct {
|
|
|
168
142
|
uniqueSignersCount
|
|
169
143
|
);
|
|
170
144
|
for (const resp of fromRedstone) {
|
|
171
|
-
this.#cache.set(dataServiceId, resp.dataFeedId, uniqueSignersCount
|
|
145
|
+
this.#cache.set(resp, dataServiceId, resp.dataFeedId, uniqueSignersCount);
|
|
172
146
|
}
|
|
173
147
|
this.#logger?.debug(
|
|
174
148
|
`got ${fromRedstone.length} new redstone updates and ${fromCache.length} from cache`
|
|
@@ -269,8 +243,10 @@ function getCalldataWithTimestamp(dataFeedId, packages, unsignedMetadata) {
|
|
|
269
243
|
cached: false
|
|
270
244
|
};
|
|
271
245
|
}
|
|
246
|
+
function isRedstone(pf) {
|
|
247
|
+
return pf.contractType === "PRICE_FEED::REDSTONE";
|
|
248
|
+
}
|
|
272
249
|
// Annotate the CommonJS export names for ESM import in node:
|
|
273
250
|
0 && (module.exports = {
|
|
274
|
-
RedstoneUpdateTx,
|
|
275
251
|
RedstoneUpdater
|
|
276
252
|
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var updates_exports = {};
|
|
20
|
+
__export(updates_exports, {
|
|
21
|
+
PythUpdater: () => import_PythUpdater.PythUpdater,
|
|
22
|
+
RedstoneUpdater: () => import_RedstoneUpdater.RedstoneUpdater
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(updates_exports);
|
|
25
|
+
var import_PythUpdater = require("./PythUpdater.js");
|
|
26
|
+
var import_RedstoneUpdater = require("./RedstoneUpdater.js");
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
PythUpdater,
|
|
30
|
+
RedstoneUpdater
|
|
31
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -38,8 +38,7 @@ const ALIASES = {
|
|
|
38
38
|
PT_corn_pumpBTC_26DEC2024: "p.c.pumpBTC(26.12.24)",
|
|
39
39
|
PT_sUSDe_27MAR2025: "p.sUSDe(27.03.25)",
|
|
40
40
|
PT_sUSDe_29MAY2025: "p.sUSDe(29.05.25)",
|
|
41
|
-
PT_beraSTONE_10APR2025: "p.beraSTONE(10.04.25)"
|
|
42
|
-
PT_uptBTC_14AUG2025: "p.uptBTC(14.08.25)"
|
|
41
|
+
PT_beraSTONE_10APR2025: "p.beraSTONE(10.04.25)"
|
|
43
42
|
};
|
|
44
43
|
class TokenData {
|
|
45
44
|
address;
|
|
@@ -22,7 +22,8 @@ __export(retry_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(retry_exports);
|
|
24
24
|
async function retry(fn, options = {}) {
|
|
25
|
-
const { attempts = 3, interval = 200 } = options;
|
|
25
|
+
const { attempts = 3, interval = 200, exponent = 1 } = options;
|
|
26
|
+
let wait = interval;
|
|
26
27
|
let cause;
|
|
27
28
|
for (let i = 0; i < attempts; i++) {
|
|
28
29
|
try {
|
|
@@ -31,8 +32,9 @@ async function retry(fn, options = {}) {
|
|
|
31
32
|
} catch (e) {
|
|
32
33
|
cause = e;
|
|
33
34
|
await new Promise((resolve) => {
|
|
34
|
-
setTimeout(resolve,
|
|
35
|
+
setTimeout(resolve, wait);
|
|
35
36
|
});
|
|
37
|
+
wait = wait * exponent;
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
throw new Error(`all attempts failed: ${cause}`);
|
|
@@ -21,9 +21,12 @@ __export(cast_exports, {
|
|
|
21
21
|
generateCastTraceCall: () => generateCastTraceCall
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(cast_exports);
|
|
24
|
-
function generateCastTraceCall(params) {
|
|
24
|
+
function generateCastTraceCall(params, rpcUrl) {
|
|
25
25
|
const { to, data, blockNumber, gas, gasPrice, maxPriorityFeePerGas, value } = params;
|
|
26
|
-
const cmd = ["cast", "call", "--trace"
|
|
26
|
+
const cmd = ["cast", "call", "--trace"];
|
|
27
|
+
if (rpcUrl) {
|
|
28
|
+
cmd.push("--rpc-url", rpcUrl);
|
|
29
|
+
}
|
|
27
30
|
if (blockNumber) {
|
|
28
31
|
cmd.push("--block", blockNumber.toString());
|
|
29
32
|
}
|
|
@@ -31,6 +31,7 @@ async function simulateMulticall(client, parameters) {
|
|
|
31
31
|
blockNumber,
|
|
32
32
|
blockTag,
|
|
33
33
|
gas,
|
|
34
|
+
value,
|
|
34
35
|
multicallAddress: multicallAddress_
|
|
35
36
|
} = parameters;
|
|
36
37
|
const contracts = parameters.contracts;
|
|
@@ -88,7 +89,8 @@ async function simulateMulticall(client, parameters) {
|
|
|
88
89
|
blockTag,
|
|
89
90
|
// does not infer well that either blockNumber or blockTag must be present
|
|
90
91
|
gas,
|
|
91
|
-
account
|
|
92
|
+
account,
|
|
93
|
+
value
|
|
92
94
|
};
|
|
93
95
|
const results = [];
|
|
94
96
|
const { data } = await (0, import_utils.getAction)(client, import_actions.call, "call")(request);
|
|
@@ -220,8 +220,8 @@ class SimulateWithPriceUpdatesError extends import_viem.BaseError {
|
|
|
220
220
|
this.timestamp = timestamp;
|
|
221
221
|
this.#request = request;
|
|
222
222
|
}
|
|
223
|
-
getCastTraceCall() {
|
|
224
|
-
return this.#request ? (0, import_cast.generateCastTraceCall)(this.#request) : "";
|
|
223
|
+
getCastTraceCall(rpcUrl) {
|
|
224
|
+
return this.#request ? (0, import_cast.generateCastTraceCall)(this.#request, rpcUrl) : "";
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -24,13 +24,15 @@ class DegenDistributorsPlugin extends BasePlugin {
|
|
|
24
24
|
acc[cfgLC] = distributors[index];
|
|
25
25
|
return acc;
|
|
26
26
|
}, {});
|
|
27
|
-
this.#distributors = new AddressMap(void 0, MAP_LABEL);
|
|
28
27
|
this.sdk.marketRegister.markets.forEach((m) => {
|
|
29
28
|
const pool = m.pool.pool.address;
|
|
30
29
|
const cfg = m.configurator.address;
|
|
31
30
|
const cfgLC = cfg.toLowerCase();
|
|
32
31
|
const r = distributorByConfigurator?.[cfgLC];
|
|
33
32
|
if (r.status === "fulfilled") {
|
|
33
|
+
if (!this.#distributors) {
|
|
34
|
+
this.#distributors = new AddressMap(void 0, MAP_LABEL);
|
|
35
|
+
}
|
|
34
36
|
this.#distributors.upsert(pool, r.value);
|
|
35
37
|
} else {
|
|
36
38
|
this.sdk.logger?.error(
|
|
@@ -35,12 +35,17 @@ class Pools7DAgoPlugin extends BasePlugin {
|
|
|
35
35
|
),
|
|
36
36
|
blockNumber: BigIntMath.max(0n, targetBlock)
|
|
37
37
|
});
|
|
38
|
-
this.#pools7DAgo = new AddressMap(void 0, MAP_LABEL);
|
|
39
38
|
resp.forEach((r, index) => {
|
|
40
39
|
const m = markets[index];
|
|
41
40
|
const cfg = m.configurator.address;
|
|
42
41
|
const pool = m.pool.pool.address;
|
|
43
42
|
if (r.status === "success") {
|
|
43
|
+
if (!this.#pools7DAgo) {
|
|
44
|
+
this.#pools7DAgo = new AddressMap(
|
|
45
|
+
void 0,
|
|
46
|
+
MAP_LABEL
|
|
47
|
+
);
|
|
48
|
+
}
|
|
44
49
|
this.#pools7DAgo.upsert(m.pool.pool.address, {
|
|
45
50
|
dieselRate: r.result.dieselRate,
|
|
46
51
|
pool
|
|
@@ -79,6 +79,7 @@ class GearboxSDK {
|
|
|
79
79
|
plugins,
|
|
80
80
|
blockNumber,
|
|
81
81
|
redstone,
|
|
82
|
+
pyth,
|
|
82
83
|
ignoreUpdateablePrices,
|
|
83
84
|
marketConfigurators: mcs,
|
|
84
85
|
strictContractTypes
|
|
@@ -112,7 +113,8 @@ class GearboxSDK {
|
|
|
112
113
|
blockNumber,
|
|
113
114
|
ignoreUpdateablePrices,
|
|
114
115
|
marketConfigurators,
|
|
115
|
-
redstone
|
|
116
|
+
redstone,
|
|
117
|
+
pyth
|
|
116
118
|
});
|
|
117
119
|
}
|
|
118
120
|
static hydrate(options, state) {
|
|
@@ -144,7 +146,8 @@ class GearboxSDK {
|
|
|
144
146
|
blockNumber,
|
|
145
147
|
ignoreUpdateablePrices,
|
|
146
148
|
marketConfigurators,
|
|
147
|
-
redstone
|
|
149
|
+
redstone,
|
|
150
|
+
pyth
|
|
148
151
|
} = opts;
|
|
149
152
|
const re = this.#attachConfig ? "re" : "";
|
|
150
153
|
this.logger?.info(
|
|
@@ -159,7 +162,12 @@ class GearboxSDK {
|
|
|
159
162
|
);
|
|
160
163
|
if (!!blockNumber && !opts.redstone?.historicTimestamp) {
|
|
161
164
|
this.logger?.warn(
|
|
162
|
-
`${re}attaching to fixed block number, but
|
|
165
|
+
`${re}attaching to fixed block number, but redstone historicTimestamp is not set. price updates might fail`
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
if (!!blockNumber && !opts.pyth?.historicTimestamp) {
|
|
169
|
+
this.logger?.warn(
|
|
170
|
+
`${re}attaching to fixed block number, but pyth historicTimestamp is not set. price updates might fail`
|
|
163
171
|
);
|
|
164
172
|
}
|
|
165
173
|
this.#attachConfig = opts;
|
|
@@ -171,7 +179,7 @@ class GearboxSDK {
|
|
|
171
179
|
);
|
|
172
180
|
this.#currentBlock = block.number;
|
|
173
181
|
this.#timestamp = block.timestamp;
|
|
174
|
-
this.#priceFeeds = new PriceFeedRegister(this, { redstone });
|
|
182
|
+
this.#priceFeeds = new PriceFeedRegister(this, { redstone, pyth });
|
|
175
183
|
this.logger?.debug(
|
|
176
184
|
`${re}attach block number ${this.currentBlock} timestamp ${this.timestamp}`
|
|
177
185
|
);
|
|
@@ -222,7 +230,10 @@ class GearboxSDK {
|
|
|
222
230
|
);
|
|
223
231
|
this.#currentBlock = state.currentBlock;
|
|
224
232
|
this.#timestamp = state.timestamp;
|
|
225
|
-
this.#priceFeeds = new PriceFeedRegister(this, {
|
|
233
|
+
this.#priceFeeds = new PriceFeedRegister(this, {
|
|
234
|
+
redstone: opts.redstone,
|
|
235
|
+
pyth: opts.pyth
|
|
236
|
+
});
|
|
226
237
|
this.#addressProvider = hydrateAddressProvider(this, state.addressProvider);
|
|
227
238
|
this.logger?.debug(
|
|
228
239
|
`address provider version: ${this.#addressProvider.version}`
|
|
@@ -274,7 +285,8 @@ class GearboxSDK {
|
|
|
274
285
|
}
|
|
275
286
|
const opts = {
|
|
276
287
|
ignoreUpdateablePrices: this.#attachConfig.ignoreUpdateablePrices,
|
|
277
|
-
redstone: this.#attachConfig.redstone
|
|
288
|
+
redstone: this.#attachConfig.redstone,
|
|
289
|
+
pyth: this.#attachConfig.pyth
|
|
278
290
|
};
|
|
279
291
|
this.#hydrate(opts, state);
|
|
280
292
|
await this.#hooks.triggerHooks("rehydrate", {
|
|
@@ -373,9 +385,9 @@ class GearboxSDK {
|
|
|
373
385
|
*/
|
|
374
386
|
async syncState(opts) {
|
|
375
387
|
let { blockNumber, timestamp, skipPriceUpdate } = opts ?? {};
|
|
376
|
-
if (this.#attachConfig?.redstone?.historicTimestamp) {
|
|
388
|
+
if (this.#attachConfig?.redstone?.historicTimestamp || this.#attachConfig?.pyth?.historicTimestamp) {
|
|
377
389
|
throw new Error(
|
|
378
|
-
"syncState is not supported with
|
|
390
|
+
"syncState is not supported with redstone or pyth historicTimestamp"
|
|
379
391
|
);
|
|
380
392
|
}
|
|
381
393
|
if (!blockNumber || !timestamp) {
|