Introduction

Orderly provides the infrastructure and tools necessary for developers to build their own DeFi dApps by accessing an array of products Orderly offers.

Builders can integrate Swaps, Spot, and Perps for NEAR native assets (BTC, ETH, NEAR, AURORA, WOO, SWEAT, USDT, USDC.e, NEAT) on their projects.

Orderly leverages NEAR’s technology to provide in-dApp Swaps for mass market companies, to power DEXs with deep Spot liquidity for major assets and a CEX-like Perps experience on-chain.

Many products and functionalities are still in development and will be rolled out according to the roadmap

What’s possible

The possibilities are endless when building with Orderly. Developers can tap into any of our products, such as Spot Trading, Perpetual Futures, Lending & Borrowing, and Cross Chain Swaps (many functionalities are still in development and are not available to the public), and create a dApp for their specific needs.

Whether you’re building a DEX, a Swap, or an entirely new product, Orderly provides the tools necessary to power your DeFi platform.

Why build on Orderly

Websites or apps using Orderly Network are free to tailor the experience to their use case and the unique needs of their target market. Integrating with Orderly will save build time for anyone building on the platform by removing the challenges of creating your own order book and liquidity, so developers can focus on delivering the best user experience possible.

High-level architecture overview

The trading flow on Orderly happens in the following steps:

Connect, Authenticate, and Stake Storage Deposit

  • Create Access & Trading Keys for users to interact with the smart contract/matching engine, pay storage deposit, and instantiate a user account in the smart contract

Deposit & Withdraw

  • Deposit and withdraw assets to/from the Orderly Asset Manager contract.

Market Data

  • Retrieve market data information including the order book and charts

Trade

  • View balances, and place, edit, cancel, or view orders

Architecture

Smart Contract (Asset Manager)

The asset manager contract is the main Smart Contract of Orderly network which acts as a custodial account to provide the best user experience possible for an on-chain exchange with it’s low fees, fast trade execution, and deep liquidity.The contract stores the following information:

  • NEAR Account ↔︎ Orderly / Trading Key mappings

  • Balance of each account in Orderly

  • Whitelist of permitted assets for the contract

  • Whitelist of permitted trading pairs

The contract has the following usages:

  • Allows users to create an account - i.e. bind their NEAR account_id with specific Orderly trading keys

  • Allows users to deposit whitelisted assets to their Orderly account

  • Allow users to withdraw their assets from their Orderly account

  • Settles executed trades by updating balances of all users on-chain after receiving trade executions

Off-Chain Engine

Currently, the Matching Engine (Orderbook) is off-chain and the smart contract is used as a settlement layer, to offer market-leading trade execution with low latency and minimal fees.The Off-Chain Engine has the following functionalities:

  • Order service

  • Matching engine

  • Trade upload management (uploads executed trades back up to the smart contract)

  • Deposit/Withdrawal management

Connect & Register

In order to register an account and connect a wallet, a user needs two key pairs: Orderly Key Pair (ed25519), also known as Access Key, and Trading Key Pair (secp256k1). Orderly Access Key Pair is generated by the wallet and more information can be found here. Trading keys can be generated using this library. Please refer to Authentication for more information on Authentication via WebSocket and RESTful APIs.

NEAR Protocol has a storage staking mechanism when the data is stored on-chain (more info can be found here). Orderly requires the users to stake a small amount of NEAR upon creating a new user account, adding new trading key pairs, and new token balances to prevent Sybil attacks and minimize the number of payable transactions

Deposit & Withdrawal

Deposit flow

Withdrawal flow

Users have to transfer their funds into the Orderly smart contract, known as an Asset Manager, which acts as a custodial account in order to trade. Deposits and withdrawals are initiated through a smart contract. More details can be found on the smart contract API page.

The number of pending withdrawals is limited to 10 per each user

Trading Flow

Trade flow

User trading data can be retrieved via various RESTful and Websocket APIs. Users can also manage orders via REST APIs. More details can be found on the off-chain engine API page.

Market Data

Market data retrieval flow

Market data can be connected via various RESTful and Websocket APIs. More details can be found on the off-chain engine API page.

Some of the market data, such as listed token pairs and listed tokens, can be retrieved through Smart Contract and Off-Chain APIs.

This guide is a WIP. If you have any suggestions or questions please contact us by email

For questions regarding building with us, send us an email or reach out in the discord