Fee Structure
Overview
JAMM DEX implements a flexible, multi-tier fee system, allowing different trading pairs to select an appropriate fee level based on their characteristics. This design provides an optimized trading experience for assets with varying risk and liquidity profiles.
Fee Tiers
Supported Fees
Four preset fee tiers are defined in JAMMFactory.sol:
// Supported fee tiers
uint24 public constant FEE_0_5_PERCENT = 50; // 0.5% fee
uint24 public constant FEE_1_PERCENT = 100; // 1.0% fee
uint24 public constant FEE_2_PERCENT = 200; // 2.0% fee
uint24 public constant FEE_3_PERCENT = 300; // 3.0% feeFee Validation
When a pair is created, the system validates the fee tier:
// from JAMMFactory.sol
require(
fee == FEE_0_5_PERCENT ||
fee == FEE_1_PERCENT ||
fee == FEE_2_PERCENT ||
fee == FEE_3_PERCENT,
"JAMMFactory: INVALID_FEE"
);Fee Calculation
Trading Fees
Trading fees are deducted from the input token when calculating the swap amount. This logic is implemented in JAMMLibrary.sol:
Fee Distribution Mechanism
JAMM DEX features a unique dual fee distribution mechanism, implemented in the _collectFee function in JAMMPair.sol, which depends on whether a referrer is present:
Fee Distribution Explained
Case 1: No Referrer
Protocol Fee: Collects
(amountIn * fee) / 50000from the input token.Referrer Fee: 0.
Case 2: With Referrer
Protocol Fee: Collects
(amountIn * fee) / 100000from the input token.Referrer Fee: Collects
(amountIn * fee) / 100000from the input token.The fee is split evenly between the protocol and the referrer.
Protocol Fee Mechanism
In addition to direct trading fees, JAMM DEX can also collect a protocol fee by minting new LP tokens. This fee is sent to the mintTo address and is managed by the _mintFee function.
Protocol Fee Calculation
The protocol fee is calculated based on the growth of the liquidity pool (increase in the k value). When the total value of the pool grows due to accumulated trading fees, the protocol mints a proportional amount of new LP tokens as revenue.
Constant Product Validation (K-Value Check)
After each swap, the system verifies the constant product formula to ensure balance after fees are deducted. The swap function in JAMMPair.sol includes this check:
Fee Tier Selection Guide
0.5% Fee
Use Case: Stablecoin pairs (e.g., USDC/USDT), highly liquid and low-volatility assets.
Characteristics: Lowest trading cost, suitable for large trades and arbitrage.
1.0% Fee
Use Case: Mainstream token pairs (e.g., JU/USDC), medium-volatility assets.
Characteristics: Standard fee level, balancing user cost and LP returns.
2.0% Fee
Use Case: Medium-risk token pairs, new project tokens.
Characteristics: Provides higher returns for LPs to compensate for higher impermanent loss risk.
3.0% Fee
Use Case: High-risk, high-volatility tokens, niche or experimental tokens.
Characteristics: Highest LP returns to compensate for high risk and impermanent loss.
Fee Event
Every fee transfer triggers a Fee event:
This event logs the details of the fee distribution, allowing for on-chain data analysis and tracking.
Summary
The JAMM DEX fee structure has the following features:
Multi-Tier Fees: Four predefined fee tiers meet the needs of different assets.
Referral Incentives: A unique fee-sharing mechanism encourages community promotion.
Protocol Sustainability: Protocol fees collected by minting LP tokens ensure long-term development.
Transparency: All fee calculations and distributions are performed publicly on-chain.
Flexibility: Allows for the selection of the most appropriate fee tier for different types of asset pairs.
Understanding the fee structure is crucial for optimizing trading costs and maximizing LP returns.