AMM V2 implements a constant-product market maker (x * y = k) for permissionless token swaps on Lux. Any ERC-20 pair can be traded by depositing liquidity into a pool. Liquidity providers receive LP tokens representing their share of the pool. The protocol charges a 0.30% swap fee, distributed entirely to LPs. AMM V2 is the base-layer DEX primitive deployed on all Lux EVM chains.
Anyone can create a pool by calling the factory:
function createPair(address tokenA, address tokenB) external returns (address pair);
Each pair is a minimal proxy contract storing reserves and minting LP tokens. One pool per unique (tokenA, tokenB) pair (order-independent).
reserveA * reserveB = k
A swap of dx of token A yields dy of token B:
dy = (reserveB * dx * 997) / (reserveA * 1000 + dx * 997)
The 0.3% fee is taken from the input amount before computing the output.
LPs deposit both tokens proportional to current reserves:
liquidityMinted = min(amountA * totalSupply / reserveA, amountB * totalSupply / reserveB)
LP tokens are burned on withdrawal, returning proportional reserves.
Pools support flash swaps: borrow any amount of either token, execute arbitrary logic, and repay within the same transaction. The repayment must satisfy the invariant including the 0.30% fee.
Each pool accumulates price0CumulativeLast and price1CumulativeLast every block. External contracts compute TWAP (Time-Weighted Average Price) over any window by reading cumulative values at two timestamps.
AMM V2 is deployed on all 15 Lux EVM chains (C-chain + 4 L1 / L2 chains * 3 networks, per LP-018). Factory address is deterministic via CREATE2.
1. Price manipulation: single-block price is manipulable. Use TWAP oracle for any price-sensitive logic.
2. Reentrancy: all state updates occur before external calls. The lock modifier prevents reentrancy.
3. Token compatibility: rebasing tokens and fee-on-transfer tokens require wrapper contracts.
github.com/luxfi/standard/contracts/amm/v2/ |LuxFactory.sol |LuxRouter02.sol |Copyright (C) 2024-2026, Lux Partners Limited. All rights reserved.
Licensed under the MIT License.