@defillama/sdk 5.0.236 → 5.0.240

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 (131) hide show
  1. package/package.json +3 -3
  2. package/build/Balances.d.ts +0 -139
  3. package/build/Balances.js +0 -363
  4. package/build/ChainApi.d.ts +0 -142
  5. package/build/ChainApi.js +0 -297
  6. package/build/abi/abi2.d.ts +0 -5
  7. package/build/abi/abi2.js +0 -215
  8. package/build/abi/cachedABIs.d.ts +0 -4
  9. package/build/abi/cachedABIs.js +0 -8
  10. package/build/abi/convertResults.d.ts +0 -5
  11. package/build/abi/convertResults.js +0 -60
  12. package/build/abi/index.d.ts +0 -31
  13. package/build/abi/index.js +0 -327
  14. package/build/abi/multicall.d.ts +0 -23
  15. package/build/abi/multicall.js +0 -382
  16. package/build/abi/multicall3.d.ts +0 -7
  17. package/build/abi/multicall3.js +0 -397
  18. package/build/abi/rpcCall.d.ts +0 -4
  19. package/build/abi/rpcCall.js +0 -62
  20. package/build/abi/tron.d.ts +0 -33
  21. package/build/abi/tron.js +0 -110
  22. package/build/api.d.ts +0 -10
  23. package/build/api.js +0 -45
  24. package/build/api2.d.ts +0 -5
  25. package/build/api2.js +0 -41
  26. package/build/chains/algorand.d.ts +0 -277
  27. package/build/chains/algorand.js +0 -618
  28. package/build/chains/aptos.d.ts +0 -230
  29. package/build/chains/aptos.js +0 -612
  30. package/build/chains/cardano.d.ts +0 -242
  31. package/build/chains/cardano.js +0 -407
  32. package/build/chains/cosmos.d.ts +0 -252
  33. package/build/chains/cosmos.js +0 -618
  34. package/build/chains/icp.d.ts +0 -235
  35. package/build/chains/icp.js +0 -1040
  36. package/build/chains/index.d.ts +0 -23
  37. package/build/chains/index.js +0 -59
  38. package/build/chains/near.d.ts +0 -192
  39. package/build/chains/near.js +0 -446
  40. package/build/chains/rpc.d.ts +0 -125
  41. package/build/chains/rpc.js +0 -326
  42. package/build/chains/starknet.d.ts +0 -205
  43. package/build/chains/starknet.js +0 -884
  44. package/build/chains/stellar.d.ts +0 -410
  45. package/build/chains/stellar.js +0 -1082
  46. package/build/chains/substrate.d.ts +0 -333
  47. package/build/chains/substrate.js +0 -1042
  48. package/build/chains/sui.d.ts +0 -365
  49. package/build/chains/sui.js +0 -1135
  50. package/build/chains/svm.d.ts +0 -340
  51. package/build/chains/svm.js +0 -760
  52. package/build/chains/tezos.d.ts +0 -225
  53. package/build/chains/tezos.js +0 -412
  54. package/build/chains/ton.d.ts +0 -353
  55. package/build/chains/ton.js +0 -788
  56. package/build/chains/tron.d.ts +0 -45
  57. package/build/chains/tron.js +0 -110
  58. package/build/chains/utxo.d.ts +0 -202
  59. package/build/chains/utxo.js +0 -592
  60. package/build/chains/xrpl.d.ts +0 -179
  61. package/build/chains/xrpl.js +0 -467
  62. package/build/computeTVL/blocks.d.ts +0 -1
  63. package/build/computeTVL/blocks.js +0 -12
  64. package/build/computeTVL/humanizeNumber.d.ts +0 -1
  65. package/build/computeTVL/humanizeNumber.js +0 -19
  66. package/build/erc20/index.d.ts +0 -31
  67. package/build/erc20/index.js +0 -56
  68. package/build/eth/index.d.ts +0 -22
  69. package/build/eth/index.js +0 -118
  70. package/build/general.d.ts +0 -5
  71. package/build/general.js +0 -20
  72. package/build/generalUtil.d.ts +0 -8
  73. package/build/generalUtil.js +0 -73
  74. package/build/index.d.ts +0 -32
  75. package/build/index.js +0 -74
  76. package/build/providers.json +0 -1
  77. package/build/types.d.ts +0 -76
  78. package/build/types.js +0 -2
  79. package/build/util/LlamaProvider.d.ts +0 -46
  80. package/build/util/LlamaProvider.js +0 -365
  81. package/build/util/blocks.d.ts +0 -36
  82. package/build/util/blocks.js +0 -292
  83. package/build/util/cache.d.ts +0 -45
  84. package/build/util/cache.js +0 -309
  85. package/build/util/chainUtils/data.json +0 -1356
  86. package/build/util/chainUtils/index.d.ts +0 -11
  87. package/build/util/chainUtils/index.js +0 -136
  88. package/build/util/coins.d.ts +0 -19
  89. package/build/util/coins.js +0 -113
  90. package/build/util/common.d.ts +0 -34
  91. package/build/util/common.js +0 -373
  92. package/build/util/computeTVL.d.ts +0 -19
  93. package/build/util/computeTVL.js +0 -102
  94. package/build/util/cosmos.d.ts +0 -1
  95. package/build/util/cosmos.js +0 -8
  96. package/build/util/debugLog.d.ts +0 -4
  97. package/build/util/debugLog.js +0 -18
  98. package/build/util/discord.d.ts +0 -1
  99. package/build/util/discord.js +0 -33
  100. package/build/util/elastic.d.ts +0 -43
  101. package/build/util/elastic.js +0 -113
  102. package/build/util/env.d.ts +0 -19
  103. package/build/util/env.js +0 -158
  104. package/build/util/graph.d.ts +0 -8
  105. package/build/util/graph.js +0 -50
  106. package/build/util/index.d.ts +0 -32
  107. package/build/util/index.js +0 -227
  108. package/build/util/indexer.compatibility.d.ts +0 -6
  109. package/build/util/indexer.compatibility.js +0 -64
  110. package/build/util/indexer.d.ts +0 -92
  111. package/build/util/indexer.js +0 -744
  112. package/build/util/indexerSql.d.ts +0 -9
  113. package/build/util/indexerSql.js +0 -102
  114. package/build/util/internal-cache.d.ts +0 -11
  115. package/build/util/internal-cache.js +0 -77
  116. package/build/util/logs.d.ts +0 -55
  117. package/build/util/logs.decode.shared.d.ts +0 -8
  118. package/build/util/logs.decode.shared.js +0 -289
  119. package/build/util/logs.js +0 -401
  120. package/build/util/promisePool.d.ts +0 -8
  121. package/build/util/promisePool.js +0 -31
  122. package/build/util/r2.d.ts +0 -4
  123. package/build/util/r2.js +0 -52
  124. package/build/util/removeRedundantRPCs.d.ts +0 -1
  125. package/build/util/removeRedundantRPCs.js +0 -49
  126. package/build/util/transactions.d.ts +0 -35
  127. package/build/util/transactions.js +0 -22
  128. package/build/util/updateChainLabels.d.ts +0 -1
  129. package/build/util/updateChainLabels.js +0 -5
  130. package/build/util/updateProviderList.d.ts +0 -1
  131. package/build/util/updateProviderList.js +0 -274
