@clonegod/ttd-core 3.1.96 → 3.1.98

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.
@@ -10,11 +10,11 @@ const token_util_1 = require("../token/token_util");
10
10
  function get_pair_name(native_token, pool_name) {
11
11
  pool_name = pool_name.split('/').map((s) => (0, __1.format_pair_symbol)(s)).join('/');
12
12
  const symbols = pool_name.split('/');
13
- if (pool_name.includes(native_token) && (pool_name.includes('USDC') || pool_name.includes('USDT') || pool_name.includes('USD1'))) {
13
+ if (pool_name.includes(native_token) && (pool_name.includes('USDC') || pool_name.includes('USDT') || pool_name.includes('USD1') || pool_name.includes('USDG'))) {
14
14
  if (pool_name.endsWith(native_token)) {
15
15
  symbols.reverse();
16
16
  }
17
- return symbols.join('/').replace('USDC', 'USDT').replace('USD1', 'USDT');
17
+ return symbols.join('/').replace('USDC', 'USDT').replace('USD1', 'USDT').replace('USDG', 'USDT');
18
18
  }
19
19
  if (symbols.includes(native_token)) {
20
20
  if (symbols[1] !== native_token) {
@@ -22,11 +22,11 @@ function get_pair_name(native_token, pool_name) {
22
22
  }
23
23
  return symbols.join('/');
24
24
  }
25
- if (symbols.includes('USDC') || symbols.includes('USDT') || symbols.includes('USD1')) {
26
- if (symbols[1] !== 'USDC' && symbols[1] !== 'USDT' && symbols[1] !== 'USD1') {
25
+ if (symbols.includes('USDC') || symbols.includes('USDT') || symbols.includes('USD1') || symbols.includes('USDG')) {
26
+ if (symbols[1] !== 'USDC' && symbols[1] !== 'USDT' && symbols[1] !== 'USD1' && symbols[1] !== 'USDG') {
27
27
  symbols.reverse();
28
28
  }
29
- return symbols.join('/').replace('USDC', 'USDT').replace('USD1', 'USDT');
29
+ return symbols.join('/').replace('USDC', 'USDT').replace('USD1', 'USDT').replace('USDG', 'USDT');
30
30
  }
31
31
  return pool_name;
32
32
  }
@@ -9,11 +9,7 @@ const is_not_arb_token = (token_or_pool_name) => {
9
9
  || symbols.includes('FDUSD')
10
10
  || symbols.includes('LUSD')
11
11
  || symbols.includes('RZUSD')
12
- || symbols.includes('USDE')
13
12
  || symbols.includes('AXLUSDC')
14
- || symbols.includes('USDS')
15
- || symbols.includes('USDG')
16
- || symbols.includes('USDY')
17
13
  || symbols.includes('EURC')
18
14
  || symbols.includes('BSOL')
19
15
  || symbols.includes('JITOSOL')
@@ -15,16 +15,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.get_eth_token_price_info = get_eth_token_price_info;
16
16
  require('dotenv').config();
17
17
  const axios_1 = __importDefault(require("axios"));
18
- const chains_1 = require("../../chains");
19
18
  const index_1 = require("../../index");
20
19
  const defi_llama_1 = require("./defi_llama");
21
20
  const gecko_terminal_1 = require("./gecko_terminal");
22
21
  const price_cache_1 = require("./price_cache");
23
22
  function get_eth_token_price_info(evm_chain_info, addresses, opts) {
24
23
  return __awaiter(this, void 0, void 0, function* () {
25
- var _a;
24
+ var _a, _b;
26
25
  const source = (_a = opts === null || opts === void 0 ? void 0 : opts.source) !== null && _a !== void 0 ? _a : 'cache_only';
27
26
  addresses = addresses.map(addr => addr.toLowerCase());
27
+ const ZERO_ADDR = '0x0000000000000000000000000000000000000000';
28
+ const wrappedNativeAddr = (_b = evm_chain_info.weth_addr) === null || _b === void 0 ? void 0 : _b.toLowerCase();
29
+ const wantsNative = !!wrappedNativeAddr && addresses.includes(ZERO_ADDR);
30
+ if (wantsNative) {
31
+ addresses = addresses.map(a => a === ZERO_ADDR ? wrappedNativeAddr : a);
32
+ addresses = Array.from(new Set(addresses));
33
+ }
28
34
  const result = new Map();
29
35
  const cachedChannel = {
30
36
  name: 'CachedPrice',
@@ -104,6 +110,11 @@ function get_eth_token_price_info(evm_chain_info, addresses, opts) {
104
110
  if (source !== 'cache_only' && addresses.length > 0) {
105
111
  (0, index_1.log_warn)(`[get_token_price_info] Failed to get prices for ${addresses.length} tokens after trying all channels: ${addresses.join(', ')}`);
106
112
  }
113
+ if (wantsNative) {
114
+ const wrappedInfo = result.get(wrappedNativeAddr);
115
+ if (wrappedInfo)
116
+ result.set(ZERO_ADDR, wrappedInfo);
117
+ }
107
118
  (0, index_1.log_debug)(`[get_token_price_info] Completed price fetching for ${result.size} tokens`);
108
119
  return result;
109
120
  }
@@ -178,15 +189,4 @@ function fetchPriceFromUniSwap(chain_name, addresses) {
178
189
  });
179
190
  }
180
191
  if (require.main === module) {
181
- (() => __awaiter(void 0, void 0, void 0, function* () {
182
- let evm_chain_info = chains_1.EvmChainConfig.ROBINHOOD;
183
- let addresses = [
184
- "0x0bd7d308f8e1639fab988df18a8011f41eacad73",
185
- "0x5fc5360d0400a0fd4f2af552add042d716f1d168".toLowerCase(),
186
- "0x020bfc650a365f8bb26819deaabf3e21291018b4".toLowerCase(),
187
- ];
188
- console.log(yield get_eth_token_price_info(evm_chain_info, addresses, { source: 'force_fetch' }));
189
- console.log(yield fetchPriceFromUniSwap(evm_chain_info.chain_full_name, addresses));
190
- console.log(yield (0, gecko_terminal_1.fetchPriceFromGeckoTerminal)(evm_chain_info.chain_short_name, addresses));
191
- }))();
192
192
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-core",
3
- "version": "3.1.96",
3
+ "version": "3.1.98",
4
4
  "description": "Common types and utilities for trading systems - use `npm run push` to publish",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",