Lesson 1: Introduction to Decentralized Finance (DeFi)
Making peer-to-peer trading scale
Key takeaway
What is decentralized finance?
- Decentralized Finance (DeFi) is one of the fastest-growing areas in the blockchain and decentralized web space. It involves removing the middleman in traditional financial tools.
Decentralized finance is an umbrella term for various protocols and financial instruments that are built on distributed ledger technology (DLT), such as blockchain.
DeFi protocols aim to provide an open, decentralized infrastructure for finicial applications. This infrastructure is designed to be accessible to anyone with an internet connection, regardless of location, identity, or wealth.
DeFi has many advantages compared to centralized finacial systems, including:
- improved security and resilience thanks to its decentralized infrastructure
- Absence of fees like that of banks and other finicial institutions
- Increased transparency
- Greater access to financial services for unbanked individuals
What's been built in the DeFi space already?
Lending and borrowing
Anyone can borrow or lend digital assets using decentralized lending and borrowing protocols. You can connect to lenders and borrowers directly, without having to provide funds or personal information to an intermediary.
MakerDAO is one of the most popular protocols in this space. The protocol allows users to collateralize digital assets and then borrow against them.
Liquidity providing
Liquidity providers (LPs) earn fees by supplying money to decentralized exchanges like automated market maker (AMMs). LPs provide this liquidity by holding an equal value of two different assets in a "liquidity pool".
LPs are rewarded with a portion of the trading fees that are generated when users trade the assets in the liquidity pool. Pancakeswap and Uniswap are two of the most popular protocols for liquidity provisioning.
Asset management
Asset management protocols integrate with a variety of DeFi projects to automate the task of constantly tracking investments for price movements, rebalancing, liquidations, and rate changes. Yearn.finance is a protocols that provides "smart vaults" for digitial assets. These vaults automatically invest user's fund in the highest-yielding protocols and strategies, so that users can earn the maximum possible return when yield farming (using DeFi to earn interest on digital assets).
Potential for growth in DeFi
One area of finance that can be improved by DeFi is the derivatives market, which is estimated to be worth over $1 quadrillion-10x the size of the global stock market.
The DeFi derivatives market has only just begun to take off, with dYdX leading the way. The Total Value Locked (TVL) in the DeFi derivative market currently sits at just over $3 billion. While this may not sound like a lot, this is a growth of roughly 200% in just a few years.
With the launch of new protocols and platforms, we can only expect this growth to continue. It's not hard to imagine that the DeFi derivates market could one day be worth trillions of dollars.
Lesson 2:How Does DeFi differ from traditional finance?
Decentralized Finance can empower the globe with more accessible and transparent transactions.
Defi simplifies finance by removing middlemen. With fewer intermediaries, DeFi is more transparent, censorship resistant, and faster to innovate. This marks a significant departure from the traditional finance landspace and centralized systems that have prevailed for decades.
The challenges of traditional finance
Our traditional financial systems have a few garlings problems. They have geographical restrictions, scrict requirments of use, and limit innovation to a few chosen players. Going into the bank is easy for some and difficult for others, all depending on where you live. This problem is exacerbated in rural areas around the world.
Traditional banking and finace also often involves centralized credit checks and complicated documentation. This can make accessing funds inaccessible to people who may have had a challenging financial situation, struggled with credit, or who don't have the necessary paperwork. In this siloed model, innovation and collaboration is not incentivized, and that just makes things harder for all of us.
How DeFi changes the game
DeFi is all about giving everyone a fair shot at financial services. It stands for Decentralized Finance - basically doing everything the traditional finance system could, but without centralized intermediaries. With a well-executed decentralized system, we can borrow, lend and trade assets without needing banks, middleman or other larger financial institutions. This is a big deal because it helps level the financial playing field for anyone who has an internet connection to manage their money and be part of an equitable system.
A more accessible system means more innovation
Because more people are able to transact and access the financial system, we're much more likely to see creativity and innovation from people around the world. Think of it like the open-source web develpent community: free and easy access to codebases and repositories means more developers collaborating and more developers building and improving exisiting libraries. Just like closed-source codebases, traditional finance technology will only eveolve as fast as the owner of governing organization chooses.
Transaction transparency
DeFi systems are resistant to censorship because transactions are recorded on public blockchain. Transactions are visible to everyone, which increases transparency and reduces the potential for fraud. Conversely, traditional financial systems lack this level of transparency, transactions and accounts can be subject to censorship based on regulations or decisions made by authorities. These factors make it more likely for participants in traditional financial systems to encoutner hidden fees and fraudulent activities.
Risk and Accountaility
Traditional finance relies on credit checks and extensive documentation to mitigate risk. In DeFi, some of that risk is held by the account owner because they must secure their own accounts, or trust another entity with their funds, and most entities like that do not have the same protection banks do.
Lesson 3: Trading value on the XRPL's decentralized exchange (DEX)
Key takeaway:
- The XRPL was the first blockchain to feature a built-in decentralized exchange.
- You can make offers to trade any type of token without a middleman.
- Autobriding and pathfinding let you find better deals by finding trades with multiples tokens in a row.
Swap what you have for what you want
Just having tokens isn't very useful unless you can trade them. Luckily, the XRP Ledgeer was the first blockchain to feature a built-in decentralized (DEX). This means you can trade XRP or tokens without having to send them to a centralized exchange.
The XRPL DEX is trustless - you don't have to worry about losing assets to hacks or thefts. The DEX is also non-custodial, meaning that you retain full control of your assets at all times.
So, what can you trade on the XRPL DEX?
You can trade any asset that is held inside your XRP wallet, including, but not limited to:
- XRP
- Issued Tokens
- Stablecoins
Example: you have a learning club and decide to tokenize memberships
This means you will exchange a one hour session for 1 LEARN token. You only want to trade LEARN tokens for USD but you receive an offer to purchase the membership with tokenized gold. The XRPL is able to facilitate this transaction using 'auto briding' or 'pathfining'.
Auto bridging uses XRP as an intermediary asset to find the best exchange rate. This is most helpful when an asset does not have enought liquidity to transact at competive rates.
Pathfinding uses a series of assets to "hop" from one currency or form of value to another, finding the best path with the best route to go from one form of value to the other. For example, if a seller wanted to trade their XRP for tokenization gold, pathfinding may find the best solution is to first trade XRP for USD, and then trade that USD for tokenized gold.
'Bids' and 'asks'
Just like with a centralized exchange, the XRP DEX uses 'bid' and 'ask' system.
- Bid: A buyer can specify a price they want to buy at or below
- Ask: A seller can specify a price they want to sell at or above
Example: Let's assume the currecnt price of XRP is $0.50. If a seller wants to sell their XRP for $0.60, they would place an ask order at $0.60 on the DEX. If a buyer wanted to buy XRP for $0.40, they would place a bid order at $0.40 on the DEX.
All bids and asks for each asset are tracked in an order book on the XRP ledger. This feature improves market transparency and allows you to quickly see the best prices available for each asset.
Additional resources
Lesson 4: What is an Automated Market Maker? (AMM)
AMM's speed up transactions through their usuage of the constant function formula and readily-available currency within liquidity pools.
Key takeaway:
- AMMs make finding an exchange rate simple by calculating a fair price automatically.
- Anyone can add to the big pools of money AMMs use to trade.
- EVM chains usually implement AMMs with smart contracts.
What does Automated Market Makers (AMM) do?
Automated market makers (AMMs for short) are systems that let you exchange assets without needing middle men. Each AMM holds a pool of two assets and enables users to swap between them at an exchange rate set by a formula. They're the most comon way to impleent a decentralized exchange to allow everday traders to exchange assets of various sorts for fair rates. The main alternative to AMS are Central Limit Order Books (CLOBs) which we'll talk about more in the next section. (Fun fact, the XRPL currently uses a CLOB, but is proposing adding AMMs as well!)
How Do AMS work?
At its heart, an A works by pooling two tokens together in a pair of liquidity pools. Once enough currency is pooled together, the AMM automatcially picks a fair exchange rate between the different currencies. AMM's figure out the fai exchange rate with a powerful formula called a "constant function formula" which tries to model the price that a traditional market would discove on its own.Liquidity pools are handy for two reasons. First, because the prices are chosen automatcially, everyday token holders can contribute without having to know what a "fair" exchange rate it. They're also useful because they can provide constant liquidity as the pool is always willing to trade. Think of it like the exchange rate that is always available at your bank.
Automated Pricing and Continous Trading
As people trade within the pool, the AMM's algorithm adjusts the price of the assets to keep everything in balace. If one asset is in hight demand, it's price goes up, and the other asset's price drops. This algorithm uses the constant function formula to keep things in balance.
- Sets a price that follows supply and demand for the various tokens. If there's a large supply of a token, exchanging for it will be easier. Conversely, with small amounts of a token in the liquidity pool, it will cost a lot to trade for the remaining tokens.
- On the demand side, trading more of a token at once is more expensive. You can think of the price updating automatically as you buy more and more of the token, reducing the supply as you go.
How does the XRPL order book differ from a typical AMM?
A traditional order book system functions differently than an AMM, which relies on math formulas to leverage the liquidity pools in commpleting a trade. In the Order Book, trades occur when buy and sell orders match, allowing for more specific pricing, but can struggle to discover a fair market price if there are few traders. Trades on the Order Book happen when a buyer's bid matches a seller's ask while an AMM executes trades instantly based on the current formula-based prices.
In the next lesson, we'll dig into the order book on the XRPL and explain how it works.
Lesson 5: Order Books and the XRPL
An efficient order book paves the way for a functional DEX
Key takeaway:
The XRP Ledger (XRPL) stands out for its built-in order book, making it an ideal choice for real-life trading.
Order Book Basics
In the last lesson about XRPL's DEX, we talked a bit about how the XRP ledger uses a central limit order book (CLOB) to trade digital assets. The order book is essentially a list of offers from traders to buy or sell tokens for a specific exchange rate. These orders are then sorted, and if there's another trader who would be happpy to take that deal, the orders will "cross" and the assets will be exchanged. These offers can include XRP, or any other issued tokens representing various real-world assets.
The real value of an order book comes when there's a large volume of traders. Then it becomes very easy to go from assets you have to assets you want for a fair exchange rate. This is often referred to as having "high liquidity" because assets can easily be traded. Exchanged, like central limit order books or automated market makers, form the bedrock of DeFi as a large portion of finance relies an easily being able to trade assets.
Why is trading on the XRPL a little different than on other blockchains?
The order book was built-in from the beginning
The XRPL was originally built to enable the internet of value - a way to move value as easily as data moves on the internet today. As part of that, XRP was intended to be a "bridge currency" to connect all sorts of real world assets using the built-in central limit order book DEX. In the same way you can translate between most languages by translating through English as an intermediary, as long as you have an exchange rate to XRP, you can trade any two assets using the DEX.
In order to make that work, the DEX had to be very efficient. Since it has been a first class feature since Day 1, there's been over a decade of optimization to enable the XRPLs DEX to handle the transaction volume we see today. The XRPL is one of the few chains to use a central limit order book rather than an automated marker maker (and is actually in the process of proposing to use both!). Other chains often implement their DEX's via smart contracts which can make it harder to manage the state and computations involved in order a central limit order.
Beyond the order book, why is the XRPL good for DeFi?
The XRPL is fast and cheap.
Low fees and fast transaction settlement are two large benefits of the XRPL's Consensus Algorithm. Because validators don't receive rewards from transaction fees, the fees are incredibly low - usually less than a hundreth of a penny. Additionally, since the network does not have to use computation effort to prove trust like in proof-of-work, transactions can settle very quickly (usually in less than 5 seconds).
These fast transaction speeds on the XRPL are a great compliment to the built-in order book for facilitating real-time trading. Higher volumes of trades can pass through the ledger, which is essential for keeping prices up to date, especially during periods of high trading activity.
You can easily trade assets by turning them into tokens.
You can tokenize a new asset on the XRPL with a single transaction. By tokenizing an asset, you gain access to the fast settlement, broad trading options, and low fees the XRPL is known for just by creating an offer against XRP. Auto-bridging, which will be explained in more detail in the next lesson, takes care of the rest. The more different types of assets that we can trade, the more liquidity we have and the more useful the exchange can be.