@@ -1,11 +0,0 @@
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;
@@ -1,136 +0,0 @@
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
- }
@@ -1,19 +0,0 @@
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 {};
@@ -1,113 +0,0 @@
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 priceCacheAll = {
56
- now: {
57
- "coingecko:tether": {
58
- price: 1,
59
- symbol: "USDT",
60
- timestamp: Math.floor(Date.now() / 1e3 + 3600), // an hour from script start time
61
- },
62
- }
63
- };
64
- const mcapCacheAll = {};
65
- async function getPrices(readKeys, timestamp) {
66
- return getPricesData(readKeys, timestamp, "price");
67
- }
68
- async function getPricesData(readKeys, timestamp, dataType) {
69
- if (!readKeys.length)
70
- return {};
71
- const cacheAllObject = dataType === "price" ? priceCacheAll : mcapCacheAll;
72
- const subRoute = dataType === "price" ? "prices" : "mcaps";
73
- const aggregatedRes = {};
74
- const timestampString = timestamp.toString();
75
- const priceCache = cacheAllObject[timestampString] || {};
76
- if (!cacheAllObject[timestampString])
77
- cacheAllObject[timestampString] = priceCache;
78
- // read data from cache where possible
79
- readKeys = readKeys.filter((PK) => {
80
- const pkNormalized = PK.toLowerCase();
81
- let pkData = priceCache[pkNormalized];
82
- if (pkData) {
83
- aggregatedRes[PK] = { ...pkData, PK };
84
- return false;
85
- }
86
- return true;
87
- });
88
- const bodies = getBodies(readKeys, timestamp);
89
- await (0, promisePool_1.default)({
90
- items: bodies,
91
- concurrency: 10,
92
- processor: async (body) => {
93
- if (!body.coins.length)
94
- return;
95
- const res = await fetchWithProFallback(body, subRoute);
96
- const data = dataType === "price" ? res.data.coins : res.data;
97
- Object.entries(data).forEach(([PK, value]) => {
98
- const pkNormalized = PK.toLowerCase();
99
- priceCache[pkNormalized] = value;
100
- });
101
- body.coins.forEach((PK) => {
102
- const pkNormalized = PK.toLowerCase();
103
- const coinData = priceCache[pkNormalized];
104
- if (coinData)
105
- aggregatedRes[PK] = { ...coinData, PK };
106
- });
107
- },
108
- });
109
- return aggregatedRes;
110
- }
111
- async function getMcaps(readKeys, timestamp) {
112
- return getPricesData(readKeys, timestamp, "mcap");
113
- }
@@ -1,34 +0,0 @@
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 {};