-
Notifications
You must be signed in to change notification settings - Fork 110
/
initialize_reward.rs
42 lines (33 loc) · 1.13 KB
/
initialize_reward.rs
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
use anchor_lang::prelude::*;
use anchor_spl::token::{self, Mint, Token, TokenAccount};
use crate::state::Whirlpool;
#[derive(Accounts)]
#[instruction(reward_index: u8)]
pub struct InitializeReward<'info> {
#[account(address = whirlpool.reward_infos[reward_index as usize].authority)]
pub reward_authority: Signer<'info>,
#[account(mut)]
pub funder: Signer<'info>,
#[account(mut)]
pub whirlpool: Box<Account<'info, Whirlpool>>,
pub reward_mint: Box<Account<'info, Mint>>,
#[account(
init,
payer = funder,
token::mint = reward_mint,
token::authority = whirlpool
)]
pub reward_vault: Box<Account<'info, TokenAccount>>,
#[account(address = token::ID)]
pub token_program: Program<'info, Token>,
pub system_program: Program<'info, System>,
pub rent: Sysvar<'info, Rent>,
}
pub fn handler(ctx: Context<InitializeReward>, reward_index: u8) -> Result<()> {
let whirlpool = &mut ctx.accounts.whirlpool;
Ok(whirlpool.initialize_reward(
reward_index as usize,
ctx.accounts.reward_mint.key(),
ctx.accounts.reward_vault.key(),
)?)
}