Skip to content

fix:jup.ag fees#681

Merged
kvhnuke merged 1 commit intodevop/packeupdates-0512from
fix/jup-ag-fees
May 12, 2025
Merged

fix:jup.ag fees#681
kvhnuke merged 1 commit intodevop/packeupdates-0512from
fix/jup-ag-fees

Conversation

@kvhnuke
Copy link
Contributor

@kvhnuke kvhnuke commented May 6, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Corrected referral fee calculations to ensure accurate percentage and basis point conversions.
    • Fixed referral account creation logic to use the correct token mint and standard SPL associated token accounts.
  • Refactor

    • Simplified referral fee account handling by removing custom Jupiter referral program logic and switching to standard SPL token account methods.
    • Cleaned up and removed unused constants and functions related to the previous referral program implementation.
  • Chores

    • Updated referrer addresses for specific wallets in the fee configuration.

@coderabbitai
Copy link

coderabbitai bot commented May 6, 2025

Walkthrough

The 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

File(s) Change Summary
packages/swap/src/configs.ts Updated referrer addresses for enkrypt and mew wallets in Jupiter provider fee configuration. No changes to fee percentages or logic.
packages/swap/src/providers/jupiter/index.ts Removed Jupiter referral program/vault constants and custom referral ATA logic. Switched to standard SPL ATA derivation and creation. Corrected fee basis point calculation. Removed and replaced associated functions.

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
Loading

Suggested reviewers

  • gamalielhere
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link

github-actions bot commented May 6, 2025

💼 Build Files
chrome: enkrypt-chrome-f16ed78c.zip
firefox: enkrypt-firefox-f16ed78c.zip

💉 Virus total analysis
chrome: f16ed78c
firefox: f16ed78c

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

referrerATAPubkey is 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 dstTokenProgramId instead:

- 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 use isDstToken2022), 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.ts

Length 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 dstTokenProgramId instead of srcTokenProgramId to 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 in getQuote

See 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 creation

Using 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-fetch getMinimumBalanceForRentExemption for both ATAs in a Promise.all to cut an extra RPC round-trip.


1028-1049: Helper is concise – consider hoisting to utils for reuse

getReferrerAssociatedTokenAccount is generic and could live in utils/solana.ts next 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

📥 Commits

Reviewing files that changed from the base of the PR and between ef577dc and f16ed78.

📒 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 accounts

The new Base-58 addresses (HXWkRK… for Enkrypt and CmrkoX… for MEW) look syntactically valid, but a quick mis-copy can silently break fee attribution.

  1. Double-check the addresses against the Jupiter referral dashboard.
  2. 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 correct

Using 10000 instead of 100 converts a percentage into basis-points properly (e.g. 0.01 → 100 bps).
✅ No issues spotted here.

Comment on lines 444 to 448
toTokenAmount: toBN(
Math.floor((1 - feePercentage) * Number(jupiterQuote.outAmount))
Math.floor((1 - feePercentage / 100) * Number(jupiterQuote.outAmount))
.toFixed(10)
.replace(/\.?0+$/, ""),
),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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),

@kvhnuke kvhnuke changed the base branch from develop to devop/packeupdates-0512 May 12, 2025 19:50
@kvhnuke kvhnuke merged commit 74c6324 into devop/packeupdates-0512 May 12, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments