@defillama/sdk 5.0.235 → 5.0.238

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 (69) hide show
  1. package/build/ChainApi.d.ts +23 -1
  2. package/build/ChainApi.js +13 -0
  3. package/build/abi/tron.js +7 -1
  4. package/build/chains/algorand.d.ts +277 -0
  5. package/build/chains/algorand.js +618 -0
  6. package/build/chains/aptos.d.ts +230 -0
  7. package/build/chains/aptos.js +612 -0
  8. package/build/chains/cardano.d.ts +242 -0
  9. package/build/chains/cardano.js +407 -0
  10. package/build/chains/cosmos.d.ts +252 -0
  11. package/build/chains/cosmos.js +618 -0
  12. package/build/chains/icp.d.ts +235 -0
  13. package/build/chains/icp.js +1040 -0
  14. package/build/chains/index.d.ts +23 -0
  15. package/build/chains/index.js +59 -0
  16. package/build/chains/near.d.ts +192 -0
  17. package/build/chains/near.js +446 -0
  18. package/build/chains/rpc.d.ts +125 -0
  19. package/build/chains/rpc.js +326 -0
  20. package/build/chains/starknet.d.ts +205 -0
  21. package/build/chains/starknet.js +884 -0
  22. package/build/chains/stellar.d.ts +410 -0
  23. package/build/chains/stellar.js +1082 -0
  24. package/build/chains/substrate.d.ts +333 -0
  25. package/build/chains/substrate.js +1042 -0
  26. package/build/chains/sui.d.ts +365 -0
  27. package/build/chains/sui.js +1135 -0
  28. package/build/chains/svm.d.ts +340 -0
  29. package/build/chains/svm.js +760 -0
  30. package/build/chains/tezos.d.ts +225 -0
  31. package/build/chains/tezos.js +412 -0
  32. package/build/chains/ton.d.ts +353 -0
  33. package/build/chains/ton.js +788 -0
  34. package/build/chains/tron.d.ts +45 -0
  35. package/build/chains/tron.js +110 -0
  36. package/build/chains/utxo.d.ts +202 -0
  37. package/build/chains/utxo.js +592 -0
  38. package/build/chains/xrpl.d.ts +179 -0
  39. package/build/chains/xrpl.js +467 -0
  40. package/build/index.d.ts +2 -1
  41. package/build/index.js +3 -1
  42. package/build/providers.json +1 -1
  43. package/build/util/LlamaProvider.js +2 -0
  44. package/build/util/blocks.js +292 -84
  45. package/build/util/chainUtils/data.json +80 -0
  46. package/build/util/chainUtils/index.d.ts +1 -0
  47. package/build/util/chainUtils/index.js +23 -0
  48. package/build/util/coins.js +14 -3
  49. package/build/util/common.js +6 -4
  50. package/build/util/computeTVL.js +1 -1
  51. package/build/util/cosmos.d.ts +1 -11
  52. package/build/util/cosmos.js +6 -66
  53. package/build/util/env.d.ts +1 -0
  54. package/build/util/env.js +18 -0
  55. package/build/util/indexer.compatibility.d.ts +6 -0
  56. package/build/util/indexer.compatibility.js +64 -0
  57. package/build/util/indexer.d.ts +24 -2
  58. package/build/util/indexer.js +333 -294
  59. package/build/util/indexerSql.d.ts +8 -1
  60. package/build/util/indexerSql.js +53 -22
  61. package/build/util/logs.d.ts +3 -0
  62. package/build/util/logs.decode.shared.js +5 -4
  63. package/build/util/logs.js +57 -26
  64. package/build/util/transactions.d.ts +23 -1
  65. package/build/util/updateChainLabels.d.ts +1 -0
  66. package/build/util/updateChainLabels.js +5 -0
  67. package/build/util/updateProviderList.js +40 -18
  68. package/package.json +20 -7
  69. package/README.md +0 -41
