stableflow-ai-sdk 1.0.0 → 2.0.0
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/README.md +483 -94
- package/dist/index.d.mts +425 -2
- package/dist/index.d.ts +425 -2
- package/dist/index.js +6826 -61
- package/dist/index.mjs +6826 -60
- package/package.json +16 -6
package/README.md
CHANGED
|
@@ -23,170 +23,552 @@ pnpm add stableflow-ai-sdk
|
|
|
23
23
|
## Quick Start
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
|
-
import { OpenAPI,
|
|
26
|
+
import { OpenAPI, SFA, tokens, EVMWallet } from 'stableflow-ai-sdk';
|
|
27
|
+
import { ethers } from 'ethers';
|
|
27
28
|
|
|
28
29
|
// Initialize the API client
|
|
29
30
|
OpenAPI.BASE = 'https://api.stableflow.ai';
|
|
30
|
-
|
|
31
|
-
// Configure your JSON Web Token (JWT) - required for most endpoints
|
|
32
31
|
OpenAPI.TOKEN = "your-JSON-Web-Token";
|
|
33
32
|
|
|
34
|
-
//
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
33
|
+
// Get wallet instance (example with EVM)
|
|
34
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
35
|
+
const signer = await provider.getSigner();
|
|
36
|
+
const wallet = new EVMWallet(provider, signer);
|
|
37
|
+
|
|
38
|
+
// Get token configurations
|
|
39
|
+
const fromToken = tokens.find(t => t.chainName === 'Ethereum' && t.symbol === 'USDT');
|
|
40
|
+
const toToken = tokens.find(t => t.chainName === 'Arbitrum' && t.symbol === 'USDT');
|
|
41
|
+
|
|
42
|
+
// Get quotes from all bridge services
|
|
43
|
+
const quotes = await SFA.getAllQuote({
|
|
44
|
+
dry: false,
|
|
45
|
+
minInputAmount: "0.1",
|
|
46
|
+
prices: {},
|
|
47
|
+
fromToken: fromToken!,
|
|
48
|
+
toToken: toToken!,
|
|
49
|
+
wallet: wallet,
|
|
50
|
+
recipient: '0x...', // recipient address
|
|
51
|
+
refundTo: '0x...', // refund address
|
|
52
|
+
amountWei: ethers.parseUnits('100', fromToken!.decimals).toString(),
|
|
53
|
+
slippageTolerance: 0.5, // 0.5%
|
|
54
|
+
});
|
|
49
55
|
|
|
50
|
-
//
|
|
51
|
-
const
|
|
56
|
+
// Select the best quote and send transaction
|
|
57
|
+
const selectedQuote = quotes.find(q => q.quote && !q.error);
|
|
58
|
+
if (selectedQuote && selectedQuote.quote) {
|
|
59
|
+
const txHash = await SFA.send(selectedQuote.serviceType, {
|
|
60
|
+
wallet: wallet,
|
|
61
|
+
quote: selectedQuote.quote,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Check transaction status
|
|
65
|
+
const status = await SFA.getStatus(selectedQuote.serviceType, {
|
|
66
|
+
hash: txHash,
|
|
67
|
+
depositAddress: selectedQuote.quote.depositAddress,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
52
70
|
```
|
|
53
71
|
|
|
54
|
-
##
|
|
72
|
+
## Authentication
|
|
73
|
+
|
|
74
|
+
The StableFlow AI API requires JWT authentication for all endpoints.
|
|
75
|
+
|
|
76
|
+
### Getting Your JWT Token
|
|
77
|
+
|
|
78
|
+
To use the SDK, you need to apply for a JWT token:
|
|
55
79
|
|
|
56
|
-
|
|
80
|
+
1. Visit [https://app.stableflow.ai/apply](https://app.stableflow.ai/apply)
|
|
81
|
+
2. Submit an application form for API access
|
|
82
|
+
3. Once approved, you will receive your JWT token
|
|
83
|
+
|
|
84
|
+
### Using Your Token
|
|
57
85
|
|
|
58
86
|
```typescript
|
|
59
|
-
|
|
87
|
+
// Set your JWT token
|
|
88
|
+
OpenAPI.TOKEN = 'your-JSON-Web-Token-here';
|
|
60
89
|
```
|
|
61
90
|
|
|
62
|
-
|
|
91
|
+
## Core API Methods
|
|
92
|
+
|
|
93
|
+
### `getAllQuote` - Get Quotes from All Bridge Services
|
|
94
|
+
|
|
95
|
+
Retrieves quotes from all supported bridge services (OneClick, CCTP, USDT0) in parallel. Returns an array of quotes with their corresponding service types, allowing users to compare and select the best route.
|
|
63
96
|
|
|
64
97
|
```typescript
|
|
65
|
-
const
|
|
98
|
+
const quotes = await SFA.getAllQuote({
|
|
99
|
+
singleService?: ServiceType, // Optional: query specific service only
|
|
100
|
+
dry?: boolean, // Set to true for testing without deposit address
|
|
101
|
+
minInputAmount?: string, // Minimum input amount (default: "1")
|
|
102
|
+
prices: Record<string, string>, // Token prices
|
|
103
|
+
fromToken: TokenConfig, // Source token configuration
|
|
104
|
+
toToken: TokenConfig, // Destination token configuration
|
|
105
|
+
wallet: WalletConfig, // Wallet instance (EVMWallet, SolanaWallet, etc.)
|
|
106
|
+
recipient: string, // Recipient address on destination chain
|
|
107
|
+
refundTo: string, // Refund address on source chain
|
|
108
|
+
amountWei: string, // Amount in smallest units (wei/satoshi/etc.)
|
|
109
|
+
slippageTolerance: number, // Slippage tolerance percentage (e.g., 0.5 for 0.5%)
|
|
110
|
+
});
|
|
66
111
|
```
|
|
67
112
|
|
|
68
|
-
|
|
113
|
+
**Returns**: `Promise<Array<{ serviceType: ServiceType; quote?: any; error?: string }>>`
|
|
114
|
+
|
|
115
|
+
**Example**:
|
|
69
116
|
|
|
70
117
|
```typescript
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
118
|
+
import { SFA, tokens, EVMWallet, GetAllQuoteParams } from 'stableflow-ai-sdk';
|
|
119
|
+
import { ethers } from 'ethers';
|
|
120
|
+
|
|
121
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
122
|
+
const signer = await provider.getSigner();
|
|
123
|
+
const wallet = new EVMWallet(provider, signer);
|
|
124
|
+
|
|
125
|
+
const fromToken = tokens.find(t => t.contractAddress === '0x...');
|
|
126
|
+
const toToken = tokens.find(t => t.contractAddress === '0x...');
|
|
127
|
+
|
|
128
|
+
const quotes = await SFA.getAllQuote({
|
|
129
|
+
dry: false,
|
|
130
|
+
prices: {},
|
|
131
|
+
fromToken: fromToken!,
|
|
132
|
+
toToken: toToken!,
|
|
133
|
+
wallet: wallet,
|
|
134
|
+
recipient: '0x1234...',
|
|
135
|
+
refundTo: '0x5678...',
|
|
136
|
+
amountWei: ethers.parseUnits('100', fromToken!.decimals).toString(),
|
|
137
|
+
slippageTolerance: 0.5,
|
|
74
138
|
});
|
|
139
|
+
|
|
140
|
+
// Filter valid quotes
|
|
141
|
+
const validQuotes = quotes.filter(q => q.quote && !q.error);
|
|
142
|
+
console.log('Available routes:', validQuotes.map(q => q.serviceType));
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Response Structure**:
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
[
|
|
149
|
+
{
|
|
150
|
+
serviceType: "oneclick",
|
|
151
|
+
quote: {
|
|
152
|
+
quote: QuoteResponse,
|
|
153
|
+
quoteParam: {...},
|
|
154
|
+
sendParam: {...},
|
|
155
|
+
depositAddress: "0x...",
|
|
156
|
+
needApprove: boolean,
|
|
157
|
+
approveSpender: "0x...",
|
|
158
|
+
fees: {...}
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
serviceType: "cctp",
|
|
163
|
+
quote: {...},
|
|
164
|
+
error: undefined
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
serviceType: "usdt0",
|
|
168
|
+
error: "Amount exceeds max"
|
|
169
|
+
}
|
|
170
|
+
]
|
|
75
171
|
```
|
|
76
172
|
|
|
77
|
-
###
|
|
173
|
+
### `send` - Execute Transaction
|
|
174
|
+
|
|
175
|
+
Executes the transaction using the specified bridge service based on the service type. This method handles token approval (if needed) and submits the transaction to the blockchain.
|
|
78
176
|
|
|
79
177
|
```typescript
|
|
80
|
-
const
|
|
178
|
+
const txHash = await SFA.send(
|
|
179
|
+
serviceType: ServiceType, // "oneclick" | "cctp" | "usdt0"
|
|
180
|
+
{
|
|
181
|
+
wallet: WalletConfig, // Wallet instance
|
|
182
|
+
quote: any, // Quote object from getAllQuote response
|
|
183
|
+
}
|
|
184
|
+
);
|
|
81
185
|
```
|
|
82
186
|
|
|
83
|
-
|
|
187
|
+
**Returns**: `Promise<string>` - Transaction hash or signature
|
|
84
188
|
|
|
85
|
-
|
|
189
|
+
**Example**:
|
|
86
190
|
|
|
87
|
-
|
|
191
|
+
```typescript
|
|
192
|
+
// After getting quotes and selecting one
|
|
193
|
+
const selectedQuote = quotes.find(q => q.quote && !q.error);
|
|
194
|
+
|
|
195
|
+
if (selectedQuote && selectedQuote.quote) {
|
|
196
|
+
// Check if approval is needed
|
|
197
|
+
if (selectedQuote.quote.needApprove) {
|
|
198
|
+
await wallet.approve({
|
|
199
|
+
contractAddress: selectedQuote.quote.quoteParam.fromToken.contractAddress,
|
|
200
|
+
spender: selectedQuote.quote.approveSpender,
|
|
201
|
+
amountWei: selectedQuote.quote.quoteParam.amountWei,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Send the transaction
|
|
206
|
+
const txHash = await SFA.send(selectedQuote.serviceType, {
|
|
207
|
+
wallet: wallet,
|
|
208
|
+
quote: selectedQuote.quote,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
console.log('Transaction hash:', txHash);
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**Note**: The `send` method automatically submits the transaction hash to the StableFlow service for tracking. You don't need to call `submitDepositTx` separately.
|
|
216
|
+
|
|
217
|
+
### `getStatus` - Check Transaction Status
|
|
218
|
+
|
|
219
|
+
Queries the transaction status from the specified bridge service. Returns the current status and destination chain transaction hash (if available).
|
|
88
220
|
|
|
89
221
|
```typescript
|
|
90
|
-
|
|
91
|
-
|
|
222
|
+
const status = await SFA.getStatus(
|
|
223
|
+
serviceType: ServiceType, // "oneclick" | "cctp" | "usdt0"
|
|
224
|
+
{
|
|
225
|
+
depositAddress?: string, // Deposit address from quote (for OneClick)
|
|
226
|
+
hash?: string, // Transaction hash (for USDT0 and CCTP)
|
|
227
|
+
}
|
|
228
|
+
);
|
|
92
229
|
```
|
|
93
230
|
|
|
94
|
-
|
|
231
|
+
**Returns**: `Promise<{ status: TransactionStatus; toChainTxHash?: string }>`
|
|
232
|
+
|
|
233
|
+
**TransactionStatus**:
|
|
234
|
+
- `TransactionStatus.Pending` - Transaction is pending
|
|
235
|
+
- `TransactionStatus.Success` - Transaction completed successfully
|
|
236
|
+
- `TransactionStatus.Failed` - Transaction failed or was refunded
|
|
237
|
+
|
|
238
|
+
**Example**:
|
|
95
239
|
|
|
96
240
|
```typescript
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
241
|
+
import { SFA, Service, TransactionStatus } from 'stableflow-ai-sdk';
|
|
242
|
+
|
|
243
|
+
// For OneClick service
|
|
244
|
+
const status = await SFA.getStatus(Service.OneClick, {
|
|
245
|
+
depositAddress: '0x...',
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// For USDT0 or CCTP service
|
|
249
|
+
const status = await SFA.getStatus(Service.Usdt0, {
|
|
250
|
+
hash: '0x...',
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
console.log('Status:', status.status); // "pending" | "success" | "failed"
|
|
254
|
+
if (status.toChainTxHash) {
|
|
255
|
+
console.log('Destination tx hash:', status.toChainTxHash);
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
**Polling Example**:
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
async function pollTransactionStatus(
|
|
263
|
+
serviceType: ServiceType,
|
|
264
|
+
params: { depositAddress?: string; hash?: string },
|
|
265
|
+
interval: number = 5000
|
|
266
|
+
): Promise<{ status: TransactionStatus; toChainTxHash?: string }> {
|
|
267
|
+
return new Promise((resolve) => {
|
|
268
|
+
const checkStatus = async () => {
|
|
269
|
+
try {
|
|
270
|
+
const result = await SFA.getStatus(serviceType, params);
|
|
271
|
+
if (result.status !== TransactionStatus.Pending) {
|
|
272
|
+
resolve(result);
|
|
273
|
+
} else {
|
|
274
|
+
setTimeout(checkStatus, interval);
|
|
275
|
+
}
|
|
276
|
+
} catch (error) {
|
|
277
|
+
console.error('Error checking status:', error);
|
|
278
|
+
setTimeout(checkStatus, interval);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
checkStatus();
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Usage
|
|
286
|
+
const finalStatus = await pollTransactionStatus(Service.OneClick, {
|
|
287
|
+
depositAddress: '0x...',
|
|
288
|
+
});
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Supported Bridge Services
|
|
292
|
+
|
|
293
|
+
The SDK supports three bridge services:
|
|
294
|
+
|
|
295
|
+
- **OneClick** (`Service.OneClick`) - Native StableFlow bridge service
|
|
296
|
+
- **CCTP** (`Service.CCTP`) - Circle's Cross-Chain Transfer Protocol
|
|
297
|
+
- **USDT0** (`Service.Usdt0`) - LayerZero-based USDT bridge
|
|
298
|
+
|
|
299
|
+
Each service has different characteristics:
|
|
300
|
+
- Different fee structures
|
|
301
|
+
- Different supported token pairs
|
|
302
|
+
- Different processing times
|
|
303
|
+
- Different minimum/maximum amounts
|
|
304
|
+
|
|
305
|
+
Use `getAllQuote` to compare all available routes and select the best one for your use case.
|
|
306
|
+
|
|
307
|
+
## Wallet Integration
|
|
308
|
+
|
|
309
|
+
The SDK supports multiple wallet types:
|
|
310
|
+
|
|
311
|
+
### EVM Wallets (Ethereum, Arbitrum, Polygon, etc.)
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
import { EVMWallet } from 'stableflow-ai-sdk';
|
|
315
|
+
import { ethers } from 'ethers';
|
|
316
|
+
|
|
317
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
318
|
+
const signer = await provider.getSigner();
|
|
319
|
+
const wallet = new EVMWallet(provider, signer);
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### Solana Wallets
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
import { SolanaWallet } from 'stableflow-ai-sdk';
|
|
326
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
327
|
+
|
|
328
|
+
const connection = new Connection('https://api.mainnet-beta.solana.com');
|
|
329
|
+
const wallet = new SolanaWallet(connection, publicKey, signTransaction);
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Near Wallets
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
import { NearWallet } from 'stableflow-ai-sdk';
|
|
336
|
+
|
|
337
|
+
const wallet = new NearWallet(connection, accountId, keyPair);
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Tron Wallets
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
import { TronWallet } from 'stableflow-ai-sdk';
|
|
344
|
+
|
|
345
|
+
const wallet = new TronWallet(tronWeb);
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Aptos Wallets
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
import { AptosWallet } from 'stableflow-ai-sdk';
|
|
352
|
+
|
|
353
|
+
const wallet = new AptosWallet(provider, signer);
|
|
102
354
|
```
|
|
103
355
|
|
|
104
|
-
|
|
356
|
+
## Token Configuration
|
|
357
|
+
|
|
358
|
+
The SDK provides pre-configured token information:
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
import { tokens, usdtTokens, usdcTokens } from 'stableflow-ai-sdk';
|
|
362
|
+
|
|
363
|
+
// Get all supported tokens
|
|
364
|
+
const allTokens = tokens;
|
|
365
|
+
|
|
366
|
+
// Get USDT tokens only
|
|
367
|
+
const usdtOnly = usdtTokens;
|
|
105
368
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
369
|
+
// Get USDC tokens only
|
|
370
|
+
const usdcOnly = usdcTokens;
|
|
371
|
+
|
|
372
|
+
// Find token by contract address
|
|
373
|
+
const token = tokens.find(t =>
|
|
374
|
+
t.contractAddress.toLowerCase() === '0x...'.toLowerCase()
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
// Find tokens by chain
|
|
378
|
+
const ethereumTokens = tokens.filter(t => t.chainName === 'Ethereum');
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
Each token configuration includes:
|
|
382
|
+
- `chainName` - Name of the blockchain
|
|
383
|
+
- `chainType` - Type of chain (evm, solana, near, tron, aptos)
|
|
384
|
+
- `symbol` - Token symbol (USDT, USDC, etc.)
|
|
385
|
+
- `decimals` - Token decimals
|
|
386
|
+
- `contractAddress` - Token contract address
|
|
387
|
+
- `assetId` - StableFlow asset identifier
|
|
388
|
+
- `services` - Array of supported bridge services
|
|
389
|
+
- `rpcUrl` - RPC endpoint URL
|
|
390
|
+
|
|
391
|
+
## Complete Example
|
|
392
|
+
|
|
393
|
+
Here's a complete example of a cross-chain swap:
|
|
394
|
+
|
|
395
|
+
```typescript
|
|
396
|
+
import { SFA, OpenAPI, tokens, EVMWallet, Service, TransactionStatus } from 'stableflow-ai-sdk';
|
|
397
|
+
import { ethers } from 'ethers';
|
|
398
|
+
|
|
399
|
+
// 1. Initialize SDK
|
|
400
|
+
OpenAPI.BASE = 'https://api.stableflow.ai';
|
|
401
|
+
OpenAPI.TOKEN = 'your-jwt-token';
|
|
402
|
+
|
|
403
|
+
// 2. Setup wallet
|
|
404
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
405
|
+
await provider.send('eth_requestAccounts', []);
|
|
406
|
+
const signer = await provider.getSigner();
|
|
407
|
+
const wallet = new EVMWallet(provider, signer);
|
|
408
|
+
const userAddress = await signer.getAddress();
|
|
409
|
+
|
|
410
|
+
// 3. Select tokens
|
|
411
|
+
const fromToken = tokens.find(t =>
|
|
412
|
+
t.chainName === 'Ethereum' && t.symbol === 'USDT'
|
|
413
|
+
);
|
|
414
|
+
const toToken = tokens.find(t =>
|
|
415
|
+
t.chainName === 'Arbitrum' && t.symbol === 'USDT'
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
if (!fromToken || !toToken) {
|
|
419
|
+
throw new Error('Token pair not supported');
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// 4. Get quotes
|
|
423
|
+
const quotes = await SFA.getAllQuote({
|
|
424
|
+
dry: false,
|
|
425
|
+
prices: {},
|
|
426
|
+
fromToken,
|
|
427
|
+
toToken,
|
|
428
|
+
wallet,
|
|
429
|
+
recipient: userAddress, // or another address
|
|
430
|
+
refundTo: userAddress,
|
|
431
|
+
amountWei: ethers.parseUnits('100', fromToken.decimals).toString(),
|
|
432
|
+
slippageTolerance: 0.5,
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
// 5. Select best quote (e.g., first valid one)
|
|
436
|
+
const selectedQuote = quotes.find(q => q.quote && !q.error);
|
|
437
|
+
if (!selectedQuote || !selectedQuote.quote) {
|
|
438
|
+
throw new Error('No valid quotes available');
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
console.log(`Selected route: ${selectedQuote.serviceType}`);
|
|
442
|
+
|
|
443
|
+
// 6. Handle approval if needed
|
|
444
|
+
if (selectedQuote.quote.needApprove) {
|
|
445
|
+
const allowance = await wallet.allowance({
|
|
446
|
+
contractAddress: selectedQuote.quote.quoteParam.fromToken.contractAddress,
|
|
447
|
+
spender: selectedQuote.quote.approveSpender,
|
|
448
|
+
address: userAddress,
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
if (allowance < BigInt(selectedQuote.quote.quoteParam.amountWei)) {
|
|
452
|
+
await wallet.approve({
|
|
453
|
+
contractAddress: selectedQuote.quote.quoteParam.fromToken.contractAddress,
|
|
454
|
+
spender: selectedQuote.quote.approveSpender,
|
|
455
|
+
amountWei: selectedQuote.quote.quoteParam.amountWei,
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// 7. Send transaction
|
|
461
|
+
const txHash = await SFA.send(selectedQuote.serviceType, {
|
|
462
|
+
wallet,
|
|
463
|
+
quote: selectedQuote.quote,
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
console.log('Transaction submitted:', txHash);
|
|
467
|
+
|
|
468
|
+
// 8. Poll for status
|
|
469
|
+
const statusParams = selectedQuote.serviceType === Service.OneClick
|
|
470
|
+
? { depositAddress: selectedQuote.quote.quote?.depositAddress }
|
|
471
|
+
: { hash: txHash };
|
|
472
|
+
|
|
473
|
+
const checkStatus = async () => {
|
|
474
|
+
const status = await SFA.getStatus(selectedQuote.serviceType, statusParams);
|
|
475
|
+
console.log('Current status:', status.status);
|
|
476
|
+
|
|
477
|
+
if (status.status === TransactionStatus.Success) {
|
|
478
|
+
console.log('Swap completed! Destination tx:', status.toChainTxHash);
|
|
479
|
+
} else if (status.status === TransactionStatus.Failed) {
|
|
480
|
+
console.log('Swap failed or refunded');
|
|
481
|
+
} else {
|
|
482
|
+
// Still pending, check again later
|
|
483
|
+
setTimeout(checkStatus, 5000);
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
checkStatus();
|
|
488
|
+
```
|
|
110
489
|
|
|
111
490
|
## Error Handling
|
|
112
491
|
|
|
113
492
|
The SDK throws typed errors that you can catch and handle:
|
|
114
493
|
|
|
115
494
|
```typescript
|
|
495
|
+
import { ApiError } from 'stableflow-ai-sdk';
|
|
496
|
+
|
|
116
497
|
try {
|
|
117
|
-
|
|
498
|
+
const quotes = await SFA.getAllQuote(params);
|
|
118
499
|
} catch (error) {
|
|
119
|
-
|
|
120
|
-
|
|
500
|
+
if (error instanceof ApiError) {
|
|
501
|
+
switch (error.status) {
|
|
502
|
+
case 401:
|
|
121
503
|
console.error('Authentication failed: JWT is missing or invalid');
|
|
122
|
-
|
|
123
|
-
|
|
504
|
+
break;
|
|
505
|
+
case 400:
|
|
124
506
|
console.error('Invalid request:', error.body);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
console.error('
|
|
507
|
+
break;
|
|
508
|
+
default:
|
|
509
|
+
console.error('API error:', error.message);
|
|
128
510
|
}
|
|
511
|
+
} else {
|
|
512
|
+
console.error('Unexpected error:', error);
|
|
513
|
+
}
|
|
129
514
|
}
|
|
130
515
|
```
|
|
131
516
|
|
|
517
|
+
Common error scenarios:
|
|
518
|
+
|
|
519
|
+
- **Invalid parameters**: Missing or invalid token configurations, addresses, or amounts
|
|
520
|
+
- **Insufficient balance**: User doesn't have enough tokens
|
|
521
|
+
- **Amount too low**: Amount below minimum threshold for the bridge service
|
|
522
|
+
- **Amount exceeds max**: Amount above maximum limit for the bridge service
|
|
523
|
+
- **No route available**: No bridge service supports the token pair
|
|
524
|
+
- **Network errors**: Connection issues or RPC failures
|
|
525
|
+
|
|
132
526
|
## Type Definitions
|
|
133
527
|
|
|
134
|
-
The SDK provides full TypeScript type definitions
|
|
528
|
+
The SDK provides full TypeScript type definitions:
|
|
135
529
|
|
|
136
|
-
- `
|
|
137
|
-
- `
|
|
138
|
-
- `
|
|
139
|
-
- `
|
|
140
|
-
- `
|
|
141
|
-
- `
|
|
530
|
+
- `GetAllQuoteParams` - Parameters for `getAllQuote`
|
|
531
|
+
- `ServiceType` - Bridge service type (`"oneclick" | "cctp" | "usdt0"`)
|
|
532
|
+
- `Service` - Service constants
|
|
533
|
+
- `TokenConfig` - Token configuration interface
|
|
534
|
+
- `WalletConfig` - Wallet interface
|
|
535
|
+
- `TransactionStatus` - Transaction status enum
|
|
142
536
|
|
|
143
537
|
## Examples
|
|
144
538
|
|
|
145
|
-
### 🌐 Web Application Demo
|
|
539
|
+
### 🌐 Web Application Demo 2.0
|
|
146
540
|
|
|
147
541
|
**Try our interactive web app with real wallet connection:**
|
|
148
542
|
|
|
149
543
|
```bash
|
|
150
|
-
cd examples/web-demo
|
|
544
|
+
cd examples/web-demo-2.0
|
|
151
545
|
npm install
|
|
152
546
|
npm run dev
|
|
153
547
|
```
|
|
154
548
|
|
|
155
549
|
Features:
|
|
156
|
-
- 🔗 **Wallet
|
|
157
|
-
- 🎨 **Modern UI** - Beautiful
|
|
158
|
-
-
|
|
159
|
-
-
|
|
160
|
-
-
|
|
161
|
-
- 🚀 **
|
|
162
|
-
- 📊 **Transaction History** - Track your bridging activity
|
|
163
|
-
|
|
164
|
-
**Tech Stack**: TypeScript, Vite, ethers.js, StableFlow SDK
|
|
165
|
-
|
|
166
|
-
See [examples/web-demo/README.md](examples/web-demo/README.md) for full documentation.
|
|
550
|
+
- 🔗 **Multi-Wallet Support** - Connect MetaMask, Solana, Near, Tron, Aptos wallets
|
|
551
|
+
- 🎨 **Modern UI** - Beautiful interface with real-time updates
|
|
552
|
+
- 🌐 **Multiple Chains** - Support for all major blockchains
|
|
553
|
+
- 💰 **Multi-Token Support** - USDT and USDC bridging
|
|
554
|
+
- 💵 **Real-Time Quotes** - Compare quotes from all bridge services
|
|
555
|
+
- 🚀 **One-Click Execution** - Execute transactions with automatic approval
|
|
556
|
+
- 📊 **Transaction History** - Track your bridging activity with status polling
|
|
167
557
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
Interactive CLI tool for testing SDK functionality:
|
|
171
|
-
|
|
172
|
-
```bash
|
|
173
|
-
cd examples
|
|
174
|
-
npm install
|
|
175
|
-
export STABLEFLOW_JWT_TOKEN='your-jwt-token'
|
|
176
|
-
npm run demo
|
|
177
|
-
```
|
|
558
|
+
**Tech Stack**: TypeScript, React, Vite, StableFlow SDK
|
|
178
559
|
|
|
179
|
-
See [examples/
|
|
560
|
+
See [examples/web-demo-2.0/README.md](examples/web-demo-2.0/README.md) for full documentation.
|
|
180
561
|
|
|
181
|
-
|
|
562
|
+
## Migration from v1.0
|
|
182
563
|
|
|
183
|
-
|
|
564
|
+
If you're using SDK v1.0, see the [v1.0 documentation](README-v1.md) for the old API methods (`getQuote`, `getExecutionStatus`, `submitDepositTx`).
|
|
184
565
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
566
|
+
Key differences in v2.0:
|
|
567
|
+
- `getAllQuote` replaces `getQuote` and returns quotes from all services
|
|
568
|
+
- `send` replaces `submitDepositTx` and handles transaction submission automatically
|
|
569
|
+
- `getStatus` replaces `getExecutionStatus` with service-specific status checking
|
|
570
|
+
- Wallet instances are now required for quote requests
|
|
571
|
+
- Token configurations are provided via the `tokens` export
|
|
190
572
|
|
|
191
573
|
## Development
|
|
192
574
|
|
|
@@ -220,9 +602,16 @@ For issues or support:
|
|
|
220
602
|
|
|
221
603
|
## Changelog
|
|
222
604
|
|
|
605
|
+
### v2.0.0
|
|
606
|
+
- Added `getAllQuote` method to get quotes from all bridge services
|
|
607
|
+
- Added `send` method for executing transactions
|
|
608
|
+
- Added `getStatus` method for checking transaction status
|
|
609
|
+
- Support for multiple bridge services (OneClick, CCTP, USDT0)
|
|
610
|
+
- Wallet integration for multiple chains
|
|
611
|
+
- Pre-configured token information
|
|
612
|
+
|
|
223
613
|
### v1.0.0
|
|
224
614
|
- Initial release
|
|
225
615
|
- Support for cross-chain token swaps
|
|
226
616
|
- JWT authentication support
|
|
227
617
|
- Full TypeScript type definitions
|
|
228
|
-
|