A decentralized perpetual futures trading platform built on RootStock, enabling high-leverage Bitcoin trading with native rBTC collateral. Eterna provides a complete trading experience with automated order matching, real-time price feeds, and seamless wallet integration.
- Leverage Trading: Up to 50x leverage on Bitcoin perpetual futures
- Native rBTC Support: Use Bitcoin directly as collateral without wrapping
- Order-Book: Real-time order matching with slippage protection
- Real-time Price Feeds: Live Bitcoin price data via Redstone Oracle
- Smart Contract Integration: Direct blockchain execution via
bulkTransfer - Order Book: Real-time order book with depth visualization
- Trading Charts: Interactive price charts with technical indicators via TradingView
- Wallet Integration: Seamless MetaMask and wallet connection
- Responsive Design: Modern UI built with Next.js and Tailwind CSS
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Frontend βββββΆβ Backend API βββββΆβ Smart Contract β
β (Next.js) β β (Express.js) β β (DDexRBTC.sol) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βΌ
ββββββββββββββββββββ
β PostgreSQL β
β Database β
ββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββ
β Redstone Oracle β
β (Price Feeds) β
ββββββββββββββββββββ
ddex/
βββ FE/ # Frontend (Next.js)
β βββ app/ # App router pages
β β βββ page.tsx # Landing page
β β βββ trade/ # Trading interface
β β βββ portfolio/ # Portfolio management
β β βββ margin/ # Margin management
β βββ components/ # React components
β β βββ trading-panel.tsx # Main trading interface
β β βββ order-book.tsx # Order book display
β β βββ positions-table.tsx # Position management
β β βββ wallet-connect.tsx # Wallet integration
β β βββ ui/ # Reusable UI components
β βββ hooks/ # Custom React hooks
β βββ services/ # API services
β βββ types/ # TypeScript definitions
βββ backend/ # Backend (Express.js)
β βββ routes/ # API routes
β βββ services/ # Business logic
β βββ cronJobs/ # Automated order matching
β βββ migrations/ # Database migrations
β βββ config/ # Configuration files
βββ contracts/ # Smart contracts
β βββ DDexRBTC.sol # Main trading contract
βββ README.md # This file
- Framework: Next.js 14 with App Router
- Language: TypeScript
- Styling: Tailwind CSS
- UI Components: Radix UI + shadcn/ui
- Charts: Recharts
- Wallet: Ethers.js
- Oracle: Redstone Finance
- Runtime: Node.js
- Framework: Express.js
- Database: PostgreSQL
- ORM: Native pg driver
- Blockchain: Ethers.js
- Cron Jobs: node-cron
- Language: Solidity ^0.8.19
- Network: RootStock Testnet
- Features: rBTC deposits, transfers, bulk operations
- Node.js 18+
- PostgreSQL 12+
- Git
- MetaMask or compatible wallet
git clone https://github.com/0xmkar/Eterna/
cd ddexcd backend
# Install dependencies
npm install
# Set up environment variables
cp env.template .env
# Edit .env with your configuration
# Set up PostgreSQL database
# Create database: perpetual_futures
# Run migrations from migrations/ folder
# Start the backend server
npm run devcd FE
# Install dependencies
npm install
# Start the development server
npm run devDeploy the DDexRBTC.sol contract to RootStock Testnet and update the contract address in your environment variables.
Create a .env file in the backend directory:
# Database Configuration
DB_USER=postgres
DB_HOST=localhost
DB_NAME=perpetual_futures
DB_PASSWORD=your_password_here
DB_PORT=5432
# Server Configuration
PORT=3001
# Smart Contract Configuration
CONTRACT_ADDRESS=0x1234567890abcdef1234567890abcdef12345678
PRIVATE_KEY=your_private_key_here
RPC_URL=https://public-node.testnet.rsk.co
# Order Matching Configuration
ORDER_MATCHING_ENABLED=true
ORDER_MATCHING_INTERVAL_SECONDS=2Create a .env.local file in the FE directory:
NEXT_PUBLIC_API_URL=http://localhost:3001
NEXT_PUBLIC_CONTRACT_ADDRESS=0x1234567890abcdef1234567890abcdef12345678
NEXT_PUBLIC_RPC_URL=https://public-node.testnet.rsk.coCREATE TABLE public.users (
id bigserial NOT NULL,
wallet_address varchar(64) NOT NULL,
created_at timestamp DEFAULT now() NULL,
CONSTRAINT users_pkey PRIMARY KEY (id),
CONSTRAINT users_wallet_address_key UNIQUE (wallet_address)
);CREATE TABLE public.orders (
id bigserial NOT NULL,
user_id int8 NULL,
side varchar(4) NOT NULL,
price numeric NULL,
quantity numeric NOT NULL,
leverage numeric NOT NULL,
margin numeric NOT NULL,
max_slippage_bps int4 DEFAULT 5 NULL,
status varchar(16) DEFAULT 'OPEN'::character varying NULL,
created_at timestamp DEFAULT now() NULL,
updated_at timestamp DEFAULT now() NULL,
CONSTRAINT orders_pkey PRIMARY KEY (id),
CONSTRAINT orders_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id)
);CREATE TABLE public.trades (
id bigserial NOT NULL,
buy_order_id int8 NOT NULL,
sell_order_id int8 NOT NULL,
execution_price numeric NOT NULL,
quantity numeric NOT NULL,
buyer_address varchar(42) NOT NULL,
seller_address varchar(42) NOT NULL,
trade_value numeric NOT NULL,
executed_at timestamp DEFAULT now() NULL,
created_at timestamp DEFAULT now() NULL,
CONSTRAINT trades_pkey PRIMARY KEY (id),
CONSTRAINT trades_buy_order_id_fkey FOREIGN KEY (buy_order_id) REFERENCES public.orders(id),
CONSTRAINT trades_sell_order_id_fkey FOREIGN KEY (sell_order_id) REFERENCES public.orders(id)
);The platform features an automated order matching engine that:
- Runs via cron job
- Matches orders based on price and slippage tolerance
- Executes trades on-chain via
bulkTransferfunction - Updates order status to
FILLEDorPARTIALLY_FILLED - Records trades in the database with transaction hashes
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Cron Job βββββΆβ Order Matching βββββΆβ Smart Contract β
β β β Algorithm β β (bulkTransfer) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βΌ
ββββββββββββββββββββ
β Database β
β (Update Orders β
β & Record Trades)β
ββββββββββββββββββββ
GET /users- Get all usersGET /users/:id- Get user by IDGET /users/wallet/:address- Get user by wallet addressPUT /users- Create new userPUT /users/:id- Update user
GET /orders- Get all ordersGET /orders/:id- Get order by IDGET /orders/user/:userId- Get orders by user IDPUT /orders- Create new orderPUT /orders/:id- Update order
GET /order-matching/status- Get matching system statusPOST /order-matching/trigger- Manually trigger matching
cd backend
npm testcd FE
npm run test- Set up PostgreSQL database
- Configure environment variables
- Run database migrations
- Deploy to your preferred hosting service
- Build the application:
npm run build - Deploy to Vercel, Netlify, or your preferred platform
- Compile contracts:
npx hardhat compile - Deploy to RootStock Testnet
- Update contract addresses in environment variables
This project is licensed under the MIT License - see the LICENSE file for details.
- Live Demo: [Coming Soon]
- Documentation: [Coming Soon]
- Smart Contract: [RootStock Explorer]
- API Docs: [Coming Soon]
Built with β€οΈ for the RootStock ecosystem