impermax-sdk 1.2.43 → 1.2.45

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.
@@ -210,7 +210,7 @@ exports.AMM_SUBGRAPH_URLS = {
210
210
  [types_1.Networks.Sxnetwork]: {},
211
211
  [types_1.Networks.Base]: {
212
212
  [Amms.aerodrome]: 'https://api.thegraph.com/subgraphs/name/ethzoomer/aerodrome-trading-data',
213
- [Amms.uniswap]: 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2',
213
+ [Amms.uniswap]: 'https://api.studio.thegraph.com/query/46041/uniswap-v2-base/v0.0.1',
214
214
  },
215
215
  [types_1.Networks.Mantle]: {},
216
216
  [types_1.Networks.Scroll]: {},
@@ -12,6 +12,7 @@ export default class OffchainPriceHelper {
12
12
  [key in Address]: number | undefined;
13
13
  }>;
14
14
  private getCoingeckoTokenPrice;
15
+ private getDexscreenerTokenPrice;
15
16
  private initializeDebankTokenPrice;
16
17
  getDebankTokenPrice(tokenAddress: Address): Promise<number>;
17
18
  }
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const debank_ids_1 = require("../config/debank-ids");
13
12
  // coingecko has priority over debank for initialized tokens
14
13
  const coingecko_ids = {
15
14
  //Polygon
@@ -37,7 +36,6 @@ const coingecko_ids = {
37
36
  "0x160e07e42adbc1fce92d505b579bcd8a3fbea77d": "dracula-fi",
38
37
  // Scroll
39
38
  "0x1a2fcb585b327fadec91f55d45829472b15f17a4": "tokan",
40
- "0x78ab77f7d590fb101aa18affc238cbfea31ead5b": "impermax",
41
39
  "0xf610a9dfb7c89644979b4a0f27063e9e7d7cda32": "wrapped-steth",
42
40
  "0x74ccbe53f77b08632ce0cb91d3a545bf6b8e0979": "fantom-bomb",
43
41
  // base
@@ -45,6 +43,18 @@ const coingecko_ids = {
45
43
  "0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed": "degen-base",
46
44
  "0x4200000000000000000000000000000000000006": "ethereum"
47
45
  };
46
+ const dexscreener_ids = {
47
+ // ibex on scroll
48
+ "0x78ab77f7d590fb101aa18affc238cbfea31ead5b": "scroll",
49
+ // ibex on polygon
50
+ "0xf972daced7c6b03223710c11413036d17eb298f6": "polygon",
51
+ // ibex on arb
52
+ "0x56659245931cb6920e39c189d2a0e7dd0da2d57b": "arbitrum",
53
+ // ibex on zksync
54
+ "0xbe9f8c0d6f0fd7e46cdacca340747ea2f247991d": "zksync",
55
+ // fantom-bomb on scroll
56
+ "0x74ccbe53f77b08632ce0cb91d3a545bf6b8e0979": "scroll",
57
+ };
48
58
  class OffchainPriceHelper {
49
59
  constructor(offchain) {
50
60
  this.offchain = offchain;
@@ -109,31 +119,55 @@ class OffchainPriceHelper {
109
119
  }
110
120
  });
111
121
  }
112
- initializeDebankTokenPrice(tokenAddress) {
122
+ getDexscreenerTokenPrice(tokenAddress) {
113
123
  return __awaiter(this, void 0, void 0, function* () {
114
- if (Object.keys(coingecko_ids).includes(tokenAddress.toLowerCase())) {
115
- const result = yield this.getCoingeckoTokenPrice(tokenAddress.toLowerCase());
116
- if (result)
117
- return result;
118
- }
119
124
  try {
120
- const response = yield fetch("https://openapi.debank.com/v1/token?chain_id=" + debank_ids_1.DEBANK_IDS[this.offchain.network] + "&id=" + tokenAddress);
121
- /*const response = await fetch(
122
- "https://pro-openapi.debank.com/v1/token?chain_id=" + debank_chain_ids[this.offchain.network] + "&id=" + tokenAddress,
123
- {headers: {"AccessKey": "0ac0fba6aeb0905b4c9a1c5cfd9d48d74fbc60e0"}}
124
- );*/
125
+ const chainId = dexscreener_ids[tokenAddress];
126
+ const response = yield fetch("https://api.dexscreener.com/latest/dex/search?q=" + tokenAddress);
125
127
  if (response.status != 200)
126
128
  return 0;
127
129
  const data = yield response.json();
128
- if (!data)
130
+ if (!data || !data.pairs || data.pairs.length === 0)
129
131
  return 0;
130
- return data.price ? data.price : 0;
132
+ const pairs = data.pairs;
133
+ const pairItem = pairs.filter((pair) => pair.chainId == chainId && (pair.baseToken.address.toLowerCase() == tokenAddress || pair.quoteToken.address.toLowerCase() == tokenAddress));
134
+ return pairItem.length > 0 ? pairItem[0].priceUsd : 0;
131
135
  }
132
136
  catch (_a) {
133
137
  return 0;
134
138
  }
135
139
  });
136
140
  }
141
+ initializeDebankTokenPrice(tokenAddress) {
142
+ return __awaiter(this, void 0, void 0, function* () {
143
+ if (Object.keys(dexscreener_ids).includes(tokenAddress.toLowerCase())) {
144
+ const result = yield this.getDexscreenerTokenPrice(tokenAddress.toLowerCase());
145
+ if (result)
146
+ return result;
147
+ }
148
+ if (Object.keys(coingecko_ids).includes(tokenAddress.toLowerCase())) {
149
+ const result = yield this.getCoingeckoTokenPrice(tokenAddress.toLowerCase());
150
+ if (result)
151
+ return result;
152
+ }
153
+ return 0;
154
+ // openapi is currently failing always so just commented out
155
+ // try {
156
+ // const response = await fetch("https://openapi.debank.com/v1/token?chain_id=" + DEBANK_IDS[this.offchain.network] + "&id=" + tokenAddress);
157
+ // /*const response = await fetch(
158
+ // "https://pro-openapi.debank.com/v1/token?chain_id=" + debank_chain_ids[this.offchain.network] + "&id=" + tokenAddress,
159
+ // {headers: {"AccessKey": "0ac0fba6aeb0905b4c9a1c5cfd9d48d74fbc60e0"}}
160
+ // );*/
161
+ // if (response.status != 200) return 0;
162
+ // const data = await response.json();
163
+ // if (!data) return 0;
164
+ // return data.price ? data.price : 0;
165
+ // }
166
+ // catch {
167
+ // return 0;
168
+ // }
169
+ });
170
+ }
137
171
  getDebankTokenPrice(tokenAddress) {
138
172
  return __awaiter(this, void 0, void 0, function* () {
139
173
  if (tokenAddress.toLowerCase() === '0xf28164a485b0b2c90639e47b0f377b4a438a16b1') { // fix for dQuick
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "1.2.43",
3
+ "version": "1.2.45",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",