2

I'm trying to get a liquidity pool of a token that is own by my program. This would be simple on other blockchains but I admit I'm having a bit of trouble on Solana.

First here is the important part of my Anchor code :

#[derive(Accounts)]
pub struct Test1<'info> {
    #[account(mut)]
    pub from: Signer<'info>,
    #[account(
        init_if_needed,
        payer = from, 
        seeds = [b"tests"],
        bump,
        space = 24
    )]
    pub staked: Account<'info, StakedAccount>,
    #[account(
        init_if_needed,
        payer = from, 
        seeds = [b"data123"],
        bump,
        space = 32
    )]
    pub data: Account<'info, DataAccount>,
    #[account(mut)]
    pub from_ata: Account<'info, TokenAccount>,
     #[account(
        init_if_needed,
        payer = from_ata,
        token::mint = mint,
        token::authority = data
    )]
    pub program_ata: Account<'info, TokenAccount>,
    #[account(
        address = MINT_ACCOUNT
    )]
    pub mint: Account<'info, Mint>,
    pub associated_token_program: Program<'info, AssociatedToken>,
    pub token_program: Program<'info, Token>,
    pub system_program: Program<'info, System>,
    pub rent: Sysvar<'info, Rent>,
}

And here is the instruction to call the program :

let txHash = await pg.program.methods
  .test()
  .accounts({
    staked:stakedTest,
    data:stakedTest2,
    from: pg.wallet.publicKey,
    fromAta: ata_user,
    programAta: ata_program,
    mint: MINT_USDC,
    tokenProgram: TOKEN_PROGRAM_ID,
    systemProgram:anchor.web3.SystemProgram.programId,
    associatedTokenProgram:SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID,
    rent: anchor.web3.SYSVAR_RENT_PUBKEY
  })
  .rpc();
await logTransaction(txHash);

Basically, the idea would be for the token account (program_ata) to be owned by data (a PDA from my program). However, I want my program to authorize only the deposit of a particular token (USDC). That's why I use: associated_token::mint = mint, associated_token::authority = data.

I get this error: "Uncaught error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: An account required by the instruction is missing".

I'm sure it's from associated_token::mint = mint, associated_token::authority = data. Do you know why I'm getting this error? Is the logic right ?

Thanks

5
  • Does adding pub token_program: Program<'info, Token> as an account solve the issue? Also, try changing associated_token::mint to token::mint (do the same with authority), and report back if that solves your issue
    – Joey Meere
    Commented Jan 12 at 16:12
  • I already had pub token_program: Program<'info, Token> as an account (I just didn't show it in the snippet). I also tried to replace associated_token::mint to token::mint. But it doesn't work
    – Albear
    Commented Jan 12 at 16:20
  • With token::mint I get : Uncaught error: Signature verification failed
    – Albear
    Commented Jan 12 at 16:23
  • Gotcha. Can you provide a snippet of how you're calling this instruction? Also, can you add all the accounts you're including to the #[derive(Accounts)] snippet
    – Joey Meere
    Commented Jan 12 at 16:24
  • I have edited the original post to add all these informations :)
    – Albear
    Commented Jan 12 at 16:29

1 Answer 1

1

There is an anchor escrow program for you to use as a reference. The repo.

The notes for the repo are here.

You will need to know how Program Derived addresses works in order to understand Solana’s program model.

1
  • Please dont only paste links, but also add the code to do so and explain a bit how it works
    – Jonas H.
    Commented Feb 19 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.