@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
@@ -0,0 +1,742 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerLiquidityCommands = registerLiquidityCommands;
4
+ const context_1 = require("../lib/context");
5
+ const command_1 = require("../lib/command");
6
+ const output_1 = require("../lib/output");
7
+ const tokens_1 = require("../lib/tokens");
8
+ const sun_kit_1 = require("@sun-protocol/sun-kit");
9
+ const V2_ROUTERS = {
10
+ mainnet: sun_kit_1.SUNSWAP_V2_MAINNET_ROUTER,
11
+ nile: sun_kit_1.SUNSWAP_V2_NILE_ROUTER,
12
+ };
13
+ const V2_FACTORIES = {
14
+ mainnet: sun_kit_1.SUNSWAP_V2_MAINNET_FACTORY,
15
+ nile: sun_kit_1.SUNSWAP_V2_NILE_FACTORY,
16
+ };
17
+ const V3_POSITION_MANAGERS = {
18
+ mainnet: sun_kit_1.SUNSWAP_V3_MAINNET_POSITION_MANAGER,
19
+ nile: sun_kit_1.SUNSWAP_V3_NILE_POSITION_MANAGER,
20
+ };
21
+ function getV2Router(network, override) {
22
+ if (override)
23
+ return override;
24
+ const router = V2_ROUTERS[network];
25
+ if (!router) {
26
+ throw new Error(`V2 router not configured for network: ${network}. Use --router to specify.`);
27
+ }
28
+ return router;
29
+ }
30
+ function getV3PositionManager(network, override) {
31
+ if (override)
32
+ return override;
33
+ const pm = V3_POSITION_MANAGERS[network];
34
+ if (!pm) {
35
+ throw new Error(`V3 position manager not configured for network: ${network}. Use --pm to specify.`);
36
+ }
37
+ return pm;
38
+ }
39
+ function toWTRXIfNative(tokenAddress, network) {
40
+ if (tokenAddress === sun_kit_1.TRX_ADDRESS) {
41
+ return network === 'nile' ? sun_kit_1.WTRX_NILE : sun_kit_1.WTRX_MAINNET;
42
+ }
43
+ return tokenAddress;
44
+ }
45
+ function getWTRX(network) {
46
+ return network === 'nile' ? sun_kit_1.WTRX_NILE : sun_kit_1.WTRX_MAINNET;
47
+ }
48
+ function getLookupToken(token, network) {
49
+ return token === sun_kit_1.TRX_ADDRESS ? getWTRX(network) : token;
50
+ }
51
+ async function getV2PairReserves(network, tokenA, tokenB) {
52
+ const tronWeb = await (0, sun_kit_1.createReadonlyTronWeb)(network);
53
+ const factoryAddress = V2_FACTORIES[network];
54
+ if (!factoryAddress) {
55
+ throw new Error(`V2 factory not configured for network: ${network}`);
56
+ }
57
+ const lookupA = getLookupToken(tokenA, network);
58
+ const lookupB = getLookupToken(tokenB, network);
59
+ const factory = await tronWeb.contract(sun_kit_1.SUNSWAP_V2_FACTORY_MIN_ABI, factoryAddress);
60
+ const pairHex = await factory.getPair(lookupA, lookupB).call();
61
+ const pairBase58 = tronWeb.address.fromHex(pairHex);
62
+ const zeroBase58 = tronWeb.address.fromHex('410000000000000000000000000000000000000000');
63
+ if (!pairBase58 || pairBase58 === zeroBase58) {
64
+ return { reserveA: '0', reserveB: '0', pairExists: false };
65
+ }
66
+ const pair = await tronWeb.contract(sun_kit_1.SUNSWAP_V2_PAIR_MIN_ABI, pairBase58);
67
+ const reserves = await pair.getReserves().call();
68
+ const token0Hex = await pair.token0().call();
69
+ const token0 = tronWeb.address.fromHex(token0Hex);
70
+ const reserve0 = (reserves._reserve0 ?? reserves[0]).toString();
71
+ const reserve1 = (reserves._reserve1 ?? reserves[1]).toString();
72
+ const reserveA = token0 === lookupA ? reserve0 : reserve1;
73
+ const reserveB = token0 === lookupB ? reserve0 : reserve1;
74
+ return { reserveA, reserveB, pairExists: true };
75
+ }
76
+ function calculateOptimalAmount(providedAmount, providedReserve, otherReserve) {
77
+ const amount = BigInt(providedAmount);
78
+ const rProvided = BigInt(providedReserve);
79
+ const rOther = BigInt(otherReserve);
80
+ if (rProvided === BigInt(0) || rOther === BigInt(0)) {
81
+ throw new Error('Pool has no liquidity. Please provide both amounts for initial liquidity.');
82
+ }
83
+ return ((amount * rOther) / rProvided).toString();
84
+ }
85
+ function registerLiquidityCommands(program) {
86
+ const liq = program.command('liquidity').description('V2, V3, and V4 liquidity management');
87
+ // ---------------------------------------------------------------------------
88
+ // V2
89
+ // ---------------------------------------------------------------------------
90
+ liq
91
+ .command('v2:add')
92
+ .description('Add liquidity to a SUNSWAP V2 pool')
93
+ .option('--router <address>', 'V2 router contract address (auto-detected by network)')
94
+ .requiredOption('--token-a <tokenOrAddress>', 'Token A (symbol like TRX/USDT or address)')
95
+ .requiredOption('--token-b <tokenOrAddress>', 'Token B (symbol like TRX/USDT or address)')
96
+ .option('--amount-a <raw>', 'Desired amount of token A (raw units)')
97
+ .option('--amount-b <raw>', 'Desired amount of token B (raw units)')
98
+ .option('--min-a <raw>', 'Minimum amount of token A')
99
+ .option('--min-b <raw>', 'Minimum amount of token B')
100
+ .option('--to <address>', 'Recipient for LP tokens (default: active wallet)')
101
+ .option('--deadline <timestamp>', 'Unix timestamp deadline')
102
+ .option('--abi <json>', 'Optional router ABI as JSON array')
103
+ .action(async (opts) => {
104
+ const network = (0, context_1.getNetwork)();
105
+ const router = getV2Router(network, opts.router);
106
+ let tokenA, tokenB;
107
+ try {
108
+ tokenA = (0, tokens_1.resolveTokenAddress)(opts.tokenA, network);
109
+ tokenB = (0, tokens_1.resolveTokenAddress)(opts.tokenB, network);
110
+ }
111
+ catch (err) {
112
+ console.error(err.message);
113
+ process.exitCode = 1;
114
+ return;
115
+ }
116
+ if (!opts.amountA && !opts.amountB) {
117
+ console.error('Error: At least one of --amount-a or --amount-b is required');
118
+ process.exitCode = 1;
119
+ return;
120
+ }
121
+ let amountA = opts.amountA;
122
+ let amountB = opts.amountB;
123
+ if (!amountA || !amountB) {
124
+ try {
125
+ const reserves = await (0, output_1.withSpinner)('Fetching pool reserves...', () => getV2PairReserves(network, tokenA, tokenB));
126
+ if (!reserves.pairExists) {
127
+ console.error('Error: Pool does not exist. Please provide both --amount-a and --amount-b for initial liquidity.');
128
+ process.exitCode = 1;
129
+ return;
130
+ }
131
+ if (!amountA) {
132
+ amountA = calculateOptimalAmount(amountB, reserves.reserveB, reserves.reserveA);
133
+ }
134
+ else {
135
+ amountB = calculateOptimalAmount(amountA, reserves.reserveA, reserves.reserveB);
136
+ }
137
+ }
138
+ catch (err) {
139
+ console.error(`Error calculating optimal amount: ${err.message}`);
140
+ process.exitCode = 1;
141
+ return;
142
+ }
143
+ }
144
+ const tokenADisplay = (0, tokens_1.getSymbolOrAddress)(tokenA, network);
145
+ const tokenBDisplay = (0, tokens_1.getSymbolOrAddress)(tokenB, network);
146
+ await (0, command_1.writeAction)({
147
+ title: 'V2 Add Liquidity',
148
+ summary: {
149
+ Router: router,
150
+ 'Token A': `${tokenADisplay} (${tokenA})`,
151
+ 'Token B': `${tokenBDisplay} (${tokenB})`,
152
+ 'Amount A': amountA,
153
+ 'Amount B': amountB,
154
+ Network: network,
155
+ },
156
+ confirmMsg: 'Add V2 liquidity?',
157
+ spinnerLabel: 'Adding V2 liquidity...',
158
+ errorLabel: 'V2 add liquidity failed',
159
+ execute: (kit) => kit.addLiquidityV2({
160
+ network,
161
+ routerAddress: router,
162
+ abi: opts.abi ? JSON.parse(opts.abi) : undefined,
163
+ tokenA,
164
+ tokenB,
165
+ amountADesired: amountA,
166
+ amountBDesired: amountB,
167
+ amountAMin: opts.minA,
168
+ amountBMin: opts.minB,
169
+ to: opts.to,
170
+ deadline: opts.deadline,
171
+ }),
172
+ });
173
+ });
174
+ liq
175
+ .command('v2:remove')
176
+ .description('Remove liquidity from a SUNSWAP V2 pool')
177
+ .option('--router <address>', 'V2 router contract address (auto-detected by network)')
178
+ .requiredOption('--token-a <tokenOrAddress>', 'Token A (symbol like TRX/USDT or address)')
179
+ .requiredOption('--token-b <tokenOrAddress>', 'Token B (symbol like TRX/USDT or address)')
180
+ .requiredOption('--liquidity <raw>', 'LP tokens to burn')
181
+ .option('--min-a <raw>', 'Minimum amount of token A to receive')
182
+ .option('--min-b <raw>', 'Minimum amount of token B to receive')
183
+ .option('--to <address>', 'Recipient of underlying tokens')
184
+ .option('--deadline <timestamp>', 'Unix timestamp deadline')
185
+ .option('--abi <json>', 'Optional router ABI as JSON array')
186
+ .action(async (opts) => {
187
+ const network = (0, context_1.getNetwork)();
188
+ const router = getV2Router(network, opts.router);
189
+ let tokenA, tokenB;
190
+ try {
191
+ tokenA = (0, tokens_1.resolveTokenAddress)(opts.tokenA, network);
192
+ tokenB = (0, tokens_1.resolveTokenAddress)(opts.tokenB, network);
193
+ }
194
+ catch (err) {
195
+ console.error(err.message);
196
+ process.exitCode = 1;
197
+ return;
198
+ }
199
+ const tokenADisplay = (0, tokens_1.getSymbolOrAddress)(tokenA, network);
200
+ const tokenBDisplay = (0, tokens_1.getSymbolOrAddress)(tokenB, network);
201
+ await (0, command_1.writeAction)({
202
+ title: 'V2 Remove Liquidity',
203
+ summary: {
204
+ Router: router,
205
+ 'Token A': `${tokenADisplay} (${tokenA})`,
206
+ 'Token B': `${tokenBDisplay} (${tokenB})`,
207
+ 'LP Tokens': opts.liquidity,
208
+ Network: network,
209
+ },
210
+ confirmMsg: 'Remove V2 liquidity?',
211
+ spinnerLabel: 'Removing V2 liquidity...',
212
+ errorLabel: 'V2 remove liquidity failed',
213
+ execute: (kit) => kit.removeLiquidityV2({
214
+ network,
215
+ routerAddress: router,
216
+ abi: opts.abi ? JSON.parse(opts.abi) : undefined,
217
+ tokenA,
218
+ tokenB,
219
+ liquidity: opts.liquidity,
220
+ amountAMin: opts.minA,
221
+ amountBMin: opts.minB,
222
+ to: opts.to,
223
+ deadline: opts.deadline,
224
+ }),
225
+ });
226
+ });
227
+ // ---------------------------------------------------------------------------
228
+ // V3
229
+ // ---------------------------------------------------------------------------
230
+ liq
231
+ .command('v3:mint')
232
+ .description('Mint a new SUNSWAP V3 concentrated liquidity position')
233
+ .option('--pm <address>', 'V3 NonfungiblePositionManager address (auto-detected by network)')
234
+ .requiredOption('--token0 <tokenOrAddress>', 'Token0 (symbol like TRX/USDT or address)')
235
+ .requiredOption('--token1 <tokenOrAddress>', 'Token1 (symbol like TRX/USDT or address)')
236
+ .option('--fee <n>', 'Pool fee tier (default: 3000)')
237
+ .option('--tick-lower <n>', 'Lower tick (auto-computed if omitted)')
238
+ .option('--tick-upper <n>', 'Upper tick (auto-computed if omitted)')
239
+ .option('--amount0 <raw>', 'Desired amount of token0')
240
+ .option('--amount1 <raw>', 'Desired amount of token1')
241
+ .option('--min0 <raw>', 'Minimum amount of token0')
242
+ .option('--min1 <raw>', 'Minimum amount of token1')
243
+ .option('--recipient <address>', 'NFT recipient')
244
+ .option('--deadline <timestamp>', 'Unix timestamp deadline')
245
+ .option('--abi <json>', 'Optional PM ABI as JSON array')
246
+ .action(async (opts) => {
247
+ const network = (0, context_1.getNetwork)();
248
+ const pm = getV3PositionManager(network, opts.pm);
249
+ let token0Input, token1Input;
250
+ try {
251
+ token0Input = (0, tokens_1.resolveTokenAddress)(opts.token0, network);
252
+ token1Input = (0, tokens_1.resolveTokenAddress)(opts.token1, network);
253
+ }
254
+ catch (err) {
255
+ console.error(err.message);
256
+ process.exitCode = 1;
257
+ return;
258
+ }
259
+ const token0 = toWTRXIfNative(token0Input, network);
260
+ const token1 = toWTRXIfNative(token1Input, network);
261
+ if (!opts.amount0 && !opts.amount1) {
262
+ console.error('Error: At least one of --amount0 or --amount1 is required');
263
+ process.exitCode = 1;
264
+ return;
265
+ }
266
+ const token0Display = (0, tokens_1.getSymbolOrAddress)(token0Input, network);
267
+ const token1Display = (0, tokens_1.getSymbolOrAddress)(token1Input, network);
268
+ const token0Note = token0 !== token0Input ? ` → WTRX` : '';
269
+ const token1Note = token1 !== token1Input ? ` → WTRX` : '';
270
+ const tickRange = opts.tickLower && opts.tickUpper ? `[${opts.tickLower}, ${opts.tickUpper}]` : '(auto)';
271
+ await (0, command_1.writeAction)({
272
+ title: 'V3 Mint Position',
273
+ summary: {
274
+ 'Position Manager': pm,
275
+ Token0: `${token0Display}${token0Note} (${token0})`,
276
+ Token1: `${token1Display}${token1Note} (${token1})`,
277
+ Fee: opts.fee || '3000 (default)',
278
+ 'Tick Range': tickRange,
279
+ Amount0: opts.amount0 || '(auto)',
280
+ Amount1: opts.amount1 || '(auto)',
281
+ Network: network,
282
+ },
283
+ confirmMsg: 'Mint V3 position?',
284
+ spinnerLabel: 'Minting V3 position...',
285
+ errorLabel: 'V3 mint failed',
286
+ execute: (kit) => kit.mintPositionV3({
287
+ network,
288
+ positionManagerAddress: pm,
289
+ abi: opts.abi ? JSON.parse(opts.abi) : undefined,
290
+ token0,
291
+ token1,
292
+ fee: opts.fee ? parseInt(opts.fee) : undefined,
293
+ tickLower: opts.tickLower ? parseInt(opts.tickLower) : undefined,
294
+ tickUpper: opts.tickUpper ? parseInt(opts.tickUpper) : undefined,
295
+ amount0Desired: opts.amount0,
296
+ amount1Desired: opts.amount1,
297
+ amount0Min: opts.min0,
298
+ amount1Min: opts.min1,
299
+ recipient: opts.recipient,
300
+ deadline: opts.deadline,
301
+ }),
302
+ summarizeResult: (result) => {
303
+ const out = {};
304
+ if (result?.computedTicks) {
305
+ out['Tick Lower'] = result.computedTicks.tickLower;
306
+ out['Tick Upper'] = result.computedTicks.tickUpper;
307
+ }
308
+ if (result?.computedAmounts) {
309
+ out['Amount0 Desired'] = result.computedAmounts.amount0Desired;
310
+ out['Amount1 Desired'] = result.computedAmounts.amount1Desired;
311
+ }
312
+ if (result?.tronscanUrl)
313
+ out['Tronscan'] = result.tronscanUrl;
314
+ return out;
315
+ },
316
+ });
317
+ });
318
+ liq
319
+ .command('v3:increase')
320
+ .description('Increase liquidity of an existing V3 position')
321
+ .option('--pm <address>', 'V3 NonfungiblePositionManager address (auto-detected by network)')
322
+ .requiredOption('--token-id <id>', 'Position NFT token ID')
323
+ .option('--amount0 <raw>', 'Additional amount of token0')
324
+ .option('--amount1 <raw>', 'Additional amount of token1')
325
+ .option('--min0 <raw>', 'Minimum amount of token0')
326
+ .option('--min1 <raw>', 'Minimum amount of token1')
327
+ .option('--deadline <timestamp>', 'Unix timestamp deadline')
328
+ .option('--abi <json>', 'Optional PM ABI as JSON array')
329
+ .action(async (opts) => {
330
+ const network = (0, context_1.getNetwork)();
331
+ const pm = getV3PositionManager(network, opts.pm);
332
+ if (!opts.amount0 && !opts.amount1) {
333
+ console.error('Error: At least one of --amount0 or --amount1 is required');
334
+ process.exitCode = 1;
335
+ return;
336
+ }
337
+ await (0, command_1.writeAction)({
338
+ title: 'V3 Increase Liquidity',
339
+ summary: {
340
+ 'Position Manager': pm,
341
+ 'Token ID': opts.tokenId,
342
+ Amount0: opts.amount0 || '(auto)',
343
+ Amount1: opts.amount1 || '(auto)',
344
+ Network: network,
345
+ },
346
+ confirmMsg: 'Increase V3 liquidity?',
347
+ spinnerLabel: 'Increasing V3 liquidity...',
348
+ errorLabel: 'V3 increase liquidity failed',
349
+ execute: (kit) => kit.increaseLiquidityV3({
350
+ network,
351
+ positionManagerAddress: pm,
352
+ abi: opts.abi ? JSON.parse(opts.abi) : undefined,
353
+ tokenId: opts.tokenId,
354
+ amount0Desired: opts.amount0,
355
+ amount1Desired: opts.amount1,
356
+ amount0Min: opts.min0,
357
+ amount1Min: opts.min1,
358
+ deadline: opts.deadline,
359
+ }),
360
+ summarizeResult: (result) => {
361
+ const out = {};
362
+ if (result?.computedAmounts) {
363
+ out['Amount0 Desired'] = result.computedAmounts.amount0Desired;
364
+ out['Amount1 Desired'] = result.computedAmounts.amount1Desired;
365
+ }
366
+ if (result?.tronscanUrl)
367
+ out['Tronscan'] = result.tronscanUrl;
368
+ return out;
369
+ },
370
+ });
371
+ });
372
+ liq
373
+ .command('v3:decrease')
374
+ .description('Decrease liquidity of an existing V3 position')
375
+ .option('--pm <address>', 'V3 NonfungiblePositionManager address (auto-detected by network)')
376
+ .requiredOption('--token-id <id>', 'Position NFT token ID')
377
+ .requiredOption('--liquidity <raw>', 'Amount of liquidity to remove')
378
+ .option('--min0 <raw>', 'Minimum amount of token0 to receive')
379
+ .option('--min1 <raw>', 'Minimum amount of token1 to receive')
380
+ .option('--deadline <timestamp>', 'Unix timestamp deadline')
381
+ .option('--abi <json>', 'Optional PM ABI as JSON array')
382
+ .action(async (opts) => {
383
+ const network = (0, context_1.getNetwork)();
384
+ const pm = getV3PositionManager(network, opts.pm);
385
+ await (0, command_1.writeAction)({
386
+ title: 'V3 Decrease Liquidity',
387
+ summary: {
388
+ 'Position Manager': pm,
389
+ 'Token ID': opts.tokenId,
390
+ Liquidity: opts.liquidity,
391
+ Network: network,
392
+ },
393
+ confirmMsg: 'Decrease V3 liquidity?',
394
+ spinnerLabel: 'Decreasing V3 liquidity...',
395
+ errorLabel: 'V3 decrease liquidity failed',
396
+ execute: (kit) => kit.decreaseLiquidityV3({
397
+ network,
398
+ positionManagerAddress: pm,
399
+ abi: opts.abi ? JSON.parse(opts.abi) : undefined,
400
+ tokenId: opts.tokenId,
401
+ liquidity: opts.liquidity,
402
+ amount0Min: opts.min0,
403
+ amount1Min: opts.min1,
404
+ deadline: opts.deadline,
405
+ }),
406
+ });
407
+ });
408
+ liq
409
+ .command('v3:collect')
410
+ .description('Collect accrued fees from an existing V3 position')
411
+ .option('--pm <address>', 'V3 NonfungiblePositionManager address (auto-detected by network)')
412
+ .requiredOption('--token-id <id>', 'Position NFT token ID')
413
+ .option('--recipient <address>', 'Fee recipient (default: active wallet)')
414
+ .option('--abi <json>', 'Optional PM ABI as JSON array')
415
+ .action(async (opts) => {
416
+ const network = (0, context_1.getNetwork)();
417
+ const pm = getV3PositionManager(network, opts.pm);
418
+ await (0, command_1.writeAction)({
419
+ title: 'V3 Collect Fees',
420
+ summary: {
421
+ 'Position Manager': pm,
422
+ 'Token ID': opts.tokenId,
423
+ Recipient: opts.recipient || '(active wallet)',
424
+ Network: network,
425
+ },
426
+ confirmMsg: 'Collect V3 fees?',
427
+ spinnerLabel: 'Collecting V3 fees...',
428
+ errorLabel: 'V3 collect failed',
429
+ execute: (kit) => kit.collectPositionV3({
430
+ network,
431
+ positionManagerAddress: pm,
432
+ abi: opts.abi ? JSON.parse(opts.abi) : undefined,
433
+ tokenId: opts.tokenId,
434
+ recipient: opts.recipient,
435
+ }),
436
+ summarizeResult: (result) => {
437
+ const out = {};
438
+ if (result?.estimatedFees) {
439
+ out['Estimated Fee 0'] = result.estimatedFees.amount0;
440
+ out['Estimated Fee 1'] = result.estimatedFees.amount1;
441
+ }
442
+ if (result?.tronscanUrl)
443
+ out['Tronscan'] = result.tronscanUrl;
444
+ return out;
445
+ },
446
+ });
447
+ });
448
+ // ---------------------------------------------------------------------------
449
+ // V4
450
+ // ---------------------------------------------------------------------------
451
+ liq
452
+ .command('v4:mint')
453
+ .description('Mint a new SUNSWAP V4 concentrated liquidity position')
454
+ .requiredOption('--token0 <tokenOrAddress>', 'Token0 (symbol like TRX/USDT or address)')
455
+ .requiredOption('--token1 <tokenOrAddress>', 'Token1 (symbol like TRX/USDT or address)')
456
+ .option('--fee <n>', 'Pool fee tier (e.g. 500)')
457
+ .option('--tick-lower <n>', 'Lower tick (auto-computed if omitted)')
458
+ .option('--tick-upper <n>', 'Upper tick (auto-computed if omitted)')
459
+ .option('--amount0 <raw>', 'Desired amount of token0')
460
+ .option('--amount1 <raw>', 'Desired amount of token1')
461
+ .option('--slippage <n>', 'Slippage tolerance as decimal (e.g. 0.01 for 1%)')
462
+ .option('--recipient <address>', 'NFT recipient')
463
+ .option('--deadline <timestamp>', 'Unix timestamp deadline')
464
+ .option('--sqrt-price <value>', 'Initial sqrtPriceX96 (for pool creation)')
465
+ .option('--create-pool', 'Create pool if it does not exist')
466
+ .action(async (opts) => {
467
+ const network = (0, context_1.getNetwork)();
468
+ let token0Input, token1Input;
469
+ try {
470
+ token0Input = (0, tokens_1.resolveTokenAddress)(opts.token0, network);
471
+ token1Input = (0, tokens_1.resolveTokenAddress)(opts.token1, network);
472
+ }
473
+ catch (err) {
474
+ console.error(err.message);
475
+ process.exitCode = 1;
476
+ return;
477
+ }
478
+ const token0 = toWTRXIfNative(token0Input, network);
479
+ const token1 = toWTRXIfNative(token1Input, network);
480
+ const token0Display = (0, tokens_1.getSymbolOrAddress)(token0Input, network);
481
+ const token1Display = (0, tokens_1.getSymbolOrAddress)(token1Input, network);
482
+ const token0Note = token0 !== token0Input ? ` → WTRX` : '';
483
+ const token1Note = token1 !== token1Input ? ` → WTRX` : '';
484
+ await (0, command_1.writeAction)({
485
+ title: 'V4 Mint Position',
486
+ summary: {
487
+ Token0: `${token0Display}${token0Note} (${token0})`,
488
+ Token1: `${token1Display}${token1Note} (${token1})`,
489
+ Fee: opts.fee || '(auto)',
490
+ 'Tick Range': opts.tickLower && opts.tickUpper ? `[${opts.tickLower}, ${opts.tickUpper}]` : '(auto)',
491
+ Amount0: opts.amount0 || '(auto)',
492
+ Amount1: opts.amount1 || '(auto)',
493
+ Slippage: opts.slippage
494
+ ? `${(parseFloat(opts.slippage) * 100).toFixed(2)}%`
495
+ : '(default)',
496
+ 'Create Pool': opts.createPool ? 'Yes' : 'No',
497
+ Network: network,
498
+ },
499
+ confirmMsg: 'Mint V4 position?',
500
+ spinnerLabel: 'Minting V4 position...',
501
+ errorLabel: 'V4 mint failed',
502
+ execute: (kit) => kit.mintPositionV4({
503
+ network,
504
+ token0,
505
+ token1,
506
+ fee: opts.fee ? parseInt(opts.fee) : undefined,
507
+ tickLower: opts.tickLower ? parseInt(opts.tickLower) : undefined,
508
+ tickUpper: opts.tickUpper ? parseInt(opts.tickUpper) : undefined,
509
+ amount0Desired: opts.amount0,
510
+ amount1Desired: opts.amount1,
511
+ slippage: opts.slippage ? parseFloat(opts.slippage) : undefined,
512
+ recipient: opts.recipient,
513
+ deadline: opts.deadline,
514
+ sqrtPriceX96: opts.sqrtPrice,
515
+ createPoolIfNeeded: opts.createPool,
516
+ }),
517
+ summarizeResult: (result) => {
518
+ const out = {};
519
+ if (result?.poolCreated !== undefined)
520
+ out['Pool Created'] = result.poolCreated;
521
+ if (result?.computedTicks) {
522
+ out['Tick Lower'] = result.computedTicks.tickLower;
523
+ out['Tick Upper'] = result.computedTicks.tickUpper;
524
+ }
525
+ if (result?.computedAmounts) {
526
+ out['Amount0 Desired'] = result.computedAmounts.amount0Desired;
527
+ out['Amount1 Desired'] = result.computedAmounts.amount1Desired;
528
+ }
529
+ if (result?.tronscanUrl)
530
+ out['Tronscan'] = result.tronscanUrl;
531
+ return out;
532
+ },
533
+ });
534
+ });
535
+ liq
536
+ .command('v4:increase')
537
+ .description('Increase liquidity of an existing V4 position')
538
+ .requiredOption('--token-id <id>', 'Position NFT token ID')
539
+ .requiredOption('--token0 <tokenOrAddress>', 'Token0 (symbol like TRX/USDT or address)')
540
+ .requiredOption('--token1 <tokenOrAddress>', 'Token1 (symbol like TRX/USDT or address)')
541
+ .option('--fee <n>', 'Pool fee tier')
542
+ .option('--amount0 <raw>', 'Additional amount of token0')
543
+ .option('--amount1 <raw>', 'Additional amount of token1')
544
+ .option('--slippage <n>', 'Slippage tolerance as decimal')
545
+ .option('--deadline <timestamp>', 'Unix timestamp deadline')
546
+ .action(async (opts) => {
547
+ const network = (0, context_1.getNetwork)();
548
+ let token0Input, token1Input;
549
+ try {
550
+ token0Input = (0, tokens_1.resolveTokenAddress)(opts.token0, network);
551
+ token1Input = (0, tokens_1.resolveTokenAddress)(opts.token1, network);
552
+ }
553
+ catch (err) {
554
+ console.error(err.message);
555
+ process.exitCode = 1;
556
+ return;
557
+ }
558
+ const token0 = toWTRXIfNative(token0Input, network);
559
+ const token1 = toWTRXIfNative(token1Input, network);
560
+ const token0Display = (0, tokens_1.getSymbolOrAddress)(token0Input, network);
561
+ const token1Display = (0, tokens_1.getSymbolOrAddress)(token1Input, network);
562
+ await (0, command_1.writeAction)({
563
+ title: 'V4 Increase Liquidity',
564
+ summary: {
565
+ 'Token ID': opts.tokenId,
566
+ Token0: `${token0Display} (${token0})`,
567
+ Token1: `${token1Display} (${token1})`,
568
+ Amount0: opts.amount0 || '(auto)',
569
+ Amount1: opts.amount1 || '(auto)',
570
+ Network: network,
571
+ },
572
+ confirmMsg: 'Increase V4 liquidity?',
573
+ spinnerLabel: 'Increasing V4 liquidity...',
574
+ errorLabel: 'V4 increase liquidity failed',
575
+ execute: (kit) => kit.increaseLiquidityV4({
576
+ network,
577
+ tokenId: opts.tokenId,
578
+ token0,
579
+ token1,
580
+ fee: opts.fee ? parseInt(opts.fee) : undefined,
581
+ amount0Desired: opts.amount0,
582
+ amount1Desired: opts.amount1,
583
+ slippage: opts.slippage ? parseFloat(opts.slippage) : undefined,
584
+ deadline: opts.deadline,
585
+ }),
586
+ summarizeResult: (result) => {
587
+ const out = {};
588
+ if (result?.computedAmounts) {
589
+ out['Amount0 Desired'] = result.computedAmounts.amount0Desired;
590
+ out['Amount1 Desired'] = result.computedAmounts.amount1Desired;
591
+ }
592
+ if (result?.tronscanUrl)
593
+ out['Tronscan'] = result.tronscanUrl;
594
+ return out;
595
+ },
596
+ });
597
+ });
598
+ liq
599
+ .command('v4:decrease')
600
+ .description('Decrease liquidity of an existing V4 position')
601
+ .requiredOption('--token-id <id>', 'Position NFT token ID')
602
+ .requiredOption('--liquidity <raw>', 'Amount of liquidity to remove')
603
+ .requiredOption('--token0 <tokenOrAddress>', 'Token0 (symbol like TRX/USDT or address)')
604
+ .requiredOption('--token1 <tokenOrAddress>', 'Token1 (symbol like TRX/USDT or address)')
605
+ .option('--fee <n>', 'Pool fee tier')
606
+ .option('--min0 <raw>', 'Minimum amount of token0 to receive')
607
+ .option('--min1 <raw>', 'Minimum amount of token1 to receive')
608
+ .option('--slippage <n>', 'Slippage tolerance as decimal')
609
+ .option('--deadline <timestamp>', 'Unix timestamp deadline')
610
+ .action(async (opts) => {
611
+ const network = (0, context_1.getNetwork)();
612
+ let token0Input, token1Input;
613
+ try {
614
+ token0Input = (0, tokens_1.resolveTokenAddress)(opts.token0, network);
615
+ token1Input = (0, tokens_1.resolveTokenAddress)(opts.token1, network);
616
+ }
617
+ catch (err) {
618
+ console.error(err.message);
619
+ process.exitCode = 1;
620
+ return;
621
+ }
622
+ const token0 = toWTRXIfNative(token0Input, network);
623
+ const token1 = toWTRXIfNative(token1Input, network);
624
+ const token0Display = (0, tokens_1.getSymbolOrAddress)(token0Input, network);
625
+ const token1Display = (0, tokens_1.getSymbolOrAddress)(token1Input, network);
626
+ await (0, command_1.writeAction)({
627
+ title: 'V4 Decrease Liquidity',
628
+ summary: {
629
+ 'Token ID': opts.tokenId,
630
+ Liquidity: opts.liquidity,
631
+ Token0: `${token0Display} (${token0})`,
632
+ Token1: `${token1Display} (${token1})`,
633
+ Network: network,
634
+ },
635
+ confirmMsg: 'Decrease V4 liquidity?',
636
+ spinnerLabel: 'Decreasing V4 liquidity...',
637
+ errorLabel: 'V4 decrease liquidity failed',
638
+ execute: (kit) => kit.decreaseLiquidityV4({
639
+ network,
640
+ tokenId: opts.tokenId,
641
+ liquidity: opts.liquidity,
642
+ token0,
643
+ token1,
644
+ fee: opts.fee ? parseInt(opts.fee) : undefined,
645
+ amount0Min: opts.min0,
646
+ amount1Min: opts.min1,
647
+ slippage: opts.slippage ? parseFloat(opts.slippage) : undefined,
648
+ deadline: opts.deadline,
649
+ }),
650
+ summarizeResult: (result) => {
651
+ const out = {};
652
+ if (result?.computedAmountMin) {
653
+ out['Amount0 Min'] = result.computedAmountMin.amount0Min;
654
+ out['Amount1 Min'] = result.computedAmountMin.amount1Min;
655
+ }
656
+ if (result?.tronscanUrl)
657
+ out['Tronscan'] = result.tronscanUrl;
658
+ return out;
659
+ },
660
+ });
661
+ });
662
+ liq
663
+ .command('v4:collect')
664
+ .description('Collect accrued fees from an existing V4 position')
665
+ .requiredOption('--token-id <id>', 'Position NFT token ID')
666
+ .option('--token0 <tokenOrAddress>', 'Token0 (symbol like TRX/USDT or address)')
667
+ .option('--token1 <tokenOrAddress>', 'Token1 (symbol like TRX/USDT or address)')
668
+ .option('--fee <n>', 'Pool fee tier')
669
+ .option('--deadline <timestamp>', 'Unix timestamp deadline')
670
+ .action(async (opts) => {
671
+ const network = (0, context_1.getNetwork)();
672
+ let token0, token1;
673
+ if (opts.token0) {
674
+ try {
675
+ const resolved = (0, tokens_1.resolveTokenAddress)(opts.token0, network);
676
+ token0 = toWTRXIfNative(resolved, network);
677
+ }
678
+ catch (err) {
679
+ console.error(err.message);
680
+ process.exitCode = 1;
681
+ return;
682
+ }
683
+ }
684
+ if (opts.token1) {
685
+ try {
686
+ const resolved = (0, tokens_1.resolveTokenAddress)(opts.token1, network);
687
+ token1 = toWTRXIfNative(resolved, network);
688
+ }
689
+ catch (err) {
690
+ console.error(err.message);
691
+ process.exitCode = 1;
692
+ return;
693
+ }
694
+ }
695
+ await (0, command_1.writeAction)({
696
+ title: 'V4 Collect Fees',
697
+ summary: {
698
+ 'Token ID': opts.tokenId,
699
+ Token0: token0 || '(auto)',
700
+ Token1: token1 || '(auto)',
701
+ Network: network,
702
+ },
703
+ confirmMsg: 'Collect V4 fees?',
704
+ spinnerLabel: 'Collecting V4 fees...',
705
+ errorLabel: 'V4 collect failed',
706
+ execute: (kit) => kit.collectPositionV4({
707
+ network,
708
+ tokenId: opts.tokenId,
709
+ token0,
710
+ token1,
711
+ fee: opts.fee ? parseInt(opts.fee) : undefined,
712
+ deadline: opts.deadline,
713
+ }),
714
+ });
715
+ });
716
+ liq
717
+ .command('v4:info')
718
+ .description('Get details of an existing V4 position (read-only)')
719
+ .requiredOption('--pm <address>', 'V4 CLPositionManager address')
720
+ .requiredOption('--token-id <id>', 'Position NFT token ID')
721
+ .action(async (opts) => {
722
+ await (0, command_1.readAction)({
723
+ spinnerLabel: 'Fetching V4 position info...',
724
+ errorLabel: 'V4 position info failed',
725
+ execute: (kit) => kit.getV4PositionInfo(opts.pm, opts.tokenId, (0, context_1.getNetwork)()),
726
+ transform: (result) => {
727
+ if (!result)
728
+ return { error: 'Position not found' };
729
+ return {
730
+ currency0: result.poolKey.currency0,
731
+ currency1: result.poolKey.currency1,
732
+ fee: result.poolKey.fee,
733
+ tickSpacing: result.poolKey.tickSpacing,
734
+ tickLower: result.tickLower,
735
+ tickUpper: result.tickUpper,
736
+ liquidity: result.liquidity,
737
+ };
738
+ },
739
+ });
740
+ });
741
+ }
742
+ //# sourceMappingURL=liquidity.js.map