Intro & Motivation

Ping Pong is a fully on-chain DEX enabling instant trade execution, limit orders while being resistant to front running.

Motivation

On-chain decentralized exchanges are a problem that ist yet to be solved well. The following is a brief overview of existing solutions:

On-chain orderbook The most straight-forward/simple solution to on-chain trading is simply deploying an OTC market/order-book on chain. It's main problem is that due to the flexibility in orders and lack of efficient on chain matching orders need to be often taken in steps. Leading to widely varying gas costs and often requiring multiple transactions or risking a bloated single tx with a batching tool . These trade-offs lead to low liquidity/usage.

Hybrid Exchanges An alternative approach is to use a hybrid of off-chain order-book and on chain settlement. Relying on centralized orderbook managers who can potentially trade against/censor their customers. as well as. The off-chain orderbook also makes smart contracts second class citizens when it come to executing trades. In addition practical implementations of this approach have shown trouble with attracting liquidity and high rate of order cancelation.

Automated Market Maker A blockchain unique approach is using an automated market maker. These exchanges throw away the old fashioned order book and maintain reserves provided by incentivized liquidity providers. They enable trades based on a certain algorithmic formula. A simple and well made AMM is deployed by Uniswap where it follows x×y=kx \times y = k formula. Providing pricing by making sure that the reserve of on asset (x) times the reserve of the other asset (y) always equals k . Two major of issues that an AMM like this has are:

1. They are susceptible to front-running attacks. The exchange model, attacks and a potential solution are presented here. However this proposal might hurt non-malicious traders by:

  • Imposing an artificially high rate

  • Increase gas costs

2. Price slippage makes it inefficient to perform large trades on the exchange.

3. There is no native support for limit orders.

Dutch Auction Exchange Dutch auction based exchanges, like their name suggests employ an auctioning mechanism where they auction a batch of tokens for a period of time. They provide good pricing sources that are resistant to front running but do so at the cost of very slow trades (taking around 6 hours).

Can we build a better exchange? One that easily aggregates liquidity and enables instant, gas efficient trading while being resistant to frontrunning and censorship?

Introducing Ping Pong DEX

Let's consider a fixed price order book where ETH is traded against TOKEN. In this order book prices are pre-fixed and are pre-set at S percent intervals. Meaning that starting from a 1:1 ratio the formula for the nth price of TOKEN to ETH is: Pn=(1+S)nP_n = (1 + S)^n

This construct allows us to aggregate liquidity around relatively large steps. This lowers gas costs for on-chain iteration and price checking, allowing for dApps to efficiently use the order book. This spread results in worse prices for lower volume orders which pay the premium for high liquidity, without needing it.

Combining this order model with an automated market maker gives an interesting solution. Any time the price of the market-maker DEX hits one of the limit order walls it starts buying from it, either filling it completely and passing it or bouncing back (like ping pong between two walls).

We now get:

  1. Full price range

  2. Resistance to front running (since purchased assets can't be instantly refunded)

  3. Limit orders

Why is it going to work? Incentive alignment.

Incentive Structure

First let's map out the 3 types of actors we have in an exchange as described above:

  • AMM liquidity providers - who put liquidity in the form of both ETH and a Token.

  • Orderbook market makers - who fill the buy and sell limit orders of the order book

  • Traders - who perform swaps either based on a formula from an AMM or based on the orderbook

The exchange then provides adequate incentives for each of the actors:

  • The liquidity providers collect a fee from the traders that grows the overall amount of value they will receive when they pull out of the exchange (could be in either token).

  • The market makers, in exchange for commiting liquidity in advance are not paying the AMM fee for their trades.

  • The traders are getting not only frontrunning resistance (since it's impossible to buy back trades done in the orderbook) but also better prices (because the orderbook slows down the price change of the AMM)

Last updated