Today we published the sixth video in our Titanoboa Llama Lend tutorial, a detailed recap of how to perform self-liquidations.
The tutorial in its current state covers most of the important concepts for getting up and running with Titanoboa.
However, there are still more advanced methods of performing liquidations using Llama Lend yet to cover, including extended liquidations and using Flashlender.
Since it takes quite a lot of time to put these videos together, we donβt want you to have to wait several months for learning more about Flashlender. Especially because itβs getting presently getting discovered by searchers.
Hence, this article is going to walk through some examples of Flashlender in the wild, and how it could be plugged into Llama Lend liquidations.
Flashlender
This weekend saw the first use of the crvUSD Flashlender contract to perform a low value arb trade.
The crvUSD Flashlender contract is authorized to lend out up to 1 million worth of the Curve stablecoin completely free, provided its use is fully repaid within the same block. This can be used for performing arbitrage trades (like the following example), but would be more useful to the ecosystemβs health for performing liquidations (the second example).
For either case, itβs a great way to earn money onchain without needing to hold onto a million in spare crvUSD.
Did we mention, zero fees! So what on earth might be scaring you off?
Well, hereβs what a typical transaction looks like:
And thatβs before we scroll to see moreβ¦
Looks complicated, but the Eigenphi transaction visualizer helps demonstrate exactly whatβs going on.
It still looks complex, but once you learn how to follow the flows in numerical order it becomes easier to figure out whatβs happening. With Eigenphi, get started by finding the boxes with the human icons (upper right corner):
From there, you can follow the arrows in numerical order to trace all the action the smart contract is executing. For simplicity sakes, weβll dub this smart contract βThe Executorβ as we summarize the remaining transactions.
As is common with contracts deployed to help single-block transactions, the Executor does not have verified source code to review.
TX 0:
This contract starts by pinging the crvUSD FlashLender. For flashloans, the entire sequence has to end with the contract repaying all the money it takes in a single block, otherwise the transaction will revert.
Big shoutout to Ivan from Curve for all the work on FlashLender, which you can find in the Curve Github repo.
In this example transaction, the sequence kicks off in which the Executor requests and receives 1063.4087 crvUSD from the Flashlender, and (SPOILER ALERT) by TX 14 it sends back the 1063.4087 crvUSD back, otherwise the entire sequence would revert.
TX 1:
The 1063.4087 $crvUSD is sent from the Executor to Augustus, a set of smart contracts that perform routing through DEXes
TX 2-4:
Augustus routes the crvUSD through a Curve pool to convert 1063.4087 crvUSD into 1062.4115 USDC, which is returned to the Executor. The USDC is needed in this case because the sequence is performing an arb of USDC.
TX 5:
The USDC is wired from the Executor contract into another contract with no published source code which weβll dub as a Helper contract.
TX 6-7:
The Helper contract trades the USDC into WETH through a Uniswap pool, returning .4658 WETH for 1062.4115 USDC. This is the crux of what the sequence has identified as an arbitrage opportunity.
TX 8-11:
The Helper contract unwraps the WETH and trades it through the TriCRV pool for 1063.7180 $crvUSD
TX 12-13:
The balance of $crvUSD is returned to the Executor contract
TX 14:
As we spoiled at the outset, the loan is repaid.
But, there is 30 cents leftover in the Executor contract!
TX 15:
The bonus 30 cents is returned to the caller, pure profit! Thirty cents from a $1000 flash loan!
Not bad for a dayβs work.
Now letβs look at gas costs andβ¦ woof!
OK, gotta spend money to make money, amirite?
Liquidations
Why care about a flashloan? Well, performing $crvUSD hard liquidations can easily make you more money. But you sometimes need enough money to trigger a liquidation. So, a flashloan can make it easy for anybody without needing to have capital sitting idle.
All you need to do is hook the flashlender up to a liquidation engine. Consider the work of xtycoon:
The README succinctly describes the steps
This repo points to a sample Arbitrum transaction that performs a liquidation using a flashloan. Itβs a great repo, except it mistakenly states that thereβs a fee to use the $crvUSD flashlender. Did we mention, itβs completely free!
The repo links this sample transaction, which doesnβt use Flashlender but instead trades manually for the crvUSD. Weβll again walk through the Eigenphi visualizer, so you can see how easy it would be to plug in the Flashlender instead:
Donβt worry, remember itβs easy! Start by finding the FROM and the TO addresses and follow it from there numerically.
TX 0:
The sequence starts with the Executor contract taking out a flashloan for 9.9846 USDC using the Balancer flashloan vault.
This works the same way as the crvUSD flashlender, except it is denominated in USDC. This adds a very small amount of complexity to the overall sequence, in that you need some extra routing to convert this USDC into crvUSD.
TX 1-3:
Some of the βextra complexityβ caused by having to start from USDC instead of crvUSD. In this case, the 9.9846 USDC is traded through Curve and Odos, resulting in 10.0165 crvUSD wired to the Executor contract
TX 4-6:
9.7411 crvUSD is used to perform a liquidation. When combined with the 10.3226 crvUSD in the AMM (from collateral conversion via soft liquidation) the loan is repaid in full, and .0046 WETH is returned to the Executor.
TX 7-10:
The WETH is sent back through Odos to be converted into 10.8575 USDC
TX 11:
9.9846 USDC is repaid.
TX 12:
But waitβ¦ thereβs 0.8729 USDC leftover here! This gets transferred back to the user.
Not too shabby for a dayβs work. Plus this was on L2, where gas is cheaper, right? So letβs just sit back and tally our profitsβ¦
Woof⦠$2.89?
Well, as proof of concept transactions, pretty good. Perhaps itβs the sort of transaction that slick-talking MEV bot operators can perhaps sweet talk some nodes into executing at a discount.
Hopefully this shows off how Flashlender and Liquidations can be performed in tandem. If you have any questions, please hit us up anywhere in public or any of Curveβs social channels!