mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-02 13:23:10 +00:00
Merge pull request #152 from logos-blockchain/simple_amm
initialize amm program PR
This commit is contained in:
commit
28b64e87f5
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2657,6 +2657,7 @@ name = "nssa"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"borsh",
|
"borsh",
|
||||||
|
"bytemuck",
|
||||||
"hex",
|
"hex",
|
||||||
"hex-literal 1.1.0",
|
"hex-literal 1.1.0",
|
||||||
"log",
|
"log",
|
||||||
@ -3025,6 +3026,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"nssa",
|
"nssa",
|
||||||
|
"nssa_core",
|
||||||
"tokio",
|
"tokio",
|
||||||
"wallet",
|
"wallet",
|
||||||
]
|
]
|
||||||
|
|||||||
BIN
artifacts/program_methods/amm.bin
Normal file
BIN
artifacts/program_methods/amm.bin
Normal file
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -5,6 +5,7 @@ edition = "2024"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nssa.workspace = true
|
nssa.workspace = true
|
||||||
|
nssa_core.workspace = true
|
||||||
wallet.workspace = true
|
wallet.workspace = true
|
||||||
|
|
||||||
tokio = { workspace = true, features = ["macros"] }
|
tokio = { workspace = true, features = ["macros"] }
|
||||||
|
|||||||
@ -15,6 +15,7 @@ borsh.workspace = true
|
|||||||
hex.workspace = true
|
hex.workspace = true
|
||||||
secp256k1 = "0.31.1"
|
secp256k1 = "0.31.1"
|
||||||
risc0-binfmt = "3.0.2"
|
risc0-binfmt = "3.0.2"
|
||||||
|
bytemuck = "1.24.0"
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|||||||
@ -9,7 +9,7 @@ borsh.workspace = true
|
|||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
chacha20 = { version = "0.9", default-features = false }
|
chacha20 = { version = "0.9", default-features = false }
|
||||||
bytemuck = { workspace = true, optional = true }
|
bytemuck.workspace = true
|
||||||
k256 = { workspace = true, optional = true }
|
k256 = { workspace = true, optional = true }
|
||||||
base58 = { workspace = true, optional = true }
|
base58 = { workspace = true, optional = true }
|
||||||
anyhow = { workspace = true, optional = true }
|
anyhow = { workspace = true, optional = true }
|
||||||
@ -19,4 +19,4 @@ serde_json.workspace = true
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
host = ["dep:bytemuck", "dep:k256", "dep:base58", "dep:anyhow"]
|
host = ["dep:k256", "dep:base58", "dep:anyhow"]
|
||||||
|
|||||||
@ -15,7 +15,7 @@ pub type Nonce = u128;
|
|||||||
|
|
||||||
/// Account to be used both in public and private contexts
|
/// Account to be used both in public and private contexts
|
||||||
#[derive(
|
#[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))]
|
#[cfg_attr(any(feature = "host", test), derive(Debug))]
|
||||||
pub struct Account {
|
pub struct Account {
|
||||||
@ -25,7 +25,7 @@ pub struct Account {
|
|||||||
pub nonce: Nonce,
|
pub nonce: Nonce,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
|
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
|
||||||
#[cfg_attr(any(feature = "host", test), derive(Debug))]
|
#[cfg_attr(any(feature = "host", test), derive(Debug))]
|
||||||
pub struct AccountWithMetadata {
|
pub struct AccountWithMetadata {
|
||||||
pub account: Account,
|
pub account: Account,
|
||||||
@ -45,9 +45,18 @@ impl AccountWithMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[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 {
|
pub struct AccountId {
|
||||||
value: [u8; 32],
|
value: [u8; 32],
|
||||||
}
|
}
|
||||||
@ -180,4 +189,11 @@ mod tests {
|
|||||||
let result = base58_str.parse::<AccountId>().unwrap_err();
|
let result = base58_str.parse::<AccountId>().unwrap_err();
|
||||||
assert!(matches!(result, AccountIdError::InvalidLength(_)));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ use std::collections::HashSet;
|
|||||||
use risc0_zkvm::{DeserializeOwned, guest::env, serde::Deserializer};
|
use risc0_zkvm::{DeserializeOwned, guest::env, serde::Deserializer};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[cfg(feature = "host")]
|
//#[cfg(feature = "host")]
|
||||||
use crate::account::AccountId;
|
use crate::account::AccountId;
|
||||||
use crate::account::{Account, AccountWithMetadata};
|
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
|
/// Each program can derive up to `2^256` unique account IDs by choosing different
|
||||||
/// seeds. PDAs allow programs to control namespaced account identifiers without
|
/// seeds. PDAs allow programs to control namespaced account identifiers without
|
||||||
/// collisions between programs.
|
/// collisions between programs.
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq)]
|
||||||
#[cfg_attr(any(feature = "host", test), derive(Debug, PartialEq, Eq))]
|
#[cfg_attr(any(feature = "host", test), derive(Debug))]
|
||||||
pub struct PdaSeed([u8; 32]);
|
pub struct PdaSeed([u8; 32]);
|
||||||
|
|
||||||
impl PdaSeed {
|
impl PdaSeed {
|
||||||
@ -32,7 +32,7 @@ impl PdaSeed {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "host")]
|
//#[cfg(feature = "host")]
|
||||||
impl From<(&ProgramId, &PdaSeed)> for AccountId {
|
impl From<(&ProgramId, &PdaSeed)> for AccountId {
|
||||||
fn from(value: (&ProgramId, &PdaSeed)) -> Self {
|
fn from(value: (&ProgramId, &PdaSeed)) -> Self {
|
||||||
use risc0_zkvm::sha::{Impl, Sha256};
|
use risc0_zkvm::sha::{Impl, Sha256};
|
||||||
@ -54,8 +54,8 @@ impl From<(&ProgramId, &PdaSeed)> for AccountId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||||
#[cfg_attr(any(feature = "host", test), derive(Debug, PartialEq, Eq))]
|
#[cfg_attr(any(feature = "host", test), derive(Debug,))]
|
||||||
pub struct ChainedCall {
|
pub struct ChainedCall {
|
||||||
/// The program ID of the program to execute
|
/// The program ID of the program to execute
|
||||||
pub program_id: ProgramId,
|
pub program_id: ProgramId,
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use serde::Serialize;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::NssaError,
|
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.
|
/// Maximum number of cycles for a public execution.
|
||||||
@ -95,6 +95,10 @@ impl Program {
|
|||||||
// `program_methods`
|
// `program_methods`
|
||||||
Self::new(TOKEN_ELF.to_vec()).unwrap()
|
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.
|
// TODO: Testnet only. Refactor to prevent compilation on mainnet.
|
||||||
|
|||||||
1553
nssa/src/state.rs
1553
nssa/src/state.rs
File diff suppressed because it is too large
Load Diff
3581
program_methods/guest/src/bin/amm.rs
Normal file
3581
program_methods/guest/src/bin/amm.rs
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user