mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-07-03 05:29:50 +00:00
fix(stablecoin): preserve clamped accrual progress
This commit is contained in:
parent
785876370c
commit
3e025c3694
@ -16,7 +16,7 @@ use crate::shared::{
|
||||
/// Mints stablecoin debt against an existing position.
|
||||
///
|
||||
/// # Panics
|
||||
/// Panics if the position is not authorized, the oracle is stale, or the post-mint position would
|
||||
/// Panics if the owner is not authorized, the oracle is stale, or the post-mint position would
|
||||
/// be undercollateralized.
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
|
||||
@ -7,7 +7,7 @@ use nssa_core::{
|
||||
use stablecoin_core::{
|
||||
compute_protocol_parameters_pda, compute_redemption_price_state_pda,
|
||||
compute_stability_fee_accumulator_pda, current_accumulated_rate, ProtocolParameters,
|
||||
RedemptionPriceState, StabilityFeeAccumulator,
|
||||
RedemptionPriceState, StabilityFeeAccumulator, MAXIMUM_COMPOUNDING_WINDOW_MILLISECONDS,
|
||||
};
|
||||
|
||||
pub(crate) fn read_clock_timestamp(clock: &AccountWithMetadata) -> u64 {
|
||||
@ -84,9 +84,17 @@ pub(crate) fn accrue_stability_fee_state(
|
||||
params: &ProtocolParameters,
|
||||
now: u64,
|
||||
) -> StabilityFeeAccumulator {
|
||||
let elapsed = now
|
||||
.saturating_sub(accumulator.last_accrued_at)
|
||||
.min(MAXIMUM_COMPOUNDING_WINDOW_MILLISECONDS);
|
||||
let last_accrued_at = accumulator
|
||||
.last_accrued_at
|
||||
.checked_add(elapsed)
|
||||
.expect("Clamped elapsed timestamp cannot overflow");
|
||||
|
||||
StabilityFeeAccumulator {
|
||||
accumulated_rate_at_last_accrual: current_accumulated_rate(accumulator, params, now),
|
||||
last_accrued_at: now,
|
||||
last_accrued_at,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -685,7 +685,7 @@ fn accrue_stability_fee_clamps_elapsed_window() {
|
||||
);
|
||||
assert_eq!(
|
||||
updated.last_accrued_at,
|
||||
MAXIMUM_COMPOUNDING_WINDOW_MILLISECONDS + 1
|
||||
MAXIMUM_COMPOUNDING_WINDOW_MILLISECONDS
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user