use anchor_lang::prelude::*;
use anchor_spl::token::Token;
use anchor_spl::token_interface::Mint;
declare_id!("FtUL5xL7oZasB5zaDUETbeHs9jcf9gopQD3Z1V92YyKv");
pub mod constants {
pub const VAULT_SEED: &[u8] = b"vault";
pub const STAKING_INFO_SEED: &[u8] = b"staking_info";
pub const TOKEN_SEED: &[u8] = b"token";
}
#[program]
pub mod solana_staking {
pub fn staking_deposit(context: Context<InitializeStaking>, amount: u64) -> Result<()> {
let user_public_key: Pubkey = context.accounts.user.key();
msg!("From {:?}", user_public_key);
msg!("Amount {:?}", amount);
Ok(())
}
}
#[derive(Accounts)]
pub struct InitializeStaking<'info> {
#[account(mut)]
pub user: Signer<'info>,
#[account(
init_if_needed,
payer = user,
seeds = [constants::VAULT_SEED],
bump,
token::mint = mint,
token::authority = token_vault_account
)]
pub token_vault_account: UncheckedAccount<'info>,
pub mint: Account<'info, Mint>,
pub token_program: Program<'info, Token>,
pub system_program: Program<'info, System>,
}
#[account]
#[derive(InitSpace)]
pub struct Staking {
pub user: Pubkey,
pub amount: u64,
}
Add a comment
|
1 Answer
If you want to use anchor_spl::token_interface::Mint
, you'll need to use InterfaceAccount
, ie:
pub mint: InterfaceAccount<'info, Mint>,
But in your case, since you're passing in Program<'info, Token>
and not Interface<'info, Token>
, you might be better off just using anchor_spl::token::Mint
instead of its interface version.