Crypto Trading
 

Instructors:           Andreas Park
 

 

Workflow Comparison:
Traditional Equity Trading vs Crypto

trading Infrastructure

payments network

Stock Exchange

Clearing House

custodian

custodian

 beneficial ownership record

seller

buyer

Broker

Broker

Broker

Exchange

Internalizer

Wholeseller

Darkpool

Venue

Settlement

Some Stylized Facts on Crypto Trading

How many CEXes are there?

(307 CEX, rest DEX)

approx:
400B p.m.

approx:
700B p.m.

Concerns with CEX-Trading

Bitcoin prices in USD, May 25 2018, 17 exchanges

Arbitrage?

Arbitrage on a Crypto Exchange

BTC/USD

ask: 7,600 

bid: 7,550

BTC/USD

ask: 7,500 

bid: 7,450

buy BTC

sell BTC

move BTC to Kraken

=> arbitrage = commit capital on multiple exchanges

Crypto Wash Trading, Lin William Cong, Xi Li, Ke Tang, Yang Yang

  • systematic tests:
    • robust statistical and behavioral patterns in trading to detect fake transactions on 29 cryptocurrency exchanges.
    • Regulated exchanges are OK
    • unregulated exchanges: rampant manipulations
    • wash trading on each unregulated exchange:  
      • on average over 70% of the reported volume
      • improve exchange ranking
      • temporarily distort prices

Volume Manipulation on Crypto Exchanges

Cryptocurrency Pump-and-Dump Schemes
Tao Li, Donghwa Shin, and Baolian Wang, 2020

What is pump and dump?

arranged via Telegram Channels

Price Manipulation on Crypto Exchanges

the 1% of hours with the strongest lagged Tether flow are associated with 58.8% of the Bitcoin buy-and-hold return over the period.

USDT Issuance vs Bitcoin Returns

the "normal-times" returns

Crypto exchanges are a security risk

By yours truly, Dec 2017: "What really concerns me about the current craziness is the role of the cryptocurrency exchange platforms, such as Coinbase, Quadriga, or Bitfinex, which most people use to buy Bitcoins. These are like banks that hold deposits. For cryptocurrencies to succeed it is critical that these interfaces with the real world are financially robust. Are they? Do they have all the Bitcoins they sell? Can they always satisfy depositors’ demands?"

And then there is FTX

Core problem with QuadrigaCX:

  • Gerry Cotton sold people crypto he did not have.

Core problem FTX

  • used customer funds to prop up their market maker Alameida
  • => they gave Alameida customer assets

In finance terms

  • call it unhedged "leverage"
  • hedge means that you have an off-setting position

Possible solution

  • prove your aggregate positions:
  • prove your assets & liabilities
  • if asset = liabilities \(\Rightarrow\) solvency

Source: https://vitalik.ca/general/2022/11/19/proof_of_solvency.html

Proof of Assets & Liabilities

  • Assets: cash in bank accounts and crypto assets in exchange wallets

  • Liabilities: crypto and cash deposits made by customers

  • Proof of cash assets

    • requires an auditor report

  • Proof of crypto asset

    • publish all exchange wallets

    • problem: cold storage

    • proof of control: shift assets from one address to another at a pre-determined time

  • Proof of liabilities

    • public customer balances - customer can check

      • own holding

      • positive customer balances

      • sums to assets

  • Problem: privacy

    • Solutions:

      • hash of customer

      • Merkle tree-type organization

      • zero-knowledge proofs 

How about fully decentralized trading?

Blockchain Infrastructure

seller

buyer

Workaround: L2/Rollup

  • Idea: deposit tokens into rollup
  • limit order= signed transaction
  • dydx builds limit order book
  • If match found, trade submitted to mainnet
  • based on StarkWare ZK rollup tech

Application: decentralized trading with automated market makers

New institutions!

  • passive "shared" liquidity provision
  • new pricing function

How do you organize DEX trading? EXAMPLE

automated market maker

invariant \(k=4\times4=16\) 

Instantaneous exchange rate:

1             =   1

Contract deposit:

How do you organize DEX trading? EXAMPLE

automated market maker

sell 4 DAI for USDC

what price will therefore be quoted?

\begin{array}{rcl} k&=&\#\text{DAI}\times\#\text{USDC}\\ 16&=&(4+4)\times(4-y)\\ y&=&2 \end{array}

how many USDC?

e=x/y~~\to~~e=2

How do you organize DEX trading? EXAMPLE

automated market maker

Problem: large "slippage" (or price impact)

  • imagine: deposit is 100 DAI & USDC:
    • \(k=100\times100=10,000~\to\) for \(x=4\) need \(y=100-10000/104=3.85\)
       
  • imagine: deposit is 10,000 DAI & USDC:
    • \(k=10,000\times10,000=100,000,000~\to\) for \(x=4\) need \(y=10,000-100,000,000/10,004=3.998\)
       
  • ​\(\to\) the more money is in the contracts, the lower the price impact

\(X-Q\)

\(X\)

\(Y+P(Q))\)

\(Y\)

\(c=X\cdot Y\)

automated market makers Pricing Function

  • remove \(Q\) of one token
  • must add \(P(Q)\) of other token 
  • so that liquidity stays invariant \[L(X,Y)=L(X-Q,Y+P(Q))\]
  • Common rule: constant product \[X\cdot Y=(X-Q)\cdot (Y+P(Q))\]

Does it matter economically?

Concerns with DEX Trading

