What is Decentraliced lending/borrowing?
Decentralized lending/borrowing is implemented through smart contracts that let users lend or borrow digital
assets at fixed or variable interest rates.
In other words, the aim is similar to commercial bank deposits and loans.
However, there is no central counterparty to decide who can make a deposit, who take a loan or what the deposit/loan terms would be.
As a result, there is no need for maintaining credit histories or other financial records of depositors and borrowers
Anyone can lend their assets and earn interest in crypto
Anyone can borrow crypto against deposited collateral
What is the aim of decentralized products and why?
Removing intermediaries - that aims at enhancing the efficiency of capital allocation, cutting costs, eliminating exclusion and increasing economic privacy and freedom.
Comparing DeFi/TradFi Lending and Borrowing
What is the difference to TradFi?
TradFi lending can be undercollateralized – but at a cost
In exchange for providing loans, TradFi lenders usually require:
Some reward, typically in the form of interest rate (which, in turn, reflects the creditworthiness of the borrower).
Some insurance that the money will be repaid, typically in the form of collateral, credit history checks and KYC.
TradFi lenders can also make borrowers repay by law.
For these reasons, lenders can provide undercollateralized or even unsecured loans: loans where the value of the collateral is less than the value of the loan (or even zero).
To cover the additional risks/costs for lenders, interest rates in TradFi are typically high.
But what about DeFi lending, where no legal, credit history or KYC processes are typically applied?
DeFi loans are normally overcollateralized
In pseudonymous, permissionless & open finance, it would be reasonable to assume that if the value of the collateral fell below the value of the loan, there would be no incentive to pay back the debt.
This is known as moral hazard
To mitigate this, DeFi loans are typically overcollateralized
In other words, a borrower can only borrow less money than the value of their collateral.
If the value of the collateral later falls below the outstanding value of the loan, the collateral will be (partially or wholly) liquidated, i.e., sold in the open market to repay the lender.
No moral hazard; no need for KYC, credit history checks or calling the authorities
DeFi: Why would someone want to borrow (and pay interest), when the value of the loan
is less than the collateral they already possess?
Collateral includes volatile assets (e.g., crypto) whose value fluctuates. To maintain exposure to the asset's volatility while needing liquidity, it makes sense to use it as collateral and borrow a portion of its value, while retaining ownership of the asset.
Increasing the leverage by increasing the deposited crypto security
What is the risk using DeFi lending/borrowing?
If the price of the collateral goes down and surpasses a certain threshold, the DeFi lending protocol will start liquidating (part of) the collateralas. This is connected to pretty high liquiditation fees.
What is LTV and what does it stand for?
Loan-to-value (LTV) ratio defines the degree of (over)collateralization
LTV defines the maximum amount that can be borrowed against specific collateral.
For example, an LTV of 75% means that someone would be able to borrow 0.75 ETH worth of the lent currency (say DAI or USDT) for every 1 ETH they post as collateral.
Naturally, since ETH is a volatile asset, the LTV will evolve with market conditions after the loan is taken.
What is LT and what is the role in the lending/borrowing process?
Liquidation Threshold (LT) defines when loans are auto-repaid
LT is the LTV level at which the lending platform (smart contract) deems the loan to be undercollateralized.
For example, an LT of 90% means that the loan is considered at-risk (unhealthy) when LTV goes above 90%.
Once LT is reached, the smart contract will automatically liquidate the loan.
Some platforms might liquidate all the loan, while others might liquidate only the portion needed to bring the LTV down to an acceptable level.
Liquidated loans are typically sold to liquidators at a discount.
What means Leverage in DeFi loans, what are the advantages and risks?
Borrowers may use DeFi loans to buy more of the asset they have provided as collateral to achieve multiplicative returns (indirect leverage) – of course, at a much higher risk.
Consider the following scenario (assuming no interest paid, transaction costs, or slippage):
Alice holds 1 ETH, currently valued at $1,000. She deposits it as collateral to a DeFi lending platform with an LTV of 75% and borrows $750 worth of DAI.
She then swaps her DAI for ETH. She receives 0.75 ETH as a result.
She now holds a total of 1.75 ETH – of course, she still needs to repay her $750 loan
If the price of ETH was to increase by 10%, her holdings would be worth 1.75x$1,100=$1,925-$750 (which she must repay to the protocol)=$1,175. This is $75 more than if she had simply held on to her 1 ETH.
Of course, by the same logic, if the price of ETH decreased by 10%, she would lose $175, instead of $100 (in practice, she would lose even more, considering the risk of liquidation).
Alice has effectively used leverage through dBorrowing:
Leverage is the use of debt to amplify returns (and losses) from an investment – not advisable for novice investors or in the case of highly volatile assets
What are reasons for dBorrowing & dLending?
For lenders:
Receive yield on otherwise unused assets.
For borrowers:
Maintain exposure to volatile collateral, while receiving liquidity
Use leverage
For lenders and borrowers:
Receive additional rewards from DeFi platforms (typically in the form of the platform’s governance token)
(depending on the jurisdiction) delay paying taxes on crypto transactions
What are flash loans?
Flash loans are special blockchain transactions that allow someone to borrow an asset without posting any collateral, if they return the asset (plus interest) within the same block (hence, the term ‘flash’). They are also sometimes called ‘one block’ loans, as everything (loan initiation, use and repayment) happen within the same block of transactions in the underlying blockchain.
Why are flash loans special in regards to TradFi?
Flash loans exist only in DeFi and cannot be replicated in TradFi
How are flash loans even possible?
Flash loans take advantage of the deterministic (vs. probabilistic databases) nature of blockchains and smart contracts.
This means that an action can be programmed to either occur in its entirety or not at all.
So, one block loans can occur with the certainty of being repaid, thus eliminating counterparty risk.
What is decentraliced lending/borrowing and how does it work?
Decentralized lending/borrowing is implemented through smart contracts that let users lend or borrow digital assets at fixed or variable interest rates.
What is the basic logic of flash loans?
The basic logic of a flash loan is simple:
A smart contract calls the dLending platform contract, requesting a flash loan of one or more pool reserves.
The pool transfers the reserves to the calling contract, which proceeds to do whatever it wants to do with them.
The calling contract approves the return or reserves plus interest to the platform pool(s).
If the repayment amount is not available for whatever reason, the whole transaction reverts and is never published on the blockchain (i.e., the initial transfer of funds never actually takes place).
What are use-cases for flash loans?
Flash loans are typically used for:
Arbitrage: exploiting price differences between assets (buying low and selling high), without needing to have the high capital amount required to execute the arbitrage. This use has the added benefit that it contributes to more efficient markets and price discovery.
Liquidity swaps: instant swapping of liquidity between pools of different versions of the same dLending/dBorrowing platform.
Collateral swaps: swapping between collaterals posted for loans, while avoiding high fees and multiple transactions.
Self-liquidation: liquidating own positions before liquidators step in and claim additional liquidation fees.
Speculation: exploiting vulnerabilities of identified decentralized system
Example of flash loan for arbitrage
A flash loan for arbitrage:
Bob spots a discrepancy in the exchange rate of wBTC/ETH in two decentralized exchanges: 1 wBTC trades for 20 ETH in DEX1, while it trades for 21 ETH in DEX2
There is an obvious arbitrage opportunity: buy wBTC in DEX1 and sell it in DEX2. But, Bob lacks a large amount of ETH capital required.
Bob requests a flash loan of 100 ETH. He uses it to buy 5 wBTC in DEX1, which he immediately proceeds to sell for 105 ETH in DEX2. He then repays the flash loan of 100 ETH and pockets 5 ETH (minus transaction fees and interest).
What are CEXes?
Centralized exchanges (CEXs) are markets where financial assets can be bought and sold.
Stock exchanges like the New York Stock Exchange (NYSE), Nasdaq, the London Stock Exchange (LSE), etc.
Cryptocurrency exchanges like Coinbase, Binance, Kraken, etc.
We also refer to centralized crypto exchanges as CeDeFi
All exchanges are intermediaries.
They provide a platform for matching buyer and sellers.
In practice, multiple layers of intermediation may exist
Most market participants (especially retail) do not trade in the market directly, but through a broker.
Brokers buy and sell financial assets on behalf of their clients for a fee.
They may also serve as financial advisors.
What services do CEXes offer?
Centralized cryptocurrency exchanges offer mediation services at many levels. They can be:
A platform for matching buyer and sellers.
A broker that places orders on behalf of clients.
A liquidity provider that maintains pools of assets to be traded in the market.
A custodian for storing user assets.
A portfolio manager by providing information and advice to clients.
An underwriter in Initial Exchange Offerings (IEOs) or other types of token launches
By serving so many roles, cryptocurrency exchanges may be even more centralized than their traditional counterparts!
What is CeDeFi?
CeDeFi, or Centralized Decentralized Finance, combines traditional centralized financial services with decentralized applications, bridging conventional regulatory measures with modern financial products and infrastructure.
E.g. a centralized exchange (CEX) offers staking, which is a decentralized service
What is a DEX?
Decentralized exchanges are smart contracts that mimic CEX functions
A Decentralized Exchange (DEX) is a decentralized application (dApp) that uses smart contracts to enable anyone to perform token swaps (buying/selling tokens in exchange for other tokens) without the need of a central mediating party.
In other words, a DEX allows its users to trade in a peer-to-peer manner, eliminating the the need for intermediaries (brokers, market makers, custodians, underwriters, etc.)
Decentralized exchanges allow for:
Self custody
Composability & interoperability with other DeFi Applications
less transaction costs
Examples:
What are order books?
The basic notion on which a CEX operates is that of an order book
Conversely, a DEX will typically rely on liquidity pools and automated market makers
To understand the difference, let’s first explain what an order book is.
An order book collects the volume of all buy (bid) and sell (ask) orders for an asset.
The current price of the asset is determined by where bids and asks meet (are matched).
Order books are effective in liquid markets as they minimize slippage (the difference between the expected and actual price of a trade).
CEX liquidity is provided by market makers (MMs), whose job is to maintain a stream of bid and ask orders in the book
Why can’t a DEX be using order books like a CEX to run?
Abandoning orders would require on-chain transactions that cost gas fees.The same would apply to order cancellations.
As a result, on-chain orders would become very expensive
Especially for market makers (MMs) and high frequency traders (HFTs).
Since MMs/HFTs are important for efficient market operations, a DEX with an order book would likely be illiquid.
Illiquidity leads to high slippage, lost trades, and inefficient price discovery
These problems would be exacerbated by the time delay created by block confirmation times
Transactions must be confirmed on the blockchain, which, among other things, opens up the possibility for frontrunning tradesTranslated with DeepL
On what mechanism is a DEX running?
Liquidity Pools (LPs)
A liquidity pool is a reserve of funds held in a smart contract.
LPs are one of the foundational mechanisms in DeFi
They are essential, not only in DEXs, but also in dLending/dBorrowing, synthetic assets, insurance, etc.
LPs aim to overcome the liquidity trap in decentralized trading by always ensuring sufficient liquidity
Bancor was the first protocol that utilized LPs, but they were popularized by Uniswap.
Other popular DEXs that use LPs are Curve (multi-blockchain), Pancakeswap (BSC), Balancer (Ethereum), etc.
In LP-based DEXs, anyone can become a market maker by providing liquidity for a token pair
This also means that there are no listing requirements, such as those found in CEXs
What are the different Types of AMMs?
There are many different AMM algorithms:
Constant Product Formula (CPF)
Constant Sum Formula (CSF)
Constant Mean Formula (CMF)
Hybrid formulas
Each comes with its own advantages, disadvantages and suitable use cases.
In all cases, the underlying logic is to provide a programmable, deterministic model for asset pricing.
What is the CPF AMM?
The Constant Product Formula (CPF)
CPF is the most widely used AMM algorithm, pioneered by Bancor and Uniswap: k = x * y
Where x and y are the reserves of each token in the LP; k, their product, must always remain constant
Assuming no transaction fees, all trades change the balance of tokens reserves so that their product (k) remains unchanged. In practice, each trade increases the k slightly – proportionally to the transaction fee and the amount traded.
Pros:
CPF ensures sufficient liquidity for a trade, as when the quantity of an asset approaches zero, its price approaches infinity.
Cons:
CPF can result in high slippage for traders and impermanent loss (IL) for liquidity providers
Example:
Suppose an ETH/DAI LP, with total reserves of 10 ETH and 15,000 DAI (assuming 1 ETH = 1,500 DAI – remember that the total token values must be balanced).
Now imagine that you wanted to swap DAI to receive 2 ETH. How much DAI would you have to pay?
The initial k of the LP is 150,000 (k=x*y=10*15,000)
This value needs to remain constant after your trade
The new amount of ETH in the pool would be 8 (you have taken away 2 ETH) and the new amount of DAI would be 15,000+z (where z the amount of DAI you paid to receive 2 ETH).
So, 8x15,000+z must be equal to 150,000 or z=3,750.
In other words, you would have to pay a total 3,750 DAI for 2 ETH, or 1,875 DAI per ETH.
Your trade in this (very illiquid) pool would result in a big difference in the new price of ETH (1 ETH=1,875 DAI) compared to other markets (where ETH would continue to trade at 1,500 DAI). This would attract arbitrageurs who would lower the price again by selling ETH to the pool until there was no more difference.
What is the CSF AMM?
The Constant Sum formula (CSF)
CSF satisfies: x+y=k (where x, y the token reserves and k (their sum) needs to remain constant)
Pros and Cons:
It is suitable for tokens with the same price
No slippage
Arbitrageurs would drain the LP if there is a price
difference between the DEX and other exchanges
What is the CMF AMM?
Introduced by Balancer, as a generalization of the CPF to allow
for more than two assets and not be restricted to a 50/50
distribution between them
CMF satisfies:
where Ri are the reserves of each token, w is the weight associated with each, and k
needs to remain constant
What is IL and why is it imporant?
Liquidity providers face impermanent loss (IL) when supplying LPs
Impermanent Loss (IL) is the loss caused to a liquidity provider due to the price volatility of the tokens they provide to an LP
IL is essentially the difference between providing tokens to an LP vs holding them
The more volatile the tokens, the higher the exposure to impermanent loss
Why ‘impermanent’?
While the liquidity provider keeps their tokens in the LP, they face no loss. The loss is realized when tokens are withdrawn. The amount of loss depends on the price difference between deposit and withdrawal
If the exchange rate between the tokens is the same, there is no loss
If the LP chooses to withdraw their funds when the exchange rate is different, the impermanent loss is realized and becomes permanent
Impermanent loss can be mitigated by supplying stablecoins, opting for one-sided liquidity pools, and by participating in uneven (weighted) pools.
Consider the ETH/DAI LP with an initial balance of 10 ETH and 15,000 DAI by a single liquidity provider. The total value at stake is $30,000 at the time of deposit.
Now, suppose that the price of ETH increases to $1,600. This would incentivize arbitrageurs to buy the “cheaper ” ETH in the pool until it there is no price discrepancy.
They would be able to buy ~ 0.32 ETH in exchange for ~496 DAI before the price of ETH in the pool reaches $1,600 and is at equilibrium with the market (you can calculate this through the constant product formula).
The LP would still realize profits, but not as much as if they simply held the tokens.
With IL at hand, why are the benefits of providing LPs?
DEXs compensate providers in various ways:
at minimum, they charge a transaction fee for each trade (which goes to liquidity providers, proportionally distributed)
Additionally, they may reward liquidity providers through DEX governance tokens (also in the form of airdrops) and other more complex reward mechanisms
Yield Farming (YF): refers to a techniques that liquidity providers may use to maximize the yield earned through providing tokens to DEXs, dLending/dBorrowing platforms and other DeFi protocols.
Risks of DEXes?
Hacks and Exploits:
DeFi protocols are as secure as the code that supports them. That is typically code on the application/protocol layer of the DeFi stack, but risks may also exist in the settlement/asset layers.
Settlement level exploits refer to security flaws of the blockchain where the DeFi application is deployed. While this kind of exploits is rarer, it the most critical (as it affects all DeFi protocols on a particular blockchain).
Protocol and application exploits refer to security flaws of the smart contract or web interface of the DeFi app. Such exploits can be mitigated to an extent through security audits.
Admin Key Risk:
It refers to the risk that the DeFi protocol owner(s) will modify the protocol in a way that will benefit them, at the expense of the users.
It can be mitigated through multi-signature deployments and by employing a DAO governing protocol updates
Price Slippage:
Slippage refers to the difference between the expected and actual price of a trade. It is highly related to the volume of a swap against the depth of liquidity in a DEX pool.
There is a positive relationship between the size of the order and slippage: the larger the order, the larger the price slippage that a trader will have to face.
There is a negative relationship between the size of the pool and slippage: the larger the pool the lower the price slippage: It can be mitigated by setting slippage limits (at the risk of the trade not being executed).
Front-running:
DEX transactions are visible to everyone before they settle on the blockchain. Bots are continuously monitoring unconfirmed transactions for profitable opportunities.
When they identify one, they submit the same transaction, but with higher fees. As miners want to maximize their profitability, they are incentivized to confirm the bot’s transaction first.
Then, the bot will either offload the newly acquired tokens to the user (trade executed at less favorable price) or simply cause the user ’s transaction to fail.
Vampire Attack:
It involves draining liquidity from a DEX by incentivising liquidity providers to move their liquidity to a competitive DEX
Rug Pulls:
Refers to the act of maliciously removing liquidity from a pool to leave users holding tokens with no utility or value.
Can be more effectively executed with thinly traded tokens.
It is also common for malicious actors to create clone tokens to trick users into thinking they are trading legitimate ones. This can be mitigated by confirming the address of the token being traded.
Oracle Manipulation:
DeFi protocols rely on oracles to receive information from the real-world. In the case of DEXs this information usually relates to token prices. There is the risk that either the oracle goes bad, or its data is manipulated.
This can be mitigated by applications relying on reliable oracles or a plethora of oracle solutions.
What are Synthetics in the TradFi world?
Futures contracts are standardized versions of forward contracts traded on exchanges:
A forward contract is an agreement to buy/sell of an asset at a certain time in the future for certain price
Options contracts are like futures, but the option holder is not obligated to exercise the agreement to buy or sell:
Instead of a requirement, options can be seen as an opportunity to buy or sell at a specific price (the strike price) at some point in the future (the expiry date)
Swaps are agreements to exchange cash flows in the future:
Typically, interest rates or currencies
Derivatives can be settled in kind (where the underlying assets really change hands) or in cash (where only profits/lots at contract expiry are settled between parties). Derivative contracts may also be tradeable: they can be bought/sold in the open market before their expiry date.
What are Blockchain Synthetic Products?
Decentralized derivative contracts use smart contracts and are deployed on blockchains
There are different types of decentralized derivatives types, including:
DEX-traded ‘traditional’ derivative contracts, like futures, options, and swaps. These are the equivalent of TradFi derivatives on blockchains.
Synthetic assets, which represent other assets (on-chain or off-chain ones) through tokens. These tokens derive their value from their underlying assets.
Wrapped tokens, which represent tokens in blockchains other than the blockchain these tokens were originally built for. They are typically 1:1 backed by their underlying tokens in a different blockchain
What are synthetic assets?
Synthetic Assets are smart contract-based derivative tokens
Synthetic assets are essentially tokens that represent customizable exposure to other assets:
They do so by creating a blockchain record of the relationship between the underlying asset and the synthetic token
This relationship is programmatically enforceable and verifiable
Theoretically, we can tokenize anything through such synthetic assets, including:
Real and financial assets, for example gold, stocks, and indexes
Digital currencies
Simple derivatives of cryptocurrencies, such as BTC futures, are NOT synthetic assets
While derivatives provide exposure to underlying assets, synthetic assets are tokenized representations of this exposure
Who can create synthetics?
Synthetic assets can be created by anyone and for anything
Anyone can create (mint) a synthetic asset by depositing (locking) collateral in the form of a token to a derivative platform.
Like decentralized loans, synthetic assets are typically overcollateralized.
The synthetic asset can then become tradeable on the blockchain, like any other token.
Oracles, algorithms, and arbitragers ensure that the price of the synthetic asset matches the price of its underlying asset(s).
What are wrapped tokens?
Wrapped tokens are synthetic tokens directly representing others
Wrapped tokens are a special case of synthetic assets.
They are also tokenized derivatives, but on a 1:1 value relationship with their underlying, which may exist in a different blockchain from its wrapped version (although not necessarily).
So, for example, 1 wrapped BTC (wBTC) on the Ethereum blockchain will be worth 1 BTC in the Bitcoin blockchain, as long as it remains exchangeable with 1 BTC.
Why do we even need wrapped tokens?
Different blockchains: so that we can use tokens across blockchains (for example, turning Bitcoin into an ERC20 token, wBTC, to use in the Ethereum network).
Same blockchain: for intra-blockchain compatibility purposes (for example, so that DeFi smart contracts can treat Ether, in the form of wETH, as an ERC20 token)
What does wrapping require?
Wrapping may require intermediary custodians
Wrapping typically requires an entity that holds the reserves of the asset that is being wrapped:
For example, someone should have custody of locked BTC on the Bitcoin blockchain while their 1:1 wrapped versions (wBTC) exist on the Ethereum blockchain
Custodians may be:
Centralized Entities
Decentralized smart contracts or dApps governed by DAOs
Wrapping is the process of depositing an asset to a custodian in exchange for a same amount of the wrapped asset.
After receiving the original, the custodian mints the same amount of the wrapped asset and sends it to the depositor, while locking the original.
The wrapped token can later be unwrapped or redeemed back for the original. This process burns (removes from circulation permanently) the wrapped version of the token and releases the original to circulation.
Last changed2 years ago