Skip to content

Commit

Permalink
Rebase Morpho to latest code, update test suites to follow the defaul…
Browse files Browse the repository at this point in the history
…t test setup
  • Loading branch information
jankjr committed Jun 22, 2023
1 parent 34a5fdb commit b83cec2
Show file tree
Hide file tree
Showing 21 changed files with 1,148 additions and 992 deletions.
14 changes: 12 additions & 2 deletions common/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export interface ITokens {
sDAI?: string
cbETH?: string
MORPHO?: string
wBTCBTC?: string
astETH?: string
}

export interface IFeeds {
Expand Down Expand Up @@ -144,7 +146,8 @@ export const networkConfig: { [key: string]: INetworkConfig } = {
ONDO: '0xfAbA6f8e4a5E8Ab82F62fe7C39859FA577269BE3',
sDAI: '0x83f20f44975d03b1b09e64809b757c47f942beea',
cbETH: '0xBe9895146f7AF43049ca1c1AE358B0541Ea49704',
MORPHO: '0x9994E35Db50125E0DF82e4c2dde62496CE330999'
MORPHO: '0x9994E35Db50125E0DF82e4c2dde62496CE330999',
astETH: "0x1982b2F5814301d4e9a8b0201555376e62F82428"
},
chainlinkFeeds: {
RSR: '0x759bBC1be8F90eE6457C44abc7d443842a976d02',
Expand All @@ -170,6 +173,8 @@ export const networkConfig: { [key: string]: INetworkConfig } = {
stETHUSD: '0xCfE54B5cD566aB89272946F602D76Ea879CAb4a8', // stETH/USD
rETH: '0x536218f9E9Eb48863970252233c8F271f554C2d0', // rETH/ETH
cbETH: '0xf017fcb346a1885194689ba23eff2fe6fa5c483b', // cbETH/ETH
wBTCBTC: "0xfdFD9C85aD200c506Cf9e21F1FD8dd01932FBB23", // "WBTC/BTC"

},
AAVE_LENDING_POOL: '0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9',
AAVE_INCENTIVES: '0xd784927Ff2f95ba542BfC824c8a8a98F3495f6b5',
Expand Down Expand Up @@ -224,6 +229,7 @@ export const networkConfig: { [key: string]: INetworkConfig } = {
stkAAVE: '0x4da27a545c0c5B758a6BA100e3a049001de870f5',
COMP: '0xc00e94Cb662C3520282E6f5717214004A7f26888',
WETH: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
aWBTC: '0x9ff58f4ffb29fa2266ab25e75e2a8b3503311656',
WBTC: '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599',
EURT: '0xC581b735A1688071A1746c968e0798D642EDE491',
RSR: '0x320623b8e4ff03373931769a31fc52a4e78b5d70',
Expand All @@ -239,6 +245,7 @@ export const networkConfig: { [key: string]: INetworkConfig } = {
ONDO: '0xfAbA6f8e4a5E8Ab82F62fe7C39859FA577269BE3',
sDAI: '0x83f20f44975d03b1b09e64809b757c47f942beea',
cbETH: '0xBe9895146f7AF43049ca1c1AE358B0541Ea49704',
astETH: "0x1982b2F5814301d4e9a8b0201555376e62F82428"
},
chainlinkFeeds: {
RSR: '0x759bBC1be8F90eE6457C44abc7d443842a976d02',
Expand All @@ -264,12 +271,15 @@ export const networkConfig: { [key: string]: INetworkConfig } = {
stETHUSD: '0xCfE54B5cD566aB89272946F602D76Ea879CAb4a8', // stETH/USD
rETH: '0x536218f9E9Eb48863970252233c8F271f554C2d0', // rETH/ETH
cbETH: '0xf017fcb346a1885194689ba23eff2fe6fa5c483b', // cbETH/ETH
wBTCBTC: "0xfdFD9C85aD200c506Cf9e21F1FD8dd01932FBB23" // "WBTC/BTC"
},
AAVE_LENDING_POOL: '0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9',
AAVE_RESERVE_TREASURY: '0x464C71f6c2F760DdA6093dCB91C24c39e5d6e18c',
FLUX_FINANCE_COMPTROLLER: '0x95Af143a021DF745bc78e845b54591C53a8B3A51',
COMPTROLLER: '0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B',
GNOSIS_EASY_AUCTION: '0x0b7fFc1f4AD541A4Ed16b40D8c37f0929158D101'
GNOSIS_EASY_AUCTION: '0x0b7fFc1f4AD541A4Ed16b40D8c37f0929158D101',
MORPHO_AAVE_LENS: '0x507fA343d0A90786d86C7cd885f5C49263A91FF4',
MORPHO_AAVE_CONTROLLER: '0x777777c9898D384F785Ee44Acfe945efDFf5f3E0'
},
'5': {
name: 'goerli',
Expand Down
3 changes: 2 additions & 1 deletion contracts/plugins/assets/morpho-aave/IMorpho.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;
pragma solidity 0.8.19;

interface IMorpho {
function supply(address _poolToken, uint256 _amount) external;

function withdraw(address _poolToken, uint256 _amount) external;
}

Expand Down
44 changes: 17 additions & 27 deletions contracts/plugins/assets/morpho-aave/MorphoAAVEFiatCollateral.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "../AppreciatingFiatCollateral.sol";
import "../../../libraries/Fixed.sol";
import "./MorphoAAVEPositionWrapper.sol";
pragma solidity 0.8.19;

// solhint-disable-next-line max-line-length
import { IRewardable, Asset, AppreciatingFiatCollateral, CollateralConfig } from "../AppreciatingFiatCollateral.sol";
import { MorphoAAVEPositionWrapper } from "./MorphoAAVEPositionWrapper.sol";
import { FixLib } from "../../../libraries/Fixed.sol";
import { OracleLib } from "../OracleLib.sol";
// solhint-disable-next-line max-line-length
import { AggregatorV3Interface } from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

/**
* @title MorphoAAVEFiatCollateral
Expand All @@ -15,14 +18,14 @@ contract MorphoAAVEFiatCollateral is AppreciatingFiatCollateral {
using OracleLib for AggregatorV3Interface;
using FixLib for uint192;

MorphoAAVEPositionWrapper wrapper;
MorphoAAVEPositionWrapper public immutable wrapper;

/// @param config Configuration of this collateral. config.erc20 must be a MorphoAAVEPositionWrapper
/// @param revenue_hiding {1} A value like 1e-6 that represents the maximum refPerTok to hide
constructor(
CollateralConfig memory config,
uint192 revenue_hiding
) AppreciatingFiatCollateral(config, revenue_hiding) {
/// @param config Configuration of this collateral.
/// config.erc20 must be a MorphoAAVEPositionWrapper
/// @param revenueHiding {1} A value like 1e-6 that represents the maximum refPerTok to hide
constructor(CollateralConfig memory config, uint192 revenueHiding)
AppreciatingFiatCollateral(config, revenueHiding)
{
require(address(config.erc20) != address(0), "missing erc20");
wrapper = MorphoAAVEPositionWrapper(address(config.erc20));
}
Expand All @@ -31,25 +34,12 @@ contract MorphoAAVEFiatCollateral is AppreciatingFiatCollateral {
/// @custom:interaction RCEI
function refresh() public virtual override {
// Update wrapper exchange rate for underlying token
wrapper.refresh_exchange_rate();
wrapper.refreshExchangeRate();
super.refresh();
}

/// @return {ref/tok} Actual quantity of whole reference units per whole collateral tokens
function _underlyingRefPerTok() internal view override returns (uint192) {
return wrapper.get_exchange_rate();
}

/// Claim rewards earned by holding a balance of the ERC20 token
/// @dev delegatecall
function claimRewards() external virtual override(Asset, IRewardable) {
// unfortunately Morpho uses a rewards scheme that requires the results
// of off-chain computation to be piped into an on-chain function,
// which is not possible to do with Reserve's collateral plugin interface.

// https://integration.morpho.xyz/track-and-manage-position/manage-positions-on-morpho/claim-morpho-rewards

// claiming rewards for this wrapper can be done by any account, and must be done on Morpho's rewards distributor contract
// https://etherscan.io/address/0x3b14e5c73e0a56d607a8688098326fd4b4292135
return wrapper.getExchangeRate();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.17;

import "./MorphoAAVEFiatCollateral.sol";
import "../../../libraries/Fixed.sol";
import "./MorphoAAVEPositionWrapper.sol";
pragma solidity 0.8.19;

import { CollateralConfig, MorphoAAVEFiatCollateral } from "./MorphoAAVEFiatCollateral.sol";
import { FixLib, CEIL } from "../../../libraries/Fixed.sol";
import { OracleLib } from "../OracleLib.sol";
// solhint-disable-next-line max-line-length
import { AggregatorV3Interface } from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

/**
* @title MorphoAAVENonFiatCollateral
Expand All @@ -18,24 +19,25 @@ contract MorphoAAVENonFiatCollateral is MorphoAAVEFiatCollateral {
AggregatorV3Interface public immutable targetUnitChainlinkFeed; // {UoA/target}
uint48 public immutable targetUnitOracleTimeout; // {s}

/// @param config Configuration of this collateral. config.erc20 must be a MorphoAAVEPositionWrapper
/// @param revenue_hiding {1} A value like 1e-6 that represents the maximum refPerTok to hide
/// @param config Configuration of this collateral.
/// config.erc20 must be a MorphoAAVEPositionWrapper
/// @param revenueHiding {1} A value like 1e-6 that represents the maximum refPerTok to hide
/// @param targetUnitChainlinkFeed_ Feed units: {UoA/target}
/// @param targetUnitOracleTimeout_ {s} oracle timeout to use for targetUnitChainlinkFeed
constructor(
CollateralConfig memory config,
uint192 revenue_hiding,
uint192 revenueHiding,
AggregatorV3Interface targetUnitChainlinkFeed_,
uint48 targetUnitOracleTimeout_
) MorphoAAVEFiatCollateral(config, revenue_hiding) {
) MorphoAAVEFiatCollateral(config, revenueHiding) {
targetUnitChainlinkFeed = targetUnitChainlinkFeed_;
targetUnitOracleTimeout = targetUnitOracleTimeout_;
}

/// Can revert, used by other contract functions in order to catch errors
/// @return low {UoA/tok} The low price estimate
/// @return high {UoA/tok} The high price estimate
/// @return pegPrice {target/ref}
/// @return pegPrice {target/ref} The actual price observed in the peg
function tryPrice()
external
view
Expand All @@ -46,17 +48,15 @@ contract MorphoAAVENonFiatCollateral is MorphoAAVEFiatCollateral {
uint192 pegPrice
)
{
pegPrice = chainlinkFeed.price(oracleTimeout); // {target/ref}
// {target/ref} Get current market peg ({btc/wbtc})
pegPrice = targetUnitChainlinkFeed.price(targetUnitOracleTimeout);

// {UoA/tok} = {UoA/target} * {target/ref} * {ref/tok}
uint192 p = targetUnitChainlinkFeed.price(targetUnitOracleTimeout).mul(pegPrice).mul(
_underlyingRefPerTok()
);
// {UoA/tok} = {UoA/ref} * {ref/tok}
uint192 p = chainlinkFeed.price(oracleTimeout).mul(_underlyingRefPerTok());
uint192 err = p.mul(oracleError, CEIL);

low = p - err;
high = p + err;
low = p - err;
// assert(low <= high); obviously true just by inspection
}

}
Loading

0 comments on commit b83cec2

Please sign in to comment.