How Flash Loans Work in DeFi Lending: Atomic Repayment

How Flash Loans Work in DeFi Lending: Atomic Repayment


After spotting a price gap between two exchanges, you can use a flash loan to borrow from a DeFi lending pool without collateral, provided you repay the amount plus a fee in the same transaction. Blockchain transactions execute atomically: every step takes effect together, or none does. That rule lets the pool lend without taking collateral.

Atomic Settlement Lets Lending Pools Skip Collateral

A flash loan gives a contract temporary access to available pool funds. To see this pool model in a live protocol, explore SparkLend because its Ethereum money market offers flash loans alongside collateral-backed borrowing. Aave V3 also offers flash loans from its pools.

First, the pool sends the requested asset to the borrowing contract. The contract carries out its chosen actions, such as trades, then makes the borrowed amount plus the fee available for repayment. The pool checks repayment before the transaction ends. If the amount is there, the transaction succeeds; if it is short, everything reverts. The Aave V3 flash loan documentation describes this transfer, action and repayment sequence.

Reverting cancels the loan transfer and every later step in that transaction. The pool keeps its funds, so it does not need collateral to cover an unpaid flash loan.

Two-Exchange Swaps Show Repayment, Costs, and Reverts

A two-exchange trade earns a spread only when its proceeds cover repayment and costs. Say you borrow an available stablecoin from SparkLend, buy ETH on one exchange and sell that ETH for the same stablecoin on another. The contract returns the stablecoin principal plus the flash loan fee. What remains is the trading gain before gas and exchange costs. Both swaps and repayment happen in one transaction.

Suppose the second exchange returns too little stablecoin to repay the pool. The transaction reverts, undoing both swaps and the loan transfer. In this self-contained attempt, the borrower loses only the gas spent, not the borrowed funds. Ethereum charges gas because the network processed the attempt, even though its changes were canceled.

Flash loans also fund liquidations and moves between debt positions. The same temporary buying power can support an attack: a borrower distorts a thin market price and exploits a lending protocol that trusts that weak price oracle. The flash loan still gets repaid; the target protocol can suffer the loss.

Each protocol’s governance sets its flash loan fee, while Ethereum gas varies with network demand and transaction work. Before acting on a two-exchange price gap, compare expected proceeds with the fee, swap costs and gas; that check spares you from mistaking a visible spread for a profitable flash loan.

Report Page