Skip to content
Open
Show file tree
Hide file tree
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 Oct 24, 2025
a2c84b6
feat: add referral config loader and mint selection with tests
MonteCrypto999 Oct 24, 2025
3ef6aea
refactor: move referral logic into service.ts
MonteCrypto999 Oct 24, 2025
a477a5e
feat: integrate platformFeeBps in getQuote and feeAccount in executeSwap
MonteCrypto999 Oct 24, 2025
70deba6
fix: add type annotations to resolve TypeScript warnings
MonteCrypto999 Oct 24, 2025
840315a
fix: add type annotations to cache functions
MonteCrypto999 Oct 24, 2025
b27c2f7
test: add integration tests for referral fees
MonteCrypto999 Oct 24, 2025
2ddea1d
docs: add comprehensive README with referral setup instructions
MonteCrypto999 Oct 24, 2025
becf1dc
feat: use REFERRAL_FEE_RECEIVER for feeAccount; update docs and ignor…
MonteCrypto999 Oct 24, 2025
733663e
docs: add backend endpoint recommendation to ensure fee ATA exists
MonteCrypto999 Oct 24, 2025
9867eee
chore: add env.example with commented referral config
MonteCrypto999 Oct 24, 2025
dca92fd
chore: add mainnet E2E script and build config
MonteCrypto999 Oct 24, 2025
2a64939
chore: add live E2E with simulation/signing; update README and env.ex…
MonteCrypto999 Oct 24, 2025
886f340
feat(workflows): add worklfo deployment and release
M4XGO Oct 25, 2025
5e9d5f1
feat(release): add release-please configuration and manifest files
M4XGO Oct 25, 2025
b8cb0a2
Merge pull request #2 from M4XGO/feat/add-workflows
standujar Oct 26, 2025
0d500dc
Merge branch '1.x' into referral
standujar Oct 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 0 additions & 112 deletions .github/workflows/npm-deploy.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/publish-npm.yaml
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 }}
15 changes: 15 additions & 0 deletions .github/workflows/release.yml
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]
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 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:

sendo-labs reusable-workflows GitHub release-workflow-v1.0.0

💡 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:

  • search GitHub again (I can try broader queries or GitHub's site search), or
  • check a specific URL/repo you have, or
  • show how to reference/use a reusable workflow tag like @v1.0.0 in a caller workflow?

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:

  • The organization name is correct (sendo-labs)
  • The repository exists and you have access (if private)
  • The tag/release version is correct
  • The workflow path is correct (.github/workflows/release.yml)

If this is a private repository, document this external dependency clearly for maintainers.

🤖 Prompt for AI Agents
.github/workflows/release.yml around line 10: the workflow references
sendo-labs/reusable-workflows/.github/workflows/[email protected]
which cannot be found publicly; verify and correct the reusable workflow
reference by confirming the organization and repo name, ensuring the
.github/workflows/release.yml path exists in that repo, and that the tag
release-workflow-v1.0.0 is valid; if the repository is private, either replace
the reference with a local or public workflow copy in this repo or add
documentation in the repo README or CONTRIBUTING noting the private external
dependency and required access permissions for maintainers.

with:
release-type: node
permissions:
contents: write
pull-requests: write
7 changes: 6 additions & 1 deletion .gitignore
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/
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "0.0.0"
}
227 changes: 225 additions & 2 deletions README.md
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
Loading