@defillama/sdk 5.0.240 → 5.0.242
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/build/Balances.d.ts +139 -0
- package/build/Balances.js +363 -0
- package/build/ChainApi.d.ts +142 -0
- package/build/ChainApi.js +310 -0
- package/build/abi/abi2.d.ts +5 -0
- package/build/abi/abi2.js +215 -0
- package/build/abi/cachedABIs.d.ts +4 -0
- package/build/abi/cachedABIs.js +8 -0
- package/build/abi/convertResults.d.ts +5 -0
- package/build/abi/convertResults.js +60 -0
- package/build/abi/index.d.ts +31 -0
- package/build/abi/index.js +327 -0
- package/build/abi/multicall.d.ts +23 -0
- package/build/abi/multicall.js +383 -0
- package/build/abi/multicall3.d.ts +7 -0
- package/build/abi/multicall3.js +403 -0
- package/build/abi/rpcCall.d.ts +4 -0
- package/build/abi/rpcCall.js +62 -0
- package/build/abi/tron.d.ts +33 -0
- package/build/abi/tron.js +116 -0
- package/build/api.d.ts +10 -0
- package/build/api.js +45 -0
- package/build/api2.d.ts +5 -0
- package/build/api2.js +41 -0
- package/build/chains/algorand.d.ts +277 -0
- package/build/chains/algorand.js +618 -0
- package/build/chains/aptos.d.ts +269 -0
- package/build/chains/aptos.js +700 -0
- package/build/chains/cardano.d.ts +242 -0
- package/build/chains/cardano.js +407 -0
- package/build/chains/cosmos.d.ts +252 -0
- package/build/chains/cosmos.js +618 -0
- package/build/chains/icp.d.ts +235 -0
- package/build/chains/icp.js +1040 -0
- package/build/chains/index.d.ts +23 -0
- package/build/chains/index.js +59 -0
- package/build/chains/near.d.ts +192 -0
- package/build/chains/near.js +446 -0
- package/build/chains/rpc.d.ts +125 -0
- package/build/chains/rpc.js +326 -0
- package/build/chains/starknet.d.ts +205 -0
- package/build/chains/starknet.js +884 -0
- package/build/chains/stellar.d.ts +410 -0
- package/build/chains/stellar.js +1082 -0
- package/build/chains/substrate.d.ts +333 -0
- package/build/chains/substrate.js +1042 -0
- package/build/chains/sui.d.ts +365 -0
- package/build/chains/sui.js +1135 -0
- package/build/chains/svm.d.ts +340 -0
- package/build/chains/svm.js +760 -0
- package/build/chains/tezos.d.ts +225 -0
- package/build/chains/tezos.js +412 -0
- package/build/chains/ton.d.ts +353 -0
- package/build/chains/ton.js +788 -0
- package/build/chains/tron.d.ts +45 -0
- package/build/chains/tron.js +110 -0
- package/build/chains/utxo.d.ts +210 -0
- package/build/chains/utxo.js +678 -0
- package/build/chains/xrpl.d.ts +179 -0
- package/build/chains/xrpl.js +467 -0
- package/build/computeTVL/blocks.d.ts +1 -0
- package/build/computeTVL/blocks.js +12 -0
- package/build/computeTVL/humanizeNumber.d.ts +1 -0
- package/build/computeTVL/humanizeNumber.js +19 -0
- package/build/erc20/index.d.ts +31 -0
- package/build/erc20/index.js +56 -0
- package/build/eth/index.d.ts +22 -0
- package/build/eth/index.js +118 -0
- package/build/general.d.ts +5 -0
- package/build/general.js +20 -0
- package/build/generalUtil.d.ts +8 -0
- package/build/generalUtil.js +73 -0
- package/build/index.d.ts +32 -0
- package/build/index.js +74 -0
- package/build/providers.json +1 -0
- package/build/types.d.ts +76 -0
- package/build/types.js +2 -0
- package/build/util/LlamaProvider.d.ts +46 -0
- package/build/util/LlamaProvider.js +367 -0
- package/build/util/blocks.d.ts +36 -0
- package/build/util/blocks.js +500 -0
- package/build/util/cache.d.ts +45 -0
- package/build/util/cache.js +309 -0
- package/build/util/chainUtils/data.json +1437 -0
- package/build/util/chainUtils/index.d.ts +11 -0
- package/build/util/chainUtils/index.js +136 -0
- package/build/util/coins.d.ts +19 -0
- package/build/util/coins.js +124 -0
- package/build/util/common.d.ts +34 -0
- package/build/util/common.js +376 -0
- package/build/util/computeTVL.d.ts +19 -0
- package/build/util/computeTVL.js +102 -0
- package/build/util/cosmos.d.ts +1 -0
- package/build/util/cosmos.js +8 -0
- package/build/util/debugLog.d.ts +4 -0
- package/build/util/debugLog.js +18 -0
- package/build/util/discord.d.ts +1 -0
- package/build/util/discord.js +33 -0
- package/build/util/elastic.d.ts +43 -0
- package/build/util/elastic.js +113 -0
- package/build/util/env.d.ts +20 -0
- package/build/util/env.js +176 -0
- package/build/util/graph.d.ts +8 -0
- package/build/util/graph.js +50 -0
- package/build/util/index.d.ts +32 -0
- package/build/util/index.js +227 -0
- package/build/util/indexer.compatibility.d.ts +6 -0
- package/build/util/indexer.compatibility.js +64 -0
- package/build/util/indexer.d.ts +92 -0
- package/build/util/indexer.js +850 -0
- package/build/util/indexerSql.d.ts +9 -0
- package/build/util/indexerSql.js +102 -0
- package/build/util/internal-cache.d.ts +11 -0
- package/build/util/internal-cache.js +77 -0
- package/build/util/logs.d.ts +58 -0
- package/build/util/logs.decode.shared.d.ts +8 -0
- package/build/util/logs.decode.shared.js +289 -0
- package/build/util/logs.js +432 -0
- package/build/util/promisePool.d.ts +8 -0
- package/build/util/promisePool.js +31 -0
- package/build/util/r2.d.ts +4 -0
- package/build/util/r2.js +52 -0
- package/build/util/removeRedundantRPCs.d.ts +1 -0
- package/build/util/removeRedundantRPCs.js +49 -0
- package/build/util/transactions.d.ts +35 -0
- package/build/util/transactions.js +22 -0
- package/build/util/updateChainLabels.d.ts +1 -0
- package/build/util/updateChainLabels.js +5 -0
- package/build/util/updateProviderList.d.ts +1 -0
- package/build/util/updateProviderList.js +275 -0
- package/package.json +3 -2
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { chainKeyToChainLabelMap, chainLabelsToKeyMap } from './data.json';
|
|
2
|
+
export { chainKeyToChainLabelMap, chainLabelsToKeyMap, };
|
|
3
|
+
export declare function updateData(): Promise<void>;
|
|
4
|
+
export declare function updateChainLabels(): Promise<void>;
|
|
5
|
+
export declare const sluggifyString: (name: string) => string;
|
|
6
|
+
export declare function getSluggifiedChainLabel(label: string): string;
|
|
7
|
+
export declare function getChainKeyFromLabel(label: string): string;
|
|
8
|
+
export declare function getChainLabelFromKey(id: string): string;
|
|
9
|
+
export declare function getDeadChains(): string[];
|
|
10
|
+
export declare function getDeadChainsSet(): Set<string>;
|
|
11
|
+
export declare function isDeadChain(chainKeyOrLabel: string): boolean;
|
|
@@ -0,0 +1,136 @@
|
|
|
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.sluggifyString = exports.chainLabelsToKeyMap = exports.chainKeyToChainLabelMap = void 0;
|
|
7
|
+
exports.updateData = updateData;
|
|
8
|
+
exports.updateChainLabels = updateChainLabels;
|
|
9
|
+
exports.getSluggifiedChainLabel = getSluggifiedChainLabel;
|
|
10
|
+
exports.getChainKeyFromLabel = getChainKeyFromLabel;
|
|
11
|
+
exports.getChainLabelFromKey = getChainLabelFromKey;
|
|
12
|
+
exports.getDeadChains = getDeadChains;
|
|
13
|
+
exports.getDeadChainsSet = getDeadChainsSet;
|
|
14
|
+
exports.isDeadChain = isDeadChain;
|
|
15
|
+
const data_json_1 = require("./data.json");
|
|
16
|
+
Object.defineProperty(exports, "chainKeyToChainLabelMap", { enumerable: true, get: function () { return data_json_1.chainKeyToChainLabelMap; } });
|
|
17
|
+
Object.defineProperty(exports, "chainLabelsToKeyMap", { enumerable: true, get: function () { return data_json_1.chainLabelsToKeyMap; } });
|
|
18
|
+
const fs_1 = __importDefault(require("fs"));
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const deadChainsArray = Object.keys(data_json_1.deadChains);
|
|
21
|
+
const deadChainsSet = new Set(deadChainsArray);
|
|
22
|
+
async function updateData() {
|
|
23
|
+
var _a;
|
|
24
|
+
try {
|
|
25
|
+
// mapping pulled from https://github.com/DefiLlama/defillama-server/blob/master/defi/src/utils/normalizeChain.ts
|
|
26
|
+
const response = await fetch('https://api.llama.fi/overview/_internal/chain-name-id-map-v2');
|
|
27
|
+
const remoteData = await response.json();
|
|
28
|
+
for (const [key, value] of Object.entries(remoteData.chainKeyToChainLabelMap)) {
|
|
29
|
+
data_json_1.chainKeyToChainLabelMap[key] = value;
|
|
30
|
+
}
|
|
31
|
+
for (const [key, value] of Object.entries(remoteData.chainLabelsToKeyMap)) {
|
|
32
|
+
data_json_1.chainLabelsToKeyMap[key] = value;
|
|
33
|
+
}
|
|
34
|
+
// dead chains are pulled from the `deadFrom` field on chainCoingeckoIds entries in https://api.llama.fi/config
|
|
35
|
+
const configResponse = await fetch('https://api.llama.fi/config');
|
|
36
|
+
const config = await configResponse.json();
|
|
37
|
+
for (const [label, value] of Object.entries((_a = config.chainCoingeckoIds) !== null && _a !== void 0 ? _a : {})) {
|
|
38
|
+
const deadFrom = value === null || value === void 0 ? void 0 : value.deadFrom;
|
|
39
|
+
if (!deadFrom)
|
|
40
|
+
continue;
|
|
41
|
+
const key = getChainKeyFromLabel(label);
|
|
42
|
+
data_json_1.deadChains[key] = deadFrom;
|
|
43
|
+
if (!deadChainsSet.has(key)) {
|
|
44
|
+
deadChainsSet.add(key);
|
|
45
|
+
deadChainsArray.push(key);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Save to data.json file
|
|
49
|
+
const dataFilePath = path_1.default.join(__dirname, 'data.json');
|
|
50
|
+
fs_1.default.writeFileSync(dataFilePath, JSON.stringify({
|
|
51
|
+
chainKeyToChainLabelMap: sortJSONData(data_json_1.chainKeyToChainLabelMap),
|
|
52
|
+
chainLabelsToKeyMap: sortJSONData(data_json_1.chainLabelsToKeyMap),
|
|
53
|
+
deadChains: sortJSONData(data_json_1.deadChains),
|
|
54
|
+
}, null, 2));
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.error('Error updating chain data:', error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// runs updateData and sanity checks that the mappings only grew
|
|
61
|
+
async function updateChainLabels() {
|
|
62
|
+
const chainKeyLabelMapCountBefore = Object.keys(data_json_1.chainKeyToChainLabelMap).length;
|
|
63
|
+
const chainLabelsKeyMapCountBefore = Object.keys(data_json_1.chainLabelsToKeyMap).length;
|
|
64
|
+
await updateData();
|
|
65
|
+
const chainKeyLabelMapCountAfter = Object.keys(data_json_1.chainKeyToChainLabelMap).length;
|
|
66
|
+
const chainLabelsKeyMapCountAfter = Object.keys(data_json_1.chainLabelsToKeyMap).length;
|
|
67
|
+
if (chainKeyLabelMapCountAfter > chainKeyLabelMapCountBefore) {
|
|
68
|
+
console.log(`Updated chainKeyToChainLabelMap: ${chainKeyLabelMapCountBefore} -> ${chainKeyLabelMapCountAfter}`);
|
|
69
|
+
}
|
|
70
|
+
if (chainLabelsKeyMapCountAfter > chainLabelsKeyMapCountBefore) {
|
|
71
|
+
console.log(`Updated chainLabelsToKeyMap: ${chainLabelsKeyMapCountBefore} -> ${chainLabelsKeyMapCountAfter}`);
|
|
72
|
+
}
|
|
73
|
+
if (chainKeyLabelMapCountAfter < chainKeyLabelMapCountBefore)
|
|
74
|
+
throw new Error('chainKeyToChainLabelMap count decreased, please investigate');
|
|
75
|
+
if (chainLabelsKeyMapCountAfter < chainLabelsKeyMapCountBefore)
|
|
76
|
+
throw new Error('chainLabelsToKeyMap count decreased, please investigate');
|
|
77
|
+
}
|
|
78
|
+
const sluggifyString = (name) => name.toLowerCase().split(" ").join("-").split("'").join("");
|
|
79
|
+
exports.sluggifyString = sluggifyString;
|
|
80
|
+
function sortJSONData(jsonData) {
|
|
81
|
+
const sortedKeys = Object.keys(jsonData).sort();
|
|
82
|
+
const sortedData = {};
|
|
83
|
+
for (const key of sortedKeys) {
|
|
84
|
+
sortedData[key] = jsonData[key];
|
|
85
|
+
}
|
|
86
|
+
return sortedData;
|
|
87
|
+
}
|
|
88
|
+
const _chainLabelToChainIdCache = {};
|
|
89
|
+
Object.entries(data_json_1.chainLabelsToKeyMap).forEach(([label, id]) => {
|
|
90
|
+
_chainLabelToChainIdCache[label] = id;
|
|
91
|
+
_chainLabelToChainIdCache[(0, exports.sluggifyString)(label)] = id;
|
|
92
|
+
});
|
|
93
|
+
// this is needed because multiple labels can point to the same chain key, so we need to ensure that while writing/reading from the cache, we always use the same label irrespective what is passed in
|
|
94
|
+
// now, Avalance, Avax, avalanche -> avalanche
|
|
95
|
+
function getSluggifiedChainLabel(label) {
|
|
96
|
+
const chainKey = getChainKeyFromLabel(label);
|
|
97
|
+
label = getChainLabelFromKey(chainKey);
|
|
98
|
+
return (0, exports.sluggifyString)(label);
|
|
99
|
+
}
|
|
100
|
+
// to be used if we are unsure if a label exists in our system, if it is known, use chainLabelsToKeyMap instead
|
|
101
|
+
function getChainKeyFromLabel(label) {
|
|
102
|
+
let value = _chainLabelToChainIdCache[label];
|
|
103
|
+
if (!value) {
|
|
104
|
+
let sluggifiedLabel = (0, exports.sluggifyString)(label);
|
|
105
|
+
value = _chainLabelToChainIdCache[sluggifiedLabel];
|
|
106
|
+
if (!value) {
|
|
107
|
+
value = sluggifiedLabel.replace(/\-/g, '_'); // try replacing - with _
|
|
108
|
+
_chainLabelToChainIdCache[sluggifiedLabel] = value;
|
|
109
|
+
}
|
|
110
|
+
_chainLabelToChainIdCache[label] = value;
|
|
111
|
+
}
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
// to be used if we are unsure if a label exists in our system, if it is known, use chainKeyToChainLabelMap instead
|
|
115
|
+
function getChainLabelFromKey(id) {
|
|
116
|
+
let value = data_json_1.chainKeyToChainLabelMap[id];
|
|
117
|
+
if (value)
|
|
118
|
+
return value;
|
|
119
|
+
value = id.slice(0, 1).toUpperCase() + id.slice(1); // Capitalize first letter
|
|
120
|
+
data_json_1.chainKeyToChainLabelMap[id] = value;
|
|
121
|
+
return value;
|
|
122
|
+
}
|
|
123
|
+
// returns the map of dead chains keyed by chain key, with the date (YYYY-MM-DD) the chain was marked dead as the value
|
|
124
|
+
function getDeadChains() {
|
|
125
|
+
return deadChainsArray;
|
|
126
|
+
}
|
|
127
|
+
// returns a Set of dead chain keys (cached)
|
|
128
|
+
function getDeadChainsSet() {
|
|
129
|
+
return deadChainsSet;
|
|
130
|
+
}
|
|
131
|
+
// returns true if the given chain (by key or label) is dead
|
|
132
|
+
function isDeadChain(chainKeyOrLabel) {
|
|
133
|
+
if (deadChainsSet.has(chainKeyOrLabel))
|
|
134
|
+
return true;
|
|
135
|
+
return deadChainsSet.has(getChainKeyFromLabel(chainKeyOrLabel));
|
|
136
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type CoinsApiData = {
|
|
2
|
+
decimals: number;
|
|
3
|
+
price: number;
|
|
4
|
+
symbol: string;
|
|
5
|
+
timestamp: number;
|
|
6
|
+
PK?: string;
|
|
7
|
+
isDistressed?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type McapsApiData = {
|
|
10
|
+
mcap: number;
|
|
11
|
+
timestamp: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function getPrices(readKeys: string[], timestamp: number | "now"): Promise<{
|
|
14
|
+
[address: string]: CoinsApiData;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function getMcaps(readKeys: string[], timestamp: number | "now"): Promise<{
|
|
17
|
+
[address: string]: McapsApiData;
|
|
18
|
+
}>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
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.getPrices = getPrices;
|
|
7
|
+
exports.getMcaps = getMcaps;
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const env_1 = require("./env");
|
|
10
|
+
const promisePool_1 = __importDefault(require("./promisePool"));
|
|
11
|
+
const common_1 = require("./common");
|
|
12
|
+
const _1 = require(".");
|
|
13
|
+
const coinsApiKey = (0, env_1.getEnvValue)("COINS_API_KEY");
|
|
14
|
+
const proApiKey = (0, env_1.getEnvValue)("INTERNAL_API_KEY");
|
|
15
|
+
const bodySize = 100;
|
|
16
|
+
function getBodies(readKeys, timestamp) {
|
|
17
|
+
const chunks = (0, _1.sliceIntoChunks)(readKeys, bodySize);
|
|
18
|
+
return chunks.map(chunk => {
|
|
19
|
+
const body = { coins: chunk };
|
|
20
|
+
if (timestamp !== "now")
|
|
21
|
+
body.timestamp = timestamp;
|
|
22
|
+
return body;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async function restCallWrapper(request, retries = 3, name = "-") {
|
|
26
|
+
retries--;
|
|
27
|
+
try {
|
|
28
|
+
const res = await request();
|
|
29
|
+
return res;
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
if (retries <= 0)
|
|
33
|
+
throw (0, common_1.formError)(e);
|
|
34
|
+
}
|
|
35
|
+
await (0, common_1.sleepRandom)(2000 + 10000, 2000);
|
|
36
|
+
return restCallWrapper(request, retries, name);
|
|
37
|
+
}
|
|
38
|
+
async function fetchWithProFallback(body, subRoute) {
|
|
39
|
+
// if pro api key is set, try the pro route first and fall back to the normal route on failure
|
|
40
|
+
if (proApiKey) {
|
|
41
|
+
try {
|
|
42
|
+
return await restCallWrapper(() => axios_1.default.post(`https://pro-api.llama.fi/${proApiKey}/coins/${subRoute}`, body, {
|
|
43
|
+
headers: { "Content-Type": "application/json" },
|
|
44
|
+
}), 2);
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
// fall through to the normal route below
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return restCallWrapper(() => axios_1.default.post(`https://coins.llama.fi/${subRoute}`, body, {
|
|
51
|
+
headers: { "Content-Type": "application/json" },
|
|
52
|
+
params: { source: "internal", apikey: coinsApiKey },
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
const nowCacheTTL = 1000 * 60 * 30; // 30 minutes, matches priceUpdateTime in computeTVL
|
|
56
|
+
let lastNowCacheClear = +Date.now();
|
|
57
|
+
function seedNowPriceCache() {
|
|
58
|
+
return {
|
|
59
|
+
"coingecko:tether": {
|
|
60
|
+
price: 1,
|
|
61
|
+
symbol: "USDT",
|
|
62
|
+
timestamp: Math.floor(Date.now() / 1e3 + 3600), // an hour from script start time
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const priceCacheAll = {
|
|
67
|
+
now: seedNowPriceCache()
|
|
68
|
+
};
|
|
69
|
+
const mcapCacheAll = {};
|
|
70
|
+
async function getPrices(readKeys, timestamp) {
|
|
71
|
+
return getPricesData(readKeys, timestamp, "price");
|
|
72
|
+
}
|
|
73
|
+
async function getPricesData(readKeys, timestamp, dataType) {
|
|
74
|
+
if (!readKeys.length)
|
|
75
|
+
return {};
|
|
76
|
+
// expire the "now" caches so current prices are never served older than nowCacheTTL
|
|
77
|
+
if (+Date.now() - lastNowCacheClear > nowCacheTTL) {
|
|
78
|
+
lastNowCacheClear = +Date.now();
|
|
79
|
+
priceCacheAll.now = seedNowPriceCache();
|
|
80
|
+
delete mcapCacheAll.now;
|
|
81
|
+
}
|
|
82
|
+
const cacheAllObject = dataType === "price" ? priceCacheAll : mcapCacheAll;
|
|
83
|
+
const subRoute = dataType === "price" ? "prices" : "mcaps";
|
|
84
|
+
const aggregatedRes = {};
|
|
85
|
+
const timestampString = timestamp.toString();
|
|
86
|
+
const priceCache = cacheAllObject[timestampString] || {};
|
|
87
|
+
if (!cacheAllObject[timestampString])
|
|
88
|
+
cacheAllObject[timestampString] = priceCache;
|
|
89
|
+
// read data from cache where possible
|
|
90
|
+
readKeys = readKeys.filter((PK) => {
|
|
91
|
+
const pkNormalized = PK.toLowerCase();
|
|
92
|
+
let pkData = priceCache[pkNormalized];
|
|
93
|
+
if (pkData) {
|
|
94
|
+
aggregatedRes[PK] = { ...pkData, PK };
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
});
|
|
99
|
+
const bodies = getBodies(readKeys, timestamp);
|
|
100
|
+
await (0, promisePool_1.default)({
|
|
101
|
+
items: bodies,
|
|
102
|
+
concurrency: 10,
|
|
103
|
+
processor: async (body) => {
|
|
104
|
+
if (!body.coins.length)
|
|
105
|
+
return;
|
|
106
|
+
const res = await fetchWithProFallback(body, subRoute);
|
|
107
|
+
const data = dataType === "price" ? res.data.coins : res.data;
|
|
108
|
+
Object.entries(data).forEach(([PK, value]) => {
|
|
109
|
+
const pkNormalized = PK.toLowerCase();
|
|
110
|
+
priceCache[pkNormalized] = value;
|
|
111
|
+
});
|
|
112
|
+
body.coins.forEach((PK) => {
|
|
113
|
+
const pkNormalized = PK.toLowerCase();
|
|
114
|
+
const coinData = priceCache[pkNormalized];
|
|
115
|
+
if (coinData)
|
|
116
|
+
aggregatedRes[PK] = { ...coinData, PK };
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
return aggregatedRes;
|
|
121
|
+
}
|
|
122
|
+
async function getMcaps(readKeys, timestamp) {
|
|
123
|
+
return getPricesData(readKeys, timestamp, "mcap");
|
|
124
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Balances, StringNumber, Address } from "../types";
|
|
2
|
+
export declare function convertToBigInt(value: any): bigint;
|
|
3
|
+
export declare function sumMultiBalanceOf(balances: Balances, results: {
|
|
4
|
+
ethCallCount?: number;
|
|
5
|
+
output: {
|
|
6
|
+
output: StringNumber;
|
|
7
|
+
success: boolean;
|
|
8
|
+
input: {
|
|
9
|
+
target: Address;
|
|
10
|
+
params: string[];
|
|
11
|
+
};
|
|
12
|
+
}[];
|
|
13
|
+
}, allCallsMustBeSuccessful?: boolean, transformAddress?: (addr: string) => string): void;
|
|
14
|
+
export declare function sumSingleBalance(balances: Balances, token: string, balance: string | number | BigInt, chain?: string): void;
|
|
15
|
+
export declare function mergeBalances(balances: Balances, balancesToMerge: Balances): void;
|
|
16
|
+
export declare function removeTokenBalance(balances: Balances, token: string, isCaseSensitive?: boolean): Balances;
|
|
17
|
+
type ChainBlocks = {
|
|
18
|
+
[chain: string]: number;
|
|
19
|
+
};
|
|
20
|
+
export declare function sumChainTvls(chainTvls: Array<(timestamp: number, ethBlock: number, chainBlocks: ChainBlocks, params: any) => Promise<Balances>>): (timestamp: number, ethBlock: number, chainBlocks: ChainBlocks, params: any) => Promise<any>;
|
|
21
|
+
export declare function getUniqueAddresses(addresses: string[], chain?: string): string[];
|
|
22
|
+
export declare function getProviderUrl(provider: any): any;
|
|
23
|
+
export declare function formErrorString(e: any, errorParams?: any): any;
|
|
24
|
+
export declare function shortenString(str: string, length?: number): string;
|
|
25
|
+
export declare function formError(e: any, errorParams?: any): Error;
|
|
26
|
+
export declare function fetchJson(url: string, params?: any): Promise<any>;
|
|
27
|
+
export declare function postJson(url: string, data?: any, params?: any): Promise<any>;
|
|
28
|
+
export declare function tronToEvmAddress(address: string): string;
|
|
29
|
+
export declare function evmToTronAddress(address: string): string;
|
|
30
|
+
export declare function sleep(ms: number): Promise<unknown>;
|
|
31
|
+
export declare function sleepRandom(max: number, min?: number): Promise<unknown>;
|
|
32
|
+
export declare function fixTronCallParams(params: any): void;
|
|
33
|
+
export declare function getHash(str: string | string[]): string;
|
|
34
|
+
export {};
|