5/5
# Flash Exercises In this exercise, you'll learn how to execute a flash loan from the [`PoolManager`](https://github.com/Uniswap/v4-core/blob/main/src/PoolManager.sol) contract. The starter code for this exercise is provided in [`foundry/src/exercises/Flash.sol`](https://github.com/Cyfrin/defi-uniswap-v4/blob/main/foundry/src/exercises/Flash.sol) Solution is in [`foundry/src/solutions/Flash.sol`](https://github.com/Cyfrin/defi-uniswap-v4/blob/main/foundry/src/solutions/Flash.sol) ## Task 1 - Initiate a flash loan ```solidity function flash(address currency, uint256 amount) external { // Write your code here } ``` - Unlock the `PoolManager` contract by calling `PoolManager.unlock` - ABI encode or store the inputs (`currency` and `amount`) in storage. ## Task 1 - Unlock callback ```solidity function unlockCallback(bytes calldata data) external onlyPoolManager returns (bytes memory) { // Write your code here return ""; } ``` - Implement the `unlockCallback` - Take out flash loan of `currency` for the `amount` specified when the function `flash` was called. - Immediately after borrowing the `currency` from the `PoolManager` contract, call `tester.call("")`. This external call will check that the flash loan was taken out correctly. ## Test ```shell forge test --fork-url $FORK_URL --match-path test/Flash.test.sol -vvv ```
In this exercise, you'll learn how to execute a flash loan from the PoolManager
contract.
The starter code for this exercise is provided in foundry/src/exercises/Flash.sol
Solution is in foundry/src/solutions/Flash.sol
Unlock the PoolManager
contract by calling PoolManager.unlock
ABI encode or store the inputs (currency
and amount
) in storage.
Implement the unlockCallback
Take out flash loan of currency
for the amount
specified when the function flash
was called.
Immediately after borrowing the currency
from the PoolManager
contract, call tester.call("")
.
This external call will check that the flash loan was taken out correctly.
A functional exercise to Flash Exercises - Learn how to execute a flash loan from the PoolManager contract by implementing the two-step unlock and unlockCallback process.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Difference between Uniswap v3 and v4
Uniswap v4 PoolManager
Uniswap v4 Hooks
Uniswap v4 Singleton architecture
Uniswap v4 flash accounting
Uniswap v4 operations
Uniswap v4 lifecycle
How to build a Uniswap v4 swap router
Last updated on September 22, 2025
Duration: 5min
Duration: 7min
Duration: 39min
Duration: 35min
Course Overview
About the course
Difference between Uniswap v3 and v4
Uniswap v4 PoolManager
Uniswap v4 Hooks
Uniswap v4 Singleton architecture
Uniswap v4 flash accounting
Uniswap v4 operations
Uniswap v4 lifecycle
How to build a Uniswap v4 swap router
Last updated on September 22, 2025