0

I'm new to solana and I'm trying to combine two swap transactions I got from jupiter API. In my attempt I got multiple types of errors depending on how the transaction's structure. I will post an error logs example but sometimes its different

logs: [ 'Program ComputeBudget111111111111111111111111111111 invoke [1]', 'Program ComputeBudget111111111111111111111111111111 success', 'Program ComputeBudget111111111111111111111111111111 invoke [1]', 'Program ComputeBudget111111111111111111111111111111 success', 'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]', 'Program log: CreateIdempotent', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]', 'Program log: Instruction: GetAccountDataSize', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1569 of 1394295 compute units', 'Program return: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA pQAAAAAAAAA=', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success', 'Program 11111111111111111111111111111111 invoke [2]', 'Program 11111111111111111111111111111111 success', 'Program log: Initialize the associated token account', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]', 'Program log: Instruction: InitializeImmutableOwner', 'Program log: Please upgrade to SPL Token 2022 for immutable owner support', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1405 of 1387708 compute units', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]', 'Program log: Instruction: InitializeAccount3', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3158 of 1383826 compute units', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success', 'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 19315 of 1399700 compute units', 'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL success', 'Program JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 invoke [1]', 'Program log: Instruction: SharedAccountsRoute', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]', 'Program log: Instruction: TransferChecked', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 6200 of 1363832 compute units', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success', 'Program log: AnchorError caused by account: swap_program. Error Code: ConstraintRaw. Error Number: 2003. Error Message: A raw constraint was violated.', 'Program JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 consumed 30615 of 1380385 compute units', 'Program JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4 failed: custom program error: 0x7d3' ]

var serializedTransaction = await decodeBase64Transaction(transactionData1.swapTransaction);
            const serializedTransaction2 = await decodeBase64Transaction(transactionData2.swapTransaction);
            

            const instractions1 = serializedTransaction.message.compiledInstructions
            const instractions2 = serializedTransaction2.message.compiledInstructions
            // console.log(instractions1)
            // console.log(instractions2)
            var table1 = serializedTransaction.message.addressTableLookups
            var table2 = serializedTransaction2.message.addressTableLookups

            table1.push(...table2)
            // console.log(table1)
            // console.log(table2)

            var addressLookupTableAccounts = await Promise.all(
                table1.map(async (lookup) => {
                    // console.log(typeof(lookup.accountKey));
            
                    let publicKey;
                    
                    if (lookup.accountKey instanceof PublicKey) {
                        publicKey = lookup.accountKey;
                    } else if (typeof lookup.accountKey === 'string') {
                        publicKey = new PublicKey(lookup.accountKey);
                    } else {
                        throw new Error("Invalid accountKey format");
                    }
            
                    const accountInfo = await connection.getAccountInfo(publicKey);
                    if (!accountInfo) {
                        throw new Error('Account info not found');
                    }
            
                    return new AddressLookupTableAccount({
                        key: publicKey,
                        state: AddressLookupTableAccount.deserialize(await connection.getAccountInfo(publicKey).then((res) => res.data)),
                    });
                })
            );
            
            
            var message = TransactionMessage.decompile(serializedTransaction.message,{addressLookupTableAccounts: addressLookupTableAccounts})
            var message2 = TransactionMessage.decompile(serializedTransaction2.message,{addressLookupTableAccounts: addressLookupTableAccounts})
            message.instructions.push(...message2.instructions.slice(2))
            console.log(addressLookupTableAccounts.length)
            console.log(serializedTransaction.message.addressTableLookups.length)
            message.recentBlockhash = serializedTransaction2.message.recentBlockhash
            console.log(message.instructions)

            serializedTransaction.message = message.compileToV0Message(addressLookupTableAccounts)
            
            
            serializedTransaction.sign([wallet]);
            const rawTransaction = serializedTransaction.serialize()
            

            
            const { txid } = await connection.sendRawTransaction(rawTransaction,{preflightCommitment: 'confirmed'});
            await connection.confirmTransaction(txid);
            console.log(`Transaction ID: ${txid}`);```

1 Answer 1

0

You can try Jito Labs Bundles.

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.