Skip to content

Commit

Permalink
routes in wallet fix (#430)
Browse files Browse the repository at this point in the history
* quick fix

* fix

* fix

* fix
  • Loading branch information
abrzezinski94 authored Jun 28, 2024
1 parent 08ebe5f commit 2962b51
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions components/swap/SwapReviewRouteInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,41 @@ export const fetchJupiterWalletSwapTransaction = async (
selectedRoute: JupiterV6RouteInfo,
userPublicKey: PublicKey,
slippage: number,
origin?: 'mango' | 'jupiter' | 'raydium',
): Promise<VersionedTransaction> => {
// docs https://station.jup.ag/api-v6/post-swap
const params: {
quoteResponse: JupiterV6RouteInfo
userPublicKey: PublicKey
slippageBps: number
autoCreateOutAta?: boolean
wrapAndUnwrapSol?: boolean
} = {
// response from /quote api
quoteResponse: selectedRoute,
// user public key to be used for the swap
userPublicKey,
slippageBps: Math.ceil(slippage * 100),
}

if (origin === 'mango') {
params.autoCreateOutAta = true
params.wrapAndUnwrapSol = true
}

const transactions = await (
await fetch(`${JUPITER_V6_QUOTE_API_MAINNET}/swap`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
await fetch(
`${
origin === 'mango' ? MANGO_ROUTER_API_URL : JUPITER_V6_QUOTE_API_MAINNET
}/swap`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params),
},
body: JSON.stringify({
// response from /quote api
quoteResponse: selectedRoute,
// user public key to be used for the swap
userPublicKey,
slippageBps: Math.ceil(slippage * 100),
}),
})
)
).json()

const { swapTransaction } = transactions
Expand Down Expand Up @@ -382,10 +401,13 @@ const SwapReviewRouteInfo = ({
selectedRoute,
wallet.publicKey,
slippage,
selectedRoute.origin,
)

const latestBlockhash = await connection.getLatestBlockhash()
const sign = wallet.signTransaction!
const signed = await sign(vtx)

const txid = await sendTxAndConfirm(
client.opts.multipleConnections,
connection,
Expand Down

0 comments on commit 2962b51

Please sign in to comment.