\(X-Q'\)

\(X\)

\(X-Q\)

\(X-Q'-Q\)

receive \(-P(-Q|X-Q'-Q)\)

pay \(P(Q)\)

\(P(Q'|X-Q)\)

\(Y\)

\(Y+P(Q)\)

\(Y+P(Q')\)

\(Y+P(Q)+P(Q'|X-Q)\)

\(P(Q')\)

Problem: MEMPOOL Frontrunning is intrinsically profitable

Problem: MEMPOOL "Sandwich Attacks" intrinsically profitable

Example: Feb 2022, ETH-USDC trade

  • Trade:
    • 100 ETH
    • av price: \(\$3,105\)
  • Sandwich attack:
    • trade 100 ETH, wait for original, sell 100 ETH:
      • cost: \(-100\times \$3,105\)
      • revenue: \(100 \times \$3,121\)
      • profit: \(\$1,639\)
    • trade \(\pm 1,000\): profit \(\approx \$17,000\)
    • trade \(\pm 10,000\): profit \(\approx \$261,000\)
  • original trade: 1.5 ETH for APE tokens
  • attacker:
    • \(\pm 1,668\) APE
    • bought for 4.14 ETH, sold for 4.46 ETH

Mempool \(\Rightarrow\) Front-Running!

So what's the Problem?

a

b

c

d

e

f

g

Dark side of DEx trading: Miner extractable value

DEX vs CEX Tradeoffs

Option

Exchange-side risk

User-side risk

Custodial exchange (eg.Coinbase today)

User funds may be lost if there is a problem on the exchange side

Exchange can help recover account

Non-custodial exchange (e.g.Uniswap or dydx today)

User can withdraw even if exchange acts maliciously

User funds may be lost if userscrews up

Source: https://vitalik.ca/general/2022/11/19/proof_of_solvency.html

Costs of AMM Liquidity Provision:
the Impermanent Loss

How lucrative is liquidity provision?

  • Math alert!
  • AMMs are built for passive liquidity provision.
  • \(\to\) compare to passive holding
  • Have \(X_0,Y_0\) tokens at price \(P_0=\frac{Y_0}{X_0}\).
  • Initial investment in $: \(X_0P_0+Y_0\)
  • Price moves to \(P_1\)
  • Pool contains \(X_1,Y_1\)
  • Dollar Profit/loss relative to passive holding: \[DL(P_0,P_1)=P_1X_1+Y_1-(P_1X_0+Y_0)\]

How lucrative is liquidity provision?

  • When price moves, the contract loses \(Q\) of the first tokens and gains \(P(Q)\) of the second token so that \[P_1=\frac{Y_1}{X_1}=\frac{Y_0+P(Q)}{X_0-Q}\]
  • Dollar Profit/loss relative to passive holding:


\[\begin{array}{rcl} DL(P_0,P_1)&=&P_1(X_0-Q)+Y_0+P(Q)-(P_1X_0+Y_0)\\ &=& P(Q)-P_1\cdot Q \end{array}\]​

Impermanent Loss

  • If there are fees, then these are collected on the dollar amount traded.
  • If volume is \(v\) and the fee rate \(f\), total fees are \(f\cdot v\).
  • The ratio \(\nu=\frac{v}{P_0X_0+Y_0}\) is the turnover.
  • Therefore IPL with fees is \[IPL_f(P_0,P_1)=\frac{DL}{2Y_0}+f\nu.\]
  • The Impermanent Loss is the dollar loss per unit of capital

    \[IPL(P_0,P_1)=\frac{DL(P_0,P_1)}{P_0X_0+Y_0}.\]

Impermanent Loss

  • If we use \(P_1=Y_1/X_1\) and \(R\equiv P_1/P_0\), we can solve
    \[P_1=\frac{Y+QY/(X-Q)}{X-Q}\]
    for \(Q\) to get
    \[Q=X\left(1-\sqrt{R^{-1}}\right).\]
  • In AMMs with constant product pricing \[XY=(X-Q)(Y+P(Q)).\]
  • Therefore \[P(Q)=\frac{QY}{X-Q}.\]
  • Subbing and simplifying gives \[IPL(R)=\sqrt{R}-\frac{1}{2}(1+R)\]

Impermanent Loss for Limit Order Books

  • One can also approximate limit order book pricing

quantity

price

\(Q\)

\(p(Q)\)

\(P^{\mathsf{dp}}(Q)=\int_0^Qp(q)~dq\)

  • Here: \(P(Q)=P_0Q+Q\times \frac{P_1-P_0}{2}.\)
  • Sparing you the derivation: \[IPL(R)=-\frac{1}{2}\frac{(R-1)^2}{3R+1}\]

Impermanent Loss in numbers

  • Jan 2022 for ETH-USDT:
    • \(R=0.7\) (30% price drop)
    • \(X_0P_0=Y_0=\$118M\)
    • Volume $1.6B \(\nu=6.8\)
    • Fee \(f=30bps)
  • Impermanent Loss
    • Constant product: \(-1.3\%\)
    • Hypothetical Limit order book: \(-1.45\%\)
    • Fee income: \(0.003\cdot 6.8=2\%\)

Comparing Impermanent Loss for Return Distributions

Gamma Distribution

Constant
product
worse

Constant
product
better

Comparing Impermanent Loss for Return Distributions

Log-Normal Distribution of Returns

Constant
 product
is always worse

The Regulator's View

Canadian View

  • Heavily influenced by QuadrigaCX debacle
  • Custody questions paramount (how stored, how accessible, what risks)
  • Custody = crypto trading platform  (CTP) offers a security (irrespective of the underlying)
  • Requirement on due diligence when listing
  • Current $50K limit for new purchases
  • CTP must register with IIROC (which has no process)
  • Only BitBuy is compliant, some are in "Sandbox"

Blockchain 2: Crypto Trading

By Andreas Park

Blockchain 2: Crypto Trading

  • 269