Introduction to DeFi

13 minute read

Since the beginning of 2020, the Decentralized Finance ecosystem is growing and is being more and more popular among investors and developers. This DeFi ecosystem brings a lot of new economic and technical innovations.

The thing with DeFi is that the learning curve is brutal. Before talking about DeFi, we have to get to the basics of what are web3, blockchains and ethereum.

In this post we will cover those four parts and try to understand the next challenges of DeFi.

The third revolution

Blockchains and DeFi are part of a major revolution of Internet and technologies around it. We call this third revolution web3. Before we start talking blockchain, let’s have an overview of the Internet history to understand why those technologies are part of a revolution.

World Wide Web

In the 90s, Sir Timothy Berners-Lee presents the concept of “World Wide Web”. This is a major revolution for information. A lot of important concepts come with the www:

  • Information is organized and accessible via URL, Hyperlinks and represented with HTML
  • Communication is made through HTTP over the Internet, a distributed network
  • People can use web browser to navigate to static websites served by web server

“Web2” and the interaction revolution

Even if Berners-Lee would consider this as a logical step of www, web2 refers to a second revolution of interaction that appears at the beginning of the XXI century. Here are the major improvements:

  • Websites become more dynamic with extensive use of JavaScript
  • Applications become more and more interconnected with APIs, this is the beginning of SaaS and Cloud companies
  • Accessibility increases with the creation of social media (YouTube, Facebook…) and the explosion of smartphones and mobile support on websites around 2010.

This revolution makes the Web more and more popular and creates fast growing companies (GAFAM) which centralize all user data and use it for business purposes. The popularity of web2 caused the creation of powerful and centralized governance over the web which is a divergence from the original www’s vision.

The birth of web3

Web3 is the new collection of major breakthroughs occuring since 2010 that aim to bring a new backend for the web. In opposition with web2, this is not a “user-end” revolution but backend proposals to solve web2 problems. There are three main technologies in web3:

  1. Edge and Cloud computing bring computation and data closer to the applications or users, this helps creating fast applications

  2. Artificial Intelligence for data manipulation, analysis and prediction

  3. Decentralized Data networks to create permissionless, open and trustless networks

This new era of the web tries to bring more computational performance, better insights and analysis and communication with shared governance.

In this post, we will focus on the third technology which is the base of Finance decentralization.

What is a Blockchain ?

In this part we will go through the technical aspects of what is a blockchain and how it works. The blockchain ecosystem is the basis of Decentralized Finance projects.

Nakamoto’s Bitcoin

In October 2008, a paper entitled “Bitcoin: A peer-to-peer electronic cash system” is anonymously published on bitcoin.org under the pseudonym of Satoshi Nakamoto. A few weeks after that, the bitcoin network goes live with a first block mined by Nakamoto in which we can find the text “The Times 03/Jan/2009 Chancellor on brink of second bailout for banks”, a reference to a Times articles.

In this paper, Nakamoto explains that the main problem of online payment is that it relies on third parties to prevent double-spending problem, which centralizes the governance of the electronic cash system. Bitcoin is a solution to that:

In this paper, we propose a solution to the double-spending problem using a peer-to-peer distributed timestamp server to generate computational proof of the chronological order of transactions.

So Bitcoin is a decentralized network of timestamp servers that all share the governance of the cash system. This network communicates data under the form of a “block chain” where each block contains:

  1. the hash of the previous block timestamp in order to form a chain
  2. a nonce which is a number incremented by the server until the block hash has the required zero bits
  3. a list of transactions represented as a merkle tree

image-20210518175236680

Bitcoin introduces a coin (BTC) which is defined as “a chain of digital signatures”. In the Bitcoin cash system, every owner has a pair of private/public key. A transaction (ex: send X BTC from A owner to B owner) is made by hashing B’s public key with the previous transaction in the chain of ownership and then sign it with A’s private key.

image-20210518175848679

This open, trustless and permissionless system certifies every data on the chain as immutable “as long as honest nodes collectively control more CPU power than any cooperating group of attacker nodes”.

Definition

Bitcoin introduces a new way to implement electronic cash system with a decentralized network. Here we clearly see the 3 layers that make a blockchain:

The network layer

A peer-to-peer and permissionless network composed of servers that we usually call nodes.

The consensus layer

Used to have a general agreement over the distributed network. Here we saw the Proof of Work which consists of incremented a nonce until the hash of the block containing the nonce contains a certain pattern. This is crucial for certifing data immutability: to change a certain block data, we would need to recompute all the nonce of the blocks added after it (as each block contains the hash of the previous block).

An application layer

Used for the transaction management, this can for example be a ticketing system or a cash system like Bitcoin with BTC.

Ethereum

Now we know how a blockchain work with Bitcoin example. In 2013, Vitalik Buterin introduces a new blockchain project: Ethereum. This project was crowdfunded and went live in 2015. This is today the most used blockchain and the basis of lots of Dapps composing DeFi.

