CFMM Implementation in Mage Labs
Mage Labs Constant Function Market Maker (CFMM) integrates dynamic reserve management with a dual-reserve system to achieve both price precision and liquidity stability.
Core Implementation
Platform Integration
Built for the Solana Virtual Machine (SVM) using the Anchor framework, ensuring efficient, secure, and composable on-chain execution.
Dual-Reserve System
Mage Labs uses two layers of reserves:
- Virtual Reserves: Enhance price precision and minimize slippage by simulating deeper liquidity.
- Real Reserves: Represent actual on-chain token balances and enforce solvency limits.
The product of virtual reserves remains constant through all swaps, preserving the CFMM invariant and ensuring consistent pricing.
Dynamic Reserve Adjustment
Each swap recalculates both virtual and real reserves to maintain the invariant:
where:
- = virtual reserve of Token A
- = virtual reserve of Token B
- = invariant constant
Swap Operations
Buy Operation (Token A → Token B)
-
Compute invariant:
-
Adjust virtual reserve of Token B:
-
Derive new virtual reserve of Token A:
-
Determine Token A cost:
Sell Operation (Token B → Token A)
-
Increase Token A reserve:
-
Recalculate Token B reserve:
-
Determine Token B output:
Liquidity & Recalibration
Liquidity events such as deposits or withdrawals trigger a recalibration routine to synchronize virtual and real reserves:
This ensures that on-chain liquidity changes are immediately reflected in trade pricing.
Fee and Reward Structure
Swap Fee (per trade)
The Mage Liquidity Layer offers 7 fee tiers ranging from 0.0001% to 1%, with 0.007% being one of the most competitive tiers.
Fee Distribution (post-ICO)
- Liquidity Providers (LPs): receive 70% of all fees
- Protocol Share (30%) split as:
- 15% → Token Staking Pool
- 10% → Treasury
- 5% → NFT Staking Pool
Loyalty Boost (Time-Weighted)
Where:
- = LP’s share of liquidity
- = total pool liquidity
- = loyalty multiplier (2× or 3× after 90 days)
Early and long-term capital endpoints earn an increased percentage of liquidity node fees, with boost levels reaching 2-3x after approximately 90 days.
Summary
Mage Labs CFMM model maintains a dual-reserve invariant, enabling:
- Tight spreads and minimal slippage
- Consistent pricing across all trade sizes
- Transparent and adaptive fee distribution
- Market-responsive pricing through virtual bonding curves
- On-chain solvency via real reserve constraints
Through precise virtual and real reserve synchronization, Mage Labs achieves a robust, fair, and scalable liquidity infrastructure layer on Solana.
Additional Resources
For more information on Mage Labs fee structure and liquidity incentives, see: