An Inevitability in Token Exchanges — Ring Trade-based Systems (Loopring, Cowswap)

Intel Chen
7 min readNov 22, 2021

--

Token Trading, DEX aggregators, Ring Trade, AMM, Order Book, NP-hard Computing

TL;DR

  1. Ring Trade makes trading tokens in the long-tail more viable than ever.
  2. The computational challenge brought by the global optimization problem can be safely conducted off-chain, given the Zero-Knowledge Proof technology is robust.

What is Token Trading / Swapping

Tokens are items whose ownership is represented on-chain (typically the Ethereum blockchain). Their value can be arbitrarily defined using associated Smart Contracts. Commonly, tokens are used to represent currency (e.g., DAI, USDC), other assets (e.g., LP tokens, NFTs), voting rights/membership (e.g., DAOs), etc.

Note that some depicted “tokens” are considered “coins.”

The question of WHY does people trade is trivial. As long as one person wants something somebody else owns, trade is inevitable. While most trades in the traditional context use some standard unit of value with high liquidity(aka money) to facilitate trade, things are slightly different in the crypto world.

Illustration from NYT

While the early implementation (e.g., Uniswap v1) of token trading does involve coins (ETH, in the context of Ethereum), people quickly realized that direct exchange of equal value tokens is more efficient, given that transactions have associated gas cost and most tokens are naturally fractionize-able. To put this in a real-world context, imagine you want some of your friend’s rice while your friend wants some of your corn kernels. Rather than selling 20 dollars of your corn to a third party, buy the rice with 20 dollars, and then sell 20 dollars with of rice to your friend in exchange for then 20 dollars, you can simply decide the portion of rice and corn that are equal value, and make a swap of items. Voila, welcome to the world of coin swapping.

Illustration of the inefficiency of indirect trading

The biggest question surrounding swapping, or trading of tokens, in general, is liquidity. In a trading model where money (coins) is involved, the exchange of n item types requires n pairs of liquidity (ItemX — money) to be maintained. However, if the direct exchange of tokens is required, then n(n-1)/2 =O(n²) pairs of liquidity must be maintained. The question is, how do you optimize for the liquidity of all trading pairs?

Swapping requires more trading pairs.

AMM and Order Book are two primary ways crypto exchanges facilitate the trading of tokens between individuals, each with its unique challenges. Order Books are prone to front-runners and require significant liquidity for a cold start. Additionally, it can only keep its spread low for highly liquid tokens. On the other hand, AMMs have low capital efficiency, and it’s on-chain presence dictates the expensive gas fee required to interact with its liquidity.

Borrowing illustration from an inbound marketing piece

More fundamentally, either model performs poorly when it comes to the tokens in the statistical long-tail in trading volumes. There is simply no one providing liquidity for them (through trades or Liquidity Pool)

Data on of Sep 2020 - Look at the significant dropoff after the first two. Insane heterogeneity.

Ring Trade as A Solution for Low-Liquidity Tokens

A Ring Trade protocol is essentially an Order Book with multiple token types. However, rather than a 1-D matching based on price with a simple exchange of matching tokens (buy A sell B, buy B sell A), a Ring Trade protocol finds a set of orders such that, in aggregate, the tokens demand matches the tokens supply while satisfying additional order constraints (e.g., exchange rate). Since each order essentially provides liquidity for more than one token pair, liquidity is no longer siloed in their own pair but shared (albeit unevenly), which meaningfully improves low liquidity tokens.

Loopring Whitepaper

In many ways, Ring Trade takes a similar approach to DEX aggregators. Both systems relax the constraint of a direct swap using either AMMs or Order Books. Instead, they take a graph-based approach to optimize for the shortest path between the two tokens in order. DEX aggregators use existing trading pairs and their liquidity in DEXs as edges in their graph; this means that their edges are confined to what’s offered by DEXs with the implied sub-optimal edge weights (due to siloed liquidity). On the other hand, Ring Trade holistically considers the liquidity it has from trades (and other liquidity sources as a fallback)

An important distinction between Ring Trade and AMMs is the treatment of P2P trade. Going back to our rice and corn example above, the most efficient trading is always the direct trade between the buyer and seller. However, for AMMs, the shortcut case of the direct (P2P) exchange is ignored. Even if the buyer and seller could have been matched in terms of the exchange rate, it takes two full access to the liquidity pool to process the exchange, incurring high gas costs along the way. Ring trade would have detected the possibility of direct P2P trade and settled the transaction with minimal on-chain work.

Cowswap Internally matches first, then uses AMM as a fallback. AMM does not match orders directly.

The benefit of Ring Trade comes at the cost of computation (infeasible on-chain); additionally, the same cold start problem applies as the traditional Order Book model.

Much like TSP, ring optimization is likely an NP-hard problem.

A Case Study: Cowswap vs. Loopring

Both Cowswap (GPv2) and Loopring believe that facilitating P2P (matched through Ring Trade) is preferred for order-matching. However, to guarantee the user experience, both provide some AMMs as a fallback mechanism.

Loopring vs. Cowswap protocol design

At a high level, both protocols

  1. submit orders (the token types and a limit price)
Loopring trading Interface

2. orders are collected, and a decentralized network of computing providers compete to submit order rings

a. Cowswap collects orders on the mainnet through messages over a batch time of 5 minutes and collects solutions from off-chain providers (Solvers) where a significantly better solution can replace an earlier submitted solution

b. Loopring collects and mines solutions continuously in a “Consortium Liquidity Sharing Blockchain” where each node is a “Relayer” that relays and aggregates orders. Some of the nodes are also “Ring-Miners” and continuously compute solutions. Miners have an incentive to generate better solutions.

3. Orders not mined are executed through AMM

a. CS uses DEX and DEX aggregators. LR uses its own AMM on layer 2

4. Rings are validated and settled on-chain

Cowswap Settlement contract

a. CS validates and settles on the mainnet. LR validates and settles on ZK layer 2.

Both implementations share some notable benefits: single clearing price for each ring/batch (no slippage), separation of pricing and execution/settlement, individual orders are front-running-proof, low mainnet gas fee, decentralization.

Each protocol has its own bells and whistles. A few that stand out are: CS — no direct gas costs; LR — patented front-running prevention through Dual Authoring.

However, there is a significant difference between the two protocols.

— To Layer 2 Or Not to Layer 2

Here’s a gross over-simplification — Loopring is a Layer 2 Cowswap. Then the question at hand is whether the security compromises introduced by Layer 2 are worth the performance gains.

Finematics has a great video on this (link)

I believe that yes, absolutely. The future of blockchain will be a continuum of the gradient between the perfect security and the perfect performance. Protocols like Loopring utilize 3 different points on the continuum for their consensus layer, order-matching layer, and ring-generation layer with decreasing security (and decentralization) and increasing performance. Such a system is truly pushing the boundary of what is possible and taking well-informed risks to optimize the performance and experience of its offering, in contrast to a blind obsession with ultimate security and decentralization.

Summary

In summary, Ring Trade-based DEX solutions introduce a meaningful upgrade to traditional Order Books and AMMs by sacrificing computation but improving efficiency and MEV resistance. By putting a Ring Trade DEX onto a ZK layer 2 and offloading computation to off-chain, Loopring further pushes the performance of the system while managing the security of the overall solution.

For the next steps, one needs to closely examine the zkRollup implementation to ensure that the security guarantee works as intended. It’s great news to hear that Loopring has been in collaboration with StarkWare (recently reaching $2B with a $50M C round led by Sequoia) developing ZK technologies, including dAMM, a solution for liquidity sharing between layers.

--

--