2026-05-11 14:51:50 +02:00
|
|
|
#![no_main]
|
|
|
|
|
|
2026-05-12 13:04:59 -03:00
|
|
|
use nssa_core::account::AccountWithMetadata;
|
|
|
|
|
use spel_framework::context::ProgramContext;
|
2026-05-11 14:51:50 +02:00
|
|
|
use spel_framework::prelude::*;
|
|
|
|
|
|
|
|
|
|
risc0_zkvm::guest::entry!(main);
|
|
|
|
|
|
|
|
|
|
#[lez_program(instruction = "stablecoin_core::Instruction")]
|
|
|
|
|
mod stablecoin {
|
2026-05-12 13:04:59 -03:00
|
|
|
#[allow(unused_imports)]
|
2026-05-11 14:51:50 +02:00
|
|
|
use super::*;
|
|
|
|
|
|
feat(stablecoin): implement `open_position`
Adds the `open_position` instruction to the Stablecoin Program. The instruction
claims a per-owner `Position` PDA, initializes a collateral vault token holding
via a chained `Token::InitializeAccount` under the vault's PDA authority, and
moves `collateral_amount` from the user's holding into the vault with a chained
`Token::Transfer`. `Position` is persisted with `collateral_amount` and
`debt_amount = 0`; the debt path is deferred to `generate_debt`.
- Add `Position` struct, `OpenPosition` instruction variant, and
`compute_position_pda{,_seed}` / `compute_position_vault_pda{,_seed}` helpers
in `stablecoin_core` with domain-separated PDA seeds.
- Implement `open_position::open_position` mirroring the ATA `create` and AMM
`new_definition` patterns: authorization and uninitialized-state asserts, PDA
verification, and same-transaction chained `InitializeAccount` + `Transfer`.
- Wire the new instruction through the SPEL guest and regenerate the stablecoin
IDL artifact.
- Cover the happy path, all assertion paths, and PDA determinism /
non-collision in 11 new unit tests.
2026-05-11 17:14:27 -03:00
|
|
|
/// Open a new collateral-only position for the calling owner.
|
|
|
|
|
///
|
|
|
|
|
/// # Errors
|
|
|
|
|
/// Returns the host program's panic-converted error if any precondition fails (see
|
|
|
|
|
/// [`stablecoin_program::open_position::open_position`] for the full list).
|
|
|
|
|
#[instruction]
|
|
|
|
|
pub fn open_position(
|
2026-05-12 13:04:59 -03:00
|
|
|
ctx: ProgramContext,
|
feat(stablecoin): implement `open_position`
Adds the `open_position` instruction to the Stablecoin Program. The instruction
claims a per-owner `Position` PDA, initializes a collateral vault token holding
via a chained `Token::InitializeAccount` under the vault's PDA authority, and
moves `collateral_amount` from the user's holding into the vault with a chained
`Token::Transfer`. `Position` is persisted with `collateral_amount` and
`debt_amount = 0`; the debt path is deferred to `generate_debt`.
- Add `Position` struct, `OpenPosition` instruction variant, and
`compute_position_pda{,_seed}` / `compute_position_vault_pda{,_seed}` helpers
in `stablecoin_core` with domain-separated PDA seeds.
- Implement `open_position::open_position` mirroring the ATA `create` and AMM
`new_definition` patterns: authorization and uninitialized-state asserts, PDA
verification, and same-transaction chained `InitializeAccount` + `Transfer`.
- Wire the new instruction through the SPEL guest and regenerate the stablecoin
IDL artifact.
- Cover the happy path, all assertion paths, and PDA determinism /
non-collision in 11 new unit tests.
2026-05-11 17:14:27 -03:00
|
|
|
owner: AccountWithMetadata,
|
|
|
|
|
position: AccountWithMetadata,
|
|
|
|
|
vault: AccountWithMetadata,
|
|
|
|
|
user_holding: AccountWithMetadata,
|
|
|
|
|
token_definition: AccountWithMetadata,
|
|
|
|
|
collateral_amount: u128,
|
|
|
|
|
) -> SpelResult {
|
|
|
|
|
let (post_states, chained_calls) = stablecoin_program::open_position::open_position(
|
|
|
|
|
owner,
|
|
|
|
|
position,
|
|
|
|
|
vault,
|
|
|
|
|
user_holding,
|
|
|
|
|
token_definition,
|
2026-05-12 13:04:59 -03:00
|
|
|
ctx.self_program_id,
|
feat(stablecoin): implement `open_position`
Adds the `open_position` instruction to the Stablecoin Program. The instruction
claims a per-owner `Position` PDA, initializes a collateral vault token holding
via a chained `Token::InitializeAccount` under the vault's PDA authority, and
moves `collateral_amount` from the user's holding into the vault with a chained
`Token::Transfer`. `Position` is persisted with `collateral_amount` and
`debt_amount = 0`; the debt path is deferred to `generate_debt`.
- Add `Position` struct, `OpenPosition` instruction variant, and
`compute_position_pda{,_seed}` / `compute_position_vault_pda{,_seed}` helpers
in `stablecoin_core` with domain-separated PDA seeds.
- Implement `open_position::open_position` mirroring the ATA `create` and AMM
`new_definition` patterns: authorization and uninitialized-state asserts, PDA
verification, and same-transaction chained `InitializeAccount` + `Transfer`.
- Wire the new instruction through the SPEL guest and regenerate the stablecoin
IDL artifact.
- Cover the happy path, all assertion paths, and PDA determinism /
non-collision in 11 new unit tests.
2026-05-11 17:14:27 -03:00
|
|
|
collateral_amount,
|
|
|
|
|
);
|
2026-05-12 13:04:59 -03:00
|
|
|
Ok(spel_framework::SpelOutput::execute(
|
|
|
|
|
post_states,
|
|
|
|
|
chained_calls,
|
|
|
|
|
))
|
feat(stablecoin): implement `open_position`
Adds the `open_position` instruction to the Stablecoin Program. The instruction
claims a per-owner `Position` PDA, initializes a collateral vault token holding
via a chained `Token::InitializeAccount` under the vault's PDA authority, and
moves `collateral_amount` from the user's holding into the vault with a chained
`Token::Transfer`. `Position` is persisted with `collateral_amount` and
`debt_amount = 0`; the debt path is deferred to `generate_debt`.
- Add `Position` struct, `OpenPosition` instruction variant, and
`compute_position_pda{,_seed}` / `compute_position_vault_pda{,_seed}` helpers
in `stablecoin_core` with domain-separated PDA seeds.
- Implement `open_position::open_position` mirroring the ATA `create` and AMM
`new_definition` patterns: authorization and uninitialized-state asserts, PDA
verification, and same-transaction chained `InitializeAccount` + `Transfer`.
- Wire the new instruction through the SPEL guest and regenerate the stablecoin
IDL artifact.
- Cover the happy path, all assertion paths, and PDA determinism /
non-collision in 11 new unit tests.
2026-05-11 17:14:27 -03:00
|
|
|
}
|
2026-05-11 14:51:50 +02:00
|
|
|
}
|