Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file modified .coverage
Binary file not shown.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ By default, Jupiter Ultra provides gasless swaps when the user has < 0.01 SOL an

This plugin enables Solana Agent to swap tokens using DFlow's Swap API with a Solana keypair. DFlow offers faster swaps compared to Jupiter Ultra with competitive rates.

**Note:** Platform fees are not supported with DFlow. Use Solana Ultra (Jupiter) if you need to collect fees on swaps.

```python
config = {
"tools": {
"solana_dflow_swap": {
"private_key": "my-private-key", # Required - base58 string
"payer_private_key": "payer-private-key", # Optional - for gasless/sponsored transactions
"rpc_url": "https://api.mainnet-beta.solana.com", # Optional - RPC URL (defaults to mainnet)
"platform_fee_bps": 50, # Optional - fee in basis points (50 = 0.5%)
"referral_account": "your-wallet-pubkey", # Optional - wallet to receive fees (DFlow creates ATAs automatically)
},
},
}
Expand All @@ -121,6 +121,7 @@ config = {
**Features:**
- **Fast Swaps**: DFlow typically executes faster than Jupiter Ultra
- **Gasless Transactions**: Optionally sponsor gas fees for users via `payer_private_key`
- **Platform Fees**: Collect fees on swaps via `referral_account` - DFlow auto-creates token accounts

### Jupiter Trigger

Expand Down Expand Up @@ -374,6 +375,8 @@ config = {
"signing_key": "wallet-auth:your-signing-key", # Required - your Privy wallet authorization signing key
"rpc_url": "https://mainnet.helius-rpc.com/?api-key=YOUR_KEY", # Required - Helius recommended for priority fees
"payer_private_key": "payer-private-key", # Optional - for gasless/sponsored transactions
"platform_fee_bps": 50, # Optional - fee in basis points (50 = 0.5%)
"referral_account": "your-wallet-pubkey", # Optional - wallet to receive fees (DFlow creates ATAs automatically)
},
},
}
Expand All @@ -384,6 +387,7 @@ config = {
- **Privy Delegated Wallets**: Seamless user experience with embedded wallets
- **Helius Priority Fees**: Uses Helius priority fee estimation for reliable transaction landing
- **Gasless Transactions**: Optionally sponsor gas fees for users via `payer_private_key`
- **Platform Fees**: Collect fees on swaps via `referral_account` - DFlow auto-creates token accounts

**RPC URL (Required):**
Helius RPC is strongly recommended (`https://mainnet.helius-rpc.com/?api-key=YOUR_KEY`). Helius provides priority fee estimation and better blockhash handling, which significantly improves transaction success rates. Get a free API key at [helius.dev](https://helius.dev).
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "sakit"
version = "14.1.4"
version = "14.1.5"
description = "Solana Agent Kit"
authors = ["Bevan Hunt <bevan@bevanhunt.com>"]
license = "MIT"
Expand Down
11 changes: 9 additions & 2 deletions sakit/privy_dflow_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
Transactions are signed via Privy's signTransaction and sent via Helius RPC
for priority fees and reliable blockhash handling.

