@sun-protocol/sun-cli 1.2.2

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 (88) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +579 -0
  3. package/bin/sun +2 -0
  4. package/dist/bin.d.ts +3 -0
  5. package/dist/bin.d.ts.map +1 -0
  6. package/dist/bin.js +83 -0
  7. package/dist/bin.js.map +1 -0
  8. package/dist/commands/contract.d.ts +3 -0
  9. package/dist/commands/contract.d.ts.map +1 -0
  10. package/dist/commands/contract.js +58 -0
  11. package/dist/commands/contract.js.map +1 -0
  12. package/dist/commands/farm.d.ts +3 -0
  13. package/dist/commands/farm.d.ts.map +1 -0
  14. package/dist/commands/farm.js +124 -0
  15. package/dist/commands/farm.js.map +1 -0
  16. package/dist/commands/liquidity.d.ts +3 -0
  17. package/dist/commands/liquidity.d.ts.map +1 -0
  18. package/dist/commands/liquidity.js +742 -0
  19. package/dist/commands/liquidity.js.map +1 -0
  20. package/dist/commands/pair.d.ts +3 -0
  21. package/dist/commands/pair.d.ts.map +1 -0
  22. package/dist/commands/pair.js +38 -0
  23. package/dist/commands/pair.js.map +1 -0
  24. package/dist/commands/pool.d.ts +3 -0
  25. package/dist/commands/pool.d.ts.map +1 -0
  26. package/dist/commands/pool.js +183 -0
  27. package/dist/commands/pool.js.map +1 -0
  28. package/dist/commands/position.d.ts +3 -0
  29. package/dist/commands/position.d.ts.map +1 -0
  30. package/dist/commands/position.js +86 -0
  31. package/dist/commands/position.js.map +1 -0
  32. package/dist/commands/price.d.ts +3 -0
  33. package/dist/commands/price.d.ts.map +1 -0
  34. package/dist/commands/price.js +60 -0
  35. package/dist/commands/price.js.map +1 -0
  36. package/dist/commands/protocol.d.ts +3 -0
  37. package/dist/commands/protocol.d.ts.map +1 -0
  38. package/dist/commands/protocol.js +151 -0
  39. package/dist/commands/protocol.js.map +1 -0
  40. package/dist/commands/sunpump.d.ts +3 -0
  41. package/dist/commands/sunpump.d.ts.map +1 -0
  42. package/dist/commands/sunpump.js +911 -0
  43. package/dist/commands/sunpump.js.map +1 -0
  44. package/dist/commands/swap.d.ts +3 -0
  45. package/dist/commands/swap.d.ts.map +1 -0
  46. package/dist/commands/swap.js +226 -0
  47. package/dist/commands/swap.js.map +1 -0
  48. package/dist/commands/token.d.ts +3 -0
  49. package/dist/commands/token.d.ts.map +1 -0
  50. package/dist/commands/token.js +73 -0
  51. package/dist/commands/token.js.map +1 -0
  52. package/dist/commands/tx.d.ts +3 -0
  53. package/dist/commands/tx.d.ts.map +1 -0
  54. package/dist/commands/tx.js +47 -0
  55. package/dist/commands/tx.js.map +1 -0
  56. package/dist/commands/wallet.d.ts +3 -0
  57. package/dist/commands/wallet.d.ts.map +1 -0
  58. package/dist/commands/wallet.js +52 -0
  59. package/dist/commands/wallet.js.map +1 -0
  60. package/dist/lib/command.d.ts +79 -0
  61. package/dist/lib/command.d.ts.map +1 -0
  62. package/dist/lib/command.js +203 -0
  63. package/dist/lib/command.js.map +1 -0
  64. package/dist/lib/confirm.d.ts +9 -0
  65. package/dist/lib/confirm.d.ts.map +1 -0
  66. package/dist/lib/confirm.js +84 -0
  67. package/dist/lib/confirm.js.map +1 -0
  68. package/dist/lib/context.d.ts +10 -0
  69. package/dist/lib/context.d.ts.map +1 -0
  70. package/dist/lib/context.js +49 -0
  71. package/dist/lib/context.js.map +1 -0
  72. package/dist/lib/output.d.ts +47 -0
  73. package/dist/lib/output.d.ts.map +1 -0
  74. package/dist/lib/output.js +389 -0
  75. package/dist/lib/output.js.map +1 -0
  76. package/dist/lib/sunpump.d.ts +143 -0
  77. package/dist/lib/sunpump.d.ts.map +1 -0
  78. package/dist/lib/sunpump.js +155 -0
  79. package/dist/lib/sunpump.js.map +1 -0
  80. package/dist/lib/tokens.d.ts +40 -0
  81. package/dist/lib/tokens.d.ts.map +1 -0
  82. package/dist/lib/tokens.js +113 -0
  83. package/dist/lib/tokens.js.map +1 -0
  84. package/dist/lib/wallet.d.ts +7 -0
  85. package/dist/lib/wallet.d.ts.map +1 -0
  86. package/dist/lib/wallet.js +97 -0
  87. package/dist/lib/wallet.js.map +1 -0
  88. package/package.json +69 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SUN Protocol
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,579 @@
1
+ # sun-cli
2
+
3
+ ![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)
4
+ ![Network](https://img.shields.io/badge/Network-TRON-red)
5
+ ![Node.js](https://img.shields.io/badge/Node.js-20%2B-339933)
6
+ ![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6)
7
+
8
+ > A CLI for AI-driven and human-operated DeFi workflows on TRON via the **SUN.IO / SUNSWAP** ecosystem.
9
+
10
+ `@sun-protocol/sun-cli` connects your terminal, scripts, or AI agents to SUN.IO. Use it to **query** prices, pools, farms, and history; **quote** swap routes; and **execute** swaps, liquidity ops, and contract calls — all with machine-friendly output for automation.
11
+
12
+ ---
13
+
14
+ ## Table of Contents
15
+
16
+ - [Highlights](#highlights)
17
+ - [Installation](#installation)
18
+ - [Quick Start](#quick-start)
19
+ - [Getting Help](#getting-help)
20
+ - [Built-In Help](#built-in-help)
21
+ - [Shell Completion](#shell-completion)
22
+ - [Configuration](#configuration)
23
+ - [Wallet](#wallet)
24
+ - [Network](#network)
25
+ - [Command Reference](#command-reference)
26
+ - [Wallet & Portfolio](#wallet--portfolio)
27
+ - [Price & Discovery](#price--discovery)
28
+ - [Swap](#swap)
29
+ - [Liquidity](#liquidity)
30
+ - [Protocol & History](#protocol--history)
31
+ - [Generic Contract](#generic-contract)
32
+ - [SunPump](#sunpump)
33
+ - [Global Flags](#global-flags)
34
+ - [Output Formats](#output-formats)
35
+ - [Built-In Token Symbols](#built-in-token-symbols)
36
+ - [Troubleshooting](#troubleshooting)
37
+ - [Security](#security)
38
+ - [Development](#development)
39
+ - [License](#license)
40
+
41
+ ---
42
+
43
+ ## Highlights
44
+
45
+ - **Read anything** — token prices, pools, farms, positions, transaction history, and protocol metrics
46
+ - **Quote and route** — best-route quotes across SUNSwap V1/V2/V3/V4
47
+ - **Execute on-chain** — swaps, liquidity management (V2/V3/V4), and arbitrary contract writes
48
+ - **Meme tokens** — SunPump discovery, one-command token launching, and bonding-curve trading
49
+ - **Automate** — JSON output, field filters, `--dry-run`, and `--yes` for non-interactive use
50
+ - **Read-only out of the box** — no wallet required for queries and quotes
51
+
52
+ ---
53
+
54
+ ## Installation
55
+
56
+ ```bash
57
+ npm install -g @sun-protocol/sun-cli
58
+ ```
59
+
60
+ Requires Node.js **20+**.
61
+
62
+ ---
63
+
64
+ ## Quick Start
65
+
66
+ ### 1. Get a token price
67
+
68
+ ```bash
69
+ $ sun price TRX
70
+ ```
71
+
72
+ ```text
73
+ ✔ Fetching prices...
74
+ ┌───────┬────────────────┐
75
+ │ Token │ Price (USD) │
76
+ ├───────┼────────────────┤
77
+ │ TRX │ 0.301739439813 │
78
+ └───────┴────────────────┘
79
+ ```
80
+
81
+ ### 2. Find the highest-APY pools
82
+
83
+ ```bash
84
+ $ sun pool top-apy --page-size 5
85
+ ```
86
+
87
+ ```text
88
+ ✔ Fetching top APY pools...
89
+ ┌────────────────────────────────────┬────────┬─────────┬────────┬────────────────┐
90
+ │ Pool │ Token0 │ Token1 │ APY │ TVL │
91
+ ├────────────────────────────────────┼────────┼─────────┼────────┼────────────────┤
92
+ │ TXX1i3BWKBuTxUmTERCztGyxSSpRagEcjX │ TRX │ USDCOLD │ 29.13% │ $215,543.763 │
93
+ │ TDJUxxbmxwC5gUHXm2on4ZHJwjzwkBcJ8s │ TEM │ WTRX │ 27.50% │ $168,679.435 │
94
+ │ TVrZ3PjjFGbnp44p6SGASAKrJWAUjCHmCA │ TRX │ ETH │ 14.61% │ $286,068.322 │
95
+ │ TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE │ TRX │ USDT │ 13.60% │ $1,179,854.455 │
96
+ │ TDR7rpU33hToG8qo9i676V56bzcjkpjqox │ WTRX │ SUNDOG │ 8.38% │ $782,507.15 │
97
+ └────────────────────────────────────┴────────┴─────────┴────────┴────────────────┘
98
+ ```
99
+
100
+ ### 3. Quote a swap (no wallet needed)
101
+
102
+ ```bash
103
+ $ sun swap:quote TRX USDT 1000000 --network nile
104
+ ```
105
+
106
+ ```text
107
+ ✔ Fetching quote...
108
+ Found 3 route(s) for swap:
109
+
110
+ Path: TRX → WIN → USDJ → USDT
111
+ Pools: v1 → v2 → old3pool
112
+ Amount In: 1.000000
113
+ Amount Out: 66.028258
114
+ Price Impact: -0.183279
115
+
116
+ (2 more route(s) available, use --all to see them)
117
+ ```
118
+
119
+ ### 4. Execute a swap (wallet required)
120
+
121
+ ```bash
122
+ $ sun swap TRX USDT 1000000 --network nile --yes
123
+ ```
124
+
125
+ ```text
126
+ Swap Preview
127
+ Token In TRX (T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb)
128
+ Token Out USDT (TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf)
129
+ Amount In 1000000
130
+ Slippage 0.50%
131
+ Network nile
132
+
133
+ ✔ Executing swap...
134
+
135
+ Swap executed successfully
136
+ TxID: 4b2ae5186666d30c9f034489813a43ad8edc771f7228759b5e6145a6f134834e
137
+ Tronscan: https://nile.tronscan.org/#/transaction/4b2ae518...
138
+ Route: TRX → WIN → USDJ → USDT
139
+ Amount Out: 66.028258
140
+ Price Impact:-0.183279
141
+ ```
142
+
143
+ > **Note:** Write operations (`swap`, `liquidity`, `contract send`) require a configured wallet. See [Configuration](#configuration).
144
+
145
+ ---
146
+
147
+ ## Getting Help
148
+
149
+ ### Built-In Help
150
+
151
+ Every command level supports `--help` (or `-h`). Use it to discover options, subcommands, and flag aliases without leaving the terminal.
152
+
153
+ | Command | What it shows |
154
+ | -------------------------- | ---------------------------------------------------------------------- |
155
+ | `sun --help` | Top-level overview, global flags, full command list |
156
+ | `sun --version` | Installed CLI version |
157
+ | `sun <group> --help` | Subcommand group help (e.g. `sun pool --help`, `sun liquidity --help`) |
158
+ | `sun <group> <cmd> --help` | Leaf command help with all options (e.g. `sun pool top-apy --help`) |
159
+ | `sun help <command>` | Equivalent to `<command> --help` |
160
+
161
+ ```bash
162
+ sun --help # global flags + command list
163
+ sun pool --help # all pool subcommands
164
+ sun pool top-apy --help # options for `pool top-apy`
165
+ sun help swap # equivalent to `sun swap --help`
166
+ sun --version # print installed version
167
+ ```
168
+
169
+ ### Shell Completion
170
+
171
+ Tab completion is **not bundled**. The two snippets below give you top-level command-name completion in your shell — drop them in your shell rc file and re-source it.
172
+
173
+ **zsh** (`~/.zshrc`):
174
+
175
+ ```zsh
176
+ _sun_cmds() {
177
+ compadd -- wallet price swap swap:quote swap:quote-raw swap:exact-input \
178
+ token pool protocol tx position pair farm liquidity contract help
179
+ }
180
+ compdef _sun_cmds sun
181
+ ```
182
+
183
+ **bash** (`~/.bashrc`):
184
+
185
+ ```bash
186
+ _sun_cmds() {
187
+ local cur="${COMP_WORDS[COMP_CWORD]}"
188
+ COMPREPLY=( $(compgen -W "wallet price swap swap:quote swap:quote-raw \
189
+ swap:exact-input token pool protocol tx position pair farm liquidity \
190
+ contract help" -- "$cur") )
191
+ }
192
+ complete -F _sun_cmds sun
193
+ ```
194
+
195
+ For richer completion (subcommands, flags, token symbols), wrap the CLI with [`omelette`](https://github.com/f/omelette) or [`tabtab`](https://github.com/mklabs/tabtab) — neither is required for normal use.
196
+
197
+ ---
198
+
199
+ ## Configuration
200
+
201
+ ### Wallet
202
+
203
+ Wallets are managed by [`agent-wallet`](https://github.com/BofAI/agent-wallet?tab=readme-ov-file#quick-start) — install and configure it first. Legacy `TRON_PRIVATE_KEY`, `TRON_MNEMONIC`, and `TRON_MNEMONIC_ACCOUNT_INDEX` variables are no longer read.
204
+
205
+ You can override wallet settings per-invocation with these root flags:
206
+
207
+ | Flag | Purpose |
208
+ | ---------------------------------- | -------------------------------- |
209
+ | `-k, --private-key <key>` | One-shot private key |
210
+ | `-m, --mnemonic <phrase>` | One-shot mnemonic |
211
+ | `-i, --mnemonic-account-index <n>` | Mnemonic account index |
212
+ | `-p, --agent-wallet-password <pw>` | Override `AGENT_WALLET_PASSWORD` |
213
+ | `-d, --agent-wallet-dir <dir>` | Override `AGENT_WALLET_DIR` |
214
+
215
+ See [`agent-wallet`](https://github.com/BofAI/agent-wallet?tab=readme-ov-file#quick-start) for file formats and the full set of `AGENT_WALLET_*` options.
216
+
217
+ ### Network
218
+
219
+ | Variable | Purpose | Default |
220
+ | ------------------ | --------------------------------------- | --------- |
221
+ | `TRON_NETWORK` | Target network (`mainnet`, `nile`, …) | `mainnet` |
222
+ | `TRONGRID_API_KEY` | TronGrid API key for higher rate limits | — |
223
+ | `TRON_RPC_URL` | Custom RPC endpoint | — |
224
+
225
+ ```bash
226
+ export TRON_NETWORK=mainnet
227
+ export TRONGRID_API_KEY="<YOUR_KEY>"
228
+ export TRON_RPC_URL=https://your-tron-rpc.example
229
+ ```
230
+
231
+ ---
232
+
233
+ ## Command Reference
234
+
235
+ ### Wallet & Portfolio
236
+
237
+ ```bash
238
+ sun wallet address
239
+ sun wallet balances
240
+ sun wallet balances --owner TYourAddress --tokens TRX,TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t
241
+
242
+ sun position list --owner TYourAddress
243
+ sun position tick <poolAddress>
244
+ sun farm positions --owner TYourAddress
245
+ ```
246
+
247
+ ### Price & Discovery
248
+
249
+ **Prices:**
250
+
251
+ ```bash
252
+ sun price TRX
253
+ sun price USDT
254
+ sun price --address TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t
255
+ ```
256
+
257
+ **Tokens, pools, pairs, farms:**
258
+
259
+ ```bash
260
+ sun token list --protocol V3
261
+ sun token search USDT
262
+
263
+ sun pool list --token TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t
264
+ sun pool search "TRX USDT"
265
+ sun pool top-apy --page-size 10
266
+ sun pool hooks
267
+
268
+ sun pair info --token TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t
269
+ sun farm list
270
+ ```
271
+
272
+ ### Swap
273
+
274
+ **High-level:**
275
+
276
+ ```bash
277
+ sun swap TRX USDT 1000000 --slippage 0.005
278
+ sun -k <private_key> --network nile --yes swap TRX USDT 1000000
279
+ ```
280
+
281
+ **Quote only:**
282
+
283
+ ```bash
284
+ sun swap:quote TRX USDT 1000000
285
+ sun swap:quote TRX USDT 1000000 --all
286
+ ```
287
+
288
+ **Low-level router calls:**
289
+
290
+ ```bash
291
+ sun swap:quote-raw --router <routerAddress> --args '[...]'
292
+ sun swap:exact-input --router <routerAddress> --args '[...]' --value 1000000
293
+ ```
294
+
295
+ A successful broadcast response includes `txid`, route details (when available), and a `tronscanUrl` for the active network.
296
+
297
+ ### Liquidity
298
+
299
+ **V2:**
300
+
301
+ ```bash
302
+ sun liquidity v2:add --token-a TRX --token-b USDT --amount-a 1000000 --amount-b 290000
303
+ sun liquidity v2:remove --token-a TRX --token-b USDT --liquidity 500000
304
+ ```
305
+
306
+ **V3:**
307
+
308
+ ```bash
309
+ sun liquidity v3:mint --token0 TRX --token1 USDT --amount0 1000000
310
+ sun liquidity v3:increase --token-id 123 --amount0 500000
311
+ sun liquidity v3:decrease --token-id 123 --liquidity 1000
312
+ sun liquidity v3:collect --token-id 123
313
+ ```
314
+
315
+ **V4:**
316
+
317
+ ```bash
318
+ sun liquidity v4:mint --token0 TRX --token1 USDT --amount0 1000000
319
+ sun liquidity v4:mint --token0 TRX --token1 USDT --amount0 1000000 --create-pool
320
+ sun liquidity v4:increase --token-id 123 --token0 TRX --token1 USDT --amount0 500000
321
+ sun liquidity v4:decrease --token-id 123 --liquidity 1000 --token0 TRX --token1 USDT
322
+ sun liquidity v4:collect --token-id 123
323
+ sun liquidity v4:info --pm <positionManager> --token-id 123
324
+ ```
325
+
326
+ ### Protocol & History
327
+
328
+ **Protocol-wide analytics:**
329
+
330
+ ```bash
331
+ sun protocol info
332
+ sun protocol vol-history --start 2026-01-01 --end 2026-03-01
333
+ sun protocol users-history --start 2026-01-01 --end 2026-03-01
334
+ sun protocol tx-history --start 2026-01-01 --end 2026-03-01
335
+ sun protocol pools-history --start 2026-01-01 --end 2026-03-01
336
+ sun protocol liq-history --start 2026-01-01 --end 2026-03-01
337
+ ```
338
+
339
+ **Per-pool and transaction history:**
340
+
341
+ ```bash
342
+ sun pool vol-history <poolAddress> --start 2026-01-01 --end 2026-03-01
343
+ sun pool liq-history <poolAddress> --start 2026-01-01 --end 2026-03-01
344
+ sun tx scan --type swap --token TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t --start 2026-01-01
345
+ ```
346
+
347
+ ### Generic Contract
348
+
349
+ Read or write to any TRON smart contract:
350
+
351
+ ```bash
352
+ sun contract read <contractAddress> balanceOf --args '["TYourAddress"]'
353
+ sun contract send <contractAddress> transfer --args '["TRecipient","1000000"]' --value 0
354
+ ```
355
+
356
+ `contract send` returns a `tronscanUrl` on successful broadcast.
357
+
358
+ ### SunPump
359
+
360
+ Access to SunPump — read-only API for discovery (token launches, trending lists,
361
+ holder portfolios), token creation via the agent endpoint (`launch`), and
362
+ on-chain trade commands (`buy`/`sell`/`quote-buy`/`quote-sell`/`state`) that talk
363
+ to the bonding-curve contract through `sun-kit`. Read-only API calls and `launch`
364
+ need no wallet; trade commands do.
365
+
366
+ SunPump is **mainnet only** — both the API host (`https://api-v2.sunpump.meme/pump-api`)
367
+ and the on-chain bonding-curve contract. Passing `--network nile` (or any non-mainnet
368
+ value) to a `sunpump` subcommand will fail fast.
369
+
370
+ ```bash
371
+ sun sunpump token king-of-hill # current king-of-the-hill token
372
+ sun sunpump token list --size 20 --sort marketCap,desc
373
+ sun sunpump token search <keyword> --size 10
374
+ sun sunpump token get <contractAddress> # token detail
375
+ sun sunpump token holders <contractAddress> --size 20
376
+ sun sunpump token ranking --type MARKET_CAP --size 10 # also: VOLUME_24H, PRICE_CHANGE_24H
377
+
378
+ sun sunpump tx token <contractAddress> --size 20 # swap history for a token
379
+ sun sunpump tx user <walletAddress> --size 20 # swap history for a wallet
380
+
381
+ sun sunpump portfolio <walletAddress> --include-zero
382
+ ```
383
+
384
+ Launch a new token through the SunPump agent endpoint (server-side creation —
385
+ no wallet needed; asks for confirmation, `--yes` to skip, `--dry-run` to preview):
386
+
387
+ ```bash
388
+ sun sunpump launch --name MyToken --symbol MTK \
389
+ --description "my meme token" --image ./logo.png \
390
+ --twitter-url https://x.com/mytoken --website-url https://mytoken.xyz
391
+ ```
392
+
393
+ `--image <path>` reads a local file and sends it as base64; pass `--image-base64`
394
+ to supply the encoded string directly. On success the CLI prints the new token's
395
+ contract address and creation tx hash.
396
+
397
+ Trade on the bonding curve (requires a wallet; pre-launch tokens only — once a token
398
+ migrates to SunSwap, use `sun swap` instead):
399
+
400
+ ```bash
401
+ sun sunpump state <contractAddress> # 0 NOT_EXIST · 1 TRADING · 2 READY_TO_LAUNCH · 3 LAUNCHED
402
+ sun sunpump quote-buy <contractAddress> --trx 10 # preview, no tx
403
+ sun sunpump quote-sell <contractAddress> --amount 1000
404
+
405
+ sun sunpump buy <contractAddress> --trx 10 # spend 10 TRX
406
+ sun sunpump buy <contractAddress> --trx 10 --slippage 0.1 # 10% slippage
407
+ sun sunpump sell <contractAddress> --amount 1000 # sell 1000 tokens (assumes 18 decimals)
408
+ sun sunpump sell <contractAddress> --amount 1000 --decimals 6 # override token decimals
409
+ sun --dry-run sunpump buy <contractAddress> --trx 10 # show params without sending
410
+ ```
411
+
412
+ `--trx` and `--amount` accept decimal values; CLI scales by TRX-Sun (1e6) and token
413
+ decimals (default 18) before calling the contract. Default slippage is 5% (meme tokens
414
+ move fast); pass `--slippage 0.005` for 0.5% or `--min-out <raw>` for an exact floor in
415
+ base units.
416
+
417
+ Endpoints requiring a signed message (`favors`) accept `--user-address`,
418
+ `--signature`, `--signed-message` flags. Override the base URL with
419
+ `SUNPUMP_API_BASE_URL` only when you have a custom mainnet-compatible host.
420
+
421
+
422
+ ---
423
+
424
+ ## Global Flags
425
+
426
+ Inherited by every subcommand:
427
+
428
+ | Flag | Description |
429
+ | ---------------------------------- | -------------------------------------- |
430
+ | `--output <format>` | Output format: `table`, `json`, `tsv` |
431
+ | `--json` | Shortcut for `--output json` |
432
+ | `--fields <list>` | Comma-separated field filter |
433
+ | `--network <network>` | Override `TRON_NETWORK` |
434
+ | `-k, --private-key <key>` | One-shot private key |
435
+ | `-m, --mnemonic <phrase>` | One-shot mnemonic |
436
+ | `-i, --mnemonic-account-index <n>` | Mnemonic account index |
437
+ | `-p, --agent-wallet-password <pw>` | Override `AGENT_WALLET_PASSWORD` |
438
+ | `-d, --agent-wallet-dir <dir>` | Override `AGENT_WALLET_DIR` |
439
+ | `-y, --yes` | Skip confirmation prompts |
440
+ | `--dry-run` | Print intent without sending the write |
441
+
442
+ **Examples:**
443
+
444
+ ```bash
445
+ sun --json price TRX
446
+ sun --output tsv pool top-apy --page-size 10
447
+ sun --fields address,network wallet address
448
+ sun --json --fields txid,tronscanUrl swap TRX USDT 1000000
449
+ sun --dry-run contract send TContract transfer --args '["TRecipient","1000000"]'
450
+ ```
451
+
452
+ ---
453
+
454
+ ## Output Formats
455
+
456
+ | Mode | When to use |
457
+ | ------------------- | -------------------------------------------- |
458
+ | `table` _(default)_ | Human-friendly terminal output |
459
+ | `json` | Machine-readable JSON for scripts and agents |
460
+ | `tsv` | Tab-separated values for shell pipelines |
461
+
462
+ ```bash
463
+ sun pool top-apy --page-size 5
464
+ sun --json wallet address
465
+ sun --output tsv token list --protocol V3
466
+ ```
467
+
468
+ ---
469
+
470
+ ## Built-In Token Symbols
471
+
472
+ Most commands accept these symbols anywhere a token is expected.
473
+
474
+ | Symbol | Address | Decimals |
475
+ | ------ | ------------------------------------ | -------- |
476
+ | `TRX` | `T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb` | 6 |
477
+ | `WTRX` | `TNUC9Qb1rRpS5CbWLmNMxXBjyFoydXjWFR` | 6 |
478
+ | `USDT` | `TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t` | 6 |
479
+ | `USDC` | `TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8` | 6 |
480
+ | `USDD` | `TPYmHEhy5n8TCEfYGqW2rPxsghSfzghPDn` | 18 |
481
+ | `SUN` | `TSSMHYeV2uE9qYH95DqyoCuNCzEL1NvU3S` | 18 |
482
+ | `JST` | `TCFLL5dx5ZJdKnWuesXxi1VPwjLVmWZZy9` | 18 |
483
+ | `BTT` | `TAFjULxiVgT4qWk6UZwjqwZXTSaGaqnVp4` | 18 |
484
+ | `WIN` | `TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7` | 6 |
485
+
486
+ Symbols and raw addresses are interchangeable:
487
+
488
+ ```bash
489
+ sun swap TRX USDT 1000000
490
+ sun swap T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t 1000000
491
+ ```
492
+
493
+ ---
494
+
495
+ ## Troubleshooting
496
+
497
+ Quick lookup for the most common errors:
498
+
499
+ | Error | Category | Jump to |
500
+ | ------------------------ | ------------ | ----------------------------------------------- |
501
+ | `unknown command 'nile'` | CLI parsing | [▸ Flag placement](#error-unknown-command-nile) |
502
+ | `No wallet configured` | Wallet setup | [▸ Wallet sources](#error-no-wallet-configured) |
503
+ | `Swap failed` | Execution | [▸ Swap diagnostics](#error-swap-failed) |
504
+
505
+ ### Error: `unknown command 'nile'`
506
+
507
+ > **Category:** CLI argument parsing — root flags placed after the subcommand.
508
+
509
+ Root flags must come **before** the subcommand:
510
+
511
+ ```bash
512
+ sun --network nile swap TRX USDT 1000000
513
+ ```
514
+
515
+ When invoking through npm, separate args with `--`:
516
+
517
+ ```bash
518
+ npm run start -- --network nile swap TRX USDT 1000000
519
+ ```
520
+
521
+ ### Error: `No wallet configured`
522
+
523
+ > **Category:** Wallet configuration — no credential source detected.
524
+
525
+ Set exactly one wallet source:
526
+
527
+ - `AGENT_WALLET_PRIVATE_KEY`
528
+ - `AGENT_WALLET_MNEMONIC`
529
+ - `AGENT_WALLET_PASSWORD`
530
+
531
+ …or pass the equivalent root flag (`-k`, `-m`, `-p`) for that invocation.
532
+
533
+ ### Error: `Swap failed`
534
+
535
+ > **Category:** Transaction execution — broadcast or routing rejected.
536
+
537
+ Common causes:
538
+
539
+ - Wallet not configured
540
+ - Unsupported token symbol
541
+ - Insufficient balance
542
+ - RPC or router API failure
543
+ - Stale or invalid route parameters
544
+
545
+ Run `swap:quote` first, then re-run with `--yes` once the quote looks right.
546
+
547
+ ---
548
+
549
+ ## Security
550
+
551
+ - Treat `AGENT_WALLET_PRIVATE_KEY`, `AGENT_WALLET_MNEMONIC`, and `AGENT_WALLET_PASSWORD` as secrets.
552
+ - Prefer environment variables over CLI flags — shell history and process lists can leak secrets.
553
+ - Use a dedicated automation wallet, not your treasury wallet.
554
+ - Use `--dry-run` before any high-value write.
555
+ - Verify token addresses carefully when not using built-in symbols.
556
+ - Quotes are estimates, not guarantees — markets move.
557
+
558
+ ---
559
+
560
+ ## Development
561
+
562
+ ```bash
563
+ npm install
564
+ npm run build
565
+ npm test
566
+ npm run lint
567
+ ```
568
+
569
+ Run from source:
570
+
571
+ ```bash
572
+ npm run dev -- price TRX
573
+ ```
574
+
575
+ ---
576
+
577
+ ## License
578
+
579
+ MIT
package/bin/sun ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require('../dist/bin.js')
package/dist/bin.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import 'dotenv/config';
3
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAEA,OAAO,eAAe,CAAA"}
package/dist/bin.js ADDED
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ require("dotenv/config");
5
+ const commander_1 = require("commander");
6
+ const output_1 = require("./lib/output");
7
+ const confirm_1 = require("./lib/confirm");
8
+ const command_1 = require("./lib/command");
9
+ const wallet_1 = require("./commands/wallet");
10
+ const price_1 = require("./commands/price");
11
+ const swap_1 = require("./commands/swap");
12
+ const token_1 = require("./commands/token");
13
+ const pool_1 = require("./commands/pool");
14
+ const protocol_1 = require("./commands/protocol");
15
+ const tx_1 = require("./commands/tx");
16
+ const position_1 = require("./commands/position");
17
+ const pair_1 = require("./commands/pair");
18
+ const farm_1 = require("./commands/farm");
19
+ const liquidity_1 = require("./commands/liquidity");
20
+ const contract_1 = require("./commands/contract");
21
+ const sunpump_1 = require("./commands/sunpump");
22
+ const { version } = require('../package.json');
23
+ const program = new commander_1.Command();
24
+ program
25
+ .name('sun')
26
+ .description('CLI for SUN.IO / SUNSWAP on TRON — for humans and AI agents')
27
+ .version(version)
28
+ .option('--output <format>', 'Output format: table, json, tsv', 'table')
29
+ .option('--json', 'Shorthand for --output json', false)
30
+ .option('--fields <fields>', 'Comma-separated fields to include in output')
31
+ .option('--network <network>', 'TRON network: mainnet, nile, shasta', process.env.TRON_NETWORK || 'mainnet')
32
+ .option('-k, --private-key <key>', 'Wallet private key for this invocation only')
33
+ .option('-m, --mnemonic <phrase>', 'Wallet mnemonic for this invocation only')
34
+ .option('-i, --mnemonic-account-index <index>', 'Wallet mnemonic account index for this invocation only')
35
+ .option('-p, --agent-wallet-password <password>', 'Agent wallet password for this invocation only')
36
+ .option('-d, --agent-wallet-dir <dir>', 'Agent wallet directory for this invocation only')
37
+ .option('-y, --yes', 'Skip confirmation prompts', false)
38
+ .option('--dry-run', 'Show what would be executed without actually running it', false)
39
+ .hook('preAction', (_thisCmd, _actionCmd) => {
40
+ const rootOpts = program.opts();
41
+ if (rootOpts.output && rootOpts.output !== 'table')
42
+ (0, output_1.setOutputFormat)(rootOpts.output);
43
+ if (rootOpts.json)
44
+ (0, output_1.setJsonMode)(true);
45
+ if (rootOpts.fields)
46
+ (0, output_1.setFields)(rootOpts.fields.split(',').map((f) => f.trim()));
47
+ if (rootOpts.yes)
48
+ (0, confirm_1.setAutoConfirm)(true);
49
+ if (rootOpts.dryRun)
50
+ (0, command_1.setDryRun)(true);
51
+ if (rootOpts.network)
52
+ process.env.TRON_NETWORK = rootOpts.network;
53
+ if (rootOpts.privateKey)
54
+ process.env.AGENT_WALLET_PRIVATE_KEY = rootOpts.privateKey;
55
+ if (rootOpts.mnemonic)
56
+ process.env.AGENT_WALLET_MNEMONIC = rootOpts.mnemonic;
57
+ if (rootOpts.mnemonicAccountIndex) {
58
+ process.env.AGENT_WALLET_MNEMONIC_ACCOUNT_INDEX = rootOpts.mnemonicAccountIndex;
59
+ }
60
+ if (rootOpts.agentWalletPassword) {
61
+ process.env.AGENT_WALLET_PASSWORD = rootOpts.agentWalletPassword;
62
+ }
63
+ if (rootOpts.agentWalletDir)
64
+ process.env.AGENT_WALLET_DIR = rootOpts.agentWalletDir;
65
+ });
66
+ (0, wallet_1.registerWalletCommands)(program);
67
+ (0, price_1.registerPriceCommand)(program);
68
+ (0, swap_1.registerSwapCommands)(program);
69
+ (0, token_1.registerTokenCommands)(program);
70
+ (0, pool_1.registerPoolCommands)(program);
71
+ (0, protocol_1.registerProtocolCommands)(program);
72
+ (0, tx_1.registerTxCommands)(program);
73
+ (0, position_1.registerPositionCommands)(program);
74
+ (0, pair_1.registerPairCommands)(program);
75
+ (0, farm_1.registerFarmCommands)(program);
76
+ (0, liquidity_1.registerLiquidityCommands)(program);
77
+ (0, contract_1.registerContractCommands)(program);
78
+ (0, sunpump_1.registerSunpumpCommands)(program);
79
+ program.parseAsync(process.argv).catch((err) => {
80
+ process.stderr.write(`${err.message}\n`);
81
+ process.exit(1);
82
+ });
83
+ //# sourceMappingURL=bin.js.map