Liquidity Framework
The Unified Liquidity Pool serves as the foundation of Herafi's liquidity architecture, employing innovative mechanisms designed to maintain balanced liquidity across all supported tokens while using oracle-based pricing. This document outlines the key aspects of Herafi's liquidity framework.
Unified Pool Concept
Unlike traditional Automated Market Makers (AMMs) that utilize separate pools for each trading pair, Herafi consolidates all supported tokens into a single unified pool. This approach offers several advantages:
Traditional AMMs vs. Unified Liquidity Pool
Feature | Traditional AMMs | Herafi UnifiedLiquidityPool |
---|---|---|
Pool Structure | Separate pools per token pair | Single unified pool for all tokens |
LP Token Valuation | Based on specific pool assets | Based on USD value of entire pool |
Price Mechanism | Fixed mathematical curves | Oracle-based pricing with dynamic fees |
Token Exchange | Limited to pairs in the same pool | Any supported token to any other in a single swap |
Liquidity Removal | Only in proportion to pool assets | Flexible single or multi-token options |
Key Benefits of the Unified Pool
-
Improved Capital Efficiency: Liquidity is shared across all token pairs rather than being fragmented across multiple pools. This means the same liquidity can serve multiple trading pairs simultaneously.
-
Reduced Slippage: Enables single-hop trades between any supported tokens, eliminating the need for multi-hop routes that increase slippage and fees.
-
Simplified Liquidity Provision: Users can deposit any supported token and receive LP tokens representing ownership in the entire pool, rather than needing to provide balanced pairs.
-
Adaptive Liquidity: The pool automatically adjusts incentives to address imbalances, encouraging the provision of tokens that are most needed.
Oracle-Based Pricing
Unlike traditional AMMs that use mathematical formulas (like constant product x*y=k) to determine exchange rates, the Unified Liquidity Pool relies on oracle price feeds.
Price Determination Mechanism
-
External Price Oracles: Token prices are derived from trusted oracle providers rather than being determined solely by pool ratios.
-
Swap Calculation Process:
- When a user swaps Token A for Token B:
- The protocol obtains oracle prices for both tokens
- Converts the Token A amount to USD value
- Applies applicable fees based on token scarcity
- Converts the remaining USD value to Token B amount
- When a user swaps Token A for Token B:
-
Example Calculation:
Advantages of Oracle-Based Pricing
- Market Alignment: Token prices in the pool reflect broader market consensus rather than localized pool conditions.
- Reduced Arbitrage Vulnerability: Minimizes opportunities for arbitrage against the pool since prices are aligned with external markets.
- Consistent Pricing: Provides more predictable and stable prices regardless of pool composition.
- Capital Efficiency: Allows the pool to operate with less idle capital while maintaining effective pricing.
Oracle Safety Measures
To ensure reliable pricing, the protocol implements several safety measures:
- Multiple Oracle Sources: Primary and fallback oracle options for each asset.
- Staleness Checks: Verification that price data is recent enough to be reliable.
- Deviation Limits: Alerts and potential pauses if price changes exceed predefined thresholds.
- Smoothing Functions: Gradual adjustment mechanisms to prevent abrupt price changes.
Dynamic Scarcity-Based Fee System
Herafi employs a sophisticated fee system that adjusts based on relative token scarcity. Unlike traditional AMMs where fees are fixed, Herafi's fees dynamically respond to supply and demand conditions.
Token Demand and Supply Measurement
-
Token Demand Calculation:
- For each token, demand is calculated based on its usage across all derivative tokens.
- This represents how much of each token would be needed to fully collateralize all derivative tokens directly.
Where:
Supply_d
is the total supply of a derivative tokenBaseValue_d
is the calculated value of the derivative tokenWeight_token
is the weight of the token in the derivativeTokenDecimals
is the decimal precision of the tokenPrice_token
is the current price of the token
-
Token Supply Measurement:
- The actual balance of each token in the liquidity pool represents its supply.
-
Scarcity Multiplier:
- The ratio of demand to supply, subject to defined constraints.
-
Smoothed Updates:
- To prevent abrupt fee changes, a smoothing function is applied:
Fee Adjustment Based on Scarcity
The dynamic fee system applies different adjustments depending on the operation:
1. Swap Fees
Base swap fee: 0.3%
The fee is adjusted based on the scarcity of both input and output tokens:
Component calculations:
Adjustment_output_scarcity
=(Percentage_scarcity(out) × 0.2) / 10
Discount_output_abundance
=(Percentage_abundance(out) × 0.2) / 20
Discount_input_scarcity
=(Percentage_scarcity(in) × 0.2) / 15
Adjustment_input_abundance
=(Percentage_abundance(in) × 0.2) / 30
This creates economic incentives:
- Higher fees for acquiring scarce tokens (protecting limited supply)
- Lower fees for acquiring abundant tokens (encouraging balance)
- Lower fees when providing scarce tokens (rewarding helpful behavior)
- Higher fees when providing abundant tokens (discouraging imbalance)
2. Single-Token Redemption Fees
Base fee: 1%
Higher fees apply when redeeming for scarce tokens to protect the pool from imbalances.
3. Multi-Token Redemption Fees
Base fee: 0.2%
With tiered scarcity adjustments based on the level of scarcity:
These adjustments ensure that the pool maintains balanced liquidity while still offering flexibility to users.
Fee Distribution
Fees collected by the protocol are distributed according to a predefined split:
- 80% accrues to liquidity providers
- 20% goes to the protocol treasury
The fee split ratio is configurable by governance but defaults to:
Where:
- FeeSplitLPs = 8000 (80%)
- FEE_PRECISION = 10000
LP Token Mechanics
Liquidity providers receive LP tokens representing their ownership share in the Unified Liquidity Pool.
LP Token Issuance
Unlike traditional AMMs where LP tokens represent specific token pairs, Herafi LP tokens represent ownership of the entire pool based on USD value:
For the first deposit (empty pool):
For subsequent deposits:
Where Value_USD is calculated based on oracle prices.
Scarcity Bonus for LP Providers
When providing scarce tokens (those with demand exceeding supply), liquidity providers receive a bonus in LP token issuance:
This creates a natural economic incentive to supply tokens that are most needed by the protocol.
LP Token Valuation
The value of LP tokens is calculated based on the total USD value of all tokens in the pool:
This ensures that LP tokens maintain a fair representation of the holder's ownership percentage in the pool.
Liquidity Provision
Users can provide liquidity to the Unified Liquidity Pool in multiple ways:
Single-Token Liquidity Provision
- User selects a single token to provide
- The token value is calculated based on oracle price
- Any scarcity bonus is applied if the token has high demand
- LP tokens are minted representing the user's share of the pool
This simplifies the liquidity provision process compared to traditional AMMs that require balanced pairs.
Multi-Token Liquidity Provision
- User selects multiple tokens to provide
- The combined value is calculated based on oracle prices
- Any scarcity bonuses are applied to relevant tokens
- LP tokens are minted representing the user's share of the pool
This allows users to provide liquidity across multiple assets in a single transaction.
Liquidity Removal Options
The UnifiedLiquidityPool offers users multiple options for redeeming their LP tokens:
1. Single-Token Removal
Users can withdraw their entire share in a single token of choice:
- User specifies the token they wish to receive
- The system calculates the user's share of the pool in USD
- The equivalent amount of the selected token is calculated
- The applicable fee is determined (base fee + scarcity adjustment)
- The token is transferred to the user minus the fee
Base fee: 1% + additional scarcity-based fee (up to 2% total)
This option offers maximum convenience but incurs higher fees, especially for scarce tokens.
2. Multi-Token Removal
Users can withdraw in multiple tokens with a specified distribution:
- User specifies multiple tokens and their desired distribution percentages
- The system calculates the user's share of the pool in USD
- The equivalent amount of each selected token is calculated based on the specified distribution
- The applicable fees are determined for each token (lower than single-token fees)
- The tokens are transferred to the user minus the fees
Base fee: 0.2% + smaller scarcity-based fee
This option offers flexibility in token selection while incurring lower fees than single-token removal.
3. Proportional Removal
Users can withdraw in proportion to the current pool composition:
- The system calculates the user's share of the pool in USD
- The equivalent amount of each token is calculated based on its proportion in the pool
- The applicable fee is determined (lowest of all options)
- The tokens are transferred to the user minus the fee
Base fee: 0.1%
This option offers the lowest fees but requires the user to accept all tokens in their current pool proportions.
Token Swap Mechanism
The Unified Liquidity Pool enables direct swaps between any supported tokens:
Swap Process
- HeraPool specifies input token, output token, and input amount
- The system calculates the input value in USD based on oracle price
- The dynamic fee is calculated based on token scarcity factors
- The fee is deducted from the USD value
- The remaining USD value is converted to the output token amount
- The output token is transferred to the user
Note: This swaps is executed in the HeraPool contract. No external contract can call this function.
Slippage Protection
To protect users from unexpected price movements:
- User specifies minimum acceptable output for the swap
- If the calculated output falls below this minimum due to price changes between transaction submission and execution, the transaction reverts
- This ensures users have control over the maximum slippage they're willing to accept
Default slippage tolerance: 1% (configurable by user)
Liquidity Pool Rebalancing Incentives
The dynamic fee system naturally encourages balanced liquidity without requiring explicit rebalancing mechanisms:
-
Economic Signals: Higher fees for scarce tokens and lower fees for abundant tokens signal to the market which tokens the pool needs.
-
LP Incentives: Enhanced LP token issuance for providing scarce tokens creates a direct incentive to supply tokens in high demand.
-
Arbitrage Opportunities: If pool prices diverge from external markets due to extreme imbalances, arbitrageurs can profit by correcting the imbalance through trades.
-
User Behavior Alignment: The fee system aligns user behavior with pool health - users are incentivized to provide scarce tokens and remove abundant tokens.
This market-driven approach to liquidity balancing is more capital efficient than traditional methods and adapts automatically to changing market conditions.
Price Impact and Liquidity Depth
Although Herafi uses oracle pricing, large trades can still impact effective prices through the dynamic fee mechanism:
Fee-Based Price Impact
-
As trade size increases for scarce tokens, the effective price becomes less favorable due to:
- Base fee percentage applied to larger amounts
- Potential increases in scarcity-based fee components
-
For very large trades, additional protections may be activated:
- Maximum trade size limits relative to pool liquidity
- Incremental fee increases for trades exceeding certain thresholds
- Circuit breakers for extreme market conditions
Liquidity Depth Assessment
Users can assess liquidity depth before trading:
- Estimated Output: The interface shows expected output amount including all applicable fees
- Fee Breakdown: Transparent display of base fee and any scarcity adjustments
- Price Impact: Visualization of how increasing trade size affects effective price
- Maximum Trade Size: Indication of maximum advisable trade size based on current liquidity
These features ensure users can make informed decisions based on current liquidity conditions.
Conclusion
Herafi's liquidity framework represents a significant innovation in DeFi liquidity management. By combining a unified pool structure, oracle-based pricing, and dynamic scarcity-based fees, the protocol creates a capital-efficient system that adapts to market conditions while providing users with flexible options for participating in the ecosystem.
This approach addresses key challenges in traditional AMM designs while opening new possibilities for derivative token issuance, multi-asset exposure, and optimized trading experiences.