impermax-sdk 1.2.129 → 1.2.131

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.
@@ -222,6 +222,18 @@ class OffchainLendingPool {
222
222
  const apr = yield this.offchain.getAPRHelper().getLlamaAPR(uniswapV2Pair, this.offchain.network);
223
223
  if (apr > 0)
224
224
  return apr;
225
+ // Try shadow on Sonic network
226
+ const selAmm = yield this.getAmm();
227
+ if (this.offchain.network === types_1.Networks.Sonic && selAmm == amms_1.Amms.shadow) {
228
+ const shadowAPR = yield this.offchain.getAPRHelper().getShadowAPR(uniswapV2Pair, this.offchain.network);
229
+ if (shadowAPR > 0)
230
+ return shadowAPR;
231
+ }
232
+ else if (this.offchain.network == types_1.Networks.Linea && (selAmm == amms_1.Amms.nile || selAmm == amms_1.Amms.nileStable)) {
233
+ const nileAPR = yield this.offchain.getAPRHelper().getNileAPR(uniswapV2Pair, this.offchain.network);
234
+ if (nileAPR > 0)
235
+ return nileAPR;
236
+ }
225
237
  const [uniswapAPR, stakingAPR] = yield Promise.all([this.getUniswapAPR(), this.getStakingAPR()]);
226
238
  return uniswapAPR + stakingAPR;
227
239
  });
@@ -21,6 +21,10 @@ export default class OffchainAPRHelper {
21
21
  private totalSuppliedInitialized;
22
22
  private chainTvlCharts;
23
23
  private protocolTvlChart;
24
+ private shadowAllPools;
25
+ private shadowInitialized;
26
+ private nileAllPools;
27
+ private nileInitialized;
24
28
  private readonly blacklistedProjects;
25
29
  offchain: Offchain;
26
30
  constructor(offchain: Offchain);
@@ -29,10 +33,16 @@ export default class OffchainAPRHelper {
29
33
  private initializeYields;
30
34
  private initializeTvls;
31
35
  private initializePoolsBorrow;
36
+ private initializeShadowPools;
37
+ private initializeNilePools;
32
38
  private getLlamaYields;
33
39
  private getLlamaTvls;
34
40
  private getChainsTotalSupplied;
41
+ private getShadowPools;
42
+ private getNilePools;
35
43
  getLlamaAPR(pool: Address, chain: Networks): Promise<number>;
44
+ getShadowAPR(pool: Address, chain: Networks): Promise<number>;
45
+ getNileAPR(pool: Address, chain: Networks): Promise<number>;
36
46
  getLlamaTvlAndBorrows(chain: Networks): Promise<{
37
47
  tvl: number;
38
48
  borrowed: number;
@@ -47,10 +47,14 @@ class OffchainAPRHelper {
47
47
  // Charts
48
48
  this.chainTvlCharts = {};
49
49
  this.protocolTvlChart = [];
50
+ this.shadowAllPools = {};
51
+ this.shadowInitialized = null;
52
+ this.nileAllPools = {};
53
+ this.nileInitialized = null;
50
54
  this.blacklistedProjects = new Set([
51
55
  "extra-finance",
52
56
  "beefy",
53
- "impermax-finance"
57
+ "impermax-finance",
54
58
  ]);
55
59
  this.offchain = offchain;
56
60
  }
@@ -127,9 +131,10 @@ class OffchainAPRHelper {
127
131
  return __awaiter(this, void 0, void 0, function* () {
128
132
  try {
129
133
  const response = yield fetch("https://yields.llama.fi/poolsBorrow").then((i) => i.json());
130
- const impermaxPools = response.data.filter((i) => i.project === 'impermax-finance');
134
+ const impermaxPools = response.data.filter((i) => i.project === "impermax-finance");
131
135
  this.chainsTotalSupplied = impermaxPools.reduce((acc, pool) => {
132
- acc[pool.chain.toLowerCase()] = (acc[pool.chain.toLowerCase()] || 0) + pool.totalSupplyUsd;
136
+ acc[pool.chain.toLowerCase()] =
137
+ (acc[pool.chain.toLowerCase()] || 0) + pool.totalSupplyUsd;
133
138
  return acc;
134
139
  }, {});
135
140
  }
@@ -139,6 +144,42 @@ class OffchainAPRHelper {
139
144
  }
140
145
  });
141
146
  }
147
+ initializeShadowPools() {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ try {
150
+ const response = yield fetch("https://api.shadow.so/mixed-pairs").then((i) => i.json());
151
+ this.shadowAllPools = response.pairs.reduce((acc, pool) => {
152
+ acc[pool.id.toLowerCase()] = {
153
+ lpApr: pool.lpApr
154
+ };
155
+ return acc;
156
+ }, {});
157
+ }
158
+ catch (err) {
159
+ console.warn("Shadow API down?");
160
+ this.shadowAllPools = {};
161
+ }
162
+ });
163
+ }
164
+ initializeNilePools() {
165
+ return __awaiter(this, void 0, void 0, function* () {
166
+ try {
167
+ const response = yield fetch("https://nile-api-production.up.railway.app/mixed-pairs").then((i) => i.json());
168
+ this.nileAllPools = response.pairs
169
+ .filter((pair) => pair.symbol.includes("vAMM-"))
170
+ .reduce((acc, pool) => {
171
+ acc[pool.id] = {
172
+ lpApr: pool.lpApr
173
+ };
174
+ return acc;
175
+ }, {});
176
+ }
177
+ catch (err) {
178
+ console.warn("Shadow API down?");
179
+ this.shadowAllPools = {};
180
+ }
181
+ });
182
+ }
142
183
  getLlamaYields() {
143
184
  return __awaiter(this, void 0, void 0, function* () {
144
185
  // First call initializes
@@ -167,6 +208,22 @@ class OffchainAPRHelper {
167
208
  return this.chainsTotalSupplied;
168
209
  });
169
210
  }
211
+ getShadowPools() {
212
+ return __awaiter(this, void 0, void 0, function* () {
213
+ if (!this.shadowInitialized)
214
+ this.shadowInitialized = this.initializeShadowPools();
215
+ yield this.shadowInitialized;
216
+ return this.shadowAllPools;
217
+ });
218
+ }
219
+ getNilePools() {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ if (!this.nileInitialized)
222
+ this.nileInitialized = this.initializeNilePools();
223
+ yield this.nileInitialized;
224
+ return this.nileAllPools;
225
+ });
226
+ }
170
227
  // ---------------- Getters ---------------- //
