Flash loans are an incredible development. They allow you to borrow as much funds as available within a certain pool and do whatever you want with them, as long as you fulfill one special condition — you need to return the full amount within the same transaction. In case you don’t, everything you attempted within the transaction will fail and revert, like it never happened.

Some argue flash loans are no good and shouldn’t be a thing, probably influenced by recent exploits we witnessed. But we feel the truth is they only level the playground, making any exploitable points accessible to anyone, rather than just the whales. And, what’s more, they enable some very cool things, so let’s talk about those.

1-transaction CDP closing powered by flash loans

The idea of one-tx CDP deleveraging (sometimes also called self-liquidation) is that you get to pay back all of your debt with the collateral contained within the CDP, effectively closing the collateralized debt position. This mechanism could be used either as a stop-loss, to prevent the need to continuously unwind one’s position (i.e. Repay) during a downward market trend, or as a way to close the position and collect profits after a bull run, the choice is up to you and the market gods.

The exact steps for closing a CDP with a flash loan are as follows:

Take out a DAI flash loan equal to current CDP debt Pay back DAI CDP debt using that DAI Withdraw ETH/BAT from the CDP Convert required amount of ETH/BAT using a DEX to DAI for flash loan debt Pay back DAI flash loan debt Withdraw remaining ETH/BAT to account

And if you look at the screenshot of all the token transfers that happen during this process, you can probably recognise most of these steps, all of which are completed within the same transaction:

Closing a CDP using an Aave flash loan.

But you don’t have to bother too much, because this option is available as a single transaction feature in the DeFi Saver MakerDAO dashboard starting today.😎