-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove deprecated features #888
base: refactor/aave-v3-origin
Are you sure you want to change the base?
Changes from all commits
3c40299
7585c13
f4f9ba6
daed681
835c675
741d0b0
59a5823
4b5dc9a
e51cb92
3d85382
65c6a17
65096e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet | |
import {DataTypes} from "@aave-v3-origin/protocol/libraries/types/DataTypes.sol"; | ||
import {UserConfiguration} from "@aave-v3-origin/protocol/libraries/configuration/UserConfiguration.sol"; | ||
import {ReserveConfiguration} from "@aave-v3-origin/protocol/libraries/configuration/ReserveConfiguration.sol"; | ||
import {ReserveConfigurationLegacy} from "./libraries/ReserveConfigurationLegacy.sol"; | ||
import {EModeConfiguration} from "@aave-v3-origin/protocol/libraries/configuration/EModeConfiguration.sol"; | ||
|
||
import {MorphoStorage} from "./MorphoStorage.sol"; | ||
|
||
|
@@ -52,7 +52,7 @@ abstract contract MorphoInternal is MorphoStorage { | |
|
||
using UserConfiguration for DataTypes.UserConfigurationMap; | ||
using ReserveConfiguration for DataTypes.ReserveConfigurationMap; | ||
using ReserveConfigurationLegacy for DataTypes.ReserveConfigurationMap; | ||
using EModeConfiguration for uint128; | ||
|
||
/* INTERNAL */ | ||
|
||
|
@@ -92,7 +92,6 @@ abstract contract MorphoInternal is MorphoStorage { | |
market.underlying = underlying; | ||
market.aToken = reserve.aTokenAddress; | ||
market.variableDebtToken = reserve.variableDebtTokenAddress; | ||
market.stableDebtToken = reserve.stableDebtTokenAddress; | ||
|
||
_marketsCreated.push(underlying); | ||
|
||
|
@@ -231,7 +230,9 @@ abstract contract MorphoInternal is MorphoStorage { | |
function _liquidityData(address user) internal view returns (Types.LiquidityData memory liquidityData) { | ||
Types.LiquidityVars memory vars; | ||
|
||
if (_eModeCategoryId != 0) vars.eModeCategory = _pool.getEModeCategoryData(_eModeCategoryId); | ||
if (_eModeCategoryId != 0) { | ||
vars.eModeCollateralConfig = _pool.getEModeCategoryCollateralConfig(_eModeCategoryId); | ||
} | ||
vars.oracle = IAaveOracle(_addressesProvider.getPriceOracle()); | ||
vars.user = user; | ||
|
||
|
@@ -307,8 +308,7 @@ abstract contract MorphoInternal is MorphoStorage { | |
/// @return debtValue The debt value of `vars.user` on the `underlying` market. | ||
function _debt(address underlying, Types.LiquidityVars memory vars) internal view returns (uint256 debtValue) { | ||
DataTypes.ReserveConfigurationMap memory config = _pool.getConfiguration(underlying); | ||
(, uint256 underlyingPrice, uint256 underlyingUnit) = | ||
_assetData(underlying, vars.oracle, config, vars.eModeCategory.priceSource); | ||
(uint256 underlyingPrice, uint256 underlyingUnit) = _assetData(underlying, vars.oracle, config); | ||
|
||
Types.Indexes256 memory indexes = _computeIndexes(underlying); | ||
debtValue = | ||
|
@@ -329,18 +329,16 @@ abstract contract MorphoInternal is MorphoStorage { | |
{ | ||
DataTypes.ReserveConfigurationMap memory config = _pool.getConfiguration(underlying); | ||
|
||
bool isInEMode; | ||
(isInEMode, underlyingPrice, underlyingUnit) = | ||
_assetData(underlying, vars.oracle, config, vars.eModeCategory.priceSource); | ||
(underlyingPrice, underlyingUnit) = _assetData(underlying, vars.oracle, config); | ||
|
||
// If the LTV is 0 on Aave V3, the asset cannot be used as collateral to borrow upon a breaking withdraw. | ||
// In response, Morpho disables the asset as collateral and sets its liquidation threshold | ||
// to 0 and the governance should warn users to repay their debt. | ||
if (config.getLtv() == 0) return (underlyingPrice, 0, 0, underlyingUnit); | ||
|
||
if (isInEMode) { | ||
ltv = vars.eModeCategory.ltv; | ||
liquidationThreshold = vars.eModeCategory.liquidationThreshold; | ||
if (_isCollateralInEMode(underlying)) { | ||
ltv = vars.eModeCollateralConfig.ltv; | ||
liquidationThreshold = vars.eModeCollateralConfig.liquidationThreshold; | ||
} else { | ||
ltv = config.getLtv(); | ||
liquidationThreshold = config.getLiquidationThreshold(); | ||
|
@@ -489,33 +487,37 @@ abstract contract MorphoInternal is MorphoStorage { | |
return liquidityData.debt > 0 ? liquidityData.maxDebt.wadDiv(liquidityData.debt) : type(uint256).max; | ||
} | ||
|
||
/// @dev Returns data relative to the given asset and its configuration, according to a given oracle. | ||
/// @return Whether the given asset is part of Morpho's e-mode category. | ||
/// @return The asset's price or the price of the given e-mode price source if the asset is in the e-mode category, according to the given oracle. | ||
/// @dev Returns data relative to the given asset, according to a given oracle. | ||
/// @return The asset's price according to the given oracle. | ||
/// @return The asset's unit. | ||
function _assetData( | ||
address asset, | ||
IAaveOracle oracle, | ||
DataTypes.ReserveConfigurationMap memory config, | ||
address priceSource | ||
) internal view returns (bool, uint256, uint256) { | ||
function _assetData(address asset, IAaveOracle oracle, DataTypes.ReserveConfigurationMap memory config) | ||
internal | ||
view | ||
returns (uint256, uint256) | ||
{ | ||
uint256 assetUnit; | ||
unchecked { | ||
assetUnit = 10 ** config.getDecimals(); | ||
} | ||
|
||
bool isInEMode = _isInEModeCategory(config); | ||
if (isInEMode && priceSource != address(0)) { | ||
uint256 eModePrice = oracle.getAssetPrice(priceSource); | ||
return (oracle.getAssetPrice(asset), assetUnit); | ||
} | ||
|
||
if (eModePrice != 0) return (isInEMode, eModePrice, assetUnit); | ||
} | ||
/// @dev Returns whether the underlying asset is enabled as an e-mode collateral on the specific Morpho e-mode. | ||
function _isCollateralInEMode(address underlying) internal view returns (bool) { | ||
if (_eModeCategoryId == 0) return false; | ||
|
||
return (isInEMode, oracle.getAssetPrice(asset), assetUnit); | ||
uint256 reserveIndex = _pool.getReserveData(underlying).id; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this call costs a lot of gas, and isn't very ergonomic. Another approach would be to do this call upfront, and use the values from it in sub-functions (in the same way that the |
||
uint128 bitmap = _pool.getEModeCategoryCollateralBitmap(_eModeCategoryId); | ||
return bitmap.isReserveEnabledOnBitmap(reserveIndex); | ||
} | ||
|
||
/// @dev Returns whether Morpho is in an e-mode category and the given asset configuration is in the same e-mode category. | ||
function _isInEModeCategory(DataTypes.ReserveConfigurationMap memory config) internal view returns (bool) { | ||
return _eModeCategoryId != 0 && config.getEModeCategory() == _eModeCategoryId; | ||
/// @dev Returns whether the underlying asset is borrowable in the specific Morpho e-mode. | ||
function _isBorrowableInEMode(address underlying) internal view returns (bool) { | ||
if (_eModeCategoryId == 0) return true; | ||
|
||
uint256 reserveIndex = _pool.getReserveData(underlying).id; | ||
uint128 bitmap = _pool.getEModeCategoryBorrowableBitmap(_eModeCategoryId); | ||
return bitmap.isReserveEnabledOnBitmap(reserveIndex); | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ import {MathUtils} from "@aave-v3-origin/protocol/libraries/math/MathUtils.sol"; | |
import {DataTypes} from "@aave-v3-origin/protocol/libraries/types/DataTypes.sol"; | ||
import {Errors as AaveErrors} from "@aave-v3-origin/protocol/libraries/helpers/Errors.sol"; | ||
import {ReserveConfiguration} from "@aave-v3-origin/protocol/libraries/configuration/ReserveConfiguration.sol"; | ||
import {ReserveConfigurationLegacy} from "src/libraries/ReserveConfigurationLegacy.sol"; | ||
|
||
import {PermitHash} from "@permit2/libraries/PermitHash.sol"; | ||
import {IAllowanceTransfer, AllowanceTransfer} from "@permit2/AllowanceTransfer.sol"; | ||
|
@@ -38,7 +37,6 @@ contract ForkTest is BaseTest, Configured { | |
using ReserveDataLib for DataTypes.ReserveDataLegacy; | ||
using ReserveDataTestLib for DataTypes.ReserveDataLegacy; | ||
using ReserveConfiguration for DataTypes.ReserveConfigurationMap; | ||
using ReserveConfigurationLegacy for DataTypes.ReserveConfigurationMap; | ||
|
||
/* STRUCTS */ | ||
|
||
|
@@ -231,36 +229,23 @@ contract ForkTest is BaseTest, Configured { | |
return reserve.totalSupplyToCap(poolSupplyIndex, poolBorrowIndex); | ||
} | ||
|
||
/// @dev Computes the valid lower bound for ltv and lt for a given CategoryEModeId, conditions required by Aave's code. | ||
/// https://github.com/aave/aave-v3-core/blob/94e571f3a7465201881a59555314cd550ccfda57/contracts/protocol/pool/PoolConfigurator.sol#L369-L376 | ||
Comment on lines
-234
to
-235
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not longer a restriction on Aave |
||
function _getLtvLt(address underlying, uint8 eModeCategoryId) | ||
internal | ||
view | ||
returns (uint256 ltvBound, uint256 ltBound, uint256 ltvConfig, uint256 ltConfig) | ||
{ | ||
address[] memory reserves = pool.getReservesList(); | ||
for (uint256 i = 0; i < reserves.length; ++i) { | ||
DataTypes.ReserveConfigurationMap memory currentConfig = pool.getConfiguration(reserves[i]); | ||
if (eModeCategoryId == currentConfig.getEModeCategory() || underlying == reserves[i]) { | ||
ltvBound = uint16(Math.max(ltvBound, currentConfig.getLtv())); | ||
|
||
ltBound = uint16(Math.max(ltBound, currentConfig.getLiquidationThreshold())); | ||
|
||
if (underlying == reserves[i]) { | ||
ltvConfig = uint16(currentConfig.getLtv()); | ||
ltConfig = uint16(currentConfig.getLiquidationThreshold()); | ||
} | ||
} | ||
} | ||
function _getLtvLt(address underlying) internal view returns (uint256 ltvConfig, uint256 ltConfig) { | ||
DataTypes.ReserveConfigurationMap memory config = pool.getConfiguration(underlying); | ||
ltvConfig = uint16(config.getLtv()); | ||
ltConfig = uint16(config.getLiquidationThreshold()); | ||
} | ||
|
||
function _setEModeCategoryAsset( | ||
DataTypes.EModeCategoryLegacy memory eModeCategory, | ||
DataTypes.CollateralConfig memory eModeCollateralConfig, | ||
address underlying, | ||
uint8 eModeCategoryId | ||
) internal { | ||
poolAdmin.setEModeCategory( | ||
eModeCategoryId, eModeCategory.ltv, eModeCategory.liquidationThreshold, eModeCategory.liquidationBonus, "" | ||
eModeCategoryId, | ||
eModeCollateralConfig.ltv, | ||
eModeCollateralConfig.liquidationThreshold, | ||
eModeCollateralConfig.liquidationBonus, | ||
"" | ||
); | ||
poolAdmin.setAssetBorrowableInEMode(underlying, eModeCategoryId, true); | ||
poolAdmin.setAssetCollateralInEMode(underlying, eModeCategoryId, true); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe not necessary to do this change ?