Merge pull request #152 from logos-blockchain/simple_amm

initialize amm program PR
This commit is contained in:
Daniil Polyakov
2025-12-24 23:03:14 +03:00
committed by GitHub
27 changed files with 5169 additions and 15 deletions
Generated
+2
View File
@@ -2657,6 +2657,7 @@ name = "nssa"
version = "0.1.0"
dependencies = [
"borsh",
"bytemuck",
"hex",
"hex-literal 1.1.0",
"log",
@@ -3025,6 +3026,7 @@ version = "0.1.0"
dependencies = [
"clap",
"nssa",
"nssa_core",
"tokio",
"wallet",
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
View File
@@ -5,6 +5,7 @@ edition = "2024"
[dependencies]
nssa.workspace = true
nssa_core.workspace = true
wallet.workspace = true
tokio = { workspace = true, features = ["macros"] }
+1
View File
@@ -15,6 +15,7 @@ borsh.workspace = true
hex.workspace = true
secp256k1 = "0.31.1"
risc0-binfmt = "3.0.2"
bytemuck = "1.24.0"
log.workspace = true
[build-dependencies]
+2 -2
View File
@@ -9,7 +9,7 @@ borsh.workspace = true
serde = { workspace = true }
thiserror.workspace = true
chacha20 = { version = "0.9", default-features = false }
bytemuck = { workspace = true, optional = true }
bytemuck.workspace = true
k256 = { workspace = true, optional = true }
base58 = { workspace = true, optional = true }
anyhow = { workspace = true, optional = true }
@@ -19,4 +19,4 @@ serde_json.workspace = true
[features]
default = []
host = ["dep:bytemuck", "dep:k256", "dep:base58", "dep:anyhow"]
host = ["dep:k256", "dep:base58", "dep:anyhow"]
+20 -4
View File
@@ -15,7 +15,7 @@ pub type Nonce = u128;
/// Account to be used both in public and private contexts
#[derive(
Serialize, Deserialize, Clone, Default, PartialEq, Eq, BorshSerialize, BorshDeserialize,
Clone, Default, Eq, PartialEq, Serialize, Deserialize, BorshSerialize, BorshDeserialize,
)]
#[cfg_attr(any(feature = "host", test), derive(Debug))]
pub struct Account {
@@ -25,7 +25,7 @@ pub struct Account {
pub nonce: Nonce,
}
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
#[cfg_attr(any(feature = "host", test), derive(Debug))]
pub struct AccountWithMetadata {
pub account: Account,
@@ -45,9 +45,18 @@ impl AccountWithMetadata {
}
#[derive(
Copy, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, BorshSerialize, BorshDeserialize,
Copy,
Clone,
Default,
Serialize,
Deserialize,
PartialEq,
Eq,
Hash,
BorshSerialize,
BorshDeserialize,
)]
#[cfg_attr(any(feature = "host", test), derive(Debug, PartialOrd, Ord, Default))]
#[cfg_attr(any(feature = "host", test), derive(Debug, PartialOrd, Ord))]
pub struct AccountId {
value: [u8; 32],
}
@@ -180,4 +189,11 @@ mod tests {
let result = base58_str.parse::<AccountId>().unwrap_err();
assert!(matches!(result, AccountIdError::InvalidLength(_)));
}
#[test]
fn default_account_id() {
let default_account_id = AccountId::default();
let expected_account_id = AccountId::new([0; 32]);
assert!(default_account_id == expected_account_id);
}
}
+6 -6
View File
@@ -3,7 +3,7 @@ use std::collections::HashSet;
use risc0_zkvm::{DeserializeOwned, guest::env, serde::Deserializer};
use serde::{Deserialize, Serialize};
#[cfg(feature = "host")]
//#[cfg(feature = "host")]
use crate::account::AccountId;
use crate::account::{Account, AccountWithMetadata};
@@ -22,8 +22,8 @@ pub struct ProgramInput<T> {
/// Each program can derive up to `2^256` unique account IDs by choosing different
/// seeds. PDAs allow programs to control namespaced account identifiers without
/// collisions between programs.
#[derive(Serialize, Deserialize, Clone)]
#[cfg_attr(any(feature = "host", test), derive(Debug, PartialEq, Eq))]
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq)]
#[cfg_attr(any(feature = "host", test), derive(Debug))]
pub struct PdaSeed([u8; 32]);
impl PdaSeed {
@@ -32,7 +32,7 @@ impl PdaSeed {
}
}
#[cfg(feature = "host")]
//#[cfg(feature = "host")]
impl From<(&ProgramId, &PdaSeed)> for AccountId {
fn from(value: (&ProgramId, &PdaSeed)) -> Self {
use risc0_zkvm::sha::{Impl, Sha256};
@@ -54,8 +54,8 @@ impl From<(&ProgramId, &PdaSeed)> for AccountId {
}
}
#[derive(Serialize, Deserialize, Clone)]
#[cfg_attr(any(feature = "host", test), derive(Debug, PartialEq, Eq))]
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
#[cfg_attr(any(feature = "host", test), derive(Debug,))]
pub struct ChainedCall {
/// The program ID of the program to execute
pub program_id: ProgramId,
+5 -1
View File
@@ -7,7 +7,7 @@ use serde::Serialize;
use crate::{
error::NssaError,
program_methods::{AUTHENTICATED_TRANSFER_ELF, PINATA_ELF, TOKEN_ELF},
program_methods::{AMM_ELF, AUTHENTICATED_TRANSFER_ELF, PINATA_ELF, TOKEN_ELF},
};
/// Maximum number of cycles for a public execution.
@@ -95,6 +95,10 @@ impl Program {
// `program_methods`
Self::new(TOKEN_ELF.to_vec()).unwrap()
}
pub fn amm() -> Self {
Self::new(AMM_ELF.to_vec()).expect("The AMM program must be a valid Risc0 program")
}
}
// TODO: Testnet only. Refactor to prevent compilation on mainnet.
+1551 -2
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff