Fiat & Crypto

Fiat money is a currency without intrinsic value that has been established as money, often by government regulation. The term fiat derives from the Latin fiat - let it be done - used in the sense of an order, decree or resolution.
A cryptocurrency is a digital asset designed to work as a medium of exchange that uses cryptography to secure financial transactions, control the creation of additional units, and verify the transfer of assets.

Cryptocurrency

  • cryptocurrencies use decentralized control as opposed to centralized digital currency and central banking systems
  • they work through a blockchain that serves as a public financial transaction database
  • Bitcoin (BTC), first released in 2009, is generally considered the first decentralized cryptocurrency
  • since the release of bitcoin many altcoins (alternative crypto coins) have been created, the most famous of them is Ether (ETH) which works on the Ethereum blockchain
  • here is the ranking of top cryptocurrencies by market capitalization

Bitcoin

  • B-money was an early proposal, dated 1998 and circulated in the cypherpunk mailing lists, created by Wei Dai for an anonymous, distributed electronic cash system

  • Satoshi Nakamoto (a pseudonymous) referenced B-money when proposing Bitcoin in 2009 in his white paper Bitcoin: A Peer-to-Peer Electronic Cash System

  • the message of Satoshi Nakamoto embedded into the very first Bitcoin block:

The Times 03/Jan/2009 Chancellor on brink of second bailout for banks

  • considering the context in which they appear – during the bank-driven financial crisis of 2009, the worst after the economic recession of 1929 – these words are calling for economic revolution

  • here is the original post of Satoshi Nakamoto proposing Bitcoin

Bitcoin halving

  • in all their infinite wisdom, bitcoin’s anonymous inventor Satoshi Nakamoto decided that only 21 million BTC would ever exist. They wanted new coins to be released gradually into the market
  • new BTC are given to bitcoin miners as their bitcoin block reward when they verify blocks of transactions. To begin with, the reward stood at 50 BTC per block
  • rewards stay fixed for 210,000 blocks (about 4 years), and then are cut by 50%. The halving is the moment (block creation) when this cut happens
  • there will only ever be 32 bitcoin halving events. Once the 32nd halving is completed, there will be no more new BTC created, as its maximum supply of 21 million will have been reached. Why?
  • each BTC is divisible to the 8th decimal place, so each BTC can be split into 100,000,000 units. Each unit of BTC, or 0.00000001 BTC, is called a satoshi. A Satoshi is the smallest unit of Bitcoin. And we have that \[50 \cdot 2^{-32} = 1.16 \cdot 10^{-8}\]

Ethereum

  • a major altcoin is Ether (ETH), the currency of blockchain Ethereum, launched in 2015
  • unlike other blockchains, Ethereum is programmable, which means that developers can use it to build new kinds of decentralized applications (dApps) using smart contracts
  • the set of dApps forms the Web3 or Web 3.0, a decentralized extension of Web 2.0
  • there is no halving or limited supply for ETH, however, since July 2021, much of the gas fees spent to transact on Ethereum, instead of being passed on to the miners, is destroyed
  • this burn reduces the Ether supply in proportion to network usage and hence increase its price
  • Ethereum is currently moving from proof-of-work to proof-of-stake consensus mechanism

Smart contracts

A smart contract is a permission-less script that:

  • runs on Ethereum
  • cannot be modified once deployed
  • does exactly what you tell it to do

The term smart contract dates to 1994, defined by Nick Szabo as:

A computerized transaction protocol that executes the terms of a contract. The general objectives of smart contract design are to satisfy common contractual conditions, minimize exceptions both malicious and accidental, and minimize the need for trusted intermediaries.

The user issuing a transaction to a smart contract will have to pay a fee proportional to the complexity of the code executed.

Tokens

Because of smart contracts, (fungible and non-fungible) tokens on Ethereum are very popular.

A cryptographic token is a quantified and tradable unit of value recorded on the blockchain.

Tokens can be:

  • fungible tokens that represent coins; they are interchangeable and can be split in smaller pieces whose sum makes the whole
  • non-fungible tokens (or NFTs) that represent something unique (for instance, a digital work of art). They are not interchangeable and cannot be divided into pieces

Token standards

  • a token standard defines a set of rules that are formalised as a minimum interface a smart contract belonging to the standard must implement to allow unique tokens to be managed, owned, and traded
  • the most common standard for fungible tokens on Ethereum is ERC-20
  • the most common standard for non-fungible tokens on Ethereum is ERC-721

Decentralized autonomous organization (DAO)

  • a decentralized autonomous organization (DAO) is an organization represented by rules encoded as a smart contract deployed on the blockchain
  • it is decentralized in the sense that it is controlled by the organization members and not influenced by a central authority
  • typically, a governance token of the DAO is distributed to members of the organization and the voting power is proportional to the number of owned tokens (one vote per token)
  • it is autonomous in the sense that after it is launched, it might be organized to run without human managerial interactivity, provided the smart contracts are supported by a Turing-complete platform like Ethereum
  • crypto art gallery SuperRare is currently becoming a DAO in which RARE token holders (artists and collectors that contributed to the success of SuperRare) govern the gallery (for instance, by deciding the new artists to onboard)

Gas and gas price in Ethereum

  • you can view the blockchain Ethereum as a large virtual machine called Ethereum Virtual Machine (EVM) that executes functions from programs called smart contracts in exchange for some fees paid in ETH
  • the machine is used by many users at the same time
  • miners compete to become the executors of these transactions, and hence to receive their fees
  • all executed transactions are registered on a blockchain

Gas and gas price in Ethereum

  • gas is a unit of computational cost of a basic operation on the Ethereum virtual machine
  • every single operation that takes part in Ethereum requires some amount of gas and hence has a computational complexity
  • miners specify a gas price that reflects their cost of inclusion of the transaction in the block
  • on the other hand, users offer a price for gas that should generally reflect how fast they want a transaction mined (the higher, the faster)
  • hence, for a transaction to be validated on the blockchain, the price offered by users should match the cost supported by miners
  • the gas price is expressed in gwei. The smallest unit of ether is the wei: \(10^{18}\) wei make 1ETH. A gwei is \(10^9\) wei, hence \(10^9\) gwei make 1ETH
  • for instance, if your transaction uses 20000 units of gas and the gas price is 50 gwei, then the transaction fees are: \[20000 \cdot 50 = 10^6 \mathrm{gwei} = 0.001\mathrm{ETH}\]
  • notice that if the price of gas is determined by each miner, and I don’t know in advance who is going to mine the block of my transaction, the fee of my transaction is not known precisely in advance
  • however, you can specify a gas limit, the maximum amount of gas units you are allowed to pay
  • you can track the gas price using this gas tracker

Central Bank Digital Currencies (CBDC)

  • Central Bank Digital Currencies (CDBCs) are digital currencies proposed and issued by the central bank of a sovereign country
  • generally, they take on a digital form of the nation’s existing fiat currency, like digital Euro or digital Dollar
  • with CBDCs, transfers could go through wallets directly from sender to receiver seamlessly and at little-to-no cost
  • because CBDCs would theoretically reach anyone with an e-wallet, it would allow for an efficient and widespread transfer of money even to those who have not been able participate in the traditional banking system
  • the domestic government could use CBDCs as a monetary-policy tool, where stimulus can be directly delivered to individuals
  • the People’s Bank of China was one of the first banks to develop a CBDC (digital yuan) and continues to be the leader in terms of development pace
  • though at first glance CBDCs and cryptocurrencies can seem interchangeable, the two are strikingly different both in ethos and design
  • cryptocurrencies were founded on the idea of decentralization, privacy, and inclusion
  • CBDCs are under centralized ownership by the government, traceable, and are inclusive only within the realms of the government’s chosen boundaries

Cryptocurrency exchange

  • a cryptocurrency exchange is an application that allows customers to trade cryptocurrencies for other assets, such as conventional fiat money or other digital currencies
  • a centralized cryptocurrency exchange is a platform owned by a private company where you can buy or sell digital assets
  • on a centralized exchange you have to trust a third party to monitor the transaction and secure the assets
  • such exchanges require you to submit your personal information for verification (Know Your Customer or KYC process)
  • the KYC process is also a legal requirement intended as an Anti-Money Laundering (AML) measure, which describes the legal controls that require financial institutions to prevent, detect and report money laundering activities
  • here is a ranking of centralized cryptocurrency exchanges by trade volume

Order book and orders

  • in a centralized exchange (CEX) each listed pair of coins has an order book with placed sell orders (in red) and buy orders (in green)
  • the price is determined in real time by the match of sell and buy orders
  • each sell order must match some buy orders to fulfill it and will decrease the price of the coin
  • each buy order must match some sell orders to fulfill it and will increase the price of the coin
  • orders can be of three types:
    • market, executed at market price; these orders are not included in the order book
    • limit, executed if and only if the price reaches a given value or better (lower than market price for buy orders and higher than market price for sell orders); these orders enter the order book when placed
    • stop-limit: if the stop price is reached, a limit order at a given price is placed in the order book. These are used to limit the losses (stop-loss). For instance:
      • I buy a coin hoping in an increase of the price (to sell higher), but instead the price decreases and I stop-loss by selling at a given lower price (for instance, 10% lower than the buy price)
      • I sell a coin hoping in a decrease of the price (to buy lower), but instead the price increases and I stop-loss by buying at a given higher price (for instance, 10% higher than the sell price)
  • see here an example for BTC/USDC pair

Decentralized finance

  • DeFi stands for decentralized finance and refers to the ecosystem comprised of financial applications that are being developed on top of blockchain systems
  • thanks to technologies like the Internet, cryptography, and blockchain, DeFi aims to create a financial system that’s open to everyone and minimizes one’s need to trust and rely on central authorities
  • because of smart contracts, most of DeFi applications run on Ethereum blockchain
  • however, because of high gas fees on Ethereum, a big deal of DeFi applications are moving on:

DeFi applications

  1. stable
  2. lend
  3. borrow
  4. swap
  5. pool
  6. cover
  7. stake
  8. stream

DeFi applications

  • stablecoins: cryptocurrencies that attempt to peg their market value to some external reference, typically the U.S. dollar
  • lending/borrowing: lend your crypto (or fiat) earning an interest at an Annual Percentage Yield or APY, or borrow crypto (or fiat) paying an interest and depositing a collateral (like bitcoin) as a guarantee
  • decentralized exchanges: provide liquidity to a pool of cryptocurrencies (market making) to get the fees of the trades or swaps (market taking)
  • decentralized insurance: get covered against smart contract failure without the need for an insurance company, for instance with Nexus Mutual
  • staking: stake your crypto on a blockchain using the Proof of Stake consensus mechanism, like Ethereum 2.0
  • real-time finance: stream your coins in time, for example with Sablier

Decentralized finance: composability

  • DeFi is a way to generate rewards with cryptocurrency holdings. In simple terms, it means locking up cryptocurrencies and getting rewards
  • hence you still hold your crypto (and hence you are exposed to the price volatility of the assets) but at the same time you farm a yield
  • DeFi protocols are permissionless and can seamlessly integrate with each other. It means that DeFi applications are composable, they can be easily joint together in a lego style
  • here is an example:
    1. borrow a token A paying an interest
    2. use it to provide liquidity in a pool earning the trade fees and additional liquidity pool (LP) tokens
    3. stake the LP tokens getting an additional token B
    4. sell the earned tokens B to borrow more tokens A

Stablecoins

  • stablecoins are cryptocurrencies that attempt to peg their market value to some external reference, typically the U.S. dollar
  • stablecoins achieve their price stability via collateralization (backing) of fiat currencies or other cryptocurrencies
  • stablecoins have gained traction as they attempt to offer the best of both world’s - the instant processing and security or privacy of payments of cryptocurrencies, and the volatility-free stable valuations of fiat currencies

Fiat-collateralized stablecoins

  • fiat-collateralized stablecoins maintain a fiat currency reserve, like the U.S. dollar, as collateral to issue a suitable number of crypto coins
  • such reserves are maintained by independent custodians and are regularly audited for adherence to the necessary compliance
  • examples of fiat-collateralized stablecoins include:
    • Tether USD (USDT): the most capitalized stablecoin; available on most exchanges; not regulated; using fractional reserve; not transparent
    • USD Coin (USDC): less popular on the exchanges; regulated in the United States (Circle and Coinbase); transparent; using fractional reserve
    • Paxos Standard (PAX): regulated in the United States; transparent; fully backed (no fractional reserve)
    • Binance USD (BUSD): regulated in the United States (Paxos and Binance); transparent; fractional reserve

Crypto-collateralized stablecoins

  • crypto-collateralized stablecoins are backed by other cryptocurrencies
  • since the reserve cryptocurrency may also be prone to high volatility, such stablecoins are over-collateralized, that is, a larger number of cryptocurrency tokens is maintained as reserve for issuing a lower number of stablecoins
  • for example, $2,000 worth of ether may be held as reserves for issuing $1,000 worth of crypto-backed stablecoins which accommodates for up to 50% of swings in reserve currency (ether)
  • the most popular example of crypto-collateralized stablecoins MakerDAO’s DAI, is pegged against the U.S. dollar and allows for using a basket of crypto-assets (including ether and fiat-collateralized stablecoins) as a reserve
  • decentralized; fully crypto; not regulated; more volatile

Algorithmic stablecoins

  • algorithm-based stablecoins do not have any associated collateral
  • the algorithm or the protocol is backing up these stablecoins works as the central bank
  • it helps in increasing the supply in event of the deflationary tendency of the token or reducing the supply in event of a decline in purchasing power of stablecoin
  • the rules for such actions by the algorithm are available in smart contracts in an embedded form
  • it is possible to change the rules only by leveraging social consensus or through governance votes associated with governance or seigniorage tokens
  • an example of algorithmic stablecoin is Terra USD (UST): read more on Investopedia, or on Tarra Docs

Decentralized exchanges

  • A DEX or a decentralized cryptocurrency exchange is similar to a centralized one, except it doesn’t have a third party on which you can rely
  • all of the funds in this exchange remain stored on the blockchain
  • examples are Uniswap, SushiSwap and PancakeSwap; all work similarly

Uniswap

  • one of the top DEX for trade volume is Uniswap
  • Uniswap is a protocol for exchanging ERC-20 tokens on Ethereum that eliminates trusted intermediaries (in particular there is no order book)
  • the original idea comes from Vitalik Buterin, the mind behind Ethereum blockchain
  • each liquidity pool on Uniswap is a pair of tokens on Ethereum
  • a pool is defined by a smart contract that includes a few functions to enable swapping the tokens (trades) and adding liquidity to the pool
  • the price of the token is defined by the ratio of the balances of the two tokens of the pool

The invariant formula

  • at its core each pool uses the invariant function \[x \cdot y = k\] to maintain a curve along which trades can happen, where \(x\) is the balance of the first token and \(y\) is the balance of the second token in the pool, while \(k\) is a positive constant
  • for each trade (swap) a certain amount of tokens are removed from the pool for an amount of the other token: if I swap A for B, I’m going to add A and remove B from the pool. The amount of B tokens received is computed so that the invariant formula holds
  • this changes the balances held by the smart contract, therefore changing the price (the balance ratio). If I swap A for B, I am selling A and buying B. The quantity of A tokens in the pool will increase (and its price decrease), and the quantity of B tokens in the pool will decrease (and its price increase)
  • notice you can’t empty the pool on either side since if either \(x\) or \(y\) is 0, the invariant equation doesn’t hold anymore
# Uniswap: swap tokens
# balance of token X
x = 100

# balance of token Y
y = 10

# price of X (wrt Y): X is worth 0.1 Y 
y / x
## [1] 0.1
# price of Y (wrt X): Y is worth 10 X
x / y
## [1] 10
# constant k
(k = x * y)
## [1] 1000
# swap X against Y (sell X to buy Y)
# swap x1 = 10 tokens of X for a number y1 of tokens of y 
# use invariant formula (x + x1) * (y - y1) = k 
# to compute y1 = y - k/(x + x1) 
x1 = 10
(y1 = y - k/(x + x1))
## [1] 0.9090909
# new balances of X and Y
(xn =  x + x1)
## [1] 110
(yn = y - y1)
## [1] 9.090909
# check invariant
xn * yn
## [1] 1000
# new price of X wrt Y 
# (lower than before since there is more X in the pool or you sold X)
yn / xn
## [1] 0.08264463
# new price of Y wrt X  
# (higher than before since there is less Y in the pool or you bought Y)
xn / yn
## [1] 12.1

