Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction simulation failed: Error processing Instruction 0 #5

Open
miaobei5555 opened this issue Nov 29, 2024 · 4 comments
Open

Comments

@miaobei5555
Copy link

`public async Task Test()
{
IRpcClient connection = ClientFactory.GetClient(Cluster.MainNet);
RaydiumAmmClient raydiumAmmClient = new RaydiumAmmClient(connection);

Account trader = account_1;
//Ray
string outputMint = "4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R";
string poolId = "2AXXcN6oN9bBT5owwmTH53C7QHUXvhLeu718Kqt8rvY2";


//amountIn must be in lamports
//Minimum out can be 0 to always execute no matter what or set it specifically to apply a fixed slippage rate
var swap_test = await raydiumAmmClient.SendSwapAsync(new PublicKey(poolId),
    SolHelper.ConvertToLamports(0.01m),
    0,
    OrderSide.Buy,
    trader, trader);

Console.WriteLine(swap_test.RawRpcResponse.ToString());

}`

Run error

{"jsonrpc":"2.0","error":{"code":-32002,"message":"Transaction simulation failed: Error processing Instruction 0: custom program error: 0x1b","data":{"accounts":null,"err":{"InstructionError":[0,{"Custom":27}]},"innerInstructions":null,"logs":["Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 invoke [1]","Program log: Error: The amm account owner is not match with this program","Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 consumed 4158 of 200000 compute units","Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 failed: custom program error: 0x1b"],"replacementBlockhash":null,"returnData":null,"unitsConsumed":4158}},"id":2}

@QingChengShan56
Copy link

道友好,首先感谢大佬开源代码。
我是新手,也遇到了这个错误,经过一周的摸索初见成果,可以交流一下

@QingChengShan56
Copy link

`public async Task<RequestResult> SendSwapAsync(string _poolAddress, ulong amountIn,
ulong minimumAmountOut, OrderSide side, PublicKey feePayer, Account trader, ulong computebudget = 0,
ulong computeprice = 0)
{
PublicKey poolAddress = new PublicKey(_poolAddress);
var ammInfo = await GetAmmInfoAsync(poolAddress);

        var makeInfo = await GetMakeInfoAsync(ammInfo.ParsedResult.Market);
        var makeOwer = makeInfo.ParsedResult.ownAddress;
        //var marketAuthority =
        PublicKey.TryCreateProgramAddress([makeOwer.KeyBytes], ammInfo.ParsedResult.SerumDex,
            out PublicKey marketAuthority);
        Console.WriteLine(marketAuthority.Key);
        //var makeInfo = "24u5hS6iXqhVYcBUZEVsqLrxaEg4HN3gDMeCg31TeT4Z";

        PublicKey baseTokenAccount =
            AssociatedTokenAccountProgram.DeriveAssociatedTokenAccount(trader, ammInfo.ParsedResult.BaseMint);
        PublicKey quoteTokenAccount =
            AssociatedTokenAccountProgram.DeriveAssociatedTokenAccount(trader, ammInfo.ParsedResult.QuoteMint);

       
       

        SwapBaseInAccounts swapBaseInAccounts = new SwapBaseInAccounts()
        {
            Amm = poolAddress,
            AmmAuthority = ammAuthority,
            AmmOpenOrders = ammInfo.ParsedResult.OpenOrders,
            AmmTargetOrders = ammInfo.ParsedResult.TargetOrders,

            SerumCoinVaultAccount = makeInfo.ParsedResult.baseVault,
            SerumAsks = makeInfo.ParsedResult.asks,
            SerumBids = makeInfo.ParsedResult.bids,
            SerumMarket = ammInfo.ParsedResult.Market,
            SerumEventQueue = makeInfo.ParsedResult.eventQueue,
            SerumPcVaultAccount = makeInfo.ParsedResult.quoteVault,
            SerumProgram = ammInfo.ParsedResult.SerumDex,
            SerumVaultSigner = marketAuthority,
            UserSourceOwner = trader,
            
            BaseVaultAccount = ammInfo.ParsedResult.BaseVault,
            QuoteVaultAccount = ammInfo.ParsedResult.QuoteVault,

            TokenProgram = TokenProgram.ProgramIdKey
        };
        TransactionInstruction accInstr = null;
        if (side == OrderSide.Sell)
        {
            //quote tokens -> base tokens
            swapBaseInAccounts.UerSourceTokenAccount = quoteTokenAccount;
            swapBaseInAccounts.UerDestinationTokenAccount = baseTokenAccount;

            // accInstr = AssociatedTokenAccountProgram.CreateAssociatedTokenAccount(trader, trader,quoteTokenAccount);
        }

        if (side == OrderSide.Buy)
        {
            //base tokens -> quote tokens
            swapBaseInAccounts.UerSourceTokenAccount = baseTokenAccount;
            swapBaseInAccounts.UerDestinationTokenAccount = quoteTokenAccount;
            //accInstr = TokenProgram.CloseAccount(quoteTokenAccount, trader, trader, TokenProgram.ProgramIdKey);
        }`

