Conversation
WalkthroughThe changes update the Jupiter provider's referral fee configuration by modifying referrer addresses for two wallets and overhauling the referral fee account logic. The custom Jupiter referral program logic is removed in favor of standard SPL associated token account handling, and fee basis point calculations are corrected. No public API signatures are altered. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Wallet
participant JupiterProvider
participant SPLTokenProgram
User->>Wallet: Initiate swap with referral
Wallet->>JupiterProvider: Request quote/swap (with referrer)
JupiterProvider->>SPLTokenProgram: Derive/create standard SPL ATA for referrer and token mint
SPLTokenProgram-->>JupiterProvider: Return ATA address (create if needed)
JupiterProvider->>Wallet: Provide quote/swap details (with correct fee and referral ATA)
Wallet-->>User: Complete swap
Suggested reviewers
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
|
💼 Build Files |
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
packages/swap/src/providers/jupiter/index.ts (1)
281-297: 💡 Verification agent🧩 Analysis chain
Referrer ATA derivation looks correct but may block fees for Token-2022 sources
referrerATAPubkeyis skipped when the source token is 2022 (isSrcToken2022).
However, Jupiter pays the fee in the output token, so the destination program-ID is what matters.If the output token is SPL-2022 while the input is not, the fee account will still be omitted and the swap will succeed but the platform earns nothing.
Consider gating on
dstTokenProgramIdinstead:- const isSrcToken2022 = - srcTokenProgramId.toBase58() === TOKEN_2022_PROGRAM_ID.toBase58(); + const isDstToken2022 = + dstTokenProgramId.toBase58() === TOKEN_2022_PROGRAM_ID.toBase58(); ... - referrerATAPubkey: isSrcToken2022 ? undefined : referrerATAPubkey, + referrerATAPubkey: isDstToken2022 ? undefined : referrerATAPubkey,
To verify whether the gating logic indeed uses
isSrcToken2022(and should instead useisDstToken2022), let’s locate both the flag definition and its usage around the referrer ATA.
🏁 Script executed:
#!/bin/bash # Find where isSrcToken2022 is defined and used rg -n "isSrcToken2022" -A5 -B5 packages/swap/src/providers/jupiter/index.ts # Find where referrerATAPubkey is passed into the swap instruction rg -n "referrerATAPubkey" -A5 -B5 packages/swap/src/providers/jupiter/index.tsLength of output: 4507
Gate referrer ATA on destination Token-2022
The current code omits the referrer ATA when the source token is SPL-2022, but Jupiter always pays fees in the output token. We need to check
dstTokenProgramIdinstead ofsrcTokenProgramIdto avoid accidentally skipping referral fees for SPL-2022 outputs.Locations to update (packages/swap/src/providers/jupiter/index.ts):
- Lines ~300–309 (flag definition and swap call)
- Lines ~328–336 (ATA-creation logic)
Proposed diff:
- const isSrcToken2022 = - srcTokenProgramId.toBase58() === TOKEN_2022_PROGRAM_ID.toBase58(); + const isDstToken2022 = + dstTokenProgramId.toBase58() === TOKEN_2022_PROGRAM_ID.toBase58(); … - referrerATAPubkey: isSrcToken2022 ? undefined : referrerATAPubkey, + referrerATAPubkey: isDstToken2022 ? undefined : referrerATAPubkey, … - } else if (!referrerATAExists && !isSrcToken2022) { + } else if (!referrerATAExists && !isDstToken2022) {
♻️ Duplicate comments (1)
packages/swap/src/providers/jupiter/index.ts (1)
503-507: Same double-fee bug as ingetQuoteSee previous comment – apply the same fix in
getSwap.
🧹 Nitpick comments (2)
packages/swap/src/providers/jupiter/index.ts (2)
331-342: Nice switch to idempotent ATA creationUsing the SPL helper avoids duplicate-account errors and the explicit rent-exemption size (
SPL_TOKEN_ATA_ACCOUNT_SIZE_BYTES) is clearer.
Minor tidy-up idea: you can pre-fetchgetMinimumBalanceForRentExemptionfor both ATAs in aPromise.allto cut an extra RPC round-trip.
1028-1049: Helper is concise – consider hoisting to utils for reuse
getReferrerAssociatedTokenAccountis generic and could live inutils/solana.tsnext to the other ATA helpers.
That would avoid future duplication when other providers need it.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/swap/src/configs.ts(1 hunks)packages/swap/src/providers/jupiter/index.ts(6 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/swap/src/providers/jupiter/index.ts (1)
packages/swap/src/utils/solana.ts (5)
solAccountExists(484-491)SPL_TOKEN_ATA_ACCOUNT_SIZE_BYTES(43-43)getCreateAssociatedTokenAccountIdempotentInstruction(388-451)ASSOCIATED_TOKEN_PROGRAM_ID(39-41)getSPLAssociatedTokenAccountPubkey(309-321)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: buildAll
- GitHub Check: test
- GitHub Check: test
🔇 Additional comments (2)
packages/swap/src/configs.ts (1)
60-66: Referrer addresses changed – please verify they match the SPL token fee accountsThe new Base-58 addresses (
HXWkRK…for Enkrypt andCmrkoX…for MEW) look syntactically valid, but a quick mis-copy can silently break fee attribution.
- Double-check the addresses against the Jupiter referral dashboard.
- Run a smoke test swap and confirm the fee account receives funds.
If you want a one-liner to validate address length & checksum on CI, let me know.
packages/swap/src/providers/jupiter/index.ts (1)
232-236: Good fix: basis-point calculation now correctUsing
10000instead of100converts a percentage into basis-points properly (e.g.0.01 → 100 bps).
✅ No issues spotted here.
| toTokenAmount: toBN( | ||
| Math.floor((1 - feePercentage) * Number(jupiterQuote.outAmount)) | ||
| Math.floor((1 - feePercentage / 100) * Number(jupiterQuote.outAmount)) | ||
| .toFixed(10) | ||
| .replace(/\.?0+$/, ""), | ||
| ), |
There was a problem hiding this comment.
outAmount is reduced twice – users lose ~1 % extra
The Jupiter API already subtracts platformFeeBps from outAmount.
Multiplying by (1 - feePercentage / 100) removes the fee a second time.
- toTokenAmount: toBN(
- Math.floor((1 - feePercentage / 100) * Number(jupiterQuote.outAmount))
- .toFixed(10)
- .replace(/\.?0+$/, ""),
- ),
+ // `outAmount` is net of the referral fee; no further deduction required
+ toTokenAmount: toBN(jupiterQuote.outAmount),Please adjust here and in getSwap to prevent under-paying the user.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| toTokenAmount: toBN( | |
| Math.floor((1 - feePercentage) * Number(jupiterQuote.outAmount)) | |
| Math.floor((1 - feePercentage / 100) * Number(jupiterQuote.outAmount)) | |
| .toFixed(10) | |
| .replace(/\.?0+$/, ""), | |
| ), | |
| // `outAmount` is net of the referral fee; no further deduction required | |
| toTokenAmount: toBN(jupiterQuote.outAmount), |
Summary by CodeRabbit
Bug Fixes
Refactor
Chores