Fixed-rate swap at a maker-defined price. Computes amountIn or amountOut from the fixed ratio balanceOut / balanceIn.
Source: src/instructions/LimitSwap.sol
Scope: LimitSwap is an instruction in the Limit Order Protocol opcode set, executed by SwapVM (the Aqua swap engine) on the limit-order router. It is not part of the deployed 1inch Aqua opcode set (Controls, XYCSwap, XYCConcentrate, Decay, Fee, PeggedSwap, Extruction) served by the AquaSwapVMRouter. Aqua strategies do not use LimitSwap; order-level partial fills belong to Limit Order and Fusion, not to Aqua pools.
Args encoding
| Field | Size | Description |
|---|---|---|
makerDirectionLt |
1 byte (bool) |
true if tokenIn < tokenOut at order creation |
Build with LimitSwapArgsBuilder.build(address tokenIn, address tokenOut), which encodes tokenIn < tokenOut automatically.
Instructions
_limitSwap1D
function _limitSwap1D(Context memory ctx, bytes calldata args) internal pure
Computes swap amounts at the fixed rate balanceOut / balanceIn. Supports partial fills.
| Mode | Computation |
|---|---|
| exactIn | amountOut = amountIn * balanceOut / balanceIn (floor) |
| exactOut | amountIn = ⌈amountOut * balanceIn / balanceOut⌉ (ceil) |
Direction check: The makerDirectionLt arg encodes the token ordering when the maker shipped the order. At execution time the taker's tokenIn < tokenOut must match the recorded value. This prevents the order from being filled in the wrong direction.
Errors
| Error | Condition |
|---|---|
LimitSwapRequiresBothBalancesNonZero(balanceIn, balanceOut) |
Either balance is zero |
LimitSwapDirectionMismatch() |
makerDirectionLt != (tokenIn < tokenOut) |
LimitSwapRecomputeDetected() |
amountOut != 0 (exactIn) or amountIn != 0 (exactOut) |
_limitSwapOnlyFull1D
function _limitSwapOnlyFull1D(Context memory ctx, bytes calldata args) internal pure
Same direction check and args as _limitSwap1D, but requires the swap to consume the entire available balance. Partial fills revert.
| Mode | Requirement | Result |
|---|---|---|
| exactIn | amountIn == balanceIn |
amountOut = balanceOut |
| exactOut | amountOut == balanceOut |
amountIn = balanceIn |
Errors (in addition to those of _limitSwap1D)
| Error | Condition |
|---|---|
LimitSwapFullyRequiresAmountInToMatchBalanceIn(amountIn, balanceIn) |
exactIn: amountIn != balanceIn |
LimitSwapFullyRequiresAmountOutToMatchBalanceOut(amountOut, balanceOut) |
exactOut: amountOut != balanceOut |
Related
- Balances sets
balanceInandbalanceOutbefore this instruction runs. - DutchAuction applies time-based price decay on top of LimitSwap.
- Invalidators tracks partial fills against
balanceInandbalanceOut. - TWAPSwap inherits LimitSwap for per-chunk price calculation.