-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(flash-loan): remove erc3156
- Loading branch information
Showing
7 changed files
with
44 additions
and
87 deletions.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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; | ||
|
||
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,15 @@ | ||
// 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,26 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import {IERC3156FlashLender} from "src/interfaces/IERC3156FlashLender.sol"; | ||
import {IERC3156FlashBorrower, FLASH_BORROWER_SUCCESS_HASH} from "src/interfaces/IERC3156FlashBorrower.sol"; | ||
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 IERC3156FlashBorrower { | ||
contract FlashBorrowerMock is IFlashBorrower { | ||
using SafeTransferLib for ERC20; | ||
|
||
IERC3156FlashLender private immutable _LENDER; | ||
IFlashLender private immutable _LENDER; | ||
|
||
constructor(IERC3156FlashLender lender) { | ||
constructor(IFlashLender lender) { | ||
_LENDER = lender; | ||
} | ||
|
||
/* EXTERNAL */ | ||
|
||
/// @inheritdoc IERC3156FlashBorrower | ||
function onFlashLoan(address, address token, uint256 amount, uint256 fee, bytes calldata) | ||
external | ||
returns (bytes32) | ||
{ | ||
/// @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 + fee); | ||
|
||
return FLASH_BORROWER_SUCCESS_HASH; | ||
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