High-level overview of action flow
This guide will provide more information on interactions with Orderly.
Four main flows for building a DEX on top of Orderly Network are:
- Connect & Register
- Allow users to create an account with Orderly Network, and also create access keys for users to interact with the smart contract and the matching engine
- Deposit & Withdrawal
- Allow users to deposit and withdraw assets to/from the Orderly Asset Manager contract.
- Allow users to view their balances and to place, edit, cancel, and view orders
- Market Data
- Allow the DEX to show market data information including the order book and charts
Orderly 1.0 Architecture
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
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
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 by the front-end 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
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
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 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 APIs and Off-Chain APIs.