From 099b1f0b054127d214e2e5bbe5f5d2dcb7c7a558 Mon Sep 17 00:00:00 2001 From: Hadrien Charlanes Date: Tue, 25 May 2021 11:22:58 +0200 Subject: [PATCH] fix: from 48 to 36 bits caps, added memory lib getters for caps --- .../configuration/ReserveConfiguration.sol | 58 ++++++++++++------- helpers/constants.ts | 4 +- markets/matic/reservesConfigs.ts | 2 + 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/contracts/protocol/libraries/configuration/ReserveConfiguration.sol b/contracts/protocol/libraries/configuration/ReserveConfiguration.sol index 77375778..567ee93b 100644 --- a/contracts/protocol/libraries/configuration/ReserveConfiguration.sol +++ b/contracts/protocol/libraries/configuration/ReserveConfiguration.sol @@ -19,8 +19,8 @@ library ReserveConfiguration { uint256 constant BORROWING_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBFFFFFFFFFFFFFF; // prettier-ignore uint256 constant STABLE_BORROWING_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFFFFF; // prettier-ignore uint256 constant RESERVE_FACTOR_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFF; // prettier-ignore - uint256 constant BORROW_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000FFFFFFFFFFFFFFFFFFFF; // prettier-ignore - uint256 constant SUPPLY_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFF000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore + uint256 constant BORROW_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFF; // prettier-ignore + uint256 constant SUPPLY_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore /// @dev For the LTV, the start bit is 0 (up to 15), hence no bitshifting is needed uint256 constant LIQUIDATION_THRESHOLD_START_BIT_POSITION = 16; @@ -32,15 +32,15 @@ library ReserveConfiguration { uint256 constant STABLE_BORROWING_ENABLED_START_BIT_POSITION = 59; uint256 constant RESERVE_FACTOR_START_BIT_POSITION = 64; uint256 constant BORROW_CAP_START_BIT_POSITION = 80; - uint256 constant SUPPLY_CAP_START_BIT_POSITION = 128; + uint256 constant SUPPLY_CAP_START_BIT_POSITION = 116; uint256 constant MAX_VALID_LTV = 65535; uint256 constant MAX_VALID_LIQUIDATION_THRESHOLD = 65535; uint256 constant MAX_VALID_LIQUIDATION_BONUS = 65535; uint256 constant MAX_VALID_DECIMALS = 255; uint256 constant MAX_VALID_RESERVE_FACTOR = 65535; - uint256 constant MAX_VALID_BORROW_CAP = 281474976710655; - uint256 constant MAX_VALID_SUPPLY_CAP = 281474976710655; + uint256 constant MAX_VALID_BORROW_CAP = 68719476735; + uint256 constant MAX_VALID_SUPPLY_CAP = 68719476735; /** * @dev Sets the Loan to Value of the reserve @@ -281,9 +281,7 @@ library ReserveConfiguration { { require(borrowCap <= MAX_VALID_BORROW_CAP, Errors.RC_INVALID_BORROW_CAP); - self.data = - (self.data & BORROW_CAP_MASK) | - (borrowCap << BORROW_CAP_START_BIT_POSITION); + self.data = (self.data & BORROW_CAP_MASK) | (borrowCap << BORROW_CAP_START_BIT_POSITION); } /** @@ -310,9 +308,7 @@ library ReserveConfiguration { { require(supplyCap <= MAX_VALID_SUPPLY_CAP, Errors.RC_INVALID_SUPPLY_CAP); - self.data = - (self.data & SUPPLY_CAP_MASK) | - (supplyCap << SUPPLY_CAP_START_BIT_POSITION); + self.data = (self.data & SUPPLY_CAP_MASK) | (supplyCap << SUPPLY_CAP_START_BIT_POSITION); } /** @@ -388,16 +384,13 @@ library ReserveConfiguration { function getCaps(DataTypes.ReserveConfigurationMap storage self) internal view - returns ( - uint256, - uint256 - ) + returns (uint256, uint256) { uint256 dataLocal = self.data; return ( - (self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION, - (self.data & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION + (dataLocal & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION, + (dataLocal & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION ); } @@ -434,10 +427,7 @@ library ReserveConfiguration { function getCapsMemory(DataTypes.ReserveConfigurationMap memory self) internal pure - returns ( - uint256, - uint256 - ) + returns (uint256, uint256) { return ( (self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION, @@ -467,4 +457,30 @@ library ReserveConfiguration { (self.data & ~STABLE_BORROWING_MASK) != 0 ); } + + /** + * @dev Gets the supply cap of the reserve from a memory objet + * @param self The reserve configuration + * @return The supply cap + **/ + function getSupplyCapMemory(DataTypes.ReserveConfigurationMap memory self) + internal + pure + returns (uint256) + { + return (self.data & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION; + } + + /** + * @dev Gets the borrow cap of the reserve from a memory object + * @param self The reserve configuration + * @return The borrow cap + **/ + function getBorrowCapMemory(DataTypes.ReserveConfigurationMap memory self) + internal + pure + returns (uint256) + { + return (self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION; + } } diff --git a/helpers/constants.ts b/helpers/constants.ts index a0274bcc..f2568ee0 100644 --- a/helpers/constants.ts +++ b/helpers/constants.ts @@ -15,8 +15,8 @@ export const oneEther = new BigNumber(Math.pow(10, 18)); export const oneRay = new BigNumber(Math.pow(10, 27)); export const MAX_UINT_AMOUNT = '115792089237316195423570985008687907853269984665640564039457584007913129639935'; -export const MAX_BORROW_CAP = '281474976710655'; -export const MAX_SUPPLY_CAP = '281474976710655'; +export const MAX_BORROW_CAP = '68719476735'; +export const MAX_SUPPLY_CAP = '68719476735'; export const ONE_YEAR = '31536000'; export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; export const ONE_ADDRESS = '0x0000000000000000000000000000000000000001'; diff --git a/markets/matic/reservesConfigs.ts b/markets/matic/reservesConfigs.ts index 2fd924f1..a9f7f29f 100644 --- a/markets/matic/reservesConfigs.ts +++ b/markets/matic/reservesConfigs.ts @@ -90,6 +90,8 @@ export const strategyMATIC: IReserveParams = { stableBorrowRateEnabled: false, reserveDecimals: '18', aTokenImpl: eContractid.AToken, + borrowCap: MAX_BORROW_CAP, + supplyCap: MAX_SUPPLY_CAP, reserveFactor: '2000', };