project screenshot 1
project screenshot 2
project screenshot 3
project screenshot 4

Perpetua

Perpetua is a decentralized perpetual futures trading platform that enables users to trade crypto assets with leverage, without expiration dates, Perpetua ensures low fees, high speed, and full transparency. Trade anytime, anywhere.

Perpetua

Created At

ETHGlobal Singapore

Project Description

Perpetua is a decentralized perpetual trading exchange (Perp DEX) that allows users to trade crypto assets with leverage and without expiration dates on contracts. It combines the flexibility of perpetual contracts with decentralized finance (DeFi) technology, offering a fast, low-cost, and transparent trading experience on the blockchain.

Key Features: Perpetual Contracts: Perpetua’s contracts have no expiration dates, enabling traders to hold positions as long as they like. This makes it ideal for both short-term trading and long-term strategies.

Off-Chain Orderbook: Perpetua uses an off-chain orderbook to facilitate faster transactions and reduce gas fees. Traders can place, modify, and cancel orders without the cost or delay of interacting with the blockchain. Once orders are matched, they are executed on-chain for transparency and security.

On-Chain Settlement: Although the orderbook is off-chain, all trades are settled on-chain, ensuring transparent execution. This provides security and verifiability, as trades are finalized through the underlying blockchain technology.

Leverage Trading: Traders can use leverage to increase their exposure to asset price movements, allowing for the possibility of higher profits with a smaller initial investment. This feature also introduces higher risk, which traders should manage accordingly.

Risk Management: Automated liquidation systems ensure that positions are closely monitored for margin compliance. If a trader’s margin falls below the required threshold, their position will be liquidated to prevent further loss.

User-Friendly Interface: Designed with both novice and expert traders in mind, Perpetua features an intuitive and responsive interface, offering advanced charting, real-time data, and easy access to trading tools.

Fee Efficiency: Perpetua’s hybrid system of off-chain order matching and on-chain settlement reduces transaction fees, making it more affordable for frequent traders while maintaining the security of blockchain settlements.

Core Components: Order Management: Users can place market, limit, and stop orders, all handled through the efficient off-chain engine. Price Oracles: Reliable price feeds, such as those from Pyth or Chainlink, ensure accurate real-time pricing for assets, which is critical for calculating profits and liquidation triggers. Liquidation Engine: The platform ensures robust risk management by automating liquidations if positions become undercollateralized, protecting users from extreme losses. Future Plans: New Asset Listings: Perpetua will continuously add new crypto assets and synthetic assets to diversify its trading options. Cross-Chain Trading: The platform will enable cross-chain support, offering users the ability to trade assets from multiple blockchains in a single interface. Mobile Trading App: Perpetua will soon launch a mobile app, allowing users to trade and monitor their positions on the go. Perpetua aims to provide a seamless, secure, and accessible platform for perpetual trading, offering a range of innovative features that cater to both experienced traders and newcomers to decentralized finance.

How it's Made

Perpetua is a decentralized perpetual trading exchange built with a focus on high performance, transparency, and scalability. Here's a detailed breakdown of the technologies and architecture involved in creating the platform:

Core Technologies: Blockchain: Flow

We chose Flow blockchain for its high throughput, developer-friendly environment, and low gas fees, ensuring smooth, cost-efficient user interactions. The Cadence smart contracts are used to manage trades, positions, and on-chain settlement in a secure and resource-oriented manner. Cadence Smart Contracts:

All critical functionalities such as position management, liquidation, leverage, and margin handling are written in Flow’s Cadence language. Cadence’s resource-oriented programming ensures ownership and safety of user assets and reduces the risks of common vulnerabilities like reentrancy. Off-Chain Orderbook:

Perpetua’s hybrid model uses an off-chain orderbook to enable fast order matching without constantly interacting with the blockchain. This reduces gas fees and improves speed. Trades are only finalized on-chain after an order is matched, allowing for efficient gas usage. Pyth Network for Price Feeds:

For reliable, real-time pricing data, we integrated Pyth Network oracles. Pyth provides decentralized, high-fidelity price feeds sourced from professional traders and financial institutions, which is critical for calculating profit & loss (PnL), margin requirements, and triggering liquidations. Pyth’s integration ensures accurate price updates for volatile assets, and its aggregation mechanism provides confidence in price accuracy, which is essential for the security of leveraged trades. These price feeds enable accurate, trustless execution of positions and prevent price manipulation by relying on aggregated prices rather than single-source data. Backend: Node.js & TypeScript:

The backend is built using Node.js and TypeScript, handling off-chain order matching and interaction with the smart contracts. TypeScript adds strong type-checking, helping to manage the complexity of perpetual trading logic with fewer bugs. Express is used to manage APIs for trade interactions, while GraphQL provides efficient data querying for live data displays. Real-Time Data Handling with WebSockets:

We implemented WebSockets for real-time updates. This allows traders to view live orderbook data, price updates, and PnL in real-time without page refreshes, offering a highly responsive trading experience. Frontend: React & Next.js:

The UI is built with React and Next.js to ensure fast, SEO-optimized rendering. This enables users to interact with the exchange in real time with minimal latency. Tailwind CSS is used to create a sleek, responsive design optimized for both mobile and desktop trading. Database: MongoDB:

We chose MongoDB for its flexibility and scalability to manage user sessions, trade history, and off-chain orderbook data. MongoDB's document-based architecture is well-suited for handling the constantly changing, complex data structures involved in perpetual trading. Prisma ORM:

Prisma is used as the ORM layer for interacting with MongoDB. It simplifies database management with its type-safe queries and schema migrations, ensuring seamless interaction between the backend and the database. Challenges & Notable Solutions: Pyth Price Integration:

One of the critical components of Perpetua is ensuring accurate price feeds for executing positions. Pyth’s network of price feeds ensures that we use aggregated data from trusted institutions, reducing the risk of slippage and front-running. We implemented a periodic verification process to update prices on-chain using Pyth's aggregated prices, ensuring consistency across trades. Gas Optimization:

We optimized the smart contracts to minimize gas usage by offloading non-critical actions (such as order placement and updates) off-chain. Only key events like trade execution and position closure happen on-chain to save costs. Liquidation System:

We built an automated liquidation engine that triggers based on margin requirements and the Pyth price feeds. The integration with real-time oracles ensures timely execution of liquidations and protects against under-collateralized positions.

background image mobile

Join the mailing list

Get the latest news and updates