Building Derivatives on StarkNet

ZKX
9 min readSep 24, 2022

--

AMA Recap — 26th August 2022

Last month, we did an AMA with rhinofi’s co-founder Ross and our Founder & CEO Eduard. We talked about all things ZKX and how we are different from our competitors.

An overview of our conversation is below:

So, grab that popcorn and read on. Lots of alpha to uncover 😉

Ross | rhino.fi: Could you please introduce yourself and also give an overview of what ZKX is?

Eduard | ZKX: I’m Eduard, founder of ZKX, a derivatives protocol on StarkNet. Together with my co-founders, Naman and Vitaly, we’re making perpetual swaps more accessible and building a novel architecture that will be able to scale and let DeFi compete at the same level as the great centralized exchanges that we all know of.

Ross | rhino.fi: What is the problem that you’re solving that is not solved by the current derivatives protocols?

Eduard | ZKX: So, all three of us had a background, working in emerging markets. There we observed problems with existing DeFi infrastructure — costly gas fees and complex user experience. We, being traders at heart, saw the rise of Wall Street bets, and realized that a huge segment of users across these emerging markets was missing out on these opportunities because they didn’t have an easy way to onboard. These are usually millennials and Gen Z, who are very eager to take risks to invest to spend their time everyday trading and uncovering alpha.

We found that most of the exchanges in crypto are fairly centralized. Even the ones that are currently within DeFi don’t have ways through which the traders can own the protocol and drive the decision-making within the exchange itself like what kind of assets are going to be listed, or what kind of features are going to be part of the exchange. So, we’re trying to build a community-driven DeFi exchange for derivatives.

But very early on we realized that there were technical barriers to making that happen.

  1. There is a huge dependency on oracles. You have certain exchanges like GMX, that are highly dependent on Chainlink and other oracles. And as we know, most of these oracles are still fairly centralized. You are dependent on the teams that are running these oracles.
  2. The second is that there wasn’t any open mechanism to lease new assets and offer incentives for people to provide liquidity to trade these assets. Rather, most listing processes within these derivatives exchanges are closed. So you never really actually know what it is that the community wants to trade. But if you look at centralized exchanges, like FTX, or Binance, they do try to check the pulse of the community.
  3. The last one was the factor of scalability, which is how you expand your solution in a way that your fee structure and your gas costs are negligible.

To solve that we opted for StarkNet and ZK Rollup. We decided that this will be the best future-proof solution to bring an exchange that’s both open, as well as scalable in the future. To give you some context, exchanges like dYdX do 300 TPS and Binance does 1 million+ TPS on average. So the difference is staggering on how little a decentralized infrastructure can scale at the moment. So for us technically, we had the challenge of designing an architecture that could scale to the same level as a centralized exchange. The first step was to move to the ZK Rollup infrastructure. And the second step was to move towards our decentralized node network that provides computation to the exchange and the smart contracts. So effectively, we can say we have a truly decentralized order book. And in the future, everyone will be able to run nodes as well for that.

Ross | rhino.fi: Could you explain more about your Order Book model?

Eduard | ZKX: Let’s talk about the three basic models for derivatives in crypto:

  1. virtual AMM: A Uniswap like AMM model, where you have a pool with two tokens. The vAMM creates a virtual token representing the swap of the actual virtual asset versus the other token, which is the collateral, which is usually a stablecoin. This model is efficient for smaller trades but is not highly suitable for high-frequency trading because it’s more expensive to trade on.
  2. Synthetix Model: Here you have synthetic positions on mutual assets. Those positions are tracked through an Oracle price, and you’re trading against a pool of collateral that absorbs the losses or gains within the overall protocol. You have some protocols built on Synthetix, and they use this model. This model is efficient to a certain extent, but it also socializes the losses towards the LPs, providing liquidity for the protocol.
  3. Centralized order book: It has been implemented in platforms like dYdX and other exchanges. You depend on market makers to provide liquidity and depth of market so everyone can trade comfortably as much as they want. But as the word says, these are centralized order books, which means it’s just the server running on AWS or Google Cloud. It doesn’t offer any capacity to be decentralized or censorship resistant. Moreover, we realize that it offers certain limitations on how much you can scale.

So for us, the challenge was creating this order book in a decentralized and scalable way. To solve these, we created our own node network, where a series of nodes interact with each other with their consensus algorithm and can do decentralized matching of the orders. In the future, anyone can install the node, run it independently, and provide services to the exchange. As much computation and processing, they’re doing, they will receive part of the liquidation and trading fees.

Ross | rhino.fi: What’s the security model behind your node network?

Eduard | ZKX: Our node network has multiple layers of consensus. A node can have three roles:

  1. Worker node
  2. Dispatcher node
  3. Consensus node

Randomly at each round, the node will get a role that you cannot know in advance. Therefore it is difficult for the node to know if they’re going to be taking orders from the smart contracts or if they are going to be verifying those orders as a consensus node, or if they are going to be doing the order matching as a worker node.

There is the other layer of consensus which incentivizes the nodes that are the fastest at matching an order when it comes and it’s verified by the dispatcher nodes. Here’s how it’ll work:

  • Someone sends an order to the node network
  • Then the dispatcher node lets the entire network know that there’s a new order coming in so that the network can go and match it
  • After that, the nodes that are the fastest in matching those orders and are going to be able to be included as part of the compensation and payment for that particular trade, or liquidation

