@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.
- package/package.json +3 -3
- package/build/Balances.d.ts +0 -139
- package/build/Balances.js +0 -363
- package/build/ChainApi.d.ts +0 -142
- package/build/ChainApi.js +0 -297
- package/build/abi/abi2.d.ts +0 -5
- package/build/abi/abi2.js +0 -215
- package/build/abi/cachedABIs.d.ts +0 -4
- package/build/abi/cachedABIs.js +0 -8
- package/build/abi/convertResults.d.ts +0 -5
- package/build/abi/convertResults.js +0 -60
- package/build/abi/index.d.ts +0 -31
- package/build/abi/index.js +0 -327
- package/build/abi/multicall.d.ts +0 -23
- package/build/abi/multicall.js +0 -382
- package/build/abi/multicall3.d.ts +0 -7
- package/build/abi/multicall3.js +0 -397
- package/build/abi/rpcCall.d.ts +0 -4
- package/build/abi/rpcCall.js +0 -62
- package/build/abi/tron.d.ts +0 -33
- package/build/abi/tron.js +0 -110
- package/build/api.d.ts +0 -10
- package/build/api.js +0 -45
- package/build/api2.d.ts +0 -5
- package/build/api2.js +0 -41
- package/build/chains/algorand.d.ts +0 -277
- package/build/chains/algorand.js +0 -618
- package/build/chains/aptos.d.ts +0 -230
- package/build/chains/aptos.js +0 -612
- package/build/chains/cardano.d.ts +0 -242
- package/build/chains/cardano.js +0 -407
- package/build/chains/cosmos.d.ts +0 -252
- package/build/chains/cosmos.js +0 -618
- package/build/chains/icp.d.ts +0 -235
- package/build/chains/icp.js +0 -1040
- package/build/chains/index.d.ts +0 -23
- package/build/chains/index.js +0 -59
- package/build/chains/near.d.ts +0 -192
- package/build/chains/near.js +0 -446
- package/build/chains/rpc.d.ts +0 -125
- package/build/chains/rpc.js +0 -326
- package/build/chains/starknet.d.ts +0 -205
- package/build/chains/starknet.js +0 -884
- package/build/chains/stellar.d.ts +0 -410
- package/build/chains/stellar.js +0 -1082
- package/build/chains/substrate.d.ts +0 -333
- package/build/chains/substrate.js +0 -1042
- package/build/chains/sui.d.ts +0 -365
- package/build/chains/sui.js +0 -1135
- package/build/chains/svm.d.ts +0 -340
- package/build/chains/svm.js +0 -760
- package/build/chains/tezos.d.ts +0 -225
- package/build/chains/tezos.js +0 -412
- package/build/chains/ton.d.ts +0 -353
- package/build/chains/ton.js +0 -788
- package/build/chains/tron.d.ts +0 -45
- package/build/chains/tron.js +0 -110
- package/build/chains/utxo.d.ts +0 -202
- package/build/chains/utxo.js +0 -592
- package/build/chains/xrpl.d.ts +0 -179
- package/build/chains/xrpl.js +0 -467
- package/build/computeTVL/blocks.d.ts +0 -1
- package/build/computeTVL/blocks.js +0 -12
- package/build/computeTVL/humanizeNumber.d.ts +0 -1
- package/build/computeTVL/humanizeNumber.js +0 -19
- package/build/erc20/index.d.ts +0 -31
- package/build/erc20/index.js +0 -56
- package/build/eth/index.d.ts +0 -22
- package/build/eth/index.js +0 -118
- package/build/general.d.ts +0 -5
- package/build/general.js +0 -20
- package/build/generalUtil.d.ts +0 -8
- package/build/generalUtil.js +0 -73
- package/build/index.d.ts +0 -32
- package/build/index.js +0 -74
- package/build/providers.json +0 -1
- package/build/types.d.ts +0 -76
- package/build/types.js +0 -2
- package/build/util/LlamaProvider.d.ts +0 -46
- package/build/util/LlamaProvider.js +0 -365
- package/build/util/blocks.d.ts +0 -36
- package/build/util/blocks.js +0 -292
- package/build/util/cache.d.ts +0 -45
- package/build/util/cache.js +0 -309
- package/build/util/chainUtils/data.json +0 -1356
- package/build/util/chainUtils/index.d.ts +0 -11
- package/build/util/chainUtils/index.js +0 -136
- package/build/util/coins.d.ts +0 -19
- package/build/util/coins.js +0 -113
- package/build/util/common.d.ts +0 -34
- package/build/util/common.js +0 -373
- package/build/util/computeTVL.d.ts +0 -19
- package/build/util/computeTVL.js +0 -102
- package/build/util/cosmos.d.ts +0 -1
- package/build/util/cosmos.js +0 -8
- package/build/util/debugLog.d.ts +0 -4
- package/build/util/debugLog.js +0 -18
- package/build/util/discord.d.ts +0 -1
- package/build/util/discord.js +0 -33
- package/build/util/elastic.d.ts +0 -43
- package/build/util/elastic.js +0 -113
- package/build/util/env.d.ts +0 -19
- package/build/util/env.js +0 -158
- package/build/util/graph.d.ts +0 -8
- package/build/util/graph.js +0 -50
- package/build/util/index.d.ts +0 -32
- package/build/util/index.js +0 -227
- package/build/util/indexer.compatibility.d.ts +0 -6
- package/build/util/indexer.compatibility.js +0 -64
- package/build/util/indexer.d.ts +0 -92
- package/build/util/indexer.js +0 -744
- package/build/util/indexerSql.d.ts +0 -9
- package/build/util/indexerSql.js +0 -102
- package/build/util/internal-cache.d.ts +0 -11
- package/build/util/internal-cache.js +0 -77
- package/build/util/logs.d.ts +0 -55
- package/build/util/logs.decode.shared.d.ts +0 -8
- package/build/util/logs.decode.shared.js +0 -289
- package/build/util/logs.js +0 -401
- package/build/util/promisePool.d.ts +0 -8
- package/build/util/promisePool.js +0 -31
- package/build/util/r2.d.ts +0 -4
- package/build/util/r2.js +0 -52
- package/build/util/removeRedundantRPCs.d.ts +0 -1
- package/build/util/removeRedundantRPCs.js +0 -49
- package/build/util/transactions.d.ts +0 -35
- package/build/util/transactions.js +0 -22
- package/build/util/updateChainLabels.d.ts +0 -1
- package/build/util/updateChainLabels.js +0 -5
- package/build/util/updateProviderList.d.ts +0 -1
- package/build/util/updateProviderList.js +0 -274
package/build/chains/rpc.js
DELETED
|
@@ -1,326 +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.sleep = exports.JsonRpcError = void 0;
|
|
7
|
-
exports.toEndpointList = toEndpointList;
|
|
8
|
-
exports.getEndpoints = getEndpoints;
|
|
9
|
-
exports.getEndpoint = getEndpoint;
|
|
10
|
-
exports.stripTrailingSlash = stripTrailingSlash;
|
|
11
|
-
exports.joinUrl = joinUrl;
|
|
12
|
-
exports.isRateLimitError = isRateLimitError;
|
|
13
|
-
exports.isRetryableError = isRetryableError;
|
|
14
|
-
exports.withRetry = withRetry;
|
|
15
|
-
exports.getLimiter = getLimiter;
|
|
16
|
-
exports.sliceIntoChunks = sliceIntoChunks;
|
|
17
|
-
exports.runInChunks = runInChunks;
|
|
18
|
-
exports.httpGet = httpGet;
|
|
19
|
-
exports.httpPost = httpPost;
|
|
20
|
-
exports.jsonRpc = jsonRpc;
|
|
21
|
-
exports.jsonRpcBatch = jsonRpcBatch;
|
|
22
|
-
exports.shortUrl = shortUrl;
|
|
23
|
-
/**
|
|
24
|
-
* Shared transport for the non-EVM chain modules under `sdk.chains.*`.
|
|
25
|
-
*
|
|
26
|
-
* Every chain module resolves its endpoints through `getEndpoints`. When
|
|
27
|
-
* `<CHAIN>_WHITELISTED_RPC` is set only those endpoints are used; otherwise the
|
|
28
|
-
* `<CHAIN>_RPC` env var (and the `SDK_` / `LLAMA_SDK_` prefixed variants read by
|
|
29
|
-
* `getEnvValue`) is tried first, followed by the module's built-in defaults.
|
|
30
|
-
* Comma separated values give a list; `jsonRpc` / `httpGet` / `httpPost` start
|
|
31
|
-
* at the first entry, rotate to the next on failure and retry with backoff.
|
|
32
|
-
*/
|
|
33
|
-
const axios_1 = __importDefault(require("axios"));
|
|
34
|
-
const p_limit_1 = __importDefault(require("p-limit"));
|
|
35
|
-
const env_1 = require("../util/env");
|
|
36
|
-
const common_1 = require("../util/common");
|
|
37
|
-
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return common_1.sleep; } });
|
|
38
|
-
const debugLog_1 = require("../util/debugLog");
|
|
39
|
-
const DEFAULT_TIMEOUT = 60000;
|
|
40
|
-
// ---------------------------------------------------------------------------
|
|
41
|
-
// endpoint resolution
|
|
42
|
-
// ---------------------------------------------------------------------------
|
|
43
|
-
function toEndpointList(value) {
|
|
44
|
-
if (!value)
|
|
45
|
-
return [];
|
|
46
|
-
const list = Array.isArray(value) ? value : value.split(',');
|
|
47
|
-
return list.map(i => i.trim()).filter(Boolean);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Resolve the endpoint list for a chain. `<CHAIN>_WHITELISTED_RPC` wins outright
|
|
51
|
-
* when set. Otherwise env (`<CHAIN>_RPC` or `envKey`, comma separated) comes
|
|
52
|
-
* first followed by the module defaults, then the generic fallback.
|
|
53
|
-
* Throws when nothing is configured so a misconfigured chain fails loudly.
|
|
54
|
-
*/
|
|
55
|
-
function getEndpoints(chain, defaults, { envKey, fallback, } = {}) {
|
|
56
|
-
if (chain) {
|
|
57
|
-
const whitelisted = toEndpointList((0, env_1.getWhitelistedRPCs)(chain));
|
|
58
|
-
if (whitelisted.length)
|
|
59
|
-
return whitelisted;
|
|
60
|
-
}
|
|
61
|
-
let fromEnv;
|
|
62
|
-
if (envKey)
|
|
63
|
-
fromEnv = (0, env_1.getEnvValue)(envKey);
|
|
64
|
-
else if (chain)
|
|
65
|
-
fromEnv = (0, env_1.getEnvRPC)(chain);
|
|
66
|
-
const list = [...new Set([...toEndpointList(fromEnv), ...toEndpointList(defaults)])];
|
|
67
|
-
if (list.length)
|
|
68
|
-
return list;
|
|
69
|
-
const fallbackList = toEndpointList(fallback);
|
|
70
|
-
if (fallbackList.length)
|
|
71
|
-
return fallbackList;
|
|
72
|
-
throw new Error(`No RPC endpoint configured for chain "${chain !== null && chain !== void 0 ? chain : '-'}"${envKey ? ` (env ${envKey})` : chain ? ` (env ${chain.toUpperCase()}_RPC)` : ''}`);
|
|
73
|
-
}
|
|
74
|
-
/** First endpoint of `getEndpoints` */
|
|
75
|
-
function getEndpoint(chain, defaults, options) {
|
|
76
|
-
return getEndpoints(chain, defaults, options)[0];
|
|
77
|
-
}
|
|
78
|
-
function stripTrailingSlash(url) {
|
|
79
|
-
return url.replace(/\/+$/, '');
|
|
80
|
-
}
|
|
81
|
-
function joinUrl(base, path) {
|
|
82
|
-
if (!path)
|
|
83
|
-
return base;
|
|
84
|
-
return stripTrailingSlash(base) + '/' + path.replace(/^\/+/, '');
|
|
85
|
-
}
|
|
86
|
-
// ---------------------------------------------------------------------------
|
|
87
|
-
// retry / concurrency
|
|
88
|
-
// ---------------------------------------------------------------------------
|
|
89
|
-
function isRateLimitError(e) {
|
|
90
|
-
var _a, _b, _c, _d;
|
|
91
|
-
const status = (_b = (_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : e === null || e === void 0 ? void 0 : e.status;
|
|
92
|
-
if (status === 429)
|
|
93
|
-
return true;
|
|
94
|
-
const message = String((_d = (_c = e === null || e === void 0 ? void 0 : e.message) !== null && _c !== void 0 ? _c : e) !== null && _d !== void 0 ? _d : '').toLowerCase();
|
|
95
|
-
return message.includes('429') || message.includes('rate limit') || message.includes('too many requests');
|
|
96
|
-
}
|
|
97
|
-
function isRetryableError(e) {
|
|
98
|
-
var _a, _b;
|
|
99
|
-
const status = (_b = (_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : e === null || e === void 0 ? void 0 : e.status;
|
|
100
|
-
if (status && status < 500 && status !== 429 && status !== 408)
|
|
101
|
-
return false;
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Run `fn` with retries and exponential backoff. `fn` receives the attempt index.
|
|
106
|
-
*/
|
|
107
|
-
async function withRetry(fn, options = {}) {
|
|
108
|
-
const { retries = 3, delay = 500, backoff = 2, maxDelay = 10000, shouldRetry = isRetryableError, label = 'request' } = options;
|
|
109
|
-
const attempts = Math.max(1, retries);
|
|
110
|
-
let wait = delay;
|
|
111
|
-
let lastError;
|
|
112
|
-
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
113
|
-
try {
|
|
114
|
-
return await fn(attempt);
|
|
115
|
-
}
|
|
116
|
-
catch (e) {
|
|
117
|
-
lastError = e;
|
|
118
|
-
const isLast = attempt === attempts - 1;
|
|
119
|
-
if (isLast || !shouldRetry(e, attempt))
|
|
120
|
-
break;
|
|
121
|
-
const jitter = Math.floor(Math.random() * Math.min(wait, 250));
|
|
122
|
-
(0, debugLog_1.debugLog)(`[chains.rpc] ${label} failed (attempt ${attempt + 1}/${attempts}), retrying in ${wait}ms: ${shortMessage(e)}`);
|
|
123
|
-
await (0, common_1.sleep)(Math.min(wait, maxDelay) + jitter);
|
|
124
|
-
wait = Math.min(wait * backoff, maxDelay);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
// keep typed errors (JsonRpcError etc) intact, only reformat transport errors
|
|
128
|
-
if (lastError instanceof JsonRpcError)
|
|
129
|
-
throw lastError;
|
|
130
|
-
throw (0, common_1.formError)(lastError);
|
|
131
|
-
}
|
|
132
|
-
const limiters = {};
|
|
133
|
-
/**
|
|
134
|
-
* Lazily created per-key concurrency limiter. Concurrency can be overridden with
|
|
135
|
-
* the `<KEY>_RPC_CONCURRENCY` env var.
|
|
136
|
-
*/
|
|
137
|
-
function getLimiter(key, concurrency = 10) {
|
|
138
|
-
if (!limiters[key]) {
|
|
139
|
-
const envValue = (0, env_1.getEnvValue)(`${key}_RPC_CONCURRENCY`);
|
|
140
|
-
limiters[key] = (0, p_limit_1.default)(envValue ? +envValue : concurrency);
|
|
141
|
-
}
|
|
142
|
-
return limiters[key];
|
|
143
|
-
}
|
|
144
|
-
function sliceIntoChunks(arr, chunkSize = 100) {
|
|
145
|
-
const res = [];
|
|
146
|
-
for (let i = 0; i < arr.length; i += chunkSize)
|
|
147
|
-
res.push(arr.slice(i, i + chunkSize));
|
|
148
|
-
return res;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Process `items` in chunks, sequentially or with limited concurrency, keeping
|
|
152
|
-
* result order. `fn` receives one chunk and returns an array (flattened) or any value.
|
|
153
|
-
*/
|
|
154
|
-
async function runInChunks(items, fn, { chunkSize = 100, concurrency = 1, sleepTime = 0 } = {}) {
|
|
155
|
-
const chunks = sliceIntoChunks(items, chunkSize);
|
|
156
|
-
const limit = (0, p_limit_1.default)(Math.max(1, concurrency));
|
|
157
|
-
const results = await Promise.all(chunks.map((chunk, i) => limit(async () => {
|
|
158
|
-
if (sleepTime && i > 0 && concurrency === 1)
|
|
159
|
-
await (0, common_1.sleep)(sleepTime);
|
|
160
|
-
return fn(chunk, i);
|
|
161
|
-
})));
|
|
162
|
-
return results.flat();
|
|
163
|
-
}
|
|
164
|
-
// ---------------------------------------------------------------------------
|
|
165
|
-
// http
|
|
166
|
-
// ---------------------------------------------------------------------------
|
|
167
|
-
function buildAxiosConfig(options) {
|
|
168
|
-
const { timeout = DEFAULT_TIMEOUT, headers, params, axiosConfig } = options;
|
|
169
|
-
return { timeout, headers, params, ...axiosConfig };
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* GET `url` (or rotate over several base urls when `url` is an array; `path` is
|
|
173
|
-
* appended to each). Retries transient failures.
|
|
174
|
-
*/
|
|
175
|
-
async function httpGet(url, options = {}) {
|
|
176
|
-
var _a;
|
|
177
|
-
const urls = Array.isArray(url) ? url : [url];
|
|
178
|
-
if (!urls.length)
|
|
179
|
-
throw new Error('httpGet: no url');
|
|
180
|
-
const config = buildAxiosConfig(options);
|
|
181
|
-
return withRetry(async (attempt) => {
|
|
182
|
-
const base = urls[attempt % urls.length];
|
|
183
|
-
const fullUrl = options.path ? joinUrl(base, options.path) : base;
|
|
184
|
-
const res = await axios_1.default.get(fullUrl, config);
|
|
185
|
-
return options.withMetadata ? res : res.data;
|
|
186
|
-
}, { label: `GET ${shortUrl(urls[0])}`, retries: (_a = options.retries) !== null && _a !== void 0 ? _a : Math.max(3, urls.length), ...pickRetry(options) });
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* POST `body` to `url` (or rotate over several urls). Retries transient failures.
|
|
190
|
-
*/
|
|
191
|
-
async function httpPost(url, body, options = {}) {
|
|
192
|
-
var _a;
|
|
193
|
-
const urls = Array.isArray(url) ? url : [url];
|
|
194
|
-
if (!urls.length)
|
|
195
|
-
throw new Error('httpPost: no url');
|
|
196
|
-
const config = buildAxiosConfig(options);
|
|
197
|
-
return withRetry(async (attempt) => {
|
|
198
|
-
const base = urls[attempt % urls.length];
|
|
199
|
-
const fullUrl = options.path ? joinUrl(base, options.path) : base;
|
|
200
|
-
const res = await axios_1.default.post(fullUrl, body, config);
|
|
201
|
-
return options.withMetadata ? res : res.data;
|
|
202
|
-
}, { label: `POST ${shortUrl(urls[0])}`, retries: (_a = options.retries) !== null && _a !== void 0 ? _a : Math.max(3, urls.length), ...pickRetry(options) });
|
|
203
|
-
}
|
|
204
|
-
// ---------------------------------------------------------------------------
|
|
205
|
-
// json-rpc
|
|
206
|
-
// ---------------------------------------------------------------------------
|
|
207
|
-
class JsonRpcError extends Error {
|
|
208
|
-
constructor(method, error) {
|
|
209
|
-
var _a;
|
|
210
|
-
super(`JSON-RPC ${method} failed: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : JSON.stringify(error)}`);
|
|
211
|
-
this.name = 'JsonRpcError';
|
|
212
|
-
this.code = error === null || error === void 0 ? void 0 : error.code;
|
|
213
|
-
this.data = error === null || error === void 0 ? void 0 : error.data;
|
|
214
|
-
this.method = method;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
exports.JsonRpcError = JsonRpcError;
|
|
218
|
-
function resolveRpcEndpoints(options) {
|
|
219
|
-
const explicit = toEndpointList(options.endpoints);
|
|
220
|
-
if (explicit.length)
|
|
221
|
-
return explicit;
|
|
222
|
-
return getEndpoints(options.chain, options.defaultEndpoints);
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Single JSON-RPC 2.0 call. Returns `result`; throws `JsonRpcError` when the node
|
|
226
|
-
* returns an `error` object. Rotates endpoints and retries on transport errors.
|
|
227
|
-
*/
|
|
228
|
-
async function jsonRpc(method, params = [], options = {}) {
|
|
229
|
-
var _a, _b, _c, _d;
|
|
230
|
-
const endpoints = resolveRpcEndpoints(options);
|
|
231
|
-
const body = { jsonrpc: '2.0', id: (_a = options.id) !== null && _a !== void 0 ? _a : 1, method, params };
|
|
232
|
-
const config = buildAxiosConfig(options);
|
|
233
|
-
return withRetry(async (attempt) => {
|
|
234
|
-
const endpoint = endpoints[attempt % endpoints.length];
|
|
235
|
-
const { data } = await axios_1.default.post(endpoint, body, config);
|
|
236
|
-
if (data === null || data === void 0 ? void 0 : data.error)
|
|
237
|
-
throw new JsonRpcError(method, data.error);
|
|
238
|
-
if (data === undefined || data === null || typeof data !== 'object')
|
|
239
|
-
throw new Error(`JSON-RPC ${method}: empty response from ${shortUrl(endpoint)}`);
|
|
240
|
-
return data.result;
|
|
241
|
-
}, {
|
|
242
|
-
label: `${(_b = options.chain) !== null && _b !== void 0 ? _b : shortUrl(endpoints[0])} ${method}`,
|
|
243
|
-
retries: (_c = options.retries) !== null && _c !== void 0 ? _c : Math.max(3, endpoints.length),
|
|
244
|
-
...pickRetry(options),
|
|
245
|
-
shouldRetry: (_d = options.shouldRetry) !== null && _d !== void 0 ? _d : ((e) => !(e instanceof JsonRpcError) || isRateLimitError(e) || isNodeSideRetryable(e)),
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* JSON-RPC 2.0 batch call. Returns results in call order. Individual `error`
|
|
250
|
-
* entries throw unless `permitFailure` is set, in which case they resolve to `undefined`.
|
|
251
|
-
*/
|
|
252
|
-
async function jsonRpcBatch(calls, options = {}) {
|
|
253
|
-
var _a, _b, _c;
|
|
254
|
-
if (!calls.length)
|
|
255
|
-
return [];
|
|
256
|
-
const endpoints = resolveRpcEndpoints(options);
|
|
257
|
-
const config = buildAxiosConfig(options);
|
|
258
|
-
const chunkSize = (_a = options.chunkSize) !== null && _a !== void 0 ? _a : calls.length;
|
|
259
|
-
const chunks = sliceIntoChunks(calls, chunkSize);
|
|
260
|
-
const results = [];
|
|
261
|
-
for (const chunk of chunks) {
|
|
262
|
-
const body = chunk.map((c, i) => { var _a, _b; return ({ jsonrpc: '2.0', id: (_a = c.id) !== null && _a !== void 0 ? _a : i, method: c.method, params: (_b = c.params) !== null && _b !== void 0 ? _b : [] }); });
|
|
263
|
-
const data = await withRetry(async (attempt) => {
|
|
264
|
-
const endpoint = endpoints[attempt % endpoints.length];
|
|
265
|
-
const { data } = await axios_1.default.post(endpoint, body, config);
|
|
266
|
-
if (!Array.isArray(data)) {
|
|
267
|
-
if (data === null || data === void 0 ? void 0 : data.error)
|
|
268
|
-
throw new JsonRpcError('batch', data.error);
|
|
269
|
-
throw new Error(`JSON-RPC batch: unexpected response from ${shortUrl(endpoint)}`);
|
|
270
|
-
}
|
|
271
|
-
return data;
|
|
272
|
-
}, { label: `${(_b = options.chain) !== null && _b !== void 0 ? _b : shortUrl(endpoints[0])} batch(${chunk.length})`, retries: (_c = options.retries) !== null && _c !== void 0 ? _c : Math.max(3, endpoints.length), ...pickRetry(options) });
|
|
273
|
-
const byId = new Map();
|
|
274
|
-
data.forEach((r) => byId.set(String(r.id), r));
|
|
275
|
-
chunk.forEach((c, i) => {
|
|
276
|
-
var _a;
|
|
277
|
-
const r = byId.get(String((_a = c.id) !== null && _a !== void 0 ? _a : i));
|
|
278
|
-
if (!r) {
|
|
279
|
-
if (options.permitFailure)
|
|
280
|
-
return results.push(undefined);
|
|
281
|
-
throw new Error(`JSON-RPC batch: missing response for ${c.method}`);
|
|
282
|
-
}
|
|
283
|
-
if (r.error) {
|
|
284
|
-
if (options.permitFailure)
|
|
285
|
-
return results.push(undefined);
|
|
286
|
-
throw new JsonRpcError(c.method, r.error);
|
|
287
|
-
}
|
|
288
|
-
results.push(r.result);
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
return results;
|
|
292
|
-
}
|
|
293
|
-
// ---------------------------------------------------------------------------
|
|
294
|
-
// misc
|
|
295
|
-
// ---------------------------------------------------------------------------
|
|
296
|
-
function isNodeSideRetryable(e) {
|
|
297
|
-
const code = e === null || e === void 0 ? void 0 : e.code;
|
|
298
|
-
// -32005 node is behind / limit exceeded, -32603 internal error, -32000 server error
|
|
299
|
-
return code === -32005 || code === -32603 || code === -32000;
|
|
300
|
-
}
|
|
301
|
-
function pickRetry(options) {
|
|
302
|
-
const { delay, backoff, maxDelay, shouldRetry } = options;
|
|
303
|
-
const res = {};
|
|
304
|
-
if (delay !== undefined)
|
|
305
|
-
res.delay = delay;
|
|
306
|
-
if (backoff !== undefined)
|
|
307
|
-
res.backoff = backoff;
|
|
308
|
-
if (maxDelay !== undefined)
|
|
309
|
-
res.maxDelay = maxDelay;
|
|
310
|
-
if (shouldRetry !== undefined)
|
|
311
|
-
res.shouldRetry = shouldRetry;
|
|
312
|
-
return res;
|
|
313
|
-
}
|
|
314
|
-
function shortUrl(url) {
|
|
315
|
-
try {
|
|
316
|
-
const u = new URL(url);
|
|
317
|
-
return u.host;
|
|
318
|
-
}
|
|
319
|
-
catch {
|
|
320
|
-
return String(url).slice(0, 60);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
function shortMessage(e) {
|
|
324
|
-
var _a;
|
|
325
|
-
return String((_a = e === null || e === void 0 ? void 0 : e.message) !== null && _a !== void 0 ? _a : e).slice(0, 200);
|
|
326
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
export declare const CHAIN = "starknet";
|
|
2
|
-
export declare const DEFAULT_ENDPOINTS: string[];
|
|
3
|
-
export declare const DEFAULT_MULTICALL_ADDRESS = "0x01a33330996310a1e3fa1df5b16c1e07f0491fdd20c441126e02613b948f0225";
|
|
4
|
-
export declare const AGGREGATE_CHUNK_SIZE = 50;
|
|
5
|
-
export declare const BATCH_CHUNK_SIZE = 25;
|
|
6
|
-
export declare function getEndpoints(): string[];
|
|
7
|
-
export declare function getMulticallAddress(): string;
|
|
8
|
-
export interface AbiParam {
|
|
9
|
-
name?: string;
|
|
10
|
-
type: string;
|
|
11
|
-
/** Cairo 0 struct members carry `offset`; kept open for other metadata */
|
|
12
|
-
[key: string]: any;
|
|
13
|
-
}
|
|
14
|
-
export interface AbiEntry {
|
|
15
|
-
name: string;
|
|
16
|
-
type?: string;
|
|
17
|
-
inputs?: AbiParam[];
|
|
18
|
-
outputs?: AbiParam[];
|
|
19
|
-
members?: AbiParam[];
|
|
20
|
-
variants?: AbiParam[];
|
|
21
|
-
stateMutability?: string;
|
|
22
|
-
state_mutability?: string;
|
|
23
|
-
/** 'address': params are passed through as raw felts, skipping encodeCalldata */
|
|
24
|
-
customInput?: string;
|
|
25
|
-
/** post-processing of a single output: 'address' pads, 'Uint256' | 'number' cast to number */
|
|
26
|
-
customType?: string;
|
|
27
|
-
[key: string]: any;
|
|
28
|
-
}
|
|
29
|
-
export type BlockTag = 'latest' | 'pending' | 'pre_confirmed' | 'l1_accepted';
|
|
30
|
-
export type BlockId = BlockTag | number | string | {
|
|
31
|
-
block_number: number;
|
|
32
|
-
} | {
|
|
33
|
-
block_hash: string;
|
|
34
|
-
};
|
|
35
|
-
export interface CallOptions {
|
|
36
|
-
abi: AbiEntry;
|
|
37
|
-
target: string;
|
|
38
|
-
params?: any;
|
|
39
|
-
allAbi?: AbiEntry[];
|
|
40
|
-
permitFailure?: boolean;
|
|
41
|
-
block?: BlockId;
|
|
42
|
-
}
|
|
43
|
-
export interface MultiCallItem {
|
|
44
|
-
target?: string;
|
|
45
|
-
params?: any;
|
|
46
|
-
abi?: AbiEntry;
|
|
47
|
-
allAbi?: AbiEntry[];
|
|
48
|
-
}
|
|
49
|
-
export interface MultiCallOptions {
|
|
50
|
-
abi?: AbiEntry;
|
|
51
|
-
target?: string;
|
|
52
|
-
calls: (MultiCallItem | string)[];
|
|
53
|
-
allAbi?: AbiEntry[];
|
|
54
|
-
permitFailure?: boolean;
|
|
55
|
-
useAggregator?: boolean;
|
|
56
|
-
block?: BlockId;
|
|
57
|
-
}
|
|
58
|
-
export interface StarknetEvent {
|
|
59
|
-
block_number?: number;
|
|
60
|
-
block_hash?: string;
|
|
61
|
-
transaction_hash: string;
|
|
62
|
-
from_address: string;
|
|
63
|
-
keys: string[];
|
|
64
|
-
data: string[];
|
|
65
|
-
}
|
|
66
|
-
export interface GetLogsOptions {
|
|
67
|
-
target: string;
|
|
68
|
-
fromBlock: number;
|
|
69
|
-
toBlock?: number;
|
|
70
|
-
/** event selectors (any of them): shorthand for keys: [topics] */
|
|
71
|
-
topics?: (string | bigint | number)[];
|
|
72
|
-
/** raw starknet_getEvents keys filter (positional, each an OR list) */
|
|
73
|
-
keys?: (string | bigint | number | (string | bigint | number)[])[];
|
|
74
|
-
/** kept for signature parity with the adapters helper (used there as cache-key segment); ignored */
|
|
75
|
-
extraKey?: string;
|
|
76
|
-
/** page size for starknet_getEvents (default 1000; halved and retried when the provider rejects it) */
|
|
77
|
-
chunkSize?: number;
|
|
78
|
-
}
|
|
79
|
-
export declare const ADDR_BOUND: bigint;
|
|
80
|
-
export declare const FIELD_PRIME: bigint;
|
|
81
|
-
export type BigNumberish = string | number | bigint | boolean;
|
|
82
|
-
export declare function toBigInt(value: BigNumberish): bigint;
|
|
83
|
-
export declare function toHex(value: BigNumberish): string;
|
|
84
|
-
export declare function addAddressPadding(address: BigNumberish): string;
|
|
85
|
-
export declare function validateAndParseAddress(address: BigNumberish): string;
|
|
86
|
-
/**
|
|
87
|
-
* Loose check for a Starknet address: 0x-prefixed hex, non-zero, inside the
|
|
88
|
-
* address bound, and not shaped like an EVM address (exactly 40 hex chars).
|
|
89
|
-
*/
|
|
90
|
-
export declare function isStarknetAddress(value: any): boolean;
|
|
91
|
-
/** starknet_keccak: keccak256 of the utf8 name, masked to 250 bits */
|
|
92
|
-
export declare function starknetKeccak(str: string): bigint;
|
|
93
|
-
export declare function getSelectorFromName(name: string): string;
|
|
94
|
-
/** u256 as { low, high } object or [low, high] felt pair -> bigint */
|
|
95
|
-
export declare function parseUint256(value: {
|
|
96
|
-
low: BigNumberish;
|
|
97
|
-
high: BigNumberish;
|
|
98
|
-
} | BigNumberish[] | BigNumberish): bigint;
|
|
99
|
-
/** Cairo short string (<= 31 utf8 bytes) -> hex felt */
|
|
100
|
-
export declare function shortStringToFelt(str: string): string;
|
|
101
|
-
/** hex/decimal/bigint felt -> utf8 short string (leading zero bytes dropped) */
|
|
102
|
-
export declare function feltToShortString(felt: BigNumberish): string;
|
|
103
|
-
/** concatenate an array of short-string felts (e.g. a felt* name) */
|
|
104
|
-
export declare function feltArrToStr(felts: BigNumberish[]): string;
|
|
105
|
-
export declare const number: {
|
|
106
|
-
toHex: typeof toHex;
|
|
107
|
-
toBigInt: typeof toBigInt;
|
|
108
|
-
toBN: typeof toBigInt;
|
|
109
|
-
hexToDecimalString: (v: BigNumberish) => string;
|
|
110
|
-
};
|
|
111
|
-
/**
|
|
112
|
-
* Encode function arguments into calldata (array of hex felts).
|
|
113
|
-
* @param fnAbi function abi entry (or just its `inputs` array)
|
|
114
|
-
* @param params positional arguments
|
|
115
|
-
* @param allAbi struct/enum definitions referenced by the function
|
|
116
|
-
*/
|
|
117
|
-
export declare function encodeCalldata(fnAbi: AbiEntry | AbiParam[], params?: any, allAbi?: AbiEntry[]): string[];
|
|
118
|
-
/**
|
|
119
|
-
* Decode a starknet_call result according to the function abi.
|
|
120
|
-
* @param fnAbi function abi entry (or just its `outputs` array)
|
|
121
|
-
* @param result array of felts returned by the node
|
|
122
|
-
* @param allAbi struct/enum definitions referenced by the function
|
|
123
|
-
*/
|
|
124
|
-
export declare function decodeOutput(fnAbi: AbiEntry | AbiParam[], result: any[], allAbi?: AbiEntry[]): any;
|
|
125
|
-
export declare function toBlockId(block?: BlockId): any;
|
|
126
|
-
export interface StarknetCallRequest {
|
|
127
|
-
contract_address: string;
|
|
128
|
-
entry_point_selector: string;
|
|
129
|
-
calldata: string[];
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Build a `starknet_call` JSON-RPC request. `abi.customInput === 'address'`
|
|
133
|
-
* passes params through as raw felts (u256 inputs pre-split by the caller).
|
|
134
|
-
*/
|
|
135
|
-
export declare function formCallBody({ abi, target, params, allAbi, block }: CallOptions, id?: number | string): {
|
|
136
|
-
jsonrpc: string;
|
|
137
|
-
id: string | number;
|
|
138
|
-
method: string;
|
|
139
|
-
params: any[];
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* Decode a call result and apply the legacy post-processing: BigInts at depth 1
|
|
143
|
-
* become strings, a single non-Cairo 1 output is unwrapped, `Uint256` outputs
|
|
144
|
-
* (or `customType: 'Uint256' | 'number'`) become numbers, `customType: 'address'`
|
|
145
|
-
* is padded.
|
|
146
|
-
*/
|
|
147
|
-
export declare function parseOutput(result: any, abi: AbiEntry, allAbi?: AbiEntry[], { permitFailure, error }?: {
|
|
148
|
-
permitFailure?: boolean;
|
|
149
|
-
error?: any;
|
|
150
|
-
}): any;
|
|
151
|
-
/** Raw JSON-RPC call against the Starknet endpoints (STARKNET_RPC rotation + retries) */
|
|
152
|
-
export declare function rpc(method: string, params?: any): Promise<any>;
|
|
153
|
-
export declare function getBlockNumber(): Promise<number>;
|
|
154
|
-
export declare function getBlock({ blockNumber, block }?: {
|
|
155
|
-
blockNumber?: number | 'latest';
|
|
156
|
-
block?: BlockId;
|
|
157
|
-
}): Promise<{
|
|
158
|
-
number: number;
|
|
159
|
-
timestamp: number;
|
|
160
|
-
hash?: string;
|
|
161
|
-
}>;
|
|
162
|
-
/** Last block whose timestamp is <= `timestamp` (binary search, no cache) */
|
|
163
|
-
export declare function getBlockAtTimestamp({ timestamp }: {
|
|
164
|
-
timestamp: number;
|
|
165
|
-
}): Promise<{
|
|
166
|
-
number: number;
|
|
167
|
-
timestamp: number;
|
|
168
|
-
}>;
|
|
169
|
-
export declare function getNonce({ address, block }: {
|
|
170
|
-
address: string;
|
|
171
|
-
block?: BlockId;
|
|
172
|
-
}): Promise<string>;
|
|
173
|
-
export declare function getClassHashAt({ address, block }: {
|
|
174
|
-
address: string;
|
|
175
|
-
block?: BlockId;
|
|
176
|
-
}): Promise<string>;
|
|
177
|
-
export declare function call({ abi, target, params, allAbi, permitFailure, block }: CallOptions): Promise<any>;
|
|
178
|
-
/**
|
|
179
|
-
* Run many `starknet_call`s. By default one on-chain `aggregate` call per 50
|
|
180
|
-
* sub-calls; if the aggregator reverts (any sub-call reverting reverts the whole
|
|
181
|
-
* batch) or `useAggregator` is false, falls back to JSON-RPC batches of 25 so
|
|
182
|
-
* `permitFailure` still applies per call. Results are in call order.
|
|
183
|
-
*/
|
|
184
|
-
export declare function multiCall(options: MultiCallOptions): Promise<any[]>;
|
|
185
|
-
/** starknet_getEvents page size; public providers reject larger pages ("Requested page size is too big") */
|
|
186
|
-
export declare const DEFAULT_EVENTS_CHUNK_SIZE = 1000;
|
|
187
|
-
/**
|
|
188
|
-
* Fetch events emitted by `target` via `starknet_getEvents`, following
|
|
189
|
-
* `continuation_token` until the range [fromBlock, toBlock] is exhausted.
|
|
190
|
-
* Returns raw events: { block_number, transaction_hash, from_address, keys, data }.
|
|
191
|
-
*/
|
|
192
|
-
export declare function getLogs({ target, fromBlock, toBlock, topics, keys, chunkSize }: GetLogsOptions): Promise<StarknetEvent[]>;
|
|
193
|
-
/**
|
|
194
|
-
* Cairo 0 style ERC20 ABIs (camelCase entrypoints, `felt` / `Uint256` types).
|
|
195
|
-
* `balanceOf` uses `customInput: 'address'` so the owner felt is passed through
|
|
196
|
-
* untouched; `decimals` casts to a number.
|
|
197
|
-
*/
|
|
198
|
-
export declare const erc20Abis: Record<string, AbiEntry>;
|
|
199
|
-
/**
|
|
200
|
-
* Cairo 1 style ERC20 ABIs (snake_case entrypoints, `core::` types). u256
|
|
201
|
-
* outputs decode to a bigint (returned as a decimal string by `call`).
|
|
202
|
-
*/
|
|
203
|
-
export declare const erc20AbisCairo1: Record<string, AbiEntry>;
|
|
204
|
-
/** alias matching the coins repo export */
|
|
205
|
-
export declare const cairoErc20Abis: Record<string, AbiEntry>;
|