DEX on Matic Network with 0x

By Anurag Arjun

An important use case for Matic Network will be transactions on decentralized exchanges — that will be enabled in a future release of Matic. Here is how Matic Network will work with the 0x protocol to enable instant, decentralized and low-cost trades.

Decentralized exchanges

Decentralized exchanges are the next important progression from the current centralized system of exchanges. Key reasons are the following:

  • No central party which can be hacked (Mt. Gox, Bitfinex, etc.)
  • No custodian for customer funds
  • No central party which a government could potentially target
  • User controls her own security

In spite of the huge benefits, however, there are usability problems with decentralized exchanges today.

As referenced in this article,

“The primary downsides to many existing decentralized exchanges are that they are illiquid, slow, expensive, and inoperable with one another. For those operating order books on the blockchain, every new order or adjustment to an order goes through the blockchain. This means that they rely entirely on block times and incur network transaction fees for every single transaction.”

Source: A beginner’s guide to 0x

According to the 0x whitepaper, 0x is “an open protocol for decentralized exchange on the Ethereum blockchain.” 0x is creating a protocol using Ethereum smart contracts for anyone in the world to operate a decentralized exchange.

0x tries to solve for these inefficiencies by creating a standard protocol of orders being relayed off of the blockchain and only having them brought back onto the blockchain when the order needs to be settled.

Problems

While the 0x protocol is a fantastic solution to the problems faced by existing decentralized exchanges, it still has to contend with scalability issues faced by the Ethereum blockchain overall. Even though the orders are relayed off-chain, the settlement transaction still needs to be on the Ethereum blockchain, which can take time and/or high transaction fees.

Here’s where Matic Network comes in.

Matic Network

As mentioned in our previous article, Matic Network is a scaling solution for Ethereum, and we support token transfers to start with. It strives to solve the scalability and usability issues while not compromising on decentralization and leveraging the existing Ethereum developer community and ecosystem. Matic Network leverages an adapted version of Plasma to provide scalability and superior user experience to DApps/user functionalities built on top of Ethereum.

Current 0x workflow

Here is the 0x order and trade workflow from their whitepaper for reference:

Figure: Off-chain order relay, on-chain settlement diagram.

The current workflow steps are as follows:

  1. Maker approves the decentralized exchange (DEX) contract to access their balance of Token A.
  2. Maker creates an order to exchange Token A for Token B, specifying the desired exchange rate, expiration time (beyond which the order cannot be filled), and signs the order with their private key.
  3. Maker broadcasts the order over any arbitrary communication medium (most probably, a Relayer — see https://0xproject.com/wiki#List-of-Projects-Using-0x-Protocol)
  4. Taker discovers the order and decides that they would like to fill it.
  5. Taker approves the DEX contract to access their balance of Token B.
  6. Taker submits the makers signed the order to the DEX contract.
  7. The DEX contract authenticates makers signature, verifies that the order has not expired, verifies that the order has not already been filled, then transfers tokens between the two parties at the specified exchange rate.

0x and Matic Network

Let’s see how 0x protocol will work on Matic Network -

Figure: 0x workflow with Matic Network integration

The workflow will be as follows:

  1. Both Maker and Taker deposits funds on the Matic network. Both users can now transfer tokens to anyone they want instantly with negligible fees(see link for more details). The next steps are exactly similar to the current 0x workflow given above — from the Relayer perspective, only the network and contract address details will change. From an end user perspective, there is no change at all. Even Step 1 can be abstracted away for the end user by a smart user interface on the Relayer side.
  2. Maker approves the decentralized exchange (DEX) contract to access their balance of Token A on the Matic chain.
  3. Maker creates an order to exchange Token A for Token B, specifying the desired exchange rate, expiration time (beyond which the order cannot be filled), and signs the order with their private key.
  4. Maker broadcasts the order over any arbitrary communication medium.
  5. Taker discovers the order and decides that they would like to fill it.
  6. Taker approves the DEX contract to access their balance of Token B on the Matic chain.
  7. Taker submits the makers signed the order to the DEX contract.
  8. The DEX contract authenticates makers signature, verifies that the order has not expired, verifies that the order has not already been filled, then transfers tokens via Matic between the two parties at the specified exchange rate.

Steps 2–8 can be repeated for as many trades as needed without any extra steps. All trades on the Matic Network will occur instantly and have significantly low transaction fees.

9. Once a user is ready, they can withdraw remaining tokens to the main chain by establishing proof of remaining tokens on Root contract (contract deployed on Ethereum chain).

Summary

Introducing Matic Network into the workflow, makes sense right out of the box. To borrow an analogy from the “centralized” world, users can deposit their funds, and conduct trades instantly and with lower transaction fees. However, instead of a typical stockbroker, a user has full control of funds, and can withdraw them back as and when needed. We ensure that the workflow is secure, without compromising on the 0x usability vision. Nothing changes from the user perspective — we will explain the UI part in a later post, which will abstract the interaction between 0x and Matic.

Let us know what you think.

We will keep updating this article as needed. Stay tuned.

Stay in touch with us by following us on Twitter. If you have any questions, feedback, feature requests or need help, please contact us on Telegram: https://t.me/maticnetwork

More from the Polygon Blog
EY and Polygon to co-develop Ethereum scaling solutions for enterprises and launch Polygon Nightfall - a privacy-focused Rollup

14th September - EY, a global professional services and technology firm, is collaborating with Polygon on building and implementing scaling and enterprise solutions for the Ethereum ecosystem. As part of this collaboration, EY and Polygon will work on Polygon Nightfall, a public, privacy-focused Rollup. In addition to this, EY will offer its other flagship blockchain […]

Read More
Polygon: First Scaling Solution for Coinbase

The Protocol team was recently established at Coinbase to work on scaling Ethereum through integration with L2 and other ETH scaling solutions. The Coinbase team plans to integrate Polygon PoS as their first scaling solution for Coinbase. The Coinbase Protocol team is an experienced group of engineers at Coinbase focused on contributing to scaling blockchains and […]

Read More
Hermez Network is Joining Polygon and Becoming Polygon Hermez via the First Full-Blown Merger of Two Blockchain Networks

We are proud and excited to announce that Hermez, one of the most prominent zero-knowledge (ZK) cryptography-based scaling projects and teams, will be joining Polygon. Starting today, we will initiate the process of merging Hermez into the Polygon ecosystem, where it will be operating under the new name: Polygon Hermez. Polygon Hermez will become a part of […]

Read More
Polygon Bug Bounty Program Is Live On Immunefi!

Polygon’s bug bounty program on Immunefi, DeFi's leading bug bounty platform, is now live with a maximum bounty of $2,000,000. If you are a security researcher looking to venture out into the blockchain space, this is your chance to understand how things function. This bug bounty program is focused on smart contracts with an essential […]

Read More
Meet Polygon Team At Messari Mainnet!

Polygon team members will be speaking at Messari Mainnet in New York City on September 21-22. We also have a booth at the conference, so come meet us and learn about Polygon! Here are some of the talks you can’t miss: On September 21, at 2:20 pm, Dean Thomas, Head of Institutional Capital, will speak […]

Read More
What do you prefer - Maximum Security or Cheaper Transactions?

The Ethereum scaling solutions space has been heating up lately. Which is a good thing, because Ethereum (and its community) needs scaling as soon as possible. As you know, Polygon's mission is to develop various kinds of Ethereum scaling solutions, from sidechains to rollups (and more). But all these solutions come with trade-offs. There's no […]

Read More
crossmenuchevron-down-circle