fix(stablecoin): preserve clamped accrual progress

This commit is contained in:
Ricardo Guilherme Schmidt 2026-06-25 21:39:32 -03:00
parent 785876370c
commit 3e025c3694
No known key found for this signature in database
GPG Key ID: 1396EA17DE132FFE
3 changed files with 12 additions and 4 deletions

View File

@ -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,

View File

@ -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,
}
}

View File

@ -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
);
}