pub fn update_state_for_lock_update(
    state: &mut State,
    prev_user_locked_balance: &UserLockedBalance,
    new_user_locked_balance: &UserLockedBalance,
) {
    // Okay now we can update the state

    // Only remove the prev coefficients if the lock isn't expired
    // Otherwise the prev coefficients were already removed as part of coefficient changes
    if !prev_user_locked_balance.expired_at_timestamp(new_user_locked_balance.timestamp) {
        // Remove prev token slope and bias
        state.voting_power_coefficients -= prev_user_locked_balance.voting_power_coefficients();
    }

    // Remove prev point deposited amount
    // This is always removed even if prev_user_locked_balance is expired
    // Because deposited_amount removal isn't scheduled as part of slope changes
    // It only takes place when a user withdraws.
    state.total_deposit -= prev_user_locked_balance.deposited_amount;

    // Add new token slope and bias
    state.voting_power_coefficients += new_user_locked_balance.voting_power_coefficients();

    // Add new point deposited amount
    state.total_deposit += new_user_locked_balance.deposited_amount;

    // Update the timestamp of the state to match the new locked balance
    state.timestamp = new_user_locked_balance.timestamp;
}
/// Update state to incorporate lock update changes
Update state to incorporate lock update changes
Update state to incorporate lock update changes
pub fn update_state_for_lock_update(
    state: &mut State,
    prev_user_locked_balance: &UserLockedBalance,
    new_user_locked_balance: &UserLockedBalance,
) {
    // Okay now we can update the state
    // Only remove the prev coefficients if the lock isn't expired
    // Otherwise the prev coefficients were already removed as part of coefficient changes
    if !prev_user_locked_balance.expired_at_timestamp(new_user_locked_balance.timestamp) {
        // Remove prev token slope and bias
        state.voting_power_coefficients -= prev_user_locked_balance.voting_power_coefficients();
    }
    // Remove prev point deposited amount
    // This is always removed even if prev_user_locked_balance is expired
    // Because deposited_amount removal isn't scheduled as part of slope changes
    // It only takes place when a user withdraws.
    state.total_deposit -= prev_user_locked_balance.deposited_amount;
    // Add new token slope and bias
    state.voting_power_coefficients += new_user_locked_balance.voting_power_coefficients();
    // Add new point deposited amount
    state.total_deposit += new_user_locked_balance.deposited_amount;
    // Update the timestamp of the state to match the new locked balance
    state.timestamp = new_user_locked_balance.timestamp;
}
pub fn update_state_for_lock_update ( state : & mut State , prev_user_locked_balance : & UserLockedBalance , new_user_locked_balance : & UserLockedBalance , ) { // Okay now we can update the state // Only remove the prev coefficients if the lock isn't expired // Otherwise the prev coefficients were already removed as part of coefficient changes if ! prev_user_locked_balance . expired_at_timestamp ( new_user_locked_balance . timestamp ) { // Remove prev token slope and bias state . voting_power_coefficients -= prev_user_locked_balance . voting_power_coefficients ( ) ; } // Remove prev point deposited amount // This is always removed even if prev_user_locked_balance is expired // Because deposited_amount removal isn't scheduled as part of slope changes // It only takes place when a user withdraws. state . total_deposit -= prev_user_locked_balance . deposited_amount ; // Add new token slope and bias state . voting_power_coefficients += new_user_locked_balance . voting_power_coefficients ( ) ; // Add new point deposited amount state . total_deposit += new_user_locked_balance . deposited_amount ; // Update the timestamp of the state to match the new locked balance state . timestamp = new_user_locked_balance . timestamp ; }
Update state to incorporate lock update changes
Update state to incorporate lock update changes
state
&mut State
prev_user_locked_balance
&UserLockedBalance
new_user_locked_balance
&UserLockedBalance