/* Considering the following program has all the other normal functionality can you identify what can go wrong here? Maybe I can if you don't want to */
use anchor_lang::prelude::*;
declare_id!("CeURMdWWbKoJe9BRvK1brgMik2EFrp1eB33SXWeA7pyW");
#[program]
pub mod let_me_claim_it {
use super::*;
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
Ok(())
}
pub fn claim_rewards(ctx: Context<ClaimRewards>) -> Result<()> {
let user_account = &mut ctx.accounts.user_account;
let clock_time = Clock::get()?;
let reward = (clock_time.slot - user_account.deposit_time) - user_account.reward_debt;
let cpi_accounts = MintTo {
mint: ctx.accounts.staking_token.to_account_info(),
to: ctx.accounts.user_staking_account.to_account_info(),
authority: ctx.accounts.admin.to_account_info(),
};
let cpi_program = ctx.accounts.token_account.to_account_info();
let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);
token::mint_to(cpi_ctx, reward)?;
user_account.reward_debt += reward;
Ok(())
}
}
#[derive(Accounts)]
pub struct ClaimRewards<'info> {
/// User who is going to stake
#[account(mut)]
pub user: Signer<'info>,
/// User account who is going to stake
#[account(mut)]
pub user_account: Account<'info, User>,
/// CHECK: Just to check the owner
#[account(mut)]
pub admin: AccountInfo<'info>,
/// The token which is going to be staked
#[account(mut)]
pub staking_token: InterfaceAccount<'info, Mint>,
/// ATA of the token for user
#[account(mut)]
pub user_staking_account: InterfaceAccount<'info, TokenAccount>,
/// ATA of the token for admin
#[account(mut)]
pub token_account: InterfaceAccount<'info, TokenAccount>,
/// The token program for the token staking token
pub token_program: Interface<'info, TokenInterface>,
}
#[account]
pub struct Escrow {
pub admin: Pubkey,
pub token: Pubkey,
pub total_amount: u64
}
#[account]
pub struct User {
pub amount: u64,
pub reward_debt: u64,
pub deposit_time: u64
}