A key aspect here is that the network doesn’t take any ownership of the funds. The funds are under the control of the user. They’re sitting on L1 and L2. So in no way, the network can’t take control of the funds, because there’s no way for them to do it.

Ross | rhino.fi: How are you using Oracles to interpret data?

Eduard | ZKX: We found that it would not be possible for an Oracle to list as many assets as the community wanted. There are certain requirements that an asset has to meet for an Oracle to list them. We also realized that the rate of refresh is not fast enough to support high-frequency trading. So we build a data layer into each node client. The nodes within the network can provide price feeds directly from the APIs or CEXs like FTX, Binance, or Coinbase. We can also pull in price feeds from Oracles whether it’s Chainlink or Empiric network.

Ross | rhino.fi: Why did you choose Starkware over other L2 protocols?

Eduard | ZKX: I’m very tempted to turn the table here because you are the pioneers of StarkWare technology. What made you in the first place choose StarkWare?

Ross | rhino.fi: So, we started out looking at decentralized Ethereum scaling four or five years ago. We went through looking at state channel scaling and realized that ZK Rollups were a very promising new technology. We encountered StarkWare and loved what they had to offer. We were the first platform to launch on StarkEx, which is a specialist ZK Rollup.

One of the many reasons why we like StarkEx is because you just get a huge amount of throughput. We have got the Validium implementation, which means that we keep data off-chain with the data availability committee. So we can process lots of TPS — a lot more than you would get on Ethereum or blockchain or anything there to that. Also, off-chain data gives people some element of privacy as well. But then flipping back on to you, Eduard, why did you choose StarkNet?

Eduard | ZKX: Well, exactly what you just described. We saw that you are building on StarkEx, successful projects were running on StarkEx and we realized very quickly that out of everyone else that was building ZK technology, StarkWare had already proven that they could make it work. And that was for us a big important factor. Last year, we started developing our initial smart contracts in Cairo. So the way we see it — it was a good compromise between a technology that already had a track record and a technology that could promise in the future to bring lower fees and greater scalability.

Ross | rhino.fi: Switching a bit of context here, I don’t think a lot of people realize how much work you do behind the scenes for the StarkNet ecosystem. You guys are pretty much responsible for training up half of the Cairo developers in the ecosystem. So I just want to say thank you for everything that you’re doing.

Eduard | ZKX: Thank you. Well, we got to the level that we have two people in the team that is fully dedicated to building our StarkNet ecosystem efforts. Within the next four months, we’ll be doing a lot of work in India, right from activations in Tech colleges, and IT colleges to bring more awareness for ZK technology and StarkNet across the country. It will be great to see, within the next six to twelve months, how much onboarding we can get from India as well as these other emerging markets that have incredible developer talent and communities.

Ross | rhino.fi: How are you going to incentivize liquidity on the order books?

Eduard | ZKX: So, we were looking at it from the perspective of ownership. We saw that most of these protocols are closed and they rely on their own token rewards. They create these circular economies like veTokenomics to help bootstrap liquidity. More often they create unsustainable token economies and inflationary pressure on the entire protocol and economy behind it. We thought that we’d design a system that would give ownership to the traders and liquidity providers on the DAO and the entire protocol based on how much they trade and contribute to the DAO and the protocol. Naturally, there will be an incentive for everyone to trade on that exchange, versus other changes that don’t give you the ability to be a part of the ownership as well as the revenue and the value that’s created within that ecosystem.

This led us to introduce Liquid Governance. It allows the traders and liquidity providers to accumulate representation within the DAO, as long as they keep using the protocol. It also gives them access to the revenue share which will be coming from liquidations and trading on the exchange. This means over time as you trade and participate on ZKX you also receive the flow of USDC revenue that’s coming on to the exchange and you get to participate in the decision-making of the DAO and the exchange. Now if you are a ZKX token holder, you can also stake the token and get access to these virtual representations, revenues, and the ability to participate in governance. The longer that you’re going to stake the ZKX token, the more ability you have to capture these. The important thing for us was to give this real presentation to the traders and liquidity providers and give them an incentive to stay with us in the long term because they’re also part of the protocol.

Ross | rhino.fi: What’s coming up over the next few months?

Eduard | ZKX: Within the next few months, we’re going to be releasing most of the technical papers. There’s going to be a lot more content around the product, how it works, where are the differences, and where are the different innovations. On top of that, there’s going to be a Community Incentives Programme through which anyone can contribute to the DAO and anyone who’s an existing derivatives trader or DeFi degen can apply and qualify for. Everyone who qualifies will have easy access to the initial launch of the protocol. Our current expected launch time is around January or February.

About ZKX

ZKX is a permissionless protocol for derivatives built on StarkNet, with a decentralized order book and a unique way to offer complex financial instruments as swaps. The protocol is powered by a DAO and will provide an elevated trading experience with gamified leaderboards and unique liquid governance. ZKX’s mission is to democratize access to global yields through its offerings to anyone, anywhere.

Twitter | Discord | Telegram | Website

--

--

ZKX

The first Social Perp Trading DEX where the world comes to trade 🔥