@gearbox-protocol/sdk 14.0.0-next.1 → 14.0.0-next.2

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 (38) hide show
  1. package/dist/cjs/plugins/apy/ApyPlugin.js +266 -0
  2. package/dist/cjs/plugins/apy/apy-cache.js +120 -0
  3. package/dist/cjs/plugins/apy/apy-parser.js +169 -0
  4. package/dist/cjs/plugins/{pools-history/index.js → apy/constants.js} +14 -7
  5. package/dist/cjs/plugins/apy/index.js +34 -0
  6. package/dist/cjs/plugins/apy/pool-apy-types.js +16 -0
  7. package/dist/cjs/plugins/apy/pool-apy-utils.js +141 -0
  8. package/dist/cjs/rewards/rewards/extra-apy.js +10 -8
  9. package/dist/esm/plugins/apy/ApyPlugin.js +255 -0
  10. package/dist/esm/plugins/apy/apy-cache.js +86 -0
  11. package/dist/esm/plugins/apy/apy-parser.js +143 -0
  12. package/dist/esm/plugins/apy/constants.js +6 -0
  13. package/dist/esm/plugins/apy/index.js +7 -0
  14. package/dist/esm/plugins/apy/pool-apy-utils.js +113 -0
  15. package/dist/esm/plugins/apy/types.js +0 -0
  16. package/dist/esm/rewards/rewards/extra-apy.js +10 -8
  17. package/dist/types/src/plugins/apy/ApyPlugin.d.ts +46 -0
  18. package/dist/types/src/plugins/apy/apy-cache.d.ts +28 -0
  19. package/dist/types/src/plugins/apy/apy-parser.d.ts +5 -0
  20. package/dist/types/src/plugins/apy/constants.d.ts +2 -0
  21. package/dist/types/src/plugins/apy/index.d.ts +7 -0
  22. package/dist/types/src/plugins/apy/pool-apy-types.d.ts +41 -0
  23. package/dist/types/src/plugins/apy/pool-apy-utils.d.ts +73 -0
  24. package/dist/types/src/plugins/apy/types.d.ts +37 -0
  25. package/dist/types/src/rewards/rewards/api.d.ts +10 -1
  26. package/dist/types/src/rewards/rewards/common.d.ts +0 -10
  27. package/dist/types/src/rewards/rewards/extra-apy.d.ts +4 -6
  28. package/package.json +1 -1
  29. package/dist/cjs/plugins/pools-history/Pools7DAgoPlugin.js +0 -108
  30. package/dist/esm/plugins/pools-history/Pools7DAgoPlugin.js +0 -90
  31. package/dist/esm/plugins/pools-history/index.js +0 -2
  32. package/dist/types/src/plugins/pools-history/Pools7DAgoPlugin.d.ts +0 -20
  33. package/dist/types/src/plugins/pools-history/index.d.ts +0 -2
  34. package/dist/types/src/plugins/pools-history/types.d.ts +0 -9
  35. /package/dist/cjs/plugins/{pools-history → apy}/package.json +0 -0
  36. /package/dist/cjs/plugins/{pools-history → apy}/types.js +0 -0
  37. /package/dist/esm/plugins/{pools-history → apy}/package.json +0 -0
  38. /package/dist/esm/plugins/{pools-history/types.js → apy/pool-apy-types.js} +0 -0
