1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use anchor_lang::prelude::*;

use crate::state::{Fee, FeeAccount};

#[derive(Accounts)]
#[instruction(amount: u64)]
pub struct FeeClaim<'info> {
    #[account(mut)]
    pub authority: Signer<'info>,

    #[account(mut)]
    pub pay_to: SystemAccount<'info>,

    #[account(
        mut,
        address = fee.pubkey(),
        has_one = authority,
    )]
    pub fee: Account<'info, Fee>,
}

pub fn handler<'info>(ctx: Context<FeeClaim>, amount: u64) -> Result<()> {
    // Get accounts
    let pay_to = &mut ctx.accounts.pay_to;
    let fee = &mut ctx.accounts.fee;

    // Claim the fee funds
    fee.claim_worker_balance(amount, pay_to)?;

    Ok(())
}