From 590d60cabd5ac2832e73ced708bf9d3b3b47644f Mon Sep 17 00:00:00 2001 From: Andrea Franz Date: Mon, 11 May 2026 14:51:50 +0200 Subject: [PATCH] feat(stablecoin): initial stablecoin scaffold closes #86 --- Cargo.lock | 26 +++++++++++++++++++ Cargo.toml | 6 +++++ artifacts/stablecoin-idl.json | 19 ++++++++++++++ stablecoin/Cargo.toml | 8 ++++++ stablecoin/core/Cargo.toml | 9 +++++++ stablecoin/core/src/lib.rs | 6 +++++ stablecoin/methods/Cargo.toml | 14 ++++++++++ stablecoin/methods/build.rs | 3 +++ stablecoin/methods/guest/Cargo.toml | 19 ++++++++++++++ .../methods/guest/src/bin/stablecoin.rs | 19 ++++++++++++++ stablecoin/methods/src/lib.rs | 1 + stablecoin/src/lib.rs | 8 ++++++ stablecoin/src/noop.rs | 5 ++++ stablecoin/src/tests.rs | 12 +++++++++ 14 files changed, 155 insertions(+) create mode 100644 artifacts/stablecoin-idl.json create mode 100644 stablecoin/Cargo.toml create mode 100644 stablecoin/core/Cargo.toml create mode 100644 stablecoin/core/src/lib.rs create mode 100644 stablecoin/methods/Cargo.toml create mode 100644 stablecoin/methods/build.rs create mode 100644 stablecoin/methods/guest/Cargo.toml create mode 100644 stablecoin/methods/guest/src/bin/stablecoin.rs create mode 100644 stablecoin/methods/src/lib.rs create mode 100644 stablecoin/src/lib.rs create mode 100644 stablecoin/src/noop.rs create mode 100644 stablecoin/src/tests.rs diff --git a/Cargo.lock b/Cargo.lock index 9732e53..7c075a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3016,6 +3016,32 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" +[[package]] +name = "stablecoin-methods" +version = "0.1.0" +dependencies = [ + "risc0-build", + "risc0-zkvm", + "stablecoin_core", +] + +[[package]] +name = "stablecoin_core" +version = "0.1.0" +dependencies = [ + "borsh", + "nssa_core", + "serde", +] + +[[package]] +name = "stablecoin_program" +version = "0.1.0" +dependencies = [ + "nssa_core", + "stablecoin_core", +] + [[package]] name = "strsim" version = "0.11.1" diff --git a/Cargo.toml b/Cargo.toml index 7021e21..8ad0cb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,9 @@ members = [ "ata/core", "ata", "ata/methods", + "stablecoin/core", + "stablecoin", + "stablecoin/methods", "integration_tests", "tools/idl-gen", ] @@ -16,6 +19,7 @@ exclude = [ "token/methods/guest", "amm/methods/guest", "ata/methods/guest", + "stablecoin/methods/guest", ] resolver = "2" @@ -28,6 +32,8 @@ amm_core = { path = "amm/core" } amm_program = { path = "amm" } ata_core = { path = "ata/core" } ata_program = { path = "ata" } +stablecoin_core = { path = "stablecoin/core" } +stablecoin_program = { path = "stablecoin" } serde = { version = "1.0", features = ["derive"] } borsh = { version = "1.0", features = ["derive"] } risc0-zkvm = { version = "=3.0.5" } diff --git a/artifacts/stablecoin-idl.json b/artifacts/stablecoin-idl.json new file mode 100644 index 0000000..27c8a2b --- /dev/null +++ b/artifacts/stablecoin-idl.json @@ -0,0 +1,19 @@ +{ + "version": "0.1.0", + "name": "stablecoin", + "instructions": [ + { + "name": "noop", + "accounts": [ + { + "name": "account", + "writable": false, + "signer": false, + "init": false + } + ], + "args": [] + } + ], + "instruction_type": "stablecoin_core::Instruction" +} diff --git a/stablecoin/Cargo.toml b/stablecoin/Cargo.toml new file mode 100644 index 0000000..30f7325 --- /dev/null +++ b/stablecoin/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "stablecoin_program" +version = "0.1.0" +edition = "2021" + +[dependencies] +nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc1", features = ["host"] } +stablecoin_core = { path = "core" } diff --git a/stablecoin/core/Cargo.toml b/stablecoin/core/Cargo.toml new file mode 100644 index 0000000..49fc14a --- /dev/null +++ b/stablecoin/core/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "stablecoin_core" +version = "0.1.0" +edition = "2021" + +[dependencies] +nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc1", features = ["host"] } +borsh = { version = "1.5", features = ["derive"] } +serde = { version = "1.0", features = ["derive"] } diff --git a/stablecoin/core/src/lib.rs b/stablecoin/core/src/lib.rs new file mode 100644 index 0000000..c006cdc --- /dev/null +++ b/stablecoin/core/src/lib.rs @@ -0,0 +1,6 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize)] +pub enum Instruction { + Noop, +} diff --git a/stablecoin/methods/Cargo.toml b/stablecoin/methods/Cargo.toml new file mode 100644 index 0000000..500a193 --- /dev/null +++ b/stablecoin/methods/Cargo.toml @@ -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"] diff --git a/stablecoin/methods/build.rs b/stablecoin/methods/build.rs new file mode 100644 index 0000000..08a8a4e --- /dev/null +++ b/stablecoin/methods/build.rs @@ -0,0 +1,3 @@ +fn main() { + risc0_build::embed_methods(); +} diff --git a/stablecoin/methods/guest/Cargo.toml b/stablecoin/methods/guest/Cargo.toml new file mode 100644 index 0000000..4336b98 --- /dev/null +++ b/stablecoin/methods/guest/Cargo.toml @@ -0,0 +1,19 @@ +[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", rev = "9e7f2754e1d4cdb3ea36e63b1ff86c3af55488d3", package = "spel-framework" } +nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc1" } +risc0-zkvm = { version = "=3.0.5", default-features = false } +stablecoin_core = { path = "../../core" } +stablecoin_program = { path = "../..", package = "stablecoin_program" } +serde = { version = "1.0", features = ["derive"] } +borsh = "1.5" diff --git a/stablecoin/methods/guest/src/bin/stablecoin.rs b/stablecoin/methods/guest/src/bin/stablecoin.rs new file mode 100644 index 0000000..c776bf6 --- /dev/null +++ b/stablecoin/methods/guest/src/bin/stablecoin.rs @@ -0,0 +1,19 @@ +#![no_main] + +use nssa_core::account::AccountWithMetadata; +use spel_framework::prelude::*; + +risc0_zkvm::guest::entry!(main); + +#[lez_program(instruction = "stablecoin_core::Instruction")] +mod stablecoin { + #[allow(unused_imports)] + use super::*; + + #[instruction] + pub fn noop(account: AccountWithMetadata) -> SpelResult { + Ok(SpelOutput::states_only(stablecoin_program::noop::noop( + account, + ))) + } +} diff --git a/stablecoin/methods/src/lib.rs b/stablecoin/methods/src/lib.rs new file mode 100644 index 0000000..1bdb308 --- /dev/null +++ b/stablecoin/methods/src/lib.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/methods.rs")); diff --git a/stablecoin/src/lib.rs b/stablecoin/src/lib.rs new file mode 100644 index 0000000..54cd98d --- /dev/null +++ b/stablecoin/src/lib.rs @@ -0,0 +1,8 @@ +//! The Stablecoin Program implementation. + +pub use stablecoin_core as core; + +pub mod noop; + +#[cfg(test)] +mod tests; diff --git a/stablecoin/src/noop.rs b/stablecoin/src/noop.rs new file mode 100644 index 0000000..e1303b0 --- /dev/null +++ b/stablecoin/src/noop.rs @@ -0,0 +1,5 @@ +use nssa_core::{account::AccountWithMetadata, program::AccountPostState}; + +pub fn noop(account: AccountWithMetadata) -> Vec { + vec![AccountPostState::new(account.account)] +} diff --git a/stablecoin/src/tests.rs b/stablecoin/src/tests.rs new file mode 100644 index 0000000..2321f7c --- /dev/null +++ b/stablecoin/src/tests.rs @@ -0,0 +1,12 @@ +use nssa_core::account::{Account, AccountId, AccountWithMetadata}; + +#[test] +fn noop_returns_single_post_state() { + let account = AccountWithMetadata { + account: Account::default(), + is_authorized: false, + account_id: AccountId::new([0u8; 32]), + }; + let post_states = crate::noop::noop(account); + assert_eq!(post_states.len(), 1); +}