apl_token_metadata/
lib.rs

1#![deny(missing_docs)]
2#![cfg_attr(not(test), forbid(unsafe_code))]
3
4//! Arch Network Token Metadata Standard
5
6pub mod error;
7pub mod instruction;
8pub mod processor;
9pub mod state;
10
11// Exclude the on-chain entrypoint when building unit tests or when the
12// consumer opts into the "no-entrypoint" feature (host-side contexts).
13#[cfg(all(not(feature = "no-entrypoint"), not(test)))]
14mod entrypoint;
15
16use arch_program::{entrypoint::ProgramResult, program_error::ProgramError, pubkey::Pubkey};
17
18/// The program ID for the Arch Token Metadata program
19pub fn id() -> Pubkey {
20    Pubkey::from_slice(b"ArchTokenMetadata111111111111111")
21}
22
23/// Checks that the supplied program ID is the correct one for Arch Token Metadata
24pub fn check_program_account(program_id: &Pubkey) -> ProgramResult {
25    if program_id != &id() {
26        return Err(ProgramError::IncorrectProgramId);
27    }
28    Ok(())
29}
30
31/// PDA seed for metadata account
32pub const METADATA_SEED: &[u8] = b"metadata";
33
34/// PDA seed for attributes account
35pub const ATTRIBUTES_SEED: &[u8] = b"attributes";
36
37/// Helper to derive the `TokenMetadata` PDA for a given mint
38pub fn find_metadata_pda_with_program(program_id: &Pubkey, mint: &Pubkey) -> (Pubkey, u8) {
39    Pubkey::find_program_address(&[METADATA_SEED, mint.as_ref()], program_id)
40}
41
42/// Helper to derive the `TokenMetadataAttributes` PDA for a given mint
43pub fn find_attributes_pda_with_program(program_id: &Pubkey, mint: &Pubkey) -> (Pubkey, u8) {
44    Pubkey::find_program_address(&[ATTRIBUTES_SEED, mint.as_ref()], program_id)
45}