Skip to content

Commit

Permalink
Merge pull request #26 from aave-dao/cantina-v3.1-merger
Browse files Browse the repository at this point in the history
Cantina v3.1 merger
  • Loading branch information
kyzia551 authored Jun 18, 2024
2 parents 3c991c4 + 80bf1e9 commit 3375062
Show file tree
Hide file tree
Showing 26 changed files with 335 additions and 122 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ bun install
- [Aave v3 technical Paper](./techpaper/Aave_V3_Technical_Paper.pdf)
- [v3 to v3.0.2 production upgrade](https://github.com/bgd-labs/proposal-3.0.2-upgrade/blob/main/README.md)
- [Aave v3.1 features](./docs/Aave-v3.1-features.md)
- [Set Ltv to 0 on Freeze Feature State diagram](./docs/freeze-ltv0-states.png)

<br>

Expand Down
2 changes: 1 addition & 1 deletion docs/Aave-v3.1-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Given its implications and criticality, virtual accounting can be considered the
- [ConfigurationInputTypes](../src/core/contracts/protocol/libraries/types/ConfiguratorInputTypes.sol)
- Added flag `useVirtualBalance` for a new listing to use or not virtual balance.
- [ReserveConfiguration](../src/core/contracts/protocol/libraries/configuration/ReserveConfiguration.sol)
- Added logic to store and set/get the new `VIRTUAL_ACC_ACTIVE` flag.
- Added logic to set/get the new configuration flag for if a reserve has virtual account active.
- [Errors](../src/core/contracts/protocol/libraries/helpers/Errors.sol)
- In relation with this feature, added the `WITHDRAW_TO_ATOKEN` and `SUPPLY_TO_ATOKEN` errors.
- [Pool](../src/core/contracts/protocol/pool/Pool.sol)
Expand Down
Binary file added docs/freeze-ltv0-states.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/core/contracts/interfaces/IPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@ interface IPool {
function swapBorrowRateMode(address asset, uint256 interestRateMode) external;

/**
* @notice Allows a borrower to swap his debt between stable and variable mode,
* @dev introduce in a flavor stable rate deprecation
* @notice Permissionless method which allows anyone to swap a users stable debt to variable debt
* @dev Introduced in favor of stable rate deprecation
* @param asset The address of the underlying asset borrowed
* @param user The address of the user to be swapped
* @param user The address of the user whose debt will be swapped from stable to variable
*/
function swapToVariable(address asset, address user) external;

Expand Down
25 changes: 17 additions & 8 deletions src/core/contracts/interfaces/IPoolConfigurator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ interface IPoolConfigurator {
*/
event PendingLtvChanged(address indexed asset, uint256 ltv);

/**
* @dev Emitted when the asset is unfrozen and pending ltv is removed.
* @param asset The address of the underlying asset of the reserve
*/
event PendingLtvRemoved(address indexed asset);

/**
* @dev Emitted when the collateralization risk parameters for the specified asset are updated.
* @param asset The address of the underlying asset of the reserve
Expand Down Expand Up @@ -144,6 +138,12 @@ interface IPoolConfigurator {
*/
event LiquidationGracePeriodChanged(address indexed asset, uint40 gracePeriodUntil);

/**
* @dev Emitted when the liquidation grace period is disabled.
* @param asset The address of the underlying asset of the reserve
*/
event LiquidationGracePeriodDisabled(address indexed asset);

/**
* @dev Emitted when the unbacked mint cap of a reserve is updated.
* @param asset The address of the underlying asset of the reserve
Expand Down Expand Up @@ -289,6 +289,8 @@ interface IPoolConfigurator {

/**
* @notice Initializes multiple reserves.
* @dev param useVirtualBalance of the input struct should be true for all normal assets and should be false
* only in special cases (ex. GHO) where an asset is minted instead of supplied.
* @param input The array of initialization parameters
*/
function initReserves(ConfiguratorInputTypes.InitReserveInput[] calldata input) external;
Expand Down Expand Up @@ -401,6 +403,13 @@ interface IPoolConfigurator {
*/
function setReservePause(address asset, bool paused) external;

/**
* @notice Disables liquidation grace period for the asset. The liquidation grace period is set in the past
* so that liquidations are allowed for the asset.
* @param asset The address of the underlying asset of the reserve
*/
function disableLiquidationGracePeriod(address asset) external;

/**
* @notice Updates the reserve factor of a reserve.
* @param asset The address of the underlying asset of the reserve
Expand Down Expand Up @@ -549,10 +558,10 @@ interface IPoolConfigurator {
function setSiloedBorrowing(address asset, bool siloed) external;

/**
* @notice Gets pending ltv value and flag if it is set
* @notice Gets pending ltv value
* @param asset The new siloed borrowing state
*/
function getPendingLtv(address asset) external returns (uint256, bool);
function getPendingLtv(address asset) external returns (uint256);

/**
* @notice Gets the address of the external ConfiguratorLogic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ library ReserveConfiguration {
uint256 internal constant EMODE_CATEGORY_MASK = 0xFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant UNBACKED_MINT_CAP_MASK = 0xFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant DEBT_CEILING_MASK = 0xF0000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant VIRTUAL_ACC_ACTIVE = 0xEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 internal constant VIRTUAL_ACC_ACTIVE_MASK = 0xEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore

/// @dev For the LTV, the start bit is 0 (up to 15), hence no bitshifting is needed
uint256 internal constant LIQUIDATION_THRESHOLD_START_BIT_POSITION = 16;
Expand Down Expand Up @@ -556,19 +556,21 @@ library ReserveConfiguration {
bool active
) internal pure {
self.data =
(self.data & VIRTUAL_ACC_ACTIVE) |
(self.data & VIRTUAL_ACC_ACTIVE_MASK) |
(uint256(active ? 1 : 0) << VIRTUAL_ACC_START_BIT_POSITION);
}

/**
* @notice Gets the virtual account active/not state of the reserve
* @dev The state should be true for all normal assets and should be false
* only in special cases (ex. GHO) where an asset is minted instead of supplied.
* @param self The reserve configuration
* @return The active state
*/
function getIsVirtualAccActive(
DataTypes.ReserveConfigurationMap memory self
) internal pure returns (bool) {
return (self.data & ~VIRTUAL_ACC_ACTIVE) != 0;
return (self.data & ~VIRTUAL_ACC_ACTIVE_MASK) != 0;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/core/contracts/protocol/libraries/helpers/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,5 @@ library Errors {
string public constant CALLER_NOT_RISK_OR_POOL_OR_EMERGENCY_ADMIN = '96'; // 'The caller of the function is not a risk, pool or emergency admin'
string public constant LIQUIDATION_GRACE_SENTINEL_CHECK_FAILED = '97'; // 'Liquidation grace sentinel validation failed'
string public constant INVALID_GRACE_PERIOD = '98'; // Grace period above a valid range
string public constant INVALID_FREEZE_STATE = '99'; // Reserve is already in the passed freeze state
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ library BorrowLogic {
* @param reserve The of the reserve of the asset being repaid
* @param userConfig The user configuration mapping that tracks the supplied/borrowed assets
* @param asset The asset of the position being swapped
* @param user The user whose debt position is being swapped
* @param interestRateMode The current interest rate mode of the position being swapped
*/
function executeSwapBorrowRateMode(
Expand Down
14 changes: 10 additions & 4 deletions src/core/contracts/protocol/libraries/logic/ConfiguratorLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {InitializableImmutableAdminUpgradeabilityProxy} from '../aave-upgradeabi
import {IReserveInterestRateStrategy} from '../../../interfaces/IReserveInterestRateStrategy.sol';
import {ReserveConfiguration} from '../configuration/ReserveConfiguration.sol';
import {DataTypes} from '../types/DataTypes.sol';
import {Errors} from '../helpers/Errors.sol';
import {ConfiguratorInputTypes} from '../types/ConfiguratorInputTypes.sol';
import {IERC20Detailed} from '../../../dependencies/openzeppelin/contracts/IERC20Detailed.sol';

/**
* @title ConfiguratorLogic library
Expand Down Expand Up @@ -52,6 +54,10 @@ library ConfiguratorLogic {
IPool pool,
ConfiguratorInputTypes.InitReserveInput calldata input
) external {
// It is an assumption that the asset listed is non-malicious, and the external call doesn't create re-entrancies
uint8 underlyingAssetDecimals = IERC20Detailed(input.underlyingAsset).decimals();
require(underlyingAssetDecimals > 5, Errors.INVALID_DECIMALS);

address aTokenProxyAddress = _initTokenWithProxy(
input.aTokenImpl,
abi.encodeWithSelector(
Expand All @@ -60,7 +66,7 @@ library ConfiguratorLogic {
input.treasury,
input.underlyingAsset,
input.incentivesController,
input.underlyingAssetDecimals,
underlyingAssetDecimals,
input.aTokenName,
input.aTokenSymbol,
input.params
Expand All @@ -74,7 +80,7 @@ library ConfiguratorLogic {
pool,
input.underlyingAsset,
input.incentivesController,
input.underlyingAssetDecimals,
underlyingAssetDecimals,
input.stableDebtTokenName,
input.stableDebtTokenSymbol,
input.params
Expand All @@ -88,7 +94,7 @@ library ConfiguratorLogic {
pool,
input.underlyingAsset,
input.incentivesController,
input.underlyingAssetDecimals,
underlyingAssetDecimals,
input.variableDebtTokenName,
input.variableDebtTokenSymbol,
input.params
Expand All @@ -105,7 +111,7 @@ library ConfiguratorLogic {

DataTypes.ReserveConfigurationMap memory currentConfig = DataTypes.ReserveConfigurationMap(0);

currentConfig.setDecimals(input.underlyingAssetDecimals);
currentConfig.setDecimals(underlyingAssetDecimals);

currentConfig.setActive(true);
currentConfig.setPaused(false);
Expand Down
1 change: 0 additions & 1 deletion src/core/contracts/protocol/libraries/logic/EModeLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {GPv2SafeERC20} from '../../../dependencies/gnosis/contracts/GPv2SafeERC2
import {IERC20} from '../../../dependencies/openzeppelin/contracts/IERC20.sol';
import {IPriceOracleGetter} from '../../../interfaces/IPriceOracleGetter.sol';
import {UserConfiguration} from '../configuration/UserConfiguration.sol';
import {Errors} from '../helpers/Errors.sol';
import {WadRayMath} from '../math/WadRayMath.sol';
import {PercentageMath} from '../math/PercentageMath.sol';
import {DataTypes} from '../types/DataTypes.sol';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {IPool} from '../../../interfaces/IPool.sol';
import {IFlashLoanReceiver} from '../../../flashloan/interfaces/IFlashLoanReceiver.sol';
import {IFlashLoanSimpleReceiver} from '../../../flashloan/interfaces/IFlashLoanSimpleReceiver.sol';
import {IPoolAddressesProvider} from '../../../interfaces/IPoolAddressesProvider.sol';
import {UserConfiguration} from '../configuration/UserConfiguration.sol';
import {ReserveConfiguration} from '../configuration/ReserveConfiguration.sol';
import {Errors} from '../helpers/Errors.sol';
import {WadRayMath} from '../math/WadRayMath.sol';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {IERC20} from '../../../dependencies/openzeppelin/contracts/IERC20.sol';
import {Address} from '../../../dependencies/openzeppelin/contracts/Address.sol';
import {GPv2SafeERC20} from '../../../dependencies/gnosis/contracts/GPv2SafeERC20.sol';
import {IReserveInterestRateStrategy} from '../../../interfaces/IReserveInterestRateStrategy.sol';
import {IStableDebtToken} from '../../../interfaces/IStableDebtToken.sol';
import {IScaledBalanceToken} from '../../../interfaces/IScaledBalanceToken.sol';
import {IPriceOracleGetter} from '../../../interfaces/IPriceOracleGetter.sol';
import {IAToken} from '../../../interfaces/IAToken.sol';
import {IPriceOracleSentinel} from '../../../interfaces/IPriceOracleSentinel.sol';
Expand Down Expand Up @@ -471,6 +469,9 @@ library ValidationLogic {
) internal view {
require(assets.length == amounts.length, Errors.INCONSISTENT_FLASHLOAN_PARAMS);
for (uint256 i = 0; i < assets.length; i++) {
for (uint256 j = i + 1; j < assets.length; j++) {
require(assets[i] != assets[j], Errors.INCONSISTENT_FLASHLOAN_PARAMS);
}
validateFlashloanSimple(reservesData[assets[i]], amounts[i]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ library ConfiguratorInputTypes {
address aTokenImpl;
address stableDebtTokenImpl;
address variableDebtTokenImpl;
uint8 underlyingAssetDecimals;
bool useVirtualBalance;
address interestRateStrategyAddress;
address underlyingAsset;
Expand Down
2 changes: 1 addition & 1 deletion src/core/contracts/protocol/libraries/types/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ library DataTypes {
uint40 lastUpdateTimestamp;
//the id of the reserve. Represents the position in the list of the active reserves
uint16 id;
//timestamp in the future, until when liquidations are not allowed on the reserve
//timestamp until when liquidations are not allowed on the reserve, if set to past liquidations will be allowed
uint40 liquidationGracePeriodUntil;
//aToken address
address aTokenAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ contract DefaultReserveInterestRateStrategyV2 is IDefaultInterestRateStrategyV2
/// @dev Map of reserves address and their interest rate data (reserveAddress => interestRateData)
mapping(address => InterestRateData) internal _interestRateData;


modifier onlyPoolConfigurator() {
require(
msg.sender == ADDRESSES_PROVIDER.getPoolConfigurator(),
Expand Down Expand Up @@ -119,7 +118,7 @@ contract DefaultReserveInterestRateStrategyV2 is IDefaultInterestRateStrategyV2
) external view virtual override returns (uint256, uint256, uint256) {
InterestRateDataRay memory rateData = _rayifyRateData(_interestRateData[params.reserve]);

// @note This is a short circuit to allow mintable assets, which by definition cannot be supplied
// @note This is a short circuit to allow mintable assets (ex. GHO), which by definition cannot be supplied
// and thus do not use virtual underlying balances.
if (!params.usingVirtualBalance) {
return (0, 0, rateData.baseVariableBorrowRate);
Expand Down
58 changes: 39 additions & 19 deletions src/core/contracts/protocol/pool/PoolConfigurator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ abstract contract PoolConfigurator is VersionedInitializable, IPoolConfigurator
IPool internal _pool;

mapping(address => uint256) internal _pendingLtv;
mapping(address => bool) internal _isPendingLtvSet;

uint40 public constant MAX_GRACE_PERIOD = 4 hours;

Expand Down Expand Up @@ -81,9 +80,8 @@ abstract contract PoolConfigurator is VersionedInitializable, IPoolConfigurator
ConfiguratorInputTypes.InitReserveInput[] calldata input
) external override onlyAssetListingOrPoolAdmins {
IPool cachedPool = _pool;
for (uint256 i = 0; i < input.length; i++) {
require(IERC20Detailed(input[i].underlyingAsset).decimals() > 5, Errors.INVALID_DECIMALS);

for (uint256 i = 0; i < input.length; i++) {
ConfiguratorLogic.executeInitReserve(cachedPool, input[i]);
emit ReserveInterestRateDataChanged(
input[i].underlyingAsset,
Expand Down Expand Up @@ -164,9 +162,11 @@ abstract contract PoolConfigurator is VersionedInitializable, IPoolConfigurator
_checkNoSuppliers(asset);
}

uint256 newLtv = ltv;

if (currentConfig.getFrozen()) {
_pendingLtv[asset] = ltv;
_isPendingLtvSet[asset] = true;
newLtv = 0;

emit PendingLtvChanged(asset, ltv);
} else {
Expand All @@ -178,7 +178,7 @@ abstract contract PoolConfigurator is VersionedInitializable, IPoolConfigurator

_pool.setConfiguration(asset, currentConfig);

emit CollateralConfigurationChanged(asset, ltv, liquidationThreshold, liquidationBonus);
emit CollateralConfigurationChanged(asset, newLtv, liquidationThreshold, liquidationBonus);
}

/// @inheritdoc IPoolConfigurator
Expand Down Expand Up @@ -222,24 +222,32 @@ abstract contract PoolConfigurator is VersionedInitializable, IPoolConfigurator
bool freeze
) external override onlyRiskOrPoolOrEmergencyAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);

require(freeze != currentConfig.getFrozen(), Errors.INVALID_FREEZE_STATE);

currentConfig.setFrozen(freeze);

uint256 ltvSet;
uint256 pendingLtvSet;

if (freeze) {
_pendingLtv[asset] = currentConfig.getLtv();
_isPendingLtvSet[asset] = true;
pendingLtvSet = currentConfig.getLtv();
_pendingLtv[asset] = pendingLtvSet;
currentConfig.setLtv(0);

emit PendingLtvChanged(asset, currentConfig.getLtv());
} else if (_isPendingLtvSet[asset]) {
uint256 ltv = _pendingLtv[asset];
currentConfig.setLtv(ltv);

} else {
ltvSet = _pendingLtv[asset];
currentConfig.setLtv(ltvSet);
delete _pendingLtv[asset];
delete _isPendingLtvSet[asset];

emit PendingLtvRemoved(asset);
}

emit PendingLtvChanged(asset, pendingLtvSet);
emit CollateralConfigurationChanged(
asset,
ltvSet,
currentConfig.getLiquidationThreshold(),
currentConfig.getLiquidationBonus()
);

_pool.setConfiguration(asset, currentConfig);
emit ReserveFrozen(asset, freeze);
}
Expand Down Expand Up @@ -280,6 +288,14 @@ abstract contract PoolConfigurator is VersionedInitializable, IPoolConfigurator
setReservePause(asset, paused, 0);
}

/// @inheritdoc IPoolConfigurator
function disableLiquidationGracePeriod(address asset) external override onlyEmergencyOrPoolAdmin {
// set the liquidation grace period in the past to disable liquidation grace period
_pool.setLiquidationGracePeriod(asset, 0);

emit LiquidationGracePeriodDisabled(asset);
}

/// @inheritdoc IPoolConfigurator
function setReserveFactor(
address asset,
Expand Down Expand Up @@ -408,7 +424,11 @@ abstract contract PoolConfigurator is VersionedInitializable, IPoolConfigurator
for (uint256 i = 0; i < reserves.length; i++) {
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(reserves[i]);
if (categoryId == currentConfig.getEModeCategory()) {
require(ltv > currentConfig.getLtv(), Errors.INVALID_EMODE_CATEGORY_PARAMS);
uint256 currentLtv = currentConfig.getFrozen()
? _pendingLtv[reserves[i]]
: currentConfig.getLtv();
require(ltv > currentLtv, Errors.INVALID_EMODE_CATEGORY_PARAMS);

require(
liquidationThreshold > currentConfig.getLiquidationThreshold(),
Errors.INVALID_EMODE_CATEGORY_PARAMS
Expand Down Expand Up @@ -537,8 +557,8 @@ abstract contract PoolConfigurator is VersionedInitializable, IPoolConfigurator
}

/// @inheritdoc IPoolConfigurator
function getPendingLtv(address asset) external view override returns (uint256, bool) {
return (_pendingLtv[asset], _isPendingLtvSet[asset]);
function getPendingLtv(address asset) external view override returns (uint256) {
return _pendingLtv[asset];
}

/// @inheritdoc IPoolConfigurator
Expand Down
Loading

0 comments on commit 3375062

Please sign in to comment.