Skip to content

Commit 7202ed7

Browse files
authored
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
1 parent cfa5d1a commit 7202ed7

13 files changed

+7850
-26
lines changed

contracts/adapters/MorphoLeverageStrategyExtension.sol

Lines changed: 1291 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: Apache License, Version 2.0
2+
pragma solidity 0.6.10;
3+
pragma experimental "ABIEncoderV2";
4+
5+
import { ISetToken } from "./ISetToken.sol";
6+
import { IMorpho } from "./IMorpho.sol";
7+
8+
interface IMorphoLeverageModule {
9+
function sync(
10+
ISetToken _setToken
11+
) external;
12+
13+
function lever(
14+
ISetToken _setToken,
15+
uint256 _borrowQuantityUnits,
16+
uint256 _minReceiveQuantityUnits,
17+
string memory _tradeAdapterName,
18+
bytes memory _tradeData
19+
) external;
20+
21+
function delever(
22+
ISetToken _setToken,
23+
uint256 _redeemQuantityUnits,
24+
uint256 _minRepayQuantityUnits,
25+
string memory _tradeAdapterName,
26+
bytes memory _tradeData
27+
) external;
28+
29+
function marketParams(ISetToken _setToken) external view returns (IMorpho.MarketParams memory);
30+
31+
function getCollateralAndBorrowBalances(
32+
ISetToken _setToken
33+
)
34+
external
35+
view
36+
returns(uint256 collateralBalance, uint256 borrowBalance, uint256 borrowSharesU256);
37+
38+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity 0.6.10;
3+
4+
/// @title IOracle
5+
/// @author Morpho Labs
6+
/// @notice Interface that oracles used by Morpho must implement.
7+
/// @dev It is the user's responsibility to select markets with safe oracles.
8+
interface IMorphoOracle {
9+
/// @notice Returns the price of 1 asset of collateral token quoted in 1 asset of loan token, scaled by 1e36.
10+
/// @dev It corresponds to the price of 10**(collateral token decimals) assets of collateral token quoted in
11+
/// 10**(loan token decimals) assets of loan token with `36 + loan token decimals - collateral token decimals`
12+
/// decimals of precision.
13+
function price() external view returns (uint256);
14+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity 0.6.10;
3+
4+
interface AggregatorInterface {
5+
function latestAnswer() external view returns (int256);
6+
function latestTimestamp() external view returns (uint256);
7+
function latestRound() external view returns (uint256);
8+
function getAnswer(uint256 roundId) external view returns (int256);
9+
function getTimestamp(uint256 roundId) external view returns (uint256);
10+
}
11+
12+
interface AggregatorV3Interface {
13+
14+
function decimals() external view returns (uint8);
15+
function description() external view returns (string memory);
16+
function version() external view returns (uint256);
17+
18+
// getRoundData and latestRoundData should both raise "No data present"
19+
// if they do not have data to report, instead of returning unset values
20+
// which could be misinterpreted as actual reported values.
21+
function getRoundData(uint80 _roundId)
22+
external
23+
view
24+
returns (
25+
uint80 roundId,
26+
int256 answer,
27+
uint256 startedAt,
28+
uint256 updatedAt,
29+
uint80 answeredInRound
30+
);
31+
function latestRoundData()
32+
external
33+
view
34+
returns (
35+
uint80 roundId,
36+
int256 answer,
37+
uint256 startedAt,
38+
uint256 updatedAt,
39+
uint80 answeredInRound
40+
);
41+
42+
}
43+
44+
interface AggregatorV2V3Interface is AggregatorInterface, AggregatorV3Interface
45+
{
46+
}
47+
48+
interface IChainlinkEACAggregatorProxy {
49+
function acceptOwnership() external;
50+
function accessController() external view returns (address);
51+
function aggregator() external view returns (address);
52+
function confirmAggregator(address _aggregator) external;
53+
function decimals() external view returns (uint8);
54+
function description() external view returns (string memory);
55+
function getAnswer(uint256 _roundId) external view returns (int256);
56+
function getRoundData(uint80 _roundId)
57+
external
58+
view
59+
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
60+
function getTimestamp(uint256 _roundId) external view returns (uint256);
61+
function latestAnswer() external view returns (int256);
62+
function latestRound() external view returns (uint256);
63+
function latestRoundData()
64+
external
65+
view
66+
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
67+
function latestTimestamp() external view returns (uint256);
68+
function owner() external view returns (address payable);
69+
function phaseAggregators(uint16) external view returns (address);
70+
function phaseId() external view returns (uint16);
71+
function proposeAggregator(address _aggregator) external;
72+
function proposedAggregator() external view returns (address);
73+
function proposedGetRoundData(uint80 _roundId)
74+
external
75+
view
76+
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
77+
function proposedLatestRoundData()
78+
external
79+
view
80+
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
81+
function setController(address _accessController) external;
82+
function transferOwnership(address _to) external;
83+
function version() external view returns (uint256);
84+
}

0 commit comments

Comments
 (0)