From 630f807108f894c9e4f9d0ce8b6d80cd588d4457 Mon Sep 17 00:00:00 2001 From: r4bbit <445106+0x-r4bbit@users.noreply.github.com> Date: Tue, 5 May 2026 15:44:48 +0200 Subject: [PATCH] feat: make use of spel's `[#account]` directive This annotates custom account data as `[#account]`, to allow for deserializing abritrary LEZ account data. Closes #49 --- Cargo.lock | 24 +++- Cargo.toml | 4 +- amm/Cargo.toml | 2 +- amm/core/Cargo.toml | 3 +- amm/core/src/lib.rs | 14 ++- amm/methods/guest/Cargo.lock | 14 ++- amm/methods/guest/Cargo.toml | 4 +- artifacts/amm-idl.json | 181 +++++++++++++++++++++++++++++++ artifacts/ata-idl.json | 137 +++++++++++++++++++++++ artifacts/token-idl.json | 137 +++++++++++++++++++++++ ata/Cargo.toml | 2 +- ata/core/Cargo.toml | 2 +- ata/core/src/lib.rs | 2 +- ata/methods/guest/Cargo.lock | 13 ++- ata/methods/guest/Cargo.toml | 4 +- integration_tests/tests/amm.rs | 4 +- integration_tests/tests/ata.rs | 8 +- integration_tests/tests/token.rs | 18 +-- token/Cargo.toml | 2 +- token/core/Cargo.toml | 3 +- token/core/src/lib.rs | 4 + token/methods/guest/Cargo.lock | 13 ++- token/methods/guest/Cargo.toml | 4 +- tools/idl-gen/Cargo.toml | 3 +- tools/idl-gen/src/main.rs | 51 ++++++++- 25 files changed, 598 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9732e53..ac00789 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,6 +46,7 @@ dependencies = [ "nssa_core", "risc0-zkvm", "serde", + "spel-framework-macros", "token_core", ] @@ -601,7 +602,7 @@ dependencies = [ [[package]] name = "clock_core" version = "0.1.0" -source = "git+https://github.com/logos-blockchain/logos-execution-zone.git?tag=v0.2.0-rc1#35d8df0d031315219f94d1546ceb862b0e5b208f" +source = "git+https://github.com/logos-blockchain/logos-execution-zone.git?tag=v0.2.0-rc3#cf3639d8252040d13b3d4e933feb19b42c76e14a" dependencies = [ "borsh", "nssa_core", @@ -1525,6 +1526,7 @@ version = "0.1.0" dependencies = [ "serde_json", "spel-framework-core", + "toml", ] [[package]] @@ -1830,7 +1832,7 @@ checksum = "a5b0c77c1b780822bc749a33e39aeb2c07584ab93332303babeabb645298a76e" [[package]] name = "nssa" version = "0.1.0" -source = "git+https://github.com/logos-blockchain/logos-execution-zone.git?tag=v0.2.0-rc1#35d8df0d031315219f94d1546ceb862b0e5b208f" +source = "git+https://github.com/logos-blockchain/logos-execution-zone.git?tag=v0.2.0-rc3#cf3639d8252040d13b3d4e933feb19b42c76e14a" dependencies = [ "anyhow", "borsh", @@ -1852,7 +1854,7 @@ dependencies = [ [[package]] name = "nssa_core" version = "0.1.0" -source = "git+https://github.com/logos-blockchain/logos-execution-zone.git?tag=v0.2.0-rc1#35d8df0d031315219f94d1546ceb862b0e5b208f" +source = "git+https://github.com/logos-blockchain/logos-execution-zone.git?tag=v0.2.0-rc3#cf3639d8252040d13b3d4e933feb19b42c76e14a" dependencies = [ "base58", "borsh", @@ -2973,7 +2975,7 @@ dependencies = [ [[package]] name = "spel-framework-core" version = "0.2.0" -source = "git+https://github.com/logos-co/spel.git?tag=v0.2.0-rc.2#9005e9fbbd78b0530412f9987273f753ed32eb2d" +source = "git+https://github.com/logos-co/spel.git?rev=577b80206bfd0562020e1511f9bd0b347f540585#577b80206bfd0562020e1511f9bd0b347f540585" dependencies = [ "borsh", "nssa_core", @@ -2984,6 +2986,19 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "spel-framework-macros" +version = "0.2.0" +source = "git+https://github.com/logos-co/spel.git?rev=577b80206bfd0562020e1511f9bd0b347f540585#577b80206bfd0562020e1511f9bd0b347f540585" +dependencies = [ + "proc-macro2", + "quote", + "serde_json", + "sha2", + "spel-framework-core", + "syn 2.0.117", +] + [[package]] name = "spin" version = "0.9.8" @@ -3216,6 +3231,7 @@ dependencies = [ "borsh", "nssa_core", "serde", + "spel-framework-macros", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 7021e21..90ebe4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,8 +20,8 @@ exclude = [ resolver = "2" [workspace.dependencies] -nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc1", features = ["host"] } -nssa = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc1", features = ["test-utils"] } +nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc3", features = ["host"] } +nssa = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc3", features = ["test-utils"] } token_core = { path = "token/core" } token_program = { path = "token" } amm_core = { path = "amm/core" } diff --git a/amm/Cargo.toml b/amm/Cargo.toml index 04be123..9ca582f 100644 --- a/amm/Cargo.toml +++ b/amm/Cargo.toml @@ -4,6 +4,6 @@ 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"] } +nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc3", features = ["host"] } amm_core = { path = "core" } token_core = { path = "../token/core" } diff --git a/amm/core/Cargo.toml b/amm/core/Cargo.toml index 16b08c6..2e20837 100644 --- a/amm/core/Cargo.toml +++ b/amm/core/Cargo.toml @@ -4,7 +4,8 @@ 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"] } +nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc3", features = ["host"] } +spel-framework-macros = { git = "https://github.com/logos-co/spel.git", rev = "577b80206bfd0562020e1511f9bd0b347f540585", package = "spel-framework-macros" } token_core = { path = "../../token/core" } borsh = { version = "1.5", features = ["derive"] } serde = { version = "1.0", features = ["derive"] } diff --git a/amm/core/src/lib.rs b/amm/core/src/lib.rs index eeac604..10e494e 100644 --- a/amm/core/src/lib.rs +++ b/amm/core/src/lib.rs @@ -6,6 +6,7 @@ use nssa_core::{ program::{PdaSeed, ProgramId}, }; use serde::{Deserialize, Serialize}; +use spel_framework_macros::account_type; // These stable seed bytes are part of the PDA derivation scheme and must stay unchanged for // compatibility. @@ -112,6 +113,7 @@ pub enum Instruction { pub const MINIMUM_LIQUIDITY: u128 = 1_000; +#[account_type] #[derive(Clone, Default, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] pub struct PoolDefinition { pub definition_token_a_id: AccountId, @@ -173,10 +175,10 @@ pub fn compute_pool_pda( definition_token_a_id: AccountId, definition_token_b_id: AccountId, ) -> AccountId { - AccountId::from(( + AccountId::for_public_pda( &amm_program_id, &compute_pool_pda_seed(definition_token_a_id, definition_token_b_id), - )) + ) } pub fn compute_pool_pda_seed( @@ -211,10 +213,10 @@ pub fn compute_vault_pda( pool_id: AccountId, definition_token_id: AccountId, ) -> AccountId { - AccountId::from(( + AccountId::for_public_pda( &amm_program_id, &compute_vault_pda_seed(pool_id, definition_token_id), - )) + ) } pub fn compute_vault_pda_seed(pool_id: AccountId, definition_token_id: AccountId) -> PdaSeed { @@ -233,7 +235,7 @@ pub fn compute_vault_pda_seed(pool_id: AccountId, definition_token_id: AccountId } pub fn compute_liquidity_token_pda(amm_program_id: ProgramId, pool_id: AccountId) -> AccountId { - AccountId::from((&amm_program_id, &compute_liquidity_token_pda_seed(pool_id))) + AccountId::for_public_pda(&amm_program_id, &compute_liquidity_token_pda_seed(pool_id)) } pub fn compute_liquidity_token_pda_seed(pool_id: AccountId) -> PdaSeed { @@ -252,7 +254,7 @@ pub fn compute_liquidity_token_pda_seed(pool_id: AccountId) -> PdaSeed { } pub fn compute_lp_lock_holding_pda(amm_program_id: ProgramId, pool_id: AccountId) -> AccountId { - AccountId::from((&amm_program_id, &compute_lp_lock_holding_pda_seed(pool_id))) + AccountId::for_public_pda(&amm_program_id, &compute_lp_lock_holding_pda_seed(pool_id)) } pub fn compute_lp_lock_holding_pda_seed(pool_id: AccountId) -> PdaSeed { diff --git a/amm/methods/guest/Cargo.lock b/amm/methods/guest/Cargo.lock index cc8d9a8..f9e23a5 100644 --- a/amm/methods/guest/Cargo.lock +++ b/amm/methods/guest/Cargo.lock @@ -51,6 +51,7 @@ dependencies = [ "nssa_core", "risc0-zkvm", "serde", + "spel-framework-macros", "token_core", ] @@ -1778,7 +1779,7 @@ checksum = "a5b0c77c1b780822bc749a33e39aeb2c07584ab93332303babeabb645298a76e" [[package]] name = "nssa_core" version = "0.1.0" -source = "git+https://github.com/logos-blockchain/logos-execution-zone.git?tag=v0.2.0-rc1#35d8df0d031315219f94d1546ceb862b0e5b208f" +source = "git+https://github.com/logos-blockchain/logos-execution-zone.git?tag=v0.2.0-rc3#cf3639d8252040d13b3d4e933feb19b42c76e14a" dependencies = [ "base58", "borsh", @@ -2898,10 +2899,11 @@ dependencies = [ [[package]] name = "spel-framework" version = "0.2.0" -source = "git+https://github.com/logos-co/spel.git?tag=v0.2.0-rc.2#9005e9fbbd78b0530412f9987273f753ed32eb2d" +source = "git+https://github.com/logos-co/spel.git?rev=577b80206bfd0562020e1511f9bd0b347f540585#577b80206bfd0562020e1511f9bd0b347f540585" dependencies = [ "borsh", "nssa_core", + "serde_json", "spel-framework-core", "spel-framework-macros", ] @@ -2909,24 +2911,27 @@ dependencies = [ [[package]] name = "spel-framework-core" version = "0.2.0" -source = "git+https://github.com/logos-co/spel.git?tag=v0.2.0-rc.2#9005e9fbbd78b0530412f9987273f753ed32eb2d" +source = "git+https://github.com/logos-co/spel.git?rev=577b80206bfd0562020e1511f9bd0b347f540585#577b80206bfd0562020e1511f9bd0b347f540585" dependencies = [ "borsh", "nssa_core", "serde", "serde_json", "sha2", + "syn 2.0.117", "thiserror 1.0.69", ] [[package]] name = "spel-framework-macros" version = "0.2.0" -source = "git+https://github.com/logos-co/spel.git?tag=v0.2.0-rc.2#9005e9fbbd78b0530412f9987273f753ed32eb2d" +source = "git+https://github.com/logos-co/spel.git?rev=577b80206bfd0562020e1511f9bd0b347f540585#577b80206bfd0562020e1511f9bd0b347f540585" dependencies = [ "proc-macro2", "quote", + "serde_json", "sha2", + "spel-framework-core", "syn 2.0.117", ] @@ -3153,6 +3158,7 @@ dependencies = [ "borsh", "nssa_core", "serde", + "spel-framework-macros", ] [[package]] diff --git a/amm/methods/guest/Cargo.toml b/amm/methods/guest/Cargo.toml index 385c4ac..9636ff7 100644 --- a/amm/methods/guest/Cargo.toml +++ b/amm/methods/guest/Cargo.toml @@ -10,8 +10,8 @@ name = "amm" path = "src/bin/amm.rs" [dependencies] -spel-framework = { git = "https://github.com/logos-co/spel.git", tag = "v0.2.0-rc.2", package = "spel-framework" } -nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc1" } +spel-framework = { git = "https://github.com/logos-co/spel.git", rev = "577b80206bfd0562020e1511f9bd0b347f540585", 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 } amm_core = { path = "../../core" } amm_program = { path = "../..", package = "amm_program" } diff --git a/artifacts/amm-idl.json b/artifacts/amm-idl.json index 3003f2f..eb6046a 100644 --- a/artifacts/amm-idl.json +++ b/artifacts/amm-idl.json @@ -318,5 +318,186 @@ "args": [] } ], + "accounts": [ + { + "name": "PoolDefinition", + "type": { + "kind": "struct", + "fields": [ + { + "name": "definition_token_a_id", + "type": "account_id" + }, + { + "name": "definition_token_b_id", + "type": "account_id" + }, + { + "name": "vault_a_id", + "type": "account_id" + }, + { + "name": "vault_b_id", + "type": "account_id" + }, + { + "name": "liquidity_pool_id", + "type": "account_id" + }, + { + "name": "liquidity_pool_supply", + "type": "u128" + }, + { + "name": "reserve_a", + "type": "u128" + }, + { + "name": "reserve_b", + "type": "u128" + }, + { + "name": "fees", + "type": "u128" + } + ] + } + }, + { + "name": "TokenDefinition", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Fungible", + "fields": [ + { + "name": "name", + "type": "string" + }, + { + "name": "total_supply", + "type": "u128" + }, + { + "name": "metadata_id", + "type": { + "option": "account_id" + } + } + ] + }, + { + "name": "NonFungible", + "fields": [ + { + "name": "name", + "type": "string" + }, + { + "name": "printable_supply", + "type": "u128" + }, + { + "name": "metadata_id", + "type": "account_id" + } + ] + } + ] + } + }, + { + "name": "TokenHolding", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Fungible", + "fields": [ + { + "name": "definition_id", + "type": "account_id" + }, + { + "name": "balance", + "type": "u128" + } + ] + }, + { + "name": "NftMaster", + "fields": [ + { + "name": "definition_id", + "type": "account_id" + }, + { + "name": "print_balance", + "type": "u128" + } + ] + }, + { + "name": "NftPrintedCopy", + "fields": [ + { + "name": "definition_id", + "type": "account_id" + }, + { + "name": "owned", + "type": "bool" + } + ] + } + ] + } + }, + { + "name": "TokenMetadata", + "type": { + "kind": "struct", + "fields": [ + { + "name": "definition_id", + "type": "account_id" + }, + { + "name": "standard", + "type": { + "defined": "MetadataStandard" + } + }, + { + "name": "uri", + "type": "string" + }, + { + "name": "creators", + "type": "string" + }, + { + "name": "primary_sale_date", + "type": "u64" + } + ] + } + } + ], + "types": [ + { + "name": "MetadataStandard", + "kind": "enum", + "variants": [ + { + "name": "Simple" + }, + { + "name": "Expanded" + } + ] + } + ], "instruction_type": "amm_core::Instruction" } diff --git a/artifacts/ata-idl.json b/artifacts/ata-idl.json index 5584ca4..2d49320 100644 --- a/artifacts/ata-idl.json +++ b/artifacts/ata-idl.json @@ -98,5 +98,142 @@ ] } ], + "accounts": [ + { + "name": "TokenDefinition", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Fungible", + "fields": [ + { + "name": "name", + "type": "string" + }, + { + "name": "total_supply", + "type": "u128" + }, + { + "name": "metadata_id", + "type": { + "option": "account_id" + } + } + ] + }, + { + "name": "NonFungible", + "fields": [ + { + "name": "name", + "type": "string" + }, + { + "name": "printable_supply", + "type": "u128" + }, + { + "name": "metadata_id", + "type": "account_id" + } + ] + } + ] + } + }, + { + "name": "TokenHolding", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Fungible", + "fields": [ + { + "name": "definition_id", + "type": "account_id" + }, + { + "name": "balance", + "type": "u128" + } + ] + }, + { + "name": "NftMaster", + "fields": [ + { + "name": "definition_id", + "type": "account_id" + }, + { + "name": "print_balance", + "type": "u128" + } + ] + }, + { + "name": "NftPrintedCopy", + "fields": [ + { + "name": "definition_id", + "type": "account_id" + }, + { + "name": "owned", + "type": "bool" + } + ] + } + ] + } + }, + { + "name": "TokenMetadata", + "type": { + "kind": "struct", + "fields": [ + { + "name": "definition_id", + "type": "account_id" + }, + { + "name": "standard", + "type": { + "defined": "MetadataStandard" + } + }, + { + "name": "uri", + "type": "string" + }, + { + "name": "creators", + "type": "string" + }, + { + "name": "primary_sale_date", + "type": "u64" + } + ] + } + } + ], + "types": [ + { + "name": "MetadataStandard", + "kind": "enum", + "variants": [ + { + "name": "Simple" + }, + { + "name": "Expanded" + } + ] + } + ], "instruction_type": "ata_core::Instruction" } diff --git a/artifacts/token-idl.json b/artifacts/token-idl.json index 6d3f033..73c5771 100644 --- a/artifacts/token-idl.json +++ b/artifacts/token-idl.json @@ -172,5 +172,142 @@ "args": [] } ], + "accounts": [ + { + "name": "TokenDefinition", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Fungible", + "fields": [ + { + "name": "name", + "type": "string" + }, + { + "name": "total_supply", + "type": "u128" + }, + { + "name": "metadata_id", + "type": { + "option": "account_id" + } + } + ] + }, + { + "name": "NonFungible", + "fields": [ + { + "name": "name", + "type": "string" + }, + { + "name": "printable_supply", + "type": "u128" + }, + { + "name": "metadata_id", + "type": "account_id" + } + ] + } + ] + } + }, + { + "name": "TokenHolding", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Fungible", + "fields": [ + { + "name": "definition_id", + "type": "account_id" + }, + { + "name": "balance", + "type": "u128" + } + ] + }, + { + "name": "NftMaster", + "fields": [ + { + "name": "definition_id", + "type": "account_id" + }, + { + "name": "print_balance", + "type": "u128" + } + ] + }, + { + "name": "NftPrintedCopy", + "fields": [ + { + "name": "definition_id", + "type": "account_id" + }, + { + "name": "owned", + "type": "bool" + } + ] + } + ] + } + }, + { + "name": "TokenMetadata", + "type": { + "kind": "struct", + "fields": [ + { + "name": "definition_id", + "type": "account_id" + }, + { + "name": "standard", + "type": { + "defined": "MetadataStandard" + } + }, + { + "name": "uri", + "type": "string" + }, + { + "name": "creators", + "type": "string" + }, + { + "name": "primary_sale_date", + "type": "u64" + } + ] + } + } + ], + "types": [ + { + "name": "MetadataStandard", + "kind": "enum", + "variants": [ + { + "name": "Simple" + }, + { + "name": "Expanded" + } + ] + } + ], "instruction_type": "token_core::Instruction" } diff --git a/ata/Cargo.toml b/ata/Cargo.toml index 51babec..ca47107 100644 --- a/ata/Cargo.toml +++ b/ata/Cargo.toml @@ -4,6 +4,6 @@ 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"] } +nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc3", features = ["host"] } ata_core = { path = "core" } token_core = { path = "../token/core" } diff --git a/ata/core/Cargo.toml b/ata/core/Cargo.toml index 0e2fd3e..0304639 100644 --- a/ata/core/Cargo.toml +++ b/ata/core/Cargo.toml @@ -4,7 +4,7 @@ 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"] } +nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc3", features = ["host"] } borsh = { version = "1.5", features = ["derive"] } serde = { version = "1.0", features = ["derive"] } risc0-zkvm = { version = "=3.0.5", default-features = false } diff --git a/ata/core/src/lib.rs b/ata/core/src/lib.rs index 4ea46bf..fb75ae2 100644 --- a/ata/core/src/lib.rs +++ b/ata/core/src/lib.rs @@ -61,7 +61,7 @@ pub fn compute_ata_seed(owner_id: AccountId, definition_id: AccountId) -> PdaSee } pub fn get_associated_token_account_id(ata_program_id: &ProgramId, seed: &PdaSeed) -> AccountId { - AccountId::from((ata_program_id, seed)) + AccountId::for_public_pda(ata_program_id, seed) } /// Verify the ATA's address matches `(ata_program_id, owner, definition)` and return diff --git a/ata/methods/guest/Cargo.lock b/ata/methods/guest/Cargo.lock index 8c55a8a..74ee6d7 100644 --- a/ata/methods/guest/Cargo.lock +++ b/ata/methods/guest/Cargo.lock @@ -1777,7 +1777,7 @@ checksum = "a5b0c77c1b780822bc749a33e39aeb2c07584ab93332303babeabb645298a76e" [[package]] name = "nssa_core" version = "0.1.0" -source = "git+https://github.com/logos-blockchain/logos-execution-zone.git?tag=v0.2.0-rc1#35d8df0d031315219f94d1546ceb862b0e5b208f" +source = "git+https://github.com/logos-blockchain/logos-execution-zone.git?tag=v0.2.0-rc3#cf3639d8252040d13b3d4e933feb19b42c76e14a" dependencies = [ "base58", "borsh", @@ -2897,10 +2897,11 @@ dependencies = [ [[package]] name = "spel-framework" version = "0.2.0" -source = "git+https://github.com/logos-co/spel.git?tag=v0.2.0-rc.2#9005e9fbbd78b0530412f9987273f753ed32eb2d" +source = "git+https://github.com/logos-co/spel.git?rev=577b80206bfd0562020e1511f9bd0b347f540585#577b80206bfd0562020e1511f9bd0b347f540585" dependencies = [ "borsh", "nssa_core", + "serde_json", "spel-framework-core", "spel-framework-macros", ] @@ -2908,24 +2909,27 @@ dependencies = [ [[package]] name = "spel-framework-core" version = "0.2.0" -source = "git+https://github.com/logos-co/spel.git?tag=v0.2.0-rc.2#9005e9fbbd78b0530412f9987273f753ed32eb2d" +source = "git+https://github.com/logos-co/spel.git?rev=577b80206bfd0562020e1511f9bd0b347f540585#577b80206bfd0562020e1511f9bd0b347f540585" dependencies = [ "borsh", "nssa_core", "serde", "serde_json", "sha2", + "syn 2.0.117", "thiserror 1.0.69", ] [[package]] name = "spel-framework-macros" version = "0.2.0" -source = "git+https://github.com/logos-co/spel.git?tag=v0.2.0-rc.2#9005e9fbbd78b0530412f9987273f753ed32eb2d" +source = "git+https://github.com/logos-co/spel.git?rev=577b80206bfd0562020e1511f9bd0b347f540585#577b80206bfd0562020e1511f9bd0b347f540585" dependencies = [ "proc-macro2", "quote", + "serde_json", "sha2", + "spel-framework-core", "syn 2.0.117", ] @@ -3152,6 +3156,7 @@ dependencies = [ "borsh", "nssa_core", "serde", + "spel-framework-macros", ] [[package]] diff --git a/ata/methods/guest/Cargo.toml b/ata/methods/guest/Cargo.toml index 22e8f42..d0106dd 100644 --- a/ata/methods/guest/Cargo.toml +++ b/ata/methods/guest/Cargo.toml @@ -10,8 +10,8 @@ name = "ata" path = "src/bin/ata.rs" [dependencies] -spel-framework = { git = "https://github.com/logos-co/spel.git", tag = "v0.2.0-rc.2", package = "spel-framework" } -nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc1" } +spel-framework = { git = "https://github.com/logos-co/spel.git", rev = "577b80206bfd0562020e1511f9bd0b347f540585", 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 } ata_core = { path = "../../core" } ata_program = { path = "../..", package = "ata_program" } diff --git a/integration_tests/tests/amm.rs b/integration_tests/tests/amm.rs index d121029..ec8c801 100644 --- a/integration_tests/tests/amm.rs +++ b/integration_tests/tests/amm.rs @@ -907,7 +907,7 @@ fn deploy_programs(state: &mut V03State) { } fn state_for_amm_tests() -> V03State { - let mut state = V03State::new_with_genesis_accounts(&[], &[], 0); + let mut state = V03State::new_with_genesis_accounts(&[], vec![], 0); deploy_programs(&mut state); state.force_insert_account(Ids::pool_definition(), Accounts::pool_definition_init()); state.force_insert_account( @@ -931,7 +931,7 @@ fn state_for_amm_tests() -> V03State { } fn state_for_amm_tests_with_new_def() -> V03State { - let mut state = V03State::new_with_genesis_accounts(&[], &[], 0); + let mut state = V03State::new_with_genesis_accounts(&[], vec![], 0); deploy_programs(&mut state); state.force_insert_account( Ids::token_a_definition(), diff --git a/integration_tests/tests/ata.rs b/integration_tests/tests/ata.rs index dd2eef7..41d36a1 100644 --- a/integration_tests/tests/ata.rs +++ b/integration_tests/tests/ata.rs @@ -125,7 +125,7 @@ fn deploy_programs(state: &mut V03State) { } fn state_for_ata_tests() -> V03State { - let mut state = V03State::new_with_genesis_accounts(&[], &[], 0); + let mut state = V03State::new_with_genesis_accounts(&[], vec![], 0); deploy_programs(&mut state); state.force_insert_account(Ids::token_definition(), Accounts::token_definition_init()); state.force_insert_account(Ids::owner_ata(), Accounts::owner_ata_init()); @@ -140,7 +140,7 @@ fn state_for_ata_tests_with_precreated_recipient_ata() -> V03State { #[test] fn ata_create() { - let mut state = V03State::new_with_genesis_accounts(&[], &[], 0); + let mut state = V03State::new_with_genesis_accounts(&[], vec![], 0); deploy_programs(&mut state); state.force_insert_account(Ids::token_definition(), Accounts::token_definition_init()); @@ -312,7 +312,7 @@ fn ata_burn() { #[test] fn ata_create_from_private_owner() { - let mut state = V03State::new_with_genesis_accounts(&[], &[], 0); + let mut state = V03State::new_with_genesis_accounts(&[], vec![], 0); deploy_programs(&mut state); state.force_insert_account(Ids::token_definition(), Accounts::token_definition_init()); @@ -359,7 +359,7 @@ fn ata_create_from_private_owner() { instruction_data, // owner=new private (2), token_definition=public (0), ata=public (0) vec![2, 0, 0], - vec![(owner_npk.clone(), shared_secret)], + vec![(owner_npk, shared_secret)], vec![], // no NSKs: new private accounts don't require one vec![None], // no membership proof: owner is being created, not spending &program_with_deps, diff --git a/integration_tests/tests/token.rs b/integration_tests/tests/token.rs index aed4d8a..01772d0 100644 --- a/integration_tests/tests/token.rs +++ b/integration_tests/tests/token.rs @@ -97,7 +97,7 @@ fn deploy_token(state: &mut V03State) { } fn state_for_token_tests() -> V03State { - let mut state = V03State::new_with_genesis_accounts(&[], &[], 0); + let mut state = V03State::new_with_genesis_accounts(&[], vec![], 0); deploy_token(&mut state); state.force_insert_account(Ids::token_definition(), Accounts::token_definition_init()); state.force_insert_account(Ids::holder(), Accounts::holder_init()); @@ -106,7 +106,7 @@ fn state_for_token_tests() -> V03State { } fn state_for_token_tests_without_recipient() -> V03State { - let mut state = V03State::new_with_genesis_accounts(&[], &[], 0); + let mut state = V03State::new_with_genesis_accounts(&[], vec![], 0); deploy_token(&mut state); state.force_insert_account(Ids::token_definition(), Accounts::token_definition_init()); state.force_insert_account(Ids::holder(), Accounts::holder_init()); @@ -115,7 +115,7 @@ fn state_for_token_tests_without_recipient() -> V03State { #[test] fn token_new_fungible_definition() { - let mut state = V03State::new_with_genesis_accounts(&[], &[], 0); + let mut state = V03State::new_with_genesis_accounts(&[], vec![], 0); deploy_token(&mut state); let instruction = token_core::Instruction::NewFungibleDefinition { @@ -639,8 +639,8 @@ fn token_private_transfer() { Program::serialize_instruction(instruction).unwrap(), vec![1, 2], vec![ - (sender_npk.clone(), shared_secret_1), - (new_recipient_npk.clone(), shared_secret_2), + (sender_npk, shared_secret_1), + (new_recipient_npk, shared_secret_2), ], vec![sender_nsk], vec![state.get_proof_for_commitment(&sender_commitment), None], @@ -652,8 +652,8 @@ fn token_private_transfer() { vec![], vec![], vec![ - (sender_npk.clone(), sender_vpk, epk_1), - (new_recipient_npk.clone(), new_recipient_vpk, epk_2), + (sender_npk, sender_vpk, epk_1), + (new_recipient_npk, new_recipient_vpk, epk_2), ], output, ) @@ -727,7 +727,7 @@ fn token_deshielded_transfer() { vec![sender_pre, public_recipient_pre], Program::serialize_instruction(instruction).unwrap(), vec![1, 0], - vec![(sender_npk.clone(), shared_secret)], + vec![(sender_npk, shared_secret)], vec![sender_nsk], vec![state.get_proof_for_commitment(&sender_commitment)], &token_program().into(), @@ -737,7 +737,7 @@ fn token_deshielded_transfer() { let message = Message::try_from_circuit_output( vec![public_recipient_id], vec![], - vec![(sender_npk.clone(), sender_vpk, epk)], + vec![(sender_npk, sender_vpk, epk)], output, ) .unwrap(); diff --git a/token/Cargo.toml b/token/Cargo.toml index bce7726..0620df3 100644 --- a/token/Cargo.toml +++ b/token/Cargo.toml @@ -4,5 +4,5 @@ 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"] } +nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc3", features = ["host"] } token_core = { path = "core" } diff --git a/token/core/Cargo.toml b/token/core/Cargo.toml index 5eb50b3..bba3dd5 100644 --- a/token/core/Cargo.toml +++ b/token/core/Cargo.toml @@ -4,6 +4,7 @@ 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"] } +nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc3", features = ["host"] } +spel-framework-macros = { git = "https://github.com/logos-co/spel.git", rev = "577b80206bfd0562020e1511f9bd0b347f540585", package = "spel-framework-macros" } borsh = { version = "1.5", features = ["derive"] } serde = { version = "1.0", features = ["derive"] } diff --git a/token/core/src/lib.rs b/token/core/src/lib.rs index 6bc04dc..3954537 100644 --- a/token/core/src/lib.rs +++ b/token/core/src/lib.rs @@ -3,6 +3,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use nssa_core::account::{AccountId, Data}; use serde::{Deserialize, Serialize}; +use spel_framework_macros::account_type; /// Token Program Instruction. #[derive(Serialize, Deserialize)] @@ -76,6 +77,7 @@ pub enum NewTokenDefinition { }, } +#[account_type] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] pub enum TokenDefinition { Fungible { @@ -110,6 +112,7 @@ impl From<&TokenDefinition> for Data { } } +#[account_type] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] pub enum TokenHolding { Fungible { @@ -201,6 +204,7 @@ pub struct NewTokenMetadata { pub creators: String, } +#[account_type] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] pub struct TokenMetadata { /// Token Definition account id. diff --git a/token/methods/guest/Cargo.lock b/token/methods/guest/Cargo.lock index 198a356..6b259c2 100644 --- a/token/methods/guest/Cargo.lock +++ b/token/methods/guest/Cargo.lock @@ -1744,7 +1744,7 @@ checksum = "a5b0c77c1b780822bc749a33e39aeb2c07584ab93332303babeabb645298a76e" [[package]] name = "nssa_core" version = "0.1.0" -source = "git+https://github.com/logos-blockchain/logos-execution-zone.git?tag=v0.2.0-rc1#35d8df0d031315219f94d1546ceb862b0e5b208f" +source = "git+https://github.com/logos-blockchain/logos-execution-zone.git?tag=v0.2.0-rc3#cf3639d8252040d13b3d4e933feb19b42c76e14a" dependencies = [ "base58", "borsh", @@ -2864,10 +2864,11 @@ dependencies = [ [[package]] name = "spel-framework" version = "0.2.0" -source = "git+https://github.com/logos-co/spel.git?tag=v0.2.0-rc.2#9005e9fbbd78b0530412f9987273f753ed32eb2d" +source = "git+https://github.com/logos-co/spel.git?rev=577b80206bfd0562020e1511f9bd0b347f540585#577b80206bfd0562020e1511f9bd0b347f540585" dependencies = [ "borsh", "nssa_core", + "serde_json", "spel-framework-core", "spel-framework-macros", ] @@ -2875,24 +2876,27 @@ dependencies = [ [[package]] name = "spel-framework-core" version = "0.2.0" -source = "git+https://github.com/logos-co/spel.git?tag=v0.2.0-rc.2#9005e9fbbd78b0530412f9987273f753ed32eb2d" +source = "git+https://github.com/logos-co/spel.git?rev=577b80206bfd0562020e1511f9bd0b347f540585#577b80206bfd0562020e1511f9bd0b347f540585" dependencies = [ "borsh", "nssa_core", "serde", "serde_json", "sha2", + "syn 2.0.117", "thiserror 1.0.69", ] [[package]] name = "spel-framework-macros" version = "0.2.0" -source = "git+https://github.com/logos-co/spel.git?tag=v0.2.0-rc.2#9005e9fbbd78b0530412f9987273f753ed32eb2d" +source = "git+https://github.com/logos-co/spel.git?rev=577b80206bfd0562020e1511f9bd0b347f540585#577b80206bfd0562020e1511f9bd0b347f540585" dependencies = [ "proc-macro2", "quote", + "serde_json", "sha2", + "spel-framework-core", "syn 2.0.117", ] @@ -3132,6 +3136,7 @@ dependencies = [ "borsh", "nssa_core", "serde", + "spel-framework-macros", ] [[package]] diff --git a/token/methods/guest/Cargo.toml b/token/methods/guest/Cargo.toml index fe9a7bf..525f5e6 100644 --- a/token/methods/guest/Cargo.toml +++ b/token/methods/guest/Cargo.toml @@ -10,8 +10,8 @@ name = "token" path = "src/bin/token.rs" [dependencies] -spel-framework = { git = "https://github.com/logos-co/spel.git", tag = "v0.2.0-rc.2", package = "spel-framework" } -nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc1" } +spel-framework = { git = "https://github.com/logos-co/spel.git", rev = "577b80206bfd0562020e1511f9bd0b347f540585", 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 } token_core = { path = "../../core" } token_program = { path = "../..", package = "token_program" } diff --git a/tools/idl-gen/Cargo.toml b/tools/idl-gen/Cargo.toml index 71dab24..150d20c 100644 --- a/tools/idl-gen/Cargo.toml +++ b/tools/idl-gen/Cargo.toml @@ -8,7 +8,8 @@ name = "idl-gen" path = "src/main.rs" [dependencies] -spel-framework-core = { git = "https://github.com/logos-co/spel.git", tag = "v0.2.0-rc.2", features = [ +spel-framework-core = { git = "https://github.com/logos-co/spel.git", rev = "577b80206bfd0562020e1511f9bd0b347f540585", features = [ "idl-gen", ] } serde_json = "1.0" +toml = "0.8" diff --git a/tools/idl-gen/src/main.rs b/tools/idl-gen/src/main.rs index f1abee5..0d508c4 100644 --- a/tools/idl-gen/src/main.rs +++ b/tools/idl-gen/src/main.rs @@ -1,4 +1,8 @@ -use std::{path::PathBuf, process}; +use std::{ + fs, + path::{Path, PathBuf}, + process, +}; fn main() { let path: PathBuf = match std::env::args().nth(1) { @@ -9,7 +13,9 @@ fn main() { } }; - match spel_framework_core::idl_gen::generate_idl_from_file(&path) { + let dep_dirs = find_path_dep_dirs(&path); + + match spel_framework_core::idl_gen::generate_idl_from_file_with_deps(&path, &dep_dirs) { Ok(idl) => println!("{}", serde_json::to_string_pretty(&idl).unwrap()), Err(e) => { eprintln!("Error: {e}"); @@ -17,3 +23,44 @@ fn main() { } } } + +/// Return the crate-root directories of all `path = "..."` entries in the +/// `[dependencies]` table of the `Cargo.toml` nearest to `source_path`. +fn find_path_dep_dirs(source_path: &Path) -> Vec { + (|| -> Option> { + let manifest = find_crate_manifest(source_path)?; + let content = fs::read_to_string(&manifest).ok()?; + let value: toml::Value = toml::from_str(&content).ok()?; + let manifest_dir = manifest.parent()?; + + let mut dirs = Vec::new(); + if let Some(table) = value.get("dependencies").and_then(|v| v.as_table()) { + for (_name, dep) in table { + if let Some(rel) = dep.get("path").and_then(|v| v.as_str()) { + let dep_dir = manifest_dir.join(rel); + if dep_dir.is_dir() { + dirs.push(dep_dir); + } + } + } + } + Some(dirs) + })() + .unwrap_or_default() +} + +/// Walk up from `start` to find the nearest `Cargo.toml`. +fn find_crate_manifest(start: &Path) -> Option { + let mut dir: &Path = if start.is_file() { + start.parent()? + } else { + start + }; + loop { + let candidate = dir.join("Cargo.toml"); + if candidate.exists() { + return Some(candidate); + } + dir = dir.parent()?; + } +}