Exchange Use Case
By the end of this guide, you should know how an exchange can integrate with the OMG Network.
The main goal of this document is to demonstrate how a token issuer or an exchange can add an OMG Network support for depositing and withdrawing a particular ERC20 token (e.g. USDt).
The integration with the OMG Network can significantly help the entire Ethereum ecosystem to offload a certain volume from the rootchain, as well as introduce faster and cheaper transactions with the same security guarantees as to the Ethereum network.
- 1.Customers - participants and active users/traders of a given exchange.
- 2.Integrator - development and management staff at an exchange that evaluates the requirements and delivers the integration to the OMG Network.
- 3.OMG Network - a technical and management team within the OMG Network that supports the Integrator during the integration process.
- 1.As a customer, I can deposit ERC20 tokens (e.g. USDt) from the OMG Network compatible wallet to my exchange account.
- 2.As a customer, I can use deposited funds to make trades on a given exchange.
- 3.As a customer, I can withdraw ERC20 tokens from my exchange account into the OMG Network wallet (web or mobile).
The proposed design includes improvements to an existing exchange platform. However, there are no strict requirements one has to follow due to the distinct nature of given exchange infrastructure, development approach, UI/UX design, etc.
The scope for integrating with the OMG Network by a given exchange includes the following steps:
As an exchange, you need to be able to generate new Ethereum addresses for your customers. The OMG Network reflects the same addresses as the Ethereum network, thus you don't need to implement extra logic for your platform's wallet. If you already have Ethereum supported, you shouldn't have any issues.
Otherwise, you can create a new public/private key pair using web3.eth.accounts.create function provided by the web3 library. Note, if the keys are generated by a third-party provider such as a custodian, the integrator must be able to sign a transaction for it with EIP-712 signature via
personalSign(). See eth-sig-util for reference.
This document doesn't cover best practices for managing and storing keys due to a variety of methods different exchanges use to achieve a high level of security guarantees on their platform.
It's important to understand how to query data from the OMG Network. There are several things that might be important for any exchange:
Query network data
You can find more details about these functions using the following resources:
Depositterminology for an exchange has a different meaning from a deposit on the OMG Network. It's very important to distinguish between those two:
- 1.OMG Network deposit - represents an ETH transaction to the corresponding
Vaultsmart contract on the Ethereum network. This creates a new deposit on the OMG Network and allows the depositor to transact on the network until a user decides to withdraw them back to Ethereum.
- 2.Exchange deposit - represents a standard transaction on the OMG Network. A safe number of confirmations for a given exchange should equal to a safe number of confirmations on the Ethereum network. This is known as deposit finality period and is currently set to 10 blocks. The confirmations are counted on the Ethereum because the OMG Network relies on rootchain (Ethereum) security and creates blocks only when new transactions are being formed (i.e. on-demand).
Note, all of the code samples on the developer portal use Ropsten testnet as an example. The production version on the mainnet will have the same logic, except for the fees:
- Ropsten - uses ETH as a fee
- Mainnet - uses OMG token as a fee
You can replace the
feeobject when constructing a transaction body with the OMG contract as follows:
Withdrawals on a given exchange also represent a standard transaction on the OMG Network. Therefore, you can use the step above.
The OMG Network uses the UTXO-based model for keeping track of balances on its chain. Each transaction can have up to 4 UTXO as inputs and can create up to 4 UTXO as outputs. This means that depositing smaller amounts of funds will create UTXO of low value, and may cause potential issues during funds withdrawal due to the following:
The first two outputs are used to cover the transferred value and transaction fee change, leaving only two outputs. Considering that it's very unlikely a user will withdraw the amount that equals a single available UTXO value, there will be another change output created. This means that the total number of UTXO you can use for a single withdrawal is 2. Therefore, it's recommended to check that your hot wallet has multiple UTXO of higher value during each withdrawal from an exchange.
In general, we suggest every exchange client merge UTXO more frequently or even automate this process as a background service. Merge operations are free because they benefit the network.
Watcher is a service that guarantees data availability, secures the network, and allows to maintain the trustlessness of the OMG Network. It's recommended for every client to run a separate Watcher instance to rely on their own information source about the incoming deposits, transactions, exits, and byzantine events that happen on the OMG Network.
It also means you fully trust the OMG Network operator with everything that occurs on the network. Running your own Watcher ensures that only valid transactions and blocks are created and confirmed by the childchain operator.
After the core integration is done, you should deposit some funds to the OMG Network. This will allow customers to withdraw funds from an exchange account to the OMG Network compatible wallet.
Lastly, you need to understand how to rebalance the corresponding hot and cold wallets. You can do this by sending funds to another wallet directly or withdraw funds back to the Ethereum network first. This step is fully covered in Start a Standard Exit guide, as well as in the Web Wallet Quick Start.
- Ropsten - 86400 seconds (1 day)
- Mainnet - 604800 seconds (1 week)
Each exchange maintains a specific set of design principles, brand book, color palette, etc. Therefore, it's recommended to follow the established user flow and UX principles the users are already familiar with.
Here's an example of the integration by one of our clients: