@1inch/swap-vm-sdk 0.1.0 → 0.1.2-rc.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 (84) hide show
  1. package/README.md +26 -25
  2. package/dist/abi/SwapVM.abi.d.mts +76 -0
  3. package/dist/abi/SwapVM.abi.d.ts +76 -0
  4. package/dist/index.js +641 -367
  5. package/dist/index.mjs +642 -370
  6. package/dist/swap-vm/instructions/concentrate/bigint-sqrt.d.mts +1 -0
  7. package/dist/swap-vm/instructions/concentrate/bigint-sqrt.d.ts +1 -0
  8. package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args.d.mts +16 -7
  9. package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args.d.ts +16 -7
  10. package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-calculator/types.d.mts +39 -0
  11. package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-calculator/types.d.ts +39 -0
  12. package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-math/concentrate-liquidity-math.d.mts +51 -0
  13. package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-math/concentrate-liquidity-math.d.ts +51 -0
  14. package/dist/swap-vm/instructions/concentrate/index.d.mts +4 -4
  15. package/dist/swap-vm/instructions/concentrate/index.d.ts +4 -4
  16. package/dist/swap-vm/instructions/concentrate/opcodes.d.mts +0 -5
  17. package/dist/swap-vm/instructions/concentrate/opcodes.d.ts +0 -5
  18. package/dist/swap-vm/instructions/dutch-auction/dutch-auction-args.d.mts +1 -2
  19. package/dist/swap-vm/instructions/dutch-auction/dutch-auction-args.d.ts +1 -2
  20. package/dist/swap-vm/instructions/fee/dynamic-protocol-fee/dynamic-protocol-fee-args-coder.d.mts +7 -0
  21. package/dist/swap-vm/instructions/fee/dynamic-protocol-fee/dynamic-protocol-fee-args-coder.d.ts +7 -0
  22. package/dist/swap-vm/instructions/fee/dynamic-protocol-fee/dynamic-protocol-fee-args.d.mts +13 -0
  23. package/dist/swap-vm/instructions/fee/dynamic-protocol-fee/dynamic-protocol-fee-args.d.ts +13 -0
  24. package/dist/swap-vm/instructions/fee/{flat-fee-args-coder.d.mts → flat-fee/flat-fee-args-coder.d.mts} +1 -1
  25. package/dist/swap-vm/instructions/fee/{flat-fee-args-coder.d.ts → flat-fee/flat-fee-args-coder.d.ts} +1 -1
  26. package/dist/swap-vm/instructions/fee/{flat-fee-args.d.mts → flat-fee/flat-fee-args.d.mts} +2 -2
  27. package/dist/swap-vm/instructions/fee/{flat-fee-args.d.ts → flat-fee/flat-fee-args.d.ts} +2 -2
  28. package/dist/swap-vm/instructions/fee/index.d.mts +3 -2
  29. package/dist/swap-vm/instructions/fee/index.d.ts +3 -2
  30. package/dist/swap-vm/instructions/fee/opcodes.d.mts +28 -8
  31. package/dist/swap-vm/instructions/fee/opcodes.d.ts +28 -8
  32. package/dist/swap-vm/instructions/fee/{protocol-fee-args-coder.d.mts → protocol-fee/protocol-fee-args-coder.d.mts} +1 -1
  33. package/dist/swap-vm/instructions/fee/{protocol-fee-args-coder.d.ts → protocol-fee/protocol-fee-args-coder.d.ts} +1 -1
  34. package/dist/swap-vm/instructions/fee/{protocol-fee-args.d.mts → protocol-fee/protocol-fee-args.d.mts} +3 -3
  35. package/dist/swap-vm/instructions/fee/{protocol-fee-args.d.ts → protocol-fee/protocol-fee-args.d.ts} +3 -3
  36. package/dist/swap-vm/instructions/index.d.mts +2 -1
  37. package/dist/swap-vm/instructions/index.d.ts +2 -1
  38. package/dist/swap-vm/instructions/pegged-swap/index.d.mts +3 -0
  39. package/dist/swap-vm/instructions/pegged-swap/index.d.ts +3 -0
  40. package/dist/swap-vm/instructions/pegged-swap/opcodes.d.mts +5 -0
  41. package/dist/swap-vm/instructions/pegged-swap/opcodes.d.ts +5 -0
  42. package/dist/swap-vm/instructions/pegged-swap/pegged-swap-args-coder.d.mts +7 -0
  43. package/dist/swap-vm/instructions/pegged-swap/pegged-swap-args-coder.d.ts +7 -0
  44. package/dist/swap-vm/instructions/pegged-swap/pegged-swap-args.d.mts +29 -0
  45. package/dist/swap-vm/instructions/pegged-swap/pegged-swap-args.d.ts +29 -0
  46. package/dist/swap-vm/instructions/pegged-swap/rate-resolver.d.mts +1 -0
  47. package/dist/swap-vm/instructions/pegged-swap/rate-resolver.d.ts +1 -0
  48. package/dist/swap-vm/instructions/pegged-swap/types.d.mts +6 -0
  49. package/dist/swap-vm/instructions/pegged-swap/types.d.ts +6 -0
  50. package/dist/swap-vm/programs/aqua-program-builder.d.mts +13 -16
  51. package/dist/swap-vm/programs/aqua-program-builder.d.ts +13 -16
  52. package/dist/swap-vm/programs/regular-program-builder.d.mts +21 -9
  53. package/dist/swap-vm/programs/regular-program-builder.d.ts +21 -9
  54. package/dist/swap-vm/strategies/aqua-amm-strategy.d.mts +2 -19
  55. package/dist/swap-vm/strategies/aqua-amm-strategy.d.ts +2 -19
  56. package/dist/swap-vm/strategies/aqua-pegged-amm-strategy.d.mts +11 -0
  57. package/dist/swap-vm/strategies/aqua-pegged-amm-strategy.d.ts +11 -0
  58. package/dist/swap-vm/strategies/aqua-xyc-amm-strategy.d.mts +11 -0
  59. package/dist/swap-vm/strategies/aqua-xyc-amm-strategy.d.ts +11 -0
  60. package/dist/swap-vm/strategies/index.d.mts +3 -0
  61. package/dist/swap-vm/strategies/index.d.ts +3 -0
  62. package/dist/swap-vm/strategies/types.d.mts +19 -0
  63. package/dist/swap-vm/strategies/types.d.ts +19 -0
  64. package/dist/swap-vm/taker-traits.d.mts +12 -2
  65. package/dist/swap-vm/taker-traits.d.ts +12 -2
  66. package/package.json +18 -18
  67. package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args-coder.d.mts +0 -7
  68. package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args-coder.d.ts +0 -7
  69. package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args.d.mts +0 -17
  70. package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args.d.ts +0 -17
  71. package/dist/swap-vm/instructions/concentrate/types.d.mts +0 -5
  72. package/dist/swap-vm/instructions/concentrate/types.d.ts +0 -5
  73. package/dist/swap-vm/instructions/concentrate/utils.d.mts +0 -4
  74. package/dist/swap-vm/instructions/concentrate/utils.d.ts +0 -4
  75. package/dist/swap-vm/instructions/stable-swap/index.d.mts +0 -2
  76. package/dist/swap-vm/instructions/stable-swap/index.d.ts +0 -2
  77. package/dist/swap-vm/instructions/stable-swap/opcodes.d.mts +0 -4
  78. package/dist/swap-vm/instructions/stable-swap/opcodes.d.ts +0 -4
  79. package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args-coder.d.mts +0 -7
  80. package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args-coder.d.ts +0 -7
  81. package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args.d.mts +0 -25
  82. package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args.d.ts +0 -25
  83. package/dist/swap-vm/types.d.mts +0 -22
  84. package/dist/swap-vm/types.d.ts +0 -22
