About the Project: Equilibrium EngineπŸ’‘ Inspiration: The "Physics-Blind" Grid ParadoxIt seems like every year, dozens of hackathon projects claim to "decentralize the energy grid" by putting solar panels on a blockchain. But if you look closely at how energy grids actually operate, you notice a massive disconnect: traditional financial markets treat electricity as a frictionless abstraction, while nature enforces harsh thermodynamic reality.When power is transmitted over long distances, high voltage doesn't prevent significant power dissipation due to $I^2R$ resistance in copper and aluminum transmission lines. Yet today’s wholesale energy markets price power uniformly across massive geographic zones. A Megawatt produced 500 miles away is priced identical to a Megawatt produced right next door by your neighbor’s microgridβ€”even though nearly 10% of the distant power was converted into pure heat loss along the wire.The realization: Wall Street trades equities in nanoseconds using location-agnostic matching engines. But energy demands spatial awareness. We were inspired to answer a single question: What if an order book engine natively calculated thermodynamic distance loss at sub-millisecond execution speeds?πŸ› οΈ How We Built ItWe engineered Equilibrium Engine as a multi-tier, hybrid HFT architecture that merges high-throughput Rust processing with real-time spatial visualization and cryptographic batch settlement. [ TypeScript Simulator ] β”‚ (WebSocket) β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Rust / Axum WebServer β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ (MPSC Channels) β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Lock-Free Matching Engine β”‚ β”‚ - Haversine Distance β”‚ β”‚ - Exponential Decay Logic β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ (EIP-712 Signatures) β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ EVM On-Chain Settlement β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  1. The Core Physics & Matching MathThe engine sits in an async Tokio actor loop written in Rust. When a buyer (Bid) and seller (Ask) interact, the matching engine calculates the geodesic distance $\Delta d$ using the Haversine formula:$$a = \sin^2\left(\frac{\Delta \phi}{2}\right) + \cos(\phi_1) \cdot \cos(\phi_2) \cdot \sin^2\left(\frac{\Delta \lambda}{2}\right)$$$$c = 2 \cdot \operatorname{atan2}\left(\sqrt{a}, \sqrt{1-a}\right)$$$$\Delta d = R \cdot c$$where $\phi$ is latitude, $\lambda$ is longitude, and $R$ is the Earth's radius ($6,371\text{ km}$).Using this spatial distance, the effective delivered power $P_{\text{eff}}$ and spatial loss penalty fee $F_{\text{loss}}$ are derived via exponential distance decay:$$P_{\text{eff}} = P_{\text{order}} \cdot e^{-k \cdot \Delta d}$$$$F_{\text{loss}} = P_{\text{order}} \cdot \left(1 - e^{-k \cdot \Delta d}\right) \cdot \text{Price}$$Here, $k$ represents the grid line resistance coefficient ($k = 0.0015\text{ km}^{-1}$). By factoring $F_{\text{loss}}$ directly into the matching order depth, localized hyper-adjacent trades naturally clear at lower effective prices, disincentivizing long-distance grid strain.2. High-Frequency Pipeline & FrontendBackend: Built with Rust (Axum/Tokio). Orders are passed via multi-producer, single-consumer (mpsc) lock-free channels into an atomic memory-resident order book, returning WebSocket telemetry frames in sub-milliseconds.Simulator: A custom TypeScript/Node.js generator simulating geometric Brownian motion with mean-reversion, streaming continuous orders from distributed regional node profiles (solar farms, wind parks, EV charging hubs).Frontend: A Next.js 14 / Tailwind CSS interface featuring an SVG spatial grid canvas that visualizes live transmission loss vectors, alongside an interactive depth order book.Settlement: Off-chain matching offloads high-volume tick traffic, generating EIP-712 typed structured data signatures for periodic on-chain EVM batch settlement.🚧 Challenges We FacedBuilding a system that balances spatial physics with sub-millisecond execution isn't without friction.1. Avoiding Lock Contention at ScaleIn an early design iteration, wrapping the order book inside a standard shared Arc> caused severe thread lock contention when concurrent WebSocket connections flooded the server with order submissions. We had to refactor the entire engine to an actor-based message-passing pattern using bounded Tokio channels, isolating state mutations inside a dedicated thread without shared locks.2. Integrating Floating-Point Spatial Math with HFT SpeedCalculating trigonometric arcsines and exponential decays inside a hot matching loop is computationally expensive. We had to carefully optimize spatial calculations in Rust, leveraging strict stack allocation and zero-copy data transformations to ensure spatial loss calculations didn't degrade execution throughput.3. Real-Time Spatial Canvas SynchronizationDisplaying dynamic transmission lines between nodes on an SVG canvas based on real-time WebSocket state required fine-tuning React rendering loops to prevent unnecessary DOM redraws under 100ms market tick intervals.πŸŽ“ What We LearnedLocality is Energy's Natural Hedge: Incorporating physical spatial decay directly into financial matching engine logic creates a self-balancing market. Prices naturally adjust to incentivize local power consumption without needing manual top-down regulatory intervention.Rust's Actor Model is Ideal for HFT Systems: Decoupling network I/O (Axum WebSockets) from execution state (OrderBook thread) via Tokio channels yields predictable execution latencies and zero data-race panics.Off-Chain Physics + On-Chain Cryptography = Scalable Utility: You don't need every high-frequency tick on-chain. Off-chain deterministic execution paired with cryptographic batch settlement (EIP-712) offers the speed of centralized finance with the auditability of decentralized ledgers.

Built With

  • algorithms
  • async-rust
  • axum
  • clean-energy
  • decentralized
  • decoupled-architecture
  • eip-712
  • evm
  • game-theory
  • high-frequency-trading
  • mathematical-modeling
  • microservices
  • next.js
  • node.js
  • physics
  • react
  • rust
  • smart-contracts
  • solidity
  • svg
  • tailwind-css
  • tokio
  • typescript
  • web3
  • websockets
Share this project:

Updates

Submission history