magicblock-labs / Solana.Unity-SDK

Open-Source Unity-Solana SDK with Full RPC coverage, NFT support and more
https://solana.unity-sdk.gg
MIT License
150 stars 84 forks source link

Failed to deserialise Jupiter swap transaction #212

Open ElXanys opened 6 months ago

ElXanys commented 6 months ago

Jupiter swap does not work for some reason : SwapQuoteAg swapQuote = await m_dexJupiter.GetSwapQuote(m_tokenSell.MintAddress, m_tokenBuy.MintAddress, DecimalUtil.ToUlong(m_amount, m_tokenSell.Decimals), SwapMode.ExactIn); Transaction tx = await m_dexJupiter.Swap(swapQuote); transaction.Sign(m_walletAccount); var result = await m_clientRPC.SendTransactionAsync(Convert.ToBase64String(transaction.Serialize()));

But Orca does : SwapQuote swapQuote = await m_dexOrca.GetSwapQuote(m_tokenSell.MintAddress, m_tokenBuy.MintAddress, DecimalUtil.ToUlong(m_amount, m_tokenSell.Decimals), 200); var _whirlpool = await m_dexOrca.FindWhirlpoolAddress(m_tokenSell.MintAddress, m_tokenBuy.MintAddress); Transaction tx = await m_dexOrca.SwapWithQuote(_whirlpool.Address, swapQuote); transaction.Sign(m_walletAccount); var result = await m_clientRPC.SendTransactionAsync(Convert.ToBase64String(transaction.Serialize()));

And there's another small glitch : by default for Orca, slippageBPS unit is decimal (0.01), instead of real unit (1).

Originally posted by @MoonNone in https://github.com/magicblock-labs/Solana.Unity-SDK/discussions/211#discussioncomment-8521557

GabrielePicco commented 6 months ago

Can you please post the full snippet to reproduce the issue? Including token mints, amount, etc ... Does the swap you are trying work in the demo: https://magicblock-labs.github.io/Solana.Unity-SDK/ ?

MoonNone commented 6 months ago

SwapQuoteAg swapQuote = await m_dexJupiter.GetSwapQuote( new Solana.Unity.Wallet.PublicKey("So11111111111111111111111111111111111111112"), new Solana.Unity.Wallet.PublicKey("WENWENvqqNya429ubCdR81ZmD69brwQaaBYY6p3LCpk"), DecimalUtil.ToUlong(0.001, 9), SwapMode.ExactIn);

Transaction tx = await m_dexJupiter.Swap(swapQuote); tx.Sign(m_walletAccount); var result = await m_clientRPC.SendTransactionAsync(Convert.ToBase64String(tx.Serialize()));