Precompiled Trading Contracts
Overview
Demex has deployed a suite of contracts to extend the usage of Demex's trading engine on EVM. EVM users are now able to create orders, query order and position details as well as perform token transfers and token conversion without having prior interaction with Demex Core. Developers are also able to deploy smart contracts to perform automated trading strategies. dApps to pool liquidity from independent users to employ specific trading strategies, performing automated trades to passively grow funds.
Below are the contracts deployed aimed to provide seamless usage of Demex's trading engine on Demex EVM:
OrderQuerier (Order Module)
Query the details of your order using the Demex Order Id or EVM Order Key (orders stemming from OrderCreation contract)
PositionQuerier (Position Module)
Query the position details of the specified address for the specific market
MarketQuerier (Market Module)
Query the market details such as the base and quote denomination and precision. Mainly targeted for trading contracts to provide the Satoshi quantity for orders
OrderCreation (Order Module)
The main bridge for the creation of order via EVM. Current implementation can only support Fill or Kill (FOK) orders.
TransferConverter (EVMContract Module)
This utility contract allows users and contract accounts to perform Token conversion or token transfers between Demex accounts. This allows directs users and contract owners to manage funds under the trading contract address.
AccountMerger (EVMContract Module)
This utility contract allows contracts and Externally Owned Addresses (EOA) to create accounts on Demex accounts for trading. These merge accounts will allow users to maintain the same account details when migrating over to Demex Core.
User Flow
1. Account Merging
Usage
Users can query this endpoint for the list of contracts available. Look for the contract type of
AccountMerger
and verify the version number and active status of the contract.EOA users will need to call
MergeEvmAccount
passing in your public key as a hexadecimal string. The public key signature field can be left as an empty string""
. To merge a contract address simply callMergeContractAccount
via the contract you wish to create a Demex account for.For contracts that wish to merge accounts on behalf of EOA users can also use
MergeEvmAccount
. Both public key and a signature from the public key will need to be provided for verification purposes.Users can utilise the TransferConverter contract to verify the creation of their Demex account by querying its balance using the method
QueryBalance
.
AccountMerger Contract
For contracts that wish to merge accounts on behalf of EOA users can also use
MergeEvmAccount
. Both public key and a signature from the public key will need to be provided for verification purposes.Users can utilise the TransferConverter contract to verify the creation of their Demex account by querying its balance using the method
QueryBalance
.
2. Transfer and Convert
Once an account is created, funds can now be transferred for trading. As trades are made using Cosmos-native ICS-20 tokens, users with only ERC-20 tokens will need to perform token conversion using TransferConverter contract.
Usage
Users can query this endpoint for the list of contracts available. Look for the contract type of
TransferConverter
and verify the version number and active status of the contract.Owners of ERC-20 tokens will need to call
ConvertERC20ToCoin
to convert their ERC-20 tokens to Cosmos-Native ICS-20 tokens and send them to the specified account for trading. This is done using the specified token-pair contract that maps the ERC-20 token to a corresponding Cosmos-Native token.Users can utilise
ConvertCoinToERC20
to convert their Cosmos-Native tokens back to ERC-20 tokens and update the receiver's balance within the corresponding token-pair contract.Using
QueryBalance
, users can verify their address's balance. With available balance, users can now perform trades via the OrderCreation contract.
TransferConverter Contract
3. Creating Orders
Usage
Users can query this endpoint for the list of contracts available. Look for the contract type of
OrderCreation
and verify the version number and active status of the contract.Users should use the MarketQuerier contracts deployed to obtain the list of available markets along with the relevant token denomination and precision required for detailing order.
Orders can be made by simply calling the
CreateOrder
method on OrderCreation contract. By specifying the order details in the contract call, a corresponding order will be inserted into the order matching engine on Demex L1 for processing.CreateOrder
returns the caller a temporary order identifier (Order Key) that will be used to query for the order's final status. More detailed information on order detailing can be found below.
Order Key generated by OrderCreation contract is a temporary identifier and will be replaced by a permanent Order Id generated by Demex Core's trading engine.
Order Id is a permanent identifier that can be used to query order details any time after creation on CarbonScan and Demex EVM.
Users should immediate utilise the contract type
OrderQuerier
and methodQueryOrder
to query the final status of the order made.QueryOrder
is also able to support queries using the Order Id generated by Demex Core's trading engine.User can also check their position a the market via the PositionQuerier Contract. Calling the
QueryPosition
returns the position of the specified address in a particular market.
OrderQuerier and PositionQuerier respond to queries via callbacks and are unable to support calls directly from EOA users.
OrderCreation Contract
The below querier contracts are designed to provide users with further utility to interact with the trading engine.
MarketQuerier Contract
This querier contract contains the essential information on all trading market in Demex Core. User are able to query the contract for details of a specified market such as the token's precision (required to correctly specify the quantity of the order).
OrderQuerier Contract
The nature of Demex's batched-based matching does not allow OrderCreation contract to immediately return the final status of the order placed. OrderQuerier contract allows smart contracts to query for the status of an order and process them by utilising callbacks.
PositionQuerier Contract
User are able to check on their current position through PositionQuerier. Position queries are responded to after the trading has finalised trades in order to return the finalised position for the current block.
Last updated
Was this helpful?