OraclePriceAdjuster is an instruction for SwapVM, the Aqua swap engine. It nudges swap amounts toward a Chainlink oracle price: when the oracle shows a better rate than the current swap amounts, the taker's fill is improved, up to a configured maximum.
Source: src/instructions/OraclePriceAdjuster.sol
Compatible with 1→0 swaps (token1 → token0) only.
OraclePriceAdjuster is not part of the deployed Aqua router opcode set. The AquaSwapVMRouter opcode table (AquaOpcodes) ships Controls, XYCSwap, XYCConcentrate, Decay, Fee, PeggedSwap, and Extruction. OraclePriceAdjuster is available as a post-swap price modifier on the relevant SwapVM router, not as a live opcode on the deployed Aqua router.
Args encoding
| Field | Offset | Size | Type | Description |
|---|---|---|---|---|
maxPriceDecay |
0 | 8 bytes | uint64 |
Maximum adjustment coefficient in 1e18 scale; must be < 1e18 (e.g. 0.95e18 = max 5% improvement) |
maxStaleness |
8 | 2 bytes | uint16 |
Max oracle data age in seconds; 0 disables the staleness check |
oracleDecimals |
10 | 1 byte | uint8 |
Oracle price decimal places; 0 triggers a live oracle.decimals() call |
oracleAddress |
11 | 20 bytes | address |
Chainlink AggregatorV3-compatible price feed |
Total: 31 bytes. Build with OraclePriceAdjusterArgsBuilder.build(uint64 maxPriceDecay, uint16 maxStaleness, uint8 oracleDecimals, address oracleAddress).
Instructions
_oraclePriceAdjuster1D
function _oraclePriceAdjuster1D(Context memory ctx, bytes calldata args) internal view
Must be placed after a swap instruction so that both amountIn and amountOut are already computed.
Behavior
- Calls
oracle.latestRoundData()to getanswerandupdatedAt - Checks staleness: reverts if
block.timestamp > updatedAt + maxStaleness(whenmaxStaleness > 0) - Normalizes oracle price to 1e18 scale using
oracleDecimals - Computes current swap price:
currentPrice = amountOut × 1e18 / amountIn - If
oraclePrice > currentPrice(oracle favors the taker):
- exactIn: increases
amountOutproportionally, capped at2e18 − maxPriceDecay - exactOut: decreases
amountInproportionally, floored atmaxPriceDecay
- If
oraclePrice <= currentPrice: no adjustment
Errors
| Error | Condition |
|---|---|
OraclePriceAdjusterShouldBeAppliedAfterSwap() |
amountIn == 0 || amountOut == 0 |
OraclePriceAdjusterOraclePriceStale(currentTime, updatedAt, maxStaleness) |
Oracle data too old |
Related
- LimitSwap: sets base amounts before this instruction
- BaseFeeAdjuster: adjusts amounts based on gas price (also post-swap)