# How to Flash-loan Assets from Saddle

Some of our pools allow flash-loaning assets for a small fee.

```
function flashLoan(
    address receiver,
    IERC20 token,
    uint256 amount,
    bytes memory params
) external;
```

Caller must provide a valid receiver address that inherits [IFlashLoanReceiver interface](https://github.com/saddle-finance/saddle-contract/blob/master/contracts/interfaces/IFlashLoanReceiver.sol).

```
function executeOperation(
    address pool,
    address token,
    uint256 amount,
    uint256 fee,
    bytes calldata params
) external;
```

Upon finishing `executeOperation`, the pool must have the initial liquidity back along with the associated fee. If the requirement is not met, then the transaction will fail.

We provide a [basic example of a flashloan borrower contract](https://github.com/saddle-finance/saddle-contract/blob/master/contracts/helper/FlashLoanBorrowerExample.sol).

## Flash-loan Supported Pools

* vETH2 pool (`0xdec2157831D6ABC3Ec328291119cc91B337272b5`)
* alETH pool (`0xa6018520EAACC06C30fF2e1B3ee2c7c22e64196a`)
* D4 pool (`0xC69DDcd4DFeF25D8a793241834d4cc4b3668EAD6`)

## Do you have any flashloan countermeasures implemented?

For flashloan safety, we have 2 safety measures in place:

* Prevent reentrancy into the same pool. You cant flashloan money out of a pool and use that fund to trade through the same pool.
* Ensure the returned amount is always higher than borrowed amount. The transaction will revert if the borrower does not pay up by end of the transaction.

Our flash loan implementation is based on [Aave](https://aave.com/)'s [IFlashLoanReceiver.sol](https://github.com/aave/aave-protocol/blob/4b4545fb583fd4f400507b10f3c3114f45b8a037/contracts/flashloan/interfaces/IFlashLoanReceiver.sol).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.saddle.finance/howtoflashloan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
