XYCSwap is the constant-product AMM instruction (x * y = k) in the SwapVM instruction set, the swap engine behind 1inch Aqua. It is a terminal instruction that computes amountIn or amountOut directly from the current virtual reserves.
XYCSwap ships in the deployed Aqua opcode set (AquaOpcodes) on AquaSwapVMRouter, alongside Controls, XYCConcentrate, Decay, Fee, PeggedSwap, and Extruction. It backs the xyc (constant-product) strategy type.
Source: src/instructions/XYCSwap.sol
Instructions
_xycSwapXD
Solidity
1
function _xycSwapXD(Context memory ctx, bytes calldata /* args */) internal pure
Args: none (0 bytes)
Behavior
| Mode | Computation |
|---|---|
| exactIn | amountOut = amountIn * balanceOut / (balanceIn + amountIn) (floor) |
| exactOut | amountIn = ⌈amountOut * balanceIn / (balanceOut − amountOut)⌉ (ceil) |
Reverts if either virtual balance is zero. Also reverts if amountOut (exactIn) or amountIn (exactOut) is already set; recompute detection prevents inconsistent state.
Errors
| Error | Condition |
|---|---|
XYCSwapRequiresBothBalancesNonZero(balanceIn, balanceOut) |
balanceIn == 0 || balanceOut == 0 |
XYCSwapRecomputeDetected() |
amountOut != 0 (exactIn) or amountIn != 0 (exactOut) |
Constraints
- Must be preceded by an instruction that sets
ctx.swap.balanceInandctx.swap.balanceOut(e.g.,_staticBalancesXD,_dynamicBalancesXD) - Suffix
XD: runs identically in quote (static) and swap (dynamic) contexts
Related
- XYCConcentrate: concentrated liquidity variant with price bounds
- Balances: sets virtual reserves before this instruction
- Fee: apply before this instruction to reduce the effective amountIn