@d9-network/ink 0.0.1

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.
@@ -0,0 +1,750 @@
1
+ import { Binary, PolkadotClient, PolkadotSigner, SS58String } from "polkadot-api";
2
+ import { Event, InkCallableDescriptor, InkDescriptors, InkMetadata, InkStorageDescriptor } from "@polkadot-api/ink-contracts";
3
+ import { Bytes } from "@subsquid/scale-codec";
4
+ import * as _polkadot_api_substrate_bindings0 from "@polkadot-api/substrate-bindings";
5
+ import { Codec } from "@polkadot-api/substrate-bindings";
6
+ import { Observable } from "rxjs";
7
+
8
+ //#region src/errors.d.ts
9
+ /**
10
+ * Structured error types for contract operations.
11
+ * Provides detailed error information for debugging and handling.
12
+ */
13
+ /**
14
+ * Error types for contract operations
15
+ */
16
+ type ContractErrorType = "METADATA_ERROR" | "ENCODE_ERROR" | "DECODE_ERROR" | "NETWORK_ERROR" | "CONTRACT_ERROR" | "LANG_ERROR" | "TIMEOUT_ERROR" | "ABORTED" | "SIGNER_ERROR" | "TX_ERROR";
17
+ /**
18
+ * Base error class for all contract-related errors
19
+ */
20
+ declare class ContractError extends Error {
21
+ readonly type: ContractErrorType;
22
+ readonly label?: string | undefined;
23
+ readonly details?: unknown | undefined;
24
+ readonly timestamp: Date;
25
+ readonly cause?: Error;
26
+ constructor(message: string, type: ContractErrorType, label?: string | undefined, details?: unknown | undefined, cause?: Error);
27
+ /**
28
+ * Create a formatted error message for logging
29
+ */
30
+ toLogString(): string;
31
+ /**
32
+ * Convert to a plain object for serialization
33
+ */
34
+ toJSON(): Record<string, unknown>;
35
+ }
36
+ /**
37
+ * Error thrown when contract metadata is missing or invalid
38
+ */
39
+ declare class MetadataError extends ContractError {
40
+ constructor(message: string, details?: unknown);
41
+ }
42
+ /**
43
+ * Error thrown when encoding call data fails
44
+ */
45
+ declare class EncodeError extends ContractError {
46
+ constructor(label: string, message: string, details?: unknown);
47
+ }
48
+ /**
49
+ * Error thrown when decoding response fails
50
+ */
51
+ declare class DecodeError extends ContractError {
52
+ constructor(label: string, message: string, details?: unknown);
53
+ }
54
+ /**
55
+ * Error thrown for network/RPC errors
56
+ */
57
+ declare class NetworkError extends ContractError {
58
+ constructor(message: string, cause?: Error, details?: unknown);
59
+ }
60
+ /**
61
+ * Error thrown when contract returns an error result
62
+ */
63
+ declare class ContractExecutionError extends ContractError {
64
+ readonly errorValue: unknown;
65
+ constructor(label: string, errorValue: unknown);
66
+ }
67
+ /**
68
+ * Error thrown for Ink LangError
69
+ */
70
+ declare class LangError extends ContractError {
71
+ readonly variant: number;
72
+ constructor(label: string, variant: number);
73
+ }
74
+ /**
75
+ * Error thrown when request times out
76
+ */
77
+ declare class TimeoutError extends ContractError {
78
+ readonly timeoutMs: number;
79
+ constructor(label: string, timeoutMs: number);
80
+ }
81
+ /**
82
+ * Error thrown when request is aborted
83
+ */
84
+ declare class AbortedError extends ContractError {
85
+ constructor(label: string, reason?: string);
86
+ }
87
+ /**
88
+ * Error thrown for signer-related issues
89
+ */
90
+ declare class SignerError extends ContractError {
91
+ constructor(message: string, details?: unknown);
92
+ }
93
+ /**
94
+ * Error thrown when transaction submission fails
95
+ */
96
+ declare class TransactionError extends ContractError {
97
+ readonly txHash?: string | undefined;
98
+ constructor(label: string, message: string, txHash?: string | undefined, details?: unknown);
99
+ }
100
+ /**
101
+ * Type guard to check if an error is a ContractError
102
+ */
103
+ declare function isContractError(error: unknown): error is ContractError;
104
+ /**
105
+ * Type guard to check for specific error types
106
+ */
107
+ declare function isErrorType<T extends ContractErrorType>(error: unknown, type: T): error is ContractError & {
108
+ type: T;
109
+ };
110
+ //#endregion
111
+ //#region src/event-types.d.ts
112
+ /**
113
+ * Raw event data from chain
114
+ */
115
+ interface RawContractEvent {
116
+ /** Block number where event was emitted */
117
+ blockNumber: number;
118
+ /** Block hash */
119
+ blockHash: string;
120
+ /** Event index in block */
121
+ eventIndex: number;
122
+ /** Contract address that emitted the event */
123
+ contractAddress: SS58String;
124
+ /** Event data (SCALE encoded) */
125
+ data: Uint8Array;
126
+ /** Event topics (indexed fields) */
127
+ topics: Uint8Array[];
128
+ }
129
+ /**
130
+ * Decoded contract event
131
+ */
132
+ interface DecodedContractEvent<T = unknown> {
133
+ /** Event label from metadata (e.g., "Transfer", "Approval") */
134
+ label: string;
135
+ /** Decoded event data */
136
+ data: T;
137
+ /** Original raw event */
138
+ raw: RawContractEvent;
139
+ }
140
+ /**
141
+ * Event filter options
142
+ */
143
+ interface EventFilterOptions {
144
+ /** Contract address to filter by */
145
+ contractAddress?: SS58String;
146
+ /** Event labels to include (e.g., ["Transfer", "Approval"]) */
147
+ eventLabels?: string[];
148
+ /** From block number (inclusive) */
149
+ fromBlock?: number;
150
+ /** To block number (inclusive) */
151
+ toBlock?: number;
152
+ }
153
+ /**
154
+ * Event subscription options
155
+ */
156
+ interface EventSubscriptionOptions {
157
+ /** Contract address to subscribe to */
158
+ contractAddress: SS58String;
159
+ /** Event labels to subscribe to (undefined = all events) */
160
+ eventLabels?: string[];
161
+ /** Include historical events from this block */
162
+ fromBlock?: number;
163
+ /**
164
+ * Function to fetch System.Events at a given block hash
165
+ * This is required because PolkadotClient doesn't expose typed API directly
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * const options = {
170
+ * contractAddress: usdtAddress,
171
+ * getEvents: async (blockHash) => {
172
+ * return await api.query.System.Events.getValue({ at: blockHash });
173
+ * }
174
+ * };
175
+ * ```
176
+ */
177
+ getEvents: (blockHash: string) => Promise<unknown[]>;
178
+ }
179
+ //#endregion
180
+ //#region src/types.d.ts
181
+ /**
182
+ * Decoder type for response decoding
183
+ */
184
+ type ResponseDecoder = {
185
+ dec: (data: Uint8Array) => unknown;
186
+ };
187
+ /**
188
+ * Query options for read operations (dry-run)
189
+ */
190
+ interface QueryOptions<Args = unknown> {
191
+ /** The origin account for the call */
192
+ origin: SS58String;
193
+ /** Arguments to pass to the contract message */
194
+ args?: Args;
195
+ /** Value to transfer with the call */
196
+ value?: bigint;
197
+ /** AbortSignal for cancellation */
198
+ signal?: AbortSignal;
199
+ /** Timeout in milliseconds */
200
+ timeout?: number;
201
+ /** Block hash to query at (default: finalized) */
202
+ at?: string;
203
+ }
204
+ /**
205
+ * Send options for write operations
206
+ */
207
+ interface SendOptions<Args = unknown> {
208
+ /** The origin account for the call */
209
+ origin: SS58String;
210
+ /** Arguments to pass to the contract message */
211
+ args?: Args;
212
+ /** Value to transfer with the call */
213
+ value?: bigint;
214
+ /** Gas limit (optional, will be estimated if not provided) */
215
+ gasLimit?: {
216
+ refTime: bigint;
217
+ proofSize: bigint;
218
+ };
219
+ /** Storage deposit limit */
220
+ storageDepositLimit?: bigint;
221
+ }
222
+ /**
223
+ * Sendable transaction that can be signed and submitted
224
+ */
225
+ interface SendableTransaction<T> {
226
+ /** Sign and submit the transaction */
227
+ signAndSubmit(signer: PolkadotSigner): Promise<TxResult<T>>;
228
+ /** Get the encoded call data */
229
+ getEncodedData(): Uint8Array;
230
+ }
231
+ /**
232
+ * Transaction result
233
+ */
234
+ interface TxResult<T> {
235
+ /** Whether the transaction was successful */
236
+ ok: boolean;
237
+ /** Transaction hash */
238
+ txHash: string;
239
+ /** Block information where tx was included */
240
+ block: {
241
+ hash: string;
242
+ number: number;
243
+ };
244
+ /** Decoded return value (if any) */
245
+ result?: T;
246
+ /** Events emitted by the transaction */
247
+ events: unknown[];
248
+ /** Dispatch error if failed */
249
+ dispatchError?: unknown;
250
+ }
251
+ /**
252
+ * Successful query result value
253
+ */
254
+ interface QuerySuccessValue<T> {
255
+ /** The decoded response from the contract */
256
+ value: T;
257
+ /** Events that would be emitted */
258
+ events: unknown[];
259
+ /** Gas consumed during dry-run */
260
+ gasConsumed: {
261
+ refTime: bigint;
262
+ proofSize: bigint;
263
+ };
264
+ /** Gas required for execution */
265
+ gasRequired: {
266
+ refTime: bigint;
267
+ proofSize: bigint;
268
+ };
269
+ /** Storage deposit required */
270
+ storageDeposit: bigint;
271
+ /** Create a sendable transaction from this query result */
272
+ send(): SendableTransaction<T>;
273
+ }
274
+ /**
275
+ * Query result - discriminated union for success/failure
276
+ * On success: QuerySuccessValue fields are spread to the same level as success
277
+ * On failure: error field contains the ContractError
278
+ */
279
+ type QueryResult<T> = ({
280
+ success: true;
281
+ } & QuerySuccessValue<T>) | {
282
+ success: false;
283
+ error: ContractError;
284
+ };
285
+ /**
286
+ * Storage query interface
287
+ */
288
+ interface ContractStorage {
289
+ /** Get the root storage value */
290
+ getRoot(): Promise<{
291
+ success: true;
292
+ value: unknown;
293
+ } | {
294
+ success: false;
295
+ value: ContractError;
296
+ }>;
297
+ /** Get a nested storage value by path */
298
+ getNested(path: string, ...keys: unknown[]): Promise<{
299
+ success: true;
300
+ value: unknown;
301
+ } | {
302
+ success: false;
303
+ value: ContractError;
304
+ }>;
305
+ }
306
+ /**
307
+ * Type helper to extract message args type
308
+ */
309
+ type MessageArgs<M$1 extends InkCallableDescriptor, K extends keyof M$1> = M$1[K]["message"];
310
+ /**
311
+ * ink! LangError type pattern
312
+ * papi generates LangError variants with { type: string; value?: unknown }
313
+ */
314
+ type InkLangError = {
315
+ type: string;
316
+ value?: unknown;
317
+ };
318
+ /**
319
+ * ink! MessageResult type pattern (Result<T, LangError>)
320
+ * papi generates this as { success: true; value: T } | { success: false; value: LangError }
321
+ */
322
+ type InkMessageResult<T> = {
323
+ success: true;
324
+ value: T;
325
+ } | {
326
+ success: false;
327
+ value: unknown;
328
+ };
329
+ /**
330
+ * Type helper to unwrap ink! MessageResult (Result<T, LangError>)
331
+ * 1. Extract T from { success: true; value: T } | { success: false; value: ... }
332
+ * 2. Exclude LangError variants from T
333
+ */
334
+ type UnwrapMessageResult<T> = T extends InkMessageResult<infer U> ? Exclude<U, InkLangError> : T;
335
+ /**
336
+ * Type helper to extract message response type (with MessageResult unwrapped)
337
+ */
338
+ type MessageResponse<M$1 extends InkCallableDescriptor, K extends keyof M$1> = UnwrapMessageResult<M$1[K]["response"]>;
339
+ /**
340
+ * D9 Ink Contract interface
341
+ */
342
+ interface D9InkContract<M$1 extends InkCallableDescriptor> {
343
+ /** Contract address */
344
+ readonly address: SS58String;
345
+ /** Contract metadata */
346
+ readonly metadata: InkMetadata;
347
+ /**
348
+ * Query a contract message (dry-run)
349
+ * @param method - The message label (e.g., "PSP22::balance_of")
350
+ * @param options - Query options including origin and args
351
+ */
352
+ query<K extends keyof M$1 & string>(method: K, options: QueryOptions<MessageArgs<M$1, K>>): Promise<QueryResult<MessageResponse<M$1, K>>>;
353
+ /**
354
+ * Create a sendable transaction for a contract message
355
+ * @param method - The message label (e.g., "PSP22::transfer")
356
+ * @param options - Send options including origin and args
357
+ */
358
+ send<K extends keyof M$1 & string>(method: K, options: SendOptions<MessageArgs<M$1, K>>): SendableTransaction<MessageResponse<M$1, K>>;
359
+ /**
360
+ * Get storage query interface
361
+ */
362
+ getStorage(): ContractStorage;
363
+ /**
364
+ * Filter events from a transaction result to only include this contract's events
365
+ */
366
+ filterEvents(events: unknown[]): DecodedContractEvent[];
367
+ /**
368
+ * Subscribe to contract events as an RxJS Observable
369
+ * @param options - Event subscription options (event labels to filter, etc.)
370
+ */
371
+ subscribeToEvents(options?: Omit<EventSubscriptionOptions, "contractAddress">): Observable<DecodedContractEvent>;
372
+ }
373
+ /**
374
+ * D9 Ink SDK options
375
+ */
376
+ interface D9InkSdkOptions {
377
+ /** Default query options */
378
+ defaultQueryOptions?: Partial<QueryOptions>;
379
+ /** Default send options */
380
+ defaultSendOptions?: Partial<SendOptions>;
381
+ }
382
+ /**
383
+ * D9 Ink SDK interface
384
+ */
385
+ interface D9InkSdk {
386
+ /**
387
+ * Get a contract instance for interacting with a deployed contract
388
+ * @param descriptor - The contract descriptor from @polkadot-api/descriptors
389
+ * @param address - The contract address (SS58 format)
390
+ */
391
+ getContract<S extends InkStorageDescriptor, M$1 extends InkCallableDescriptor, C extends InkCallableDescriptor, E extends Event>(descriptor: InkDescriptors<S, M$1, C, E>, address: SS58String): D9InkContract<M$1>;
392
+ }
393
+ type D9InkContractFromDescriptor<D> = D extends InkDescriptors<infer _S, infer M, infer _C, infer _E> ? D9InkContract<M> : never;
394
+ /**
395
+ * Internal options for contract creation
396
+ */
397
+ interface CreateContractOptions {
398
+ client: PolkadotClient;
399
+ typedApi?: unknown;
400
+ defaultQueryOptions?: Partial<QueryOptions>;
401
+ defaultSendOptions?: Partial<SendOptions>;
402
+ }
403
+ /**
404
+ * Type helper to infer the Messages type from an InkDescriptors
405
+ */
406
+ type InferMessages<D> = D extends InkDescriptors<InkStorageDescriptor, infer M, InkCallableDescriptor, Event> ? M : never;
407
+ //#endregion
408
+ //#region src/sdk.d.ts
409
+ /**
410
+ * Options for creating D9 Ink SDK
411
+ */
412
+ interface CreateD9InkSdkOptions extends D9InkSdkOptions {
413
+ /**
414
+ * Typed API for transaction submission.
415
+ * Required for submitting real transactions.
416
+ */
417
+ typedApi?: unknown;
418
+ }
419
+ /**
420
+ * Create a D9 Ink SDK instance.
421
+ *
422
+ * This SDK provides a similar API to the official @polkadot-api/sdk-ink,
423
+ * but uses state_call + ContractsApi_call instead of ReviveApi.
424
+ *
425
+ * @example
426
+ * ```ts
427
+ * import { createD9InkSdk } from "@d9-network/ink";
428
+ * import { contracts } from "@polkadot-api/descriptors";
429
+ *
430
+ * const sdk = createD9InkSdk(client);
431
+ * const usdtContract = sdk.getContract(
432
+ * contracts.d9_usdt,
433
+ * "uLj9DRUujbpCyK7USZY5ebGbxdtKoWvdRvGyyUsoLWDsNng"
434
+ * );
435
+ *
436
+ * // Query balance
437
+ * const result = await usdtContract.query("PSP22::balance_of", {
438
+ * origin: aliceAddress,
439
+ * args: { owner: aliceAddress }
440
+ * });
441
+ *
442
+ * if (result.success) {
443
+ * console.log("Balance:", result.value.response);
444
+ *
445
+ * // Send transaction from the query result
446
+ * const txResult = await result.value.send().signAndSubmit(aliceSigner);
447
+ * }
448
+ *
449
+ * // Or send directly
450
+ * const txResult = await usdtContract
451
+ * .send("PSP22::transfer", {
452
+ * origin: aliceAddress,
453
+ * args: { to: bobAddress, value: 1000n, data: [] }
454
+ * })
455
+ * .signAndSubmit(aliceSigner);
456
+ * ```
457
+ *
458
+ * @param client - The PolkadotClient instance
459
+ * @param options - Optional SDK configuration
460
+ * @returns D9 Ink SDK instance
461
+ */
462
+ declare function createD9InkSdk(client: PolkadotClient, options?: CreateD9InkSdkOptions): D9InkSdk;
463
+ //#endregion
464
+ //#region src/contract.d.ts
465
+ /**
466
+ * Create a D9 Ink Contract instance
467
+ */
468
+ declare function createD9InkContract<S extends InkStorageDescriptor, M$1 extends InkCallableDescriptor, C extends InkCallableDescriptor, E extends Event>(descriptor: InkDescriptors<S, M$1, C, E>, address: SS58String, options: CreateContractOptions): D9InkContract<M$1>;
469
+ //#endregion
470
+ //#region src/encode.d.ts
471
+ /**
472
+ * Encode a contract call for ContractsApi_call state_call.
473
+ *
474
+ * The encoded format matches the ContractsApi::call runtime API:
475
+ * - origin: AccountId (32 bytes)
476
+ * - dest: AccountId (32 bytes)
477
+ * - value: Balance (u128)
478
+ * - gas_limit: Option<Weight> (1 byte for None)
479
+ * - storage_deposit_limit: Option<Balance> (1 byte for None)
480
+ * - input_data: Vec<u8> (compact length + bytes)
481
+ *
482
+ * @param origin - The origin account (as Uint8Array or hex string)
483
+ * @param dest - The contract address (as Uint8Array or hex string)
484
+ * @param input - The encoded call data (selector + arguments)
485
+ * @param value - Optional value to transfer (default: 0)
486
+ * @returns Hex-encoded bytes for state_call
487
+ */
488
+ declare function encodeContractCall(origin: Uint8Array | string, dest: Uint8Array | string, input: Binary | Uint8Array, value?: bigint): Bytes;
489
+ /**
490
+ * Encode a contract call using the same address for origin and dest.
491
+ * This is a simplified version for query operations where the origin
492
+ * doesn't matter much.
493
+ *
494
+ * @param address - The contract address
495
+ * @param input - The encoded call data
496
+ * @param value - Optional value to transfer
497
+ * @returns Hex-encoded bytes for state_call
498
+ */
499
+ declare function encodeCall(address: Uint8Array | string, input: Binary | Uint8Array, value?: bigint): Bytes;
500
+ /**
501
+ * Encode a contract call with specific gas limit and storage deposit limit.
502
+ *
503
+ * @param origin - The origin account
504
+ * @param dest - The contract address
505
+ * @param input - The encoded call data
506
+ * @param options - Call options including value, gas limit, storage deposit limit
507
+ * @returns Hex-encoded bytes for state_call
508
+ */
509
+ declare function encodeContractCallWithLimits(origin: Uint8Array | string, dest: Uint8Array | string, input: Binary | Uint8Array, options?: {
510
+ value?: bigint;
511
+ gasLimit?: {
512
+ refTime: bigint;
513
+ proofSize: bigint;
514
+ };
515
+ storageDepositLimit?: bigint;
516
+ }): Bytes;
517
+ //#endregion
518
+ //#region src/decode.d.ts
519
+ /**
520
+ * Gas information from contract execution
521
+ */
522
+ interface GasInfo {
523
+ /** Gas consumed during execution */
524
+ gasConsumed: {
525
+ refTime: bigint;
526
+ proofSize: bigint;
527
+ };
528
+ /** Gas required for execution */
529
+ gasRequired: {
530
+ refTime: bigint;
531
+ proofSize: bigint;
532
+ };
533
+ }
534
+ /**
535
+ * Storage deposit information
536
+ */
537
+ interface StorageDepositInfo {
538
+ /** Storage deposit type: 0 = Refund, 1 = Charge */
539
+ type: "Refund" | "Charge";
540
+ /** Amount of storage deposit */
541
+ amount: bigint;
542
+ }
543
+ /**
544
+ * Full decoded result from ContractsApi_call
545
+ */
546
+ interface ContractCallResult {
547
+ /** Gas information */
548
+ gas: GasInfo;
549
+ /** Storage deposit information */
550
+ storageDeposit: StorageDepositInfo;
551
+ /** Debug message (if any) */
552
+ debugMessage: string;
553
+ /** Whether the execution was successful */
554
+ success: boolean;
555
+ /** Execution flags */
556
+ flags: number;
557
+ /** The raw execution result bytes (still wrapped in Result<T, LangError>) */
558
+ data: Uint8Array;
559
+ }
560
+ /**
561
+ * Decode the raw ContractsApi_call response.
562
+ *
563
+ * The response format is:
564
+ * - gasConsumed: Weight { ref_time: Compact<u64>, proof_size: Compact<u64> }
565
+ * - gasRequired: Weight
566
+ * - storageDeposit: StorageDeposit { variant: u8, amount: u128 }
567
+ * - debugMessage: String
568
+ * - result: Result<ExecReturnValue, DispatchError>
569
+ * - ExecReturnValue: { flags: u32, data: Vec<u8> }
570
+ *
571
+ * @param result - The raw response bytes from state_call ContractsApi_call
572
+ * @returns Decoded contract call result
573
+ */
574
+ declare function decodeContractCallResult(result: Uint8Array): ContractCallResult;
575
+ /**
576
+ * Legacy function - decode and return just the exec result data.
577
+ * @deprecated Use decodeContractCallResult for full information
578
+ */
579
+ declare function decodeResult(result: Uint8Array): Uint8Array;
580
+ /**
581
+ * Unwrap the inner value from Result<T, LangError> by checking the variant byte.
582
+ *
583
+ * Ink contracts wrap their return values in Result<T, LangError>.
584
+ * This function handles the unwrapping and throws an error for LangError.
585
+ *
586
+ * @param data - The exec result bytes (Result<T, LangError> encoded)
587
+ * @returns The inner value bytes (T encoded)
588
+ * @throws Error if the result is Err variant (LangError)
589
+ */
590
+ declare function unwrapInkResult(data: Uint8Array): Uint8Array;
591
+ /**
592
+ * Check if the result indicates a LangError
593
+ *
594
+ * @param data - The exec result bytes
595
+ * @returns True if it's a LangError (Err variant)
596
+ */
597
+ declare function isLangError(data: Uint8Array): boolean;
598
+ /**
599
+ * Decode ink contract message result using a custom SCALE codec.
600
+ * This bypasses polkadot-api's ink decoder which has issues with LangError type.
601
+ *
602
+ * @param data - The exec result bytes (Result<T, LangError> encoded)
603
+ * @param codec - The SCALE codec for the inner value type T
604
+ * @returns The decoded value
605
+ */
606
+ declare function decodeInkValue<T>(data: Uint8Array, codec: Codec<T>): T;
607
+ /**
608
+ * Pre-defined codecs for common types
609
+ */
610
+ declare const InkCodecs: {
611
+ /** u128 codec for Balance type */
612
+ u128: Codec<bigint>;
613
+ /** Tuple of two u128 values, commonly used for (Balance, Balance) */
614
+ balancePair: [_polkadot_api_substrate_bindings0.Encoder<[bigint, bigint]>, _polkadot_api_substrate_bindings0.Decoder<[bigint, bigint]>] & {
615
+ enc: _polkadot_api_substrate_bindings0.Encoder<[bigint, bigint]>;
616
+ dec: _polkadot_api_substrate_bindings0.Decoder<[bigint, bigint]>;
617
+ } & {
618
+ inner: [Codec<bigint>, Codec<bigint>];
619
+ };
620
+ };
621
+ //#endregion
622
+ //#region src/codec-builder.d.ts
623
+ /**
624
+ * Build a decoder for a message's return type from ink metadata.
625
+ * This handles the Result<T, LangError> wrapper and returns a decoder for T.
626
+ *
627
+ * @param metadata - The ink contract metadata
628
+ * @param messageLabel - The message label (e.g., "PSP22::balance_of")
629
+ * @returns A decoder function that decodes the inner value bytes
630
+ */
631
+ declare function buildMessageDecoder(metadata: InkMetadata, messageLabel: string): (data: Uint8Array) => unknown;
632
+ /**
633
+ * Build decoders for all messages in the metadata.
634
+ * Returns a Map of message label -> decoder function.
635
+ */
636
+ declare function buildAllMessageDecoders(metadata: InkMetadata): Map<string, (data: Uint8Array) => unknown>;
637
+ /**
638
+ * Create a codec registry compatible with ResponseDecoder type
639
+ */
640
+ declare function createCodecRegistry(metadata: InkMetadata): Map<string, {
641
+ dec: (data: Uint8Array) => unknown;
642
+ }>;
643
+ /**
644
+ * Build a SCALE decoder for a contract event from ink metadata
645
+ *
646
+ * @param metadata - The ink contract metadata
647
+ * @param eventLabel - The event label (e.g., "Transfer", "Approval")
648
+ * @returns A decoder function that decodes the event data bytes
649
+ */
650
+ declare function buildEventDecoder(metadata: InkMetadata, eventLabel: string): (data: Uint8Array) => unknown;
651
+ /**
652
+ * Build decoders for all events in the metadata
653
+ *
654
+ * @param metadata - The ink contract metadata
655
+ * @returns Map of event label -> decoder function
656
+ */
657
+ declare function buildAllEventDecoders(metadata: InkMetadata): Map<string, (data: Uint8Array) => unknown>;
658
+ /**
659
+ * Get event signature (topic[0]) for filtering
660
+ * Events in ink! use blake2_256 hash of event label as topic[0]
661
+ *
662
+ * @param eventLabel - The event label (e.g., "Transfer")
663
+ * @returns Event signature as Uint8Array (32 bytes)
664
+ */
665
+ declare function getEventSignature(eventLabel: string): Uint8Array;
666
+ //#endregion
667
+ //#region src/events.d.ts
668
+ /**
669
+ * Event parser for a specific contract
670
+ */
671
+ declare class ContractEventParser {
672
+ private eventDecoders;
673
+ private eventSignatures;
674
+ private contractAddressBytes;
675
+ private contractAddress;
676
+ private metadata;
677
+ constructor(metadata: InkMetadata, contractAddress: SS58String);
678
+ /**
679
+ * Parse a raw chain event into a contract event (if it matches)
680
+ * Returns null if the event is not from this contract or cannot be parsed
681
+ */
682
+ parseEvent(chainEvent: unknown): DecodedContractEvent | null;
683
+ /**
684
+ * Filter a batch of events
685
+ */
686
+ filterEvents(chainEvents: unknown[], options?: EventFilterOptions): DecodedContractEvent[];
687
+ /**
688
+ * Get the contract address as SS58 string
689
+ */
690
+ private getContractAddress;
691
+ /**
692
+ * Extract ContractEmitted event from chain event structure
693
+ * Based on polkadot-api event format
694
+ */
695
+ private extractContractEmittedEvent;
696
+ /**
697
+ * Compare two Uint8Arrays for equality
698
+ */
699
+ private bytesEqual;
700
+ /**
701
+ * Build event signature map from metadata
702
+ */
703
+ private static buildEventSignatureMap;
704
+ }
705
+ //#endregion
706
+ //#region src/subscriptions.d.ts
707
+ /**
708
+ * Create an observable stream of contract events
709
+ *
710
+ * @param client - Polkadot API client
711
+ * @param metadata - Contract metadata
712
+ * @param options - Subscription options
713
+ * @returns Observable stream of decoded contract events
714
+ */
715
+ declare function createContractEventStream(client: PolkadotClient, metadata: InkMetadata, options: EventSubscriptionOptions): Observable<DecodedContractEvent>;
716
+ /**
717
+ * Convenience helper to create a Transfer event stream for PSP22 tokens
718
+ *
719
+ * @param client - Polkadot API client
720
+ * @param metadata - PSP22 contract metadata
721
+ * @param contractAddress - PSP22 contract address
722
+ * @param getEvents - Function to fetch System.Events at a block hash
723
+ * @param watchAddress - Optional address to filter transfers (only events involving this address)
724
+ * @returns Observable stream of Transfer events
725
+ */
726
+ declare function createPSP22TransferStream(client: PolkadotClient, metadata: InkMetadata, contractAddress: SS58String, getEvents: (blockHash: string) => Promise<unknown[]>, watchAddress?: SS58String): Observable<DecodedContractEvent<{
727
+ from?: SS58String | null;
728
+ to?: SS58String | null;
729
+ value: bigint;
730
+ }>>;
731
+ /**
732
+ * Create a native token (D9) transfer event stream
733
+ *
734
+ * This monitors System.Transfer events instead of contract events
735
+ *
736
+ * @param client - Polkadot API client
737
+ * @param getEvents - Function to fetch System.Events at a block hash
738
+ * @param watchAddress - Address to monitor for transfers
739
+ * @returns Observable stream of native transfer events
740
+ */
741
+ declare function createNativeTransferStream(client: PolkadotClient, getEvents: (blockHash: string) => Promise<unknown[]>, watchAddress: SS58String): Observable<{
742
+ from: SS58String;
743
+ to: SS58String;
744
+ amount: bigint;
745
+ blockNumber: number;
746
+ blockHash: string;
747
+ }>;
748
+ //#endregion
749
+ export { AbortedError, type ContractCallResult, ContractError, type ContractErrorType, ContractEventParser, ContractExecutionError, type ContractStorage, type CreateContractOptions, type CreateD9InkSdkOptions, type D9InkContract, type D9InkContractFromDescriptor, type D9InkSdk, type D9InkSdkOptions, DecodeError, type DecodedContractEvent, EncodeError, type EventFilterOptions, type EventSubscriptionOptions, type GasInfo, type InferMessages, InkCodecs, LangError, MetadataError, NetworkError, type QueryOptions, type QueryResult, type QuerySuccessValue, type RawContractEvent, type ResponseDecoder, type SendOptions, type SendableTransaction, SignerError, type StorageDepositInfo, TimeoutError, TransactionError, type TxResult, buildAllEventDecoders, buildAllMessageDecoders, buildEventDecoder, buildMessageDecoder, createCodecRegistry, createContractEventStream, createD9InkContract, createD9InkSdk, createNativeTransferStream, createPSP22TransferStream, decodeContractCallResult, decodeInkValue, decodeResult, encodeCall, encodeContractCall, encodeContractCallWithLimits, getEventSignature, isContractError, isErrorType, isLangError, unwrapInkResult };
750
+ //# sourceMappingURL=index.d.mts.map