impermax-sdk 2.1.48 → 2.1.49

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.
@@ -54,7 +54,7 @@ export default class OffchainLendingPool {
54
54
  isBlacklisted(): Promise<boolean>;
55
55
  isLowTVL(): Promise<boolean>;
56
56
  isHighTVL(): Promise<boolean>;
57
- isStable(): boolean;
57
+ isStable(): Promise<boolean>;
58
58
  getLendingPoolVersion(): LendingPoolVersion;
59
59
  getTotalBorrowsUSD(): Promise<number>;
60
60
  getUniswapV2PairAddress(): Promise<Address>;
@@ -185,7 +185,7 @@ class OffchainLendingPool {
185
185
  getAmm() {
186
186
  var _a, _b, _c;
187
187
  return __awaiter(this, void 0, void 0, function* () {
188
- const lendingPoolData = yield this.getLendingPoolData();
188
+ const lendingPoolData = (yield this.getLendingPoolData());
189
189
  // TODO: this properly
190
190
  const pairFactory = (_b = (_a = lendingPoolData.pair) === null || _a === void 0 ? void 0 : _a.uniswapV2Factory) !== null && _b !== void 0 ? _b : (_c = lendingPoolData.nftlp) === null || _c === void 0 ? void 0 : _c.dexFactory;
191
191
  return (0, amms_1.getAmmByFactory)(this.offchain.network, pairFactory);
@@ -252,7 +252,7 @@ class OffchainLendingPool {
252
252
  const [supply0USD, supply1USD, totalBalanceUSD] = yield Promise.all([
253
253
  this.getBorrowableA().getTotalBalanceUSD(),
254
254
  this.getBorrowableB().getTotalBalanceUSD(),
255
- this.getCollateral().getTotalBalanceUSD()
255
+ this.getCollateral().getTotalBalanceUSD(),
256
256
  ]);
257
257
  if (supply0USD && supply1USD && totalBalanceUSD)
258
258
  return supply0USD + supply1USD + totalBalanceUSD;
@@ -280,12 +280,21 @@ class OffchainLendingPool {
280
280
  return false;
281
281
  });
282
282
  }
283
- // WARN: If V3 supports multiple pool types, then need more robust way to check if is stable or not
283
+ // Stable is defined if any following condition is met:
284
+ // - Both tokens are stables
285
+ // - factory type is "7" (ie. SOL_STABLE)
284
286
  isStable() {
285
- const factoryType = Number(this.factory);
286
- if (factoryType === 7)
287
- return true;
288
- return false;
287
+ return __awaiter(this, void 0, void 0, function* () {
288
+ const [stables, token0, token1] = yield Promise.all([
289
+ this.getOffchain().getAPRHelper().getAllStablecoins(),
290
+ this.getBorrowableA().getSymbol(),
291
+ this.getBorrowableB().getSymbol(),
292
+ ]);
293
+ const bothStable = stables.includes(token0) && stables.includes(token1);
294
+ if (bothStable || this.factory === "7")
295
+ return true;
296
+ return false;
297
+ });
289
298
  }
290
299
  // Versions Specfics
291
300
  getLendingPoolVersion() {
@@ -13,14 +13,16 @@ export type LlamaChainChart = {
13
13
  }[];
14
14
  }[];
15
15
  export default class OffchainAPRHelper {
16
- private llamaAllPools;
17
16
  private initialized;
18
- private chainTvls;
17
+ private llamaAllPools;
18
+ private chainTvlCharts;
19
+ private protocolTvlChart;
19
20
  private tvlInitialized;
21
+ private chainTvls;
20
22
  private chainsTotalSupplied;
21
23
  private totalSuppliedInitialized;
22
- private chainTvlCharts;
23
- private protocolTvlChart;
24
+ private stablecoins;
25
+ private stablecoinsInitialized;
24
26
  private readonly blacklistedProjects;
25
27
  offchainMultichain: OffchainMultichain;
26
28
  constructor(offchainMultichain: OffchainMultichain);
@@ -43,4 +45,6 @@ export default class OffchainAPRHelper {
43
45
  getImpermaxTotalSupplied(): Promise<number>;
44
46
  getProtocolTvlChart(): Promise<LlamaTvlChart>;
45
47
  getChainTvlChart(chain: Networks): Promise<LlamaTvlChart>;
48
+ private initializeStablecoins;
49
+ getAllStablecoins(): Promise<string[]>;
46
50
  }
@@ -35,18 +35,24 @@ const LlamaChains = {
35
35
  // Class to get the APR from DefiLlama directly, only makes 1 call to api and caches all pools
36
36
  class OffchainAPRHelper {
37
37
  constructor(offchainMultichain) {
38
- this.llamaAllPools = {};
38
+ // Llama Yields
39
39
  this.initialized = null;
40
- this.chainTvls = {};
40
+ this.llamaAllPools = {};
41
+ // Chain Charts
42
+ this.chainTvlCharts = {};
43
+ this.protocolTvlChart = [];
44
+ // Chain TVLs
41
45
  this.tvlInitialized = null;
46
+ this.chainTvls = {};
47
+ // Chain Total Supplied
42
48
  this.chainsTotalSupplied = {};
43
49
  this.totalSuppliedInitialized = null;
44
- // Charts
45
- this.chainTvlCharts = {};
46
- this.protocolTvlChart = [];
50
+ // Misc.
51
+ this.stablecoins = [];
52
+ this.stablecoinsInitialized = null;
47
53
  this.blacklistedProjects = new Set([
48
54
  "extra-finance",
49
- "beefy"
55
+ "beefy",
50
56
  ]);
51
57
  this.offchainMultichain = offchainMultichain;
52
58
  }
@@ -57,6 +63,8 @@ class OffchainAPRHelper {
57
63
  this.tvlInitialized = null;
58
64
  this.chainsTotalSupplied = {};
59
65
  this.totalSuppliedInitialized = null;
66
+ this.stablecoins = [];
67
+ this.stablecoinsInitialized = null;
60
68
  }
61
69
  // Blacklist certain projects which might report same pool as dex (aggregators, etc.)
62
70
  // Reason we need this is that we want the DEX APR and not the APR of other projects
@@ -123,9 +131,10 @@ class OffchainAPRHelper {
123
131
  return __awaiter(this, void 0, void 0, function* () {
124
132
  try {
125
133
  const response = yield fetch("https://yields.llama.fi/poolsBorrow").then((i) => i.json());
126
- const impermaxPools = response.data.filter((i) => i.project === 'impermax-finance');
134
+ const impermaxPools = response.data.filter((i) => i.project === "impermax-finance");
127
135
  this.chainsTotalSupplied = impermaxPools.reduce((acc, pool) => {
128
- acc[pool.chain.toLowerCase()] = (acc[pool.chain.toLowerCase()] || 0) + pool.totalSupplyUsd;
136
+ acc[pool.chain.toLowerCase()] =
137
+ (acc[pool.chain.toLowerCase()] || 0) + pool.totalSupplyUsd;
129
138
  return acc;
130
139
  }, {});
131
140
  }
@@ -191,7 +200,7 @@ class OffchainAPRHelper {
191
200
  // Get or initialize the tvl for all chains
192
201
  const [llamaTvls, totalSuppliedYields] = yield Promise.all([
193
202
  this.getLlamaTvls(),
194
- this.getChainsTotalSupplied()
203
+ this.getChainsTotalSupplied(),
195
204
  ]);
196
205
  const llamaChain = LlamaChains[chain];
197
206
  if (!llamaChain)
@@ -249,5 +258,26 @@ class OffchainAPRHelper {
249
258
  return this.chainTvlCharts[llamaChain];
250
259
  });
251
260
  }
261
+ initializeStablecoins() {
262
+ return __awaiter(this, void 0, void 0, function* () {
263
+ try {
264
+ const response = yield fetch("https://stablecoins.llama.fi/stablecoins").then((i) => i.json());
265
+ this.stablecoins = response.peggedAssets.map((i) => i.symbol);
266
+ }
267
+ catch (err) {
268
+ console.log("Error getting stablecoins data: ", err);
269
+ }
270
+ });
271
+ }
272
+ // Other helpful defillama functions
273
+ // Get a list of stablecoins
274
+ getAllStablecoins() {
275
+ return __awaiter(this, void 0, void 0, function* () {
276
+ if (!this.stablecoinsInitialized)
277
+ this.stablecoinsInitialized = this.initializeStablecoins();
278
+ yield this.stablecoinsInitialized;
279
+ return this.stablecoins;
280
+ });
281
+ }
252
282
  }
253
283
  exports.default = OffchainAPRHelper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.48",
3
+ "version": "2.1.49",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",