Skip to content
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

Point to aave-v3-origin #886

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
7 changes: 3 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
[submodule "lib/morpho-utils"]
path = lib/morpho-utils
url = https://github.com/morpho-dao/morpho-utils
[submodule "lib/aave-v3-core"]
path = lib/aave-v3-core
url = https://github.com/aave/aave-v3-core
branch = v1.17.2
[submodule "lib/aave-v3-periphery"]
path = lib/aave-v3-periphery
url = https://github.com/aave/aave-v3-periphery
Expand All @@ -25,3 +21,6 @@
path = lib/permit2
url = https://github.com/Uniswap/permit2
branch = f3349109ed405970a7fb3bb7e9ac9574c822a90d
[submodule "lib/aave-v3-origin"]
path = lib/aave-v3-origin
url = git@github.com:aave-dao/aave-v3-origin.git
1 change: 0 additions & 1 deletion lib/aave-v3-core
Submodule aave-v3-core deleted from a00f28
1 change: 1 addition & 0 deletions lib/aave-v3-origin
Submodule aave-v3-origin added at ec33f4
4 changes: 2 additions & 2 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ config/=config/
@morpho-utils/=lib/morpho-utils/src/
@morpho-data-structures/=lib/morpho-data-structures/src/

@openzeppelin/=lib/morpho-utils/lib/openzeppelin-contracts/
@openzeppelin/contracts/=lib/morpho-utils/lib/openzeppelin-contracts/contracts/
MathisGD marked this conversation as resolved.
Show resolved Hide resolved
@openzeppelin-upgradeable/=lib/morpho-utils/lib/openzeppelin-contracts-upgradeable/contracts/

@aave-v3-core/=lib/aave-v3-core/contracts/
@aave-v3-origin/=lib/aave-v3-origin/src/contracts/
@aave-v3-periphery/=lib/aave-v3-periphery/contracts/

@solmate/=lib/solmate/src/
Expand Down
2 changes: 1 addition & 1 deletion script/DeployScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.17;

import {IMorpho} from "src/interfaces/IMorpho.sol";
import {IPositionsManager} from "src/interfaces/IPositionsManager.sol";
import {IPool, IPoolAddressesProvider} from "@aave-v3-core/interfaces/IPool.sol";
import {IPool, IPoolAddressesProvider} from "@aave-v3-origin/interfaces/IPool.sol";

import {Types} from "src/libraries/Types.sol";

Expand Down
6 changes: 3 additions & 3 deletions script/EthEModeDeployScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ pragma solidity ^0.8.17;

import {IMorpho} from "src/interfaces/IMorpho.sol";
import {IPositionsManager} from "src/interfaces/IPositionsManager.sol";
import {IPool, IPoolAddressesProvider} from "@aave-v3-core/interfaces/IPool.sol";
import {IPoolDataProvider} from "@aave-v3-core/interfaces/IPoolDataProvider.sol";
import {IAToken} from "@aave-v3-core/interfaces/IAToken.sol";
import {IPool, IPoolAddressesProvider} from "@aave-v3-origin/interfaces/IPool.sol";
import {IPoolDataProvider} from "@aave-v3-origin/interfaces/IPoolDataProvider.sol";
import {IAToken} from "@aave-v3-origin/interfaces/IAToken.sol";

import {Types} from "src/libraries/Types.sol";
import {ERC20, SafeTransferLib} from "@solmate/utils/SafeTransferLib.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/Morpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.17;

import {IMorpho} from "./interfaces/IMorpho.sol";
import {IPositionsManager} from "./interfaces/IPositionsManager.sol";
import {IPool, IPoolAddressesProvider} from "@aave-v3-core/interfaces/IPool.sol";
import {IPool, IPoolAddressesProvider} from "@aave-v3-origin/interfaces/IPool.sol";
import {IRewardsController} from "@aave-v3-periphery/rewards/interfaces/IRewardsController.sol";

import {Types} from "./libraries/Types.sol";
Expand Down
14 changes: 8 additions & 6 deletions src/MorphoInternal.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.17;

import {IPool} from "@aave-v3-core/interfaces/IPool.sol";
import {IPool} from "@aave-v3-origin/interfaces/IPool.sol";
import {IRewardsManager} from "./interfaces/IRewardsManager.sol";
import {IAaveOracle} from "@aave-v3-core/interfaces/IAaveOracle.sol";
import {IAaveOracle} from "@aave-v3-origin/interfaces/IAaveOracle.sol";

import {Types} from "./libraries/Types.sol";
import {Events} from "./libraries/Events.sol";
Expand All @@ -24,9 +24,10 @@ import {ERC20, SafeTransferLib} from "@solmate/utils/SafeTransferLib.sol";
import {LogarithmicBuckets} from "@morpho-data-structures/LogarithmicBuckets.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

