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
use crate::Jungle;
use anchor_lang::prelude::*;

#[derive(Accounts)]
pub struct UpdateRewardToken<'info> {
    /// The Jungle
    #[account(
        mut,
        // has_one = owner,
    )]
    pub jungle: Account<'info, Jungle>,

    /// The mint of the reward token
    /// CHECK: This is not dangerous because we don't read or write from this account
    pub mint: AccountInfo<'info>,

    /// The wallet that owns the jungle
    pub owner: Signer<'info>,
}

pub fn handler(ctx: Context<UpdateRewardToken>, decimals: u8, value: u64) -> Result<()> {
    msg!("Update reward token");
    let mint = &ctx.accounts.mint;
    let jungle = &mut ctx.accounts.jungle;

    let found = jungle
        .reward_tokens
        .iter()
        .position(|x| x.mint == mint.key());
    if let Some(index) = found {
        jungle.reward_tokens[index].decimals = decimals;
        jungle.reward_tokens[index].value = value;
        msg!("Reward token updated!");
    } else {
        msg!("Mint not found!");
    }
    Ok(())
}