Why We Chose xDai Chain to Scale Perpetual Protocol

Perpetual Protocol
Oct 19, 2020 · 4 min read

Recently, high gas prices on Ethereum have demonstrated the importance of scalability. After thoroughly evaluating the various scaling options on the market today, we have chosen to use xDai because:

  • It’s Ethereum-compatible and users can use Metamask to interact with it.
  • It’s production-ready and there already are some Dapps running on it.
  • It’s user-friendly as in having a short dispute period and fast block times.

Besides xDai, we considered other scaling solutions, but most candidates had unresolved issues such as:

  1. No ERC-20 Bridge:
    For non-Etheruem chains such as Binance Smart Chain (and other Cosmos-based chains) and Avalanche, there is no ERC-20 bridge that enables users to migrate their ERC-20 assets to the other chain trustlessly (at least during the time when we made the decision).
  2. Not Using Solidity:
    For Ethereum L2 solutions such as ZK-Rollups and Starkware, they’re not using Solidity as the programming language, which means more development work for us as well as a higher chance of bugs because auditing companies might have less hands-on experience with the language right now.
  3. Not Supported by Metamask:
    There are more than 1 million users using Metamask each month and, as we all know, most of the DeFi initiatives take place on Ethereum, so Metamask (or WalletConnect) support is crucial to us. Based on this criterion, solutions such as Nervos were filtered out.
  4. Not ready to use on Mainnet yet:
    Optimistic Rollups are being tested by some prominent DeFi projects, but it is still on testnet now, with mainnet not ready to use yet.

xDai addresses all these issues. It is also extremely easy to onboard existing Ethereum applications to it. The ease of migrating onto or off of xDai gives us the flexibility to pursue other scaling solutions as Ethereum evolves.

Perpetual Protocol on xDai

What does Perpetual Protocol on xDai look like?
Faster, and cheaper. Much cheaper.

According to our initial testing, the time it takes to successfully open a position (steps 2 & 3 below) is around 30 seconds and costs less than 1 cent. There is still room for improvement but so far we’re excited about these results.

Here is the architecture of Perpetual Protocol after incorporation with xDai:

The architecture of Perpetual Protocol with Ethereum as Layer 1 and xDai as Layer 2

From a user’s perspective, only one additional step is needed to start trading compared to L1 — deposit funds into the deposit proxy:

  1. You deposit USDT to the Deposit Proxy on Ethereum (using MetaMask/WalletConnect), where it passes your deposit all the way to the Root Bridge Contract, crediting you the same amount of xUSDT to your address on xDai.
  2. When you want to open a position from our UI, the only thing you need to do is to sign a transaction with your wallet; the signature will be submitted to the Meta Transaction Relayer (no gas involved in this step, since it’s a meta transaction).
  3. The position is opened on xDai and the UI is updated.

Technical considerations

And of course, each design has its trade-offs. Here are the pros and cons of using xDai as our current scaling solution:

Pros:

  1. The gas fee (ETH) is only needed when a trader deposits or withdraws funds to the Deposit Proxy on Ethereum. Trading activities are gas-free thanks to meta transactions.
  2. Traders’ funds on Ethereum and xDai are all controlled by the same wallet (Metamask or WalletConnect). No extra L2 wallet needed.
  3. Frequent operations (trading activities, in our case) can be speeded up by xDai.
  4. Tech-savvy traders can directly interact with Perpetual Protocol’s architecture on xDai without the need to go through our proxy and relayer.

Cons:

  1. Traders need to deposit funds first as opposed to starting trading directly. This adds a little bit of complexity but we expect traders won’t mind since it is standard procedure in the CEX space.
  2. We lose composability by moving the vAMM to xDai.

One thing we want to emphasize is that, despite using xDai to launch on Ethereum mainnet, with the latest architecture, it’s possible to migrate the whole system to other scaling solutions (L2 and other chains alike) without much hassle. One can imagine the Perpetual DAO voting to pause trading activities on xDai, snapshot the state (traders’ active positions, balances, etc.), and proceed to ‘paste’ every trader’s state onto another L2/chain and resume trading activities.

We’ll keep an eye on the development of scaling solutions, and if a more suitable solution emerges, we’ll let our community decide whether we should migrate to a new one.

Perpetual Protocol

Perpetual Protocol is a decentralized perpetual contract protocol for every asset, made possible by a Virtual Automated Market Maker (vAMM).

Perpetual Protocol

Written by

Decentralized perpetual contract for every asset

Perpetual Protocol

Perpetual Protocol is a decentralized perpetual contract protocol for every asset, made possible by a Virtual Automated Market Maker (vAMM).