171
228
  getLlamaAPR(pool, chain) {
172
229
  var _a;
@@ -185,12 +242,42 @@ class OffchainAPRHelper {
185
242
  return apy || 0;
186
243
  });
187
244
  }
245
+ // Shadow APRs for Shadow on Sonic chain only
246
+ getShadowAPR(pool, chain) {
247
+ var _a;
248
+ return __awaiter(this, void 0, void 0, function* () {
249
+ // Guard for Sonic network only (for now..)
250
+ if (chain !== types_1.Networks.Sonic)
251
+ return 0;
252
+ // Get or initialize the Shadow pools
253
+ const shadowPools = yield this.getShadowPools();
254
+ // `initializeShadowPools` keys by pool address
255
+ // Convert to decimals to match `getUniswapAPR` and `getStakingAPR`
256
+ const apy = ((_a = shadowPools[pool.toLowerCase()]) === null || _a === void 0 ? void 0 : _a.lpApr) / 100;
257
+ return apy || 0;
258
+ });
259
+ }
260
+ // Nile APRs for Nile on Linea chain only
261
+ getNileAPR(pool, chain) {
262
+ var _a;
263
+ return __awaiter(this, void 0, void 0, function* () {
264
+ // Guard for Sonic network only (for now..)
265
+ if (chain !== types_1.Networks.Linea)
266
+ return 0;
267
+ // Get or initialize the Nile pools
268
+ const nilePools = yield this.getNilePools();
269
+ // `initializeNilePools` keys by pool address
270
+ // Convert to decimals to match `getUniswapAPR` and `getStakingAPR`
271
+ const apy = (_a = nilePools[pool.toLowerCase()]) === null || _a === void 0 ? void 0 : _a.lpApr;
272
+ return apy || 0;
273
+ });
274
+ }
188
275
  getLlamaTvlAndBorrows(chain) {
189
276
  return __awaiter(this, void 0, void 0, function* () {
190
277
  // Get or initialize the tvl for all chains
191
278
  const [llamaTvls, totalSuppliedYields] = yield Promise.all([
192
279
  this.getLlamaTvls(),
193
- this.getChainsTotalSupplied()
280
+ this.getChainsTotalSupplied(),
194
281
  ]);
195
282
  const llamaChain = LlamaChains[chain];
196
283
  if (!llamaChain)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "1.2.129",
3
+ "version": "1.2.131",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",