Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the trait Discriminator is not implemented for anchor_spl::token_interface::TokenAccount #2

Open
cxp-13 opened this issue Aug 5, 2024 · 2 comments

Comments

@cxp-13
Copy link

cxp-13 commented Aug 5, 2024

token22-staking-latest/programs/token22-staking-latest/src/instructions/init_pool.rs:

use {
    anchor_lang::prelude::*,
    crate::{state::*, utils::*},
    anchor_spl::*,
    std::mem::size_of
};

pub fn handler(ctx: Context<InitializePool>) -> Result <()> {
    check_token_program(ctx.accounts.token_program.key());
    
    // initialize pool state
    let pool_state = &mut ctx.accounts.pool_state;
    pool_state.bump = ctx.bumps.pool_state;
    pool_state.amount = 0;
    pool_state.vault_bump = ctx.bumps.token_vault;
    pool_state.vault_auth_bump = ctx.bumps.pool_authority;
    pool_state.token_mint = ctx.accounts.token_mint.key();
    pool_state.staking_token_mint = ctx.accounts.staking_token_mint.key();
    pool_state.vault_authority = ctx.accounts.pool_authority.key();

    msg!("Staking pool created!");

    Ok(())
}

#[derive(Accounts)]
pub struct InitializePool<'info> {
    /// CHECK: PDA, auth over all token vaults
    #[account(
        seeds = [VAULT_AUTH_SEED.as_bytes()],
        bump
    )]
    pub pool_authority: UncheckedAccount<'info>,
    // pool state account
    #[account(
        init,
        seeds = [token_mint.key().as_ref(), STAKE_POOL_STATE_SEED.as_bytes()],
        bump,
        payer = payer,
        space = 8 + size_of::<PoolState>()
    )]
    pub pool_state: Account<'info, PoolState>,
    // Mint of token
    #[account(
        mint::token_program = token_program,
        mint::authority = payer
    )]
    pub token_mint: InterfaceAccount<'info, token_interface::Mint>,
    // pool token account for Token Mint
    #[account(
        init,
        token::mint = token_mint,
        token::authority = pool_authority,
        token::token_program = token_program,
        // use token_mint, pool auth, and constant as seeds for token a vault
        seeds = [token_mint.key().as_ref(), pool_authority.key().as_ref(), VAULT_SEED.as_bytes()],
        bump,
        payer = payer,
    )]
    pub token_vault: InterfaceAccount<'info, token_interface::TokenAccount>,
    // Mint of staking token
    #[account(
        mut,
        mint::token_program = token_program
    )]
    pub staking_token_mint: InterfaceAccount<'info, token_interface::Mint>,
    // payer, will pay for creation of pool vault
    #[account(mut)]
    pub payer: Signer<'info>,
    pub token_program: Interface<'info, token_interface::TokenInterface>,
    pub system_program: Program<'info, System>,
    pub rent: Sysvar<'info, Rent>
}
error[E0599]: no function or associated item named `create_type` found for struct `anchor_spl::token_interface::Mint` in the current scope
  --> programs/token22-staking-latest/src/instructions/init_pool.rs:26:10
   |
26 | #[derive(Accounts)]
   |          ^^^^^^^^ function or associated item not found in `Mint`
   |
   = note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `anchor_spl::token_interface::Mint: Discriminator` is not satisfied
  --> programs/token22-staking-latest/src/instructions/init_pool.rs:48:45
   |
48 |     pub token_mint: InterfaceAccount<'info, token_interface::Mint>,
   |                                             ^^^^^^^^^^^^^^^^^^^^^ the trait `Discriminator` is not implemented for `anchor_spl::token_interface::Mint`
   |
   = help: the following other types implement trait `Discriminator`:
             InitPool
             InitStakeEntry
             StakeEntry
             __idl::IdlAccount
             anchor_lang::ProgramData
             anchor_lang::idl::IdlAccount
             instruction::Stake
             instruction::Unstake
             state::PoolState

error[E0599]: no function or associated item named `insert_types` found for struct `anchor_spl::token_interface::Mint` in the current scope
  --> programs/token22-staking-latest/src/instructions/init_pool.rs:26:10
   |
26 | #[derive(Accounts)]
   |          ^^^^^^^^ function or associated item not found in `Mint`
   |
   = note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no function or associated item named `create_type` found for struct `anchor_spl::token_interface::TokenAccount` in the current scope
  --> programs/token22-staking-latest/src/instructions/init_pool.rs:26:10
   |
26 | #[derive(Accounts)]
   |          ^^^^^^^^ function or associated item not found in `TokenAccount`
   |
   = note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `anchor_spl::token_interface::TokenAccount: Discriminator` is not satisfied
  --> programs/token22-staking-latest/src/instructions/init_pool.rs:60:46
   |
60 |     pub token_vault: InterfaceAccount<'info, token_interface::TokenAccount>,
   |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Discriminator` is not implemented for `anchor_spl::token_interface::TokenAccount`
   |
   = help: the following other types implement trait `Discriminator`:
             InitPool
             InitStakeEntry
             StakeEntry
             __idl::IdlAccount
             anchor_lang::ProgramData
             anchor_lang::idl::IdlAccount
             instruction::Stake
             instruction::Unstake
             state::PoolState

error[E0599]: no function or associated item named `insert_types` found for struct `anchor_spl::token_interface::TokenAccount` in the current scope
  --> programs/token22-staking-latest/src/instructions/init_pool.rs:26:10
   |
26 | #[derive(Accounts)]
   |          ^^^^^^^^ function or associated item not found in `TokenAccount`
   |
   = note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `anchor_spl::token_interface::Mint: Discriminator` is not satisfied
  --> programs/token22-staking-latest/src/instructions/init_pool.rs:66:53
   |
66 |     pub staking_token_mint: InterfaceAccount<'info, token_interface::Mint>,
   |                                                     ^^^^^^^^^^^^^^^^^^^^^ the trait `Discriminator` is not implemented for `anchor_spl::token_interface::Mint`
   |
   = help: the following other types implement trait `Discriminator`:
             InitPool
             InitStakeEntry
             StakeEntry
             __idl::IdlAccount
             anchor_lang::ProgramData
             anchor_lang::idl::IdlAccount
             instruction::Stake
             instruction::Unstake
             state::PoolState

warning: unused variable: `stake_amount`
  --> programs/token22-staking-latest/src/instructions/stake.rs:10:37
   |
10 | pub fn handler(ctx: Context<Stake>, stake_amount: u64) -> Result <()> {
   |                                     ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_stake_amount`
   |
   = note: `#[warn(unused_variables)]` on by default

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
warning: `token22-staking-latest` (lib test) generated 5 warnings
error: could not compile `token22-staking-latest` (lib test) due to 7 previous errors; 5 warnings emitted
Error: Building IDL failed
[dependencies]
anchor-lang = "0.30.1"
anchor-spl = "0.30.1"
solana-program = "2.0.4"
spl-token = "6.0.0"
spl-token-2022 = "3.0.4"
@Blessedbiello
Copy link

have you gotten a solution? add this to your cargo.toml file, under [features]
idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]

@austbot
Copy link

austbot commented Sep 6, 2024

this worked for me, thanks @Blessedbiello

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants