Skip to main content

apl_token_metadata/
lib.rs

1#![deny(missing_docs)]
2#![cfg_attr(not(test), forbid(unsafe_code))]
3
4//! On-chain token metadata program for the Arch runtime.
5//!
6//! This crate provides:
7//! - deterministic PDA helpers for metadata and attribute accounts
8//! - instruction and processor logic for create/update/finalize flows
9//! - state definitions for metadata payloads stored on chain
10//!
11//! Package details:
12//! - Cargo package: `apl-token-metadata`
13//! - Library crate: `apl_token_metadata`
14//! - Program ID and PDA helpers live in this file
15//! - Instruction, state, and processor logic live in sibling modules
16
17pub mod error;
18pub mod instruction;
19pub mod processor;
20pub mod state;
21
22// Exclude the on-chain entrypoint when building unit tests or when the
23// consumer opts into the "no-entrypoint" feature (host-side contexts).
24#[cfg(all(not(feature = "no-entrypoint"), not(test)))]
25mod entrypoint;
26
27use arch_program::{entrypoint::ProgramResult, program_error::ProgramError, pubkey::Pubkey};
28
29arch_program::declare_id!("MetaLUJnthcRKvy3ayXTnVcxaXqca1fbaQox8ChQqAk");
30
31/// Checks that the supplied program ID is the correct one for Arch Token Metadata
32pub fn check_program_account(program_id: &Pubkey) -> ProgramResult {
33    if !check_id(program_id) {
34        return Err(ProgramError::IncorrectProgramId);
35    }
36    Ok(())
37}
38
39/// PDA seed for metadata account
40pub const METADATA_SEED: &[u8] = b"metadata";
41
42/// PDA seed for attributes account
43pub const ATTRIBUTES_SEED: &[u8] = b"attributes";
44
45/// Helper to derive the `TokenMetadata` PDA for a given mint
46pub fn find_metadata_pda_with_program(program_id: &Pubkey, mint: &Pubkey) -> (Pubkey, u8) {
47    Pubkey::find_program_address(&[METADATA_SEED, mint.as_ref()], program_id)
48}
49
50/// Helper to derive the `TokenMetadataAttributes` PDA for a given mint
51pub fn find_attributes_pda_with_program(program_id: &Pubkey, mint: &Pubkey) -> (Pubkey, u8) {
52    Pubkey::find_program_address(&[ATTRIBUTES_SEED, mint.as_ref()], program_id)
53}