From 30cca8f68af0685b855521b6cbb37ba6d1b47fa5 Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 15 Oct 2024 11:03:51 +0200 Subject: [PATCH 1/8] chore: remove aave-v3-core --- .gitmodules | 4 ---- lib/aave-v3-core | 1 - 2 files changed, 5 deletions(-) delete mode 160000 lib/aave-v3-core diff --git a/.gitmodules b/.gitmodules index 8c141fbe..3deca10e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/lib/aave-v3-core b/lib/aave-v3-core deleted file mode 160000 index a00f28e3..00000000 --- a/lib/aave-v3-core +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a00f28e3ad7c0e4a369d8e06e0ac9fd0acabcab7 From 5f746eb617550a22a202b40fc3bd23914b38e5f0 Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 15 Oct 2024 11:07:48 +0200 Subject: [PATCH 2/8] chore: add module aave-v3-origin --- .gitmodules | 3 +++ lib/aave-v3-origin | 1 + remappings.txt | 2 +- script/avalanche-mainnet/Deploy.s.sol | 2 +- script/eth-mainnet/Deploy.s.sol | 2 +- script/eth-mainnet/EthEModeDeploy.s.sol | 6 ++--- src/Morpho.sol | 2 +- src/MorphoInternal.sol | 10 ++++----- src/MorphoSetters.sol | 4 ++-- src/MorphoStorage.sol | 2 +- src/PositionsManager.sol | 2 +- src/PositionsManagerInternal.sol | 10 ++++----- src/RewardsManager.sol | 2 +- src/interfaces/aave/IAToken.sol | 4 ++-- src/libraries/MarketLib.sol | 6 ++--- src/libraries/PoolLib.sol | 4 ++-- src/libraries/ReserveDataLib.sol | 10 ++++----- src/libraries/Types.sol | 4 ++-- test/helpers/ForkTest.sol | 22 +++++++++---------- test/helpers/ReserveDataTestLib.sol | 4 ++-- test/helpers/TestMarketLib.sol | 2 +- .../TestIntegrationAssetAsCollateral.sol | 2 +- test/integration/TestIntegrationPoolLib.sol | 4 ++-- .../TestIntegrationRewardsManager.sol | 2 +- test/internal/TestInternalEMode.sol | 6 ++--- test/internal/TestInternalMorphoInternal.sol | 4 ++-- ...stInternalPositionsManagerInternalCaps.sol | 2 +- test/mocks/AaveOracleMock.sol | 4 ++-- test/mocks/FlashBorrowerMock.sol | 2 +- test/mocks/PriceOracleSentinelMock.sol | 2 +- test/mocks/UserMock.sol | 2 +- 31 files changed, 69 insertions(+), 65 deletions(-) create mode 160000 lib/aave-v3-origin diff --git a/.gitmodules b/.gitmodules index 3deca10e..e26d5bb5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -21,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 diff --git a/lib/aave-v3-origin b/lib/aave-v3-origin new file mode 160000 index 00000000..ec33f4fc --- /dev/null +++ b/lib/aave-v3-origin @@ -0,0 +1 @@ +Subproject commit ec33f4fcc5546710c0faca5208af1775c761ac9c diff --git a/remappings.txt b/remappings.txt index 6c1de783..fad31ddd 100644 --- a/remappings.txt +++ b/remappings.txt @@ -11,7 +11,7 @@ config/=config/ @openzeppelin/=lib/morpho-utils/lib/openzeppelin-contracts/ @openzeppelin-upgradeable/=lib/morpho-utils/lib/openzeppelin-contracts-upgradeable/contracts/ -@aave-v3-core/=lib/aave-v3-core/contracts/ +@aave-v3-origin/=lib/aave-v3-core/src/contracts/ @aave-v3-periphery/=lib/aave-v3-periphery/contracts/ @solmate/=lib/solmate/src/ diff --git a/script/avalanche-mainnet/Deploy.s.sol b/script/avalanche-mainnet/Deploy.s.sol index bc141f77..138037f4 100644 --- a/script/avalanche-mainnet/Deploy.s.sol +++ b/script/avalanche-mainnet/Deploy.s.sol @@ -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"; diff --git a/script/eth-mainnet/Deploy.s.sol b/script/eth-mainnet/Deploy.s.sol index 16cc69c2..0cd2face 100644 --- a/script/eth-mainnet/Deploy.s.sol +++ b/script/eth-mainnet/Deploy.s.sol @@ -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"; diff --git a/script/eth-mainnet/EthEModeDeploy.s.sol b/script/eth-mainnet/EthEModeDeploy.s.sol index 18e9cc13..173e5bf6 100644 --- a/script/eth-mainnet/EthEModeDeploy.s.sol +++ b/script/eth-mainnet/EthEModeDeploy.s.sol @@ -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"; diff --git a/src/Morpho.sol b/src/Morpho.sol index 5d5e763e..9f175165 100644 --- a/src/Morpho.sol +++ b/src/Morpho.sol @@ -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"; diff --git a/src/MorphoInternal.sol b/src/MorphoInternal.sol index bb12d842..77862729 100644 --- a/src/MorphoInternal.sol +++ b/src/MorphoInternal.sol @@ -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"; @@ -24,9 +24,9 @@ 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 {MorphoStorage} from "./MorphoStorage.sol"; diff --git a/src/MorphoSetters.sol b/src/MorphoSetters.sol index 1ccb73e4..300c5747 100644 --- a/src/MorphoSetters.sol +++ b/src/MorphoSetters.sol @@ -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"; diff --git a/src/MorphoStorage.sol b/src/MorphoStorage.sol index 7171fec1..7879f3b6 100644 --- a/src/MorphoStorage.sol +++ b/src/MorphoStorage.sol @@ -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"; diff --git a/src/PositionsManager.sol b/src/PositionsManager.sol index 42b76216..8ee0e2df 100644 --- a/src/PositionsManager.sol +++ b/src/PositionsManager.sol @@ -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"; diff --git a/src/PositionsManagerInternal.sol b/src/PositionsManagerInternal.sol index a7bcf68a..60e4fc71 100644 --- a/src/PositionsManagerInternal.sol +++ b/src/PositionsManagerInternal.sol @@ -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"; @@ -20,9 +20,9 @@ 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 {ERC20} from "@solmate/tokens/ERC20.sol"; diff --git a/src/RewardsManager.sol b/src/RewardsManager.sol index da1220b5..0e7c553c 100644 --- a/src/RewardsManager.sol +++ b/src/RewardsManager.sol @@ -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"; diff --git a/src/interfaces/aave/IAToken.sol b/src/interfaces/aave/IAToken.sol index d4f0a93b..75b894f9 100644 --- a/src/interfaces/aave/IAToken.sol +++ b/src/interfaces/aave/IAToken.sol @@ -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 diff --git a/src/libraries/MarketLib.sol b/src/libraries/MarketLib.sol index 74047248..d6a22229 100644 --- a/src/libraries/MarketLib.sol +++ b/src/libraries/MarketLib.sol @@ -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"; @@ -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 diff --git a/src/libraries/PoolLib.sol b/src/libraries/PoolLib.sol index a6ec870e..4ccbebbf 100644 --- a/src/libraries/PoolLib.sol +++ b/src/libraries/PoolLib.sol @@ -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"; diff --git a/src/libraries/ReserveDataLib.sol b/src/libraries/ReserveDataLib.sol index 487c05c8..d4b76860 100644 --- a/src/libraries/ReserveDataLib.sol +++ b/src/libraries/ReserveDataLib.sol @@ -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 {IStableDebtToken} from "@aave-v3-origin/interfaces/IStableDebtToken.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 diff --git a/src/libraries/Types.sol b/src/libraries/Types.sol index c58059ea..acc51c73 100644 --- a/src/libraries/Types.sol +++ b/src/libraries/Types.sol @@ -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"; diff --git a/test/helpers/ForkTest.sol b/test/helpers/ForkTest.sol index 6e8837b9..4b6ba739 100644 --- a/test/helpers/ForkTest.sol +++ b/test/helpers/ForkTest.sol @@ -2,23 +2,23 @@ pragma solidity ^0.8.0; import {IAToken} from "src/interfaces/aave/IAToken.sol"; -import {IAaveOracle} from "@aave-v3-core/interfaces/IAaveOracle.sol"; -import {IPriceOracleGetter} from "@aave-v3-core/interfaces/IPriceOracleGetter.sol"; -import {IACLManager} from "@aave-v3-core/interfaces/IACLManager.sol"; +import {IAaveOracle} from "@aave-v3-origin/interfaces/IAaveOracle.sol"; +import {IPriceOracleGetter} from "@aave-v3-origin/interfaces/IPriceOracleGetter.sol"; +import {IACLManager} from "@aave-v3-origin/interfaces/IACLManager.sol"; import {IPoolConfigurator} from "test/helpers/IPoolConfigurator.sol"; -import {IPoolDataProvider} from "@aave-v3-core/interfaces/IPoolDataProvider.sol"; -import {IPool, IPoolAddressesProvider} from "@aave-v3-core/interfaces/IPool.sol"; -import {IStableDebtToken} from "@aave-v3-core/interfaces/IStableDebtToken.sol"; -import {IVariableDebtToken} from "@aave-v3-core/interfaces/IVariableDebtToken.sol"; +import {IPoolDataProvider} from "@aave-v3-origin/interfaces/IPoolDataProvider.sol"; +import {IPool, IPoolAddressesProvider} from "@aave-v3-origin/interfaces/IPool.sol"; +import {IStableDebtToken} from "@aave-v3-origin/interfaces/IStableDebtToken.sol"; +import {IVariableDebtToken} from "@aave-v3-origin/interfaces/IVariableDebtToken.sol"; import {IRewardsController} from "@aave-v3-periphery/rewards/interfaces/IRewardsController.sol"; import {ReserveDataLib} from "src/libraries/ReserveDataLib.sol"; import {ReserveDataTestLib} from "test/helpers/ReserveDataTestLib.sol"; import {Config, ConfigLib} from "config/ConfigLib.sol"; -import {MathUtils} from "@aave-v3-core/protocol/libraries/math/MathUtils.sol"; -import {DataTypes} from "@aave-v3-core/protocol/libraries/types/DataTypes.sol"; -import {Errors as AaveErrors} from "@aave-v3-core/protocol/libraries/helpers/Errors.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 {Errors as AaveErrors} from "@aave-v3-origin/protocol/libraries/helpers/Errors.sol"; +import {ReserveConfiguration} from "@aave-v3-origin/protocol/libraries/configuration/ReserveConfiguration.sol"; import {PermitHash} from "@permit2/libraries/PermitHash.sol"; import {IAllowanceTransfer, AllowanceTransfer} from "@permit2/AllowanceTransfer.sol"; diff --git a/test/helpers/ReserveDataTestLib.sol b/test/helpers/ReserveDataTestLib.sol index 90489136..d3a49011 100644 --- a/test/helpers/ReserveDataTestLib.sol +++ b/test/helpers/ReserveDataTestLib.sol @@ -5,8 +5,8 @@ import {IAToken} from "src/interfaces/aave/IAToken.sol"; import {Types} from "src/libraries/Types.sol"; import {ReserveDataLib} from "src/libraries/ReserveDataLib.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"; import {WadRayMath} from "@morpho-utils/math/WadRayMath.sol"; import {Math} from "@morpho-utils/math/Math.sol"; diff --git a/test/helpers/TestMarketLib.sol b/test/helpers/TestMarketLib.sol index 0d76b859..7773a955 100644 --- a/test/helpers/TestMarketLib.sol +++ b/test/helpers/TestMarketLib.sol @@ -5,7 +5,7 @@ import {Constants} from "src/libraries/Constants.sol"; import {Math} from "@morpho-utils/math/Math.sol"; import {PercentageMath} from "@morpho-utils/math/PercentageMath.sol"; -import {DataTypes} from "@aave-v3-core/protocol/libraries/types/DataTypes.sol"; +import {DataTypes} from "@aave-v3-origin/protocol/libraries/types/DataTypes.sol"; import {collateralValue, rawCollateralValue} from "test/helpers/Utils.sol"; import {ERC20} from "@solmate/tokens/ERC20.sol"; diff --git a/test/integration/TestIntegrationAssetAsCollateral.sol b/test/integration/TestIntegrationAssetAsCollateral.sol index 0eb27893..9c50001e 100644 --- a/test/integration/TestIntegrationAssetAsCollateral.sol +++ b/test/integration/TestIntegrationAssetAsCollateral.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {IMorpho} from "src/interfaces/IMorpho.sol"; import {Errors} from "src/libraries/Errors.sol"; -import {UserConfiguration} from "@aave-v3-core/protocol/libraries/configuration/UserConfiguration.sol"; +import {UserConfiguration} from "@aave-v3-origin/protocol/libraries/configuration/UserConfiguration.sol"; import {Morpho} from "src/Morpho.sol"; diff --git a/test/integration/TestIntegrationPoolLib.sol b/test/integration/TestIntegrationPoolLib.sol index 4cf182fc..8d0602a0 100644 --- a/test/integration/TestIntegrationPoolLib.sol +++ b/test/integration/TestIntegrationPoolLib.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; -import {IPool, IPoolAddressesProvider} from "@aave-v3-core/interfaces/IPool.sol"; +import {IPool, IPoolAddressesProvider} from "@aave-v3-origin/interfaces/IPool.sol"; import {PoolLib} from "src/libraries/PoolLib.sol"; -import {DataTypes} from "@aave-v3-core/protocol/libraries/types/DataTypes.sol"; +import {DataTypes} from "@aave-v3-origin/protocol/libraries/types/DataTypes.sol"; import "test/helpers/ForkTest.sol"; diff --git a/test/integration/TestIntegrationRewardsManager.sol b/test/integration/TestIntegrationRewardsManager.sol index 4c83357b..1f3a9c81 100644 --- a/test/integration/TestIntegrationRewardsManager.sol +++ b/test/integration/TestIntegrationRewardsManager.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; -import {IScaledBalanceToken} from "@aave-v3-core/interfaces/IScaledBalanceToken.sol"; +import {IScaledBalanceToken} from "@aave-v3-origin/interfaces/IScaledBalanceToken.sol"; import {IEACAggregatorProxy} from "@aave-v3-periphery/misc/interfaces/IEACAggregatorProxy.sol"; import {ITransferStrategyBase} from "@aave-v3-periphery/rewards/interfaces/ITransferStrategyBase.sol"; diff --git a/test/internal/TestInternalEMode.sol b/test/internal/TestInternalEMode.sol index b99e5813..b0a070d7 100644 --- a/test/internal/TestInternalEMode.sol +++ b/test/internal/TestInternalEMode.sol @@ -2,16 +2,16 @@ pragma solidity ^0.8.0; import {IMorpho} from "src/interfaces/IMorpho.sol"; -import {IPool} from "@aave-v3-core/interfaces/IPool.sol"; +import {IPool} from "@aave-v3-origin/interfaces/IPool.sol"; -import {DataTypes} from "@aave-v3-core/protocol/libraries/types/DataTypes.sol"; +import {DataTypes} from "@aave-v3-origin/protocol/libraries/types/DataTypes.sol"; import {Types} from "src/libraries/Types.sol"; import {PoolLib} from "src/libraries/PoolLib.sol"; import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; -import {ReserveConfiguration} from "@aave-v3-core/protocol/libraries/configuration/ReserveConfiguration.sol"; +import {ReserveConfiguration} from "@aave-v3-origin/protocol/libraries/configuration/ReserveConfiguration.sol"; import {ERC20, SafeTransferLib} from "@solmate/utils/SafeTransferLib.sol"; diff --git a/test/internal/TestInternalMorphoInternal.sol b/test/internal/TestInternalMorphoInternal.sol index 8abf8812..5ed69d0c 100644 --- a/test/internal/TestInternalMorphoInternal.sol +++ b/test/internal/TestInternalMorphoInternal.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; -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"; import {LogarithmicBuckets} from "@morpho-data-structures/LogarithmicBuckets.sol"; import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; diff --git a/test/internal/TestInternalPositionsManagerInternalCaps.sol b/test/internal/TestInternalPositionsManagerInternalCaps.sol index 15643cc1..42ca4ca8 100644 --- a/test/internal/TestInternalPositionsManagerInternalCaps.sol +++ b/test/internal/TestInternalPositionsManagerInternalCaps.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; -import {IPriceOracleGetter} from "@aave-v3-core/interfaces/IPriceOracleGetter.sol"; +import {IPriceOracleGetter} from "@aave-v3-origin/interfaces/IPriceOracleGetter.sol"; import {PoolLib} from "src/libraries/PoolLib.sol"; import {MarketLib} from "src/libraries/MarketLib.sol"; diff --git a/test/mocks/AaveOracleMock.sol b/test/mocks/AaveOracleMock.sol index 2eb69e5d..f7bca682 100644 --- a/test/mocks/AaveOracleMock.sol +++ b/test/mocks/AaveOracleMock.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; -import {IAaveOracle} from "@aave-v3-core/interfaces/IAaveOracle.sol"; -import {IPoolAddressesProvider} from "@aave-v3-core/interfaces/IPoolAddressesProvider.sol"; +import {IAaveOracle} from "@aave-v3-origin/interfaces/IAaveOracle.sol"; +import {IPoolAddressesProvider} from "@aave-v3-origin/interfaces/IPoolAddressesProvider.sol"; contract AaveOracleMock is IAaveOracle { address public immutable BASE_CURRENCY; diff --git a/test/mocks/FlashBorrowerMock.sol b/test/mocks/FlashBorrowerMock.sol index 905f919c..c6d661c9 100644 --- a/test/mocks/FlashBorrowerMock.sol +++ b/test/mocks/FlashBorrowerMock.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; -import {IPool} from "@aave-v3-core/interfaces/IPool.sol"; +import {IPool} from "@aave-v3-origin/interfaces/IPool.sol"; import {SafeTransferLib, ERC20} from "@solmate/utils/SafeTransferLib.sol"; diff --git a/test/mocks/PriceOracleSentinelMock.sol b/test/mocks/PriceOracleSentinelMock.sol index 11943a40..9bb3a7fe 100644 --- a/test/mocks/PriceOracleSentinelMock.sol +++ b/test/mocks/PriceOracleSentinelMock.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; -import {IPoolAddressesProvider} from "@aave-v3-core/interfaces/IPoolAddressesProvider.sol"; +import {IPoolAddressesProvider} from "@aave-v3-origin/interfaces/IPoolAddressesProvider.sol"; contract PriceOracleSentinelMock { bool internal borrowAllowed; diff --git a/test/mocks/UserMock.sol b/test/mocks/UserMock.sol index 0487c424..c8e8b069 100644 --- a/test/mocks/UserMock.sol +++ b/test/mocks/UserMock.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import {IMorpho} from "src/interfaces/IMorpho.sol"; import {ERC4626UpgradeableSafe} from "@morpho-utils/ERC4626UpgradeableSafe.sol"; -import {IPool} from "@aave-v3-core/interfaces/IPool.sol"; +import {IPool} from "@aave-v3-origin/interfaces/IPool.sol"; import {ERC20, SafeTransferLib} from "@solmate/utils/SafeTransferLib.sol"; From 8500dafe1c35d6c158642ad60c04116c43b996b3 Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 15 Oct 2024 12:14:18 +0200 Subject: [PATCH 3/8] refactor: adapt to aave-v3-origin without changes --- remappings.txt | 2 +- src/MorphoInternal.sol | 4 +- src/PositionsManagerInternal.sol | 4 +- src/libraries/MarketLib.sol | 4 +- src/libraries/ReserveConfigurationLegacy.sol | 25 ++++++++++++ src/libraries/ReserveDataLib.sol | 3 +- src/libraries/Types.sol | 2 +- test/helpers/ForkTest.sol | 11 +++--- test/helpers/IntegrationTest.sol | 5 ++- test/helpers/ProductionTest.sol | 3 +- test/helpers/ReserveDataTestLib.sol | 39 +++++++++---------- test/helpers/TestMarketLib.sol | 2 +- .../TestIntegrationEModeNative.sol | 1 + .../TestIntegrationMorphoSetters.sol | 4 +- test/integration/TestIntegrationPoolLib.sol | 2 +- test/internal/TestInternalEMode.sol | 7 ++-- test/internal/TestInternalMorphoInternal.sol | 18 ++++----- .../TestInternalPositionsManagerInternal.sol | 6 +-- ...stInternalPositionsManagerInternalCaps.sol | 4 +- test/unit/TestUnitMarketLibIdle.sol | 10 ++--- 20 files changed, 94 insertions(+), 62 deletions(-) create mode 100644 src/libraries/ReserveConfigurationLegacy.sol diff --git a/remappings.txt b/remappings.txt index fad31ddd..5e6d10d8 100644 --- a/remappings.txt +++ b/remappings.txt @@ -11,7 +11,7 @@ config/=config/ @openzeppelin/=lib/morpho-utils/lib/openzeppelin-contracts/ @openzeppelin-upgradeable/=lib/morpho-utils/lib/openzeppelin-contracts-upgradeable/contracts/ -@aave-v3-origin/=lib/aave-v3-core/src/contracts/ +@aave-v3-origin/=lib/aave-v3-origin/src/contracts/ @aave-v3-periphery/=lib/aave-v3-periphery/contracts/ @solmate/=lib/solmate/src/ diff --git a/src/MorphoInternal.sol b/src/MorphoInternal.sol index 77862729..727c836b 100644 --- a/src/MorphoInternal.sol +++ b/src/MorphoInternal.sol @@ -27,6 +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 {MorphoStorage} from "./MorphoStorage.sol"; @@ -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 */ @@ -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); + DataTypes.ReserveDataLegacy memory reserve = _pool.getReserveData(underlying); if (!reserve.configuration.getActive()) revert Errors.MarketIsNotListedOnAave(); if (reserve.configuration.getSiloedBorrowing()) revert Errors.SiloedBorrowMarket(); diff --git a/src/PositionsManagerInternal.sol b/src/PositionsManagerInternal.sol index 60e4fc71..15dc7941 100644 --- a/src/PositionsManagerInternal.sol +++ b/src/PositionsManagerInternal.sol @@ -23,6 +23,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 {ERC20} from "@solmate/tokens/ERC20.sol"; @@ -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 { @@ -596,7 +598,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; diff --git a/src/libraries/MarketLib.sol b/src/libraries/MarketLib.sol index d6a22229..d4ecc5b9 100644 --- a/src/libraries/MarketLib.sol +++ b/src/libraries/MarketLib.sol @@ -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. @@ -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()); diff --git a/src/libraries/ReserveConfigurationLegacy.sol b/src/libraries/ReserveConfigurationLegacy.sol new file mode 100644 index 00000000..aa9909ec --- /dev/null +++ b/src/libraries/ReserveConfigurationLegacy.sol @@ -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); + } +} diff --git a/src/libraries/ReserveDataLib.sol b/src/libraries/ReserveDataLib.sol index d4b76860..6e5c5e58 100644 --- a/src/libraries/ReserveDataLib.sol +++ b/src/libraries/ReserveDataLib.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.17; -import {IStableDebtToken} from "@aave-v3-origin/interfaces/IStableDebtToken.sol"; import {IVariableDebtToken} from "@aave-v3-origin/interfaces/IVariableDebtToken.sol"; import {Types} from "./Types.sol"; @@ -28,7 +27,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) diff --git a/src/libraries/Types.sol b/src/libraries/Types.sol index acc51c73..28184378 100644 --- a/src/libraries/Types.sol +++ b/src/libraries/Types.sol @@ -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. diff --git a/test/helpers/ForkTest.sol b/test/helpers/ForkTest.sol index 4b6ba739..2e2633ef 100644 --- a/test/helpers/ForkTest.sol +++ b/test/helpers/ForkTest.sol @@ -8,7 +8,6 @@ import {IACLManager} from "@aave-v3-origin/interfaces/IACLManager.sol"; import {IPoolConfigurator} from "test/helpers/IPoolConfigurator.sol"; import {IPoolDataProvider} from "@aave-v3-origin/interfaces/IPoolDataProvider.sol"; import {IPool, IPoolAddressesProvider} from "@aave-v3-origin/interfaces/IPool.sol"; -import {IStableDebtToken} from "@aave-v3-origin/interfaces/IStableDebtToken.sol"; import {IVariableDebtToken} from "@aave-v3-origin/interfaces/IVariableDebtToken.sol"; import {IRewardsController} from "@aave-v3-periphery/rewards/interfaces/IRewardsController.sol"; @@ -19,6 +18,7 @@ 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"; @@ -35,9 +35,10 @@ contract ForkTest is BaseTest, Configured { using PercentageMath for uint256; using SafeTransferLib for ERC20; using ConfigLib for Config; - using ReserveDataLib for DataTypes.ReserveData; - using ReserveDataTestLib for DataTypes.ReserveData; + using ReserveDataLib for DataTypes.ReserveDataLegacy; + using ReserveDataTestLib for DataTypes.ReserveDataLegacy; using ReserveConfiguration for DataTypes.ReserveConfigurationMap; + using ReserveConfigurationLegacy for DataTypes.ReserveConfigurationMap; /* STRUCTS */ @@ -223,7 +224,7 @@ contract ForkTest is BaseTest, Configured { /// @dev Returns the total supply used towards the supply cap. function _totalSupplyToCap(address underlying) internal view returns (uint256) { - DataTypes.ReserveData memory reserve = pool.getReserveData(underlying); + DataTypes.ReserveDataLegacy memory reserve = pool.getReserveData(underlying); uint256 poolSupplyIndex = pool.getReserveNormalizedIncome(underlying); uint256 poolBorrowIndex = pool.getReserveNormalizedVariableDebt(underlying); @@ -254,7 +255,7 @@ contract ForkTest is BaseTest, Configured { } function _setEModeCategoryAsset( - DataTypes.EModeCategory memory eModeCategory, + DataTypes.EModeCategoryLegacy memory eModeCategory, address underlying, uint8 eModeCategoryId ) internal { diff --git a/test/helpers/IntegrationTest.sol b/test/helpers/IntegrationTest.sol index 351ab384..e73d8bf2 100644 --- a/test/helpers/IntegrationTest.sol +++ b/test/helpers/IntegrationTest.sol @@ -27,6 +27,7 @@ contract IntegrationTest is ForkTest { using PercentageMath for uint256; using ReserveDataTestLib for DataTypes.ReserveData; using ReserveConfiguration for DataTypes.ReserveConfigurationMap; + using ReserveConfigurationLegacy for DataTypes.ReserveConfigurationMap; using TestMarketLib for TestMarket; uint256 internal constant INITIAL_BALANCE = 10_000_000_000 ether; @@ -122,7 +123,7 @@ contract IntegrationTest is ForkTest { function _initMarket(address underlying, uint16 reserveFactor, uint16 p2pIndexCursor) internal virtual - returns (TestMarket storage market, DataTypes.ReserveData memory reserve) + returns (TestMarket storage market, DataTypes.ReserveDataLegacy memory reserve) { market = testMarkets[underlying]; reserve = pool.getReserveData(underlying); @@ -136,7 +137,7 @@ contract IntegrationTest is ForkTest { market.p2pIndexCursor = p2pIndexCursor; market.price = oracle.getAssetPrice(underlying); // Price is constant, equal to price at fork block number. - (market.ltv, market.lt, market.liquidationBonus, market.decimals,,) = reserve.configuration.getParams(); + (market.ltv, market.lt, market.liquidationBonus, market.decimals,) = reserve.configuration.getParams(); market.minAmount = (MIN_USD_AMOUNT * 10 ** market.decimals) / market.price; market.maxAmount = (MAX_USD_AMOUNT * 10 ** market.decimals) / market.price; diff --git a/test/helpers/ProductionTest.sol b/test/helpers/ProductionTest.sol index 08600a43..54c6ea90 100644 --- a/test/helpers/ProductionTest.sol +++ b/test/helpers/ProductionTest.sol @@ -5,6 +5,7 @@ import "./IntegrationTest.sol"; contract ProductionTest is IntegrationTest { using ReserveConfiguration for DataTypes.ReserveConfigurationMap; + using ReserveConfigurationLegacy for DataTypes.ReserveConfigurationMap; using TestMarketLib for TestMarket; using ConfigLib for Config; @@ -54,7 +55,7 @@ contract ProductionTest is IntegrationTest { market.p2pIndexCursor = morphoMarket.p2pIndexCursor; market.price = oracle.getAssetPrice(underlying); // Price is constant, equal to price at fork block number. - (market.ltv, market.lt, market.liquidationBonus, market.decimals,,) = configuration.getParams(); + (market.ltv, market.lt, market.liquidationBonus, market.decimals,) = configuration.getParams(); market.minAmount = (MIN_USD_AMOUNT * 10 ** market.decimals) / market.price; market.maxAmount = (MAX_USD_AMOUNT * 10 ** market.decimals) / market.price; diff --git a/test/helpers/ReserveDataTestLib.sol b/test/helpers/ReserveDataTestLib.sol index d3a49011..984f1d86 100644 --- a/test/helpers/ReserveDataTestLib.sol +++ b/test/helpers/ReserveDataTestLib.sol @@ -19,46 +19,45 @@ library ReserveDataTestLib { using ReserveConfiguration for DataTypes.ReserveConfigurationMap; /// @dev Returns the quantity currently supplied on the market on AaveV3. - function totalSupply(DataTypes.ReserveData memory reserve) internal view returns (uint256) { + function totalSupply(DataTypes.ReserveDataLegacy memory reserve) internal view returns (uint256) { return ERC20(reserve.aTokenAddress).totalSupply(); } - /// @dev Returns the quantity currently borrowed (with variable & stable rates) on the market on AaveV3. - function totalBorrow(DataTypes.ReserveData memory reserve) internal view returns (uint256) { - return totalVariableBorrow(reserve) + totalStableBorrow(reserve); + /// @dev Returns the quantity currently borrowed (with variable only, stable being deprecated) on the market on AaveV3. + function totalBorrow(DataTypes.ReserveDataLegacy memory reserve) internal view returns (uint256) { + return totalVariableBorrow(reserve); } /// @dev Returns the quantity currently borrowed with variable rate from the market on AaveV3. - function totalVariableBorrow(DataTypes.ReserveData memory reserve) internal view returns (uint256) { + function totalVariableBorrow(DataTypes.ReserveDataLegacy memory reserve) internal view returns (uint256) { return ERC20(reserve.variableDebtTokenAddress).totalSupply(); } - /// @dev Returns the quantity currently borrowed with stable rate from the market on AaveV3. - function totalStableBorrow(DataTypes.ReserveData memory reserve) internal view returns (uint256) { - return ERC20(reserve.stableDebtTokenAddress).totalSupply(); - } - /// @dev Returns the quantity currently supplied on behalf of the user, on the market on AaveV3. - function supplyOf(DataTypes.ReserveData memory reserve, address user) internal view returns (uint256) { + function supplyOf(DataTypes.ReserveDataLegacy memory reserve, address user) internal view returns (uint256) { return ERC20(reserve.aTokenAddress).balanceOf(user); } /// @dev Returns the quantity currently borrowed on behalf of the user, with variable rate, on the market on AaveV3. - function variableBorrowOf(DataTypes.ReserveData memory reserve, address user) internal view returns (uint256) { + function variableBorrowOf(DataTypes.ReserveDataLegacy memory reserve, address user) + internal + view + returns (uint256) + { return ERC20(reserve.variableDebtTokenAddress).balanceOf(user); } /// @dev Returns the quantity currently borrowed on behalf of the user, with stable rate, on the market on AaveV3. - function stableBorrowOf(DataTypes.ReserveData memory reserve, address user) internal view returns (uint256) { + function stableBorrowOf(DataTypes.ReserveDataLegacy memory reserve, address user) internal view returns (uint256) { return ERC20(reserve.stableDebtTokenAddress).balanceOf(user); } /// @dev Returns the total supply used towards the supply cap. - function totalSupplyToCap(DataTypes.ReserveData memory reserve, uint256 poolSupplyIndex, uint256 poolBorrowIndex) - internal - view - returns (uint256) - { + function totalSupplyToCap( + DataTypes.ReserveDataLegacy memory reserve, + uint256 poolSupplyIndex, + uint256 poolBorrowIndex + ) internal view returns (uint256) { return ( IAToken(reserve.aTokenAddress).scaledTotalSupply() + ReserveDataLib.getAccruedToTreasury( @@ -72,7 +71,7 @@ library ReserveDataTestLib { } /// @dev Calculates the underlying amount that can be supplied on the given market on AaveV3, reaching the supply cap. - function supplyGap(DataTypes.ReserveData memory reserve, uint256 poolSupplyIndex, uint256 poolBorrowIndex) + function supplyGap(DataTypes.ReserveDataLegacy memory reserve, uint256 poolSupplyIndex, uint256 poolBorrowIndex) internal view returns (uint256) @@ -83,7 +82,7 @@ library ReserveDataTestLib { } /// @dev Calculates the underlying amount that can be borrowed on the given market on AaveV3, reaching the borrow cap. - function borrowGap(DataTypes.ReserveData memory reserve) internal view returns (uint256) { + function borrowGap(DataTypes.ReserveDataLegacy memory reserve) internal view returns (uint256) { return (reserve.configuration.getBorrowCap() * 10 ** reserve.configuration.getDecimals()).zeroFloorSub( totalBorrow(reserve) ); diff --git a/test/helpers/TestMarketLib.sol b/test/helpers/TestMarketLib.sol index 7773a955..99cecdf0 100644 --- a/test/helpers/TestMarketLib.sol +++ b/test/helpers/TestMarketLib.sol @@ -32,7 +32,7 @@ struct TestMarket { uint256 maxAmount; // uint8 eModeCategoryId; - DataTypes.EModeCategory eModeCategory; + DataTypes.EModeCategoryLegacy eModeCategory; // bool isInEMode; bool isCollateral; diff --git a/test/integration/TestIntegrationEModeNative.sol b/test/integration/TestIntegrationEModeNative.sol index 16c17f24..35eb67ad 100644 --- a/test/integration/TestIntegrationEModeNative.sol +++ b/test/integration/TestIntegrationEModeNative.sol @@ -11,6 +11,7 @@ contract TestIntegrationEModeNative is IntegrationTest { using PercentageMath for uint256; using TestMarketLib for TestMarket; using ReserveConfiguration for DataTypes.ReserveConfigurationMap; + using ReserveConfigurationLegacy for DataTypes.ReserveConfigurationMap; function setUp() public virtual override { DataTypes.ReserveConfigurationMap memory lsdConfig = pool.getConfiguration(stNative); diff --git a/test/integration/TestIntegrationMorphoSetters.sol b/test/integration/TestIntegrationMorphoSetters.sol index 6ad4d57d..f64b42dc 100644 --- a/test/integration/TestIntegrationMorphoSetters.sol +++ b/test/integration/TestIntegrationMorphoSetters.sol @@ -24,7 +24,7 @@ contract TestIntegrationMorphoSetters is IntegrationTest { } function testShouldNotCreateSiloedBorrowMarket(uint16 reserveFactor, uint16 p2pIndexCursor) public { - DataTypes.ReserveData memory reserve = pool.getReserveData(link); + DataTypes.ReserveDataLegacy memory reserve = pool.getReserveData(link); reserve.configuration.setSiloedBorrowing(true); vm.mockCall(address(pool), abi.encodeCall(pool.getReserveData, (link)), abi.encode(reserve)); @@ -94,7 +94,7 @@ contract TestIntegrationMorphoSetters is IntegrationTest { morpho.createMarket(link, reserveFactor, p2pIndexCursor); Types.Market memory market = morpho.market(link); - DataTypes.ReserveData memory reserveData = pool.getReserveData(link); + DataTypes.ReserveDataLegacy memory reserveData = pool.getReserveData(link); assertEq(market.indexes.supply.poolIndex, expectedPoolSupplyIndex, "supply pool index"); assertEq(market.indexes.supply.p2pIndex, WadRayMath.RAY, "supply p2p index"); diff --git a/test/integration/TestIntegrationPoolLib.sol b/test/integration/TestIntegrationPoolLib.sol index 8d0602a0..87b13dbc 100644 --- a/test/integration/TestIntegrationPoolLib.sol +++ b/test/integration/TestIntegrationPoolLib.sol @@ -20,7 +20,7 @@ contract TestIntegrationPoolLib is ForkTest { constructor() { ERC20(dai).approve(address(pool), type(uint256).max); - DataTypes.ReserveData memory reserveData = pool.getReserveData(dai); + DataTypes.ReserveDataLegacy memory reserveData = pool.getReserveData(dai); aDai = reserveData.aTokenAddress; vDai = reserveData.variableDebtTokenAddress; } diff --git a/test/internal/TestInternalEMode.sol b/test/internal/TestInternalEMode.sol index b0a070d7..5176e9bd 100644 --- a/test/internal/TestInternalEMode.sol +++ b/test/internal/TestInternalEMode.sol @@ -27,6 +27,7 @@ contract TestInternalEMode is InternalTest, PositionsManagerInternal { using ConfigLib for Config; using SafeTransferLib for ERC20; using ReserveConfiguration for DataTypes.ReserveConfigurationMap; + using ReserveConfigurationLegacy for DataTypes.ReserveConfigurationMap; struct AssetData { uint256 underlyingPrice; @@ -68,7 +69,7 @@ contract TestInternalEMode is InternalTest, PositionsManagerInternal { vm.assume(uint256(assetData.ltEMode).percentMul(uint256(liquidationBonus)) <= PercentageMath.PERCENTAGE_FACTOR); vm.assume(assetData.underlyingPrice != assetData.underlyingPriceEMode); - DataTypes.EModeCategory memory eModeCategory = DataTypes.EModeCategory({ + DataTypes.EModeCategoryLegacy memory eModeCategory = DataTypes.EModeCategoryLegacy({ ltv: assetData.ltvEMode, liquidationThreshold: assetData.ltEMode, liquidationBonus: liquidationBonus, @@ -121,7 +122,7 @@ contract TestInternalEMode is InternalTest, PositionsManagerInternal { liquidationBonus = uint16(bound(liquidationBonus, PercentageMath.PERCENTAGE_FACTOR + 1, type(uint16).max)); vm.assume(uint256(lt).percentMul(liquidationBonus) <= PercentageMath.PERCENTAGE_FACTOR); - DataTypes.EModeCategory memory eModeCategory = DataTypes.EModeCategory({ + DataTypes.EModeCategoryLegacy memory eModeCategory = DataTypes.EModeCategoryLegacy({ ltv: ltv, liquidationThreshold: lt, liquidationBonus: liquidationBonus, @@ -250,7 +251,7 @@ contract TestInternalEMode is InternalTest, PositionsManagerInternal { function testShouldNotAuthorizeBorrowInconsistentEmode( uint8 eModeCategoryId, Types.Indexes256 memory indexes, - DataTypes.EModeCategory memory eModeCategory + DataTypes.EModeCategoryLegacy memory eModeCategory ) public { eModeCategoryId = uint8(bound(uint256(eModeCategoryId), 1, type(uint8).max)); (uint256 ltvBound, uint256 ltBound,,) = _getLtvLt(dai, eModeCategoryId); diff --git a/test/internal/TestInternalMorphoInternal.sol b/test/internal/TestInternalMorphoInternal.sol index 5ed69d0c..eb182675 100644 --- a/test/internal/TestInternalMorphoInternal.sol +++ b/test/internal/TestInternalMorphoInternal.sol @@ -50,7 +50,7 @@ contract TestInternalMorphoInternal is InternalTest { } function createTestMarket(address underlying, uint16 reserveFactor, uint16 p2pIndexCursor) internal { - DataTypes.ReserveData memory reserveData = _pool.getReserveData(underlying); + DataTypes.ReserveDataLegacy memory reserveData = _pool.getReserveData(underlying); Types.Market storage market = _market[underlying]; @@ -379,8 +379,8 @@ contract TestInternalMorphoInternal is InternalTest { } function testAssetLiquidityData() public view { - DataTypes.EModeCategory memory eModeCategory = _pool.getEModeCategoryData(0); - (uint256 poolLtv, uint256 poolLt,, uint256 poolDecimals,,) = _pool.getConfiguration(dai).getParams(); + DataTypes.EModeCategoryLegacy memory eModeCategory = _pool.getEModeCategoryData(0); + (uint256 poolLtv, uint256 poolLt,, uint256 poolDecimals,) = _pool.getConfiguration(dai).getParams(); Types.LiquidityVars memory vars = Types.LiquidityVars(address(1), oracle, eModeCategory); (uint256 price, uint256 ltv, uint256 lt, uint256 units) = _assetLiquidityData(dai, vars); @@ -401,7 +401,7 @@ contract TestInternalMorphoInternal is InternalTest { _marketBalances[dai].collateral[address(1)] = amount.rayDivUp(_market[dai].indexes.supply.poolIndex); - DataTypes.EModeCategory memory eModeCategory = _pool.getEModeCategoryData(0); + DataTypes.EModeCategoryLegacy memory eModeCategory = _pool.getEModeCategoryData(0); Types.LiquidityVars memory vars = Types.LiquidityVars(address(1), oracle, eModeCategory); (uint256 borrowable, uint256 maxDebt) = _collateralData(dai, vars); @@ -415,7 +415,7 @@ contract TestInternalMorphoInternal is InternalTest { _market[dai].isCollateral = true; _marketBalances[dai].collateral[address(1)] = amount.rayDivUp(_market[dai].indexes.supply.poolIndex); - DataTypes.EModeCategory memory eModeCategory = _pool.getEModeCategoryData(0); + DataTypes.EModeCategoryLegacy memory eModeCategory = _pool.getEModeCategoryData(0); Types.LiquidityVars memory vars = Types.LiquidityVars(address(1), oracle, eModeCategory); (uint256 borrowable, uint256 maxDebt) = _collateralData(dai, vars); @@ -443,7 +443,7 @@ contract TestInternalMorphoInternal is InternalTest { true ); - DataTypes.EModeCategory memory eModeCategory = _pool.getEModeCategoryData(0); + DataTypes.EModeCategoryLegacy memory eModeCategory = _pool.getEModeCategoryData(0); Types.LiquidityVars memory vars = Types.LiquidityVars(address(1), oracle, eModeCategory); Types.Indexes256 memory indexes = _computeIndexes(dai); @@ -466,7 +466,7 @@ contract TestInternalMorphoInternal is InternalTest { _userCollaterals[address(1)].add(wbtc); _userCollaterals[address(1)].add(usdc); - DataTypes.EModeCategory memory eModeCategory = _pool.getEModeCategoryData(0); + DataTypes.EModeCategoryLegacy memory eModeCategory = _pool.getEModeCategoryData(0); Types.LiquidityVars memory vars = Types.LiquidityVars(address(1), oracle, eModeCategory); (uint256 borrowable, uint256 maxDebt) = _totalCollateralData(vars); @@ -513,7 +513,7 @@ contract TestInternalMorphoInternal is InternalTest { _userBorrows[address(1)].add(wbtc); _userBorrows[address(1)].add(usdc); - DataTypes.EModeCategory memory eModeCategory = _pool.getEModeCategoryData(0); + DataTypes.EModeCategoryLegacy memory eModeCategory = _pool.getEModeCategoryData(0); Types.LiquidityVars memory vars = Types.LiquidityVars(address(1), oracle, eModeCategory); uint256 debt = _totalDebt(vars); @@ -560,7 +560,7 @@ contract TestInternalMorphoInternal is InternalTest { _userBorrows[address(1)].add(usdc); Types.LiquidityData memory liquidityData = _liquidityData(address(1)); - DataTypes.EModeCategory memory eModeCategory = _pool.getEModeCategoryData(0); + DataTypes.EModeCategoryLegacy memory eModeCategory = _pool.getEModeCategoryData(0); Types.LiquidityVars memory vars = Types.LiquidityVars(address(1), oracle, eModeCategory); (uint256 borrowable, uint256 maxDebt) = _totalCollateralData(vars); diff --git a/test/internal/TestInternalPositionsManagerInternal.sol b/test/internal/TestInternalPositionsManagerInternal.sol index 7376d6fa..297b5b3c 100644 --- a/test/internal/TestInternalPositionsManagerInternal.sol +++ b/test/internal/TestInternalPositionsManagerInternal.sol @@ -393,10 +393,10 @@ contract TestInternalPositionsManagerInternal is InternalTest, PositionsManagerI DataTypes.ReserveConfigurationMap memory borrowConfig = _pool.getConfiguration(wbtc); DataTypes.ReserveConfigurationMap memory collateralConfig = _pool.getConfiguration(dai); - DataTypes.EModeCategory memory eModeCategory = _pool.getEModeCategoryData(_eModeCategoryId); + DataTypes.EModeCategoryLegacy memory eModeCategory = _pool.getEModeCategoryData(_eModeCategoryId); - (,,, vars.borrowedTokenUnit,,) = borrowConfig.getParams(); - (,, vars.liquidationBonus, vars.collateralTokenUnit,,) = collateralConfig.getParams(); + (,,, vars.borrowedTokenUnit,) = borrowConfig.getParams(); + (,, vars.liquidationBonus, vars.collateralTokenUnit,) = collateralConfig.getParams(); bool isInCollateralEMode; (, vars.borrowedPrice, vars.borrowedTokenUnit) = diff --git a/test/internal/TestInternalPositionsManagerInternalCaps.sol b/test/internal/TestInternalPositionsManagerInternalCaps.sol index 42ca4ca8..4b291dd1 100644 --- a/test/internal/TestInternalPositionsManagerInternalCaps.sol +++ b/test/internal/TestInternalPositionsManagerInternalCaps.sol @@ -13,7 +13,7 @@ import "test/helpers/InternalTest.sol"; contract TestInternalPositionsManagerInternalCaps is InternalTest, PositionsManagerInternal { using ReserveConfiguration for DataTypes.ReserveConfigurationMap; - using ReserveDataLib for DataTypes.ReserveData; + using ReserveDataLib for DataTypes.ReserveDataLegacy; using EnumerableSet for EnumerableSet.AddressSet; using WadRayMath for uint256; using PoolLib for IPool; @@ -116,7 +116,7 @@ contract TestInternalPositionsManagerInternalCaps is InternalTest, PositionsMana Types.Market storage market = _market[dai]; Types.Indexes256 memory indexes = _computeIndexes(dai); - DataTypes.ReserveData memory reserve = pool.getReserveData(market.underlying); + DataTypes.ReserveDataLegacy memory reserve = pool.getReserveData(market.underlying); uint256 totalPoolSupply = (IAToken(market.aToken).scaledTotalSupply() + reserve.getAccruedToTreasury(indexes)) .rayMul(indexes.supply.poolIndex); supplyCap = bound( diff --git a/test/unit/TestUnitMarketLibIdle.sol b/test/unit/TestUnitMarketLibIdle.sol index 4edeaab8..0151d0db 100644 --- a/test/unit/TestUnitMarketLibIdle.sol +++ b/test/unit/TestUnitMarketLibIdle.sol @@ -6,8 +6,8 @@ import {MarketLib} from "src/libraries/MarketLib.sol"; import "test/helpers/ForkTest.sol"; contract TestUnitMarketLibIdle is ForkTest { - using ReserveDataLib for DataTypes.ReserveData; - using ReserveDataTestLib for DataTypes.ReserveData; + using ReserveDataLib for DataTypes.ReserveDataLegacy; + using ReserveDataTestLib for DataTypes.ReserveDataLegacy; using ReserveConfiguration for DataTypes.ReserveConfigurationMap; using MarketLib for Types.Market; using Math for uint256; @@ -23,7 +23,7 @@ contract TestUnitMarketLibIdle is ForkTest { function testIncreaseIdleWhenNoSupplyCap(Types.Market memory _market, uint256 amount) public { poolAdmin.setSupplyCap(dai, 0); - DataTypes.ReserveData memory reserve = pool.getReserveData(dai); + DataTypes.ReserveDataLegacy memory reserve = pool.getReserveData(dai); _market.indexes.supply.poolIndex = uint128(pool.getReserveNormalizedIncome(dai)); _market.indexes.borrow.poolIndex = uint128(pool.getReserveNormalizedVariableDebt(dai)); @@ -43,7 +43,7 @@ contract TestUnitMarketLibIdle is ForkTest { // Set the supply gap to always be at least 1 underlying unit even if rounded down supplyGap = bound(supplyGap, daiTokenUnit, MAX_AMOUNT * daiTokenUnit); - DataTypes.ReserveData memory reserve = pool.getReserveData(dai); + DataTypes.ReserveDataLegacy memory reserve = pool.getReserveData(dai); uint256 poolSupplyIndex = pool.getReserveNormalizedIncome(dai); uint256 poolBorrowIndex = pool.getReserveNormalizedVariableDebt(dai); @@ -77,7 +77,7 @@ contract TestUnitMarketLibIdle is ForkTest { { supplyGap = bound(supplyGap, daiTokenUnit, MAX_AMOUNT * daiTokenUnit); - DataTypes.ReserveData memory reserve = pool.getReserveData(dai); + DataTypes.ReserveDataLegacy memory reserve = pool.getReserveData(dai); uint256 poolSupplyIndex = pool.getReserveNormalizedIncome(dai); uint256 poolBorrowIndex = pool.getReserveNormalizedVariableDebt(dai); From 7cf2fcb380c4fc87b4983cd2b991f0f18a93f9fc Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 15 Oct 2024 12:16:28 +0200 Subject: [PATCH 4/8] chore: use IPoolConfigurator from aave-v3-origin --- test/helpers/ForkTest.sol | 2 +- test/helpers/IPoolConfigurator.sol | 411 ----------------------------- test/mocks/PoolAdminMock.sol | 2 +- 3 files changed, 2 insertions(+), 413 deletions(-) delete mode 100644 test/helpers/IPoolConfigurator.sol diff --git a/test/helpers/ForkTest.sol b/test/helpers/ForkTest.sol index 2e2633ef..b2caa24d 100644 --- a/test/helpers/ForkTest.sol +++ b/test/helpers/ForkTest.sol @@ -5,7 +5,7 @@ import {IAToken} from "src/interfaces/aave/IAToken.sol"; import {IAaveOracle} from "@aave-v3-origin/interfaces/IAaveOracle.sol"; import {IPriceOracleGetter} from "@aave-v3-origin/interfaces/IPriceOracleGetter.sol"; import {IACLManager} from "@aave-v3-origin/interfaces/IACLManager.sol"; -import {IPoolConfigurator} from "test/helpers/IPoolConfigurator.sol"; +import {IPoolConfigurator} from "@aave-v3-origin/interfaces/IPoolConfigurator.sol"; import {IPoolDataProvider} from "@aave-v3-origin/interfaces/IPoolDataProvider.sol"; import {IPool, IPoolAddressesProvider} from "@aave-v3-origin/interfaces/IPool.sol"; import {IVariableDebtToken} from "@aave-v3-origin/interfaces/IVariableDebtToken.sol"; diff --git a/test/helpers/IPoolConfigurator.sol b/test/helpers/IPoolConfigurator.sol deleted file mode 100644 index 3d8dd758..00000000 --- a/test/helpers/IPoolConfigurator.sol +++ /dev/null @@ -1,411 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0 -pragma solidity ^0.8.0; - -/** - * @title IPoolConfigurator - * @author Aave - * @notice Defines the basic interface for a Pool configurator. - */ -interface IPoolConfigurator { - /** - * @dev Emitted when a reserve is initialized. - * @param asset The address of the underlying asset of the reserve - * @param aToken The address of the associated aToken contract - * @param stableDebtToken The address of the associated stable rate debt token - * @param variableDebtToken The address of the associated variable rate debt token - * @param interestRateStrategyAddress The address of the interest rate strategy for the reserve - */ - event ReserveInitialized( - address indexed asset, - address indexed aToken, - address stableDebtToken, - address variableDebtToken, - address interestRateStrategyAddress - ); - - /** - * @dev Emitted when borrowing is enabled or disabled on a reserve. - * @param asset The address of the underlying asset of the reserve - * @param enabled True if borrowing is enabled, false otherwise - */ - event ReserveBorrowing(address indexed asset, bool enabled); - - /** - * @dev Emitted when flashloans are enabled or disabled on a reserve. - * @param asset The address of the underlying asset of the reserve - * @param enabled True if flashloans are enabled, false otherwise - */ - event ReserveFlashLoaning(address indexed asset, bool enabled); - - /** - * @dev Emitted when the collateralization risk parameters for the specified asset are updated. - * @param asset The address of the underlying asset of the reserve - * @param ltv The loan to value of the asset when used as collateral - * @param liquidationThreshold The threshold at which loans using this asset as collateral will be considered undercollateralized - * @param liquidationBonus The bonus liquidators receive to liquidate this asset - */ - event CollateralConfigurationChanged( - address indexed asset, uint256 ltv, uint256 liquidationThreshold, uint256 liquidationBonus - ); - - /** - * @dev Emitted when stable rate borrowing is enabled or disabled on a reserve - * @param asset The address of the underlying asset of the reserve - * @param enabled True if stable rate borrowing is enabled, false otherwise - */ - event ReserveStableRateBorrowing(address indexed asset, bool enabled); - - /** - * @dev Emitted when a reserve is activated or deactivated - * @param asset The address of the underlying asset of the reserve - * @param active True if reserve is active, false otherwise - */ - event ReserveActive(address indexed asset, bool active); - - /** - * @dev Emitted when a reserve is frozen or unfrozen - * @param asset The address of the underlying asset of the reserve - * @param frozen True if reserve is frozen, false otherwise - */ - event ReserveFrozen(address indexed asset, bool frozen); - - /** - * @dev Emitted when a reserve is paused or unpaused - * @param asset The address of the underlying asset of the reserve - * @param paused True if reserve is paused, false otherwise - */ - event ReservePaused(address indexed asset, bool paused); - - /** - * @dev Emitted when a reserve is dropped. - * @param asset The address of the underlying asset of the reserve - */ - event ReserveDropped(address indexed asset); - - /** - * @dev Emitted when a reserve factor is updated. - * @param asset The address of the underlying asset of the reserve - * @param oldReserveFactor The old reserve factor, expressed in bps - * @param newReserveFactor The new reserve factor, expressed in bps - */ - event ReserveFactorChanged(address indexed asset, uint256 oldReserveFactor, uint256 newReserveFactor); - - /** - * @dev Emitted when the borrow cap of a reserve is updated. - * @param asset The address of the underlying asset of the reserve - * @param oldBorrowCap The old borrow cap - * @param newBorrowCap The new borrow cap - */ - event BorrowCapChanged(address indexed asset, uint256 oldBorrowCap, uint256 newBorrowCap); - - /** - * @dev Emitted when the supply cap of a reserve is updated. - * @param asset The address of the underlying asset of the reserve - * @param oldSupplyCap The old supply cap - * @param newSupplyCap The new supply cap - */ - event SupplyCapChanged(address indexed asset, uint256 oldSupplyCap, uint256 newSupplyCap); - - /** - * @dev Emitted when the liquidation protocol fee of a reserve is updated. - * @param asset The address of the underlying asset of the reserve - * @param oldFee The old liquidation protocol fee, expressed in bps - * @param newFee The new liquidation protocol fee, expressed in bps - */ - event LiquidationProtocolFeeChanged(address indexed asset, uint256 oldFee, uint256 newFee); - - /** - * @dev Emitted when the unbacked mint cap of a reserve is updated. - * @param asset The address of the underlying asset of the reserve - * @param oldUnbackedMintCap The old unbacked mint cap - * @param newUnbackedMintCap The new unbacked mint cap - */ - event UnbackedMintCapChanged(address indexed asset, uint256 oldUnbackedMintCap, uint256 newUnbackedMintCap); - - /* @dev Emitted when an collateral configuration of an asset in an eMode is changed. - * @param asset The address of the underlying asset of the reserve - * @param categoryId The eMode category - * @param collateral True if the asset is enabled as collateral in the eMode, false otherwise. - */ - event AssetCollateralInEModeChanged(address indexed asset, uint8 categoryId, bool collateral); - - /** - * @dev Emitted when the borrowable configuration of an asset in an eMode changed. - * @param asset The address of the underlying asset of the reserve - * @param categoryId The eMode category - * @param borrowable True if the asset is enabled as borrowable in the eMode, false otherwise. - */ - event AssetBorrowableInEModeChanged(address indexed asset, uint8 categoryId, bool borrowable); - - /** - * @dev Emitted when a new eMode category is added. - * @param categoryId The new eMode category id - * @param ltv The ltv for the asset category in eMode - * @param liquidationThreshold The liquidationThreshold for the asset category in eMode - * @param liquidationBonus The liquidationBonus for the asset category in eMode - * @param label A human readable identifier for the category - */ - event EModeCategoryAdded( - uint8 indexed categoryId, uint256 ltv, uint256 liquidationThreshold, uint256 liquidationBonus, string label - ); - - /** - * @dev Emitted when a reserve interest strategy contract is updated. - * @param asset The address of the underlying asset of the reserve - * @param oldStrategy The address of the old interest strategy contract - * @param newStrategy The address of the new interest strategy contract - */ - event ReserveInterestRateStrategyChanged(address indexed asset, address oldStrategy, address newStrategy); - - /** - * @dev Emitted when an aToken implementation is upgraded. - * @param asset The address of the underlying asset of the reserve - * @param proxy The aToken proxy address - * @param implementation The new aToken implementation - */ - event ATokenUpgraded(address indexed asset, address indexed proxy, address indexed implementation); - - /** - * @dev Emitted when the implementation of a variable debt token is upgraded. - * @param asset The address of the underlying asset of the reserve - * @param proxy The variable debt token proxy address - * @param implementation The new aToken implementation - */ - event VariableDebtTokenUpgraded(address indexed asset, address indexed proxy, address indexed implementation); - - /** - * @dev Emitted when the debt ceiling of an asset is set. - * @param asset The address of the underlying asset of the reserve - * @param oldDebtCeiling The old debt ceiling - * @param newDebtCeiling The new debt ceiling - */ - event DebtCeilingChanged(address indexed asset, uint256 oldDebtCeiling, uint256 newDebtCeiling); - - /** - * @dev Emitted when the the siloed borrowing state for an asset is changed. - * @param asset The address of the underlying asset of the reserve - * @param oldState The old siloed borrowing state - * @param newState The new siloed borrowing state - */ - event SiloedBorrowingChanged(address indexed asset, bool oldState, bool newState); - - /** - * @dev Emitted when the bridge protocol fee is updated. - * @param oldBridgeProtocolFee The old protocol fee, expressed in bps - * @param newBridgeProtocolFee The new protocol fee, expressed in bps - */ - event BridgeProtocolFeeUpdated(uint256 oldBridgeProtocolFee, uint256 newBridgeProtocolFee); - - /** - * @dev Emitted when the total premium on flashloans is updated. - * @param oldFlashloanPremiumTotal The old premium, expressed in bps - * @param newFlashloanPremiumTotal The new premium, expressed in bps - */ - event FlashloanPremiumTotalUpdated(uint128 oldFlashloanPremiumTotal, uint128 newFlashloanPremiumTotal); - - /** - * @dev Emitted when the part of the premium that goes to protocol is updated. - * @param oldFlashloanPremiumToProtocol The old premium, expressed in bps - * @param newFlashloanPremiumToProtocol The new premium, expressed in bps - */ - event FlashloanPremiumToProtocolUpdated( - uint128 oldFlashloanPremiumToProtocol, uint128 newFlashloanPremiumToProtocol - ); - - /** - * @dev Emitted when the reserve is set as borrowable/non borrowable in isolation mode. - * @param asset The address of the underlying asset of the reserve - * @param borrowable True if the reserve is borrowable in isolation, false otherwise - */ - event BorrowableInIsolationChanged(address asset, bool borrowable); - - /** - * @notice Configures borrowing on a reserve. - * @dev Can only be disabled (set to false) if stable borrowing is disabled - * @param asset The address of the underlying asset of the reserve - * @param enabled True if borrowing needs to be enabled, false otherwise - */ - function setReserveBorrowing(address asset, bool enabled) external; - - /** - * @notice Configures the reserve collateralization parameters. - * @dev All the values are expressed in bps. A value of 10000, results in 100.00% - * @dev The `liquidationBonus` is always above 100%. A value of 105% means the liquidator will receive a 5% bonus - * @param asset The address of the underlying asset of the reserve - * @param ltv The loan to value of the asset when used as collateral - * @param liquidationThreshold The threshold at which loans using this asset as collateral will be considered undercollateralized - * @param liquidationBonus The bonus liquidators receive to liquidate this asset - */ - function configureReserveAsCollateral( - address asset, - uint256 ltv, - uint256 liquidationThreshold, - uint256 liquidationBonus - ) external; - - /** - * @notice Enable or disable flashloans on a reserve - * @param asset The address of the underlying asset of the reserve - * @param enabled True if flashloans need to be enabled, false otherwise - */ - function setReserveFlashLoaning(address asset, bool enabled) external; - - /** - * @notice Activate or deactivate a reserve - * @param asset The address of the underlying asset of the reserve - * @param active True if the reserve needs to be active, false otherwise - */ - function setReserveActive(address asset, bool active) external; - - /** - * @notice Freeze or unfreeze a reserve. A frozen reserve doesn't allow any new supply, borrow - * or rate swap but allows repayments, liquidations, rate rebalances and withdrawals. - * @param asset The address of the underlying asset of the reserve - * @param freeze True if the reserve needs to be frozen, false otherwise - */ - function setReserveFreeze(address asset, bool freeze) external; - - /** - * @notice Sets the borrowable in isolation flag for the reserve. - * @dev When this flag is set to true, the asset will be borrowable against isolated collaterals and the - * borrowed amount will be accumulated in the isolated collateral's total debt exposure - * @dev Only assets of the same family (e.g. USD stablecoins) should be borrowable in isolation mode to keep - * consistency in the debt ceiling calculations - * @param asset The address of the underlying asset of the reserve - * @param borrowable True if the asset should be borrowable in isolation, false otherwise - */ - function setBorrowableInIsolation(address asset, bool borrowable) external; - - /** - * @notice Pauses a reserve. A paused reserve does not allow any interaction (supply, borrow, repay, - * swap interest rate, liquidate, atoken transfers). - * @param asset The address of the underlying asset of the reserve - * @param paused True if pausing the reserve, false if unpausing - */ - function setReservePause(address asset, bool paused) external; - - /** - * @notice Updates the reserve factor of a reserve. - * @param asset The address of the underlying asset of the reserve - * @param newReserveFactor The new reserve factor of the reserve - */ - function setReserveFactor(address asset, uint256 newReserveFactor) external; - - /** - * @notice Sets the interest rate strategy of a reserve. - * @param asset The address of the underlying asset of the reserve - * @param newRateStrategyAddress The address of the new interest strategy contract - */ - function setReserveInterestRateStrategyAddress(address asset, address newRateStrategyAddress) external; - - /** - * @notice Pauses or unpauses all the protocol reserves. In the paused state all the protocol interactions - * are suspended. - * @param paused True if protocol needs to be paused, false otherwise - */ - function setPoolPause(bool paused) external; - - /** - * @notice Updates the borrow cap of a reserve. - * @param asset The address of the underlying asset of the reserve - * @param newBorrowCap The new borrow cap of the reserve - */ - function setBorrowCap(address asset, uint256 newBorrowCap) external; - - /** - * @notice Updates the supply cap of a reserve. - * @param asset The address of the underlying asset of the reserve - * @param newSupplyCap The new supply cap of the reserve - */ - function setSupplyCap(address asset, uint256 newSupplyCap) external; - - /** - * @notice Updates the liquidation protocol fee of reserve. - * @param asset The address of the underlying asset of the reserve - * @param newFee The new liquidation protocol fee of the reserve, expressed in bps - */ - function setLiquidationProtocolFee(address asset, uint256 newFee) external; - - /** - * @notice Updates the unbacked mint cap of reserve. - * @param asset The address of the underlying asset of the reserve - * @param newUnbackedMintCap The new unbacked mint cap of the reserve - */ - function setUnbackedMintCap(address asset, uint256 newUnbackedMintCap) external; - - /** - * @notice Enables/disables an asset to be borrowable in a selected eMode. - * - eMode.borrowable always has less priority then reserve.borrowable - * @param asset The address of the underlying asset of the reserve - * @param categoryId The eMode categoryId - * @param borrowable True if the asset should be borrowable in the given eMode category, false otherwise. - */ - function setAssetBorrowableInEMode(address asset, uint8 categoryId, bool borrowable) external; - - /** - * @notice Enables/disables an asset to be collateral in a selected eMode. - * @param asset The address of the underlying asset of the reserve - * @param categoryId The eMode categoryId - * @param collateral True if the asset should be collateral in the given eMode category, false otherwise. - */ - function setAssetCollateralInEMode(address asset, uint8 categoryId, bool collateral) external; - - /** - * @notice Adds a new efficiency mode (eMode) category or alters a existing one. - * @param categoryId The id of the category to be configured - * @param ltv The ltv associated with the category - * @param liquidationThreshold The liquidation threshold associated with the category - * @param liquidationBonus The liquidation bonus associated with the category - * @param label A label identifying the category - */ - function setEModeCategory( - uint8 categoryId, - uint16 ltv, - uint16 liquidationThreshold, - uint16 liquidationBonus, - string calldata label - ) external; - - /** - * @notice Drops a reserve entirely. - * @param asset The address of the reserve to drop - */ - function dropReserve(address asset) external; - - /** - * @notice Updates the bridge fee collected by the protocol reserves. - * @param newBridgeProtocolFee The part of the fee sent to the protocol treasury, expressed in bps - */ - function updateBridgeProtocolFee(uint256 newBridgeProtocolFee) external; - - /** - * @notice Updates the total flash loan premium. - * Total flash loan premium consists of two parts: - * - A part is sent to aToken holders as extra balance - * - A part is collected by the protocol reserves - * @dev Expressed in bps - * @dev The premium is calculated on the total amount borrowed - * @param newFlashloanPremiumTotal The total flashloan premium - */ - function updateFlashloanPremiumTotal(uint128 newFlashloanPremiumTotal) external; - - /** - * @notice Updates the flash loan premium collected by protocol reserves - * @dev Expressed in bps - * @dev The premium to protocol is calculated on the total flashloan premium - * @param newFlashloanPremiumToProtocol The part of the flashloan premium sent to the protocol treasury - */ - function updateFlashloanPremiumToProtocol(uint128 newFlashloanPremiumToProtocol) external; - - /** - * @notice Sets the debt ceiling for an asset. - * @param newDebtCeiling The new debt ceiling - */ - function setDebtCeiling(address asset, uint256 newDebtCeiling) external; - - /** - * @notice Sets siloed borrowing for an asset - * @param siloed The new siloed borrowing state - */ - function setSiloedBorrowing(address asset, bool siloed) external; -} diff --git a/test/mocks/PoolAdminMock.sol b/test/mocks/PoolAdminMock.sol index 0ad82926..0693e565 100644 --- a/test/mocks/PoolAdminMock.sol +++ b/test/mocks/PoolAdminMock.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; -import {IPoolConfigurator} from "test/helpers/IPoolConfigurator.sol"; +import {IPoolConfigurator} from "@aave-v3-origin/interfaces/IPoolConfigurator.sol"; contract PoolAdminMock { IPoolConfigurator internal immutable _POOL_CONFIGURATOR; From 0459b24d7bb9459bde6202479f0f51369aec36db Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Tue, 15 Oct 2024 14:58:50 +0200 Subject: [PATCH 5/8] chore: fix remappings --- remappings.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remappings.txt b/remappings.txt index 5e6d10d8..eadfb8c2 100644 --- a/remappings.txt +++ b/remappings.txt @@ -8,7 +8,7 @@ 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/ @openzeppelin-upgradeable/=lib/morpho-utils/lib/openzeppelin-contracts-upgradeable/contracts/ @aave-v3-origin/=lib/aave-v3-origin/src/contracts/ From 2aa02e7b77f83c8cc9c48d9d5824b1649a806e00 Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Wed, 16 Oct 2024 19:17:06 +0200 Subject: [PATCH 6/8] chore: add IStableDebtLegacy --- src/interfaces/aave/IStableDebtTokenLegacy.sol | 6 ++++++ src/libraries/ReserveDataLib.sol | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 src/interfaces/aave/IStableDebtTokenLegacy.sol diff --git a/src/interfaces/aave/IStableDebtTokenLegacy.sol b/src/interfaces/aave/IStableDebtTokenLegacy.sol new file mode 100644 index 00000000..4acfc34c --- /dev/null +++ b/src/interfaces/aave/IStableDebtTokenLegacy.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: AGPL-3.0-only +pragma solidity >=0.5.0; + +interface IStableDebtTokenLegacy { + function getSupplyData() external view returns (uint256, uint256, uint256, uint40); +} diff --git a/src/libraries/ReserveDataLib.sol b/src/libraries/ReserveDataLib.sol index 440e81ba..c1089100 100644 --- a/src/libraries/ReserveDataLib.sol +++ b/src/libraries/ReserveDataLib.sol @@ -12,6 +12,8 @@ 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"; +import {IStableDebtTokenLegacy} from "src/interfaces/aave/IStableDebtTokenLegacy.sol"; + /// @title ReserveDataLib /// @author Morpho Labs /// @custom:contact security@morpho.xyz @@ -40,7 +42,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); From 74fd56106a652e7a9cfebe1968f220cf1c1dd122 Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Thu, 17 Oct 2024 12:19:34 +0200 Subject: [PATCH 7/8] chore: remove change unrelated to aave-v3-origin pointer --- src/libraries/ReserveDataLib.sol | 3 +-- test/helpers/ReserveDataTestLib.sol | 9 +++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libraries/ReserveDataLib.sol b/src/libraries/ReserveDataLib.sol index c1089100..c7b89dee 100644 --- a/src/libraries/ReserveDataLib.sol +++ b/src/libraries/ReserveDataLib.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.17; +import {IStableDebtTokenLegacy} from "src/interfaces/aave/IStableDebtTokenLegacy.sol"; import {IVariableDebtToken} from "@aave-v3-origin/interfaces/IVariableDebtToken.sol"; import {Types} from "./Types.sol"; @@ -12,8 +13,6 @@ 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"; -import {IStableDebtTokenLegacy} from "src/interfaces/aave/IStableDebtTokenLegacy.sol"; - /// @title ReserveDataLib /// @author Morpho Labs /// @custom:contact security@morpho.xyz diff --git a/test/helpers/ReserveDataTestLib.sol b/test/helpers/ReserveDataTestLib.sol index 984f1d86..67a1ccd7 100644 --- a/test/helpers/ReserveDataTestLib.sol +++ b/test/helpers/ReserveDataTestLib.sol @@ -23,9 +23,9 @@ library ReserveDataTestLib { return ERC20(reserve.aTokenAddress).totalSupply(); } - /// @dev Returns the quantity currently borrowed (with variable only, stable being deprecated) on the market on AaveV3. + /// @dev Returns the quantity currently borrowed (with variable & stable rates) on the market on AaveV3. function totalBorrow(DataTypes.ReserveDataLegacy memory reserve) internal view returns (uint256) { - return totalVariableBorrow(reserve); + return totalVariableBorrow(reserve) + totalStableBorrow(reserve); } /// @dev Returns the quantity currently borrowed with variable rate from the market on AaveV3. @@ -33,6 +33,11 @@ library ReserveDataTestLib { return ERC20(reserve.variableDebtTokenAddress).totalSupply(); } + /// @dev Returns the quantity currently borrowed with stable rate from the market on AaveV3. + function totalStableBorrow(DataTypes.ReserveDataLegacy memory reserve) internal view returns (uint256) { + return ERC20(reserve.stableDebtTokenAddress).totalSupply(); + } + /// @dev Returns the quantity currently supplied on behalf of the user, on the market on AaveV3. function supplyOf(DataTypes.ReserveDataLegacy memory reserve, address user) internal view returns (uint256) { return ERC20(reserve.aTokenAddress).balanceOf(user); From 6057aab0e81bb0fca4f547f336f7f25816a1ad0c Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Fri, 25 Oct 2024 15:54:22 +0200 Subject: [PATCH 8/8] chore: comply to repo pragma convention --- src/interfaces/aave/IStableDebtTokenLegacy.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaces/aave/IStableDebtTokenLegacy.sol b/src/interfaces/aave/IStableDebtTokenLegacy.sol index 4acfc34c..34faf6a9 100644 --- a/src/interfaces/aave/IStableDebtTokenLegacy.sol +++ b/src/interfaces/aave/IStableDebtTokenLegacy.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: AGPL-3.0-only -pragma solidity >=0.5.0; +pragma solidity ^0.8.0; interface IStableDebtTokenLegacy { function getSupplyData() external view returns (uint256, uint256, uint256, uint40);