mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Merge branch 'fix/88-validations-configs' into 'master'
Fixes #88 Closes #88 See merge request aave-tech/protocol-v2!101
This commit is contained in:
commit
251bd591f5
|
@ -1,6 +1,8 @@
|
|||
// SPDX-License-Identifier: agpl-3.0
|
||||
pragma solidity ^0.6.8;
|
||||
|
||||
import {Errors} from '../helpers/Errors.sol';
|
||||
|
||||
/**
|
||||
* @title ReserveConfiguration library
|
||||
* @author Aave
|
||||
|
@ -27,6 +29,12 @@ library ReserveConfiguration {
|
|||
uint256 constant STABLE_BORROWING_ENABLED_START_BIT_POSITION = 59;
|
||||
uint256 constant RESERVE_FACTOR_START_BIT_POSITION = 64;
|
||||
|
||||
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;
|
||||
|
||||
struct Map {
|
||||
//bit 0-15: LTV
|
||||
//bit 16-31: Liq. threshold
|
||||
|
@ -47,6 +55,8 @@ library ReserveConfiguration {
|
|||
* @param ltv the new ltv
|
||||
**/
|
||||
function setLtv(ReserveConfiguration.Map memory self, uint256 ltv) internal pure {
|
||||
require(ltv <= MAX_VALID_LTV, Errors.INVALID_LTV);
|
||||
|
||||
self.data = (self.data & LTV_MASK) | ltv;
|
||||
}
|
||||
|
||||
|
@ -68,6 +78,8 @@ library ReserveConfiguration {
|
|||
internal
|
||||
pure
|
||||
{
|
||||
require(threshold <= MAX_VALID_LIQUIDATION_THRESHOLD, Errors.INVALID_LIQ_THRESHOLD);
|
||||
|
||||
self.data =
|
||||
(self.data & LIQUIDATION_THRESHOLD_MASK) |
|
||||
(threshold << LIQUIDATION_THRESHOLD_START_BIT_POSITION);
|
||||
|
@ -92,6 +104,8 @@ library ReserveConfiguration {
|
|||
* @param bonus the new liquidation bonus
|
||||
**/
|
||||
function setLiquidationBonus(ReserveConfiguration.Map memory self, uint256 bonus) internal pure {
|
||||
require(bonus <= MAX_VALID_LIQUIDATION_BONUS, Errors.INVALID_LIQ_BONUS);
|
||||
|
||||
self.data =
|
||||
(self.data & LIQUIDATION_BONUS_MASK) |
|
||||
(bonus << LIQUIDATION_BONUS_START_BIT_POSITION);
|
||||
|
@ -116,6 +130,8 @@ library ReserveConfiguration {
|
|||
* @param decimals the decimals
|
||||
**/
|
||||
function setDecimals(ReserveConfiguration.Map memory self, uint256 decimals) internal pure {
|
||||
require(decimals <= MAX_VALID_DECIMALS, Errors.INVALID_DECIMALS);
|
||||
|
||||
self.data = (self.data & DECIMALS_MASK) | (decimals << RESERVE_DECIMALS_START_BIT_POSITION);
|
||||
}
|
||||
|
||||
|
@ -225,6 +241,8 @@ library ReserveConfiguration {
|
|||
internal
|
||||
pure
|
||||
{
|
||||
require(reserveFactor <= MAX_VALID_RESERVE_FACTOR, Errors.INVALID_RESERVE_FACTOR);
|
||||
|
||||
self.data =
|
||||
(self.data & RESERVE_FACTOR_MASK) |
|
||||
(reserveFactor << RESERVE_FACTOR_START_BIT_POSITION);
|
||||
|
@ -316,8 +334,7 @@ library ReserveConfiguration {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* @dev gets the configuration flags of the reserve from a memory object
|
||||
* @param self the reserve configuration
|
||||
* @return the state flags representing active, freezed, borrowing enabled, stableRateBorrowing enabled
|
||||
|
|
|
@ -89,6 +89,15 @@ library Errors {
|
|||
|
||||
// pausable error message
|
||||
string public constant IS_PAUSED = '58'; // 'Pool is paused'
|
||||
|
||||
// Reserve configuration
|
||||
string public constant INVALID_LTV = '70';
|
||||
string public constant INVALID_LIQ_THRESHOLD = '71';
|
||||
string public constant INVALID_LIQ_BONUS = '72';
|
||||
string public constant INVALID_DECIMALS = '73';
|
||||
string public constant INVALID_RESERVE_FACTOR = '74';
|
||||
|
||||
|
||||
enum CollateralManagerErrors {
|
||||
NO_ERROR,
|
||||
NO_COLLATERAL_AVAILABLE,
|
||||
|
|
|
@ -117,6 +117,12 @@ export enum ProtocolErrors {
|
|||
|
||||
IS_PAUSED = '58', // Pool is paused
|
||||
|
||||
INVALID_LTV = '70',
|
||||
INVALID_LIQ_THRESHOLD = '71',
|
||||
INVALID_LIQ_BONUS = '72',
|
||||
INVALID_DECIMALS = '73',
|
||||
INVALID_RESERVE_FACTOR = '74',
|
||||
|
||||
// old
|
||||
|
||||
INVALID_FROM_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer',
|
||||
|
|
|
@ -10,7 +10,63 @@ const APPROVAL_AMOUNT_LENDING_POOL =
|
|||
const {expect} = require('chai');
|
||||
|
||||
makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||
const {CALLER_NOT_AAVE_ADMIN, RESERVE_LIQUIDITY_NOT_0} = ProtocolErrors;
|
||||
const {
|
||||
CALLER_NOT_AAVE_ADMIN,
|
||||
RESERVE_LIQUIDITY_NOT_0,
|
||||
INVALID_LTV,
|
||||
INVALID_LIQ_THRESHOLD,
|
||||
INVALID_LIQ_BONUS,
|
||||
INVALID_DECIMALS,
|
||||
INVALID_RESERVE_FACTOR,
|
||||
} = ProtocolErrors;
|
||||
|
||||
it('Reverts trying to set an invalid LTV', async () => {
|
||||
const {configurator, weth} = testEnv;
|
||||
|
||||
const invalidLtv = 65536;
|
||||
|
||||
await expect(configurator.setLtv(weth.address, invalidLtv)).to.be.revertedWith(INVALID_LTV);
|
||||
});
|
||||
|
||||
it('Reverts trying to set an invalid liquidation threshold', async () => {
|
||||
const {configurator, weth} = testEnv;
|
||||
|
||||
const invalidLiqThreshold = 65536;
|
||||
|
||||
await expect(
|
||||
configurator.setLiquidationThreshold(weth.address, invalidLiqThreshold)
|
||||
).to.be.revertedWith(INVALID_LIQ_THRESHOLD);
|
||||
});
|
||||
|
||||
it('Reverts trying to set an invalid liquidation bonus', async () => {
|
||||
const {configurator, weth} = testEnv;
|
||||
|
||||
const invalidLiqBonus = 65536;
|
||||
|
||||
await expect(
|
||||
configurator.setLiquidationBonus(weth.address, invalidLiqBonus)
|
||||
).to.be.revertedWith(INVALID_LIQ_BONUS);
|
||||
});
|
||||
|
||||
it('Reverts trying to set an invalid reserve decimals', async () => {
|
||||
const {configurator, weth} = testEnv;
|
||||
|
||||
const invalidDecimals = 256;
|
||||
|
||||
await expect(configurator.setReserveDecimals(weth.address, invalidDecimals)).to.be.revertedWith(
|
||||
INVALID_DECIMALS
|
||||
);
|
||||
});
|
||||
|
||||
it('Reverts trying to set an invalid reserve factor', async () => {
|
||||
const {configurator, weth} = testEnv;
|
||||
|
||||
const invalidReserveFactor = 65536;
|
||||
|
||||
await expect(
|
||||
configurator.setReserveFactor(weth.address, invalidReserveFactor)
|
||||
).to.be.revertedWith(INVALID_RESERVE_FACTOR);
|
||||
});
|
||||
|
||||
it('Deactivates the ETH reserve', async () => {
|
||||
const {configurator, weth, helpersContract} = testEnv;
|
||||
|
|
Loading…
Reference in New Issue
Block a user