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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use crate::*;
pub fn handler(ctx: Context<CreateQuarry>) -> Result<()> {
let rewarder = &mut ctx.accounts.auth.rewarder;
let index = rewarder.num_quarries;
rewarder.num_quarries = unwrap_int!(rewarder.num_quarries.checked_add(1));
let quarry = &mut ctx.accounts.quarry;
quarry.bump = unwrap_bump!(ctx, "quarry");
quarry.index = index;
quarry.famine_ts = i64::MAX;
quarry.rewarder = rewarder.key();
quarry.annual_rewards_rate = 0;
quarry.rewards_share = 0;
quarry.token_mint_decimals = ctx.accounts.token_mint.decimals;
quarry.token_mint_key = ctx.accounts.token_mint.key();
let current_ts = Clock::get()?.unix_timestamp;
emit!(QuarryCreateEvent {
token_mint: quarry.token_mint_key,
timestamp: current_ts,
});
Ok(())
}
#[derive(Accounts)]
pub struct CreateQuarry<'info> {
#[account(
init,
seeds = [
b"Quarry".as_ref(),
auth.rewarder.key().to_bytes().as_ref(),
token_mint.key().to_bytes().as_ref()
],
bump,
payer = payer,
space = 8 + Quarry::LEN
)]
pub quarry: Account<'info, Quarry>,
pub auth: MutableRewarderWithAuthority<'info>,
pub token_mint: Account<'info, Mint>,
#[account(mut)]
pub payer: Signer<'info>,
pub unused_account: UncheckedAccount<'info>,
pub system_program: Program<'info, System>,
}
impl<'info> Validate<'info> for CreateQuarry<'info> {
fn validate(&self) -> Result<()> {
self.auth.validate()?;
invariant!(!self.auth.rewarder.is_paused, Paused);
Ok(())
}
}