ore_boost_api/state/
boost.rs

1use ore_api::state::Proof;
2use steel::*;
3
4use super::{BoostAccount, Config, OldBoostAccount};
5
6/// Boost tracks the priority, deposits, and rewards of a staking incentive.
7#[repr(C)]
8#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
9pub struct Boost {
10    /// The unix timestamp this boost expires.
11    pub expires_at: i64,
12
13    /// The config rewards factor the last time rewards were collected by this boost.
14    pub last_rewards_factor: Numeric,
15
16    /// The mint address of the token associated with this boost.
17    pub mint: Pubkey,
18
19    /// The cumulative rewards collected by this boost, divided by the total deposits at the time of collection.
20    pub rewards_factor: Numeric,
21
22    /// The total amount of stake deposited in this boost.
23    pub total_deposits: u64,
24
25    /// The number of stakers in this boost.
26    pub total_stakers: u64,
27
28    /// The weight of this boost relative to other boosts.
29    pub weight: u64,
30
31    /// A protocol fee charged for withdrawing from this boost (in basis points).
32    pub withdraw_fee: u64,
33}
34
35impl Boost {
36    /// Collect weighted rewards from the global rewards pool.
37    pub(crate) fn collect_rewards(&mut self, config: &mut Config, proof: &Proof) {
38        // Increment the global rewards factor
39        if config.total_weight > 0 {
40            config.rewards_factor += Numeric::from_fraction(proof.balance, config.total_weight);
41        }
42
43        // Accumulate weighted rewards into the boost rewards factor
44        if config.rewards_factor > self.last_rewards_factor {
45            let accumulated_rewards = config.rewards_factor - self.last_rewards_factor;
46            if accumulated_rewards < Numeric::ZERO {
47                panic!("Accumulated rewards is negative");
48            }
49            let boost_rewards = accumulated_rewards * Numeric::from_u64(self.weight);
50            self.rewards_factor += boost_rewards / Numeric::from_u64(self.total_deposits);
51        }
52
53        // Update this boost's last seen rewards factor
54        self.last_rewards_factor = config.rewards_factor;
55    }
56}
57
58account!(BoostAccount, Boost);
59
60/// Boost tracks the priority, deposits, and rewards of a staking incentive.
61#[repr(C)]
62#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
63pub struct OldBoost {
64    /// The unix timestamp this boost expires.
65    pub expires_at: i64,
66
67    /// The mint address of the token associated with this boost.
68    pub mint: Pubkey,
69
70    /// The take rate in basis points (1/100th of a percent).
71    pub bps: u64,
72
73    /// The cumulative rewards collected by this boost, divided by the total deposits at the time of collection.
74    pub rewards_factor: Numeric,
75
76    /// The total amount of stake deposited in this boost.
77    pub total_deposits: u64,
78
79    /// The number of stakers in this boost.
80    pub total_stakers: u64,
81
82    /// A protocol fee charged for withdrawing from this boost (in basis points).
83    pub withdraw_fee: u64,
84
85    /// A buffer for future config variables.
86    pub _buffer: [u8; 1024],
87}
88
89account!(OldBoostAccount, OldBoost);