@1inch/swap-vm-sdk 0.1.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 (241) hide show
  1. package/LICENSE +103 -0
  2. package/README.md +584 -0
  3. package/dist/abi/SwapVM.abi.d.mts +403 -0
  4. package/dist/abi/SwapVM.abi.d.ts +403 -0
  5. package/dist/abi/index.d.mts +1 -0
  6. package/dist/abi/index.d.ts +1 -0
  7. package/dist/index.d.mts +4 -0
  8. package/dist/index.d.ts +4 -0
  9. package/dist/index.js +3842 -0
  10. package/dist/index.mjs +3777 -0
  11. package/dist/swap-vm/index.d.mts +6 -0
  12. package/dist/swap-vm/index.d.ts +6 -0
  13. package/dist/swap-vm/instructions/balances/balances-args-coder.d.mts +7 -0
  14. package/dist/swap-vm/instructions/balances/balances-args-coder.d.ts +7 -0
  15. package/dist/swap-vm/instructions/balances/balances-args.d.mts +17 -0
  16. package/dist/swap-vm/instructions/balances/balances-args.d.ts +17 -0
  17. package/dist/swap-vm/instructions/balances/index.d.mts +3 -0
  18. package/dist/swap-vm/instructions/balances/index.d.ts +3 -0
  19. package/dist/swap-vm/instructions/balances/opcodes.d.mts +12 -0
  20. package/dist/swap-vm/instructions/balances/opcodes.d.ts +12 -0
  21. package/dist/swap-vm/instructions/balances/types.d.mts +5 -0
  22. package/dist/swap-vm/instructions/balances/types.d.ts +5 -0
  23. package/dist/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args-coder.d.mts +7 -0
  24. package/dist/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args-coder.d.ts +7 -0
  25. package/dist/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args.d.mts +40 -0
  26. package/dist/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args.d.ts +40 -0
  27. package/dist/swap-vm/instructions/base-fee-adjuster/index.d.mts +2 -0
  28. package/dist/swap-vm/instructions/base-fee-adjuster/index.d.ts +2 -0
  29. package/dist/swap-vm/instructions/base-fee-adjuster/opcodes.d.mts +5 -0
  30. package/dist/swap-vm/instructions/base-fee-adjuster/opcodes.d.ts +5 -0
  31. package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args-coder.d.mts +7 -0
  32. package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args-coder.d.ts +7 -0
  33. package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args.d.mts +21 -0
  34. package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args.d.ts +21 -0
  35. package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args-coder.d.mts +7 -0
  36. package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args-coder.d.ts +7 -0
  37. package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args.d.mts +17 -0
  38. package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args.d.ts +17 -0
  39. package/dist/swap-vm/instructions/concentrate/index.d.mts +5 -0
  40. package/dist/swap-vm/instructions/concentrate/index.d.ts +5 -0
  41. package/dist/swap-vm/instructions/concentrate/opcodes.d.mts +10 -0
  42. package/dist/swap-vm/instructions/concentrate/opcodes.d.ts +10 -0
  43. package/dist/swap-vm/instructions/concentrate/types.d.mts +5 -0
  44. package/dist/swap-vm/instructions/concentrate/types.d.ts +5 -0
  45. package/dist/swap-vm/instructions/concentrate/utils.d.mts +4 -0
  46. package/dist/swap-vm/instructions/concentrate/utils.d.ts +4 -0
  47. package/dist/swap-vm/instructions/controls/deadline-args-coder.d.mts +7 -0
  48. package/dist/swap-vm/instructions/controls/deadline-args-coder.d.ts +7 -0
  49. package/dist/swap-vm/instructions/controls/deadline-args.d.mts +9 -0
  50. package/dist/swap-vm/instructions/controls/deadline-args.d.ts +9 -0
  51. package/dist/swap-vm/instructions/controls/index.d.mts +8 -0
  52. package/dist/swap-vm/instructions/controls/index.d.ts +8 -0
  53. package/dist/swap-vm/instructions/controls/jump-args-coder.d.mts +7 -0
  54. package/dist/swap-vm/instructions/controls/jump-args-coder.d.ts +7 -0
  55. package/dist/swap-vm/instructions/controls/jump-args.d.mts +16 -0
  56. package/dist/swap-vm/instructions/controls/jump-args.d.ts +16 -0
  57. package/dist/swap-vm/instructions/controls/jump-if-token-args-coder.d.mts +7 -0
  58. package/dist/swap-vm/instructions/controls/jump-if-token-args-coder.d.ts +7 -0
  59. package/dist/swap-vm/instructions/controls/jump-if-token-args.d.mts +10 -0
  60. package/dist/swap-vm/instructions/controls/jump-if-token-args.d.ts +10 -0
  61. package/dist/swap-vm/instructions/controls/only-taker-token-balance-gte-args-coder.d.mts +7 -0
  62. package/dist/swap-vm/instructions/controls/only-taker-token-balance-gte-args-coder.d.ts +7 -0
  63. package/dist/swap-vm/instructions/controls/only-taker-token-balance-gte-args.d.mts +17 -0
  64. package/dist/swap-vm/instructions/controls/only-taker-token-balance-gte-args.d.ts +17 -0
  65. package/dist/swap-vm/instructions/controls/only-taker-token-balance-non-zero-args-coder.d.mts +7 -0
  66. package/dist/swap-vm/instructions/controls/only-taker-token-balance-non-zero-args-coder.d.ts +7 -0
  67. package/dist/swap-vm/instructions/controls/only-taker-token-balance-non-zero-args.d.mts +16 -0
  68. package/dist/swap-vm/instructions/controls/only-taker-token-balance-non-zero-args.d.ts +16 -0
  69. package/dist/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args-coder.d.mts +7 -0
  70. package/dist/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args-coder.d.ts +7 -0
  71. package/dist/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args.d.mts +18 -0
  72. package/dist/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args.d.ts +18 -0
  73. package/dist/swap-vm/instructions/controls/opcodes.d.mts +36 -0
  74. package/dist/swap-vm/instructions/controls/opcodes.d.ts +36 -0
  75. package/dist/swap-vm/instructions/controls/salt-args-coder.d.mts +7 -0
  76. package/dist/swap-vm/instructions/controls/salt-args-coder.d.ts +7 -0
  77. package/dist/swap-vm/instructions/controls/salt-args.d.mts +16 -0
  78. package/dist/swap-vm/instructions/controls/salt-args.d.ts +16 -0
  79. package/dist/swap-vm/instructions/debug/debug-args.d.mts +8 -0
  80. package/dist/swap-vm/instructions/debug/debug-args.d.ts +8 -0
  81. package/dist/swap-vm/instructions/debug/debug-empty-args.d.mts +19 -0
  82. package/dist/swap-vm/instructions/debug/debug-empty-args.d.ts +19 -0
  83. package/dist/swap-vm/instructions/debug/opcodes.d.mts +18 -0
  84. package/dist/swap-vm/instructions/debug/opcodes.d.ts +18 -0
  85. package/dist/swap-vm/instructions/debug/print-amount-for-swap.d.mts +16 -0
  86. package/dist/swap-vm/instructions/debug/print-amount-for-swap.d.ts +16 -0
  87. package/dist/swap-vm/instructions/debug/print-context.d.mts +16 -0
  88. package/dist/swap-vm/instructions/debug/print-context.d.ts +16 -0
  89. package/dist/swap-vm/instructions/debug/print-free-memory-pointer.d.mts +16 -0
  90. package/dist/swap-vm/instructions/debug/print-free-memory-pointer.d.ts +16 -0
  91. package/dist/swap-vm/instructions/debug/print-gas-left.d.mts +16 -0
  92. package/dist/swap-vm/instructions/debug/print-gas-left.d.ts +16 -0
  93. package/dist/swap-vm/instructions/debug/print-swap-query.d.mts +16 -0
  94. package/dist/swap-vm/instructions/debug/print-swap-query.d.ts +16 -0
  95. package/dist/swap-vm/instructions/debug/print-swap-registers.d.mts +16 -0
  96. package/dist/swap-vm/instructions/debug/print-swap-registers.d.ts +16 -0
  97. package/dist/swap-vm/instructions/decay/decay-xd-args-coder.d.mts +7 -0
  98. package/dist/swap-vm/instructions/decay/decay-xd-args-coder.d.ts +7 -0
  99. package/dist/swap-vm/instructions/decay/decay-xd-args.d.mts +16 -0
  100. package/dist/swap-vm/instructions/decay/decay-xd-args.d.ts +16 -0
  101. package/dist/swap-vm/instructions/decay/index.d.mts +2 -0
  102. package/dist/swap-vm/instructions/decay/index.d.ts +2 -0
  103. package/dist/swap-vm/instructions/decay/opcodes.d.mts +5 -0
  104. package/dist/swap-vm/instructions/decay/opcodes.d.ts +5 -0
  105. package/dist/swap-vm/instructions/dutch-auction/dutch-auction-args-coder.d.mts +7 -0
  106. package/dist/swap-vm/instructions/dutch-auction/dutch-auction-args-coder.d.ts +7 -0
  107. package/dist/swap-vm/instructions/dutch-auction/dutch-auction-args.d.mts +44 -0
  108. package/dist/swap-vm/instructions/dutch-auction/dutch-auction-args.d.ts +44 -0
  109. package/dist/swap-vm/instructions/dutch-auction/index.d.mts +2 -0
  110. package/dist/swap-vm/instructions/dutch-auction/index.d.ts +2 -0
  111. package/dist/swap-vm/instructions/dutch-auction/opcodes.d.mts +10 -0
  112. package/dist/swap-vm/instructions/dutch-auction/opcodes.d.ts +10 -0
  113. package/dist/swap-vm/instructions/empty.d.mts +13 -0
  114. package/dist/swap-vm/instructions/empty.d.ts +13 -0
  115. package/dist/swap-vm/instructions/extruction/extruction-args-coder.d.mts +7 -0
  116. package/dist/swap-vm/instructions/extruction/extruction-args-coder.d.ts +7 -0
  117. package/dist/swap-vm/instructions/extruction/extruction-args.d.mts +21 -0
  118. package/dist/swap-vm/instructions/extruction/extruction-args.d.ts +21 -0
  119. package/dist/swap-vm/instructions/extruction/index.d.mts +2 -0
  120. package/dist/swap-vm/instructions/extruction/index.d.ts +2 -0
  121. package/dist/swap-vm/instructions/extruction/opcodes.d.mts +5 -0
  122. package/dist/swap-vm/instructions/extruction/opcodes.d.ts +5 -0
  123. package/dist/swap-vm/instructions/fee/flat-fee-args-coder.d.mts +7 -0
  124. package/dist/swap-vm/instructions/fee/flat-fee-args-coder.d.ts +7 -0
  125. package/dist/swap-vm/instructions/fee/flat-fee-args.d.mts +28 -0
  126. package/dist/swap-vm/instructions/fee/flat-fee-args.d.ts +28 -0
  127. package/dist/swap-vm/instructions/fee/index.d.mts +3 -0
  128. package/dist/swap-vm/instructions/fee/index.d.ts +3 -0
  129. package/dist/swap-vm/instructions/fee/opcodes.d.mts +30 -0
  130. package/dist/swap-vm/instructions/fee/opcodes.d.ts +30 -0
  131. package/dist/swap-vm/instructions/fee/protocol-fee-args-coder.d.mts +7 -0
  132. package/dist/swap-vm/instructions/fee/protocol-fee-args-coder.d.ts +7 -0
  133. package/dist/swap-vm/instructions/fee/protocol-fee-args.d.mts +35 -0
  134. package/dist/swap-vm/instructions/fee/protocol-fee-args.d.ts +35 -0
  135. package/dist/swap-vm/instructions/index.d.mts +29 -0
  136. package/dist/swap-vm/instructions/index.d.ts +29 -0
  137. package/dist/swap-vm/instructions/instruction.d.mts +7 -0
  138. package/dist/swap-vm/instructions/instruction.d.ts +7 -0
  139. package/dist/swap-vm/instructions/invalidators/index.d.mts +4 -0
  140. package/dist/swap-vm/instructions/invalidators/index.d.ts +4 -0
  141. package/dist/swap-vm/instructions/invalidators/invalidate-bit-1d-args-coder.d.mts +7 -0
  142. package/dist/swap-vm/instructions/invalidators/invalidate-bit-1d-args-coder.d.ts +7 -0
  143. package/dist/swap-vm/instructions/invalidators/invalidate-bit-1d-args.d.mts +16 -0
  144. package/dist/swap-vm/instructions/invalidators/invalidate-bit-1d-args.d.ts +16 -0
  145. package/dist/swap-vm/instructions/invalidators/invalidate-token-in-1d-args-coder.d.mts +7 -0
  146. package/dist/swap-vm/instructions/invalidators/invalidate-token-in-1d-args-coder.d.ts +7 -0
  147. package/dist/swap-vm/instructions/invalidators/invalidate-token-in-1d-args.d.mts +8 -0
  148. package/dist/swap-vm/instructions/invalidators/invalidate-token-in-1d-args.d.ts +8 -0
  149. package/dist/swap-vm/instructions/invalidators/invalidate-token-out-1d-args-coder.d.mts +7 -0
  150. package/dist/swap-vm/instructions/invalidators/invalidate-token-out-1d-args-coder.d.ts +7 -0
  151. package/dist/swap-vm/instructions/invalidators/invalidate-token-out-1d-args.d.mts +8 -0
  152. package/dist/swap-vm/instructions/invalidators/invalidate-token-out-1d-args.d.ts +8 -0
  153. package/dist/swap-vm/instructions/invalidators/opcodes.d.mts +15 -0
  154. package/dist/swap-vm/instructions/invalidators/opcodes.d.ts +15 -0
  155. package/dist/swap-vm/instructions/limit-swap/index.d.mts +2 -0
  156. package/dist/swap-vm/instructions/limit-swap/index.d.ts +2 -0
  157. package/dist/swap-vm/instructions/limit-swap/limit-swap-direction-args-coder.d.mts +7 -0
  158. package/dist/swap-vm/instructions/limit-swap/limit-swap-direction-args-coder.d.ts +7 -0
  159. package/dist/swap-vm/instructions/limit-swap/limit-swap-direction-args.d.mts +24 -0
  160. package/dist/swap-vm/instructions/limit-swap/limit-swap-direction-args.d.ts +24 -0
  161. package/dist/swap-vm/instructions/limit-swap/opcodes.d.mts +10 -0
  162. package/dist/swap-vm/instructions/limit-swap/opcodes.d.ts +10 -0
  163. package/dist/swap-vm/instructions/min-rate/index.d.mts +2 -0
  164. package/dist/swap-vm/instructions/min-rate/index.d.ts +2 -0
  165. package/dist/swap-vm/instructions/min-rate/min-rate-args-coder.d.mts +7 -0
  166. package/dist/swap-vm/instructions/min-rate/min-rate-args-coder.d.ts +7 -0
  167. package/dist/swap-vm/instructions/min-rate/min-rate-args.d.mts +22 -0
  168. package/dist/swap-vm/instructions/min-rate/min-rate-args.d.ts +22 -0
  169. package/dist/swap-vm/instructions/min-rate/opcodes.d.mts +10 -0
  170. package/dist/swap-vm/instructions/min-rate/opcodes.d.ts +10 -0
  171. package/dist/swap-vm/instructions/opcode.d.mts +8 -0
  172. package/dist/swap-vm/instructions/opcode.d.ts +8 -0
  173. package/dist/swap-vm/instructions/oracle-price-adjuster/index.d.mts +2 -0
  174. package/dist/swap-vm/instructions/oracle-price-adjuster/index.d.ts +2 -0
  175. package/dist/swap-vm/instructions/oracle-price-adjuster/opcodes.d.mts +5 -0
  176. package/dist/swap-vm/instructions/oracle-price-adjuster/opcodes.d.ts +5 -0
  177. package/dist/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args-coder.d.mts +7 -0
  178. package/dist/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args-coder.d.ts +7 -0
  179. package/dist/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args.d.mts +41 -0
  180. package/dist/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args.d.ts +41 -0
  181. package/dist/swap-vm/instructions/stable-swap/index.d.mts +2 -0
  182. package/dist/swap-vm/instructions/stable-swap/index.d.ts +2 -0
  183. package/dist/swap-vm/instructions/stable-swap/opcodes.d.mts +4 -0
  184. package/dist/swap-vm/instructions/stable-swap/opcodes.d.ts +4 -0
  185. package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args-coder.d.mts +7 -0
  186. package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args-coder.d.ts +7 -0
  187. package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args.d.mts +25 -0
  188. package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args.d.ts +25 -0
  189. package/dist/swap-vm/instructions/twap-swap/index.d.mts +2 -0
  190. package/dist/swap-vm/instructions/twap-swap/index.d.ts +2 -0
  191. package/dist/swap-vm/instructions/twap-swap/opcodes.d.mts +5 -0
  192. package/dist/swap-vm/instructions/twap-swap/opcodes.d.ts +5 -0
  193. package/dist/swap-vm/instructions/twap-swap/twap-swap-args-coder.d.mts +7 -0
  194. package/dist/swap-vm/instructions/twap-swap/twap-swap-args-coder.d.ts +7 -0
  195. package/dist/swap-vm/instructions/twap-swap/twap-swap-args.d.mts +71 -0
  196. package/dist/swap-vm/instructions/twap-swap/twap-swap-args.d.ts +71 -0
  197. package/dist/swap-vm/instructions/types.d.mts +18 -0
  198. package/dist/swap-vm/instructions/types.d.ts +18 -0
  199. package/dist/swap-vm/instructions/xyc-swap/index.d.mts +2 -0
  200. package/dist/swap-vm/instructions/xyc-swap/index.d.ts +2 -0
  201. package/dist/swap-vm/instructions/xyc-swap/opcodes.d.mts +5 -0
  202. package/dist/swap-vm/instructions/xyc-swap/opcodes.d.ts +5 -0
  203. package/dist/swap-vm/instructions/xyc-swap/xyc-swap-xd-args-coder.d.mts +7 -0
  204. package/dist/swap-vm/instructions/xyc-swap/xyc-swap-xd-args-coder.d.ts +7 -0
  205. package/dist/swap-vm/instructions/xyc-swap/xyc-swap-xd-args.d.mts +15 -0
  206. package/dist/swap-vm/instructions/xyc-swap/xyc-swap-xd-args.d.ts +15 -0
  207. package/dist/swap-vm/maker-traits.d.mts +206 -0
  208. package/dist/swap-vm/maker-traits.d.ts +206 -0
  209. package/dist/swap-vm/order.d.mts +84 -0
  210. package/dist/swap-vm/order.d.ts +84 -0
  211. package/dist/swap-vm/programs/aqua-program-builder.d.mts +118 -0
  212. package/dist/swap-vm/programs/aqua-program-builder.d.ts +118 -0
  213. package/dist/swap-vm/programs/index.d.mts +4 -0
  214. package/dist/swap-vm/programs/index.d.ts +4 -0
  215. package/dist/swap-vm/programs/program-builder.d.mts +26 -0
  216. package/dist/swap-vm/programs/program-builder.d.ts +26 -0
  217. package/dist/swap-vm/programs/regular-program-builder.d.mts +187 -0
  218. package/dist/swap-vm/programs/regular-program-builder.d.ts +187 -0
  219. package/dist/swap-vm/programs/swap-vm-program.d.mts +6 -0
  220. package/dist/swap-vm/programs/swap-vm-program.d.ts +6 -0
  221. package/dist/swap-vm/strategies/aqua-amm-strategy.d.mts +32 -0
  222. package/dist/swap-vm/strategies/aqua-amm-strategy.d.ts +32 -0
  223. package/dist/swap-vm/strategies/index.d.mts +1 -0
  224. package/dist/swap-vm/strategies/index.d.ts +1 -0
  225. package/dist/swap-vm/taker-traits.d.mts +214 -0
  226. package/dist/swap-vm/taker-traits.d.ts +214 -0
  227. package/dist/swap-vm/types.d.mts +22 -0
  228. package/dist/swap-vm/types.d.ts +22 -0
  229. package/dist/swap-vm-contract/constants.d.mts +13 -0
  230. package/dist/swap-vm-contract/constants.d.ts +13 -0
  231. package/dist/swap-vm-contract/events/index.d.mts +1 -0
  232. package/dist/swap-vm-contract/events/index.d.ts +1 -0
  233. package/dist/swap-vm-contract/events/swapped-event.d.mts +19 -0
  234. package/dist/swap-vm-contract/events/swapped-event.d.ts +19 -0
  235. package/dist/swap-vm-contract/index.d.mts +4 -0
  236. package/dist/swap-vm-contract/index.d.ts +4 -0
  237. package/dist/swap-vm-contract/swap-vm-contract.d.mts +38 -0
  238. package/dist/swap-vm-contract/swap-vm-contract.d.ts +38 -0
  239. package/dist/swap-vm-contract/types.d.mts +22 -0
  240. package/dist/swap-vm-contract/types.d.ts +22 -0
  241. package/package.json +72 -0
