impermax-sdk 2.1.441 → 2.1.443

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.
@@ -34,7 +34,9 @@ exports.WHITELISTED_PAIRS = {
34
34
  "0x0b96755241DeAccc83BF8b4eda314d81905Cd7Bd",
35
35
  "0x4f667a0220EF7c1284C763c33eD86f9413a177B3",
36
36
  "0x375ff4a46eb1e75f702e9be411bf0ac96d8e55dd",
37
- "0x679d91d08eb980c6f1b69632eca139f006e4b914" // id/avax
37
+ "0x679d91d08eb980c6f1b69632eca139f006e4b914",
38
+ "0x237dC61F6346e931A0Ff8801D8cAB566cE1c7F94",
39
+ "0x03e92DF133Fa319e55D806687c46118072532433" // fbomb/usdc
38
40
  ],
39
41
  },
40
42
  [types_1.Networks.Moonriver]: {
@@ -55,6 +55,21 @@ export interface LendingPoolListParams {
55
55
  highTvl?: boolean;
56
56
  pairState?: PairState;
57
57
  }
58
+ export interface MultichainTvlData {
59
+ totalSuppliedUSD: number;
60
+ totalBorrowedUSD: number;
61
+ totalCollateralUSD: number;
62
+ }
63
+ declare enum TvlDataSources {
64
+ defillama = 0,
65
+ sdk = 1
66
+ }
67
+ export interface MultichainTvlParams {
68
+ networks?: Array<Networks>;
69
+ version?: LendingPoolVersion;
70
+ pairState?: PairState;
71
+ source?: TvlDataSources;
72
+ }
58
73
  export default class OffchainMultichain {
59
74
  #private;
60
75
  protected offchains: NetworkIndex<Offchain>;
@@ -80,11 +95,16 @@ export default class OffchainMultichain {
80
95
  getMultichainAccount(accountAddress: Address): OffchainMultichainAccount;
81
96
  getMultichainBorrowersList(params?: BorrowersListParams): Promise<OffchainAccount[]>;
82
97
  getActiveAmms(params?: LendingPoolListParams): Promise<Amms[]>;
83
- getTvlData(params?: LendingPoolListParams): Promise<{
84
- totalSuppliedUSD: number;
85
- totalBorrowedUSD: number;
86
- totalCollateralUSD: number;
87
- }>;
98
+ /** Gets TVL from defillama */
99
+ getDefillamaTvlData(params?: MultichainTvlParams): Promise<MultichainTvlData>;
100
+ /** Gets TVL from SDK. */
101
+ getSDKTvlData(params?: MultichainTvlParams): Promise<MultichainTvlData>;
102
+ /**
103
+ * Returns {@link MultichainTvlData}. Collateral is given by the SDK, while Total Supplied
104
+ * and Total Borrowed is given by max of SDK/Defillama
105
+ */
106
+ getTvlData(params?: MultichainTvlParams): Promise<MultichainTvlData>;
88
107
  getImpermaxTvlChart(network?: Networks): Promise<LlamaTvlChart>;
89
108
  getNetworkTokens(networks?: Networks[]): Promise<Token[]>;
90
109
  }
110
+ export {};
@@ -45,6 +45,11 @@ var LendingPoolListOrderBy;
45
45
  LendingPoolListOrderBy[LendingPoolListOrderBy["SUPPLY_APR"] = 3] = "SUPPLY_APR";
46
46
  LendingPoolListOrderBy[LendingPoolListOrderBy["LEVERAGED_APR"] = 4] = "LEVERAGED_APR";
47
47
  })(LendingPoolListOrderBy = exports.LendingPoolListOrderBy || (exports.LendingPoolListOrderBy = {}));
48
+ var TvlDataSources;
49
+ (function (TvlDataSources) {
50
+ TvlDataSources[TvlDataSources["defillama"] = 0] = "defillama";
51
+ TvlDataSources[TvlDataSources["sdk"] = 1] = "sdk";
52
+ })(TvlDataSources || (TvlDataSources = {}));
48
53
  // singleton class