@QingChengShan56
Copy link

`public partial class MakeInfo
{
/*
blob(5),
blob(8)//accountFlagsLayout("accountFlags"),
publicKey("ownAddress"),
u64("vaultSignerNonce"),
publicKey("baseMint"),
publicKey("quoteMint"),
publicKey("baseVault"),
u64("baseDepositsTotal"),
u64("baseFeesAccrued"),
publicKey("quoteVault"),
u64("quoteDepositsTotal"),
u64("quoteFeesAccrued"),
u64("quoteDustThreshold"),
publicKey("requestQueue"),
publicKey("eventQueue"),
publicKey("bids"),
publicKey("asks"),
u64("baseLotSize"),
u64("quoteLotSize"),
u64("feeRateBps"),
u64("referrerRebatesAccrued"),
blob(7),
*/

    public PublicKey ownAddress { get; set; }
    public ulong vaultSignerNonce { get; set; }
    public PublicKey baseMint { get; set; }
    public PublicKey quoteMint { get; set; }
    public PublicKey baseVault { get; set; }
    public ulong baseDepositsTotal { get; set; }
    public ulong baseFeesAccrued { get; set; }
    public PublicKey quoteVault { get; set; }
    public ulong quoteDepositsTotal { get; set; }
    public ulong quoteFeesAccrued { get; set; }
    public ulong quoteDustThreshold { get; set; }
    public PublicKey requestQueue { get; set; }
    public PublicKey eventQueue { get; set; }
    public PublicKey bids { get; set; }
    public PublicKey asks { get; set; }
    public ulong baseLotSize { get; set; }
    public ulong quoteLotSize { get; set; }
    public ulong feeRateBps { get; set; }
    public ulong referrerRebatesAccrued { get; set; }

    public static MakeInfo Deserialize(ReadOnlySpan<byte> _data, int initialOffset = 13)
    {
        var offset = initialOffset;// 13;
        var makeInfo = new MakeInfo();
        makeInfo.ownAddress = _data.GetPubKey(offset);
        offset += 32;
        makeInfo.vaultSignerNonce = _data.GetU64(offset);
        offset += 8;
        
        makeInfo.baseMint = _data.GetPubKey(offset);
        offset += 32;
        makeInfo.quoteMint = _data.GetPubKey(offset);
        offset += 32;
        makeInfo.baseVault = _data.GetPubKey(offset);
        offset += 32;
        makeInfo.baseDepositsTotal = _data.GetU64(offset);
        offset += 8;
        makeInfo.baseFeesAccrued = _data.GetU64(offset);
        offset += 8;
        makeInfo.quoteVault = _data.GetPubKey(offset);
        offset += 32;
        
        makeInfo.quoteDepositsTotal = _data.GetU64(offset);
        offset += 8;
        makeInfo.quoteFeesAccrued = _data.GetU64(offset);
        offset += 8;
        makeInfo.quoteDustThreshold = _data.GetU64(offset);
        offset += 8;
        makeInfo.requestQueue = _data.GetPubKey(offset);
        offset += 32;
        makeInfo.eventQueue = _data.GetPubKey(offset);
        offset += 32;
        makeInfo.bids = _data.GetPubKey(offset);
        offset += 32;
        makeInfo.asks = _data.GetPubKey(offset);
        offset += 32;
        makeInfo.baseLotSize = _data.GetU64(offset);
        offset += 8;
        makeInfo.quoteLotSize = _data.GetU64(offset);
        offset += 8;
        makeInfo.feeRateBps = _data.GetU64(offset);
        offset += 8;
        makeInfo.referrerRebatesAccrued = _data.GetU64(offset);
        offset += 8;
        return makeInfo;
    }
    
}`

@Zeddex
Copy link

Zeddex commented Dec 31, 2024

Have exactly the same error. Any solution, please?

@Bifrost-Technologies Bifrost-Technologies deleted a comment Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants