# 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
Course Overview
About the course
Difference between Uniswap v3 and v4
Uniswap v4 PoolManager
Uniswap v4 Hooks
Uniswap v4 PositionManager
Uniswap v4 Universal Router
Uniswap v4 Singleton architecture and flash accounting
Uniswap v4 operations and lifecycle
Uniswap v4 multihopping and quoting
How to build a Uniswap v4 swap router
How to build a smart contract a liquidation bot executes
Last updated on November 6, 2025
Duration: 5min
Duration: 7min
Duration: 39min
Duration: 35min
Duration: 34min
Duration: 31min
Course Overview
About the course
Difference between Uniswap v3 and v4
Uniswap v4 PoolManager
Uniswap v4 Hooks
Uniswap v4 PositionManager
Uniswap v4 Universal Router
Uniswap v4 Singleton architecture and flash accounting
Uniswap v4 operations and lifecycle
Uniswap v4 multihopping and quoting
How to build a Uniswap v4 swap router
How to build a smart contract a liquidation bot executes
Last updated on November 6, 2025