Skip to main content

Smart Contracts Overview

Contract Architecture​

The Lunarys eDEX is composed of the following contracts:

ContractPurposeLines
EPOOLCore confidential AMM pool~487
EPoolFactoryPool deployment factory~144
UniversalRouterPool discovery and route validation~154
AirdropTest token distribution~66
CERC20Confidential ERC20 token (ERC7984)--

Libraries​

LibraryPurpose
SwapLib4-term Taylor approximation for constant-product pricing
LiquidityLibProportional LP minting and withdrawal math
EPoolObfuscationLibHCU-optimized random factor generation
EPoolTypesType definitions (obfuscatedStatesStruct)
EPoolErrorsCustom errors (InvalidRecipient, DeadlineExpired, etc.)
EPoolFactoryLibPool 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​

  1. Deploy CERC20 tokens (or wrap existing ERC20s)
  2. Deploy EPoolFactory with encrypted obfuscation parameters
  3. Deploy UniversalRouter pointing to factory
  4. Create pools via factory: factory.createPool(tokenA, tokenB, swapFee, ...)
  5. Bootstrap each pool: pool.bootstrap(amountA, amountB, proof)
  6. Deploy Airdrop and fund with tokens (testnet)

Security Model​

Access Control​

ContractAccessDetails
EPoolFactoryOwnablePool creation, obfuscation param updates
EPOOLOwnable2Step (via CERC20)Owner bootstraps; swaps/liquidity open to all
TokensOperator modelTime-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​

  1. Fetch obfuscated reserves: pool.obfuscatedStates()
  2. Decrypt via FHE gateway
  3. Encrypt swap amounts via FHE SDK
  4. Call pool.atomicSwapAForB(...) or pool.atomicSwapBForA(...)

For Liquidity Providers​

  1. Set operator on both tokens
  2. Fetch and decrypt obfuscated state (including LP supply)
  3. Encrypt deposit amounts
  4. Call pool.contributeLiquidity(...)

For Pool Deployers​

  1. Call factory.createPool(tokenA, tokenB, swapFee, name, symbol, uri)
  2. Bootstrap pool with initial liquidity

See Frontend Integration for complete TypeScript examples.