@gearbox-protocol/sdk 13.5.0 → 13.6.0-apy-plugin.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.
Files changed (34) hide show
  1. package/dist/cjs/plugins/pools-history/ApyPlugin.js +328 -0
  2. package/dist/cjs/plugins/pools-history/apy-cache.js +120 -0
  3. package/dist/cjs/plugins/pools-history/apy-parser.js +169 -0
  4. package/dist/cjs/plugins/pools-history/constants.js +31 -0
  5. package/dist/cjs/plugins/pools-history/index.js +12 -2
  6. package/dist/cjs/plugins/pools-history/pool-apy-types.js +16 -0
  7. package/dist/cjs/plugins/pools-history/pool-apy-utils.js +141 -0
  8. package/dist/cjs/rewards/rewards/extra-apy.js +10 -8
  9. package/dist/cjs/sdk/GearboxSDK.js +11 -0
  10. package/dist/esm/plugins/pools-history/ApyPlugin.js +317 -0
  11. package/dist/esm/plugins/pools-history/apy-cache.js +86 -0
  12. package/dist/esm/plugins/pools-history/apy-parser.js +143 -0
  13. package/dist/esm/plugins/pools-history/constants.js +6 -0
  14. package/dist/esm/plugins/pools-history/index.js +6 -1
  15. package/dist/esm/plugins/pools-history/pool-apy-types.js +0 -0
  16. package/dist/esm/plugins/pools-history/pool-apy-utils.js +113 -0
  17. package/dist/esm/rewards/rewards/extra-apy.js +10 -8
  18. package/dist/esm/sdk/GearboxSDK.js +11 -0
  19. package/dist/types/plugins/pools-history/ApyPlugin.d.ts +70 -0
  20. package/dist/types/plugins/pools-history/apy-cache.d.ts +28 -0
  21. package/dist/types/plugins/pools-history/apy-parser.d.ts +5 -0
  22. package/dist/types/plugins/pools-history/constants.d.ts +2 -0
  23. package/dist/types/plugins/pools-history/index.d.ts +6 -1
  24. package/dist/types/plugins/pools-history/pool-apy-types.d.ts +39 -0
  25. package/dist/types/plugins/pools-history/pool-apy-utils.d.ts +71 -0
  26. package/dist/types/plugins/pools-history/types.d.ts +28 -0
  27. package/dist/types/rewards/rewards/api.d.ts +10 -1
  28. package/dist/types/rewards/rewards/common.d.ts +0 -10
  29. package/dist/types/rewards/rewards/extra-apy.d.ts +4 -6
  30. package/dist/types/sdk/GearboxSDK.d.ts +19 -0
  31. package/package.json +1 -1
  32. package/dist/cjs/plugins/pools-history/Pools7DAgoPlugin.js +0 -108
  33. package/dist/esm/plugins/pools-history/Pools7DAgoPlugin.js +0 -90
  34. package/dist/types/plugins/pools-history/Pools7DAgoPlugin.d.ts +0 -20
