Counterparty (exchange) risk is one of the main risks to consider when trading cryptocurrencies. In contrast to traditional financial markets, where different institutions, such as exchanges, brokers, clearing houses, and banks, provide infrastructure to minimize such risks, in the cryptocurrency market, an exchange is usually a combination of all these institutions in one entity. Trading cryptocurrency requires depositing the funds to an account opened at an exchange, which in most cases is not regulated by any agency. Within the exchange, the funds are tracked off the blockchain, so in general, clients have little control over their funds.

Decentralized exchanges and why they don’t work

There are multiple so-called “decentralized exchanges” that claim to have overcome the counterparty risk. However, from our point of view, not only do they have the same (if not greater) counterparty risk, but they also introduce additional problems that make the whole concept nonviable.

Here’s a brief description of how a typical DEx works:

  • The client brings their funds (say, Bitcoins) to the so-called gate. The gate stores the client’s Bitcoins and issues the same amount of tokens (let’s call them DexBTC for our example) that can be traded within the DEx’s blockchain. Basically, these tokens are collateralized by the real Bitcoins kept by the gates.
  • The client sends an order to sell their DexBTC and get, say, DexETH in exchange. The order, the matching process, and the resulting trades are all stored on the blockchain — that’s the really good part of this concept.
  • After receiving the DexETH, the client may convert them to real ETH (Ether) using the same or another gate.

It’s obvious that the gates are the point of failure. There is no guarantee that the gate will not default or in any other way refuse to convert the DEx chain tokens back to real cryptocurrency. A DEx may implement a cryptocurrency audit to show that all issued tokens are collateralized by real assets, but a centralized exchange can do the same.

In addition, the design of DExs leads to a much lower transaction speed than on centralized exchanges. Though many blockchains are quite fast, they can never compete with the matching engines of centralized exchanges (on traditional financial markets, exchanges optimize their performance in terms of microseconds). There will never be HFT on a decentralized exchange.

Xena Exchange offers decentralized accounts (DAccs)

Decentralized accounts are built using a proprietary clearing protocol based on principles similar to those of the Lightning network and combine centralized trading with segregated fund storage, with the exchange not having direct access to clients’ funds. Though the counterparty risk is not eliminated completely for Xena Exchange clients, this system decreases it by up to 90%. In the first stage, DAccs will be used for margin trading on Xena Exchange, and later, they may be adapted for the spot market as well.

Excursus: Lightning Network. Lightning Network is a network built over the Bitcoin blockchain that operates with the notion of channels. When opening a channel, two parties commit some of their funds to a multi-sig wallet. To withdraw the committed funds from this wallet, one needs signatures from both parties. When using a channel, the parties exchange with the new states of the channel, which shows the new distribution of funds. This happens off-chain, so the exchange can be as fast as needed. When the channel has a new state, each party can close it, settling this state to the blockchain at any time. There are also special mechanics in place that allow parties to get their funds back after some time if the second party doesn’t respond or closes the channel in the normal way, or to retrieve all the funds allocated to the channel if the second party tries to cheat somehow. In a nutshell, it works like this:

  1. Alice and Bob create a channel. Alice commits 10 BTC, and Bob commits 5 BTC. After settling the special channel-opening transactions to the blockchain, 15 BTC are stored in a dedicated multi-sig wallet, and the parties have the following transactions in the channel (not settled to the blockchain):
  2. Alice submits a transaction to withdraw 10 BTC from the multi-sig wallet, signed by Bob
  3. Bob submits a transaction to withdraw 5 BTC from the multi-sig wallet, signed by Alice
  4. Either party can add their signature to the transaction they have submitted and settle it to the blockchain at any moment
  5. Alice buys something from Bob and wants to pay 2 BTC to him. She exchanges the new state of the channel with Bob using an off-chain means of communication. Now:
  6. Alice has a transaction to withdraw 8 BTC from the wallet, signed by Bob
  7. Bob has a transaction to withdraw 7 BTC from the wallet, signed by Alice
  8. This process can be repeated until both parties decide to close the channel. To do so, both of them must settle the last state of the channel to the blockchain, redistributing the funds from the multi-sig wallet to their personal wallets.

Lightning was originally created as a fast payment solution that could significantly increase the capacity and speed of transaction processing on the Bitcoin blockchain. As a result, it has some restrictions and overcomplications not required for DAccs. Xena Exchange’s clearing protocol was tailored for exchange custodian functions, but the basic principles and underlying blockchain transactions are the same. Here is a brief description of how DAccs work from the client’s perspective:

  1. Alice wants to trade on margin on Xena Exchange. Say she decides to open a position with a value of 1000 BTC. The initial margin for this position depends on the instrument and position value and may be as low as 10 BTC. However, to avoid the liquidation of the position, Alice will most likely decide to use a much lower leverage, such as 300–500 BTC (a leverage of 1:3.3–1:2) as the collateral. In most cases, all these funds must be deposited to the client’s account on the exchange and, hence, are exposed to counterparty risk.
  2. Let’s consider the case of DAccs. Alice creates a channel and deposits 500 BTC to this channel. The channel-opening transaction is settled to the blockchain, creating a multi-sig wallet storing these funds, and the initial state is as follows:
  3. Xena Exchange can withdraw 0 from the channel
  4. Alice can withdraw 500 BTC
  5. Before opening a position, Alice signs and sends the new state of the channel to Xena Exchange. This state may be something like Xena Exchange – 30 BTC, Alice – 470 BTC.
  6. After receiving the new state, Xena Exchange updates the balance of Alice’s account — now it’s 30 BTC. Alice can open the position (remember, its initial margin is 10 BTC). Alice’s risk on Xena Exchange is only 30 BTC, which is only a fraction of the total counterparty risk she could have had.
  7. Having a position with a value of 1000 BTC and 30 BTC deposited as collateral means Alice has a leverage of 1:33.3 and a much higher risk of liquidation of her position. Xena Exchange’s trading engine monitors the risk of the positions in real time and issues a margin call if the margin level of Alice’s account approaches the stop-out level. When she sees the margin call, Alice can send a new state of the channel, allocating more funds from the multi-sig wallet to her account on Xena Exchange.

In theory, Alice could have used her own wallet to respond to the margin calls. However, in reality, this approach would not work, since the transfer from a wallet to an account on the exchange must be settled to the blockchain. Even if the exchange deposited the transfer after two confirmations of the transaction, it could take up to 30 minutes to have the amount deposited. Given the volatility of cryptocurrency, we can say that, most likely, the positions on the account would be closed much earlier than the deposit would arrive.

So, to sum up, Xena Exchange DAccs reduce counterparty risk and allow clients to transfer funds from a secure wallet to their accounts in less than a second to mitigate increased market risks.

The interaction between clients and Xena Exchange occurs through the public Xena Exchange DAccs API. Xena Exchange has also developed a basic client application that allows clients to open and close channels and respond to margin calls. We allow for some basic automation: For instance, a client may configure the app to automatically confirm additional allocations less than 10 BTC, or not more than 50 BTC per day, etc. The app will be integrated with native Bitcoin wallets and use their API, and it will not have access to private keys kept securely within the wallet. It will be published with open-source code so everybody can ensure there are no backdoors. Clients that need a higher level of automation (for example, some funds using DAccs may control the risk of their positions on their own and automatically send additional collateral without waiting for margin calls from the exchange) may extend the application or use the DAccs API directly.

Applicability and further development

At the beginning, DAccs will be used for Bitcoin collateral. The technology can be easily extended to blockchains based on Bitcoin that support SegWit. Later on, the same basic approach may be used to ensure DvP (Delivery versus Payment) transactions on the spot market.