Smart Contracts Overview
Contract Architecture
The Lunarys eDEX is composed of the following contracts:
| Contract | Purpose | Lines |
|---|---|---|
EPOOL | Core confidential AMM pool | ~487 |
EPoolFactory | Pool deployment factory | ~144 |
UniversalRouter | Pool discovery and route validation | ~154 |
Airdrop | Test token distribution | ~66 |
CERC20 | Confidential ERC20 token (ERC7984) | -- |
Libraries
| Library | Purpose |
|---|---|
SwapLib | 4-term Taylor approximation for constant-product pricing |
LiquidityLib | Proportional LP minting and withdrawal math |
EPoolObfuscationLib | HCU-optimized random factor generation |
EPoolTypes | Type definitions (obfuscatedStatesStruct) |
EPoolErrors | Custom errors (InvalidRecipient, DeadlineExpired, etc.) |
EPoolFactoryLib | Pool deployment helper |
Technology Stack
- Solidity: ^0.8.24 with optimization
- FHE Layer: Encrypted types and FHE operations
- ERC7984: Confidential ERC20 standard
- OpenZeppelin: ReentrancyGuard, Ownable, Ownable2Step
Deployment Order
- Deploy CERC20 tokens (or wrap existing ERC20s)
- Deploy
EPoolFactorywith encrypted obfuscation parameters - Deploy
UniversalRouterpointing to factory - Create pools via factory:
factory.createPool(tokenA, tokenB, swapFee, ...) - Bootstrap each pool:
pool.bootstrap(amountA, amountB, proof) - Deploy
Airdropand fund with tokens (testnet)
Security Model
Access Control
| Contract | Access | Details |
|---|---|---|
| EPoolFactory | Ownable | Pool creation, obfuscation param updates |
| EPOOL | Ownable2Step (via CERC20) | Owner bootstraps; swaps/liquidity open to all |
| Tokens | Operator model | Time-limited approvals via setOperator |
Privacy Guarantees
- All reserves encrypted (
euint64) - Obfuscated public state for price discovery (~3x uncertainty)
- Encrypted LP shares (CERC20)
- Per-operation factor rotation
Reentrancy Protection
All critical EPOOL functions use ReentrancyGuard.
Integration Points
For Traders
- Fetch obfuscated reserves:
pool.obfuscatedStates() - Decrypt via FHE gateway
- Encrypt swap amounts via FHE SDK
- Call
pool.atomicSwapAForB(...)orpool.atomicSwapBForA(...)
For Liquidity Providers
- Set operator on both tokens
- Fetch and decrypt obfuscated state (including LP supply)
- Encrypt deposit amounts
- Call
pool.contributeLiquidity(...)
For Pool Deployers
- Call
factory.createPool(tokenA, tokenB, swapFee, name, symbol, uri) - Bootstrap pool with initial liquidity
See Frontend Integration for complete TypeScript examples.