fn compute_reward(config: &Config, state: &mut State, timestamp: u64) {
    compute_state_extra(config, state, timestamp);

    if state.total_bond_amount.is_zero() {
        state.last_distributed = timestamp;
        return;
    }

    let mut distributed_amount: Uint128 = Uint128::zero();
    let s = config.distribution_schedule;
    if s.0 < timestamp && s.1 > state.last_distributed {
        let time_passed =
            std::cmp::min(s.1, timestamp) - std::cmp::max(s.0, state.last_distributed);
        let duration = s.1 - s.0;
        let distribution_rate: Decimal = Decimal::from_ratio(s.2, duration);
        distributed_amount += distribution_rate * Uint128::from(time_passed as u128);
    }

    state.last_distributed = timestamp;
    state.global_reward_index = state.global_reward_index
        + Decimal::from_ratio(distributed_amount, state.total_bond_amount);
}
// compute distributed rewards and update global reward index
compute distributed rewards and update global reward index
compute distributed rewards and update global reward index
fn compute_reward(config: &Config, state: &mut State, timestamp: u64) {
    compute_state_extra(config, state, timestamp);
    if state.total_bond_amount.is_zero() {
        state.last_distributed = timestamp;
        return;
    }
    let mut distributed_amount: Uint128 = Uint128::zero();
    let s = config.distribution_schedule;
    if s.0 < timestamp && s.1 > state.last_distributed {
        let time_passed =
            std::cmp::min(s.1, timestamp) - std::cmp::max(s.0, state.last_distributed);
        let duration = s.1 - s.0;
        let distribution_rate: Decimal = Decimal::from_ratio(s.2, duration);
        distributed_amount += distribution_rate * Uint128::from(time_passed as u128);
    }
    state.last_distributed = timestamp;
    state.global_reward_index = state.global_reward_index
        + Decimal::from_ratio(distributed_amount, state.total_bond_amount);
}
fn compute_reward ( config : & Config , state : & mut State , timestamp : u64 ) { compute_state_extra ( config , state , timestamp ) ; if state . total_bond_amount . is_zero ( ) { state . last_distributed = timestamp ; return ; } let mut distributed_amount : Uint128 = Uint128 :: zero ( ) ; let s = config . distribution_schedule ; if s . 0 < timestamp && s . 1 > state . last_distributed { let time_passed = std :: cmp :: min ( s . 1 , timestamp ) - std :: cmp :: max ( s . 0 , state . last_distributed ) ; let duration = s . 1 - s . 0 ; let distribution_rate : Decimal = Decimal :: from_ratio ( s . 2 , duration ) ; distributed_amount += distribution_rate * Uint128 :: from ( time_passed as u128 ) ; } state . last_distributed = timestamp ; state . global_reward_index = state . global_reward_index + Decimal :: from_ratio ( distributed_amount , state . total_bond_amount ) ; }
compute distributed rewards and update global reward index
compute distributed rewards and update global reward index
config
&Config
state
&mut State
timestamp
u64
config
&Config
state
&mut State
timestamp
u64