feat(stablecoin): expose initialize_program guest entry + e2e test

closes #164
This commit is contained in:
Andrea Franz
2026-08-20 14:21:58 +02:00
parent 0410d83ae4
commit ebc9b4b9fe
3 changed files with 370 additions and 1 deletions
@@ -12,6 +12,71 @@ mod stablecoin {
#[allow(unused_imports)]
use super::*;
/// Bootstrap the protocol (see spec §10.1 and host-function
/// `stablecoin_program::initialize_program::initialize_program`).
///
/// Wall-clock time is read from the system `CLOCK_01` account passed as the
/// 9th input — the pinned `ProgramContext` exposes no clock.
///
/// # Errors
/// Returns the host program's panic-converted error if any precondition
/// fails — see the host fn for the full list.
#[instruction]
#[allow(
clippy::too_many_arguments,
reason = "nine account inputs + the numerical params mirror the host function's ABI"
)]
pub fn initialize_program(
ctx: ProgramContext,
admin: AccountWithMetadata,
protocol_parameters: AccountWithMetadata,
stability_fee_accumulator: AccountWithMetadata,
redemption_price_state: AccountWithMetadata,
stablecoin_definition: AccountWithMetadata,
stablecoin_master_holding: AccountWithMetadata,
collateral_definition: AccountWithMetadata,
market_price_oracle: AccountWithMetadata,
clock: AccountWithMetadata,
freeze_authority_account_id: nssa_core::account::AccountId,
initial_stability_fee_per_millisecond: u128,
initial_controller_proportional_gain: i128,
initial_controller_integral_gain: i128,
initial_minimum_collateralization_ratio: u128,
minimum_milliseconds_between_rate_updates: u64,
maximum_oracle_price_age_milliseconds: u64,
initial_redemption_price: u128,
stablecoin_name: String,
) -> SpelResult {
let (post_states, chained_calls) =
stablecoin_program::initialize_program::initialize_program(
admin,
protocol_parameters,
stability_fee_accumulator,
redemption_price_state,
stablecoin_definition,
stablecoin_master_holding,
collateral_definition,
market_price_oracle,
clock,
ctx.self_program_id,
stablecoin_program::initialize_program::InitializeProgramParams {
freeze_authority_account_id,
initial_stability_fee_per_millisecond,
initial_controller_proportional_gain,
initial_controller_integral_gain,
initial_minimum_collateralization_ratio,
minimum_milliseconds_between_rate_updates,
maximum_oracle_price_age_milliseconds,
initial_redemption_price,
stablecoin_name: &stablecoin_name,
},
);
Ok(spel_framework::SpelOutput::execute(
post_states,
chained_calls,
))
}
/// Open a new collateral-only position for the calling owner.
///
/// # Errors