-
Notifications
You must be signed in to change notification settings - Fork 125
add Jupiter Ultra Swap #154
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
Conversation
9f353ba to
740621b
Compare
| const response = await fetch(`${JUPITER_ULTRA_BASE}/v1/holdings/${walletAddress}`, { | ||
| headers: getHeaders(), | ||
| cache: "no-store", | ||
| }); |
Check failure
Code scanning / CodeQL
Server-side request forgery Critical
URL
user-provided value
Copilot Autofix
AI 4 days ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mike I think you can resolve this due your isAddress()validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some easily fixable actually it looks like browsers have changed the default to base 10 if the radix is undefined now, there's some comments below but no blockers! 👍parseInt() issues (base 16 is a silly default] - but otherwise good to go!
| if (data.amount && parseInt(data.amount) > 0) { | ||
| balances.push({ | ||
| mint: "So11111111111111111111111111111111111111112", // SOL mint address | ||
| balance: parseInt(data.amount), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseInt is base16 by default, use Number() or parseInt(string, 10). Number is better though.
| // If Jupiter API key is missing, fetch SOL balance via RPC as fallback | ||
| // This allows users to swap SOL even without the API key | ||
| if (!JUPITER_API_KEY) { | ||
| const balances: any[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Nitpick, feel free to ignore) for consistency with the rest of the code, I always use the generics syntax. Eg you have Promise<number> elsewhere, use Array<any> here.
AI can change this in one step!
| } catch (error) { | ||
| console.error("Error executing swap:", error); | ||
| return NextResponse.json( | ||
| { error: error instanceof Error ? error.message : "Failed to execute swap" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the weird things about JS is that you can throw anything - an array, an object, a string, a number - but in reality, nobody ever does. So now everyone has to write error instanceof Error. This isn't useful advice just an old man grumbling. 😅
|
|
||
| @layer utilities { | ||
| .text-balance { | ||
| text-wrap: balance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oooh fancy 🎩🧐
| tokensAreDifferent && | ||
| hasAmount && | ||
| !hasInsufficientBalance && | ||
| status === "idle"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good variable naming here this is all super clear 👍
| readOnly = false, | ||
| }: TokenInputProps) { | ||
| const handleMaxClick = () => { | ||
| if (balance !== undefined && balance > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a dig deal, but you could do if balance here - null, undefined, and 0 would all be false.
mikemaccana
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved! Some hopefully comments below on optimisations but that's it.
0xsergen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

Note
Introduces a self-contained swap demo under
solana/jupiter-ultra-swapusing Next.js, Jupiter Ultra API, QuickNode RPC, and Solana Wallet Adapter.api/tokens,api/balances,api/quote,api/execute, andapi/rpcwith API key support, address validation, error handling, timeouts, and BigInt precision for amountsSwapCard,TokenInput,TokenSelector,SwapButton,StatusMessage,WalletButton) and hooks (useTokenList,useTokenBalances,useQuote,useSwap) to fetch quotes, sign transactions, and execute swapsWalletProviderwired to a server-side RPC proxy and uses@solana/web3.jsonly for signing the Ultra transactionlib/jupiter.ts,lib/types.ts, and a simplesolana-clienthelper.env.example,.gitignore, and a README with setup instructionsWritten by Cursor Bugbot for commit 123d65c. This will update automatically on new commits. Configure here.