@clonegod/ttd-core 2.0.56 → 2.0.58
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.
package/dist/index.d.ts
CHANGED
|
@@ -56,7 +56,10 @@ export declare enum DEX_ID {
|
|
|
56
56
|
LFJ_V1 = "LFJ-V1",
|
|
57
57
|
LFJ_V2 = "LFJ-V2",
|
|
58
58
|
BLACKHOLE_V2 = "BLACKHOLE-V2",
|
|
59
|
-
BLACKHOLE_V3 = "BLACKHOLE-V3"
|
|
59
|
+
BLACKHOLE_V3 = "BLACKHOLE-V3",
|
|
60
|
+
MOMENTUM = "MOMENTUM",
|
|
61
|
+
CETUS = "CETUS",
|
|
62
|
+
BLUEFIN = "BLUEFIN"
|
|
60
63
|
}
|
|
61
64
|
export declare enum GROUP_ID {
|
|
62
65
|
TRON_DEV1 = "TRON-DEV1",
|
package/dist/index.js
CHANGED
|
@@ -141,6 +141,9 @@ var DEX_ID;
|
|
|
141
141
|
DEX_ID["LFJ_V2"] = "LFJ-V2";
|
|
142
142
|
DEX_ID["BLACKHOLE_V2"] = "BLACKHOLE-V2";
|
|
143
143
|
DEX_ID["BLACKHOLE_V3"] = "BLACKHOLE-V3";
|
|
144
|
+
DEX_ID["MOMENTUM"] = "MOMENTUM";
|
|
145
|
+
DEX_ID["CETUS"] = "CETUS";
|
|
146
|
+
DEX_ID["BLUEFIN"] = "BLUEFIN";
|
|
144
147
|
})(DEX_ID || (exports.DEX_ID = DEX_ID = {}));
|
|
145
148
|
var GROUP_ID;
|
|
146
149
|
(function (GROUP_ID) {
|
|
@@ -0,0 +1,65 @@
|
|
|
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.fetchPriceFromDefiLlama = fetchPriceFromDefiLlama;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const index_1 = require("../../index");
|
|
18
|
+
function fetchPriceFromDefiLlama(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.map(address => `${network.toLowerCase()}:${address}`).join(',');
|
|
26
|
+
const url = `https://coins.llama.fi/prices/current/${addressString}`;
|
|
27
|
+
console.log(url);
|
|
28
|
+
(0, index_1.log_debug)(`[fetchPriceFromDefiLlama] Requesting prices for ${addresses.length} tokens`);
|
|
29
|
+
let retryCount = 0;
|
|
30
|
+
while (retryCount <= maxRetries) {
|
|
31
|
+
try {
|
|
32
|
+
const response = yield axios_1.default.get(url, { timeout });
|
|
33
|
+
let tokenPrices = response.data['coins'];
|
|
34
|
+
if (tokenPrices) {
|
|
35
|
+
for (const address of addresses) {
|
|
36
|
+
let network_token_address = `${network.toLowerCase()}:${address}`;
|
|
37
|
+
if (tokenPrices[network_token_address]) {
|
|
38
|
+
result.set(address, {
|
|
39
|
+
address: address,
|
|
40
|
+
price: tokenPrices[network_token_address].price,
|
|
41
|
+
symbol: tokenPrices[network_token_address].symbol,
|
|
42
|
+
name: '',
|
|
43
|
+
update_time: currentTime
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
(0, index_1.log_debug)(`[fetchPriceFromDefiLlama] Invalid response format from DefiLlama API`);
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
retryCount++;
|
|
55
|
+
(0, index_1.log_warn)(`[fetchPriceFromDefiLlama] Request failed (attempt ${retryCount}/${maxRetries}): ${error instanceof Error ? error.message : String(error)}`);
|
|
56
|
+
if (retryCount <= maxRetries) {
|
|
57
|
+
const currentRetrysleep = retrysleepMs * retryCount;
|
|
58
|
+
(0, index_1.log_debug)(`[fetchPriceFromDefiLlama] Retrying in ${currentRetrysleep}ms...`);
|
|
59
|
+
yield (0, index_1.sleep)(currentRetrysleep);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
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_sui_token_price_info = get_sui_token_price_info;
|
|
13
|
+
require('dotenv').config();
|
|
14
|
+
const index_1 = require("../../index");
|
|
15
|
+
const defi_llama_1 = require("./defi_llama");
|
|
16
|
+
const gecko_terminal_1 = require("./gecko_terminal");
|
|
17
|
+
const price_cache_1 = require("./price_cache");
|
|
18
|
+
function get_sui_token_price_info(addresses) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
(0, index_1.log_info)(`get_sui_token_price_info`, addresses);
|
|
21
|
+
const result = new Map();
|
|
22
|
+
const PRICE_CHANNELS = [
|
|
23
|
+
{
|
|
24
|
+
name: 'CachedPrice',
|
|
25
|
+
fetchFn: price_cache_1.fetchPriceFromCache,
|
|
26
|
+
batchSize: 100,
|
|
27
|
+
batchDelay: 1000,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'DefiLlama',
|
|
31
|
+
fetchFn: (address_list) => (0, defi_llama_1.fetchPriceFromDefiLlama)(index_1.CHAIN_ID.SUI, address_list),
|
|
32
|
+
batchSize: 10,
|
|
33
|
+
batchDelay: 2000,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'GeckoTerminal',
|
|
37
|
+
fetchFn: (address_list) => (0, gecko_terminal_1.fetchPriceFromGeckoTerminal)('sui-network', address_list),
|
|
38
|
+
batchSize: 10,
|
|
39
|
+
batchDelay: 2000,
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
try {
|
|
43
|
+
for (const channel of PRICE_CHANNELS) {
|
|
44
|
+
if (addresses.length === 0)
|
|
45
|
+
break;
|
|
46
|
+
(0, index_1.log_debug)(`[get_token_price_info] Processing ${addresses.length} tokens using ${channel.name}`);
|
|
47
|
+
const batches = (0, index_1.chunkArray)(addresses, channel.batchSize);
|
|
48
|
+
(0, index_1.log_debug)(`[get_token_price_info] Split into ${batches.length} batches of size ${channel.batchSize}`);
|
|
49
|
+
let remainingAddresses = [...addresses];
|
|
50
|
+
for (let i = 0; i < batches.length; i++) {
|
|
51
|
+
const batch = batches[i];
|
|
52
|
+
if (batch.length === 0)
|
|
53
|
+
continue;
|
|
54
|
+
(0, index_1.log_debug)(`[get_token_price_info] Processing batch ${i + 1}/${batches.length} (${batch.length} tokens) with ${channel.name}`);
|
|
55
|
+
try {
|
|
56
|
+
const channelResult = yield channel.fetchFn(batch);
|
|
57
|
+
for (const [address, priceInfo] of channelResult.entries()) {
|
|
58
|
+
result.set(address, priceInfo);
|
|
59
|
+
remainingAddresses = remainingAddresses.filter(addr => addr !== address);
|
|
60
|
+
if (channel.name !== 'CachedPrice') {
|
|
61
|
+
(0, price_cache_1.cache_new_market_price)(address, priceInfo.price, channel.name);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
(0, index_1.log_debug)(`[get_token_price_info] ${channel.name} found prices for ${channelResult.size}/${batch.length} tokens in batch ${i + 1}`);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
(0, index_1.log_warn)(`[get_token_price_info] Error processing batch ${i + 1} with ${channel.name}: ${error instanceof Error ? error.message : String(error)}`);
|
|
68
|
+
}
|
|
69
|
+
if (i < batches.length - 1) {
|
|
70
|
+
yield (0, index_1.sleep)(channel.batchDelay);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
addresses = [...remainingAddresses];
|
|
74
|
+
if (addresses.length === 0) {
|
|
75
|
+
(0, index_1.log_debug)(`[get_token_price_info] All token prices retrieved using ${channel.name}`);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (result.size === 0) {
|
|
80
|
+
throw new Error(`Unable to get price information for any token: ${addresses.join(', ')}`);
|
|
81
|
+
}
|
|
82
|
+
if (addresses.length > 0) {
|
|
83
|
+
(0, index_1.log_warn)(`[get_token_price_info] Failed to get prices for ${addresses.length} tokens after trying all channels: ${addresses.join(', ')}`);
|
|
84
|
+
}
|
|
85
|
+
(0, index_1.log_debug)(`[get_token_price_info] Completed price fetching for ${result.size} tokens`);
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
throw new Error(`Failed to get token price information: ${error instanceof Error ? error.message : String(error)}`);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (require.main === module) {
|
|
94
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
+
let addresses = [
|
|
96
|
+
"0x2::sui::SUI",
|
|
97
|
+
"0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT",
|
|
98
|
+
"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
|
|
99
|
+
"0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL",
|
|
100
|
+
];
|
|
101
|
+
}))();
|
|
102
|
+
}
|