22
33[ ![ Github Release] ( https://img.shields.io/github/v/tag/1inch/swap-vm?sort=semver&label=github )] ( https://github.com/1inch/swap-vm/releases/latest )
44[ ![ CI] ( https://github.com/1inch/swap-vm/actions/workflows/ci.yml/badge.svg )] ( https://github.com/1inch/swap-vm/actions/workflows/ci.yml )
5- [ ![ Coverage] ( https://img.shields.io/badge/Coverage-50.46 %25-yellow )] ( https://github.com/1inch/swap-vm )
5+ [ ![ Coverage] ( https://img.shields.io/badge/Coverage-85 %25-green )] ( https://github.com/1inch/swap-vm )
66[ ![ Tests] ( https://img.shields.io/github/actions/workflow/status/1inch/swap-vm/ci.yml?branch=main&label=tests )] ( https://github.com/1inch/swap-vm/actions )
77[ ![ npm] ( https://img.shields.io/npm/v/@1inch/swap-vm.svg )] ( https://www.npmjs.com/package/@1inch/swap-vm )
88[ ![ License] ( https://img.shields.io/badge/License-Degensoft--SwapVM--1.1-orange )] ( LICENSE )
@@ -123,7 +123,9 @@ The execution flow shows all available instructions and strategies for each bala
123123│ ├─ _progressiveFeeInXD → Size-based dynamic fee (input)│
124124│ ├─ _progressiveFeeOutXD → Size-based dynamic fee (output)│
125125│ ├─ _protocolFeeAmountOutXD → Protocol revenue (ERC20) │
126- │ └─ _aquaProtocolFeeAmountOutXD → Protocol revenue (Aqua)│
126+ │ ├─ _aquaProtocolFeeAmountOutXD → Protocol revenue (Aqua)│
127+ │ ├─ _dynamicProtocolFeeAmountInXD → Dynamic fee via provider│
128+ │ └─ _aquaDynamicProtocolFeeAmountInXD → Dynamic Aqua fee│
127129│ │
128130│ 6. Advanced Strategies (Optional) │
129131│ ├─ _requireMinRate1D → Enforce minimum exchange rate │
@@ -174,6 +176,7 @@ The execution flow shows all available instructions and strategies for each bala
174176│ │
175177│ 2. AMM Logic (Choose Primary Strategy) │
176178│ ├─ _xycSwapXD → Classic x*y=k constant product │
179+ │ ├─ _peggedSwapGrowPriceRange2D → Curve for pegged assets│
177180│ └─ _xycConcentrateGrowLiquidityXD/2D → CLMM ranges │
178181│ │
179182│ 3. Fee Mechanisms (Optional, Combinable) │
@@ -182,7 +185,9 @@ The execution flow shows all available instructions and strategies for each bala
182185│ ├─ _progressiveFeeInXD → Size-based dynamic fee (input) │
183186│ ├─ _progressiveFeeOutXD → Size-based dynamic fee (output)│
184187│ ├─ _protocolFeeAmountOutXD → Protocol revenue (ERC20) │
185- │ └─ _aquaProtocolFeeAmountOutXD → Protocol revenue (Aqua)│
188+ │ ├─ _aquaProtocolFeeAmountOutXD → Protocol revenue (Aqua)│
189+ │ ├─ _dynamicProtocolFeeAmountInXD → Dynamic fee via provider│
190+ │ └─ _aquaDynamicProtocolFeeAmountInXD → Dynamic Aqua fee │
186191│ │
187192│ 4. MEV Protection (Optional) │
188193│ └─ _decayXD → Virtual reserves (Mooniswap-style) │
@@ -410,21 +415,28 @@ bytes memory program = bytes.concat(
410415);
411416
412417// 2. Configure order parameters
413- MakerTraits makerTraits = MakerTraitsLib.build(MakerTraitsLib.Args({
418+ ISwapVM.Order memory order = MakerTraitsLib.build(MakerTraitsLib.Args({
419+ maker: yourAddress, // Your address
420+ receiver: address(0), // You receive the tokens (0 = maker)
414421 shouldUnwrapWeth: false, // Keep WETH (don't unwrap to ETH)
415- expiration: block.timestamp + 1 days, // Order expires in 24h
416- receiver: address(0), // You receive the tokens
417- useAquaInsteadOfSignature: false // Use standard EIP-712 signing
422+ useAquaInsteadOfSignature: false, // Use standard EIP-712 signing
423+ allowZeroAmountIn: false, // Require non-zero input
424+ hasPreTransferInHook: false,
425+ hasPostTransferInHook: false,
426+ hasPreTransferOutHook: false,
427+ hasPostTransferOutHook: false,
428+ preTransferInTarget: address(0),
429+ preTransferInData: "",
430+ postTransferInTarget: address(0),
431+ postTransferInData: "",
432+ preTransferOutTarget: address(0),
433+ preTransferOutData: "",
434+ postTransferOutTarget: address(0),
435+ postTransferOutData: "",
436+ program: program // Your swap program
418437}));
419438
420- // 3. Create order (completely off-chain)
421- ISwapVM.Order memory order = ISwapVM.Order({
422- maker: yourAddress,
423- traits: makerTraits,
424- program: program
425- });
426-
427- // 4. Sign order off-chain (gasless)
439+ // 3. Sign order off-chain (gasless)
428440bytes32 orderHash = swapVM.hash(order);
429441bytes memory signature = signEIP712(orderHash);
430442```
@@ -499,7 +511,7 @@ MakerTraits makerTraits = MakerTraitsLib.build({
499511** Use Case:** Share liquidity across multiple strategies
500512** Key Difference:** Unlike isolated dynamic balances, Aqua enables shared liquidity
501513
502- See [ Aqua Protocol] ( https://github.com/1inch/aqua-protocol ) for details
514+ See [ Aqua Protocol] ( https://github.com/1inch/aqua ) for details
503515
504516### Maker Security
505517
@@ -657,45 +669,51 @@ Context
657669
658670```
659671MakerTraits (256-bit packed)
660- ├── Token Handling
661- │ └── shouldUnwrapWeth ────────── Unwrap WETH to ETH on output
662- │
663- ├── Order Lifecycle
664- │ └── expiration (40 bits) ────── Unix timestamp when order expires
665- │
666- ├── Balance Management
667- │ ├── useAquaInsteadOfSignature ─ Use Aqua balance instead of signature
668- │ └── allowZeroAmountIn ─── Skip Aqua for input transfers
672+ ├── Bit Flags (bits 245-255)
673+ │ ├── shouldUnwrapWeth (255) ──── Unwrap WETH to ETH on output
674+ │ ├── useAquaInsteadOfSignature (254) ─ Use Aqua balance instead of signature
675+ │ ├── allowZeroAmountIn (253) ── Allow zero amountIn (skip validation)
676+ │ ├── hasPreTransferInHook (252) ── Call maker before input transfer
677+ │ ├── hasPostTransferInHook (251) ── Call maker after input transfer
678+ │ ├── hasPreTransferOutHook (250) ── Call maker before output transfer
679+ │ ├── hasPostTransferOutHook (249) ── Call maker after output transfer
680+ │ ├── preTransferInHookHasTarget (248) ── Hook has custom target
681+ │ ├── postTransferInHookHasTarget (247)
682+ │ ├── preTransferOutHookHasTarget (246)
683+ │ └── postTransferOutHookHasTarget (245)
669684│
670- ├── Recipient Control
671- │ └── receiver ─────────────────── Custom recipient (0 = maker)
685+ ├── Data Slices Indexes (bits 160-223, 64 bits)
686+ │ └── Packed 4x uint16 offsets for hook data slices
672687│
673- └── Hooks (Callbacks)
674- ├── hasPreTransferOutHook ────── Call maker before output transfer
675- ├── hasPostTransferInHook ────── Call maker after input transfer
676- ├── preTransferOutData ────────── Data for pre-transfer hook
677- └── postTransferInData ────────── Data for post-transfer hook
688+ └── Receiver (bits 0-159, 160 bits)
689+ └── Custom recipient address (0 = maker)
678690```
679691
680692```
681- TakerTraits (Variable-length)
682- ├── Swap Direction
683- │ └── isExactIn ────────────────── true = specify input, false = output
693+ TakerTraits (Variable-length with 176-bit header)
694+ ├── Header (22 bytes packed)
695+ │ ├── Slices Indexes (160 bits) ── 10x uint16 offsets for data slices
696+ │ └── Bit Flags (16 bits)
697+ │ ├── isExactIn (0) ────────── true = specify input, false = output
698+ │ ├── shouldUnwrapWeth (1) ── Unwrap WETH to ETH on output
699+ │ ├── hasPreTransferInCallback (2) ── Call taker before input transfer
700+ │ ├── hasPreTransferOutCallback (3) ── Call taker before output transfer
701+ │ ├── isStrictThresholdAmount (4) ── true = exact, false = min/max
702+ │ ├── isFirstTransferFromTaker (5) ── Who transfers first
703+ │ └── useTransferFromAndAquaPush (6) ── SwapVM does transferFrom + Aqua push
684704│
685- ├── Amount Validation
686- │ ├── threshold ────────────────── Min output or max input
687- │ └── isStrictThresholdAmount ─── true = exact, false = min/max
688- │
689- ├── Token Handling
690- │ ├── shouldUnwrapWeth ─────────── Unwrap WETH to ETH on output
691- │ └── to ───────────────────────── Custom recipient (0 = taker)
692- │
693- ├── Transfer Mechanics
694- │ ├── isFirstTransferFromTaker ── Who transfers first
695- │ └── useTransferFromAndAquaPush ─ SwapVM does transferFrom + Aqua push (vs taker pushes in callback)
696- │
697- └── Hooks (Callbacks)
698- └── hasPreTransferInHook ─────── Call taker before input transfer
705+ └── Variable-length Data Slices
706+ ├── threshold (0 or 32 bytes) ── Min output or max input
707+ ├── to (0 or 20 bytes) ───────── Custom recipient
708+ ├── deadline (0 or 5 bytes) ──── Unix timestamp (uint40)
709+ ├── preTransferInHookData ────── Data for maker pre-in hook
710+ ├── postTransferInHookData ───── Data for maker post-in hook
711+ ├── preTransferOutHookData ──── Data for maker pre-out hook
712+ ├── postTransferOutHookData ─── Data for maker post-out hook
713+ ├── preTransferInCallbackData ─ Data for taker pre-in callback
714+ ├── preTransferOutCallbackData ─ Data for taker pre-out callback
715+ ├── instructionsArgs ──────────── Data consumed by VM instructions
716+ └── signature ─────────────────── EIP-712 signature for order
699717```
700718
701719### Instruction Capabilities
@@ -879,7 +897,7 @@ if (useAquaInsteadOfSignature) {
879897| Feature | Description | Implementation |
880898| ---------| -------------| ----------------|
881899| ** Signature Control** | Orders cannot be modified | EIP-712 signatures |
882- | ** Expiration** | Time-limited orders | ` expiration ` in MakerTraits |
900+ | ** Expiration** | Time-limited orders | ` _deadline ` instruction or TakerTraits deadline |
883901| ** Balance Limits** | Cannot exceed specified amounts | Register bounds checking |
884902| ** One-time Execution** | Prevent replay | ` _invalidateBit1D ` instruction |
885903| ** Custom Logic** | Hooks for validation | Pre/post transfer hooks |
@@ -890,8 +908,10 @@ if (useAquaInsteadOfSignature) {
890908// Limit order exposure
891909p.build(Invalidators._invalidateBit1D, bitIndex);
892910
893- // Add expiration
894- traits.expiration = block.timestamp + 1 hours;
911+ // Add expiration via _deadline instruction in program
912+ p.build(Controls._deadline, ControlsArgsBuilder.buildDeadline(block.timestamp + 1 hours));
913+
914+ // Or via TakerTraits deadline field
895915
896916// MEV protection
897917p.build(Decay._decayXD, DecayArgsBuilder.build(30));
0 commit comments