impermax-sdk 2.1.16 → 2.1.18

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.
@@ -205,47 +205,47 @@ exports.getAmmByFactory = getAmmByFactory;
205
205
  exports.AMM_SUBGRAPH_URLS = {
206
206
  [types_1.Networks.Ropsten]: {},
207
207
  [types_1.Networks.Mainnet]: {
208
- [Amms.uniswap]: 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2',
208
+ // [Amms.uniswap]: 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2',
209
209
  },
210
210
  [types_1.Networks.Polygon]: {
211
- [Amms.quickswap]: 'https://api.thegraph.com/subgraphs/name/sameepsi/quickswap06',
212
- //[Amms.satin]: "",
213
- //[Amms.pearl]: "",
214
- [Amms.sushiswap]: 'https://api.thegraph.com/subgraphs/name/sushiswap/matic-exchange',
215
- [Amms.tetuswap]: 'https://api.thegraph.com/subgraphs/name/tetu-io/tetu-swap',
211
+ // [Amms.quickswap]: 'https://api.thegraph.com/subgraphs/name/sameepsi/quickswap06',
212
+ //[Amms.satin]: "",
213
+ //[Amms.pearl]: "",
214
+ // [Amms.sushiswap]: 'https://api.thegraph.com/subgraphs/name/sushiswap/matic-exchange',
215
+ // [Amms.tetuswap]: 'https://api.thegraph.com/subgraphs/name/tetu-io/tetu-swap',
216
216
  },
217
217
  [types_1.Networks.Arbitrum]: {
218
- [Amms.sushiswap]: 'https://api.thegraph.com/subgraphs/name/sushiswap/arbitrum-exchange',
219
- [Amms.swapr]: 'https://api.thegraph.com/subgraphs/name/luzzif/swapr-arbitrum-one-v2',
220
- [Amms.zyberswap]: 'https://api.thegraph.com/subgraphs/name/zyberswap-arbitrum/zyber-amm',
221
- //[Amms.arbidex]: '',
222
- [Amms.solidlizard]: 'https://api.thegraph.com/subgraphs/name/solidlizardfinance/sliz',
223
- //[Amms.ramses]: '',
224
- //[Amms.auragi]: '',
225
- //[Amms.chronos]: '',
226
- //[Amms.swapfish]: 'https://bsc.streamingfast.io/subgraphs/name/pancakeswap/exchange-v2',
218
+ //[Amms.sushiswap]: 'https://api.thegraph.com/subgraphs/name/sushiswap/arbitrum-exchange',
219
+ //[Amms.swapr]: 'https://api.thegraph.com/subgraphs/name/luzzif/swapr-arbitrum-one-v2',
220
+ //[Amms.zyberswap]: 'https://api.thegraph.com/subgraphs/name/zyberswap-arbitrum/zyber-amm',
221
+ ////[Amms.arbidex]: '',
222
+ //[Amms.solidlizard]: 'https://api.thegraph.com/subgraphs/name/solidlizardfinance/sliz',
223
+ //[Amms.ramses]: '',
224
+ //[Amms.auragi]: '',
225
+ //[Amms.chronos]: '',
226
+ //[Amms.swapfish]: 'https://bsc.streamingfast.io/subgraphs/name/pancakeswap/exchange-v2',
227
227
  },
228
228
  [types_1.Networks.Avalanche]: {
229
- [Amms.pangolin]: 'https://api.thegraph.com/subgraphs/name/dasconnor/pangolin-dex',
230
- [Amms.traderJoe]: 'https://api.thegraph.com/subgraphs/name/traderjoe-xyz/exchange',
231
- [Amms.flair]: '',
232
- [Amms.glacier]: '',
233
- [Amms.thorus]: '',
229
+ //[Amms.pangolin]: 'https://api.thegraph.com/subgraphs/name/dasconnor/pangolin-dex',
230
+ //[Amms.traderJoe]: 'https://api.thegraph.com/subgraphs/name/traderjoe-xyz/exchange',
231
+ //[Amms.flair]: '',
232
+ //[Amms.glacier]: '',
233
+ //[Amms.thorus]: '',
234
234
  },
235
235
  [types_1.Networks.Moonriver]: {
236
- [Amms.sushiswap]: 'https://api.thegraph.com/subgraphs/name/sushiswap/moonriver-exchange',
237
- [Amms.solarbeam]: 'https://analytics.solarbeam.io/api/subgraph',
236
+ //[Amms.sushiswap]: 'https://api.thegraph.com/subgraphs/name/sushiswap/moonriver-exchange',
237
+ //[Amms.solarbeam]: 'https://analytics.solarbeam.io/api/subgraph',
238
238
  },
239
239
  [types_1.Networks.Aurora]: {},
240
240
  [types_1.Networks.Cronos]: {},
241
241
  [types_1.Networks.Fantom]: {
242
- [Amms.solidly]: 'https://api.thegraph.com/subgraphs/name/spartacus-finance/solidly',
243
- [Amms.solidlyB]: 'https://api.thegraph.com/subgraphs/name/spartacus-finance/solidly',
244
- [Amms.solidlyUSDC]: 'https://api.thegraph.com/subgraphs/name/spartacus-finance/solidly',
245
- [Amms.solidlyUSDCB]: 'https://api.thegraph.com/subgraphs/name/spartacus-finance/solidly',
246
- [Amms.solidly091]: 'https://api.thegraph.com/subgraphs/name/spartacus-finance/solidly',
247
- [Amms.solidlyOxd]: 'https://api.thegraph.com/subgraphs/name/spartacus-finance/solidly',
248
- [Amms.wigoswap]: 'https://gateway.thegraph.com/api/031cf65e6bf1e03a781f69aeba9770d2/subgraphs/id/ykYhkpzjz9FpT4RZRgFHQ84udU1581pfs4u9KcbA4yt'
242
+ //[Amms.solidly]: 'https://api.thegraph.com/subgraphs/name/spartacus-finance/solidly',
243
+ //[Amms.solidlyB]: 'https://api.thegraph.com/subgraphs/name/spartacus-finance/solidly',
244
+ //[Amms.solidlyUSDC]: 'https://api.thegraph.com/subgraphs/name/spartacus-finance/solidly',
245
+ //[Amms.solidlyUSDCB]: 'https://api.thegraph.com/subgraphs/name/spartacus-finance/solidly',
246
+ //[Amms.solidly091]: 'https://api.thegraph.com/subgraphs/name/spartacus-finance/solidly',
247
+ //[Amms.solidlyOxd]: 'https://api.thegraph.com/subgraphs/name/spartacus-finance/solidly',
248
+ //[Amms.wigoswap]: 'https://gateway.thegraph.com/api/031cf65e6bf1e03a781f69aeba9770d2/subgraphs/id/ykYhkpzjz9FpT4RZRgFHQ84udU1581pfs4u9KcbA4yt'
249
249
  },
250
250
  [types_1.Networks.Canto]: {},
251
251
  [types_1.Networks.ZksyncEra]: {},
@@ -254,8 +254,8 @@ exports.AMM_SUBGRAPH_URLS = {
254
254
  [types_1.Networks.Moonbeam]: {},
255
255
  [types_1.Networks.Sxnetwork]: {},
256
256
  [types_1.Networks.Base]: {
257
- [Amms.aerodrome]: 'https://api.thegraph.com/subgraphs/name/ethzoomer/aerodrome-trading-data',
258
- [Amms.uniswap]: 'https://api.studio.thegraph.com/query/46041/uniswap-v2-base/v0.0.1',
257
+ //[Amms.aerodrome]: 'https://api.thegraph.com/subgraphs/name/ethzoomer/aerodrome-trading-data', //could not find "official" subgraph,
258
+ //[Amms.uniswap]: 'https://api.studio.thegraph.com/query/46041/uniswap-v2-base/v0.0.1',
259
259
  },
260
260
  [types_1.Networks.Mantle]: {},
261
261
  [types_1.Networks.Scroll]: {},
@@ -236,7 +236,7 @@ class OffchainBorrowable extends offchainPoolToken_1.default {
236
236
  return [];
237
237
  const rewards = [];
238
238
  for (const reward of farmingRewards) {
239
- const rewardPrice = yield this.getOffchain().getPriceHelper().getDebankTokenPrice(reward.rewardToken);
239
+ const rewardPrice = yield this.getOffchain().getPriceHelper().getDebankTokenPrice(this.getOffchain().network, reward.rewardToken);
240
240
  rewards.push({
241
241
  APR: (0, utils_1.toAPR)((rewardPrice * reward.rewardRate) / totalBorrowedUSD),
242
242
  symbol: reward.rewardToken == "0x98878b06940ae243284ca214f92bb71a2b032b8a" ? "WMOVR" :
@@ -349,7 +349,7 @@ class OffchainBorrowable extends offchainPoolToken_1.default {
349
349
  });
350
350
  return __awaiter(this, void 0, void 0, function* () {
351
351
  let tokenAddress = yield this.getUnderlyingAddress();
352
- let tokenPrices = yield this.getOffchain().getPriceHelper().getSubgraphTokensPrice();
352
+ let tokenPrices = yield this.getOffchain().getPriceHelper().getSubgraphTokensPrice(this.getOffchain().network);
353
353
  let tokenPrice = tokenPrices[tokenAddress];
354
354
  if (tokenPrice !== undefined && tokenPrice > 0)
355
355
  return tokenPrice;
@@ -359,7 +359,7 @@ class OffchainBorrowable extends offchainPoolToken_1.default {
359
359
  getTokenPriceAccurate() {
360
360
  return __awaiter(this, void 0, void 0, function* () {
361
361
  let tokenAddress = yield this.getUnderlyingAddress();
362
- return this.getOffchain().getPriceHelper().getDebankTokenPrice(tokenAddress);
362
+ return this.getOffchain().getPriceHelper().getDebankTokenPrice(this.getOffchain().network, tokenAddress);
363
363
  });
364
364
  }
365
365
  }
@@ -136,7 +136,7 @@ class OffchainLendingPool {
136
136
  rewardRate = rewardRate * 0.45;
137
137
  const rewardPrice = yield this.offchain
138
138
  .getPriceHelper()
139
- .getDebankTokenPrice(reward.rewardsToken.id);
139
+ .getDebankTokenPrice(this.offchain.network, reward.rewardsToken.id);
140
140
  rewards.push({
141
141
  APR: (0, utils_1.toAPR)(((rewardPrice * rewardRate) /
142
142
  (stakedTotalSupply * underlyingLPPrice)) *
@@ -48,9 +48,9 @@ export default class Offchain {
48
48
  getLendingPool(factory: Factory, pairAddress: Address): Promise<OffchainLendingPool>;
49
49
  getVault(vaultAddress: Address): Promise<OffchainVault>;
50
50
  getAccount(accountAddress: Address): OffchainAccount;
51
- getPriceHelper: () => OffchainPriceHelper;
52
51
  getSolidexHelper: () => OffchainSolidexHelper;
53
52
  getConfigManager: () => OffchainConfigManager;
53
+ getPriceHelper: () => OffchainPriceHelper;
54
54
  getAPRHelper: () => OffchainAPRHelper;
55
55
  apolloFetcher: typeof initializer.apolloFetcher;
56
56
  protected fetchLendingPools: typeof initializer.fetchLendingPools;
@@ -36,8 +36,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  const initializer = __importStar(require("./offchainInitializer"));
39
- const offchainPriceHelper_1 = __importDefault(require("./offchainPriceHelper"));
40
- const offchainAPRHelper_1 = __importDefault(require("./offchainAPRHelper"));
41
39
  const offchainSolidexHelper_1 = __importDefault(require("./offchainSolidexHelper"));
42
40
  const account_1 = __importDefault(require("./account"));
43
41
  const offchainEndpointManager_1 = __importDefault(require("./offchainEndpointManager"));
@@ -47,10 +45,11 @@ const chainId_1 = require("../config/chainId");
47
45
  class Offchain {
48
46
  constructor(offchainMultichain, network, whitelist) {
49
47
  this.whitelistedPairs = {};
50
- this.getPriceHelper = () => this.priceHelper;
51
48
  this.getSolidexHelper = () => this.solidexHelper;
52
49
  this.getConfigManager = () => this.configManager;
53
- this.getAPRHelper = () => this.aprHelper;
50
+ // Multichain, 1 instance
51
+ this.getPriceHelper = () => this.offchainMultichain.getPriceHelper();
52
+ this.getAPRHelper = () => this.offchainMultichain.getAPRHelper();
54
53
  // TODO make everything protected
55
54
  // Fetchers
56
55
  this.apolloFetcher = initializer.apolloFetcher;
@@ -95,10 +94,8 @@ class Offchain {
95
94
  this.offchainMultichain = offchainMultichain;
96
95
  this.network = network;
97
96
  this.chainId = chainId_1.CHAIN_IDS[network];
98
- this.priceHelper = new offchainPriceHelper_1.default(this);
99
97
  this.solidexHelper = new offchainSolidexHelper_1.default(this);
100
98
  this.configManager = new configManager_1.default(this);
101
- this.aprHelper = new offchainAPRHelper_1.default(this);
102
99
  this.endpointManager = new offchainEndpointManager_1.default();
103
100
  this.accounts = {};
104
101
  this.usersData = {};
@@ -112,10 +109,10 @@ class Offchain {
112
109
  this.tvlData = null;
113
110
  this.ximxData = null;
114
111
  this.whitelistData = null;
115
- this.priceHelper.cleanCache();
116
112
  this.solidexHelper.cleanCache();
117
113
  this.configManager.cleanCache();
118
- this.aprHelper.cleanCache();
114
+ this.getPriceHelper().cleanCache();
115
+ this.getAPRHelper().cleanCache();
119
116
  }
120
117
  getLendingPool(factory, pairAddress) {
121
118
  return __awaiter(this, void 0, void 0, function* () {
@@ -1,5 +1,5 @@
1
1
  import { Address, Networks } from "../config/types";
2
- import Offchain from "./index";
2
+ import OffchainMultichain from "./offchainMultichain";
3
3
  export type LlamaTvlChart = {
4
4
  date: number;
5
5
  totalLiquidityUSD: number;
@@ -22,8 +22,8 @@ export default class OffchainAPRHelper {
22
22
  private chainTvlCharts;
23
23
  private protocolTvlChart;
24
24
  private readonly blacklistedProjects;
25
- offchain: Offchain;
26
- constructor(offchain: Offchain);
25
+ offchainMultichain: OffchainMultichain;
26
+ constructor(offchainMultichain: OffchainMultichain);
27
27
  cleanCache(): void;
28
28
  private isBlacklisted;
29
29
  private initializeYields;
@@ -34,7 +34,7 @@ const LlamaChains = {
34
34
  };
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
- constructor(offchain) {
37
+ constructor(offchainMultichain) {
38
38
  this.llamaAllPools = {};
39
39
  this.initialized = null;
40
40
  this.chainTvls = {};
@@ -48,7 +48,7 @@ class OffchainAPRHelper {
48
48
  "extra-finance",
49
49
  "beefy"
50
50
  ]);
51
- this.offchain = offchain;
51
+ this.offchainMultichain = offchainMultichain;
52
52
  }
53
53
  cleanCache() {
54
54
  this.llamaAllPools = {};
@@ -6,6 +6,8 @@ import { Farms } from "../config/farms";
6
6
  import { RiskLevel } from "./vault/offchainLendingVault";
7
7
  import OffchainLendingPool from "./lendingPool";
8
8
  import { LendingPoolVersion } from "./lendingPool/offchainLendingPool";
9
+ import OffchainAPRHelper from "./offchainAPRHelper";
10
+ import OffchainPriceHelper from "./offchainPriceHelper";
9
11
  export declare enum SortDirection {
10
12
  ASC = "asc",
11
13
  DESC = "desc"
@@ -46,9 +48,15 @@ export interface LendingPoolListParams {
46
48
  export default class OffchainMultichain {
47
49
  #private;
48
50
  protected offchains: NetworkIndex<Offchain>;
51
+ protected aprHelper: OffchainAPRHelper;
52
+ protected priceHelper: OffchainPriceHelper;
53
+ private lendingPoolsInitialized;
54
+ protected lendingPools: OffchainLendingPool[];
49
55
  private constructor();
50
56
  static get instance(): OffchainMultichain;
51
57
  getOffchain(network: Networks, whitelist?: FactoryIndex<Address[]>): Offchain;
58
+ getAPRHelper(): OffchainAPRHelper;
59
+ getPriceHelper(): OffchainPriceHelper;
52
60
  getVaultList(params?: VaultListParams): Promise<Array<OffchainVault>>;
53
61
  networkHasVault(network: Networks): boolean;
54
62
  getLendingPoolList(params?: LendingPoolListParams): Promise<Array<OffchainLendingPool>>;
@@ -28,6 +28,8 @@ exports.LendingPoolListOrderBy = exports.VaultListOrderBy = exports.SortDirectio
28
28
  const types_1 = require("../config/types");
29
29
  const offchain_1 = __importDefault(require("./offchain"));
30
30
  const subgraphs_1 = require("../config/subgraphs");
31
+ const offchainAPRHelper_1 = __importDefault(require("./offchainAPRHelper"));
32
+ const offchainPriceHelper_1 = __importDefault(require("./offchainPriceHelper"));
31
33
  // For vaults and pools
32
34
  var SortDirection;
33
35
  (function (SortDirection) {
@@ -52,8 +54,12 @@ var LendingPoolListOrderBy;
52
54
  // singleton class
53
55
  class OffchainMultichain {
54
56
  constructor() {
57
+ this.lendingPoolsInitialized = null;
58
+ this.lendingPools = [];
55
59
  // Initialize empty
56
60
  this.offchains = {};
61
+ this.aprHelper = new offchainAPRHelper_1.default(this);
62
+ this.priceHelper = new offchainPriceHelper_1.default(this); // Create single instance
57
63
  }
58
64
  static get instance() {
59
65
  if (!__classPrivateFieldGet(OffchainMultichain, _a, "f", _OffchainMultichain_instance)) {
@@ -66,6 +72,12 @@ class OffchainMultichain {
66
72
  this.offchains[network] = new offchain_1.default(this, network, whitelist);
67
73
  return this.offchains[network];
68
74
  }
75
+ getAPRHelper() {
76
+ return this.aprHelper;
77
+ }
78
+ getPriceHelper() {
79
+ return this.priceHelper;
80
+ }
69
81
  /*--------------------------------------------------------*
70
82
  * Vaults
71
83
  *--------------------------------------------------------*/
@@ -1,22 +1,25 @@
1
- import Offchain from "./index";
2
- import { Address } from '../config/types';
1
+ import { Address, Networks } from "../config/types";
2
+ import OffchainMultichain from "./offchainMultichain";
3
3
  export default class OffchainPriceHelper {
4
- offchain: Offchain;
4
+ offchainMultichain: OffchainMultichain;
5
5
  private subgraphTokensPrice;
6
6
  private debankTokensPrice;
7
7
  private coingeckoInitialized;
8
8
  private coingeckoTokenPrices;
9
- constructor(offchain: Offchain);
9
+ private fantomTokenPricesInitialized;
10
+ private fantomTokenPrices;
11
+ constructor(offchainMultichain: OffchainMultichain);
10
12
  cleanCache(): void;
11
13
  private addPriceIfMissing;
12
14
  private initializeSubgraphTokenPrice;
13
- getSubgraphTokensPrice(): Promise<{
15
+ getSubgraphTokensPrice(network: Networks): Promise<{
14
16
  [key in Address]: number | undefined;
15
17
  }>;
16
18
  private getAllCoingeckoPrices;
17
19
  private getCoingeckoTokenPrice;
18
- private getDexscreenerTokenPrice;
20
+ private initializeFantomTokenPrices;
19
21
  private getFantomTokenPrice;
22
+ private getDexscreenerTokenPrice;
20
23
  private initializeDebankTokenPrice;
21
- getDebankTokenPrice(tokenAddress: Address): Promise<number>;
24
+ getDebankTokenPrice(network: Networks, tokenAddress: Address): Promise<number>;
22
25
  }
@@ -122,13 +122,20 @@ const fantom_ids = {
122
122
  // mclb
123
123
  "0x5deb27e51dbeef691ba1175a2e563870499c2acb": "fantom",
124
124
  // hedgy
125
- "0x16c22105301cfd85fd0f911920d282d18cc175c1": "fantom"
125
+ "0x16c22105301cfd85fd0f911920d282d18cc175c1": "fantom",
126
126
  };
127
+ // Sources used so far:
128
+ // 1. Our subgraphs
129
+ // 2. Coingecko
130
+ // 3. Equalizer's (fantom) API
131
+ // 4. DexScreener
127
132
  class OffchainPriceHelper {
128
- ;
129
- constructor(offchain) {
133
+ // No need for dexscreener mutex since it allows only one token per call
134
+ constructor(offchainMultichain) {
130
135
  this.coingeckoInitialized = null;
131
- this.offchain = offchain;
136
+ this.fantomTokenPricesInitialized = null;
137
+ this.fantomTokenPrices = {};
138
+ this.offchainMultichain = offchainMultichain;
132
139
  this.debankTokensPrice = {};
133
140
  }
134
141
  cleanCache() {
@@ -141,9 +148,14 @@ class OffchainPriceHelper {
141
148
  return;
142
149
  offchainTokenPrice[token.id] = parseFloat(token.derivedUSD);
143
150
  }
144
- initializeSubgraphTokenPrice() {
151
+ /* -----------------------------------------------------------------------
152
+ * 1. Subgraph (least priority)
153
+ * ----------------------------------------------------------------------*/
154
+ initializeSubgraphTokenPrice(network) {
145
155
  return __awaiter(this, void 0, void 0, function* () {
146
- const lendingPoolsData = yield this.offchain.getLendingPoolsData();
156
+ const lendingPoolsData = yield this.offchainMultichain
157
+ .getOffchain(network)
158
+ .getLendingPoolsData();
147
159
  const offchainTokenPrice = {};
148
160
  for (const factory in lendingPoolsData) {
149
161
  for (const id in lendingPoolsData[factory]) {
@@ -165,17 +177,19 @@ class OffchainPriceHelper {
165
177
  offchainTokenPrice["0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83"] = 0;
166
178
  offchainTokenPrice["0xc19669a405067927865b40ea045a2baabbbe57f5"] = 0;
167
179
  offchainTokenPrice["0x3fd3a0c85b70754efc07ac9ac0cbbdce664865a6"] = 0;
168
- //offchainTokenPrice["0xad531012c0651a85a212f10fc97b3ec15684548a"] = 0;
169
180
  return offchainTokenPrice;
170
181
  });
171
182
  }
172
- getSubgraphTokensPrice() {
183
+ getSubgraphTokensPrice(network) {
173
184
  return __awaiter(this, void 0, void 0, function* () {
174
185
  if (!this.subgraphTokensPrice)
175
- this.subgraphTokensPrice = this.initializeSubgraphTokenPrice();
186
+ this.subgraphTokensPrice = this.initializeSubgraphTokenPrice(network);
176
187
  return this.subgraphTokensPrice;
177
188
  });
178
189
  }
190
+ /* -----------------------------------------------------------------------
191
+ * 2. Coingecko
192
+ * ----------------------------------------------------------------------*/
179
193
  getAllCoingeckoPrices() {
180
194
  return __awaiter(this, void 0, void 0, function* () {
181
195
  // Remove duplicates just in case, get the unique coingecko token ids
@@ -183,7 +197,9 @@ class OffchainPriceHelper {
183
197
  const uniqueIds = [...new Set(tokenIds)].join(",");
184
198
  try {
185
199
  // Get all token prices from gecko
186
- const response = yield fetch("https://api.coingecko.com/api/v3/simple/price?ids=" + uniqueIds + "&vs_currencies=usd");
200
+ const response = yield fetch("https://api.coingecko.com/api/v3/simple/price?ids=" +
201
+ uniqueIds +
202
+ "&vs_currencies=usd");
187
203
  if (response.status != 200)
188
204
  return;
189
205
  const data = yield response.json();
@@ -212,43 +228,63 @@ class OffchainPriceHelper {
212
228
  return geckoPrice || 0;
213
229
  });
214
230
  }
215
- getDexscreenerTokenPrice(tokenAddress) {
231
+ /* -----------------------------------------------------------------------
232
+ * 3. Fantom (Equalizer's API)
233
+ * ----------------------------------------------------------------------*/
234
+ initializeFantomTokenPrices() {
216
235
  return __awaiter(this, void 0, void 0, function* () {
217
236
  try {
218
- const chainId = dexscreener_ids[tokenAddress];
219
- const response = yield fetch("https://api.dexscreener.com/latest/dex/search?q=" + tokenAddress);
237
+ const response = yield fetch("https://eqapi-beta-8868m.ondigitalocean.app/fantom/v4/tokens");
220
238
  if (response.status != 200)
221
- return 0;
239
+ return;
222
240
  const data = yield response.json();
223
- if (!data || !data.pairs || data.pairs.length === 0)
224
- return 0;
225
- const pairs = data.pairs;
226
- const pairItem = pairs.filter((pair) => chainId.includes(pair.chainId) && (pair.baseToken.address.toLowerCase() == tokenAddress || pair.quoteToken.address.toLowerCase() == tokenAddress));
227
- return pairItem.length > 0 ? pairItem[0].priceUsd : 0;
241
+ if (!(data === null || data === void 0 ? void 0 : data.data))
242
+ return;
243
+ this.fantomTokenPrices = Object.entries(data.data).reduce((acc, [address, data]) => {
244
+ acc[address.toLowerCase()] = Number(data.priceUsd);
245
+ return acc;
246
+ }, {});
228
247
  }
229
248
  catch (_a) {
230
- return 0;
249
+ this.fantomTokenPrices = {};
231
250
  }
232
251
  });
233
252
  }
234
253
  getFantomTokenPrice(tokenAddress) {
254
+ return __awaiter(this, void 0, void 0, function* () {
255
+ if (!this.fantomTokenPricesInitialized)
256
+ this.fantomTokenPricesInitialized = this.initializeFantomTokenPrices();
257
+ yield this.fantomTokenPricesInitialized;
258
+ return this.fantomTokenPrices[tokenAddress.toLowerCase()] || 0;
259
+ });
260
+ }
261
+ /* -----------------------------------------------------------------------
262
+ * 4. Dexscreener
263
+ * ----------------------------------------------------------------------*/
264
+ getDexscreenerTokenPrice(tokenAddress) {
235
265
  return __awaiter(this, void 0, void 0, function* () {
236
266
  try {
237
- const response = yield fetch("https://eqapi-beta-8868m.ondigitalocean.app/fantom/v4/tokens");
267
+ const chainId = dexscreener_ids[tokenAddress];
268
+ const response = yield fetch("https://api.dexscreener.com/latest/dex/search?q=" + tokenAddress);
238
269
  if (response.status != 200)
239
270
  return 0;
240
271
  const data = yield response.json();
241
- if (!data || !data.data)
272
+ if (!data || !data.pairs || data.pairs.length === 0)
242
273
  return 0;
243
- const priceData = data.data;
244
- const priceItem = Object.keys(priceData).filter((keyId) => keyId.toLowerCase() == tokenAddress);
245
- return priceItem.length > 0 ? Number(priceData[priceItem[0]].priceUsd) : 0;
274
+ const pairs = data.pairs;
275
+ const pairItem = pairs.filter((pair) => chainId.includes(pair.chainId) &&
276
+ (pair.baseToken.address.toLowerCase() == tokenAddress ||
277
+ pair.quoteToken.address.toLowerCase() == tokenAddress));
278
+ return pairItem.length > 0 ? pairItem[0].priceUsd : 0;
246
279
  }
247
280
  catch (_a) {
248
281
  return 0;
249
282
  }
250
283
  });
251
284
  }
285
+ /* -----------------------------------------------------------------------
286
+ * Main logic of Price helper
287
+ * ----------------------------------------------------------------------*/
252
288
  initializeDebankTokenPrice(tokenAddress) {
253
289
  return __awaiter(this, void 0, void 0, function* () {
254
290
  if (Object.keys(fantom_ids).includes(tokenAddress.toLowerCase())) {
@@ -269,45 +305,72 @@ class OffchainPriceHelper {
269
305
  return 0;
270
306
  });
271
307
  }
272
- getDebankTokenPrice(tokenAddress) {
308
+ // TODO: Simplify this logic and reove the old temporaries we dont need anymore
309
+ getDebankTokenPrice(network, tokenAddress) {
273
310
  return __awaiter(this, void 0, void 0, function* () {
274
- if (tokenAddress.toLowerCase() === '0xf28164a485b0b2c90639e47b0f377b4a438a16b1') { // fix for dQuick
275
- return (yield this.getDebankTokenPrice('0x831753dd7087cac61ab5644b308642cc1c33dc13')) * 1.68;
311
+ if (tokenAddress.toLowerCase() ===
312
+ "0xf28164a485b0b2c90639e47b0f377b4a438a16b1") {
313
+ // fix for dQuick
314
+ return ((yield this.getDebankTokenPrice(network, "0x831753dd7087cac61ab5644b308642cc1c33dc13")) * 1.68);
276
315
  }
277
- if (tokenAddress.toLowerCase() === '0x63468133ed352e602beb61dd254d6060ad2fe419') { // fix for sTHO
278
- return (yield this.getDebankTokenPrice('0xae4aa155d2987b454c29450ef4f862cf00907b61')) * 1.1;
316
+ if (tokenAddress.toLowerCase() ===
317
+ "0x63468133ed352e602beb61dd254d6060ad2fe419") {
318
+ // fix for sTHO
319
+ return ((yield this.getDebankTokenPrice(network, "0xae4aa155d2987b454c29450ef4f862cf00907b61")) * 1.1);
279
320
  }
280
- if (tokenAddress.toLowerCase() === '0xfcef8a994209d6916eb2c86cdd2afd60aa6f54b1') { // fix for fBEETS
281
- return (yield this.getDebankTokenPrice('0xf24bcf4d1e507740041c9cfd2dddb29585adce1e')) * 0.93;
321
+ if (tokenAddress.toLowerCase() ===
322
+ "0xfcef8a994209d6916eb2c86cdd2afd60aa6f54b1") {
323
+ // fix for fBEETS
324
+ return ((yield this.getDebankTokenPrice(network, "0xf24bcf4d1e507740041c9cfd2dddb29585adce1e")) * 0.93);
282
325
  }
283
- if (tokenAddress.toLowerCase() === '0x5979d7b546e38e414f7e9822514be443a4800529') { // TEMPORARY fix for WSTETH
284
- return (yield this.getDebankTokenPrice('0x82af49447d8a07e3bd95bd0d56f35241523fbab1')) / 0.92;
326
+ if (tokenAddress.toLowerCase() ===
327
+ "0x5979d7b546e38e414f7e9822514be443a4800529") {
328
+ // TEMPORARY fix for WSTETH
329
+ return ((yield this.getDebankTokenPrice(network, "0x82af49447d8a07e3bd95bd0d56f35241523fbab1")) / 0.92);
285
330
  }
286
- if (tokenAddress.toLowerCase() === '0x3f56e0c36d275367b8c502090edf38289b3dea0d') { // TEMPORARY fix for MAI
331
+ if (tokenAddress.toLowerCase() ===
332
+ "0x3f56e0c36d275367b8c502090edf38289b3dea0d") {
333
+ // TEMPORARY fix for MAI
287
334
  return 1;
288
335
  }
289
- if (tokenAddress.toLowerCase() === '0x2fc5cf65fd0a660801f119832b2158756968266d') { // TEMPORARY fix for CHI
336
+ if (tokenAddress.toLowerCase() ===
337
+ "0x2fc5cf65fd0a660801f119832b2158756968266d") {
338
+ // TEMPORARY fix for CHI
290
339
  return 1;
291
340
  }
292
- if (tokenAddress.toLowerCase() === '0xc19669a405067927865b40ea045a2baabbbe57f5') { // TEMPORARY fix for STAR
341
+ if (tokenAddress.toLowerCase() ===
342
+ "0xc19669a405067927865b40ea045a2baabbbe57f5") {
343
+ // TEMPORARY fix for STAR
293
344
  return 1;
294
345
  }
295
- if (tokenAddress.toLowerCase() === '0xb79dd08ea68a908a97220c76d19a6aa9cbde4376') { // TEMPORARY fix for usd+
346
+ if (tokenAddress.toLowerCase() ===
347
+ "0xb79dd08ea68a908a97220c76d19a6aa9cbde4376") {
348
+ // TEMPORARY fix for usd+
296
349
  return 1;
297
350
  }
298
- if (tokenAddress.toLowerCase() === '0xc518a88c67ceca8b3f24c4562cb71deeb2af86b7') { // TEMPORARY fix for re.al usdc
351
+ if (tokenAddress.toLowerCase() ===
352
+ "0xc518a88c67ceca8b3f24c4562cb71deeb2af86b7") {
353
+ // TEMPORARY fix for re.al usdc
299
354
  return 1;
300
355
  }
301
- if (tokenAddress.toLowerCase() === '0xaec9e50e3397f9ddc635c6c429c8c7eca418a143') { // TEMPORARY fix for re.al arcUSD
356
+ if (tokenAddress.toLowerCase() ===
357
+ "0xaec9e50e3397f9ddc635c6c429c8c7eca418a143") {
358
+ // TEMPORARY fix for re.al arcUSD
302
359
  return 1;
303
360
  }
304
- if (tokenAddress.toLowerCase() === '0xc71aaf8e486e3f33841bb56ca3fd2ac3fa8d29a8') { // TEMPORARY fix for WSTETH Canto
305
- return (yield this.getDebankTokenPrice('0x5fd55a1b9fc24967c4db09c513c3ba0dfa7ff687')) * 1.12;
361
+ if (tokenAddress.toLowerCase() ===
362
+ "0xc71aaf8e486e3f33841bb56ca3fd2ac3fa8d29a8") {
363
+ // TEMPORARY fix for WSTETH Canto
364
+ return ((yield this.getDebankTokenPrice(network, "0x5fd55a1b9fc24967c4db09c513c3ba0dfa7ff687")) * 1.12);
306
365
  }
307
- if (tokenAddress.toLowerCase() === '0x152b9d0fdc40c096757f570a51e494bd4b943e50') { // TEMPORARY fix for BTC.b AVAX
308
- return (yield this.getDebankTokenPrice('0x50b7545627a5162f82a992c33b87adc75187b218'));
366
+ if (tokenAddress.toLowerCase() ===
367
+ "0x152b9d0fdc40c096757f570a51e494bd4b943e50") {
368
+ // TEMPORARY fix for BTC.b AVAX
369
+ return yield this.getDebankTokenPrice(network, "0x50b7545627a5162f82a992c33b87adc75187b218");
309
370
  }
310
- if (tokenAddress.toLowerCase() === '0x9fc3104f6fc188fee65c85bbc4b94a48282ae76d') { // TEMPORARY fix for SATIN
371
+ if (tokenAddress.toLowerCase() ===
372
+ "0x9fc3104f6fc188fee65c85bbc4b94a48282ae76d") {
373
+ // TEMPORARY fix for SATIN
311
374
  return 0;
312
375
  }
313
376
  if ([
@@ -316,44 +379,64 @@ class OffchainPriceHelper {
316
379
  "0xea6887e4a9cda1b77e70129e5fba830cdb5cddef",
317
380
  "0x60bb3d364b765c497c8ce50ae0ae3f0882c5bd05",
318
381
  "0x900f1ec5819fa087d368877cd03b265bf1802667",
319
- "0xea38f1ccf77bf43f352636241b05dd8f6f5f52b2"
320
- ].includes(tokenAddress.toLowerCase())) { // fix for IMX
382
+ "0xea38f1ccf77bf43f352636241b05dd8f6f5f52b2",
383
+ ].includes(tokenAddress.toLowerCase())) {
384
+ // fix for IMX
321
385
  return 0;
322
386
  }
323
- if (tokenAddress.toLowerCase() === '0xda0053f0befcbcac208a3f867bb243716734d809') { // TEMPORARY fix for oxSOLID
324
- return (yield this.getDebankTokenPrice('0x888ef71766ca594ded1f0fa3ae64ed2941740a20')) * 0.88;
387
+ if (tokenAddress.toLowerCase() ===
388
+ "0xda0053f0befcbcac208a3f867bb243716734d809") {
389
+ // TEMPORARY fix for oxSOLID
390
+ return ((yield this.getDebankTokenPrice(network, "0x888ef71766ca594ded1f0fa3ae64ed2941740a20")) * 0.88);
325
391
  }
326
- if (tokenAddress.toLowerCase() === '0x431d5dff03120afa4bdf332c61a6e1766ef37bdb') { // TEMPORARY fix for JPYCv2
327
- return (yield this.getDebankTokenPrice('0x6ae7dfc73e0dde2aa99ac063dcf7e8a63265108c'));
392
+ if (tokenAddress.toLowerCase() ===
393
+ "0x431d5dff03120afa4bdf332c61a6e1766ef37bdb") {
394
+ // TEMPORARY fix for JPYCv2
395
+ return yield this.getDebankTokenPrice(network, "0x6ae7dfc73e0dde2aa99ac063dcf7e8a63265108c");
328
396
  }
329
397
  if (!this.debankTokensPrice[tokenAddress])
330
- this.debankTokensPrice[tokenAddress] = this.initializeDebankTokenPrice(tokenAddress);
331
- const tokenPrice = yield this.debankTokensPrice[tokenAddress];
398
+ this.debankTokensPrice[tokenAddress] =
399
+ this.initializeDebankTokenPrice(tokenAddress);
400
+ const tokenPrice = (yield this.debankTokensPrice[tokenAddress]);
332
401
  if (tokenPrice === 0) {
333
402
  //manual fallback
334
- if (tokenAddress.toLowerCase() === '0xaaa6c1e32c55a7bfa8066a6fae9b42650f262418') { // fix for RAM
403
+ if (tokenAddress.toLowerCase() ===
404
+ "0xaaa6c1e32c55a7bfa8066a6fae9b42650f262418") {
405
+ // fix for RAM
335
406
  return 0.02;
336
407
  }
337
- if (tokenAddress.toLowerCase() === '0xd5954c3084a1ccd70b4da011e67760b8e78aee84') { // fix for ARX
408
+ if (tokenAddress.toLowerCase() ===
409
+ "0xd5954c3084a1ccd70b4da011e67760b8e78aee84") {
410
+ // fix for ARX
338
411
  return 0.5;
339
412
  }
340
- if (tokenAddress.toLowerCase() === '0xe80772eaf6e2e18b651f160bc9158b2a5cafca65') { // fix for USD+
413
+ if (tokenAddress.toLowerCase() ===
414
+ "0xe80772eaf6e2e18b651f160bc9158b2a5cafca65") {
415
+ // fix for USD+
341
416
  return 1;
342
417
  }
343
- if (tokenAddress.toLowerCase() === '0x3712871408a829c5cd4e86da1f4ce727efcd28f6') { // fix for GLCR
418
+ if (tokenAddress.toLowerCase() ===
419
+ "0x3712871408a829c5cd4e86da1f4ce727efcd28f6") {
420
+ // fix for GLCR
344
421
  return 0.011;
345
422
  }
346
- if (tokenAddress.toLowerCase() === '0x5756a28e2aae01f600fc2c01358395f5c1f8ad3a') { // fix for VS
423
+ if (tokenAddress.toLowerCase() ===
424
+ "0x5756a28e2aae01f600fc2c01358395f5c1f8ad3a") {
425
+ // fix for VS
347
426
  return 0.05;
348
427
  }
349
- if (tokenAddress.toLowerCase() === '0x160e07e42adbc1fce92d505b579bcd8a3fbea77d') { // fix for FANG
428
+ if (tokenAddress.toLowerCase() ===
429
+ "0x160e07e42adbc1fce92d505b579bcd8a3fbea77d") {
430
+ // fix for FANG
350
431
  return 0.1;
351
432
  }
352
- if (tokenAddress.toLowerCase() === '0x1c28edf9e0d66f3124f141a3cf3ef1217f7019c4') { // fix for SLNA
433
+ if (tokenAddress.toLowerCase() ===
434
+ "0x1c28edf9e0d66f3124f141a3cf3ef1217f7019c4") {
435
+ // fix for SLNA
353
436
  return 0.00045;
354
437
  }
355
438
  // try fallback on offchain
356
- const subgraphTokensPrice = yield this.getSubgraphTokensPrice();
439
+ const subgraphTokensPrice = yield this.getSubgraphTokensPrice(network);
357
440
  const subgraphTokenPrice = subgraphTokensPrice[tokenAddress];
358
441
  return subgraphTokenPrice ? subgraphTokenPrice : 0;
359
442
  }
@@ -113,7 +113,7 @@ class OffchainVault extends offchainPoolToken_1.default {
113
113
  getTokenPriceAccurate() {
114
114
  return __awaiter(this, void 0, void 0, function* () {
115
115
  let tokenAddress = yield this.getUnderlyingAddress();
116
- return this.getOffchain().getPriceHelper().getDebankTokenPrice(tokenAddress);
116
+ return this.getOffchain().getPriceHelper().getDebankTokenPrice(this.getOffchain().network, tokenAddress);
117
117
  });
118
118
  }
119
119
  // Flags
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.16",
3
+ "version": "2.1.18",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",