Kyber Network <> Melon

Melon funds can now trade on Kyber as integration between Melon and Kyber network is complete.

Hello from the Melon dev team. In the past couple of weeks, we have been working closely with Kyber Network to integrate their on-chain liquidity protocol with the Melon protocol. This blog post describes the results of the work.

Before getting into the details, let me give you a brief overview of our general exchange integration process. Given our modular architecture, it is relatively simple to integrate a new exchange with our protocol through an exchange adapter. An exchange adapter is basically a smart contract that acts as a bridge between the Melon fund and the exchange. It handles the logic for making and taking of orders while maintaining the integrity of the fund. This is the smart contract interface it follows. For a new exchange type to be integrated, an adapter contract following the interface should be written containing the code for logic for handling orders.

Currently Melon funds can trade on OasisDex and 0x (Radar Relay and ERCDex orderbooks shown in the UI). You can check out our OasisDex adapter and 0x adapter. We are open for more integrations in the future.

Constructing a DEX from Kyber

Kyber can be seen as an on-chain liquidity provider and integrating it with Melon will allow fund managers to leverage the liquidity provided by Kyber. Melon funds can now trade and tap directly into the Kyber liquidity pool! You can see the adapter contract that we wrote for our funds’ interaction with Kyber here.

Kyber is a little bit special in the sense that unlike other exchanges there is no concept of an orderbook. Rather it offers almost guaranteed liquidity pools (by allowing anyone to act as reserve operators to provide liquidity to integrated applications) that the managers can super conveniently tap into when managing their portfolio.

Swapping assets can be done in a single click. On Kyber, all you need to choose is the asset you want to trade, the amount of that asset you wish to trade and the max price you are willing to pay for that. On Melon, the execution is also conditional on passing the risk management profile of the fund.

From a UX perspective, we decided to derive an artificial orderbook from the prices retrieved on Kyber. We then integrated that orderbook into our exchange aggregator, and you can now consult an aggregated orderbook of Radar Relay / ERCDex / OasisDex / Kyber. How cool is that?

Kyber as a pricefeed

Since there is not enough liquidity on decentralized exchanges, it is impractical at the moment to use them as a reliable price source. Our existing canonical pricefeed mechanism calculates the median of prices from multiple on-chain pricefeed operators to be more robust from outliers, errors and manipulation. Yet, it is not nearly as robust as it needs to be.

Meanwhile in the process of integrating Kyber as a liquidity provider, we explored the interesting possibility of using it as a price source. Given our comprehensive research on pricefeeds and given the scope of our project, the value proposition of using Kyber prices is very appealing. We retrieved the historical prices for a dozen of asset pairs over a few months, and compared them with the prices provided by centralized exchanges. The results were quite impressive; globally Kyber prices don’t deviate more than 1.5% from the prices on centralized exchanges. If you’d like to check it out yourself, head over to this Github repository.

It may sound counter-intuitive at first, given that the prices in Kyber are pushed by reserve managers. Same like any other oracles with centralized point of failure, right? Wrong.

Firstly, Kyber Network is a congregation of several reserves. The price given by the network is algorithmically guaranteed to be the best price among all the existing reserves. Secondly, there is a game theoretic approach to it. If the price returned from the network is significantly lower than the market price, arbitragers can capitalize on the difference and drain the reserve. This would highly incentivize reserve managers to act right. Lastly, reserve managers are whitelisted by Kyber, which means they are known entities and therefore have a reputation risk. In the future, Kyber is planning to make the protocol permissionless, i.e. anyone can serve as a reserve (in parallel with the whitelisted ones). It is worth noting here that Kyber plans to make their protocol permissionless, meaning that eventually anyone will be able to serve as reserve (in parallel with the whitelisted one). When that happens, we will evaluate again the risk implied and how to mitigate it.

We also have additional checks like maximum spread value to prevent one-sided price manipulation.