From d56a7a27797dedae3822e0ae914be469c2733eda Mon Sep 17 00:00:00 2001 From: eboado Date: Wed, 30 Sep 2020 11:24:22 +0200 Subject: [PATCH 01/11] Misc changes on ReserveConfiguration: - Fixed unprecise STABLE_BORROWING_MASK. - Added constant for start bit positions of the different configurations. --- .../configuration/ReserveConfiguration.sol | 113 +++++++++++------- 1 file changed, 71 insertions(+), 42 deletions(-) diff --git a/contracts/libraries/configuration/ReserveConfiguration.sol b/contracts/libraries/configuration/ReserveConfiguration.sol index 66fa21f4..7b3e44f7 100644 --- a/contracts/libraries/configuration/ReserveConfiguration.sol +++ b/contracts/libraries/configuration/ReserveConfiguration.sol @@ -20,40 +20,32 @@ library ReserveConfiguration { uint256 constant ACTIVE_MASK = 0xFFFFFEFFFFFFFFFFFFFF; uint256 constant FROZEN_MASK = 0xFFFFFDFFFFFFFFFFFFFF; uint256 constant BORROWING_MASK = 0xFFFFFBFFFFFFFFFFFFFF; - uint256 constant STABLE_BORROWING_MASK = 0xFFFF07FFFFFFFFFFFFFF; + uint256 constant STABLE_BORROWING_MASK = 0xFFFFF7FFFFFFFFFFFFFF; uint256 constant RESERVE_FACTOR_MASK = 0xFFFFFFFFFFFFFFFF; + /// @dev For the LTV, the start bit is 0 (up to 15), but we don't declare it as for 0 no bit movement is needed + uint256 constant LIQUIDATION_THRESHOLD_START_BIT_POSITION = 16; + uint256 constant LIQUIDATION_BONUS_START_BIT_POSITION = 32; + uint256 constant RESERVE_DECIMALS_START_BIT_POSITION = 48; + uint256 constant IS_ACTIVE_START_BIT_POSITION = 56; + uint256 constant IS_FROZEN_START_BIT_POSITION = 57; + uint256 constant BORROWING_ENABLED_START_BIT_POSITION = 58; + uint256 constant STABLE_BORROWING_ENABLED_START_BIT_POSITION = 59; + uint256 constant RESERVE_FACTOR_START_BIT_POSITION = 64; + struct Map { //bit 0-15: LTV //bit 16-31: Liq. threshold //bit 32-47: Liq. bonus //bit 48-55: Decimals //bit 56: Reserve is active - //bit 57: reserve is freezed + //bit 57: reserve is frozen //bit 58: borrowing is enabled //bit 59: stable rate borrowing enabled //bit 64-79: reserve factor uint256 data; } - /** - * @dev sets the reserve factor of the reserve - * @param self the reserve configuration - * @param reserveFactor the reserve factor - **/ - function setReserveFactor(ReserveConfiguration.Map memory self, uint256 reserveFactor) internal pure { - - self.data = (self.data & RESERVE_FACTOR_MASK) | reserveFactor << 64; - } - - /** - * @dev gets the reserve factor of the reserve - * @param self the reserve configuration - * @return the reserve factor - **/ - function getReserveFactor(ReserveConfiguration.Map storage self) internal view returns (uint256) { - return (self.data & ~RESERVE_FACTOR_MASK) >> 64; - } /** * @dev sets the Loan to Value of the reserve * @param self the reserve configuration @@ -81,7 +73,9 @@ library ReserveConfiguration { internal pure { - self.data = (self.data & LIQUIDATION_THRESHOLD_MASK) | (threshold << 16); + self.data = + (self.data & LIQUIDATION_THRESHOLD_MASK) | + (threshold << LIQUIDATION_THRESHOLD_START_BIT_POSITION); } /** @@ -94,7 +88,7 @@ library ReserveConfiguration { view returns (uint256) { - return (self.data & ~LIQUIDATION_THRESHOLD_MASK) >> 16; + return (self.data & ~LIQUIDATION_THRESHOLD_MASK) >> LIQUIDATION_THRESHOLD_START_BIT_POSITION; } /** @@ -103,7 +97,9 @@ library ReserveConfiguration { * @param bonus the new liquidation bonus **/ function setLiquidationBonus(ReserveConfiguration.Map memory self, uint256 bonus) internal pure { - self.data = (self.data & LIQUIDATION_BONUS_MASK) | (bonus << 32); + self.data = + (self.data & LIQUIDATION_BONUS_MASK) | + (bonus << LIQUIDATION_BONUS_START_BIT_POSITION); } /** @@ -116,7 +112,7 @@ library ReserveConfiguration { view returns (uint256) { - return (self.data & ~LIQUIDATION_BONUS_MASK) >> 32; + return (self.data & ~LIQUIDATION_BONUS_MASK) >> LIQUIDATION_BONUS_START_BIT_POSITION; } /** @@ -125,7 +121,7 @@ library ReserveConfiguration { * @param decimals the decimals **/ function setDecimals(ReserveConfiguration.Map memory self, uint256 decimals) internal pure { - self.data = (self.data & DECIMALS_MASK) | (decimals << 48); + self.data = (self.data & DECIMALS_MASK) | (decimals << RESERVE_DECIMALS_START_BIT_POSITION); } /** @@ -134,7 +130,7 @@ library ReserveConfiguration { * @return the decimals of the asset **/ function getDecimals(ReserveConfiguration.Map storage self) internal view returns (uint256) { - return (self.data & ~DECIMALS_MASK) >> 48; + return (self.data & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION; } /** @@ -143,7 +139,9 @@ library ReserveConfiguration { * @param active the active state **/ function setActive(ReserveConfiguration.Map memory self, bool active) internal pure { - self.data = (self.data & ACTIVE_MASK) | (uint256(active ? 1 : 0) << 56); + self.data = + (self.data & ACTIVE_MASK) | + (uint256(active ? 1 : 0) << IS_ACTIVE_START_BIT_POSITION); } /** @@ -152,7 +150,7 @@ library ReserveConfiguration { * @return the active state **/ function getActive(ReserveConfiguration.Map storage self) internal view returns (bool) { - return ((self.data & ~ACTIVE_MASK) >> 56) != 0; + return ((self.data & ~ACTIVE_MASK) >> IS_ACTIVE_START_BIT_POSITION) != 0; } /** @@ -161,7 +159,9 @@ library ReserveConfiguration { * @param frozen the frozen state **/ function setFrozen(ReserveConfiguration.Map memory self, bool frozen) internal pure { - self.data = (self.data & FROZEN_MASK) | (uint256(frozen ? 1 : 0) << 57); + self.data = + (self.data & FROZEN_MASK) | + (uint256(frozen ? 1 : 0) << IS_FROZEN_START_BIT_POSITION); } /** @@ -170,7 +170,7 @@ library ReserveConfiguration { * @return the frozen state **/ function getFrozen(ReserveConfiguration.Map storage self) internal view returns (bool) { - return ((self.data & ~FROZEN_MASK) >> 57) != 0; + return ((self.data & ~FROZEN_MASK) >> IS_FROZEN_START_BIT_POSITION) != 0; } /** @@ -179,7 +179,9 @@ library ReserveConfiguration { * @param enabled true if the borrowing needs to be enabled, false otherwise **/ function setBorrowingEnabled(ReserveConfiguration.Map memory self, bool enabled) internal pure { - self.data = (self.data & BORROWING_MASK) | (uint256(enabled ? 1 : 0) << 58); + self.data = + (self.data & BORROWING_MASK) | + (uint256(enabled ? 1 : 0) << BORROWING_ENABLED_START_BIT_POSITION); } /** @@ -188,7 +190,7 @@ library ReserveConfiguration { * @return the borrowing state **/ function getBorrowingEnabled(ReserveConfiguration.Map storage self) internal view returns (bool) { - return ((self.data & ~BORROWING_MASK) >> 58) != 0; + return ((self.data & ~BORROWING_MASK) >> BORROWING_ENABLED_START_BIT_POSITION) != 0; } /** @@ -197,9 +199,12 @@ library ReserveConfiguration { * @param enabled true if the stable rate borrowing needs to be enabled, false otherwise **/ function setStableRateBorrowingEnabled(ReserveConfiguration.Map memory self, bool enabled) - internal pure + internal + pure { - self.data = (self.data & STABLE_BORROWING_MASK) | (uint256(enabled ? 1 : 0) << 59); + self.data = + (self.data & STABLE_BORROWING_MASK) | + (uint256(enabled ? 1 : 0) << STABLE_BORROWING_ENABLED_START_BIT_POSITION); } /** @@ -212,7 +217,31 @@ library ReserveConfiguration { view returns (bool) { - return ((self.data & ~STABLE_BORROWING_MASK) >> 59) != 0; + return + ((self.data & ~STABLE_BORROWING_MASK) >> STABLE_BORROWING_ENABLED_START_BIT_POSITION) != 0; + } + + /** + * @dev sets the reserve factor of the reserve + * @param self the reserve configuration + * @param reserveFactor the reserve factor + **/ + function setReserveFactor(ReserveConfiguration.Map memory self, uint256 reserveFactor) + internal + pure + { + self.data = + (self.data & RESERVE_FACTOR_MASK) | + (reserveFactor << RESERVE_FACTOR_START_BIT_POSITION); + } + + /** + * @dev gets the reserve factor of the reserve + * @param self the reserve configuration + * @return the reserve factor + **/ + function getReserveFactor(ReserveConfiguration.Map storage self) internal view returns (uint256) { + return (self.data & ~RESERVE_FACTOR_MASK) >> RESERVE_FACTOR_START_BIT_POSITION; } /** @@ -233,10 +262,10 @@ library ReserveConfiguration { uint256 dataLocal = self.data; return ( - (dataLocal & ~ACTIVE_MASK) >> 56 != 0, - (dataLocal & ~FROZEN_MASK) >> 57 != 0, - (dataLocal & ~BORROWING_MASK) >> 58 != 0, - (dataLocal & ~STABLE_BORROWING_MASK) >> 59 != 0 + (dataLocal & ~ACTIVE_MASK) >> IS_ACTIVE_START_BIT_POSITION != 0, + (dataLocal & ~FROZEN_MASK) >> IS_FROZEN_START_BIT_POSITION != 0, + (dataLocal & ~BORROWING_MASK) >> BORROWING_ENABLED_START_BIT_POSITION != 0, + (dataLocal & ~STABLE_BORROWING_MASK) >> STABLE_BORROWING_ENABLED_START_BIT_POSITION != 0 ); } @@ -259,9 +288,9 @@ library ReserveConfiguration { return ( dataLocal & ~LTV_MASK, - (dataLocal & ~LIQUIDATION_THRESHOLD_MASK) >> 16, - (dataLocal & ~LIQUIDATION_BONUS_MASK) >> 32, - (dataLocal & ~DECIMALS_MASK) >> 48 + (dataLocal & ~LIQUIDATION_THRESHOLD_MASK) >> LIQUIDATION_THRESHOLD_START_BIT_POSITION, + (dataLocal & ~LIQUIDATION_BONUS_MASK) >> LIQUIDATION_BONUS_START_BIT_POSITION, + (dataLocal & ~DECIMALS_MASK) >> RESERVE_DECIMALS_START_BIT_POSITION ); } } From e86cf9fe0a12552ffef0b43da397352dd5813a76 Mon Sep 17 00:00:00 2001 From: The3D Date: Tue, 6 Oct 2020 10:23:02 +0200 Subject: [PATCH 02/11] Fixes liquidation bonus mask, adds comment on reserved bits --- contracts/libraries/configuration/ReserveConfiguration.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/libraries/configuration/ReserveConfiguration.sol b/contracts/libraries/configuration/ReserveConfiguration.sol index 7b3e44f7..5053c0fd 100644 --- a/contracts/libraries/configuration/ReserveConfiguration.sol +++ b/contracts/libraries/configuration/ReserveConfiguration.sol @@ -15,7 +15,7 @@ import {IPriceOracleGetter} from '../../interfaces/IPriceOracleGetter.sol'; library ReserveConfiguration { uint256 constant LTV_MASK = 0xFFFFFFFFFFFFFFFF0000; uint256 constant LIQUIDATION_THRESHOLD_MASK = 0xFFFFFFFFFFFF0000FFFF; - uint256 constant LIQUIDATION_BONUS_MASK = 0xFFFFFFF0000FFFFFFFF; + uint256 constant LIQUIDATION_BONUS_MASK = 0xFFFFFFFF0000FFFFFFFF; uint256 constant DECIMALS_MASK = 0xFFFFFF00FFFFFFFFFFFF; uint256 constant ACTIVE_MASK = 0xFFFFFEFFFFFFFFFFFFFF; uint256 constant FROZEN_MASK = 0xFFFFFDFFFFFFFFFFFFFF; @@ -42,6 +42,7 @@ library ReserveConfiguration { //bit 57: reserve is frozen //bit 58: borrowing is enabled //bit 59: stable rate borrowing enabled + //bit 60-63: reserved //bit 64-79: reserve factor uint256 data; } From 4d991e6709729f696cea234bb1ccfe858d100cd8 Mon Sep 17 00:00:00 2001 From: The3D Date: Tue, 6 Oct 2020 10:59:33 +0200 Subject: [PATCH 03/11] Updated tests on freeze, borrowingEnabled --- test/configurator.spec.ts | 45 +++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/test/configurator.spec.ts b/test/configurator.spec.ts index 0fa3289c..8c24d43d 100644 --- a/test/configurator.spec.ts +++ b/test/configurator.spec.ts @@ -42,8 +42,27 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { it('Freezes the ETH reserve', async () => { const {configurator, pool, weth} = testEnv; await configurator.freezeReserve(weth.address); - const {isFreezed} = await pool.getReserveConfigurationData(weth.address); + const { + decimals, + ltv, + liquidationBonus, + liquidationThreshold, + reserveFactor, + stableBorrowRateEnabled, + borrowingEnabled, + isActive, + isFreezed + } = await pool.getReserveConfigurationData(weth.address); + + expect(borrowingEnabled).to.be.equal(true); + expect(isActive).to.be.equal(true); expect(isFreezed).to.be.equal(true); + expect(decimals).to.be.equal(18); + expect(ltv).to.be.equal(7500); + expect(liquidationThreshold).to.be.equal(8000); + expect(liquidationBonus).to.be.equal(10500); + expect(stableBorrowRateEnabled).to.be.equal(true); + expect(reserveFactor).to.be.equal(0); }); it('Unfreezes the ETH reserve', async () => { @@ -73,8 +92,28 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { it('Deactivates the ETH reserve for borrowing', async () => { const {configurator, pool, weth} = testEnv; await configurator.disableBorrowingOnReserve(weth.address); - const {borrowingEnabled} = await pool.getReserveConfigurationData(weth.address); + const { + decimals, + ltv, + liquidationBonus, + liquidationThreshold, + reserveFactor, + stableBorrowRateEnabled, + borrowingEnabled, + isActive, + isFreezed + } = await pool.getReserveConfigurationData(weth.address); + expect(borrowingEnabled).to.be.equal(false); + expect(isActive).to.be.equal(true); + expect(isFreezed).to.be.equal(false); + expect(decimals).to.be.equal(18); + expect(ltv).to.be.equal(7500); + expect(liquidationThreshold).to.be.equal(8000); + expect(liquidationBonus).to.be.equal(10500); + expect(stableBorrowRateEnabled).to.be.equal(true); + expect(reserveFactor).to.be.equal(0); + }); it('Activates the ETH reserve for borrowing', async () => { @@ -180,7 +219,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { ).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN); }); - it('Changes the reserve factor of the reserve', async () => { const {configurator, pool, weth} = testEnv; await configurator.setReserveFactor(weth.address, '1000'); @@ -196,7 +234,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { ).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN); }); - it('Changes liquidation threshold of the reserve', async () => { const {configurator, pool, weth} = testEnv; await configurator.setLiquidationThreshold(weth.address, '75'); From bad45772c145f0b431cef39d0324cd2fe3dba5dc Mon Sep 17 00:00:00 2001 From: The3D Date: Tue, 6 Oct 2020 11:02:34 +0200 Subject: [PATCH 04/11] Updated tests on unfreeze --- test/configurator.spec.ts | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/test/configurator.spec.ts b/test/configurator.spec.ts index 8c24d43d..d83f5d71 100644 --- a/test/configurator.spec.ts +++ b/test/configurator.spec.ts @@ -51,7 +51,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { stableBorrowRateEnabled, borrowingEnabled, isActive, - isFreezed + isFreezed, } = await pool.getReserveConfigurationData(weth.address); expect(borrowingEnabled).to.be.equal(true); @@ -62,15 +62,34 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { expect(liquidationThreshold).to.be.equal(8000); expect(liquidationBonus).to.be.equal(10500); expect(stableBorrowRateEnabled).to.be.equal(true); - expect(reserveFactor).to.be.equal(0); + expect(reserveFactor).to.be.equal(0); }); it('Unfreezes the ETH reserve', async () => { const {configurator, pool, weth} = testEnv; await configurator.unfreezeReserve(weth.address); - const {isFreezed} = await pool.getReserveConfigurationData(weth.address); + const { + decimals, + ltv, + liquidationBonus, + liquidationThreshold, + reserveFactor, + stableBorrowRateEnabled, + borrowingEnabled, + isActive, + isFreezed, + } = await pool.getReserveConfigurationData(weth.address); + + expect(borrowingEnabled).to.be.equal(true); + expect(isActive).to.be.equal(true); expect(isFreezed).to.be.equal(false); + expect(decimals).to.be.equal(18); + expect(ltv).to.be.equal(7500); + expect(liquidationThreshold).to.be.equal(8000); + expect(liquidationBonus).to.be.equal(10500); + expect(stableBorrowRateEnabled).to.be.equal(true); + expect(reserveFactor).to.be.equal(0); }); it('Check the onlyAaveAdmin on freezeReserve ', async () => { @@ -101,7 +120,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { stableBorrowRateEnabled, borrowingEnabled, isActive, - isFreezed + isFreezed, } = await pool.getReserveConfigurationData(weth.address); expect(borrowingEnabled).to.be.equal(false); @@ -113,7 +132,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { expect(liquidationBonus).to.be.equal(10500); expect(stableBorrowRateEnabled).to.be.equal(true); expect(reserveFactor).to.be.equal(0); - }); it('Activates the ETH reserve for borrowing', async () => { From 450cdfa95c197d8d44f8c3fed70095b84e3c49f2 Mon Sep 17 00:00:00 2001 From: The3D Date: Tue, 6 Oct 2020 11:03:51 +0200 Subject: [PATCH 05/11] Updated tests on enableBorrowingOnReserve --- test/configurator.spec.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/configurator.spec.ts b/test/configurator.spec.ts index d83f5d71..de6fbd76 100644 --- a/test/configurator.spec.ts +++ b/test/configurator.spec.ts @@ -137,9 +137,30 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { it('Activates the ETH reserve for borrowing', async () => { const {configurator, pool, weth} = testEnv; await configurator.enableBorrowingOnReserve(weth.address, true); - const {borrowingEnabled} = await pool.getReserveConfigurationData(weth.address); const {variableBorrowIndex} = await pool.getReserveData(weth.address); + + const { + decimals, + ltv, + liquidationBonus, + liquidationThreshold, + reserveFactor, + stableBorrowRateEnabled, + borrowingEnabled, + isActive, + isFreezed, + } = await pool.getReserveConfigurationData(weth.address); + expect(borrowingEnabled).to.be.equal(true); + expect(isActive).to.be.equal(true); + expect(isFreezed).to.be.equal(false); + expect(decimals).to.be.equal(18); + expect(ltv).to.be.equal(7500); + expect(liquidationThreshold).to.be.equal(8000); + expect(liquidationBonus).to.be.equal(10500); + expect(stableBorrowRateEnabled).to.be.equal(true); + expect(reserveFactor).to.be.equal(0); + expect(variableBorrowIndex.toString()).to.be.equal(RAY); }); From 3fd4003aa039c1aa44673ae8415f1e5a3d05dc6c Mon Sep 17 00:00:00 2001 From: The3D Date: Tue, 6 Oct 2020 11:20:45 +0200 Subject: [PATCH 06/11] Added test on deactivate as collateral --- test/configurator.spec.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/test/configurator.spec.ts b/test/configurator.spec.ts index de6fbd76..4253b51f 100644 --- a/test/configurator.spec.ts +++ b/test/configurator.spec.ts @@ -183,8 +183,27 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { it('Deactivates the ETH reserve as collateral', async () => { const {configurator, pool, weth} = testEnv; await configurator.disableReserveAsCollateral(weth.address); - const {usageAsCollateralEnabled} = await pool.getReserveConfigurationData(weth.address); - expect(usageAsCollateralEnabled).to.be.equal(false); + const { + decimals, + ltv, + liquidationBonus, + liquidationThreshold, + reserveFactor, + stableBorrowRateEnabled, + borrowingEnabled, + isActive, + isFreezed, + } = await pool.getReserveConfigurationData(weth.address); + + expect(borrowingEnabled).to.be.equal(true); + expect(isActive).to.be.equal(true); + expect(isFreezed).to.be.equal(false); + expect(decimals).to.be.equal(18); + expect(ltv).to.be.equal(0); + expect(liquidationThreshold).to.be.equal(8000); + expect(liquidationBonus).to.be.equal(10500); + expect(stableBorrowRateEnabled).to.be.equal(true); + expect(reserveFactor).to.be.equal(0); }); it('Activates the ETH reserve as collateral', async () => { From 35db5833faab26aa2c1e67386b7d3e756546f576 Mon Sep 17 00:00:00 2001 From: The3D Date: Tue, 6 Oct 2020 11:27:53 +0200 Subject: [PATCH 07/11] Added test on disable stable borrow rate --- test/configurator.spec.ts | 46 +++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/test/configurator.spec.ts b/test/configurator.spec.ts index 4253b51f..5b5bbe8c 100644 --- a/test/configurator.spec.ts +++ b/test/configurator.spec.ts @@ -208,10 +208,29 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { it('Activates the ETH reserve as collateral', async () => { const {configurator, pool, weth} = testEnv; - await configurator.enableReserveAsCollateral(weth.address, '75', '80', '105'); + await configurator.enableReserveAsCollateral(weth.address, '7500', '8000', '10500'); - const {usageAsCollateralEnabled} = await pool.getReserveConfigurationData(weth.address); - expect(usageAsCollateralEnabled).to.be.equal(true); + const { + decimals, + ltv, + liquidationBonus, + liquidationThreshold, + reserveFactor, + stableBorrowRateEnabled, + borrowingEnabled, + isActive, + isFreezed, + } = await pool.getReserveConfigurationData(weth.address); + + expect(borrowingEnabled).to.be.equal(true); + expect(isActive).to.be.equal(true); + expect(isFreezed).to.be.equal(false); + expect(decimals).to.be.equal(18); + expect(ltv).to.be.equal(7500); + expect(liquidationThreshold).to.be.equal(8000); + expect(liquidationBonus).to.be.equal(10500); + expect(stableBorrowRateEnabled).to.be.equal(true); + expect(reserveFactor).to.be.equal(0); }); it('Check the onlyAaveAdmin on disableReserveAsCollateral ', async () => { @@ -235,8 +254,27 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { it('Disable stable borrow rate on the ETH reserve', async () => { const {configurator, pool, weth} = testEnv; await configurator.disableReserveStableRate(weth.address); - const {stableBorrowRateEnabled} = await pool.getReserveConfigurationData(weth.address); + const { + decimals, + ltv, + liquidationBonus, + liquidationThreshold, + reserveFactor, + stableBorrowRateEnabled, + borrowingEnabled, + isActive, + isFreezed, + } = await pool.getReserveConfigurationData(weth.address); + + expect(borrowingEnabled).to.be.equal(true); + expect(isActive).to.be.equal(true); + expect(isFreezed).to.be.equal(false); + expect(decimals).to.be.equal(18); + expect(ltv).to.be.equal(7500); + expect(liquidationThreshold).to.be.equal(8000); + expect(liquidationBonus).to.be.equal(10500); expect(stableBorrowRateEnabled).to.be.equal(false); + expect(reserveFactor).to.be.equal(0); }); it('Enables stable borrow rate on the ETH reserve', async () => { From b30ccd6dd288e39a2c8a42ee2b71dddfcd0e78ed Mon Sep 17 00:00:00 2001 From: The3D Date: Tue, 6 Oct 2020 11:28:46 +0200 Subject: [PATCH 08/11] Added test on disable stable borrow rate --- test/configurator.spec.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test/configurator.spec.ts b/test/configurator.spec.ts index 5b5bbe8c..865e2b8a 100644 --- a/test/configurator.spec.ts +++ b/test/configurator.spec.ts @@ -280,9 +280,27 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { it('Enables stable borrow rate on the ETH reserve', async () => { const {configurator, pool, weth} = testEnv; await configurator.enableReserveStableRate(weth.address); - const {stableBorrowRateEnabled} = await pool.getReserveConfigurationData(weth.address); + const { + decimals, + ltv, + liquidationBonus, + liquidationThreshold, + reserveFactor, + stableBorrowRateEnabled, + borrowingEnabled, + isActive, + isFreezed, + } = await pool.getReserveConfigurationData(weth.address); + + expect(borrowingEnabled).to.be.equal(true); + expect(isActive).to.be.equal(true); + expect(isFreezed).to.be.equal(false); + expect(decimals).to.be.equal(18); + expect(ltv).to.be.equal(7500); + expect(liquidationThreshold).to.be.equal(8000); + expect(liquidationBonus).to.be.equal(10500); expect(stableBorrowRateEnabled).to.be.equal(true); - }); + expect(reserveFactor).to.be.equal(0); }); it('Check the onlyAaveAdmin on disableReserveStableRate', async () => { const {configurator, users, weth} = testEnv; From d77e5ce5be2a4814ffa960a7c3634563f555bc9b Mon Sep 17 00:00:00 2001 From: The3D Date: Tue, 6 Oct 2020 11:30:10 +0200 Subject: [PATCH 09/11] Added test on disable stable borrow rate --- test/configurator.spec.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/test/configurator.spec.ts b/test/configurator.spec.ts index 865e2b8a..6da90661 100644 --- a/test/configurator.spec.ts +++ b/test/configurator.spec.ts @@ -320,10 +320,29 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { it('Changes LTV of the reserve', async () => { const {configurator, pool, weth} = testEnv; - await configurator.setLtv(weth.address, '60'); - const {ltv} = await pool.getReserveConfigurationData(weth.address); - expect(ltv.toString()).to.be.bignumber.equal('60', 'Invalid LTV'); - }); + await configurator.setLtv(weth.address, '6000'); + const { + decimals, + ltv, + liquidationBonus, + liquidationThreshold, + reserveFactor, + stableBorrowRateEnabled, + borrowingEnabled, + isActive, + isFreezed, + } = await pool.getReserveConfigurationData(weth.address); + + expect(borrowingEnabled).to.be.equal(true); + expect(isActive).to.be.equal(true); + expect(isFreezed).to.be.equal(false); + expect(decimals).to.be.equal(18); + expect(ltv).to.be.equal(6000); + expect(liquidationThreshold).to.be.equal(8000); + expect(liquidationBonus).to.be.equal(10500); + expect(stableBorrowRateEnabled).to.be.equal(true); + expect(reserveFactor).to.be.equal(0); + }); it('Check the onlyAaveAdmin on setLtv', async () => { const {configurator, users, weth} = testEnv; From b88bdc8c2c47930e94b35d23da796bf4573c1bde Mon Sep 17 00:00:00 2001 From: The3D Date: Tue, 6 Oct 2020 11:34:50 +0200 Subject: [PATCH 10/11] updated test on liquidation threshold, reserve factor --- test/configurator.spec.ts | 58 +++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/test/configurator.spec.ts b/test/configurator.spec.ts index 6da90661..82982ec6 100644 --- a/test/configurator.spec.ts +++ b/test/configurator.spec.ts @@ -300,7 +300,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { expect(liquidationThreshold).to.be.equal(8000); expect(liquidationBonus).to.be.equal(10500); expect(stableBorrowRateEnabled).to.be.equal(true); - expect(reserveFactor).to.be.equal(0); }); + expect(reserveFactor).to.be.equal(0); + }); it('Check the onlyAaveAdmin on disableReserveStableRate', async () => { const {configurator, users, weth} = testEnv; @@ -321,7 +322,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { it('Changes LTV of the reserve', async () => { const {configurator, pool, weth} = testEnv; await configurator.setLtv(weth.address, '6000'); - const { + const { decimals, ltv, liquidationBonus, @@ -342,7 +343,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { expect(liquidationBonus).to.be.equal(10500); expect(stableBorrowRateEnabled).to.be.equal(true); expect(reserveFactor).to.be.equal(0); - }); + }); it('Check the onlyAaveAdmin on setLtv', async () => { const {configurator, users, weth} = testEnv; @@ -355,8 +356,27 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { it('Changes the reserve factor of the reserve', async () => { const {configurator, pool, weth} = testEnv; await configurator.setReserveFactor(weth.address, '1000'); - const {reserveFactor} = await pool.getReserveConfigurationData(weth.address); - expect(reserveFactor.toString()).to.be.bignumber.equal('1000', 'Invalid reserve factor'); + const { + decimals, + ltv, + liquidationBonus, + liquidationThreshold, + reserveFactor, + stableBorrowRateEnabled, + borrowingEnabled, + isActive, + isFreezed, + } = await pool.getReserveConfigurationData(weth.address); + + expect(borrowingEnabled).to.be.equal(true); + expect(isActive).to.be.equal(true); + expect(isFreezed).to.be.equal(false); + expect(decimals).to.be.equal(18); + expect(ltv).to.be.equal(6000); + expect(liquidationThreshold).to.be.equal(8000); + expect(liquidationBonus).to.be.equal(10500); + expect(stableBorrowRateEnabled).to.be.equal(true); + expect(reserveFactor).to.be.equal(1000); }); it('Check the onlyLendingPoolManager on setReserveFactor', async () => { @@ -369,12 +389,28 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { it('Changes liquidation threshold of the reserve', async () => { const {configurator, pool, weth} = testEnv; - await configurator.setLiquidationThreshold(weth.address, '75'); - const {liquidationThreshold} = await pool.getReserveConfigurationData(weth.address); - expect(liquidationThreshold.toString()).to.be.bignumber.equal( - '75', - 'Invalid Liquidation threshold' - ); + await configurator.setLiquidationThreshold(weth.address, '7500'); + const { + decimals, + ltv, + liquidationBonus, + liquidationThreshold, + reserveFactor, + stableBorrowRateEnabled, + borrowingEnabled, + isActive, + isFreezed, + } = await pool.getReserveConfigurationData(weth.address); + + expect(borrowingEnabled).to.be.equal(true); + expect(isActive).to.be.equal(true); + expect(isFreezed).to.be.equal(false); + expect(decimals).to.be.equal(18); + expect(ltv).to.be.equal(6000); + expect(liquidationThreshold).to.be.equal(7500); + expect(liquidationBonus).to.be.equal(10500); + expect(stableBorrowRateEnabled).to.be.equal(true); + expect(reserveFactor).to.be.equal(1000); }); it('Check the onlyAaveAdmin on setLiquidationThreshold', async () => { From f3852d7081e5bb40e6df84f6b9de83a774f30fde Mon Sep 17 00:00:00 2001 From: The3D Date: Tue, 6 Oct 2020 11:36:29 +0200 Subject: [PATCH 11/11] Updated test on liquidation bonus --- test/configurator.spec.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/test/configurator.spec.ts b/test/configurator.spec.ts index 82982ec6..3ed53984 100644 --- a/test/configurator.spec.ts +++ b/test/configurator.spec.ts @@ -423,12 +423,28 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { it('Changes liquidation bonus of the reserve', async () => { const {configurator, pool, weth} = testEnv; - await configurator.setLiquidationBonus(weth.address, '110'); - const {liquidationBonus} = await pool.getReserveConfigurationData(weth.address); - expect(liquidationBonus.toString()).to.be.bignumber.equal( - '110', - 'Invalid Liquidation discount' - ); + await configurator.setLiquidationBonus(weth.address, '11000'); + const { + decimals, + ltv, + liquidationBonus, + liquidationThreshold, + reserveFactor, + stableBorrowRateEnabled, + borrowingEnabled, + isActive, + isFreezed, + } = await pool.getReserveConfigurationData(weth.address); + + expect(borrowingEnabled).to.be.equal(true); + expect(isActive).to.be.equal(true); + expect(isFreezed).to.be.equal(false); + expect(decimals).to.be.equal(18); + expect(ltv).to.be.equal(6000); + expect(liquidationThreshold).to.be.equal(7500); + expect(liquidationBonus).to.be.equal(11000); + expect(stableBorrowRateEnabled).to.be.equal(true); + expect(reserveFactor).to.be.equal(1000); }); it('Check the onlyAaveAdmin on setLiquidationBonus', async () => {