@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/dist/index.mjs CHANGED
@@ -2,7 +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 assert$1 from "node:assert";
5
+ import { UINT_64_MAX as UINT_64_MAX$1 } from "@1inch/byte-utils/dist/constants";
6
6
 
7
7
  //#region rolldown:runtime
8
8
  var __defProp = Object.defineProperty;
@@ -329,6 +329,11 @@ const SWAP_VM_ABI = [
329
329
  name: "amount",
330
330
  type: "uint256",
331
331
  internalType: "uint256"
332
+ },
333
+ {
334
+ name: "amountNetPulled",
335
+ type: "uint256",
336
+ internalType: "uint256"
332
337
  }
333
338
  ]
334
339
  },
@@ -396,6 +401,89 @@ const SWAP_VM_ABI = [
396
401
  internalType: "uint256"
397
402
  }]
398
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
+ },
399
487
  {
400
488
  type: "error",
401
489
  name: "SafeTransferFromFailed",
@@ -497,6 +585,11 @@ const SWAP_VM_ABI = [
497
585
  internalType: "uint256"
498
586
  }]
499
587
  },
588
+ {
589
+ type: "error",
590
+ name: "TakerTraitsDeadlineExpired",
591
+ inputs: []
592
+ },
500
593
  {
501
594
  type: "error",
502
595
  name: "UnexpectedLock",
@@ -842,7 +935,7 @@ var MakerTraits = class MakerTraits {
842
935
  traits = traits.setMask(MakerTraits.CUSTOM_RECEIVER_MASK, BigInt(this.customReceiver?.toString() || 0n));
843
936
  const { data, offsets } = MakerTraits.HOOKS.reduce((acc, hookName, i) => {
844
937
  const hook = this[hookName];
845
- const hasTarget = this.hasTargetForHook(hookName);
938
+ const hasTarget = this.hasTargetForHook(hookName, maker);
846
939
  const encoded = hook && hasTarget ? hook.encode() : hook?.data || HexString$1.EMPTY;
847
940
  acc.sum += BigInt(encoded.bytesCount());
848
941
  acc.offsets += acc.sum << 16n * BigInt(i);
@@ -889,7 +982,7 @@ var TakerTraits = class TakerTraits {
889
982
  static IS_STRICT_THRESHOLD_BIT_FLAG = 4n;
890
983
  static IS_FIRST_TRANSFER_FROM_TAKER_BIT_FLAG = 5n;
891
984
  static USE_TRANSFER_FROM_AND_AQUA_PUSH_FLAG = 6n;
892
- 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) {
893
986
  this.exactIn = exactIn;
894
987
  this.shouldUnwrap = shouldUnwrap;
895
988
  this.preTransferInCallbackEnabled = preTransferInCallbackEnabled;
@@ -899,6 +992,7 @@ var TakerTraits = class TakerTraits {
899
992
  this.useTransferFromAndAquaPush = useTransferFromAndAquaPush;
900
993
  this.threshold = threshold;
901
994
  this.customReceiver = customReceiver;
995
+ this.deadline = deadline$1;
902
996
  this.preTransferInHookData = preTransferInHookData;
903
997
  this.postTransferInHookData = postTransferInHookData;
904
998
  this.preTransferOutHookData = preTransferOutHookData;
@@ -913,7 +1007,7 @@ var TakerTraits = class TakerTraits {
913
1007
  * Provides default values for unspecified fields.
914
1008
  */
915
1009
  static new(data = {}) {
916
- 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);
917
1011
  }
918
1012
  /**
919
1013
  * Creates a default TakerTraits instance with standard settings.
@@ -933,6 +1027,7 @@ var TakerTraits = class TakerTraits {
933
1027
  firstTransferFromTaker: false,
934
1028
  useTransferFromAndAquaPush: true,
935
1029
  threshold: 0n,
1030
+ deadline: 0n,
936
1031
  customReceiver: Address$1.ZERO_ADDRESS,
937
1032
  preTransferInHookData: HexString$1.EMPTY,
938
1033
  postTransferInHookData: HexString$1.EMPTY,
@@ -947,16 +1042,16 @@ var TakerTraits = class TakerTraits {
947
1042
  /**
948
1043
  * Decodes a packed TakerTraits from a hex string.
949
1044
  * The packed format consists of:
950
- * - 18 bytes: 9 uint16 offsets for data sections
1045
+ * - 20 bytes: 10 uint16 offsets for data sections
951
1046
  * - 2 bytes: uint16 flags
952
- * - Variable: data sections (threshold, to, hook data, callback data, etc.)
1047
+ * - Variable: data sections (threshold, to, deadline, hook data, callback data, etc.)
953
1048
  * - Variable: signature
954
1049
  */
955
1050
  static decode(packed) {
956
1051
  const iter = BytesIter.BigInt(packed.toString());
957
- const offsets = Array.from({ length: 9 }, () => Number(iter.nextUint16())).reverse();
1052
+ const offsets = Array.from({ length: 10 }, () => Number(iter.nextUint16())).reverse();
958
1053
  const flags = new BN(iter.nextUint16());
959
- const dataStr = trim0x(packed.toString()).slice(40);
1054
+ const dataStr = trim0x(packed.toString()).slice(44);
960
1055
  const sections = [];
961
1056
  offsets.forEach((offset, i) => {
962
1057
  const start = i === 0 ? 0 : offsets[i - 1];
@@ -964,7 +1059,7 @@ var TakerTraits = class TakerTraits {
964
1059
  });
965
1060
  const lastOffset = offsets[offsets.length - 1];
966
1061
  const signature = dataStr.length > lastOffset * 2 ? dataStr.slice(lastOffset * 2) : "";
967
- 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;
968
1063
  return TakerTraits.new({
969
1064
  exactIn: Boolean(flags.getBit(TakerTraits.IS_EXACT_IN_BIT_FLAG)),
970
1065
  shouldUnwrap: Boolean(flags.getBit(TakerTraits.SHOULD_UNWRAP_BIT_FLAG)),
@@ -975,6 +1070,7 @@ var TakerTraits = class TakerTraits {
975
1070
  useTransferFromAndAquaPush: Boolean(flags.getBit(TakerTraits.USE_TRANSFER_FROM_AND_AQUA_PUSH_FLAG)),
976
1071
  threshold: threshold ? BigInt(add0x(threshold)) : 0n,
977
1072
  customReceiver: to ? new Address$1(add0x(to)) : Address$1.ZERO_ADDRESS,
1073
+ deadline: deadline$1 ? BigInt(add0x(deadline$1)) : 0n,
978
1074
  preTransferInHookData: preTransferInHookData ? new HexString$1(add0x(preTransferInHookData)) : HexString$1.EMPTY,
979
1075
  postTransferInHookData: postTransferInHookData ? new HexString$1(add0x(postTransferInHookData)) : HexString$1.EMPTY,
980
1076
  preTransferOutHookData: preTransferOutHookData ? new HexString$1(add0x(preTransferOutHookData)) : HexString$1.EMPTY,
@@ -1003,6 +1099,7 @@ var TakerTraits = class TakerTraits {
1003
1099
  const dataFields = [
1004
1100
  this.threshold > 0n ? new HexString$1("0x" + this.threshold.toString(16).padStart(64, "0")) : HexString$1.EMPTY,
1005
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,
1006
1103
  this.preTransferInHookData,
1007
1104
  this.postTransferInHookData,
1008
1105
  this.preTransferOutHookData,
@@ -1272,7 +1369,7 @@ var JumpArgs = class JumpArgs {
1272
1369
  static CODER = new JumpArgsCoder();
1273
1370
  constructor(nextPC) {
1274
1371
  this.nextPC = nextPC;
1275
- assert$1(nextPC <= UINT_16_MAX$1 && nextPC >= 0n, `Invalid nextPC value: ${nextPC}. Must be between 0 and 65535`);
1372
+ assert(nextPC <= UINT_16_MAX$1 && nextPC >= 0n, `Invalid nextPC value: ${nextPC}. Must be between 0 and 65535`);
1276
1373
  }
1277
1374
  /**
1278
1375
  * Decodes hex data into JumpArgs instance
@@ -1417,7 +1514,7 @@ var OnlyTakerTokenBalanceGteArgs = class OnlyTakerTokenBalanceGteArgs {
1417
1514
  constructor(token, minAmount) {
1418
1515
  this.token = token;
1419
1516
  this.minAmount = minAmount;
1420
- assert$1(minAmount >= 0n, "minAmount must be non-negative");
1517
+ assert(minAmount >= 0n, "minAmount must be non-negative");
1421
1518
  }
1422
1519
  /**
1423
1520
  * Decodes hex data into OnlyTakerTokenBalanceGteArgs instance
@@ -1453,7 +1550,7 @@ var OnlyTakerTokenSupplyShareGteArgsCoder = class {
1453
1550
 
1454
1551
  //#endregion
1455
1552
  //#region src/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args.ts
1456
- const UINT_64_MAX$1 = 0xffffffffffffffffn;
1553
+ const UINT_64_MAX$2 = 0xffffffffffffffffn;
1457
1554
  /**
1458
1555
  * Arguments for checking if taker holds at least specified share of token's total supply
1459
1556
  * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L10
@@ -1463,7 +1560,7 @@ var OnlyTakerTokenSupplyShareGteArgs = class OnlyTakerTokenSupplyShareGteArgs {
1463
1560
  constructor(token, minShareE18) {
1464
1561
  this.token = token;
1465
1562
  this.minShareE18 = minShareE18;
1466
- assert$1(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`);
1467
1564
  }
1468
1565
  /**
1469
1566
  * Decodes hex data into OnlyTakerTokenSupplyShareGteArgs instance
@@ -1504,7 +1601,7 @@ var SaltArgs = class SaltArgs {
1504
1601
  static CODER = new SaltArgsCoder();
1505
1602
  constructor(salt$1) {
1506
1603
  this.salt = salt$1;
1507
- assert$1(salt$1 >= 0n && salt$1 <= UINT_64_MAX, `Invalid salt value: ${salt$1}. Must be a valid uint64`);
1604
+ assert(salt$1 >= 0n && salt$1 <= UINT_64_MAX, `Invalid salt value: ${salt$1}. Must be a valid uint64`);
1508
1605
  }
1509
1606
  /**
1510
1607
  * Decodes hex data into SaltArgs instance
@@ -1594,7 +1691,7 @@ var InvalidateBit1DArgs = class InvalidateBit1DArgs {
1594
1691
  static CODER = new InvalidateBit1DArgsCoder();
1595
1692
  constructor(bitIndex) {
1596
1693
  this.bitIndex = bitIndex;
1597
- assert$1(bitIndex >= 0n && bitIndex <= UINT_32_MAX, `Invalid bitIndex value: ${bitIndex}. Must be a valid uint32`);
1694
+ assert(bitIndex >= 0n && bitIndex <= UINT_32_MAX, `Invalid bitIndex value: ${bitIndex}. Must be a valid uint32`);
1598
1695
  }
1599
1696
  /**
1600
1697
  * Decodes hex data into InvalidateBit1DArgs instance
@@ -1732,100 +1829,71 @@ __export(xyc_swap_exports, {
1732
1829
  xycSwapXD: () => xycSwapXD
1733
1830
  });
1734
1831
 
1735
- //#endregion
1736
- //#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args-coder.ts
1737
- var ConcentrateGrowLiquidityXDArgsCoder = class {
1738
- encode(args) {
1739
- const builder = new BytesBuilder();
1740
- builder.addUint16(BigInt(args.tokenDeltas.length));
1741
- for (const { tokenHalf } of args.tokenDeltas) builder.addBytes(tokenHalf.toString());
1742
- for (const { delta } of args.tokenDeltas) builder.addUint256(delta);
1743
- return new HexString$1(builder.asHex());
1744
- }
1745
- decode(data) {
1746
- const iter = BytesIter.HexString(data.toString());
1747
- const tokenCount = Number(iter.nextUint16());
1748
- const tokenHalves = [];
1749
- for (let i = 0; i < tokenCount; i++) {
1750
- const bytes = iter.nextBytes(10);
1751
- tokenHalves.push(AddressHalf.fromHex(bytes));
1752
- }
1753
- const tokenDeltas = [];
1754
- for (let i = 0; i < tokenCount; i++) tokenDeltas.push({
1755
- tokenHalf: tokenHalves[i],
1756
- delta: BigInt(iter.nextUint256())
1757
- });
1758
- return new ConcentrateGrowLiquidityXDArgs(tokenDeltas);
1759
- }
1760
- };
1761
-
1762
- //#endregion
1763
- //#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args.ts
1764
- /**
1765
- * Arguments for concentrateGrowLiquidityXD instruction with multiple token deltas
1766
- * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L139
1767
- **/
1768
- var ConcentrateGrowLiquidityXDArgs = class ConcentrateGrowLiquidityXDArgs {
1769
- static CODER = new ConcentrateGrowLiquidityXDArgsCoder();
1770
- constructor(tokenDeltas) {
1771
- this.tokenDeltas = tokenDeltas;
1772
- tokenDeltas.forEach((td, index) => {
1773
- assert$1(td.delta >= 0n && td.delta <= UINT_256_MAX, `Invalid delta at index ${index}: ${td.delta}. Must be >= 0 and <= UINT_256_MAX`);
1774
- });
1775
- }
1776
- /**
1777
- * Decodes hex data into ConcentrateGrowLiquidityXDArgs instance
1778
- **/
1779
- static decode(data) {
1780
- return ConcentrateGrowLiquidityXDArgs.CODER.decode(data);
1781
- }
1782
- toJSON() {
1783
- return { tokenDeltas: this.tokenDeltas.map(({ tokenHalf, delta }) => ({
1784
- token: tokenHalf.toString(),
1785
- delta: delta.toString()
1786
- })) };
1787
- }
1788
- };
1789
-
1790
1832
  //#endregion
1791
1833
  //#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args-coder.ts
1792
1834
  var ConcentrateGrowLiquidity2DArgsCoder = class {
1793
1835
  encode(args) {
1794
1836
  const builder = new BytesBuilder();
1795
- builder.addUint256(args.deltaLt);
1796
- builder.addUint256(args.deltaGt);
1837
+ builder.addUint256(args.sqrtPriceMin);
1838
+ builder.addUint256(args.sqrtPriceMax);
1797
1839
  return new HexString$1(builder.asHex());
1798
1840
  }
1799
1841
  decode(data) {
1800
1842
  const iter = BytesIter.BigInt(data.toString());
1801
- const deltaLt = iter.nextUint256();
1802
- const deltaGt = iter.nextUint256();
1803
- return new ConcentrateGrowLiquidity2DArgs(deltaLt, deltaGt);
1843
+ const sqrtPriceMin = iter.nextUint256();
1844
+ const sqrtPriceMax = iter.nextUint256();
1845
+ return new ConcentrateGrowLiquidity2DArgs(sqrtPriceMin, sqrtPriceMax);
1804
1846
  }
1805
1847
  };
1806
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
+
1807
1864
  //#endregion
1808
1865
  //#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args.ts
1866
+ const ONE_E18 = 10n ** 18n;
1809
1867
  /**
1810
- * 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
1811
1871
  * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L172
1812
1872
  **/
1813
1873
  var ConcentrateGrowLiquidity2DArgs = class ConcentrateGrowLiquidity2DArgs {
1814
1874
  static CODER = new ConcentrateGrowLiquidity2DArgsCoder();
1815
- constructor(deltaLt, deltaGt) {
1816
- this.deltaLt = deltaLt;
1817
- this.deltaGt = deltaGt;
1818
- assert$1(deltaLt >= 0n && deltaLt <= UINT_256_MAX, `Invalid deltaLt: ${deltaLt}. Must be >= 0 and <= UINT_256_MAX`);
1819
- assert$1(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})`);
1820
1881
  }
1821
1882
  /**
1822
- * 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.
1823
1885
  **/
1824
- static fromTokenDeltas(tokenA, tokenB, deltaA, deltaB) {
1825
- const tokenABigInt = BigInt(tokenA.toString());
1826
- const tokenBBigInt = BigInt(tokenB.toString());
1827
- const [deltaLt, deltaGt] = tokenABigInt < tokenBBigInt ? [deltaA, deltaB] : [deltaB, deltaA];
1828
- 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);
1829
1897
  }
1830
1898
  /**
1831
1899
  * Decodes hex data into ConcentrateGrowLiquidity2DArgs instance
@@ -1835,8 +1903,8 @@ var ConcentrateGrowLiquidity2DArgs = class ConcentrateGrowLiquidity2DArgs {
1835
1903
  }
1836
1904
  toJSON() {
1837
1905
  return {
1838
- deltaLt: this.deltaLt.toString(),
1839
- deltaGt: this.deltaGt.toString()
1906
+ sqrtPriceMin: this.sqrtPriceMin.toString(),
1907
+ sqrtPriceMax: this.sqrtPriceMax.toString()
1840
1908
  };
1841
1909
  }
1842
1910
  };
@@ -1844,36 +1912,97 @@ var ConcentrateGrowLiquidity2DArgs = class ConcentrateGrowLiquidity2DArgs {
1844
1912
  //#endregion
1845
1913
  //#region src/swap-vm/instructions/concentrate/opcodes.ts
1846
1914
  /**
1847
- * Concentrates liquidity within price bounds for multiple tokens
1848
- * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L139
1849
- **/
1850
- const concentrateGrowLiquidityXD = new Opcode(Symbol("XYCConcentrate.concentrateGrowLiquidityXD"), ConcentrateGrowLiquidityXDArgs.CODER);
1851
- /**
1852
1915
  * Concentrates liquidity within price bounds for two tokens
1853
1916
  * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L172
1854
1917
  **/
1855
1918
  const concentrateGrowLiquidity2D = new Opcode(Symbol("XYCConcentrate.concentrateGrowLiquidity2D"), ConcentrateGrowLiquidity2DArgs.CODER);
1856
1919
 
1857
1920
  //#endregion
1858
- //#region src/swap-vm/instructions/concentrate/utils.ts
1859
- const TEN_POW_18 = 10n ** 18n;
1860
- function computeDeltas(balanceA, balanceB, price, priceMin, priceMax) {
1861
- const sqrtMin = sqrt(price * TEN_POW_18 / priceMin);
1862
- 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);
1863
1943
  return {
1864
- deltaA: price == priceMin ? 0n : balanceA * TEN_POW_18 / (sqrtMin - TEN_POW_18),
1865
- deltaB: price == priceMax ? 0n : balanceB * TEN_POW_18 / (sqrtMax - TEN_POW_18)
1944
+ targetL,
1945
+ actualLt,
1946
+ actualGt
1866
1947
  };
1867
1948
  }
1868
- function sqrt(value) {
1869
- if (value < 0n) throw "square root of negative numbers is not supported";
1870
- if (value < 2n) return value;
1871
- function newtonIteration(n, x0) {
1872
- const x1 = n / x0 + x0 >> 1n;
1873
- if (x0 === x1 || x0 === x1 - 1n) return x0;
1874
- return newtonIteration(n, x1);
1875
- }
1876
- 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;
1877
2006
  }
1878
2007
 
1879
2008
  //#endregion
@@ -1881,10 +2010,12 @@ function sqrt(value) {
1881
2010
  var concentrate_exports = {};
1882
2011
  __export(concentrate_exports, {
1883
2012
  ConcentrateGrowLiquidity2DArgs: () => ConcentrateGrowLiquidity2DArgs,
1884
- ConcentrateGrowLiquidityXDArgs: () => ConcentrateGrowLiquidityXDArgs,
1885
- computeDeltas: () => computeDeltas,
1886
- concentrateGrowLiquidity2D: () => concentrateGrowLiquidity2D,
1887
- concentrateGrowLiquidityXD: () => concentrateGrowLiquidityXD
2013
+ ONE_E18: () => ONE_E18,
2014
+ bigintSqrt: () => bigintSqrt,
2015
+ computeBalances: () => computeBalances,
2016
+ computeLiquidityAndPrice: () => computeLiquidityAndPrice,
2017
+ computeLiquidityFromAmounts: () => computeLiquidityFromAmounts,
2018
+ concentrateGrowLiquidity2D: () => concentrateGrowLiquidity2D
1888
2019
  });
1889
2020
 
1890
2021
  //#endregion
@@ -1912,7 +2043,7 @@ var DecayXDArgs = class DecayXDArgs {
1912
2043
  static CODER = new DecayXDArgsCoder();
1913
2044
  constructor(decayPeriod) {
1914
2045
  this.decayPeriod = decayPeriod;
1915
- assert$1(decayPeriod >= 0n && decayPeriod <= UINT_16_MAX, `Invalid decayPeriod value: ${decayPeriod}. Must be a valid uint16`);
2046
+ assert(decayPeriod >= 0n && decayPeriod <= UINT_16_MAX, `Invalid decayPeriod value: ${decayPeriod}. Must be a valid uint16`);
1916
2047
  }
1917
2048
  /**
1918
2049
  * Decodes hex data into DecayXDArgs instance
@@ -2035,8 +2166,8 @@ var MinRateArgs = class MinRateArgs {
2035
2166
  constructor(rateLt, rateGt) {
2036
2167
  this.rateLt = rateLt;
2037
2168
  this.rateGt = rateGt;
2038
- assert$1(rateLt >= 0n && rateLt <= UINT_64_MAX, `Invalid rateLt: ${rateLt}. Must be a valid uint64`);
2039
- assert$1(rateGt >= 0n && rateGt <= UINT_64_MAX, `Invalid rateGt: ${rateGt}. Must be a valid uint64`);
2169
+ assert(rateLt >= 0n && rateLt <= UINT_64_MAX, `Invalid rateLt: ${rateLt}. Must be a valid uint64`);
2170
+ assert(rateGt >= 0n && rateGt <= UINT_64_MAX, `Invalid rateGt: ${rateGt}. Must be a valid uint64`);
2040
2171
  }
2041
2172
  static fromTokens(tokenA, tokenB, rateA, rateB) {
2042
2173
  if (BigInt(tokenA.toString()) < BigInt(tokenB.toString())) return new MinRateArgs(rateA, rateB);
@@ -2085,14 +2216,14 @@ var DutchAuctionArgsCoder = class {
2085
2216
  const builder = new BytesBuilder();
2086
2217
  builder.addUint40(args.startTime);
2087
2218
  builder.addUint16(args.duration);
2088
- builder.addUint32(args.decayFactor);
2219
+ builder.addUint64(args.decayFactor);
2089
2220
  return new HexString$1(add0x(builder.asHex()));
2090
2221
  }
2091
2222
  decode(data) {
2092
2223
  const iter = BytesIter.BigInt(data.toString());
2093
2224
  const startTime = iter.nextUint40();
2094
2225
  const duration = iter.nextUint16();
2095
- const decayFactor = iter.nextUint32();
2226
+ const decayFactor = iter.nextUint64();
2096
2227
  return new DutchAuctionArgs(startTime, duration, decayFactor);
2097
2228
  }
2098
2229
  };
@@ -2110,7 +2241,6 @@ var DutchAuctionArgsCoder = class {
2110
2241
  * - Only works for 1=>0 swaps (token1 to token0)
2111
2242
  *
2112
2243
  * The decay factor determines the price reduction rate:
2113
- * - 1.0e18 = no decay (constant price)
2114
2244
  * - 0.999e18 = 0.1% decay per second
2115
2245
  * - 0.99e18 = 1% decay per second
2116
2246
  * - 0.9e18 = 10% decay per second
@@ -2129,16 +2259,16 @@ var DutchAuctionArgs = class DutchAuctionArgs {
2129
2259
  /**
2130
2260
  * startTime - auction start time (uint40)
2131
2261
  * duration - auction duration in seconds (uint16)
2132
- * decayFactor - price decay per second, 1e18 = no decay (uint32)
2262
+ * decayFactor - price decay per second, 1e18 = no decay (uint64)
2133
2263
  **/
2134
2264
  constructor(startTime, duration, decayFactor) {
2135
2265
  this.startTime = startTime;
2136
2266
  this.duration = duration;
2137
2267
  this.decayFactor = decayFactor;
2138
- assert$1(startTime >= 0n && startTime <= UINT_40_MAX, `Invalid startTime: ${startTime}. Must be a valid uint40`);
2139
- assert$1(duration >= 0n && duration <= UINT_16_MAX, `Invalid duration: ${duration}. Must be a valid uint16`);
2140
- assert$1(decayFactor >= 0n && decayFactor <= UINT_32_MAX, `Invalid decayFactor: ${decayFactor}. Must be a valid uint32`);
2141
- assert$1(decayFactor < 1e18, `Decay factor should be less than 1e18: ${decayFactor}`);
2268
+ assert(startTime >= 0n && startTime <= UINT_40_MAX, `Invalid startTime: ${startTime}. Must be a valid uint40`);
2269
+ assert(duration >= 0n && duration <= UINT_16_MAX, `Invalid duration: ${duration}. Must be a valid uint16`);
2270
+ assert(decayFactor >= 0n && decayFactor <= UINT_64_MAX$1, `Invalid decayFactor: ${decayFactor}. Must be a valid uint64`);
2271
+ assert(decayFactor < 1e18, `Decay factor should be less than 1e18: ${decayFactor}`);
2142
2272
  }
2143
2273
  /**
2144
2274
  * Decodes hex data into DutchAuctionArgs instance
@@ -2177,99 +2307,6 @@ __export(dutch_auction_exports, {
2177
2307
  dutchAuctionBalanceOut1D: () => dutchAuctionBalanceOut1D
2178
2308
  });
2179
2309
 
2180
- //#endregion
2181
- //#region src/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args-coder.ts
2182
- var OraclePriceAdjusterArgsCoder = class {
2183
- encode(args) {
2184
- const builder = new BytesBuilder();
2185
- builder.addUint64(args.maxPriceDecay);
2186
- builder.addUint16(args.maxStaleness);
2187
- builder.addUint8(args.oracleDecimals);
2188
- builder.addAddress(args.oracleAddress.toString());
2189
- return new HexString$1(builder.asHex());
2190
- }
2191
- decode(data) {
2192
- const iter = BytesIter.HexString(data.toString());
2193
- const maxPriceDecay = iter.nextUint64();
2194
- const maxStaleness = iter.nextUint16();
2195
- const oracleDecimals = iter.nextUint8();
2196
- const oracleAddress = new Address$1(iter.nextAddress());
2197
- return new OraclePriceAdjusterArgs(BigInt(maxPriceDecay), BigInt(maxStaleness), BigInt(oracleDecimals), oracleAddress);
2198
- }
2199
- };
2200
-
2201
- //#endregion
2202
- //#region src/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args.ts
2203
- /**
2204
- * @notice Oracle Price Adjuster instruction for dynamic price adjustment based on Chainlink price feeds
2205
- * @dev Adjusts swap prices to match Chainlink oracle prices within safe bounds:
2206
- * - Works only for 1=>0 swaps (token1 to token0), compatible with LimitSwap and other swap instructions
2207
- * - Fetches current market price from a Chainlink oracle (AggregatorV3Interface)
2208
- * - Adjusts the swap price towards the oracle price within maxPriceDecay limits
2209
- * - Ensures the adjustment is always favorable for the taker
2210
- * - Handles different decimal places from Chainlink oracles (e.g., 8 decimals for USD prices)
2211
- *
2212
- * This creates adaptive orders that automatically track market prices while maintaining
2213
- * safety bounds to prevent excessive slippage or manipulation.
2214
- *
2215
- * Example usage:
2216
- * 1. LimitSwap sets base price: 1 ETH for 3000 USDC
2217
- * 2. OraclePriceAdjuster with Chainlink ETH/USD oracle: 1 ETH = 3100 USD, maxPriceDecay=0.95e18 (5% max)
2218
- * 3. exactIn: Taker gets more ETH (up to 5% improvement)
2219
- * 4. exactOut: Taker pays less USDC (up to 5% discount)
2220
- *
2221
- * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/OraclePriceAdjuster.sol#L84
2222
- */
2223
- var OraclePriceAdjusterArgs = class OraclePriceAdjusterArgs {
2224
- static CODER = new OraclePriceAdjusterArgsCoder();
2225
- /**
2226
- * maxPriceDecay - maximum price decay coefficient (uint64)
2227
- * maxStaleness - maximum allowed oracle data staleness in seconds (uint16
2228
- * oracleDecimals - decimals used by the oracle (uint8)
2229
- * oracleAddress - address of the Chainlink price oracle contract
2230
- **/
2231
- constructor(maxPriceDecay, maxStaleness, oracleDecimals, oracleAddress) {
2232
- this.maxPriceDecay = maxPriceDecay;
2233
- this.maxStaleness = maxStaleness;
2234
- this.oracleDecimals = oracleDecimals;
2235
- this.oracleAddress = oracleAddress;
2236
- assert$1(maxPriceDecay >= 0n && maxPriceDecay <= UINT_64_MAX, `Invalid maxPriceDecay: ${maxPriceDecay}. Must be a valid uint64`);
2237
- assert$1(maxPriceDecay < 1e18, `Max price decay should be less than 1e18: ${maxPriceDecay}`);
2238
- assert$1(maxStaleness >= 0n && maxStaleness <= UINT_16_MAX, `Invalid maxStaleness: ${maxStaleness}. Must be a valid uint16`);
2239
- assert$1(oracleDecimals >= 0n && oracleDecimals <= UINT_8_MAX, `Invalid oracleDecimals: ${oracleDecimals}. Must be a valid uint8`);
2240
- }
2241
- /**
2242
- * Decodes hex data into OraclePriceAdjusterArgs instance
2243
- **/
2244
- static decode(data) {
2245
- return OraclePriceAdjusterArgs.CODER.decode(data);
2246
- }
2247
- toJSON() {
2248
- return {
2249
- maxPriceDecay: this.maxPriceDecay.toString(),
2250
- maxStaleness: this.maxStaleness.toString(),
2251
- oracleDecimals: this.oracleDecimals.toString(),
2252
- oracleAddress: this.oracleAddress.toString()
2253
- };
2254
- }
2255
- };
2256
-
2257
- //#endregion
2258
- //#region src/swap-vm/instructions/oracle-price-adjuster/opcodes.ts
2259
- /**
2260
- * Adjusts swap prices based on Chainlink oracle feeds
2261
- * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/OraclePriceAdjuster.sol#L84
2262
- **/
2263
- const oraclePriceAdjuster1D = new Opcode(Symbol("OraclePriceAdjuster.oraclePriceAdjuster1D"), OraclePriceAdjusterArgs.CODER);
2264
-
2265
- //#endregion
2266
- //#region src/swap-vm/instructions/oracle-price-adjuster/index.ts
2267
- var oracle_price_adjuster_exports = {};
2268
- __export(oracle_price_adjuster_exports, {
2269
- OraclePriceAdjusterArgs: () => OraclePriceAdjusterArgs,
2270
- oraclePriceAdjuster1D: () => oraclePriceAdjuster1D
2271
- });
2272
-
2273
2310
  //#endregion
2274
2311
  //#region src/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args-coder.ts
2275
2312
  var BaseFeeAdjusterArgsCoder = class {
@@ -2325,10 +2362,10 @@ var BaseFeeAdjusterArgs = class BaseFeeAdjusterArgs {
2325
2362
  this.ethToToken1Price = ethToToken1Price;
2326
2363
  this.gasAmount = gasAmount;
2327
2364
  this.maxPriceDecay = maxPriceDecay;
2328
- assert$1(baseGasPrice >= 0n && baseGasPrice <= UINT_64_MAX, `Invalid baseGasPrice: ${baseGasPrice}. Must be a valid uint64`);
2329
- assert$1(ethToToken1Price >= 0n && ethToToken1Price <= UINT_96_MAX, `Invalid ethToToken1Price: ${ethToToken1Price}. Must be a valid uint96`);
2330
- assert$1(gasAmount >= 0n && gasAmount <= UINT_24_MAX, `Invalid gasAmount: ${gasAmount}. Must be a valid uint24`);
2331
- assert$1(maxPriceDecay >= 0n && maxPriceDecay <= UINT_64_MAX, `Invalid maxPriceDecay: ${maxPriceDecay}. Must be a valid uint64`);
2365
+ assert(baseGasPrice >= 0n && baseGasPrice <= UINT_64_MAX, `Invalid baseGasPrice: ${baseGasPrice}. Must be a valid uint64`);
2366
+ assert(ethToToken1Price >= 0n && ethToToken1Price <= UINT_96_MAX, `Invalid ethToToken1Price: ${ethToToken1Price}. Must be a valid uint96`);
2367
+ assert(gasAmount >= 0n && gasAmount <= UINT_24_MAX, `Invalid gasAmount: ${gasAmount}. Must be a valid uint24`);
2368
+ assert(maxPriceDecay >= 0n && maxPriceDecay <= UINT_64_MAX, `Invalid maxPriceDecay: ${maxPriceDecay}. Must be a valid uint64`);
2332
2369
  }
2333
2370
  /**
2334
2371
  * Decodes hex data into BaseFeeAdjusterArgs instance
@@ -2452,12 +2489,12 @@ var TWAPSwapArgs = class TWAPSwapArgs {
2452
2489
  this.duration = duration;
2453
2490
  this.priceBumpAfterIlliquidity = priceBumpAfterIlliquidity;
2454
2491
  this.minTradeAmountOut = minTradeAmountOut;
2455
- assert$1(balanceIn >= 0n && balanceIn <= UINT_256_MAX, `Invalid balanceIn: ${balanceIn}. Must be >= 0 and <= UINT_256_MAX`);
2456
- assert$1(balanceOut >= 0n && balanceOut <= UINT_256_MAX, `Invalid balanceOut: ${balanceOut}. Must be >= 0 and <= UINT_256_MAX`);
2457
- assert$1(startTime >= 0n && startTime <= UINT_256_MAX, `Invalid startTime: ${startTime}. Must be >= 0 and <= UINT_256_MAX`);
2458
- assert$1(duration >= 0n && duration <= UINT_256_MAX, `Invalid duration: ${duration}. Must be >= 0 and <= UINT_256_MAX`);
2459
- assert$1(priceBumpAfterIlliquidity >= 0n && priceBumpAfterIlliquidity <= UINT_256_MAX, `Invalid priceBumpAfterIlliquidity: ${priceBumpAfterIlliquidity}. Must be >= 0 and <= UINT_256_MAX`);
2460
- assert$1(minTradeAmountOut >= 0n && minTradeAmountOut <= UINT_256_MAX, `Invalid minTradeAmountOut: ${minTradeAmountOut}. Must be >= 0 and <= UINT_256_MAX`);
2492
+ assert(balanceIn >= 0n && balanceIn <= UINT_256_MAX, `Invalid balanceIn: ${balanceIn}. Must be >= 0 and <= UINT_256_MAX`);
2493
+ assert(balanceOut >= 0n && balanceOut <= UINT_256_MAX, `Invalid balanceOut: ${balanceOut}. Must be >= 0 and <= UINT_256_MAX`);
2494
+ assert(startTime >= 0n && startTime <= UINT_256_MAX, `Invalid startTime: ${startTime}. Must be >= 0 and <= UINT_256_MAX`);
2495
+ assert(duration >= 0n && duration <= UINT_256_MAX, `Invalid duration: ${duration}. Must be >= 0 and <= UINT_256_MAX`);
2496
+ assert(priceBumpAfterIlliquidity >= 0n && priceBumpAfterIlliquidity <= UINT_256_MAX, `Invalid priceBumpAfterIlliquidity: ${priceBumpAfterIlliquidity}. Must be >= 0 and <= UINT_256_MAX`);
2497
+ assert(minTradeAmountOut >= 0n && minTradeAmountOut <= UINT_256_MAX, `Invalid minTradeAmountOut: ${minTradeAmountOut}. Must be >= 0 and <= UINT_256_MAX`);
2461
2498
  }
2462
2499
  /**
2463
2500
  * Decodes hex data into TWAPSwapArgs instance
@@ -2494,7 +2531,7 @@ __export(twap_swap_exports, {
2494
2531
  });
2495
2532
 
2496
2533
  //#endregion
2497
- //#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
2498
2535
  var FlatFeeArgsCoder = class {
2499
2536
  encode(args) {
2500
2537
  const builder = new BytesBuilder();
@@ -2509,18 +2546,18 @@ var FlatFeeArgsCoder = class {
2509
2546
  };
2510
2547
 
2511
2548
  //#endregion
2512
- //#region src/swap-vm/instructions/fee/flat-fee-args.ts
2549
+ //#region src/swap-vm/instructions/fee/flat-fee/flat-fee-args.ts
2513
2550
  const FEE_100_PERCENT$1 = 1e9;
2514
2551
  /**
2515
- * Arguments for flat fee instructions (flatFeeXD, flatFeeAmountInXD, flatFeeAmountOutXD, progressiveFeeXD)
2552
+ * Arguments for flat fee instructions (flatFeeAmountInXD)
2516
2553
  * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L66
2517
2554
  **/
2518
2555
  var FlatFeeArgs = class FlatFeeArgs {
2519
2556
  static CODER = new FlatFeeArgsCoder();
2520
2557
  constructor(fee) {
2521
2558
  this.fee = fee;
2522
- assert$1(fee >= 0n && fee <= UINT_32_MAX, `Invalid fee: ${fee}. Must be a valid uint32`);
2523
- assert$1(fee <= BigInt(FEE_100_PERCENT$1), `Fee out of range: ${fee}. Must be <= ${FEE_100_PERCENT$1}`);
2559
+ assert(fee >= 0n && fee <= UINT_32_MAX, `Invalid fee: ${fee}. Must be a valid uint32`);
2560
+ assert(fee <= BigInt(FEE_100_PERCENT$1), `Fee out of range: ${fee}. Must be <= ${FEE_100_PERCENT$1}`);
2524
2561
  }
2525
2562
  /**
2526
2563
  * Decodes hex data into FlatFeeArgs instance
@@ -2551,7 +2588,7 @@ var FlatFeeArgs = class FlatFeeArgs {
2551
2588
  };
2552
2589
 
2553
2590
  //#endregion
2554
- //#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
2555
2592
  var ProtocolFeeArgsCoder = class {
2556
2593
  encode(args) {
2557
2594
  const builder = new BytesBuilder();
@@ -2568,11 +2605,11 @@ var ProtocolFeeArgsCoder = class {
2568
2605
  };
2569
2606
 
2570
2607
  //#endregion
2571
- //#region src/swap-vm/instructions/fee/protocol-fee-args.ts
2608
+ //#region src/swap-vm/instructions/fee/protocol-fee/protocol-fee-args.ts
2572
2609
  const FEE_100_PERCENT = 1e9;
2573
2610
  /**
2574
- * Arguments for protocol fee instructions (protocolFeeAmountOutXD, aquaProtocolFeeAmountOutXD)
2575
- * @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
2576
2613
  **/
2577
2614
  var ProtocolFeeArgs = class ProtocolFeeArgs {
2578
2615
  static CODER = new ProtocolFeeArgsCoder();
@@ -2583,8 +2620,8 @@ var ProtocolFeeArgs = class ProtocolFeeArgs {
2583
2620
  constructor(fee, to) {
2584
2621
  this.fee = fee;
2585
2622
  this.to = to;
2586
- assert$1(fee >= 0n && fee <= UINT_32_MAX, `Invalid fee: ${fee}. Must be a valid uint32`);
2587
- assert$1(fee <= BigInt(FEE_100_PERCENT), `Fee out of range: ${fee}. Must be <= ${FEE_100_PERCENT}`);
2623
+ assert(fee >= 0n && fee <= UINT_32_MAX, `Invalid fee: ${fee}. Must be a valid uint32`);
2624
+ assert(fee <= BigInt(FEE_100_PERCENT), `Fee out of range: ${fee}. Must be <= ${FEE_100_PERCENT}`);
2588
2625
  }
2589
2626
  /**
2590
2627
  * Decodes hex data into ProtocolFeeArgs instance
@@ -2619,50 +2656,110 @@ var ProtocolFeeArgs = class ProtocolFeeArgs {
2619
2656
  }
2620
2657
  };
2621
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
+
2622
2694
  //#endregion
2623
2695
  //#region src/swap-vm/instructions/fee/opcodes.ts
2624
2696
  /**
2625
2697
  * Applies fee to amountIn
2626
- * @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
2627
2699
  **/
2628
2700
  const flatFeeAmountInXD = new Opcode(Symbol("Fee.flatFeeAmountInXD"), FlatFeeArgs.CODER);
2629
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
+ /**
2630
2722
  * Applies fee to amountOut
2631
- * @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
2632
2724
  **/
2633
- const flatFeeAmountOutXD = new Opcode(Symbol("Fee.flatFeeAmountOutXD"), FlatFeeArgs.CODER);
2725
+ const flatFeeAmountOutXD = new Opcode(Symbol("FeeExperimental.flatFeeAmountOutXD"), FlatFeeArgs.CODER);
2634
2726
  /**
2635
2727
  * Applies progressive fee to amountIn
2636
- * @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
2637
2729
  **/
2638
- const progressiveFeeInXD = new Opcode(Symbol("Fee.progressiveFeeInXD"), FlatFeeArgs.CODER);
2730
+ const progressiveFeeInXD = new Opcode(Symbol("FeeExperimental.progressiveFeeInXD"), FlatFeeArgs.CODER);
2639
2731
  /**
2640
2732
  * Applies progressive fee to amountOut
2641
- * @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
2642
2734
  **/
2643
- const progressiveFeeOutXD = new Opcode(Symbol("Fee.progressiveFeeOutXD"), FlatFeeArgs.CODER);
2735
+ const progressiveFeeOutXD = new Opcode(Symbol("FeeExperimental.progressiveFeeOutXD"), FlatFeeArgs.CODER);
2644
2736
  /**
2645
- * Applies protocol fee to amountOut with direct transfer
2646
- * @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
2647
2739
  **/
2648
- const protocolFeeAmountOutXD = new Opcode(Symbol("Fee.protocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
2740
+ const protocolFeeAmountOutXD = new Opcode(Symbol("FeeExperimental.protocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
2649
2741
  /**
2650
- * Applies protocol fee to amountOut through Aqua protocol
2651
- * @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
2652
2744
  **/
2653
- const aquaProtocolFeeAmountOutXD = new Opcode(Symbol("Fee.aquaProtocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
2745
+ const aquaProtocolFeeAmountOutXD = new Opcode(Symbol("FeeExperimental.aquaProtocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
2654
2746
 
2655
2747
  //#endregion
2656
2748
  //#region src/swap-vm/instructions/fee/index.ts
2657
2749
  var fee_exports = {};
2658
2750
  __export(fee_exports, {
2751
+ DynamicProtocolFeeArgs: () => DynamicProtocolFeeArgs,
2659
2752
  FlatFeeArgs: () => FlatFeeArgs,
2660
2753
  ProtocolFeeArgs: () => ProtocolFeeArgs,
2754
+ aquaDynamicProtocolFeeAmountInXD: () => aquaDynamicProtocolFeeAmountInXD,
2755
+ aquaProtocolFeeAmountInXD: () => aquaProtocolFeeAmountInXD,
2661
2756
  aquaProtocolFeeAmountOutXD: () => aquaProtocolFeeAmountOutXD,
2757
+ dynamicProtocolFeeAmountInXD: () => dynamicProtocolFeeAmountInXD,
2662
2758
  flatFeeAmountInXD: () => flatFeeAmountInXD,
2663
2759
  flatFeeAmountOutXD: () => flatFeeAmountOutXD,
2664
2760
  progressiveFeeInXD: () => progressiveFeeInXD,
2665
2761
  progressiveFeeOutXD: () => progressiveFeeOutXD,
2762
+ protocolFeeAmountInXD: () => protocolFeeAmountInXD,
2666
2763
  protocolFeeAmountOutXD: () => protocolFeeAmountOutXD
2667
2764
  });
2668
2765
 
@@ -2730,82 +2827,194 @@ __export(extruction_exports, {
2730
2827
  });
2731
2828
 
2732
2829
  //#endregion
2733
- //#region src/swap-vm/instructions/stable-swap/stable-swap-2d-args-coder.ts
2734
- var StableSwap2DArgsCoder = class {
2830
+ //#region src/swap-vm/instructions/pegged-swap/pegged-swap-args-coder.ts
2831
+ var PeggedSwapArgsCoder = class {
2735
2832
  encode(args) {
2736
2833
  const builder = new BytesBuilder();
2737
- builder.addUint32(args.fee);
2738
- builder.addUint32(args.A);
2834
+ builder.addUint256(args.x0);
2835
+ builder.addUint256(args.y0);
2836
+ builder.addUint256(args.linearWidth);
2739
2837
  builder.addUint256(args.rateLt);
2740
2838
  builder.addUint256(args.rateGt);
2741
- return new HexString$1(add0x(builder.asHex()));
2839
+ return new HexString$1(builder.asHex());
2742
2840
  }
2743
2841
  decode(data) {
2744
2842
  const iter = BytesIter.BigInt(data.toString());
2745
- const fee = iter.nextUint32();
2746
- const A = iter.nextUint32();
2747
- const rateLt = iter.nextUint256();
2748
- const rateGt = iter.nextUint256();
2749
- 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);
2750
2849
  }
2751
2850
  };
2752
2851
 
2753
2852
  //#endregion
2754
- //#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
2755
2862
  /**
2756
- * 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
2757
2866
  **/
2758
- var StableSwap2DArgs = class StableSwap2DArgs {
2759
- static CODER = new StableSwap2DArgsCoder();
2760
- /**
2761
- * fee - swap fee in 1e10 (uint32)
2762
- * A - amplification coefficient (uint32)
2763
- * rateLt - rate for token with lower address (uint256)
2764
- * rateGt - rate for token with higher address (uint256)
2765
- **/
2766
- constructor(fee, A, rateLt, rateGt) {
2767
- this.fee = fee;
2768
- 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;
2769
2882
  this.rateLt = rateLt;
2770
2883
  this.rateGt = rateGt;
2771
- assert$1(fee >= 0n && fee <= UINT_32_MAX, `Invalid fee: ${fee}`);
2772
- assert$1(A >= 0n && A <= UINT_32_MAX, `Invalid A: ${A}`);
2773
- assert$1(rateLt > 0n && rateLt <= UINT_256_MAX, `Invalid rateLt: ${rateLt}. Must be positive and <= UINT_256_MAX`);
2774
- assert$1(rateGt > 0n && rateGt <= UINT_256_MAX, `Invalid rateGt: ${rateGt}. Must be positive and <= UINT_256_MAX`);
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}`);
2888
+ assert(rateLt > 0n && rateLt <= UINT_256_MAX, `Invalid rateLt: ${rateLt}. Must be positive and <= UINT_256_MAX`);
2889
+ assert(rateGt > 0n && rateGt <= UINT_256_MAX, `Invalid rateGt: ${rateGt}. Must be positive and <= UINT_256_MAX`);
2890
+ }
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);
2896
+ }
2897
+ static decode(data) {
2898
+ return PeggedSwapArgs.CODER.decode(data);
2899
+ }
2900
+ toJSON() {
2901
+ return {
2902
+ x0: this.x0.toString(),
2903
+ y0: this.y0.toString(),
2904
+ linearWidth: this.linearWidth.toString(),
2905
+ rateLt: this.rateLt.toString(),
2906
+ rateGt: this.rateGt.toString()
2907
+ };
2908
+ }
2909
+ };
2910
+
2911
+ //#endregion
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());
2775
2937
  }
2776
- static fromTokens(fee, a, tokenA, tokenB, rateA, rateB) {
2777
- if (BigInt(tokenA.toString()) < BigInt(tokenB.toString())) return new StableSwap2DArgs(fee, a, rateA, rateB);
2778
- return new StableSwap2DArgs(fee, a, rateB, rateA);
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`);
2779
2987
  }
2780
2988
  /**
2781
- * Decodes hex data into StableSwap2DArgs instance
2989
+ * Decodes hex data into OraclePriceAdjusterArgs instance
2782
2990
  **/
2783
2991
  static decode(data) {
2784
- return StableSwap2DArgs.CODER.decode(data);
2992
+ return OraclePriceAdjusterArgs.CODER.decode(data);
2785
2993
  }
2786
2994
  toJSON() {
2787
2995
  return {
2788
- fee: this.fee.toString(),
2789
- A: this.A.toString(),
2790
- rateLt: this.rateLt.toString(),
2791
- rateGt: this.rateGt.toString()
2996
+ maxPriceDecay: this.maxPriceDecay.toString(),
2997
+ maxStaleness: this.maxStaleness.toString(),
2998
+ oracleDecimals: this.oracleDecimals.toString(),
2999
+ oracleAddress: this.oracleAddress.toString()
2792
3000
  };
2793
3001
  }
2794
3002
  };
2795
3003
 
2796
3004
  //#endregion
2797
- //#region src/swap-vm/instructions/stable-swap/opcodes.ts
3005
+ //#region src/swap-vm/instructions/oracle-price-adjuster/opcodes.ts
2798
3006
  /**
2799
- * 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
2800
3009
  **/
2801
- const stableSwap2D = new Opcode(Symbol("StableSwap.stableSwap2D"), StableSwap2DArgs.CODER);
3010
+ const oraclePriceAdjuster1D = new Opcode(Symbol("OraclePriceAdjuster.oraclePriceAdjuster1D"), OraclePriceAdjusterArgs.CODER);
2802
3011
 
2803
3012
  //#endregion
2804
- //#region src/swap-vm/instructions/stable-swap/index.ts
2805
- var stable_swap_exports = {};
2806
- __export(stable_swap_exports, {
2807
- StableSwap2DArgs: () => StableSwap2DArgs,
2808
- 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
2809
3018
  });
2810
3019
 
2811
3020
  //#endregion
@@ -2827,7 +3036,8 @@ __export(instructions_exports, {
2827
3036
  limitSwap: () => limit_swap_exports,
2828
3037
  minRate: () => min_rate_exports,
2829
3038
  oraclePriceAdjuster: () => oracle_price_adjuster_exports,
2830
- stableSwap: () => stable_swap_exports,
3039
+ peggedSwap: () => pegged_swap_exports,
3040
+ stableSwap: () => pegged_swap_exports,
2831
3041
  twapSwap: () => twap_swap_exports,
2832
3042
  xycSwap: () => xyc_swap_exports
2833
3043
  });
@@ -2859,7 +3069,6 @@ const _allInstructions = [
2859
3069
  invalidateTokenIn1D,
2860
3070
  invalidateTokenOut1D,
2861
3071
  xycSwapXD,
2862
- concentrateGrowLiquidityXD,
2863
3072
  concentrateGrowLiquidity2D,
2864
3073
  decayXD,
2865
3074
  limitSwap1D,
@@ -2868,7 +3077,6 @@ const _allInstructions = [
2868
3077
  adjustMinRate1D,
2869
3078
  dutchAuctionBalanceIn1D,
2870
3079
  dutchAuctionBalanceOut1D,
2871
- oraclePriceAdjuster1D,
2872
3080
  baseFeeAdjuster1D,
2873
3081
  twap,
2874
3082
  extruction,
@@ -2878,7 +3086,12 @@ const _allInstructions = [
2878
3086
  progressiveFeeInXD,
2879
3087
  progressiveFeeOutXD,
2880
3088
  protocolFeeAmountOutXD,
2881
- aquaProtocolFeeAmountOutXD
3089
+ aquaProtocolFeeAmountOutXD,
3090
+ peggedSwapGrowPriceRange2D,
3091
+ protocolFeeAmountInXD,
3092
+ aquaProtocolFeeAmountInXD,
3093
+ dynamicProtocolFeeAmountInXD,
3094
+ aquaDynamicProtocolFeeAmountInXD
2882
3095
  ];
2883
3096
  /**
2884
3097
  * Aqua opcodes array - matching AquaSwapVM contract (29 opcodes)
@@ -2903,16 +3116,21 @@ const aquaInstructions = [
2903
3116
  onlyTakerTokenBalanceGte,
2904
3117
  onlyTakerTokenSupplyShareGte,
2905
3118
  xycSwapXD,
2906
- concentrateGrowLiquidityXD,
2907
3119
  concentrateGrowLiquidity2D,
2908
3120
  decayXD,
2909
3121
  salt,
2910
3122
  flatFeeAmountInXD,
2911
- flatFeeAmountOutXD,
2912
- progressiveFeeInXD,
2913
- progressiveFeeOutXD,
2914
- protocolFeeAmountOutXD,
2915
- 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
2916
3134
  ];
2917
3135
 
2918
3136
  //#endregion
@@ -3214,17 +3432,17 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
3214
3432
  return this;
3215
3433
  }
3216
3434
  /**
3217
- * Concentrates liquidity within price bounds for multiple tokens
3435
+ * Concentrates liquidity within price bounds for two tokens
3218
3436
  **/
3219
- concentrateGrowLiquidityXD(data) {
3220
- super.add(concentrateGrowLiquidityXD.createIx(new ConcentrateGrowLiquidityXDArgs(data.tokenDeltas)));
3437
+ concentrateGrowLiquidity2D(data) {
3438
+ super.add(concentrateGrowLiquidity2D.createIx(new ConcentrateGrowLiquidity2DArgs(data.sqrtPriceMin, data.sqrtPriceMax)));
3221
3439
  return this;
3222
3440
  }
3223
3441
  /**
3224
- * Concentrates liquidity within price bounds for two tokens
3442
+ * Square-root linear swap curve for pegged assets
3225
3443
  **/
3226
- concentrateGrowLiquidity2D(data) {
3227
- 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)));
3228
3446
  return this;
3229
3447
  }
3230
3448
  /**
@@ -3277,13 +3495,6 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
3277
3495
  return this;
3278
3496
  }
3279
3497
  /**
3280
- * Adjusts swap prices based on Chainlink oracle feeds
3281
- **/
3282
- oraclePriceAdjuster1D(data) {
3283
- super.add(oraclePriceAdjuster1D.createIx(new OraclePriceAdjusterArgs(data.maxPriceDecay, data.maxStaleness, data.oracleDecimals, data.oracleAddress)));
3284
- return this;
3285
- }
3286
- /**
3287
3498
  * Adjusts swap prices based on network gas costs
3288
3499
  **/
3289
3500
  baseFeeAdjuster1D(data) {
@@ -3333,6 +3544,13 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
3333
3544
  return this;
3334
3545
  }
3335
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
+ /**
3336
3554
  * Applies protocol fee to amountOut with direct transfer
3337
3555
  **/
3338
3556
  protocolFeeAmountOutXD(data) {
@@ -3340,6 +3558,13 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
3340
3558
  return this;
3341
3559
  }
3342
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
+ /**
3343
3568
  * Applies protocol fee to amountOut through Aqua protocol
3344
3569
  **/
3345
3570
  aquaProtocolFeeAmountOutXD(data) {
@@ -3347,6 +3572,20 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
3347
3572
  return this;
3348
3573
  }
3349
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
+ /**
3350
3589
  * DEBUG: Prints current swap registers (amounts and tokens)
3351
3590
  * WARNING: Requires withDebug() to be called first, otherwise will throw an error
3352
3591
  */
@@ -3482,17 +3721,17 @@ var AquaProgramBuilder = class AquaProgramBuilder extends ProgramBuilder {
3482
3721
  return this;
3483
3722
  }
3484
3723
  /**
3485
- * Concentrates liquidity within price bounds for multiple tokens
3724
+ * Concentrates liquidity within price bounds for two tokens
3486
3725
  **/
3487
- concentrateGrowLiquidityXD(data) {
3488
- super.add(concentrateGrowLiquidityXD.createIx(new ConcentrateGrowLiquidityXDArgs(data.tokenDeltas)));
3726
+ concentrateGrowLiquidity2D(data) {
3727
+ super.add(concentrateGrowLiquidity2D.createIx(new ConcentrateGrowLiquidity2DArgs(data.sqrtPriceMin, data.sqrtPriceMax)));
3489
3728
  return this;
3490
3729
  }
3491
3730
  /**
3492
- * Concentrates liquidity within price bounds for two tokens
3731
+ * Square-root linear swap curve for pegged assets
3493
3732
  **/
3494
- concentrateGrowLiquidity2D(data) {
3495
- 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)));
3496
3735
  return this;
3497
3736
  }
3498
3737
  /**
@@ -3510,38 +3749,31 @@ var AquaProgramBuilder = class AquaProgramBuilder extends ProgramBuilder {
3510
3749
  return this;
3511
3750
  }
3512
3751
  /**
3513
- * Applies fee to amountOut
3514
- **/
3515
- flatFeeAmountOutXD(data) {
3516
- super.add(flatFeeAmountOutXD.createIx(new FlatFeeArgs(data.fee)));
3517
- return this;
3518
- }
3519
- /**
3520
- * Applies progressive fee to amountIn
3752
+ * Applies protocol fee to amountIn with direct transfer
3521
3753
  **/
3522
- progressiveFeeInXD(data) {
3523
- super.add(progressiveFeeInXD.createIx(new FlatFeeArgs(data.fee)));
3754
+ protocolFeeAmountInXD(data) {
3755
+ super.add(protocolFeeAmountInXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
3524
3756
  return this;
3525
3757
  }
3526
3758
  /**
3527
- * Applies progressive fee to amountOut
3759
+ * Applies protocol fee to amountIn through Aqua protocol
3528
3760
  **/
3529
- progressiveFeeOutXD(data) {
3530
- super.add(progressiveFeeOutXD.createIx(new FlatFeeArgs(data.fee)));
3761
+ aquaProtocolFeeAmountInXD(data) {
3762
+ super.add(aquaProtocolFeeAmountInXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
3531
3763
  return this;
3532
3764
  }
3533
3765
  /**
3534
- * Applies protocol fee to amountOut with direct transfer
3766
+ * Applies protocol fee, fetched from external contract, to amountIn with direct transfer
3535
3767
  **/
3536
- protocolFeeAmountOutXD(data) {
3537
- super.add(protocolFeeAmountOutXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
3768
+ dynamicProtocolFeeAmountInXD(data) {
3769
+ super.add(dynamicProtocolFeeAmountInXD.createIx(new DynamicProtocolFeeArgs(data.feeProvider)));
3538
3770
  return this;
3539
3771
  }
3540
3772
  /**
3541
- * Applies protocol fee to amountOut through Aqua protocol
3773
+ * Applies protocol fee, fetched from external contract, to amountIn through Aqua protocol
3542
3774
  **/
3543
- aquaProtocolFeeAmountOutXD(data) {
3544
- super.add(aquaProtocolFeeAmountOutXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
3775
+ aquaDynamicProtocolFeeAmountInXD(data) {
3776
+ super.add(aquaDynamicProtocolFeeAmountInXD.createIx(new DynamicProtocolFeeArgs(data.feeProvider)));
3545
3777
  return this;
3546
3778
  }
3547
3779
  /**
@@ -3704,23 +3936,12 @@ var Order = class Order {
3704
3936
 
3705
3937
  //#endregion
3706
3938
  //#region src/swap-vm/strategies/aqua-amm-strategy.ts
3707
- /**
3708
- * Aqua AMM Strategy builder that mirrors AquaAMM.sol
3709
- * @see https://github.com/1inch/swap-vm/blob/main/src/strategies/AquaAMM.sol
3710
- */
3711
- var AquaAMMStrategy = class AquaAMMStrategy {
3939
+ var AquaAMMStrategy = class {
3712
3940
  feeBpsIn;
3713
- deltas;
3714
3941
  decayPeriod;
3715
3942
  protocolFee;
3716
3943
  salt;
3717
- constructor(tokenA, tokenB) {
3718
- this.tokenA = tokenA;
3719
- this.tokenB = tokenB;
3720
- }
3721
- static new(tokens) {
3722
- return new AquaAMMStrategy(tokens.tokenA, tokens.tokenB);
3723
- }
3944
+ constructor() {}
3724
3945
  withProtocolFee(bps, receiver) {
3725
3946
  this.protocolFee = {
3726
3947
  bps,
@@ -3728,13 +3949,6 @@ var AquaAMMStrategy = class AquaAMMStrategy {
3728
3949
  };
3729
3950
  return this;
3730
3951
  }
3731
- withDeltas(a, b) {
3732
- this.deltas = {
3733
- a,
3734
- b
3735
- };
3736
- return this;
3737
- }
3738
3952
  withDecayPeriod(decayPeriod) {
3739
3953
  this.decayPeriod = decayPeriod;
3740
3954
  return this;
@@ -3747,22 +3961,80 @@ var AquaAMMStrategy = class AquaAMMStrategy {
3747
3961
  this.salt = salt$1;
3748
3962
  return this;
3749
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
+ }
3750
3987
  build() {
3751
3988
  const builder = new AquaProgramBuilder();
3752
- if (this.deltas) {
3753
- const data = ConcentrateGrowLiquidity2DArgs.fromTokenDeltas(this.tokenA, this.tokenB, this.deltas.a, this.deltas.b);
3754
- 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));
3755
3992
  }
3993
+ if (this.xycConcentrateArgs) builder.add(concentrateGrowLiquidity2D.createIx(this.xycConcentrateArgs));
3756
3994
  if (this.decayPeriod) builder.decayXD({ decayPeriod: this.decayPeriod });
3757
3995
  if (this.feeBpsIn) {
3758
3996
  const data = FlatFeeArgs.fromBps(this.feeBpsIn);
3759
3997
  builder.add(flatFeeAmountInXD.createIx(data));
3760
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();
3761
4019
  if (this.protocolFee) {
3762
4020
  const data = ProtocolFeeArgs.fromBps(this.protocolFee.bps, this.protocolFee.receiver);
3763
- builder.add(aquaProtocolFeeAmountOutXD.createIx(data));
4021
+ builder.add(aquaProtocolFeeAmountInXD.createIx(data));
3764
4022
  }
3765
- 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);
3766
4038
  if (this.salt) builder.salt({ salt: this.salt });
3767
4039
  return builder.build();
3768
4040
  }
@@ -3774,4 +4046,4 @@ var abi_exports = {};
3774
4046
  __export(abi_exports, { SWAP_VM_ABI: () => SWAP_VM_ABI });
3775
4047
 
3776
4048
  //#endregion
3777
- 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 };