Rewarder Module
Implements liquidity mining rewards to incentivize liquidity provision.
Core Data Structures
RewarderManager
The main controller that manages all rewarders for a pool:
struct RewarderManager {
rewarders: vector<Rewarder>, // Up to 5 rewarders
points_released: u128, // Total points released over time
points_growth_global: u128, // Global points growth rate
last_updated_time: u64, // Last settlement timestamp
}Rewarder
Individual rewarder configuration for a specific reward token:
struct Rewarder {
reward_coin: TypeName, // Type of reward token
emissions_per_second: u128, // Emission rate (tokens per second)
growth_global: u128, // Accumulated growth factor
}RewarderGlobalVault
Centralized storage for all reward token balances:
Core Functionality
Initialization
The module automatically creates a shared RewarderGlobalVault during initialization:
This vault serves as the central repository for all reward tokens across all pools.
Rewarder Management
Adding a New Rewarder
Adds a new rewarder for the specified
CoinTypeValidates that the coin type doesn't already exist
Enforces the maximum limit of 5 rewarders per pool
Initializes with zero emissions (must be configured separately)
Updating Emission Rates
Updates the emission rate for a specific rewarder
Automatically settles pending rewards before updating
Validates sufficient balance for 24 hours of rewards at the new rate
Requires vault balance ≥
86400 * new_emissionsfor rate increases
Reward Distribution
Settlement Process
The settlement process:
Time Validation: Ensures time progression is valid
Liquidity Check: Skips settlement if no liquidity or no time passed
Growth Calculation: For each rewarder with non-zero emissions:
Points Update: Updates global points tracking using a constant multiplier
Token Management
Depositing Rewards
Adds reward tokens to the global vault
Creates new balance entry if token type doesn't exist
Emits
DepositEventfor trackingReturns the final balance amount
Emergency Withdrawal
Admin-only function for emergency token withdrawal
Requires
AdminCapauthorizationEmits
EmergentWithdrawEventfor auditability
API Reference
Query Functions
Balance Queries
Rewarder Information
Individual Rewarder Data
Manager State
Friend Functions
These functions are restricted to the ferra_clmm::pool module:
Events
RewarderInitEvent
Emitted during module initialization:
DepositEvent
Emitted when rewards are deposited:
EmergentWithdrawEvent
Emitted during emergency withdrawals:
Error Codes
Error 1: Maximum number of rewarders exceeded (limit: 5)
Error 2: Rewarder for this coin type already exists
Error 3: Invalid time progression (current_time < last_updated_time)
Error 4: Insufficient balance in vault for new emission rate
Error 5: Rewarder not found for the specified coin type
Mathematical Formulas
Growth Calculation
For each rewarder during settlement:
Points Calculation
Using a constant multiplier (2^64 * 10^6):
Balance Validation
For emission rate increases:
Best Practices
Regular Settlement: Settle rewards before major pool operations
Sufficient Funding: Maintain adequate vault balances for sustained rewards
Gradual Rate Changes: Avoid sudden large emission rate changes
Monitor Events: Track all reward-related events for proper accounting
Emergency Procedures: Have clear protocols for emergency withdrawals
Last updated