-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Morpho leverage extension (#185)
* First version of MorphoLeverageStrategyExtension * Adjust calculation of liquidation thresholds etc * Set up tests for Morpho Leverage Extension * add engage tests * Fix some engage tests * rebalance tests * Simulate price change in rebalance * All rebalance tests passing * Add iterateRebalance tests * Add ripcord tests * Add disengage tests * fix failing tests * tests for setter methods * test shouldRebalance * test shouldRebalanceWithBounds * test #getChunkRebalanceNotional * fix open TODOs * Minor code cleanup in smart contract * Adjust docstring on _calculateMaxBorrowCollateral method * Adjust more comments * Adjust collateralValue to be correctly denominated in borrow asset units * Remove unnecessary sync call from test * Cosmetic changes to smart contract code
- Loading branch information
Showing
13 changed files
with
7,850 additions
and
26 deletions.
There are no files selected for viewing
1,291 changes: 1,291 additions & 0 deletions
1,291
contracts/adapters/MorphoLeverageStrategyExtension.sol
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,38 @@ | ||
// SPDX-License-Identifier: Apache License, Version 2.0 | ||
pragma solidity 0.6.10; | ||
pragma experimental "ABIEncoderV2"; | ||
|
||
import { ISetToken } from "./ISetToken.sol"; | ||
import { IMorpho } from "./IMorpho.sol"; | ||
|
||
interface IMorphoLeverageModule { | ||
function sync( | ||
ISetToken _setToken | ||
) external; | ||
|
||
function lever( | ||
ISetToken _setToken, | ||
uint256 _borrowQuantityUnits, | ||
uint256 _minReceiveQuantityUnits, | ||
string memory _tradeAdapterName, | ||
bytes memory _tradeData | ||
) external; | ||
|
||
function delever( | ||
ISetToken _setToken, | ||
uint256 _redeemQuantityUnits, | ||
uint256 _minRepayQuantityUnits, | ||
string memory _tradeAdapterName, | ||
bytes memory _tradeData | ||
) external; | ||
|
||
function marketParams(ISetToken _setToken) external view returns (IMorpho.MarketParams memory); | ||
|
||
function getCollateralAndBorrowBalances( | ||
ISetToken _setToken | ||
) | ||
external | ||
view | ||
returns(uint256 collateralBalance, uint256 borrowBalance, uint256 borrowSharesU256); | ||
|
||
} |
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,14 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity 0.6.10; | ||
|
||
/// @title IOracle | ||
/// @author Morpho Labs | ||
/// @notice Interface that oracles used by Morpho must implement. | ||
/// @dev It is the user's responsibility to select markets with safe oracles. | ||
interface IMorphoOracle { | ||
/// @notice Returns the price of 1 asset of collateral token quoted in 1 asset of loan token, scaled by 1e36. | ||
/// @dev It corresponds to the price of 10**(collateral token decimals) assets of collateral token quoted in | ||
/// 10**(loan token decimals) assets of loan token with `36 + loan token decimals - collateral token decimals` | ||
/// decimals of precision. | ||
function price() external view returns (uint256); | ||
} |
84 changes: 84 additions & 0 deletions
84
contracts/interfaces/external/IChainlinkEACAggregatorProxy.sol
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,84 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.6.10; | ||
|
||
interface AggregatorInterface { | ||
function latestAnswer() external view returns (int256); | ||
function latestTimestamp() external view returns (uint256); | ||
function latestRound() external view returns (uint256); | ||
function getAnswer(uint256 roundId) external view returns (int256); | ||
function getTimestamp(uint256 roundId) external view returns (uint256); | ||
} | ||
|
||
interface AggregatorV3Interface { | ||
|
||
function decimals() external view returns (uint8); | ||
function description() external view returns (string memory); | ||
function version() external view returns (uint256); | ||
|
||
// getRoundData and latestRoundData should both raise "No data present" | ||
// if they do not have data to report, instead of returning unset values | ||
// which could be misinterpreted as actual reported values. | ||
function getRoundData(uint80 _roundId) | ||
external | ||
view | ||
returns ( | ||
uint80 roundId, | ||
int256 answer, | ||
uint256 startedAt, | ||
uint256 updatedAt, | ||
uint80 answeredInRound | ||
); | ||
function latestRoundData() | ||
external | ||
view | ||
returns ( | ||
uint80 roundId, | ||
int256 answer, | ||
uint256 startedAt, | ||
uint256 updatedAt, | ||
uint80 answeredInRound | ||
); | ||
|
||
} | ||
|
||
interface AggregatorV2V3Interface is AggregatorInterface, AggregatorV3Interface | ||
{ | ||
} | ||
|
||
interface IChainlinkEACAggregatorProxy { | ||
function acceptOwnership() external; | ||
function accessController() external view returns (address); | ||
function aggregator() external view returns (address); | ||
function confirmAggregator(address _aggregator) external; | ||
function decimals() external view returns (uint8); | ||
function description() external view returns (string memory); | ||
function getAnswer(uint256 _roundId) external view returns (int256); | ||
function getRoundData(uint80 _roundId) | ||
external | ||
view | ||
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound); | ||
function getTimestamp(uint256 _roundId) external view returns (uint256); | ||
function latestAnswer() external view returns (int256); | ||
function latestRound() external view returns (uint256); | ||
function latestRoundData() | ||
external | ||
view | ||
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound); | ||
function latestTimestamp() external view returns (uint256); | ||
function owner() external view returns (address payable); | ||
function phaseAggregators(uint16) external view returns (address); | ||
function phaseId() external view returns (uint16); | ||
function proposeAggregator(address _aggregator) external; | ||
function proposedAggregator() external view returns (address); | ||
function proposedGetRoundData(uint80 _roundId) | ||
external | ||
view | ||
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound); | ||
function proposedLatestRoundData() | ||
external | ||
view | ||
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound); | ||
function setController(address _accessController) external; | ||
function transferOwnership(address _to) external; | ||
function version() external view returns (uint256); | ||
} |
Oops, something went wrong.