1

I am trying to create a functionality where the admin can fund SPL tokens in the pool and any other user can claim from that pool.

I am using global authority as the authority for the pool address

pub struct CreateTweet<'info> {
    #[account(mut)]
    pub user: Signer<'info>,
    #[account(init, payer = user, seeds = [b"tweets", user.key().as_ref(), &[my_id as u8], &[my_id2 as u8]], bump, space = 64,)]
    pub tweetData: Account<'info, MyTweet>,
    #[account(
        mut,
        seeds = [GLOBAL_AUTHORITY_SEED.as_ref()],
        bump = global_bump,
    )]
    pub global_authority: Account<'info, GlobalPool>,
    #[account(
        init,
        payer = user,
        seeds = [b"pool", user.key().as_ref(), tweetData.key().as_ref()],
        bump,
        token::mint = pool_mint,
        token::authority = global_authority,
    )]
    pub pool: Account<'info, TokenAccount>,
    #[account(mut)]
    pub user_ata: Account<'info, TokenAccount>,
    pub pool_mint: Account<'info, Mint>,
    pub system_program: Program<'info, System>,
    pub token_program: Program<'info, Token>,
    pub rent: Sysvar<'info, Rent>,
}

this is my function where I am transferring SPL tokens from pool to user token account

    let seeds = &[GLOBAL_AUTHORITY_SEED.as_bytes(), &[global_bump]];
        let signer = &[&seeds[..]];

        
        
        token::transfer(
            CpiContext::new_with_signer(
                ctx.accounts.token_program.to_account_info(),
                token::Transfer {
                    from: ctx.accounts.pool.to_account_info(),
                    to: ctx.accounts.user_ata.to_account_info(),
                    authority: ctx.accounts.global_authority.to_account_info(),
                },
                signer
            ),
            1000000000
        )?;

But it is giving me an Error with code 0xbbf:

Error: #[msg("The given account is owned by a different program than expected")] AccountOwnedByWrongProgram

Also, the pool address is owned by the same address created with global authority seeds

Global authority address: https://explorer.solana.com/address/3Z3vN7UUoDcCWpYksnM5nj7BHgERQKhbKTEEXnnratk6?cluster=devnet

Pool (account) address: https://explorer.solana.com/address/FyJWLhuZase1mVpVraRHU6HBav9heHmS1Bu28NckRfSj?cluster=devnet

1
  • can you provide the context where you have initialized global_authority?
    – vicyyn
    Aug 2, 2022 at 15:01

1 Answer 1

1

Your seeds for global_authority in the validator are [GLOBAL_AUTHORITY_SEED.as_ref()]. Your signer seeds are [GLOBAL_AUTHORITY_SEED.as_bytes()]. These don't match and that's why you're getting that error.

Update
If you absolutely have to, here's to declare a constant you intend to use as one of the seeds of a PDA:

const GLOBAL_AUTHORITY_SEED: &[u8] = "global-authority".as_bytes();

and in your validator:

seeds=[GLOBAL_AUTHORITY_SEED]
10
  • Switching as_bytes to as_ref it is giving error on compilation time: expected reference &[&[&[u8]]] found reference &[&[&[u8; 1]]; 1] also, have tried using as_byte on both sides. same results for me.
    – PenandWeb
    Aug 1, 2022 at 9:49
  • What is your 'GLOBAL_AUTHORITY_SEED'?
    – Ademola
    Aug 1, 2022 at 9:54
  • its string: pub const GLOBAL_AUTHORITY_SEED: &str = "global-authority";
    – PenandWeb
    Aug 1, 2022 at 9:55
  • In that case your seeds should be [GLOBAL_AUTHORITY_SEED].as_bytes().as_ref()
    – Ademola
    Aug 1, 2022 at 10:02
  • Just tried it ... but same error..!!
    – PenandWeb
    Aug 1, 2022 at 10:34

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.