The DEX-Lending Loop: Why Decentralized Exchanges and Lending Protocols Are Each Other’s Most Important Infrastructure
Image source: ChatGPT
In decentralized finance, there’s a relationship that is discussed as if it’s between two distinct products, each serving a different use case. Decentralized exchanges are where to trade. Lending protocols are protocols for borrowing and lending yield. They are neighbouring, they may be combined, but they differ from each other in nature.
This framing is lacking in structural aspect. The decentralized exchange platform and the lending protocol are not just side by side, but they are linked in a way that makes each one more useful and makes them more dangerous if they were not there. Recognizing that this dependence is what makes DeFi so capital efficient, as it shows in its best moments, and how it fails when stress arises, even in predictable ways.
How the Loop Works
The first thing to note is the obvious fact that when DeFi protocols are composable, the same asset can accomplish more than one purpose.
A trader with the ETH can lock up his/her tokens in the lending protocol to serve as collateral. This deposit creates a lending position that they can borrow against without selling any ETH, in exchange for a stablecoin loan. They use that stable coin to deposit funds on another decentralized trading platform to purchase more ETH. This extra ETH is returned to the lending protocol as collateral, which leads to more borrowing, which leads to more buying. The trader’s exposure to ETH is further amplified with each loop around the loop.
This consists of leverage built with composable DeFi primitives and not a standalone leverage product. The DEX is where borrowed stablecoins turn into other asset overhang. It’s when the asset exposure turns into the borrowing capacity that the lending protocol kicks in. Just one of them is doing something new. They combine to form a circuit that generates results that neither could generate alone.
During stress, the same loop is reversed. As the ETH price drops, the collateral value decreases in the lending protocol. If it is below the liquidation mark, the protocol sells the collateral (sells it on the decentralized crypto exchange) to get the value of the loan back. Selling drives ETH’s price down — reducing more collateral values across the system — causing more liquidation, which leads to more selling on the DEX. The leveraged upside effect of rising prices yields the leveraged downside effect of falling prices.
The DEX as the Settlement Layer for Lending
The most apparent interaction between the DEX and the lending protocol is during the liquidation process. If a borrower’s collateral is lowered to below required ratio, the lending protocol must convert that collateral to stablecoins quickly so the lending protocol can get its money back. There is no internal market making mechanism. It is the decentralized trading platform.
The quality of the DEX’s liquidity at the time of the liquidation will determine a number of factors at once: how fast the protocol can recover its capital, how much slippage the liquidation will absorb and how much extra pressure the liquidation will place on the market. A DEX that has liquidity has a greater ability to take in big liquidations without affecting the prices much. A DEX with shallow liquidity is one where large liquidations become price-moving events that further liquidate, thus creating a cascade effect.
This is not a speculation; this is a real worry. During market stress, cascading liquidations are recurrently highlighting how critical liquidity of the DEXs in certain price ranges and asset pairings is to the stability of the lending protocols. The lending protocol that seems to be well-designed in quiet markets breaks down during times of peak liquidation when the DEX settlement layer simply cannot absorb the amount of liquidation without causing price action.
A decentralized trading platform that has deep liquidity for the asset pairs that are most frequently used as collateral in related lending protocols is offering a stability service to these protocols which extends beyond simply the trading volume. The DEX isn’t a place where traders exchange assets. It’s the place the lending protocol’s risk management comes into play when it must.
Cross-Chain DEX-Lending Composability
While the DEX-lending loop can be both profitable and risky on a single chain, it gets significantly more complex when both DEX activity and lending protocol activity is spread across multiple chains.
If a borrower wants to deposit their assets on a lending protocol as collateral, and then borrow stablecoins to invest in a token that isn’t offered by the protocol, but rather only on Solana, they need cross-chain infrastructure to complete the transaction. To swap tokens across blockchains, tokens are borrowed from Ethereum and then swapped on Solana, which requires a cross chain decentralized exchange to bridge the chains and to perform the swap on the destination chain as well.
The cross-chain composability is further intensified by the risk aspect. If the collateral is deposited on one chain and the DEX settlement layer for liquidations is on another, or if the best liquidation route goes through a cross-chain path, the speed at which the lending protocol can liquidate is limited by the latency and reliability of the cross-chain infrastructure. A liquidation that takes minutes as opposed to seconds, is a liquidation that can execute at a worse price with more residual bad debt that a same-chain liquidation would create for the protocol.
However, where the borrower’s portfolio is multi-chain, the liquidation settlement layer (the DEX used to swap collateral) should be on the same chain as the collateral, in order to address this problem. This design places high emphasis on the reliability of the liquidation without worrying about capital efficiency, but takes the advantage of having some capital pre-positioned on each chain instead of sharing them. However, as the collateral mobility infrastructure continues to mature, this will be less important, although it is a legitimate constraint at this point that the cross-chain DEX-lending composability must overcome.
What Flash Loans Reveal About the Loop
Flash loans are the most distilled form of DEX-lending composability, and the perfect example of what composable financial infrastructure can yield when its attributes are understood.
A flash loan is a loan that is taken for the time of a single transaction without giving any collateral, but the loan must be repaid before the transaction is completed. If payment has not been successfully returned, the whole transaction is cancelled as if it had never taken place. The blockchain’s atomic transaction model guarantees that the funds are always paid back before leaving the lending protocol’s control, making it a risk-free loan for the lending protocol.
In one transaction, an advanced user can perform several operations on several protocols: borrow, swap, arbitrage, repay, and make a profit from the difference in prices without investing any capital. The borrowed funds are exchanged for the borrowed assets in the DEX. The capital for the entire operation comes from the lending protocol. It’s the atomic transaction model of the blockchain that enables the entire system to operate without counterparty risk.
However, flash loan arbitrage and liquidation support rely on the same productivity of composability, with the potential for flash loan attacks being the dark side. The same qualities that can make the DEX-lending loop productive in its normal operation can make it exploitable if the design of the protocol does not consider the impact of atomic composability at scale.
What Traders and Liquidity Providers Should Take From This
The DEX-lending dependency means that it is not possible to judge either platform type alone without having other information about its actual risk and value.
Lending protocol is as good as the depth of liquidity on the DEX that enables it to fulfil its liquidations. Another stress test for a DEX with heavily concentrated LPs in pairs, who also act as the collateralists in related lending protocols, is a large liquidation event that will also lead to a liquidation of the DEX (selling lps) and a deep DEX liquidation (buying lps). Both effects act counter to one another.
The more productive loop is further extended from the cross chain crypto exchange that brings lending protocols from across chains, and there is added complexity in the risk picture. A new chain is a new environment where the feedback dynamics are realized, each has a different liquidity depth, a different architecture of oracles, and a different speed of settling the liquidations.
No one can articulate the opportunity or the risk in the DeFi ecosystem without taking a holistic view of the DEX-lending loop as a whole.
The DEX-Lending Loop: Why Decentralized Exchanges and Lending Protocols Are Each Other’s Most… was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this story.
