@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.
- package/LICENSE +21 -0
- package/README.md +400 -0
- package/dist/index.d.ts +565 -0
- package/dist/ree-sdk.js +26640 -0
- package/dist/ree-sdk.umd.cjs +146 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Ree Network
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
# Ree Typescript SDK
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for interacting with the Ree protocol on Bitcoin, providing seamless integration with Bitcoin wallets and Rune tokens.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ๐ **Bitcoin Integration**: Connect with Bitcoin wallets and manage UTXOs
|
|
8
|
+
- ๐ช **Rune Support**: Full support for Bitcoin Runes protocol
|
|
9
|
+
- โ๏ธ **React Integration**: Built-in React hooks and providers
|
|
10
|
+
- ๐ง **TypeScript**: Full type safety and IntelliSense support
|
|
11
|
+
- ๐งช **Well Tested**: Comprehensive test coverage
|
|
12
|
+
- ๐ฆ **Lightweight**: Minimal dependencies and optimized bundle size
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @ree-network/ts-sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
### Initializing the Client
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { ReeClient, Network, type Config } from "@ree-network/ts-sdk";
|
|
26
|
+
|
|
27
|
+
const config: Config = {
|
|
28
|
+
network: Network.Testnet,
|
|
29
|
+
maestroApiKey: "your-maestro-api-key",
|
|
30
|
+
exchangeIdlFactory: yourExchangeIdlFactory,
|
|
31
|
+
exchangeCanisterId: "your-canister-id",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const client = new ReeClient(config);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Basic Usage
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
// Get Bitcoin UTXOs
|
|
41
|
+
const utxos = await client.getBtcUtxos("bc1q..."); // payment address
|
|
42
|
+
|
|
43
|
+
// Get Rune UTXOs
|
|
44
|
+
const runeUtxos = await client.getRuneUtxos("bc1q...", "RUNE_ID"); // address, runeId
|
|
45
|
+
|
|
46
|
+
// Get Rune Info
|
|
47
|
+
const runeInfo = await client.getRuneInfo("RUNE_ID");
|
|
48
|
+
|
|
49
|
+
// Get Bitcoin Balance
|
|
50
|
+
const btcBalance = await client.getBtcBalance("bc1q..."); // payment address
|
|
51
|
+
|
|
52
|
+
const runeBalance = await client.getRuneBalance("bc1q...", "RUNE_ID"); // address, runeId
|
|
53
|
+
|
|
54
|
+
// Search for runes
|
|
55
|
+
const runes = await client.searchRunes("DOG");
|
|
56
|
+
|
|
57
|
+
// Get pool information
|
|
58
|
+
const pools = await client.getPoolList();
|
|
59
|
+
const poolInfo = await client.getPoolInfo("pool-address");
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Creating and Executing Transactions
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
// Create a swap transaction
|
|
66
|
+
const transaction = await client.createTransaction({
|
|
67
|
+
address: "bc1q...", // Bitcoin address
|
|
68
|
+
paymentAddress: "bc1q...", // Payment address
|
|
69
|
+
poolAddress: "bc1q...",
|
|
70
|
+
sendBtcAmount: BigInt(100000), // 0.001 BTC in satoshis
|
|
71
|
+
sendRuneAmount: BigInt(0),
|
|
72
|
+
receiveBtcAmount: BigInt(0),
|
|
73
|
+
receiveRuneAmount: BigInt(1000),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Build the transaction
|
|
77
|
+
const psbt = await transaction.build("swap", BigInt(Date.now()));
|
|
78
|
+
|
|
79
|
+
// Sign with your wallet (implementation depends on wallet)
|
|
80
|
+
const signedPsbt = await wallet.signPsbt(psbt);
|
|
81
|
+
|
|
82
|
+
// Submit the transaction
|
|
83
|
+
const result = await transaction.send(signedPsbt.toHex());
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### React Integration
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
import { ReeProvider, useRee, useBtcBalance } from "@ree-network/ts-sdk";
|
|
90
|
+
|
|
91
|
+
function App() {
|
|
92
|
+
return (
|
|
93
|
+
<ReeProvider config={config}>
|
|
94
|
+
<WalletComponent />
|
|
95
|
+
</ReeProvider>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function WalletComponent() {
|
|
100
|
+
const { client, address, updateWallet } = useRee();
|
|
101
|
+
|
|
102
|
+
const { balance: btcBalance } = useBtcBalance();
|
|
103
|
+
|
|
104
|
+
const connectWallet = () => {
|
|
105
|
+
updateWallet({
|
|
106
|
+
address: "bc1q...",
|
|
107
|
+
paymentAddress: "bc1q...",
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<div>
|
|
113
|
+
<div>Connected: {address}</div>
|
|
114
|
+
<div>Balance: {btcBalance} BTC</div>
|
|
115
|
+
<button onClick={connectWallet}>Connect wallet</button>
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Integration with LaserEyes
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
import { LaserEyesProvider, useLaserEyes } from "@omnisat/lasereyes-core";
|
|
125
|
+
import { ReeProvider, useRee } from "@ree-network/ts-sdk";
|
|
126
|
+
|
|
127
|
+
function App() {
|
|
128
|
+
return (
|
|
129
|
+
<LaserEyesProvider config={laserEyesConfig}>
|
|
130
|
+
<ReeProvider config={reeConfig}>
|
|
131
|
+
<ConnectWalletModal />
|
|
132
|
+
<MyComponent />
|
|
133
|
+
</ReeProvider>
|
|
134
|
+
</LaserEyesProvider>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function MyComponent({ children }) {
|
|
139
|
+
const { signPsbt } = useLaserEyes();
|
|
140
|
+
const { updateWallet, createTransaction, exchange } = useRee();
|
|
141
|
+
|
|
142
|
+
const sendTransaction = async () => {
|
|
143
|
+
const depositBtcAmount = BigInt(100000);
|
|
144
|
+
const depositOffer = await exchange.pre_deposit("bc1q...", {
|
|
145
|
+
id: "0:0",
|
|
146
|
+
value: depositBtcAmount,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const tx = await createTransaction({
|
|
150
|
+
poolAddress: "bc1q...",
|
|
151
|
+
sendBtcAmount: depositBtcAmount,
|
|
152
|
+
sendRuneAmount: BigInt(0),
|
|
153
|
+
receiveBtcAmount: BigInt(0),
|
|
154
|
+
receiveRuneAmount: BigInt(0),
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const psbt = await tx.build("deposit", depositOffer.nonce);
|
|
158
|
+
|
|
159
|
+
const signedPsbt = await signPsbt(psbt);
|
|
160
|
+
const txid = await tx.send(signedPsbt.toHex());
|
|
161
|
+
|
|
162
|
+
console.log("Transaction sent:", txid);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<div>
|
|
167
|
+
<button onClick={sendTransaction}>Send Transaction</button>
|
|
168
|
+
</div>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function ConnectWalletModal() {
|
|
173
|
+
const { address, paymentAddress, connect } = useLaserEyes();
|
|
174
|
+
const { updateWallet } = useRee();
|
|
175
|
+
|
|
176
|
+
useEffect(() => {
|
|
177
|
+
updateWallet({
|
|
178
|
+
address,
|
|
179
|
+
paymentAddress,
|
|
180
|
+
});
|
|
181
|
+
}, [address, paymentAddress, updateWallet]);
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<div>
|
|
185
|
+
<button onClick={connect}>Connect Wallet</button>
|
|
186
|
+
</div>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## API Reference
|
|
192
|
+
|
|
193
|
+
### ReeClient
|
|
194
|
+
|
|
195
|
+
The main client class for interacting with the Ree protocol.
|
|
196
|
+
|
|
197
|
+
#### Constructor
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
new ReeClient(config: Config)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
#### Methods
|
|
204
|
+
|
|
205
|
+
##### Balance & UTXO Methods
|
|
206
|
+
|
|
207
|
+
- `getBtcBalance(paymentAddress: string): Promise<number>` - Get Bitcoin balance in BTC
|
|
208
|
+
- `getBtcUtxos(paymentAddress: string): Promise<Utxo[]>` - Get Bitcoin UTXOs for the payment address
|
|
209
|
+
- `getRuneBalance(address: string, runeId: string): Promise<number | undefined>` - Get balance for a specific rune
|
|
210
|
+
- `getRuneUtxos(address: string, runeId: string): Promise<Utxo[]>` - Get UTXOs containing a specific rune
|
|
211
|
+
|
|
212
|
+
##### Rune Information Methods
|
|
213
|
+
|
|
214
|
+
- `searchRunes(keyword: string): Promise<RuneInfo[]>` - Search for runes by keyword or rune ID
|
|
215
|
+
- `getRuneInfo(runeId: string): Promise<RuneInfo | undefined>` - Get detailed information for a specific rune
|
|
216
|
+
|
|
217
|
+
##### Pool Methods
|
|
218
|
+
|
|
219
|
+
- `getPoolList(): Promise<Pool[]>` - Get list of all available liquidity pools
|
|
220
|
+
- `getPoolInfo(poolAddress: string): Promise<PoolInfo>` - Get information about a specific liquidity pool
|
|
221
|
+
|
|
222
|
+
##### Transaction Methods
|
|
223
|
+
|
|
224
|
+
- `createTransaction(params): Promise<Transaction>` - Create a transaction for trading with a liquidity pool
|
|
225
|
+
|
|
226
|
+
### Transaction
|
|
227
|
+
|
|
228
|
+
Transaction builder for Bitcoin and Rune transactions.
|
|
229
|
+
|
|
230
|
+
#### Methods
|
|
231
|
+
|
|
232
|
+
- `build(action: string, nonce: bigint, actionParams?: string): Promise<bitcoin.Psbt>` - Build the PSBT
|
|
233
|
+
- `send(signedPsbtHex: string): Promise<any>` - Submit the signed transaction to orchestrator
|
|
234
|
+
|
|
235
|
+
### React Hooks
|
|
236
|
+
|
|
237
|
+
The SDK provides specialized hooks for all operations:
|
|
238
|
+
|
|
239
|
+
```tsx
|
|
240
|
+
import {
|
|
241
|
+
useBtcBalance,
|
|
242
|
+
useRuneBalance,
|
|
243
|
+
useBtcUtxos,
|
|
244
|
+
useRuneUtxos,
|
|
245
|
+
useSearchRunes,
|
|
246
|
+
useRuneInfo,
|
|
247
|
+
usePoolList,
|
|
248
|
+
usePoolInfo,
|
|
249
|
+
} from "@ree-network/ts-sdk";
|
|
250
|
+
|
|
251
|
+
function TradingDashboard() {
|
|
252
|
+
// Balance & UTXO hooks
|
|
253
|
+
const { balance: btcBalance, loading: btcLoading } = useBtcBalance();
|
|
254
|
+
const { balance: runeBalance } = useRuneBalance("840000:3");
|
|
255
|
+
const { utxos: btcUtxos } = useBtcUtxos();
|
|
256
|
+
const { utxos: runeUtxos } = useRuneUtxos("840000:3");
|
|
257
|
+
|
|
258
|
+
const [runes, setRunes] = useState([]);
|
|
259
|
+
|
|
260
|
+
// Rune search hooks
|
|
261
|
+
const searchRunes = useSearchRunes();
|
|
262
|
+
const { runeInfo } = useRuneInfo("840000:3");
|
|
263
|
+
|
|
264
|
+
// Pool hooks
|
|
265
|
+
const { pools } = usePoolList();
|
|
266
|
+
const { poolInfo } = usePoolInfo("bc1q...");
|
|
267
|
+
|
|
268
|
+
const handleSearch = () => {
|
|
269
|
+
searchRunes("DOG").then(setRunes); // Search for runes containing "DOG"
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
return (
|
|
273
|
+
<div>
|
|
274
|
+
<h2>Balances</h2>
|
|
275
|
+
<div>BTC: {btcBalance} BTC</div>
|
|
276
|
+
<div>Rune: {runeBalance}</div>
|
|
277
|
+
|
|
278
|
+
<h2>Search Runes</h2>
|
|
279
|
+
<button onClick={handleSearch}>Search DOG</button>
|
|
280
|
+
<div>{runes.length} runes found</div>
|
|
281
|
+
|
|
282
|
+
<h2>Pools</h2>
|
|
283
|
+
<div>{pools.length} pools available</div>
|
|
284
|
+
</div>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
#### Available Hooks
|
|
290
|
+
|
|
291
|
+
**Balance & UTXO Hooks:**
|
|
292
|
+
|
|
293
|
+
- `useBtcBalance(options?)` - Bitcoin balance management
|
|
294
|
+
- `useRuneBalance(runeId, options?)` - Rune balance for specific rune
|
|
295
|
+
- `useBtcUtxos(options?)` - Bitcoin UTXOs management
|
|
296
|
+
- `useRuneUtxos(runeId, options?)` - Rune UTXOs for specific rune
|
|
297
|
+
|
|
298
|
+
**Rune Information Hooks:**
|
|
299
|
+
|
|
300
|
+
- `useSearchRunes(keyword?, options?)` - Search runes by keyword
|
|
301
|
+
- `useRuneInfo(runeId?, options?)` - Get rune information by ID
|
|
302
|
+
|
|
303
|
+
**Pool Hooks:**
|
|
304
|
+
|
|
305
|
+
- `usePoolList(options?)` - Get all available pools
|
|
306
|
+
- `usePoolInfo(poolAddress?, options?)` - Get specific pool information
|
|
307
|
+
|
|
308
|
+
#### Hook Usage Examples
|
|
309
|
+
|
|
310
|
+
```tsx
|
|
311
|
+
// Search runes with auto-search
|
|
312
|
+
const { runes, loading, search } = useSearchRunes("DOG", { autoRefresh: true });
|
|
313
|
+
|
|
314
|
+
// Get rune info with polling
|
|
315
|
+
const { runeInfo } = useRuneInfo("840000:3", { refreshInterval: 30000 });
|
|
316
|
+
|
|
317
|
+
// Get pools with manual refresh only
|
|
318
|
+
const { pools, refetch } = usePoolList({ autoRefresh: false });
|
|
319
|
+
|
|
320
|
+
// Search manually
|
|
321
|
+
const { runes, search } = useSearchRunes();
|
|
322
|
+
await search("BITCOIN");
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Core useRee Hook
|
|
326
|
+
|
|
327
|
+
The `useRee()` hook now focuses on core functionality:
|
|
328
|
+
|
|
329
|
+
```tsx
|
|
330
|
+
const {
|
|
331
|
+
client, // Direct access to ReeClient
|
|
332
|
+
address, // Current Bitcoin address
|
|
333
|
+
paymentAddress, // Current payment address
|
|
334
|
+
updateWallet, // Update wallet addresses
|
|
335
|
+
exchange, // Exchange canister actor
|
|
336
|
+
createTransaction, // Create transactions
|
|
337
|
+
} = useRee();
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Types
|
|
341
|
+
|
|
342
|
+
The SDK exports all necessary TypeScript types:
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
import type {
|
|
346
|
+
Config,
|
|
347
|
+
Utxo,
|
|
348
|
+
RuneInfo,
|
|
349
|
+
Pool,
|
|
350
|
+
PoolInfo,
|
|
351
|
+
IntentionSet,
|
|
352
|
+
Intention,
|
|
353
|
+
TransactionConfig,
|
|
354
|
+
AddressType,
|
|
355
|
+
} from "@ree-network/ts-sdk";
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Configuration
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
interface Config {
|
|
362
|
+
network: Network; // Network.Mainnet or Network.Testnet
|
|
363
|
+
maestroApiKey: string; // Your Maestro API key
|
|
364
|
+
exchangeIdlFactory: IDL.InterfaceFactory; // Exchange canister IDL
|
|
365
|
+
exchangeCanisterId: string; // Exchange canister ID
|
|
366
|
+
exchangeId: string; // Exchange ID for transactions
|
|
367
|
+
}
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Networks
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
enum Network {
|
|
374
|
+
Mainnet = "mainnet",
|
|
375
|
+
Testnet = "testnet",
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## Error Handling
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
try {
|
|
383
|
+
const utxos = await client.getBtcUtxos("bc1q...");
|
|
384
|
+
} catch (error) {
|
|
385
|
+
console.error("Failed to fetch UTXOs:", error);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// React hook error handling
|
|
389
|
+
const { client } = useRee();
|
|
390
|
+
|
|
391
|
+
const loadBalance = async () => {
|
|
392
|
+
try {
|
|
393
|
+
const balance = await client.getBtcBalance("bc1q...");
|
|
394
|
+
setBalance(balance);
|
|
395
|
+
} catch (error) {
|
|
396
|
+
console.error("Failed to load balance:", error);
|
|
397
|
+
setError(error.message);
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
```
|