mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-08-26 22:51:14 +00:00
refactor: move programs into programs and UIs into apps
This refactors the repository structure as it has grown over time.
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "stablecoin-methods"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[build-dependencies]
|
||||
risc0-build = "=3.0.5"
|
||||
|
||||
[dependencies]
|
||||
risc0-zkvm = { version = "=3.0.5", features = ["std"] }
|
||||
stablecoin_core = { path = "../core" }
|
||||
|
||||
[package.metadata.risc0]
|
||||
methods = ["guest"]
|
||||
@@ -0,0 +1,4 @@
|
||||
//! Build script that embeds the stablecoin RISC Zero guest ELF as host-side constants.
|
||||
fn main() {
|
||||
risc0_build::embed_methods();
|
||||
}
|
||||
+4059
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "stablecoin-guest"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[workspace]
|
||||
|
||||
[[bin]]
|
||||
name = "stablecoin"
|
||||
path = "src/bin/stablecoin.rs"
|
||||
|
||||
[dependencies]
|
||||
spel-framework = { git = "https://github.com/logos-co/spel.git", tag = "v0.3.0", package = "spel-framework" }
|
||||
nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc3" }
|
||||
risc0-zkvm = { version = "=3.0.5", default-features = false }
|
||||
twap_oracle_core = { path = "../../../twap_oracle/core" }
|
||||
stablecoin_core = { path = "../../core" }
|
||||
stablecoin_program = { path = "../..", package = "stablecoin_program" }
|
||||
token_core = { path = "../../../token/core" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
borsh = "1.5"
|
||||
@@ -0,0 +1,105 @@
|
||||
#![cfg_attr(not(test), no_main)]
|
||||
|
||||
use nssa_core::account::AccountWithMetadata;
|
||||
use spel_framework::context::ProgramContext;
|
||||
use spel_framework::prelude::*;
|
||||
|
||||
#[cfg(not(test))]
|
||||
risc0_zkvm::guest::entry!(main);
|
||||
|
||||
#[lez_program(instruction = "stablecoin_core::Instruction")]
|
||||
mod stablecoin {
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
|
||||
/// 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(
|
||||
ctx: ProgramContext,
|
||||
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,
|
||||
ctx.self_program_id,
|
||||
collateral_amount,
|
||||
);
|
||||
Ok(spel_framework::SpelOutput::execute(
|
||||
post_states,
|
||||
chained_calls,
|
||||
))
|
||||
}
|
||||
|
||||
/// Withdraw `amount` collateral tokens from an existing position back to a
|
||||
/// user-controlled holding.
|
||||
///
|
||||
/// # Errors
|
||||
/// Returns the host program's panic-converted error if any precondition
|
||||
/// fails (see
|
||||
/// [`stablecoin_program::withdraw_collateral::withdraw_collateral`] for the
|
||||
/// full list).
|
||||
#[instruction]
|
||||
pub fn withdraw_collateral(
|
||||
ctx: ProgramContext,
|
||||
owner: AccountWithMetadata,
|
||||
position: AccountWithMetadata,
|
||||
vault: AccountWithMetadata,
|
||||
destination: AccountWithMetadata,
|
||||
amount: u128,
|
||||
) -> SpelResult {
|
||||
let (post_states, chained_calls) =
|
||||
stablecoin_program::withdraw_collateral::withdraw_collateral(
|
||||
owner,
|
||||
position,
|
||||
vault,
|
||||
destination,
|
||||
ctx.self_program_id,
|
||||
amount,
|
||||
);
|
||||
Ok(spel_framework::SpelOutput::execute(
|
||||
post_states,
|
||||
chained_calls,
|
||||
))
|
||||
}
|
||||
|
||||
/// Repay `amount` of outstanding stablecoin debt against an existing position.
|
||||
///
|
||||
/// # Errors
|
||||
/// Returns the host program's panic-converted error if any precondition
|
||||
/// fails (see [`stablecoin_program::repay_debt::repay_debt`] for the
|
||||
/// full list).
|
||||
#[instruction]
|
||||
pub fn repay_debt(
|
||||
ctx: ProgramContext,
|
||||
owner: AccountWithMetadata,
|
||||
position: AccountWithMetadata,
|
||||
stablecoin_definition: AccountWithMetadata,
|
||||
user_stablecoin_holding: AccountWithMetadata,
|
||||
amount: u128,
|
||||
) -> SpelResult {
|
||||
let (post_states, chained_calls) = stablecoin_program::repay_debt::repay_debt(
|
||||
owner,
|
||||
position,
|
||||
stablecoin_definition,
|
||||
user_stablecoin_holding,
|
||||
ctx.self_program_id,
|
||||
amount,
|
||||
);
|
||||
Ok(spel_framework::SpelOutput::execute(
|
||||
post_states,
|
||||
chained_calls,
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
//! Host-side embedding of the stablecoin RISC Zero guest ELF.
|
||||
//!
|
||||
//! Re-exports the constants produced by `build.rs` via `risc0_build::embed_methods` —
|
||||
//! `STABLECOIN_ELF`, `STABLECOIN_PATH`, and `STABLECOIN_ID` — used by host code to
|
||||
//! load and identify the guest binary.
|
||||
|
||||
#![allow(
|
||||
missing_docs,
|
||||
reason = "constants below are generated by risc0_build::embed_methods at build time"
|
||||
)]
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/methods.rs"));
|
||||
Reference in New Issue
Block a user