xflows 1.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +682 -0
  3. package/dist/index.js +19191 -0
  4. package/package.json +55 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
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,682 @@
1
+ # xflows
2
+
3
+ A command-line interface for the [Wanchain XFlows](https://docs.wanchain.org/developers/xflows-api) cross-chain bridge protocol. Designed for both human operators and AI agents, every operation can be executed as a single one-liner command.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Installation](#installation)
8
+ - [Quick Start](#quick-start)
9
+ - [How It Works](#how-it-works)
10
+ - [Architecture Overview](#architecture-overview)
11
+ - [Cross-Chain Transaction Flow](#cross-chain-transaction-flow)
12
+ - [Work Modes](#work-modes)
13
+ - [Wallet Encryption](#wallet-encryption)
14
+ - [Wanchain Gas Price Enforcement](#wanchain-gas-price-enforcement)
15
+ - [RPC Endpoints](#rpc-endpoints)
16
+ - [Commands](#commands)
17
+ - [Wallet Management](#wallet-management)
18
+ - [Query Commands](#query-commands)
19
+ - [Quote](#quote)
20
+ - [Send Transaction](#send-transaction)
21
+ - [Transaction Status](#transaction-status)
22
+ - [RPC List](#rpc-list)
23
+ - [Complete Workflow Example](#complete-workflow-example)
24
+ - [AI Agent Integration](#ai-agent-integration)
25
+ - [Testing](#testing)
26
+ - [Project Structure](#project-structure)
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ # Clone and install dependencies
32
+ bun install
33
+
34
+ # Run directly
35
+ bun src/index.ts --help
36
+
37
+ # Or link as a global command
38
+ bun link
39
+ xflows --help
40
+ ```
41
+
42
+ **Requirements:** [Bun](https://bun.sh) v1.0+
43
+
44
+ ## Quick Start
45
+
46
+ ```bash
47
+ # 1. Create a wallet
48
+ xflows wallet create --name alice
49
+
50
+ # 2. Check what chains and tokens are available
51
+ xflows chains
52
+ xflows tokens --chain-id 1
53
+
54
+ # 3. Get a cross-chain quote
55
+ xflows quote \
56
+ --from-chain 1 --to-chain 56 \
57
+ --from-token 0x0000000000000000000000000000000000000000 \
58
+ --to-token 0x0000000000000000000000000000000000000000 \
59
+ --from-address 0xYourAddress --to-address 0xYourAddress \
60
+ --amount 0.1
61
+
62
+ # 4. Execute the cross-chain transfer
63
+ xflows send \
64
+ --wallet alice \
65
+ --from-chain 1 --to-chain 56 \
66
+ --from-token 0x0000000000000000000000000000000000000000 \
67
+ --to-token 0x0000000000000000000000000000000000000000 \
68
+ --to-address 0xDestAddress \
69
+ --amount 0.1
70
+
71
+ # 5. Track the transaction
72
+ xflows status \
73
+ --hash 0xYourTxHash \
74
+ --from-chain 1 --to-chain 56 \
75
+ --from-token 0x0000000000000000000000000000000000000000 \
76
+ --to-token 0x0000000000000000000000000000000000000000 \
77
+ --from-address 0xYourAddress --to-address 0xDestAddress \
78
+ --amount 0.1
79
+ ```
80
+
81
+ ## How It Works
82
+
83
+ ### Architecture Overview
84
+
85
+ ```
86
+ +------------------+ +---------------------+ +----------------+
87
+ | xflows CLI | ----> | XFlows API (v3) | ----> | Wanchain |
88
+ | | | xflows.wanchain.org | | Storeman Nodes |
89
+ | - Wallet Mgmt | | | | |
90
+ | - Quote | | - /supported/* | | Cross-chain |
91
+ | - Build Tx | | - /quote | | settlement |
92
+ | - Sign & Send | | - /buildTx | | |
93
+ | - Track Status | | - /status | +----------------+
94
+ +------------------+ +---------------------+
95
+ |
96
+ v
97
+ +------------------+
98
+ | EVM RPC Nodes |
99
+ | (publicnode.com) |
100
+ | |
101
+ | Sign & broadcast |
102
+ | transactions |
103
+ +------------------+
104
+ ```
105
+
106
+ The CLI acts as a local orchestrator that:
107
+
108
+ 1. **Manages wallets** locally on disk (`~/.xflows/wallets/`)
109
+ 2. **Queries the XFlows API** for supported assets, quotes, and transaction data
110
+ 3. **Signs transactions** locally using ethers.js (private keys never leave your machine)
111
+ 4. **Broadcasts** signed transactions to EVM chains via public RPC endpoints
112
+ 5. **Tracks** cross-chain transaction status through the XFlows API
113
+
114
+ ### Cross-Chain Transaction Flow
115
+
116
+ When you run `xflows send`, the following steps happen in sequence:
117
+
118
+ ```
119
+ Step 1: Quote Step 2: Build Tx Step 3: Approve (if ERC-20)
120
+ POST /quote ---> POST /buildTx ---> Check allowance
121
+ Get estimated output Get raw tx data If needed, send approve() tx
122
+ Check fees Get approval addr Wait for confirmation
123
+
124
+ Step 4: Sign & Send Step 5: Track
125
+ Apply gas settings ---> POST /status
126
+ Sign with local key Poll until terminal
127
+ Broadcast to RPC statusCode
128
+ Wait for receipt
129
+ ```
130
+
131
+ **Detailed breakdown:**
132
+
133
+ 1. **Quote phase** -- The CLI sends your swap parameters to `POST /quote`. The API evaluates available routes (direct bridge, swap-then-bridge, bridge-then-swap, etc.) and returns the best route with estimated output amount, fees, slippage, and the `workMode` (1-6) that describes which type of cross-chain operation will be performed.
134
+
135
+ 2. **Build phase** -- The same parameters are sent to `POST /buildTx`. The API returns a ready-to-sign transaction object containing `to` (the bridge/router contract address), `data` (ABI-encoded function call), and `value` (native token amount in wei). For non-EVM chains, the API returns chain-specific formats (e.g., `serializedTx` for Solana/Cardano/Sui).
136
+
137
+ 3. **Approval phase** -- If the source token is an ERC-20 (not the native token), the CLI checks whether the bridge contract already has sufficient token allowance. If not, it sends an `approve()` transaction granting unlimited allowance to the bridge contract, then waits for confirmation before proceeding.
138
+
139
+ 4. **Sign & send phase** -- The CLI constructs the final transaction request, applies any gas overrides (custom gas limit, Wanchain minimum gas price), signs it with the local private key, and broadcasts it to the source chain's RPC endpoint. It then waits for the transaction receipt.
140
+
141
+ 5. **Tracking phase** -- After the source chain transaction is confirmed, the cross-chain settlement is handled by Wanchain's Storeman nodes. You can query the status at any time using `xflows status`, which calls `POST /status` and returns the current state of the cross-chain transfer.
142
+
143
+ ### Work Modes
144
+
145
+ The XFlows API determines the optimal route for each swap and indicates it via the `workMode` field:
146
+
147
+ | Mode | Name | Description |
148
+ |------|------|-------------|
149
+ | 1 | Direct Bridge (WanBridge) | Tokens are bridged directly from source to destination chain via WanBridge lock/mint mechanism |
150
+ | 2 | Direct Bridge (QUiX) | Same as mode 1 but uses the QUiX rapid bridge for faster settlement |
151
+ | 3 | Bridge + Swap | Tokens are first bridged to the destination chain, then swapped to the target token on a DEX |
152
+ | 4 | Bridge + Swap + Bridge | Tokens are bridged to Wanchain L1, swapped on Wanchain DEX, then bridged to the destination chain |
153
+ | 5 | Single-chain Swap | No cross-chain transfer; tokens are swapped on the same chain via a DEX aggregator |
154
+ | 6 | Swap + Bridge | Tokens are first swapped on the source chain DEX, then the resulting tokens are bridged to the destination chain |
155
+
156
+ The CLI does not choose the mode -- the XFlows API selects the best route automatically based on available liquidity, fees, and token pair availability.
157
+
158
+ ### Wallet Encryption
159
+
160
+ Wallets are stored as JSON files in `~/.xflows/wallets/`. Two storage modes are supported:
161
+
162
+ **Unencrypted (default):**
163
+ ```json
164
+ {
165
+ "name": "alice",
166
+ "address": "0x...",
167
+ "encrypted": false,
168
+ "privateKey": "0xabc123...",
169
+ "createdAt": "2025-01-01T00:00:00.000Z"
170
+ }
171
+ ```
172
+
173
+ **Encrypted (with `--encrypt`):**
174
+ ```json
175
+ {
176
+ "name": "alice",
177
+ "address": "0x...",
178
+ "encrypted": true,
179
+ "privateKey": "{\"salt\":\"...\",\"iv\":\"...\",\"data\":\"...\"}",
180
+ "createdAt": "2025-01-01T00:00:00.000Z"
181
+ }
182
+ ```
183
+
184
+ The encryption scheme uses:
185
+ - **Key derivation:** scrypt (password + 16-byte random salt -> 32-byte key)
186
+ - **Cipher:** AES-256-CBC with 16-byte random IV
187
+ - **Storage:** salt, IV, and ciphertext are stored as hex strings in a JSON object
188
+
189
+ Each encryption produces different ciphertext due to random salt and IV generation. The password is never stored. When an encrypted wallet is needed for signing (`xflows send`), the `--password` flag must be provided to decrypt the private key in memory.
190
+
191
+ ### Wanchain Gas Price Enforcement
192
+
193
+ Wanchain mainnet (chainId 888) has a protocol-level requirement that the base fee must be at least 1 gwei (1,000,000,000 wei), regardless of what the RPC node reports as the current gas price. The CLI enforces this automatically:
194
+
195
+ ```
196
+ if (chainId == 888) {
197
+ gasPrice = max(reported_gasPrice, 1 gwei)
198
+ }
199
+ ```
200
+
201
+ This prevents transactions from failing due to an underpriced gas fee on the Wanchain network.
202
+
203
+ ### RPC Endpoints
204
+
205
+ The CLI comes pre-configured with public RPC endpoints for 22 chains. Most endpoints are sourced from [publicnode.com](https://publicnode.com), which provides free, rate-limited public RPC access. Wanchain uses its own official endpoints.
206
+
207
+ | Chain | Chain ID | RPC |
208
+ |-------|----------|-----|
209
+ | Ethereum | 1 | ethereum-rpc.publicnode.com |
210
+ | BSC | 56 | bsc-rpc.publicnode.com |
211
+ | Polygon | 137 | polygon-bor-rpc.publicnode.com |
212
+ | Avalanche | 43114 | avalanche-c-chain-rpc.publicnode.com |
213
+ | Arbitrum | 42161 | arbitrum-one-rpc.publicnode.com |
214
+ | Optimism | 10 | optimism-rpc.publicnode.com |
215
+ | Fantom | 250 | fantom-rpc.publicnode.com |
216
+ | Base | 8453 | base-rpc.publicnode.com |
217
+ | Linea | 59144 | linea-rpc.publicnode.com |
218
+ | zkSync Era | 324 | zksync-era-rpc.publicnode.com |
219
+ | Polygon zkEVM | 1101 | polygon-zkevm-rpc.publicnode.com |
220
+ | Gnosis | 100 | gnosis-rpc.publicnode.com |
221
+ | Scroll | 534352 | scroll-rpc.publicnode.com |
222
+ | Mantle | 5000 | mantle-rpc.publicnode.com |
223
+ | Manta Pacific | 169 | manta-pacific-rpc.publicnode.com |
224
+ | Blast | 81457 | blast-rpc.publicnode.com |
225
+ | Boba | 2888 | boba-ethereum-rpc.publicnode.com |
226
+ | Metis | 1088 | metis-rpc.publicnode.com |
227
+ | Celo | 42220 | celo-rpc.publicnode.com |
228
+ | Kava | 2222 | kava-evm-rpc.publicnode.com |
229
+ | Wanchain | 888 | gwan-ssl.wandevs.org:56891 |
230
+ | Wanchain Testnet | 999 | gwan-ssl.wandevs.org:46891 |
231
+
232
+ You can override any RPC endpoint at runtime using the `--rpc` flag on `send` and `wallet balance` commands.
233
+
234
+ Run `xflows rpc` to see the full list at any time.
235
+
236
+ ## Commands
237
+
238
+ ### Wallet Management
239
+
240
+ #### `wallet create` -- Create a new wallet
241
+
242
+ ```bash
243
+ # Generate a new random wallet
244
+ xflows wallet create --name alice
245
+
246
+ # Generate with encryption
247
+ xflows wallet create --name alice --encrypt --password mypassword
248
+
249
+ # Import an existing private key
250
+ xflows wallet create --name alice --private-key 0xabc123...
251
+
252
+ # Import and encrypt
253
+ xflows wallet create --name alice --private-key 0xabc123... --encrypt --password mypassword
254
+ ```
255
+
256
+ | Flag | Required | Description |
257
+ |------|----------|-------------|
258
+ | `--name <name>` | Yes | Wallet name (used as the filename) |
259
+ | `--encrypt` | No | Encrypt the private key with a password |
260
+ | `--password <pw>` | No | Encryption password (prompted interactively if omitted with `--encrypt`) |
261
+ | `--private-key <key>` | No | Import an existing private key instead of generating a new one |
262
+
263
+ #### `wallet list` -- List all saved wallets
264
+
265
+ ```bash
266
+ xflows wallet list
267
+ ```
268
+
269
+ Displays all wallets in `~/.xflows/wallets/` with their address, encryption status, and creation date.
270
+
271
+ #### `wallet show` -- Show wallet details
272
+
273
+ ```bash
274
+ # Unencrypted wallet
275
+ xflows wallet show --name alice
276
+
277
+ # Encrypted wallet (requires password)
278
+ xflows wallet show --name alice --password mypassword
279
+ ```
280
+
281
+ | Flag | Required | Description |
282
+ |------|----------|-------------|
283
+ | `--name <name>` | Yes | Wallet name |
284
+ | `--password <pw>` | No | Password for encrypted wallets |
285
+
286
+ #### `wallet balance` -- Check native token balance
287
+
288
+ ```bash
289
+ # Check ETH balance on Ethereum
290
+ xflows wallet balance --name alice --chain-id 1
291
+
292
+ # Check BNB balance on BSC
293
+ xflows wallet balance --name alice --chain-id 56
294
+
295
+ # Check WAN balance on Wanchain
296
+ xflows wallet balance --name alice --chain-id 888
297
+
298
+ # Encrypted wallet
299
+ xflows wallet balance --name alice --chain-id 1 --password mypassword
300
+
301
+ # Custom RPC
302
+ xflows wallet balance --name alice --chain-id 1 --rpc https://my-rpc.example.com
303
+ ```
304
+
305
+ | Flag | Required | Description |
306
+ |------|----------|-------------|
307
+ | `--name <name>` | Yes | Wallet name |
308
+ | `--chain-id <id>` | Yes | Chain ID to query balance on |
309
+ | `--password <pw>` | No | Password for encrypted wallets |
310
+ | `--rpc <url>` | No | Override default RPC endpoint |
311
+
312
+ #### `wallet delete` -- Delete a wallet
313
+
314
+ ```bash
315
+ # Interactive confirmation
316
+ xflows wallet delete --name alice
317
+
318
+ # Skip confirmation
319
+ xflows wallet delete --name alice --force
320
+ ```
321
+
322
+ ### Query Commands
323
+
324
+ All query commands output raw JSON from the XFlows API, making them easy to pipe into `jq` or consume programmatically.
325
+
326
+ #### `chains` -- List supported chains
327
+
328
+ ```bash
329
+ xflows chains # All chains
330
+ xflows chains --chain-id 1 # Filter by chain ID
331
+ xflows chains --quix # QUiX-supported chains only
332
+ ```
333
+
334
+ #### `tokens` -- List supported tokens
335
+
336
+ ```bash
337
+ xflows tokens # All tokens across all chains
338
+ xflows tokens --chain-id 1 # Tokens on Ethereum only
339
+ xflows tokens --chain-id 56 --quix # QUiX tokens on BSC
340
+ ```
341
+
342
+ #### `pairs` -- List bridgeable token pairs
343
+
344
+ ```bash
345
+ xflows pairs --from-chain 1 # All pairs from Ethereum
346
+ xflows pairs --from-chain 1 --to-chain 56 # Ethereum -> BSC pairs only
347
+ ```
348
+
349
+ #### `bridges` -- List available bridges
350
+
351
+ ```bash
352
+ xflows bridges
353
+ # Returns: wanbridge, quix
354
+ ```
355
+
356
+ #### `dexes` -- List available DEX aggregators
357
+
358
+ ```bash
359
+ xflows dexes
360
+ # Returns: wanchain, rubic
361
+ ```
362
+
363
+ ### Quote
364
+
365
+ Get an estimated output for a cross-chain swap without executing it.
366
+
367
+ ```bash
368
+ xflows quote \
369
+ --from-chain 1 \
370
+ --to-chain 56 \
371
+ --from-token 0x0000000000000000000000000000000000000000 \
372
+ --to-token 0x0000000000000000000000000000000000000000 \
373
+ --from-address 0xYourAddress \
374
+ --to-address 0xYourAddress \
375
+ --amount 1.0
376
+
377
+ # With options
378
+ xflows quote \
379
+ --from-chain 1 --to-chain 56 \
380
+ --from-token 0x0000000000000000000000000000000000000000 \
381
+ --to-token 0x0000000000000000000000000000000000000000 \
382
+ --from-address 0xYourAddress --to-address 0xYourAddress \
383
+ --amount 1.0 \
384
+ --bridge quix \
385
+ --slippage 0.005 \
386
+ --dex rubic
387
+ ```
388
+
389
+ | Flag | Required | Description |
390
+ |------|----------|-------------|
391
+ | `--from-chain <id>` | Yes | Source chain ID |
392
+ | `--to-chain <id>` | Yes | Destination chain ID |
393
+ | `--from-token <addr>` | Yes | Source token address (`0x0...0` for native token) |
394
+ | `--to-token <addr>` | Yes | Destination token address (`0x0...0` for native token) |
395
+ | `--from-address <addr>` | Yes | Sender wallet address |
396
+ | `--to-address <addr>` | Yes | Recipient wallet address |
397
+ | `--amount <amount>` | Yes | Human-readable amount (e.g., `1.5`, `0.001`) |
398
+ | `--bridge <name>` | No | `wanbridge` or `quix` (default: best route) |
399
+ | `--dex <name>` | No | `wanchain` or `rubic` |
400
+ | `--slippage <value>` | No | Max slippage tolerance (e.g., `0.01` = 1%) |
401
+ | `--id <id>` | No | Request identifier for tracking |
402
+
403
+ **Response fields:**
404
+
405
+ | Field | Description |
406
+ |-------|-------------|
407
+ | `amountOut` | Estimated output amount (human-readable) |
408
+ | `amountOutMin` | Minimum output after slippage |
409
+ | `workMode` | Route type (1-6, see [Work Modes](#work-modes)) |
410
+ | `nativeFees[]` | Gas/network fees in the source chain's native token |
411
+ | `tokenFees[]` | Fees deducted from the swap token |
412
+ | `approvalAddress` | Contract that needs ERC-20 approval (if applicable) |
413
+ | `priceImpact` | Estimated price impact |
414
+
415
+ ### Send Transaction
416
+
417
+ Build, sign, and broadcast a cross-chain transaction.
418
+
419
+ ```bash
420
+ # Basic native token transfer
421
+ xflows send \
422
+ --wallet alice \
423
+ --from-chain 1 --to-chain 56 \
424
+ --from-token 0x0000000000000000000000000000000000000000 \
425
+ --to-token 0x0000000000000000000000000000000000000000 \
426
+ --to-address 0xRecipient \
427
+ --amount 0.1
428
+
429
+ # With encrypted wallet
430
+ xflows send \
431
+ --wallet alice --password mypassword \
432
+ --from-chain 1 --to-chain 56 \
433
+ --from-token 0x0000000000000000000000000000000000000000 \
434
+ --to-token 0x0000000000000000000000000000000000000000 \
435
+ --to-address 0xRecipient \
436
+ --amount 0.1
437
+
438
+ # Dry run (preview the transaction without sending)
439
+ xflows send \
440
+ --wallet alice \
441
+ --from-chain 1 --to-chain 56 \
442
+ --from-token 0x0000000000000000000000000000000000000000 \
443
+ --to-token 0x0000000000000000000000000000000000000000 \
444
+ --to-address 0xRecipient \
445
+ --amount 0.1 \
446
+ --dry-run
447
+
448
+ # With all options
449
+ xflows send \
450
+ --wallet alice --password mypassword \
451
+ --from-chain 1 --to-chain 56 \
452
+ --from-token 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 \
453
+ --to-token 0x0000000000000000000000000000000000000000 \
454
+ --to-address 0xRecipient \
455
+ --amount 100 \
456
+ --bridge wanbridge \
457
+ --slippage 0.01 \
458
+ --gas-limit 300000 \
459
+ --rpc https://my-private-rpc.example.com
460
+ ```
461
+
462
+ | Flag | Required | Description |
463
+ |------|----------|-------------|
464
+ | `--wallet <name>` | Yes | Wallet name to use for signing |
465
+ | `--from-chain <id>` | Yes | Source chain ID |
466
+ | `--to-chain <id>` | Yes | Destination chain ID |
467
+ | `--from-token <addr>` | Yes | Source token address |
468
+ | `--to-token <addr>` | Yes | Destination token address |
469
+ | `--to-address <addr>` | Yes | Recipient wallet address |
470
+ | `--amount <amount>` | Yes | Amount to swap |
471
+ | `--password <pw>` | No | Password for encrypted wallet |
472
+ | `--bridge <name>` | No | Force a specific bridge |
473
+ | `--dex <name>` | No | Force a specific DEX |
474
+ | `--slippage <value>` | No | Max slippage tolerance |
475
+ | `--rpc <url>` | No | Override source chain RPC |
476
+ | `--gas-limit <limit>` | No | Custom gas limit |
477
+ | `--dry-run` | No | Build but do not send the transaction |
478
+
479
+ **What happens during `send`:**
480
+
481
+ 1. Loads the wallet from disk (decrypts if needed)
482
+ 2. Fetches a quote from the XFlows API and displays estimated output + fees
483
+ 3. Calls `/buildTx` to get the raw transaction data
484
+ 4. If the source token is ERC-20 and needs approval, sends an `approve()` transaction first
485
+ 5. Constructs the final transaction (with Wanchain gas price enforcement if applicable)
486
+ 6. Signs with the local private key and broadcasts to the source chain RPC
487
+ 7. Waits for on-chain confirmation
488
+ 8. Prints the transaction hash and a ready-to-use `xflows status` command for tracking
489
+
490
+ ### Transaction Status
491
+
492
+ Check the current state of a cross-chain transaction.
493
+
494
+ ```bash
495
+ # One-time status check
496
+ xflows status \
497
+ --hash 0xYourTxHash \
498
+ --from-chain 1 --to-chain 56 \
499
+ --from-token 0x0000000000000000000000000000000000000000 \
500
+ --to-token 0x0000000000000000000000000000000000000000 \
501
+ --from-address 0xSender --to-address 0xReceiver \
502
+ --amount 0.1
503
+
504
+ # Poll until completion (checks every 15 seconds)
505
+ xflows status \
506
+ --hash 0xYourTxHash \
507
+ --from-chain 1 --to-chain 56 \
508
+ --from-token 0x0000000000000000000000000000000000000000 \
509
+ --to-token 0x0000000000000000000000000000000000000000 \
510
+ --from-address 0xSender --to-address 0xReceiver \
511
+ --amount 0.1 \
512
+ --poll --interval 10
513
+ ```
514
+
515
+ | Flag | Required | Description |
516
+ |------|----------|-------------|
517
+ | `--hash <hash>` | Yes | Source chain transaction hash |
518
+ | `--from-chain <id>` | Yes | Source chain ID |
519
+ | `--to-chain <id>` | Yes | Destination chain ID |
520
+ | `--from-token <addr>` | Yes | Source token address |
521
+ | `--to-token <addr>` | Yes | Destination token address |
522
+ | `--from-address <addr>` | Yes | Sender address |
523
+ | `--to-address <addr>` | Yes | Receiver address |
524
+ | `--amount <amount>` | Yes | Amount that was swapped |
525
+ | `--bridge <name>` | No | Bridge that was used |
526
+ | `--poll` | No | Keep polling until a terminal status is reached |
527
+ | `--interval <seconds>` | No | Polling interval in seconds (default: 15) |
528
+
529
+ **Status codes:**
530
+
531
+ | Code | Meaning | Terminal? |
532
+ |------|---------|-----------|
533
+ | 1 | Success -- tokens delivered to destination | Yes |
534
+ | 2 | Failed -- transaction failed | Yes |
535
+ | 3 | Processing -- cross-chain settlement in progress | No |
536
+ | 4 | Refunded -- tokens returned to sender | Yes |
537
+ | 5 | Refunded (alternate) | Yes |
538
+ | 6 | Trusteeship -- requires manual intervention | Yes |
539
+ | 7 | Risk transaction -- flagged by AML checks | Yes |
540
+
541
+ ### RPC List
542
+
543
+ ```bash
544
+ xflows rpc
545
+ ```
546
+
547
+ Displays all pre-configured RPC endpoints and their associated chain IDs.
548
+
549
+ ## Complete Workflow Example
550
+
551
+ A full end-to-end example bridging USDC from Ethereum to BSC:
552
+
553
+ ```bash
554
+ # Step 1: Create an encrypted wallet
555
+ xflows wallet create --name bridge-wallet --encrypt --password s3cret
556
+
557
+ # Step 2: Fund the wallet with ETH (for gas) and USDC on Ethereum
558
+ # (done externally via exchange or another wallet)
559
+
560
+ # Step 3: Check balance
561
+ xflows wallet balance --name bridge-wallet --chain-id 1 --password s3cret
562
+
563
+ # Step 4: Find the USDC token addresses
564
+ xflows tokens --chain-id 1 | jq '.data[] | select(.tokenSymbol == "USDC")'
565
+ xflows tokens --chain-id 56 | jq '.data[] | select(.tokenSymbol == "USDC")'
566
+
567
+ # Step 5: Check available pairs
568
+ xflows pairs --from-chain 1 --to-chain 56
569
+
570
+ # Step 6: Get a quote
571
+ xflows quote \
572
+ --from-chain 1 --to-chain 56 \
573
+ --from-token 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 \
574
+ --to-token 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d \
575
+ --from-address 0xYourAddress --to-address 0xYourAddress \
576
+ --amount 100 \
577
+ --slippage 0.005
578
+
579
+ # Step 7: Execute (the CLI handles ERC-20 approval automatically)
580
+ xflows send \
581
+ --wallet bridge-wallet --password s3cret \
582
+ --from-chain 1 --to-chain 56 \
583
+ --from-token 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 \
584
+ --to-token 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d \
585
+ --to-address 0xYourAddress \
586
+ --amount 100 \
587
+ --slippage 0.005
588
+
589
+ # Step 8: Track (the send command prints this command for you)
590
+ xflows status \
591
+ --hash 0xYourTxHash \
592
+ --from-chain 1 --to-chain 56 \
593
+ --from-token 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 \
594
+ --to-token 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d \
595
+ --from-address 0xYourAddress --to-address 0xYourAddress \
596
+ --amount 100 \
597
+ --poll
598
+ ```
599
+
600
+ ## AI Agent Integration
601
+
602
+ The CLI is designed for non-interactive, single-command execution so that AI agents can use it directly:
603
+
604
+ - Every command accepts all parameters via flags (no interactive prompts needed when flags are provided)
605
+ - All query commands output raw JSON to stdout for easy parsing
606
+ - The `send` command prints a ready-to-use `xflows status` command after execution
607
+ - Wallet encryption is optional -- unencrypted wallets avoid the need for password management
608
+ - The `--dry-run` flag allows previewing transactions without executing them
609
+
610
+ **Example agent workflow:**
611
+
612
+ ```bash
613
+ # Agent creates wallet (no interaction needed)
614
+ xflows wallet create --name agent-wallet
615
+
616
+ # Agent queries available routes
617
+ PAIRS=$(xflows pairs --from-chain 1 --to-chain 56)
618
+
619
+ # Agent gets a quote and parses the output
620
+ QUOTE=$(xflows quote --from-chain 1 --to-chain 56 \
621
+ --from-token 0x0000000000000000000000000000000000000000 \
622
+ --to-token 0x0000000000000000000000000000000000000000 \
623
+ --from-address 0xAgentAddr --to-address 0xAgentAddr \
624
+ --amount 0.01)
625
+
626
+ # Agent executes the transaction
627
+ xflows send --wallet agent-wallet \
628
+ --from-chain 1 --to-chain 56 \
629
+ --from-token 0x0000000000000000000000000000000000000000 \
630
+ --to-token 0x0000000000000000000000000000000000000000 \
631
+ --to-address 0xAgentAddr \
632
+ --amount 0.01
633
+ ```
634
+
635
+ ## Testing
636
+
637
+ ```bash
638
+ # Run all tests
639
+ bun test
640
+
641
+ # Run tests with verbose output
642
+ bun test --verbose
643
+ ```
644
+
645
+ The test suite includes 135 tests covering:
646
+
647
+ - Wallet encryption/decryption (roundtrip, wrong password, security properties)
648
+ - Wallet file management (create, load, list, delete, format validation)
649
+ - API helpers (URL construction, request/response handling, error codes)
650
+ - CLI integration (subprocess tests for all commands)
651
+ - Live API smoke tests (chains, tokens, pairs, bridges, dexes)
652
+ - Live RPC balance queries (Ethereum, BSC, Polygon, Wanchain)
653
+ - Transaction status with mocked responses (all status codes 1-7)
654
+ - Quote/buildTx response parsing (all work modes 1-6)
655
+ - Wanchain gas price enforcement logic
656
+ - Error handling (missing parameters, unknown chains, encrypted wallet errors)
657
+
658
+ ## Project Structure
659
+
660
+ ```
661
+ xflows/
662
+ src/
663
+ index.ts # CLI entry point and all core logic
664
+ index.test.ts # Comprehensive test suite
665
+ package.json
666
+ tsconfig.json
667
+ README.md
668
+ ```
669
+
670
+ **Key dependencies:**
671
+
672
+ | Package | Purpose |
673
+ |---------|---------|
674
+ | `commander` | CLI argument parsing and help generation |
675
+ | `ethers` | Wallet management, transaction signing, RPC interaction |
676
+ | Node.js `crypto` | AES-256-CBC encryption for wallet private keys |
677
+
678
+ **Data storage:**
679
+
680
+ | Path | Content |
681
+ |------|---------|
682
+ | `~/.xflows/wallets/*.json` | Wallet files (plaintext or encrypted private keys) |