@clonegod/ttd-core 2.0.1

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.
Files changed (77) hide show
  1. package/README.md +3 -0
  2. package/dist/analyze/index.d.ts +3 -0
  3. package/dist/analyze/index.js +49 -0
  4. package/dist/app_config/app_config.d.ts +15 -0
  5. package/dist/app_config/app_config.js +50 -0
  6. package/dist/app_config/env_args.d.ts +16 -0
  7. package/dist/app_config/env_args.js +28 -0
  8. package/dist/app_config/index.d.ts +2 -0
  9. package/dist/app_config/index.js +18 -0
  10. package/dist/cache/arb_cache.d.ts +80 -0
  11. package/dist/cache/arb_cache.js +1010 -0
  12. package/dist/cache/arb_event_pub.d.ts +14 -0
  13. package/dist/cache/arb_event_pub.js +77 -0
  14. package/dist/cache/arb_event_sub.d.ts +17 -0
  15. package/dist/cache/arb_event_sub.js +166 -0
  16. package/dist/cache/index.d.ts +6 -0
  17. package/dist/cache/index.js +22 -0
  18. package/dist/cache/loading_cache.d.ts +62 -0
  19. package/dist/cache/loading_cache.js +233 -0
  20. package/dist/cache/redis_client.d.ts +3 -0
  21. package/dist/cache/redis_client.js +73 -0
  22. package/dist/cache/redis_cmd.d.ts +14 -0
  23. package/dist/cache/redis_cmd.js +83 -0
  24. package/dist/index.d.ts +216 -0
  25. package/dist/index.js +883 -0
  26. package/dist/market_price/estimate_token_amount.d.ts +4 -0
  27. package/dist/market_price/estimate_token_amount.js +109 -0
  28. package/dist/market_price/index.d.ts +1 -0
  29. package/dist/market_price/index.js +17 -0
  30. package/dist/pool/cache_pool_config.d.ts +2 -0
  31. package/dist/pool/cache_pool_config.js +116 -0
  32. package/dist/pool/index.d.ts +3 -0
  33. package/dist/pool/index.js +19 -0
  34. package/dist/pool/pool_util.d.ts +5 -0
  35. package/dist/pool/pool_util.js +65 -0
  36. package/dist/pool/types.d.ts +20 -0
  37. package/dist/pool/types.js +2 -0
  38. package/dist/quote/index.d.ts +1 -0
  39. package/dist/quote/index.js +17 -0
  40. package/dist/quote/log_quote_price.d.ts +2 -0
  41. package/dist/quote/log_quote_price.js +29 -0
  42. package/dist/quote/on_quote_response.d.ts +3 -0
  43. package/dist/quote/on_quote_response.js +28 -0
  44. package/dist/quote/publish_quote_price.d.ts +3 -0
  45. package/dist/quote/publish_quote_price.js +19 -0
  46. package/dist/quote/to_price_message.d.ts +5 -0
  47. package/dist/quote/to_price_message.js +103 -0
  48. package/dist/test/test_is_empty.d.ts +1 -0
  49. package/dist/test/test_is_empty.js +24 -0
  50. package/dist/test/test_log_level.d.ts +3 -0
  51. package/dist/test/test_log_level.js +29 -0
  52. package/dist/test/test_merge_property.d.ts +1 -0
  53. package/dist/test/test_merge_property.js +21 -0
  54. package/dist/token/cache_token_config.d.ts +2 -0
  55. package/dist/token/cache_token_config.js +68 -0
  56. package/dist/token/fixed_symbol_address.d.ts +2 -0
  57. package/dist/token/fixed_symbol_address.js +26 -0
  58. package/dist/token/index.d.ts +6 -0
  59. package/dist/token/index.js +22 -0
  60. package/dist/token/is_not_arb_token.d.ts +1 -0
  61. package/dist/token/is_not_arb_token.js +24 -0
  62. package/dist/token/price/gecko_terminal.d.ts +2 -0
  63. package/dist/token/price/gecko_terminal.js +69 -0
  64. package/dist/token/price/get_bsc_token_price.d.ts +2 -0
  65. package/dist/token/price/get_bsc_token_price.js +131 -0
  66. package/dist/token/price/get_solana_token_price.d.ts +2 -0
  67. package/dist/token/price/get_solana_token_price.js +17 -0
  68. package/dist/token/price/get_tron_token_price.d.ts +2 -0
  69. package/dist/token/price/get_tron_token_price.js +17 -0
  70. package/dist/token/price/index.d.ts +3 -0
  71. package/dist/token/price/index.js +19 -0
  72. package/dist/token/token_util.d.ts +3 -0
  73. package/dist/token/token_util.js +23 -0
  74. package/dist/token/types.d.ts +29 -0
  75. package/dist/token/types.js +2 -0
  76. package/package.json +47 -0
  77. package/types/index.d.ts +709 -0
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.xx = xx;
4
+ exports.yy = yy;
5
+ exports.zz = zz;
6
+ const index_1 = require("../index");
7
+ function xx() {
8
+ (0, index_1.log_debug)('xx run');
9
+ yy();
10
+ }
11
+ function yy() {
12
+ (0, index_1.log_info)('yy run');
13
+ zz();
14
+ }
15
+ function zz() {
16
+ (0, index_1.log_error)('zz error', new Error(''));
17
+ }
18
+ const main = () => {
19
+ (0, index_1.new_line)(3);
20
+ console.log('process.env.LOG_LEVEL=', process.env.LOG_LEVEL);
21
+ console.log('LOG_LEVEL[process.env.LOG_LEVEL]=', index_1.LOG_LEVEL[process.env.LOG_LEVEL]);
22
+ console.log('LOG_LEVEL.DEBUG=', index_1.LOG_LEVEL.DEBUG);
23
+ console.log('_active_log_level', index_1._active_log_level);
24
+ console.log('log_trace', index_1.LOG.trace);
25
+ console.log('log_debug', index_1.LOG.debug);
26
+ console.log('log_info', index_1.LOG.info);
27
+ console.log('log_warn', index_1.LOG.warn);
28
+ };
29
+ main();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("../index");
4
+ const main = () => {
5
+ let default_settings = {
6
+ slippage: 10,
7
+ strategy: {
8
+ fee_exact: 0.0001,
9
+ fee_max: 0.0005,
10
+ }
11
+ };
12
+ let pair_settings = {
13
+ slippage: 30,
14
+ strategy: {
15
+ fee_exact: 0.0002
16
+ }
17
+ };
18
+ const deepMergedObjSpread = (0, index_1.deep_merge_object)(default_settings, pair_settings);
19
+ console.log(deepMergedObjSpread);
20
+ };
21
+ main();
@@ -0,0 +1,2 @@
1
+ import { CHAIN_ID, FormattedTokenInfo } from "../index";
2
+ export declare const cache_token_config: (chain_id: CHAIN_ID, valid_tokens_map: Map<string, FormattedTokenInfo[]>) => Promise<void>;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.cache_token_config = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const index_1 = require("../index");
18
+ const is_not_arb_token_1 = require("./is_not_arb_token");
19
+ const cache_token_config = (chain_id, valid_tokens_map) => __awaiter(void 0, void 0, void 0, function* () {
20
+ (0, index_1.log_info)(`cache_token_config start`);
21
+ let config_token_url = `http://${process.env.CONFIG_CENTER_HOST}/${chain_id}/config/tokens`;
22
+ let count = 0;
23
+ let batch_symbols = (0, index_1.chunkArray)(Array.from(valid_tokens_map.keys()), 20);
24
+ for (let one_batch of batch_symbols) {
25
+ let valid_tokens = [];
26
+ for (let key of one_batch) {
27
+ let value = valid_tokens_map.get(key);
28
+ if (!value || value.length !== 1) {
29
+ continue;
30
+ }
31
+ let token = value[0];
32
+ let std_token = {
33
+ symbol: token.symbol,
34
+ address: token.address,
35
+ address_hex: '',
36
+ decimals: token.decimals,
37
+ name: token.name,
38
+ is_token2022: false,
39
+ market_price: token.price,
40
+ update_time: (0, index_1.getCurDateTime)(),
41
+ alias: (0, index_1.get_token_symbol_alias)(token.address),
42
+ enable: true
43
+ };
44
+ if ((0, is_not_arb_token_1.is_not_arb_token)(std_token.symbol)) {
45
+ continue;
46
+ }
47
+ valid_tokens.push(std_token);
48
+ count += 1;
49
+ }
50
+ if (valid_tokens.length === 0) {
51
+ continue;
52
+ }
53
+ const body = valid_tokens;
54
+ const res = (yield axios_1.default.post(config_token_url, body, {
55
+ headers: { 'Content-Type': 'application/json' }
56
+ })).data;
57
+ (0, index_1.log_trace)('cache_token_config, res', res);
58
+ yield (0, index_1.sleep)(200);
59
+ }
60
+ (0, index_1.log_info)(`cache_token_config finish! sync token count: ${count}`);
61
+ let notify_config_change_url = `http://${process.env.CONFIG_CENTER_HOST}/${chain_id}/config/change?type=token`;
62
+ let res = (yield axios_1.default.get(notify_config_change_url)).data;
63
+ (0, index_1.log_info)('fetch tokens end, notify config change', {
64
+ notify_config_change_url,
65
+ res
66
+ });
67
+ });
68
+ exports.cache_token_config = cache_token_config;
@@ -0,0 +1,2 @@
1
+ import { TokenFixedSymbolAddress } from './types';
2
+ export declare const fixed_symbol_address: TokenFixedSymbolAddress[];
@@ -0,0 +1,26 @@
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
+ exports.fixed_symbol_address = void 0;
7
+ const os_1 = __importDefault(require("os"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const index_1 = require("../index");
10
+ const get_fixed_symbol_address = () => {
11
+ let chain_id = process.env.CHAIN_ID;
12
+ if (!chain_id) {
13
+ throw new Error(`process.env.CHAIN_ID is null or empty`);
14
+ }
15
+ let filepath = process.env.BSC_FIXED_SYMBOL_ADDRESS_FILE || path_1.default.join(os_1.default.homedir(), 'data', 'onchain_data', chain_id.toLowerCase(), 'fixed_symbol_address.json');
16
+ console.log(`get_fixed_symbol_address: ${filepath}`);
17
+ let fixed_symbol_address_list = [];
18
+ try {
19
+ fixed_symbol_address_list = (0, index_1.readFile)(filepath, true, true);
20
+ }
21
+ catch (error) {
22
+ console.error('get_fixed_symbol_address erro!', error);
23
+ }
24
+ return fixed_symbol_address_list;
25
+ };
26
+ exports.fixed_symbol_address = get_fixed_symbol_address();
@@ -0,0 +1,6 @@
1
+ export * from './cache_token_config';
2
+ export * from './fixed_symbol_address';
3
+ export * from './is_not_arb_token';
4
+ export * from './price';
5
+ export * from './token_util';
6
+ export * from './types';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./cache_token_config"), exports);
18
+ __exportStar(require("./fixed_symbol_address"), exports);
19
+ __exportStar(require("./is_not_arb_token"), exports);
20
+ __exportStar(require("./price"), exports);
21
+ __exportStar(require("./token_util"), exports);
22
+ __exportStar(require("./types"), exports);
@@ -0,0 +1 @@
1
+ export declare const is_not_arb_token: (token_or_pool_name: string) => boolean;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.is_not_arb_token = void 0;
4
+ const is_not_arb_token = (token_or_pool_name) => {
5
+ let symbols = token_or_pool_name.toUpperCase().split('/').filter(Boolean);
6
+ return (symbols.includes('USDC') && symbols.includes('USDT'))
7
+ || symbols.includes('BUSD')
8
+ || symbols.includes('TUSD')
9
+ || symbols.includes('FDUSD')
10
+ || symbols.includes('LUSD')
11
+ || symbols.includes('RZUSD')
12
+ || symbols.includes('USDE')
13
+ || symbols.includes('AXLUSDC')
14
+ || symbols.includes('USDS')
15
+ || symbols.includes('USDG')
16
+ || symbols.includes('USDY')
17
+ || symbols.includes('EURC')
18
+ || symbols.includes('BSOL')
19
+ || symbols.includes('JITOSOL')
20
+ || symbols.includes('JUPSOL')
21
+ || symbols.includes('MSOL')
22
+ || symbols.includes('SSOL');
23
+ };
24
+ exports.is_not_arb_token = is_not_arb_token;
@@ -0,0 +1,2 @@
1
+ import { FormattedTokenPrice } from "../../index";
2
+ export declare function fetchPriceFromGeckoTerminal(network: string, addresses: string[]): Promise<Map<string, FormattedTokenPrice>>;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.fetchPriceFromGeckoTerminal = fetchPriceFromGeckoTerminal;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const index_1 = require("../../index");
18
+ function fetchPriceFromGeckoTerminal(network, addresses) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const result = new Map();
21
+ const currentTime = (0, index_1.getCurDateTime)();
22
+ const timeout = 10000;
23
+ const maxRetries = 3;
24
+ const retrysleepMs = 1000;
25
+ const addressString = addresses.join(',');
26
+ const url = `https://api.geckoterminal.com/api/v2/simple/networks/${network.toLowerCase()}/token_price/${addressString}`;
27
+ (0, index_1.log_debug)(`[fetchPriceFromGeckoTerminal] Requesting prices for ${addresses.length} tokens`);
28
+ let retryCount = 0;
29
+ while (retryCount <= maxRetries) {
30
+ try {
31
+ const response = yield axios_1.default.get(url, { timeout });
32
+ if (response.data && response.data.data && response.data.data.attributes && response.data.data.attributes.token_prices) {
33
+ const tokenPrices = response.data.data.attributes.token_prices;
34
+ const foundTokens = Object.keys(tokenPrices);
35
+ if (foundTokens.length > 0) {
36
+ (0, index_1.log_debug)(`[fetchPriceFromGeckoTerminal] Retrieved prices for ${foundTokens.length}/${addresses.length} tokens`);
37
+ }
38
+ else {
39
+ (0, index_1.log_debug)(`[fetchPriceFromGeckoTerminal] No prices found for any tokens`);
40
+ }
41
+ for (const address of addresses) {
42
+ if (tokenPrices[address]) {
43
+ result.set(address, {
44
+ symbol: '',
45
+ address: address,
46
+ price: tokenPrices[address],
47
+ update_time: currentTime
48
+ });
49
+ }
50
+ }
51
+ }
52
+ else {
53
+ (0, index_1.log_debug)(`[fetchPriceFromGeckoTerminal] Invalid response format from GeckoTerminal API`);
54
+ }
55
+ break;
56
+ }
57
+ catch (error) {
58
+ retryCount++;
59
+ (0, index_1.log_warn)(`[fetchPriceFromGeckoTerminal] Request failed (attempt ${retryCount}/${maxRetries}): ${error instanceof Error ? error.message : String(error)}`);
60
+ if (retryCount <= maxRetries) {
61
+ const currentRetrysleep = retrysleepMs * retryCount;
62
+ (0, index_1.log_debug)(`[fetchPriceFromGeckoTerminal] Retrying in ${currentRetrysleep}ms...`);
63
+ yield (0, index_1.sleep)(currentRetrysleep);
64
+ }
65
+ }
66
+ }
67
+ return result;
68
+ });
69
+ }
@@ -0,0 +1,2 @@
1
+ import { FormattedTokenPrice } from "../types";
2
+ export declare function get_bsc_token_price_info(addresses: string[]): Promise<Map<string, FormattedTokenPrice>>;
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.get_bsc_token_price_info = get_bsc_token_price_info;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const index_1 = require("../../index");
18
+ const gecko_terminal_1 = require("./gecko_terminal");
19
+ function get_bsc_token_price_info(addresses) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const result = new Map();
22
+ const PRICE_CHANNELS = [
23
+ {
24
+ name: 'PancakeSwap',
25
+ fetchFn: fetchPriceFromPancakeSwap,
26
+ batchSize: 10,
27
+ batchDelay: 1000,
28
+ },
29
+ {
30
+ name: 'GeckoTerminal',
31
+ fetchFn: (address_list) => (0, gecko_terminal_1.fetchPriceFromGeckoTerminal)(index_1.CHAIN_ID.BSC, address_list),
32
+ batchSize: 10,
33
+ batchDelay: 2000,
34
+ },
35
+ ];
36
+ try {
37
+ for (const channel of PRICE_CHANNELS) {
38
+ if (addresses.length === 0)
39
+ break;
40
+ (0, index_1.log_debug)(`[get_token_price_info] Processing ${addresses.length} tokens using ${channel.name}`);
41
+ const batches = (0, index_1.chunkArray)(addresses, channel.batchSize);
42
+ (0, index_1.log_debug)(`[get_token_price_info] Split into ${batches.length} batches of size ${channel.batchSize}`);
43
+ let remainingAddresses = [...addresses];
44
+ for (let i = 0; i < batches.length; i++) {
45
+ const batch = batches[i];
46
+ if (batch.length === 0)
47
+ continue;
48
+ (0, index_1.log_debug)(`[get_token_price_info] Processing batch ${i + 1}/${batches.length} (${batch.length} tokens) with ${channel.name}`);
49
+ try {
50
+ const channelResult = yield channel.fetchFn(batch);
51
+ for (const [address, priceInfo] of channelResult.entries()) {
52
+ result.set(address, priceInfo);
53
+ remainingAddresses = remainingAddresses.filter(addr => addr !== address);
54
+ }
55
+ (0, index_1.log_debug)(`[get_token_price_info] ${channel.name} found prices for ${channelResult.size}/${batch.length} tokens in batch ${i + 1}`);
56
+ }
57
+ catch (error) {
58
+ (0, index_1.log_warn)(`[get_token_price_info] Error processing batch ${i + 1} with ${channel.name}: ${error instanceof Error ? error.message : String(error)}`);
59
+ }
60
+ if (i < batches.length - 1) {
61
+ yield (0, index_1.sleep)(channel.batchDelay);
62
+ }
63
+ }
64
+ addresses = [...remainingAddresses];
65
+ if (addresses.length === 0) {
66
+ (0, index_1.log_debug)(`[get_token_price_info] All token prices retrieved using ${channel.name}`);
67
+ break;
68
+ }
69
+ }
70
+ if (result.size === 0) {
71
+ throw new Error(`Unable to get price information for any token: ${addresses.join(', ')}`);
72
+ }
73
+ if (addresses.length > 0) {
74
+ (0, index_1.log_warn)(`[get_token_price_info] Failed to get prices for ${addresses.length} tokens after trying all channels: ${addresses.join(', ')}`);
75
+ }
76
+ (0, index_1.log_debug)(`[get_token_price_info] Completed price fetching for ${result.size} tokens`);
77
+ return result;
78
+ }
79
+ catch (error) {
80
+ throw new Error(`Failed to get token price information: ${error instanceof Error ? error.message : String(error)}`);
81
+ }
82
+ });
83
+ }
84
+ function fetchPriceFromPancakeSwap(addresses) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ const result = new Map();
87
+ const currentTime = (0, index_1.getCurDateTime)();
88
+ const timeout = 10000;
89
+ const maxRetries = 2;
90
+ const retrysleepMs = 500;
91
+ const addressString = addresses.map(addr => `56:${addr}`).join('%2C');
92
+ const url = `https://wallet-api.pancakeswap.com/v1/prices/list/${addressString}`;
93
+ (0, index_1.log_debug)(`[fetchPriceFromPancakeSwap] Requesting PancakeSwap API for ${addresses.length} tokens`);
94
+ let retryCount = 0;
95
+ while (retryCount <= maxRetries) {
96
+ try {
97
+ const response = yield axios_1.default.get(url, { timeout });
98
+ if (response.data) {
99
+ for (const address of addresses) {
100
+ const key = `56:${address}`;
101
+ if (response.data[key] !== undefined) {
102
+ result.set(address, {
103
+ symbol: '',
104
+ address: address,
105
+ price: response.data[key].toString(),
106
+ update_time: currentTime
107
+ });
108
+ }
109
+ }
110
+ (0, index_1.log_debug)(`[fetchPriceFromPancakeSwap] Retrieved prices for ${result.size}/${addresses.length} tokens`);
111
+ }
112
+ else {
113
+ (0, index_1.log_debug)(`[fetchPriceFromPancakeSwap] Invalid response from PancakeSwap for ${addresses.length} tokens`);
114
+ }
115
+ break;
116
+ }
117
+ catch (error) {
118
+ retryCount++;
119
+ (0, index_1.log_warn)(`[fetchPriceFromPancakeSwap] Request failed (attempt ${retryCount}/${maxRetries}): ${error instanceof Error ? error.message : String(error)}`);
120
+ if (retryCount <= maxRetries) {
121
+ const currentRetrysleep = retrysleepMs * retryCount;
122
+ (0, index_1.log_debug)(`[fetchPriceFromPancakeSwap] Retrying in ${currentRetrysleep}ms...`);
123
+ yield (0, index_1.sleep)(currentRetrysleep);
124
+ }
125
+ }
126
+ }
127
+ return result;
128
+ });
129
+ }
130
+ (() => __awaiter(void 0, void 0, void 0, function* () {
131
+ }))();
@@ -0,0 +1,2 @@
1
+ import { FormattedTokenPrice } from "../types";
2
+ export declare function get_solana_token_price_info(addresses: string[]): Promise<Map<string, FormattedTokenPrice>>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.get_solana_token_price_info = get_solana_token_price_info;
13
+ function get_solana_token_price_info(addresses) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ throw new Error(`not implement yet!`);
16
+ });
17
+ }
@@ -0,0 +1,2 @@
1
+ import { FormattedTokenPrice } from "../types";
2
+ export declare function get_tron_token_price_info(addresses: string[]): Promise<Map<string, FormattedTokenPrice>>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.get_tron_token_price_info = get_tron_token_price_info;
13
+ function get_tron_token_price_info(addresses) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ throw new Error(`not implement yet!`);
16
+ });
17
+ }
@@ -0,0 +1,3 @@
1
+ export * from './get_bsc_token_price';
2
+ export * from './get_solana_token_price';
3
+ export * from './get_tron_token_price';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./get_bsc_token_price"), exports);
18
+ __exportStar(require("./get_solana_token_price"), exports);
19
+ __exportStar(require("./get_tron_token_price"), exports);
@@ -0,0 +1,3 @@
1
+ export declare const formate_token_symbol: (symbol: string) => string;
2
+ export declare const is_valid_symbol: (symbol: string) => boolean;
3
+ export declare function get_token_symbol_alias(token_address: string): string;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.is_valid_symbol = exports.formate_token_symbol = void 0;
4
+ exports.get_token_symbol_alias = get_token_symbol_alias;
5
+ const __1 = require("..");
6
+ const formate_token_symbol = (symbol) => {
7
+ return symbol.toUpperCase()
8
+ .replace('$', '')
9
+ .replace('WSOL', 'SOL')
10
+ .replace('WBTC', 'BTC')
11
+ .replace('WETH', 'ETH').replace('WHETH', 'ETH')
12
+ .replace('WBNB', 'BNB')
13
+ .trim();
14
+ };
15
+ exports.formate_token_symbol = formate_token_symbol;
16
+ const is_valid_symbol = (symbol) => {
17
+ return !(0, __1.isEmpty)(symbol) && /^[a-zA-Z0-9_.+-]+$/.test(symbol);
18
+ };
19
+ exports.is_valid_symbol = is_valid_symbol;
20
+ function get_token_symbol_alias(token_address) {
21
+ let token = __1.fixed_symbol_address.find(e => e.address === token_address);
22
+ return (token === null || token === void 0 ? void 0 : token.alias) || '';
23
+ }
@@ -0,0 +1,29 @@
1
+ export interface PriceChannelConfig {
2
+ name: string;
3
+ fetchFn: (addresses: string[]) => Promise<Map<string, FormattedTokenPrice>>;
4
+ batchSize: number;
5
+ batchDelay: number;
6
+ }
7
+ export interface TokenFixedSymbolAddress {
8
+ symbol: string;
9
+ ref: string;
10
+ alias: string;
11
+ address: string;
12
+ }
13
+ export interface FormattedTokenInfo {
14
+ chainId: number;
15
+ address: string;
16
+ programId: string;
17
+ logoURI: string;
18
+ symbol: string;
19
+ name: string;
20
+ decimals: number;
21
+ is_token_2022: boolean;
22
+ price?: string;
23
+ }
24
+ export interface FormattedTokenPrice {
25
+ symbol: string;
26
+ address: string;
27
+ price: string;
28
+ update_time: string;
29
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@clonegod/ttd-core",
3
+ "version": "2.0.1",
4
+ "description": "Common types and utilities for trading systems",
5
+ "main": "dist/index.js",
6
+ "types": "types/index.d.ts",
7
+ "keywords": [],
8
+ "author": "",
9
+ "license": "ISC",
10
+ "scripts": {
11
+ "clean": "rm -rf dist node_modules",
12
+ "build": "npx tsc --outDir ./dist",
13
+ "push": "npm run build && npm publish"
14
+ },
15
+ "dependencies": {
16
+ "dotenv": "^16.4.7",
17
+ "redis": "^4.7.0",
18
+ "express": "^4.19.2",
19
+ "express-ws": "^5.0.2",
20
+ "body-parser": "^1.20.3",
21
+ "axios": "^1.8.4",
22
+ "bn.js": "^5.2.1",
23
+ "bs58": "^6.0.0",
24
+ "decimal.js": "^10.5.0",
25
+ "moment": "^2.30.1",
26
+ "uuid": "^11.1.0",
27
+ "short-uuid": "^5.2.0",
28
+ "keccak": "^3.0.4",
29
+ "@noble/secp256k1": "1.7.1",
30
+ "typescript": "^5.3.3",
31
+ "ts-node": "^10.9.2"
32
+ },
33
+ "devDependencies": {
34
+ "@types/bn.js": "~5.1.5",
35
+ "chai": "^5.0.0",
36
+ "mocha": "^10.2.0",
37
+ "rimraf": "^5.0.5",
38
+ "ts-mocha": "^10.0.0",
39
+ "ts-node": "^10.9.2",
40
+ "typescript": "^5.3.3",
41
+ "@types/node": "^22.7.9"
42
+ },
43
+ "overrides": {},
44
+ "publishConfig": {
45
+ "access": "public"
46
+ }
47
+ }