An order is a user's request to trade a certain amount of tokens at a certain price and an order book is a collection of resting orders sorted in a price-time priority sequence. When two orders are matched at the same price, a trade is done. It is important to note that each order can be matched with multiple orders and hence, can have multiple trades done. Two roles are established each time a trade is done accordingly to the time the orders were placed – the Maker role is the order that is placed earlier and the Taker role is the order that is placed later.
ZK-Rollup technology has enabled DeGate to be able to offer an order placement experience as seamlessly as on centralized exchanges. Users can place an order, an off-chain transaction, by using the signature of the asset private key, and therefore, it is free and executed instantly. Once the DeGate node has received the order's signature, the order will either be matched or entered into the order book as a pending open order depending on the orders in the order book. For every order matched, the trade information will be rolled up to the blockchain with zero-knowledge proof.
A limit order is an order where the user specifies both the price and the quantity. The Post-Only function is supported and when it is enabled, this ensures that the limit order is 100% a maker. If any part of the order is a taker, the entire limit order will be rejected. DeGate offers a risk management feature called the Price Deviation Alert to mitigate the risk of fat fingers. If the entered limit order price is +/-5% from the best price, an alert will be displayed on the trade interface to warn and caution the user to check the order price again. This does not block the user from placing the order.
A market order is an order where the user only specifies the quantity and the order will be executed with the best prices in the order book. DeGate offers another risk management feature called the Slippage Protection feature to minimize the slippage risk for users and the DeGate node from front-running. When a market order is placed, the order can at most be matched up to +/-10% from the best price in the order book and the remaining part of the order will be canceled. This limits the possible loss resulting from front-running to be at most 10%. Users can use the limit order option if they are insensitive to price and wants the fastest way to trade.
For limit orders, the order quantity and total need to meet the minimum order size requirement. As for market orders, they do not need to meet the minimum order size requirement as the gas fee is paid during order placement. A market order can be placed as long as the account has a sufficient available balance to cover the pre-authorization gas fee and the filled quantity is at least the smallest denomination of the token.
Each time a trade occurs in DeGate, the taker will pay for both the trading fee and the gas fee and the maker does not need to pay any fee. By default, a market order will be a taker order. A limit order can be either a maker, taker, or partially maker and partially taker depending on the orders in the order book and the order price.
Before placing the limit order, it is not possible to determine if the order will be a maker or a taker. Thus, during order placement regardless of market or limit orders, users will need to authorize to pay the max gas amount. Users are not required to configure the pre-authorization gas fee manually as it is automatically determined. The DeGate node will calculate the pre-authorization gas fee in real time based on the current Ethereum network gas price, ETH price, and gas usage per trade. The pre-authorization gas fee is not necessarily the actual cost as it is dependent on the number of taker orders when the trade is done. The total gas fee paid the taker will pay for this order will not exceed the pre-authorization gas fee amount. No gas fee will be charged for the maker component of this order.
Currently, the pre-authorization gas fee for each order has been configured to fulfill the gas cost for 6 trades. This means that for every order placed, there can at most be 6 trades that are a taker. If there are more than 6 taker orders filled, the first 6 matched trades as taker will be executed while the remaining unfilled part of the order will be canceled. Refer to the different scenarios below:
- 1.A market order is placed. After 4 trades, the order is fully filled.
- 2.A market order is placed. After 6 trades, the order is not fully filled. The remaining unfilled part of the order is canceled.
- 3.A limit order is placed. The order was not matched instantly with other existing orders in the order book meaning it was not executed as a taker. The order enters and rests the order book, waiting to be matched as a maker.
- 4.A limit order is placed. The order was instantly matched 3 times as a taker, and the remaining unfilled part of the order enters the order book as a maker.
- 5.A limit order is placed. The order was instantly matched 6 times as a taker and the next match will also be a taker, hence not matched. The outcome was the order was filled 6 times and the remaining unfilled part of the order is canceled.
- 6.A limit order is placed. The order was instantly matched 6 times. There is no 7th taker trade at this junction, thus, the remaining unfilled part of the order enters the order book as a maker.
The gas fee will be paid in the quote currency of the trading pair. To enhance user experience, the DeGate protocol has enabled, for sell-taker orders, the gas fee in the quote token will be deducted from the proceeds of trade.
For example, in a DG/USDC trading pair, a user may only have DG but not USDC in his account. At this point, the user will be able to place a sell DG order and the USDC gas fee amount will be deducted from the obtained USDC from the trade.
Lastly, the details of the latest pre-authorization gas fee value can be viewed by clicking the "Advanced" button in the place order section of the trade interface.
The trading fee is the main source of revenue for the DeGate Protocol. Each time a trade is completed, the trading fee will be charged according to the trading fee rate and the asset that the taker will receive from the trade. Click here to view the fee rates.
The DeGate protocol has enforced every order to require an expiration duration. With each trade, the circuit verifies the expiration date of the orders and if any of the orders has expired, the verification would fail because before an order is fully filled, the order's signature is effectively valid and can be used for trade. The purpose of having the order expiration duration is to reduce the risks if an attacker gets hold of the order's signature.
Both limit and order have a default expiration duration. Users can amend the value of the "Expire in" field under the "advanced" component for a limit order. There is no need for users to amend the order expiration duration for a market order as the order will be executed immediately, hence having a short order expiration duration.
Users can cancel their order at any time and the cancellation is done instantly and for free. This is possible because as soon as the DeGate node verifies the order cancellation request, the order is canceled in the trading system and the order signature is discarded. However, it is important to understand that this will require the user to trust that the DeGate node has truthfully canceled the order and discarded the order signature such that the order can never be used for matching again. Given this, to achieve trustlessness in the order cancellation process, the DeGate protocol offers an on-chain order cancellation and on-chain grid cancellation feature.
To use this feature, the user must first select a canceled order and proceed to perform an on-chain cancellation request. As soon as the DeGate node has rolled up this cancellation request transaction onto the blockchain, the order will be tagged as closed and can never be matched again. Therefore, users are required to pay a gas fee to execute this on-chain cancellation request. Users can check the calldata to determine if the DeGate node has processed the on-chain cancellation request. On-chain cancellation is no longer applicable if the order has expired as the order signature is no longer valid and will not be able to match.
The ability to distinguish between default and non-default tokens can help users swiftly identify a commonly seen token. Click here to view the differences between the two token types. If the base token is a non-default token, users will see a warning display when accessing the trade and grid strategy user interface. Before trading, please ensure that the token contract address is correct to avoid buying counterfeit tokens.
Based on the system design, during the order matching, the trading system first deducts both the gas and trading fees, then the operator batch the trade transaction and updates the asset merkle tree node after the circuit verification.
The numerical precision used in the trading system is higher than the circuit so there is the possibility where asset value change in the circuit is lesser than the asset value in the trading system. The source of truth of users' assets is based on the asset merkle tree which is regularly rolled up to the DeGate smart contract. Account reconciliation is performed with some adjustments to ensure that the user's DeGate balance is correctly displayed on the DeGate website after the roll-up transaction is completed. The reconciliation amount is very small and will not affect regular usage.