fix(stablecoin): derive controller gain scale

This commit is contained in:
Ricardo Guilherme Schmidt 2026-06-29 12:35:08 -03:00
parent 61c3f6299f
commit 12ca678d01
No known key found for this signature in database
GPG Key ID: 1396EA17DE132FFE
2 changed files with 17 additions and 4 deletions

View File

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

View File

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