raydium-io / raydium-cpi-example

cpi call example for amm, cpswap and clmm program
16 stars 6 forks source link

Calling contract enforces seeds/bump using the calling contracts program id. #1

Open yornaath opened 3 months ago

yornaath commented 3 months ago

Implementing this example(cp-swap-cpi) locally I ran into errors where seed constraints for accounts like authority are violated, probably since the account::seeds macro checks if the account passed mathches the seed discriminator + the calling programm:id. But it should be seed desicriminator + raydium_cp_swap:programId.

Omitting the seeds and the bump fixes the problem for me and I am able to cpi into the raydium contract and init a pool.

/// CHECK: pool vault and lp mint authority
#[account(mut)]
pub authority: UncheckedAccount<'info>,

I think this is fine since the underlying raydium contract enforces the correct seed?

0x777A commented 2 months ago

I have add a seeds::program constraint to fix it.

#[derive(Accounts)]
pub struct ProxyInitialize<'info> {
    pub cp_swap_program: Program<'info, RaydiumCpSwap>,
    /// Address paying to create the pool. Can be anyone
    #[account(mut)]
    pub creator: Signer<'info>,

    /// Which config the pool belongs to.
    pub amm_config: Box<Account<'info, AmmConfig>>,

    /// CHECK: pool vault and lp mint authority
    #[account(
        seeds = [
            raydium_cp_swap::AUTH_SEED.as_bytes(),
        ],
        seeds::program = cp_swap_program,
        bump,
    )]
    pub authority: UncheckedAccount<'info>,
    .....
}