From 1679d5a4b8392f1fed5c8f7db7b0ce8d6c361175 Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Mon, 29 Jun 2026 12:35:08 -0300 Subject: [PATCH] fix(stablecoin): derive controller gain scale --- programs/integration_tests/tests/stablecoin.rs | 6 +++++- programs/stablecoin/src/redemption_controller.rs | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/programs/integration_tests/tests/stablecoin.rs b/programs/integration_tests/tests/stablecoin.rs index 450cb96..af61a8e 100644 --- a/programs/integration_tests/tests/stablecoin.rs +++ b/programs/integration_tests/tests/stablecoin.rs @@ -58,6 +58,10 @@ impl Ids { AccountId::new([8; 32]) } + fn oracle_source() -> AccountId { + AccountId::new([10; 32]) + } + fn redemption_controller() -> AccountId { compute_redemption_controller_pda( Self::stablecoin_program(), @@ -189,7 +193,7 @@ impl Accounts { quote_asset: Ids::collateral_definition(), price, timestamp, - source_id: String::from("twap"), + source_id: Ids::oracle_source(), confidence_interval: 0, }), nonce: Nonce(0), diff --git a/programs/stablecoin/src/redemption_controller.rs b/programs/stablecoin/src/redemption_controller.rs index 9f45433..f0783f6 100644 --- a/programs/stablecoin/src/redemption_controller.rs +++ b/programs/stablecoin/src/redemption_controller.rs @@ -2,11 +2,16 @@ use nssa_core::{ account::{Account, AccountId, AccountWithMetadata, Data}, program::{AccountPostState, ProgramId}, }; -use stablecoin_core::{verify_redemption_controller_and_get_seed, RedemptionController}; +use stablecoin_core::{ + verify_redemption_controller_and_get_seed, RedemptionController, CONTROLLER_GAIN_SCALE, +}; use token_core::TokenDefinition; use twap_oracle_core::OraclePriceAccount; -const CONTROLLER_GAIN_SCALE_I128: i128 = 1_000_000_000; +const CONTROLLER_GAIN_SCALE_I128: i128 = { + assert!(CONTROLLER_GAIN_SCALE <= i128::MAX as u128); + CONTROLLER_GAIN_SCALE as i128 +}; /// Initialize the redemption-rate feedback controller for one stablecoin/feed pair. /// @@ -345,6 +350,10 @@ mod tests { AccountId::new([3; 32]) } + fn oracle_source_id() -> AccountId { + AccountId::new([15; 32]) + } + fn controller_id() -> AccountId { compute_redemption_controller_pda( STABLECOIN_PROGRAM_ID, @@ -393,7 +402,7 @@ mod tests { quote_asset: collateral_definition_id(), price, timestamp, - source_id: "twap".to_owned(), + source_id: oracle_source_id(), confidence_interval: 0, }), nonce: Nonce(0),