package/dist/index.mjs ADDED
@@ -0,0 +1,3777 @@
1
+ import { decodeAbiParameters, decodeEventLog, encodeAbiParameters, encodeFunctionData, hashTypedData, keccak256 } from "viem";
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
+ 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
+ import assert from "assert";
5
+ import assert$1 from "node:assert";
6
+
7
+ //#region rolldown:runtime
8
+ var __defProp = Object.defineProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ };
15
+
16
+ //#endregion
17
+ //#region src/abi/SwapVM.abi.ts
18
+ const SWAP_VM_ABI = [
19
+ {
20
+ type: "function",
21
+ name: "AQUA",
22
+ inputs: [],
23
+ outputs: [{
24
+ name: "",
25
+ type: "address",
26
+ internalType: "contract IAqua"
27
+ }],
28
+ stateMutability: "view"
29
+ },
30
+ {
31
+ type: "function",
32
+ name: "ORDER_TYPEHASH",
33
+ inputs: [],
34
+ outputs: [{
35
+ name: "",
36
+ type: "bytes32",
37
+ internalType: "bytes32"
38
+ }],
39
+ stateMutability: "view"
40
+ },
41
+ {
42
+ type: "function",
43
+ name: "asView",
44
+ inputs: [],
45
+ outputs: [{
46
+ name: "",
47
+ type: "address",
48
+ internalType: "contract ISwapVM"
49
+ }],
50
+ stateMutability: "view"
51
+ },
52
+ {
53
+ type: "function",
54
+ name: "eip712Domain",
55
+ inputs: [],
56
+ outputs: [
57
+ {
58
+ name: "fields",
59
+ type: "bytes1",
60
+ internalType: "bytes1"
61
+ },
62
+ {
63
+ name: "name",
64
+ type: "string",
65
+ internalType: "string"
66
+ },
67
+ {
68
+ name: "version",
69
+ type: "string",
70
+ internalType: "string"
71
+ },
72
+ {
73
+ name: "chainId",
74
+ type: "uint256",
75
+ internalType: "uint256"
76
+ },
77
+ {
78
+ name: "verifyingContract",
79
+ type: "address",
80
+ internalType: "address"
81
+ },
82
+ {
83
+ name: "salt",
84
+ type: "bytes32",
85
+ internalType: "bytes32"
86
+ },
87
+ {
88
+ name: "extensions",
89
+ type: "uint256[]",
90
+ internalType: "uint256[]"
91
+ }
92
+ ],
93
+ stateMutability: "view"
94
+ },
95
+ {
96
+ type: "function",
97
+ name: "hash",
98
+ inputs: [{
99
+ name: "order",
100
+ type: "tuple",
101
+ internalType: "struct ISwapVM.Order",
102
+ components: [
103
+ {
104
+ name: "maker",
105
+ type: "address",
106
+ internalType: "address"
107
+ },
108
+ {
109
+ name: "traits",
110
+ type: "uint256",
111
+ internalType: "MakerTraits"
112
+ },
113
+ {
114
+ name: "data",
115
+ type: "bytes",
116
+ internalType: "bytes"
117
+ }
118
+ ]
119
+ }],
120
+ outputs: [{
121
+ name: "",
122
+ type: "bytes32",
123
+ internalType: "bytes32"
124
+ }],
125
+ stateMutability: "view"
126
+ },
127
+ {
128
+ type: "function",
129
+ name: "quote",
130
+ inputs: [
131
+ {
132
+ name: "order",
133
+ type: "tuple",
134
+ internalType: "struct ISwapVM.Order",
135
+ components: [
136
+ {
137
+ name: "maker",
138
+ type: "address",
139
+ internalType: "address"
140
+ },
141
+ {
142
+ name: "traits",
143
+ type: "uint256",
144
+ internalType: "MakerTraits"
145
+ },
146
+ {
147
+ name: "data",
148
+ type: "bytes",
149
+ internalType: "bytes"
150
+ }
151
+ ]
152
+ },
153
+ {
154
+ name: "tokenIn",
155
+ type: "address",
156
+ internalType: "address"
157
+ },
158
+ {
159
+ name: "tokenOut",
160
+ type: "address",
161
+ internalType: "address"
162
+ },
163
+ {
164
+ name: "amount",
165
+ type: "uint256",
166
+ internalType: "uint256"
167
+ },
168
+ {
169
+ name: "takerTraitsAndData",
170
+ type: "bytes",
171
+ internalType: "bytes"
172
+ }
173
+ ],
174
+ outputs: [
175
+ {
176
+ name: "amountIn",
177
+ type: "uint256",
178
+ internalType: "uint256"
179
+ },
180
+ {
181
+ name: "amountOut",
182
+ type: "uint256",
183
+ internalType: "uint256"
184
+ },
185
+ {
186
+ name: "orderHash",
187
+ type: "bytes32",
188
+ internalType: "bytes32"
189
+ }
190
+ ],
191
+ stateMutability: "nonpayable"
192
+ },
193
+ {
194
+ type: "function",
195
+ name: "swap",
196
+ inputs: [
197
+ {
198
+ name: "order",
199
+ type: "tuple",
200
+ internalType: "struct ISwapVM.Order",
201
+ components: [
202
+ {
203
+ name: "maker",
204
+ type: "address",
205
+ internalType: "address"
206
+ },
207
+ {
208
+ name: "traits",
209
+ type: "uint256",
210
+ internalType: "MakerTraits"
211
+ },
212
+ {
213
+ name: "data",
214
+ type: "bytes",
215
+ internalType: "bytes"
216
+ }
217
+ ]
218
+ },
219
+ {
220
+ name: "tokenIn",
221
+ type: "address",
222
+ internalType: "address"
223
+ },
224
+ {
225
+ name: "tokenOut",
226
+ type: "address",
227
+ internalType: "address"
228
+ },
229
+ {
230
+ name: "amount",
231
+ type: "uint256",
232
+ internalType: "uint256"
233
+ },
234
+ {
235
+ name: "takerTraitsAndData",
236
+ type: "bytes",
237
+ internalType: "bytes"
238
+ }
239
+ ],
240
+ outputs: [
241
+ {
242
+ name: "amountIn",
243
+ type: "uint256",
244
+ internalType: "uint256"
245
+ },
246
+ {
247
+ name: "amountOut",
248
+ type: "uint256",
249
+ internalType: "uint256"
250
+ },
251
+ {
252
+ name: "orderHash",
253
+ type: "bytes32",
254
+ internalType: "bytes32"
255
+ }
256
+ ],
257
+ stateMutability: "nonpayable"
258
+ },
259
+ {
260
+ type: "event",
261
+ name: "EIP712DomainChanged",
262
+ inputs: [],
263
+ anonymous: false
264
+ },
265
+ {
266
+ type: "event",
267
+ name: "Swapped",
268
+ inputs: [
269
+ {
270
+ name: "orderHash",
271
+ type: "bytes32",
272
+ indexed: false,
273
+ internalType: "bytes32"
274
+ },
275
+ {
276
+ name: "maker",
277
+ type: "address",
278
+ indexed: false,
279
+ internalType: "address"
280
+ },
281
+ {
282
+ name: "taker",
283
+ type: "address",
284
+ indexed: false,
285
+ internalType: "address"
286
+ },
287
+ {
288
+ name: "tokenIn",
289
+ type: "address",
290
+ indexed: false,
291
+ internalType: "address"
292
+ },
293
+ {
294
+ name: "tokenOut",
295
+ type: "address",
296
+ indexed: false,
297
+ internalType: "address"
298
+ },
299
+ {
300
+ name: "amountIn",
301
+ type: "uint256",
302
+ indexed: false,
303
+ internalType: "uint256"
304
+ },
305
+ {
306
+ name: "amountOut",
307
+ type: "uint256",
308
+ indexed: false,
309
+ internalType: "uint256"
310
+ }
311
+ ],
312
+ anonymous: false
313
+ },
314
+ {
315
+ type: "error",
316
+ name: "AquaBalanceInsufficientAfterTakerPush",
317
+ inputs: [
318
+ {
319
+ name: "balance",
320
+ type: "uint256",
321
+ internalType: "uint256"
322
+ },
323
+ {
324
+ name: "preBalance",
325
+ type: "uint256",
326
+ internalType: "uint256"
327
+ },
328
+ {
329
+ name: "amount",
330
+ type: "uint256",
331
+ internalType: "uint256"
332
+ }
333
+ ]
334
+ },
335
+ {
336
+ type: "error",
337
+ name: "BadSignature",
338
+ inputs: [
339
+ {
340
+ name: "maker",
341
+ type: "address",
342
+ internalType: "address"
343
+ },
344
+ {
345
+ name: "orderHash",
346
+ type: "bytes32",
347
+ internalType: "bytes32"
348
+ },
349
+ {
350
+ name: "signature",
351
+ type: "bytes",
352
+ internalType: "bytes"
353
+ }
354
+ ]
355
+ },
356
+ {
357
+ type: "error",
358
+ name: "ForceApproveFailed",
359
+ inputs: []
360
+ },
361
+ {
362
+ type: "error",
363
+ name: "InvalidShortString",
364
+ inputs: []
365
+ },
366
+ {
367
+ type: "error",
368
+ name: "MakerTraitsCustomReceiverIsIncompatibleWithAqua",
369
+ inputs: []
370
+ },
371
+ {
372
+ type: "error",
373
+ name: "MakerTraitsTokenInAndTokenOutMustBeDifferent",
374
+ inputs: []
375
+ },
376
+ {
377
+ type: "error",
378
+ name: "MakerTraitsUnwrapIsIncompatibleWithAqua",
379
+ inputs: []
380
+ },
381
+ {
382
+ type: "error",
383
+ name: "MakerTraitsZeroAmountInNotAllowed",
384
+ inputs: []
385
+ },
386
+ {
387
+ type: "error",
388
+ name: "RunLoopExcessiveCall",
389
+ inputs: [{
390
+ name: "pc",
391
+ type: "uint256",
392
+ internalType: "uint256"
393
+ }, {
394
+ name: "programLength",
395
+ type: "uint256",
396
+ internalType: "uint256"
397
+ }]
398
+ },
399
+ {
400
+ type: "error",
401
+ name: "SafeTransferFromFailed",
402
+ inputs: []
403
+ },
404
+ {
405
+ type: "error",
406
+ name: "StringTooLong",
407
+ inputs: [{
408
+ name: "str",
409
+ type: "string",
410
+ internalType: "string"
411
+ }]
412
+ },
413
+ {
414
+ type: "error",
415
+ name: "TakerTraitsAmountOutMustBeGreaterThanZero",
416
+ inputs: [{
417
+ name: "amountOut",
418
+ type: "uint256",
419
+ internalType: "uint256"
420
+ }]
421
+ },
422
+ {
423
+ type: "error",
424
+ name: "TakerTraitsExceedingMaxInputAmount",
425
+ inputs: [{
426
+ name: "amountIn",
427
+ type: "uint256",
428
+ internalType: "uint256"
429
+ }, {
430
+ name: "amountInMax",
431
+ type: "uint256",
432
+ internalType: "uint256"
433
+ }]
434
+ },
435
+ {
436
+ type: "error",
437
+ name: "TakerTraitsInsufficientMinOutputAmount",
438
+ inputs: [{
439
+ name: "amountOut",
440
+ type: "uint256",
441
+ internalType: "uint256"
442
+ }, {
443
+ name: "amountOutMin",
444
+ type: "uint256",
445
+ internalType: "uint256"
446
+ }]
447
+ },
448
+ {
449
+ type: "error",
450
+ name: "TakerTraitsNonExactThresholdAmountIn",
451
+ inputs: [{
452
+ name: "amountIn",
453
+ type: "uint256",
454
+ internalType: "uint256"
455
+ }, {
456
+ name: "amountThreshold",
457
+ type: "uint256",
458
+ internalType: "uint256"
459
+ }]
460
+ },
461
+ {
462
+ type: "error",
463
+ name: "TakerTraitsNonExactThresholdAmountOut",
464
+ inputs: [{
465
+ name: "amountOut",
466
+ type: "uint256",
467
+ internalType: "uint256"
468
+ }, {
469
+ name: "amountThreshold",
470
+ type: "uint256",
471
+ internalType: "uint256"
472
+ }]
473
+ },
474
+ {
475
+ type: "error",
476
+ name: "TakerTraitsTakerAmountInMismatch",
477
+ inputs: [{
478
+ name: "takerAmount",
479
+ type: "uint256",
480
+ internalType: "uint256"
481
+ }, {
482
+ name: "computedAmount",
483
+ type: "uint256",
484
+ internalType: "uint256"
485
+ }]
486
+ },
487
+ {
488
+ type: "error",
489
+ name: "TakerTraitsTakerAmountOutMismatch",
490
+ inputs: [{
491
+ name: "takerAmount",
492
+ type: "uint256",
493
+ internalType: "uint256"
494
+ }, {
495
+ name: "computedAmount",
496
+ type: "uint256",
497
+ internalType: "uint256"
498
+ }]
499
+ },
500
+ {
501
+ type: "error",
502
+ name: "UnexpectedLock",
503
+ inputs: []
504
+ }
505
+ ];
506
+
507
+ //#endregion
508
+ //#region src/swap-vm-contract/swap-vm-contract.ts
509
+ /**
510
+ * SwapVM contract encoding/decoding utilities
511
+ */
512
+ var SwapVMContract = class SwapVMContract {
513
+ constructor(address) {
514
+ this.address = address;
515
+ }
516
+ /**
517
+ * Encode quote function call data
518
+ * @see https://github.com/1inch/swap-vm/blob/main/src/SwapVM.sol#L84
519
+ */
520
+ static encodeQuoteCallData(args) {
521
+ const result = encodeFunctionData({
522
+ abi: SWAP_VM_ABI,
523
+ functionName: "quote",
524
+ args: [
525
+ args.order.build(),
526
+ args.tokenIn.toString(),
527
+ args.tokenOut.toString(),
528
+ args.amount,
529
+ args.takerTraits.encode().toString()
530
+ ]
531
+ });
532
+ return new HexString$1(result);
533
+ }
534
+ /**
535
+ * Encode `hashOrder` function call data
536
+ * @see https://github.com/1inch/swap-vm/blob/main/src/SwapVM.sol#L70
537
+ */
538
+ static encodeHashOrderCallData(order) {
539
+ const result = encodeFunctionData({
540
+ abi: SWAP_VM_ABI,
541
+ functionName: "hash",
542
+ args: [order.build()]
543
+ });
544
+ return new HexString$1(result);
545
+ }
546
+ /**
547
+ * Encode swap function call data
548
+ * @see https://github.com/1inch/swap-vm/blob/main/src/SwapVM.sol#L124
549
+ */
550
+ static encodeSwapCallData(args) {
551
+ const result = encodeFunctionData({
552
+ abi: SWAP_VM_ABI,
553
+ functionName: "swap",
554
+ args: [
555
+ args.order.build(),
556
+ args.tokenIn.toString(),
557
+ args.tokenOut.toString(),
558
+ args.amount,
559
+ args.takerTraits.encode().toString()
560
+ ]
561
+ });
562
+ return new HexString$1(result);
563
+ }
564
+ /**
565
+ * Build quote transaction
566
+ */
567
+ static buildQuoteTx(contractAddress, args) {
568
+ return {
569
+ to: contractAddress.toString(),
570
+ data: this.encodeQuoteCallData(args).toString(),
571
+ value: 0n
572
+ };
573
+ }
574
+ /**
575
+ * Build swap transaction
576
+ */
577
+ static buildSwapTx(contractAddress, args) {
578
+ return {
579
+ to: contractAddress.toString(),
580
+ data: this.encodeSwapCallData(args).toString(),
581
+ value: 0n
582
+ };
583
+ }
584
+ static buildHashOrderTx(contractAddress, order) {
585
+ return {
586
+ to: contractAddress.toString(),
587
+ data: this.encodeHashOrderCallData(order).toString(),
588
+ value: 0n
589
+ };
590
+ }
591
+ swap(args) {
592
+ return SwapVMContract.buildSwapTx(this.address, args);
593
+ }
594
+ quote(args) {
595
+ return SwapVMContract.buildQuoteTx(this.address, args);
596
+ }
597
+ hashOrder(order) {
598
+ return SwapVMContract.buildHashOrderTx(this.address, order);
599
+ }
600
+ };
601
+
602
+ //#endregion
603
+ //#region src/swap-vm-contract/constants.ts
604
+ /**
605
+ * AquaSwapVMRouter contract addresses by chain ID
606
+ * These addresses supports only AQUA instructions set
607
+ *
608
+ * Deployed with next params
609
+ * - name = `AquaSwapVMRouter`
610
+ * - version = `1.0.0`
611
+ *
612
+ * @see https://github.com/1inch/swap-vm/blob/8cc4c467374959af9efdb6e2b67d32d3c1083e1e/src/routers/AquaSwapVMRouter.sol#L11
613
+ * @see "../swap-vm/programs/aqua-program-builder"
614
+ */
615
+ const AQUA_SWAP_VM_CONTRACT_ADDRESSES = {
616
+ [NetworkEnum$1.ETHEREUM]: new Address$1("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
617
+ [NetworkEnum$1.BINANCE]: new Address$1("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
618
+ [NetworkEnum$1.POLYGON]: new Address$1("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
619
+ [NetworkEnum$1.ARBITRUM]: new Address$1("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
620
+ [NetworkEnum$1.AVALANCHE]: new Address$1("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
621
+ [NetworkEnum$1.GNOSIS]: new Address$1("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
622
+ [NetworkEnum$1.COINBASE]: new Address$1("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
623
+ [NetworkEnum$1.OPTIMISM]: new Address$1("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
624
+ [NetworkEnum$1.ZKSYNC]: new Address$1("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
625
+ [NetworkEnum$1.LINEA]: new Address$1("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
626
+ [NetworkEnum$1.UNICHAIN]: new Address$1("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
627
+ [NetworkEnum$1.SONIC]: new Address$1("0x8fdd04dbf6111437b44bbca99c28882434e0958f")
628
+ };
629
+
630
+ //#endregion
631
+ //#region src/swap-vm-contract/events/swapped-event.ts
632
+ var SwappedEvent = class SwappedEvent {
633
+ static TOPIC = new HexString$1("0x54bc5c027d15d7aa8ae083f994ab4411d2f223291672ecd3a344f3d92dcaf8b2");
634
+ constructor(orderHash, maker, taker, tokenIn, tokenOut, amountIn, amountOut) {
635
+ this.orderHash = orderHash;
636
+ this.maker = maker;
637
+ this.taker = taker;
638
+ this.tokenIn = tokenIn;
639
+ this.tokenOut = tokenOut;
640
+ this.amountIn = amountIn;
641
+ this.amountOut = amountOut;
642
+ }
643
+ static new(data) {
644
+ return new SwappedEvent(data.orderHash, data.maker, data.taker, data.tokenIn, data.tokenOut, data.amountIn, data.amountOut);
645
+ }
646
+ /**
647
+ * Creates a SwappedEvent
648
+ * @throws Error if the log data is invalid or doesn't match the expected event structure
649
+ */
650
+ static fromLog(log) {
651
+ const decoded = decodeEventLog({
652
+ abi: SWAP_VM_ABI,
653
+ data: log.data,
654
+ topics: log.topics,
655
+ eventName: "Swapped"
656
+ });
657
+ const { orderHash, maker, taker, tokenIn, tokenOut, amountIn, amountOut } = decoded.args;
658
+ return new SwappedEvent(new HexString$1(orderHash), new Address$1(maker), new Address$1(taker), new Address$1(tokenIn), new Address$1(tokenOut), amountIn, amountOut);
659
+ }
660
+ };
661
+
662
+ //#endregion
663
+ //#region src/swap-vm/maker-traits.ts
664
+ /**
665
+ * Maker-side order configuration packed into a single `uint256` and an optional hooks data blob.
666
+ *
667
+ * This class mirrors the on-chain `MakerTraits` bit layout and encoding used by the SwapVM
668
+ * contracts. It is responsible for:
669
+ *
670
+ * - maker preferences (unwrap WETH, allow zero amount in, Aqua vs signature)
671
+ * - selecting an optional custom receiver
672
+ * - wiring pre/post transfer hooks and their optional targets/payloads
673
+ *
674
+ * The ABI-level representation is:
675
+ * - `traits` – a `uint256` where:
676
+ * - high bits 245–255 store boolean flags
677
+ * - bits 160–223 store cumulative offsets for hook data slices (4 × `uint16`)
678
+ * - bits 0–159 store the receiver address (0 means "maker")
679
+ * - `hooksData` – concatenation of hook payloads in the order:
680
+ * `preTransferIn`, `postTransferIn`, `preTransferOut`, `postTransferOut`
681
+ */
682
+ var MakerTraits = class MakerTraits {
683
+ static HOOKS = [
684
+ "preTransferInHook",
685
+ "postTransferInHook",
686
+ "preTransferOutHook",
687
+ "postTransferOutHook"
688
+ ];
689
+ static SHOULD_UNWRAP_BIT_FLAG = 255n;
690
+ static USE_AQUA_INSTEAD_OF_SIGNATURE_BIT_FLAG = 254n;
691
+ static ALLOW_ZERO_AMOUNT_IN = 253n;
692
+ static HAS_PRE_TRANSFER_IN_HOOK_BIT_FLAG = 252n;
693
+ static HAS_POST_TRANSFER_IN_HOOK_BIT_FLAG = 251n;
694
+ static HAS_PRE_TRANSFER_OUT_HOOK_BIT_FLAG = 250n;
695
+ static HAS_POST_TRANSFER_OUT_HOOK_BIT_FLAG = 249n;
696
+ static PRE_TRANSFER_IN_HOOK_HAS_TARGET = 248n;
697
+ static POST_TRANSFER_IN_HOOK_HAS_TARGET = 247n;
698
+ static PRE_TRANSFER_OUT_HOOK_HAS_TARGET = 246n;
699
+ static POST_TRANSFER_OUT_HOOK_HAS_TARGET = 245n;
700
+ static CUSTOM_RECEIVER_MASK = new BitMask(0n, 160n);
701
+ static HOOKS_DATA_OFFSETS_MASK = new BitMask(160n, 224n);
702
+ constructor(shouldUnwrap, useAquaInsteadOfSignature, allowZeroAmountIn, customReceiver, preTransferInHook, postTransferInHook, preTransferOutHook, postTransferOutHook) {
703
+ this.shouldUnwrap = shouldUnwrap;
704
+ this.useAquaInsteadOfSignature = useAquaInsteadOfSignature;
705
+ this.allowZeroAmountIn = allowZeroAmountIn;
706
+ this.customReceiver = customReceiver;
707
+ this.preTransferInHook = preTransferInHook;
708
+ this.postTransferInHook = postTransferInHook;
709
+ this.preTransferOutHook = preTransferOutHook;
710
+ this.postTransferOutHook = postTransferOutHook;
711
+ }
712
+ /**
713
+ * Construct traits from a plain data object.
714
+ */
715
+ static new(data) {
716
+ return new MakerTraits(data.shouldUnwrap, data.useAquaInsteadOfSignature, data.allowZeroAmountIn, data.customReceiver, data.preTransferInHook, data.postTransferInHook, data.preTransferOutHook, data.postTransferOutHook);
717
+ }
718
+ /**
719
+ * Create traits with library defaults that match the on-chain SwapVM expectations:
720
+ * - `useAquaInsteadOfSignature` = `true`
721
+ * - `shouldUnwrap` = `false`
722
+ * - `allowZeroAmountIn` = `false`
723
+ * - no receiver or hooks configured.
724
+ */
725
+ static default() {
726
+ return MakerTraits.new({
727
+ useAquaInsteadOfSignature: true,
728
+ allowZeroAmountIn: false,
729
+ shouldUnwrap: false
730
+ });
731
+ }
732
+ /**
733
+ * Decode ABI-level representation into a `MakerTraits` instance.
734
+ *
735
+ * @param traits Packed `uint256` bitfield as produced by {@link encode}.
736
+ * @param hooksData Concatenated hooks payloads in the format expected by SwapVM
737
+ * contracts (may be `HexString.EMPTY` when no hooks are present).
738
+ *
739
+ * Both arguments are typically obtained from contract storage / ABI and must
740
+ * follow the bit layout described in the class-level documentation.
741
+ */
742
+ static decode(traits, hooksData = HexString$1.EMPTY) {
743
+ const traitsBN = new BN(traits);
744
+ const shouldUnwrap = traitsBN.getBit(MakerTraits.SHOULD_UNWRAP_BIT_FLAG);
745
+ const useAquaInsteadOfSignature = traitsBN.getBit(MakerTraits.USE_AQUA_INSTEAD_OF_SIGNATURE_BIT_FLAG);
746
+ const allowZeroAmountIn = traitsBN.getBit(MakerTraits.ALLOW_ZERO_AMOUNT_IN);
747
+ const customReceiver = Address$1.fromBigInt(traitsBN.getMask(MakerTraits.CUSTOM_RECEIVER_MASK).value);
748
+ const hooksDataOffsets = traitsBN.getMask(MakerTraits.HOOKS_DATA_OFFSETS_MASK).value;
749
+ const hasPreTransferInHook = Boolean(traitsBN.getBit(MakerTraits.HAS_PRE_TRANSFER_IN_HOOK_BIT_FLAG));
750
+ const hasPreTransferInHookTarget = Boolean(traitsBN.getBit(MakerTraits.PRE_TRANSFER_IN_HOOK_HAS_TARGET));
751
+ const preTransferInHook = parseHook(hooksData, hasPreTransferInHook, hasPreTransferInHookTarget, hooksDataOffsets, 0);
752
+ const hasPostTransferInHook = Boolean(traitsBN.getBit(MakerTraits.HAS_POST_TRANSFER_IN_HOOK_BIT_FLAG));
753
+ const hasPostTransferInHookTarget = Boolean(traitsBN.getBit(MakerTraits.POST_TRANSFER_IN_HOOK_HAS_TARGET));
754
+ const postTransferInHook = parseHook(hooksData, hasPostTransferInHook, hasPostTransferInHookTarget, hooksDataOffsets, 1);
755
+ const hasPreTransferOutHook = Boolean(traitsBN.getBit(MakerTraits.HAS_PRE_TRANSFER_OUT_HOOK_BIT_FLAG));
756
+ const hasPreTransferOutHookTarget = Boolean(traitsBN.getBit(MakerTraits.PRE_TRANSFER_OUT_HOOK_HAS_TARGET));
757
+ const preTransferOutHook = parseHook(hooksData, hasPreTransferOutHook, hasPreTransferOutHookTarget, hooksDataOffsets, 2);
758
+ const hasPostTransferOutHook = Boolean(traitsBN.getBit(MakerTraits.HAS_POST_TRANSFER_OUT_HOOK_BIT_FLAG));
759
+ const hasPostTransferOutHookTarget = Boolean(traitsBN.getBit(MakerTraits.POST_TRANSFER_OUT_HOOK_HAS_TARGET));
760
+ const postTransferOutHook = parseHook(hooksData, hasPostTransferOutHook, hasPostTransferOutHookTarget, hooksDataOffsets, 3);
761
+ return MakerTraits.new({
762
+ useAquaInsteadOfSignature: Boolean(useAquaInsteadOfSignature),
763
+ allowZeroAmountIn: Boolean(allowZeroAmountIn),
764
+ shouldUnwrap: Boolean(shouldUnwrap),
765
+ customReceiver: customReceiver.isZero() ? void 0 : customReceiver,
766
+ preTransferInHook,
767
+ postTransferInHook,
768
+ preTransferOutHook,
769
+ postTransferOutHook
770
+ });
771
+ }
772
+ static hooksDataEndsAtByte(traits) {
773
+ const bn = new BN(traits);
774
+ const offsets = bn.getMask(MakerTraits.HOOKS_DATA_OFFSETS_MASK).value;
775
+ const dataEndAt = Number(offsets >> 16n * BigInt(MakerTraits.HOOKS.length - 1) & 0xffffn);
776
+ return dataEndAt;
777
+ }
778
+ /**
779
+ * Mutate the traits instance in-place with a partial update and return it.
780
+ *
781
+ * This is primarily used for fluent-style construction in tests and examples, e.g.:
782
+ *
783
+ * `MakerTraits.default().with({ shouldUnwrap: true })`
784
+ *
785
+ * Only fields present in `data` are updated; flags, receiver, and hooks can be
786
+ * changed independently.
787
+ */
788
+ with(data) {
789
+ Object.assign(this, data);
790
+ return this;
791
+ }
792
+ /**
793
+ * Encode traits into the ABI format expected by SwapVM contracts.
794
+ *
795
+ * @param maker - Maker address for this order. This parameter is required only
796
+ * for gas/size optimisation; if omitted, any non-zero hook `target`
797
+ * is treated as an explicit target.
798
+ *
799
+ * @returns An object containing:
800
+ * - `traits` - Packed `uint256` bitfield with flags, receiver and offsets
801
+ * - `hooksData` - Concatenation of hook segments for all configured hooks
802
+ *
803
+ * ## Bit Layout of `traits` (uint256)
804
+ *
805
+ * ```
806
+ * 255 0
807
+ * +------------+----------------------------+------------------+
808
+ * | Flags | Hook Offsets (4×uint16) | Receiver Address |
809
+ * | [255-245] | [223-160] | [159-0] |
810
+ * +------------+----------------------------+------------------+
811
+ * ```
812
+ *
813
+ * ## Flags (by bit index)
814
+ *
815
+ * | Bit | Flag Name |
816
+ * |-----|------------------------------------------|
817
+ * | 255 | SHOULD_UNWRAP_BIT_FLAG |
818
+ * | 254 | USE_AQUA_INSTEAD_OF_SIGNATURE_BIT_FLAG |
819
+ * | 253 | ALLOW_ZERO_AMOUNT_IN |
820
+ * | 252 | HAS_PRE_TRANSFER_IN_HOOK_BIT_FLAG |
821
+ * | 251 | HAS_POST_TRANSFER_IN_HOOK_BIT_FLAG |
822
+ * | 250 | HAS_PRE_TRANSFER_OUT_HOOK_BIT_FLAG |
823
+ * | 249 | HAS_POST_TRANSFER_OUT_HOOK_BIT_FLAG |
824
+ * | 248 | PRE_TRANSFER_IN_HOOK_HAS_TARGET |
825
+ * | 247 | POST_TRANSFER_IN_HOOK_HAS_TARGET |
826
+ * | 246 | PRE_TRANSFER_OUT_HOOK_HAS_TARGET |
827
+ * | 245 | POST_TRANSFER_OUT_HOOK_HAS_TARGET |
828
+ */
829
+ encode(maker) {
830
+ let traits = new BN(0n);
831
+ traits = traits.setBit(MakerTraits.SHOULD_UNWRAP_BIT_FLAG, this.shouldUnwrap);
832
+ traits = traits.setBit(MakerTraits.USE_AQUA_INSTEAD_OF_SIGNATURE_BIT_FLAG, this.useAquaInsteadOfSignature);
833
+ traits = traits.setBit(MakerTraits.ALLOW_ZERO_AMOUNT_IN, this.allowZeroAmountIn);
834
+ traits = traits.setBit(MakerTraits.HAS_PRE_TRANSFER_IN_HOOK_BIT_FLAG, this.preTransferInHook !== void 0);
835
+ traits = traits.setBit(MakerTraits.HAS_POST_TRANSFER_IN_HOOK_BIT_FLAG, this.postTransferInHook !== void 0);
836
+ traits = traits.setBit(MakerTraits.HAS_PRE_TRANSFER_OUT_HOOK_BIT_FLAG, this.preTransferOutHook !== void 0);
837
+ traits = traits.setBit(MakerTraits.HAS_POST_TRANSFER_OUT_HOOK_BIT_FLAG, this.postTransferOutHook !== void 0);
838
+ traits = traits.setBit(MakerTraits.PRE_TRANSFER_IN_HOOK_HAS_TARGET, this.hasTargetForHook("preTransferInHook", maker));
839
+ traits = traits.setBit(MakerTraits.POST_TRANSFER_IN_HOOK_HAS_TARGET, this.hasTargetForHook("postTransferInHook", maker));
840
+ traits = traits.setBit(MakerTraits.PRE_TRANSFER_OUT_HOOK_HAS_TARGET, this.hasTargetForHook("preTransferOutHook", maker));
841
+ traits = traits.setBit(MakerTraits.POST_TRANSFER_OUT_HOOK_HAS_TARGET, this.hasTargetForHook("postTransferOutHook", maker));
842
+ traits = traits.setMask(MakerTraits.CUSTOM_RECEIVER_MASK, BigInt(this.customReceiver?.toString() || 0n));
843
+ const { data, offsets } = MakerTraits.HOOKS.reduce((acc, hookName, i) => {
844
+ const hook = this[hookName];
845
+ const hasTarget = this.hasTargetForHook(hookName);
846
+ const encoded = hook && hasTarget ? hook.encode() : hook?.data || HexString$1.EMPTY;
847
+ acc.sum += BigInt(encoded.bytesCount());
848
+ acc.offsets += acc.sum << 16n * BigInt(i);
849
+ acc.data = acc.data.concat(encoded);
850
+ return acc;
851
+ }, {
852
+ data: HexString$1.EMPTY,
853
+ offsets: 0n,
854
+ sum: 0n
855
+ });
856
+ traits = traits.setMask(MakerTraits.HOOKS_DATA_OFFSETS_MASK, offsets);
857
+ return {
858
+ traits: traits.value,
859
+ hooksData: data
860
+ };
861
+ }
862
+ hasTargetForHook(hookName, maker = Address$1.ZERO_ADDRESS) {
863
+ const hook = this[hookName];
864
+ if (!hook) return false;
865
+ return !(hook.target.isZero() || hook.target.equal(maker));
866
+ }
867
+ };
868
+ function parseHook(fullHookData, hasHook, hasHookTarget, offsets, idx) {
869
+ if (!hasHook) return void 0;
870
+ const startDataIdx = idx === 0 ? 0 : Number(offsets >> 16n * BigInt(idx - 1) & 0xffffn);
871
+ const endDataIdx = Number(offsets >> 16n * BigInt(idx) & 0xffffn);
872
+ const hookData = fullHookData.sliceBytes(startDataIdx, endDataIdx);
873
+ if (!hasHookTarget) return new Interaction(Address$1.ZERO_ADDRESS, hookData);
874
+ return Interaction.decode(hookData);
875
+ }
876
+
877
+ //#endregion
878
+ //#region src/swap-vm/taker-traits.ts
879
+ /**
880
+ * TakerTraits encodes taker-specific parameters and flags for swap execution.
881
+ * It defines how the taker wants the swap to be executed, including thresholds,
882
+ * callbacks, hooks, and other execution parameters.
883
+ */
884
+ var TakerTraits = class TakerTraits {
885
+ static IS_EXACT_IN_BIT_FLAG = 0n;
886
+ static SHOULD_UNWRAP_BIT_FLAG = 1n;
887
+ static HAS_PRE_TRANSFER_IN_CALLBACK_BIT_FLAG = 2n;
888
+ static HAS_PRE_TRANSFER_OUT_CALLBACK_BIT_FLAG = 3n;
889
+ static IS_STRICT_THRESHOLD_BIT_FLAG = 4n;
890
+ static IS_FIRST_TRANSFER_FROM_TAKER_BIT_FLAG = 5n;
891
+ 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) {
893
+ this.exactIn = exactIn;
894
+ this.shouldUnwrap = shouldUnwrap;
895
+ this.preTransferInCallbackEnabled = preTransferInCallbackEnabled;
896
+ this.preTransferOutCallbackEnabled = preTransferOutCallbackEnabled;
897
+ this.strictThreshold = strictThreshold;
898
+ this.firstTransferFromTaker = firstTransferFromTaker;
899
+ this.useTransferFromAndAquaPush = useTransferFromAndAquaPush;
900
+ this.threshold = threshold;
901
+ this.customReceiver = customReceiver;
902
+ this.preTransferInHookData = preTransferInHookData;
903
+ this.postTransferInHookData = postTransferInHookData;
904
+ this.preTransferOutHookData = preTransferOutHookData;
905
+ this.postTransferOutHookData = postTransferOutHookData;
906
+ this.preTransferInCallbackData = preTransferInCallbackData;
907
+ this.preTransferOutCallbackData = preTransferOutCallbackData;
908
+ this.instructionsArgs = instructionsArgs;
909
+ this.signature = signature;
910
+ }
911
+ /**
912
+ * Creates a new TakerTraits instance with the specified data.
913
+ * Provides default values for unspecified fields.
914
+ */
915
+ 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);
917
+ }
918
+ /**
919
+ * Creates a default TakerTraits instance with standard settings.
920
+ * - exactIn mode
921
+ * - No unwrapping
922
+ * - No callbacks
923
+ * - No custom receiver
924
+ * - transferFromAndAquaPush enabled
925
+ */
926
+ static default() {
927
+ return TakerTraits.new({
928
+ exactIn: true,
929
+ shouldUnwrap: false,
930
+ preTransferInCallbackEnabled: false,
931
+ preTransferOutCallbackEnabled: false,
932
+ strictThreshold: false,
933
+ firstTransferFromTaker: false,
934
+ useTransferFromAndAquaPush: true,
935
+ threshold: 0n,
936
+ customReceiver: Address$1.ZERO_ADDRESS,
937
+ preTransferInHookData: HexString$1.EMPTY,
938
+ postTransferInHookData: HexString$1.EMPTY,
939
+ preTransferOutHookData: HexString$1.EMPTY,
940
+ postTransferOutHookData: HexString$1.EMPTY,
941
+ preTransferInCallbackData: HexString$1.EMPTY,
942
+ preTransferOutCallbackData: HexString$1.EMPTY,
943
+ instructionsArgs: HexString$1.EMPTY,
944
+ signature: HexString$1.EMPTY
945
+ });
946
+ }
947
+ /**
948
+ * Decodes a packed TakerTraits from a hex string.
949
+ * The packed format consists of:
950
+ * - 18 bytes: 9 uint16 offsets for data sections
951
+ * - 2 bytes: uint16 flags
952
+ * - Variable: data sections (threshold, to, hook data, callback data, etc.)
953
+ * - Variable: signature
954
+ */
955
+ static decode(packed) {
956
+ const iter = BytesIter.BigInt(packed.toString());
957
+ const offsets = Array.from({ length: 9 }, () => Number(iter.nextUint16())).reverse();
958
+ const flags = new BN(iter.nextUint16());
959
+ const dataStr = trim0x(packed.toString()).slice(40);
960
+ const sections = [];
961
+ offsets.forEach((offset, i) => {
962
+ const start = i === 0 ? 0 : offsets[i - 1];
963
+ sections.push(offset > start ? dataStr.slice(start * 2, offset * 2) : "");
964
+ });
965
+ const lastOffset = offsets[offsets.length - 1];
966
+ const signature = dataStr.length > lastOffset * 2 ? dataStr.slice(lastOffset * 2) : "";
967
+ const [threshold, to, preTransferInHookData, postTransferInHookData, preTransferOutHookData, postTransferOutHookData, preTransferInCallbackData, preTransferOutCallbackData, instructionsArgs] = sections;
968
+ return TakerTraits.new({
969
+ exactIn: Boolean(flags.getBit(TakerTraits.IS_EXACT_IN_BIT_FLAG)),
970
+ shouldUnwrap: Boolean(flags.getBit(TakerTraits.SHOULD_UNWRAP_BIT_FLAG)),
971
+ preTransferInCallbackEnabled: Boolean(flags.getBit(TakerTraits.HAS_PRE_TRANSFER_IN_CALLBACK_BIT_FLAG)),
972
+ preTransferOutCallbackEnabled: Boolean(flags.getBit(TakerTraits.HAS_PRE_TRANSFER_OUT_CALLBACK_BIT_FLAG)),
973
+ strictThreshold: Boolean(flags.getBit(TakerTraits.IS_STRICT_THRESHOLD_BIT_FLAG)),
974
+ firstTransferFromTaker: Boolean(flags.getBit(TakerTraits.IS_FIRST_TRANSFER_FROM_TAKER_BIT_FLAG)),
975
+ useTransferFromAndAquaPush: Boolean(flags.getBit(TakerTraits.USE_TRANSFER_FROM_AND_AQUA_PUSH_FLAG)),
976
+ threshold: threshold ? BigInt(add0x(threshold)) : 0n,
977
+ customReceiver: to ? new Address$1(add0x(to)) : Address$1.ZERO_ADDRESS,
978
+ preTransferInHookData: preTransferInHookData ? new HexString$1(add0x(preTransferInHookData)) : HexString$1.EMPTY,
979
+ postTransferInHookData: postTransferInHookData ? new HexString$1(add0x(postTransferInHookData)) : HexString$1.EMPTY,
980
+ preTransferOutHookData: preTransferOutHookData ? new HexString$1(add0x(preTransferOutHookData)) : HexString$1.EMPTY,
981
+ postTransferOutHookData: postTransferOutHookData ? new HexString$1(add0x(postTransferOutHookData)) : HexString$1.EMPTY,
982
+ preTransferInCallbackData: preTransferInCallbackData ? new HexString$1(add0x(preTransferInCallbackData)) : HexString$1.EMPTY,
983
+ preTransferOutCallbackData: preTransferOutCallbackData ? new HexString$1(add0x(preTransferOutCallbackData)) : HexString$1.EMPTY,
984
+ instructionsArgs: instructionsArgs ? new HexString$1(add0x(instructionsArgs)) : HexString$1.EMPTY,
985
+ signature: signature ? new HexString$1(add0x(signature)) : HexString$1.EMPTY
986
+ });
987
+ }
988
+ /**
989
+ * Creates a new instance with updated fields.
990
+ * Useful for creating modified versions of existing TakerTraits.
991
+ */
992
+ with(data) {
993
+ Object.assign(this, data);
994
+ return this;
995
+ }
996
+ /**
997
+ * Encodes the TakerTraits into a packed hex string format.
998
+ * The encoding includes offsets, flags, data sections, and signature.
999
+ * Callback flags are automatically set based on callback data presence.
1000
+ */
1001
+ encode() {
1002
+ const builder = new BytesBuilder();
1003
+ const dataFields = [
1004
+ this.threshold > 0n ? new HexString$1("0x" + this.threshold.toString(16).padStart(64, "0")) : HexString$1.EMPTY,
1005
+ !this.customReceiver.isZero() ? new HexString$1(this.customReceiver.toString()) : HexString$1.EMPTY,
1006
+ this.preTransferInHookData,
1007
+ this.postTransferInHookData,
1008
+ this.preTransferOutHookData,
1009
+ this.postTransferOutHookData,
1010
+ this.preTransferInCallbackData,
1011
+ this.preTransferOutCallbackData,
1012
+ this.instructionsArgs
1013
+ ];
1014
+ const { offsets, data } = dataFields.reduce((acc, field) => {
1015
+ const length = field.bytesCount();
1016
+ acc.sum += length;
1017
+ acc.offsets.push(acc.sum);
1018
+ acc.data.push(field.toString().slice(2));
1019
+ return acc;
1020
+ }, {
1021
+ sum: 0,
1022
+ offsets: [],
1023
+ data: []
1024
+ });
1025
+ offsets.reverse().forEach((offset) => builder.addUint16(BigInt(offset)));
1026
+ let flags = new BN(0n);
1027
+ flags = flags.setBit(TakerTraits.IS_EXACT_IN_BIT_FLAG, this.exactIn);
1028
+ flags = flags.setBit(TakerTraits.SHOULD_UNWRAP_BIT_FLAG, this.shouldUnwrap);
1029
+ flags = flags.setBit(TakerTraits.HAS_PRE_TRANSFER_IN_CALLBACK_BIT_FLAG, !this.preTransferInCallbackData.isEmpty());
1030
+ flags = flags.setBit(TakerTraits.HAS_PRE_TRANSFER_OUT_CALLBACK_BIT_FLAG, !this.preTransferOutCallbackData.isEmpty());
1031
+ flags = flags.setBit(TakerTraits.IS_STRICT_THRESHOLD_BIT_FLAG, this.strictThreshold);
1032
+ flags = flags.setBit(TakerTraits.IS_FIRST_TRANSFER_FROM_TAKER_BIT_FLAG, this.firstTransferFromTaker);
1033
+ flags = flags.setBit(TakerTraits.USE_TRANSFER_FROM_AND_AQUA_PUSH_FLAG, this.useTransferFromAndAquaPush);
1034
+ builder.addUint16(flags.value);
1035
+ const allData = data.join("") + this.signature.toString().slice(2);
1036
+ if (allData) builder.addBytes("0x" + allData);
1037
+ return new HexString$1(builder.asHex());
1038
+ }
1039
+ /**
1040
+ * Validates the swap amounts against the threshold settings.
1041
+ * @param amountIn - The input amount of the swap
1042
+ * @param amountOut - The output amount of the swap
1043
+ * @throws Error if the amounts don't meet the threshold requirements
1044
+ */
1045
+ validate(amountIn, amountOut) {
1046
+ if (this.threshold === 0n) return;
1047
+ const threshold = this.threshold;
1048
+ if (this.strictThreshold) {
1049
+ const actual = this.exactIn ? amountOut : amountIn;
1050
+ if (actual !== threshold) throw new Error(`TakerTraitsNonExactThresholdAmount: ${this.exactIn ? "amountOut" : "amountIn"} ${actual} != threshold ${threshold}`);
1051
+ } else if (this.exactIn) {
1052
+ if (amountOut < threshold) throw new Error(`TakerTraitsInsufficientMinOutputAmount: amountOut ${amountOut} < threshold ${threshold}`);
1053
+ } else if (amountIn > threshold) throw new Error(`TakerTraitsExceedingMaxInputAmount: amountIn ${amountIn} > threshold ${threshold}`);
1054
+ }
1055
+ };
1056
+
1057
+ //#endregion
1058
+ //#region src/swap-vm/programs/swap-vm-program.ts
1059
+ /**
1060
+ * Represents encoded SwapVM program bytecode
1061
+ **/
1062
+ var SwapVmProgram = class extends HexString$1 {};
1063
+
1064
+ //#endregion
1065
+ //#region src/swap-vm/instructions/instruction.ts
1066
+ var Instruction = class {
1067
+ constructor(opcode, args) {
1068
+ this.opcode = opcode;
1069
+ this.args = args;
1070
+ }
1071
+ toJSON() {
1072
+ return {
1073
+ opcode: this.opcode.id.toString(),
1074
+ args: this.args.toJSON()
1075
+ };
1076
+ }
1077
+ };
1078
+
1079
+ //#endregion
1080
+ //#region src/swap-vm/instructions/opcode.ts
1081
+ var Opcode = class {
1082
+ constructor(id, coder) {
1083
+ this.id = id;
1084
+ this.coder = coder;
1085
+ }
1086
+ argsCoder() {
1087
+ return this.coder;
1088
+ }
1089
+ createIx(args) {
1090
+ return new Instruction(this, args);
1091
+ }
1092
+ };
1093
+
1094
+ //#endregion
1095
+ //#region src/swap-vm/instructions/empty.ts
1096
+ var EmptyCoder = class {
1097
+ encode(_) {
1098
+ return HexString$1.EMPTY;
1099
+ }
1100
+ decode(_) {
1101
+ return new EmptyArgs();
1102
+ }
1103
+ };
1104
+ var EmptyArgs = class {
1105
+ static CODER = new EmptyCoder();
1106
+ toJSON() {
1107
+ return null;
1108
+ }
1109
+ };
1110
+ const EMPTY_OPCODE = new Opcode(Symbol("empty"), EmptyArgs.CODER);
1111
+
1112
+ //#endregion
1113
+ //#region src/swap-vm/programs/program-builder.ts
1114
+ /**
1115
+ * Abstract base class for building SwapVM programs
1116
+ **/
1117
+ var ProgramBuilder = class {
1118
+ program = [];
1119
+ constructor(ixsSet) {
1120
+ this.ixsSet = ixsSet;
1121
+ }
1122
+ /**
1123
+ * Decodes a SwapVM program into builder instructions
1124
+ **/
1125
+ decode(program) {
1126
+ const iter = BytesIter.HexString(program.toString());
1127
+ while (!iter.isEmpty()) {
1128
+ const opcodeIdx = Number(iter.nextByte());
1129
+ const argsLength = Number(iter.nextByte());
1130
+ const argsHex = argsLength ? iter.nextBytes(argsLength) : "0x";
1131
+ if (opcodeIdx === 0) throw new Error("Invalid opcode: 0 (NOT_INSTRUCTION)");
1132
+ const opcode = this.ixsSet[opcodeIdx];
1133
+ if (!opcode) throw new Error(`Opcode at index ${opcodeIdx} is missing`);
1134
+ this.program.push(opcode.createIx(opcode.argsCoder().decode(new HexString$1(argsHex))));
1135
+ }
1136
+ return this;
1137
+ }
1138
+ /**
1139
+ * Builds the SwapVM program bytecode from accumulated instructions
1140
+ **/
1141
+ build() {
1142
+ const builder = new BytesBuilder();
1143
+ for (const ix of this.program) {
1144
+ const { args, opcode } = ix;
1145
+ const opcodeIdx = this.ixsSet.findIndex((o) => o.id === opcode.id);
1146
+ const coder = opcode.argsCoder();
1147
+ const encoded = coder.encode(args);
1148
+ const encodedBytes = trim0x(encoded.toString());
1149
+ builder.addByte(BigInt(opcodeIdx)).addByte(BigInt(encodedBytes.length / 2));
1150
+ if (encodedBytes.length) builder.addBytes(add0x(encodedBytes));
1151
+ }
1152
+ return new SwapVmProgram(builder.asHex());
1153
+ }
1154
+ /**
1155
+ * Returns the current list of instructions in the program
1156
+ **/
1157
+ getInstructions() {
1158
+ return this.program;
1159
+ }
1160
+ /**
1161
+ * Adds an instruction to the program with validation
1162
+ **/
1163
+ add(ix) {
1164
+ const opcodeId = this.ixsSet.findIndex((o) => o.id === ix.opcode.id);
1165
+ if (opcodeId === -1) {
1166
+ const opcodes = this.ixsSet.map((i) => String(i.id)).filter((s) => s !== EMPTY_OPCODE.toString()).join(", ");
1167
+ throw new Error(`Invalid opcode ${String(ix.opcode.id)}: Supported opcodes: ${opcodes}`);
1168
+ }
1169
+ this.program.push(ix);
1170
+ return this;
1171
+ }
1172
+ };
1173
+
1174
+ //#endregion
1175
+ //#region src/swap-vm/instructions/balances/balances-args-coder.ts
1176
+ var BalancesArgsCoder = class {
1177
+ encode(args) {
1178
+ const builder = new BytesBuilder();
1179
+ builder.addUint16(BigInt(args.tokenBalances.length));
1180
+ for (const { tokenHalf } of args.tokenBalances) builder.addBytes(tokenHalf.toString());
1181
+ for (const { value } of args.tokenBalances) builder.addUint256(value);
1182
+ return new HexString$1(builder.asHex());
1183
+ }
1184
+ decode(data) {
1185
+ const iter = BytesIter.HexString(data.toString());
1186
+ const tokenCount = Number(iter.nextUint16());
1187
+ const tokenHalfs = [];
1188
+ for (let i = 0; i < tokenCount; i++) {
1189
+ const bytes = iter.nextBytes(10);
1190
+ const hexString = add0x(bytes);
1191
+ tokenHalfs.push(AddressHalf.fromHex(hexString));
1192
+ }
1193
+ const tokenBalances = [];
1194
+ for (let i = 0; i < tokenCount; i++) tokenBalances.push({
1195
+ tokenHalf: tokenHalfs[i],
1196
+ value: BigInt(iter.nextUint256())
1197
+ });
1198
+ return new BalancesArgs(tokenBalances);
1199
+ }
1200
+ };
1201
+
1202
+ //#endregion
1203
+ //#region src/swap-vm/instructions/balances/balances-args.ts
1204
+ /**
1205
+ * Arguments for setBalances and balances instructions containing token-amount pairs
1206
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Balances.sol#L10
1207
+ **/
1208
+ var BalancesArgs = class BalancesArgs {
1209
+ static CODER = new BalancesArgsCoder();
1210
+ constructor(tokenBalances) {
1211
+ this.tokenBalances = tokenBalances;
1212
+ }
1213
+ /**
1214
+ * Decodes hex data into BalancesArgs instance
1215
+ **/
1216
+ static decode(data) {
1217
+ return BalancesArgs.CODER.decode(data);
1218
+ }
1219
+ toJSON() {
1220
+ return { tokenBalances: this.tokenBalances.map(({ tokenHalf, value }) => ({
1221
+ token: tokenHalf.toString(),
1222
+ value: value.toString()
1223
+ })) };
1224
+ }
1225
+ };
1226
+
1227
+ //#endregion
1228
+ //#region src/swap-vm/instructions/balances/opcodes.ts
1229
+ /**
1230
+ * Sets initial token balances for the swap program
1231
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Balances.sol#L59
1232
+ **/
1233
+ const staticBalancesXD = new Opcode(Symbol("Balances.staticBalancesXD"), BalancesArgs.CODER);
1234
+ /**
1235
+ * Reads token balances from program data or contract storage
1236
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Balances.sol#L89
1237
+ **/
1238
+ const dynamicBalancesXD = new Opcode(Symbol("Balances.dynamicBalancesXD"), BalancesArgs.CODER);
1239
+
1240
+ //#endregion
1241
+ //#region src/swap-vm/instructions/balances/index.ts
1242
+ var balances_exports = {};
1243
+ __export(balances_exports, {
1244
+ BalancesArgs: () => BalancesArgs,
1245
+ dynamicBalancesXD: () => dynamicBalancesXD,
1246
+ staticBalancesXD: () => staticBalancesXD
1247
+ });
1248
+
1249
+ //#endregion
1250
+ //#region src/swap-vm/instructions/controls/jump-args-coder.ts
1251
+ var JumpArgsCoder = class {
1252
+ encode(args) {
1253
+ const builder = new BytesBuilder();
1254
+ builder.addUint16(args.nextPC);
1255
+ return new HexString$1(add0x(builder.asHex()));
1256
+ }
1257
+ decode(data) {
1258
+ const iter = BytesIter.BigInt(data.toString());
1259
+ const nextPC = iter.nextUint16();
1260
+ return new JumpArgs(nextPC);
1261
+ }
1262
+ };
1263
+
1264
+ //#endregion
1265
+ //#region src/swap-vm/instructions/controls/jump-args.ts
1266
+ const UINT_16_MAX$1 = 0xffffn;
1267
+ /**
1268
+ * Arguments for jump instructions containing target program counter
1269
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L10
1270
+ **/
1271
+ var JumpArgs = class JumpArgs {
1272
+ static CODER = new JumpArgsCoder();
1273
+ constructor(nextPC) {
1274
+ this.nextPC = nextPC;
1275
+ assert$1(nextPC <= UINT_16_MAX$1 && nextPC >= 0n, `Invalid nextPC value: ${nextPC}. Must be between 0 and 65535`);
1276
+ }
1277
+ /**
1278
+ * Decodes hex data into JumpArgs instance
1279
+ **/
1280
+ static decode(data) {
1281
+ return JumpArgs.CODER.decode(data);
1282
+ }
1283
+ toJSON() {
1284
+ return { nextPC: this.nextPC };
1285
+ }
1286
+ };
1287
+
1288
+ //#endregion
1289
+ //#region src/swap-vm/instructions/controls/jump-if-token-args-coder.ts
1290
+ var JumpIfTokenArgsCoder = class {
1291
+ encode(args) {
1292
+ const builder = new BytesBuilder();
1293
+ builder.addBytes(args.tokenTail.toString());
1294
+ builder.addUint16(args.nextPC);
1295
+ return new HexString$1(add0x(builder.asHex()));
1296
+ }
1297
+ decode(data) {
1298
+ const iter = BytesIter.HexString(data.toString());
1299
+ const tokenTailBytes = iter.nextBytes(10);
1300
+ const tokenTail = AddressHalf.fromHex(tokenTailBytes);
1301
+ const nextPC = BigInt(iter.nextUint16());
1302
+ return new JumpIfTokenArgs(tokenTail, nextPC);
1303
+ }
1304
+ };
1305
+
1306
+ //#endregion
1307
+ //#region src/swap-vm/instructions/controls/jump-if-token-args.ts
1308
+ var JumpIfTokenArgs = class JumpIfTokenArgs {
1309
+ static CODER = new JumpIfTokenArgsCoder();
1310
+ constructor(tokenTail, nextPC) {
1311
+ this.tokenTail = tokenTail;
1312
+ this.nextPC = nextPC;
1313
+ }
1314
+ static decode(data) {
1315
+ return JumpIfTokenArgs.CODER.decode(data);
1316
+ }
1317
+ toJSON() {
1318
+ return {
1319
+ tokenTail: this.tokenTail.toString(),
1320
+ nextPC: this.nextPC
1321
+ };
1322
+ }
1323
+ };
1324
+
1325
+ //#endregion
1326
+ //#region src/swap-vm/instructions/controls/deadline-args-coder.ts
1327
+ var DeadlineArgsCoder = class {
1328
+ encode(args) {
1329
+ const builder = new BytesBuilder();
1330
+ builder.addUint40(args.deadline);
1331
+ return new HexString$1(add0x(builder.asHex()));
1332
+ }
1333
+ decode(data) {
1334
+ const iter = BytesIter.BigInt(data.toString());
1335
+ const deadline$1 = iter.nextUint40();
1336
+ return new DeadlineArgs(deadline$1);
1337
+ }
1338
+ };
1339
+
1340
+ //#endregion
1341
+ //#region src/swap-vm/instructions/controls/deadline-args.ts
1342
+ var DeadlineArgs = class DeadlineArgs {
1343
+ static CODER = new DeadlineArgsCoder();
1344
+ constructor(deadline$1) {
1345
+ this.deadline = deadline$1;
1346
+ }
1347
+ static decode(data) {
1348
+ return DeadlineArgs.CODER.decode(data);
1349
+ }
1350
+ toJSON() {
1351
+ return { deadline: this.deadline.toString() };
1352
+ }
1353
+ };
1354
+
1355
+ //#endregion
1356
+ //#region src/swap-vm/instructions/controls/only-taker-token-balance-non-zero-args-coder.ts
1357
+ var OnlyTakerTokenBalanceNonZeroArgsCoder = class {
1358
+ encode(args) {
1359
+ const builder = new BytesBuilder();
1360
+ builder.addAddress(args.token.toString());
1361
+ return new HexString$1(add0x(builder.asHex()));
1362
+ }
1363
+ decode(data) {
1364
+ const iter = BytesIter.HexString(data.toString());
1365
+ const token = new Address$1(iter.nextUint160());
1366
+ return new OnlyTakerTokenBalanceNonZeroArgs(token);
1367
+ }
1368
+ };
1369
+
1370
+ //#endregion
1371
+ //#region src/swap-vm/instructions/controls/only-taker-token-balance-non-zero-args.ts
1372
+ /**
1373
+ * Arguments for checking if taker holds any amount of a token
1374
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L10
1375
+ **/
1376
+ var OnlyTakerTokenBalanceNonZeroArgs = class OnlyTakerTokenBalanceNonZeroArgs {
1377
+ static CODER = new OnlyTakerTokenBalanceNonZeroArgsCoder();
1378
+ constructor(token) {
1379
+ this.token = token;
1380
+ }
1381
+ /**
1382
+ * Decodes hex data into OnlyTakerTokenBalanceNonZeroArgs instance
1383
+ **/
1384
+ static decode(data) {
1385
+ return OnlyTakerTokenBalanceNonZeroArgs.CODER.decode(data);
1386
+ }
1387
+ toJSON() {
1388
+ return { token: this.token.toString() };
1389
+ }
1390
+ };
1391
+
1392
+ //#endregion
1393
+ //#region src/swap-vm/instructions/controls/only-taker-token-balance-gte-args-coder.ts
1394
+ var OnlyTakerTokenBalanceGteArgsCoder = class {
1395
+ encode(args) {
1396
+ const builder = new BytesBuilder();
1397
+ builder.addAddress(args.token.toString());
1398
+ builder.addUint256(args.minAmount);
1399
+ return new HexString$1(add0x(builder.asHex()));
1400
+ }
1401
+ decode(data) {
1402
+ const iter = BytesIter.HexString(data.toString());
1403
+ const token = new Address$1(iter.nextUint160());
1404
+ const minAmount = BigInt(iter.nextUint256());
1405
+ return new OnlyTakerTokenBalanceGteArgs(token, minAmount);
1406
+ }
1407
+ };
1408
+
1409
+ //#endregion
1410
+ //#region src/swap-vm/instructions/controls/only-taker-token-balance-gte-args.ts
1411
+ /**
1412
+ * Arguments for checking if taker holds at least specified amount of token
1413
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L10
1414
+ **/
1415
+ var OnlyTakerTokenBalanceGteArgs = class OnlyTakerTokenBalanceGteArgs {
1416
+ static CODER = new OnlyTakerTokenBalanceGteArgsCoder();
1417
+ constructor(token, minAmount) {
1418
+ this.token = token;
1419
+ this.minAmount = minAmount;
1420
+ assert$1(minAmount >= 0n, "minAmount must be non-negative");
1421
+ }
1422
+ /**
1423
+ * Decodes hex data into OnlyTakerTokenBalanceGteArgs instance
1424
+ **/
1425
+ static decode(data) {
1426
+ return OnlyTakerTokenBalanceGteArgs.CODER.decode(data);
1427
+ }
1428
+ toJSON() {
1429
+ return {
1430
+ token: this.token.toString(),
1431
+ minAmount: this.minAmount.toString()
1432
+ };
1433
+ }
1434
+ };
1435
+
1436
+ //#endregion
1437
+ //#region src/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args-coder.ts
1438
+ var OnlyTakerTokenSupplyShareGteArgsCoder = class {
1439
+ encode(args) {
1440
+ const builder = new BytesBuilder();
1441
+ builder.addAddress(args.token.toString());
1442
+ builder.addUint64(args.minShareE18);
1443
+ return new HexString$1(add0x(builder.asHex()));
1444
+ }
1445
+ decode(data) {
1446
+ const iter = BytesIter.HexString(data.toString());
1447
+ const token = new Address$1(iter.nextUint160());
1448
+ const bytes = iter.nextBytes(8);
1449
+ const minShareE18 = BigInt(add0x(bytes));
1450
+ return new OnlyTakerTokenSupplyShareGteArgs(token, minShareE18);
1451
+ }
1452
+ };
1453
+
1454
+ //#endregion
1455
+ //#region src/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args.ts
1456
+ const UINT_64_MAX$1 = 0xffffffffffffffffn;
1457
+ /**
1458
+ * Arguments for checking if taker holds at least specified share of token's total supply
1459
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L10
1460
+ **/
1461
+ var OnlyTakerTokenSupplyShareGteArgs = class OnlyTakerTokenSupplyShareGteArgs {
1462
+ static CODER = new OnlyTakerTokenSupplyShareGteArgsCoder();
1463
+ constructor(token, minShareE18) {
1464
+ this.token = token;
1465
+ this.minShareE18 = minShareE18;
1466
+ assert$1(minShareE18 >= 0n && minShareE18 <= UINT_64_MAX$1, `Invalid minShareE18 value: ${minShareE18}. Must be a valid uint64`);
1467
+ }
1468
+ /**
1469
+ * Decodes hex data into OnlyTakerTokenSupplyShareGteArgs instance
1470
+ **/
1471
+ static decode(data) {
1472
+ return OnlyTakerTokenSupplyShareGteArgs.CODER.decode(data);
1473
+ }
1474
+ toJSON() {
1475
+ return {
1476
+ token: this.token.toString(),
1477
+ minShareE18: this.minShareE18.toString()
1478
+ };
1479
+ }
1480
+ };
1481
+
1482
+ //#endregion
1483
+ //#region src/swap-vm/instructions/controls/salt-args-coder.ts
1484
+ var SaltArgsCoder = class {
1485
+ encode(args) {
1486
+ const builder = new BytesBuilder();
1487
+ builder.addUint64(args.salt);
1488
+ return new HexString$1(add0x(builder.asHex()));
1489
+ }
1490
+ decode(data) {
1491
+ const iter = BytesIter.BigInt(data.toString());
1492
+ const bytes = iter.nextUint64();
1493
+ return new SaltArgs(bytes);
1494
+ }
1495
+ };
1496
+
1497
+ //#endregion
1498
+ //#region src/swap-vm/instructions/controls/salt-args.ts
1499
+ /**
1500
+ * Arguments for salt instruction used to add uniqueness to order hashes
1501
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L48
1502
+ **/
1503
+ var SaltArgs = class SaltArgs {
1504
+ static CODER = new SaltArgsCoder();
1505
+ constructor(salt$1) {
1506
+ 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`);
1508
+ }
1509
+ /**
1510
+ * Decodes hex data into SaltArgs instance
1511
+ **/
1512
+ static decode(data) {
1513
+ return SaltArgs.CODER.decode(data);
1514
+ }
1515
+ toJSON() {
1516
+ return { salt: this.salt.toString() };
1517
+ }
1518
+ };
1519
+
1520
+ //#endregion
1521
+ //#region src/swap-vm/instructions/controls/opcodes.ts
1522
+ /**
1523
+ * Unconditional jump to specified program counter
1524
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L52
1525
+ **/
1526
+ const jump = new Opcode(Symbol("Controls.jump"), JumpArgs.CODER);
1527
+ const jumpIfTokenIn = new Opcode(Symbol("Controls.jumpIfTokenIn"), JumpIfTokenArgs.CODER);
1528
+ const jumpIfTokenOut = new Opcode(Symbol("Controls.jumpIfTokenOut"), JumpIfTokenArgs.CODER);
1529
+ const deadline = new Opcode(Symbol("Controls.deadline"), DeadlineArgs.CODER);
1530
+ /**
1531
+ * Requires taker to hold any amount of specified token (supports NFTs)
1532
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L77
1533
+ **/
1534
+ const onlyTakerTokenBalanceNonZero = new Opcode(Symbol("Controls.onlyTakerTokenBalanceNonZero"), OnlyTakerTokenBalanceNonZeroArgs.CODER);
1535
+ /**
1536
+ * Requires taker to hold at least specified amount of token
1537
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L86
1538
+ */
1539
+ const onlyTakerTokenBalanceGte = new Opcode(Symbol("Controls.onlyTakerTokenBalanceGte"), OnlyTakerTokenBalanceGteArgs.CODER);
1540
+ /**
1541
+ * Requires taker to hold at least specified share of token's total supply
1542
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L96
1543
+ **/
1544
+ const onlyTakerTokenSupplyShareGte = new Opcode(Symbol("Controls.onlyTakerTokenSupplyShareGte"), OnlyTakerTokenSupplyShareGteArgs.CODER);
1545
+ /**
1546
+ * No-op instruction used to add uniqueness to order hashes (prevents replay attacks)
1547
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L48
1548
+ **/
1549
+ const salt = new Opcode(Symbol("Controls.salt"), SaltArgs.CODER);
1550
+
1551
+ //#endregion
1552
+ //#region src/swap-vm/instructions/controls/index.ts
1553
+ var controls_exports = {};
1554
+ __export(controls_exports, {
1555
+ DeadlineArgs: () => DeadlineArgs,
1556
+ JumpArgs: () => JumpArgs,
1557
+ JumpIfTokenArgs: () => JumpIfTokenArgs,
1558
+ OnlyTakerTokenBalanceGteArgs: () => OnlyTakerTokenBalanceGteArgs,
1559
+ OnlyTakerTokenBalanceNonZeroArgs: () => OnlyTakerTokenBalanceNonZeroArgs,
1560
+ OnlyTakerTokenSupplyShareGteArgs: () => OnlyTakerTokenSupplyShareGteArgs,
1561
+ SaltArgs: () => SaltArgs,
1562
+ deadline: () => deadline,
1563
+ jump: () => jump,
1564
+ jumpIfTokenIn: () => jumpIfTokenIn,
1565
+ jumpIfTokenOut: () => jumpIfTokenOut,
1566
+ onlyTakerTokenBalanceGte: () => onlyTakerTokenBalanceGte,
1567
+ onlyTakerTokenBalanceNonZero: () => onlyTakerTokenBalanceNonZero,
1568
+ onlyTakerTokenSupplyShareGte: () => onlyTakerTokenSupplyShareGte,
1569
+ salt: () => salt
1570
+ });
1571
+
1572
+ //#endregion
1573
+ //#region src/swap-vm/instructions/invalidators/invalidate-bit-1d-args-coder.ts
1574
+ var InvalidateBit1DArgsCoder = class {
1575
+ encode(args) {
1576
+ const builder = new BytesBuilder();
1577
+ builder.addUint32(args.bitIndex);
1578
+ return new HexString$1(add0x(builder.asHex()));
1579
+ }
1580
+ decode(data) {
1581
+ const iter = BytesIter.BigInt(data.toString());
1582
+ const bitIndex = iter.nextUint32();
1583
+ return new InvalidateBit1DArgs(bitIndex);
1584
+ }
1585
+ };
1586
+
1587
+ //#endregion
1588
+ //#region src/swap-vm/instructions/invalidators/invalidate-bit-1d-args.ts
1589
+ /**
1590
+ * Arguments for invalidateBit1D instruction to invalidate a specific bit index
1591
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Invalidators.sol#L75
1592
+ **/
1593
+ var InvalidateBit1DArgs = class InvalidateBit1DArgs {
1594
+ static CODER = new InvalidateBit1DArgsCoder();
1595
+ constructor(bitIndex) {
1596
+ this.bitIndex = bitIndex;
1597
+ assert$1(bitIndex >= 0n && bitIndex <= UINT_32_MAX, `Invalid bitIndex value: ${bitIndex}. Must be a valid uint32`);
1598
+ }
1599
+ /**
1600
+ * Decodes hex data into InvalidateBit1DArgs instance
1601
+ **/
1602
+ static decode(data) {
1603
+ return InvalidateBit1DArgs.CODER.decode(data);
1604
+ }
1605
+ toJSON() {
1606
+ return { bitIndex: this.bitIndex.toString() };
1607
+ }
1608
+ };
1609
+
1610
+ //#endregion
1611
+ //#region src/swap-vm/instructions/invalidators/invalidate-token-in-1d-args-coder.ts
1612
+ var InvalidateTokenIn1DArgsCoder = class {
1613
+ encode(_args) {
1614
+ return new HexString$1("0x");
1615
+ }
1616
+ decode(_data) {
1617
+ return new InvalidateTokenIn1DArgs();
1618
+ }
1619
+ };
1620
+
1621
+ //#endregion
1622
+ //#region src/swap-vm/instructions/invalidators/invalidate-token-in-1d-args.ts
1623
+ var InvalidateTokenIn1DArgs = class InvalidateTokenIn1DArgs {
1624
+ static CODER = new InvalidateTokenIn1DArgsCoder();
1625
+ constructor() {}
1626
+ static decode(data) {
1627
+ return InvalidateTokenIn1DArgs.CODER.decode(data);
1628
+ }
1629
+ toJSON() {
1630
+ return {};
1631
+ }
1632
+ };
1633
+
1634
+ //#endregion
1635
+ //#region src/swap-vm/instructions/invalidators/invalidate-token-out-1d-args-coder.ts
1636
+ var InvalidateTokenOut1DArgsCoder = class {
1637
+ encode(_args) {
1638
+ return new HexString$1("0x");
1639
+ }
1640
+ decode(_data) {
1641
+ return new InvalidateTokenOut1DArgs();
1642
+ }
1643
+ };
1644
+
1645
+ //#endregion
1646
+ //#region src/swap-vm/instructions/invalidators/invalidate-token-out-1d-args.ts
1647
+ var InvalidateTokenOut1DArgs = class InvalidateTokenOut1DArgs {
1648
+ static CODER = new InvalidateTokenOut1DArgsCoder();
1649
+ constructor() {}
1650
+ static decode(data) {
1651
+ return InvalidateTokenOut1DArgs.CODER.decode(data);
1652
+ }
1653
+ toJSON() {
1654
+ return {};
1655
+ }
1656
+ };
1657
+
1658
+ //#endregion
1659
+ //#region src/swap-vm/instructions/invalidators/opcodes.ts
1660
+ /**
1661
+ * Invalidates a specific bit index for order uniqueness
1662
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Invalidators.sol#L75
1663
+ **/
1664
+ const invalidateBit1D = new Opcode(Symbol("Invalidators.invalidateBit1D"), InvalidateBit1DArgs.CODER);
1665
+ /**
1666
+ * Invalidates order by token input to prevent re-use
1667
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Invalidators.sol#L85
1668
+ **/
1669
+ const invalidateTokenIn1D = new Opcode(Symbol("Invalidators.invalidateTokenIn1D"), InvalidateTokenIn1DArgs.CODER);
1670
+ /**
1671
+ * Invalidates order by token output to prevent re-use
1672
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Invalidators.sol#L103
1673
+ **/
1674
+ const invalidateTokenOut1D = new Opcode(Symbol("Invalidators.invalidateTokenOut1D"), InvalidateTokenOut1DArgs.CODER);
1675
+
1676
+ //#endregion
1677
+ //#region src/swap-vm/instructions/invalidators/index.ts
1678
+ var invalidators_exports = {};
1679
+ __export(invalidators_exports, {
1680
+ InvalidateBit1DArgs: () => InvalidateBit1DArgs,
1681
+ InvalidateTokenIn1DArgs: () => InvalidateTokenIn1DArgs,
1682
+ InvalidateTokenOut1DArgs: () => InvalidateTokenOut1DArgs,
1683
+ invalidateBit1D: () => invalidateBit1D,
1684
+ invalidateTokenIn1D: () => invalidateTokenIn1D,
1685
+ invalidateTokenOut1D: () => invalidateTokenOut1D
1686
+ });
1687
+
1688
+ //#endregion
1689
+ //#region src/swap-vm/instructions/xyc-swap/xyc-swap-xd-args-coder.ts
1690
+ var XycSwapXDArgsCoder = class {
1691
+ encode(_args) {
1692
+ return new HexString$1("0x");
1693
+ }
1694
+ decode(_data) {
1695
+ return new XycSwapXDArgs();
1696
+ }
1697
+ };
1698
+
1699
+ //#endregion
1700
+ //#region src/swap-vm/instructions/xyc-swap/xyc-swap-xd-args.ts
1701
+ /**
1702
+ * Arguments for xycSwapXD instruction (no arguments required)
1703
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCSwap.sol#L15
1704
+ **/
1705
+ var XycSwapXDArgs = class XycSwapXDArgs {
1706
+ static CODER = new XycSwapXDArgsCoder();
1707
+ constructor() {}
1708
+ /**
1709
+ * Decodes hex data into XycSwapXDArgs instance
1710
+ **/
1711
+ static decode(data) {
1712
+ return XycSwapXDArgs.CODER.decode(data);
1713
+ }
1714
+ toJSON() {
1715
+ return {};
1716
+ }
1717
+ };
1718
+
1719
+ //#endregion
1720
+ //#region src/swap-vm/instructions/xyc-swap/opcodes.ts
1721
+ /**
1722
+ * Basic swap using constant product formula (x*y=k)
1723
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCSwap.sol#L15
1724
+ **/
1725
+ const xycSwapXD = new Opcode(Symbol("XYCSwap.xycSwapXD"), XycSwapXDArgs.CODER);
1726
+
1727
+ //#endregion
1728
+ //#region src/swap-vm/instructions/xyc-swap/index.ts
1729
+ var xyc_swap_exports = {};
1730
+ __export(xyc_swap_exports, {
1731
+ XycSwapXDArgs: () => XycSwapXDArgs,
1732
+ xycSwapXD: () => xycSwapXD
1733
+ });
1734
+
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
+ //#endregion
1791
+ //#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args-coder.ts
1792
+ var ConcentrateGrowLiquidity2DArgsCoder = class {
1793
+ encode(args) {
1794
+ const builder = new BytesBuilder();
1795
+ builder.addUint256(args.deltaLt);
1796
+ builder.addUint256(args.deltaGt);
1797
+ return new HexString$1(builder.asHex());
1798
+ }
1799
+ decode(data) {
1800
+ const iter = BytesIter.BigInt(data.toString());
1801
+ const deltaLt = iter.nextUint256();
1802
+ const deltaGt = iter.nextUint256();
1803
+ return new ConcentrateGrowLiquidity2DArgs(deltaLt, deltaGt);
1804
+ }
1805
+ };
1806
+
1807
+ //#endregion
1808
+ //#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args.ts
1809
+ /**
1810
+ * Arguments for concentrateGrowLiquidity2D instruction with two deltas
1811
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L172
1812
+ **/
1813
+ var ConcentrateGrowLiquidity2DArgs = class ConcentrateGrowLiquidity2DArgs {
1814
+ 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`);
1820
+ }
1821
+ /**
1822
+ * Helper to create args from token addresses and deltas (handles ordering)
1823
+ **/
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);
1829
+ }
1830
+ /**
1831
+ * Decodes hex data into ConcentrateGrowLiquidity2DArgs instance
1832
+ **/
1833
+ static decode(data) {
1834
+ return ConcentrateGrowLiquidity2DArgs.CODER.decode(data);
1835
+ }
1836
+ toJSON() {
1837
+ return {
1838
+ deltaLt: this.deltaLt.toString(),
1839
+ deltaGt: this.deltaGt.toString()
1840
+ };
1841
+ }
1842
+ };
1843
+
1844
+ //#endregion
1845
+ //#region src/swap-vm/instructions/concentrate/opcodes.ts
1846
+ /**
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
+ * Concentrates liquidity within price bounds for two tokens
1853
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L172
1854
+ **/
1855
+ const concentrateGrowLiquidity2D = new Opcode(Symbol("XYCConcentrate.concentrateGrowLiquidity2D"), ConcentrateGrowLiquidity2DArgs.CODER);
1856
+
1857
+ //#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);
1863
+ 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)
1866
+ };
1867
+ }
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);
1877
+ }
1878
+
1879
+ //#endregion
1880
+ //#region src/swap-vm/instructions/concentrate/index.ts
1881
+ var concentrate_exports = {};
1882
+ __export(concentrate_exports, {
1883
+ ConcentrateGrowLiquidity2DArgs: () => ConcentrateGrowLiquidity2DArgs,
1884
+ ConcentrateGrowLiquidityXDArgs: () => ConcentrateGrowLiquidityXDArgs,
1885
+ computeDeltas: () => computeDeltas,
1886
+ concentrateGrowLiquidity2D: () => concentrateGrowLiquidity2D,
1887
+ concentrateGrowLiquidityXD: () => concentrateGrowLiquidityXD
1888
+ });
1889
+
1890
+ //#endregion
1891
+ //#region src/swap-vm/instructions/decay/decay-xd-args-coder.ts
1892
+ var DecayXDArgsCoder = class {
1893
+ encode(args) {
1894
+ const builder = new BytesBuilder();
1895
+ builder.addUint16(args.decayPeriod);
1896
+ return new HexString$1(builder.asHex());
1897
+ }
1898
+ decode(data) {
1899
+ const iter = BytesIter.BigInt(data.toString());
1900
+ const decayPeriod = iter.nextUint16();
1901
+ return new DecayXDArgs(decayPeriod);
1902
+ }
1903
+ };
1904
+
1905
+ //#endregion
1906
+ //#region src/swap-vm/instructions/decay/decay-xd-args.ts
1907
+ /**
1908
+ * Arguments for decayXD instruction with decay period
1909
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Decay.sol#L79
1910
+ **/
1911
+ var DecayXDArgs = class DecayXDArgs {
1912
+ static CODER = new DecayXDArgsCoder();
1913
+ constructor(decayPeriod) {
1914
+ this.decayPeriod = decayPeriod;
1915
+ assert$1(decayPeriod >= 0n && decayPeriod <= UINT_16_MAX, `Invalid decayPeriod value: ${decayPeriod}. Must be a valid uint16`);
1916
+ }
1917
+ /**
1918
+ * Decodes hex data into DecayXDArgs instance
1919
+ **/
1920
+ static decode(data) {
1921
+ return DecayXDArgs.CODER.decode(data);
1922
+ }
1923
+ toJSON() {
1924
+ return { decayPeriod: this.decayPeriod.toString() };
1925
+ }
1926
+ };
1927
+
1928
+ //#endregion
1929
+ //#region src/swap-vm/instructions/decay/opcodes.ts
1930
+ /**
1931
+ * Applies time-based decay to balance adjustments
1932
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Decay.sol#L79
1933
+ **/
1934
+ const decayXD = new Opcode(Symbol("Decay.decayXD"), DecayXDArgs.CODER);
1935
+
1936
+ //#endregion
1937
+ //#region src/swap-vm/instructions/decay/index.ts
1938
+ var decay_exports = {};
1939
+ __export(decay_exports, {
1940
+ DecayXDArgs: () => DecayXDArgs,
1941
+ decayXD: () => decayXD
1942
+ });
1943
+
1944
+ //#endregion
1945
+ //#region src/swap-vm/instructions/limit-swap/limit-swap-direction-args-coder.ts
1946
+ var LimitSwapDirectionArgsCoder = class {
1947
+ encode(args) {
1948
+ const builder = new BytesBuilder();
1949
+ builder.addUint8(args.makerDirectionLt ? 1n : 0n);
1950
+ return new HexString$1(add0x(builder.asHex()));
1951
+ }
1952
+ decode(data) {
1953
+ const iter = BytesIter.BigInt(data.toString());
1954
+ const makerDirectionLt = iter.nextUint8() !== 0n;
1955
+ return new LimitSwapDirectionArgs(makerDirectionLt);
1956
+ }
1957
+ };
1958
+
1959
+ //#endregion
1960
+ //#region src/swap-vm/instructions/limit-swap/limit-swap-direction-args.ts
1961
+ /**
1962
+ * Arguments for limit swap instructions (limitSwap1D, limitSwapOnlyFull1D)
1963
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/LimitSwap.sol#L27
1964
+ **/
1965
+ var LimitSwapDirectionArgs = class LimitSwapDirectionArgs {
1966
+ static CODER = new LimitSwapDirectionArgsCoder();
1967
+ constructor(makerDirectionLt) {
1968
+ this.makerDirectionLt = makerDirectionLt;
1969
+ }
1970
+ static fromTokens(tokenIn, tokenOut) {
1971
+ return new LimitSwapDirectionArgs(BigInt(tokenIn.toString()) < BigInt(tokenOut.toString()));
1972
+ }
1973
+ /**
1974
+ * Decodes hex data into LimitSwapDirectionArgs instance
1975
+ **/
1976
+ static decode(data) {
1977
+ return LimitSwapDirectionArgs.CODER.decode(data);
1978
+ }
1979
+ toJSON() {
1980
+ return { makerDirectionLt: this.makerDirectionLt };
1981
+ }
1982
+ };
1983
+
1984
+ //#endregion
1985
+ //#region src/swap-vm/instructions/limit-swap/opcodes.ts
1986
+ /**
1987
+ * Limit order swap with proportional execution
1988
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/LimitSwap.sol#L27
1989
+ **/
1990
+ const limitSwap1D = new Opcode(Symbol("LimitSwap.limitSwap1D"), LimitSwapDirectionArgs.CODER);
1991
+ /**
1992
+ * Limit order swap requiring full amount execution
1993
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/LimitSwap.sol#L44
1994
+ **/
1995
+ const limitSwapOnlyFull1D = new Opcode(Symbol("LimitSwap.limitSwapOnlyFull1D"), LimitSwapDirectionArgs.CODER);
1996
+
1997
+ //#endregion
1998
+ //#region src/swap-vm/instructions/limit-swap/index.ts
1999
+ var limit_swap_exports = {};
2000
+ __export(limit_swap_exports, {
2001
+ LimitSwapDirectionArgs: () => LimitSwapDirectionArgs,
2002
+ limitSwap1D: () => limitSwap1D,
2003
+ limitSwapOnlyFull1D: () => limitSwapOnlyFull1D
2004
+ });
2005
+
2006
+ //#endregion
2007
+ //#region src/swap-vm/instructions/min-rate/min-rate-args-coder.ts
2008
+ var MinRateArgsCoder = class {
2009
+ encode(args) {
2010
+ const builder = new BytesBuilder();
2011
+ builder.addUint64(args.rateLt);
2012
+ builder.addUint64(args.rateGt);
2013
+ return new HexString$1(add0x(builder.asHex()));
2014
+ }
2015
+ decode(data) {
2016
+ const iter = BytesIter.BigInt(data.toString());
2017
+ const rateLt = iter.nextUint64();
2018
+ const rateGt = iter.nextUint64();
2019
+ return new MinRateArgs(rateLt, rateGt);
2020
+ }
2021
+ };
2022
+
2023
+ //#endregion
2024
+ //#region src/swap-vm/instructions/min-rate/min-rate-args.ts
2025
+ /**
2026
+ * Arguments for min rate instructions (requireMinRate1D, adjustMinRate1D)
2027
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/MinRate.sol#L36
2028
+ **/
2029
+ var MinRateArgs = class MinRateArgs {
2030
+ static CODER = new MinRateArgsCoder();
2031
+ /**
2032
+ * rateLt - minimum acceptable rate for token with lower address (uint64)
2033
+ * rateGt - minimum acceptable rate for token with higher address (uint64)
2034
+ **/
2035
+ constructor(rateLt, rateGt) {
2036
+ this.rateLt = rateLt;
2037
+ 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`);
2040
+ }
2041
+ static fromTokens(tokenA, tokenB, rateA, rateB) {
2042
+ if (BigInt(tokenA.toString()) < BigInt(tokenB.toString())) return new MinRateArgs(rateA, rateB);
2043
+ return new MinRateArgs(rateB, rateA);
2044
+ }
2045
+ /**
2046
+ * Decodes hex data into MinRateArgs instance
2047
+ **/
2048
+ static decode(data) {
2049
+ return MinRateArgs.CODER.decode(data);
2050
+ }
2051
+ toJSON() {
2052
+ return {
2053
+ rateLt: this.rateLt.toString(),
2054
+ rateGt: this.rateGt.toString()
2055
+ };
2056
+ }
2057
+ };
2058
+
2059
+ //#endregion
2060
+ //#region src/swap-vm/instructions/min-rate/opcodes.ts
2061
+ /**
2062
+ * Enforces minimum exchange rate or reverts
2063
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/MinRate.sol#L36
2064
+ **/
2065
+ const requireMinRate1D = new Opcode(Symbol("MinRate.requireMinRate1D"), MinRateArgs.CODER);
2066
+ /**
2067
+ * Adjusts swap amounts to meet minimum rate if needed
2068
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/MinRate.sol#L50
2069
+ **/
2070
+ const adjustMinRate1D = new Opcode(Symbol("MinRate.adjustMinRate1D"), MinRateArgs.CODER);
2071
+
2072
+ //#endregion
2073
+ //#region src/swap-vm/instructions/min-rate/index.ts
2074
+ var min_rate_exports = {};
2075
+ __export(min_rate_exports, {
2076
+ MinRateArgs: () => MinRateArgs,
2077
+ adjustMinRate1D: () => adjustMinRate1D,
2078
+ requireMinRate1D: () => requireMinRate1D
2079
+ });
2080
+
2081
+ //#endregion
2082
+ //#region src/swap-vm/instructions/dutch-auction/dutch-auction-args-coder.ts
2083
+ var DutchAuctionArgsCoder = class {
2084
+ encode(args) {
2085
+ const builder = new BytesBuilder();
2086
+ builder.addUint40(args.startTime);
2087
+ builder.addUint16(args.duration);
2088
+ builder.addUint32(args.decayFactor);
2089
+ return new HexString$1(add0x(builder.asHex()));
2090
+ }
2091
+ decode(data) {
2092
+ const iter = BytesIter.BigInt(data.toString());
2093
+ const startTime = iter.nextUint40();
2094
+ const duration = iter.nextUint16();
2095
+ const decayFactor = iter.nextUint32();
2096
+ return new DutchAuctionArgs(startTime, duration, decayFactor);
2097
+ }
2098
+ };
2099
+
2100
+ //#endregion
2101
+ //#region src/swap-vm/instructions/dutch-auction/dutch-auction-args.ts
2102
+ /**
2103
+ * @notice Dutch Auction instruction for time-based price decay with deadline
2104
+ * @dev Implements an exponential decay auction mechanism that works after any swap:
2105
+ * - Designed to be used after any swap instruction (LimitSwap, XYCSwap, etc.) which sets amounts
2106
+ * - Applies time-based decay to the amounts calculated by the previous swap
2107
+ * - Maker sells token0 and receives token1
2108
+ * - Price improves for taker over time through exponential decay until deadline
2109
+ * - Reverts if current time exceeds deadline
2110
+ * - Only works for 1=>0 swaps (token1 to token0)
2111
+ *
2112
+ * The decay factor determines the price reduction rate:
2113
+ * - 1.0e18 = no decay (constant price)
2114
+ * - 0.999e18 = 0.1% decay per second
2115
+ * - 0.99e18 = 1% decay per second
2116
+ * - 0.9e18 = 10% decay per second
2117
+ *
2118
+ * Example usage:
2119
+ * 1. Any swap instruction sets: 100 token1 → 1000 token0
2120
+ * 2. DutchAuction with decayFactor = 0.99e18, after 100 seconds:
2121
+ * - exactIn: Taker gets ~2.73x more token0 for the same token1
2122
+ * - exactOut: Taker needs only ~36.6% of initial token1
2123
+ * 3. After deadline, the auction expires and cannot be executed
2124
+ *
2125
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/DutchAuction.sol#L66
2126
+ */
2127
+ var DutchAuctionArgs = class DutchAuctionArgs {
2128
+ static CODER = new DutchAuctionArgsCoder();
2129
+ /**
2130
+ * startTime - auction start time (uint40)
2131
+ * duration - auction duration in seconds (uint16)
2132
+ * decayFactor - price decay per second, 1e18 = no decay (uint32)
2133
+ **/
2134
+ constructor(startTime, duration, decayFactor) {
2135
+ this.startTime = startTime;
2136
+ this.duration = duration;
2137
+ 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}`);
2142
+ }
2143
+ /**
2144
+ * Decodes hex data into DutchAuctionArgs instance
2145
+ **/
2146
+ static decode(data) {
2147
+ return DutchAuctionArgs.CODER.decode(data);
2148
+ }
2149
+ toJSON() {
2150
+ return {
2151
+ startTime: this.startTime.toString(),
2152
+ duration: this.duration.toString(),
2153
+ decayFactor: this.decayFactor.toString()
2154
+ };
2155
+ }
2156
+ };
2157
+
2158
+ //#endregion
2159
+ //#region src/swap-vm/instructions/dutch-auction/opcodes.ts
2160
+ /**
2161
+ * Dutch auction with time-based decay on amountIn
2162
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/DutchAuction.sol#L75
2163
+ **/
2164
+ const dutchAuctionBalanceIn1D = new Opcode(Symbol("DutchAuction.dutchAuctionBalanceIn1D"), DutchAuctionArgs.CODER);
2165
+ /**
2166
+ * Dutch auction with time-based decay on amountOut
2167
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/DutchAuction.sol#L85
2168
+ **/
2169
+ const dutchAuctionBalanceOut1D = new Opcode(Symbol("DutchAuction.dutchAuctionBalanceOut1D"), DutchAuctionArgs.CODER);
2170
+
2171
+ //#endregion
2172
+ //#region src/swap-vm/instructions/dutch-auction/index.ts
2173
+ var dutch_auction_exports = {};
2174
+ __export(dutch_auction_exports, {
2175
+ DutchAuctionArgs: () => DutchAuctionArgs,
2176
+ dutchAuctionBalanceIn1D: () => dutchAuctionBalanceIn1D,
2177
+ dutchAuctionBalanceOut1D: () => dutchAuctionBalanceOut1D
2178
+ });
2179
+
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
+ //#endregion
2274
+ //#region src/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args-coder.ts
2275
+ var BaseFeeAdjusterArgsCoder = class {
2276
+ encode(args) {
2277
+ const builder = new BytesBuilder();
2278
+ builder.addUint64(args.baseGasPrice);
2279
+ builder.addUint96(args.ethToToken1Price);
2280
+ builder.addUint24(args.gasAmount);
2281
+ builder.addUint64(args.maxPriceDecay);
2282
+ return new HexString$1(add0x(builder.asHex()));
2283
+ }
2284
+ decode(data) {
2285
+ const iter = BytesIter.BigInt(data.toString());
2286
+ const baseGasPrice = iter.nextUint64();
2287
+ const ethToToken1Price = iter.nextUint96();
2288
+ const gasAmount = iter.nextUint24();
2289
+ const maxPriceDecay = iter.nextUint64();
2290
+ return new BaseFeeAdjusterArgs(baseGasPrice, ethToToken1Price, gasAmount, maxPriceDecay);
2291
+ }
2292
+ };
2293
+
2294
+ //#endregion
2295
+ //#region src/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args.ts
2296
+ /**
2297
+ * @notice Base Fee Gas Price Adjuster instruction for dynamic price adjustment based on network gas costs
2298
+ * @dev Adjusts swap prices based on current gas conditions to compensate for transaction costs:
2299
+ * - Works only for 1=>0 swaps (token1 to token0), compatible with LimitSwap and DutchAuction
2300
+ * - When gas price exceeds base level, maker improves the price to compensate taker for gas costs
2301
+ * - The adjustment is proportional to the difference between current and base gas prices
2302
+ * - Maximum adjustment is limited by maxPriceDecay parameter
2303
+ *
2304
+ * This creates adaptive limit orders that automatically become more attractive during high gas periods,
2305
+ * ensuring execution even when transaction costs are elevated.
2306
+ *
2307
+ * Example usage:
2308
+ * 1. LimitSwap sets base price: 1 ETH for 3000 USDC
2309
+ * 2. BaseFeeAdjuster with baseGasPrice=20 gwei, current=100 gwei
2310
+ * 3. Extra cost = 80 gwei * 150k gas * 3000 USDC/ETH = 36 USDC
2311
+ * 4. With maxPriceDecay=0.99e18 (1% max), final price: 1 ETH for 2970 USDC
2312
+ *
2313
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/BaseFeeAdjuster.sol#L75
2314
+ */
2315
+ var BaseFeeAdjusterArgs = class BaseFeeAdjusterArgs {
2316
+ static CODER = new BaseFeeAdjusterArgsCoder();
2317
+ /**
2318
+ * baseGasPrice - base gas price for comparison (uint64)
2319
+ * ethToToken1Price - ETH price in token1 units, e.g.,
2320
+ * 3000e18 for 1 ETH = 3000 USDC (uint96)
2321
+ * gasAmount - gas amount to compensate for (uint24)
2322
+ **/
2323
+ constructor(baseGasPrice, ethToToken1Price, gasAmount, maxPriceDecay) {
2324
+ this.baseGasPrice = baseGasPrice;
2325
+ this.ethToToken1Price = ethToToken1Price;
2326
+ this.gasAmount = gasAmount;
2327
+ 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`);
2332
+ }
2333
+ /**
2334
+ * Decodes hex data into BaseFeeAdjusterArgs instance
2335
+ **/
2336
+ static decode(data) {
2337
+ return BaseFeeAdjusterArgs.CODER.decode(data);
2338
+ }
2339
+ toJSON() {
2340
+ return {
2341
+ baseGasPrice: this.baseGasPrice.toString(),
2342
+ ethToToken1Price: this.ethToToken1Price.toString(),
2343
+ gasAmount: this.gasAmount.toString(),
2344
+ maxPriceDecay: this.maxPriceDecay.toString()
2345
+ };
2346
+ }
2347
+ };
2348
+
2349
+ //#endregion
2350
+ //#region src/swap-vm/instructions/base-fee-adjuster/opcodes.ts
2351
+ /**
2352
+ * Adjusts swap prices based on network gas costs
2353
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/BaseFeeAdjuster.sol#L75
2354
+ **/
2355
+ const baseFeeAdjuster1D = new Opcode(Symbol("BaseFeeAdjuster.baseFeeAdjuster1D"), BaseFeeAdjusterArgs.CODER);
2356
+
2357
+ //#endregion
2358
+ //#region src/swap-vm/instructions/base-fee-adjuster/index.ts
2359
+ var base_fee_adjuster_exports = {};
2360
+ __export(base_fee_adjuster_exports, {
2361
+ BaseFeeAdjusterArgs: () => BaseFeeAdjusterArgs,
2362
+ baseFeeAdjuster1D: () => baseFeeAdjuster1D
2363
+ });
2364
+
2365
+ //#endregion
2366
+ //#region src/swap-vm/instructions/twap-swap/twap-swap-args-coder.ts
2367
+ var TWAPSwapArgsCoder = class {
2368
+ encode(args) {
2369
+ const builder = new BytesBuilder();
2370
+ builder.addUint256(args.balanceIn);
2371
+ builder.addUint256(args.balanceOut);
2372
+ builder.addUint256(args.startTime);
2373
+ builder.addUint256(args.duration);
2374
+ builder.addUint256(args.priceBumpAfterIlliquidity);
2375
+ builder.addUint256(args.minTradeAmountOut);
2376
+ return new HexString$1(add0x(builder.asHex()));
2377
+ }
2378
+ decode(data) {
2379
+ const iter = BytesIter.BigInt(data.toString());
2380
+ const balanceIn = iter.nextUint256();
2381
+ const balanceOut = iter.nextUint256();
2382
+ const startTime = iter.nextUint256();
2383
+ const duration = iter.nextUint256();
2384
+ const priceBumpAfterIlliquidity = iter.nextUint256();
2385
+ const minTradeAmountOut = iter.nextUint256();
2386
+ return new TWAPSwapArgs(balanceIn, balanceOut, startTime, duration, priceBumpAfterIlliquidity, minTradeAmountOut);
2387
+ }
2388
+ };
2389
+
2390
+ //#endregion
2391
+ //#region src/swap-vm/instructions/twap-swap/twap-swap-args.ts
2392
+ /**
2393
+ * @notice TWAP Hook with exponential dutch auction and illiquidity handling
2394
+ * @dev Implements a TWAP (Time-Weighted Average Price) selling strategy with the following features:
2395
+ * - Linear liquidity unlocking over time
2396
+ * - Exponential price decay (dutch auction) for better price discovery
2397
+ * - Automatic price bump after periods of insufficient liquidity
2398
+ * - Minimum trade size enforcement during TWAP duration
2399
+ *
2400
+ * Minimum Trade Size (minTradeAmountOut):
2401
+ * The minimum trade size protects against gas cost impact on execution price.
2402
+ * It should be set 1000x+ larger than the expected transaction fees on the deployment network.
2403
+ *
2404
+ * For example:
2405
+ * - Ethereum mainnet with $50 gas cost → minTradeAmountOut should be $50,000+
2406
+ * - Arbitrum/Optimism with $0.50 gas cost → minTradeAmountOut should be $500+
2407
+ * - BSC/Polygon with $0.05 gas cost → minTradeAmountOut should be $50+
2408
+ *
2409
+ * This ensures gas costs remain negligible (<0.1%) relative to trade value.
2410
+ *
2411
+ * Price Bump Configuration Guidelines:
2412
+ *
2413
+ * The priceBumpAfterIlliquidity compensates for mandatory waiting periods due to linear unlocking.
2414
+ * Time to unlock minTradeAmountOut = (minTradeAmountOut / balance0) * duration
2415
+ *
2416
+ * Examples:
2417
+ * - minTradeAmountOut = 0.1% of balance0, duration = 24h → 14.4 min to unlock each min trade
2418
+ * Recommended bump: 1.05e18 - 1.10e18 (5-10%)
2419
+ *
2420
+ * - minTradeAmountOut = 1% of balance0, duration = 24h → 14.4 min to unlock each min trade
2421
+ * Recommended bump: 1.10e18 - 1.20e18 (10-20%)
2422
+ *
2423
+ * - minTradeAmountOut = 5% of balance0, duration = 24h → 1.2 hours to unlock each min trade
2424
+ * Recommended bump: 1.30e18 - 1.50e18 (30-50%)
2425
+ *
2426
+ * - minTradeAmountOut = 10% of balance0, duration = 24h → 2.4 hours to unlock each min trade
2427
+ * Recommended bump: 1.50e18 - 2.00e18 (50-100%)
2428
+ *
2429
+ * Additional factors to consider:
2430
+ * - Network gas costs: Higher gas requires larger bumps
2431
+ * - Pair volatility: Volatile pairs need larger bumps to compensate for price risk
2432
+ * - Market depth: Thin markets may need higher bumps to attract arbitrageurs
2433
+ *
2434
+ * The bump should ensure profitability after the mandatory waiting period.
2435
+ *
2436
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/TWAPSwap.sol#L104
2437
+ */
2438
+ var TWAPSwapArgs = class TWAPSwapArgs {
2439
+ static CODER = new TWAPSwapArgsCoder();
2440
+ /**
2441
+ * balanceIn - expected amount of token1 for initial price (uint256)
2442
+ * balanceOut - total amount of token0 for TWAP (uint256)
2443
+ * startTime - TWAP start time (uint256)
2444
+ * duration - TWAP duration (uint256)
2445
+ * priceBumpAfterIlliquidity - price jump when liquidity insufficient, e.g. 1.10e18 = +10% (uint256)
2446
+ * minTradeAmountOut - minimum trade size for token0 (uint256)
2447
+ **/
2448
+ constructor(balanceIn, balanceOut, startTime, duration, priceBumpAfterIlliquidity, minTradeAmountOut) {
2449
+ this.balanceIn = balanceIn;
2450
+ this.balanceOut = balanceOut;
2451
+ this.startTime = startTime;
2452
+ this.duration = duration;
2453
+ this.priceBumpAfterIlliquidity = priceBumpAfterIlliquidity;
2454
+ 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`);
2461
+ }
2462
+ /**
2463
+ * Decodes hex data into TWAPSwapArgs instance
2464
+ **/
2465
+ static decode(data) {
2466
+ return TWAPSwapArgs.CODER.decode(data);
2467
+ }
2468
+ toJSON() {
2469
+ return {
2470
+ balanceIn: this.balanceIn.toString(),
2471
+ balanceOut: this.balanceOut.toString(),
2472
+ startTime: this.startTime.toString(),
2473
+ duration: this.duration.toString(),
2474
+ priceBumpAfterIlliquidity: this.priceBumpAfterIlliquidity.toString(),
2475
+ minTradeAmountOut: this.minTradeAmountOut.toString()
2476
+ };
2477
+ }
2478
+ };
2479
+
2480
+ //#endregion
2481
+ //#region src/swap-vm/instructions/twap-swap/opcodes.ts
2482
+ /**
2483
+ * TWAP trading with exponential dutch auction and illiquidity handling
2484
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/TWAPSwap.sol#L104
2485
+ **/
2486
+ const twap = new Opcode(Symbol("TWAPSwap.twap"), TWAPSwapArgs.CODER);
2487
+
2488
+ //#endregion
2489
+ //#region src/swap-vm/instructions/twap-swap/index.ts
2490
+ var twap_swap_exports = {};
2491
+ __export(twap_swap_exports, {
2492
+ TWAPSwapArgs: () => TWAPSwapArgs,
2493
+ twap: () => twap
2494
+ });
2495
+
2496
+ //#endregion
2497
+ //#region src/swap-vm/instructions/fee/flat-fee-args-coder.ts
2498
+ var FlatFeeArgsCoder = class {
2499
+ encode(args) {
2500
+ const builder = new BytesBuilder();
2501
+ builder.addUint32(args.fee);
2502
+ return new HexString$1(add0x(builder.asHex()));
2503
+ }
2504
+ decode(data) {
2505
+ const iter = BytesIter.BigInt(data.toString());
2506
+ const fee = iter.nextUint32();
2507
+ return new FlatFeeArgs(fee);
2508
+ }
2509
+ };
2510
+
2511
+ //#endregion
2512
+ //#region src/swap-vm/instructions/fee/flat-fee-args.ts
2513
+ const FEE_100_PERCENT$1 = 1e9;
2514
+ /**
2515
+ * Arguments for flat fee instructions (flatFeeXD, flatFeeAmountInXD, flatFeeAmountOutXD, progressiveFeeXD)
2516
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L66
2517
+ **/
2518
+ var FlatFeeArgs = class FlatFeeArgs {
2519
+ static CODER = new FlatFeeArgsCoder();
2520
+ constructor(fee) {
2521
+ 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}`);
2524
+ }
2525
+ /**
2526
+ * Decodes hex data into FlatFeeArgs instance
2527
+ **/
2528
+ static decode(data) {
2529
+ return FlatFeeArgs.CODER.decode(data);
2530
+ }
2531
+ /**
2532
+ * Creates a FlatFeeArgs instance from percentage
2533
+ * @param percent - Fee as percentage (e.g., 1 for 1%, 0.1 for 0.1%)
2534
+ * @returns FlatFeeArgs instance
2535
+ */
2536
+ static fromPercent(percent) {
2537
+ return FlatFeeArgs.fromBps(percent * 100);
2538
+ }
2539
+ /**
2540
+ * Creates a FlatFeeArgs instance from basis points
2541
+ * @param bps - Fee in basis points (10000 bps = 100%)
2542
+ * @returns FlatFeeArgs instance
2543
+ */
2544
+ static fromBps(bps) {
2545
+ const fee = BigInt(bps * 1e5);
2546
+ return new FlatFeeArgs(fee);
2547
+ }
2548
+ toJSON() {
2549
+ return { fee: this.fee.toString() };
2550
+ }
2551
+ };
2552
+
2553
+ //#endregion
2554
+ //#region src/swap-vm/instructions/fee/protocol-fee-args-coder.ts
2555
+ var ProtocolFeeArgsCoder = class {
2556
+ encode(args) {
2557
+ const builder = new BytesBuilder();
2558
+ builder.addUint32(args.fee);
2559
+ builder.addAddress(args.to.toString());
2560
+ return new HexString$1(builder.asHex());
2561
+ }
2562
+ decode(data) {
2563
+ const iter = BytesIter.HexString(data.toString());
2564
+ const fee = iter.nextUint32();
2565
+ const to = new Address$1(iter.nextAddress());
2566
+ return new ProtocolFeeArgs(BigInt(fee), to);
2567
+ }
2568
+ };
2569
+
2570
+ //#endregion
2571
+ //#region src/swap-vm/instructions/fee/protocol-fee-args.ts
2572
+ const FEE_100_PERCENT = 1e9;
2573
+ /**
2574
+ * Arguments for protocol fee instructions (protocolFeeAmountOutXD, aquaProtocolFeeAmountOutXD)
2575
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L102
2576
+ **/
2577
+ var ProtocolFeeArgs = class ProtocolFeeArgs {
2578
+ static CODER = new ProtocolFeeArgsCoder();
2579
+ /**
2580
+ * fee - 1e9 = 100% (uint32)
2581
+ * to - address to send pulled tokens to (20 bytes)
2582
+ **/
2583
+ constructor(fee, to) {
2584
+ this.fee = fee;
2585
+ 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}`);
2588
+ }
2589
+ /**
2590
+ * Decodes hex data into ProtocolFeeArgs instance
2591
+ **/
2592
+ static decode(data) {
2593
+ return ProtocolFeeArgs.CODER.decode(data);
2594
+ }
2595
+ /**
2596
+ * Creates a ProtocolFeeArgs instance from percentage
2597
+ * @param percent - Fee as percentage (e.g., 1 for 1%, 0.1 for 0.1%)
2598
+ * @param to - Address to receive the protocol fee
2599
+ * @returns ProtocolFeeArgs instance
2600
+ */
2601
+ static fromPercent(percent, to) {
2602
+ return ProtocolFeeArgs.fromBps(percent * 100, to);
2603
+ }
2604
+ /**
2605
+ * Creates a ProtocolFeeArgs instance from basis points
2606
+ * @param bps - Fee in basis points (10000 bps = 100%)
2607
+ * @param to - Address to receive the protocol fee
2608
+ * @returns ProtocolFeeArgs instance
2609
+ */
2610
+ static fromBps(bps, to) {
2611
+ const fee = BigInt(bps * 1e5);
2612
+ return new ProtocolFeeArgs(fee, to);
2613
+ }
2614
+ toJSON() {
2615
+ return {
2616
+ fee: this.fee.toString(),
2617
+ to: this.to.toString()
2618
+ };
2619
+ }
2620
+ };
2621
+
2622
+ //#endregion
2623
+ //#region src/swap-vm/instructions/fee/opcodes.ts
2624
+ /**
2625
+ * Applies fee to amountIn
2626
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L66
2627
+ **/
2628
+ const flatFeeAmountInXD = new Opcode(Symbol("Fee.flatFeeAmountInXD"), FlatFeeArgs.CODER);
2629
+ /**
2630
+ * Applies fee to amountOut
2631
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L72
2632
+ **/
2633
+ const flatFeeAmountOutXD = new Opcode(Symbol("Fee.flatFeeAmountOutXD"), FlatFeeArgs.CODER);
2634
+ /**
2635
+ * Applies progressive fee to amountIn
2636
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L78
2637
+ **/
2638
+ const progressiveFeeInXD = new Opcode(Symbol("Fee.progressiveFeeInXD"), FlatFeeArgs.CODER);
2639
+ /**
2640
+ * Applies progressive fee to amountOut
2641
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L106
2642
+ **/
2643
+ const progressiveFeeOutXD = new Opcode(Symbol("Fee.progressiveFeeOutXD"), FlatFeeArgs.CODER);
2644
+ /**
2645
+ * Applies protocol fee to amountOut with direct transfer
2646
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L102
2647
+ **/
2648
+ const protocolFeeAmountOutXD = new Opcode(Symbol("Fee.protocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
2649
+ /**
2650
+ * Applies protocol fee to amountOut through Aqua protocol
2651
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L110
2652
+ **/
2653
+ const aquaProtocolFeeAmountOutXD = new Opcode(Symbol("Fee.aquaProtocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
2654
+
2655
+ //#endregion
2656
+ //#region src/swap-vm/instructions/fee/index.ts
2657
+ var fee_exports = {};
2658
+ __export(fee_exports, {
2659
+ FlatFeeArgs: () => FlatFeeArgs,
2660
+ ProtocolFeeArgs: () => ProtocolFeeArgs,
2661
+ aquaProtocolFeeAmountOutXD: () => aquaProtocolFeeAmountOutXD,
2662
+ flatFeeAmountInXD: () => flatFeeAmountInXD,
2663
+ flatFeeAmountOutXD: () => flatFeeAmountOutXD,
2664
+ progressiveFeeInXD: () => progressiveFeeInXD,
2665
+ progressiveFeeOutXD: () => progressiveFeeOutXD,
2666
+ protocolFeeAmountOutXD: () => protocolFeeAmountOutXD
2667
+ });
2668
+
2669
+ //#endregion
2670
+ //#region src/swap-vm/instructions/extruction/extruction-args-coder.ts
2671
+ var ExtructionArgsCoder = class {
2672
+ encode(args) {
2673
+ const builder = new BytesBuilder();
2674
+ builder.addAddress(args.target.toString());
2675
+ builder.addBytes(args.extructionArgs.toString());
2676
+ return new HexString$1(builder.asHex());
2677
+ }
2678
+ decode(data) {
2679
+ const iter = BytesIter.HexString(data.toString());
2680
+ const target = new Address$1(iter.nextAddress());
2681
+ const extructionArgs = new HexString$1(iter.rest());
2682
+ return new ExtructionArgs(target, extructionArgs);
2683
+ }
2684
+ };
2685
+
2686
+ //#endregion
2687
+ //#region src/swap-vm/instructions/extruction/extruction-args.ts
2688
+ /**
2689
+ * Arguments for extruction instruction to call external contract logic
2690
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Extruction.sol#L33
2691
+ **/
2692
+ var ExtructionArgs = class ExtructionArgs {
2693
+ static CODER = new ExtructionArgsCoder();
2694
+ /**
2695
+ * target - External contract address (20 bytes)
2696
+ * extructionArgs - Arguments to pass to external contract (variable)
2697
+ **/
2698
+ constructor(target, extructionArgs) {
2699
+ this.target = target;
2700
+ this.extructionArgs = extructionArgs;
2701
+ }
2702
+ /**
2703
+ * Decodes hex data into ExtructionArgs instance
2704
+ **/
2705
+ static decode(data) {
2706
+ return ExtructionArgs.CODER.decode(data);
2707
+ }
2708
+ toJSON() {
2709
+ return {
2710
+ target: this.target.toString(),
2711
+ extructionArgs: this.extructionArgs.toString()
2712
+ };
2713
+ }
2714
+ };
2715
+
2716
+ //#endregion
2717
+ //#region src/swap-vm/instructions/extruction/opcodes.ts
2718
+ /**
2719
+ * Calls external contract to perform custom logic, potentially modifying swap state
2720
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Extruction.sol#L33
2721
+ **/
2722
+ const extruction = new Opcode(Symbol("Extruction.extruction"), ExtructionArgs.CODER);
2723
+
2724
+ //#endregion
2725
+ //#region src/swap-vm/instructions/extruction/index.ts
2726
+ var extruction_exports = {};
2727
+ __export(extruction_exports, {
2728
+ ExtructionArgs: () => ExtructionArgs,
2729
+ extruction: () => extruction
2730
+ });
2731
+
2732
+ //#endregion
2733
+ //#region src/swap-vm/instructions/stable-swap/stable-swap-2d-args-coder.ts
2734
+ var StableSwap2DArgsCoder = class {
2735
+ encode(args) {
2736
+ const builder = new BytesBuilder();
2737
+ builder.addUint32(args.fee);
2738
+ builder.addUint32(args.A);
2739
+ builder.addUint256(args.rateLt);
2740
+ builder.addUint256(args.rateGt);
2741
+ return new HexString$1(add0x(builder.asHex()));
2742
+ }
2743
+ decode(data) {
2744
+ 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);
2750
+ }
2751
+ };
2752
+
2753
+ //#endregion
2754
+ //#region src/swap-vm/instructions/stable-swap/stable-swap-2d-args.ts
2755
+ /**
2756
+ * Arguments for stableSwap2D instruction for stablecoin optimized swaps
2757
+ **/
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;
2769
+ this.rateLt = rateLt;
2770
+ 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`);
2775
+ }
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);
2779
+ }
2780
+ /**
2781
+ * Decodes hex data into StableSwap2DArgs instance
2782
+ **/
2783
+ static decode(data) {
2784
+ return StableSwap2DArgs.CODER.decode(data);
2785
+ }
2786
+ toJSON() {
2787
+ return {
2788
+ fee: this.fee.toString(),
2789
+ A: this.A.toString(),
2790
+ rateLt: this.rateLt.toString(),
2791
+ rateGt: this.rateGt.toString()
2792
+ };
2793
+ }
2794
+ };
2795
+
2796
+ //#endregion
2797
+ //#region src/swap-vm/instructions/stable-swap/opcodes.ts
2798
+ /**
2799
+ * Stablecoin optimized swap using StableSwap algorithm (Curve-style)
2800
+ **/
2801
+ const stableSwap2D = new Opcode(Symbol("StableSwap.stableSwap2D"), StableSwap2DArgs.CODER);
2802
+
2803
+ //#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
2809
+ });
2810
+
2811
+ //#endregion
2812
+ //#region src/swap-vm/instructions/index.ts
2813
+ var instructions_exports = {};
2814
+ __export(instructions_exports, {
2815
+ EMPTY_OPCODE: () => EMPTY_OPCODE,
2816
+ _allInstructions: () => _allInstructions,
2817
+ aquaInstructions: () => aquaInstructions,
2818
+ balances: () => balances_exports,
2819
+ baseFeeAdjuster: () => base_fee_adjuster_exports,
2820
+ concentrate: () => concentrate_exports,
2821
+ controls: () => controls_exports,
2822
+ decay: () => decay_exports,
2823
+ dutchAuction: () => dutch_auction_exports,
2824
+ extruction: () => extruction_exports,
2825
+ fee: () => fee_exports,
2826
+ invalidators: () => invalidators_exports,
2827
+ limitSwap: () => limit_swap_exports,
2828
+ minRate: () => min_rate_exports,
2829
+ oraclePriceAdjuster: () => oracle_price_adjuster_exports,
2830
+ stableSwap: () => stable_swap_exports,
2831
+ twapSwap: () => twap_swap_exports,
2832
+ xycSwap: () => xyc_swap_exports
2833
+ });
2834
+ /**
2835
+ * Regular opcodes array - matching SwapVM contract exactly (44 opcodes)
2836
+ * @see https://github.com/1inch/swap-vm/blob/main/src/opcodes/Opcodes.sol#L46
2837
+ */
2838
+ const _allInstructions = [
2839
+ EMPTY_OPCODE,
2840
+ EMPTY_OPCODE,
2841
+ EMPTY_OPCODE,
2842
+ EMPTY_OPCODE,
2843
+ EMPTY_OPCODE,
2844
+ EMPTY_OPCODE,
2845
+ EMPTY_OPCODE,
2846
+ EMPTY_OPCODE,
2847
+ EMPTY_OPCODE,
2848
+ EMPTY_OPCODE,
2849
+ jump,
2850
+ jumpIfTokenIn,
2851
+ jumpIfTokenOut,
2852
+ deadline,
2853
+ onlyTakerTokenBalanceNonZero,
2854
+ onlyTakerTokenBalanceGte,
2855
+ onlyTakerTokenSupplyShareGte,
2856
+ staticBalancesXD,
2857
+ dynamicBalancesXD,
2858
+ invalidateBit1D,
2859
+ invalidateTokenIn1D,
2860
+ invalidateTokenOut1D,
2861
+ xycSwapXD,
2862
+ concentrateGrowLiquidityXD,
2863
+ concentrateGrowLiquidity2D,
2864
+ decayXD,
2865
+ limitSwap1D,
2866
+ limitSwapOnlyFull1D,
2867
+ requireMinRate1D,
2868
+ adjustMinRate1D,
2869
+ dutchAuctionBalanceIn1D,
2870
+ dutchAuctionBalanceOut1D,
2871
+ oraclePriceAdjuster1D,
2872
+ baseFeeAdjuster1D,
2873
+ twap,
2874
+ extruction,
2875
+ salt,
2876
+ flatFeeAmountInXD,
2877
+ flatFeeAmountOutXD,
2878
+ progressiveFeeInXD,
2879
+ progressiveFeeOutXD,
2880
+ protocolFeeAmountOutXD,
2881
+ aquaProtocolFeeAmountOutXD
2882
+ ];
2883
+ /**
2884
+ * Aqua opcodes array - matching AquaSwapVM contract (29 opcodes)
2885
+ * @see https://github.com/1inch/swap-vm/blob/main/src/opcodes/AquaOpcodes.sol#L28
2886
+ */
2887
+ const aquaInstructions = [
2888
+ EMPTY_OPCODE,
2889
+ EMPTY_OPCODE,
2890
+ EMPTY_OPCODE,
2891
+ EMPTY_OPCODE,
2892
+ EMPTY_OPCODE,
2893
+ EMPTY_OPCODE,
2894
+ EMPTY_OPCODE,
2895
+ EMPTY_OPCODE,
2896
+ EMPTY_OPCODE,
2897
+ EMPTY_OPCODE,
2898
+ jump,
2899
+ jumpIfTokenIn,
2900
+ jumpIfTokenOut,
2901
+ deadline,
2902
+ onlyTakerTokenBalanceNonZero,
2903
+ onlyTakerTokenBalanceGte,
2904
+ onlyTakerTokenSupplyShareGte,
2905
+ xycSwapXD,
2906
+ concentrateGrowLiquidityXD,
2907
+ concentrateGrowLiquidity2D,
2908
+ decayXD,
2909
+ salt,
2910
+ flatFeeAmountInXD,
2911
+ flatFeeAmountOutXD,
2912
+ progressiveFeeInXD,
2913
+ progressiveFeeOutXD,
2914
+ protocolFeeAmountOutXD,
2915
+ aquaProtocolFeeAmountOutXD
2916
+ ];
2917
+
2918
+ //#endregion
2919
+ //#region src/swap-vm/instructions/debug/debug-empty-args.ts
2920
+ var DebugEmptyArgsCoder = class {
2921
+ encode(_args) {
2922
+ return HexString$1.EMPTY;
2923
+ }
2924
+ decode(_data) {
2925
+ return new DebugEmptyArgs();
2926
+ }
2927
+ };
2928
+ /**
2929
+ * Debug empty instruction arguments - used for debugging purposes
2930
+ * @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Debug.sol
2931
+ **/
2932
+ var DebugEmptyArgs = class DebugEmptyArgs {
2933
+ static CODER = new DebugEmptyArgsCoder();
2934
+ /**
2935
+ * Decodes hex data into DebugEmptyArgs instance
2936
+ **/
2937
+ static decode(_data) {
2938
+ return DebugEmptyArgs.CODER.decode(_data);
2939
+ }
2940
+ toJSON() {
2941
+ return null;
2942
+ }
2943
+ };
2944
+
2945
+ //#endregion
2946
+ //#region src/swap-vm/instructions/debug/debug-args.ts
2947
+ /**
2948
+ * Base class for all debug instruction arguments
2949
+ * Debug instructions don't have parameters, they just print/log state
2950
+ */
2951
+ var DebugArgs = class {
2952
+ toJSON() {
2953
+ return null;
2954
+ }
2955
+ };
2956
+
2957
+ //#endregion
2958
+ //#region src/swap-vm/instructions/debug/print-swap-registers.ts
2959
+ var PrintSwapRegistersArgsCoder = class {
2960
+ encode(_args) {
2961
+ return HexString$1.EMPTY;
2962
+ }
2963
+ decode(_data) {
2964
+ return new PrintSwapRegistersArgs();
2965
+ }
2966
+ };
2967
+ /**
2968
+ * Debug instruction to print swap registers
2969
+ * @see Debug._printSwapRegisters in Solidity
2970
+ */
2971
+ var PrintSwapRegistersArgs = class PrintSwapRegistersArgs extends DebugArgs {
2972
+ static CODER = new PrintSwapRegistersArgsCoder();
2973
+ static decode(_data) {
2974
+ return PrintSwapRegistersArgs.CODER.decode(_data);
2975
+ }
2976
+ };
2977
+
2978
+ //#endregion
2979
+ //#region src/swap-vm/instructions/debug/print-swap-query.ts
2980
+ var PrintSwapQueryArgsCoder = class {
2981
+ encode(_args) {
2982
+ return HexString$1.EMPTY;
2983
+ }
2984
+ decode(_data) {
2985
+ return new PrintSwapQueryArgs();
2986
+ }
2987
+ };
2988
+ /**
2989
+ * Debug instruction to print swap query information
2990
+ * @see Debug._printSwapQuery in Solidity
2991
+ */
2992
+ var PrintSwapQueryArgs = class PrintSwapQueryArgs extends DebugArgs {
2993
+ static CODER = new PrintSwapQueryArgsCoder();
2994
+ static decode(_data) {
2995
+ return PrintSwapQueryArgs.CODER.decode(_data);
2996
+ }
2997
+ };
2998
+
2999
+ //#endregion
3000
+ //#region src/swap-vm/instructions/debug/print-context.ts
3001
+ var PrintContextArgsCoder = class {
3002
+ encode(_args) {
3003
+ return HexString$1.EMPTY;
3004
+ }
3005
+ decode(_data) {
3006
+ return new PrintContextArgs();
3007
+ }
3008
+ };
3009
+ /**
3010
+ * Debug instruction to print execution context
3011
+ * @see Debug._printContext in Solidity
3012
+ */
3013
+ var PrintContextArgs = class PrintContextArgs extends DebugArgs {
3014
+ static CODER = new PrintContextArgsCoder();
3015
+ static decode(_data) {
3016
+ return PrintContextArgs.CODER.decode(_data);
3017
+ }
3018
+ };
3019
+
3020
+ //#endregion
3021
+ //#region src/swap-vm/instructions/debug/print-amount-for-swap.ts
3022
+ var PrintAmountForSwapArgsCoder = class {
3023
+ encode(_args) {
3024
+ return HexString$1.EMPTY;
3025
+ }
3026
+ decode(_data) {
3027
+ return new PrintAmountForSwapArgs();
3028
+ }
3029
+ };
3030
+ /**
3031
+ * Debug instruction to print amount for swap
3032
+ * @see Debug._printAmountForSwap in Solidity
3033
+ */
3034
+ var PrintAmountForSwapArgs = class PrintAmountForSwapArgs extends DebugArgs {
3035
+ static CODER = new PrintAmountForSwapArgsCoder();
3036
+ static decode(_data) {
3037
+ return PrintAmountForSwapArgs.CODER.decode(_data);
3038
+ }
3039
+ };
3040
+
3041
+ //#endregion
3042
+ //#region src/swap-vm/instructions/debug/print-free-memory-pointer.ts
3043
+ var PrintFreeMemoryPointerArgsCoder = class {
3044
+ encode(_args) {
3045
+ return HexString$1.EMPTY;
3046
+ }
3047
+ decode(_data) {
3048
+ return new PrintFreeMemoryPointerArgs();
3049
+ }
3050
+ };
3051
+ /**
3052
+ * Debug instruction to print free memory pointer
3053
+ * @see Debug._printFreeMemoryPointer in Solidity
3054
+ */
3055
+ var PrintFreeMemoryPointerArgs = class PrintFreeMemoryPointerArgs extends DebugArgs {
3056
+ static CODER = new PrintFreeMemoryPointerArgsCoder();
3057
+ static decode(_data) {
3058
+ return PrintFreeMemoryPointerArgs.CODER.decode(_data);
3059
+ }
3060
+ };
3061
+
3062
+ //#endregion
3063
+ //#region src/swap-vm/instructions/debug/print-gas-left.ts
3064
+ var PrintGasLeftArgsCoder = class {
3065
+ encode(_args) {
3066
+ return HexString$1.EMPTY;
3067
+ }
3068
+ decode(_data) {
3069
+ return new PrintGasLeftArgs();
3070
+ }
3071
+ };
3072
+ /**
3073
+ * Debug instruction to print remaining gas
3074
+ * @see Debug._printGasLeft in Solidity
3075
+ */
3076
+ var PrintGasLeftArgs = class PrintGasLeftArgs extends DebugArgs {
3077
+ static CODER = new PrintGasLeftArgsCoder();
3078
+ static decode(_data) {
3079
+ return PrintGasLeftArgs.CODER.decode(_data);
3080
+ }
3081
+ };
3082
+
3083
+ //#endregion
3084
+ //#region src/swap-vm/instructions/debug/opcodes.ts
3085
+ /**
3086
+ * Debug empty opcode - placeholder
3087
+ */
3088
+ const debugEmpty = new Opcode(Symbol("Debug.Empty"), DebugEmptyArgs.CODER);
3089
+ const printSwapRegisters = new Opcode(Symbol("Debug.printSwapRegisters"), PrintSwapRegistersArgs.CODER);
3090
+ const printSwapQuery = new Opcode(Symbol("Debug.printSwapQuery"), PrintSwapQueryArgs.CODER);
3091
+ const printContext = new Opcode(Symbol("Debug.printContext"), PrintContextArgs.CODER);
3092
+ const printAmountForSwap = new Opcode(Symbol("debug.printAmountForSwap"), PrintAmountForSwapArgs.CODER);
3093
+ const printFreeMemoryPointer = new Opcode(Symbol("Debug.printFreeMemoryPointer"), PrintFreeMemoryPointerArgs.CODER);
3094
+ const printGasLeft = new Opcode(Symbol("Debug.printGasLeft"), PrintGasLeftArgs.CODER);
3095
+
3096
+ //#endregion
3097
+ //#region src/swap-vm/programs/regular-program-builder.ts
3098
+ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
3099
+ constructor() {
3100
+ super([..._allInstructions]);
3101
+ }
3102
+ static decode(program) {
3103
+ return new RegularProgramBuilder().decode(program);
3104
+ }
3105
+ /**
3106
+ * Enables debug mode for the program
3107
+ * WARNING: Debug instructions will throw an error if debug mode is not enabled
3108
+ */
3109
+ withDebug() {
3110
+ this.ixsSet[0] = printSwapRegisters;
3111
+ this.ixsSet[1] = printSwapQuery;
3112
+ this.ixsSet[2] = printContext;
3113
+ this.ixsSet[3] = printAmountForSwap;
3114
+ this.ixsSet[4] = printFreeMemoryPointer;
3115
+ this.ixsSet[5] = printGasLeft;
3116
+ return this;
3117
+ }
3118
+ /**
3119
+ * Sets initial token balances for the swap program
3120
+ **/
3121
+ staticBalancesXD(data) {
3122
+ super.add(staticBalancesXD.createIx(new BalancesArgs(data.tokenBalances)));
3123
+ return this;
3124
+ }
3125
+ /**
3126
+ * Reads token balances from program data or contract storage
3127
+ **/
3128
+ dynamicBalancesXD(data) {
3129
+ super.add(dynamicBalancesXD.createIx(new BalancesArgs(data.tokenBalances)));
3130
+ return this;
3131
+ }
3132
+ /**
3133
+ * Unconditional jump to specified program counter
3134
+ **/
3135
+ jump(data) {
3136
+ super.add(jump.createIx(new JumpArgs(data.nextPC)));
3137
+ return this;
3138
+ }
3139
+ /**
3140
+ * Jumps if tokenIn is the specified token
3141
+ **/
3142
+ jumpIfTokenIn(data) {
3143
+ super.add(jumpIfTokenIn.createIx(new JumpIfTokenArgs(data.tokenTail, data.nextPC)));
3144
+ return this;
3145
+ }
3146
+ /**
3147
+ * Jumps if tokenOut is the specified token
3148
+ **/
3149
+ jumpIfTokenOut(data) {
3150
+ super.add(jumpIfTokenOut.createIx(new JumpIfTokenArgs(data.tokenTail, data.nextPC)));
3151
+ return this;
3152
+ }
3153
+ /**
3154
+ * Reverts if the deadline has been reached
3155
+ **/
3156
+ deadline(data) {
3157
+ super.add(deadline.createIx(new DeadlineArgs(data.deadline)));
3158
+ return this;
3159
+ }
3160
+ /**
3161
+ * Requires taker to hold any amount of specified token (supports NFTs)
3162
+ **/
3163
+ onlyTakerTokenBalanceNonZero(data) {
3164
+ super.add(onlyTakerTokenBalanceNonZero.createIx(new OnlyTakerTokenBalanceNonZeroArgs(data.token)));
3165
+ return this;
3166
+ }
3167
+ /**
3168
+ * Requires taker to hold at least specified amount of token
3169
+ **/
3170
+ onlyTakerTokenBalanceGte(data) {
3171
+ super.add(onlyTakerTokenBalanceGte.createIx(new OnlyTakerTokenBalanceGteArgs(data.token, data.minAmount)));
3172
+ return this;
3173
+ }
3174
+ /**
3175
+ * Requires taker to hold at least specified share of token's total supply
3176
+ **/
3177
+ onlyTakerTokenSupplyShareGte(data) {
3178
+ super.add(onlyTakerTokenSupplyShareGte.createIx(new OnlyTakerTokenSupplyShareGteArgs(data.token, data.minShareE18)));
3179
+ return this;
3180
+ }
3181
+ /**
3182
+ * No-op instruction used to add uniqueness to order hashes (prevents replay attacks)
3183
+ **/
3184
+ salt(data) {
3185
+ super.add(salt.createIx(new SaltArgs(data.salt)));
3186
+ return this;
3187
+ }
3188
+ /**
3189
+ * Invalidates a specific bit index for order uniqueness
3190
+ **/
3191
+ invalidateBit1D(data) {
3192
+ super.add(invalidateBit1D.createIx(new InvalidateBit1DArgs(data.bitIndex)));
3193
+ return this;
3194
+ }
3195
+ /**
3196
+ * Invalidates order by token input to prevent re-use
3197
+ **/
3198
+ invalidateTokenIn1D() {
3199
+ super.add(invalidateTokenIn1D.createIx(new InvalidateTokenIn1DArgs()));
3200
+ return this;
3201
+ }
3202
+ /**
3203
+ * Invalidates order by token output to prevent re-use
3204
+ **/
3205
+ invalidateTokenOut1D() {
3206
+ super.add(invalidateTokenOut1D.createIx(new InvalidateTokenOut1DArgs()));
3207
+ return this;
3208
+ }
3209
+ /**
3210
+ * Basic swap using constant product formula (x*y=k)
3211
+ **/
3212
+ xycSwapXD() {
3213
+ super.add(xycSwapXD.createIx(new XycSwapXDArgs()));
3214
+ return this;
3215
+ }
3216
+ /**
3217
+ * Concentrates liquidity within price bounds for multiple tokens
3218
+ **/
3219
+ concentrateGrowLiquidityXD(data) {
3220
+ super.add(concentrateGrowLiquidityXD.createIx(new ConcentrateGrowLiquidityXDArgs(data.tokenDeltas)));
3221
+ return this;
3222
+ }
3223
+ /**
3224
+ * Concentrates liquidity within price bounds for two tokens
3225
+ **/
3226
+ concentrateGrowLiquidity2D(data) {
3227
+ super.add(concentrateGrowLiquidity2D.createIx(new ConcentrateGrowLiquidity2DArgs(data.deltaLt, data.deltaGt)));
3228
+ return this;
3229
+ }
3230
+ /**
3231
+ * Applies time-based decay to balance adjustments
3232
+ **/
3233
+ decayXD(data) {
3234
+ super.add(decayXD.createIx(new DecayXDArgs(data.decayPeriod)));
3235
+ return this;
3236
+ }
3237
+ /**
3238
+ * Limit order swap with proportional execution
3239
+ **/
3240
+ limitSwap1D(data) {
3241
+ super.add(limitSwap1D.createIx(new LimitSwapDirectionArgs(data.makerDirectionLt)));
3242
+ return this;
3243
+ }
3244
+ /**
3245
+ * Limit order swap requiring full amount execution
3246
+ **/
3247
+ limitSwapOnlyFull1D(data) {
3248
+ super.add(limitSwapOnlyFull1D.createIx(new LimitSwapDirectionArgs(data.makerDirectionLt)));
3249
+ return this;
3250
+ }
3251
+ /**
3252
+ * Enforces minimum exchange rate or reverts
3253
+ **/
3254
+ requireMinRate1D(data) {
3255
+ super.add(requireMinRate1D.createIx(new MinRateArgs(data.rateLt, data.rateGt)));
3256
+ return this;
3257
+ }
3258
+ /**
3259
+ * Adjusts swap amounts to meet minimum rate if needed
3260
+ **/
3261
+ adjustMinRate1D(data) {
3262
+ super.add(adjustMinRate1D.createIx(new MinRateArgs(data.rateLt, data.rateGt)));
3263
+ return this;
3264
+ }
3265
+ /**
3266
+ * Dutch auction with time-based decay on amountIn
3267
+ **/
3268
+ dutchAuctionBalanceIn1D(data) {
3269
+ super.add(dutchAuctionBalanceIn1D.createIx(new DutchAuctionArgs(data.startTime, data.duration, data.decayFactor)));
3270
+ return this;
3271
+ }
3272
+ /**
3273
+ * Dutch auction with time-based decay on amountOut
3274
+ **/
3275
+ dutchAuctionBalanceOut1D(data) {
3276
+ super.add(dutchAuctionBalanceOut1D.createIx(new DutchAuctionArgs(data.startTime, data.duration, data.decayFactor)));
3277
+ return this;
3278
+ }
3279
+ /**
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
+ * Adjusts swap prices based on network gas costs
3288
+ **/
3289
+ baseFeeAdjuster1D(data) {
3290
+ super.add(baseFeeAdjuster1D.createIx(new BaseFeeAdjusterArgs(data.baseGasPrice, data.ethToToken1Price, data.gasAmount, data.maxPriceDecay)));
3291
+ return this;
3292
+ }
3293
+ /**
3294
+ * TWAP trading with exponential dutch auction and illiquidity handling
3295
+ **/
3296
+ twap(data) {
3297
+ super.add(twap.createIx(new TWAPSwapArgs(data.balanceIn, data.balanceOut, data.startTime, data.duration, data.priceBumpAfterIlliquidity, data.minTradeAmountOut)));
3298
+ return this;
3299
+ }
3300
+ /**
3301
+ * Calls external contract to perform custom logic
3302
+ **/
3303
+ extruction(data) {
3304
+ super.add(extruction.createIx(new ExtructionArgs(data.target, data.extructionArgs)));
3305
+ return this;
3306
+ }
3307
+ /**
3308
+ * Applies fee to amountIn
3309
+ **/
3310
+ flatFeeAmountInXD(data) {
3311
+ super.add(flatFeeAmountInXD.createIx(new FlatFeeArgs(data.fee)));
3312
+ return this;
3313
+ }
3314
+ /**
3315
+ * Applies fee to amountOut
3316
+ **/
3317
+ flatFeeAmountOutXD(data) {
3318
+ super.add(flatFeeAmountOutXD.createIx(new FlatFeeArgs(data.fee)));
3319
+ return this;
3320
+ }
3321
+ /**
3322
+ * Applies progressive fee to amountIn
3323
+ **/
3324
+ progressiveFeeInXD(data) {
3325
+ super.add(progressiveFeeInXD.createIx(new FlatFeeArgs(data.fee)));
3326
+ return this;
3327
+ }
3328
+ /**
3329
+ * Applies progressive fee to amountOut
3330
+ **/
3331
+ progressiveFeeOutXD(data) {
3332
+ super.add(progressiveFeeOutXD.createIx(new FlatFeeArgs(data.fee)));
3333
+ return this;
3334
+ }
3335
+ /**
3336
+ * Applies protocol fee to amountOut with direct transfer
3337
+ **/
3338
+ protocolFeeAmountOutXD(data) {
3339
+ super.add(protocolFeeAmountOutXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
3340
+ return this;
3341
+ }
3342
+ /**
3343
+ * Applies protocol fee to amountOut through Aqua protocol
3344
+ **/
3345
+ aquaProtocolFeeAmountOutXD(data) {
3346
+ super.add(aquaProtocolFeeAmountOutXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
3347
+ return this;
3348
+ }
3349
+ /**
3350
+ * DEBUG: Prints current swap registers (amounts and tokens)
3351
+ * WARNING: Requires withDebug() to be called first, otherwise will throw an error
3352
+ */
3353
+ debugPrintSwapRegisters() {
3354
+ super.add(printSwapRegisters.createIx(new PrintSwapRegistersArgs()));
3355
+ return this;
3356
+ }
3357
+ /**
3358
+ * DEBUG: Prints current swap query state
3359
+ * WARNING: Requires withDebug() to be called first, otherwise will throw an error
3360
+ */
3361
+ debugPrintSwapQuery() {
3362
+ super.add(printSwapQuery.createIx(new PrintSwapQueryArgs()));
3363
+ return this;
3364
+ }
3365
+ /**
3366
+ * DEBUG: Prints execution context information
3367
+ * WARNING: Requires withDebug() to be called first, otherwise will throw an error
3368
+ */
3369
+ debugPrintContext() {
3370
+ super.add(printContext.createIx(new PrintContextArgs()));
3371
+ return this;
3372
+ }
3373
+ /**
3374
+ * DEBUG: Prints calculated amount for swap
3375
+ * WARNING: Requires withDebug() to be called first, otherwise will throw an error
3376
+ */
3377
+ debugPrintAmountForSwap() {
3378
+ super.add(printAmountForSwap.createIx(new PrintAmountForSwapArgs()));
3379
+ return this;
3380
+ }
3381
+ /**
3382
+ * DEBUG: Prints current free memory pointer value
3383
+ * WARNING: Requires withDebug() to be called first, otherwise will throw an error
3384
+ */
3385
+ debugPrintFreeMemoryPointer() {
3386
+ super.add(printFreeMemoryPointer.createIx(new PrintFreeMemoryPointerArgs()));
3387
+ return this;
3388
+ }
3389
+ /**
3390
+ * DEBUG: Prints remaining gas
3391
+ * WARNING: Requires withDebug() to be called first, otherwise will throw an error
3392
+ */
3393
+ debugPrintGasLeft() {
3394
+ super.add(printGasLeft.createIx(new PrintGasLeftArgs()));
3395
+ return this;
3396
+ }
3397
+ };
3398
+
3399
+ //#endregion
3400
+ //#region src/swap-vm/programs/aqua-program-builder.ts
3401
+ var AquaProgramBuilder = class AquaProgramBuilder extends ProgramBuilder {
3402
+ constructor() {
3403
+ super([...aquaInstructions]);
3404
+ }
3405
+ static decode(program) {
3406
+ return new AquaProgramBuilder().decode(program);
3407
+ }
3408
+ /**
3409
+ * Enables debug mode for the program
3410
+ * WARNING: Debug instructions will throw an error if debug mode is not enabled
3411
+ */
3412
+ withDebug() {
3413
+ this.ixsSet[0] = printSwapRegisters;
3414
+ this.ixsSet[1] = printSwapQuery;
3415
+ this.ixsSet[2] = printContext;
3416
+ this.ixsSet[3] = printAmountForSwap;
3417
+ this.ixsSet[4] = printFreeMemoryPointer;
3418
+ this.ixsSet[5] = printGasLeft;
3419
+ return this;
3420
+ }
3421
+ /**
3422
+ * Unconditional jump to specified program counter
3423
+ **/
3424
+ jump(data) {
3425
+ super.add(jump.createIx(new JumpArgs(data.nextPC)));
3426
+ return this;
3427
+ }
3428
+ /**
3429
+ * Jumps if tokenIn is the specified token
3430
+ **/
3431
+ jumpIfTokenIn(data) {
3432
+ super.add(jumpIfTokenIn.createIx(new JumpIfTokenArgs(data.tokenTail, data.nextPC)));
3433
+ return this;
3434
+ }
3435
+ /**
3436
+ * Jumps if tokenOut is the specified token
3437
+ **/
3438
+ jumpIfTokenOut(data) {
3439
+ super.add(jumpIfTokenOut.createIx(new JumpIfTokenArgs(data.tokenTail, data.nextPC)));
3440
+ return this;
3441
+ }
3442
+ /**
3443
+ * Reverts if the deadline has been reached
3444
+ **/
3445
+ deadline(data) {
3446
+ super.add(deadline.createIx(new DeadlineArgs(data.deadline)));
3447
+ return this;
3448
+ }
3449
+ /**
3450
+ * Requires taker to hold any amount of specified token (supports NFTs)
3451
+ **/
3452
+ onlyTakerTokenBalanceNonZero(data) {
3453
+ super.add(onlyTakerTokenBalanceNonZero.createIx(new OnlyTakerTokenBalanceNonZeroArgs(data.token)));
3454
+ return this;
3455
+ }
3456
+ /**
3457
+ * Requires taker to hold at least specified amount of token
3458
+ **/
3459
+ onlyTakerTokenBalanceGte(data) {
3460
+ super.add(onlyTakerTokenBalanceGte.createIx(new OnlyTakerTokenBalanceGteArgs(data.token, data.minAmount)));
3461
+ return this;
3462
+ }
3463
+ /**
3464
+ * Requires taker to hold at least specified share of token's total supply
3465
+ **/
3466
+ onlyTakerTokenSupplyShareGte(data) {
3467
+ super.add(onlyTakerTokenSupplyShareGte.createIx(new OnlyTakerTokenSupplyShareGteArgs(data.token, data.minShareE18)));
3468
+ return this;
3469
+ }
3470
+ /**
3471
+ * No-op instruction used to add uniqueness to order hashes (prevents replay attacks)
3472
+ **/
3473
+ salt(data) {
3474
+ super.add(salt.createIx(new SaltArgs(data.salt)));
3475
+ return this;
3476
+ }
3477
+ /**
3478
+ * Basic swap using constant product formula (x*y=k)
3479
+ **/
3480
+ xycSwapXD() {
3481
+ super.add(xycSwapXD.createIx(new XycSwapXDArgs()));
3482
+ return this;
3483
+ }
3484
+ /**
3485
+ * Concentrates liquidity within price bounds for multiple tokens
3486
+ **/
3487
+ concentrateGrowLiquidityXD(data) {
3488
+ super.add(concentrateGrowLiquidityXD.createIx(new ConcentrateGrowLiquidityXDArgs(data.tokenDeltas)));
3489
+ return this;
3490
+ }
3491
+ /**
3492
+ * Concentrates liquidity within price bounds for two tokens
3493
+ **/
3494
+ concentrateGrowLiquidity2D(data) {
3495
+ super.add(concentrateGrowLiquidity2D.createIx(new ConcentrateGrowLiquidity2DArgs(data.deltaLt, data.deltaGt)));
3496
+ return this;
3497
+ }
3498
+ /**
3499
+ * Applies time-based decay to balance adjustments
3500
+ **/
3501
+ decayXD(data) {
3502
+ super.add(decayXD.createIx(new DecayXDArgs(data.decayPeriod)));
3503
+ return this;
3504
+ }
3505
+ /**
3506
+ * Applies fee to amountIn
3507
+ **/
3508
+ flatFeeAmountInXD(data) {
3509
+ super.add(flatFeeAmountInXD.createIx(new FlatFeeArgs(data.fee)));
3510
+ return this;
3511
+ }
3512
+ /**
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
3521
+ **/
3522
+ progressiveFeeInXD(data) {
3523
+ super.add(progressiveFeeInXD.createIx(new FlatFeeArgs(data.fee)));
3524
+ return this;
3525
+ }
3526
+ /**
3527
+ * Applies progressive fee to amountOut
3528
+ **/
3529
+ progressiveFeeOutXD(data) {
3530
+ super.add(progressiveFeeOutXD.createIx(new FlatFeeArgs(data.fee)));
3531
+ return this;
3532
+ }
3533
+ /**
3534
+ * Applies protocol fee to amountOut with direct transfer
3535
+ **/
3536
+ protocolFeeAmountOutXD(data) {
3537
+ super.add(protocolFeeAmountOutXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
3538
+ return this;
3539
+ }
3540
+ /**
3541
+ * Applies protocol fee to amountOut through Aqua protocol
3542
+ **/
3543
+ aquaProtocolFeeAmountOutXD(data) {
3544
+ super.add(aquaProtocolFeeAmountOutXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
3545
+ return this;
3546
+ }
3547
+ /**
3548
+ * DEBUG: Prints current swap registers (amounts and tokens)
3549
+ * WARNING: Requires withDebug() to be called first, otherwise will throw an error
3550
+ */
3551
+ debugPrintSwapRegisters() {
3552
+ super.add(printSwapRegisters.createIx(new PrintSwapRegistersArgs()));
3553
+ return this;
3554
+ }
3555
+ /**
3556
+ * DEBUG: Prints current swap query state
3557
+ * WARNING: Requires withDebug() to be called first, otherwise will throw an error
3558
+ */
3559
+ debugPrintSwapQuery() {
3560
+ super.add(printSwapQuery.createIx(new PrintSwapQueryArgs()));
3561
+ return this;
3562
+ }
3563
+ /**
3564
+ * DEBUG: Prints execution context information
3565
+ * WARNING: Requires withDebug() to be called first, otherwise will throw an error
3566
+ */
3567
+ debugPrintContext() {
3568
+ super.add(printContext.createIx(new PrintContextArgs()));
3569
+ return this;
3570
+ }
3571
+ /**
3572
+ * DEBUG: Prints calculated amount for swap
3573
+ * WARNING: Requires withDebug() to be called first, otherwise will throw an error
3574
+ */
3575
+ debugPrintAmountForSwap() {
3576
+ super.add(printAmountForSwap.createIx(new PrintAmountForSwapArgs()));
3577
+ return this;
3578
+ }
3579
+ /**
3580
+ * DEBUG: Prints current free memory pointer value
3581
+ * WARNING: Requires withDebug() to be called first, otherwise will throw an error
3582
+ */
3583
+ debugPrintFreeMemoryPointer() {
3584
+ super.add(printFreeMemoryPointer.createIx(new PrintFreeMemoryPointerArgs()));
3585
+ return this;
3586
+ }
3587
+ /**
3588
+ * DEBUG: Prints remaining gas
3589
+ * WARNING: Requires withDebug() to be called first, otherwise will throw an error
3590
+ */
3591
+ debugPrintGasLeft() {
3592
+ super.add(printGasLeft.createIx(new PrintGasLeftArgs()));
3593
+ return this;
3594
+ }
3595
+ };
3596
+
3597
+ //#endregion
3598
+ //#region src/swap-vm/order.ts
3599
+ /**
3600
+ * Representation of a SwapVM order.
3601
+ */
3602
+ var Order = class Order {
3603
+ static ABI = {
3604
+ type: "tuple",
3605
+ components: [
3606
+ {
3607
+ name: "maker",
3608
+ type: "address"
3609
+ },
3610
+ {
3611
+ name: "traits",
3612
+ type: "uint256"
3613
+ },
3614
+ {
3615
+ name: "data",
3616
+ type: "bytes"
3617
+ }
3618
+ ]
3619
+ };
3620
+ constructor(maker, traits, program) {
3621
+ this.maker = maker;
3622
+ this.traits = traits;
3623
+ this.program = program;
3624
+ }
3625
+ static new(params) {
3626
+ return new Order(params.maker, params.traits, params.program);
3627
+ }
3628
+ /**
3629
+ * Reconstructs an `Order` from its ABI-encoded representation.
3630
+ *
3631
+ * 🎯 Non-obvious:
3632
+ * - Any change to how `MakerTraits` packs `hooksData` must preserve the contract that
3633
+ * `hooksDataEndsAtByte(traits)` points exactly to the start of the program, or decoding will drift.
3634
+ */
3635
+ static decode(encoded) {
3636
+ const [{ maker, traits, data }] = decodeAbiParameters([Order.ABI], encoded.toString());
3637
+ const makerTraits = MakerTraits.decode(traits, new HexString$1(data));
3638
+ const program = new HexString$1(data).sliceBytes(MakerTraits.hooksDataEndsAtByte(traits));
3639
+ return new Order(new Address$1(maker), makerTraits, new SwapVmProgram(program.toString()));
3640
+ }
3641
+ /**
3642
+ * Computes an order hash used for signing or as a deterministic order identifier.
3643
+ *
3644
+ * Hashing modes:
3645
+ * - Aqua mode (`traits.useAquaInsteadOfSignature === true`):
3646
+ * - Returns `keccak256(encode())`.
3647
+ * - Ignores provided `domain` completely.
3648
+ * - EIP-712 signature mode (`useAquaInsteadOfSignature === false`):
3649
+ * - Requires a `domain`; if missing, an assertion error is thrown.
3650
+ *
3651
+ * ⚠️ IMPORTANT:
3652
+ * - Callers must ensure they pass the same `domain` parameters that the verifier
3653
+ * uses on-chain; mismatches will produce hashes that cannot be verified.
3654
+ */
3655
+ hash(domain) {
3656
+ if (this.traits.useAquaInsteadOfSignature) return new HexString$1(keccak256(this.encode().toString()));
3657
+ assert(domain, "domain info required if isUseOfAquaInsteadOfSignatureEnabled is false");
3658
+ return new HexString$1(hashTypedData({
3659
+ domain: {
3660
+ ...domain,
3661
+ verifyingContract: domain.verifyingContract.toString()
3662
+ },
3663
+ primaryType: "Order",
3664
+ types: { Order: [
3665
+ {
3666
+ name: "maker",
3667
+ type: "address"
3668
+ },
3669
+ {
3670
+ name: "traits",
3671
+ type: "uint256"
3672
+ },
3673
+ {
3674
+ name: "data",
3675
+ type: "bytes"
3676
+ }
3677
+ ] },
3678
+ message: this.build()
3679
+ }));
3680
+ }
3681
+ /**
3682
+ * ABI-encodes the order into the exact bytes blob expected by on-chain contracts.
3683
+ *
3684
+ * Usage:
3685
+ * - Input to `keccak256` in Aqua mode (`hash()`).
3686
+ * - Payload for contract methods expecting an `Order` tuple.
3687
+ */
3688
+ encode() {
3689
+ const encoded = encodeAbiParameters([Order.ABI], [this.build()]);
3690
+ return new HexString$1(encoded);
3691
+ }
3692
+ /**
3693
+ * Produces the ABI-ready `BuiltOrder` tuple`.
3694
+ */
3695
+ build() {
3696
+ const { traits, hooksData } = this.traits.encode(this.maker);
3697
+ return {
3698
+ maker: this.maker.toString(),
3699
+ traits,
3700
+ data: hooksData.concat(this.program).toString()
3701
+ };
3702
+ }
3703
+ };
3704
+
3705
+ //#endregion
3706
+ //#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 {
3712
+ feeBpsIn;
3713
+ deltas;
3714
+ decayPeriod;
3715
+ protocolFee;
3716
+ 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
+ }
3724
+ withProtocolFee(bps, receiver) {
3725
+ this.protocolFee = {
3726
+ bps,
3727
+ receiver
3728
+ };
3729
+ return this;
3730
+ }
3731
+ withDeltas(a, b) {
3732
+ this.deltas = {
3733
+ a,
3734
+ b
3735
+ };
3736
+ return this;
3737
+ }
3738
+ withDecayPeriod(decayPeriod) {
3739
+ this.decayPeriod = decayPeriod;
3740
+ return this;
3741
+ }
3742
+ withFeeTokenIn(bps) {
3743
+ this.feeBpsIn = bps;
3744
+ return this;
3745
+ }
3746
+ withSalt(salt$1) {
3747
+ this.salt = salt$1;
3748
+ return this;
3749
+ }
3750
+ build() {
3751
+ 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));
3755
+ }
3756
+ if (this.decayPeriod) builder.decayXD({ decayPeriod: this.decayPeriod });
3757
+ if (this.feeBpsIn) {
3758
+ const data = FlatFeeArgs.fromBps(this.feeBpsIn);
3759
+ builder.add(flatFeeAmountInXD.createIx(data));
3760
+ }
3761
+ if (this.protocolFee) {
3762
+ const data = ProtocolFeeArgs.fromBps(this.protocolFee.bps, this.protocolFee.receiver);
3763
+ builder.add(aquaProtocolFeeAmountOutXD.createIx(data));
3764
+ }
3765
+ builder.xycSwapXD();
3766
+ if (this.salt) builder.salt({ salt: this.salt });
3767
+ return builder.build();
3768
+ }
3769
+ };
3770
+
3771
+ //#endregion
3772
+ //#region src/abi/index.ts
3773
+ var abi_exports = {};
3774
+ __export(abi_exports, { SWAP_VM_ABI: () => SWAP_VM_ABI });
3775
+
3776
+ //#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 };