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

Jupiter swap failed - Transaction failed to sanitize accounts offsets correctly #225

Open
Zeddex opened this issue Jun 16, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Zeddex
Copy link

Zeddex commented Jun 16, 2024

I'm getting error "invalid transaction: Transaction failed to sanitize accounts offsets correctly" making Jupiter swap.

string tokenIn = "SOL";
string tokenOut = "PONKE";
decimal amount = 0.001m;
public class JupiterSwap
{
    public IRpcClient RpcClient { get; } = ClientFactory.GetClient(Cluster.MainNet);
    public IDexAggregator Dex { get; }
    public Wallet Wallet { get; }

    public JupiterSwap(IRpcClient rpcClient, Wallet wallet) 
    {
        Wallet = wallet;
        RpcClient = rpcClient;
        Dex = new JupiterDexAg(Wallet.Account);
    }

    public async Task<string> MakeSwap(string tokenIn, string tokenOut, decimal inputAmount) 
    {
        TokenData tokenA = await Dex.GetTokenBySymbol(tokenIn);
        TokenData tokenB = await Dex.GetTokenBySymbol(tokenOut);

        SwapQuoteAg swapQuote = await Dex.GetSwapQuote(
            tokenA.MintAddress,
            tokenB.MintAddress,
            DecimalUtil.ToUlong(inputAmount, tokenA.Decimals)
        );

        var quoteOutput = DecimalUtil.FromBigInteger(swapQuote.OutputAmount, tokenB.Decimals);
        await Console.Out.WriteLineAsync($"Output Amount: {quoteOutput} {tokenOut}");
        await Console.Out.WriteLineAsync(string.Join(" -> ", swapQuote.RoutePlan.Select(p => p.SwapInfo.Label)));

        var swapTransaction = await Dex.Swap(swapQuote);
        swapTransaction.Sign(Wallet.Account);

        var txSignature = await RpcClient.SendTransactionAsync(swapTransaction.Serialize());

        return txSignature.Result;
    }
}
@Zeddex Zeddex added the bug Something isn't working label Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants
@Zeddex and others