IDEX has been the most successful DEX and DApp to date, with over 300k users executing five million trades worth over $2 billion. However, this success comes at a cost—in particular, the cost of using the Ethereum network. IDEX users have paid over $6 million in ETH gas fees, and the IDEX contract has grown to become the largest on the entire network. It’s time for this to change!

O2 Rollup to the Rescue

IDEX 1.0 introduced the hybrid DEX by combining an on-chain deposit contract with a single authorized submitter address. This design enables the escrow of funds and coordination of trade settlement necessary to support instant, off-chain execution. The remaining drawbacks derive primarily from the fact that each trade is settled to the network one at a time. In order to scale beyond the current limitations of blockchain networks, we need a more efficient method of trade settlement.

Optimized Optimistic Rollup (O2 Rollup) is a novel, open-source layer-2 design for bringing scalable applications to public blockchains. It builds on IDEX’s current hybrid design to allow for unlimited off-chain scaling with a fixed on-chain settlement cost, removing bottlenecks and costs that have inhibited DEX adoption to date.

What’s So Expensive About Settlement?

The Ethereum network, like all other blockchains, charges participants a fee for use of the resources of the network. On Ethereum, different actions (contract functions) are priced in gas, and the price is dependent on the complexity of the function. Functions require the entire network to process and store any outputs forever; the more resources required, the more expensive it will be.

In the case of the IDEX contract, cost is driven by the need to process trade inputs and update and store user balances. The goal of any IDEX scaling solution is to reduce the frequency of these expensive transactions such that fewer resources are required to process trades and settle funds from one user to another.

Off-Chain Balances and Batch Settlement via Merkle Roots

A Merkle tree is a well-known data structure that can be used to “shrink” a data set of arbitrary size into a unique, short set of characters. The individual data elements, or leaves of the tree, are hashed together in pairs to create outputs of fixed length. This pairing and hashing process continues until what remains is one single 32-byte string (the Merkle root) that represents the cumulative hashing of all data elements. Any change to any of the underlying data elements will produce an entirely different Merkle root output.

IDEX 2.0 combines the hybrid design of IDEX 1.0 with Merkle roots to support batch settlement of trades and drastically reduce gas costs. The first critical change is the removal of balances from the on-chain contract; recall that balance updates are one of the most expensive parts of processing trades. The core contract becomes responsible solely for escrowing funds, while the actual account and balance information is stored off-chain in a public, layer-2 ledger maintained by IDEX and cryptographically guaranteed to be available to the public.

Just like IDEX 1.0, all changes to this ledger, such as trades or withdrawals, require a private key signature from the account holder. However, instead of settling each of these changes individually to the Ethereum network, they are settled in batches. Every few minutes, all of the previous transactions, known as an O2 block, are hashed together into a Merkle root, the fixed-length data structure. It is this Merkle root that is submitted to the network and stored for public validation.