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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use crate::*;
pub fn handler(ctx: Context<NewRewarder>) -> Result<()> {
let rewarder = &mut ctx.accounts.rewarder;
rewarder.base = ctx.accounts.base.key();
rewarder.bump = unwrap_bump!(ctx, "rewarder");
rewarder.authority = ctx.accounts.initial_authority.key();
rewarder.pending_authority = Pubkey::default();
rewarder.annual_rewards_rate = 0;
rewarder.num_quarries = 0;
rewarder.total_rewards_shares = 0;
rewarder.mint_wrapper = ctx.accounts.mint_wrapper.key();
rewarder.rewards_token_mint = ctx.accounts.rewards_token_mint.key();
rewarder.claim_fee_token_account = ctx.accounts.claim_fee_token_account.key();
rewarder.max_claim_fee_millibps = DEFAULT_CLAIM_FEE_MILLIBPS;
rewarder.pause_authority = Pubkey::default();
rewarder.is_paused = false;
let current_ts = Clock::get()?.unix_timestamp;
emit!(NewRewarderEvent {
authority: rewarder.authority,
timestamp: current_ts,
});
Ok(())
}
#[derive(Accounts)]
pub struct NewRewarder<'info> {
pub base: Signer<'info>,
#[account(
init,
seeds = [
b"Rewarder".as_ref(),
base.key().to_bytes().as_ref()
],
bump,
payer = payer,
space = 8 + Rewarder::LEN
)]
pub rewarder: Account<'info, Rewarder>,
pub initial_authority: UncheckedAccount<'info>,
#[account(mut)]
pub payer: Signer<'info>,
pub system_program: Program<'info, System>,
pub unused_account: UncheckedAccount<'info>,
pub mint_wrapper: Account<'info, quarry_mint_wrapper::MintWrapper>,
pub rewards_token_mint: Account<'info, Mint>,
pub claim_fee_token_account: Account<'info, TokenAccount>,
}
impl<'info> Validate<'info> for NewRewarder<'info> {
fn validate(&self) -> Result<()> {
invariant!(self.base.is_signer, Unauthorized);
assert_keys_eq!(self.mint_wrapper.token_mint, self.rewards_token_mint);
assert_keys_eq!(
self.rewards_token_mint.mint_authority.unwrap(),
self.mint_wrapper
);
assert_keys_eq!(self.claim_fee_token_account.owner, self.rewarder);
assert_keys_eq!(self.claim_fee_token_account.mint, self.rewards_token_mint);
invariant!(self.claim_fee_token_account.delegate.is_none());
invariant!(self.claim_fee_token_account.close_authority.is_none());
Ok(())
}
}
#[event]
pub struct NewRewarderEvent {
#[index]
pub authority: Pubkey,
pub timestamp: i64,
}