@defillama/sdk 5.0.242 → 5.0.244

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.
@@ -45,7 +45,7 @@ const DEPLOYMENT_BLOCK = {
45
45
  flare: 3002461,
46
46
  milkomeda: 4377424,
47
47
  velas: 55883577,
48
- // telos: 246530709,
48
+ telos: 246530709,
49
49
  step: 5734583,
50
50
  canto: 2905789,
51
51
  iotex: 22163670,
@@ -245,6 +245,8 @@ const DEPLOYMENT_BLOCK = {
245
245
  metall2: 1,
246
246
  rbn: 2714761,
247
247
  xpla: 19189761,
248
+ funki: 1,
249
+ etn: 15031577,
248
250
  };
249
251
  async function makeMultiCall(functionABI, calls, chain, block) {
250
252
  if (!functionABI)
package/build/abi/tron.js CHANGED
@@ -46,6 +46,7 @@ const p_limit_1 = __importDefault(require("p-limit"));
46
46
  const env_1 = require("../util/env");
47
47
  const common_1 = require("../util/common");
48
48
  const evmAbi = __importStar(require("./index"));
49
+ const callStats_1 = require("../util/callStats");
49
50
  const limitRPCCalls = (0, p_limit_1.default)(+(0, env_1.getEnvValue)('TRON_RPC_CONCURRENCY_LIMIT', '5'));
50
51
  const getEndpoint = () => (0, env_1.getEnvValue)('TRON_WALLET_RPC');
51
52
  const balanceCache = {};
@@ -96,6 +97,7 @@ exports.hexifyTarget = common_1.tronToEvmAddress;
96
97
  async function post(body = {}, endpoint = '/wallet/triggerconstantcontract') {
97
98
  await (0, common_1.sleepRandom)(3000); // sleep random time to avoid rate limit
98
99
  const hosts = (getEndpoint()).split(',');
100
+ (0, callStats_1.registerEndpoints)('tron', hosts);
99
101
  hosts.sort(() => Math.random() - 0.5); // shuffle hosts
100
102
  const errors = [];
101
103
  for (const host of hosts) {
@@ -77,6 +77,7 @@ const env_1 = require("../util/env");
77
77
  const LlamaProvider_1 = require("../util/LlamaProvider");
78
78
  const debugLog_1 = require("../util/debugLog");
79
79
  const rpc_1 = require("./rpc");
80
+ const callStats_1 = require("../util/callStats");
80
81
  // ---------------------------------------------------------------------------
81
82
  // config
82
83
  // ---------------------------------------------------------------------------
@@ -213,12 +214,16 @@ function getEndpoints({ chain }) {
213
214
  throw new Error('cosmos.getEndpoints: chain is required');
214
215
  const envKey = `${chain.toUpperCase()}_LCD`;
215
216
  const fromLcdEnv = (0, rpc_1.toEndpointList)((0, env_1.getEnvValue)(envKey));
216
- if (fromLcdEnv.length)
217
+ if (fromLcdEnv.length) {
218
+ (0, callStats_1.registerEndpoints)(chain, fromLcdEnv);
217
219
  return fromLcdEnv;
220
+ }
218
221
  if (!isEvmLikeChain(chain)) {
219
222
  const fromRpcEnv = (0, rpc_1.toEndpointList)((0, env_1.getEnvRPC)(chain));
220
- if (fromRpcEnv.length)
223
+ if (fromRpcEnv.length) {
224
+ (0, callStats_1.registerEndpoints)(chain, fromRpcEnv);
221
225
  return fromRpcEnv;
226
+ }
222
227
  }
223
228
  return (0, rpc_1.getEndpoints)(chain, exports.DEFAULT_ENDPOINTS[chain], { envKey, fallback: `${COSMOS_DIRECTORY_REST}/${chain}` });
224
229
  }
@@ -36,6 +36,7 @@ const env_1 = require("../util/env");
36
36
  const common_1 = require("../util/common");
37
37
  Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return common_1.sleep; } });
38
38
  const debugLog_1 = require("../util/debugLog");
39
+ const callStats_1 = require("../util/callStats");
39
40
  const DEFAULT_TIMEOUT = 60000;
40
41
  // ---------------------------------------------------------------------------
41
42
  // endpoint resolution
@@ -53,6 +54,11 @@ function toEndpointList(value) {
53
54
  * Throws when nothing is configured so a misconfigured chain fails loudly.
54
55
  */
55
56
  function getEndpoints(chain, defaults, { envKey, fallback, } = {}) {
57
+ const list = _getEndpoints(chain, defaults, { envKey, fallback });
58
+ (0, callStats_1.registerEndpoints)(chain, list); // so http level call stats are attributed to this chain
59
+ return list;
60
+ }
61
+ function _getEndpoints(chain, defaults, { envKey, fallback, } = {}) {
56
62
  if (chain) {
57
63
  const whitelisted = toEndpointList((0, env_1.getWhitelistedRPCs)(chain));
58
64
  if (whitelisted.length)
@@ -61,6 +61,7 @@ exports.getLogs = getLogs;
61
61
  const ethers_1 = require("ethers");
62
62
  const env_1 = require("../util/env");
63
63
  const debugLog_1 = require("../util/debugLog");
64
+ const callStats_1 = require("../util/callStats");
64
65
  const rpc_1 = require("./rpc");
65
66
  // ---------------------------------------------------------------------------
66
67
  // config
@@ -753,6 +754,7 @@ async function getLogs({ target, fromBlock, toBlock, topics, keys, chunkSize = e
753
754
  while (true) {
754
755
  let page;
755
756
  try {
757
+ (0, callStats_1.recordMethod)('getLogs', 'starknet');
756
758
  page = await rpc('starknet_getEvents', [filter]);
757
759
  }
758
760
  catch (e) {
@@ -295,6 +295,33 @@ export interface CoinMetadata {
295
295
  }
296
296
  /** `coinMetadata` (GraphQL) or `<prefix>x_getCoinMetadata` + `<prefix>x_getTotalSupply` (JSON-RPC) */
297
297
  export declare function getCoinMetadata({ chain, coinType }: CoinTypeOptions): Promise<CoinMetadata>;
298
+ /** `0x2::coin_registry::Currency<T>` — the standard that replaces `0x2::coin::CoinMetadata<T>` */
299
+ export declare const COIN_REGISTRY_TYPE = "0x2::coin_registry::Currency";
300
+ export interface CoinRegistryCurrency {
301
+ decimals: number;
302
+ symbol: string;
303
+ name: string;
304
+ description?: string;
305
+ iconUrl?: string;
306
+ /** base units: the registry's own value when it has one, else the TreasuryCap's `total_supply` */
307
+ supply?: string;
308
+ treasuryCapId?: string;
309
+ regulated?: boolean;
310
+ }
311
+ /**
312
+ * First numeric payload of a BCS enum variant (`{ '@variant': 'Fixed', pos0: '123' }`), if any.
313
+ * `SupplyState::Fixed` / `BurnOnly` wrap a `balance::Supply<T>`, so the number sits a struct deeper
314
+ * (`pos0.fields.value`): recurse into nested structs instead of only reading immediate scalars.
315
+ */
316
+ export declare function variantNumber(value: any, depth?: number): string | undefined;
317
+ /**
318
+ * Metadata for a coin registered under `coin_registry`. A coin minted that way can have **no**
319
+ * `0x2::coin::CoinMetadata<T>` object at all (`metadata_cap_id: Deleted`), which is exactly why
320
+ * `coinMetadata` returns null for it — a null there is not evidence the coin type is wrong.
321
+ * The registry's own `supply` is usually the `Unknown` variant, so the number is read from the
322
+ * `TreasuryCap` it points at. Returns null when the coin is not in the registry.
323
+ */
324
+ export declare function getCoinRegistryCurrency({ chain, coinType }: CoinTypeOptions): Promise<CoinRegistryCurrency | null>;
298
325
  export interface TokenSupply {
299
326
  /** base units */
300
327
  supply: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sliceIntoChunks = exports.SuiGraphqlError = exports.fromU256 = exports.fromU128 = exports.fromU64 = exports.fromU32 = exports.fromU16 = exports.toU256 = exports.toU128 = exports.toU64 = exports.toU32 = exports.toU16 = exports.uleb128 = exports.EMPTY_STRUCT_BCS = exports.DUMMY_SENDER = exports.DEFAULT_RPC_ENDPOINTS = exports.DEFAULT_GRAPHQL_ENDPOINTS = exports.suiChains = void 0;
3
+ exports.sliceIntoChunks = exports.COIN_REGISTRY_TYPE = exports.SuiGraphqlError = exports.fromU256 = exports.fromU128 = exports.fromU64 = exports.fromU32 = exports.fromU16 = exports.toU256 = exports.toU128 = exports.toU64 = exports.toU32 = exports.toU16 = exports.uleb128 = exports.EMPTY_STRUCT_BCS = exports.DUMMY_SENDER = exports.DEFAULT_RPC_ENDPOINTS = exports.DEFAULT_GRAPHQL_ENDPOINTS = exports.suiChains = void 0;
4
4
  exports.getGraphqlEndpoints = getGraphqlEndpoints;
5
5
  exports.getGraphqlEndpoint = getGraphqlEndpoint;
6
6
  exports.getRpcEndpoints = getRpcEndpoints;
@@ -39,6 +39,8 @@ exports.queryEvents = queryEvents;
39
39
  exports.getDynamicFieldObject = getDynamicFieldObject;
40
40
  exports.getDynamicFieldObjects = getDynamicFieldObjects;
41
41
  exports.getCoinMetadata = getCoinMetadata;
42
+ exports.variantNumber = variantNumber;
43
+ exports.getCoinRegistryCurrency = getCoinRegistryCurrency;
42
44
  exports.getTokenSupply = getTokenSupply;
43
45
  exports.getAllBalances = getAllBalances;
44
46
  exports.getBalance = getBalance;
@@ -920,7 +922,7 @@ async function getDynamicFieldObjects({ chain = 'sui', parent, cursor = null, li
920
922
  }
921
923
  /** `coinMetadata` (GraphQL) or `<prefix>x_getCoinMetadata` + `<prefix>x_getTotalSupply` (JSON-RPC) */
922
924
  async function getCoinMetadata({ chain = 'sui', coinType }) {
923
- var _a, _b;
925
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
924
926
  if (!hasGraphql(chain)) {
925
927
  const prefix = rpcPrefix(chain);
926
928
  const meta = await call({ chain, method: `${prefix}x_getCoinMetadata`, params: [coinType] });
@@ -942,9 +944,85 @@ async function getCoinMetadata({ chain = 'sui', coinType }) {
942
944
  }`, variables: { coinType }
943
945
  });
944
946
  const meta = data.coinMetadata;
945
- if (!meta)
947
+ if (meta && meta.supply != null)
948
+ return { decimals: (_a = meta.decimals) !== null && _a !== void 0 ? _a : 0, symbol: meta.symbol, name: meta.name, description: meta.description, iconUrl: meta.iconUrl, supply: meta.supply };
949
+ // No legacy metadata, or metadata without a supply: try the coin_registry standard below.
950
+ const currency = await getCoinRegistryCurrency({ chain, coinType }).catch((e) => {
951
+ (0, debugLog_1.debugLog)(`[${chain}] coin_registry lookup failed for ${coinType}: ${e === null || e === void 0 ? void 0 : e.message}`);
952
+ return null;
953
+ });
954
+ if (!meta && !currency)
946
955
  throw new Error(`[${chain}] Failed to fetch coin metadata for token: ${coinType}`);
947
- return { decimals: (_a = meta.decimals) !== null && _a !== void 0 ? _a : 0, symbol: meta.symbol, name: meta.name, description: meta.description, iconUrl: meta.iconUrl, supply: (_b = meta.supply) !== null && _b !== void 0 ? _b : undefined };
956
+ return {
957
+ decimals: (_c = (_b = meta === null || meta === void 0 ? void 0 : meta.decimals) !== null && _b !== void 0 ? _b : currency === null || currency === void 0 ? void 0 : currency.decimals) !== null && _c !== void 0 ? _c : 0,
958
+ symbol: (_d = meta === null || meta === void 0 ? void 0 : meta.symbol) !== null && _d !== void 0 ? _d : currency === null || currency === void 0 ? void 0 : currency.symbol,
959
+ name: (_e = meta === null || meta === void 0 ? void 0 : meta.name) !== null && _e !== void 0 ? _e : currency === null || currency === void 0 ? void 0 : currency.name,
960
+ description: (_f = meta === null || meta === void 0 ? void 0 : meta.description) !== null && _f !== void 0 ? _f : currency === null || currency === void 0 ? void 0 : currency.description,
961
+ iconUrl: (_g = meta === null || meta === void 0 ? void 0 : meta.iconUrl) !== null && _g !== void 0 ? _g : currency === null || currency === void 0 ? void 0 : currency.iconUrl,
962
+ supply: (_j = (_h = meta === null || meta === void 0 ? void 0 : meta.supply) !== null && _h !== void 0 ? _h : currency === null || currency === void 0 ? void 0 : currency.supply) !== null && _j !== void 0 ? _j : undefined,
963
+ };
964
+ }
965
+ /** `0x2::coin_registry::Currency<T>` — the standard that replaces `0x2::coin::CoinMetadata<T>` */
966
+ exports.COIN_REGISTRY_TYPE = '0x2::coin_registry::Currency';
967
+ /**
968
+ * First numeric payload of a BCS enum variant (`{ '@variant': 'Fixed', pos0: '123' }`), if any.
969
+ * `SupplyState::Fixed` / `BurnOnly` wrap a `balance::Supply<T>`, so the number sits a struct deeper
970
+ * (`pos0.fields.value`): recurse into nested structs instead of only reading immediate scalars.
971
+ */
972
+ function variantNumber(value, depth = 4) {
973
+ var _a;
974
+ const fields = (_a = value === null || value === void 0 ? void 0 : value.fields) !== null && _a !== void 0 ? _a : value;
975
+ if (!fields || typeof fields !== 'object')
976
+ return undefined;
977
+ for (const [key, inner] of Object.entries(fields)) {
978
+ if (key === '@variant')
979
+ continue;
980
+ if (typeof inner === 'number')
981
+ return String(inner);
982
+ if (typeof inner === 'string' && /^\d+$/.test(inner))
983
+ return inner;
984
+ if (depth > 0 && inner && typeof inner === 'object') {
985
+ const nested = variantNumber(inner, depth - 1);
986
+ if (nested !== undefined)
987
+ return nested;
988
+ }
989
+ }
990
+ return undefined;
991
+ }
992
+ /**
993
+ * Metadata for a coin registered under `coin_registry`. A coin minted that way can have **no**
994
+ * `0x2::coin::CoinMetadata<T>` object at all (`metadata_cap_id: Deleted`), which is exactly why
995
+ * `coinMetadata` returns null for it — a null there is not evidence the coin type is wrong.
996
+ * The registry's own `supply` is usually the `Unknown` variant, so the number is read from the
997
+ * `TreasuryCap` it points at. Returns null when the coin is not in the registry.
998
+ */
999
+ async function getCoinRegistryCurrency({ chain = 'sui', coinType }) {
1000
+ var _a, _b, _c, _d, _e, _f;
1001
+ if (!hasGraphql(chain))
1002
+ return null;
1003
+ const [currency] = await getObjectsByType({ chain, type: `${exports.COIN_REGISTRY_TYPE}<${normalizeCoinType(coinType)}>`, skipLayout: true, limit: 1 });
1004
+ const fields = currency === null || currency === void 0 ? void 0 : currency.fields;
1005
+ if (!fields)
1006
+ return null;
1007
+ const treasuryCapId = fields.treasury_cap_id ? toAddr(fields.treasury_cap_id) : undefined;
1008
+ let supply = variantNumber(fields.supply);
1009
+ if (supply === undefined && treasuryCapId) {
1010
+ const cap = await getObject({ chain, objectId: treasuryCapId, skipLayout: true });
1011
+ const total = (_a = cap === null || cap === void 0 ? void 0 : cap.fields) === null || _a === void 0 ? void 0 : _a.total_supply;
1012
+ const value = (_c = (_b = total === null || total === void 0 ? void 0 : total.fields) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : total === null || total === void 0 ? void 0 : total.value;
1013
+ if (value !== undefined && value !== null)
1014
+ supply = String(value);
1015
+ }
1016
+ return {
1017
+ decimals: Number((_d = fields.decimals) !== null && _d !== void 0 ? _d : 0),
1018
+ symbol: fields.symbol,
1019
+ name: fields.name,
1020
+ description: fields.description || undefined,
1021
+ iconUrl: fields.icon_url || undefined,
1022
+ supply,
1023
+ treasuryCapId,
1024
+ regulated: ((_f = (_e = fields.regulated) === null || _e === void 0 ? void 0 : _e.fields) === null || _f === void 0 ? void 0 : _f['@variant']) === 'Regulated' || undefined,
1025
+ };
948
1026
  }
949
1027
  async function getTokenSupply({ chain = 'sui', coinType }) {
950
1028
  const { supply, decimals } = await getCoinMetadata({ chain, coinType });
@@ -78,6 +78,7 @@ const crypto_1 = require("crypto");
78
78
  const env_1 = require("../util/env");
79
79
  const debugLog_1 = require("../util/debugLog");
80
80
  const rpc_1 = require("./rpc");
81
+ const callStats_1 = require("../util/callStats");
81
82
  // ---------------------------------------------------------------------------
82
83
  // config
83
84
  // ---------------------------------------------------------------------------
@@ -104,8 +105,11 @@ function isSvmChain(chain) {
104
105
  function getEndpoints({ chain = 'solana', isClient = false } = {}) {
105
106
  if (isClient && chain === 'solana') {
106
107
  const client = (0, env_1.getEnvValue)('SOLANA_RPC_CLIENT');
107
- if (client)
108
- return client.split(',').map(i => i.trim()).filter(Boolean);
108
+ if (client) {
109
+ const list = client.split(',').map(i => i.trim()).filter(Boolean);
110
+ (0, callStats_1.registerEndpoints)(chain, list);
111
+ return list;
112
+ }
109
113
  }
110
114
  return (0, rpc_1.getEndpoints)(chain, exports.DEFAULT_ENDPOINTS[chain]);
111
115
  }
package/build/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export * as erc20 from "./erc20";
20
20
  export * as coins from "./util/coins";
21
21
  export * as chainUtils from "./util/chainUtils";
22
22
  export * as chains from "./chains";
23
+ export * as callStats from "./util/callStats";
23
24
  export declare const log: typeof debugLog;
24
25
  export declare const logTable: typeof debugTable;
25
26
  export declare const humanizeNumber: typeof humanN.humanizeNumber;
package/build/index.js CHANGED
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.providerListJSON = exports.humanizeNumber = exports.logTable = exports.log = exports.chains = exports.chainUtils = exports.coins = exports.erc20 = exports.tron = exports.types = exports.isIndexerSqlEnabled = exports.queryIndexerSql = exports.queryClickhouse = exports.indexer = exports.graph = exports.blocks = exports.api2 = exports.elastic = exports.api = exports.sdkCache = exports.getEventLogs = exports.cache = exports.util = exports.setProvider = exports.getProvider = exports.Balances = exports.ChainApi = void 0;
39
+ exports.providerListJSON = exports.humanizeNumber = exports.logTable = exports.log = exports.callStats = exports.chains = exports.chainUtils = exports.coins = exports.erc20 = exports.tron = exports.types = exports.isIndexerSqlEnabled = exports.queryIndexerSql = exports.queryClickhouse = exports.indexer = exports.graph = exports.blocks = exports.api2 = exports.elastic = exports.api = exports.sdkCache = exports.getEventLogs = exports.cache = exports.util = exports.setProvider = exports.getProvider = exports.Balances = exports.ChainApi = void 0;
40
40
  const debugLog_1 = require("./util/debugLog");
41
41
  var ChainApi_1 = require("./ChainApi");
42
42
  Object.defineProperty(exports, "ChainApi", { enumerable: true, get: function () { return ChainApi_1.ChainApi; } });
@@ -67,6 +67,7 @@ exports.erc20 = __importStar(require("./erc20"));
67
67
  exports.coins = __importStar(require("./util/coins"));
68
68
  exports.chainUtils = __importStar(require("./util/chainUtils"));
69
69
  exports.chains = __importStar(require("./chains"));
70
+ exports.callStats = __importStar(require("./util/callStats"));
70
71
  const providers_json_1 = __importDefault(require("./providers.json"));
71
72
  exports.log = debugLog_1.debugLog;
72
73
  exports.logTable = debugLog_1.debugTable;