@@ -0,0 +1,266 @@
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
+ class ApyPlugin extends import_sdk.BasePlugin {
35
+ #apyUrl;
36
+ #cacheTtlMs;
37
+ #pools7DAgo;
38
+ #apySnapshot;
39
+ constructor(loadOnAttach = false, options) {
40
+ super(loadOnAttach);
41
+ this.#apyUrl = options?.apyUrl ?? import_constants.APY_STATE_CACHE_URL;
42
+ this.#cacheTtlMs = options?.cacheTtlMs ?? import_constants.DEFAULT_APY_INTERVAL_MS;
43
+ }
44
+ // ---------------------------------------------------------------------------
45
+ // Load — single entry point for all data (on-chain + state-cache)
46
+ // ---------------------------------------------------------------------------
47
+ async load(force, loadOptions) {
48
+ if (!force && this.loaded) {
49
+ return this.state;
50
+ }
51
+ const targetBlock = this.sdk.currentBlock - import_sdk.BLOCKS_PER_WEEK_BY_NETWORK[this.sdk.networkType];
52
+ const [marketCompressorAddress] = this.sdk.addressProvider.mustGetLatest(
53
+ import_sdk.AP_MARKET_COMPRESSOR,
54
+ import_sdk.VERSION_RANGE_310
55
+ );
56
+ this.#logger?.debug(
57
+ `loading pools 7d ago with market compressor ${marketCompressorAddress}`
58
+ );
59
+ const markets = this.sdk.marketRegister.markets;
60
+ const shouldLoadPools7DAgo = !this.#pools7DAgo || !!loadOptions?.loadPools7DAgo;
61
+ const [multicallResp, apySnapshot] = await Promise.all([
62
+ shouldLoadPools7DAgo ? this.client.multicall({
63
+ allowFailure: true,
64
+ contracts: markets.map(
65
+ (m) => ({
66
+ address: marketCompressorAddress,
67
+ abi: import_marketCompressor.marketCompressorAbi,
68
+ functionName: "getPoolState",
69
+ args: [m.pool.pool.address]
70
+ })
71
+ ),
72
+ blockNumber: targetBlock > 0n ? targetBlock : void 0,
73
+ batchSize: 0
74
+ }) : null,
75
+ this.#fetchApy()
76
+ ]);
77
+ if (multicallResp !== null) {
78
+ this.#pools7DAgo = new import_sdk.AddressMap(void 0, MAP_LABEL);
79
+ multicallResp.forEach((r, index) => {
80
+ const m = markets[index];
81
+ const cfg = m.configurator.address;
82
+ const pool = m.pool.pool.address;
83
+ if (r.status === "success") {
84
+ this.#pools7DAgo?.upsert(m.pool.pool.address, {
85
+ dieselRate: r.result.dieselRate,
86
+ pool
87
+ });
88
+ } else {
89
+ this.#logger?.error(
90
+ `failed to load pools 7d ago for market configurator ${this.labelAddress(cfg)} and pool ${this.labelAddress(pool)}: ${r.error}`
91
+ );
92
+ }
93
+ });
94
+ }
95
+ if (apySnapshot) {
96
+ this.#apySnapshot = apySnapshot;
97
+ }
98
+ return this.state;
99
+ }
100
+ get loaded() {
101
+ return !!this.#pools7DAgo && !!this.#apySnapshot;
102
+ }
103
+ // ---------------------------------------------------------------------------
104
+ // Accessors
105
+ // ---------------------------------------------------------------------------
106
+ /**
107
+ * @throws if plugin is not loaded
108
+ */
109
+ get pools7DAgo() {
110
+ if (!this.#pools7DAgo) {
111
+ throw new Error("apy plugin not loaded");
112
+ }
113
+ return this.#pools7DAgo;
114
+ }
115
+ /**
116
+ * @throws if plugin is not loaded
117
+ */
118
+ get apySnapshot() {
119
+ if (!this.#apySnapshot) {
120
+ throw new Error("apy plugin not loaded");
121
+ }
122
+ return this.#apySnapshot;
123
+ }
124
+ // ---------------------------------------------------------------------------
125
+ // Aggregated APY / points
126
+ // ---------------------------------------------------------------------------
127
+ /**
128
+ * Computes per-pool APY (current + 7d-ago) and points for all markets.
129
+ *
130
+ * @throws if plugin is not loaded
131
+ */
132
+ getPoolsAPY() {
133
+ if (!this.loaded) {
134
+ throw new Error("apy plugin not loaded");
135
+ }
136
+ const markets = this.sdk.marketRegister.markets;
137
+ const { apy } = this.apySnapshot;
138
+ const totalTokenBalances = {};
139
+ const poolPointsBase = apy.poolRewardsList && Object.keys(apy.poolRewardsList).length > 0 ? import_extra_apy.PoolPointsAPI.getPointsByPool({
140
+ poolRewards: apy.poolRewardsList,
141
+ totalTokenBalances,
142
+ pools: markets,
143
+ tokensList: this.sdk.tokensMeta
144
+ }) : {};
145
+ const data = {};
146
+ const data7DAgo = {};
147
+ const points = {};
148
+ for (const market of markets) {
149
+ const pool = market.pool.pool;
150
+ const poolAddr = pool.address.toLowerCase();
151
+ const underlyingLc = pool.underlying.toLowerCase();
152
+ const depositAPY = (0, import_formatter.rayToNumber)(pool.supplyRate) * Number(import_sdk.PERCENTAGE_DECIMALS);
153
+ const underlyingAPY = apy.apyList?.[underlyingLc] ?? apy.apyList?.[pool.underlying] ?? 0;
154
+ const lookupAddresses = this.#getExtraAPYLookupAddresses(poolAddr);
155
+ const extraAPY = (0, import_pool_apy_utils.getPoolExtraAPY)(lookupAddresses, apy.poolExtraAPYList);
156
+ const currentExternalList = apy.poolExternalAPYList?.[poolAddr];
157
+ const poolAPY = (0, import_pool_apy_utils.calculatePoolFullAPY)({
158
+ depositAPY,
159
+ underlyingAPY,
160
+ extraAPY,
161
+ currentExternalList
162
+ });
163
+ data[poolAddr] = poolAPY;
164
+ const pool7DAgo = this.#pools7DAgo?.get(poolAddr);
165
+ const supplyAPY7DAgo = pool7DAgo ? (0, import_pool_apy_utils.calculateSupplyApy7d)(
166
+ pool.dieselRate,
167
+ pool.supplyRate,
168
+ pool7DAgo.dieselRate
169
+ ) : void 0;
170
+ data7DAgo[poolAddr] = (0, import_pool_apy_utils.calculatePoolFullAPY7DAgo)({
171
+ supplyAPY7DAgo,
172
+ depositAPY,
173
+ poolAPY
174
+ });
175
+ const poolTokenMeta = this.sdk.tokensMeta.get(pool.underlying);
176
+ points[poolAddr] = (0, import_pool_apy_utils.calculatePoolPoints)({
177
+ poolTokenSymbol: poolTokenMeta?.symbol,
178
+ points: poolPointsBase[poolAddr],
179
+ tokensList: this.sdk.tokensMeta
180
+ });
181
+ }
182
+ return { data, data7DAgo, pointsBase: poolPointsBase, points };
183
+ }
184
+ // ---------------------------------------------------------------------------
185
+ // Plugin lifecycle
186
+ // ---------------------------------------------------------------------------
187
+ async syncState() {
188
+ await this.load();
189
+ }
190
+ stateHuman(_) {
191
+ return this.pools7DAgo.values().flatMap((p) => ({
192
+ address: p.pool,
193
+ version: this.version,
194
+ dieselRate: p.dieselRate
195
+ }));
196
+ }
197
+ get state() {
198
+ return {
199
+ pools7DAgo: this.pools7DAgo.asRecord(),
200
+ apySnapshot: this.apySnapshot
201
+ };
202
+ }
203
+ hydrate(state) {
204
+ this.#pools7DAgo = new import_sdk.AddressMap(
205
+ Object.entries(state.pools7DAgo),
206
+ MAP_LABEL
207
+ );
208
+ this.#apySnapshot = state.apySnapshot;
209
+ }
210
+ // ---------------------------------------------------------------------------
211
+ // Internal
212
+ // ---------------------------------------------------------------------------
213
+ async #fetchApy() {
214
+ try {
215
+ const cache = import_apy_cache.ApyOutputCache.get(
216
+ this.#apyUrl,
217
+ this.#cacheTtlMs,
218
+ this.#logger
219
+ );
220
+ const output = await cache.fetch();
221
+ if (!output) return void 0;
222
+ const chainData = output.chains[this.sdk.chainId];
223
+ if (!chainData) {
224
+ this.#logger?.debug(
225
+ `apy state-cache: no data for chainId ${this.sdk.chainId}`
226
+ );
227
+ return void 0;
228
+ }
229
+ const apy = (0, import_apy_parser.parseNetworkApy)(chainData.tokens, chainData.pools);
230
+ if (!apy) return void 0;
231
+ return {
232
+ apy,
233
+ gearStats: (0, import_apy_parser.parseGearStats)(output),
234
+ timestamp: output.timestamp
235
+ };
236
+ } catch (e) {
237
+ this.#logger?.error(e, "failed to fetch apy state-cache");
238
+ return void 0;
239
+ }
240
+ }
241
+ /**
242
+ * Collects addresses to look up in poolExtraAPYList for a given pool.
243
+ * Includes pool address (= diesel token) + any staked diesel token
244
+ * outputs discovered from zappers.
245
+ */
246
+ #getExtraAPYLookupAddresses(poolAddr) {
247
+ const addresses = [poolAddr];
248
+ try {
249
+ const zappers = this.sdk.marketRegister.poolZappers(poolAddr);
250
+ for (const z of zappers) {
251
+ if (!(0, import_hex.hexEq)(z.tokenOut.addr, poolAddr)) {
252
+ addresses.push(z.tokenOut.addr);
253
+ }
254
+ }
255
+ } catch {
256
+ }
257
+ return addresses;
258
+ }
259
+ get #logger() {
260
+ return this.logger;
261
+ }
262
+ }
263
+ // Annotate the CommonJS export names for ESM import in node:
264
+ 0 && (module.exports = {
265
+ ApyPlugin
266
+ });
@@ -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
+ });
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
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
+ };
6
10
  var __copyProps = (to, from, except, desc) => {
7
11
  if (from && typeof from === "object" || typeof from === "function") {
8
12
  for (let key of __getOwnPropNames(from))
@@ -11,14 +15,17 @@ var __copyProps = (to, from, except, desc) => {
11
15
  }
12
16
  return to;
13
17
  };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var pools_history_exports = {};
17
- module.exports = __toCommonJS(pools_history_exports);
18
- __reExport(pools_history_exports, require("./Pools7DAgoPlugin.js"), module.exports);
19
- __reExport(pools_history_exports, require("./types.js"), module.exports);
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;
20
27
  // Annotate the CommonJS export names for ESM import in node:
21
28
  0 && (module.exports = {
22
- ...require("./Pools7DAgoPlugin.js"),
23
- ...require("./types.js")
29
+ APY_STATE_CACHE_URL,
30
+ DEFAULT_APY_INTERVAL_MS
24
31
  });
@@ -0,0 +1,34 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var apy_exports = {};
17
+ module.exports = __toCommonJS(apy_exports);
18
+ __reExport(apy_exports, require("./ApyPlugin.js"), module.exports);
19
+ __reExport(apy_exports, require("./apy-cache.js"), module.exports);
20
+ __reExport(apy_exports, require("./apy-parser.js"), module.exports);
21
+ __reExport(apy_exports, require("./constants.js"), module.exports);
22
+ __reExport(apy_exports, require("./pool-apy-types.js"), module.exports);
23
+ __reExport(apy_exports, require("./pool-apy-utils.js"), module.exports);
24
+ __reExport(apy_exports, require("./types.js"), module.exports);
25
+ // Annotate the CommonJS export names for ESM import in node:
26
+ 0 && (module.exports = {
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"),
33
+ ...require("./types.js")
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);