-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from morpho-labs/feat/flashloan
feat(flash-loan): add flash loan
- Loading branch information
Showing
7 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.5.0; | ||
|
||
interface IFlashBorrower { | ||
/// @dev Receives a flash loan. | ||
/// @param initiator The initiator of the loan. | ||
/// @param token The token lent. | ||
/// @param amount The amount of tokens lent. | ||
/// @param data Arbitrary data structure, intended to contain user-defined parameters. | ||
function onFlashLoan(address initiator, address token, uint256 amount, bytes calldata data) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.5.0; | ||
|
||
import {IFlashBorrower} from "src/interfaces/IFlashBorrower.sol"; | ||
|
||
interface IFlashLender { | ||
/// @dev Initiate a flash loan. | ||
/// @param receiver The receiver of the tokens in the loan, and the receiver of the callback. | ||
/// @param token The token lent. | ||
/// @param amount The amount of tokens lent. | ||
/// @param data Arbitrary data structure, intended to contain user-defined parameters. | ||
function flashLoan(IFlashBorrower receiver, address token, uint256 amount, bytes calldata data) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import {IFlashLender} from "src/interfaces/IFlashLender.sol"; | ||
import {IFlashBorrower} from "src/interfaces/IFlashBorrower.sol"; | ||
|
||
import {ERC20, SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; | ||
|
||
contract FlashBorrowerMock is IFlashBorrower { | ||
using SafeTransferLib for ERC20; | ||
|
||
IFlashLender private immutable _LENDER; | ||
|
||
constructor(IFlashLender lender) { | ||
_LENDER = lender; | ||
} | ||
|
||
/* EXTERNAL */ | ||
|
||
/// @inheritdoc IFlashBorrower | ||
function onFlashLoan(address, address token, uint256 amount, bytes calldata) external { | ||
require(msg.sender == address(_LENDER), "invalid lender"); | ||
|
||
ERC20(token).safeApprove(address(_LENDER), amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters