FuturX, dApp enabling futures trading of RWAs on Citrea chain using smart contracts, custom oracles
FuturX is a decentralized derivatives trading dApp that runs on the Citrea testnet, combining on-chain smart contracts with a custom price oracle built from scratch and a modern web UI using NextJS to enable trustless creation, matching, and settlement of futures and options positions—initially for BTC/USD and Gold/USD. The ultimate goal is, to provide a derivate platform for multiple coins, natural assets and RWA tokens. The project targets common problems in traditional futures markets—centralized custody/risk, opaque settlement, and restricted access. By pushing both the trading logic and price feed transparency on-chain, FuturX aims to remove intermediaries and make the lifecycle of a financial derivative trade verifiable end-to-end.
High-level architecture Smart contracts (Solidity) implement the futures lifecycle: create → match → settle. An on-chain price Oracle holds the latest price per asset plus history. Backend updater (Node + ethers) pushes off-chain market prices into the Oracle on a cadence. Frontend (Next.js/React + Tailwind) is the trading UI: pick market/side/size/duration and call createPosition(...) on the futures contract. Repo layout reflects that split: contract/, backend/, frontend/ folders, and language mix TypeScript/Solidity/JS/CSS.
Contracts (Solidity): Core idea: encode a bilateral future with symmetric margin, minimal assumptions, and a discrete expiry. Futures contract Create: seller opens a position with createPosition(asset, side, expiryTime, fraction, margin) (payable). This saves seller, side (long/short), asset (e.g., BTC or GOLD), priceBefore from the oracle, expiry timestamp, margin, and size (fraction). Match: buyer takes the other side by locking equivalent margin (matchPosition(id)). Settle: at or after expiry, contract grabs the oracle’s price and transfers PnL between parties (settle(id)). Emits PositionCreated, PositionMatched, PositionSettled for indexable history and off-chain indexing. Oracle Stores current price per string asset symbol and a history array of { price, timestamp } entries. Read APIs (getPrice, getPriceWithTimestamp, getHistory*) make it easy to build analytics (like volatility) without another off-chain DB. Why this shape? Payable createPosition and matchPosition simplify accounting (margin = msg.value). Using an enum for Asset/Side keeps calldata compact and less error-prone than string inputs for those fields. Storing priceBefore at open plus expiryTime reduces settlement ambiguity and prevents “look-back” games by either side.
Backend oracle updater (Node.js + ethers) What it does: a small Node process fetches prices from public APIs (e.g., BTC/USD, Gold/USD) and pushes them on-chain via updatePrice / updatePrices. It signs a transaction using a hot wallet (or deployer key) and calls the Oracle. Why not a decentralized oracle? This project is a vertical slice; an on-chain history plus signed updates are enough to demo the DEX mechanics. It leaves the door open to swap in Chainlink/Redstone later. How it fits: Fetch external price → Normalize to on-chain decimals (e.g., 8) → Send TX to Oracle. Benefit: keeping price history on-chain enables frontends or scripts to compute things like EWMA volatility and derive a margin schedule dynamically (you’ve shown this in your simulation script with the ewmaVolatility + marginFromVol pipeline). The repo’s backend/ folder indicates a dedicated backend piece, and your shared code shows ethers-based price pushes and history reads for analytics. GitHub Frontend (Next.js/React + Tailwind) What it does: wallet-connected UI to open positions. Stack: TypeScript + React (Next.js), TailwindCSS, lucide icons; uses ethers for wallet/chain calls. The repo language stats reflect heavy TS and some CSS/JS. GitHub Happy path (create): User picks market (BTC-USDC / GOLD-USDC), side (long/short), duration (e.g., 1m/1h/1d), and collateral (margin). UI maps selections to the contract’s enum values and computes expiryTime = now + duration. Calls futures.createPosition(asset, side, expiryTime, fraction, margin, { value: margin }). Wallets/chain: connects to Citrea Testnet RPC; MetaMask (or any EVM wallet) signs/broadcasts the TX. Chain & infra: Citrea (Bitcoin ZK rollup, EVM-compatible) Why Citrea? It’s a Bitcoin-aligned ZK rollup with EVM compatibility, so you can use standard Solidity + ethers + MetaMask and still tie security/settlement to Bitcoin. docs.citrea.xyz Testnet details: Citrea exposes EVM JSON-RPC endpoints and has a public faucet and chain metadata
Sophisticated risk models (beyond most derivatives marketplaces) One of the most unusual aspects of FuturX is that it experiments with quantitative finance models rarely seen in crypto derivatives platforms: EWMA margining (Exponentially Weighted Moving Average) The system can compute volatility from the oracle’s on-chain price history using an EWMA variance estimator (the same RiskMetrics methodology used in banks). Each new return updates variance with exponential decay (σ²ₜ = λσ²ₜ₋₁ + (1–λ)r²), giving more weight to recent moves. Margin requirements are then scaled dynamically: higher volatility → higher margin. This makes the margin model more risk-sensitive than fixed % margins that most DeFi perps and futures markets use. Jump diffusion considerations The project also explores how jump diffusion processes (think Merton or Kou models) could be incorporated into risk controls. These models allow for rare but extreme price jumps on top of continuous volatility. Most derivative platforms assume lognormal returns (Black-Scholes style). By acknowledging jumps, FuturX can set more robust buffers for margin and liquidation, protecting against “fat tail” risks.

