mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-07-07 07:29:49 +00:00
fix(stablecoin): preserve clamped accrual progress
This commit is contained in:
parent
bc61f4cee9
commit
f55c8dd884
@ -16,7 +16,7 @@ use crate::shared::{
|
|||||||
/// Mints stablecoin debt against an existing position.
|
/// Mints stablecoin debt against an existing position.
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # 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.
|
/// be undercollateralized.
|
||||||
#[expect(
|
#[expect(
|
||||||
clippy::too_many_arguments,
|
clippy::too_many_arguments,
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use nssa_core::{
|
|||||||
use stablecoin_core::{
|
use stablecoin_core::{
|
||||||
compute_protocol_parameters_pda, compute_redemption_price_state_pda,
|
compute_protocol_parameters_pda, compute_redemption_price_state_pda,
|
||||||
compute_stability_fee_accumulator_pda, current_accumulated_rate, ProtocolParameters,
|
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 {
|
pub(crate) fn read_clock_timestamp(clock: &AccountWithMetadata) -> u64 {
|
||||||
@ -84,9 +84,17 @@ pub(crate) fn accrue_stability_fee_state(
|
|||||||
params: &ProtocolParameters,
|
params: &ProtocolParameters,
|
||||||
now: u64,
|
now: u64,
|
||||||
) -> StabilityFeeAccumulator {
|
) -> 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 {
|
StabilityFeeAccumulator {
|
||||||
accumulated_rate_at_last_accrual: current_accumulated_rate(accumulator, params, now),
|
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!(
|
assert_eq!(
|
||||||
updated.last_accrued_at,
|
updated.last_accrued_at,
|
||||||
MAXIMUM_COMPOUNDING_WINDOW_MILLISECONDS + 1
|
MAXIMUM_COMPOUNDING_WINDOW_MILLISECONDS
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user