For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 CoinType

  • Validates 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_emissions for rate increases

Reward Distribution

Settlement Process

The settlement process:

  1. Time Validation: Ensures time progression is valid

  2. Liquidity Check: Skips settlement if no liquidity or no time passed

  3. Growth Calculation: For each rewarder with non-zero emissions:

  4. 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 DepositEvent for tracking

  • Returns the final balance amount

Emergency Withdrawal

  • Admin-only function for emergency token withdrawal

  • Requires AdminCap authorization

  • Emits EmergentWithdrawEvent for 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

  1. Regular Settlement: Settle rewards before major pool operations

  2. Sufficient Funding: Maintain adequate vault balances for sustained rewards

  3. Gradual Rate Changes: Avoid sudden large emission rate changes

  4. Monitor Events: Track all reward-related events for proper accounting

  5. Emergency Procedures: Have clear protocols for emergency withdrawals

Last updated