impermax-sdk 1.2.151 → 1.2.152

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.
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Single endpoint for all factory subgraph token prices
3
+ */
4
+ export declare const PRICE_AGGREGATOR_API_URL = "https://price-aggregator-production.up.railway.app/api/tokens";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PRICE_AGGREGATOR_API_URL = void 0;
4
+ /**
5
+ * Single endpoint for all factory subgraph token prices
6
+ */
7
+ exports.PRICE_AGGREGATOR_API_URL = "https://price-aggregator-production.up.railway.app/api/tokens";
@@ -238,7 +238,7 @@ class OffchainBorrowable extends offchainPoolToken_1.default {
238
238
  return [];
239
239
  const rewards = [];
240
240
  for (const reward of farmingRewards) {
241
- const rewardPrice = await this.getOffchain().getPriceHelper().getDebankTokenPrice(reward.rewardToken);
241
+ const rewardPrice = await this.getOffchain().getPriceHelper().getTokenPrice(reward.rewardToken);
242
242
  rewards.push({
243
243
  APR: (0, utils_1.toAPR)((rewardPrice * reward.rewardRate) / totalBorrowedUSD),
244
244
  symbol: reward.rewardToken == "0x98878b06940ae243284ca214f92bb71a2b032b8a" ? "WMOVR" :
@@ -326,7 +326,7 @@ class OffchainBorrowable extends offchainPoolToken_1.default {
326
326
  // Token price getters
327
327
  async getTokenPriceFast(fallback = true) {
328
328
  let tokenAddress = await this.getUnderlyingAddress();
329
- let tokenPrices = await this.getOffchain().getPriceHelper().getSubgraphTokensPrice();
329
+ let tokenPrices = await this.getOffchain().getPriceHelper().offchainPriceHelperV1.getSubgraphTokensPrice();
330
330
  let tokenPrice = tokenPrices[tokenAddress];
331
331
  if (tokenPrice !== undefined && tokenPrice > 0)
332
332
  return tokenPrice;
@@ -334,7 +334,7 @@ class OffchainBorrowable extends offchainPoolToken_1.default {
334
334
  }
335
335
  async getTokenPriceAccurate() {
336
336
  let tokenAddress = await this.getUnderlyingAddress();
337
- return this.getOffchain().getPriceHelper().getDebankTokenPrice(tokenAddress);
337
+ return this.getOffchain().getPriceHelper().getTokenPrice(tokenAddress);
338
338
  }
339
339
  }
340
340
  exports.default = OffchainBorrowable;
@@ -92,7 +92,7 @@ class OffchainLendingPool {
92
92
  let rewardRate = parseFloat(reward.rewardRate);
93
93
  if (farm == farms_1.Farms.traderJoeV4)
94
94
  rewardRate = rewardRate * 0.45;
95
- const rewardPrice = await this.offchain.getPriceHelper().getDebankTokenPrice(reward.rewardsToken.id);
95
+ const rewardPrice = await this.offchain.getPriceHelper().getTokenPrice(reward.rewardsToken.id);
96
96
  rewards.push({
97
97
  APR: (0, utils_1.toAPR)((rewardPrice * rewardRate) / (stakedTotalSupply * underlyingLPPrice) * multiplier),
98
98
  symbol: reward.rewardsToken.symbol,
@@ -1,6 +1,6 @@
1
1
  import * as initializer from "./offchainInitializer";
2
2
  import OffchainLendingPool from "./lendingPool";
3
- import OffchainPriceHelper from "./offchainPriceHelper";
3
+ import OffchainPriceHelperV2 from "./offchainPriceHelperV2";
4
4
  import OffchainAPRHelper from "./offchainAPRHelper";
5
5
  import OffchainSolidexHelper from "./offchainSolidexHelper";
6
6
  import OffchainAccount from "./account";
@@ -22,7 +22,7 @@ export default class Offchain {
22
22
  protected lendingPools: LendingPoolIndex<OffchainLendingPool>;
23
23
  protected lendingVaults: AddressIndex<OffchainLendingVault>;
24
24
  protected accounts: AddressIndex<OffchainAccount>;
25
- protected priceHelper: OffchainPriceHelper;
25
+ protected priceHelper: OffchainPriceHelperV2;
26
26
  protected aprHelper: OffchainAPRHelper;
27
27
  protected solidexHelper: OffchainSolidexHelper;
28
28
  protected configManager: OffchainConfigManager;
@@ -43,7 +43,7 @@ export default class Offchain {
43
43
  getLendingPool(factory: Factory, pairAddress: Address): Promise<OffchainLendingPool>;
44
44
  getLendingVault(vaultAddress: Address): Promise<OffchainLendingVault>;
45
45
  getAccount(accountAddress: Address): OffchainAccount;
46
- getPriceHelper: () => OffchainPriceHelper;
46
+ getPriceHelper: () => OffchainPriceHelperV2;
47
47
  getSolidexHelper: () => OffchainSolidexHelper;
48
48
  getConfigManager: () => OffchainConfigManager;
49
49
  getAPRHelper: () => OffchainAPRHelper;
@@ -27,7 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const initializer = __importStar(require("./offchainInitializer"));
30
- const offchainPriceHelper_1 = __importDefault(require("./offchainPriceHelper"));
30
+ const offchainPriceHelperV2_1 = __importDefault(require("./offchainPriceHelperV2"));
31
31
  const offchainAPRHelper_1 = __importDefault(require("./offchainAPRHelper"));
32
32
  const offchainSolidexHelper_1 = __importDefault(require("./offchainSolidexHelper"));
33
33
  const account_1 = __importDefault(require("./account"));
@@ -83,7 +83,7 @@ class Offchain {
83
83
  this.network = cfg.network;
84
84
  this.chainId = cfg.chainId;
85
85
  this.whitelistedPairs = cfg.whitelistedPairs ? cfg.whitelistedPairs : {};
86
- this.priceHelper = new offchainPriceHelper_1.default(this);
86
+ this.priceHelper = new offchainPriceHelperV2_1.default(this);
87
87
  this.solidexHelper = new offchainSolidexHelper_1.default(this);
88
88
  this.configManager = new configManager_1.default(this);
89
89
  this.aprHelper = new offchainAPRHelper_1.default(this);
@@ -275,10 +275,7 @@ class OffchainAPRHelper {
275
275
  const etherexPools = await this.getEtherexPools();
276
276
  // `initializeShadowPools` keys by pool address
277
277
  // Convert to decimals to match `getUniswapAPR` and `getStakingAPR`
278
- console.log(etherexPools[pool.toLowerCase()]);
279
- console.log(etherexPools);
280
278
  const apy = etherexPools[pool.toLowerCase()]?.lpApr / 100;
281
- console.log("APY: ", apy);
282
279
  return apy || 0;
283
280
  }
284
281
  async getLlamaTvlAndBorrows(chain) {
@@ -71,7 +71,7 @@ class OffchainLendingVault extends offchainPoolToken_1.default {
71
71
  }
72
72
  async getTokenPriceAccurate() {
73
73
  let tokenAddress = await this.getUnderlyingAddress();
74
- return this.getOffchain().getPriceHelper().getDebankTokenPrice(tokenAddress);
74
+ return this.getOffchain().getPriceHelper().getTokenPrice(tokenAddress);
75
75
  }
76
76
  }
77
77
  exports.default = OffchainLendingVault;
@@ -0,0 +1,27 @@
1
+ import { Address } from "../config/types";
2
+ import Offchain from "./offchain";
3
+ import OffchainPriceHelperV1 from "./offchainPriceHelper";
4
+ export default class OffchainPriceHelper {
5
+ private apiTokens;
6
+ private apiTokensInitialized;
7
+ offchainPriceHelperV1: OffchainPriceHelperV1;
8
+ offchain: Offchain;
9
+ constructor(offchain: Offchain);
10
+ cleanCache(): void;
11
+ /**
12
+ * NOTE: Used as a fallback at the moment while we deprecate the old price helper
13
+ */
14
+ private getTokenPriceOld;
15
+ /**
16
+ * Initializes token prices from the API
17
+ */
18
+ private initializeTokenPrices;
19
+ /**
20
+ * Gets all tokens data from the API
21
+ */
22
+ private getTokenPrices;
23
+ /**
24
+ * Gets the price of a token from the API, initializes all tokens
25
+ */
26
+ getTokenPrice(tokenAddress: Address): Promise<number>;
27
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const private_api_1 = require("../config/private-api");
7
+ const offchainPriceHelper_1 = __importDefault(require("./offchainPriceHelper"));
8
+ class OffchainPriceHelper {
9
+ constructor(offchain) {
10
+ // Multichain private api
11
+ this.apiTokens = null;
12
+ this.apiTokensInitialized = null;
13
+ this.offchain = offchain;
14
+ this.offchainPriceHelperV1 = new offchainPriceHelper_1.default(offchain);
15
+ this.apiTokensInitialized = this.initializeTokenPrices();
16
+ }
17
+ cleanCache() {
18
+ this.apiTokens = null;
19
+ this.apiTokensInitialized = null;
20
+ this.offchainPriceHelperV1.cleanCache();
21
+ }
22
+ /**
23
+ * NOTE: Used as a fallback at the moment while we deprecate the old price helper
24
+ */
25
+ async getTokenPriceOld(tokenAddress) {
26
+ // Initializes v1 prices once if necessary
27
+ const price = await this.offchainPriceHelperV1.getDebankTokenPrice(tokenAddress);
28
+ return price;
29
+ }
30
+ /* -----------------------------------------------------------------------
31
+ * 1. Price aggreagator API (railway)
32
+ * ----------------------------------------------------------------------*/
33
+ /**
34
+ * Initializes token prices from the API
35
+ */
36
+ async initializeTokenPrices() {
37
+ try {
38
+ const response = await fetch(private_api_1.PRICE_AGGREGATOR_API_URL);
39
+ if (!response.ok)
40
+ throw new Error(`API response error: ${response.status}`);
41
+ this.apiTokens = await response.json();
42
+ }
43
+ catch (error) {
44
+ console.error("Error fetching token prices:", error);
45
+ this.apiTokens = null;
46
+ }
47
+ }
48
+ /**
49
+ * Gets all tokens data from the API
50
+ */
51
+ async getTokenPrices() {
52
+ if (!this.apiTokensInitialized)
53
+ this.apiTokensInitialized = this.initializeTokenPrices();
54
+ await this.apiTokensInitialized;
55
+ return this.apiTokens;
56
+ }
57
+ /**
58
+ * Gets the price of a token from the API, initializes all tokens
59
+ */
60
+ async getTokenPrice(tokenAddress) {
61
+ // Initialize tokens if necessary
62
+ const apiData = await this.getTokenPrices();
63
+ // Our price aggregator stores tokens as `chainId-tokenAddress`
64
+ // in case diff tokens have same address on diff networks
65
+ const key = `${this.offchain.chainId}-${tokenAddress.toLowerCase()}`;
66
+ this.offchain.chainId;
67
+ // First try get token price from our price-aggregator
68
+ const priceUsd = apiData?.tokens[key]?.priceUsd;
69
+ if (priceUsd)
70
+ return parseFloat(priceUsd);
71
+ // Fallback to price old
72
+ return this.getTokenPriceOld(tokenAddress);
73
+ }
74
+ }
75
+ exports.default = OffchainPriceHelper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "1.2.151",
3
+ "version": "1.2.152",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",