In this part we will answer two main questions:

  1. How does Ethereum work and why is it considered as a good foundation for DeFi ?
  2. How is Ethereum 2.0 correcting Ethereum limitations, and how will it help Decentralized Applications ?

Ethereum

EVM, Smart Contracts and gas

Ethereum is the blockchain of decentralized application which are developed with Smart Contracts. If a developer wants to create a Dapp, he must use an Ethereum Virtual Machine (EVM) compatible language. Solidity is one of the most famous language used for Smart Contracts, which directly compiles to EVM bytecode. Every Smart Contract is defined with its address, its balance, its bytecode and a persistent storage, used during the contract’s execution.

Ethereum implements a Proof of Work consensus, like Bitcoin. When a node needs to validate a transaction invoking a Smart Contract it executes the contract’s bytecode inside the EVM.

The cool thing about the EVM is that it is Turing complete, so we can use smart contract for a lot of different usecases. But Turing completness is also a problem, because of the Halting problem. Turing proved theorically that we cannot create a program that, taking a Turing-complete program and its input, can output if this program will eventually stop or loop forever.

Imagine a malicious developer who wants to down the Ethereum network. He could simply do that by creating an infinite-looping contract and ask the network to validate a transaction on it. Every node would run this infinite loop and the network would freeze.

In order to solve this problem, Ethereum introduces gas, a virtual unit used for having an execution cost for contracts, depending on their execution complexity and resource usage. Every Ethereum transactions has a gas limit, if during its execution, a contract start consuming more gas than this limit, the run is aborted and the transaction fails. The gas limit comes with a gas price used to compute the price of a transaction on the network.

EVM

The ERC economy

With Smart Contracts, everyone can easily create tokens based on the Ethereum chain. This can cover many use cases: digital currency, tickets for concerts, representation of gold or levels in video games… Those tokens are handled by standards, defined by Open Zeppelin. These standards are contracts that you can inherit in your own contract to create your own token. Here is an example of a really basic “Gold/GLD” token using one of those standards:

// contracts/GLDToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract GLDToken is ERC20 {
    constructor(uint256 initialSupply) public ERC20("Gold", "GLD") {
        _mint(msg.sender, initialSupply);
    }
}

Creation of tokens is made really easy and secured thanks to those standards. There are 2 main standards you must know.

ERC20

The purpose of ERC20 tokens is to easily create fungible tokens without having to deploy your own chain. This standard helped develop a large ecosystem of financial projects on Ethereum with wallets and exchanges for ERC20 tokens.

ERC721

ERC721 tokens are non-fungible tokens, meaning they cannot be exchange with one another like usual currencies. Thanks to this standard, projects based on NFTs like Cryptokitties or marketplaces have emerged.

Note that there are also ERC777, a backward compatible upgrade of ERC20 and ERC1155 a standard for handling multiple tokens in the same Smart Contract.

These standards help develop an economic ecosystem on Ethereum with many ERC tokens: trading tools, marketplaces, exchanges, wallets and financial products. From the beginning, Ethereum has been a foundation for new decentralized financial projects and is considered as one of the best candidate for the base of a DeFi project.

Limitations

Ethereum has become more and more popular and a large ecosystem of projects are built on it. But Ethereum has several issues:

  • The use of Proof of Work consensus is not energy-efficient, and not really decentralized. If a miner has the best calculus units of the network, it will likely validate more transactions than its peers. More centralization implies less security for the network and its ecosystem.
  • The Ethereum blockchain can handle ~30 transactions per second. This sets some limits to the scaling of the ethereum ecosystem. The “single chain with consecutive blocks” model cannot be scaled easily and it limits the growth of the ecosystem.

This is why in late 2020, a new version of Ethereum is coming out: Ethereum 2.0 which aims to bring more security and decentralization to the ecosystem.

Ethereum 2.0

Ethereum 2.0 comes with a lot of improvements and retro-compatibility with Ethereum. Here we will focus on two major changes: the change of consensus algorithm and the introduction of sharding.

Proof of Stake

Ethereum 2.0 switches from Proof of Work to Proof of Stake. This consensus method is less power-consuming and enables more decentralization and therefore more security for the network.

In a Proof of Stake chain, you can run validator nodes. Those nodes must have a certain amount of tokens on their wallet (here 32 ETH) to be selected for the validation of transaction. The tokens placed on the node’s wallet are staked, meaning that they are locked while the node is doing validation on the network and generates rewards.

With this consensus, Ethereum becomes more efficient, less power consuming and more secure.

Sharding

Sharding is a well known process in the data storage world. It consists of splitting data horizontally to spread the load. For Ethereum, this means that there will be multiple chains, considered as shard, that will all contain some part of the blockchain data.

This will help increasing drastically the number of transaction per second and the hardware requirements for running a validator: with sharding, validator nodes no longer need to store all the chain data, but only their shard data.

Sharding also enables Ethereum 2.0 to be retro-compatible with Ethereum as the original Ethereum chain will become a shard of Ethereum 2.0.

