quarry_mint_wrapper/instructions/
new_minter.rs1use crate::*;
2
3pub fn handler(ctx: Context<NewMinter>) -> Result<()> {
4 let minter = &mut ctx.accounts.minter;
5
6 minter.mint_wrapper = ctx.accounts.auth.mint_wrapper.key();
7 minter.minter_authority = ctx.accounts.new_minter_authority.key();
8 minter.bump = unwrap_bump!(ctx, "minter");
9
10 let index = ctx.accounts.auth.mint_wrapper.num_minters;
11 minter.index = index;
12
13 let mint_wrapper = &mut ctx.accounts.auth.mint_wrapper;
15 mint_wrapper.num_minters = unwrap_int!(index.checked_add(1));
16
17 minter.allowance = 0;
18 minter.total_minted = 0;
19
20 emit!(NewMinterEvent {
21 mint_wrapper: minter.mint_wrapper,
22 minter: minter.key(),
23 index: minter.index,
24 minter_authority: minter.minter_authority,
25 });
26 Ok(())
27}
28
29#[derive(Accounts)]
31pub struct NewMinter<'info> {
32 pub auth: OnlyAdmin<'info>,
34
35 pub new_minter_authority: UncheckedAccount<'info>,
38
39 #[account(
41 init,
42 seeds = [
43 b"MintWrapperMinter".as_ref(),
44 auth.mint_wrapper.key().to_bytes().as_ref(),
45 new_minter_authority.key().to_bytes().as_ref()
46 ],
47 bump,
48 payer = payer,
49 space = 8 + Minter::LEN
50 )]
51 pub minter: Account<'info, Minter>,
52
53 #[account(mut)]
55 pub payer: Signer<'info>,
56
57 pub system_program: Program<'info, System>,
59}
60
61impl<'info> Validate<'info> for NewMinter<'info> {
62 fn validate(&self) -> Result<()> {
63 self.auth.validate()?;
64 Ok(())
65 }
66}