token_metadata_descriptor/
lib.rs

1use anchor_lang::prelude::*;
2use solana_security_txt::security_txt;
3
4mod constants;
5pub mod instructions;
6pub mod state;
7mod utils;
8
9use constants::*;
10use instructions::*;
11use state::*;
12
13declare_id!("DesCwDwfrbxTDSjAm5Xjqh9Cij5Ucb46F6qH7cwieXB");
14
15#[cfg(not(feature = "no-entrypoint"))]
16security_txt! {
17    name: "Token Metadata Descriptor",
18    project_url: "https://github.com/sooshisan/token-metadata-descriptor",
19    contacts: "link:https://github.com/sooshisan/token-metadata-descriptor/security/advisories/new",
20    policy: "https://github.com/sooshisan/token-metadata-descriptor/blob/main/SECURITY.md",
21    preferred_languages: "en"
22}
23
24#[program]
25pub mod token_metadata_descriptor {
26    use super::*;
27
28    pub fn initialize(
29        ctx: Context<Initialize>,
30        data_size: u64,
31        encoding: Encoding,
32        bump: u8,
33    ) -> Result<()> {
34        instructions::initialize_handler(ctx, data_size, encoding, bump)
35    }
36
37    pub fn resize(ctx: Context<Resize>, new_size: u64) -> Result<()> {
38        instructions::resize_handler(ctx, new_size)
39    }
40
41    pub fn copy(
42        ctx: Context<Copy>,
43        buffer_range: Range,
44        descriptor_start_range: u64,
45        encoding: Encoding,
46    ) -> Result<()> {
47        instructions::copy_handler(ctx, buffer_range, descriptor_start_range, encoding)
48    }
49
50    pub fn close(ctx: Context<Close>) -> Result<()> {
51        instructions::close_handler(ctx)
52    }
53
54    /// Combination of `initialize` and `copy` in one instruction
55    pub fn initialize_with_buffer(
56        ctx: Context<InitializeWithBuffer>,
57        range: Option<Range>,
58        encoding: Encoding,
59        bump: u8,
60    ) -> Result<()> {
61        instructions::initialize_with_buffer_handler(ctx, range, encoding, bump)
62    }
63
64    /// Special version of `initialize` with data passed in directly as the MTU
65    /// upper bound (1280 bytes) is observed. This can be used to avoid the overhead
66    /// of building multiple instructions and or dealing with an intermediary buffer.
67    pub fn initialize_with_data(
68        ctx: Context<InitializeWithData>,
69        encoding: Encoding,
70        bump: u8,
71        data: Vec<u8>
72    ) -> Result<()> {
73        instructions::initialize_with_data_handler(ctx, encoding, bump, &data)
74    }
75}
76
77#[error_code]
78pub enum DescriptorError {
79    #[msg("Authority is not allowed to perform such action")]
80    IncorrectAuthority,
81    #[msg("Account already initialized")]
82    Initialized,
83    #[msg("Account is not initialized")]
84    Uninitialized,
85    #[msg("Mint Mismatch")]
86    MintMismatch,
87    #[msg("Incorrect seeds")]
88    IncorrectSeeds,
89    #[msg("Target account exceeds limit")]
90    AccountTooLarge,
91    #[msg("Invalid range")]
92    InvalidRange,
93    #[msg("Math error")]
94    MathError,
95    #[msg("Insufficient balance")]
96    InsufficientBalance,
97}