Liquidity providing

  • but to swap tokens, you have to fill the pool: who fills the pool with liquidity?
  • anyone can become a liquidity provider for a pool by depositing an equivalent value of each underlying token in return for pool tokens
  • these tokens track liquidity provider (LP) shares of the total reserves, and can be redeemed for the underlying assets at any time
  • sometimes these LP tokens can be stacked to farm additional tokens (like token UNI for Uniswap, SUSHI for SushiSwap, CAKE for PancakeSwap)
  • each trade costs a fee, which is added to reserves; this functions as a payout to liquidity providers, which is realized when they burn their LP tokens to withdraw their portion of total reserves
  • because the relative price of the two pair assets can only be changed through trading, divergences between the Uniswap price and external prices (for tokens listed elsewhere) create arbitrage opportunities
  • this mechanism ensures that Uniswap prices always trend toward the market-clearing price (the equilibrium price at which quantity supplied is equal to quantity demanded)
  • however, this arbitrage process is costly, and thus liquidity providers might incur in the so-called divergence or impermanent loss, based on the divergence in price of tokens between deposit and withdrawal and only realised when the liquidity provider withdraws their liquidity
  • the divergence loss is due to the price change of the tokens in the pool: the higher the price spread, the higher the potential loss
  • so the actual return for liquidity providers is a balance between the divergence loss caused by the price differential and the accumulated fees from trades on the exchange (and by stacking the pool tokens when possible)

Real-time finance

  • imagine doing a job for which you are paid 2160 Euros per month, which is 72E per day, 3E per hour, and 0.05E per minute
  • why on earth should you get paid once a month? Why not receive it (and be able to spend it) every minute?
  • this possibility exists, it is called real-time finance or money streaming
  • basically, after streaming music and videos, now it’s up to the money
  • the idea was coined by Andreas Antonopoulos in 2017
  • sablier is an application for streaming money on Ethereum blockchain. You can stream Ether or an ERC-20 token like DAI

Crypto crime

  • despite its transparent and traceable design, crypto currencies remain appealing for criminals, primary due to its pseudonymous nature and the ease with which they allow to send funds around the world
  • scams and darknet markets dominate by revenue, but ransomware grew fast in 2020
  • however, the good news is three-fold:
    1. crypto crime represents a small part of the crypto economy, estimated at 2.1% (or $21.4 billion) in 2019 according to Chainalysis crypto crime report 2021 (Chainalysis is a leading blockchain analysis company)
    2. crypto crime is falling, with an estimated share of 0.34% (or $10 billion) in 2020
    3. crypto crime is comparatively smaller to the amount of illicit founds involved in traditional finance

Swap-Pool-Farm-Stake on PancakeSwap

  1. Open an account on Binance and go through the Know Your Customer (KYC) verification
  2. Buy some BNB, the token of Binance (you’ll need BNB later). You can use both credit card or bank transfer
  3. Install the Ethereum Metamask wallet on your favorite browser; watch this video before
  4. Add the Binance Smart Chain (BSC) as a custom network to Metamask: you can use chainlist.org
  5. Move some BNB from Binance to your Metamask wallet on the BSC: use the withdraw function of Binance, select the BSC network, and provide your Metamask address as destination
  6. Go to PancakeSwap and connect your Metamask wallet (select the BSC)
  7. Swap: use Exchange under Trade to swap 25% of your BNB into CAKE (keep the rest for later)
  8. Pool: use Liquidity under Trade to provide liquidity to the CAKE-BNB pool. Add your CAKE and a corresponding amount (about 25%) of your BNB
  9. Farm: use Farms under Earn to stake the LP tokens to the corresponding BNB-CAKE farm to obtain CAKE tokens at a given APR
  10. Stake: use Pools under Earn to stake half of the remaining BNB (about 25% of the initial amount) in the Auto Cake pool, which provides automatic compounding
  11. To move back:
    • first unstake your tokens
    • redeem your liquidity in the pool
    • swap all back into BNB
    • finally using Metamask (select the BSC network) transfer the BNB tokens to Binance (see BNB deposit from Binance to get a destination address)

Delegate-Swap-Lend on Terra Station

  1. Open an account on Binance and go through the Know Your Customer (KYC) verification
  2. Buy some LUNA, the token of Terra blockchain. You can use both credit card or bank transfer
  3. Install Terra Station mobile wallet (Google, Apple)
  4. Transfer LUNA from Binance to your Terra address
  5. Go to Terra Station web app and connect using the mobile app. You can see your LUNA under Wallet
  6. Under Staking, delegate some of your LUNA to some validator. You can check the staking rewards under Dashboard
  7. Under Swap, swap some LUNA to stablecoin UST (keep some to pay fees). You can see your UST under Wallet
  8. Under Wallet, lend (deposit) the UST on Anchor Protocol for an APY of 19.55%