Skip to content

Commit

Permalink
fix: fixed validateSetUserEMode
Browse files Browse the repository at this point in the history
  • Loading branch information
The-3D committed Sep 24, 2021
1 parent 0534f47 commit 750fd34
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 6 additions & 0 deletions contracts/mocks/helpers/MockReserveConfiguration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ contract MockReserveConfiguration {
return configuration.getEModeCategory();
}

function setEModeCategory(uint8 categoryId) external {
DataTypes.ReserveConfigurationMap memory config = configuration;
config.setEModeCategory(categoryId);
configuration = config;
}

function setSupplyCap(uint256 supplyCap) external {
DataTypes.ReserveConfigurationMap memory config = configuration;
config.setSupplyCap(supplyCap);
Expand Down
9 changes: 4 additions & 5 deletions contracts/protocol/libraries/logic/ValidationLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ library ValidationLogic {
(bool isActive, bool isFrozen, , , bool isPaused) = reserveCache
.reserveConfiguration
.getFlags();
(, , , uint256 reserveDecimals, ,) = reserveCache.reserveConfiguration.getParams();
(, , , uint256 reserveDecimals, , ) = reserveCache.reserveConfiguration.getParams();
uint256 supplyCap = reserveCache.reserveConfiguration.getSupplyCap();

require(amount != 0, Errors.VL_INVALID_AMOUNT);
Expand Down Expand Up @@ -122,7 +122,7 @@ library ValidationLogic {
) internal view {
ValidateBorrowLocalVars memory vars;

(, , , vars.reserveDecimals, ,) = params.reserveCache.reserveConfiguration.getParams();
(, , , vars.reserveDecimals, , ) = params.reserveCache.reserveConfiguration.getParams();

(
vars.isActive,
Expand Down Expand Up @@ -169,8 +169,7 @@ library ValidationLogic {

if (params.userEModeCategory != 0) {
require(
params.reserveCache.reserveConfiguration.getEModeCategory() ==
params.userEModeCategory,
params.reserveCache.reserveConfiguration.getEModeCategory() == params.userEModeCategory,
Errors.VL_INCONSISTENT_EMODE_CATEGORY
);
vars.eModePriceSource = eModeCategories[params.userEModeCategory].priceSource;
Expand Down Expand Up @@ -630,7 +629,7 @@ library ValidationLogic {
) internal view {
// category is invalid if the liq threshold is not set
require(
eModeCategories[categoryId].liquidationThreshold > 0,
categoryId == 0 || eModeCategories[categoryId].liquidationThreshold > 0,
Errors.VL_INCONSISTENT_EMODE_CATEGORY
);

Expand Down
8 changes: 4 additions & 4 deletions test-suites/reserve-configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ describe('ReserveConfiguration', async () => {
it('getEModeCategory()', async () => {
expect(await configMock.getParams()).to.be.eql([ZERO, ZERO, ZERO, ZERO, ZERO, ZERO]);
expect(await configMock.getEModeCategory()).to.be.eq(ZERO);
expect(await configMock.setDecimals(EMODE_CATEGORY));
expect(await configMock.setEModeCategory(EMODE_CATEGORY));
// eMode category is the 6th param
expect(await configMock.getParams()).to.be.eql([ZERO, ZERO, ZERO, ZERO, ZERO, EMODE_CATEGORY]);
expect(await configMock.getDecimals()).to.be.eq(EMODE_CATEGORY);
expect(await configMock.setDecimals(0));
expect(await configMock.getEModeCategory()).to.be.eq(EMODE_CATEGORY);
expect(await configMock.setEModeCategory(0));
expect(await configMock.getParams()).to.be.eql([ZERO, ZERO, ZERO, ZERO, ZERO, ZERO]);
expect(await configMock.getDecimals()).to.be.eq(ZERO);
expect(await configMock.getEModeCategory()).to.be.eq(ZERO);
});

it('getFrozen()', async () => {
Expand Down

0 comments on commit 750fd34

Please sign in to comment.