mpl_candy_guard/
lib.rs

1#![allow(clippy::result_large_err)]
2
3use anchor_lang::prelude::*;
4
5use instructions::*;
6
7pub mod errors;
8pub mod guards;
9pub mod instructions;
10pub mod state;
11pub mod utils;
12
13declare_id!("CguarSUzT8jJEudNF9adPGeQnwcaf7i5CgFWdRbLEvfN");
14
15#[program]
16pub mod candy_guard {
17    use super::*;
18
19    /// Create a new candy guard account.
20    pub fn initialize(ctx: Context<Initialize>, data: Vec<u8>) -> Result<()> {
21        instructions::initialize(ctx, data)
22    }
23
24    /// Mint an NFT from a candy machine wrapped in the candy guard.
25    pub fn mint<'info>(
26        ctx: Context<'_, '_, '_, 'info, Mint<'info>>,
27        mint_args: Vec<u8>,
28        label: Option<String>,
29    ) -> Result<()> {
30        instructions::mint(ctx, mint_args, label)
31    }
32
33    /// Mint an NFT from a candy machine wrapped in the candy guard.
34    pub fn mint_v2<'info>(
35        ctx: Context<'_, '_, '_, 'info, MintV2<'info>>,
36        mint_args: Vec<u8>,
37        label: Option<String>,
38    ) -> Result<()> {
39        instructions::mint_v2(ctx, mint_args, label)
40    }
41
42    /// Route the transaction to a guard instruction.
43    pub fn route<'info>(
44        ctx: Context<'_, '_, '_, 'info, Route<'info>>,
45        args: RouteArgs,
46        label: Option<String>,
47    ) -> Result<()> {
48        instructions::route(ctx, args, label)
49    }
50
51    /// Set a new authority of the candy guard.
52    pub fn set_authority(ctx: Context<SetAuthority>, new_authority: Pubkey) -> Result<()> {
53        instructions::set_authority(ctx, new_authority)
54    }
55
56    /// Remove a candy guard from a candy machine, setting the authority to the
57    /// candy guard authority.
58    pub fn unwrap(ctx: Context<Unwrap>) -> Result<()> {
59        instructions::unwrap(ctx)
60    }
61
62    /// Update the candy guard configuration.
63    pub fn update(ctx: Context<Update>, data: Vec<u8>) -> Result<()> {
64        instructions::update(ctx, data)
65    }
66
67    /// Withdraw the rent SOL from the candy guard account.
68    pub fn withdraw(ctx: Context<Withdraw>) -> Result<()> {
69        instructions::withdraw(ctx)
70    }
71
72    /// Add a candy guard to a candy machine. After the guard is added, mint
73    /// is only allowed through the candy guard.
74    pub fn wrap(ctx: Context<Wrap>) -> Result<()> {
75        instructions::wrap(ctx)
76    }
77}