Reputation: 185
I am using raydium sdk to add liquidity to the pair, I have created the transaction but whenever it gets approved from the phatom wallet an error occurs which is stated below.
Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0
Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]
Program log: Allocate space for the associated token account
Program 11111111111111111111111111111111 invoke [2]
Allocate: account Address { address: 7hLSYuEhn7t1P62n9gpv2aG8peTtLvjSRKqSsk2MXa91, base: None } already in use
Program 11111111111111111111111111111111 failed: custom program error: 0x0
Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 8366 of 200000 compute units
Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: custom program error: 0x0
I need help to fix this as I am unable to identify the issue.
Below is my function code which I am using in ReactJS with the help of Raydium SDK.
const tokenReq = await solanaConnectionObj.getTokenAccountsByOwner(publicKey, { programId: TOKEN_PROGRAM_ID })
const parsedTokenAccounts = await solanaConnectionObj.getParsedTokenAccountsByOwner(publicKey, {
programId: TOKEN_PROGRAM_ID,
})
const tokenAccounts = []
for (let index = 0; index < tokenReq.value.length; index++) {
const rawResult = SPL_ACCOUNT_LAYOUT.decode(tokenReq.value[index].account.data)
if (
rawResult.mint.toString().toLowerCase() === tokenObj0.mint.toString().toLowerCase() ||
rawResult.mint.toString().toLowerCase() === tokenObj1.mint.toString().toLowerCase() ||
rawResult.mint.toString().toLowerCase() === RAYDIUM_LP_TOKEN_ACCOUNT.toLowerCase()
) {
tokenAccounts.push({
accountInfo: rawResult,
pubkey: publicKey,
})
}
}
const transactionData = await Liquidity.makeAddLiquidityTransaction({
poolKeys: RAYDIUM_POOL,
userKeys: {
tokenAccounts: tokenAccounts,
owner: publicKey,
payer: publicKey,
},
fixedSide: 'a',
amountInB: new TokenAmount(tokenObj1, amount0.toWei().toString()),
amountInA: new TokenAmount(tokenObj0, amount1.toWei().toString()),
connection: solanaConnectionObj,
})
transactionData.transaction.feePayer = publicKey
const latestBlockHashResult = await solanaConnectionObj.getRecentBlockhash('confirmed')
transactionData.transaction.recentBlockhash = latestBlockHashResult.blockhash
const signedTxs = await signTransaction(transactionData.transaction)
const txids = await solanaConnectionObj.sendRawTransaction(signedTxs.serialize())
return transactionData
Upvotes: 0
Views: 18036
Reputation: 49551
Transaction simulation failed errors (in ethereum too) happens when the contract code logic is broken. You either pass the wrong arguments to the function call on the client side (for example it requires string but you pass a number) or on the client side you are calling functions the wrong way (ake sure you check the api of client side packages)
Upvotes: 0
Reputation: 8462
It's hard to give a full answer without knowing more details about the makeAddLiquidityTransaction
endpoint, but the error you're seeing is:
Allocate: account Address { address: 7hLSYuEhn7t1P62n9gpv2aG8peTtLvjSRKqSsk2MXa91, base: None } already in use
during the invocation of the Associated Token Account program, which creates new token accounts for users.
In your case, the error says that the account is already in use, so the transaction contains an unnecessary call to create the associated token account. This may be a bug in the Raydium SDK, or the RAYDIUM_LP_TOKEN_ACCOUNT
address may be incorrect, causing the SDK to think you don't have the proper LP token account. You can hack around this by removing that first instruction if needed.
More background for the associated-token-account program at https://spl.solana.com/associated-token-account
Upvotes: 1