@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.
- package/build/ChainApi.d.ts +23 -1
- package/build/ChainApi.js +13 -0
- package/build/abi/tron.js +7 -1
- package/build/chains/algorand.d.ts +277 -0
- package/build/chains/algorand.js +618 -0
- package/build/chains/aptos.d.ts +230 -0
- package/build/chains/aptos.js +612 -0
- package/build/chains/cardano.d.ts +242 -0
- package/build/chains/cardano.js +407 -0
- package/build/chains/cosmos.d.ts +252 -0
- package/build/chains/cosmos.js +618 -0
- package/build/chains/icp.d.ts +235 -0
- package/build/chains/icp.js +1040 -0
- package/build/chains/index.d.ts +23 -0
- package/build/chains/index.js +59 -0
- package/build/chains/near.d.ts +192 -0
- package/build/chains/near.js +446 -0
- package/build/chains/rpc.d.ts +125 -0
- package/build/chains/rpc.js +326 -0
- package/build/chains/starknet.d.ts +205 -0
- package/build/chains/starknet.js +884 -0
- package/build/chains/stellar.d.ts +410 -0
- package/build/chains/stellar.js +1082 -0
- package/build/chains/substrate.d.ts +333 -0
- package/build/chains/substrate.js +1042 -0
- package/build/chains/sui.d.ts +365 -0
- package/build/chains/sui.js +1135 -0
- package/build/chains/svm.d.ts +340 -0
- package/build/chains/svm.js +760 -0
- package/build/chains/tezos.d.ts +225 -0
- package/build/chains/tezos.js +412 -0
- package/build/chains/ton.d.ts +353 -0
- package/build/chains/ton.js +788 -0
- package/build/chains/tron.d.ts +45 -0
- package/build/chains/tron.js +110 -0
- package/build/chains/utxo.d.ts +202 -0
- package/build/chains/utxo.js +592 -0
- package/build/chains/xrpl.d.ts +179 -0
- package/build/chains/xrpl.js +467 -0
- package/build/index.d.ts +2 -1
- package/build/index.js +3 -1
- package/build/providers.json +1 -1
- package/build/util/LlamaProvider.js +2 -0
- package/build/util/blocks.js +292 -84
- package/build/util/chainUtils/data.json +80 -0
- package/build/util/chainUtils/index.d.ts +1 -0
- package/build/util/chainUtils/index.js +23 -0
- package/build/util/coins.js +14 -3
- package/build/util/common.js +6 -4
- package/build/util/computeTVL.js +1 -1
- package/build/util/cosmos.d.ts +1 -11
- package/build/util/cosmos.js +6 -66
- package/build/util/env.d.ts +1 -0
- package/build/util/env.js +18 -0
- package/build/util/indexer.compatibility.d.ts +6 -0
- package/build/util/indexer.compatibility.js +64 -0
- package/build/util/indexer.d.ts +24 -2
- package/build/util/indexer.js +333 -294
- package/build/util/indexerSql.d.ts +8 -1
- package/build/util/indexerSql.js +53 -22
- package/build/util/logs.d.ts +3 -0
- package/build/util/logs.decode.shared.js +5 -4
- package/build/util/logs.js +57 -26
- package/build/util/transactions.d.ts +23 -1
- package/build/util/updateChainLabels.d.ts +1 -0
- package/build/util/updateChainLabels.js +5 -0
- package/build/util/updateProviderList.js +40 -18
- package/package.json +20 -7
- package/README.md +0 -41
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { Endpoints } from "./rpc";
|
|
2
|
+
export declare const CHAIN = "icp";
|
|
3
|
+
export declare const DEFAULT_ENDPOINTS: string[];
|
|
4
|
+
/** ICP ledger canister */
|
|
5
|
+
export declare const ICP_LEDGER = "ryjl3-tyaaa-aaaaa-aaaba-cai";
|
|
6
|
+
/** Candid encoding of an empty argument list: "DIDL" + 0 types + 0 args */
|
|
7
|
+
export declare const EMPTY_ARGS: Uint8Array;
|
|
8
|
+
/** anonymous principal (0x04) */
|
|
9
|
+
export declare const ANONYMOUS_SENDER: Uint8Array;
|
|
10
|
+
type Cursor = {
|
|
11
|
+
i: number;
|
|
12
|
+
};
|
|
13
|
+
/** Encode a CBOR item head: major type (0-7) + unsigned argument. */
|
|
14
|
+
export declare function encodeCborHead(major: number, value: number | bigint): Buffer;
|
|
15
|
+
/**
|
|
16
|
+
* Encode a JS value as CBOR. Supports null, booleans, integers (number / bigint, negative too),
|
|
17
|
+
* byte strings (Buffer / Uint8Array), text, arrays and plain objects (keys encoded as text, in
|
|
18
|
+
* insertion order). Floats are rejected: the IC request format never needs them.
|
|
19
|
+
*/
|
|
20
|
+
export declare function encodeCbor(value: any): Buffer;
|
|
21
|
+
/**
|
|
22
|
+
* Decode one CBOR item starting at `state.i` (default: the start of `bytes`).
|
|
23
|
+
* Integers within the safe range decode to `number`, larger ones to `bigint`; byte strings to
|
|
24
|
+
* `Uint8Array`; maps to plain objects. Tags are skipped (the IC self-describe tag 55799 included).
|
|
25
|
+
*/
|
|
26
|
+
export declare function decodeCbor(bytes: Uint8Array, state?: Cursor): any;
|
|
27
|
+
/** Read an unsigned LEB128 integer at `state.i`, advancing the cursor. */
|
|
28
|
+
export declare function decodeUleb128(bytes: Uint8Array, state: Cursor): bigint;
|
|
29
|
+
/** Read a signed LEB128 integer at `state.i`, advancing the cursor. */
|
|
30
|
+
export declare function decodeSleb128(bytes: Uint8Array, state: Cursor): bigint;
|
|
31
|
+
/** Encode a non-negative integer as unsigned LEB128. */
|
|
32
|
+
export declare function encodeUleb128(value: number | bigint | string): Buffer;
|
|
33
|
+
/** Encode an integer as signed LEB128. */
|
|
34
|
+
export declare function encodeSleb128(value: number | bigint | string): Buffer;
|
|
35
|
+
/** Candid type opcodes (negative sleb128 in the type table) */
|
|
36
|
+
export declare const CANDID_TYPE: {
|
|
37
|
+
readonly null: -1;
|
|
38
|
+
readonly bool: -2;
|
|
39
|
+
readonly nat: -3;
|
|
40
|
+
readonly int: -4;
|
|
41
|
+
readonly nat8: -5;
|
|
42
|
+
readonly nat16: -6;
|
|
43
|
+
readonly nat32: -7;
|
|
44
|
+
readonly nat64: -8;
|
|
45
|
+
readonly int8: -9;
|
|
46
|
+
readonly int16: -10;
|
|
47
|
+
readonly int32: -11;
|
|
48
|
+
readonly int64: -12;
|
|
49
|
+
readonly float32: -13;
|
|
50
|
+
readonly float64: -14;
|
|
51
|
+
readonly text: -15;
|
|
52
|
+
readonly reserved: -16;
|
|
53
|
+
readonly empty: -17;
|
|
54
|
+
readonly opt: -18;
|
|
55
|
+
readonly vec: -19;
|
|
56
|
+
readonly record: -20;
|
|
57
|
+
readonly variant: -21;
|
|
58
|
+
readonly func: -22;
|
|
59
|
+
readonly service: -23;
|
|
60
|
+
readonly principal: -24;
|
|
61
|
+
};
|
|
62
|
+
export type CandidPrimitive = 'null' | 'bool' | 'nat' | 'int' | 'nat8' | 'nat16' | 'nat32' | 'nat64' | 'int8' | 'int16' | 'int32' | 'int64' | 'float32' | 'float64' | 'text' | 'reserved' | 'empty' | 'principal'
|
|
63
|
+
/** shorthand for `vec nat8`, value may be Uint8Array / number[] / hex string */
|
|
64
|
+
| 'blob';
|
|
65
|
+
/**
|
|
66
|
+
* Type descriptor for {@link encodeCandid}. Record / variant field names are hashed with
|
|
67
|
+
* {@link hashCandidLabel}; a purely numeric name (`'0'`, `'1'`) is used as the field id directly
|
|
68
|
+
* (Candid tuple fields).
|
|
69
|
+
*/
|
|
70
|
+
export type CandidType = CandidPrimitive | {
|
|
71
|
+
opt: CandidType;
|
|
72
|
+
} | {
|
|
73
|
+
vec: CandidType;
|
|
74
|
+
} | {
|
|
75
|
+
record: Record<string, CandidType>;
|
|
76
|
+
} | {
|
|
77
|
+
variant: Record<string, CandidType>;
|
|
78
|
+
};
|
|
79
|
+
export interface CandidValue {
|
|
80
|
+
type: CandidType;
|
|
81
|
+
value: any;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Candid identifies a record field by a hash of its name rather than the name itself, so a decoded
|
|
85
|
+
* record comes back keyed by number. Build a `{ [hash]: name }` map with this (or with
|
|
86
|
+
* {@link buildLabelHashMap}) to get readable keys. `hash = fold(h * 223 + byte) mod 2^32`.
|
|
87
|
+
*/
|
|
88
|
+
export declare function hashCandidLabel(label: string): number;
|
|
89
|
+
/** `['owner', 'subaccount']` -> `{ 947296307: 'owner', 1349681965: 'subaccount' }` */
|
|
90
|
+
export declare function buildLabelHashMap(labels?: string[]): Record<number, string>;
|
|
91
|
+
/**
|
|
92
|
+
* Decode a Candid-encoded reply. Candid is self-describing, so the concrete shape is only known at
|
|
93
|
+
* runtime and values are returned as `any`; narrow them at the call site.
|
|
94
|
+
* - `nat`, `int`, `nat64`, `int64` -> `bigint`; `nat8/16/32`, `int8/16/32`, floats -> `number`
|
|
95
|
+
* - `text`, `principal` -> `string`; `opt` -> 0- or 1-element array; `vec` -> array (`vec nat8` too)
|
|
96
|
+
* - `record` -> object keyed by label (via `labelHashMap`) or by field hash as a string
|
|
97
|
+
* - `variant` -> single-key object
|
|
98
|
+
* @param bytes the raw `DIDL...` payload returned by {@link queryCanister}
|
|
99
|
+
* @param labelHashMap `{ [hash]: name }` from {@link hashCandidLabel}; unmapped fields keep their hash
|
|
100
|
+
* @returns one entry per value in the reply tuple
|
|
101
|
+
*/
|
|
102
|
+
export declare function decodeCandid(bytes: Uint8Array, labelHashMap?: Record<number, string>): any[];
|
|
103
|
+
/**
|
|
104
|
+
* Minimal Candid encoder: `DIDL` + type table + arg types + values.
|
|
105
|
+
*
|
|
106
|
+
* Value conventions (mirroring what {@link decodeCandid} produces):
|
|
107
|
+
* - `nat` / `int` / fixed-width ints accept number, bigint or decimal string
|
|
108
|
+
* - `text` string; `bool` boolean; `null` / `reserved` anything (nothing is written)
|
|
109
|
+
* - `principal` textual principal or raw bytes
|
|
110
|
+
* - `blob` (`vec nat8`) Uint8Array / Buffer / number[] / hex string
|
|
111
|
+
* - `opt` `null` / `undefined` / `[]` -> none, `[x]` -> some(x), any other value -> some(value)
|
|
112
|
+
* - `vec` array (or Uint8Array when the element type is `nat8`)
|
|
113
|
+
* - `record` object keyed by field name; a missing `opt` field is encoded as none
|
|
114
|
+
* - `variant` single-key object `{ Tag: value }`, or a string `'Tag'` for unit variants
|
|
115
|
+
*/
|
|
116
|
+
export declare function encodeCandid(args?: CandidValue[]): Buffer;
|
|
117
|
+
/** Uint8Array / Buffer / number[] / hex string (0x optional) -> Uint8Array */
|
|
118
|
+
export declare function toBytes(value: any, what?: string): Uint8Array;
|
|
119
|
+
/** CRC-32 (IEEE) as used by principal text and account identifiers */
|
|
120
|
+
export declare function crc32(bytes: Uint8Array): number;
|
|
121
|
+
/** RFC 4648 base32 without padding, lowercase alphabet by default (as principals use). */
|
|
122
|
+
export declare function bytesToBase32(bytes: Uint8Array, alphabet?: string): string;
|
|
123
|
+
/** Inverse of {@link bytesToBase32}: case-insensitive, ignores `-` separators and `=` padding. */
|
|
124
|
+
export declare function base32ToBytes(text: string): Uint8Array;
|
|
125
|
+
/** Raw principal bytes -> textual principal (`crc32 || bytes`, base32, dashed every 5 chars). */
|
|
126
|
+
export declare function principalBytesToText(principalBytes: Uint8Array): string;
|
|
127
|
+
/** Textual principal -> raw bytes. Verifies the CRC-32 prefix and throws on mismatch. */
|
|
128
|
+
export declare function principalTextToBytes(principalText: string): Uint8Array;
|
|
129
|
+
/** True when `str` is a well formed textual principal (valid base32, checksum and grouping). */
|
|
130
|
+
export declare function isPrincipal(str: any): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* ICP ledger account identifier (hex, 32 bytes):
|
|
133
|
+
* `crc32(h) || h` where `h = sha224("\x0Aaccount-id" || principal || subaccount)`.
|
|
134
|
+
* `subaccount` defaults to 32 zero bytes; accepts Uint8Array / number[] / hex, right-padded to 32 bytes.
|
|
135
|
+
*/
|
|
136
|
+
export declare function accountIdentifierFromPrincipal(principal: string | Uint8Array, subaccount?: Uint8Array | number[] | string | null): string;
|
|
137
|
+
/** Boundary node list: `ICP_RPC` (comma separated) or {@link DEFAULT_ENDPOINTS}. */
|
|
138
|
+
export declare function getEndpoints(): string[];
|
|
139
|
+
/** Thrown when the replica answers a query with a reject (canister error, missing method, dead canister). */
|
|
140
|
+
export declare class IcpRejectError extends Error {
|
|
141
|
+
canisterId: string;
|
|
142
|
+
method: string;
|
|
143
|
+
status?: string;
|
|
144
|
+
rejectCode?: number;
|
|
145
|
+
rejectMessage?: string;
|
|
146
|
+
errorCode?: string;
|
|
147
|
+
constructor(canisterId: string, method: string, decoded: any);
|
|
148
|
+
}
|
|
149
|
+
export interface QueryCanisterParams {
|
|
150
|
+
canisterId: string;
|
|
151
|
+
/** canister method name */
|
|
152
|
+
method?: string;
|
|
153
|
+
/** alias of `method` (DefiLlama-Adapters / dimension-adapters naming) */
|
|
154
|
+
methodName?: string;
|
|
155
|
+
/** Candid encoded argument, default: empty args (`DIDL\0\0`) */
|
|
156
|
+
arg?: Uint8Array;
|
|
157
|
+
/** explicit boundary node(s); overrides `ICP_RPC` and the defaults */
|
|
158
|
+
host?: Endpoints;
|
|
159
|
+
/** http timeout in ms, default 30s */
|
|
160
|
+
timeout?: number;
|
|
161
|
+
/** total transport attempts across hosts, default max(3, hosts) */
|
|
162
|
+
retries?: number;
|
|
163
|
+
}
|
|
164
|
+
export interface QueryDecodedParams extends QueryCanisterParams {
|
|
165
|
+
/** `{ [hash]: name }` map for record / variant labels (see {@link hashCandidLabel}) */
|
|
166
|
+
labelHashMap?: Record<number, string>;
|
|
167
|
+
/** label names, merged into `labelHashMap` via {@link buildLabelHashMap} */
|
|
168
|
+
labels?: string[];
|
|
169
|
+
}
|
|
170
|
+
export interface CallCandidParams extends QueryDecodedParams {
|
|
171
|
+
/** typed arguments `{ type, value }`; or raw values when `argTypes` is given */
|
|
172
|
+
args?: CandidValue[] | any[];
|
|
173
|
+
/** types for `args` when they are raw values */
|
|
174
|
+
argTypes?: CandidType[];
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Anonymous query call against a canister (`/api/v2/canister/<id>/query`).
|
|
178
|
+
* Rotates over the configured boundary nodes and retries transport errors; canister rejects are
|
|
179
|
+
* thrown as {@link IcpRejectError} without retry.
|
|
180
|
+
* @returns the raw Candid reply (`DIDL...` bytes), to be passed to {@link decodeCandid}
|
|
181
|
+
*/
|
|
182
|
+
export declare function queryCanister(params: QueryCanisterParams): Promise<Uint8Array>;
|
|
183
|
+
/**
|
|
184
|
+
* Query a method and decode its reply in one step.
|
|
185
|
+
* Accepts either `{ canisterId, method, arg?, labelHashMap?, labels? }` or the dimension-adapters
|
|
186
|
+
* positional form `(canisterId, methodName, labels?)`.
|
|
187
|
+
* @returns the first value of the reply tuple (`any`, see {@link decodeCandid})
|
|
188
|
+
*/
|
|
189
|
+
export declare function queryCanisterDecoded(params: QueryDecodedParams): Promise<any>;
|
|
190
|
+
export declare function queryCanisterDecoded(canisterId: string, method: string, labels?: string[]): Promise<any>;
|
|
191
|
+
/**
|
|
192
|
+
* Encode `args` with {@link encodeCandid}, query `method` and decode the reply.
|
|
193
|
+
* `args` is either `CandidValue[]` (`{ type, value }`) or raw values paired with `argTypes`.
|
|
194
|
+
* @returns the first value of the reply tuple
|
|
195
|
+
*/
|
|
196
|
+
export declare function callCandid(params: CallCandidParams): Promise<any>;
|
|
197
|
+
export interface LedgerParams {
|
|
198
|
+
/** ledger canister id */
|
|
199
|
+
ledger: string;
|
|
200
|
+
host?: Endpoints;
|
|
201
|
+
timeout?: number;
|
|
202
|
+
}
|
|
203
|
+
export type IcrcMetadataValue = string | Uint8Array;
|
|
204
|
+
/**
|
|
205
|
+
* `icrc1_metadata` as `{ 'icrc1:symbol': 'ckBTC', 'icrc1:decimals': '8', ... }`.
|
|
206
|
+
* `Nat` / `Int` values are returned as decimal strings, `Text` as string, `Blob` as Uint8Array.
|
|
207
|
+
*/
|
|
208
|
+
export declare function getIcrcMetadata({ ledger, host, timeout }: LedgerParams): Promise<Record<string, IcrcMetadataValue>>;
|
|
209
|
+
/** `icrc1_decimals` (nat8) */
|
|
210
|
+
export declare function getIcrcDecimals({ ledger, host, timeout }: LedgerParams): Promise<number>;
|
|
211
|
+
/** `icrc1_symbol` */
|
|
212
|
+
export declare function getIcrcSymbol({ ledger, host, timeout }: LedgerParams): Promise<string>;
|
|
213
|
+
/** `icrc1_name` */
|
|
214
|
+
export declare function getIcrcName({ ledger, host, timeout }: LedgerParams): Promise<string>;
|
|
215
|
+
/** `icrc1_total_supply` as a decimal string in base units */
|
|
216
|
+
export declare function getIcrcTotalSupply({ ledger, host, timeout }: LedgerParams): Promise<string>;
|
|
217
|
+
/**
|
|
218
|
+
* `icrc1_balance_of(record { owner: principal; subaccount: opt blob })` as a decimal string in base units.
|
|
219
|
+
* `subaccount` accepts Uint8Array / number[] / hex; omit it for the default subaccount.
|
|
220
|
+
*/
|
|
221
|
+
export declare function getIcrcBalance({ ledger, owner, subaccount, host, timeout }: LedgerParams & {
|
|
222
|
+
owner: string;
|
|
223
|
+
subaccount?: Uint8Array | number[] | string | null;
|
|
224
|
+
}): Promise<string>;
|
|
225
|
+
/**
|
|
226
|
+
* ICP ledger `account_balance(record { account: blob })` -> `e8s` as a decimal string.
|
|
227
|
+
* `accountIdentifierHex` is the 32 byte account identifier (see {@link accountIdentifierFromPrincipal}).
|
|
228
|
+
*/
|
|
229
|
+
export declare function getIcpAccountBalance({ accountIdentifierHex, ledger, host, timeout }: {
|
|
230
|
+
accountIdentifierHex: string;
|
|
231
|
+
ledger?: string;
|
|
232
|
+
host?: Endpoints;
|
|
233
|
+
timeout?: number;
|
|
234
|
+
}): Promise<string>;
|
|
235
|
+
export {};
|