pub fn update_slope_changes_for_lock_update(
    storage: &mut dyn Storage,
    prev_user_locked_balance: &UserLockedBalance,
    new_user_locked_balance: &UserLockedBalance,
) -> StdResult<()> {
    // Get old slope
    let mut old_coefficient_changes = COEFFICIENT_CHANGES
        .may_load(
            storage,
            U64Key::from(prev_user_locked_balance.end_lock_time),
        )?
        .unwrap_or_default();

    // Remove prev token point slope
    old_coefficient_changes -= prev_user_locked_balance.voting_power_coefficients();

    if new_user_locked_balance.end_lock_time == prev_user_locked_balance.end_lock_time {
        // If new token point ends at the same location, update old coefficient changes accordingly

        // Add new coefficient changes

        old_coefficient_changes += new_user_locked_balance.voting_power_coefficients();
    } else {
        // If new token points ends at a new location,
        // read the corresponding slope, update it, and save it
        let mut new_coefficient_changes = COEFFICIENT_CHANGES
            .may_load(storage, U64Key::from(new_user_locked_balance.end_lock_time))?
            .unwrap_or_default();

        // Add new coefficient changes
        new_coefficient_changes += new_user_locked_balance.voting_power_coefficients();

        COEFFICIENT_CHANGES.save(
            storage,
            U64Key::from(new_user_locked_balance.end_lock_time),
            &new_coefficient_changes,
        )?;
    }

    // Save old_dslope
    COEFFICIENT_CHANGES.save(
        storage,
        U64Key::from(prev_user_locked_balance.end_lock_time),
        &old_coefficient_changes,
    )?;

    Ok(())
}
/// Update slope changes to schedule a reversal of the changes to made to state in
/// `update_state_for_lock_update`
Update slope changes to schedule a reversal of the changes to made to state in
`update_state_for_lock_update`
Update slope changes to schedule a reversal of the changes to made to state in ` update_state_for_lock_update `
pub fn update_slope_changes_for_lock_update(
    storage: &mut dyn Storage,
    prev_user_locked_balance: &UserLockedBalance,
    new_user_locked_balance: &UserLockedBalance,
) -> StdResult<()> {
    // Get old slope
    let mut old_coefficient_changes = COEFFICIENT_CHANGES
        .may_load(
            storage,
            U64Key::from(prev_user_locked_balance.end_lock_time),
        )?
        .unwrap_or_default();
    // Remove prev token point slope
    old_coefficient_changes -= prev_user_locked_balance.voting_power_coefficients();
    if new_user_locked_balance.end_lock_time == prev_user_locked_balance.end_lock_time {
        // If new token point ends at the same location, update old coefficient changes accordingly
        // Add new coefficient changes
        old_coefficient_changes += new_user_locked_balance.voting_power_coefficients();
    } else {
        // If new token points ends at a new location,
        // read the corresponding slope, update it, and save it
        let mut new_coefficient_changes = COEFFICIENT_CHANGES
            .may_load(storage, U64Key::from(new_user_locked_balance.end_lock_time))?
            .unwrap_or_default();
        // Add new coefficient changes
        new_coefficient_changes += new_user_locked_balance.voting_power_coefficients();
        COEFFICIENT_CHANGES.save(
            storage,
            U64Key::from(new_user_locked_balance.end_lock_time),
            &new_coefficient_changes,
        )?;
    }
    // Save old_dslope
    COEFFICIENT_CHANGES.save(
        storage,
        U64Key::from(prev_user_locked_balance.end_lock_time),
        &old_coefficient_changes,
    )?;
    Ok(())
}
pub fn update_slope_changes_for_lock_update ( storage : & mut dyn Storage , prev_user_locked_balance : & UserLockedBalance , new_user_locked_balance : & UserLockedBalance , ) -> StdResult < ( ) > { // Get old slope let mut old_coefficient_changes = COEFFICIENT_CHANGES . may_load ( storage , U64Key :: from ( prev_user_locked_balance . end_lock_time ) , ) ? . unwrap_or_default ( ) ; // Remove prev token point slope old_coefficient_changes -= prev_user_locked_balance . voting_power_coefficients ( ) ; if new_user_locked_balance . end_lock_time == prev_user_locked_balance . end_lock_time { // If new token point ends at the same location, update old coefficient changes accordingly // Add new coefficient changes old_coefficient_changes += new_user_locked_balance . voting_power_coefficients ( ) ; } else { // If new token points ends at a new location, // read the corresponding slope, update it, and save it let mut new_coefficient_changes = COEFFICIENT_CHANGES . may_load ( storage , U64Key :: from ( new_user_locked_balance . end_lock_time ) ) ? . unwrap_or_default ( ) ; // Add new coefficient changes new_coefficient_changes += new_user_locked_balance . voting_power_coefficients ( ) ; COEFFICIENT_CHANGES . save ( storage , U64Key :: from ( new_user_locked_balance . end_lock_time ) , & new_coefficient_changes , ) ? ; } // Save old_dslope COEFFICIENT_CHANGES . save ( storage , U64Key :: from ( prev_user_locked_balance . end_lock_time ) , & old_coefficient_changes , ) ? ; Ok ( ( ) ) }
Update slope changes to schedule a reversal of the changes to made to state in
`update_state_for_lock_update`
Update slope changes to schedule a reversal of the changes to made to state in ` update_state_for_lock_update `
storage
&mut dyn Storage
prev_user_locked_balance
&UserLockedBalance
new_user_locked_balance
&UserLockedBalance