Constant-Product AMM
Constant-product (x*y=k) automated market maker for permissionless token swaps on every Lux EVM chain
Abstract
The constant-product AMM is the base-layer DEX primitive on Lux: any ERC-20 pair can be traded by depositing liquidity into a pool that holds the invariant x * y = k. Liquidity providers receive fungible LP tokens representing their share of the pool. The protocol charges a 0.30% swap fee, distributed entirely to LPs. It is deployed on every Lux EVM chain and is the reference implementation of the pooled half of LP-9000 (D-Chain matches order flow; C-Chain contracts hold pooled liquidity).
Motivation
An order book needs a counterparty willing to quote. A constant-product pool always quotes, at every price, without an operator. That property — a permissionless, always-on, zero-coordination market for any pair — is what bootstraps a long tail of assets that no market maker would list. The 0.30% fee and the x*y=k curve are the smallest mechanism that makes providing that liquidity rational.
Specification
Pool Creation
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).
Constant Product Invariant
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.
Liquidity Provision
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.
Flash Swaps
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.
Oracle
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.
Fee Structure
| Fee | Rate | Recipient |
|---|---|---|
| Swap fee | 0.30% | 100% to LP token holders |
| Protocol fee | 0.00% (governance-activatable up to 0.05%) | Treasury |
Deployment
The AMM is deployed on every Lux EVM chain in the roster of LP-5210, across mainnet, testnet, and devnet. The factory address is deterministic via CREATE2 (LP-9074), so the same pair resolves to the same address on every chain.
Rationale
Constant product is chosen over constant sum or a bonding curve because it is the only two-token invariant that (a) can never be drained — the price approaches infinity as a reserve approaches zero — and (b) requires no external price input. The fee is applied to the input rather than the output so the invariant strictly increases on every swap, which is what makes LP token value monotone in trade volume.
Security Considerations
- Price manipulation: single-block price is manipulable. Use TWAP oracle for any price-sensitive logic.
- Reentrancy: all state updates occur before external calls. The lock modifier prevents reentrancy.
- Token compatibility: rebasing tokens and fee-on-transfer tokens require wrapper contracts.
Reference
| Resource | Location |
|---|---|
| AMM contracts | github.com/luxfi/standard/contracts/amm/v2/ |
| Factory | LuxFactory.sol |
| Router | LuxRouter02.sol |
Related LPs
- LP-9000 — DEX core: order book (D-Chain) and pooled liquidity (C-Chain)
- LP-9201 — concentrated liquidity, the capital-efficient successor
- LP-9202 — pegged-asset curve
- LP-9018 — incentives directed at these pools
Copyright
Copyright (C) 2024-2026, Lux Industries Inc. All rights reserved.
Licensed under the MIT License.