49
54
  class OffchainMultichain {
50
55
  constructor() {
@@ -210,17 +215,23 @@ class OffchainMultichain {
210
215
  /*--------------------------------------------------------*
211
216
  * Protocol Data
212
217
  *--------------------------------------------------------*/
213
- async getTvlData(params = {}) {
214
- // 1. Try defillama first
218
+ //
219
+ // TVL DATA
220
+ //
221
+ /** Gets TVL from defillama */
222
+ async getDefillamaTvlData(params = {}) {
215
223
  try {
216
224
  // We cannot filter out llama tvl by pair state, but can filter by network
217
225
  const llamaTvlData = await this.getAPRHelper().getTvlData(params.networks);
218
226
  return llamaTvlData;
219
227
  }
220
228
  catch (err) {
221
- console.log("Failed to get TVL data from defillama, trying with SDK");
229
+ console.log("Failed to get TVL data from defillama");
222
230
  }
223
- // 2.. Try getting TVL data from SDK
231
+ return { totalCollateralUSD: 0, totalBorrowedUSD: 0, totalSuppliedUSD: 0 };
232
+ }
233
+ /** Gets TVL from SDK. */
234
+ async getSDKTvlData(params = {}) {
224
235
  try {
225
236
  const lendingPools = await this.getLendingPoolList(params);
226
237
  const results = await Promise.all(lendingPools.map(async (pool) => {
@@ -239,22 +250,50 @@ class OffchainMultichain {
239
250
  return {
240
251
  totalSuppliedUSD: acc.totalSuppliedUSD + val.suppliedUSD,
241
252
  totalBorrowedUSD: acc.totalBorrowedUSD + val.borrowedUSD,
242
- totalCollateralUSD: acc.totalCollateralUSD + val.collateralUSD
253
+ totalCollateralUSD: acc.totalCollateralUSD + val.collateralUSD,
243
254
  };
244
255
  }, { totalSuppliedUSD: 0, totalBorrowedUSD: 0, totalCollateralUSD: 0 });
245
- if ((tvlData.totalBorrowedUSD + tvlData.totalSuppliedUSD + tvlData.totalCollateralUSD) > 0)
246
- return tvlData;
256
+ return tvlData;
247
257
  }
248
258
  catch (err) {
249
- console.log("Failed to get TVL data natively");
259
+ console.log("Failed to get TVL data from SDK");
250
260
  }
251
261
  return { totalCollateralUSD: 0, totalBorrowedUSD: 0, totalSuppliedUSD: 0 };
252
262
  }
263
+ /**
264
+ * Returns {@link MultichainTvlData}. Collateral is given by the SDK, while Total Supplied
265
+ * and Total Borrowed is given by max of SDK/Defillama
266
+ */
267
+ async getTvlData(params = {}) {
268
+ const tvlData = {
269
+ totalSuppliedUSD: 0,
270
+ totalCollateralUSD: 0,
271
+ totalBorrowedUSD: 0
272
+ };
273
+ if (params.source === TvlDataSources.sdk)
274
+ return this.getSDKTvlData(params);
275
+ if (params.source === TvlDataSources.defillama)
276
+ return this.getDefillamaTvlData(params);
277
+ // Get both
278
+ const [llamaResult, sdkResult] = await Promise.allSettled([this.getDefillamaTvlData(params), this.getSDKTvlData(params)]);
279
+ const llamaTvl = llamaResult.status === 'fulfilled' ? llamaResult.value : tvlData;
280
+ const sdkTvl = sdkResult.status === 'fulfilled' ? sdkResult.value : tvlData;
281
+ const res0 = llamaTvl.totalCollateralUSD + llamaTvl.totalSuppliedUSD - llamaTvl.totalBorrowedUSD;
282
+ const res1 = sdkTvl.totalCollateralUSD + sdkTvl.totalSuppliedUSD - sdkTvl.totalBorrowedUSD;
283
+ // Return highest tvl of the two
284
+ return res0 > res1 ? llamaTvl : sdkTvl;
285
+ }
286
+ //
287
+ // CHARTS
288
+ //
253
289
  // Impermax daily TVL chart since deployment, optional to just get single chain data (~2021)
254
290
  async getImpermaxTvlChart(network) {
255
291
  const impermaxTvlChart = await this.getAPRHelper().getImpermaxTvlChart(network);
256
292
  return impermaxTvlChart;
257
293
  }
294
+ //
295
+ // ERC20 TOKENS
296
+ //
258
297
  async getNetworkTokens(networks) {
259
298
  const lendingPools = await this.getLendingPoolList({ networks });
260
299
  const tokenSet = new Set();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.441",
3
+ "version": "2.1.443",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",