DeepBook Social Margin: Copy Trading, Leaderboard & AI Risk Alerts
MarginMaster is a decentralised social copy trading protocol built on the Sui blockchain, designed to democratise access to institutional-grade trading strategies whilst maintaining full user sovereignty.
In the current DeFi landscape, retail traders often struggle against information asymmetry and lack the sophisticated tools available to professional market makers. Furthermore, existing copy trading solutions are predominantly centralised, requiring users to entrust their funds to custodial platforms with opaque performance metrics.
MarginMaster solves this by enabling a completely trustless, non-custodial copy trading experience. Users retain full custody of their assets within a personal Vault object, only authorising the protocol to mirror trades from their chosen Master Trader. Our smart contracts, written in Sui Move, leverage the unique object-centric architecture of Sui to deliver sub-second trade execution and instant finality, minimising the critical slippage between the Master's original trade and the Followers' execution.
Technically, the protocol introduces two novel mechanisms to the Sui ecosystem:
Flash Liquidation via 'Hot Potato' Pattern: We utilise a custom FlashLoan struct (a hot potato with no drop ability) to allow liquidators to borrow the necessary capital from the protocol's own vault to liquidate underwater positions. This means liquidators require zero upfront capital, significantly increasing protocol resilience and capital efficiency. Batch Copy Execution: To optimise gas costs and reduce network congestion, our off-chain event indexer captures trade signals and bundles multiple follower executions into a single Programmable Transaction Block (PTB). This ensures that even with hundreds of followers, trades are executed efficiently and atomically. The platform features a fully responsive interface built with React and Vite, offering real-time WebSocket price feeds, interactive charts, and a transparent Leaderboard where every statistic—PnL, Win Rate, and Trade History—is derived directly from immutable on-chain data. MarginMaster provides the transparency of DeFi with the polished user experience of a top-tier CEX.
This project is a testament to the power of human-AI collaboration. I personally architected the protocol and wrote the Sui Move smart contracts to ensuring the core financial logic was secure, efficient, and capital-efficient. To accelerate development, I utilised AI agents to generate the boilerplate and implementation details for the React (Vite) frontend and Express.js backend. My role then shifted to that of a lead engineer and security auditor—constantly verifying the AI-generated code, running rigorous integration tests, and ensuring the off-chain infrastructure perfectly synchronised with the on-chain state.
Technologies Used:
Smart Contracts: Written in Sui Move, utilising the object-centric model for our Vault and Position structures. Frontend: Built with React, Vite, and Tailwind CSS for a responsive, high-performance UI. We used Recharts for the interactive price charts and @mysten/dapp-kit for seamless wallet integration. Backend: An Express.js server with Socket.IO handles real-time data feeds. We used Prisma ORM with a Supabase (PostgreSQL) database to index and query on-chain data for the leaderboard. Indexer: A custom-built event indexer listens to Sui network events to trigger copy trades and update user statistics. Notable Implementations: The most "hacky" and innovative part of our stack is the Flash Liquidation mechanism. I designed a "Hot Potato" pattern (a struct with no drop ability) that forces the liquidator to repay the loan within the same transaction block. This allows anyone to liquidate underwater positions without needing their own capital, democratising the liquidation process.
Additionally, we leveraged Programmable Transaction Blocks (PTBs) to batch execute copy trades. Instead of sending one transaction per follower, our backend bundles multiple executions into a single transaction, significantly reducing gas costs and network congestion—a critical optimisation for a social trading protocol.