package/README.md CHANGED
@@ -28,7 +28,8 @@ import {
28
28
  NetworkEnum,
29
29
  Order,
30
30
  MakerTraits,
31
- AquaAMMStrategy
31
+ AquaXYCAmmStrategy,
32
+ instructions
32
33
  } from '@1inch/swap-vm-sdk'
33
34
  import { AquaProtocolContract, AQUA_CONTRACT_ADDRESSES } from '@1inch/aqua-sdk'
34
35
 
@@ -40,9 +41,11 @@ const maker = '0xmaker_address'
40
41
  const USDC = new Address('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48')
41
42
  const WETH = new Address('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2')
42
43
 
43
- const program = AquaAMMStrategy.new({
44
- tokenA: USDC,
45
- tokenB: WETH
44
+ // Price range as P = tokenGt/tokenLt (1e18). E.g. 1500–3000 USDC per WETH → rawPriceMin = 1e18/3000, rawPriceMax = 1e18/1500
45
+ const { ONE_E18 } = instructions.concentrate
46
+ const program = AquaXYCAmmStrategy.newConcentrate({
47
+ rawPriceMin: ONE_E18 / 3000n,
48
+ rawPriceMax: ONE_E18 / 1500n
46
49
  }).build()
47
50
 
48
51
  const order = Order.new({
@@ -235,8 +238,7 @@ Available instruction categories in the full Swap VM instruction set include:
235
238
 
236
239
  ### Trading instructions
237
240
  - `XYC_SWAP_XD` - XYC swap for multi-dimensional pools
238
- - `CONCENTRATE_GROW_LIQUIDITY_XD` - Concentrate liquidity in multi-dimensional pools
239
- - `CONCENTRATE_GROW_LIQUIDITY_2D` - Concentrate liquidity in 2D pools
241
+ - `CONCENTRATE_GROW_LIQUIDITY_2D` - Concentrate liquidity in 2-token pools (sqrtPriceMin/sqrtPriceMax, P = tokenGt/tokenLt, 1e18)
240
242
  - `DECAY_XD` - Apply decay calculation
241
243
  - `LIMIT_SWAP_1D` - Execute limit order swap
242
244
  - `LIMIT_SWAP_ONLY_FULL_1D` - Execute limit order only if fully fillable
@@ -338,14 +340,14 @@ const { concentrate, fee } = instructions
338
340
 
339
341
  /**
340
342
  * Minimal strategy:
341
- * - concentrates liquidity for a 2-token pool
343
+ * - concentrates liquidity for a 2-token pool (price range in raw P = tokenGt/tokenLt, 1e18)
342
344
  * - optionally charges a taker fee on input
343
345
  * - always finishes with a simple XYC swap
344
346
  */
345
347
  export class SimpleAmmStrategy {
346
- private liquidityA?: bigint
348
+ private rawPriceMin?: bigint
347
349
 
348
- private liquidityB?: bigint
350
+ private rawPriceMax?: bigint
349
351
 
350
352
  private feeBpsIn?: number
351
353
 
@@ -355,11 +357,12 @@ export class SimpleAmmStrategy {
355
357
  ) {}
356
358
 
357
359
  /**
358
- * Sets initial virtual liquidity for the pair.
360
+ * Sets the concentrated liquidity price range.
361
+ * Prices are P = tokenGt/tokenLt in 1e18 fixed-point (e.g. WETH per USDC when USDC < WETH).
359
362
  */
360
- public withLiquidity(a: bigint, b: bigint): this {
361
- this.liquidityA = a
362
- this.liquidityB = b
363
+ public withPriceRange(rawPriceMin: bigint, rawPriceMax: bigint): this {
364
+ this.rawPriceMin = rawPriceMin
365
+ this.rawPriceMax = rawPriceMax
363
366
 
364
367
  return this
365
368
  }
@@ -381,12 +384,10 @@ export class SimpleAmmStrategy {
381
384
  public build(): SwapVmProgram {
382
385
  const builder = new AquaProgramBuilder()
383
386
 
384
- if (this.liquidityA !== undefined && this.liquidityB !== undefined) {
385
- const data = concentrate.ConcentrateGrowLiquidity2DArgs.fromTokenDeltas(
386
- this.tokenA,
387
- this.tokenB,
388
- this.liquidityA,
389
- this.liquidityB,
387
+ if (this.rawPriceMin !== undefined && this.rawPriceMax !== undefined) {
388
+ const data = concentrate.ConcentrateGrowLiquidity2DArgs.fromRawPrices(
389
+ this.rawPriceMin,
390
+ this.rawPriceMax,
390
391
  )
391
392
  builder.add(concentrate.concentrateGrowLiquidity2D.createIx(data))
392
393
  }
@@ -403,13 +404,12 @@ export class SimpleAmmStrategy {
403
404
  }
404
405
  }
405
406
 
406
- // Example usage:
407
+ // Example usage (price range: e.g. 1500–3000 USDC per WETH → P = WETH per USDC = 1/3000 .. 1/1500 in 1e18):
408
+
409
+ const { ONE_E18 } = concentrate
407
410
 
408
411
  const strategy = new SimpleAmmStrategy(USDC, WETH)
409
- .withLiquidity(
410
- 10_000n * 10n ** 6n, // 10k USDC
411
- 5n * 10n ** 18n, // 5 WETH
412
- )
412
+ .withPriceRange(ONE_E18 / 3000n, ONE_E18 / 1500n) // 1500–3000 USDC per WETH
413
413
  .withFeeTokenIn(5) // 5 bps taker fee on input (optional)
414
414
 
415
415
  const program = strategy.build()
@@ -558,12 +558,13 @@ The SDK exports:
558
558
  - **[`MakerTraits`](./src/swap-vm/maker-traits.ts)** - Maker-side configuration and flags
559
559
  - **[`TakerTraits`](./src/swap-vm/taker-traits.ts)** - Taker-side configuration and flags
560
560
  - **[`ABI`](./src/abi/)** - Contract ABI exports
561
+ - **Strategies** - [`AquaAMMStrategy`](./src/swap-vm/strategies/aqua-amm-strategy.ts) (base), [`AquaXYCAmmStrategy`](./src/swap-vm/strategies/aqua-xyc-amm-strategy.ts) (use `new()` or `newConcentrate({ rawPriceMin, rawPriceMax })` / `{ sqrtPriceMin, sqrtPriceMax }`), [`AquaPeggedAmmStrategy`](./src/swap-vm/strategies/aqua-pegged-amm-strategy.ts)
561
562
  - **[Instructions](./src/swap-vm/instructions/)** - Comprehensive instruction system:
562
563
  - `controls` - Flow control instructions
563
564
  - `balances` - Balance manipulation instructions
564
565
  - `invalidators` - Invalidation instructions
565
566
  - `xycSwap` - XYC swap instructions
566
- - `concentrate` - Liquidity concentration instructions
567
+ - `concentrate` - Liquidity concentration (e.g. `ConcentrateGrowLiquidity2DArgs.fromSqrtPrices` / `fromRawPrices`; P = tokenGt/tokenLt in 1e18)
567
568
  - `decay` - Decay calculation instructions
568
569
  - `limitSwap` - Limit order instructions
569
570
  - `minRate` - Minimum rate guard instructions
@@ -251,6 +251,10 @@ export declare const SWAP_VM_ABI: readonly [{
251
251
  readonly name: "amount";
252
252
  readonly type: "uint256";
253
253
  readonly internalType: "uint256";
254
+ }, {
255
+ readonly name: "amountNetPulled";
256
+ readonly type: "uint256";
257
+ readonly internalType: "uint256";
254
258
  }];
255
259
  }, {
256
260
  readonly type: "error";
@@ -304,6 +308,74 @@ export declare const SWAP_VM_ABI: readonly [{
304
308
  readonly type: "uint256";
305
309
  readonly internalType: "uint256";
306
310
  }];
311
+ }, {
312
+ readonly type: "error";
313
+ readonly name: "DeadlineReached";
314
+ readonly inputs: readonly [{
315
+ readonly name: "taker";
316
+ readonly type: "address";
317
+ readonly internalType: "address";
318
+ }, {
319
+ readonly name: "deadline";
320
+ readonly type: "uint256";
321
+ readonly internalType: "uint256";
322
+ }];
323
+ }, {
324
+ readonly type: "error";
325
+ readonly name: "TakerTokenBalanceIsZero";
326
+ readonly inputs: readonly [{
327
+ readonly name: "taker";
328
+ readonly type: "address";
329
+ readonly internalType: "address";
330
+ }, {
331
+ readonly name: "token";
332
+ readonly type: "address";
333
+ readonly internalType: "address";
334
+ }];
335
+ }, {
336
+ readonly type: "error";
337
+ readonly name: "TakerTokenBalanceIsLessThanRequired";
338
+ readonly inputs: readonly [{
339
+ readonly name: "taker";
340
+ readonly type: "address";
341
+ readonly internalType: "address";
342
+ }, {
343
+ readonly name: "token";
344
+ readonly type: "address";
345
+ readonly internalType: "address";
346
+ }, {
347
+ readonly name: "balance";
348
+ readonly type: "uint256";
349
+ readonly internalType: "uint256";
350
+ }, {
351
+ readonly name: "minAmount";
352
+ readonly type: "uint256";
353
+ readonly internalType: "uint256";
354
+ }];
355
+ }, {
356
+ readonly type: "error";
357
+ readonly name: "TakerTokenBalanceSupplyShareIsLessThanRequired";
358
+ readonly inputs: readonly [{
359
+ readonly name: "taker";
360
+ readonly type: "address";
361
+ readonly internalType: "address";
362
+ }, {
363
+ readonly name: "token";
364
+ readonly type: "address";
365
+ readonly internalType: "address";
366
+ }, {
367
+ readonly name: "balance";
368
+ readonly type: "uint256";
369
+ readonly internalType: "uint256";
370
+ }, {
371
+ readonly name: "totalSupply";
372
+ readonly type: "uint256";
373
+ readonly internalType: "uint256";
374
+ }, {
375
+ readonly name: "minShareE18";
376
+ readonly type: "uint256";
377
+ readonly internalType: "uint256";
378
+ }];
307
379
  }, {
308
380
  readonly type: "error";
309
381
  readonly name: "SafeTransferFromFailed";
@@ -396,6 +468,10 @@ export declare const SWAP_VM_ABI: readonly [{
396
468
  readonly type: "uint256";
397
469
  readonly internalType: "uint256";
398
470
  }];
471
+ }, {
472
+ readonly type: "error";
473
+ readonly name: "TakerTraitsDeadlineExpired";
474
+ readonly inputs: readonly [];
399
475
  }, {
400
476
  readonly type: "error";
401
477
  readonly name: "UnexpectedLock";
@@ -251,6 +251,10 @@ export declare const SWAP_VM_ABI: readonly [{
251
251
  readonly name: "amount";
252
252
  readonly type: "uint256";
253
253
  readonly internalType: "uint256";
254
+ }, {
255
+ readonly name: "amountNetPulled";
256
+ readonly type: "uint256";
257
+ readonly internalType: "uint256";
254
258
  }];
255
259
  }, {
256
260
  readonly type: "error";
@@ -304,6 +308,74 @@ export declare const SWAP_VM_ABI: readonly [{
304
308
  readonly type: "uint256";
305
309
  readonly internalType: "uint256";
306
310
  }];
311
+ }, {
312
+ readonly type: "error";
313
+ readonly name: "DeadlineReached";
314
+ readonly inputs: readonly [{
315
+ readonly name: "taker";
316
+ readonly type: "address";
317
+ readonly internalType: "address";
318
+ }, {
319
+ readonly name: "deadline";
320
+ readonly type: "uint256";
321
+ readonly internalType: "uint256";
322
+ }];
323
+ }, {
324
+ readonly type: "error";
325
+ readonly name: "TakerTokenBalanceIsZero";
326
+ readonly inputs: readonly [{
327
+ readonly name: "taker";
328
+ readonly type: "address";
329
+ readonly internalType: "address";
330
+ }, {
331
+ readonly name: "token";
332
+ readonly type: "address";
333
+ readonly internalType: "address";
334
+ }];
335
+ }, {
336
+ readonly type: "error";
337
+ readonly name: "TakerTokenBalanceIsLessThanRequired";
338
+ readonly inputs: readonly [{
339
+ readonly name: "taker";
340
+ readonly type: "address";
341
+ readonly internalType: "address";
342
+ }, {
343
+ readonly name: "token";
344
+ readonly type: "address";
345
+ readonly internalType: "address";
346
+ }, {
347
+ readonly name: "balance";
348
+ readonly type: "uint256";
349
+ readonly internalType: "uint256";
350
+ }, {
351
+ readonly name: "minAmount";
352
+ readonly type: "uint256";
353
+ readonly internalType: "uint256";
354
+ }];
355
+ }, {
356
+ readonly type: "error";
357
+ readonly name: "TakerTokenBalanceSupplyShareIsLessThanRequired";
358
+ readonly inputs: readonly [{
359
+ readonly name: "taker";
360
+ readonly type: "address";
361
+ readonly internalType: "address";
362
+ }, {
363
+ readonly name: "token";
364
+ readonly type: "address";
365
+ readonly internalType: "address";
366
+ }, {
367
+ readonly name: "balance";
368
+ readonly type: "uint256";
369
+ readonly internalType: "uint256";
370
+ }, {
371
+ readonly name: "totalSupply";
372
+ readonly type: "uint256";
373
+ readonly internalType: "uint256";
374
+ }, {
375
+ readonly name: "minShareE18";
376
+ readonly type: "uint256";
377
+ readonly internalType: "uint256";
378
+ }];
307
379
  }, {
308
380
  readonly type: "error";
309
381
  readonly name: "SafeTransferFromFailed";
@@ -396,6 +468,10 @@ export declare const SWAP_VM_ABI: readonly [{
396
468
  readonly type: "uint256";
397
469
  readonly internalType: "uint256";
398
470
  }];
471
+ }, {
472
+ readonly type: "error";
473
+ readonly name: "TakerTraitsDeadlineExpired";
474
+ readonly inputs: readonly [];
399
475
  }, {
400
476
  readonly type: "error";
401
477
  readonly name: "UnexpectedLock";