@sun-protocol/sun-cli 2.0.0-next.1794970981877.g4586222 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +14 -1
  2. package/dist/commands/contract.d.ts.map +1 -1
  3. package/dist/commands/contract.js +10 -9
  4. package/dist/commands/contract.js.map +1 -1
  5. package/dist/commands/liquidity.d.ts.map +1 -1
  6. package/dist/commands/liquidity.js +150 -78
  7. package/dist/commands/liquidity.js.map +1 -1
  8. package/dist/commands/sunpump.d.ts.map +1 -1
  9. package/dist/commands/sunpump.js +2 -2
  10. package/dist/commands/sunpump.js.map +1 -1
  11. package/dist/commands/swap.d.ts.map +1 -1
  12. package/dist/commands/swap.js +149 -26
  13. package/dist/commands/swap.js.map +1 -1
  14. package/dist/commands/wallet.d.ts.map +1 -1
  15. package/dist/commands/wallet.js +5 -4
  16. package/dist/commands/wallet.js.map +1 -1
  17. package/dist/lib/command.d.ts +2 -0
  18. package/dist/lib/command.d.ts.map +1 -1
  19. package/dist/lib/command.js +5 -3
  20. package/dist/lib/command.js.map +1 -1
  21. package/dist/lib/output.d.ts +1 -1
  22. package/dist/lib/output.d.ts.map +1 -1
  23. package/dist/lib/output.js +5 -2
  24. package/dist/lib/output.js.map +1 -1
  25. package/dist/lib/sdk/compat.d.ts +1 -0
  26. package/dist/lib/sdk/compat.d.ts.map +1 -1
  27. package/dist/lib/sdk/compat.js +5 -0
  28. package/dist/lib/sdk/compat.js.map +1 -1
  29. package/dist/lib/sdk/factory.d.ts +3 -3
  30. package/dist/lib/sdk/factory.d.ts.map +1 -1
  31. package/dist/lib/sdk/factory.js +15 -27
  32. package/dist/lib/sdk/factory.js.map +1 -1
  33. package/dist/lib/sdk/liquidity-v3.d.ts +2 -3
  34. package/dist/lib/sdk/liquidity-v3.d.ts.map +1 -1
  35. package/dist/lib/sdk/liquidity-v3.js +8 -15
  36. package/dist/lib/sdk/liquidity-v3.js.map +1 -1
  37. package/dist/lib/sdk/liquidity-v4.d.ts +1 -2
  38. package/dist/lib/sdk/liquidity-v4.d.ts.map +1 -1
  39. package/dist/lib/sdk/liquidity-v4.js +25 -31
  40. package/dist/lib/sdk/liquidity-v4.js.map +1 -1
  41. package/package.json +9 -9
package/README.md CHANGED
@@ -312,11 +312,16 @@ sun liquidity v3:decrease --token-id 123 --liquidity 1000
312
312
  sun liquidity v3:collect --token-id 123
313
313
  ```
314
314
 
315
+ When upgrading from 1.x, remove `--abi` from V2 add/remove and V3 mint/increase/decrease/collect
316
+ scripts. These commands use the standard SDK ABI. Use `--router` (V2) or `--pm` (V3) to target
317
+ a different contract that implements the standard interface. Use `sun contract read --abi` or
318
+ `sun contract send --abi` when calling a method with a custom ABI.
319
+
315
320
  **V4:**
316
321
 
317
322
  ```bash
318
323
  sun liquidity v4:mint --token0 TRX --token1 USDT --amount0 1000000 --amount1 290000
319
- sun liquidity v4:mint --token0 TRX --token1 USDT --amount0 1000000 --amount1 290000 --create-pool
324
+ sun liquidity v4:mint --token0 TRX --token1 USDT --amount0 1000000 --amount1 290000 --sqrt-price <sqrtPriceX96>
320
325
  sun liquidity v4:increase --token-id 123 --amount0 500000 --amount1 145000
321
326
  sun liquidity v4:decrease --token-id 123 --liquidity 1000
322
327
  sun liquidity v4:collect --token-id 123
@@ -328,6 +333,14 @@ For existing V4 positions, the CLI loads the authoritative pool currencies and f
328
333
  assertions. If the supplied token order is reversed, the CLI maps amount and minimum fields to the
329
334
  position's on-chain currency order before execution.
330
335
 
