diff --git a/contracts/protocol/configuration/AaveIncentivesController.sol b/contracts/protocol/configuration/AaveIncentivesController.sol new file mode 100644 index 00000000..ff46c6b4 --- /dev/null +++ b/contracts/protocol/configuration/AaveIncentivesController.sol @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: agpl-3.0 +pragma solidity 0.6.12; +pragma experimental ABIEncoderV2; + +contract AaveIncentivesController { + function handleAction( + address user, + uint256 userBalance, + uint256 totalSupply + ) external{ + require(true, "AHHA"); + } +} diff --git a/contracts/protocol/lendingpool/LendingPool.sol b/contracts/protocol/lendingpool/LendingPool.sol index 8e38650c..bc752c8f 100644 --- a/contracts/protocol/lendingpool/LendingPool.sol +++ b/contracts/protocol/lendingpool/LendingPool.sol @@ -87,7 +87,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage _addressesProvider = provider; _maxStableRateBorrowSizePercent = 2500; _flashLoanPremiumTotal = 9; - _maxNumberOfReserves = 128; + _maxNumberOfReserves = 10000; } /** diff --git a/contracts/protocol/lendingpool/LendingPoolStorage.sol b/contracts/protocol/lendingpool/LendingPoolStorage.sol index 198a3eea..35a7b63b 100644 --- a/contracts/protocol/lendingpool/LendingPoolStorage.sol +++ b/contracts/protocol/lendingpool/LendingPoolStorage.sol @@ -20,7 +20,7 @@ contract LendingPoolStorage { // the list of the available reserves, structured as a mapping for gas savings reasons mapping(uint256 => address) internal _reservesList; - uint256 internal _reservesCount; + uint256 public _reservesCount; bool internal _paused; diff --git a/contracts/protocol/libraries/configuration/UserConfiguration.sol b/contracts/protocol/libraries/configuration/UserConfiguration.sol index 2994f05d..508fa7a5 100644 --- a/contracts/protocol/libraries/configuration/UserConfiguration.sol +++ b/contracts/protocol/libraries/configuration/UserConfiguration.sol @@ -24,10 +24,14 @@ library UserConfiguration { uint256 reserveIndex, bool borrowing ) internal { - require(reserveIndex < 128, Errors.UL_INVALID_INDEX); - self.data = - (self.data & ~(1 << (reserveIndex * 2))) | - (uint256(borrowing ? 1 : 0) << (reserveIndex * 2)); + require(reserveIndex < 10000, Errors.UL_INVALID_INDEX); + uint256 dataIndex; + for(uint256 reserveDataIndex = reserveIndex; reserveDataIndex>128; reserveDataIndex-=128){ + dataIndex++; + } + self.data[dataIndex] = + (self.data[dataIndex] & ~(1 << (reserveIndex % 128 * 2))) | + (uint256(borrowing ? 1 : 0) << (reserveIndex % 128 * 2)); } /** @@ -41,10 +45,14 @@ library UserConfiguration { uint256 reserveIndex, bool usingAsCollateral ) internal { - require(reserveIndex < 128, Errors.UL_INVALID_INDEX); - self.data = - (self.data & ~(1 << (reserveIndex * 2 + 1))) | - (uint256(usingAsCollateral ? 1 : 0) << (reserveIndex * 2 + 1)); + require(reserveIndex < 10000, Errors.UL_INVALID_INDEX); + uint dataIndex; + for(uint256 reserveDataIndex = reserveIndex; reserveDataIndex>128; reserveDataIndex-=128){ + dataIndex++; + } + self.data[dataIndex] = + (self.data[dataIndex] & ~(1 << (reserveIndex % 128 * 2 + 1))) | + (uint256(usingAsCollateral ? 1 : 0) << (reserveIndex % 128 * 2 + 1)); } /** @@ -57,8 +65,12 @@ library UserConfiguration { DataTypes.UserConfigurationMap memory self, uint256 reserveIndex ) internal pure returns (bool) { - require(reserveIndex < 128, Errors.UL_INVALID_INDEX); - return (self.data >> (reserveIndex * 2)) & 3 != 0; + require(reserveIndex < 10000, Errors.UL_INVALID_INDEX); + uint256 dataIndex; + for(uint256 reserveDataIndex = reserveIndex; reserveDataIndex > 128; reserveDataIndex-=128){ + dataIndex++; + }S + return (self.data[dataIndex] >> (reserveIndex % 128 * 2)) & 3 != 0; } /** @@ -72,8 +84,13 @@ library UserConfiguration { pure returns (bool) { - require(reserveIndex < 128, Errors.UL_INVALID_INDEX); - return (self.data >> (reserveIndex * 2)) & 1 != 0; + require(reserveIndex < 10000, Errors.UL_INVALID_INDEX); + uint256 dataIndex; + for(uint256 reserveDataIndex = reserveIndex; reserveDataIndex>128; reserveDataIndex-=128){ + dataIndex++; + } + + return (self.data[dataIndex] >> (reserveIndex % 128 * 2)) & 1 != 0; } /** @@ -87,8 +104,12 @@ library UserConfiguration { pure returns (bool) { - require(reserveIndex < 128, Errors.UL_INVALID_INDEX); - return (self.data >> (reserveIndex * 2 + 1)) & 1 != 0; + require(reserveIndex < 10000, Errors.UL_INVALID_INDEX); + uint256 dataIndex; + for(uint256 reserveDataIndex = reserveIndex; reserveDataIndex>128; reserveDataIndex-=128){ + dataIndex++; + } + return (self.data[dataIndex] >> (reserveIndex % 128 * 2 + 1)) & 1 != 0; } /** @@ -97,7 +118,11 @@ library UserConfiguration { * @return True if the user has been borrowing any reserve, false otherwise **/ function isBorrowingAny(DataTypes.UserConfigurationMap memory self) internal pure returns (bool) { - return self.data & BORROWING_MASK != 0; + for(uint i=0; i<79; i++){ + if(self.data[i] & BORROWING_MASK != 0){ + return true; + } + } } /** @@ -106,6 +131,6 @@ library UserConfiguration { * @return True if the user has been borrowing any reserve, false otherwise **/ function isEmpty(DataTypes.UserConfigurationMap memory self) internal pure returns (bool) { - return self.data == 0; + return self.data[0] == 0; } } diff --git a/contracts/protocol/libraries/logic/GenericLogic.sol b/contracts/protocol/libraries/logic/GenericLogic.sol index d4081dda..463d79f5 100644 --- a/contracts/protocol/libraries/logic/GenericLogic.sol +++ b/contracts/protocol/libraries/logic/GenericLogic.sol @@ -166,13 +166,14 @@ library GenericLogic { ) { CalculateUserAccountDataVars memory vars; - + if (userConfig.isEmpty()) { return (0, 0, 0, 0, uint256(-1)); } + for (vars.i = 0; vars.i < reservesCount; vars.i++) { if (!userConfig.isUsingAsCollateralOrBorrowing(vars.i)) { - continue; + continue; } vars.currentReserveAddress = reserves[vars.i]; @@ -184,7 +185,7 @@ library GenericLogic { vars.tokenUnit = 10**vars.decimals; vars.reserveUnitPrice = IPriceOracleGetter(oracle).getAssetPrice(vars.currentReserveAddress); - + if (vars.liquidationThreshold != 0 && userConfig.isUsingAsCollateral(vars.i)) { vars.compoundedLiquidityBalance = IERC20(currentReserve.aTokenAddress).balanceOf(user); @@ -198,8 +199,7 @@ library GenericLogic { liquidityBalanceETH.mul(vars.liquidationThreshold) ); } - - if (userConfig.isBorrowing(vars.i)) { + if (userConfig.isBorrowing(vars.i)) { vars.compoundedBorrowBalance = IERC20(currentReserve.stableDebtTokenAddress).balanceOf( user ); @@ -213,6 +213,9 @@ library GenericLogic { } } + vars.currentReserveAddress = reserves[vars.i]; + + vars.avgLtv = vars.totalCollateralInETH > 0 ? vars.avgLtv.div(vars.totalCollateralInETH) : 0; vars.avgLiquidationThreshold = vars.totalCollateralInETH > 0 ? vars.avgLiquidationThreshold.div(vars.totalCollateralInETH) diff --git a/contracts/protocol/libraries/types/DataTypes.sol b/contracts/protocol/libraries/types/DataTypes.sol index a19e5efc..828788bb 100644 --- a/contracts/protocol/libraries/types/DataTypes.sol +++ b/contracts/protocol/libraries/types/DataTypes.sol @@ -24,7 +24,7 @@ library DataTypes { //address of the interest rate strategy address interestRateStrategyAddress; //the id of the reserve. Represents the position in the list of the active reserves - uint8 id; + uint256 id; } struct ReserveConfigurationMap { @@ -42,7 +42,7 @@ library DataTypes { } struct UserConfigurationMap { - uint256 data; + uint256[79] data; } enum InterestRateMode {NONE, STABLE, VARIABLE}