solana_nft_programs_creator_standard/
lib.rs

1use borsh::BorshDeserialize;
2use borsh::BorshSerialize;
3use shank::ShankInstruction;
4use solana_program::account_info::AccountInfo;
5use solana_program::entrypoint::ProgramResult;
6use solana_program::msg;
7use solana_program::pubkey::Pubkey;
8
9pub mod errors;
10pub mod instructions;
11pub mod pda;
12pub mod state;
13pub mod utils;
14
15use instructions::*;
16use solana_security_txt::security_txt;
17
18solana_program::declare_id!("ccsxqYAg64wuLEh45KabyPvkKjrEfDPsDZUQrGn7mf3");
19
20#[cfg(not(feature = "no-entrypoint"))]
21solana_program::entrypoint!(process_instruction);
22
23#[cfg_attr(feature = "serde-feature", derive(Serialize, Deserialize))]
24#[derive(BorshSerialize, BorshDeserialize, Clone, ShankInstruction)]
25#[rustfmt::skip]
26pub enum CreatorStandardInstruction {
27    // ruleset
28    #[account(0, writable, name = "ruleset")]
29    #[account(1, signer, name = "authority")]
30    #[account(2, writable, signer, name = "payer")]
31    #[account(3, name = "system_program")]
32    InitRuleset(InitRulesetIx),
33
34    #[account(0, writable, name = "ruleset")]
35    #[account(1, signer, name = "authority")]
36    #[account(2, writable, signer, name = "payer")]
37    #[account(3, name = "system_program")]
38    UpdateRuleset(UpdateRulesetIx),
39
40    #[account(0, writable, name = "ruleset")]
41    #[account(1, writable, signer, name = "authority")]
42    CloseRuleset,
43
44    // mint_manager
45    #[account(0, writable, name = "mint_manager")]
46    #[account(1, writable, name = "mint")]
47    #[account(2, name = "mint_metadata", desc = "Mint metadata")]
48    #[account(3, name = "ruleset")]
49    #[account(4, writable, name = "holder_token_account")]
50    #[account(5, signer, name = "token_authority")]
51    #[account(6, name = "authority")]
52    #[account(7, writable, signer, name = "payer")]
53    #[account(8, name = "token_program", desc = "Token program")]
54    #[account(9, name = "system_program", desc = "System program")]
55    InitMintManager,
56
57    #[account(0, writable, name = "mint_manager")]
58    #[account(1, name = "ruleset")]
59    #[account(2, signer, name = "authority")]
60    #[account(3, writable, signer, name = "payer")]
61    #[account(4, name = "system_program", desc = "System program")]
62    UpdateMintManager(UpdateMintManagerIx),
63
64    #[account(0, writable, name = "mint_manager")]
65    #[account(1, name = "ruleset")]
66    #[account(2, name = "in_use_by_address")]
67    #[account(3, signer, name = "holder")]
68    #[account(4, name = "holder_token_account")]
69    SetInUseBy,
70
71    #[account(0, writable, name = "mint_manager")]
72    #[account(1, signer, name = "user")]
73    RemoveInUseBy,
74
75    // token
76    #[account(0, name = "mint_manager")]
77    #[account(1, name = "ruleset")]
78    #[account(2, name = "mint")]
79    #[account(3, writable, name = "holder_token_account")]
80    #[account(4, signer, name = "holder")]
81    #[account(5, name = "delegate")]
82    #[account(6, name = "token_program")]
83    Approve(ApproveIx),
84
85    #[account(0, writable, name = "mint_manager")]
86    #[account(1, name = "ruleset")]
87    #[account(2, name = "mint")]
88    #[account(3, name = "in_use_by_address")]
89    #[account(4, writable, name = "holder_token_account")]
90    #[account(5, signer, name = "holder")]
91    #[account(6, name = "delegate")]
92    #[account(7, name = "token_program")]
93    ApproveAndSetInUseBy(ApproveAndSetInUseByIx),
94
95    #[account(0, writable, name = "mint_manager")]
96    #[account(1, writable, name = "mint")]
97    #[account(2, writable, name = "holder_token_account")]
98    #[account(3, writable, signer, name = "holder")]
99    #[account(4, name = "token_program")]
100    #[account(5, name = "system_program")]
101    Burn,
102
103    #[account(0, name = "mint_manager")]
104    #[account(1, writable, name = "mint")]
105    #[account(2, writable, name = "token_account")]
106    #[account(3, signer, name = "owner")]
107    #[account(4, name = "token_program")]
108    Close,
109
110    #[account(0, name = "mint")]
111    #[account(1, writable, name = "token_account")]
112    #[account(2, name = "owner")]
113    #[account(3, writable, signer, name = "payer")]
114    #[account(4, name = "rent")]
115    #[account(5, name = "token_program")]
116    #[account(6, name = "associated_token_program")]
117    #[account(7, name = "system_program")]
118    InitializeAccount,
119
120    #[account(0, name = "mint_manager")]
121    #[account(1, name = "mint")]
122    #[account(2, writable, name = "holder_token_account")]
123    #[account(3, signer, name = "holder")]
124    #[account(4, name = "token_program")]
125    Revoke,
126
127    #[account(0, name = "mint_manager")]
128    #[account(1, name = "mint")]
129    #[account(2, name = "mint_metadata", desc = "Mint metadata")]
130    #[account(3, name = "ruleset")]
131    #[account(4, writable, name = "from")]
132    #[account(5, writable, name = "to")]
133    #[account(6, signer, name = "authority")]
134    #[account(7, name = "token_program")]
135    #[account(8, name = "system_program")]
136    #[account(9, name = "instructions")]
137    Transfer,
138
139    #[account(0, writable, name = "mint_manager")]
140    #[account(1, writable, name = "mint")]
141    #[account(2, writable, name = "holder_token_account")]
142    #[account(3, name = "new_token_authority")]
143    #[account(4, name = "authority")]
144    #[account(5, writable, signer, name = "payer")]
145    #[account(6, name = "token_program", desc = "Token program")]
146    #[account(7, name = "system_program", desc = "System program")]
147    CloseMintManager,
148}
149
150pub fn process_instruction(
151    _program_id: &Pubkey,
152    accounts: &[AccountInfo],
153    instruction_data: &[u8],
154) -> ProgramResult {
155    let instruction = CreatorStandardInstruction::try_from_slice(instruction_data)?;
156    match instruction {
157        CreatorStandardInstruction::InitRuleset(ix) => {
158            msg!("CreatorStandardInstruction::InitRuleset");
159            let ctx = InitRulesetCtx::load(accounts)?;
160            instructions::ruleset::init_ruleset::handler(ctx, ix)
161        }
162        CreatorStandardInstruction::UpdateRuleset(ix) => {
163            msg!("CreatorStandardInstruction::UpdateRuleset");
164            let ctx = UpdateRulesetCtx::load(accounts)?;
165            instructions::ruleset::update_ruleset::handler(ctx, ix)
166        }
167        CreatorStandardInstruction::CloseRuleset => {
168            msg!("CreatorStandardInstruction::CloseRuleset");
169            let ctx = CloseRulesetCtx::load(accounts)?;
170            instructions::ruleset::close_ruleset::handler(ctx)
171        }
172        CreatorStandardInstruction::InitMintManager => {
173            msg!("CreatorStandardInstruction::InitMintManager");
174            let ctx = InitMintManagerCtx::load(accounts)?;
175            instructions::mint_manager::init_mint_manager::handler(ctx)
176        }
177        CreatorStandardInstruction::UpdateMintManager(ix) => {
178            msg!("CreatorStandardInstruction::UpdateMintManager");
179            let ctx = UpdateMintManagerCtx::load(accounts)?;
180            instructions::mint_manager::update_mint_manager::handler(ctx, ix)
181        }
182        CreatorStandardInstruction::SetInUseBy => {
183            msg!("CreatorStandardInstruction::SetInUseBy");
184            let ctx = mint_manager::SetInUseByCtx::load(accounts)?;
185            instructions::mint_manager::set_in_use_by::handler(ctx)
186        }
187        CreatorStandardInstruction::RemoveInUseBy => {
188            msg!("CreatorStandardInstruction::RemoveInUseBy");
189            let ctx = RemoveInUseByCtx::load(accounts)?;
190            instructions::mint_manager::remove_in_use_by::handler(ctx)
191        }
192        CreatorStandardInstruction::Approve(ix) => {
193            msg!("CreatorStandardInstruction::Approve");
194            let ctx = ApproveCtx::load(accounts)?;
195            instructions::token::approve::handler(ctx, ix)
196        }
197        CreatorStandardInstruction::ApproveAndSetInUseBy(ix) => {
198            msg!("CreatorStandardInstruction::Approve");
199            let ctx = ApproveAndSetInUseByCtx::load(accounts)?;
200            instructions::token::approve_and_set_in_use_by::handler(ctx, ix)
201        }
202        CreatorStandardInstruction::Burn => {
203            msg!("CreatorStandardInstruction::Burn");
204            let ctx = BurnCtx::load(accounts)?;
205            instructions::token::burn::handler(ctx)
206        }
207        CreatorStandardInstruction::Close => {
208            msg!("CreatorStandardInstruction::Close");
209            let ctx = CloseCtx::load(accounts)?;
210            instructions::token::close::handler(ctx)
211        }
212        CreatorStandardInstruction::InitializeAccount => {
213            msg!("CreatorStandardInstruction::InitializeAccount");
214            let ctx = InitializeAccountCtx::load(accounts)?;
215            instructions::token::initialize_account::handler(ctx)
216        }
217        CreatorStandardInstruction::Revoke => {
218            msg!("CreatorStandardInstruction::Revoke");
219            let ctx = RevokeCtx::load(accounts)?;
220            instructions::token::revoke::handler(ctx)
221        }
222        CreatorStandardInstruction::Transfer => {
223            msg!("CreatorStandardInstruction::Transfer");
224            let ctx = TransferCtx::load(accounts)?;
225            instructions::token::transfer::handler(ctx)
226        }
227        CreatorStandardInstruction::CloseMintManager => {
228            msg!("CreatorStandardInstruction::CloseMintManager");
229            let ctx = CloseMintManagerCtx::load(accounts)?;
230            instructions::mint_manager::close_mint_manager::handler(ctx)
231        }
232    }
233}