@@ -0,0 +1,328 @@
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 ApyPlugin_exports = {};
20
+ __export(ApyPlugin_exports, {
21
+ ApyPlugin: () => ApyPlugin
22
+ });
23
+ module.exports = __toCommonJS(ApyPlugin_exports);
24
+ var import_marketCompressor = require("../../abi/compressors/marketCompressor.js");
25
+ var import_extra_apy = require("../../rewards/rewards/extra-apy.js");
26
+ var import_sdk = require("../../sdk/index.js");
27
+ var import_formatter = require("../../sdk/utils/formatter.js");
28
+ var import_hex = require("../../sdk/utils/hex.js");
29
+ var import_apy_cache = require("./apy-cache.js");
30
+ var import_apy_parser = require("./apy-parser.js");
31
+ var import_constants = require("./constants.js");
32
+ var import_pool_apy_utils = require("./pool-apy-utils.js");
33
+ const MAP_LABEL = "pools7DAgo";
34
+ const PLUGIN_KEY = "ApyPlugin";
35
+ class ApyPlugin extends import_sdk.BasePlugin {
36
+ #timerInterval;
37
+ #apyUrl;
38
+ #cacheTtlMs;
39
+ #pools7DAgo;
40
+ #apySnapshot;
41
+ /**
42
+ * Default timer options
43
+ * @see PluginTimerOptions
44
+ */
45
+ #defaultTimerOptions;
46
+ /**
47
+ * When `true`, the timer is started eagerly during the `attach` phase
48
+ * rather than waiting for an explicit `load` call.
49
+ **/
50
+ startTimerOnAttach;
51
+ constructor(loadOnAttach = false, startTimerOnAttach = false, options) {
52
+ super(loadOnAttach);
53
+ this.startTimerOnAttach = startTimerOnAttach;
54
+ this.#apyUrl = options?.apyUrl ?? import_constants.APY_STATE_CACHE_URL;
55
+ this.#cacheTtlMs = options?.cacheTtlMs ?? import_constants.DEFAULT_APY_INTERVAL_MS;
56
+ this.#defaultTimerOptions = options?.timer ?? {
57
+ refreshPools7DAgoOnTick: false,
58
+ intervalMs: import_constants.DEFAULT_APY_INTERVAL_MS,
59
+ onChange: () => {
60
+ }
61
+ };
62
+ }
63
+ async attach() {
64
+ await super.attach();
65
+ if (this.startTimerOnAttach) {
66
+ this.startTimer();
67
+ }
68
+ }
69
+ // ---------------------------------------------------------------------------
70
+ // Load — single entry point for all data (on-chain + state-cache)
71
+ // ---------------------------------------------------------------------------
72
+ async load(force, loadOptions) {
73
+ if (!force && this.loaded) {
74
+ return this.state;
75
+ }
76
+ const targetBlock = this.sdk.currentBlock - import_sdk.BLOCKS_PER_WEEK_BY_NETWORK[this.sdk.networkType];
77
+ const [marketCompressorAddress] = this.sdk.addressProvider.mustGetLatest(
78
+ import_sdk.AP_MARKET_COMPRESSOR,
79
+ import_sdk.VERSION_RANGE_310
80
+ );
81
+ this.#logger?.debug(
82
+ `loading pools 7d ago with market compressor ${marketCompressorAddress}`
83
+ );
84
+ const markets = this.sdk.marketRegister.markets;
85
+ const shouldLoadPools7DAgo = !this.#pools7DAgo || !!loadOptions?.loadPools7DAgo;
86
+ const [multicallResp, apySnapshot] = await Promise.all([
87
+ shouldLoadPools7DAgo ? this.client.multicall({
88
+ allowFailure: true,
89
+ contracts: markets.map(
90
+ (m) => ({
91
+ address: marketCompressorAddress,
92
+ abi: import_marketCompressor.marketCompressorAbi,
93
+ functionName: "getPoolState",
94
+ args: [m.pool.pool.address]
95
+ })
96
+ ),
97
+ blockNumber: targetBlock > 0n ? targetBlock : void 0,
98
+ batchSize: 0
99
+ }) : null,
100
+ this.#fetchApy()
101
+ ]);
102
+ if (multicallResp !== null) {
103
+ this.#pools7DAgo = new import_sdk.AddressMap(void 0, MAP_LABEL);
104
+ multicallResp.forEach((r, index) => {
105
+ const m = markets[index];
106
+ const cfg = m.configurator.address;
107
+ const pool = m.pool.pool.address;
108
+ if (r.status === "success") {
109
+ this.#pools7DAgo?.upsert(m.pool.pool.address, {
110
+ dieselRate: r.result.dieselRate,
111
+ pool
112
+ });
113
+ } else {
114
+ this.#logger?.error(
115
+ `failed to load pools 7d ago for market configurator ${this.labelAddress(cfg)} and pool ${this.labelAddress(pool)}: ${r.error}`
116
+ );
117
+ }
118
+ });
119
+ }
120
+ if (apySnapshot) {
121
+ this.#apySnapshot = apySnapshot;
122
+ }
123
+ return this.state;
124
+ }
125
+ get loaded() {
126
+ return !!this.#pools7DAgo && !!this.#apySnapshot;
127
+ }
128
+ // ---------------------------------------------------------------------------
129
+ // Accessors
130
+ // ---------------------------------------------------------------------------
131
+ /**
132
+ * @throws if plugin is not loaded
133
+ */
134
+ get pools7DAgo() {
135
+ if (!this.#pools7DAgo) {
136
+ throw new Error("apy plugin not loaded");
137
+ }
138
+ return this.#pools7DAgo;
139
+ }
140
+ /**
141
+ * @throws if plugin is not loaded
142
+ */
143
+ get apySnapshot() {
144
+ if (!this.#apySnapshot) {
145
+ throw new Error("apy plugin not loaded");
146
+ }
147
+ return this.#apySnapshot;
148
+ }
149
+ // ---------------------------------------------------------------------------
150
+ // Aggregated APY / points
151
+ // ---------------------------------------------------------------------------
152
+ /**
153
+ * Computes per-pool APY (current + 7d-ago) and points for all markets.
154
+ *
155
+ * @throws if plugin is not loaded
156
+ */
157
+ getPoolsAPY() {
158
+ if (!this.loaded) {
159
+ throw new Error("apy plugin not loaded");
160
+ }
161
+ const markets = this.sdk.marketRegister.markets;
162
+ const { apy } = this.apySnapshot;
163
+ const totalTokenBalances = {};
164
+ const poolPointsBase = apy.poolRewardsList && Object.keys(apy.poolRewardsList).length > 0 ? import_extra_apy.PoolPointsAPI.getPointsByPool({
165
+ poolRewards: apy.poolRewardsList,
166
+ totalTokenBalances,
167
+ pools: markets,
168
+ tokensList: this.sdk.tokensMeta
169
+ }) : {};
170
+ const data = {};
171
+ const data7DAgo = {};
172
+ const points = {};
173
+ for (const market of markets) {
174
+ const pool = market.pool.pool;
175
+ const poolAddr = pool.address.toLowerCase();
176
+ const depositAPY = (0, import_formatter.rayToNumber)(pool.supplyRate) * Number(import_sdk.PERCENTAGE_DECIMALS);
177
+ const underlyingAPY = apy.apyList?.[pool.underlying] ?? 0;
178
+ const lookupAddresses = this.#getExtraAPYLookupAddresses(poolAddr);
179
+ const extraAPY = (0, import_pool_apy_utils.getPoolExtraAPY)(lookupAddresses, apy.poolExtraAPYList);
180
+ const currentExternalList = apy.poolExternalAPYList?.[poolAddr];
181
+ const poolAPY = (0, import_pool_apy_utils.calculatePoolFullAPY)({
182
+ depositAPY,
183
+ underlyingAPY,
184
+ extraAPY,
185
+ currentExternalList
186
+ });
187
+ data[poolAddr] = poolAPY;
188
+ const pool7DAgo = this.#pools7DAgo?.get(poolAddr);
189
+ const supplyAPY7DAgo = pool7DAgo ? (0, import_pool_apy_utils.calculateSupplyApy7d)(
190
+ pool.dieselRate,
191
+ pool.supplyRate,
192
+ pool7DAgo.dieselRate
193
+ ) : void 0;
194
+ data7DAgo[poolAddr] = (0, import_pool_apy_utils.calculatePoolFullAPY7DAgo)({
195
+ supplyAPY7DAgo,
196
+ depositAPY,
197
+ poolAPY
198
+ });
199
+ const poolTokenMeta = this.sdk.tokensMeta.get(pool.underlying);
200
+ points[poolAddr] = (0, import_pool_apy_utils.calculatePoolPoints)({
201
+ poolTokenSymbol: poolTokenMeta?.symbol,
202
+ points: poolPointsBase[poolAddr],
203
+ tokensList: this.sdk.tokensMeta
204
+ });
205
+ }
206
+ return { data, data7DAgo, points };
207
+ }
208
+ // ---------------------------------------------------------------------------
209
+ // Periodic full refresh
210
+ // ---------------------------------------------------------------------------
211
+ /**
212
+ * Starts a periodic timer that performs a full plugin state refresh.
213
+ * Only one timer can be active; calling again is a no-op.
214
+ * @returns Cleanup function that stops the timer.
215
+ */
216
+ startTimer(opts) {
217
+ if (this.#timerInterval) {
218
+ this.#logger?.debug("plugin timer already running");
219
+ return () => this.stopTimer();
220
+ }
221
+ const intervalMs = opts?.intervalMs ?? this.#defaultTimerOptions.intervalMs;
222
+ this.#logger?.debug(`starting plugin timer (interval: ${intervalMs}ms)`);
223
+ this.#timerInterval = setInterval(async () => {
224
+ try {
225
+ const prevTimestamp = this.#apySnapshot?.timestamp;
226
+ await this.load(true, {
227
+ loadPools7DAgo: opts?.refreshPools7DAgoOnTick ?? this.#defaultTimerOptions.refreshPools7DAgoOnTick
228
+ });
229
+ if (this.#apySnapshot?.timestamp !== prevTimestamp) {
230
+ opts?.onChange?.() ?? this.#defaultTimerOptions.onChange?.();
231
+ await this.sdk.triggerPluginUpdate(PLUGIN_KEY);
232
+ }
233
+ } catch (e) {
234
+ this.#logger?.error(e, "periodic refresh failed");
235
+ }
236
+ }, intervalMs);
237
+ return () => this.stopTimer();
238
+ }
239
+ stopTimer() {
240
+ if (this.#timerInterval) {
241
+ clearInterval(this.#timerInterval);
242
+ this.#timerInterval = void 0;
243
+ this.#logger?.debug("plugin timer stopped");
244
+ }
245
+ }
246
+ // ---------------------------------------------------------------------------
247
+ // Plugin lifecycle
248
+ // ---------------------------------------------------------------------------
249
+ async syncState() {
250
+ await this.load(true);
251
+ }
252
+ stateHuman(_) {
253
+ return this.pools7DAgo.values().flatMap((p) => ({
254
+ address: p.pool,
255
+ version: this.version,
256
+ dieselRate: p.dieselRate
257
+ }));
258
+ }
259
+ get state() {
260
+ return {
261
+ pools7DAgo: this.pools7DAgo.asRecord(),
262
+ apySnapshot: this.apySnapshot
263
+ };
264
+ }
265
+ hydrate(state) {
266
+ this.#pools7DAgo = new import_sdk.AddressMap(
267
+ Object.entries(state.pools7DAgo),
268
+ MAP_LABEL
269
+ );
270
+ this.#apySnapshot = state.apySnapshot;
271
+ }
272
+ // ---------------------------------------------------------------------------
273
+ // Internal
274
+ // ---------------------------------------------------------------------------
275
+ async #fetchApy() {
276
+ try {
277
+ const cache = import_apy_cache.ApyOutputCache.get(
278
+ this.#apyUrl,
279
+ this.#cacheTtlMs,
280
+ this.#logger
281
+ );
282
+ const output = await cache.fetch();
283
+ if (!output) return void 0;
284
+ const chainData = output.chains[this.sdk.chainId];
285
+ if (!chainData) {
286
+ this.#logger?.debug(
287
+ `apy state-cache: no data for chainId ${this.sdk.chainId}`
288
+ );
289
+ return void 0;
290
+ }
291
+ const apy = (0, import_apy_parser.parseNetworkApy)(chainData.tokens, chainData.pools);
292
+ if (!apy) return void 0;
293
+ return {
294
+ apy,
295
+ gearStats: (0, import_apy_parser.parseGearStats)(output),
296
+ timestamp: output.timestamp
297
+ };
298
+ } catch (e) {
299
+ this.#logger?.error(e, "failed to fetch apy state-cache");
300
+ return void 0;
301
+ }
302
+ }
303
+ /**
304
+ * Collects addresses to look up in poolExtraAPYList for a given pool.
305
+ * Includes pool address (= diesel token) + any staked diesel token
306
+ * outputs discovered from zappers.
307
+ */
308
+ #getExtraAPYLookupAddresses(poolAddr) {
309
+ const addresses = [poolAddr];
310
+ try {
311
+ const zappers = this.sdk.marketRegister.poolZappers(poolAddr);
312
+ for (const z of zappers) {
313
+ if (!(0, import_hex.hexEq)(z.tokenOut.addr, poolAddr)) {
314
+ addresses.push(z.tokenOut.addr);
315
+ }
316
+ }
317
+ } catch {
318
+ }
319
+ return addresses;
320
+ }
321
+ get #logger() {
322
+ return this.logger;
323
+ }
324
+ }
325
+ // Annotate the CommonJS export names for ESM import in node:
326
+ 0 && (module.exports = {
327
+ ApyPlugin
328
+ });
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var apy_cache_exports = {};
30
+ __export(apy_cache_exports, {
31
+ ApyOutputCache: () => ApyOutputCache
32
+ });
33
+ module.exports = __toCommonJS(apy_cache_exports);
34
+ var import_axios = __toESM(require("axios"));
35
+ class ApyOutputCache {
36
+ static #instances = /* @__PURE__ */ new Map();
37
+ #url;
38
+ #ttlMs;
39
+ #cache;
40
+ #pending;
41
+ #logger;
42
+ constructor(url, ttlMs, logger) {
43
+ this.#url = url;
44
+ this.#ttlMs = ttlMs;
45
+ this.#logger = logger;
46
+ }
47
+ /**
48
+ * Returns a shared cache instance for the given URL.
49
+ * The same instance is reused across all callers with identical URL.
50
+ */
51
+ static get(url, ttlMs, logger) {
52
+ let instance = ApyOutputCache.#instances.get(url);
53
+ if (!instance) {
54
+ instance = new ApyOutputCache(url, ttlMs, logger);
55
+ ApyOutputCache.#instances.set(url, instance);
56
+ }
57
+ if (logger) {
58
+ instance.#logger = logger;
59
+ }
60
+ return instance;
61
+ }
62
+ /**
63
+ * Returns cached Output if fresh, otherwise fetches from the network.
64
+ * Concurrent calls are de-duplicated.
65
+ */
66
+ async fetch() {
67
+ if (this.#cache && Date.now() - this.#cache.fetchedAt < this.#ttlMs) {
68
+ this.#logger?.debug("apy cache: TTL still valid, returning cached data");
69
+ return this.#cache.data;
70
+ }
71
+ if (this.#pending) {
72
+ this.#logger?.debug("apy cache: request in flight, waiting");
73
+ return this.#pending;
74
+ }
75
+ this.#pending = this.#doFetch();
76
+ try {
77
+ return await this.#pending;
78
+ } finally {
79
+ this.#pending = void 0;
80
+ }
81
+ }
82
+ async #doFetch() {
83
+ try {
84
+ const headers = {};
85
+ if (this.#cache?.etag) {
86
+ headers["If-None-Match"] = this.#cache.etag;
87
+ }
88
+ const response = await import_axios.default.get(this.#url, {
89
+ headers,
90
+ validateStatus: (status) => status === 200 || status === 304
91
+ });
92
+ if (response.status === 304 && this.#cache) {
93
+ this.#cache.fetchedAt = Date.now();
94
+ this.#logger?.debug("apy cache: 304 Not Modified, extended TTL");
95
+ return this.#cache.data;
96
+ }
97
+ const etag = response.headers["etag"];
98
+ this.#cache = {
99
+ data: response.data,
100
+ etag,
101
+ fetchedAt: Date.now()
102
+ };
103
+ this.#logger?.debug(
104
+ `apy cache: fetched fresh data (timestamp: ${response.data.timestamp})`
105
+ );
106
+ return response.data;
107
+ } catch (e) {
108
+ this.#logger?.error(e, "apy cache: fetch failed");
109
+ return this.#cache?.data;
110
+ }
111
+ }
112
+ /** Evicts all cached entries. Mainly useful for tests. */
113
+ static clearAll() {
114
+ ApyOutputCache.#instances.clear();
115
+ }
116
+ }
117
+ // Annotate the CommonJS export names for ESM import in node:
118
+ 0 && (module.exports = {
119
+ ApyOutputCache
120
+ });
@@ -0,0 +1,169 @@
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 apy_parser_exports = {};
20
+ __export(apy_parser_exports, {
21
+ numberToAPY: () => numberToAPY,
22
+ parseGearStats: () => parseGearStats,
23
+ parseNetworkApy: () => parseNetworkApy
24
+ });
25
+ module.exports = __toCommonJS(apy_parser_exports);
26
+ var import_sdk = require("../../sdk/index.js");
27
+ function numberToAPY(baseApy) {
28
+ return Math.round(baseApy * Number(import_sdk.PERCENTAGE_FACTOR));
29
+ }
30
+ function parseGearStats(output) {
31
+ const d = output.gearApy?.status === "ok" ? output.gearApy.data : void 0;
32
+ if (!d) return null;
33
+ return {
34
+ base: numberToAPY(d.base ?? 0),
35
+ crv: numberToAPY(d.crv ?? 0),
36
+ gear: numberToAPY(d.gear ?? 0),
37
+ gearPrice: d.gearPrice ?? 0
38
+ };
39
+ }
40
+ function parseNetworkApy(apyResp, poolResp) {
41
+ const baseAPYList = {};
42
+ const extraCollateralAPYList = {};
43
+ const basePointsList = {};
44
+ const extraCollateralPointsList = {};
45
+ const tokenExtraRewardsList = {};
46
+ const apyData = apyResp?.status === "ok" ? apyResp.data : void 0;
47
+ for (const d of apyData ?? []) {
48
+ const tokenAddress = d.address.toLowerCase();
49
+ const tokenSymbol = d.symbol;
50
+ const apy = d.rewards.apy?.[0];
51
+ if (apy) {
52
+ baseAPYList[tokenAddress] = numberToAPY(apy.value ?? 0);
53
+ }
54
+ const points = d.rewards.points?.[0];
55
+ if (points) {
56
+ basePointsList[tokenAddress] = {
57
+ address: tokenAddress,
58
+ symbol: tokenSymbol,
59
+ rewards: points.rewards.map((p) => ({
60
+ ...p,
61
+ multiplier: p.multiplier === "soon" ? p.multiplier : BigInt(p.multiplier || 0)
62
+ })),
63
+ debtRewards: points.debtRewards?.map((p) => ({
64
+ ...p,
65
+ cm: (p.cm || "").toLowerCase(),
66
+ multiplier: p.multiplier === "soon" ? p.multiplier : BigInt(p.multiplier || 0)
67
+ }))
68
+ };
69
+ }
70
+ const extraRewards = d.rewards.extraRewards;
71
+ if (extraRewards && extraRewards.length > 0) {
72
+ tokenExtraRewardsList[tokenAddress] = extraRewards.map((r) => ({
73
+ address: tokenAddress,
74
+ symbol: r.rewardSymbol,
75
+ rewardToken: r.rewardToken.toLowerCase(),
76
+ rewardSymbol: r.rewardSymbol,
77
+ token: r.rewardToken.toLowerCase(),
78
+ finished: BigInt(r.finished || 0),
79
+ duration: BigInt(r.duration || 0),
80
+ reward: BigInt(r.reward || 0),
81
+ balance: BigInt(r.balance || 0)
82
+ }));
83
+ }
84
+ const ecApy = d.rewards.extraCollateralAPY;
85
+ if (ecApy && ecApy.length > 0) {
86
+ for (const ea of ecApy) {
87
+ const pool = ea.pool.toLowerCase();
88
+ if (!extraCollateralAPYList[pool]) extraCollateralAPYList[pool] = {};
89
+ extraCollateralAPYList[pool][tokenAddress] = {
90
+ ...ea,
91
+ address: tokenAddress,
92
+ symbol: tokenSymbol,
93
+ pool,
94
+ value: numberToAPY(ea.value ?? 0)
95
+ };
96
+ }
97
+ }
98
+ const ecPoints = d.rewards.extraCollateralPoints;
99
+ if (ecPoints && ecPoints.length > 0) {
100
+ for (const ea of ecPoints) {
101
+ const pool = ea.pool.toLowerCase();
102
+ if (!extraCollateralPointsList[pool])
103
+ extraCollateralPointsList[pool] = {};
104
+ extraCollateralPointsList[pool][tokenAddress] = {
105
+ address: tokenAddress,
106
+ symbol: tokenSymbol,
107
+ rewards: ea.rewards.map((p) => ({
108
+ ...p,
109
+ multiplier: p.multiplier === "soon" ? p.multiplier : BigInt(p.multiplier || 0)
110
+ })),
111
+ debtRewards: ea.debtRewards?.map((p) => ({
112
+ ...p,
113
+ cm: (p.cm || "").toLowerCase(),
114
+ multiplier: p.multiplier === "soon" ? p.multiplier : BigInt(p.multiplier || 0)
115
+ }))
116
+ };
117
+ }
118
+ }
119
+ }
120
+ const poolRewardsList = {};
121
+ const poolExternalAPYList = {};
122
+ const poolExtraAPYList = {};
123
+ const poolData = poolResp?.status === "ok" ? poolResp.data : void 0;
124
+ for (const r of poolData ?? []) {
125
+ const pool = (r.pool || "").toLowerCase();
126
+ const points = r.rewards.points;
127
+ if (points && points.length > 0) {
128
+ poolRewardsList[pool] = points.map((p) => ({
129
+ ...p,
130
+ token: p.token.toLowerCase(),
131
+ pool,
132
+ amount: BigInt(p.amount || 0)
133
+ }));
134
+ }
135
+ const externalAPY = r.rewards.externalAPY;
136
+ if (externalAPY && externalAPY.length > 0) {
137
+ poolExternalAPYList[pool] = externalAPY.map((ex) => ({ ...ex, pool }));
138
+ }
139
+ const extraAPY = r.rewards.extraAPY;
140
+ if (extraAPY && extraAPY.length > 0) {
141
+ poolExtraAPYList[extraAPY[0].token.toLowerCase()] = extraAPY.map((ex) => ({
142
+ ...ex,
143
+ token: ex.token.toLowerCase(),
144
+ rewardToken: ex.rewardToken.toLowerCase()
145
+ }));
146
+ }
147
+ }
148
+ const allResponses = [apyResp, poolResp];
149
+ const allErrors = allResponses.filter((r) => r?.status === "error");
150
+ if (allResponses.length > 0 && allErrors.length === allResponses.length) {
151
+ return void 0;
152
+ }
153
+ return {
154
+ apyList: Object.keys(baseAPYList).length > 0 ? baseAPYList : void 0,
155
+ extraCollateralAPYList: Object.keys(extraCollateralAPYList).length > 0 ? extraCollateralAPYList : void 0,
156
+ pointsList: Object.keys(basePointsList).length > 0 ? basePointsList : void 0,
157
+ extraCollateralPointsList: Object.keys(extraCollateralPointsList).length > 0 ? extraCollateralPointsList : void 0,
158
+ poolRewardsList: Object.keys(poolRewardsList).length > 0 ? poolRewardsList : void 0,
159
+ tokenExtraRewardsList: Object.keys(tokenExtraRewardsList).length > 0 ? tokenExtraRewardsList : void 0,
160
+ poolExternalAPYList: Object.keys(poolExternalAPYList).length > 0 ? poolExternalAPYList : void 0,
161
+ poolExtraAPYList: Object.keys(poolExtraAPYList).length > 0 ? poolExtraAPYList : void 0
162
+ };
163
+ }
164
+ // Annotate the CommonJS export names for ESM import in node:
165
+ 0 && (module.exports = {
166
+ numberToAPY,
167
+ parseGearStats,
168
+ parseNetworkApy
169
+ });
@@ -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 constants_exports = {};
20
+ __export(constants_exports, {
21
+ APY_STATE_CACHE_URL: () => APY_STATE_CACHE_URL,
22
+ DEFAULT_APY_INTERVAL_MS: () => DEFAULT_APY_INTERVAL_MS
23
+ });
24
+ module.exports = __toCommonJS(constants_exports);
25
+ const APY_STATE_CACHE_URL = "https://state-cache.gearbox.foundation/apy-server/latest.json";
26
+ const DEFAULT_APY_INTERVAL_MS = 10 * 60 * 1e3;
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ APY_STATE_CACHE_URL,
30
+ DEFAULT_APY_INTERVAL_MS
31
+ });
@@ -15,10 +15,20 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
16
  var pools_history_exports = {};
