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.
struct RewarderGlobalVault has key, store {
id: UID,
balances: Bag,
}
Fields:
id
: Unique identifier for the vaultbalances
: Bag containing balance objects for each token type
Core Functions
Initialization
new()
Creates a new RewarderManager instance.
public(friend) fun new(): RewarderManager
Returns: Empty RewarderManager with no rewarders configured
add_rewarder<RewardCoin>()
Adds a new rewarder for a specific reward token type.
public(friend) fun add_rewarder<RewardCoin>(
manager: &mut RewarderManager
)
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.
public(friend) fun calculate_reward_emission(
manager: &mut RewarderManager,
clock: &Clock
): vector<u128>
Parameters:
manager
: Mutable reference to RewarderManagerclock
: Clock object for timestamp access
Returns: Vector of reward amounts for each rewarder
Logic:
reward_emission = emission_per_ms × (current_time - last_update_time)
simulate_reward_emission()
Simulates reward calculation without updating the manager state.
public fun simulate_reward_emission(
manager: &RewarderManager,
clock: &Clock
): vector<u128>
Use Case: Preview reward amounts before actual distribution
Reward Management
Deposit Rewards
deposit_reward<RewardCoin>()
Deposits reward tokens into the global vault.
public fun deposit_reward<RewardCoin>(
global_config: &GlobalConfig,
vault: &mut RewarderGlobalVault,
reward: Balance<RewardCoin>
)
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.
public(friend) fun withdraw_reward<RewardCoin>(
vault: &mut RewarderGlobalVault,
amount: u64,
): Balance<RewardCoin>
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.
public fun emergent_withdraw<CoinType>(
global_config: &GlobalConfig,
vault: &mut RewarderGlobalVault,
amount: u64,
ctx: &mut TxContext
)
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
struct RewardEmissionUpdateEvent has copy, drop {
pair: ID,
reward_type: TypeName,
old_emission: u128,
new_emission: u128,
}
Emitted when emission rates are updated.
DepositEvent
struct DepositEvent has copy, drop {
vault: ID,
reward_type: TypeName,
amount: u64,
total_balance: u64,
}
Emitted when tokens are deposited into the vault.
WithdrawEvent
struct WithdrawEvent has copy, drop {
vault: ID,
reward_type: TypeName,
amount: u64,
remaining_balance: u64,
}
Emitted when tokens are withdrawn from the vault.
Last updated