A React frontend application that executes atomic DeFi operations via Jito bundles using wallet adapter for signing.
- π Wallet Adapter Integration - Connect with Phantom, Solflare, Backpack, Coinbase
- β‘ Atomic Execution - All transactions succeed or fail together via Jito bundles
- π Jupiter Swap - SOL β JUP swap with configurable slippage
- π° Drift Deposit - Deposit USDC collateral to Drift margin account
- π Drift Short - Open perpetual short positions on JUP-PERP
- πΈ Token Transfer - Send JUP to any address
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β React Frontend β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β β useJupiterSwap β β useDriftShort β β useTokenTransferβ β
β ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ β
β β β β β
β ββββββββββββββββββββββΌβββββββββββββββββββββ β
β β β
β βββββββββββββΌββββββββββββ β
β β useAtomicSwapShort β β
β β (orchestrates all) β β
β βββββββββββββ¬ββββββββββββ β
β β β
β βββββββββββββΌββββββββββββ β
β β Wallet Adapter β β
β β signAllTransactions β β
β βββββββββββββ¬ββββββββββββ β
ββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββ
β
ββββββββββββββΌβββββββββββββ
β Jito JSON-RPC API β
β (sendBundle) β
ββββββββββββββ¬βββββββββββββ
β
ββββββββββββββΌβββββββββββββ
β Solana Validators β
β (Atomic Execution) β
βββββββββββββββββββββββββββ
src/
βββ hooks/
β βββ useJupiterSwap.ts # Jupiter swap transaction builder
β βββ useDriftShort.ts # Drift deposit + short position builder
β βββ useTokenTransfer.ts # SPL token transfer builder
β βββ useJitoBundle.ts # Jito bundle submission
β βββ useAtomicSwapShort.ts # Orchestrates all operations
βββ utils/
β βββ jupiter.ts # Jupiter API integration
β βββ drift.ts # Drift SDK integration (deposit + short)
β βββ transfer.ts # SPL token transfer logic
β βββ jito.ts # Jito JSON-RPC client
βββ components/
β βββ AtomicSwapButton.tsx # Main action button
β βββ AtomicSwapForm.tsx # Configuration form
β βββ WalletContextProvider.tsx
βββ types/
β βββ index.ts # TypeScript type definitions
βββ App.tsx # Main app component
βββ main.tsx # Entry point
# Install dependencies
npm install
# Copy environment variables
cp .env.example .env
# Edit .env with your RPC URL (recommended: use high-performance RPC)
# Start development server
npm run devimport { WalletContextProvider, AtomicSwapForm } from './src/components';
function App() {
return (
<WalletContextProvider rpcUrl="YOUR_RPC_URL">
<AtomicSwapForm />
</WalletContextProvider>
);
}import { useJupiterSwap, useDriftShort, useJitoBundle } from './src/hooks';
function MyComponent() {
const { buildSwap, quote } = useJupiterSwap();
const { buildShort, buildDeposit } = useDriftShort();
const { submitBundle } = useJitoBundle();
const handleExecute = async () => {
// Build transactions
const swapTx = await buildSwap('SOL', 'JUP', 0.1);
// Option 1: Short with deposit in same transaction
const shortTx = await buildShort('JUP-PERP', 10, 50); // 50 USDC deposit
// Option 2: Standalone deposit
const depositTx = await buildDeposit(100); // 100 USDC
// Submit as bundle
const result = await submitBundle([swapTx, shortTx], 50000);
console.log(result);
};
return <button onClick={handleExecute}>Execute</button>;
}| Aspect | Backend | Frontend |
|---|---|---|
| Signing | Keypair.sign() |
wallet.signAllTransactions() |
| Jito API | gRPC (jito-ts) | JSON-RPC (fetch) |
| Drift | Node SDK | Browser SDK with adapter |
| Security | Private key in file | Browser wallet (Phantom etc.) |
Main hook that orchestrates the entire atomic operation.
const {
execute, // (config) => Promise<JitoBundleResult>
progress, // { step, message, swapExpectedOutput }
result, // JitoBundleResult | null
isExecuting,// boolean
reset, // () => void
} = useAtomicSwapShort();
// Config includes optional depositAmount
await execute({
solAmount: 0.1,
shortAmount: 10,
transferAmount: 5,
targetAddress: '...',
depositAmount: 50, // Optional: USDC to deposit before shorting
slippageBps: 50,
jitoTipLamports: 50000,
});Build Jupiter swap transactions.
const {
buildSwap, // (inputToken, outputToken, amount, slippage?) => Promise<Tx>
quote, // JupiterQuote | null
expectedOutput, // number | null
state, // { status, data, error }
} = useJupiterSwap();Build Drift deposit and/or short position transactions.
const {
buildShort, // (marketName, amount, depositAmount?, subAccountId?) => Promise<Tx>
buildDeposit, // (usdcAmount, subAccountId?) => Promise<Tx>
state, // { status, data, error }
} = useDriftShort();
// Short with deposit included in same transaction
const tx1 = await buildShort('JUP-PERP', 10, 50); // Deposit 50 USDC + Short 10 JUP
// Standalone deposit
const tx2 = await buildDeposit(100); // Deposit 100 USDC onlySubmit transaction bundles to Jito.
const {
submitBundle, // (transactions, tipLamports?) => Promise<JitoBundleResult>
state, // { status, data, error }
} = useJitoBundle();The frontend now supports atomic USDC deposits to Drift. You can either:
-
Deposit + Short atomically: Include
depositAmountin your config, and the USDC deposit will be included in the same transaction as the short position. -
Use existing collateral: Set
depositAmountto 0 or omit it. In this case, you must already have USDC in your Drift margin account. -
Standalone deposit: Use
buildDeposit()to create a deposit-only transaction.
The atomic bundle executes in this order:
- Jupiter Swap: SOL β JUP (creates JUP in your wallet)
- Drift Deposit + Short: (Optional) Deposit USDC + Open JUP-PERP short position
- Transfer: Send JUP to target address (uses JUP from step 1)
- For deposit: USDC in your wallet's associated token account
- For short without deposit: Existing USDC collateral in Drift margin account
- For transfer: JUP will come from the Jupiter swap output
- Minimum tip: 1,000 lamports (0.000001 SOL)
- Recommended tip: 50,000+ lamports for faster inclusion
- Max transactions: 5 per bundle
The app uses polyfills for Node.js modules (buffer, crypto, etc.) required by Solana libraries.
For production, use a high-performance RPC provider:
- Helius
- QuickNode
- Triton
ISC