A modern, responsive UI template for integrating with the Drift protocol. This template provides a foundation for building trading applications with spot and perpetual markets using the AuthorityDrift wrapper for simplified integrations.
- Drift Integration: Pre-configured AuthorityDrift setup with real-time price feeds
- Multi-Asset Support: Perpetual trading functionality
- Wallet Integration: Solana wallet adapter with multiple wallet support
- Real-time Data: Live oracle prices, mark prices, and user account data
- Modern Stack: Built with Next.js 15, React 19, and TypeScript
- User Management (
/user): Account creation, deposits, and user management - Spot Trading (
/spot): Deposit and withdraw supported tokens - Perpetuals (
/perps): Trade perpetual futures with leverage - Market Data (
/data): Real-time market information
- AuthorityDrift: Simplified wrapper around the Drift SDK for easy integration
- Real-time Stores: Zustand-based state management for prices and user data
- Wallet Adapter: Seamless integration with Solana wallets
- Node.js 18+ or Bun
- Solana wallet (Phantom, Solflare, etc.)
- Basic knowledge of React and Solana development
git clone <your-repository-url>
cd drift-ui-templateNavigate to the UI directory and install dependencies:
cd ui
bun installCreate a .env.local file in the ui directory:
NEXT_PUBLIC_SOLANA_MAINNET_RPC_ENDPOINT=your_mainnet_rpc_url
NEXT_PUBLIC_SOLANA_DEVNET_RPC_ENDPOINT=your_devnet_rpc_urlcd ui
bun devThe application will be available at http://localhost:3000.
The template is configured for mainnet by default. To switch to devnet, modify the configuration in src/hooks/globalSyncs/useSetupDrift.ts:
// Change this line
const driftConfig = MAINNET_DRIFT_CONFIG;
// To
const driftConfig = _DEVNET_DRIFT_CONFIG;You can specify which markets to trade by uncommenting and configuring the tradableMarkets array in the drift config:
tradableMarkets: [
new MarketId(0, MarketType.SPOT), // USDC
new MarketId(1, MarketType.SPOT), // SOL
new MarketId(0, MarketType.PERP), // SOL-PERP
new MarketId(1, MarketType.PERP), // BTC-PERP
],Find available markets:
The template uses AuthorityDrift for simplified integration with the Drift protocol:
const authorityDrift = new AuthorityDrift({
solanaRpcEndpoint: rpcEndpoint,
driftEnv: "mainnet-beta",
wallet: walletAdapter,
});
await authorityDrift.subscribe();The template includes pre-configured stores for real-time data:
- Oracle Prices: Live price feeds from Pyth and Switchboard
- Mark Prices: Drift's calculated mark prices
- User Account Data: Real-time user positions and balances
The template uses Zustand for state management with the following stores:
DriftStore: Main Drift client and configurationOraclePriceStore: Real-time oracle price dataMarkPriceStore: Mark price data for perpetualsUserAccountDataStore: User account information and positions
The template uses Tailwind CSS for styling. You can customize the theme by editing:
ui/src/app/globals.css: Global styles and CSS variablesui/tailwind.config.js: Tailwind configuration
UI components are located in ui/src/components/ui/ and built with Radix UI primitives:
- Cards, buttons, forms, tooltips
- Dropdown menus and selects
- Customizable and accessible
- Create new pages in
ui/src/app/ - Add corresponding components in
ui/src/components/ - Use the existing stores for state management
- Follow the established patterns for AuthorityDrift integration
bun run dev # Start development server with Turbopack
bun run build # Build for production
bun run start # Start production server
bun run lint # Run ESLintui/
βββ src/
β βββ app/ # Next.js pages and layouts
β βββ components/ # Reusable UI components
β βββ stores/ # Zustand state management
β βββ hooks/ # Custom React hooks
β βββ providers/ # React context providers
β βββ utils/ # Utility functions
β βββ constants/ # Application constants
βββ public/ # Static assets
βββ package.json # Dependencies and scripts
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
The template is optimized for performance with:
- Next.js 15 with Turbopack for fast development
- React 19 with modern concurrent features
- Efficient state management with Zustand
- Real-time subscriptions with minimal re-renders
- Code splitting and lazy loading
- Environment variables for sensitive configuration
- Wallet adapter security best practices
- No private keys stored in the application
- RPC endpoint configuration for reliable connections
For questions and support: