Skip to main content

Protocol Overview

Lunarys Protocol is a privacy-preserving DEX that uses Fully Homomorphic Encryption to keep all financial data confidential while enabling trustless trading.

The Privacy Problem​

Traditional AMMs expose sensitive financial information:

  • Public Balances: Anyone can see how much of each token a wallet holds
  • Visible Trades: Transaction amounts are visible to all observers
  • Pool Transparency: Reserve amounts reveal market conditions and opportunities for MEV extraction

This transparency creates risks for traders:

  • Front-running attacks
  • Sandwich attacks
  • Portfolio analysis and tracking
  • Strategic exploitation based on position sizes

The Lunarys Solution​

Lunarys uses Fhenix CoFHE to encrypt all sensitive values while maintaining the ability to perform AMM calculations on-chain.

How FHE Works​

Fully Homomorphic Encryption allows mathematical operations on encrypted data:

Encrypted(a) + Encrypted(b) = Encrypted(a + b)
Encrypted(a) * Encrypted(b) = Encrypted(a * b)

This means the AMM can:

  1. Accept encrypted swap amounts
  2. Compute output amounts using encrypted reserves
  3. Update reserves without revealing actual values
  4. Return encrypted output to the user

Privacy Guarantees​

DataVisibility
Token addressesPublic
Swap directionPublic
Swap amountsEncrypted
Pool reservesEncrypted
User balancesEncrypted
LP positionsEncrypted
Fee amountsEncrypted

AMM Mechanics​

Lunarys implements a constant product AMM:

x * y = k

Where:

  • x = Reserve of token A (encrypted)
  • y = Reserve of token B (encrypted)
  • k = Constant product (computed from encrypted values)

Swap Formula​

For a swap of token A for token B:

amountOut = reserveB - (k / (reserveA + amountIn))

All arithmetic operations are performed on encrypted values using FHE operations provided by Fhenix.

Fee Structure​

  • Swap Fee: Configurable (default 0.3%)
  • Protocol Fee: Optional cut for protocol treasury (max 1%)
  • LP Fee: Remainder goes to liquidity providers

Fees are deducted from the input amount before calculating the swap output.

Token Standard​

Lunarys uses FHERC20 tokens, an extension of ERC20 that supports:

  • Encrypted balances stored as euint128
  • Encrypted transfers between addresses
  • Permission system for decryption access
  • Wrap/unwrap functionality for converting between plaintext and encrypted balances

Position Tracking​

Liquidity positions are represented as NFTs (ERC721) that store:

  • Token pair addresses
  • Tick range (for future concentrated liquidity)
  • Encrypted liquidity amount
  • Encrypted token amounts
  • Fee growth snapshots for reward calculation

Use Cases​

Private Trading​

Traders can swap tokens without revealing:

  • How much they are trading
  • Their total portfolio value
  • Their trading patterns

Confidential Market Making​

Liquidity providers can:

  • Deposit without revealing position size
  • Earn fees proportionally (calculated encrypted)
  • Withdraw without exposing realized profits

Dark Pool Functionality​

The protocol functions as a decentralized dark pool where:

  • Order sizes remain hidden
  • Price impact is distributed among all LPs
  • No single party can observe all trading activity