@defillama/sdk 5.0.245 → 5.0.249

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.
@@ -131,7 +131,7 @@ const DEPLOYMENT_BLOCK = {
131
131
  flow: 968659,
132
132
  rupx: 35231,
133
133
  fluence: 207583,
134
- ontology: 17984796,
134
+ ontology_evm: 17984796,
135
135
  wc: 4353799,
136
136
  unit0: 9727,
137
137
  spn: 39,
@@ -214,7 +214,7 @@ const DEPLOYMENT_BLOCK = {
214
214
  ebc: 1,
215
215
  citrea: 1,
216
216
  tempo: 1,
217
- edegex: 1,
217
+ edgex: 2121,
218
218
  wchain: 2207643,
219
219
  fluent: 754598,
220
220
  pharos: 1,
@@ -0,0 +1,84 @@
1
+ /**
2
+ * ICON JSON-RPC (v3) client: `icx_call` read-only contract calls, balances, blocks.
3
+ *
4
+ * Replaces the chain access parts of:
5
+ * - DefiLlama-Adapters projects/helper/chain/icx.js (call, getICXBalance, toInt, toHex)
6
+ * - peggedassets-server src/adapters/peggedAssets/helper/icon.ts (getXSupply, getICONSupply)
7
+ *
8
+ * Endpoints: `ICON_RPC` (comma separated) overrides `DEFAULT_ENDPOINTS`.
9
+ *
10
+ * ICON returns every number as a `0x` hex string. Functions here return the raw hex from
11
+ * `call` and decimal strings (base units) from the typed helpers; use `hexToBigInt`,
12
+ * `hexToNumber` or `fromLoop` (1 ICX = 1e18 loop) to convert.
13
+ *
14
+ * Usage: `sdk.chains.icon.call({ to: 'cx88fd...', method: 'totalSupply' })`
15
+ */
16
+ import { JsonRpcOptions } from "./rpc";
17
+ export declare const CHAIN = "icon";
18
+ export declare const DEFAULT_ENDPOINTS: string[];
19
+ export declare const LOOP_PER_ICX: bigint;
20
+ /** Configured endpoints (env `ICON_RPC` first, then `DEFAULT_ENDPOINTS`). */
21
+ export declare function getEndpoints(): string[];
22
+ /** `hx...` wallet or `cx...` contract address. */
23
+ export declare function isIconAddress(str: any): boolean;
24
+ export declare function isContractAddress(str: any): boolean;
25
+ /** `0x`-hex (or decimal) string / number / bigint -> bigint. Negative hex (`-0x..`) is accepted. */
26
+ export declare function hexToBigInt(value: string | number | bigint | null | undefined): bigint;
27
+ /** Same as `hexToBigInt` but as a JS number (precision is lost above 2^53). */
28
+ export declare function hexToNumber(value: string | number | bigint | null | undefined): number;
29
+ /** loop (1e-18 ICX, or any 18-decimal IRC-2 unit) -> whole units as a JS number. */
30
+ export declare function fromLoop(value: string | number | bigint | null | undefined): number;
31
+ /** number / bigint / decimal string -> `0x` hex as ICON expects it. */
32
+ export declare function toHex(value: number | bigint | string): string;
33
+ export type RpcOptions = Omit<JsonRpcOptions, 'chain' | 'endpoints' | 'defaultEndpoints'>;
34
+ /** Raw JSON-RPC call. ICON wants `params` to be an object (never an array), so none becomes `{}`. */
35
+ export declare function rpc(method: string, params?: Record<string, any>, options?: RpcOptions): Promise<any>;
36
+ export interface CallOptions extends RpcOptions {
37
+ /** `cx...` contract */
38
+ to: string;
39
+ method: string;
40
+ /** named params as the contract declares them, e.g. `{ _owner: 'hx...' }` */
41
+ params?: Record<string, any>;
42
+ /** block height (number or `0x` hex) for a historical read */
43
+ height?: number | string;
44
+ /** sender, defaults to the null wallet */
45
+ from?: string;
46
+ }
47
+ /** `icx_call`: read-only method call, returns the raw result (hex string or object). */
48
+ export declare function call({ to, method, params, height, from, ...options }: CallOptions): Promise<any>;
49
+ /** Native ICX balance in loop as a decimal string. */
50
+ export declare function getBalance({ address, height }: {
51
+ address: string;
52
+ height?: number | string;
53
+ }): Promise<string>;
54
+ /** IRC-2 `balanceOf(_owner)` in token base units as a decimal string. */
55
+ export declare function getTokenBalance({ token, owner, height }: {
56
+ token: string;
57
+ owner: string;
58
+ height?: number | string;
59
+ }): Promise<string>;
60
+ /** IRC-2 `totalSupply()` in token base units as a decimal string. */
61
+ export declare function getTokenTotalSupply({ token, height }: {
62
+ token: string;
63
+ height?: number | string;
64
+ }): Promise<string>;
65
+ /** IRC-2 `decimals()` as a number. */
66
+ export declare function getTokenDecimals({ token }: {
67
+ token: string;
68
+ }): Promise<number>;
69
+ /** IRC-2 `symbol()` */
70
+ export declare function getTokenSymbol({ token }: {
71
+ token: string;
72
+ }): Promise<string>;
73
+ export interface BlockInfo {
74
+ number: number;
75
+ /** unix timestamp in seconds (ICON reports microseconds) */
76
+ timestamp: number;
77
+ hash: string;
78
+ }
79
+ /** `icx_getLastBlock` */
80
+ export declare function getLastBlock(): Promise<BlockInfo>;
81
+ /** `icx_getBlockByHeight` */
82
+ export declare function getBlock({ height }: {
83
+ height: number | string;
84
+ }): Promise<BlockInfo>;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LOOP_PER_ICX = exports.DEFAULT_ENDPOINTS = exports.CHAIN = void 0;
4
+ exports.getEndpoints = getEndpoints;
5
+ exports.isIconAddress = isIconAddress;
6
+ exports.isContractAddress = isContractAddress;
7
+ exports.hexToBigInt = hexToBigInt;
8
+ exports.hexToNumber = hexToNumber;
9
+ exports.fromLoop = fromLoop;
10
+ exports.toHex = toHex;
11
+ exports.rpc = rpc;
12
+ exports.call = call;
13
+ exports.getBalance = getBalance;
14
+ exports.getTokenBalance = getTokenBalance;
15
+ exports.getTokenTotalSupply = getTokenTotalSupply;
16
+ exports.getTokenDecimals = getTokenDecimals;
17
+ exports.getTokenSymbol = getTokenSymbol;
18
+ exports.getLastBlock = getLastBlock;
19
+ exports.getBlock = getBlock;
20
+ /**
21
+ * ICON JSON-RPC (v3) client: `icx_call` read-only contract calls, balances, blocks.
22
+ *
23
+ * Replaces the chain access parts of:
24
+ * - DefiLlama-Adapters projects/helper/chain/icx.js (call, getICXBalance, toInt, toHex)
25
+ * - peggedassets-server src/adapters/peggedAssets/helper/icon.ts (getXSupply, getICONSupply)
26
+ *
27
+ * Endpoints: `ICON_RPC` (comma separated) overrides `DEFAULT_ENDPOINTS`.
28
+ *
29
+ * ICON returns every number as a `0x` hex string. Functions here return the raw hex from
30
+ * `call` and decimal strings (base units) from the typed helpers; use `hexToBigInt`,
31
+ * `hexToNumber` or `fromLoop` (1 ICX = 1e18 loop) to convert.
32
+ *
33
+ * Usage: `sdk.chains.icon.call({ to: 'cx88fd...', method: 'totalSupply' })`
34
+ */
35
+ const rpc_1 = require("./rpc");
36
+ exports.CHAIN = 'icon';
37
+ exports.DEFAULT_ENDPOINTS = ['https://ctz.solidwallet.io/api/v3'];
38
+ exports.LOOP_PER_ICX = BigInt('1000000000000000000');
39
+ /** Configured endpoints (env `ICON_RPC` first, then `DEFAULT_ENDPOINTS`). */
40
+ function getEndpoints() {
41
+ return (0, rpc_1.getEndpoints)(exports.CHAIN, exports.DEFAULT_ENDPOINTS);
42
+ }
43
+ // ---------------------------------------------------------------------------
44
+ // pure helpers
45
+ // ---------------------------------------------------------------------------
46
+ const ADDRESS_RE = /^(hx|cx)[0-9a-f]{40}$/;
47
+ /** `hx...` wallet or `cx...` contract address. */
48
+ function isIconAddress(str) {
49
+ return typeof str === 'string' && ADDRESS_RE.test(str);
50
+ }
51
+ function isContractAddress(str) {
52
+ return isIconAddress(str) && str.startsWith('cx');
53
+ }
54
+ /** `0x`-hex (or decimal) string / number / bigint -> bigint. Negative hex (`-0x..`) is accepted. */
55
+ function hexToBigInt(value) {
56
+ if (value === null || value === undefined || value === '')
57
+ return BigInt(0);
58
+ if (typeof value === 'bigint')
59
+ return value;
60
+ if (typeof value === 'number')
61
+ return BigInt(Math.trunc(value));
62
+ const s = String(value).trim();
63
+ if (s.startsWith('-0x') || s.startsWith('-0X'))
64
+ return -BigInt(s.slice(1));
65
+ return BigInt(s);
66
+ }
67
+ /** Same as `hexToBigInt` but as a JS number (precision is lost above 2^53). */
68
+ function hexToNumber(value) {
69
+ return Number(hexToBigInt(value));
70
+ }
71
+ /** loop (1e-18 ICX, or any 18-decimal IRC-2 unit) -> whole units as a JS number. */
72
+ function fromLoop(value) {
73
+ return Number(hexToBigInt(value)) / 1e18;
74
+ }
75
+ /** number / bigint / decimal string -> `0x` hex as ICON expects it. */
76
+ function toHex(value) {
77
+ const n = typeof value === 'string' && !value.startsWith('0x') ? BigInt(value) : BigInt(value);
78
+ return (n < BigInt(0) ? '-0x' : '0x') + (n < BigInt(0) ? -n : n).toString(16);
79
+ }
80
+ // ICON answers JSON-RPC errors (reverted call, unknown method, missing block) with HTTP 400, which
81
+ // axios reports as a transport error; surface those as JsonRpcError and do not retry them
82
+ function rpcErrorBody(e) {
83
+ var _a, _b, _c;
84
+ return ((_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.status) === 400 ? (_c = (_b = e === null || e === void 0 ? void 0 : e.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error : undefined;
85
+ }
86
+ /** Raw JSON-RPC call. ICON wants `params` to be an object (never an array), so none becomes `{}`. */
87
+ async function rpc(method, params, options = {}) {
88
+ var _a;
89
+ try {
90
+ return await (0, rpc_1.jsonRpc)(method, params !== null && params !== void 0 ? params : {}, {
91
+ ...options, chain: exports.CHAIN, endpoints: getEndpoints(),
92
+ shouldRetry: (_a = options.shouldRetry) !== null && _a !== void 0 ? _a : ((e) => !rpcErrorBody(e) && !(e instanceof rpc_1.JsonRpcError && !(0, rpc_1.isRateLimitError)(e))),
93
+ });
94
+ }
95
+ catch (e) {
96
+ const error = rpcErrorBody(e);
97
+ if (error)
98
+ throw new rpc_1.JsonRpcError(method, error);
99
+ throw e;
100
+ }
101
+ }
102
+ /** `icx_call`: read-only method call, returns the raw result (hex string or object). */
103
+ async function call({ to, method, params, height, from, ...options }) {
104
+ const body = {
105
+ to,
106
+ dataType: 'call',
107
+ data: params === undefined ? { method } : { method, params },
108
+ };
109
+ if (from)
110
+ body.from = from;
111
+ if (height !== undefined)
112
+ body.height = typeof height === 'number' ? toHex(height) : height;
113
+ return rpc('icx_call', body, options);
114
+ }
115
+ // ---------------------------------------------------------------------------
116
+ // balances / tokens
117
+ // ---------------------------------------------------------------------------
118
+ /** Native ICX balance in loop as a decimal string. */
119
+ async function getBalance({ address, height }) {
120
+ const params = { address };
121
+ if (height !== undefined)
122
+ params.height = typeof height === 'number' ? toHex(height) : height;
123
+ return hexToBigInt(await rpc('icx_getBalance', params)).toString();
124
+ }
125
+ /** IRC-2 `balanceOf(_owner)` in token base units as a decimal string. */
126
+ async function getTokenBalance({ token, owner, height }) {
127
+ return hexToBigInt(await call({ to: token, method: 'balanceOf', params: { _owner: owner }, height })).toString();
128
+ }
129
+ /** IRC-2 `totalSupply()` in token base units as a decimal string. */
130
+ async function getTokenTotalSupply({ token, height }) {
131
+ return hexToBigInt(await call({ to: token, method: 'totalSupply', height })).toString();
132
+ }
133
+ /** IRC-2 `decimals()` as a number. */
134
+ async function getTokenDecimals({ token }) {
135
+ return hexToNumber(await call({ to: token, method: 'decimals' }));
136
+ }
137
+ /** IRC-2 `symbol()` */
138
+ async function getTokenSymbol({ token }) {
139
+ return String(await call({ to: token, method: 'symbol' }));
140
+ }
141
+ function toBlockInfo(block) {
142
+ return {
143
+ number: Number(block.height),
144
+ timestamp: Math.floor(Number(block.time_stamp) / 1e6),
145
+ hash: block.block_hash,
146
+ };
147
+ }
148
+ /** `icx_getLastBlock` */
149
+ async function getLastBlock() {
150
+ return toBlockInfo(await rpc('icx_getLastBlock'));
151
+ }
152
+ /** `icx_getBlockByHeight` */
153
+ async function getBlock({ height }) {
154
+ return toBlockInfo(await rpc('icx_getBlockByHeight', { height: typeof height === 'number' ? toHex(height) : height }));
155
+ }
@@ -21,3 +21,6 @@ export * as icp from "./icp";
21
21
  export * as substrate from "./substrate";
22
22
  export * as utxo from "./utxo";
23
23
  export * as tron from "./tron";
24
+ export * as zilliqa from "./zilliqa";
25
+ export * as icon from "./icon";
26
+ export * as ontology from "./ontology";
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.tron = exports.utxo = exports.substrate = exports.icp = exports.tezos = exports.cardano = exports.xrpl = exports.stellar = exports.algorand = exports.ton = exports.near = exports.sui = exports.aptos = exports.starknet = exports.cosmos = exports.svm = exports.rpc = void 0;
36
+ exports.ontology = exports.icon = exports.zilliqa = exports.tron = exports.utxo = exports.substrate = exports.icp = exports.tezos = exports.cardano = exports.xrpl = exports.stellar = exports.algorand = exports.ton = exports.near = exports.sui = exports.aptos = exports.starknet = exports.cosmos = exports.svm = exports.rpc = void 0;
37
37
  /**
38
38
  * Non-EVM chain clients. One module per chain family, all resolving endpoints
39
39
  * through `rpc.getEndpoints` so `<CHAIN>_RPC` env vars override built-in defaults.
@@ -57,3 +57,6 @@ exports.icp = __importStar(require("./icp"));
57
57
  exports.substrate = __importStar(require("./substrate"));
58
58
  exports.utxo = __importStar(require("./utxo"));
59
59
  exports.tron = __importStar(require("./tron"));
60
+ exports.zilliqa = __importStar(require("./zilliqa"));
61
+ exports.icon = __importStar(require("./icon"));
62
+ exports.ontology = __importStar(require("./ontology"));
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Ontology (non-EVM) balances and token info over the Ontology explorer REST API.
3
+ *
4
+ * Replaces the chain access parts of:
5
+ * - DefiLlama-Adapters projects/helper/chain/ontology.js (getNativeBalances)
6
+ * - peggedassets-server src/adapters/peggedAssets/helper/ontology.ts (getTotalSupply, getBalance)
7
+ *
8
+ * Endpoints: `ONTOLOGY_EXPLORER` (comma separated) overrides `DEFAULT_EXPLORER`. There is no
9
+ * public JSON-RPC that answers balance queries for OEP-4 / ORC-20 tokens without running a
10
+ * node, so the explorer is the source. `ontology_evm` is a separate EVM chain and is not
11
+ * handled here.
12
+ *
13
+ * The explorer already divides balances and supplies by the token decimals, so every
14
+ * amount here is in WHOLE units as a decimal string (unlike the other chain modules).
15
+ *
16
+ * Usage: `sdk.chains.ontology.getTokenBalance({ address: 'A...', tokenType: 'oep4', contract: '061a...' })`
17
+ */
18
+ import { HttpOptions } from "./rpc";
19
+ export declare const CHAIN = "ontology";
20
+ export declare const DEFAULT_EXPLORER = "https://explorer.ont.io";
21
+ export type TokenType = 'native' | 'oep4' | 'oep5' | 'oep8' | 'orc20' | 'orc721' | 'orc1155';
22
+ /** Configured explorer base urls (env `ONTOLOGY_EXPLORER` first, then `DEFAULT_EXPLORER`). */
23
+ export declare function getEndpoints(): string[];
24
+ export interface NativeBalance {
25
+ /** `ont`, `ong`, `unboundong`, `waitboundong` */
26
+ asset_name: string;
27
+ /** whole units */
28
+ balance: string;
29
+ asset_type: string;
30
+ contract_hash: string;
31
+ }
32
+ export interface TokenBalance {
33
+ /** whole units */
34
+ balance: string;
35
+ asset_name: string;
36
+ asset_type: string;
37
+ contract_hash: string;
38
+ [key: string]: any;
39
+ }
40
+ export interface TokenInfo {
41
+ contract_hash: string;
42
+ name?: string;
43
+ symbol?: string;
44
+ decimals?: number;
45
+ /** whole units */
46
+ total_supply: string;
47
+ [key: string]: any;
48
+ }
49
+ /** bare lowercase contract hash (the explorer ignores a `0x` prefix in paths but not in comparisons) */
50
+ export declare function normalizeContract(contract: string): string;
51
+ /**
52
+ * GET `path` on the explorer and unwrap `{ code, msg, result }`. The explorer answers
53
+ * HTTP 200 with `code != 0` on failure, so that is turned into an error here.
54
+ */
55
+ export declare function explorerGet({ path, params, ...options }: {
56
+ path: string;
57
+ params?: Record<string, any>;
58
+ } & HttpOptions): Promise<any>;
59
+ /** ONT / ONG (+ unbound / waitbound ONG) balances of `address`, whole units. */
60
+ export declare function getNativeBalances({ address }: {
61
+ address: string;
62
+ }): Promise<NativeBalance[]>;
63
+ /** One native asset balance (`ont` or `ong`) in whole units, `'0'` when absent. */
64
+ export declare function getNativeBalance({ address, asset }: {
65
+ address: string;
66
+ asset: 'ont' | 'ong';
67
+ }): Promise<string>;
68
+ /** Every `tokenType` balance held by `address`, whole units. */
69
+ export declare function getTokenBalances({ address, tokenType }: {
70
+ address: string;
71
+ tokenType: TokenType;
72
+ }): Promise<TokenBalance[]>;
73
+ /** Balance of one token (`contract` hash) held by `address`, whole units; `'0'` when not held. */
74
+ export declare function getTokenBalance({ address, tokenType, contract }: {
75
+ address: string;
76
+ tokenType: TokenType;
77
+ contract: string;
78
+ }): Promise<string>;
79
+ /** Token details (`/v2/tokens/{type}/{hash}`); throws when the explorer does not know it. */
80
+ export declare function getToken({ tokenType, contract }: {
81
+ tokenType: TokenType;
82
+ contract: string;
83
+ }): Promise<TokenInfo>;
84
+ /** Total supply in whole units as a decimal string. */
85
+ export declare function getTokenTotalSupply({ tokenType, contract }: {
86
+ tokenType: TokenType;
87
+ contract: string;
88
+ }): Promise<string>;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_EXPLORER = exports.CHAIN = void 0;
4
+ exports.getEndpoints = getEndpoints;
5
+ exports.normalizeContract = normalizeContract;
6
+ exports.explorerGet = explorerGet;
7
+ exports.getNativeBalances = getNativeBalances;
8
+ exports.getNativeBalance = getNativeBalance;
9
+ exports.getTokenBalances = getTokenBalances;
10
+ exports.getTokenBalance = getTokenBalance;
11
+ exports.getToken = getToken;
12
+ exports.getTokenTotalSupply = getTokenTotalSupply;
13
+ /**
14
+ * Ontology (non-EVM) balances and token info over the Ontology explorer REST API.
15
+ *
16
+ * Replaces the chain access parts of:
17
+ * - DefiLlama-Adapters projects/helper/chain/ontology.js (getNativeBalances)
18
+ * - peggedassets-server src/adapters/peggedAssets/helper/ontology.ts (getTotalSupply, getBalance)
19
+ *
20
+ * Endpoints: `ONTOLOGY_EXPLORER` (comma separated) overrides `DEFAULT_EXPLORER`. There is no
21
+ * public JSON-RPC that answers balance queries for OEP-4 / ORC-20 tokens without running a
22
+ * node, so the explorer is the source. `ontology_evm` is a separate EVM chain and is not
23
+ * handled here.
24
+ *
25
+ * The explorer already divides balances and supplies by the token decimals, so every
26
+ * amount here is in WHOLE units as a decimal string (unlike the other chain modules).
27
+ *
28
+ * Usage: `sdk.chains.ontology.getTokenBalance({ address: 'A...', tokenType: 'oep4', contract: '061a...' })`
29
+ */
30
+ const rpc_1 = require("./rpc");
31
+ exports.CHAIN = 'ontology';
32
+ exports.DEFAULT_EXPLORER = 'https://explorer.ont.io';
33
+ /** Configured explorer base urls (env `ONTOLOGY_EXPLORER` first, then `DEFAULT_EXPLORER`). */
34
+ function getEndpoints() {
35
+ return (0, rpc_1.getEndpoints)(exports.CHAIN, exports.DEFAULT_EXPLORER, { envKey: 'ONTOLOGY_EXPLORER' });
36
+ }
37
+ /** bare lowercase contract hash (the explorer ignores a `0x` prefix in paths but not in comparisons) */
38
+ function normalizeContract(contract) {
39
+ return contract.trim().replace(/^0x/i, '').toLowerCase();
40
+ }
41
+ /**
42
+ * GET `path` on the explorer and unwrap `{ code, msg, result }`. The explorer answers
43
+ * HTTP 200 with `code != 0` on failure, so that is turned into an error here.
44
+ */
45
+ async function explorerGet({ path, params, ...options }) {
46
+ var _a;
47
+ const res = await (0, rpc_1.httpGet)(getEndpoints(), { path, params, ...options });
48
+ if (!res || typeof res !== 'object')
49
+ throw new Error(`ontology explorer: empty response for ${path}`);
50
+ if (res.code !== 0)
51
+ throw new Error(`ontology explorer: ${(_a = res.msg) !== null && _a !== void 0 ? _a : 'request failed'} (code ${res.code}) for ${path}`);
52
+ return res.result;
53
+ }
54
+ // ---------------------------------------------------------------------------
55
+ // balances
56
+ // ---------------------------------------------------------------------------
57
+ /** ONT / ONG (+ unbound / waitbound ONG) balances of `address`, whole units. */
58
+ async function getNativeBalances({ address }) {
59
+ const res = await explorerGet({ path: `/v2/addresses/${address}/native/balances` });
60
+ return Array.isArray(res) ? res : [];
61
+ }
62
+ /** One native asset balance (`ont` or `ong`) in whole units, `'0'` when absent. */
63
+ async function getNativeBalance({ address, asset }) {
64
+ var _a;
65
+ const row = (await getNativeBalances({ address })).find(i => i.asset_name === asset);
66
+ return String((_a = row === null || row === void 0 ? void 0 : row.balance) !== null && _a !== void 0 ? _a : '0');
67
+ }
68
+ /** Every `tokenType` balance held by `address`, whole units. */
69
+ async function getTokenBalances({ address, tokenType }) {
70
+ const res = await explorerGet({ path: `/v2/addresses/${address}/${tokenType}/balances` });
71
+ return Array.isArray(res) ? res : [];
72
+ }
73
+ /** Balance of one token (`contract` hash) held by `address`, whole units; `'0'` when not held. */
74
+ async function getTokenBalance({ address, tokenType, contract }) {
75
+ var _a;
76
+ const hash = normalizeContract(contract);
77
+ const row = (await getTokenBalances({ address, tokenType })).find(i => { var _a; return normalizeContract((_a = i.contract_hash) !== null && _a !== void 0 ? _a : '') === hash; });
78
+ return String((_a = row === null || row === void 0 ? void 0 : row.balance) !== null && _a !== void 0 ? _a : '0');
79
+ }
80
+ // ---------------------------------------------------------------------------
81
+ // tokens
82
+ // ---------------------------------------------------------------------------
83
+ /** Token details (`/v2/tokens/{type}/{hash}`); throws when the explorer does not know it. */
84
+ async function getToken({ tokenType, contract }) {
85
+ return explorerGet({ path: `/v2/tokens/${tokenType}/${normalizeContract(contract)}` });
86
+ }
87
+ /** Total supply in whole units as a decimal string. */
88
+ async function getTokenTotalSupply({ tokenType, contract }) {
89
+ const token = await getToken({ tokenType, contract });
90
+ if ((token === null || token === void 0 ? void 0 : token.total_supply) === undefined || token.total_supply === null)
91
+ throw new Error(`ontology: no total_supply for ${tokenType} ${contract}`);
92
+ return String(token.total_supply);
93
+ }
@@ -57,8 +57,9 @@ const rpc_1 = require("./rpc");
57
57
  exports.DEFAULT_TZKT = 'https://api.tzkt.io';
58
58
  /** Tezos node RPC endpoints, overridable with `TEZOS_RPC` (comma separated). */
59
59
  exports.DEFAULT_RPC_ENDPOINTS = [
60
- 'https://mainnet.api.tez.ie',
61
60
  'https://rpc.tzkt.io/mainnet',
61
+ 'https://mainnet.smartpy.io',
62
+ 'https://rpc.tzbeta.net',
62
63
  ];
63
64
  exports.MUTEZ_PER_TEZ = 1000000;
64
65
  exports.MAINNET_CHAIN_ID = 'NetXdQprcVkpaWU';
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Zilliqa native (Scilla) JSON-RPC client.
3
+ *
4
+ * Replaces the chain access parts of:
5
+ * - DefiLlama-Adapters projects/helper/chain/zilliqa.js (call, formQuery, getContractState,
6
+ * getBalance, getZilliqaBalance, getBalances)
7
+ * - peggedassets-server src/adapters/peggedAssets/helper/zilliqa.ts (getZilliqaTokenSupply)
8
+ *
9
+ * Endpoints: `ZILLIQA_NATIVE_RPC` (comma separated) overrides the default. The chain's
10
+ * `ZILLIQA_RPC` key is its EVM endpoint in providers.json, so it is deliberately not used here,
11
+ * the same way cosmos uses `<CHAIN>_LCD`. api.zilliqa.com serves both.
12
+ *
13
+ * Addresses: the API wants bare 40-char hex. Every function accepts `0x`-prefixed hex, bare hex
14
+ * or bech32 (`zil1...`) and normalises with `toHexAddress`. Balances come back as raw base units
15
+ * (Qa for ZIL, 1e12 per ZIL; token base units for ZRC-2) as decimal strings.
16
+ *
17
+ * Usage: `sdk.chains.zilliqa.getTokenBalance({ token: '0x818c...', address: 'zil1...' })`
18
+ */
19
+ import { JsonRpcOptions } from "./rpc";
20
+ export declare const CHAIN = "zilliqa";
21
+ export declare const DEFAULT_ENDPOINTS: string[];
22
+ export declare const QA_PER_ZIL = 1000000000000;
23
+ export declare const BECH32_HRP = "zil";
24
+ /** Configured endpoints (env `ZILLIQA_NATIVE_RPC` first, then `DEFAULT_ENDPOINTS`). */
25
+ export declare function getEndpoints(): string[];
26
+ /** Decode a bech32 string into `{ hrp, data }` where `data` is the 8-bit payload. */
27
+ export declare function bech32Decode(str: string): {
28
+ hrp: string;
29
+ data: Buffer;
30
+ };
31
+ /** Encode an 8-bit payload as bech32 with `hrp`. */
32
+ export declare function bech32Encode(hrp: string, data: Uint8Array): string;
33
+ export declare function isBech32Address(str: any): boolean;
34
+ export declare function isHexAddress(str: any): boolean;
35
+ /** bech32 (`zil1...`), `0x` hex or bare hex -> bare lowercase hex (what the API expects). */
36
+ export declare function toHexAddress(address: string): string;
37
+ /** Any accepted address form -> `zil1...` bech32. */
38
+ export declare function toBech32Address(address: string): string;
39
+ /** Qa (1e-12 ZIL) -> ZIL as a JS number. */
40
+ export declare function qaToZil(qa: string | number | bigint): number;
41
+ export type RpcOptions = Omit<JsonRpcOptions, 'chain' | 'endpoints' | 'defaultEndpoints'>;
42
+ /** Raw JSON-RPC call against the configured endpoints (rotated + retried). */
43
+ export declare function rpc(method: string, params?: any[], options?: RpcOptions): Promise<any>;
44
+ export interface BatchCall {
45
+ method: string;
46
+ params?: any[];
47
+ id?: string | number;
48
+ }
49
+ /**
50
+ * JSON-RPC batch, results in call order. Failed entries resolve to `undefined`
51
+ * (the API answers errors per item, e.g. an unknown substate).
52
+ */
53
+ export declare function rpcBatch(calls: BatchCall[], options?: RpcOptions & {
54
+ chunkSize?: number;
55
+ }): Promise<any[]>;
56
+ /** `GetBalance`: `{ balance (Qa string), nonce }`; `{ balance: '0', nonce: 0 }` for an unused address. */
57
+ export declare function getAccount({ address }: {
58
+ address: string;
59
+ }): Promise<{
60
+ balance: string;
61
+ nonce: number;
62
+ }>;
63
+ /** Native ZIL balance in Qa as a decimal string. */
64
+ export declare function getBalance({ address }: {
65
+ address: string;
66
+ }): Promise<string>;
67
+ /** `GetSmartContractInit`: the immutable init params as `[{ vname, type, value }]`. */
68
+ export declare function getContractInit({ contract }: {
69
+ contract: string;
70
+ }): Promise<{
71
+ vname: string;
72
+ type: string;
73
+ value: any;
74
+ }[]>;
75
+ /** `[{ vname, value }]` -> `{ vname: value }`. */
76
+ export declare function initToObject(init: {
77
+ vname: string;
78
+ value: any;
79
+ }[]): Record<string, any>;
80
+ /** `GetSmartContractState`: the whole mutable state. Large for tokens; prefer `getContractSubState`. */
81
+ export declare function getContractState({ contract }: {
82
+ contract: string;
83
+ }): Promise<any>;
84
+ /**
85
+ * `GetSmartContractSubState`: one state variable, optionally narrowed by map `indices`.
86
+ * Resolves to `{ [variable]: value }` or `null` when the variable / index does not exist.
87
+ */
88
+ export declare function getContractSubState({ contract, variable, indices }: {
89
+ contract: string;
90
+ variable: string;
91
+ indices?: string[];
92
+ }): Promise<any>;
93
+ /** Several `GetSmartContractSubState` in one batch; missing entries are `undefined`. */
94
+ export declare function getContractSubStates(items: {
95
+ contract: string;
96
+ variable: string;
97
+ indices?: string[];
98
+ }[], options?: RpcOptions & {
99
+ chunkSize?: number;
100
+ }): Promise<any[]>;
101
+ export interface TokenInfo {
102
+ contract: string;
103
+ symbol?: string;
104
+ name?: string;
105
+ decimals?: number;
106
+ /** raw total supply in token base units */
107
+ totalSupply: string;
108
+ }
109
+ /** Raw ZRC-2 balance of `address` for `token`; `'0'` when the holder is unknown. */
110
+ export declare function getTokenBalance({ token, address }: {
111
+ token: string;
112
+ address: string;
113
+ }): Promise<string>;
114
+ /**
115
+ * Raw ZRC-2 balances for every `token` x `address` pair, one batch request.
116
+ * Returns `{ [tokenHex]: { [addressHex]: balance } }` with `0x`-prefixed lowercase keys.
117
+ */
118
+ export declare function getTokenBalances({ tokens, addresses }: {
119
+ tokens: string[];
120
+ addresses: string[];
121
+ }): Promise<Record<string, Record<string, string>>>;
122
+ /**
123
+ * Raw ZRC-2 total supply. Reads the `total_supply` substate; contracts that name the
124
+ * field differently fall back to a full state scan for a `*supply*` key.
125
+ */
126
+ export declare function getTokenTotalSupply({ token }: {
127
+ token: string;
128
+ }): Promise<string>;
129
+ /** `decimals` from the init params (ZRC-2); undefined when the contract has none. */
130
+ export declare function getTokenDecimals({ token }: {
131
+ token: string;
132
+ }): Promise<number | undefined>;
133
+ /** symbol / name / decimals (init params) + raw total supply. */
134
+ export declare function getTokenInfo({ token }: {
135
+ token: string;
136
+ }): Promise<TokenInfo>;
137
+ export interface BlockInfo {
138
+ /** tx block number */
139
+ number: number;
140
+ /** unix timestamp in seconds (the API reports microseconds) */
141
+ timestamp: number;
142
+ hash: string;
143
+ }
144
+ /** `GetLatestTxBlock` */
145
+ export declare function getLatestBlock(): Promise<BlockInfo>;
146
+ /** `GetTxBlock` by number. */
147
+ export declare function getBlock({ number }: {
148
+ number: number | string;
149
+ }): Promise<BlockInfo>;