2026-03-17 18:08:53 +01:00
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
|
|
use spel_framework::prelude::*;
|
|
|
|
|
use nssa_core::account::AccountWithMetadata;
|
|
|
|
|
|
|
|
|
|
risc0_zkvm::guest::entry!(main);
|
|
|
|
|
|
|
|
|
|
#[lez_program(instruction = "token_core::Instruction")]
|
|
|
|
|
mod token {
|
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
/// Transfer tokens from sender to recipient.
|
2026-04-15 14:55:04 -03:00
|
|
|
/// Fresh public recipients must be explicitly authorized in the same transaction.
|
2026-03-17 18:08:53 +01:00
|
|
|
#[instruction]
|
|
|
|
|
pub fn transfer(
|
|
|
|
|
sender: AccountWithMetadata,
|
|
|
|
|
recipient: AccountWithMetadata,
|
|
|
|
|
amount_to_transfer: u128,
|
|
|
|
|
) -> SpelResult {
|
2026-05-12 11:33:19 +02:00
|
|
|
Ok(spel_framework::SpelOutput::execute(token_program::transfer::transfer(
|
2026-03-17 18:08:53 +01:00
|
|
|
sender,
|
|
|
|
|
recipient,
|
|
|
|
|
amount_to_transfer,
|
2026-05-12 11:33:19 +02:00
|
|
|
), vec![]))
|
2026-03-17 18:08:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Create a new fungible token definition without metadata.
|
2026-04-15 14:55:04 -03:00
|
|
|
/// Definition and holding targets must be uninitialized and authorized.
|
2026-03-17 18:08:53 +01:00
|
|
|
#[instruction]
|
|
|
|
|
pub fn new_fungible_definition(
|
|
|
|
|
definition_target_account: AccountWithMetadata,
|
|
|
|
|
holding_target_account: AccountWithMetadata,
|
|
|
|
|
name: String,
|
|
|
|
|
total_supply: u128,
|
|
|
|
|
) -> SpelResult {
|
2026-05-12 11:33:19 +02:00
|
|
|
Ok(spel_framework::SpelOutput::execute(
|
2026-03-17 18:08:53 +01:00
|
|
|
token_program::new_definition::new_fungible_definition(
|
|
|
|
|
definition_target_account,
|
|
|
|
|
holding_target_account,
|
|
|
|
|
name,
|
|
|
|
|
total_supply,
|
|
|
|
|
),
|
2026-05-12 11:33:19 +02:00
|
|
|
vec![],
|
2026-03-17 18:08:53 +01:00
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Create a new fungible or non-fungible token definition with metadata.
|
2026-04-15 14:55:04 -03:00
|
|
|
/// Definition, holding, and metadata targets must be uninitialized and authorized.
|
2026-03-17 18:08:53 +01:00
|
|
|
#[instruction]
|
|
|
|
|
pub fn new_definition_with_metadata(
|
|
|
|
|
definition_target_account: AccountWithMetadata,
|
|
|
|
|
holding_target_account: AccountWithMetadata,
|
|
|
|
|
metadata_target_account: AccountWithMetadata,
|
|
|
|
|
new_definition: token_core::NewTokenDefinition,
|
|
|
|
|
metadata: Box<token_core::NewTokenMetadata>,
|
|
|
|
|
) -> SpelResult {
|
2026-05-12 11:33:19 +02:00
|
|
|
Ok(spel_framework::SpelOutput::execute(
|
2026-03-17 18:08:53 +01:00
|
|
|
token_program::new_definition::new_definition_with_metadata(
|
|
|
|
|
definition_target_account,
|
|
|
|
|
holding_target_account,
|
|
|
|
|
metadata_target_account,
|
|
|
|
|
new_definition,
|
|
|
|
|
*metadata,
|
|
|
|
|
),
|
2026-05-12 11:33:19 +02:00
|
|
|
vec![],
|
2026-03-17 18:08:53 +01:00
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Initialize a token holding account for a given token definition.
|
2026-04-15 14:55:04 -03:00
|
|
|
/// The holding target must be uninitialized and authorized.
|
2026-03-17 18:08:53 +01:00
|
|
|
#[instruction]
|
|
|
|
|
pub fn initialize_account(
|
|
|
|
|
definition_account: AccountWithMetadata,
|
|
|
|
|
account_to_initialize: AccountWithMetadata,
|
|
|
|
|
) -> SpelResult {
|
2026-05-12 11:33:19 +02:00
|
|
|
Ok(spel_framework::SpelOutput::execute(
|
2026-03-17 18:08:53 +01:00
|
|
|
token_program::initialize::initialize_account(
|
|
|
|
|
definition_account,
|
|
|
|
|
account_to_initialize,
|
|
|
|
|
),
|
2026-05-12 11:33:19 +02:00
|
|
|
vec![],
|
2026-03-17 18:08:53 +01:00
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Burn tokens from the holder's account.
|
|
|
|
|
#[instruction]
|
|
|
|
|
pub fn burn(
|
|
|
|
|
definition_account: AccountWithMetadata,
|
|
|
|
|
user_holding_account: AccountWithMetadata,
|
|
|
|
|
amount_to_burn: u128,
|
|
|
|
|
) -> SpelResult {
|
2026-05-12 11:33:19 +02:00
|
|
|
Ok(spel_framework::SpelOutput::execute(token_program::burn::burn(
|
2026-03-17 18:08:53 +01:00
|
|
|
definition_account,
|
|
|
|
|
user_holding_account,
|
|
|
|
|
amount_to_burn,
|
2026-05-12 11:33:19 +02:00
|
|
|
), vec![]))
|
2026-03-17 18:08:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Mint new tokens to the holder's account.
|
2026-04-15 14:55:04 -03:00
|
|
|
/// Fresh public holders must be explicitly authorized in the same transaction.
|
2026-03-17 18:08:53 +01:00
|
|
|
#[instruction]
|
|
|
|
|
pub fn mint(
|
|
|
|
|
definition_account: AccountWithMetadata,
|
|
|
|
|
user_holding_account: AccountWithMetadata,
|
|
|
|
|
amount_to_mint: u128,
|
|
|
|
|
) -> SpelResult {
|
2026-05-12 11:33:19 +02:00
|
|
|
Ok(spel_framework::SpelOutput::execute(token_program::mint::mint(
|
2026-03-17 18:08:53 +01:00
|
|
|
definition_account,
|
|
|
|
|
user_holding_account,
|
|
|
|
|
amount_to_mint,
|
2026-05-12 11:33:19 +02:00
|
|
|
), vec![]))
|
2026-03-17 18:08:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Print a new NFT from the master copy.
|
2026-04-15 14:55:04 -03:00
|
|
|
/// The printed copy target must be uninitialized and authorized.
|
2026-03-17 18:08:53 +01:00
|
|
|
#[instruction]
|
|
|
|
|
pub fn print_nft(
|
|
|
|
|
master_account: AccountWithMetadata,
|
|
|
|
|
printed_account: AccountWithMetadata,
|
|
|
|
|
) -> SpelResult {
|
2026-05-12 11:33:19 +02:00
|
|
|
Ok(spel_framework::SpelOutput::execute(token_program::print_nft::print_nft(
|
2026-03-17 18:08:53 +01:00
|
|
|
master_account,
|
|
|
|
|
printed_account,
|
2026-05-12 11:33:19 +02:00
|
|
|
), vec![]))
|
2026-03-17 18:08:53 +01:00
|
|
|
}
|
|
|
|
|
}
|