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 configurationslast_update_timestamp: Timestamp of the last reward calculation update
Rewarder
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 millisecondreward_coin: Type name of the reward token
RewarderGlobalVault
Global storage for all reward token balances across the system.
Fields:
id: Unique identifier for the vaultbalances: Bag containing balance objects for each token type
Core Functions
Initialization
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 RewarderManagerRewardCoin: 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 RewarderManagerclock: 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 controlvault: Mutable reference to global vaultreward: Balance object containing tokens to deposit
Process:
Validate package version
Create balance entry if doesn't exist
Join deposited balance with existing balance
Emit deposit event
Withdraw Rewards
withdraw_reward<RewardCoin>()
Withdraws reward tokens from the global vault.
Parameters:
vault: Mutable reference to global vaultamount: 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
Error Codes
3000
E_TOO_MANY_REWARDERS
Exceeds maximum rewarders per pair
3001
E_REWARDER_ALREADY_EXISTS
Duplicate rewarder for token type
3003
E_INSUFFICIENT_BALANCE
Insufficient vault balance
3004
E_REWARDER_NOT_FOUND
Rewarder not found for token type
Events
Key Events
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