Fee Module
Manages the discrete price points and liquidity distribution across the price curve.
Fee Architecture Overview
┌──────────────────────────────────────────────────────────────────┐
│ Total Fee │
│ │
│ total_fee = base_fee + variable_fee │
│ capped at MAX_FEE (50% = 500,000,000) │
│ │
│ ┌────────────────────────┐ ┌─────────────────────────────────┐ │
│ │ Base Fee │ │ Variable Fee │ │
│ │ (Fee Scheduler) │ │ (Dynamic Fee) │ │
│ │ │ │ │ │
│ │ If scheduler enabled: │ │ If dynamic fee enabled: │ │
│ │ Linear or Exponential│ │ Based on volatility │ │
│ │ decay from cliff_fee │ │ accumulator × tick_spacing │ │
│ │ │ │ │ │
│ │ If scheduler disabled: │ │ If dynamic fee disabled: │ │
│ │ Static fee_rate │ │ 0 │ │
│ └─────────────────────────┘ └────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────┘PairParameters
Static Fee Fields
Field
Type
Description
Fee Scheduler Fields
Field
Type
Description
Dynamic Fee Config Fields
Field
Type
Description
Dynamic Fee State Fields (Updated on Every Swap)
Field
Type
Description
Fee Scheduler (Base Fee)
How It Works
get_total_fee_rate
get_base_fee
Linear Mode (fee_scheduler_mode = 0)
fee_scheduler_mode = 0)Exponential Mode (fee_scheduler_mode = 1)
fee_scheduler_mode = 1)get_current_number_period
Fee Scheduler Query Functions
Function
Returns
Description
Dynamic Fee (Variable Fee)
How It Works
get_variable_fee
Volatility Update Flow
Dynamic Fee Query Functions
Function
Returns
Description
Fee Helper (Validation & Calculation)
validate_dynamic_fee_parameters
validate_base_fee
Fee Amount Calculation Functions
General Query Functions
Function
Returns
Description
Constants Reference
Constant
Value
Description
Error Codes
fee_helper
Code
Constant
Description
pair_parameter_helper
Code
Constant
Description
Usage Examples
Reading Current Fee State
Fee Scheduler Timeline
Dynamic Fee Response to Volatility
Last updated