Skip to content

Commit

Permalink
Merge pull request #264 from aave/revert/reserves-cap
Browse files Browse the repository at this point in the history
Release Fix: Revert reserves cap change due breaking change at ILendingPool interface
  • Loading branch information
LHerskind authored Jan 10, 2022
2 parents d998c2f + 138446b commit 61c2273
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 204 deletions.
4 changes: 2 additions & 2 deletions contracts/protocol/lendingpool/LendingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
_addressesProvider = provider;
_maxStableRateBorrowSizePercent = 2500;
_flashLoanPremiumTotal = 9;
_maxNumberOfReserves = UserConfiguration._maxReserves;
_maxNumberOfReserves = 128;
}

/**
Expand Down Expand Up @@ -713,7 +713,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
}

/**
* @dev Returns the fee on flash loans
* @dev Returns the fee on flash loans
*/
function FLASHLOAN_PREMIUM_TOTAL() public view returns (uint256) {
return _flashLoanPremiumTotal;
Expand Down
51 changes: 14 additions & 37 deletions contracts/protocol/libraries/configuration/UserConfiguration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ library UserConfiguration {
uint256 internal constant BORROWING_MASK =
0x5555555555555555555555555555555555555555555555555555555555555555;

uint256 internal constant _maxReserves = 256;
uint256 internal constant _indexCount = _maxReserves / 128 + ((_maxReserves % 128 > 0) ? 1 : 0);

/**
* @dev Sets if the user is borrowing the reserve identified by reserveIndex
* @param self The configuration object
Expand All @@ -27,11 +24,9 @@ library UserConfiguration {
uint256 reserveIndex,
bool borrowing
) internal {
require(reserveIndex < _maxReserves, Errors.UL_INVALID_INDEX);
uint256 index = reserveIndex / 128;
reserveIndex = reserveIndex % 128;
self.data[index] =
(self.data[index] & ~(1 << (reserveIndex * 2))) |
require(reserveIndex < 128, Errors.UL_INVALID_INDEX);
self.data =
(self.data & ~(1 << (reserveIndex * 2))) |
(uint256(borrowing ? 1 : 0) << (reserveIndex * 2));
}

Expand All @@ -46,11 +41,9 @@ library UserConfiguration {
uint256 reserveIndex,
bool usingAsCollateral
) internal {
require(reserveIndex < _maxReserves, Errors.UL_INVALID_INDEX);
uint256 index = reserveIndex / 128;
reserveIndex = reserveIndex % 128;
self.data[index] =
(self.data[index] & ~(1 << (reserveIndex * 2 + 1))) |
require(reserveIndex < 128, Errors.UL_INVALID_INDEX);
self.data =
(self.data & ~(1 << (reserveIndex * 2 + 1))) |
(uint256(usingAsCollateral ? 1 : 0) << (reserveIndex * 2 + 1));
}

Expand All @@ -64,10 +57,8 @@ library UserConfiguration {
DataTypes.UserConfigurationMap memory self,
uint256 reserveIndex
) internal pure returns (bool) {
require(reserveIndex < _maxReserves, Errors.UL_INVALID_INDEX);
uint256 index = reserveIndex / 128;
reserveIndex = reserveIndex % 128;
return (self.data[index] >> (reserveIndex * 2)) & 3 != 0;
require(reserveIndex < 128, Errors.UL_INVALID_INDEX);
return (self.data >> (reserveIndex * 2)) & 3 != 0;
}

/**
Expand All @@ -81,10 +72,8 @@ library UserConfiguration {
pure
returns (bool)
{
require(reserveIndex < _maxReserves, Errors.UL_INVALID_INDEX);
uint256 index = reserveIndex / 128;
reserveIndex = reserveIndex % 128;
return (self.data[index] >> (reserveIndex * 2)) & 1 != 0;
require(reserveIndex < 128, Errors.UL_INVALID_INDEX);
return (self.data >> (reserveIndex * 2)) & 1 != 0;
}

/**
Expand All @@ -98,10 +87,8 @@ library UserConfiguration {
pure
returns (bool)
{
require(reserveIndex < _maxReserves, Errors.UL_INVALID_INDEX);
uint256 index = reserveIndex / 128;
reserveIndex = reserveIndex % 128;
return (self.data[index] >> (reserveIndex * 2 + 1)) & 1 != 0;
require(reserveIndex < 128, Errors.UL_INVALID_INDEX);
return (self.data >> (reserveIndex * 2 + 1)) & 1 != 0;
}

/**
Expand All @@ -110,12 +97,7 @@ library UserConfiguration {
* @return True if the user has been borrowing any reserve, false otherwise
**/
function isBorrowingAny(DataTypes.UserConfigurationMap memory self) internal pure returns (bool) {
for (uint8 i = 0; i < _indexCount; i++) {
if (self.data[i] & BORROWING_MASK != 0) {
return true;
}
}
return false;
return self.data & BORROWING_MASK != 0;
}

/**
Expand All @@ -124,11 +106,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) {
for (uint8 i = 0; i < _indexCount; i++) {
if (self.data[i] != 0) {
return false;
}
}
return true;
return self.data == 0;
}
}
2 changes: 1 addition & 1 deletion contracts/protocol/libraries/types/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ library DataTypes {
}

struct UserConfigurationMap {
uint256[2] data; // size is _maxReserves / 128 + ((_maxReserves % 128 > 0) ? 1 : 0), but need to be literal
uint256 data;
}

enum InterestRateMode {NONE, STABLE, VARIABLE}
Expand Down
164 changes: 0 additions & 164 deletions test-suites/test-aave/many-asset.spec.ts

This file was deleted.

0 comments on commit 61c2273

Please sign in to comment.