Money, money, money…
Welcome back!
In the previous post, we went over all the fancy technical details that make Ethereum the protocol that it is. Now that we are all clear on that [right?], we can start talking about the financial ecosystem of Ethereum. Specifically, we will focus on the initial generation of DeFi (decentralised finance) applications, which rose to prominence during the “DeFi Summer” of 2020.
Let’s discuss how these dapps (decentralised applications) are gearing up to provide you with the services that you currently receive from the traditional banking sector.
But first, let’s start with the basics.
What is DeFi?
Decentralised Finance applications are computer programmes (“smart contracts”) which run on a blockchain such as Ethereum and provide blockchain users with financial services.
Crucially, they do this without:
a centralised intermediary to coordinate activities
identity verification requirements for customers
restrictions on who can use them
having closing hours; they operate 24/7
In contrast, TradFi (traditional finance):
needs intermediaries such as brokerages, exchanges, and banks
requires participants to verify their identities
can limit the services that are provided to specific audiences, e.g. by geographic location, net worth, or perceived financial competence
often has limited or no services outside of normal working hours
In fairness to TradFi, 2 and 3 are mainly due to regulation requirements imposed by governments. So far DeFi has been able to avoid the majority of these. In cases where they have bowed to regulators, users can often still interact with contracts by changing locations with VPN providers or bypassing application front ends and directly interacting with the smart contracts behind the protocols.
Major DeFi applications
Decentralised Exchanges (DEXs)
Automated Market Makers
Similarly to stock exchanges in TradFi which allow you to buy and sell company shares, DEXs allow you to buy and sell digital tokens. The most popular DEXs on Layer 1 Ethereum are automated market makers (AMMs). They use mathematical algorithms to determine the relative prices at which you can trade tokens.
Creating a new trading market
Anyone can add a new trading market on an AMMs by creating a “liquidity pool” and depositing (usually two) tokens to it, for example ETH and USDC (a stable-coin pegged to USD). Such users are called “liquidity providers”. They collect fees based on the levels of trading in the liquidity pools that they have contributed to and their share of pool assets. This is because the user who creates the initial liquidity pool does not have a monopoly over it, others can also deposit tokens and become liquidity providers. Once a liquidity pool is created, traders can then interact with it and swap between the tokens in the pool. They pay a fee to the liquidity providers, and in some cases to the DEX.
Price discovery
While the tokens in the pools are provided by liquidity providers, the DEX algorithm determines the prices at which trading occurs. A simple AMM algorithm is one that maintains a constant product among the assets in the pool so that X * Y = K, where X and Y are the volumes of the respective tokens in the pool (e.g. ETH and USDC) and K is the constant product among them. The algorithm selects a token exchange rate such that after each trade is completed the new remaining volumes of tokens will still have the K product. In practice this means that if trading becomes heavily one-sided and depletes the volume of one of the tokens, the relative cost of selling it (slippage) is higher than if the pool were more balanced.
A practical example
Let’s go through an example trade on an constant-product AMM
An ETH-USDC pool contains 10 ETH and 15,000 USDC tokens.
Then K would be 150,000 (10 * 15,000) and 1 ETH would be valued at 1,500 USDC.
However, trading will not occur at this price, as it only holds for infinitely small amounts of ETH.
Let’s calculate the effective price if someone wanted to buy 2 ETH from the pool.
After the trade the pool would end up with 8 ETH.
Keeping K at 150,000, we must have 150,000 / 8 = 18,750 USDC remaining in the pool after the transaction completes.
So a user would be charged 18,750 - 15,000 = 3,750 USDC (before fees).
This is 3,750 / 2 = 1,875 USDC per ETH.
They would also be charged a trading fee. Let’s assume the fee is 0.05%.
Then, their total purchase cost would be 3,750 * (1 + 0.05/100) or 3,751.875 USDC [yes, USDC has more decimal places than USD].
After the trade completes, the pool now has 8 ETH and 18,750 USDC, and K has remained constant at 150,000 (8 * 18,750)
Not too complex, right? All you need to remember is that K needs to stay the same, and work backwards from there.
Figure 1: AMM Flow
Source: Uniswap
Notable DEXs on Ethereum:
Uniswap is by far the most popular AMM DEX and has large brand recognition
SushiSwap was created as a “vampire attack” on Uniswap when a rival group of developers copied the code of Uniswap and added a governance and revenue-sharing token as an incentive for traders to use their protocol instead [yes, this can happen when code is open-source].
Curve specialises in stable-coin trading, allowing users to transact large amounts of stable-coins with less slippage than traditional AMMs.
While most protocols have two assets in each liquidity pool, Balancer supports pools with up to eight tokens.
Order-book trading
There are also order-book DEXs. These are similar to the exchanges you see in TradFi but are [or aim to become] decentralised. A prominent example is dYdX (not fully decentralised yet), which moved to Layer 2 on Ethereum, due to the limited blockspace (15TPS) and high transaction costs on Layer 1 Ethereum. Order-book exchanges allow users and market makers to post buy and sell orders at different (“limit”) prices or choose to transact at the most favourable existing “market” price for their order. The exchange sorts the buy and sell orders by price and executes a trade when there is an overlap in the prices that participants are willing to trade at with one another.
The Crypto space also has its fair share of Centralised Exchanges (CEXs). The most prominent ones are Binance, Coinbase, FTX, and Kraken.
Borrowing and Lending Services
Lending DeFi protocols have emerged as a way to provide more sophisticated financial services to blockchain participants. Their loans are “default open” and can be closed at any point when the borrowers choose to repay them. Lenders have their assets pooled and earn variable interest rates on the tokens that they provide for borrowing. The rates depend on how many other lenders want to lend out the same tokens as well as the volume of the tokens that users wish to borrow (supply and demand mechanics). Borrowers are not pooled into a group and are responsible for their individual loans.
Over-collateralised loans
Because borrowers are pseudonymous, protocols find it hard to determine their ability and willingness to repay loans. Therefore, to ensure loan repayment they rely on the assets which are put as collateral for the loans. These are the assets which borrowers deposit into lending protocols in exchange for the “loan” assets that they receive.
As a result, the loan-to-(collateral) value (LTV) ratio of DeFi loans is below one, which is also referred to as debt over-collateralisation. To emphasise, in addition to paying interest on their loans, borrowers must put as collateral assets which have a larger market value than the value of the loan that they are taking out.
They also must ensure that their LTV stays above a loan liquidation threshold, or risk having part or all of their loan be liquidated. Crucially, the loan liquidation threshold implies a collateral value that is also larger than the loan value. To reduce their risk of liquidation, some borrowers post larger collateral that is strictly required by the protocols.
Not that if you borrowed a non-stable coin, you can hit the liquidation threshold not only if the value of your collateral falls in absolute terms, but also if the borrowed asset rises sufficiently high in value against your collateral. Borrowing is risky!
Loan Liquidations
Liquidations exist to protect lenders from losses. Once the loan liquidation threshold is reached anyone can purchase part (or all) of the loan collateral at a discount and “liquidate” it, making this a profitable transaction. Since this is an MEV opportunity, a portion of the fees gets paid to blockchain miners, to incentivise them to prioritise a particular liquidator.
Because (some of) the collateral gets liquidated when it is still larger than the loan value, the protocol lenders are made whole even after providing a discount to the liquidator. Liquidated users keep the assets that they have borrowed but lose part (or all) of their collateral. If they only lost part of their collateral, the remaining loan is again over-collateralised but they now they owe less to the protocol.
What if prices move in your favour? Then you can enjoy the safety of a lower LTV ratio, or use some of the excess tokens to repay part of your loan.
Figure 2: Liquidation Flow
Source: Aave
A liquidation example
This probably seem overly complicated. So let’s walk through an example loan and liquidation to make things clearer:
Let’s say you put up 24 ETH as collateral and borrow 18 ETH-worth of DAI (a stable-coin pegged to USD).
At inception your loan is overcollateralised with an LTV of 18/24 = 0.75.
If ETH price at the time of originating the loan was 1,500, you borrowed 18 * 1,500 = 27,000 DAI, with collateral equivalent to 24 * 1,500 = 36,000 DAI.
DAI is a stable coin so we assume we won’t have to worry about its value rising (the risk for stable-coins valuations is generally to the downside)
Therefore, the main loan risk is of the value of ETH falling in DAI[USD] terms
At a liquidation threshold of 0.80 (assumed), if your collateral value falls to 27,000 / 0.80 = 33,750 ( loan value / liquidation threshold = liquidation value) then your loan can be liquidated.
This implies that ETH price falls to 33,750 / 24 = 1,406.25, a 6.25% decrease in value.
To simplify the calculation we assume that this fall happens before your loan has accumulated any meaningful interest.
We also assume that the liquidator is allowed to liquidate 50% of your collateral as a maximum and would receive a 5% liquidation bonus.
So once you hit the threshold, the liquidator repays 50% of your collateral, 12 ETH = 12 * 1,406.25 = 16,875 DAI
This reduces the outstanding loan to 27,000 - 16,875= 10,125 DAI.
The liquidator then gets 12 ETH + the 5% liquidation bonus on your collateral, 12 * (1 + 5/100) = 12.6 ETH
You are left with 24 - 12.6 = 11.4 ETH as collateral
Your collateral has a fair value of 11.4 * 1,406.2 = 16,030.68 DAI.
The new LTV of your loan is 10,125/16,030.68 = 0.63, below the liquidation threshold of 0.80
The protocol does not lose money as it is now holding a healthily overcollateralised loan on its books, and was repaid in full the difference in the loan value by the liquidator.
The liquidator profits 0.6 ETH (5% of 12 ETH), minus the fees that they pay to block miners [this can be significant]
You are the only loser, as the 5% discount to the liquidator comes out of your pocket.
Another way to calculate your loss is to consider that you got 16,875 DAI of your loan repaid at a cost of 12 * (1 + 5/100) * 1,406.25 = 17,718.75, so your loss is 17,718.75 - 16,875 = 843.75 ( 0.6 ETH).
So, when you get close to a liquidation, it is in your best interest to repay your loan or post more collateral to keep your LTV over the liquidation threshold. You could also try to liquidate yourself and hope you out-bid all the other potential liquidators.
Why borrow in the first place?
Given the dangers of over-collateralised borrowing, you may be wondering, why borrow at all? Well, borrowers get exposure to other tokens without having to sell their existing assets. This can be advantageous for several of reasons.
First, borrowing could save people taxes by not having to pay capital gains taxes on their collateral, part of which would otherwise need to be sold to obtain the borrowed assets. Second, borrowing also helps users keep their exposure to their existing holdings in cases where the believe that these will appreciate in value more than the borrowed tokens.
Why would you want to get exposure to the borrowed tokens if you believe they will perform worse than your current holdings? You could need a specific token to interact with a particular application, or execute a profitable trade [yes, the “profitable trade” angle is quite broad and does include a lot of speculation].
Flash loans
An innovation of lending protocols was to introduce short-term (“flash”) borrowing at a small fee (0.09% on Aave). These are loans which need to be paid back within the same block and can be used to arbitrage price imbalances among DEXes or liquidate loans [yes, this is MEV]. If the flash loan borrower is unable to pay the loan in the same ethereum block, then the borrowing transaction will not be valid and will not be added to the blockchain.
This is a case where the structure of the blockchain has a allowed a financial instrument with no equivalent in the TradFi world. Flash loans allow users without sufficient financial resources to participate and profit from liquidations and other MEV opportunities across the Ethereum blockchain.
Notable Ethereum Lending protocols
MakerDao has the largest share of loans among the three major DeFi Lending protocols. It allows users to borrow DAI, its own USD-pegged stable-coin.
In contrast, using Compound users can borrow and lend multiple digital tokens
Aave follows in the footsteps of Compound but offers both variable and fixed (for a period) lending interest rates. It also pioneered the use of flash loans.
The hunt for yield, DeFi style
As you can imagine, tracking which is the most profitable use of your money tokens in the DeFi ecosystem can be cumbersome. Yearn Finance emerged to allow users to deposit funds to their platform. The protocol then automatically maximises the yield they earn by interacting with lending and borrowing protocols on their behalf.
DeFi: a Fad or the Future of Finance?
Many users in the western world may consider the current state of DeFi protocols to be too simple compared to what they have access to. This is largely true, but mind the trajectory:
Not everyone has access to the financial services that you may take for granted. In those cases, having access to even a basic version version of financial services is a massive improvement on the status quo.
Even users in the developed worlds should appreciate the permission-less nature of DeFi compared to the cumbersome experience many of us have with legacy financial institutions. You can transfer large amounts without having to explain yourself to your banker [unfortunately, so could a thief that just stole your wallet’s seed phrase]
New innovations which have no equivalent in TradFi, such as flash loans, are already emerging. What could come up next?
That being said, DeFi still has major hurdles to overcome in order to be a strong contender for the “Future of Finance” award:
DeFi needs to add more safety features. Currently the space is full of paranoid people who are constantly weary of scams [and innocent people who are getting scammed]. Normal people will not want, or be able to handle, that experience. Luckily, with the help of smart contracts and better user interfaces, we can help safeguard user assets better. And, yes, transactions within an application can become reversible if they are wrapped in the proper smart contract architecture. We will need to experiment with different safety designs but I am confident that we can find a set of solutions, ones that uses can opt into depending on their profiles and circumstances.
Over-collateralised lending is a rich person’s game. To onboard the next billion people we will need under-collateralised lending options. There are protocols that are working on this (coincidently backed by a16z) , as well as initiatives to bring “real world” credentials on the blockchain, which may help protocols assess borrower risk.
Trading costs need to go down so they do not stifle adoption. I am least concerned about this as Ethereum’s Layer 2 platforms are on the case.
DeFi apps will also need to prepare to face competition from FinTech companies. Some argue that FinTechs will collaborate with DeFi to improve user experience (the “DeFi Mullet” thesis). Perhaps, but undoubtedly there will be some competition too. However, FinTechs are more tightly regulated by governments so are unlikely to be able to provide all the benefits of DeFi. Nevertheless, a threat to be considered.
Conclusion
DeFi is in its infancy and once critical impediments are taken care of it will likely quickly expand beyond its current niche offerings. It doesn’t hurt that the current global polarisation is playing right into crypto’s hands. Examples such as Canadian protestors getting their bank accounts frozen, and Russia being banned from Swift only accelerate the search for a credibly neutral space where transactions can take place [yes, I know that technically Swift is just a messaging platform, the point still stands]. China will undoubtedly make a play for a share of the pie but DeFi may end up being the clear winner.
But it is not all roses and sunshine, and success is not pre-determined. DeFi is still rough around the edges and not polished enough to “onboard the world”. The industry cannot afford to rest on its laurels and needs to keep innovating to overcome the major existing roadblocks it still faces.
Also, governments will likely try to regulate DeFi protocols out of their usefulness. However, I doubt that they will be successful. In the digital space, the barriers to innovation are getting lower and lower. We have all learnt that once something is on the internet it is hard to make it disappear.
To paraphrase Balajis, government organisations were not created to deal with people being able to launch their own stock exchanges and banks from their mobile phones, they were built to deal with large slow-moving corporates. This is an entirely new ball-game and they will be grossly understaffed in trying to control the creativity and ingenuity of millions of individuals [I am assuming that alas not everyone will be inspired to design a new DEX].
TradFi people in particular should be on notice, as they may be in for a disruption similar to the one that social media dealt to traditional media outlets. “TradMedia” had the excuse of not being able to appreciate the strength of the network effects that the internet would conjure. No one in 2022 has that excuse.
PS
I hope you enjoyed this post, let me know what you think! In the next one we will move into the world of art and talk about the current state of NFTs and their future impact on our world.
Stay tuned, digital frens.
For the hobbyists
Check out the the ETH-USDC Uniswap Pool
Play with this AMM simulator
Review a few Gauntlet Protocol Risk Management Dashboards
Learn more details about the SushiSwap “Vampire” attack on Uniswap
Try to figure out what this Liquidation Transaction does
Read Bankless’ “DeFi Mullet” thesis on a potential FinTech and crypto collaborations