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

routes in wallet fix #430

Merged
merged 5 commits into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading