quarry_operator/instructions/
delegate_create_quarry.rs

1use crate::*;
2
3/// Calls [quarry_mine::quarry_mine::create_quarry].
4pub fn handler(ctx: Context<DelegateCreateQuarry>) -> Result<()> {
5    let operator = &ctx.accounts.with_delegate.operator;
6    let signer_seeds: &[&[&[u8]]] = &[gen_operator_signer_seeds!(operator)];
7    quarry_mine::cpi::create_quarry_v2(CpiContext::new_with_signer(
8        ctx.accounts
9            .with_delegate
10            .quarry_mine_program
11            .to_account_info(),
12        quarry_mine::cpi::accounts::CreateQuarryV2 {
13            quarry: ctx.accounts.quarry.to_account_info(),
14            auth: ctx.accounts.with_delegate.to_auth_accounts(),
15            token_mint: ctx.accounts.token_mint.to_account_info(),
16            payer: ctx.accounts.payer.to_account_info(),
17            system_program: ctx.accounts.system_program.to_account_info(),
18        },
19        signer_seeds,
20    ))?;
21    Ok(())
22}
23
24/// Accounts for [crate::quarry_operator::delegate_create_quarry_v2].
25#[derive(Accounts)]
26pub struct DelegateCreateQuarry<'info> {
27    /// Delegate information.
28    pub with_delegate: WithDelegate<'info>,
29
30    /// The Quarry to create.
31    #[account(mut)]
32    pub quarry: SystemAccount<'info>,
33
34    /// Mint of the Quarry being created.
35    pub token_mint: Box<Account<'info, anchor_spl::token::Mint>>,
36
37    /// Payer of [Quarry] creation.
38    #[account(mut)]
39    pub payer: Signer<'info>,
40
41    /// Unused variable that held the clock. Placeholder.
42    /// CHECK: OK
43    pub unused_account: UncheckedAccount<'info>,
44
45    /// System program.
46    pub system_program: Program<'info, System>,
47}
48
49impl<'info> Validate<'info> for DelegateCreateQuarry<'info> {
50    fn validate(&self) -> Result<()> {
51        assert_keys_eq!(
52            self.with_delegate.operator.quarry_creator,
53            self.with_delegate.delegate,
54            Unauthorized
55        );
56        self.with_delegate.validate()?;
57        Ok(())
58    }
59}