impermax-sdk 1.2.76 → 1.2.77

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.
@@ -169,6 +169,11 @@ class Offchain {
169
169
  // Crosschain TVL Data
170
170
  getCrossChainTVL() {
171
171
  return __awaiter(this, void 0, void 0, function* () {
172
+ // Try llama
173
+ const llamaTvl = yield this.getAPRHelper().getImpermaxTvl();
174
+ if (llamaTvl)
175
+ return llamaTvl;
176
+ // Fallback to subgraph
172
177
  const tvlData = yield this.getTvlData();
173
178
  return tvlData.crossChainTVLUSD;
174
179
  });
@@ -188,6 +193,11 @@ class Offchain {
188
193
  // This chain TVL Data
189
194
  getTotalValueLocked() {
190
195
  return __awaiter(this, void 0, void 0, function* () {
196
+ // Try llama
197
+ const { tvl } = yield this.getAPRHelper().getLlamaTvlAndBorrows(this.network);
198
+ if (tvl)
199
+ return tvl;
200
+ // Gallback to subgraph
191
201
  const tvlData = yield this.getTvlData();
192
202
  return tvlData.totalBalanceUSD;
193
203
  });
@@ -4,6 +4,8 @@ export default class OffchainPriceHelper {
4
4
  offchain: Offchain;
5
5
  private subgraphTokensPrice;
6
6
  private debankTokensPrice;
7
+ private coingeckoInitialized;
8
+ private coingeckoTokenPrices;
7
9
  constructor(offchain: Offchain);
8
10
  cleanCache(): void;
9
11
  private addPriceIfMissing;
@@ -11,6 +13,7 @@ export default class OffchainPriceHelper {
11
13
  getSubgraphTokensPrice(): Promise<{
12
14
  [key in Address]: number | undefined;
13
15
  }>;
16
+ private getAllCoingeckoPrices;
14
17
  private getCoingeckoTokenPrice;
15
18
  private getDexscreenerTokenPrice;
16
19
  private getFantomTokenPrice;
@@ -38,7 +38,6 @@ const coingecko_ids = {
38
38
  "0x1a2fcb585b327fadec91f55d45829472b15f17a4": "tokan",
39
39
  "0x188b158caf5ea252012dbd6030afc030329c4961": "zen",
40
40
  "0xf610a9dfb7c89644979b4a0f27063e9e7d7cda32": "wrapped-steth",
41
- "0x74ccbe53f77b08632ce0cb91d3a545bf6b8e0979": "fantom-bomb",
42
41
  "0xa25b25548b4c98b0c7d3d27dca5d5ca743d68b7f": "wrapped-rseth",
43
42
  "0x80137510979822322193fc997d400d5a6c747bf7": "stakestone-ether",
44
43
  "0x2b6a85cd35d15691357eea61d88cb3f401a92fc3": "surveyor-dao",
@@ -79,6 +78,8 @@ const dexscreener_ids = {
79
78
  "0x994ac01750047B9d35431a7Ae4Ed312ee955E030": "base",
80
79
  // opxvelo on op
81
80
  "0xc38464250f51123078bbd7ea574e185f6623d037": "optimism",
81
+ // fantom-bomb on scroll (removed from coingecko)
82
+ "0x6b6882f7642ee1c15f12b51f1a4988b3e7e29f5c": "scroll",
82
83
  };
83
84
  const fantom_ids = {
84
85
  // uponly on ftm
@@ -115,7 +116,9 @@ const fantom_ids = {
115
116
  "0x5deb27e51dbeef691ba1175a2e563870499c2acb": "fantom"
116
117
  };
117
118
  class OffchainPriceHelper {
119
+ ;
118
120
  constructor(offchain) {
121
+ this.coingeckoInitialized = null;
119
122
  this.offchain = offchain;
120
123
  this.debankTokensPrice = {};
121
124
  }
@@ -164,23 +167,42 @@ class OffchainPriceHelper {
164
167
  return this.subgraphTokensPrice;
165
168
  });
166
169
  }
167
- getCoingeckoTokenPrice(tokenAddress) {
170
+ getAllCoingeckoPrices() {
168
171
  return __awaiter(this, void 0, void 0, function* () {
172
+ // Remove duplicates just in case, get the unique coingecko token ids
173
+ const tokenIds = Object.values(coingecko_ids);
174
+ const uniqueIds = [...new Set(tokenIds)].join(",");
169
175
  try {
170
- const tokenId = coingecko_ids[tokenAddress];
171
- const response = yield fetch("https://api.coingecko.com/api/v3/simple/price?ids=" + tokenId + "&vs_currencies=usd");
176
+ // Get all token prices from gecko
177
+ const response = yield fetch("https://api.coingecko.com/api/v3/simple/price?ids=" + uniqueIds + "&vs_currencies=usd");
172
178
  if (response.status != 200)
173
- return 0;
179
+ return;
174
180
  const data = yield response.json();
175
181
  if (!data)
176
- return 0;
177
- return data[tokenId].usd ? data[tokenId].usd : 0;
182
+ return;
183
+ // Record of: { 'address_0': price, 'address_1': price }
184
+ this.coingeckoTokenPrices = Object.keys(coingecko_ids).reduce((prices, address) => {
185
+ var _a;
186
+ const tokenId = coingecko_ids[address];
187
+ prices[address] = ((_a = data[tokenId]) === null || _a === void 0 ? void 0 : _a.usd) || 0;
188
+ return prices;
189
+ }, {});
178
190
  }
179
- catch (_a) {
180
- return 0;
191
+ catch (err) {
192
+ console.log("Gecko API fail");
193
+ this.coingeckoTokenPrices = {};
181
194
  }
182
195
  });
183
196
  }
197
+ getCoingeckoTokenPrice(tokenAddress) {
198
+ return __awaiter(this, void 0, void 0, function* () {
199
+ if (!this.coingeckoInitialized)
200
+ this.coingeckoInitialized = this.getAllCoingeckoPrices();
201
+ yield this.coingeckoInitialized;
202
+ const geckoPrice = this.coingeckoTokenPrices[tokenAddress];
203
+ return geckoPrice || 0;
204
+ });
205
+ }
184
206
  getDexscreenerTokenPrice(tokenAddress) {
185
207
  return __awaiter(this, void 0, void 0, function* () {
186
208
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "1.2.76",
3
+ "version": "1.2.77",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",