A chain called the Beacon chain is responsible for managing the shards by coordinating the stakers in the network and assigning them to certain shards.

Eth2 Sharding

Sharding will be live in 2022.

Therefore Ethereum is already a foundation for DeFi projects and will enable the ecosystem to scale and be more secure with its 2.0, currently in deployment.

DeFi

Decentralized Finance is a recent consequence of projects like Bitcoin or Ethereum. The community uses these projects as a foundation for their financial projects since 4 years now.

The premises

Maker

The first popular DeFi project based on Ethereum is Maker, a protocol used to create stable coins launched in 2017. This is a precursor project for the whole DeFi ecosystem: with this protocol, DAI is created. DAI is a stable coin that does not depend on a fiat currency. In opposition to other stable coins which use dollar as a collateral (meaning they lock X dollars to emit X tokens), DAI uses ETH as collateral which enforce its decentralization and with its multi-collateral version, it now has many crypto collaterals.

ICOs

During the 2017-2018 period, a lot of projects were funded with ICOs where project owners offered their tokens in exchange for ETH. Even if this period is today known as a succession of scams and poorly designed projects, some innovative ones appear and are now at the heart of the DeFi ecosystem. AAVE, a protocol that decentralizes lending and borrowing, is one of them.

AAVE

Using AAVE one can provide liquidity to lending pools and get rewarded with fees everytime these tokens are used for loans. On the other end, AAVE proposes a new mechanism: flash loans. The purpose of flash loan is to execute a loan in one transaction (borrow and pay back during the same tx) without needing to provide a collateral. This means that you can borrow million of dollars in ethereum to perform some actions and then give it back with a fee at the end of your transaction. This mechanism get really popular to make arbitrage (use the difference between two liquidity pools to make profit).

Uniswap

In the end of 2018, Uniswap is released on the Ethereum mainnet. This is a fully decentralized protocol that provides liquidity pools and automated market makers, two concepts really important for decentralized exchanges.

Liquidity pools are used by two type of users:

  1. Liquidity provider who gives an equivalent amount of the 2 tokens of the pool (ex: ETH/BTC) and is rewarded with fees at every transaction. The more liquidity, the more fees.
  2. Automated Market Makers are a decentralized version of the traditional exchange platform. In a traditional centralized platform, buyers and sellers offer different prices for an asset. When a user find a listed price that fits with his trading strategy, the trade is executed and the price of the transaction become the market price. AMM are permission-less and automated thanks to their liquidity pools.

Those pools work with the formula x * y = k where x and y are the balance of each tokens present in the pool and k is a constant. If you buy ETH in a ETH/BTC pool, you will decrease the quantity of tokens in the pool and therefore increase the price of ETH and decrease the price of BTC in the pool, as there is now less ETH and more BTC. This formula regulates the pool prices.

DeFi Summer

After a short crisis in the crypto world at the beginning of the COVID pandemic, the ecosystem knew a growth period called DeFi summer of 2020. This period was initiated with the Compound project.

Compound

Compound popularized, in June 2020, yield farming which is defined as a strategy for liquidity providers to maximize their rewards by switching their tokens between various liquidity pools. In those strategies, users keep switching between lending and borrowing to achieve the best yield possible.

Compound also popularized the concept of governance token, with the COMP token enabling its holders to vote for changes on the protocol. This governance model is now widely used in DeFi projects.

Yearn

Yearn Finance is a yield farming optimizer that automatically makes the most optimized switches between lending protocols. The governance token of Yearn was distributed through liquidity mining, locking 600 million dollars into the liquidity pool during the 2020 summer.

Food swap

Sushiswap was released in August by an anonymous team with the goal of taking advantage of the Uniswap pools. It locked a billion dollars of total value.

During this period, a lot of new iterations on open source projects were launched, like Spaghetti swap or Pasta swap on Ethereum or Binance Smart Chain.

Finally Uniswap introduced their governance token in late summer 2020, attracting more than 2 billion dollars of liquidity in their pools.

The end of the summer

This DeFi summer has been a complete game changer for the ecosystem, with the development of yield farming, liquidity provider protocols and governance tokens. The total value locked in DeFi was multiplied by more than 12 times the value at the beginning of the COVID pandemic.

This period was followed by a decrease of value in protocols, called the DeFi winter. But the projects keep going and the BTC price was higher than its 2017 record at the end of 2020.

What’s left to do ?

DeFi is a still new ecosystem with a lot of room for new projects and new finance mechanisms. DeFi summer was a good example of a period of bootstrapping of the ecosystem, there are still a lot of things to do.

Today developers can contribute to Open Source protocols or create their own project easily with tools like tendermint and smart contracts standards.

2021 is the year of Ethereum 2.0 which already started its scaling with the Beacon chain, and soon the sharding. There are also new projects for the Layer 2 to reduce the gas cost of transactions and facilitate decentralization of applications.

Even with Elon Musk and China’s decisions that affected the market, the total value locked in DeFi is still really high, and only at the beginning of its rise.

Total locked value in DeFi