MinRate is a rate-guard instruction for SwapVM, the Aqua swap engine. It enforces or adjusts a minimum exchange rate after the nested swap formula runs, protecting makers from accepting a rate below a configured floor.
Source: src/instructions/MinRate.sol
MinRate is not part of the deployed Aqua router opcode set (Controls, XYCSwap, XYCConcentrate, Decay, Fee, PeggedSwap, Extruction). It is a SwapVM rate-guard modifier that runs on the limit-order router, where it composes with rate-setting instructions such as LimitSwap.
Args encoding
Rates are stored in token-address order (lower address first):
| Field | Offset | Size | Description |
|---|---|---|---|
rateLt |
0 | 8 bytes (uint64) |
Rate for the token with the lower address |
rateGt |
8 | 8 bytes (uint64) |
Rate for the token with the higher address |
Total: 16 bytes. Build with MinRateArgsBuilder.build(address tokenA, address tokenB, uint64 rateA, uint64 rateB), which automatically assigns rateLt/rateGt based on address comparison.
At execution time, the instruction re-maps to (rateIn, rateOut) based on tokenIn < tokenOut.
Rate interpretation: The minimum acceptable rate is rateIn / rateOut, that is, the number of tokenIn units per tokenOut unit. The swap is valid when:
amountIn × rateOut >= rateIn × amountOut
Instructions
_requireMinRate1D
function _requireMinRate1D(Context memory ctx, bytes calldata args) internal
Runs the nested swap formula via ctx.runLoop(), then reverts if the resulting rate is below the minimum.
Must be placed before swap amounts are computed.
Errors
| Error | Condition |
|---|---|
MinRateExpectedBeforeSwapAmountsComputed(amountIn, amountOut) |
Amounts already set |
MinRateFailed(swapAmountIn, swapAmountOut, rateIn, rateOut) |
amountIn × rateOut < rateIn × amountOut |
_adjustMinRate1D
function _adjustMinRate1D(Context memory ctx, bytes calldata args) internal
Runs the nested swap formula via ctx.runLoop(). If the resulting rate is below the minimum, caps the amounts to exactly the minimum rate rather than reverting.
| Mode | Adjustment when rate below minimum |
|---|---|
| exactIn | amountOut = amountIn × rateOut / rateIn |
| exactOut | amountIn = ⌈amountOut × rateIn / rateOut⌉ |
Must be placed before swap amounts are computed. Requires the nested loop to produce non-zero amounts.
Errors
| Error | Condition |
|---|---|
MinRateExpectedBeforeSwapAmountsComputed(amountIn, amountOut) |
Amounts already set |
MinRateRunLoopExpectToComputeSwapAmounts(amountIn, amountOut) |
Loop produced zero amounts |
Related
- LimitSwap: sets a fixed rate; MinRate can enforce a floor on top.
- OraclePriceAdjuster: adjusts amounts toward an oracle price after the swap.