Multi-Party Liquidity Aggregation & Fee Fairness Proof
This document provides the complete mathematical proof, accounting model, numerical walkthroughs, and on-chain test verification demonstrating that Biatec CLAMM (BIATEC-CLAMM-01-06-08) collects and distributes fees accurately when multiple users provide and withdraw liquidity in the same pool at different times.
Specifically, this guide proves that:
- No Fee Loss: 100% of swap fees and distributed staking rewards are captured on-chain and partitioned between liquidity providers (
LiquidityUsersFromFees) and the protocol (LiquidityBiatecFromFees) with zero unallocated leakage. - No Fee Scooping by Late Joiners: A liquidity provider who joins a pool after fees have accrued cannot extract any portion of the fees earned prior to their deposit.
- No Dilution of Incumbent LPs: Existing liquidity providers retain 100% of their principal and 100% of their previously accrued fees when new liquidity providers join the pool, and their accrued fees automatically compound as active liquidity for subsequent trades.
- Order-Independent Withdrawals: When multiple liquidity providers exit a pool, the payout to each participant is independent of who withdraws first (up to atomic asset units of integer division flooring, which always rounds in favor of the remaining pool).
1. On-Chain Accounting Variables & Conservation Invariant
Every BiatecClammPool contract maintains four core liquidity quantities in 9-decimal base scale ():
| Symbol | Contract State / Formula | Description |
|---|---|---|
Liquidity (L) | Total concentrated liquidity derived from tracked reserves . | |
distributedLp | Circulating LP tokens held outside the pool account, scaled to 9 decimals: . | |
LiquidityUsersFromFees (Lu) | Accumulated fee/reward liquidity owned pro rata by circulating LP token holders. | |
LiquidityBiatecFromFees (Lb) | Accumulated protocol fee liquidity owned by the Biatec fee executor (addressExecutiveFee). |
Fundamental Conservation Invariant
At every point in the pool lifecycle, total curve liquidity satisfies:
where:
- is the total liquidity claim of all LP token holders (redeemable via
removeLiquidity), - is the total liquidity claim of the protocol fee executor (redeemable via
removeLiquidityAdmin), - is the sub-micro-LP integer flooring remainder ( per deposit), which can be credited to (or if ) at any time via
reconcileLiquidity.
2. How Fees Are Collected on Every Swap and Reward Distribution
2.1 Swap Fee Accrual (swap)
When a trader swaps input amount (in base scale):
-
Fee Deduction Before Curve Pricing: The contract computes the effective fee multiplier from the pool's
feeparameter and the trader'sBiatecIdentityProvidertier:Only the net input is used to compute the counter-asset output along the constant-liquidity curve .
-
Output Rounding Protection: When converting from 9-decimal base scale to the output asset's native decimals, any non-zero fractional remainder causes the output to be stepped down by 1 native asset unit (
realSwapBDecimals = realSwapBDecimals - 1), ensuring integer conversion never bleeds pool reserves. -
Reserve Update & Liquidity Recomputation: The full input (including the fee portion ) is added to the incoming reserve, while only the transferred output is subtracted from the outgoing reserve. The contract then recomputes pool liquidity:
-
Exhaustive Fee Partition (): The liquidity gain is split between LP holders and Biatec:
Because is defined as , the sum holds identically with zero rounding loss.
2.2 Staking & Excess Asset Distribution (distributeExcessAssets)
When staking rewards or external yield are credited via distributeExcessAssets, the contract verifies physical backing (ensurePoolBalancesWithinHoldings), computes , and applies the identical exhaustive split .
3. Mathematical Proof: Aggregating Liquidity of Multiple Parties at Different Times
Consider two independent liquidity providers — Party A (Incumbent) and Party B (Newcomer) — who deposit into the same pool at different times , with swaps occurring both before () and after () Party B joins.
Step 1 (): Party A Supplies Initial Liquidity
Party A deposits assets adding of liquidity into an empty pool ().
-
Party A receives micro-LP tokens, corresponding to base units ().
-
Pool state after :