@1inch/swap-vm-sdk 0.1.1 → 0.1.2-rc.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 (82) 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 +614 -339
  5. package/dist/index.mjs +615 -342
  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
package/dist/index.mjs CHANGED
@@ -2,6 +2,7 @@ import { decodeAbiParameters, decodeEventLog, encodeAbiParameters, encodeFunctio
2
2
  import { Address, Address as Address$1, AddressHalf, CallInfo, HexString, HexString as HexString$1, Interaction, NetworkEnum, NetworkEnum as NetworkEnum$1 } from "@1inch/sdk-core";
3
3
  import { BN, BitMask, BytesBuilder, BytesIter, UINT_16_MAX, UINT_24_MAX, UINT_256_MAX, UINT_32_MAX, UINT_40_MAX, UINT_64_MAX, UINT_8_MAX, UINT_96_MAX, add0x, trim0x } from "@1inch/byte-utils";
4
4
  import assert from "assert";
5
+ import { UINT_64_MAX as UINT_64_MAX$1 } from "@1inch/byte-utils/dist/constants";
5
6
 
6
7
  //#region rolldown:runtime
7
8
  var __defProp = Object.defineProperty;
@@ -328,6 +329,11 @@ const SWAP_VM_ABI = [
328
329
  name: "amount",
329
330
  type: "uint256",
330
331
  internalType: "uint256"
332
+ },
333
+ {
334
+ name: "amountNetPulled",
335
+ type: "uint256",
336
+ internalType: "uint256"
331
337
  }
332
338
  ]
333
339
  },
@@ -395,6 +401,89 @@ const SWAP_VM_ABI = [
395
401
  internalType: "uint256"
396
402
  }]
397
403
  },
404
+ {
405
+ type: "error",
406
+ name: "DeadlineReached",
407
+ inputs: [{
408
+ name: "taker",
409
+ type: "address",
410
+ internalType: "address"
411
+ }, {
412
+ name: "deadline",
413
+ type: "uint256",
414
+ internalType: "uint256"
415
+ }]
416
+ },
417
+ {
418
+ type: "error",
419
+ name: "TakerTokenBalanceIsZero",
420
+ inputs: [{
421
+ name: "taker",
422
+ type: "address",
423
+ internalType: "address"
424
+ }, {
425
+ name: "token",
426
+ type: "address",
427
+ internalType: "address"
428
+ }]
429
+ },
430
+ {
431
+ type: "error",
432
+ name: "TakerTokenBalanceIsLessThanRequired",
433
+ inputs: [
434
+ {
435
+ name: "taker",
436
+ type: "address",
437
+ internalType: "address"
438
+ },
439
+ {
440
+ name: "token",
441
+ type: "address",
442
+ internalType: "address"
443
+ },
444
+ {
445
+ name: "balance",
446
+ type: "uint256",
447
+ internalType: "uint256"
448
+ },
449
+ {
450
+ name: "minAmount",
451
+ type: "uint256",
452
+ internalType: "uint256"
453
+ }
454
+ ]
455
+ },
456
+ {
457
+ type: "error",
458
+ name: "TakerTokenBalanceSupplyShareIsLessThanRequired",
459
+ inputs: [
460
+ {
461
+ name: "taker",
462
+ type: "address",
463
+ internalType: "address"
464
+ },
465
+ {
466
+ name: "token",
467
+ type: "address",
468
+ internalType: "address"
469
+ },
470
+ {
471
+ name: "balance",
472
+ type: "uint256",
473
+ internalType: "uint256"
474
+ },
475
+ {
476
+ name: "totalSupply",
477
+ type: "uint256",
478
+ internalType: "uint256"
479
+ },
480
+ {
481
+ name: "minShareE18",
482
+ type: "uint256",
483
+ internalType: "uint256"
484
+ }
485
+ ]
486
+ },
398
487
  {
399
488
  type: "error",
400
489
  name: "SafeTransferFromFailed",
@@ -496,6 +585,11 @@ const SWAP_VM_ABI = [
496
585
  internalType: "uint256"
497
586
  }]
498
587
  },