import {DataTypes} from "@aave-v3-core/protocol/libraries/types/DataTypes.sol";
import {UserConfiguration} from "@aave-v3-core/protocol/libraries/configuration/UserConfiguration.sol";
import {ReserveConfiguration} from "@aave-v3-core/protocol/libraries/configuration/ReserveConfiguration.sol";
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 {MorphoStorage} from "./MorphoStorage.sol";

Expand All @@ -51,6 +52,7 @@ abstract contract MorphoInternal is MorphoStorage {

using UserConfiguration for DataTypes.UserConfigurationMap;
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;
using ReserveConfigurationLegacy for DataTypes.ReserveConfigurationMap;

/* INTERNAL */

Expand All @@ -71,7 +73,7 @@ abstract contract MorphoInternal is MorphoStorage {
function _createMarket(address underlying, uint16 reserveFactor, uint16 p2pIndexCursor) internal {
if (underlying == address(0)) revert Errors.AddressIsZero();

DataTypes.ReserveData memory reserve = _pool.getReserveData(underlying);
MathisGD marked this conversation as resolved.
Show resolved Hide resolved
DataTypes.ReserveDataLegacy memory reserve = _pool.getReserveData(underlying);
if (!reserve.configuration.getActive()) revert Errors.MarketIsNotListedOnAave();
if (reserve.configuration.getSiloedBorrowing()) revert Errors.SiloedBorrowMarket();

Expand Down
4 changes: 2 additions & 2 deletions src/MorphoSetters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {Events} from "./libraries/Events.sol";
import {Errors} from "./libraries/Errors.sol";
import {MarketLib} from "./libraries/MarketLib.sol";

import {DataTypes} from "@aave-v3-core/protocol/libraries/types/DataTypes.sol";
import {UserConfiguration} from "@aave-v3-core/protocol/libraries/configuration/UserConfiguration.sol";
import {DataTypes} from "@aave-v3-origin/protocol/libraries/types/DataTypes.sol";
import {UserConfiguration} from "@aave-v3-origin/protocol/libraries/configuration/UserConfiguration.sol";

import {MorphoInternal} from "./MorphoInternal.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/MorphoStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.17;

import {IRewardsManager} from "./interfaces/IRewardsManager.sol";
import {IPool, IPoolAddressesProvider} from "@aave-v3-core/interfaces/IPool.sol";
import {IPool, IPoolAddressesProvider} from "@aave-v3-origin/interfaces/IPool.sol";

import {Types} from "./libraries/Types.sol";
import {Constants} from "./libraries/Constants.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/PositionsManager.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.17;

import {IPool} from "@aave-v3-core/interfaces/IPool.sol";
import {IPool} from "@aave-v3-origin/interfaces/IPool.sol";
import {IPositionsManager} from "./interfaces/IPositionsManager.sol";

import {Types} from "./libraries/Types.sol";
Expand Down
14 changes: 8 additions & 6 deletions src/PositionsManagerInternal.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.17;

import {IAaveOracle} from "@aave-v3-core/interfaces/IAaveOracle.sol";
import {IPriceOracleSentinel} from "@aave-v3-core/interfaces/IPriceOracleSentinel.sol";
import {IAaveOracle} from "@aave-v3-origin/interfaces/IAaveOracle.sol";
import {IPriceOracleSentinel} from "@aave-v3-origin/interfaces/IPriceOracleSentinel.sol";

import {Types} from "./libraries/Types.sol";
import {Events} from "./libraries/Events.sol";
Expand All @@ -20,9 +20,10 @@ import {PercentageMath} from "@morpho-utils/math/PercentageMath.sol";
import {LogarithmicBuckets} from "@morpho-data-structures/LogarithmicBuckets.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

import {DataTypes} from "@aave-v3-core/protocol/libraries/types/DataTypes.sol";
import {UserConfiguration} from "@aave-v3-core/protocol/libraries/configuration/UserConfiguration.sol";
import {ReserveConfiguration} from "@aave-v3-core/protocol/libraries/configuration/ReserveConfiguration.sol";
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 {ERC20} from "@solmate/tokens/ERC20.sol";

Expand All @@ -47,6 +48,7 @@ abstract contract PositionsManagerInternal is MatchingEngine {

using UserConfiguration for DataTypes.UserConfigurationMap;
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;
using ReserveConfigurationLegacy for DataTypes.ReserveConfigurationMap;

/// @dev Validates the manager's permission.
function _validatePermission(address delegator, address manager) internal view {
Expand Down Expand Up @@ -597,7 +599,7 @@ abstract contract PositionsManagerInternal is MatchingEngine {
) internal view returns (uint256 amountToRepay, uint256 amountToSeize) {
Types.AmountToSeizeVars memory vars;

DataTypes.EModeCategory memory eModeCategory;
DataTypes.EModeCategoryLegacy memory eModeCategory;
if (_eModeCategoryId != 0) eModeCategory = _pool.getEModeCategoryData(_eModeCategoryId);

bool collateralIsInEMode;
Expand Down
2 changes: 1 addition & 1 deletion src/RewardsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.17;
import {IMorpho} from "./interfaces/IMorpho.sol";
import {IPoolToken} from "./interfaces/aave/IPoolToken.sol";
import {IRewardsManager} from "./interfaces/IRewardsManager.sol";
import {IScaledBalanceToken} from "@aave-v3-core/interfaces/IScaledBalanceToken.sol";
import {IScaledBalanceToken} from "@aave-v3-origin/interfaces/IScaledBalanceToken.sol";
import {IRewardsController} from "@aave-v3-periphery/rewards/interfaces/IRewardsController.sol";

import {Types} from "./libraries/Types.sol";
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/aave/IAToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity ^0.8.0;

import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
import {IScaledBalanceToken} from "@aave-v3-core/interfaces/IScaledBalanceToken.sol";
import {IInitializableAToken} from "@aave-v3-core/interfaces/IInitializableAToken.sol";
import {IScaledBalanceToken} from "@aave-v3-origin/interfaces/IScaledBalanceToken.sol";
import {IInitializableAToken} from "@aave-v3-origin/interfaces/IInitializableAToken.sol";

/**
* @title IAToken
Expand Down
6 changes: 6 additions & 0 deletions src/interfaces/aave/IStableDebtTokenLegacy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;

interface IStableDebtTokenLegacy {
function getSupplyData() external view returns (uint256, uint256, uint256, uint40);
}
10 changes: 5 additions & 5 deletions src/libraries/MarketLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.17;

import {IAToken} from "../interfaces/aave/IAToken.sol";
import {IPool} from "@aave-v3-core/interfaces/IPool.sol";
import {IPool} from "@aave-v3-origin/interfaces/IPool.sol";

import {Types} from "./Types.sol";
import {Events} from "./Events.sol";
Expand All @@ -14,8 +14,8 @@ import {WadRayMath} from "@morpho-utils/math/WadRayMath.sol";
import {PercentageMath} from "@morpho-utils/math/PercentageMath.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";

import {DataTypes} from "@aave-v3-core/protocol/libraries/types/DataTypes.sol";
import {ReserveConfiguration} from "@aave-v3-core/protocol/libraries/configuration/ReserveConfiguration.sol";
import {DataTypes} from "@aave-v3-origin/protocol/libraries/types/DataTypes.sol";
import {ReserveConfiguration} from "@aave-v3-origin/protocol/libraries/configuration/ReserveConfiguration.sol";

/// @title MarketLib
/// @author Morpho Labs
Expand All @@ -26,7 +26,7 @@ library MarketLib {
using SafeCast for uint256;
using WadRayMath for uint256;
using MarketLib for Types.Market;
using ReserveDataLib for DataTypes.ReserveData;
using ReserveDataLib for DataTypes.ReserveDataLegacy;
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;

/// @notice Returns whether the `market` is created or not.
Expand Down Expand Up @@ -241,7 +241,7 @@ library MarketLib {
Types.Market storage market,
address underlying,
uint256 amount,
DataTypes.ReserveData memory reserve,
DataTypes.ReserveDataLegacy memory reserve,
Types.Indexes256 memory indexes
) internal returns (uint256, uint256) {
uint256 supplyCap = reserve.configuration.getSupplyCap() * (10 ** reserve.configuration.getDecimals());
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/PoolLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity ^0.8.17;

import {IAToken} from "../interfaces/aave/IAToken.sol";
import {IPool} from "@aave-v3-core/interfaces/IPool.sol";
import {IVariableDebtToken} from "@aave-v3-core/interfaces/IVariableDebtToken.sol";
import {IPool} from "@aave-v3-origin/interfaces/IPool.sol";
import {IVariableDebtToken} from "@aave-v3-origin/interfaces/IVariableDebtToken.sol";

import {Constants} from "./Constants.sol";

Expand Down
25 changes: 25 additions & 0 deletions src/libraries/ReserveConfigurationLegacy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.17;

import {Errors} from "@aave-v3-origin/protocol/libraries/helpers/Errors.sol";
import {DataTypes} from "@aave-v3-origin/protocol/libraries/types/DataTypes.sol";

/// @title ReserveConfigurationLegacy
/// @author Morpho Labs
/// @custom:contact security@morpho.xyz
/// @notice Library used to ease AaveV3's legacy reserve configuration calculations.
library ReserveConfigurationLegacy {
uint256 internal constant EMODE_CATEGORY_START_BIT_POSITION = 168;
uint256 internal constant EMODE_CATEGORY_MASK = 0xFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
uint256 internal constant MAX_VALID_EMODE_CATEGORY = 255;

function getEModeCategory(DataTypes.ReserveConfigurationMap memory self) internal pure returns (uint256) {
return (self.data & ~EMODE_CATEGORY_MASK) >> EMODE_CATEGORY_START_BIT_POSITION;
}

function setEModeCategory(DataTypes.ReserveConfigurationMap memory self, uint256 category) internal pure {
require(category <= MAX_VALID_EMODE_CATEGORY, Errors.INVALID_EMODE_CATEGORY);

self.data = (self.data & EMODE_CATEGORY_MASK) | (category << EMODE_CATEGORY_START_BIT_POSITION);
}
}
14 changes: 7 additions & 7 deletions src/libraries/ReserveDataLib.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.17;

import {IStableDebtToken} from "@aave-v3-core/interfaces/IStableDebtToken.sol";
import {IVariableDebtToken} from "@aave-v3-core/interfaces/IVariableDebtToken.sol";
import {IStableDebtTokenLegacy} from "src/interfaces/aave/IStableDebtTokenLegacy.sol";
import {IVariableDebtToken} from "@aave-v3-origin/interfaces/IVariableDebtToken.sol";

import {Types} from "./Types.sol";

import {WadRayMath} from "@morpho-utils/math/WadRayMath.sol";
import {PercentageMath} from "@morpho-utils/math/PercentageMath.sol";

import {MathUtils} from "@aave-v3-core/protocol/libraries/math/MathUtils.sol";
import {DataTypes} from "@aave-v3-core/protocol/libraries/types/DataTypes.sol";
import {ReserveConfiguration} from "@aave-v3-core/protocol/libraries/configuration/ReserveConfiguration.sol";
import {MathUtils} from "@aave-v3-origin/protocol/libraries/math/MathUtils.sol";
import {DataTypes} from "@aave-v3-origin/protocol/libraries/types/DataTypes.sol";
import {ReserveConfiguration} from "@aave-v3-origin/protocol/libraries/configuration/ReserveConfiguration.sol";

/// @title ReserveDataLib
/// @author Morpho Labs
Expand All @@ -28,7 +28,7 @@ library ReserveDataLib {
/// @param reserve The reserve data of a given market.
/// @param indexes The updated pool & peer-to-peer indexes of the associated market.
/// @return The reserve's dedicated treasury, in pool unit.
function getAccruedToTreasury(DataTypes.ReserveData memory reserve, Types.Indexes256 memory indexes)
function getAccruedToTreasury(DataTypes.ReserveDataLegacy memory reserve, Types.Indexes256 memory indexes)
internal
view
returns (uint256)
Expand All @@ -41,7 +41,7 @@ library ReserveDataLib {
uint256 currTotalStableDebt,
uint256 currAvgStableBorrowRate,
uint40 stableDebtLastUpdateTimestamp
) = IStableDebtToken(reserve.stableDebtTokenAddress).getSupplyData();
) = IStableDebtTokenLegacy(reserve.stableDebtTokenAddress).getSupplyData();
uint256 scaledTotalVariableDebt = IVariableDebtToken(reserve.variableDebtTokenAddress).scaledTotalSupply();

uint256 currTotalVariableDebt = scaledTotalVariableDebt.rayMul(indexes.borrow.poolIndex);
Expand Down
6 changes: 3 additions & 3 deletions src/libraries/Types.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.17;

import {IAaveOracle} from "@aave-v3-core/interfaces/IAaveOracle.sol";
import {IAaveOracle} from "@aave-v3-origin/interfaces/IAaveOracle.sol";

import {DataTypes} from "@aave-v3-core/protocol/libraries/types/DataTypes.sol";
import {DataTypes} from "@aave-v3-origin/protocol/libraries/types/DataTypes.sol";

import {LogarithmicBuckets} from "@morpho-data-structures/LogarithmicBuckets.sol";

Expand Down Expand Up @@ -169,7 +169,7 @@ library Types {
struct LiquidityVars {
address user; // The user address.
IAaveOracle oracle; // The oracle used by Aave.
DataTypes.EModeCategory eModeCategory; // The data related to the eMode category (could be empty if not in any e-mode).
DataTypes.EModeCategoryLegacy eModeCategory; // The data related to the eMode category (could be empty if not in any e-mode).
}

/// @notice Variables used during a borrow or withdraw.
Expand Down
Loading
Loading