@omnity/ree-client-ts-sdk 0.1.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,565 @@
1
+ import { ActorSubclass } from '@dfinity/agent';
2
+ import * as bitcoin from 'bitcoinjs-lib';
3
+ import { IDL } from '@dfinity/candid';
4
+ import { JSX as JSX_2 } from 'react/jsx-runtime';
5
+ import { ReactNode } from 'react';
6
+
7
+ export declare const AddressType: {
8
+ P2PKH: {
9
+ P2PKH: null;
10
+ };
11
+ P2SH_P2WPKH: {
12
+ P2SH_P2WPKH: null;
13
+ };
14
+ P2WPKH: {
15
+ P2WPKH: null;
16
+ };
17
+ P2WSH: {
18
+ P2WSH: null;
19
+ };
20
+ P2SH: {
21
+ P2SH: null;
22
+ };
23
+ P2TR: {
24
+ P2TR: null;
25
+ };
26
+ UNKNOWN: {
27
+ UNKNOWN: null;
28
+ };
29
+ };
30
+
31
+ export declare type AddressType = (typeof AddressType)[keyof typeof AddressType] | {
32
+ OpReturn: bigint;
33
+ };
34
+
35
+ declare function bytesToHex(bytes: Uint8Array): string;
36
+
37
+ declare type CoinBalance = {
38
+ id: string;
39
+ value: bigint;
40
+ };
41
+
42
+ export declare type Config = {
43
+ network: Network;
44
+ maestroApiKey: string;
45
+ exchangeIdlFactory: IDL.InterfaceFactory;
46
+ exchangeId: string;
47
+ exchangeCanisterId: string;
48
+ };
49
+
50
+ declare function getAddressType(address: string): AddressType;
51
+
52
+ declare function getScriptByAddress(address: string, network?: Network): Buffer<ArrayBufferLike>;
53
+
54
+ declare function hexToBytes(hex: string): Uint8Array;
55
+
56
+ declare type InputCoin = {
57
+ coin: CoinBalance;
58
+ from: string;
59
+ };
60
+
61
+ export declare type Intention = {
62
+ input_coins: InputCoin[];
63
+ output_coins: OutputCoin[];
64
+ action: string;
65
+ exchange_id: string;
66
+ action_params: string;
67
+ pool_utxo_spent: string[];
68
+ nonce: bigint;
69
+ pool_utxo_received: string[];
70
+ pool_address: string;
71
+ };
72
+
73
+ export declare type IntentionSet = {
74
+ tx_fee_in_sats: bigint;
75
+ initiator_address: string;
76
+ intentions: Intention[];
77
+ };
78
+
79
+ declare class Maestro {
80
+ private axios;
81
+ constructor(params: {
82
+ baseUrl: string;
83
+ apiKey: string;
84
+ });
85
+ utxosByAddress(address: string, cursor?: string | null): Promise<{
86
+ next_cursor: string | null;
87
+ last_updated: {
88
+ block_hash: string;
89
+ block_height: bigint;
90
+ };
91
+ data: RawBtcUtxo[];
92
+ }>;
93
+ inscriptionsByAddress(address: string, cursor?: string | null): Promise<{
94
+ next_cursor: string | null;
95
+ last_updated: {
96
+ block_hash: string;
97
+ block_height: bigint;
98
+ };
99
+ data: RawInscription[];
100
+ }>;
101
+ inscriptionIdsByCollectionSymbol(collection: string, cursor?: string | null): Promise<{
102
+ next_cursor: string | null;
103
+ last_updated: {
104
+ block_hash: string;
105
+ block_height: bigint;
106
+ };
107
+ data: string[];
108
+ }>;
109
+ runeUtxosByAddress(address: string, rune: string, cursor?: string | null): Promise<{
110
+ next_cursor: string | null;
111
+ last_updated: {
112
+ block_hash: string;
113
+ block_height: bigint;
114
+ };
115
+ data: RawRuneUtxo[];
116
+ }>;
117
+ }
118
+
119
+ export declare const Network: {
120
+ readonly Mainnet: "mainnet";
121
+ readonly Testnet: "testnet";
122
+ };
123
+
124
+ export declare type Network = (typeof Network)[keyof typeof Network];
125
+
126
+ declare type OutputCoin = {
127
+ coin: CoinBalance;
128
+ to: string;
129
+ };
130
+
131
+ export declare type Pool = {
132
+ name: string;
133
+ address: string;
134
+ };
135
+
136
+ export declare type PoolInfo = {
137
+ address: string;
138
+ attributes: string;
139
+ btc_reserved: bigint;
140
+ coin_reserved: {
141
+ id: string;
142
+ value: bigint;
143
+ }[];
144
+ key: string;
145
+ name: string;
146
+ nonce: bigint;
147
+ utxos: {
148
+ coins: {
149
+ id: string;
150
+ value: bigint;
151
+ }[];
152
+ sats: bigint;
153
+ txid: string;
154
+ vout: number;
155
+ }[];
156
+ };
157
+
158
+ declare type RawBtcUtxo = {
159
+ txid: string;
160
+ vout: number;
161
+ script_pubkey: string;
162
+ satoshis: string;
163
+ confirmations: bigint;
164
+ height: bigint;
165
+ runes: {
166
+ rune_id: string;
167
+ amount: string;
168
+ }[];
169
+ inscriptions: {
170
+ offset: bigint;
171
+ inscription_id: string;
172
+ }[];
173
+ address: string;
174
+ };
175
+
176
+ declare type RawInscription = {
177
+ inscription_id: string;
178
+ satoshis: string;
179
+ utxo_sat_offset: bigint;
180
+ utxo_txid: string;
181
+ utxo_vout: number;
182
+ utxo_block_height: number;
183
+ utxo_confirmations: string;
184
+ };
185
+
186
+ declare type RawRuneUtxo = {
187
+ txid: string;
188
+ vout: number;
189
+ satoshis: string;
190
+ confirmations: bigint;
191
+ height: bigint;
192
+ runes: {
193
+ rune_id: string;
194
+ amount: string;
195
+ }[];
196
+ };
197
+
198
+ /**
199
+ * Main client for interacting with the Ree protocol
200
+ * Provides methods for Bitcoin UTXO management, Rune operations, and transaction creation
201
+ */
202
+ export declare class ReeClient {
203
+ /** Maestro API client for Bitcoin data */
204
+ readonly maestro: Maestro;
205
+ /** Configuration object */
206
+ readonly config: Config;
207
+ /** Exchange canister actor for pool operations */
208
+ readonly exchange: ActorSubclass;
209
+ /** Orchestrator canister actor for transaction processing */
210
+ readonly orchestrator: ActorSubclass;
211
+ /**
212
+ * Initialize ReeClient with wallet addresses and configuration
213
+ * @param config - Client configuration including network and API keys
214
+ */
215
+ constructor(config: Config);
216
+ /**
217
+ * Filter out UTXOs that have already been spent or are being used in pending transactions
218
+ * Queries the orchestrator to get a list of used outpoints and removes them from the UTXO set
219
+ * @param address - The Bitcoin (or Ordinals) address to check used outpoints for
220
+ * @param utxos - Array of UTXOs to filter
221
+ * @returns Filtered array of UTXOs excluding spent/used ones
222
+ */
223
+ private filterSpentUtxos;
224
+ /**
225
+ * Get all Bitcoin UTXOs for the payment address
226
+ * Handles pagination automatically to fetch all available UTXOs
227
+ * @returns Array of Bitcoin UTXOs
228
+ */
229
+ getBtcUtxos(paymentAddress: string): Promise<Utxo[]>;
230
+ /**
231
+ * Get UTXOs containing a specific rune for the user's address
232
+ * @param runeId - The rune ID to filter UTXOs by
233
+ * @returns Array of UTXOs containing the specified rune
234
+ */
235
+ getRuneUtxos(address: string, runeId: string): Promise<Utxo[]>;
236
+ /**
237
+ * Search for runes by keyword or rune ID
238
+ * Supports both exact rune ID matches and fuzzy name matching
239
+ * @param keyword - Search term (rune ID or partial name)
240
+ * @returns Array of matching rune information
241
+ */
242
+ searchRunes(keyword: string): Promise<RuneInfo[]>;
243
+ /**
244
+ * Get detailed information for a specific rune by ID
245
+ * @param runeId - The rune ID to look up
246
+ * @returns Rune information or undefined if not found
247
+ */
248
+ getRuneInfo(runeId: string): Promise<RuneInfo | undefined>;
249
+ /**
250
+ * Get total Bitcoin balance from all UTXOs
251
+ * @returns Total balance in satoshis
252
+ */
253
+ getBtcBalance(paymentAddress: string): Promise<number>;
254
+ /**
255
+ * Get the balance of a specific rune for the user's address
256
+ * Calculates total rune amount across all UTXOs and applies divisibility
257
+ * @param runeId - The rune ID to get balance for (format: "block:index")
258
+ * @returns Rune balance as a number, or undefined if rune not found
259
+ */
260
+ getRuneBalance(address: string, runeId: string): Promise<number | undefined>;
261
+ /**
262
+ * Get list of all available liquidity pools
263
+ * @returns Array of pool information
264
+ */
265
+ getPoolList(): Promise<Pool[]>;
266
+ /**
267
+ * Get detailed information about a specific liquidity pool
268
+ * @param poolAddress - The pool's Bitcoin address
269
+ * @returns Pool information including UTXOs and balances
270
+ * @throws Error if pool is not found
271
+ */
272
+ getPoolInfo(poolAddress: string): Promise<PoolInfo>;
273
+ /**
274
+ * Create a transaction for trading with a liquidity pool
275
+ * Supports both BTC-only and BTC-Rune swaps
276
+ * @param params - Transaction parameters
277
+ * @param params.runeId - Optional rune ID for rune swaps
278
+ * @param params.poolAddress - Target pool address
279
+ * @param params.sendBtcAmount - BTC amount to send
280
+ * @param params.sendRuneAmount - Rune amount to send (0 for BTC-only)
281
+ * @param params.receiveBtcAmount - Expected BTC to receive
282
+ * @param params.receiveRuneAmount - Expected rune amount to receive
283
+ * @returns Transaction builder instance
284
+ */
285
+ createTransaction({ address, paymentAddress, runeId, poolAddress, sendBtcAmount, sendRuneAmount, receiveBtcAmount, receiveRuneAmount, }: {
286
+ runeId?: string;
287
+ address: string;
288
+ paymentAddress: string;
289
+ poolAddress: string;
290
+ sendBtcAmount: bigint;
291
+ sendRuneAmount: bigint;
292
+ receiveBtcAmount: bigint;
293
+ receiveRuneAmount: bigint;
294
+ }): Promise<Transaction>;
295
+ }
296
+
297
+ declare interface ReeContextValue {
298
+ client: ReeClient;
299
+ exchange: ActorSubclass;
300
+ address: string;
301
+ paymentAddress: string;
302
+ updateWallet: (wallet: {
303
+ address?: string;
304
+ paymentAddress?: string;
305
+ }) => void;
306
+ createTransaction: (params: {
307
+ runeId?: string;
308
+ poolAddress: string;
309
+ sendBtcAmount: bigint;
310
+ sendRuneAmount: bigint;
311
+ receiveBtcAmount: bigint;
312
+ receiveRuneAmount: bigint;
313
+ }) => Promise<Transaction>;
314
+ }
315
+
316
+ export declare function ReeProvider({ children, config }: ReeProviderProps): JSX_2.Element;
317
+
318
+ declare interface ReeProviderProps {
319
+ children: ReactNode;
320
+ config: Config;
321
+ }
322
+
323
+ export declare interface RuneInfo {
324
+ runeId: string;
325
+ spacedRune: string;
326
+ symbol: string;
327
+ divisibility: number;
328
+ etching: string;
329
+ }
330
+
331
+ declare function toBitcoinNetwork(network: Network): bitcoin.networks.Network;
332
+
333
+ /**
334
+ * Transaction builder for Bitcoin and Rune transactions
335
+ * Handles PSBT creation, UTXO selection, and fee calculation
336
+ */
337
+ export declare class Transaction {
338
+ private psbt;
339
+ private inputAddressTypes;
340
+ private outputAddressTypes;
341
+ private config;
342
+ /** Track dust amounts from user input UTXOs for fee calculation */
343
+ private userInputUtxoDusts;
344
+ /** Orchestrator actor for fee estimation */
345
+ readonly orchestrator: ActorSubclass;
346
+ private intentionSet;
347
+ constructor(config: TransactionConfig, orchestrator: ActorSubclass);
348
+ /**
349
+ * Add a UTXO as transaction input
350
+ * @param utxo - The UTXO to add as input
351
+ */
352
+ private addInput;
353
+ /**
354
+ * Add a standard output to the transaction
355
+ * @param address - Recipient address
356
+ * @param amount - Amount in satoshis
357
+ */
358
+ private addOutput;
359
+ /**
360
+ * Add an OP_RETURN script output (for Runestone)
361
+ * @param script - The script buffer to include
362
+ */
363
+ private addScriptOutput;
364
+ /**
365
+ * Select UTXOs containing specific runes for the transaction
366
+ * @param runeUtxos - Available rune UTXOs
367
+ * @param runeId - Target rune ID
368
+ * @param runeAmount - Required rune amount
369
+ * @returns Selected UTXOs that contain the required runes
370
+ */
371
+ private selectRuneUtxos;
372
+ /**
373
+ * Select BTC UTXOs for the transaction
374
+ * @param btcUtxos - Available BTC UTXOs
375
+ * @param btcAmount - Required BTC amount in satoshis
376
+ * @returns Selected UTXOs that contain enough BTC
377
+ */
378
+ private selectBtcUtxos;
379
+ /**
380
+ * Calculate rune change amount and determine if change is needed
381
+ * @param runeId - The rune ID to calculate change for
382
+ * @param runeUtxos - UTXOs containing the runes
383
+ * @param runeAmount - Amount being sent
384
+ * @returns Change calculation result
385
+ */
386
+ private caclulateRuneChangeAmount;
387
+ /**
388
+ * Add rune-related outputs to the transaction
389
+ * @param runeIdStr - Rune ID string (block:index format)
390
+ * @param runeUtxos - UTXOs containing the runes
391
+ * @param runeAmount - Amount of runes to transfer
392
+ * @param receiveAddress - Address to receive the runes
393
+ * @returns Information about whether change output is needed
394
+ */
395
+ private addRuneOutputs;
396
+ /**
397
+ * Add BTC outputs and calculate transaction fees
398
+ * @param btcUtxos - Available BTC UTXOs
399
+ * @param btcAmount - Required BTC amount
400
+ * @param paymentAddress - Address for change output
401
+ * @param additionalDustNeeded - Additional dust needed for rune outputs
402
+ * @returns Fee calculation result
403
+ */
404
+ private addBtcAndFees;
405
+ /**
406
+ * Build the complete transaction
407
+ * Handles both BTC-only and Rune transactions
408
+ * @returns Built PSBT and total fee
409
+ */
410
+ build(action: string, nonce: bigint, actionParams?: string): Promise<bitcoin.Psbt>;
411
+ /**
412
+ * Submit the signed transaction to the orchestrator for execution
413
+ * This method sends the signed PSBT along with the intention set to the orchestrator canister
414
+ *
415
+ * @param signedPsbtHex - The signed PSBT in hexadecimal format from the user's wallet
416
+ * @returns Promise that resolves to the orchestrator's response on success
417
+ * @throws Error if intention set is not available or if the orchestrator returns an error
418
+ *
419
+ * @example
420
+ * ```typescript
421
+ * // After building and signing the transaction
422
+ * const signedPsbt = await wallet.signPsbt(psbt);
423
+ * const result = await transaction.send(signedPsbt.toHex());
424
+ * ```
425
+ */
426
+ send(signedPsbtHex: string): Promise<any>;
427
+ }
428
+
429
+ export declare interface TransactionConfig {
430
+ network: Network;
431
+ exchangeId: string;
432
+ address: string;
433
+ paymentAddress: string;
434
+ poolAddress: string;
435
+ runeId?: string;
436
+ runeUtxos?: Utxo[];
437
+ btcUtxos: Utxo[];
438
+ poolUtxos: Utxo[];
439
+ sendBtcAmount: bigint;
440
+ sendRuneAmount: bigint;
441
+ receiveBtcAmount: bigint;
442
+ receiveRuneAmount: bigint;
443
+ }
444
+
445
+ declare interface UseBalanceOptions {
446
+ /** Auto-refresh interval in milliseconds (0 to disable) */
447
+ refreshInterval?: number;
448
+ /** Enable automatic refresh when wallet changes */
449
+ autoRefresh?: boolean;
450
+ }
451
+
452
+ /**
453
+ * Hook to get and manage Bitcoin balance
454
+ * @returns Object with balance, loading state, error, and refresh function
455
+ */
456
+ export declare function useBtcBalance(options?: UseBalanceOptions): {
457
+ balance: number | null;
458
+ loading: boolean;
459
+ error: string | null;
460
+ refetch: () => Promise<void>;
461
+ };
462
+
463
+ /**
464
+ * Hook to get and manage Bitcoin UTXOs
465
+ * @returns Object with UTXOs, loading state, error, and refresh function
466
+ */
467
+ export declare function useBtcUtxos(options?: UseBalanceOptions): {
468
+ utxos: Utxo[];
469
+ loading: boolean;
470
+ error: string | null;
471
+ refetch: () => Promise<void>;
472
+ };
473
+
474
+ /**
475
+ * Hook to get pool information by address
476
+ * @param poolAddress - The pool address to get info for
477
+ * @returns Object with pool info, loading state, error, and refetch function
478
+ */
479
+ export declare function usePoolInfo(poolAddress?: string): {
480
+ poolInfo: PoolInfo | null;
481
+ loading: boolean;
482
+ error: string | null;
483
+ refetch: () => Promise<void>;
484
+ };
485
+
486
+ /**
487
+ * Hook to get list of all pools
488
+ * @returns Object with pools, loading state, error, and refetch function
489
+ */
490
+ export declare function usePoolList(): {
491
+ pools: Pool[];
492
+ loading: boolean;
493
+ error: string | null;
494
+ refetch: () => Promise<void>;
495
+ };
496
+
497
+ export declare function useRee(): ReeContextValue;
498
+
499
+ /**
500
+ * Hook to get and manage Rune balance for a specific rune
501
+ * @param runeId - The rune ID to get balance for
502
+ * @returns Object with balance, loading state, error, and refresh function
503
+ */
504
+ export declare function useRuneBalance(runeId: string | undefined, options?: UseBalanceOptions): {
505
+ balance: number | null;
506
+ loading: boolean;
507
+ error: string | null;
508
+ refetch: () => Promise<void>;
509
+ };
510
+
511
+ /**
512
+ * Hook to get rune information by ID
513
+ * @param runeId - The rune ID to get info for
514
+ * @returns Object with rune info, loading state, error, and refetch function
515
+ */
516
+ export declare function useRuneInfo(runeId?: string): {
517
+ runeInfo: RuneInfo | null;
518
+ loading: boolean;
519
+ error: string | null;
520
+ refetch: () => Promise<void>;
521
+ };
522
+
523
+ /**
524
+ * Hook to get and manage Rune UTXOs for a specific rune
525
+ * @param runeId - The rune ID to get UTXOs for
526
+ * @returns Object with UTXOs, loading state, error, and refresh function
527
+ */
528
+ export declare function useRuneUtxos(runeId: string, options?: UseBalanceOptions): {
529
+ utxos: Utxo[];
530
+ loading: boolean;
531
+ error: string | null;
532
+ refetch: () => Promise<void>;
533
+ };
534
+
535
+ /**
536
+ * Hook to search for runes by keyword
537
+ * @param keyword - Search term (rune ID or partial name)
538
+ * @returns Object with runes, loading state, error, and search function
539
+ */
540
+ export declare function useSearchRunes(): (searchKeyword?: string) => Promise<RuneInfo[]>;
541
+
542
+ export declare namespace utils {
543
+ export {
544
+ hexToBytes,
545
+ bytesToHex,
546
+ toBitcoinNetwork,
547
+ getScriptByAddress,
548
+ getAddressType
549
+ }
550
+ }
551
+
552
+ export declare type Utxo = {
553
+ txid: string;
554
+ vout: number;
555
+ satoshis: string;
556
+ height?: number;
557
+ runes: {
558
+ id: string;
559
+ amount: string;
560
+ }[];
561
+ address: string;
562
+ scriptPk: string;
563
+ };
564
+
565
+ export { }