Rewarder Module
Distributes additional rewards to liquidity provider
Data Structures
RewarderManager
The main structure that manages all rewarders for a specific pair.
struct RewarderManager has store {
rewarders: vector<Rewarder>,
last_update_timestamp: u64,
}
Fields:
rewarders: Vector containing up to 5 rewarder configurations
last_update_timestamp: Timestamp of the last reward calculation update
Individual rewarder configuration for a specific token type.
struct Rewarder has copy, drop, store {
emission_per_ms: u128,
reward_coin: TypeName
}
Fields:
emission_per_ms: Rate of token emission per millisecond
reward_coin: Type name of the reward token
RewarderGlobalVault
Global storage for all reward token balances across the system.
Fields:
id: Unique identifier for the vault
balances: Bag containing balance objects for each token type
new()
Creates a new RewarderManager instance.
Returns: Empty RewarderManager with no rewarders configured
add_rewarder<RewardCoin>()
Adds a new rewarder for a specific reward token type.
Parameters:
manager: Mutable reference to RewarderManager
RewardCoin: Type parameter for the reward token
Validations:
Maximum 5 rewarders per pair
No duplicate rewarders for the same token type
Reward Calculation
calculate_reward_emission()
Calculates and updates reward emissions based on elapsed time.
Parameters:
manager: Mutable reference to RewarderManager
clock: Clock object for timestamp access
Returns: Vector of reward amounts for each rewarder
Logic:
simulate_reward_emission()
Simulates reward calculation without updating the manager state.
Use Case: Preview reward amounts before actual distribution
Reward Management
Deposit Rewards
deposit_reward<RewardCoin>()
Deposits reward tokens into the global vault.
Parameters:
global_config: Global configuration for access control
vault: Mutable reference to global vault
reward: Balance object containing tokens to deposit
Process:
Create balance entry if doesn't exist
Join deposited balance with existing balance
Withdraw Rewards
withdraw_reward<RewardCoin>()
Withdraws reward tokens from the global vault.
Parameters:
vault: Mutable reference to global vault
amount: Amount to withdraw
Validations:
Rewarder must exist for the token type
Sufficient balance must be available
Emergency Withdrawal
emergent_withdraw<CoinType>()
Emergency withdrawal function for administrators.
Access Control:
Only pool managers can execute
Withdrawn funds sent to designated receiver
Exceeds maximum rewarders per pair
E_REWARDER_ALREADY_EXISTS
Duplicate rewarder for token type
Insufficient vault balance
Rewarder not found for token type
RewardEmissionUpdateEvent
Emitted when emission rates are updated.
DepositEvent
Emitted when tokens are deposited into the vault.
WithdrawEvent
Emitted when tokens are withdrawn from the vault.
Last updated