0x Roadmap 2019 (part 3): Networked Liquidity & 0x Mesh

Introducing 0x Mesh, a peer-to-peer communication network for the 0x ecosystem

This is the third post in a series that discusses the different areas of focus for the 0x Core Team in 2019. Read part 1 and 2 to learn how 0x Mesh fits into the greater 0x stack.

Today, we’re excited to introduce 0x Mesh, a peer-to-peer network for sharing orders which will serve as an alternative to the Standard Relayer API. 0x Mesh will massively reduce the effort required to tap into the 0x networked liquidity pool and the technical work associated with maintaining a compliant endpoint. Our plans to explore the use of a distributed peer-to-peer network for propagating orders go all the way back to the original 0x white paper. Since then, we’ve picked up a great deal of knowledge around how such a network should be designed. We are excited to share what we’ve learned and what we are building.

One of the most compelling aspects of 0x protocol is its ability to facilitate networked liquidity: the seamless flow of orders through a network of interconnected marketplaces and dApps. The Radar team has described networked liquidity as a paradigm shift that transforms the term “exchange” from a noun to a verb. We agree with this assessment.



While market participants tend to meet in specific locations to facilitate more efficient markets, networked liquidity allows orders to flow outward through a growing number of web3 capillaries, reaching a broader cross-section of users. These interconnections act as a source of network effects that lead to a greater number of opportunities for market makers and better prices for end-users.



Over the past 18 months, the 0x Core Team has shipped key components needed to facilitate networked liquidity. 0x Instant allows orders to flow to a variety of surfaces including popular Ethereum wallets (MyCrypto), dApps (Augur), and blockchain explorers (Coingecko, EtherScan). 0x Launch Kit provides a simple way for developers to launch a custom digital asset marketplace in a matter of minutes. The one underlying component that all of these products have heavily relied upon is the Standard Relayer API (SRA), which provides guidelines for sharing orders between endpoints. Moving forward, 0x Mesh can connect these products and tools in a more seamless way.

The Standard Relayer API (SRA) and its challenges

The SRA is an API specification that is meant to be implemented by relayers as a way to easily share liquidity with others. It allows 0x Instant integrations and market makers to use a single client to pull liquidity from multiple relayers. In order to make this possible, every relayer must implement the same set of HTTP/WebSocket endpoints according to the SRA specification. However, since most relayers use different programming languages and server frameworks, this implementation work is largely duplicative. Whenever a new version of the SRA is released, every relayer must update their own implementation to satisfy the new interface. Additionally, plugging into every additional SRA endpoint is a manual process that each participant must do, making it harder to join the networked liquidity pool. As evidenced by the above description, this process requires a huge amount of coordination and effort. One solution to the coordination problem is for the relayers to connect to and rely on a centralized aggregator, but this eliminates the benefits of decentralization.



After conducting a study on the compliance of various SRA implementations, we found that most were inconsistent or only partially compliant with the API specification. This greatly reduces the utility of the SRA since developers cannot build clients and applications that rely on the specified behaviors described in the API specification. It turns out that it is non-trivial to implement the API to spec, and it would be preferable to have everyone use a single implementation.



When we released the first version of the SRA, it was built with fungible (ERC-20) tokens in mind. With the launch of V2, 0x has become a multi-asset protocol and the need to support multiple token types has started to test the limits of the SRA. Fitting NFTs (ERC-721) into the SRA design has already proven challenging and no one knows what the next 20 token standards added to 0x will look like, or what the best interface will be for querying them. Decoupling order sharing from order querying could alleviate these issues.

The solution: A P2P network for sharing orders

We plan to offer an alternative to the SRA in the form of a 0x Mesh node that can be run by anyone wanting to share orders. Because every node shares the same codebase, they are able to communicate without any API compliance issues, inconsistencies, or requirements to write redundant code. Additionally, the node will automatically take care of finding and connecting to peers interested in sharing orders for a particular market, removing the need for explicit coordination by participants. Lastly, the node operator can subscribe to a stream of order updates, emitting an event whenever a new order is discovered or an existing order’s status changes (filled, canceled, expired, etc…). Node operators can decide how to transform and ingest this stream of order data from their 0x Mesh node, optimizing how it can be queried for their particular use-case. This level of querying flexibility will make it easier for the 0x protocol to seamlessly incorporate new functionality, such as new token standards and AssetProxies.

How this benefits relayers

Effortlessly surface orders across the web



