1

I'm now developing on solana blockchain. I want to users can deposit and refund their sol on my pool. create_pool works well it means users can deposit their sol to my pool. but cancel_pool error. here is my code.

pub fn cancel_pool(ctx: Context<CancelPool>, _pool_id: u64) -> Result<()> {
        let pool = &mut ctx.accounts.pool;
        let configuration = &mut ctx.accounts.configuration;

        if pool.pool_status == false {
            return Err(ErrorCode::PoolAlreadyClosed.into());
        }

        let nonce = *(ctx.bumps.get("mun_sol_vault").unwrap());
        // Transfer back additional collateral
        {
            let seeds = &[ctx.accounts.mun_sol_mint.to_account_info().key.as_ref(), constants::MUN_SOL_VAULT_SEED.as_ref(), &[nonce]];
            let signer = &[&seeds[..]];
            
            let cpi_context = CpiContext::new_with_signer(
            ctx.accounts.system_program.to_account_info(), 
            system_program::Transfer {
                from: ctx.accounts.mun_sol_vault.to_account_info(),
                to: ctx.accounts.user_sol_vault.to_account_info()
            },
            signer);
            system_program::transfer(cpi_context, pool.deposit_amount)?;
        }
        
        Ok(())
    }

#[derive(Accounts)]
#[instruction(_pool_id: u64)]
pub struct CancelPool<'info> {
    #[account(
        mut,
        has_one = mun_sol_vault,
        has_one = mun_sol_mint
    )]
    pub configuration: Box<Account<'info, Configuration>>,

    // Order.
    #[account(
        mut,
        seeds = [
            _pool_id.to_string().as_ref(),
            constants::MUN_POOL_SEED.as_ref(),
            configuration.to_account_info().key().as_ref()
        ],
        bump,
        constraint = pool.mun_sol_vault == mun_sol_vault.key(),
        close = signer
    )]
    pub pool: Box<Account<'info, LenderPool>>,

    pub mun_sol_mint: Box<Account<'info, Mint>>,

    #[account(
        mut,
        seeds = [mun_sol_mint.key().as_ref(), constants::MUN_SOL_VAULT_SEED.as_ref()],
        bump,
    )]
    pub mun_sol_vault: AccountInfo<'info>,

    #[account(mut)]
    pub user_sol_vault: AccountInfo<'info>,

    #[account(
        mut
    )]
    pub signer: Signer<'info>,
    // misc
    pub system_program: Program<'info, System>,
    pub token_program: Program<'info, Token>
}

please help me.

3
  • This should help. Check it out!
    – Ademola
    Commented May 4, 2023 at 19:34
  • Do you have the actual error?
    – Jacob Creech
    Commented May 5, 2023 at 18:05
  • Thank you for your reply. I have an error like this 'Signature verification failed' or in some case 'Invalid program argument'. I think getting signer of PDA account with nonce and seed isn't valid. plz help me.
    – Watcher
    Commented May 6, 2023 at 6:46

0

Your Answer

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

Browse other questions tagged or ask your own question.