@@ -1,68 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isCosmosChain = void 0;
4
- exports.getCosmosBlock = getCosmosBlock;
5
- exports.getCosmosProvider = getCosmosProvider;
6
- const env_1 = require("./env");
7
- const common_1 = require("./common");
8
- // where to find chain info
9
- // https://proxy.atomscan.com/chains.json
10
- // https://cosmos-chain.directory/chains/cosmoshub
11
- // https://cosmos-chain.directory/chains
12
- const endPoints = {
13
- crescent: "https://mainnet.crescent.network:1317",
14
- osmosis: "https://osmosis-api.polkachu.com",
15
- cosmos: "https://cosmoshub-lcd.stakely.io",
16
- kujira: "https://kuji-api.kleomedes.network",
17
- comdex: "https://rest.comdex.one",
18
- terra: "https://terra-classic-lcd.publicnode.com",
19
- terra2: "https://terra-lcd.publicnode.com",
20
- umee: "https://umee-api.polkachu.com",
21
- orai: "https://lcd.orai.io",
22
- juno: "https://juno.api.m.stavr.tech",
23
- // cronos: "https://rest.mainnet.crypto.org", // it is also evm like kava
24
- chihuahua: "https://rest.cosmos.directory/chihuahua",
25
- stargaze: "https://rest.stargaze-apis.com",
26
- quicksilver: "https://rest.cosmos.directory/quicksilver",
27
- persistence: "https://rest.cosmos.directory/persistence",
28
- secret: "https://lcd.secret.express",
29
- // chihuahua: "https://api.chihuahua.wtf",
30
- injective: "https://sentry.lcd.injective.network:443",
31
- migaloo: "https://migaloo-api.polkachu.com",
32
- fxcore: "https://fx-rest.functionx.io",
33
- xpla: "https://dimension-lcd.xpla.dev",
34
- neutron: "https://rest-kralum.neutron-1.neutron.org",
35
- quasar: "https://quasar-api.polkachu.com",
36
- gravitybridge: "https://gravitychain.io:1317",
37
- // sei: "https://sei-api.polkachu.com",
38
- // aura: "https://lcd.aura.network", // is evm now
39
- archway: "https://api.mainnet.archway.io",
40
- sifchain: "https://sifchain-api.polkachu.com",
41
- nolus: "https://pirin-cl.nolus.network:1317",
42
- bostrom: "https://lcd.bostrom.cybernode.ai"
43
- };
44
- const ibcChains = ['terra', 'terra2', 'crescent', 'osmosis', 'kujira', 'stargaze', 'juno', 'injective', 'cosmos', 'comdex', 'umee', 'orai', 'persistence', 'fxcore', 'neutron', 'quasar', 'chihuahua', 'archway', 'migaloo', 'secret', 'xpla', 'bostrom'];
45
- const isCosmosChain = (chain) => ibcChains.includes(chain) || !!endPoints[chain];
46
- exports.isCosmosChain = isCosmosChain;
47
- async function getCosmosBlock(block = 'latest', chain = 'cosmos') {
48
- var _a;
49
- const endPoint = (0, env_1.getEnvRPC)(chain) || endPoints[chain] || 'https://rest.cosmos.directory/' + chain;
50
- try {
51
- const data = await (0, common_1.postJson)(`${endPoint}/blocks/${block}`);
52
- const { block: { header: { height, time } } } = data;
53
- return {
54
- number: Number(height),
55
- timestamp: Math.floor(Date.parse(time) / 1000),
56
- };
57
- }
58
- catch (e) {
59
- const message = `Error fetchin cosmos block -
60
- chain: ${chain}, block: ${block}, endPoint: ${endPoint}, error: ${(_a = e === null || e === void 0 ? void 0 : e.message) !== null && _a !== void 0 ? _a : JSON.stringify(e)}`;
61
- throw new Error(message);
62
- }
63
- }
64
- function getCosmosProvider(chain) {
65
- return {
66
- getBlock: (block = 'latest') => getCosmosBlock(block, chain)
67
- };
68
- }
3
+ exports.getCosmosProvider = exports.getCosmosBlock = exports.isCosmosChain = void 0;
4
+ // Kept for backwards compatibility, the implementation lives in ../chains/cosmos
5
+ var cosmos_1 = require("../chains/cosmos");
6
+ Object.defineProperty(exports, "isCosmosChain", { enumerable: true, get: function () { return cosmos_1.isCosmosChain; } });
7
+ Object.defineProperty(exports, "getCosmosBlock", { enumerable: true, get: function () { return cosmos_1.getCosmosBlock; } });
8
+ Object.defineProperty(exports, "getCosmosProvider", { enumerable: true, get: function () { return cosmos_1.getCosmosProvider; } });
@@ -5,6 +5,7 @@ export declare const ENV_CONSTANTS: {
5
5
  export declare function getChainId(chain: string, chainId: number): number;
6
6
  export declare function getMaxParallelRequests(chain: string): number;
7
7
  export declare function getParallelGetLogsLimit(chain: string, providerUrl?: string): number;
8
+ export declare function getBlockServiceUrl(): string | undefined;
8
9
  export declare function getParallelGetBlocksLimit(chain: string): number;
9
10
  export declare function getEnvRPC(chain: string): string | undefined;
10
11
  export declare function getEnvValue(key: string, defaultValue?: string): string;
package/build/util/env.js CHANGED
@@ -5,6 +5,7 @@ exports.ENV_CONSTANTS = exports.whitelistedEnvConstants = void 0;
5
5
  exports.getChainId = getChainId;
6
6
  exports.getMaxParallelRequests = getMaxParallelRequests;
7
7
  exports.getParallelGetLogsLimit = getParallelGetLogsLimit;
8
+ exports.getBlockServiceUrl = getBlockServiceUrl;
8
9
  exports.getParallelGetBlocksLimit = getParallelGetBlocksLimit;
9
10
  exports.getEnvRPC = getEnvRPC;
10
11
  exports.getEnvValue = getEnvValue;
@@ -21,6 +22,8 @@ exports.whitelistedEnvConstants = [
21
22
  'R2_ENDPOINT', 'R2_ACCESS_KEY_ID', 'R2_SECRET_ACCESS_KEY', 'TRON_PRO_API_KEY', 'COINS_API_KEY', 'INTERNAL_API_KEY',
22
23
  'ELASTICSEARCH_CONFIG', 'GRAPH_API_KEY', 'LLAMA_INDEXER_V2_ENDPOINT', 'LLAMA_INDEXER_V2_API_KEY', 'LLAMA_INDEXER_TIMEOUT_MS',
23
24
  'LLAMA_INDEXER_V4_ENDPOINT', 'LLAMA_INDEXER_V4_API_KEY', 'LLAMA_INDEXER_PREFER_V4', 'LLAMA_INDEXER_V4_ONLY_CHAINS',
25
+ 'LLAMA_INDEXER_SQL_ENDPOINT', 'LLAMA_INDEXER_SQL_USER', 'LLAMA_INDEXER_SQL_PASSWORD',
26
+ 'BLOCK_SERVICE_URL', 'BLOCK_SERVICE_URL_DISABLED',
24
27
  ];
25
28
  const isDebugLevel3 = process.env.LLAMA_SDK_DEBUG_LEVEL_3 === 'true';
26
29
  const defaultEnvValues = {
@@ -81,6 +84,21 @@ function getParallelGetLogsLimit(chain, providerUrl) {
81
84
  return +(defaultAlchemyLimit);
82
85
  return +(getEnvValue(`${chain}_RPC_GET_LOGS_CONCURRENCY_LIMIT`, defaultLimit));
83
86
  }
87
+ // url of a block-service deployment, lookups go there first and fall back to the local search
88
+ let blockServiceUrl;
89
+ let blockServiceUrlSet = false;
90
+ function getBlockServiceUrl() {
91
+ if (!blockServiceUrlSet) {
92
+ blockServiceUrl = _getBlockServiceUrl();
93
+ blockServiceUrlSet = true;
94
+ }
95
+ return blockServiceUrl;
96
+ }
97
+ function _getBlockServiceUrl() {
98
+ const url = getEnvValue('BLOCK_SERVICE_URL');
99
+ const disabled = getEnvValue('BLOCK_SERVICE_URL_DISABLED') === 'true';
100
+ return disabled ? undefined : url === null || url === void 0 ? void 0 : url.replace(/\/$/, '');
101
+ }
84
102
  function getParallelGetBlocksLimit(chain) {
85
103
  const defaultLimit = getEnvValue('GET_BLOCKS_CONCURRENCY_LIMIT', '5');
86
104
  return +(getEnvValue(`${chain}_RPC_GET_BLOCKS_CONCURRENCY_LIMIT`, defaultLimit));
@@ -0,0 +1,6 @@
1
+ type RowKind = "logs" | "transfers" | "transactions";
2
+ /** Preserve v2 REST field types and padding; never applied to SQL results. */
3
+ export declare function normalizeV4Row(row: any, kind: RowKind): any;
4
+ /** Capture an unquoted UInt256 id before JSON.parse can round it. */
5
+ export declare function parseTransferResponse(text: string): Promise<any>;
6
+ export {};
@@ -0,0 +1,64 @@
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.normalizeV4Row = normalizeV4Row;
7
+ exports.parseTransferResponse = parseTransferResponse;
8
+ const stream_1 = require("stream");
9
+ const promises_1 = require("stream/promises");
10
+ const stream_json_1 = require("stream-json");
11
+ const Assembler_1 = __importDefault(require("stream-json/Assembler"));
12
+ const numericFields = {
13
+ logs: ["chain", "block_number", "log_index"],
14
+ transfers: ["chain", "block_number", "log_index", "value", "id"],
15
+ transactions: ["chain", "block_number", "transaction_index", "value", "gas", "gas_price",
16
+ "gas_used", "effective_gas_price", "max_fee_per_gas", "max_priority_fee_per_gas",
17
+ "base_fee_per_gas", "nonce", "transaction_type", "cumulative_gas_used"],
18
+ };
19
+ const addressFields = {
20
+ logs: ["source", "address"],
21
+ transfers: ["from_address", "to_address", "token", "operator"],
22
+ transactions: ["from_address", "to_address", "contract_created"],
23
+ };
24
+ const hashFields = {
25
+ logs: ["transaction_hash", "topic0", "topic1", "topic2", "topic3"],
26
+ transfers: ["transaction_hash"],
27
+ transactions: ["hash", "block_hash"],
28
+ };
29
+ function fixedHex(value, bytes) {
30
+ // Empty/absent values are not the zero address or the zero topic.
31
+ if (typeof value !== "string" || !/^0x[0-9a-f]+$/i.test(value))
32
+ return value;
33
+ const hex = value.slice(2);
34
+ return hex.length <= bytes * 2 ? `0x${hex.toLowerCase().padStart(bytes * 2, "0")}` : value;
35
+ }
36
+ /** Preserve v2 REST field types and padding; never applied to SQL results. */
37
+ function normalizeV4Row(row, kind) {
38
+ for (const key of numericFields[kind]) {
39
+ // The exact transfer id is captured for the cursor before restoring the public Number.
40
+ if (typeof row[key] === "string" && /^-?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i.test(row[key]))
41
+ row[key] = Number(row[key]);
42
+ }
43
+ for (const key of addressFields[kind])
44
+ if (key in row)
45
+ row[key] = fixedHex(row[key], 20);
46
+ for (const key of hashFields[kind])
47
+ if (key in row)
48
+ row[key] = fixedHex(row[key], 32);
49
+ if (kind === "logs" && row.source === undefined && row.address !== undefined)
50
+ row.source = row.address;
51
+ return row;
52
+ }
53
+ /** Capture an unquoted UInt256 id before JSON.parse can round it. */
54
+ async function parseTransferResponse(text) {
55
+ const assembler = new Assembler_1.default();
56
+ // Assembler only needs packed values, not intermediate string/number chunks.
57
+ await (0, promises_1.pipeline)(stream_1.Readable.from([text]), (0, stream_json_1.parser)({ streamValues: false }), async (tokens) => {
58
+ for await (const token of tokens) {
59
+ assembler.consume(token.name === "numberValue" && assembler.key === "id"
60
+ ? { name: "stringValue", value: token.value } : token);
61
+ }
62
+ });
63
+ return assembler.current;
64
+ }
@@ -29,7 +29,7 @@ export type IndexerGetLogsOptions = {
29
29
  processor?: (logs: any[]) => Promise<void> | void;
30
30
  maxBlockRange?: number;
31
31
  allowParseFailure?: boolean;
32
- /** Feature flag: enable client-side streaming of /logs v2 */
32
+ /** Opt in to streaming /logs instead of paginated requests. */
33
33
  clientStreaming?: boolean;
34
34
  /** Decoder type: 'viem' (faster) or 'ethers' (fallback) */
35
35
  decoderType?: "viem" | "ethers";
@@ -65,6 +65,28 @@ export type IndexerGetTokenTransfersOptions = {
65
65
  };
66
66
  export declare function getLogs(options: IndexerGetLogsOptions): Promise<any[]>;
67
67
  export declare function getTokenTransfers({ chain, fromAddressFilter, fromBlock, toBlock, all, limit, offset, target, targets, flatten, fromTimestamp, toTimestamp, debugMode, transferType, token, tokens, }: IndexerGetTokenTransfersOptions): Promise<any[]>;
68
- export declare function getTransactions({ chain, addresses, transaction_hashes, from_block, to_block, all, limit, offset, debugMode, transactionType, }: GetTransactionOptions): Promise<any>;
68
+ export declare function getTransactions({ chain, addresses, transaction_hashes, from_block, to_block, all, limit, offset, debugMode, transactionType, }: GetTransactionOptions): Promise<{
69
+ hash: any;
70
+ blockNumber: number;
71
+ transactionIndex: number;
72
+ from: any;
73
+ to: any;
74
+ value: any;
75
+ gasPrice: any;
76
+ gas: any;
77
+ input: any;
78
+ nonce: number;
79
+ data: any;
80
+ type: any;
81
+ maxFeePerGas: any;
82
+ maxPriorityFeePerGas: any;
83
+ baseFeePerGas: any;
84
+ effectiveGasPrice: any;
85
+ gasUsed: any;
86
+ cumulativeGasUsed: any;
87
+ status: number;
88
+ contractCreated: any;
89
+ timestamp: any;
90
+ }[] | null>;
69
91
  export declare function isIndexerEnabled(chain?: string): boolean;
70
92
  export declare function isIndexer2Enabled(chain?: string): boolean;