Skip to main content

quarry_mint_wrapper/instructions/
new_wrapper.rs

1use crate::*;
2
3pub fn handler(ctx: Context<NewWrapper>, hard_cap: u64) -> Result<()> {
4    let mint_wrapper = &mut ctx.accounts.mint_wrapper;
5    mint_wrapper.base = ctx.accounts.base.key();
6    mint_wrapper.bump = unwrap_bump!(ctx, "mint_wrapper");
7    mint_wrapper.hard_cap = hard_cap;
8    mint_wrapper.admin = ctx.accounts.admin.key();
9    mint_wrapper.pending_admin = Pubkey::default();
10    mint_wrapper.token_mint = ctx.accounts.token_mint.key();
11    mint_wrapper.num_minters = 0;
12
13    mint_wrapper.total_allowance = 0;
14    mint_wrapper.total_minted = 0;
15
16    emit!(NewMintWrapperEvent {
17        mint_wrapper: mint_wrapper.key(),
18        hard_cap,
19        admin: ctx.accounts.admin.key(),
20        token_mint: ctx.accounts.token_mint.key()
21    });
22
23    Ok(())
24}
25
26#[derive(Accounts)]
27pub struct NewWrapper<'info> {
28    /// Base account.
29    pub base: Signer<'info>,
30
31    #[account(
32        init,
33        seeds = [
34            b"MintWrapper".as_ref(),
35            base.key().to_bytes().as_ref()
36        ],
37        bump,
38        payer = payer,
39        space = 8 + MintWrapper::LEN
40    )]
41    pub mint_wrapper: Account<'info, MintWrapper>,
42
43    /// CHECK: Admin-to-be of the [MintWrapper].
44    pub admin: UncheckedAccount<'info>,
45
46    /// Token mint to mint.
47    pub token_mint: Account<'info, Mint>,
48
49    /// Token program.
50    pub token_program: Program<'info, Token>,
51
52    /// Payer.
53    #[account(mut)]
54    pub payer: Signer<'info>,
55
56    /// System program.
57    pub system_program: Program<'info, System>,
58}
59
60impl<'info> Validate<'info> for NewWrapper<'info> {
61    fn validate(&self) -> Result<()> {
62        assert_keys_eq!(self.token_mint.mint_authority.unwrap(), self.mint_wrapper);
63        assert_keys_eq!(self.token_mint.freeze_authority.unwrap(), self.mint_wrapper);
64        Ok(())
65    }
66}