-
Notifications
You must be signed in to change notification settings - Fork 4
Add referral fee support (Legacy Swap) + live E2E scripts, docs, and config #3
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
Open
MonteCrypto999
wants to merge
17
commits into
elizaos-plugins:1.x
Choose a base branch
from
MonteCrypto999:referral
base: 1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
985725a
feat: add referral types (ReferralConfig, FeeMode, FeeMintSelection)
MonteCrypto999 a2c84b6
feat: add referral config loader and mint selection with tests
MonteCrypto999 3ef6aea
refactor: move referral logic into service.ts
MonteCrypto999 a477a5e
feat: integrate platformFeeBps in getQuote and feeAccount in executeSwap
MonteCrypto999 70deba6
fix: add type annotations to resolve TypeScript warnings
MonteCrypto999 840315a
fix: add type annotations to cache functions
MonteCrypto999 b27c2f7
test: add integration tests for referral fees
MonteCrypto999 2ddea1d
docs: add comprehensive README with referral setup instructions
MonteCrypto999 becf1dc
feat: use REFERRAL_FEE_RECEIVER for feeAccount; update docs and ignor…
MonteCrypto999 733663e
docs: add backend endpoint recommendation to ensure fee ATA exists
MonteCrypto999 9867eee
chore: add env.example with commented referral config
MonteCrypto999 dca92fd
chore: add mainnet E2E script and build config
MonteCrypto999 2a64939
chore: add live E2E with simulation/signing; update README and env.ex…
MonteCrypto999 886f340
feat(workflows): add worklfo deployment and release
M4XGO 5e9d5f1
feat(release): add release-please configuration and manifest files
M4XGO b8cb0a2
Merge pull request #2 from M4XGO/feat/add-workflows
standujar 0d500dc
Merge branch '1.x' into referral
standujar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| name: Publish to NPM | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [closed] | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| publish: | ||
| if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release-please--') | ||
| uses: sendo-labs/reusable-workflows/.github/workflows/[email protected] | ||
| with: | ||
| bun-version: 'latest' | ||
| node-version: '22' | ||
| working-directory: '.' | ||
| registry-url: 'https://registry.npmjs.org' | ||
| skip-tests: true | ||
| skip-build: false | ||
| access: 'public' | ||
| secrets: | ||
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| name: Auto Release | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main # ou master | ||
|
|
||
| jobs: | ||
| release: | ||
| uses: sendo-labs/reusable-workflows/.github/workflows/[email protected] | ||
| with: | ||
| release-type: node | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| ".": "0.0.0" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| To create fee accounts, users can: | ||
| - Use any Solana wallet (Phantom, Solflare, etc.) | ||
| - Call `createAssociatedTokenAccount` from `@solana/spl-token` | ||
|
|
||
| ### Recommended backend endpoint (optional) | ||
|
|
||
| For production setups, we recommend a backend endpoint to ensure the fee receiver has the required ATA before swaps: | ||
|
|
||
| ```ts | ||
| // Minimal Express endpoint to ensure fee ATA exists | ||
| // npm i express @solana/web3.js @solana/spl-token | ||
| import express from 'express'; | ||
| import { Connection, Keypair, PublicKey, clusterApiUrl } from '@solana/web3.js'; | ||
| import { getOrCreateAssociatedTokenAccount } from '@solana/spl-token'; | ||
|
|
||
| const app = express(); | ||
| app.use(express.json()); | ||
|
|
||
| const RPC_URL = process.env.SOLANA_RPC_URL ?? clusterApiUrl('mainnet-beta'); | ||
| const FEE_PAYER = Keypair.fromSecretKey( | ||
| Uint8Array.from(JSON.parse(process.env.FEE_PAYER_SECRET_KEY!)) | ||
| ); | ||
|
|
||
| app.post('/api/fee-ata/ensure', async (req, res) => { | ||
| try { | ||
| const { receiver, mint } = req.body; | ||
| if (!receiver || !mint) return res.status(400).json({ error: 'receiver and mint are required' }); | ||
|
|
||
| const connection = new Connection(RPC_URL, 'confirmed'); | ||
| const receiverPk = new PublicKey(receiver); | ||
| const mintPk = new PublicKey(mint); | ||
|
|
||
| const ata = await getOrCreateAssociatedTokenAccount( | ||
| connection, | ||
| FEE_PAYER, | ||
| mintPk, | ||
| receiverPk | ||
| ); | ||
|
|
||
| res.json({ feeAccount: ata.address.toBase58() }); | ||
| } catch (e: any) { | ||
| res.status(500).json({ error: e?.message ?? 'unknown error' }); | ||
| } | ||
| }); | ||
|
|
||
| app.listen(3000, () => console.log('fee-ata endpoint ready on :3000')); | ||
| ``` | ||
|
|
||
| Call it from your ops/scripts prior to swaps, e.g.: | ||
|
|
||
| ```bash | ||
| curl -X POST http://localhost:3000/api/fee-ata/ensure \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d '{ | ||
| "receiver": "'$REFERRAL_FEE_RECEIVER'", | ||
| "mint": "So11111111111111111111111111111111111111112" | ||
| }' | ||
| ``` | ||
|
|
||
| ## API Reference | ||
|
|
||
| ### JupiterService | ||
|
|
||
| ```typescript | ||
| import { JupiterService } from '@elizaos/plugin-jupiter'; | ||
|
|
||
| const service = new JupiterService(runtime); | ||
|
|
||
| // Get quote | ||
| const quote = await service.getQuote({ | ||
| inputMint: 'So11111111111111111111111111111111111111112', // WSOL | ||
| outputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC | ||
| amount: 100000, // 0.0001 SOL (in lamports) | ||
| slippageBps: 50, // 0.5% | ||
| }); | ||
|
|
||
| // Execute swap | ||
| const swap = await service.executeSwap({ | ||
| quoteResponse: quote, | ||
| userPublicKey: 'USER_WALLET_ADDRESS', | ||
| slippageBps: 50, | ||
| }); | ||
| ``` | ||
|
|
||
| ## Testing | ||
|
|
||
| ```bash | ||
| # Unit tests | ||
| bun test src/__tests__/referral.test.ts | ||
|
|
||
| # Integration tests (mocked API) | ||
| bun test src/__tests__/integration.test.ts | ||
|
|
||
| # All tests | ||
| bun test | ||
|
|
||
| # Live E2E (example using .env.example), with optional simulation/signing | ||
| # 1) Copy .env.example to .env and set: | ||
| # REFERRAL_FEE_BPS=20 | ||
| # REFERRAL_MODE=sol_only | ||
| # REFERRAL_FEE_RECEIVER=<FEE_RECEIVER_PUBKEY> | ||
| # TEST_INPUT_MINT=So11111111111111111111111111111111111111112 | ||
| # TEST_OUTPUT_MINT=Dz9mQ9NzkBcCsuGPFJ3r1bS4wgqKMHBPiVuniW8Mbonk | ||
| # TEST_INPUT_AMOUNT_ATOMIC=5000000 # 0.005 SOL | ||
| # TEST_SLIPPAGE_BPS=150 | ||
| # # Optional (simulation/signing) | ||
| # HELIUS_RPC_URL=https://mainnet.helius-rpc.com/?api-key=... | ||
| # SIGNER_SECRET_KEY=[1,2,3,...,64] | ||
| # # SEND_TX=1 # uncomment to broadcast | ||
| # 2) Build and run E2E: | ||
| npm run build && node dist/scripts/e2e-mainnet.js | ||
| ``` | ||
|
|
||
| ## Development | ||
|
|
||
| ```bash | ||
| # Install dependencies | ||
| npm install | ||
|
|
||
| # Build | ||
| npm run build | ||
|
|
||
| # Watch mode | ||
| npm run dev | ||
|
|
||
| # Lint | ||
| npm run lint | ||
| ``` | ||
|
|
||
| ## References | ||
|
|
||
| - [Jupiter Swap API](https://station.jup.ag/docs/apis/swap-api) | ||
| - [Jupiter - Add Fees To Swap](https://dev.jup.ag/docs/swap/add-fees-to-swap) | ||
| - [ElizaOS Plugin Development](https://docs.elizaos.ai/guides/create-a-plugin) | ||
|
|
||
| ## License | ||
|
|
||
| MIT |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
Verify external reusable workflow dependency.
The workflow delegates to
sendo-labs/[email protected]. Ensure this external repository and version tag are correct and from a trusted source.🌐 Web query:
💡 Result:
I couldn't find a public GitHub repository or a release/tag named "sendo-labs reusable-workflows release-workflow-v1.0.0". (I searched GitHub/docs for reusable-workflow usage but found no matching sendo-labs repo or that tag.) (github.com)
Do you want me to:
Citations:
Reusable workflow reference cannot be verified—repository not found publicly.
The workflow references
sendo-labs/[email protected], but no public GitHub repository with this name or tag exists. Verify:sendo-labs).github/workflows/release.yml)If this is a private repository, document this external dependency clearly for maintainers.
🤖 Prompt for AI Agents