336
+ In V4, `TRX` selects the native TRX pool. If a 1.x script used `TRX` to target the wrapped pool,
337
+ change it to `WTRX`. Existing position commands can omit both token assertions and use the
338
+ currencies stored on-chain. Mint initializes a pool only if it is uninitialized and an initial
339
+ price is provided. Mint and increase default to 0% payment tolerance and show both maximum payment
340
+ amounts before confirmation. These two commands preserve the 1.x calculation: `--slippage 0.5`
341
+ allows up to 0.5% extra payment, rounded down in raw units. Any new Permit2 allowance for the V4
342
+ position manager covers the planned amount for one hour.
343
+
331
344
  ### Protocol & History
332
345
 
333
346
  **Protocol-wide analytics:**
@@ -1 +1 @@
1
- {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/commands/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAanC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,QAwDxD"}
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/commands/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAUnC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,QA2DxD"}
@@ -4,9 +4,7 @@ exports.registerContractCommands = registerContractCommands;
4
4
  const context_1 = require("../lib/context");
5
5
  const command_1 = require("../lib/command");
6
6
  const compat_1 = require("../lib/sdk/compat");
7
- function parseAbi(value) {
8
- return value === undefined ? undefined : JSON.parse(value);
9
- }
7
+ const factory_1 = require("../lib/sdk/factory");
10
8
  function parseValue(value) {
11
9
  return value === undefined ? undefined : BigInt(value);
12
10
  }
@@ -20,14 +18,16 @@ function registerContractCommands(program) {
20
18
  .option('--args <json>', 'Arguments as JSON array', '[]')
21
19
  .option('--abi <json>', 'Optional contract ABI as JSON array')
22
20
  .action(async (address, functionName, opts) => {
21
+ const target = (0, compat_1.toBase58Address)(address);
23
22
  await (0, command_1.readRuntimeAction)({
24
23
  spinnerLabel: `Reading ${functionName}...`,
25
24
  errorLabel: 'Contract read failed',
26
- execute: (sdk) => sdk.runtime.contract.read({
27
- address,
25
+ errorCode: 'CONTRACT_READ_FAILED',
26
+ execute: async (sdk) => sdk.runtime.contract.read({
27
+ address: target,
28
28
  functionName,
29
29
  args: JSON.parse(opts.args),
30
- abi: parseAbi(opts.abi),
30
+ abi: await (0, factory_1.resolveCallAbi)(sdk.runtime, target, opts.abi),
31
31
  }),
32
32
  transform: (result) => ({ result }),
33
33
  });
@@ -39,6 +39,7 @@ function registerContractCommands(program) {
39
39
  .option('--value <sun>', 'TRX call value in Sun')
40
40
  .option('--abi <json>', 'Optional contract ABI as JSON array')
41
41
  .action(async (address, functionName, opts) => {
42
+ const target = (0, compat_1.toBase58Address)(address);
42
43
  await (0, command_1.writeRuntimeAction)({
43
44
  title: 'Contract Transaction',
44
45
  summary: {
@@ -51,13 +52,13 @@ function registerContractCommands(program) {
51
52
  confirmMsg: 'Send this transaction?',
52
53
  spinnerLabel: `Sending ${functionName}...`,
53
54
  errorLabel: 'Contract send failed',
54
- execute: (kit) => kit.runtime.contract
55
+ execute: async (kit) => kit.runtime.contract
55
56
  .write({
56
- address,
57
+ address: target,
57
58
  functionName,
58
59
  args: JSON.parse(opts.args),
59
60
  callValue: parseValue(opts.value),
60
- abi: parseAbi(opts.abi),
61
+ abi: await (0, factory_1.resolveCallAbi)(kit.runtime, target, opts.abi),
61
62
  })
62
63
  .then(compat_1.toCliTxResult),
63
64
  });
@@ -1 +1 @@
1
- {"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/commands/contract.ts"],"names":[],"mappings":";;AAaA,4DAwDC;AApED,4CAA2C;AAC3C,4CAAmG;AACnG,8CAAiD;AAEjD,SAAS,QAAQ,CAAC,KAAyB;IACzC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;AAC5D,CAAC;AAED,SAAS,UAAU,CAAC,KAAyB;IAC3C,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACxD,CAAC;AAED,SAAgB,wBAAwB,CAAC,OAAgB;IACvD,MAAM,QAAQ,GAAG,OAAO;SACrB,OAAO,CAAC,UAAU,CAAC;SACnB,WAAW,CAAC,0CAA0C,CAAC,CAAA;IAE1D,QAAQ;SACL,OAAO,CAAC,+BAA+B,CAAC;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AE,WAAW,YAAY,KAAK;YAC1C,UAAU,EAAE,sBAAsB;YAClC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CACrB,GAAG,CAAC,OAAO,CAAC,QAAQ;iBACjB,KAAK,CAAC;gBACL,OAAO,EAAE,MAAM;gBACf,YAAY;gBACZ,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;gBAC3B,SAAS,EAAE,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;gBACjC,GAAG,EAAE,MAAM,IAAA,wBAAc,EAAC,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC;aACzD,CAAC;iBACD,IAAI,CAAC,sBAAa,CAAC;SACzB,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACN,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"liquidity.d.ts","sourceRoot":"","sources":["../../src/commands/liquidity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAsPnC,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAQlF;AA8DD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,QA01BzD"}
1
+ {"version":3,"file":"liquidity.d.ts","sourceRoot":"","sources":["../../src/commands/liquidity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAiUnC,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAQlF;AA8DD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,QA81BzD"}
@@ -7,6 +7,8 @@ const command_1 = require("../lib/command");
7
7
  const output_1 = require("../lib/output");
8
8
  const tokens_1 = require("../lib/tokens");
9
9
  const sun_sdk_chains_1 = require("@sun-protocol/sun-sdk-chains");
10
+ const sun_sdk_protocols_1 = require("@sun-protocol/sun-sdk-protocols");
11
+ const sun_sdk_sunswap_v4_1 = require("@sun-protocol/sun-sdk-sunswap-v4");
10
12
  const tronweb_1 = require("tronweb");
11
13
  const constants_1 = require("../lib/sdk/constants");
12
14
  const factory_1 = require("../lib/sdk/factory");
@@ -67,6 +69,68 @@ function getV2Factory(network) {
67
69
  function parseOptionalSlippage(value) {
68
70
  return value === undefined ? undefined : (0, slippage_1.parseDecimalSlippage)(value);
69
71
  }
72
+ function parseV4PaymentSlippage(value) {
73
+ const match = /^(?:(\d+)(?:\.(\d*))?|\.(\d+))$/.exec(value ?? '0');
74
+ const whole = Number(match?.[1] ?? '0');
75
+ const fraction = match?.[2] ?? match?.[3] ?? '';
76
+ if (!match || whole > 100 || (whole === 100 && /[1-9]/.test(fraction))) {
77
+ throw new Error('--slippage must be a percentage between 0 and 100');
78
+ }
79
+ // Truncate fractional basis points so the payment cap stays within the input tolerance.
80
+ const bips = whole * 100 + Number(fraction.slice(0, 2).padEnd(2, '0'));
81
+ const percent = bips / 100;
82
+ return { bips, sdk: `${percent}%`, display: `${percent.toFixed(2)}%` };
83
+ }
84
+ async function withV4PaymentApprovals(sdk, plan) {
85
+ const action = plan.transactions.find((transaction) => transaction.type === 'contract-call');
86
+ if (!action || action.type !== 'contract-call') {
87
+ throw new Error('V4 transaction plan is missing the liquidity call');
88
+ }
89
+ if (!action.tokenRequirements?.length)
90
+ return plan;
91
+ if (!plan.owner)
92
+ throw new Error('V4 transaction plan is missing a wallet');
93
+ const approvals = [];
94
+ for (const { token, spender, amount } of action.tokenRequirements) {
95
+ if (BigInt(amount) === 0n)
96
+ continue;
97
+ const authorization = await (0, sun_sdk_protocols_1.planRouterPermit2Authorization)(sdk.context, {
98
+ owner: plan.owner,
99
+ token,
100
+ spender,
101
+ amount,
102
+ approval: 'approve',
103
+ approveAmountType: 'exact',
104
+ ttlSeconds: 3600,
105
+ });
106
+ approvals.push(...authorization.actions);
107
+ }
108
+ return { ...plan, approvals };
109
+ }
110
+ function executeV4PaymentPlan(sdk, plan) {
111
+ for (const approval of plan.approvals) {
112
+ if (approval.type === 'contract-call' &&
113
+ approval.functionSelector === 'approve(address,address,uint160,uint48)') {
114
+ const expiration = BigInt(String(approval.parameters?.[3]?.value));
115
+ if (expiration <= BigInt(Math.floor(sdk.context.now() / 1000))) {
116
+ throw Object.assign(new Error('V4 Permit2 approval expired. Run the command again.'), {
117
+ code: 'PERMIT2_APPROVAL_EXPIRED',
118
+ });
119
+ }
120
+ }
121
+ }
122
+ return (0, sun_sdk_protocols_1.executeTransactionPlan)(plan, (0, sun_sdk_protocols_1.createContextExecutor)(sdk.context));
123
+ }
124
+ function v4PaymentLimits(plan, token0, token1) {
125
+ const action = plan.transactions.find((item) => item.type === 'contract-call');
126
+ if (!action || action.type !== 'contract-call') {
127
+ throw new Error('V4 transaction plan is missing the liquidity call');
128
+ }
129
+ const limit = (token) => token === constants_1.TRX_ADDRESS
130
+ ? String(action.callValue ?? 0n)
131
+ : (action.tokenRequirements?.find((item) => item.token === token)?.amount ?? '0');
132
+ return { 'Max Amount0 (raw)': limit(token0), 'Max Amount1 (raw)': limit(token1) };
133
+ }
70
134
  function invalidParamsError(message) {
71
135
  return Object.assign(new Error(message), { code: 'INVALID_PARAMS' });
72
136
  }
@@ -249,7 +313,6 @@ function registerLiquidityCommands(program) {
249
313
  .option('--min-b <raw>', 'Minimum amount of token B')
250
314
  .option('--to <address>', 'Recipient for LP tokens (default: active wallet)')
251
315
  .option('--deadline <timestamp>', 'Unix timestamp deadline')
252
- .option('--abi <json>', 'Optional router ABI as JSON array')
253
316
  .action(async (opts) => {
254
317
  const network = (0, context_1.getNetwork)();
255
318
  const router = getV2Router(network, opts.router);
@@ -306,7 +369,7 @@ function registerLiquidityCommands(program) {
306
369
  confirmMsg: 'Add V2 liquidity?',
307
370
  spinnerLabel: 'Adding V2 liquidity...',
308
371
  errorLabel: 'V2 add liquidity failed',
309
- execute: async (client) => (await (0, factory_1.withLiquidityAbi)(client, router, opts.abi)).liquidity.v2.add
372
+ execute: async (client) => client.liquidity.v2.add
310
373
  .execute({
311
374
  contracts: withContracts({ sunswapV2Router: router }),
312
375
  tokenA,
@@ -315,6 +378,7 @@ function registerLiquidityCommands(program) {
315
378
  amountBDesired: amountB,
316
379
  amountAMin: opts.minA,
317
380
  amountBMin: opts.minB,
381
+ slippage: '5%',
318
382
  approvalAmount: 'exact',
319
383
  recipient: opts.to,
320
384
  ttlSeconds: 1800,
@@ -334,7 +398,6 @@ function registerLiquidityCommands(program) {
334
398
  .option('--min-b <raw>', 'Minimum amount of token B to receive')
335
399
  .option('--to <address>', 'Recipient of underlying tokens')
336
400
  .option('--deadline <timestamp>', 'Unix timestamp deadline')
337
- .option('--abi <json>', 'Optional router ABI as JSON array')
338
401
  .action(async (opts) => {
339
402
  const network = (0, context_1.getNetwork)();
340
403
  const router = getV2Router(network, opts.router);
@@ -362,7 +425,7 @@ function registerLiquidityCommands(program) {
362
425
  confirmMsg: 'Remove V2 liquidity?',
363
426
  spinnerLabel: 'Removing V2 liquidity...',
364
427
  errorLabel: 'V2 remove liquidity failed',
365
- execute: async (sdk) => (await (0, factory_1.withLiquidityAbi)(sdk, router, opts.abi)).liquidity.v2.remove
428
+ execute: async (sdk) => sdk.liquidity.v2.remove
366
429
  .execute({
367
430
  contracts: withContracts({ sunswapV2Router: router }),
368
431
  tokenA,
@@ -370,6 +433,7 @@ function registerLiquidityCommands(program) {
370
433
  liquidity: opts.liquidity,
371
434
  amountAMin: opts.minA,
372
435
  amountBMin: opts.minB,
436
+ slippage: '5%',
373
437
  recipient: opts.to,
374
438
  ttlSeconds: 1800,
375
439
  deadline: opts.deadline,
@@ -395,7 +459,6 @@ function registerLiquidityCommands(program) {
395
459
  .option('--min1 <raw>', 'Minimum amount of token1')
396
460
  .option('--recipient <address>', 'NFT recipient')
397
461
  .option('--deadline <timestamp>', 'Unix timestamp deadline')
398
- .option('--abi <json>', 'Optional PM ABI as JSON array')
399
462
  .action(async (opts) => {
400
463
  const network = (0, context_1.getNetwork)();
401
464
  const pm = getV3PositionManager(network, opts.pm);
@@ -440,13 +503,13 @@ function registerLiquidityCommands(program) {
440
503
  confirmMsg: 'Mint V3 position?',
441
504
  spinnerLabel: 'Minting V3 position...',
442
505
  errorLabel: 'V3 mint failed',
443
- execute: async (sdk) => (await (0, factory_1.withLiquidityAbi)(sdk, pm, opts.abi)).liquidity.v3.add
506
+ execute: async (sdk) => sdk.liquidity.v3.add
444
507
  .execute({
445
508
  contracts: withContracts({ sunswapV3PositionManager: pm }),
446
509
  tokenA: token0,
447
510
  tokenB: token1,
448
511
  fee: opts.fee ? parseInt(opts.fee) : constants_1.DEFAULT_V3_FEE,
449
- pool: await (0, liquidity_v3_1.resolveLegacyV3Pool)(sdk, {
512
+ pool: await (0, liquidity_v3_1.resolveV3PoolState)(sdk, {
450
513
  token0,
451
514
  token1,
452
515
  fee: opts.fee ? parseInt(opts.fee) : constants_1.DEFAULT_V3_FEE,
@@ -493,7 +556,6 @@ function registerLiquidityCommands(program) {
493
556
  .option('--min0 <raw>', 'Minimum amount of token0')
494
557
  .option('--min1 <raw>', 'Minimum amount of token1')
495
558
  .option('--deadline <timestamp>', 'Unix timestamp deadline')
496
- .option('--abi <json>', 'Optional PM ABI as JSON array')
497
559
  .action(async (opts) => {
498
560
  const network = (0, context_1.getNetwork)();
499
561
  const pm = getV3PositionManager(network, opts.pm);
@@ -516,9 +578,7 @@ function registerLiquidityCommands(program) {
516
578
  confirmMsg: 'Increase V3 liquidity?',
517
579
  spinnerLabel: 'Increasing V3 liquidity...',
518
580
  errorLabel: 'V3 increase liquidity failed',
519
- execute: async (sdk) => (await (0, factory_1.withLiquidityAbi)(sdk, pm, opts.abi, BigInt(opts.amount0 ?? '0') === 0n || BigInt(opts.amount1 ?? '0') === 0n
520
- ? ['positions(uint256)']
521
- : [])).liquidity.v3.increase
581
+ execute: async (sdk) => sdk.liquidity.v3.increase
522
582
  .execute({
523
583
  contracts: withContracts({ sunswapV3PositionManager: pm }),
524
584
  tokenId: opts.tokenId,
@@ -526,12 +586,13 @@ function registerLiquidityCommands(program) {
526
586
  amount1: opts.amount1,
527
587
  amountInputMode: 'legacy-cli',
528
588
  includeComputedMetadata: true,
529
- pool: opts.pm || BigInt(opts.amount0 ?? '0') === 0n || BigInt(opts.amount1 ?? '0') === 0n
530
- ? await (0, liquidity_v3_1.resolveLegacyV3Pool)(sdk, {
589
+ pool: network === 'nile' ||
590
+ opts.pm ||
591
+ BigInt(opts.amount0 ?? '0') === 0n ||
592
+ BigInt(opts.amount1 ?? '0') === 0n
593
+ ? await (0, liquidity_v3_1.resolveV3PoolState)(sdk, {
531
594
  tokenId: opts.tokenId,
532
595
  positionManager: pm,
533
- positionAbi: opts.abi,
534
- factory: opts.pm ? undefined : constants_1.CLI_V3_FACTORY[assertSdkNetwork(network)],
535
596
  })
536
597
  : undefined,
537
598
  amount0Min: opts.min0,
@@ -562,7 +623,6 @@ function registerLiquidityCommands(program) {
562
623
  .option('--min0 <raw>', 'Minimum amount of token0 to receive')
563
624
  .option('--min1 <raw>', 'Minimum amount of token1 to receive')
564
625
  .option('--deadline <timestamp>', 'Unix timestamp deadline')
565
- .option('--abi <json>', 'Optional PM ABI as JSON array')
566
626
  .action(async (opts) => {
567
627
  const network = (0, context_1.getNetwork)();
568
628
  const pm = getV3PositionManager(network, opts.pm);
@@ -577,20 +637,19 @@ function registerLiquidityCommands(program) {
577
637
  confirmMsg: 'Decrease V3 liquidity?',
578
638
  spinnerLabel: 'Decreasing V3 liquidity...',
579
639
  errorLabel: 'V3 decrease liquidity failed',
580
- execute: async (sdk) => (await (0, factory_1.withLiquidityAbi)(sdk, pm, opts.abi)).positions.v3.remove
640
+ execute: async (sdk) => sdk.positions.v3.remove
581
641
  .execute({
582
642
  contracts: withContracts({ sunswapV3PositionManager: pm }),
583
643
  tokenId: opts.tokenId,
584
644
  liquidity: opts.liquidity,
585
- pool: opts.pm
586
- ? await (0, liquidity_v3_1.resolveLegacyV3Pool)(sdk, {
645
+ pool: network === 'nile' || opts.pm
646
+ ? await (0, liquidity_v3_1.resolveV3PoolState)(sdk, {
587
647
  tokenId: opts.tokenId,
588
648
  positionManager: pm,
589
- positionAbi: opts.abi,
590
649
  })
591
650
  : undefined,
592
- amount0Min: opts.min0,
593
- amount1Min: opts.min1,
651
+ amount0Min: opts.min0 ?? '0',
652
+ amount1Min: opts.min1 ?? '0',
594
653
  collectFees: false,
595
654
  ttlSeconds: 1800,
596
655
  deadline: opts.deadline,
@@ -604,7 +663,6 @@ function registerLiquidityCommands(program) {
604
663
  .option('--pm <address>', 'V3 NonfungiblePositionManager address (auto-detected by network)')
605
664
  .requiredOption('--token-id <id>', 'Position NFT token ID')
606
665
  .option('--recipient <address>', 'Fee recipient (default: active wallet)')
607
- .option('--abi <json>', 'Optional PM ABI as JSON array')
608
666
  .action(async (opts) => {
609
667
  const network = (0, context_1.getNetwork)();
610
668
  const pm = getV3PositionManager(network, opts.pm);
@@ -619,7 +677,7 @@ function registerLiquidityCommands(program) {
619
677
  confirmMsg: 'Collect V3 fees?',
620
678
  spinnerLabel: 'Collecting V3 fees...',
621
679
  errorLabel: 'V3 collect failed',
622
- execute: async (sdk) => (await (0, factory_1.withLiquidityAbi)(sdk, pm, opts.abi)).positions.v3.collect
680
+ execute: async (sdk) => sdk.positions.v3.collect
623
681
  .execute({
624
682
  contracts: withContracts({ sunswapV3PositionManager: pm }),
625
683
  tokenId: opts.tokenId,
@@ -652,11 +710,11 @@ function registerLiquidityCommands(program) {
652
710
  .option('--tick-upper <n>', 'Upper tick (auto-computed if omitted)')
653
711
  .option('--amount0 <raw>', 'Desired amount of token0')
654
712
  .option('--amount1 <raw>', 'Desired amount of token1')
655
- .option('--slippage <n>', 'Slippage tolerance as decimal (e.g. 0.01 for 1%)')
713
+ .option('--slippage <n>', 'Payment tolerance as a percentage (e.g. 0.5 for 0.5%)')
656
714
  .option('--recipient <address>', 'NFT recipient')
657
715
  .option('--deadline <timestamp>', 'Unix timestamp deadline')
658
716
  .option('--sqrt-price <value>', 'Initial sqrtPriceX96 (for pool creation)')
659
- .option('--create-pool', 'Create pool if it does not exist')
717
+ .option('--create-pool', 'Compatibility flag; uninitialized pools require --sqrt-price')
660
718
  .action(async (opts) => {
661
719
  const network = (0, context_1.getNetwork)();
662
720
  let token0Input, token1Input;
@@ -679,7 +737,7 @@ function registerLiquidityCommands(program) {
679
737
  const tickUpper = opts.tickUpper !== undefined ? parseInt(opts.tickUpper) : undefined;
680
738
  let slippage;
681
739
  try {
682
- slippage = parseOptionalSlippage(opts.slippage);
740
+ slippage = parseV4PaymentSlippage(opts.slippage);
683
741
  }
684
742
  catch (err) {
685
743
  (0, output_1.outputError)('Invalid --slippage', err);
@@ -692,37 +750,38 @@ function registerLiquidityCommands(program) {
692
750
  (0, output_1.outputError)('Invalid liquidity amounts', err);
693
751
  return;
694
752
  }
753
+ const summary = {
754
+ Token0: `${token0Display} (${token0})`,
755
+ Token1: `${token1Display} (${token1})`,
756
+ Fee: opts.fee || `${constants_1.DEFAULT_V4_FEE} (default)`,
757
+ 'Tick Range': tickLower !== undefined && tickUpper !== undefined
758
+ ? `[${tickLower}, ${tickUpper}]`
759
+ : '(auto)',
760
+ Amount0: opts.amount0 ?? '(not provided)',
761
+ Amount1: opts.amount1 ?? '(not provided)',
762
+ Slippage: slippage.display,
763
+ Recipient: opts.recipient ?? '(active wallet)',
764
+ 'Create Pool': '(from pool state)',
765
+ Network: network,
766
+ };
767
+ let plan;
768
+ let ticks;
695
769
  await (0, command_1.writeAction)({
696
770
  title: 'V4 Mint Position',
697
- summary: {
698
- Token0: `${token0Display} (${token0})`,
699
- Token1: `${token1Display} (${token1})`,
700
- Fee: opts.fee || `${constants_1.DEFAULT_V4_FEE} (default)`,
701
- 'Tick Range': tickLower !== undefined && tickUpper !== undefined
702
- ? `[${tickLower}, ${tickUpper}]`
703
- : '(auto)',
704
- Amount0: opts.amount0 ?? '(not provided)',
705
- Amount1: opts.amount1 ?? '(not provided)',
706
- Slippage: slippage?.display ?? '(default)',
707
- Recipient: opts.recipient ?? '(active wallet)',
708
- 'Create Pool': opts.createPool ? 'Yes' : 'No',
709
- Network: network,
710
- },
771
+ summary,
711
772
  confirmMsg: 'Mint V4 position?',
712
773
  spinnerLabel: 'Minting V4 position...',
713
774
  errorLabel: 'V4 mint failed',
714
- execute: async (sdk) => {
715
- const ticks = await (0, liquidity_v4_1.resolveV4MintTicks)(sdk, {
775
+ prepare: async (sdk) => {
776
+ ticks = await (0, liquidity_v4_1.resolveV4MintTicks)(sdk, {
716
777
  token0,
717
778
  token1,
718
779
  fee,
719
780
  tickLower,
720
781
  tickUpper,
721
782
  sqrtPriceX96: opts.sqrtPrice,
722
- createPool: opts.createPool,
723
783
  });
724
- return sdk.liquidity.v4.add
725
- .execute({
784
+ plan = await sdk.liquidity.v4.add.plan({
726
785
  token0,
727
786
  token1,
728
787
  fee,
@@ -730,21 +789,29 @@ function registerLiquidityCommands(program) {
730
789
  amount0: opts.amount0,
731
790
  amount1: opts.amount1,
732
791
  amountInputMode: 'legacy-cli',
733
- slippage: slippage?.sdk,
792
+ slippage: slippage.sdk,
793
+ roundingMode: 'floor',
794
+ approval: 'none',
795
+ poolInitializationMode: 'trust-input',
734
796
  includeComputedMetadata: true,
735
797
  transactionMode: 'multicall',
736
798
  recipient: opts.recipient,
737
- sweepRecipient: opts.recipient,
738
799
  ttlSeconds: 1800,
739
800
  deadline: opts.deadline,
740
801
  sqrtPriceX96: opts.sqrtPrice,
741
- })
742
- .then((result) => {
743
- const mapped = mapTx(result);
744
- return tickLower === undefined || tickUpper === undefined
745
- ? { ...mapped, computedTicks: ticks }
746
- : mapped;
747
802
  });
803
+ plan = await withV4PaymentApprovals(sdk, plan);
804
+ Object.assign(summary, v4PaymentLimits(plan, token0, token1), {
805
+ 'Tick Range': `[${ticks.tickLower}, ${ticks.tickUpper}]`,
806
+ 'Create Pool': ticks.createPool ? 'Yes' : 'No',
807
+ });
808
+ },
809
+ execute: async (sdk) => {
810
+ const result = await executeV4PaymentPlan(sdk, plan);
811
+ const mapped = mapTx(result);
812
+ return tickLower === undefined || tickUpper === undefined
813
+ ? { ...mapped, computedTicks: ticks }
814
+ : mapped;
748
815
  },
749
816
  summarizeResult: (result) => {
750
817
  const out = {};
@@ -773,7 +840,7 @@ function registerLiquidityCommands(program) {
773
840
  .option('--fee <n>', 'Expected pool fee tier (validated against the position)')
774
841
  .option('--amount0 <raw>', 'Additional amount of token0')
775
842
  .option('--amount1 <raw>', 'Additional amount of token1')
776
- .option('--slippage <n>', 'Slippage tolerance as decimal')
843
+ .option('--slippage <n>', 'Payment tolerance as a percentage (e.g. 0.5 for 0.5%)')
777
844
  .option('--deadline <timestamp>', 'Unix timestamp deadline')
778
845
  .action(async (opts) => {
779
846
  const network = (0, context_1.getNetwork)();
@@ -788,7 +855,7 @@ function registerLiquidityCommands(program) {
788
855
  }
789
856
  let slippage;
790
857
  try {
791
- slippage = parseOptionalSlippage(opts.slippage);
858
+ slippage = parseV4PaymentSlippage(opts.slippage);
792
859
  }
793
860
  catch (err) {
794
861
  (0, output_1.outputError)('Invalid --slippage', err);
@@ -808,10 +875,11 @@ function registerLiquidityCommands(program) {
808
875
  Fee: expectedFee ?? '(from tokenId)',
809
876
  Amount0: opts.amount0 ?? '(not provided)',
810
877
  Amount1: opts.amount1 ?? '(not provided)',
811
- Slippage: slippage?.display ?? '(default)',
878
+ Slippage: slippage.display,
812
879
  Network: network,
813
880
  };
814
881
  const loadPosition = createV4PositionLoader(opts.tokenId, expectedPair, expectedFee);
882
+ let plan;
815
883
  await (0, command_1.writeAction)({
816
884
  title: 'V4 Increase Liquidity',
817
885
  summary,
@@ -819,7 +887,22 @@ function registerLiquidityCommands(program) {
819
887
  prepare: async (sdk) => {
820
888
  const prepared = await loadPosition(sdk);
821
889
  const [amount0, amount1] = orderV4PositionValues(prepared.reversed, opts.amount0, opts.amount1);
822
- Object.assign(summary, v4PositionTokenSummary(prepared.poolKey, network), {
890
+ plan = await sdk.liquidity.v4.increase.plan({
891
+ tokenId: opts.tokenId,
892
+ amount0,
893
+ amount1,
894
+ amountInputMode: 'legacy-cli',
895
+ slippage: slippage.sdk,
896
+ roundingMode: 'floor',
897
+ approval: 'none',
898
+ includeComputedMetadata: true,
899
+ transactionMode: 'multicall',
900
+ ttlSeconds: 1800,
901
+ deadline: opts.deadline,
902
+ });
903
+ plan = await withV4PaymentApprovals(sdk, plan);
904
+ const { currency0, currency1 } = prepared.poolKey;
905
+ Object.assign(summary, v4PositionTokenSummary(prepared.poolKey, network), v4PaymentLimits(plan, currency0, currency1), {
823
906
  Amount0: amount0 ?? '(not provided)',
824
907
  Amount1: amount1 ?? '(not provided)',
825
908
  });
@@ -829,20 +912,8 @@ function registerLiquidityCommands(program) {
829
912
  errorLabel: 'V4 increase liquidity failed',
830
913
  execute: async (sdk) => {
831
914
  const prepared = await loadPosition(sdk);
832
- const [amount0, amount1] = orderV4PositionValues(prepared.reversed, opts.amount0, opts.amount1);
833
- return sdk.liquidity.v4.increase
834
- .execute({
835
- tokenId: opts.tokenId,
836
- amount0,
837
- amount1,
838
- amountInputMode: 'legacy-cli',
839
- slippage: slippage?.sdk,
840
- includeComputedMetadata: true,
841
- transactionMode: 'multicall',
842
- ttlSeconds: 1800,
843
- deadline: opts.deadline,
844
- })
845
- .then(mapTx);
915
+ const result = await executeV4PaymentPlan(sdk, plan);
916
+ return mapTx(result, prepared.reversed);
846
917
  },
847
918
  summarizeResult: (result) => {
848
919
  const out = {};
@@ -1012,13 +1083,14 @@ function registerLiquidityCommands(program) {
1012
1083
  transform: (result) => {
1013
1084
  if (!result)
1014
1085
  return { error: 'Position not found' };
1015
- const fee = result.poolKey?.fee;
1086
+ const poolKey = result.poolKey;
1016
1087
  return {
1017
- currency0: result.poolKey?.currency0,
1018
- currency1: result.poolKey?.currency1,
1019
- fee: fee === undefined ? undefined : String(fee),
1020
- tickSpacing: result.poolKey?.tickSpacing ??
1021
- (Number.isFinite(Number(fee)) ? (0, liquidity_v4_1.v4TickSpacingForFee)(Number(fee)) : undefined),
1088
+ currency0: poolKey?.currency0,
1089
+ currency1: poolKey?.currency1,
1090
+ fee: poolKey?.fee === undefined ? undefined : String(poolKey.fee),
1091
+ tickSpacing: poolKey?.parameters === undefined
1092
+ ? (poolKey?.tickSpacing ?? 0)
1093
+ : (0, sun_sdk_sunswap_v4_1.decodeV4PoolParameters)(poolKey.parameters).tickSpacing,
1022
1094
  tickLower: result.tickLower,
1023
1095
  tickUpper: result.tickUpper,
1024
1096
  liquidity: result.liquidity,