Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"token/ids",
"token/core",
"token",
"token/methods",
Expand Down
6 changes: 3 additions & 3 deletions ata/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum Instruction {
/// - Token definition account
/// - Associated token account (default/uninitialized, or already initialized)
///
/// `token_program_id` is derived from `token_definition.account.program_owner`.
/// The downstream token program is the canonical token program wired by the ATA guest.
Create { ata_program_id: ProgramId },

/// Transfer tokens FROM owner's ATA to a recipient token holding account.
Expand All @@ -26,7 +26,7 @@ pub enum Instruction {
/// - Sender ATA (owner's token holding)
/// - Recipient token holding (must be initialized)
///
/// `token_program_id` is derived from `sender_ata.account.program_owner`.
/// The downstream token program is the canonical token program wired by the ATA guest.
Transfer {
ata_program_id: ProgramId,
amount: u128,
Expand All @@ -40,7 +40,7 @@ pub enum Instruction {
/// - Owner's ATA (the holding to burn from)
/// - Token definition account
///
/// `token_program_id` is derived from `holder_ata.account.program_owner`.
/// The downstream token program is the canonical token program wired by the ATA guest.
Burn {
ata_program_id: ProgramId,
amount: u128,
Expand Down
5 changes: 5 additions & 0 deletions ata/methods/guest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ata/methods/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.gi
risc0-zkvm = { version = "=3.0.5", default-features = false }
ata_core = { path = "../../core" }
ata_program = { path = "../..", package = "ata_program" }
token-ids = { path = "../../../token/ids" }
token_core = { path = "../../../token/core" }
serde = { version = "1.0", features = ["derive"] }
borsh = "1.5"
3 changes: 3 additions & 0 deletions ata/methods/guest/src/bin/ata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod ata {
token_definition,
ata_account,
ata_program_id,
token_ids::TOKEN_ID,
);
Ok(SpelOutput::with_chained_calls(post_states, chained_calls))
}
Expand All @@ -44,6 +45,7 @@ mod ata {
sender_ata,
recipient,
ata_program_id,
token_ids::TOKEN_ID,
amount,
);
Ok(SpelOutput::with_chained_calls(post_states, chained_calls))
Expand All @@ -64,6 +66,7 @@ mod ata {
holder_ata,
token_definition,
ata_program_id,
token_ids::TOKEN_ID,
amount,
);
Ok(SpelOutput::with_chained_calls(post_states, chained_calls))
Expand Down
14 changes: 9 additions & 5 deletions ata/src/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ use nssa_core::{
account::AccountWithMetadata,
program::{AccountPostState, ChainedCall, ProgramId},
};
use token_core::TokenHolding;

pub fn burn_from_associated_token_account(
owner: AccountWithMetadata,
holder_ata: AccountWithMetadata,
token_definition: AccountWithMetadata,
ata_program_id: ProgramId,
token_program_id: ProgramId,
amount: u128,
) -> (Vec<AccountPostState>, Vec<ChainedCall>) {
let token_program_id = holder_ata.account.program_owner;
assert!(owner.is_authorized, "Owner authorization is missing");
let definition_id = TokenHolding::try_from(&holder_ata.account.data)
.expect("Holder ATA must hold a valid token")
.definition_id();
let _definition =
crate::validation::canonical_token_definition(&token_definition, token_program_id);
let definition_id =
crate::validation::canonical_ata_holding(&holder_ata, token_program_id).definition_id();
assert_eq!(
definition_id, token_definition.account_id,
"Holder ATA token definition mismatch"
);
let seed =
ata_core::verify_ata_and_get_seed(&holder_ata, &owner, definition_id, ata_program_id);

Expand Down
10 changes: 9 additions & 1 deletion ata/src/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ pub fn create_associated_token_account(
token_definition: AccountWithMetadata,
ata_account: AccountWithMetadata,
ata_program_id: ProgramId,
token_program_id: ProgramId,
) -> (Vec<AccountPostState>, Vec<ChainedCall>) {
// No explicit owner authorization check is needed here: ATA creation is idempotent, so the
// call itself may proceed without `owner.is_authorized`. If the owner account is still
// default, the returned post-state will still carry `Claim::Authorized` so the runtime can
// claim that owner account when needed.
let token_program_id = token_definition.account.program_owner;
let _definition =
crate::validation::canonical_token_definition(&token_definition, token_program_id);
let seed = ata_core::verify_ata_and_get_seed(
&ata_account,
&owner,
Expand All @@ -23,6 +25,12 @@ pub fn create_associated_token_account(

// Idempotent: already initialized → no-op
if ata_account.account != Account::default() {
let holding = crate::validation::canonical_ata_holding(&ata_account, token_program_id);
assert_eq!(
holding.definition_id(),
token_definition.account_id,
"Existing ATA token definition mismatch"
);
return (
vec![
AccountPostState::new_claimed_if_default(owner.account.clone(), Claim::Authorized),
Expand Down
1 change: 1 addition & 0 deletions ata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub use ata_core as core;
pub mod burn;
pub mod create;
pub mod transfer;
mod validation;

#[cfg(test)]
mod tests;
Loading
Loading