Note: Platform fees are not supported. Use Jupiter Ultra (privy_ultra) if you
need to collect fees on swaps.
Supports platform fee collection via referralAccount - DFlow auto-creates the
required token accounts to receive fees in the output token.
"""

import base64
Expand Down Expand Up @@ -210,6 +210,8 @@ def __init__(self, registry: Optional[ToolRegistry] = None):
self._signing_key: Optional[str] = None
self._payer_private_key: Optional[str] = None
self._rpc_url: Optional[str] = None
self._platform_fee_bps: Optional[int] = None
self._referral_account: Optional[str] = None

def get_schema(self) -> Dict[str, Any]:
return {
Expand Down Expand Up @@ -250,6 +252,9 @@ def configure(self, config: Dict[str, Any]) -> None:
self._payer_private_key = tool_cfg.get("payer_private_key")
# RPC URL for sending transactions (Helius recommended for priority fees)
self._rpc_url = tool_cfg.get("rpc_url")
# Platform fee configuration (uses referralAccount for auto ATA creation)
self._platform_fee_bps = tool_cfg.get("platform_fee_bps")
self._referral_account = tool_cfg.get("referral_account")

async def execute( # pragma: no cover
self,
Expand Down Expand Up @@ -302,6 +307,8 @@ async def execute( # pragma: no cover
user_public_key=public_key,
slippage_bps=slippage_bps if slippage_bps > 0 else None,
sponsor=sponsor,
platform_fee_bps=self._platform_fee_bps,
referral_account=self._referral_account,
)

if not order_result.success:
Expand Down
11 changes: 9 additions & 2 deletions sakit/solana_dflow_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Enables fast token swaps using DFlow's Swap API with a Solana keypair.
DFlow offers faster swaps compared to Jupiter Ultra with similar liquidity.

Note: Platform fees are not supported. Use Jupiter Ultra (solana_ultra) if you
need to collect fees on swaps.
Supports platform fee collection via referralAccount - DFlow auto-creates the
required token accounts to receive fees in the output token.
"""

import base64
Expand Down Expand Up @@ -80,6 +80,8 @@ def __init__(self, registry: Optional[ToolRegistry] = None):
self._private_key: Optional[str] = None
self._payer_private_key: Optional[str] = None
self._rpc_url: Optional[str] = None
self._platform_fee_bps: Optional[int] = None
self._referral_account: Optional[str] = None

def get_schema(self) -> Dict[str, Any]:
return {
Expand Down Expand Up @@ -113,6 +115,9 @@ def configure(self, config: Dict[str, Any]) -> None:
self._private_key = tool_cfg.get("private_key")
self._payer_private_key = tool_cfg.get("payer_private_key")
self._rpc_url = tool_cfg.get("rpc_url") or DEFAULT_RPC_URL
# Platform fee configuration (uses referralAccount for auto ATA creation)
self._platform_fee_bps = tool_cfg.get("platform_fee_bps")
self._referral_account = tool_cfg.get("referral_account")

async def execute(
self,
Expand Down Expand Up @@ -146,6 +151,8 @@ async def execute(
user_public_key=user_pubkey,
slippage_bps=slippage_bps if slippage_bps > 0 else None,
sponsor=sponsor,
platform_fee_bps=self._platform_fee_bps,
referral_account=self._referral_account,
)

if not order_result.success:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_privy_dflow_swap_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def test_configure_sets_credentials(self):
"signing_key": "test_signing_key",
"payer_private_key": "payer_key",
"rpc_url": "https://custom-rpc.com",
"platform_fee_bps": 50,
"referral_account": "RefAcct123",
}
}
}
Expand All @@ -78,6 +80,8 @@ def test_configure_sets_credentials(self):
assert tool._signing_key == "test_signing_key"
assert tool._payer_private_key == "payer_key"
assert tool._rpc_url == "https://custom-rpc.com"
assert tool._platform_fee_bps == 50
assert tool._referral_account == "RefAcct123"


class TestPrivyDFlowSwapToolExecute:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_solana_dflow_swap_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def test_configure_sets_credentials(self):
"private_key": "test_private_key",
"payer_private_key": "payer_key",
"rpc_url": "https://custom-rpc.com",
"platform_fee_bps": 50,
"referral_account": "RefAcct123",
}
}
}
Expand All @@ -80,6 +82,8 @@ def test_configure_sets_credentials(self):
assert tool._private_key == "test_private_key"
assert tool._payer_private_key == "payer_key"
assert tool._rpc_url == "https://custom-rpc.com"
assert tool._platform_fee_bps == 50
assert tool._referral_account == "RefAcct123"

def test_configure_uses_default_rpc_url(self):
"""Should use default RPC URL when not provided."""
Expand Down