-
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 branch 'main' of github.com:morpho-labs/blue into feat/repay-wi…
…thdraw-all
- Loading branch information
Showing
16 changed files
with
333 additions
and
150 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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,71 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.5.0; | ||
|
||
import {IFlashLender} from "./IFlashLender.sol"; | ||
|
||
type Id is bytes32; | ||
|
||
struct Market { | ||
address borrowableAsset; | ||
address collateralAsset; | ||
address borrowableOracle; | ||
address collateralOracle; | ||
address irm; | ||
uint256 lltv; | ||
} | ||
|
||
/// @notice Contains the `v`, `r` and `s` parameters of an ECDSA signature. | ||
struct Signature { | ||
uint8 v; | ||
bytes32 r; | ||
bytes32 s; | ||
} | ||
|
||
interface IBlue is IFlashLender { | ||
function DOMAIN_SEPARATOR() external view returns (bytes32); | ||
|
||
function owner() external view returns (address); | ||
function feeRecipient() external view returns (address); | ||
|
||
function supplyShares(Id, address) external view returns (uint256); | ||
function borrowShares(Id, address) external view returns (uint256); | ||
function collateral(Id, address) external view returns (uint256); | ||
function totalSupply(Id) external view returns (uint256); | ||
function totalSupplyShares(Id) external view returns (uint256); | ||
function totalBorrow(Id) external view returns (uint256); | ||
function totalBorrowShares(Id) external view returns (uint256); | ||
function lastUpdate(Id) external view returns (uint256); | ||
function fee(Id) external view returns (uint256); | ||
|
||
function isIrmEnabled(address) external view returns (bool); | ||
function isLltvEnabled(uint256) external view returns (bool); | ||
function isAuthorized(address, address) external view returns (bool); | ||
function nonce(address) external view returns (uint256); | ||
|
||
function setOwner(address newOwner) external; | ||
function enableIrm(address irm) external; | ||
function enableLltv(uint256 lltv) external; | ||
function setFee(Market memory market, uint256 newFee) external; | ||
function setFeeRecipient(address recipient) external; | ||
function createMarket(Market memory market) external; | ||
|
||
function supply(Market memory market, uint256 amount, address onBehalf, bytes memory data) external; | ||
function withdraw(Market memory market, uint256 amount, address onBehalf, address receiver) external; | ||
function borrow(Market memory market, uint256 amount, address onBehalf, address receiver) external; | ||
function repay(Market memory market, uint256 amount, address onBehalf, bytes memory data) external; | ||
function supplyCollateral(Market memory market, uint256 amount, address onBehalf, bytes memory data) external; | ||
function withdrawCollateral(Market memory market, uint256 amount, address onBehalf, address receiver) external; | ||
function liquidate(Market memory market, address borrower, uint256 seized, bytes memory data) external; | ||
function flashLoan(address token, uint256 amount, bytes calldata data) external; | ||
|
||
function setAuthorization(address manager, bool isAllowed) external; | ||
function setAuthorization( | ||
address authorizer, | ||
address authorized, | ||
bool newIsAuthorized, | ||
uint256 deadline, | ||
Signature calldata signature | ||
) external; | ||
|
||
function extsload(bytes32[] memory slots) external view returns (bytes32[] memory res); | ||
} |
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 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,13 +1,8 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.5.0; | ||
|
||
import {IFlashBorrower} from "src/interfaces/IFlashBorrower.sol"; | ||
import {IBlueFlashLoanCallback} from "./IBlueCallbacks.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; | ||
function flashLoan(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
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,63 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import {Id, Market} from "src/libraries/MarketLib.sol"; | ||
|
||
library Events { | ||
event SupplyCollateral(Id indexed id, address indexed caller, address indexed onBehalf, uint256 amount); | ||
event WithdrawCollateral( | ||
Id indexed id, address caller, address indexed onBehalf, address indexed receiver, uint256 amount | ||
); | ||
|
||
event Supply(Id indexed id, address indexed caller, address indexed onBehalf, uint256 amount, uint256 shares); | ||
event Withdraw( | ||
Id indexed id, | ||
address caller, | ||
address indexed onBehalf, | ||
address indexed receiver, | ||
uint256 amount, | ||
uint256 shares | ||
); | ||
|
||
event Borrow( | ||
Id indexed id, | ||
address caller, | ||
address indexed onBehalf, | ||
address indexed receiver, | ||
uint256 amount, | ||
uint256 shares | ||
); | ||
event Repay(Id indexed id, address indexed caller, address indexed onBehalf, uint256 amount, uint256 shares); | ||
|
||
event Liquidate( | ||
Id indexed id, | ||
address indexed caller, | ||
address indexed borrower, | ||
uint256 repaid, | ||
uint256 repaidShares, | ||
uint256 seized, | ||
uint256 badDebtShares | ||
); | ||
|
||
event FlashLoan(address indexed caller, address indexed token, uint256 amount); | ||
|
||
event SetOwner(address indexed newOwner); | ||
|
||
event SetFee(Id indexed id, uint256 fee); | ||
|
||
event SetFeeRecipient(address indexed feeRecipient); | ||
|
||
event CreateMarket(Id indexed id, Market market); | ||
|
||
event SetAuthorization( | ||
address indexed caller, address indexed authorizer, address indexed authorized, bool isAuthorized | ||
); | ||
|
||
event IncrementNonce(address indexed caller, address indexed signatory, uint256 usedNonce); | ||
|
||
event EnableIrm(address indexed irm); | ||
|
||
event EnableLltv(uint256 lltv); | ||
|
||
event AccrueInterests(Id indexed id, uint256 borrowRate, uint256 accruedInterests, uint256 feeShares); | ||
} |
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
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 |
---|---|---|
@@ -1,26 +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 {IFlashLender} from "../interfaces/IFlashLender.sol"; | ||
import {IBlueFlashLoanCallback} from "../interfaces/IBlueCallbacks.sol"; | ||
|
||
import {ERC20, SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; | ||
|
||
contract FlashBorrowerMock is IFlashBorrower { | ||
contract FlashBorrowerMock is IBlueFlashLoanCallback { | ||
using SafeTransferLib for ERC20; | ||
|
||
IFlashLender private immutable _LENDER; | ||
IFlashLender private immutable BLUE; | ||
|
||
constructor(IFlashLender lender) { | ||
_LENDER = lender; | ||
constructor(IFlashLender newBlue) { | ||
BLUE = newBlue; | ||
} | ||
|
||
/* EXTERNAL */ | ||
|
||
/// @inheritdoc IFlashBorrower | ||
function onBlueFlashLoan(address, address token, uint256 amount, bytes calldata) external { | ||
require(msg.sender == address(_LENDER), "invalid lender"); | ||
function flashLoan(address token, uint256 amount, bytes calldata data) external { | ||
BLUE.flashLoan(token, amount, data); | ||
} | ||
|
||
ERC20(token).safeApprove(address(_LENDER), amount); | ||
function onBlueFlashLoan(address token, uint256 amount, bytes calldata) external { | ||
require(msg.sender == address(BLUE)); | ||
ERC20(token).safeApprove(address(BLUE), 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
Oops, something went wrong.