0x, The Ocean, and the High Performance Funnel

The 0x Project is building a protocol for decentralized exchange of ERC20 tokens. They’ve got a ton of community support, launched their own ZRX token with great success, and now companies like ours, The Ocean, are building liquidity pools and relayers. The ecosystem is growing.

The 0x protocol is designed for off-chain order books, and there some areas in the flow that we think could be improved with a novel approach, inspired by conversations with the 0x core dev team, that we call ‘high performance funnel’ (HPF). We have built HPF into The Ocean and it will premier with our public beta in the next few weeks or so (API draft available now).

A high performance funnel approach solves two problems:

  1. When someone wants to take an order that’s posted in an order book, there is a delay between the moment they declare that intent and the time when the order is settled on the blockchain. The HPF allows The Ocean to keep the order book up to date during this period thereby avoiding orders being taken by multiple users. By closing this gap, a funnel also prevents collisions, where takers pay wasted gas to fill an order that’s not actually available.
  2. Takers don’t have to interact with smart contracts on the blockchain, they only need to sign the order and they are good to go.

How The High Performance Funnel Works

The high performance funnel model for a 0x order means that every order submitted to our order book will indicate the Funnel Address as the taker for that order.

First, a trader submits a ‘target order’ which is like a limit order in the traditional sense. You specify the price and amount you want to trade.

Next, someone else sees that order and decides they want to take you up on your offer. They submit a ‘matching order’, which is like a traditional market order in that it takes existing orders.

Finally, the funnel address, which is specified as the taker on both of these orders, brings them both to the blockchain to be atomically filled. The funnel address never holds any tokens and the two trading parties are provided only the trades that they specified in their orders.

Here’s a breakdown of the flow:

  1. Maker creates signed TARGET ORDER with the Funnel Address as the taker and with zero fees.
  2. TARGET ORDER is submitted to The Ocean and put into the Order Book.
  3. Matcher requests the order book and finds the TARGET ORDER.
  4. Matcher creates MATCHING ORDER with the Funnel Address as the taker. The ‘price’ of the order must match that of the TARGET ORDER and the amount must be less than or equal to it.
  5. Matcher submits the MATCHING ORDER along with a reference to the TARGET ORDER. If they are the first to submit a valid order, then The Pcean will batch fill and will remove the TARGET ORDER from the Order Book (so that new matchers don’t see an order that’s already being filled).
  6. TARGET ORDER and MATCHING ORDER are coupled into a single, atomic Ethereum transaction.
  7. The transaction is submitted to the blockchain, settled, and the tokens are successfully exchanged.

Benefits of the High Performance Funnel

  • Order book maintenance: 0x is a protocol for orders and therefore is not in charge of maintaining order books. This is what relayers do, as laid out in the 0x whitepaper. It’s up to relayers to insure that their books aren’t cluttered with orders that have been filled or canceled and this can be difficult considering that an order won’t be really filled until it’s confirmed on the blockchain. By acting as a funnel, we can know exactly what orders are filled, pending and canceled at any given time so our order books will be fresh and clean.
  • Takers stay off the block chain so they don’t have to deal with interacting with smart contracts. Our client libraries will provide the functionality to create and transmit the orders you need based on what you want to pay. Just sign the json and you’re good to go.
  • We got your gas. Since The Ocean is maintaining the funnel address, we’ll be paying the gas for the transactions so you don’t have to factor that into your trading calculations. It’s built right into your fees, so you will know your total cost upfront.
  • Collision protection. Nobody wants to take an order to the block chain and pay the gas for it only to find out that it’s already been filled. With a HPF, you will be sure that this doesn’t happen because a) you aren’t paying gas and b) we won’t double match any of the orders.

Savvy readers may already be wondering about a few potential implications of this approach, but don’t worry:

  • We aren’t taking double fees. We don’t think you’re stupid. The Ocean will be at the razor’s edge of competitive fees.
  • It’s still trustless. All of the benefits of 0x, Ethereum, blockchain and trustlessness are still in place. Whether you’re placing a target order or a matching order, you’re still placing a 0x order and you never have to worry about centralized entities being hacked or going down.
  • Multiple filling. Want to buy a lot of stuff? You can submit as many matching orders as you want and we’ll batch them all together with the target orders.
  • Partial filling. Only want to trade a little? No problem. Not only can you submit a matching order for part of a target order, but we’ll make sure that the order in our book is immediately updated to reflect that so that the rest of it can be filled without interfering with your trade.

Our HPF implementation will dramatically improve the performance and usability of our API and liquidity pool. Our goals at The Ocean are to offer outstanding performance, easy integrations, very low fees, and deep liquidity. The high performance funnel is a vital component of making that possible.

__________________________

Follow us on Twitter at @TheOceanTrade or subscribe to our newsletter to stay in the loop.

Like what you read? Give The Ocean a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.