-
Notifications
You must be signed in to change notification settings - Fork 2
Add referral fee support (Legacy Swap) + live E2E scripts, docs, and config #1
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
base: 1.x
Are you sure you want to change the base?
Changes from 13 commits
985725a
a2c84b6
3ef6aea
a477a5e
70deba6
840315a
b27c2f7
2ddea1d
becf1dc
733663e
9867eee
dca92fd
2a64939
0d500dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| dist | ||
| node_modules | ||
| node_modules | ||
| doc/ | ||
| .env | ||
| .env.local | ||
| .env.*.local | ||
| local-e2e/ |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,226 @@ | ||||||||||
| # plugin-jupiter | ||||||||||
| # @elizaos/plugin-jupiter | ||||||||||
|
|
||||||||||
| This PR adds a jupiter service and functionality for executing swaps with jupiter | ||||||||||
| Jupiter DEX integration plugin for ElizaOS with referral fee support. | ||||||||||
|
|
||||||||||
| ## Features | ||||||||||
|
|
||||||||||
| - **Token Swaps**: Execute swaps via Jupiter aggregator | ||||||||||
| - **Referral Fees**: Collect platform fees on swaps (0-10%) | ||||||||||
| - **Fee Modes**: | ||||||||||
| - `sol_only`: Collect fees only in SOL/WSOL | ||||||||||
| - `smart`: Prefer SOL, fallback to input mint | ||||||||||
| - **Automatic Fee Account**: Derives ATA for fee collection | ||||||||||
| - **Rate Limiting**: Built-in queue system respecting Jupiter API limits | ||||||||||
|
|
||||||||||
| ## Installation | ||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| npm install @elizaos/plugin-jupiter | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| ## Configuration | ||||||||||
|
|
||||||||||
| ### Basic Setup | ||||||||||
|
|
||||||||||
| Add the plugin to your ElizaOS character: | ||||||||||
|
|
||||||||||
| ```typescript | ||||||||||
| import { jupiterPlugin } from '@elizaos/plugin-jupiter'; | ||||||||||
|
|
||||||||||
| export const character = { | ||||||||||
| name: 'MyAgent', | ||||||||||
| plugins: [jupiterPlugin], | ||||||||||
| // ... other config | ||||||||||
| }; | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| ### Referral Fees (Optional) | ||||||||||
|
|
||||||||||
| Enable platform fees by setting environment variables: | ||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| # Platform fee in basis points (20 = 0.2%) | ||||||||||
| REFERRAL_FEE_BPS=20 | ||||||||||
|
|
||||||||||
| # Fee collection mode: sol_only | smart (default: smart) | ||||||||||
| REFERRAL_MODE=smart | ||||||||||
|
|
||||||||||
| # Public key that will receive the fees (fee receiver) | ||||||||||
| # An ATA will be derived for the chosen mint | ||||||||||
| REFERRAL_FEE_RECEIVER=REPLACE_WITH_FEE_RECEIVER_PUBKEY | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| #### Fee Modes | ||||||||||
|
|
||||||||||
| **`sol_only`**: Collect fees only when SOL/WSOL is in the swap pair | ||||||||||
| - SOL → USDC: ✅ Fees collected in SOL | ||||||||||
| - USDC → JUP: ❌ No fees (no SOL in pair) | ||||||||||
|
|
||||||||||
| **`smart`**: Prefer SOL, otherwise use input mint | ||||||||||
| - SOL → USDC: ✅ Fees in SOL | ||||||||||
| - USDC → JUP: ✅ Fees in USDC | ||||||||||
|
|
||||||||||
| ### Complete Example | ||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| # .env | ||||||||||
| REFERRAL_FEE_BPS=20 | ||||||||||
| REFERRAL_MODE=smart | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| ## How It Works | ||||||||||
|
|
||||||||||
| ### Fee Collection | ||||||||||
|
|
||||||||||
| 1. **Quote**: Plugin adds `platformFeeBps` parameter to Jupiter quote request | ||||||||||
| 2. **Swap**: Plugin derives fee account (ATA) for the selected mint | ||||||||||
| 3. **Execution**: Jupiter deducts fees and sends to your fee account | ||||||||||
|
|
||||||||||
| ### Fee Account | ||||||||||
|
|
||||||||||
| The fee account is automatically derived as an Associated Token Account (ATA): | ||||||||||
| - Owner: Fee receiver (env `REFERRAL_FEE_RECEIVER`) | ||||||||||
| - Mint: Selected based on fee mode (SOL or input mint) | ||||||||||
|
|
||||||||||
| ⚠️ **Important**: The fee account must exist before the swap. If it doesn't exist: | ||||||||||
| - The swap will proceed **without fees** | ||||||||||
| - A warning will be logged | ||||||||||
|
Comment on lines
+86
to
+87
|
||||||||||
| - The swap will proceed **without fees** | |
| - A warning will be logged | |
| - A warning will be logged | |
| - The swap may fail (Jupiter may reject the transaction if the fee account is invalid or missing) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # --- Jupiter Referral - Minimal Configuration --- | ||
| # Copy this file to .env and adjust values as needed. | ||
|
|
||
| # Platform fee in basis points. Example: 20 = 0.2% | ||
| REFERRAL_FEE_BPS=20 | ||
|
|
||
| # Fee selection mode: | ||
| # - smart: prefer SOL if available, otherwise input mint | ||
| # - sol_only: collect only when SOL/WSOL is in the pair | ||
| REFERRAL_MODE=smart | ||
|
|
||
| # Public key that will receive the fees (fee receiver) | ||
| # An ATA will be derived for the chosen mint | ||
| REFERRAL_FEE_RECEIVER=REPLACE_WITH_FEE_RECEIVER_PUBKEY | ||
|
|
||
| # --- Optional backend preflight (ensure fee ATA exists) --- | ||
| # If you implement the recommended backend endpoint, you may need: | ||
| # SOLANA_RPC_URL=https://api.mainnet-beta.solana.com | ||
| # FEE_PAYER_SECRET_KEY=[1,2,3,...,64] | ||
|
|
||
| # --- E2E example (mainnet), can be used with dist/scripts/e2e-mainnet.js --- | ||
| # TEST_INPUT_MINT=So11111111111111111111111111111111111111112 # WSOL | ||
| # TEST_OUTPUT_MINT=Dz9mQ9NzkBcCsuGPFJ3r1bS4wgqKMHBPiVuniW8Mbonk # USELESS | ||
| # TEST_INPUT_AMOUNT_ATOMIC=5000000 # 0.005 SOL | ||
| # TEST_SLIPPAGE_BPS=150 | ||
|
|
||
| # Optional simulation/signing for E2E | ||
| # HELIUS_RPC_URL=https://mainnet.helius-rpc.com/?api-key=... | ||
| # SIGNER_SECRET_KEY=[1,2,3,...,64] | ||
| # SEND_TX=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.
The documentation states fees can be 0-10%, but there is no validation in the code to enforce this upper limit. Consider adding validation in
loadReferralConfigto ensurefeeBpsdoes not exceed 1000 (10%), or update the documentation to reflect that any value is accepted.