2026-03-17 18:08:53 +01:00
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
|
|
use spel_framework::prelude::*;
|
2026-05-04 10:34:10 -03:00
|
|
|
use spel_framework::context::ProgramContext;
|
|
|
|
|
use nssa_core::account::AccountWithMetadata;
|
2026-03-17 18:08:53 +01:00
|
|
|
|
|
|
|
|
risc0_zkvm::guest::entry!(main);
|
|
|
|
|
|
|
|
|
|
#[lez_program(instruction = "ata_core::Instruction")]
|
|
|
|
|
mod ata {
|
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
/// Create the Associated Token Account for (owner, definition).
|
|
|
|
|
/// Idempotent: no-op if the account already exists.
|
|
|
|
|
#[instruction]
|
|
|
|
|
pub fn create(
|
2026-05-04 10:34:10 -03:00
|
|
|
ctx: ProgramContext,
|
2026-03-17 18:08:53 +01:00
|
|
|
owner: AccountWithMetadata,
|
|
|
|
|
token_definition: AccountWithMetadata,
|
|
|
|
|
ata_account: AccountWithMetadata,
|
|
|
|
|
) -> SpelResult {
|
|
|
|
|
let (post_states, chained_calls) = ata_program::create::create_associated_token_account(
|
|
|
|
|
owner,
|
|
|
|
|
token_definition,
|
|
|
|
|
ata_account,
|
2026-05-04 10:34:10 -03:00
|
|
|
ctx.self_program_id,
|
2026-03-17 18:08:53 +01:00
|
|
|
);
|
2026-05-12 11:33:19 +02:00
|
|
|
Ok(spel_framework::SpelOutput::execute(post_states, chained_calls))
|
2026-03-17 18:08:53 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-15 14:55:04 -03:00
|
|
|
/// Transfer tokens FROM owner's ATA to a recipient token holding account.
|
|
|
|
|
/// The recipient holding account must already be initialized.
|
2026-03-17 18:08:53 +01:00
|
|
|
#[instruction]
|
|
|
|
|
pub fn transfer(
|
2026-05-04 10:34:10 -03:00
|
|
|
ctx: ProgramContext,
|
2026-03-17 18:08:53 +01:00
|
|
|
owner: AccountWithMetadata,
|
|
|
|
|
sender_ata: AccountWithMetadata,
|
|
|
|
|
recipient: AccountWithMetadata,
|
|
|
|
|
amount: u128,
|
|
|
|
|
) -> SpelResult {
|
|
|
|
|
let (post_states, chained_calls) =
|
|
|
|
|
ata_program::transfer::transfer_from_associated_token_account(
|
|
|
|
|
owner,
|
|
|
|
|
sender_ata,
|
|
|
|
|
recipient,
|
2026-05-04 10:34:10 -03:00
|
|
|
ctx.self_program_id,
|
2026-03-17 18:08:53 +01:00
|
|
|
amount,
|
|
|
|
|
);
|
2026-05-12 11:33:19 +02:00
|
|
|
Ok(spel_framework::SpelOutput::execute(post_states, chained_calls))
|
2026-03-17 18:08:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Burn tokens FROM owner's ATA.
|
|
|
|
|
#[instruction]
|
|
|
|
|
pub fn burn(
|
2026-05-04 10:34:10 -03:00
|
|
|
ctx: ProgramContext,
|
2026-03-17 18:08:53 +01:00
|
|
|
owner: AccountWithMetadata,
|
|
|
|
|
holder_ata: AccountWithMetadata,
|
|
|
|
|
token_definition: AccountWithMetadata,
|
|
|
|
|
amount: u128,
|
|
|
|
|
) -> SpelResult {
|
|
|
|
|
let (post_states, chained_calls) =
|
|
|
|
|
ata_program::burn::burn_from_associated_token_account(
|
|
|
|
|
owner,
|
|
|
|
|
holder_ata,
|
|
|
|
|
token_definition,
|
2026-05-04 10:34:10 -03:00
|
|
|
ctx.self_program_id,
|
2026-03-17 18:08:53 +01:00
|
|
|
amount,
|
|
|
|
|
);
|
2026-05-12 11:33:19 +02:00
|
|
|
Ok(spel_framework::SpelOutput::execute(post_states, chained_calls))
|
2026-03-17 18:08:53 +01:00
|
|
|
}
|
|
|
|
|
}
|