The largest value proposition to relayers is that 0x Mesh will help surface their orders throughout the Internet. Unlike the SRA, 0x Mesh features a push-based messaging system and a dynamic set of peers which do not need to be known ahead of time. This makes it much easier to connect to and share orders with other members of the 0x ecosystem.

This is particularly relevant for 0x Instant, where currently hosts need to manually plug in an SRA endpoint for each relayer they want to connect to. As the number of projects that utilize 0x Instant increase, it will eventually become infeasible for each host to keep track of all the SRA endpoints they want to include. With 0x Mesh, integrators can connect to a neutral platform that aggregates orders across many relayers. In the near-term, this will likely involve an “SRA Bridge” which provides an SRA endpoint on top of 0x Mesh. This means relayers won’t need to manually contact each integrator in order to reach their audiences; it will happen automatically.



Implementing & maintaining SRA becomes optional



Currently, the only way to share orders with and receive orders from other relayers is to implement the SRA. 0x Mesh will provide an additional way to contribute that does not involve implementing and maintaining a standard interface. Simply spin up a Docker container, and you can already submit orders to the network and listen for new orders. Relayers which use 0x Mesh will no longer need to worry about listening for order-related events on the Ethereum blockchain. Under the hood, each 0x Mesh node will use OrderWatcher to validate orders and remove any invalid ones.



Become a valuable access point into the network



A third, more subtle benefit stems from how the 0x Mesh will be implemented. Each node in the network will score its neighbors based on the quantity and quality (validity, novelty, etc.) of the orders it shares. Since relayers provide a single-access point into the network for their users, they will naturally move towards the core of the network graph, and as a result, will be able to offer a better trading experience. More concretely, their users will find out about orders before others, and will also have their orders more rapidly discovered than those of peripheral nodes. This advantage is especially pronounced in highly liquid markets.

Towards a Unified network transport layer

0x protocol consists of an order schema — which describes how order information is arranged into a packet — and a canonical system of Ethereum contracts which consume and process these orders. However, there are two important aspects that don’t fall into the scope of 0x protocol: (1) the network transport layer, i.e., where orders are communicated and (2) the message passing semantics, which describe how market participants coordinate trades (i.e. relayer models). While we still believe that 0x protocol should be agnostic to the network transport layer, 0x Mesh could greatly reduce friction and allow liquidity to find its way to different surfaces. Eventually, we plan to extend 0x Mesh to support any arbitrary DeFi protocol which uses off-chain messages.

A Browser-friendly node

We have already mentioned that 0x Mesh can be run as a Docker container, and we expect that this is how most people will interact with the network, especially in the near-term. In this model, relayers run their own backend services for connecting to 0x Mesh, maintaining a consistent view of the order book, and ultimately serving a UI to their users. The traditional relayer model comes with a lot of benefits and we believe it will continue to be the best solution for highly-liquid and well-established markets.

Instead of a Docker container, 0x Mesh can also run directly in a browser. This introduces the possibility of a new type of “serverless relayer” which only requires a front-end UI and doesn’t require any backend services. In this model, each user independently maintains their own order book and shares orders directly with other peers in the 0x Mesh network. The code could even be stored in a decentralized way (e.g. on IPFS) and accessed via a dApp browser. This will allow for frictionless market formation for the long-tail of assets that are not or cannot be serviced by relayers.

As exciting as this possibility is, the serverless relayer model comes with some downsides and is not appropriate for all markets. The first time users interact with a serverless relayer, they will experience a “warm-up delay” while the underlying 0x Mesh node finds peers to connect to and gathers orders. In addition, highly liquid markets could place a significant strain on a user’s internet bandwidth and storage space. Such markets also increase the likelihood of accidental order collisions (when two people try to fill an order at the same time). For these reasons, there is absolutely still a place in the ecosystem for traditional relayers. We expect that once a market matures to a certain level of liquidity, traditional relayers will step in to provide a more reliable experience and expose the market to a larger demographic of users.

Technical Details and Timeline

We are planning to launch a beta version of 0x Mesh with a handful of early participants near the end of Q2 2019. The 0x Mesh beta will be written in Go and will be compiled to WebAssembly when run in the browser. It will use WebRTC as a first-class protocol for inter-node communication (both browser and non-browser based nodes) and will rely on signaling servers to bootstrap connections between peers. We have developed a novel order eviction algorithm that precludes the need for explicit staking while preventing malicious nodes from filling up the available space on other nodes and evicting the orders of benign users. We will be releasing a comprehensive technical specification with descriptions and justifications for all our design choices in a forum post soon, so stay tuned!