Fee System
Overview
Lunarys uses a Uniswap V2-style fee model where swap fees stay implicitly in reserves. There are no fee accumulators or growth tracking -- this is a deliberate privacy design choice to prevent leaking trading activity information.
Swap Fees
How It Works
Swap fees are deducted from the input amount before pricing:
effectiveIn = amountIn * (BPS_DENOMINATOR - swapFeeBps) / BPS_DENOMINATOR
Where BPS_DENOMINATOR = 1,000,000.
The full amountIn (including the fee portion) is added to reserves. The output is computed on effectiveIn only. This means the fee stays in the pool, increasing the reserve-to-supply ratio over time.
Fee Tiers
| Tier | BPS Value | Percentage | Example Pools |
|---|---|---|---|
| Low | 1,000 | 0.10% | eUSDT/eUSD (stablecoins) |
| Standard | 3,000 | 0.30% | eBTC/eUSD, eETH/eUSD, most pairs |
The fee is set per pool at creation time via EPoolFactory.createPool(...) and is stored as a uint24 (public, not encrypted).
Example
Pool with 0.3% fee (3,000 BPS):
User swaps 1,000 eUSD for eBTC
effectiveIn = 1,000 * (1,000,000 - 3,000) / 1,000,000
= 1,000 * 997,000 / 1,000,000
= 997 eUSD
Output computed on 997 eUSD (3 eUSD = fee)
Full 1,000 eUSD added to reserves
Withdrawal Fee
A 0.05% (500 BPS) fee is applied when removing liquidity:
grossA = sharesToRemove * obfReserveA / obfTotalSupply
feeA = grossA * 500 / 1,000,000
netA = grossA - feeA
The fee stays in the pool, benefiting remaining LPs.
Why a Withdrawal Fee?
Prevents Just-In-Time (JIT) liquidity attacks where an attacker adds liquidity just before a large swap and removes it immediately after, extracting fees without providing sustained liquidity.
Privacy-Preserving Design
No Fee Accumulators
Unlike Uniswap V3 which tracks feeGrowthGlobal and per-position fee snapshots, Lunarys has no public fee tracking. This prevents:
- Inferring trading volume from fee growth
- Tracking individual LP earnings
- Estimating pool utilization from fee data
How LPs Realize Fees
LPs realize accumulated fees when they call removeLiquidity(). Since the reserve-to-supply ratio has grown from accumulated fees, they receive proportionally more tokens than they deposited.
Fee is Public
The swapFeeBps value is a public uint24 -- this is by design. The fee rate itself doesn't reveal sensitive information; it's the fee amounts (derived from trade sizes) that would leak privacy. Since trade sizes are encrypted, fee amounts are also effectively hidden.