588
+ {
589
+ type: "error",
590
+ name: "TakerTraitsDeadlineExpired",
591
+ inputs: []
592
+ },
499
593
  {
500
594
  type: "error",
501
595
  name: "UnexpectedLock",
@@ -888,7 +982,7 @@ var TakerTraits = class TakerTraits {
888
982
  static IS_STRICT_THRESHOLD_BIT_FLAG = 4n;
889
983
  static IS_FIRST_TRANSFER_FROM_TAKER_BIT_FLAG = 5n;
890
984
  static USE_TRANSFER_FROM_AND_AQUA_PUSH_FLAG = 6n;
891
- constructor(exactIn, shouldUnwrap, preTransferInCallbackEnabled, preTransferOutCallbackEnabled, strictThreshold, firstTransferFromTaker, useTransferFromAndAquaPush, threshold = 0n, customReceiver = Address$1.ZERO_ADDRESS, preTransferInHookData = HexString$1.EMPTY, postTransferInHookData = HexString$1.EMPTY, preTransferOutHookData = HexString$1.EMPTY, postTransferOutHookData = HexString$1.EMPTY, preTransferInCallbackData = HexString$1.EMPTY, preTransferOutCallbackData = HexString$1.EMPTY, instructionsArgs = HexString$1.EMPTY, signature = HexString$1.EMPTY) {
985
+ constructor(exactIn, shouldUnwrap, preTransferInCallbackEnabled, preTransferOutCallbackEnabled, strictThreshold, firstTransferFromTaker, useTransferFromAndAquaPush, threshold = 0n, customReceiver = Address$1.ZERO_ADDRESS, deadline$1 = 0n, preTransferInHookData = HexString$1.EMPTY, postTransferInHookData = HexString$1.EMPTY, preTransferOutHookData = HexString$1.EMPTY, postTransferOutHookData = HexString$1.EMPTY, preTransferInCallbackData = HexString$1.EMPTY, preTransferOutCallbackData = HexString$1.EMPTY, instructionsArgs = HexString$1.EMPTY, signature = HexString$1.EMPTY) {
892
986
  this.exactIn = exactIn;
893
987
  this.shouldUnwrap = shouldUnwrap;
894
988
  this.preTransferInCallbackEnabled = preTransferInCallbackEnabled;
@@ -898,6 +992,7 @@ var TakerTraits = class TakerTraits {
898
992
  this.useTransferFromAndAquaPush = useTransferFromAndAquaPush;
899
993
  this.threshold = threshold;
900
994
  this.customReceiver = customReceiver;
995
+ this.deadline = deadline$1;
901
996
  this.preTransferInHookData = preTransferInHookData;
902
997
  this.postTransferInHookData = postTransferInHookData;
903
998
  this.preTransferOutHookData = preTransferOutHookData;
@@ -912,7 +1007,7 @@ var TakerTraits = class TakerTraits {
912
1007
  * Provides default values for unspecified fields.
913
1008
  */
914
1009
  static new(data = {}) {
915
- return new TakerTraits(data.exactIn ?? true, data.shouldUnwrap ?? false, data.preTransferInCallbackEnabled ?? false, data.preTransferOutCallbackEnabled ?? false, data.strictThreshold ?? false, data.firstTransferFromTaker ?? false, data.useTransferFromAndAquaPush ?? true, data.threshold, data.customReceiver, data.preTransferInHookData, data.postTransferInHookData, data.preTransferOutHookData, data.postTransferOutHookData, data.preTransferInCallbackData, data.preTransferOutCallbackData, data.instructionsArgs, data.signature);
1010
+ return new TakerTraits(data.exactIn ?? true, data.shouldUnwrap ?? false, data.preTransferInCallbackEnabled ?? false, data.preTransferOutCallbackEnabled ?? false, data.strictThreshold ?? false, data.firstTransferFromTaker ?? false, data.useTransferFromAndAquaPush ?? true, data.threshold, data.customReceiver, data.deadline, data.preTransferInHookData, data.postTransferInHookData, data.preTransferOutHookData, data.postTransferOutHookData, data.preTransferInCallbackData, data.preTransferOutCallbackData, data.instructionsArgs, data.signature);
916
1011
  }
917
1012
  /**
918
1013
  * Creates a default TakerTraits instance with standard settings.
@@ -932,6 +1027,7 @@ var TakerTraits = class TakerTraits {
932
1027
  firstTransferFromTaker: false,
933
1028
  useTransferFromAndAquaPush: true,
934
1029
  threshold: 0n,
1030
+ deadline: 0n,
935
1031
  customReceiver: Address$1.ZERO_ADDRESS,
936
1032
  preTransferInHookData: HexString$1.EMPTY,
937
1033
  postTransferInHookData: HexString$1.EMPTY,
@@ -946,16 +1042,16 @@ var TakerTraits = class TakerTraits {
946
1042
  /**
947
1043
  * Decodes a packed TakerTraits from a hex string.
948
1044
  * The packed format consists of:
949
- * - 18 bytes: 9 uint16 offsets for data sections
1045
+ * - 20 bytes: 10 uint16 offsets for data sections
950
1046
  * - 2 bytes: uint16 flags
951
- * - Variable: data sections (threshold, to, hook data, callback data, etc.)
1047
+ * - Variable: data sections (threshold, to, deadline, hook data, callback data, etc.)
952
1048
  * - Variable: signature
953
1049
  */
954
1050
  static decode(packed) {
955
1051
  const iter = BytesIter.BigInt(packed.toString());
956
- const offsets = Array.from({ length: 9 }, () => Number(iter.nextUint16())).reverse();
1052
+ const offsets = Array.from({ length: 10 }, () => Number(iter.nextUint16())).reverse();
957
1053
  const flags = new BN(iter.nextUint16());
958
- const dataStr = trim0x(packed.toString()).slice(40);
1054
+ const dataStr = trim0x(packed.toString()).slice(44);
959
1055
  const sections = [];
960
1056
  offsets.forEach((offset, i) => {
961
1057
  const start = i === 0 ? 0 : offsets[i - 1];
@@ -963,7 +1059,7 @@ var TakerTraits = class TakerTraits {
963
1059
  });
964
1060
  const lastOffset = offsets[offsets.length - 1];
965
1061
  const signature = dataStr.length > lastOffset * 2 ? dataStr.slice(lastOffset * 2) : "";
966
- const [threshold, to, preTransferInHookData, postTransferInHookData, preTransferOutHookData, postTransferOutHookData, preTransferInCallbackData, preTransferOutCallbackData, instructionsArgs] = sections;
1062
+ const [threshold, to, deadline$1, preTransferInHookData, postTransferInHookData, preTransferOutHookData, postTransferOutHookData, preTransferInCallbackData, preTransferOutCallbackData, instructionsArgs] = sections;
967
1063
  return TakerTraits.new({
968
1064
  exactIn: Boolean(flags.getBit(TakerTraits.IS_EXACT_IN_BIT_FLAG)),
969
1065
  shouldUnwrap: Boolean(flags.getBit(TakerTraits.SHOULD_UNWRAP_BIT_FLAG)),
@@ -974,6 +1070,7 @@ var TakerTraits = class TakerTraits {
974
1070
  useTransferFromAndAquaPush: Boolean(flags.getBit(TakerTraits.USE_TRANSFER_FROM_AND_AQUA_PUSH_FLAG)),
975
1071
  threshold: threshold ? BigInt(add0x(threshold)) : 0n,
976
1072
  customReceiver: to ? new Address$1(add0x(to)) : Address$1.ZERO_ADDRESS,
1073
+ deadline: deadline$1 ? BigInt(add0x(deadline$1)) : 0n,
977
1074
  preTransferInHookData: preTransferInHookData ? new HexString$1(add0x(preTransferInHookData)) : HexString$1.EMPTY,
978
1075
  postTransferInHookData: postTransferInHookData ? new HexString$1(add0x(postTransferInHookData)) : HexString$1.EMPTY,
979
1076
  preTransferOutHookData: preTransferOutHookData ? new HexString$1(add0x(preTransferOutHookData)) : HexString$1.EMPTY,
@@ -1002,6 +1099,7 @@ var TakerTraits = class TakerTraits {
1002
1099
  const dataFields = [
1003
1100
  this.threshold > 0n ? new HexString$1("0x" + this.threshold.toString(16).padStart(64, "0")) : HexString$1.EMPTY,
1004
1101
  !this.customReceiver.isZero() ? new HexString$1(this.customReceiver.toString()) : HexString$1.EMPTY,
1102
+ this.deadline > 0n ? new HexString$1("0x" + this.deadline.toString(16).padStart(10, "0")) : HexString$1.EMPTY,
1005
1103
  this.preTransferInHookData,
1006
1104
  this.postTransferInHookData,
1007
1105
  this.preTransferOutHookData,
@@ -1452,7 +1550,7 @@ var OnlyTakerTokenSupplyShareGteArgsCoder = class {
1452
1550
 
1453
1551
  //#endregion
1454
1552
  //#region src/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args.ts
1455
- const UINT_64_MAX$1 = 0xffffffffffffffffn;
1553
+ const UINT_64_MAX$2 = 0xffffffffffffffffn;
1456
1554
  /**
1457
1555
  * Arguments for checking if taker holds at least specified share of token's total supply
1458
1556
  * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L10
@@ -1462,7 +1560,7 @@ var OnlyTakerTokenSupplyShareGteArgs = class OnlyTakerTokenSupplyShareGteArgs {
1462
1560
  constructor(token, minShareE18) {
1463
1561
  this.token = token;
1464
1562
  this.minShareE18 = minShareE18;
1465
- assert(minShareE18 >= 0n && minShareE18 <= UINT_64_MAX$1, `Invalid minShareE18 value: ${minShareE18}. Must be a valid uint64`);
1563
+ assert(minShareE18 >= 0n && minShareE18 <= UINT_64_MAX$2, `Invalid minShareE18 value: ${minShareE18}. Must be a valid uint64`);
1466
1564
  }
1467
1565
  /**
1468
1566
  * Decodes hex data into OnlyTakerTokenSupplyShareGteArgs instance
@@ -1731,100 +1829,71 @@ __export(xyc_swap_exports, {
1731
1829
  xycSwapXD: () => xycSwapXD
1732
1830
  });
1733
1831
 
1734
- //#endregion
1735
- //#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args-coder.ts
1736
- var ConcentrateGrowLiquidityXDArgsCoder = class {
1737
- encode(args) {
1738
- const builder = new BytesBuilder();
1739
- builder.addUint16(BigInt(args.tokenDeltas.length));
1740
- for (const { tokenHalf } of args.tokenDeltas) builder.addBytes(tokenHalf.toString());
1741
- for (const { delta } of args.tokenDeltas) builder.addUint256(delta);
1742
- return new HexString$1(builder.asHex());
1743
- }
1744
- decode(data) {
1745
- const iter = BytesIter.HexString(data.toString());
1746
- const tokenCount = Number(iter.nextUint16());
1747
- const tokenHalves = [];
1748
- for (let i = 0; i < tokenCount; i++) {
1749
- const bytes = iter.nextBytes(10);
1750
- tokenHalves.push(AddressHalf.fromHex(bytes));
1751
- }
1752
- const tokenDeltas = [];
1753
- for (let i = 0; i < tokenCount; i++) tokenDeltas.push({
1754
- tokenHalf: tokenHalves[i],
1755
- delta: BigInt(iter.nextUint256())
1756
- });
1757
- return new ConcentrateGrowLiquidityXDArgs(tokenDeltas);
1758
- }
1759
- };
1760
-
1761
- //#endregion
1762
- //#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args.ts
1763
- /**
1764
- * Arguments for concentrateGrowLiquidityXD instruction with multiple token deltas
1765
- * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L139
1766
- **/
1767
- var ConcentrateGrowLiquidityXDArgs = class ConcentrateGrowLiquidityXDArgs {
1768
- static CODER = new ConcentrateGrowLiquidityXDArgsCoder();
1769
- constructor(tokenDeltas) {
1770
- this.tokenDeltas = tokenDeltas;
1771
- tokenDeltas.forEach((td, index) => {
1772
- assert(td.delta >= 0n && td.delta <= UINT_256_MAX, `Invalid delta at index ${index}: ${td.delta}. Must be >= 0 and <= UINT_256_MAX`);
1773
- });
1774
- }
1775
- /**
1776
- * Decodes hex data into ConcentrateGrowLiquidityXDArgs instance
1777
- **/
1778
- static decode(data) {
1779
- return ConcentrateGrowLiquidityXDArgs.CODER.decode(data);
1780
- }
1781
- toJSON() {
1782
- return { tokenDeltas: this.tokenDeltas.map(({ tokenHalf, delta }) => ({
1783
- token: tokenHalf.toString(),
1784
- delta: delta.toString()
1785
- })) };
1786
- }
1787
- };
1788
-
1789
1832
  //#endregion
1790
1833
  //#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args-coder.ts
1791
1834
  var ConcentrateGrowLiquidity2DArgsCoder = class {
1792
1835
  encode(args) {
1793
1836
  const builder = new BytesBuilder();
1794
- builder.addUint256(args.deltaLt);
1795
- builder.addUint256(args.deltaGt);
1837
+ builder.addUint256(args.sqrtPriceMin);
1838
+ builder.addUint256(args.sqrtPriceMax);
1796
1839
  return new HexString$1(builder.asHex());
1797
1840
  }
1798
1841
  decode(data) {
1799
1842
  const iter = BytesIter.BigInt(data.toString());
1800
- const deltaLt = iter.nextUint256();
1801
- const deltaGt = iter.nextUint256();
1802
- return new ConcentrateGrowLiquidity2DArgs(deltaLt, deltaGt);
1843
+ const sqrtPriceMin = iter.nextUint256();
1844
+ const sqrtPriceMax = iter.nextUint256();
1845
+ return new ConcentrateGrowLiquidity2DArgs(sqrtPriceMin, sqrtPriceMax);
1803
1846
  }
1804
1847
  };
1805
1848
 
1849
+ //#endregion
1850
+ //#region src/swap-vm/instructions/concentrate/bigint-sqrt.ts
1851
+ function bigintSqrt(value) {
1852
+ if (value < 0n) throw new Error("square root of negative numbers is not supported");
1853
+ if (value < 2n) return value;
1854
+ if (value <= 9007199254740991n) return BigInt(Math.floor(Math.sqrt(Number(value))));
1855
+ let x0 = value;
1856
+ let x1 = value / x0 + x0 >> 1n;
1857
+ while (x1 < x0) {
1858
+ x0 = x1;
1859
+ x1 = value / x0 + x0 >> 1n;
1860
+ }
1861
+ return x0;
1862
+ }
1863
+
1806
1864
  //#endregion
1807
1865
  //#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args.ts
1866
+ const ONE_E18 = 10n ** 18n;
1808
1867
  /**
1809
- * Arguments for concentrateGrowLiquidity2D instruction with two deltas
1868
+ * Arguments for concentrateGrowLiquidity2D instruction
1869
+ * Contract encodes sqrtPriceMin and sqrtPriceMax (2 × uint256, 64 bytes)
1870
+ * P = tokenGt/tokenLt; sqrt(P) in 1e18 fixed-point
1810
1871
  * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L172
1811
1872
  **/
1812
1873
  var ConcentrateGrowLiquidity2DArgs = class ConcentrateGrowLiquidity2DArgs {
1813
1874
  static CODER = new ConcentrateGrowLiquidity2DArgsCoder();
1814
- constructor(deltaLt, deltaGt) {
1815
- this.deltaLt = deltaLt;
1816
- this.deltaGt = deltaGt;
1817
- assert(deltaLt >= 0n && deltaLt <= UINT_256_MAX, `Invalid deltaLt: ${deltaLt}. Must be >= 0 and <= UINT_256_MAX`);
1818
- assert(deltaGt >= 0n && deltaGt <= UINT_256_MAX, `Invalid deltaGt: ${deltaGt}. Must be >= 0 and <= UINT_256_MAX`);
1875
+ constructor(sqrtPriceMin, sqrtPriceMax) {
1876
+ this.sqrtPriceMin = sqrtPriceMin;
1877
+ this.sqrtPriceMax = sqrtPriceMax;
1878
+ assert(sqrtPriceMin > 0n && sqrtPriceMin <= UINT_256_MAX, `Invalid sqrtPriceMin: ${sqrtPriceMin}. Must be > 0 and <= UINT_256_MAX`);
1879
+ assert(sqrtPriceMax > 0n && sqrtPriceMax <= UINT_256_MAX, `Invalid sqrtPriceMax: ${sqrtPriceMax}. Must be > 0 and <= UINT_256_MAX`);
1880
+ assert(sqrtPriceMin < sqrtPriceMax, `Invalid bounds: sqrtPriceMin (${sqrtPriceMin}) must be < sqrtPriceMax (${sqrtPriceMax})`);
1819
1881
  }
1820
1882
  /**
1821
- * Helper to create args from token addresses and deltas (handles ordering)
1883
+ * Build args from sqrt prices (1e18 fixed-point).
1884
+ * sqrtPriceMin/Max = sqrt(P) where P = tokenGt/tokenLt.
1822
1885
  **/
1823
- static fromTokenDeltas(tokenA, tokenB, deltaA, deltaB) {
1824
- const tokenABigInt = BigInt(tokenA.toString());
1825
- const tokenBBigInt = BigInt(tokenB.toString());
1826
- const [deltaLt, deltaGt] = tokenABigInt < tokenBBigInt ? [deltaA, deltaB] : [deltaB, deltaA];
1827
- return new ConcentrateGrowLiquidity2DArgs(deltaLt, deltaGt);
1886
+ static fromSqrtPrices(sqrtPriceMin, sqrtPriceMax) {
1887
+ return new ConcentrateGrowLiquidity2DArgs(sqrtPriceMin, sqrtPriceMax);
1888
+ }
1889
+ /**
1890
+ * Build args from raw prices P_min, P_max (1e18 fixed-point).
1891
+ * Computes sqrtPrice = sqrt(P * 1e18) so that (sqrtPrice/1e18)^2 = P/1e18.
1892
+ **/
1893
+ static fromRawPrices(rawPriceMin, rawPriceMax) {
1894
+ const sqrtPriceMin = bigintSqrt(rawPriceMin * ONE_E18);
1895
+ const sqrtPriceMax = bigintSqrt(rawPriceMax * ONE_E18);
1896
+ return new ConcentrateGrowLiquidity2DArgs(sqrtPriceMin, sqrtPriceMax);
1828
1897
  }
1829
1898
  /**
1830
1899
  * Decodes hex data into ConcentrateGrowLiquidity2DArgs instance
@@ -1834,8 +1903,8 @@ var ConcentrateGrowLiquidity2DArgs = class ConcentrateGrowLiquidity2DArgs {
1834
1903
  }
1835
1904
  toJSON() {
1836
1905
  return {
1837
- deltaLt: this.deltaLt.toString(),
1838
- deltaGt: this.deltaGt.toString()
1906
+ sqrtPriceMin: this.sqrtPriceMin.toString(),
1907
+ sqrtPriceMax: this.sqrtPriceMax.toString()
1839
1908
  };
1840
1909
  }
1841
1910
  };
@@ -1843,36 +1912,97 @@ var ConcentrateGrowLiquidity2DArgs = class ConcentrateGrowLiquidity2DArgs {
1843
1912
  //#endregion
1844
1913
  //#region src/swap-vm/instructions/concentrate/opcodes.ts
1845
1914
  /**
1846
- * Concentrates liquidity within price bounds for multiple tokens
1847
- * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L139
1848
- **/
1849
- const concentrateGrowLiquidityXD = new Opcode(Symbol("XYCConcentrate.concentrateGrowLiquidityXD"), ConcentrateGrowLiquidityXDArgs.CODER);
1850
- /**
1851
1915
  * Concentrates liquidity within price bounds for two tokens
1852
1916
  * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L172
1853
1917
  **/
1854
1918
  const concentrateGrowLiquidity2D = new Opcode(Symbol("XYCConcentrate.concentrateGrowLiquidity2D"), ConcentrateGrowLiquidity2DArgs.CODER);
1855
1919
 
1856
1920
  //#endregion
1857
- //#region src/swap-vm/instructions/concentrate/utils.ts
1858
- const TEN_POW_18 = 10n ** 18n;
1859
- function computeDeltas(balanceA, balanceB, price, priceMin, priceMax) {
1860
- const sqrtMin = sqrt(price * TEN_POW_18 / priceMin);
1861
- const sqrtMax = sqrt(priceMax * TEN_POW_18 / price);
1921
+ //#region src/swap-vm/instructions/concentrate/concentrate-liquidity-math/concentrate-liquidity-math.ts
1922
+ const ONE = 10n ** 18n;
1923
+ /**
1924
+ * Compute max achievable L from available token amounts at a given spot price.
1925
+ * Takes the minimum of L implied by each token, then returns the resulting
1926
+ * targetL and the actual amounts (actualLt, actualGt) needed.
1927
+ *
1928
+ * Mirrors XYCConcentrateArgsBuilder.computeLiquidityFromAmounts in XYCConcentrate.sol.
1929
+ *
1930
+ * @param availableLt Available amount of token with lower address
1931
+ * @param availableGt Available amount of token with higher address
1932
+ * @param sqrtPspot sqrt(P_spot) in 1e18 fixed-point
1933
+ * @param sqrtPmin sqrt(P_min) in 1e18 fixed-point
1934
+ * @param sqrtPmax sqrt(P_max) in 1e18 fixed-point
1935
+ * @returns { targetL, actualLt, actualGt } max L and amounts actually needed (<= available)
1936
+ */
1937
+ function computeLiquidityFromAmounts(availableLt, availableGt, sqrtPspot, sqrtPmin, sqrtPmax) {
1938
+ if (sqrtPmin >= sqrtPmax) throw new Error("sqrtPmax should be greater than sqrtPmin");
1939
+ const lFromLt = sqrtPmax > sqrtPspot ? mulDiv(availableLt, mulDiv(sqrtPmax, sqrtPspot, ONE), sqrtPmax - sqrtPspot) : UINT_256_MAX;
1940
+ const lFromGt = sqrtPspot > sqrtPmin ? mulDiv(availableGt, ONE, sqrtPspot - sqrtPmin) : UINT_256_MAX;
1941
+ const targetL = lFromLt < lFromGt ? lFromLt : lFromGt;
1942
+ const { bLt: actualLt, bGt: actualGt } = computeBalances(targetL, sqrtPspot, sqrtPmin, sqrtPmax);
1862
1943
  return {
1863
- deltaA: price == priceMin ? 0n : balanceA * TEN_POW_18 / (sqrtMin - TEN_POW_18),
1864
- deltaB: price == priceMax ? 0n : balanceB * TEN_POW_18 / (sqrtMax - TEN_POW_18)
1944
+ targetL,
1945
+ actualLt,
1946
+ actualGt
1865
1947
  };
1866
1948
  }
1867
- function sqrt(value) {
1868
- if (value < 0n) throw "square root of negative numbers is not supported";
1869
- if (value < 2n) return value;
1870
- function newtonIteration(n, x0) {
1871
- const x1 = n / x0 + x0 >> 1n;
1872
- if (x0 === x1 || x0 === x1 - 1n) return x0;
1873
- return newtonIteration(n, x1);
1874
- }
1875
- return newtonIteration(value, 1n);
1949
+ /**
1950
+ * Compute the initial balances for given L, P_spot, P_min, P_max:
1951
+ * bLt = L * (sqrtPmax - sqrtPspot) / (sqrtPmax * sqrtPspot / ONE)
1952
+ * bGt = L * (sqrtPspot - sqrtPmin)
1953
+ *
1954
+ * Mirrors XYCConcentrateArgsBuilder.computeBalances in XYCConcentrate.sol.
1955
+ *
1956
+ * @param targetL Liquidity L (1e18 scale implied by ONE)
1957
+ * @param sqrtPspot sqrt(P_spot) in 1e18 fixed-point
1958
+ * @param sqrtPmin sqrt(P_min) in 1e18 fixed-point
1959
+ * @param sqrtPmax sqrt(P_max) in 1e18 fixed-point
1960
+ * @returns { bLt, bGt } amounts of tokenLt and tokenGt for the given L and prices
1961
+ */
1962
+ function computeBalances(targetL, sqrtPspot, sqrtPmin, sqrtPmax) {
1963
+ if (sqrtPmin >= sqrtPmax) throw new Error("sqrtPmax should be greater than sqrtPmin");
1964
+ const bLt = sqrtPmax > sqrtPspot ? mulDiv(targetL, sqrtPmax - sqrtPspot, mulDiv(sqrtPmax, sqrtPspot, ONE)) : 0n;
1965
+ const bGt = sqrtPspot > sqrtPmin ? mulDiv(targetL, sqrtPspot - sqrtPmin, ONE) : 0n;
1966
+ return {
1967
+ bLt,
1968
+ bGt
1969
+ };
1970
+ }
1971
+ /**
1972
+ * Compute the implied spot price and liquidity from real balances and price bounds.
1973
+ *
1974
+ * Mirrors XYCConcentrateArgsBuilder.computeLiquidityAndPrice in XYCConcentrate.sol.
1975
+ *
1976
+ * @param balanceLt Real balance of the token with lower address
1977
+ * @param balanceGt Real balance of the token with higher address
1978
+ * @param sqrtPriceMin sqrt(P_min) in 1e18 fixed-point
1979
+ * @param sqrtPriceMax sqrt(P_max) in 1e18 fixed-point
1980
+ * @returns { liquidity, sqrtPriceSpot } L and implied sqrt(P_spot) in 1e18 fixed-point
1981
+ */
1982
+ function computeLiquidityAndPrice(balanceLt, balanceGt, sqrtPriceMin, sqrtPriceMax) {
1983
+ const liquidity = computeL(balanceLt, balanceGt, sqrtPriceMin, sqrtPriceMax);
1984
+ const virtualLt = balanceLt + mulDiv(liquidity, ONE, sqrtPriceMax);
1985
+ const virtualGt = balanceGt + mulDiv(liquidity, sqrtPriceMin, ONE);
1986
+ const sqrtPriceSpot = bigintSqrt(mulDiv(virtualGt, ONE * ONE, virtualLt));
1987
+ return {
1988
+ liquidity,
1989
+ sqrtPriceSpot
1990
+ };
1991
+ }
1992
+ /**
1993
+ * Compute L from real balances and price bounds.
1994
+ * Mirrors XYCConcentrateArgsBuilder._computeL in XYCConcentrate.sol.
1995
+ */
1996
+ function computeL(bLt, bGt, sqrtPriceMin, sqrtPriceMax) {
1997
+ const alpha = ONE - mulDiv(sqrtPriceMin, ONE, sqrtPriceMax);
1998
+ const beta = mulDiv(bLt, sqrtPriceMin, ONE) + mulDiv(bGt, ONE, sqrtPriceMax);
1999
+ const fourAC = mulDiv(4n * alpha, bLt, ONE) * bGt;
2000
+ const disc = beta * beta + fourAC;
2001
+ return mulDiv(beta + bigintSqrt(disc), ONE, 2n * alpha);
2002
+ }
2003
+ function mulDiv(a, b, c) {
2004
+ if (c === 0n) throw new Error("mulDiv: division by zero");
2005
+ return a * b / c;
1876
2006
  }
1877
2007
 
1878
2008
  //#endregion
@@ -1880,10 +2010,12 @@ function sqrt(value) {
1880
2010
  var concentrate_exports = {};
1881
2011
  __export(concentrate_exports, {
1882
2012
  ConcentrateGrowLiquidity2DArgs: () => ConcentrateGrowLiquidity2DArgs,
1883
- ConcentrateGrowLiquidityXDArgs: () => ConcentrateGrowLiquidityXDArgs,
1884
- computeDeltas: () => computeDeltas,
1885
- concentrateGrowLiquidity2D: () => concentrateGrowLiquidity2D,
1886
- concentrateGrowLiquidityXD: () => concentrateGrowLiquidityXD
2013
+ ONE_E18: () => ONE_E18,
2014
+ bigintSqrt: () => bigintSqrt,
2015
+ computeBalances: () => computeBalances,
2016
+ computeLiquidityAndPrice: () => computeLiquidityAndPrice,
2017
+ computeLiquidityFromAmounts: () => computeLiquidityFromAmounts,
2018
+ concentrateGrowLiquidity2D: () => concentrateGrowLiquidity2D
1887
2019
  });
1888
2020
 
1889
2021
  //#endregion
@@ -2084,14 +2216,14 @@ var DutchAuctionArgsCoder = class {
2084
2216
  const builder = new BytesBuilder();
2085
2217
  builder.addUint40(args.startTime);
2086
2218
  builder.addUint16(args.duration);
2087
- builder.addUint32(args.decayFactor);
2219
+ builder.addUint64(args.decayFactor);
2088
2220
  return new HexString$1(add0x(builder.asHex()));
2089
2221
  }
2090
2222
  decode(data) {
2091
2223
  const iter = BytesIter.BigInt(data.toString());
2092
2224
  const startTime = iter.nextUint40();
2093
2225
  const duration = iter.nextUint16();
2094
- const decayFactor = iter.nextUint32();
2226
+ const decayFactor = iter.nextUint64();
2095
2227
  return new DutchAuctionArgs(startTime, duration, decayFactor);
2096
2228
  }
2097
2229
  };
@@ -2109,7 +2241,6 @@ var DutchAuctionArgsCoder = class {
2109
2241
  * - Only works for 1=>0 swaps (token1 to token0)
2110
2242
  *
2111
2243
  * The decay factor determines the price reduction rate:
2112
- * - 1.0e18 = no decay (constant price)
2113
2244
  * - 0.999e18 = 0.1% decay per second
2114
2245
  * - 0.99e18 = 1% decay per second
2115
2246
  * - 0.9e18 = 10% decay per second
@@ -2128,7 +2259,7 @@ var DutchAuctionArgs = class DutchAuctionArgs {
2128
2259
  /**
2129
2260
  * startTime - auction start time (uint40)
2130
2261
  * duration - auction duration in seconds (uint16)
2131
- * decayFactor - price decay per second, 1e18 = no decay (uint32)
2262
+ * decayFactor - price decay per second, 1e18 = no decay (uint64)
2132
2263
  **/
2133
2264
  constructor(startTime, duration, decayFactor) {
2134
2265
  this.startTime = startTime;
@@ -2136,7 +2267,7 @@ var DutchAuctionArgs = class DutchAuctionArgs {
2136
2267
  this.decayFactor = decayFactor;
2137
2268
  assert(startTime >= 0n && startTime <= UINT_40_MAX, `Invalid startTime: ${startTime}. Must be a valid uint40`);
2138
2269
  assert(duration >= 0n && duration <= UINT_16_MAX, `Invalid duration: ${duration}. Must be a valid uint16`);
2139
- assert(decayFactor >= 0n && decayFactor <= UINT_32_MAX, `Invalid decayFactor: ${decayFactor}. Must be a valid uint32`);
2270
+ assert(decayFactor >= 0n && decayFactor <= UINT_64_MAX$1, `Invalid decayFactor: ${decayFactor}. Must be a valid uint64`);
2140
2271
  assert(decayFactor < 1e18, `Decay factor should be less than 1e18: ${decayFactor}`);
2141
2272
  }
2142
2273
  /**
@@ -2176,99 +2307,6 @@ __export(dutch_auction_exports, {
2176
2307
  dutchAuctionBalanceOut1D: () => dutchAuctionBalanceOut1D
2177
2308
  });
2178
2309
 
2179
- //#endregion
2180
- //#region src/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args-coder.ts
2181
- var OraclePriceAdjusterArgsCoder = class {
2182
- encode(args) {
2183
- const builder = new BytesBuilder();
2184
- builder.addUint64(args.maxPriceDecay);
2185
- builder.addUint16(args.maxStaleness);
2186
- builder.addUint8(args.oracleDecimals);
2187
- builder.addAddress(args.oracleAddress.toString());
2188
- return new HexString$1(builder.asHex());
2189
- }
2190
- decode(data) {
2191
- const iter = BytesIter.HexString(data.toString());
2192
- const maxPriceDecay = iter.nextUint64();
2193
- const maxStaleness = iter.nextUint16();
2194
- const oracleDecimals = iter.nextUint8();
2195
- const oracleAddress = new Address$1(iter.nextAddress());
2196
- return new OraclePriceAdjusterArgs(BigInt(maxPriceDecay), BigInt(maxStaleness), BigInt(oracleDecimals), oracleAddress);
2197
- }
2198
- };
2199
-
2200
- //#endregion
2201
- //#region src/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args.ts
2202
- /**
2203
- * @notice Oracle Price Adjuster instruction for dynamic price adjustment based on Chainlink price feeds
2204
- * @dev Adjusts swap prices to match Chainlink oracle prices within safe bounds:
2205
- * - Works only for 1=>0 swaps (token1 to token0), compatible with LimitSwap and other swap instructions
2206
- * - Fetches current market price from a Chainlink oracle (AggregatorV3Interface)
2207
- * - Adjusts the swap price towards the oracle price within maxPriceDecay limits
2208
- * - Ensures the adjustment is always favorable for the taker
2209
- * - Handles different decimal places from Chainlink oracles (e.g., 8 decimals for USD prices)
2210
- *
2211
- * This creates adaptive orders that automatically track market prices while maintaining
2212
- * safety bounds to prevent excessive slippage or manipulation.
2213
- *
2214
- * Example usage:
2215
- * 1. LimitSwap sets base price: 1 ETH for 3000 USDC
2216
- * 2. OraclePriceAdjuster with Chainlink ETH/USD oracle: 1 ETH = 3100 USD, maxPriceDecay=0.95e18 (5% max)
2217
- * 3. exactIn: Taker gets more ETH (up to 5% improvement)
2218
- * 4. exactOut: Taker pays less USDC (up to 5% discount)
2219
- *
2220
- * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/OraclePriceAdjuster.sol#L84
2221
- */
2222
- var OraclePriceAdjusterArgs = class OraclePriceAdjusterArgs {
2223
- static CODER = new OraclePriceAdjusterArgsCoder();
2224
- /**
2225
- * maxPriceDecay - maximum price decay coefficient (uint64)
2226
- * maxStaleness - maximum allowed oracle data staleness in seconds (uint16
2227
- * oracleDecimals - decimals used by the oracle (uint8)
2228
- * oracleAddress - address of the Chainlink price oracle contract
2229
- **/
2230
- constructor(maxPriceDecay, maxStaleness, oracleDecimals, oracleAddress) {
2231
- this.maxPriceDecay = maxPriceDecay;
2232
- this.maxStaleness = maxStaleness;
2233
- this.oracleDecimals = oracleDecimals;
2234
- this.oracleAddress = oracleAddress;
2235
- assert(maxPriceDecay >= 0n && maxPriceDecay <= UINT_64_MAX, `Invalid maxPriceDecay: ${maxPriceDecay}. Must be a valid uint64`);
2236
- assert(maxPriceDecay < 1e18, `Max price decay should be less than 1e18: ${maxPriceDecay}`);
2237
- assert(maxStaleness >= 0n && maxStaleness <= UINT_16_MAX, `Invalid maxStaleness: ${maxStaleness}. Must be a valid uint16`);
2238
- assert(oracleDecimals >= 0n && oracleDecimals <= UINT_8_MAX, `Invalid oracleDecimals: ${oracleDecimals}. Must be a valid uint8`);
2239
- }
2240
- /**
2241
- * Decodes hex data into OraclePriceAdjusterArgs instance
2242
- **/
2243
- static decode(data) {
2244
- return OraclePriceAdjusterArgs.CODER.decode(data);
2245
- }
2246
- toJSON() {
2247
- return {
2248
- maxPriceDecay: this.maxPriceDecay.toString(),
2249
- maxStaleness: this.maxStaleness.toString(),
2250
- oracleDecimals: this.oracleDecimals.toString(),
2251
- oracleAddress: this.oracleAddress.toString()
2252
- };
2253
- }
2254
- };
2255
-
2256
- //#endregion
2257
- //#region src/swap-vm/instructions/oracle-price-adjuster/opcodes.ts
2258
- /**
2259
- * Adjusts swap prices based on Chainlink oracle feeds
2260
- * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/OraclePriceAdjuster.sol#L84
2261
- **/
2262
- const oraclePriceAdjuster1D = new Opcode(Symbol("OraclePriceAdjuster.oraclePriceAdjuster1D"), OraclePriceAdjusterArgs.CODER);
2263
-
2264
- //#endregion
2265
- //#region src/swap-vm/instructions/oracle-price-adjuster/index.ts
2266
- var oracle_price_adjuster_exports = {};
2267
- __export(oracle_price_adjuster_exports, {
2268
- OraclePriceAdjusterArgs: () => OraclePriceAdjusterArgs,
2269
- oraclePriceAdjuster1D: () => oraclePriceAdjuster1D
2270
- });
2271
-
2272
2310
  //#endregion
2273
2311
  //#region src/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args-coder.ts
2274
2312
  var BaseFeeAdjusterArgsCoder = class {
@@ -2493,7 +2531,7 @@ __export(twap_swap_exports, {
2493
2531
  });
2494
2532
 
2495
2533
  //#endregion
2496
- //#region src/swap-vm/instructions/fee/flat-fee-args-coder.ts
2534
+ //#region src/swap-vm/instructions/fee/flat-fee/flat-fee-args-coder.ts
2497
2535
  var FlatFeeArgsCoder = class {
2498
2536
  encode(args) {
2499
2537
  const builder = new BytesBuilder();
@@ -2508,10 +2546,10 @@ var FlatFeeArgsCoder = class {
2508
2546
  };
2509
2547
 
2510
2548
  //#endregion
2511
- //#region src/swap-vm/instructions/fee/flat-fee-args.ts
2549
+ //#region src/swap-vm/instructions/fee/flat-fee/flat-fee-args.ts
2512
2550
  const FEE_100_PERCENT$1 = 1e9;
2513
2551
  /**
2514
- * Arguments for flat fee instructions (flatFeeXD, flatFeeAmountInXD, flatFeeAmountOutXD, progressiveFeeXD)
2552
+ * Arguments for flat fee instructions (flatFeeAmountInXD)
2515
2553
  * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L66
2516
2554
  **/
2517
2555
  var FlatFeeArgs = class FlatFeeArgs {
@@ -2550,7 +2588,7 @@ var FlatFeeArgs = class FlatFeeArgs {
2550
2588
  };
2551
2589
 
2552
2590
  //#endregion
2553
- //#region src/swap-vm/instructions/fee/protocol-fee-args-coder.ts
2591
+ //#region src/swap-vm/instructions/fee/protocol-fee/protocol-fee-args-coder.ts
2554
2592
  var ProtocolFeeArgsCoder = class {
2555
2593
  encode(args) {
2556
2594
  const builder = new BytesBuilder();
@@ -2567,11 +2605,11 @@ var ProtocolFeeArgsCoder = class {
2567
2605
  };
2568
2606
 
2569
2607
  //#endregion
2570
- //#region src/swap-vm/instructions/fee/protocol-fee-args.ts
2608
+ //#region src/swap-vm/instructions/fee/protocol-fee/protocol-fee-args.ts
2571
2609
  const FEE_100_PERCENT = 1e9;
2572
2610
  /**
2573
- * Arguments for protocol fee instructions (protocolFeeAmountOutXD, aquaProtocolFeeAmountOutXD)
2574
- * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L102
2611
+ * Arguments for protocol fee instructions (protocolFeeAmountInXD, aquaProtocolFeeAmountInXD)
2612
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L101
2575
2613
  **/
2576
2614
  var ProtocolFeeArgs = class ProtocolFeeArgs {
2577
2615
  static CODER = new ProtocolFeeArgsCoder();
@@ -2618,50 +2656,110 @@ var ProtocolFeeArgs = class ProtocolFeeArgs {
2618
2656
  }
2619
2657
  };
2620
2658
 
2659
+ //#endregion
2660
+ //#region src/swap-vm/instructions/fee/dynamic-protocol-fee/dynamic-protocol-fee-args-coder.ts
2661
+ var DynamicProtocolFeeArgsCoder = class {
2662
+ encode(args) {
2663
+ const builder = new BytesBuilder();
2664
+ builder.addAddress(args.feeProvider.toString());
2665
+ return new HexString$1(builder.asHex());
2666
+ }
2667
+ decode(data) {
2668
+ const iter = BytesIter.HexString(data.toString());
2669
+ const feeProvider = new Address$1(iter.nextAddress());
2670
+ return new DynamicProtocolFeeArgs(feeProvider);
2671
+ }
2672
+ };
2673
+
2674
+ //#endregion
2675
+ //#region src/swap-vm/instructions/fee/dynamic-protocol-fee/dynamic-protocol-fee-args.ts
2676
+ /**
2677
+ * Arguments for dynamic protocol fee instructions (dynamicProtocolFeeAmountInXD, aquaDynamicProtocolFeeAmountInXD).
2678
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol
2679
+ **/
2680
+ var DynamicProtocolFeeArgs = class DynamicProtocolFeeArgs {
2681
+ static CODER = new DynamicProtocolFeeArgsCoder();
2682
+ constructor(feeProvider) {
2683
+ this.feeProvider = feeProvider;
2684
+ assert(!feeProvider.isZero(), "Invalid feeProvider. Must be non zero address");
2685
+ }
2686
+ static decode(data) {
2687
+ return DynamicProtocolFeeArgs.CODER.decode(data);
2688
+ }
2689
+ toJSON() {
2690
+ return { feeProvider: this.feeProvider.toString() };
2691
+ }
2692
+ };
2693
+
2621
2694
  //#endregion
2622
2695
  //#region src/swap-vm/instructions/fee/opcodes.ts
2623
2696
  /**
2624
2697
  * Applies fee to amountIn
2625
- * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L66
2698
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L72
2626
2699
  **/
2627
2700
  const flatFeeAmountInXD = new Opcode(Symbol("Fee.flatFeeAmountInXD"), FlatFeeArgs.CODER);
2628
2701
  /**
2702
+ * Protocol fee on amountIn (feeBps + to). Fee transferred from maker to recipient.
2703
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L101
2704
+ **/
2705
+ const protocolFeeAmountInXD = new Opcode(Symbol("Fee.protocolFeeAmountInXD"), ProtocolFeeArgs.CODER);
2706
+ /**
2707
+ * Protocol fee on amountIn for Aqua (feeBps + to). Pulls from maker's Aqua balance.
2708
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L121
2709
+ **/
2710
+ const aquaProtocolFeeAmountInXD = new Opcode(Symbol("Fee.aquaProtocolFeeAmountInXD"), ProtocolFeeArgs.CODER);
2711
+ /**
2712
+ * Dynamic protocol fee: args = feeProvider address (20 bytes).
2713
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L148
2714
+ **/
2715
+ const dynamicProtocolFeeAmountInXD = new Opcode(Symbol("Fee.dynamicProtocolFeeAmountInXD"), DynamicProtocolFeeArgs.CODER);
2716
+ /**
2717
+ * Dynamic protocol fee for Aqua: args = feeProvider address (20 bytes).
2718
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L197
2719
+ **/
2720
+ const aquaDynamicProtocolFeeAmountInXD = new Opcode(Symbol("Fee.aquaDynamicProtocolFeeAmountInXD"), DynamicProtocolFeeArgs.CODER);
2721
+ /**
2629
2722
  * Applies fee to amountOut
2630
- * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L72
2723
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/FeeExperimental.sol#L40
2631
2724
  **/
2632
- const flatFeeAmountOutXD = new Opcode(Symbol("Fee.flatFeeAmountOutXD"), FlatFeeArgs.CODER);
2725
+ const flatFeeAmountOutXD = new Opcode(Symbol("FeeExperimental.flatFeeAmountOutXD"), FlatFeeArgs.CODER);
2633
2726
  /**
2634
2727
  * Applies progressive fee to amountIn
2635
- * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L78
2728
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/FeeExperimental.sol#L46
2636
2729
  **/
2637
- const progressiveFeeInXD = new Opcode(Symbol("Fee.progressiveFeeInXD"), FlatFeeArgs.CODER);
2730
+ const progressiveFeeInXD = new Opcode(Symbol("FeeExperimental.progressiveFeeInXD"), FlatFeeArgs.CODER);
2638
2731
  /**
2639
2732
  * Applies progressive fee to amountOut
2640
- * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L106
2733
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/FeeExperimental.sol#L74
2641
2734
  **/
2642
- const progressiveFeeOutXD = new Opcode(Symbol("Fee.progressiveFeeOutXD"), FlatFeeArgs.CODER);
2735
+ const progressiveFeeOutXD = new Opcode(Symbol("FeeExperimental.progressiveFeeOutXD"), FlatFeeArgs.CODER);
2643
2736
  /**
2644
- * Applies protocol fee to amountOut with direct transfer
2645
- * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L102
2737
+ * Protocol fee on amountOut (feeBps + to). Fee transferred from maker to recipient.
2738
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/FeeExperimental.sol#L107
2646
2739
  **/
2647
- const protocolFeeAmountOutXD = new Opcode(Symbol("Fee.protocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
2740
+ const protocolFeeAmountOutXD = new Opcode(Symbol("FeeExperimental.protocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
2648
2741
  /**
2649
- * Applies protocol fee to amountOut through Aqua protocol
2650
- * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L110
2742
+ * Protocol fee on amountOut (feeBps + to) for Aqua (feeBps + to). Pulls from maker's Aqua balance.
2743
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/FeeExperimental.sol#L122
2651
2744
  **/
2652
- const aquaProtocolFeeAmountOutXD = new Opcode(Symbol("Fee.aquaProtocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
2745
+ const aquaProtocolFeeAmountOutXD = new Opcode(Symbol("FeeExperimental.aquaProtocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
2653
2746
 
2654
2747
  //#endregion
2655
2748
  //#region src/swap-vm/instructions/fee/index.ts
2656
2749
  var fee_exports = {};
2657
2750
  __export(fee_exports, {
2751
+ DynamicProtocolFeeArgs: () => DynamicProtocolFeeArgs,
2658
2752
  FlatFeeArgs: () => FlatFeeArgs,
2659
2753
  ProtocolFeeArgs: () => ProtocolFeeArgs,
2754
+ aquaDynamicProtocolFeeAmountInXD: () => aquaDynamicProtocolFeeAmountInXD,
2755
+ aquaProtocolFeeAmountInXD: () => aquaProtocolFeeAmountInXD,
2660
2756
  aquaProtocolFeeAmountOutXD: () => aquaProtocolFeeAmountOutXD,
2757
+ dynamicProtocolFeeAmountInXD: () => dynamicProtocolFeeAmountInXD,
2661
2758
  flatFeeAmountInXD: () => flatFeeAmountInXD,
2662
2759
  flatFeeAmountOutXD: () => flatFeeAmountOutXD,
2663
2760
  progressiveFeeInXD: () => progressiveFeeInXD,
2664
2761
  progressiveFeeOutXD: () => progressiveFeeOutXD,
2762
+ protocolFeeAmountInXD: () => protocolFeeAmountInXD,
2665
2763
  protocolFeeAmountOutXD: () => protocolFeeAmountOutXD
2666
2764
  });
2667
2765
 
@@ -2729,63 +2827,81 @@ __export(extruction_exports, {
2729
2827
  });
2730
2828
 
2731
2829
  //#endregion
2732
- //#region src/swap-vm/instructions/stable-swap/stable-swap-2d-args-coder.ts
2733
- var StableSwap2DArgsCoder = class {
2830
+ //#region src/swap-vm/instructions/pegged-swap/pegged-swap-args-coder.ts
2831
+ var PeggedSwapArgsCoder = class {
2734
2832
  encode(args) {
2735
2833
  const builder = new BytesBuilder();
2736
- builder.addUint32(args.fee);
2737
- builder.addUint32(args.A);
2834
+ builder.addUint256(args.x0);
2835
+ builder.addUint256(args.y0);
2836
+ builder.addUint256(args.linearWidth);
2738
2837
  builder.addUint256(args.rateLt);
2739
2838
  builder.addUint256(args.rateGt);
2740
- return new HexString$1(add0x(builder.asHex()));
2839
+ return new HexString$1(builder.asHex());
2741
2840
  }
2742
2841
  decode(data) {
2743
2842
  const iter = BytesIter.BigInt(data.toString());
2744
- const fee = iter.nextUint32();
2745
- const A = iter.nextUint32();
2746
- const rateLt = iter.nextUint256();
2747
- const rateGt = iter.nextUint256();
2748
- return new StableSwap2DArgs(fee, A, rateLt, rateGt);
2843
+ const x0 = BigInt(iter.nextUint256());
2844
+ const y0 = BigInt(iter.nextUint256());
2845
+ const linearWidth = BigInt(iter.nextUint256());
2846
+ const rateLt = BigInt(iter.nextUint256());
2847
+ const rateGt = BigInt(iter.nextUint256());
2848
+ return new PeggedSwapArgs(x0, y0, linearWidth, rateLt, rateGt);
2749
2849
  }
2750
2850
  };
2751
2851
 
2752
2852
  //#endregion
2753
- //#region src/swap-vm/instructions/stable-swap/stable-swap-2d-args.ts
2853
+ //#region src/swap-vm/instructions/pegged-swap/rate-resolver.ts
2854
+ function resolveRate(tokenADecimals, tokenBDecimals) {
2855
+ if (tokenADecimals === tokenBDecimals) return 1n;
2856
+ if (tokenADecimals > tokenBDecimals) return 1n;
2857
+ return 10n ** BigInt(tokenBDecimals - tokenADecimals);
2858
+ }
2859
+
2860
+ //#endregion
2861
+ //#region src/swap-vm/instructions/pegged-swap/pegged-swap-args.ts
2754
2862
  /**
2755
- * Arguments for stableSwap2D instruction for stablecoin optimized swaps
2863
+ * Arguments for PeggedSwap._peggedSwapGrowPriceRange2D.
2864
+ * 5 × uint256: x0, y0, linearWidth, rateLt, rateGt (160 bytes).
2865
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/PeggedSwap.sol
2756
2866
  **/
2757
- var StableSwap2DArgs = class StableSwap2DArgs {
2758
- static CODER = new StableSwap2DArgsCoder();
2759
- /**
2760
- * fee - swap fee in 1e10 (uint32)
2761
- * A - amplification coefficient (uint32)
2762
- * rateLt - rate for token with lower address (uint256)
2763
- * rateGt - rate for token with higher address (uint256)
2764
- **/
2765
- constructor(fee, A, rateLt, rateGt) {
2766
- this.fee = fee;
2767
- this.A = A;
2867
+ var PeggedSwapArgs = class PeggedSwapArgs {
2868
+ static CODER = new PeggedSwapArgsCoder();
2869
+ /**
2870
+ * x0 - Initial X reserve (normalization factor) = initial_balance_X * rateLt (or rateGt)
2871
+ * y0 - Initial Y reserve (normalization factor) = initial_balance_Y * rateGt (or rateLt)
2872
+ * linearWidth - Linear component coefficient A scaled by 1e27 (e.g., 0.8e27 for A=0.8)
2873
+ * rateLt - Rate multiplier for token with LOWER address
2874
+ * rateGt - Rate multiplier for token with GREATER address
2875
+ * > For equal decimals (e.g., both 18): rateLt = rateGt = 1
2876
+ * > For 18 vs 6 decimals: rate18 = 1, rate6 = 1e12 (to scale up to common precision)
2877
+ **/
2878
+ constructor(x0, y0, linearWidth, rateLt, rateGt) {
2879
+ this.x0 = x0;
2880
+ this.y0 = y0;
2881
+ this.linearWidth = linearWidth;
2768
2882
  this.rateLt = rateLt;
2769
2883
  this.rateGt = rateGt;
2770
- assert(fee >= 0n && fee <= UINT_32_MAX, `Invalid fee: ${fee}`);
2771
- assert(A >= 0n && A <= UINT_32_MAX, `Invalid A: ${A}`);
2884
+ assert(x0 > 0n && y0 > 0n, "Reserves cannot be zero");
2885
+ assert(x0 <= UINT_256_MAX, `Invalid x0: ${x0}`);
2886
+ assert(y0 <= UINT_256_MAX, `Invalid y0: ${y0}`);
2887
+ assert(linearWidth <= 2n * 10n ** 27n, `Invalid linearWidth: ${linearWidth}`);
2772
2888
  assert(rateLt > 0n && rateLt <= UINT_256_MAX, `Invalid rateLt: ${rateLt}. Must be positive and <= UINT_256_MAX`);
2773
2889
  assert(rateGt > 0n && rateGt <= UINT_256_MAX, `Invalid rateGt: ${rateGt}. Must be positive and <= UINT_256_MAX`);
2774
2890
  }
2775
- static fromTokens(fee, a, tokenA, tokenB, rateA, rateB) {
2776
- if (BigInt(tokenA.toString()) < BigInt(tokenB.toString())) return new StableSwap2DArgs(fee, a, rateA, rateB);
2777
- return new StableSwap2DArgs(fee, a, rateB, rateA);
2891
+ static fromTokens(tokenA, tokenB, linearWidth) {
2892
+ const tokenARate = resolveRate(tokenA.decimals, tokenB.decimals);
2893
+ const tokenBRate = resolveRate(tokenB.decimals, tokenA.decimals);
2894
+ if (BigInt(tokenA.address.toString()) < BigInt(tokenB.address.toString())) return new PeggedSwapArgs(tokenA.reserve * tokenARate, tokenB.reserve * tokenBRate, linearWidth, tokenARate, tokenBRate);
2895
+ return new PeggedSwapArgs(tokenB.reserve * tokenBRate, tokenA.reserve * tokenARate, linearWidth, tokenBRate, tokenARate);
2778
2896
  }
2779
- /**
2780
- * Decodes hex data into StableSwap2DArgs instance
2781
- **/
2782
2897
  static decode(data) {
2783
- return StableSwap2DArgs.CODER.decode(data);
2898
+ return PeggedSwapArgs.CODER.decode(data);
2784
2899
  }
2785
2900
  toJSON() {
2786
2901
  return {
2787
- fee: this.fee.toString(),
2788
- A: this.A.toString(),
2902
+ x0: this.x0.toString(),
2903
+ y0: this.y0.toString(),
2904
+ linearWidth: this.linearWidth.toString(),
2789
2905
  rateLt: this.rateLt.toString(),
2790
2906
  rateGt: this.rateGt.toString()
2791
2907
  };
@@ -2793,18 +2909,112 @@ var StableSwap2DArgs = class StableSwap2DArgs {
2793
2909
  };
2794
2910
 
2795
2911
  //#endregion
2796
- //#region src/swap-vm/instructions/stable-swap/opcodes.ts
2912
+ //#region src/swap-vm/instructions/pegged-swap/opcodes.ts
2913
+ /**
2914
+ * PeggedSwap - Square-root linear swap curve for pegged assets
2915
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/PeggedSwap.sol
2916
+ **/
2917
+ const peggedSwapGrowPriceRange2D = new Opcode(Symbol("PeggedSwap.peggedSwapGrowPriceRange2D"), PeggedSwapArgs.CODER);
2918
+
2919
+ //#endregion
2920
+ //#region src/swap-vm/instructions/pegged-swap/index.ts
2921
+ var pegged_swap_exports = {};
2922
+ __export(pegged_swap_exports, {
2923
+ PeggedSwapArgs: () => PeggedSwapArgs,
2924
+ peggedSwapGrowPriceRange2D: () => peggedSwapGrowPriceRange2D
2925
+ });
2926
+
2927
+ //#endregion
2928
+ //#region src/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args-coder.ts
2929
+ var OraclePriceAdjusterArgsCoder = class {
2930
+ encode(args) {
2931
+ const builder = new BytesBuilder();
2932
+ builder.addUint64(args.maxPriceDecay);
2933
+ builder.addUint16(args.maxStaleness);
2934
+ builder.addUint8(args.oracleDecimals);
2935
+ builder.addAddress(args.oracleAddress.toString());
2936
+ return new HexString$1(builder.asHex());
2937
+ }
2938
+ decode(data) {
2939
+ const iter = BytesIter.HexString(data.toString());
2940
+ const maxPriceDecay = iter.nextUint64();
2941
+ const maxStaleness = iter.nextUint16();
2942
+ const oracleDecimals = iter.nextUint8();
2943
+ const oracleAddress = new Address$1(iter.nextAddress());
2944
+ return new OraclePriceAdjusterArgs(BigInt(maxPriceDecay), BigInt(maxStaleness), BigInt(oracleDecimals), oracleAddress);
2945
+ }
2946
+ };
2947
+
2948
+ //#endregion
2949
+ //#region src/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args.ts
2950
+ /**
2951
+ * @notice Oracle Price Adjuster instruction for dynamic price adjustment based on Chainlink price feeds
2952
+ * @dev Adjusts swap prices to match Chainlink oracle prices within safe bounds:
2953
+ * - Works only for 1=>0 swaps (token1 to token0), compatible with LimitSwap and other swap instructions
2954
+ * - Fetches current market price from a Chainlink oracle (AggregatorV3Interface)
2955
+ * - Adjusts the swap price towards the oracle price within maxPriceDecay limits
2956
+ * - Ensures the adjustment is always favorable for the taker
2957
+ * - Handles different decimal places from Chainlink oracles (e.g., 8 decimals for USD prices)
2958
+ *
2959
+ * This creates adaptive orders that automatically track market prices while maintaining
2960
+ * safety bounds to prevent excessive slippage or manipulation.
2961
+ *
2962
+ * Example usage:
2963
+ * 1. LimitSwap sets base price: 1 ETH for 3000 USDC
2964
+ * 2. OraclePriceAdjuster with Chainlink ETH/USD oracle: 1 ETH = 3100 USD, maxPriceDecay=0.95e18 (5% max)
2965
+ * 3. exactIn: Taker gets more ETH (up to 5% improvement)
2966
+ * 4. exactOut: Taker pays less USDC (up to 5% discount)
2967
+ *
2968
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/OraclePriceAdjuster.sol#L84
2969
+ */
2970
+ var OraclePriceAdjusterArgs = class OraclePriceAdjusterArgs {
2971
+ static CODER = new OraclePriceAdjusterArgsCoder();
2972
+ /**
2973
+ * maxPriceDecay - maximum price decay coefficient (uint64)
2974
+ * maxStaleness - maximum allowed oracle data staleness in seconds (uint16
2975
+ * oracleDecimals - decimals used by the oracle (uint8)
2976
+ * oracleAddress - address of the Chainlink price oracle contract
2977
+ **/
2978
+ constructor(maxPriceDecay, maxStaleness, oracleDecimals, oracleAddress) {
2979
+ this.maxPriceDecay = maxPriceDecay;
2980
+ this.maxStaleness = maxStaleness;
2981
+ this.oracleDecimals = oracleDecimals;
2982
+ this.oracleAddress = oracleAddress;
2983
+ assert(maxPriceDecay >= 0n && maxPriceDecay <= UINT_64_MAX, `Invalid maxPriceDecay: ${maxPriceDecay}. Must be a valid uint64`);
2984
+ assert(maxPriceDecay < 1e18, `Max price decay should be less than 1e18: ${maxPriceDecay}`);
2985
+ assert(maxStaleness >= 0n && maxStaleness <= UINT_16_MAX, `Invalid maxStaleness: ${maxStaleness}. Must be a valid uint16`);
2986
+ assert(oracleDecimals >= 0n && oracleDecimals <= UINT_8_MAX, `Invalid oracleDecimals: ${oracleDecimals}. Must be a valid uint8`);
2987
+ }
2988
+ /**
2989
+ * Decodes hex data into OraclePriceAdjusterArgs instance
2990
+ **/
2991
+ static decode(data) {
2992
+ return OraclePriceAdjusterArgs.CODER.decode(data);
2993
+ }
2994
+ toJSON() {
2995
+ return {
2996
+ maxPriceDecay: this.maxPriceDecay.toString(),
2997
+ maxStaleness: this.maxStaleness.toString(),
2998
+ oracleDecimals: this.oracleDecimals.toString(),
2999
+ oracleAddress: this.oracleAddress.toString()
3000
+ };
3001
+ }
3002
+ };
3003
+
3004
+ //#endregion
3005
+ //#region src/swap-vm/instructions/oracle-price-adjuster/opcodes.ts
2797
3006
  /**
2798
- * Stablecoin optimized swap using StableSwap algorithm (Curve-style)
3007
+ * Adjusts swap prices based on Chainlink oracle feeds
3008
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/OraclePriceAdjuster.sol#L84
2799
3009
  **/
2800
- const stableSwap2D = new Opcode(Symbol("StableSwap.stableSwap2D"), StableSwap2DArgs.CODER);
3010
+ const oraclePriceAdjuster1D = new Opcode(Symbol("OraclePriceAdjuster.oraclePriceAdjuster1D"), OraclePriceAdjusterArgs.CODER);
2801
3011
 
2802
3012
  //#endregion
2803
- //#region src/swap-vm/instructions/stable-swap/index.ts
2804
- var stable_swap_exports = {};
2805
- __export(stable_swap_exports, {
2806
- StableSwap2DArgs: () => StableSwap2DArgs,
2807
- stableSwap2D: () => stableSwap2D
3013
+ //#region src/swap-vm/instructions/oracle-price-adjuster/index.ts
3014
+ var oracle_price_adjuster_exports = {};
3015
+ __export(oracle_price_adjuster_exports, {
3016
+ OraclePriceAdjusterArgs: () => OraclePriceAdjusterArgs,
3017
+ oraclePriceAdjuster1D: () => oraclePriceAdjuster1D
2808
3018
  });
2809
3019
 
2810
3020
  //#endregion
@@ -2826,7 +3036,8 @@ __export(instructions_exports, {
2826
3036
  limitSwap: () => limit_swap_exports,
2827
3037
  minRate: () => min_rate_exports,
2828
3038
  oraclePriceAdjuster: () => oracle_price_adjuster_exports,
2829
- stableSwap: () => stable_swap_exports,
3039
+ peggedSwap: () => pegged_swap_exports,
3040
+ stableSwap: () => pegged_swap_exports,
2830
3041
  twapSwap: () => twap_swap_exports,
2831
3042
  xycSwap: () => xyc_swap_exports
2832
3043
  });
@@ -2858,7 +3069,6 @@ const _allInstructions = [
2858
3069
  invalidateTokenIn1D,
2859
3070
  invalidateTokenOut1D,
2860
3071
  xycSwapXD,
2861
- concentrateGrowLiquidityXD,
2862
3072
  concentrateGrowLiquidity2D,
2863
3073
  decayXD,
2864
3074
  limitSwap1D,
@@ -2867,7 +3077,6 @@ const _allInstructions = [
2867
3077
  adjustMinRate1D,
2868
3078
  dutchAuctionBalanceIn1D,
2869
3079
  dutchAuctionBalanceOut1D,
2870
- oraclePriceAdjuster1D,
2871
3080
  baseFeeAdjuster1D,
2872
3081
  twap,
2873
3082
  extruction,
@@ -2877,7 +3086,12 @@ const _allInstructions = [
2877
3086
  progressiveFeeInXD,
2878
3087
  progressiveFeeOutXD,
2879
3088
  protocolFeeAmountOutXD,
2880
- aquaProtocolFeeAmountOutXD
3089
+ aquaProtocolFeeAmountOutXD,
3090
+ peggedSwapGrowPriceRange2D,
3091
+ protocolFeeAmountInXD,
3092
+ aquaProtocolFeeAmountInXD,
3093
+ dynamicProtocolFeeAmountInXD,
3094
+ aquaDynamicProtocolFeeAmountInXD
2881
3095
  ];
2882
3096
  /**
2883
3097
  * Aqua opcodes array - matching AquaSwapVM contract (29 opcodes)
@@ -2902,16 +3116,21 @@ const aquaInstructions = [
2902
3116
  onlyTakerTokenBalanceGte,
2903
3117
  onlyTakerTokenSupplyShareGte,
2904
3118
  xycSwapXD,
2905
- concentrateGrowLiquidityXD,
2906
3119
  concentrateGrowLiquidity2D,
2907
3120
  decayXD,
2908
3121
  salt,
2909
3122
  flatFeeAmountInXD,
2910
- flatFeeAmountOutXD,
2911
- progressiveFeeInXD,
2912
- progressiveFeeOutXD,
2913
- protocolFeeAmountOutXD,
2914
- aquaProtocolFeeAmountOutXD
3123
+ EMPTY_OPCODE,
3124
+ EMPTY_OPCODE,
3125
+ EMPTY_OPCODE,
3126
+ EMPTY_OPCODE,
3127
+ EMPTY_OPCODE,
3128
+ protocolFeeAmountInXD,
3129
+ aquaProtocolFeeAmountInXD,
3130
+ dynamicProtocolFeeAmountInXD,
3131
+ aquaDynamicProtocolFeeAmountInXD,
3132
+ peggedSwapGrowPriceRange2D,
3133
+ extruction
2915
3134
  ];
2916
3135
 
2917
3136
  //#endregion
@@ -3213,17 +3432,17 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
3213
3432
  return this;
3214
3433
  }
3215
3434
  /**
3216
- * Concentrates liquidity within price bounds for multiple tokens
3435
+ * Concentrates liquidity within price bounds for two tokens
3217
3436
  **/
3218
- concentrateGrowLiquidityXD(data) {
3219
- super.add(concentrateGrowLiquidityXD.createIx(new ConcentrateGrowLiquidityXDArgs(data.tokenDeltas)));
3437
+ concentrateGrowLiquidity2D(data) {
3438
+ super.add(concentrateGrowLiquidity2D.createIx(new ConcentrateGrowLiquidity2DArgs(data.sqrtPriceMin, data.sqrtPriceMax)));
3220
3439
  return this;
3221
3440
  }
3222
3441
  /**
3223
- * Concentrates liquidity within price bounds for two tokens
3442
+ * Square-root linear swap curve for pegged assets
3224
3443
  **/
3225
- concentrateGrowLiquidity2D(data) {
3226
- super.add(concentrateGrowLiquidity2D.createIx(new ConcentrateGrowLiquidity2DArgs(data.deltaLt, data.deltaGt)));
3444
+ peggedSwapGrowPriceRange2D(data) {
3445
+ super.add(peggedSwapGrowPriceRange2D.createIx(new PeggedSwapArgs(data.x0, data.y0, data.linearWidth, data.rateLt, data.rateGt)));
3227
3446
  return this;
3228
3447
  }
3229
3448
  /**
@@ -3276,13 +3495,6 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
3276
3495
  return this;
3277
3496
  }
3278
3497
  /**
3279
- * Adjusts swap prices based on Chainlink oracle feeds
3280
- **/
3281
- oraclePriceAdjuster1D(data) {
3282
- super.add(oraclePriceAdjuster1D.createIx(new OraclePriceAdjusterArgs(data.maxPriceDecay, data.maxStaleness, data.oracleDecimals, data.oracleAddress)));
3283
- return this;
3284
- }
3285
- /**
3286
3498
  * Adjusts swap prices based on network gas costs
3287
3499
  **/
3288
3500
  baseFeeAdjuster1D(data) {
@@ -3332,6 +3544,13 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
3332
3544
  return this;
3333
3545
  }
3334
3546
  /**
3547
+ * Applies protocol fee to amountIn with direct transfer
3548
+ **/
3549
+ protocolFeeAmountInXD(data) {
3550
+ super.add(protocolFeeAmountInXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
3551
+ return this;
3552
+ }
3553
+ /**
3335
3554
  * Applies protocol fee to amountOut with direct transfer
3336
3555
  **/
3337
3556
  protocolFeeAmountOutXD(data) {
@@ -3339,6 +3558,13 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
3339
3558
  return this;
3340
3559
  }
3341
3560
  /**
3561
+ * Applies protocol fee to amountIn through Aqua protocol
3562
+ **/
3563
+ aquaProtocolFeeAmountInXD(data) {
3564
+ super.add(aquaProtocolFeeAmountInXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
3565
+ return this;
3566
+ }
3567
+ /**
3342
3568
  * Applies protocol fee to amountOut through Aqua protocol
3343
3569
  **/
3344
3570
  aquaProtocolFeeAmountOutXD(data) {
@@ -3346,6 +3572,20 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
3346
3572
  return this;
3347
3573
  }
3348
3574
  /**
3575
+ * Applies protocol fee, fetched from external contract, to amountIn with direct transfer
3576
+ **/
3577
+ dynamicProtocolFeeAmountInXD(data) {
3578
+ super.add(dynamicProtocolFeeAmountInXD.createIx(new DynamicProtocolFeeArgs(data.feeProvider)));
3579
+ return this;
3580
+ }
3581
+ /**
3582
+ * Applies protocol fee, fetched from external contract, to amountIn through Aqua protocol
3583
+ **/
3584
+ aquaDynamicProtocolFeeAmountInXD(data) {
3585
+ super.add(aquaDynamicProtocolFeeAmountInXD.createIx(new DynamicProtocolFeeArgs(data.feeProvider)));
3586
+ return this;
3587
+ }
3588
+ /**
3349
3589
  * DEBUG: Prints current swap registers (amounts and tokens)
3350
3590
  * WARNING: Requires withDebug() to be called first, otherwise will throw an error
3351
3591
  */
@@ -3481,17 +3721,17 @@ var AquaProgramBuilder = class AquaProgramBuilder extends ProgramBuilder {
3481
3721
  return this;
3482
3722
  }
3483
3723
  /**
3484
- * Concentrates liquidity within price bounds for multiple tokens
3724
+ * Concentrates liquidity within price bounds for two tokens
3485
3725
  **/
3486
- concentrateGrowLiquidityXD(data) {
3487
- super.add(concentrateGrowLiquidityXD.createIx(new ConcentrateGrowLiquidityXDArgs(data.tokenDeltas)));
3726
+ concentrateGrowLiquidity2D(data) {
3727
+ super.add(concentrateGrowLiquidity2D.createIx(new ConcentrateGrowLiquidity2DArgs(data.sqrtPriceMin, data.sqrtPriceMax)));
3488
3728
  return this;
3489
3729
  }
3490
3730
  /**
3491
- * Concentrates liquidity within price bounds for two tokens
3731
+ * Square-root linear swap curve for pegged assets
3492
3732
  **/
3493
- concentrateGrowLiquidity2D(data) {
3494
- super.add(concentrateGrowLiquidity2D.createIx(new ConcentrateGrowLiquidity2DArgs(data.deltaLt, data.deltaGt)));
3733
+ peggedSwapGrowPriceRange2D(data) {
3734
+ super.add(peggedSwapGrowPriceRange2D.createIx(new PeggedSwapArgs(data.x0, data.y0, data.linearWidth, data.rateLt, data.rateGt)));
3495
3735
  return this;
3496
3736
  }
3497
3737
  /**
@@ -3509,38 +3749,31 @@ var AquaProgramBuilder = class AquaProgramBuilder extends ProgramBuilder {
3509
3749
  return this;
3510
3750
  }
3511
3751
  /**
3512
- * Applies fee to amountOut
3513
- **/
3514
- flatFeeAmountOutXD(data) {
3515
- super.add(flatFeeAmountOutXD.createIx(new FlatFeeArgs(data.fee)));
3516
- return this;
3517
- }
3518
- /**
3519
- * Applies progressive fee to amountIn
3752
+ * Applies protocol fee to amountIn with direct transfer
3520
3753
  **/
3521
- progressiveFeeInXD(data) {
3522
- super.add(progressiveFeeInXD.createIx(new FlatFeeArgs(data.fee)));
3754
+ protocolFeeAmountInXD(data) {
3755
+ super.add(protocolFeeAmountInXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
3523
3756
  return this;
3524
3757
  }
3525
3758
  /**
3526
- * Applies progressive fee to amountOut
3759
+ * Applies protocol fee to amountIn through Aqua protocol
3527
3760
  **/
3528
- progressiveFeeOutXD(data) {
3529
- super.add(progressiveFeeOutXD.createIx(new FlatFeeArgs(data.fee)));
3761
+ aquaProtocolFeeAmountInXD(data) {
3762
+ super.add(aquaProtocolFeeAmountInXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
3530
3763
  return this;
3531
3764
  }
3532
3765
  /**
3533
- * Applies protocol fee to amountOut with direct transfer
3766
+ * Applies protocol fee, fetched from external contract, to amountIn with direct transfer
3534
3767
  **/
3535
- protocolFeeAmountOutXD(data) {
3536
- super.add(protocolFeeAmountOutXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
3768
+ dynamicProtocolFeeAmountInXD(data) {
3769
+ super.add(dynamicProtocolFeeAmountInXD.createIx(new DynamicProtocolFeeArgs(data.feeProvider)));
3537
3770
  return this;
3538
3771
  }
3539
3772
  /**
3540
- * Applies protocol fee to amountOut through Aqua protocol
3773
+ * Applies protocol fee, fetched from external contract, to amountIn through Aqua protocol
3541
3774
  **/
3542
- aquaProtocolFeeAmountOutXD(data) {
3543
- super.add(aquaProtocolFeeAmountOutXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
3775
+ aquaDynamicProtocolFeeAmountInXD(data) {
3776
+ super.add(aquaDynamicProtocolFeeAmountInXD.createIx(new DynamicProtocolFeeArgs(data.feeProvider)));
3544
3777
  return this;
3545
3778
  }
3546
3779
  /**
@@ -3703,23 +3936,12 @@ var Order = class Order {
3703
3936
 
3704
3937
  //#endregion
3705
3938
  //#region src/swap-vm/strategies/aqua-amm-strategy.ts
3706
- /**
3707
- * Aqua AMM Strategy builder that mirrors AquaAMM.sol
3708
- * @see https://github.com/1inch/swap-vm/blob/main/src/strategies/AquaAMM.sol
3709
- */
3710
- var AquaAMMStrategy = class AquaAMMStrategy {
3939
+ var AquaAMMStrategy = class {
3711
3940
  feeBpsIn;
3712
- deltas;
3713
3941
  decayPeriod;
3714
3942
  protocolFee;
3715
3943
  salt;
3716
- constructor(tokenA, tokenB) {
3717
- this.tokenA = tokenA;
3718
- this.tokenB = tokenB;
3719
- }
3720
- static new(tokens) {
3721
- return new AquaAMMStrategy(tokens.tokenA, tokens.tokenB);
3722
- }
3944
+ constructor() {}
3723
3945
  withProtocolFee(bps, receiver) {
3724
3946
  this.protocolFee = {
3725
3947
  bps,
@@ -3727,13 +3949,6 @@ var AquaAMMStrategy = class AquaAMMStrategy {
3727
3949
  };
3728
3950
  return this;
3729
3951
  }
3730
- withDeltas(a, b) {
3731
- this.deltas = {
3732
- a,
3733
- b
3734
- };
3735
- return this;
3736
- }
3737
3952
  withDecayPeriod(decayPeriod) {
3738
3953
  this.decayPeriod = decayPeriod;
3739
3954
  return this;
@@ -3746,22 +3961,80 @@ var AquaAMMStrategy = class AquaAMMStrategy {
3746
3961
  this.salt = salt$1;
3747
3962
  return this;
3748
3963
  }
3964
+ };
3965
+
3966
+ //#endregion
3967
+ //#region src/swap-vm/strategies/aqua-xyc-amm-strategy.ts
3968
+ var AquaXYCAmmStrategy = class AquaXYCAmmStrategy extends AquaAMMStrategy {
3969
+ constructor(xycConcentrateArgs) {
3970
+ super();
3971
+ this.xycConcentrateArgs = xycConcentrateArgs;
3972
+ }
3973
+ static new() {
3974
+ return new AquaXYCAmmStrategy();
3975
+ }
3976
+ static newConcentrate(prices) {
3977
+ if ("rawPriceMin" in prices && "rawPriceMax" in prices) {
3978
+ const args = ConcentrateGrowLiquidity2DArgs.fromRawPrices(prices.rawPriceMin, prices.rawPriceMax);
3979
+ return new AquaXYCAmmStrategy(args);
3980
+ }
3981
+ if ("sqrtPriceMin" in prices && "sqrtPriceMax" in prices) {
3982
+ const args = ConcentrateGrowLiquidity2DArgs.fromSqrtPrices(prices.sqrtPriceMin, prices.sqrtPriceMax);
3983
+ return new AquaXYCAmmStrategy(args);
3984
+ }
3985
+ throw new Error("unknown parameters for newXYCConcentrate");
3986
+ }
3749
3987
  build() {
3750
3988
  const builder = new AquaProgramBuilder();
3751
- if (this.deltas) {
3752
- const data = ConcentrateGrowLiquidity2DArgs.fromTokenDeltas(this.tokenA, this.tokenB, this.deltas.a, this.deltas.b);
3753
- builder.add(concentrateGrowLiquidity2D.createIx(data));
3989
+ if (this.protocolFee) {
3990
+ const data = ProtocolFeeArgs.fromBps(this.protocolFee.bps, this.protocolFee.receiver);
3991
+ builder.add(aquaProtocolFeeAmountInXD.createIx(data));
3754
3992
  }
3993
+ if (this.xycConcentrateArgs) builder.add(concentrateGrowLiquidity2D.createIx(this.xycConcentrateArgs));
3755
3994
  if (this.decayPeriod) builder.decayXD({ decayPeriod: this.decayPeriod });
3756
3995
  if (this.feeBpsIn) {
3757
3996
  const data = FlatFeeArgs.fromBps(this.feeBpsIn);
3758
3997
  builder.add(flatFeeAmountInXD.createIx(data));
3759
3998
  }
3999
+ builder.xycSwapXD();
4000
+ if (this.salt) builder.salt({ salt: this.salt });
4001
+ return builder.build();
4002
+ }
4003
+ };
4004
+
4005
+ //#endregion
4006
+ //#region src/swap-vm/strategies/aqua-pegged-amm-strategy.ts
4007
+ var AquaPeggedAmmStrategy = class AquaPeggedAmmStrategy extends AquaAMMStrategy {
4008
+ constructor(tokenA, tokenB, linearWidth) {
4009
+ super();
4010
+ this.tokenA = tokenA;
4011
+ this.tokenB = tokenB;
4012
+ this.linearWidth = linearWidth;
4013
+ }
4014
+ static new(data) {
4015
+ return new AquaPeggedAmmStrategy(data.tokenA, data.tokenB, data.linearWidth);
4016
+ }
4017
+ build() {
4018
+ const builder = new AquaProgramBuilder();
3760
4019
  if (this.protocolFee) {
3761
4020
  const data = ProtocolFeeArgs.fromBps(this.protocolFee.bps, this.protocolFee.receiver);
3762
- builder.add(aquaProtocolFeeAmountOutXD.createIx(data));
4021
+ builder.add(aquaProtocolFeeAmountInXD.createIx(data));
3763
4022
  }
3764
- builder.xycSwapXD();
4023
+ if (this.decayPeriod) builder.decayXD({ decayPeriod: this.decayPeriod });
4024
+ if (this.feeBpsIn) {
4025
+ const data = FlatFeeArgs.fromBps(this.feeBpsIn);
4026
+ builder.add(flatFeeAmountInXD.createIx(data));
4027
+ }
4028
+ const peggedArgs = PeggedSwapArgs.fromTokens({
4029
+ address: this.tokenA.address,
4030
+ decimals: this.tokenA.decimals,
4031
+ reserve: this.tokenA.reserve
4032
+ }, {
4033
+ address: this.tokenB.address,
4034
+ decimals: this.tokenB.decimals,
4035
+ reserve: this.tokenB.reserve
4036
+ }, this.linearWidth);
4037
+ builder.peggedSwapGrowPriceRange2D(peggedArgs);
3765
4038
  if (this.salt) builder.salt({ salt: this.salt });
3766
4039
  return builder.build();
3767
4040
  }
@@ -3773,4 +4046,4 @@ var abi_exports = {};
3773
4046
  __export(abi_exports, { SWAP_VM_ABI: () => SWAP_VM_ABI });
3774
4047
 
3775
4048
  //#endregion
3776
- export { abi_exports as ABI, AQUA_SWAP_VM_CONTRACT_ADDRESSES, Address, AquaAMMStrategy, AquaProgramBuilder, CallInfo, HexString, MakerTraits, NetworkEnum, Order, ProgramBuilder, RegularProgramBuilder, SwapVMContract, SwapVmProgram, SwappedEvent, TakerTraits, instructions_exports as instructions };
4049
+ export { abi_exports as ABI, AQUA_SWAP_VM_CONTRACT_ADDRESSES, Address, AquaAMMStrategy, AquaPeggedAmmStrategy, AquaProgramBuilder, AquaXYCAmmStrategy, CallInfo, HexString, MakerTraits, NetworkEnum, Order, ProgramBuilder, RegularProgramBuilder, SwapVMContract, SwapVmProgram, SwappedEvent, TakerTraits, instructions_exports as instructions };