17
17
  module.exports = __toCommonJS(pools_history_exports);
18
- __reExport(pools_history_exports, require("./Pools7DAgoPlugin.js"), module.exports);
18
+ __reExport(pools_history_exports, require("./ApyPlugin.js"), module.exports);
19
+ __reExport(pools_history_exports, require("./apy-cache.js"), module.exports);
20
+ __reExport(pools_history_exports, require("./apy-parser.js"), module.exports);
21
+ __reExport(pools_history_exports, require("./constants.js"), module.exports);
22
+ __reExport(pools_history_exports, require("./pool-apy-types.js"), module.exports);
23
+ __reExport(pools_history_exports, require("./pool-apy-utils.js"), module.exports);
19
24
  __reExport(pools_history_exports, require("./types.js"), module.exports);
20
25
  // Annotate the CommonJS export names for ESM import in node:
21
26
  0 && (module.exports = {
22
- ...require("./Pools7DAgoPlugin.js"),
27
+ ...require("./ApyPlugin.js"),
28
+ ...require("./apy-cache.js"),
29
+ ...require("./apy-parser.js"),
30
+ ...require("./constants.js"),
31
+ ...require("./pool-apy-types.js"),
32
+ ...require("./pool-apy-utils.js"),
23
33
  ...require("./types.js")
24
34
  });
@@ -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 pool_apy_types_exports = {};
16
+ module.exports = __toCommonJS(pool_apy_types_exports);