2
        accounts: {
            pool: pool.publicKey,
            longPayer: longKeypair.publicKey,
            shortPayer: shortKeypair.publicKey,
            mint: gdTokenMint,
            authority: gdTokenKeypair.publicKey,
            from: longusdc,
            from2: shortusdc,
            transferTo: poolusdc,
            mintTo: poolgd,
            tokenProgram: Spl.TOKEN_PROGRAM_ID,
            systemProgram: anchor.web3.SystemProgram.programId,
        },
        signers: [pool, longKeypair, shortKeypair, gdTokenKeypair],
    });
            from: ctx.accounts.from.to_account_info(),
            to: ctx.accounts.transferTo.to_account_info(),
            authority: ctx.accounts.longPayer.to_account_info(),
        };
        let cpi_program1 = ctx.accounts.token_program.to_account_info();
        let cpi_ctx1 = CpiContext::new(cpi_program1, cpi_accounts1);

        token::transfer(cpi_ctx1, long_col)?;

        let cpi_accounts2 = Transfer {
            from: ctx.accounts.from2.to_account_info(),
            to: ctx.accounts.transferTo.to_account_info(),
            authority: ctx.accounts.shortPayer.to_account_info(),
        };
        let cpi_program2 = ctx.accounts.token_program.to_account_info();
        let cpi_ctx2 = CpiContext::new(cpi_program2, cpi_accounts2);

        token::transfer(cpi_ctx2, short_col)?;

        let cpi_accounts = MintTo {
            mint: ctx.accounts.mint.to_account_info(),
            to: ctx.accounts.mintTo.to_account_info(),
            authority: ctx.accounts.authority.to_account_info(),
        };
        let cpi_program = ctx.accounts.token_program.to_account_info();
        let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);

        token::mint_to(cpi_ctx, long_col)?; 
#[derive(Accounts)]
pub struct CreatePool<'info> {
    #[account(init, payer = longPayer, space = Pool::LEN)]
    pub pool: Account<'info, Pool>,
    pub authority: Signer<'info>,
    #[account(mut)]
    pub longPayer: Signer<'info>,
    #[account(mut)]
    pub shortPayer: Signer<'info>,
    #[account(mut)]
    pub mint: Account<'info, Mint>,
    #[account(mut)]
    pub from: Account<'info, TokenAccount>,
    #[account(mut)]
    pub from2: Account<'info, TokenAccount>,
    #[account(mut)]
    pub mintTo: Account<'info, TokenAccount>,
    #[account(mut)]
    pub transferTo: Account<'info, TokenAccount>,
    pub token_program: Program<'info, Token>,
    pub system_program: Program<'info, System>,
}

The error message is not giving me any good leads.

Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Program failed to complete

2 Answers 2

1

You need to send the transaction with preflightChecks: false so that you can get the full error message in the program logs. There's no issue with calling two CPIs in one transaction.

1

I got similar issue before and solved with zero copy. the problem with two cpi calls is that you need to copy the account info twice. Solana call stack has a fixed size for all the nested cpis. you can read more here: https://docs.solana.com/developing/on-chain-programs/overview#:~:text=Each%20stack%20frame%20is%204KB%20in%20size. There's also a new address look up table coming up, aim to solve this problem, you can follow up here: https://docs.solana.com/proposals/transactions-v2

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.