2020-07-13 08:54:08 +00:00
|
|
|
import {TestEnv, makeSuite} from './helpers/make-suite';
|
2020-08-13 11:06:23 +00:00
|
|
|
import {RAY, APPROVAL_AMOUNT_LENDING_POOL} from '../helpers/constants';
|
2020-07-13 08:54:08 +00:00
|
|
|
import {convertToCurrencyDecimals} from '../helpers/contracts-helpers';
|
|
|
|
import {ProtocolErrors} from '../helpers/types';
|
|
|
|
|
|
|
|
const {expect} = require('chai');
|
|
|
|
|
|
|
|
makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
2020-09-16 12:09:42 +00:00
|
|
|
const {CALLER_NOT_AAVE_ADMIN, RESERVE_LIQUIDITY_NOT_0} = ProtocolErrors;
|
2020-06-12 08:39:42 +00:00
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
it('Deactivates the ETH reserve', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, pool, weth} = testEnv;
|
|
|
|
await configurator.deactivateReserve(weth.address);
|
|
|
|
const {isActive} = await pool.getReserveConfigurationData(weth.address);
|
2020-06-12 07:41:30 +00:00
|
|
|
expect(isActive).to.be.equal(false);
|
|
|
|
});
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
it('Rectivates the ETH reserve', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, pool, weth} = testEnv;
|
|
|
|
await configurator.activateReserve(weth.address);
|
2020-06-12 07:41:30 +00:00
|
|
|
|
2020-08-13 11:06:23 +00:00
|
|
|
const {isActive} = await pool.getReserveConfigurationData(weth.address);
|
2020-06-12 07:41:30 +00:00
|
|
|
expect(isActive).to.be.equal(true);
|
|
|
|
});
|
|
|
|
|
2020-09-16 12:09:42 +00:00
|
|
|
it('Check the onlyAaveAdmin on deactivateReserve ', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, users, weth} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await expect(
|
2020-08-13 11:06:23 +00:00
|
|
|
configurator.connect(users[2].signer).deactivateReserve(weth.address),
|
2020-09-16 12:09:42 +00:00
|
|
|
CALLER_NOT_AAVE_ADMIN
|
|
|
|
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-09-16 12:09:42 +00:00
|
|
|
it('Check the onlyAaveAdmin on activateReserve ', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, users, weth} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await expect(
|
2020-08-13 11:06:23 +00:00
|
|
|
configurator.connect(users[2].signer).activateReserve(weth.address),
|
2020-09-16 12:09:42 +00:00
|
|
|
CALLER_NOT_AAVE_ADMIN
|
|
|
|
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
it('Freezes the ETH reserve', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, pool, weth} = testEnv;
|
|
|
|
await configurator.freezeReserve(weth.address);
|
|
|
|
const {isFreezed} = await pool.getReserveConfigurationData(weth.address);
|
2020-06-12 07:41:30 +00:00
|
|
|
expect(isFreezed).to.be.equal(true);
|
|
|
|
});
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
it('Unfreezes the ETH reserve', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, pool, weth} = testEnv;
|
|
|
|
await configurator.unfreezeReserve(weth.address);
|
2020-06-12 07:41:30 +00:00
|
|
|
|
2020-08-13 11:06:23 +00:00
|
|
|
const {isFreezed} = await pool.getReserveConfigurationData(weth.address);
|
2020-06-12 07:41:30 +00:00
|
|
|
expect(isFreezed).to.be.equal(false);
|
|
|
|
});
|
|
|
|
|
2020-09-16 12:09:42 +00:00
|
|
|
it('Check the onlyAaveAdmin on freezeReserve ', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, users, weth} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await expect(
|
2020-08-13 11:06:23 +00:00
|
|
|
configurator.connect(users[2].signer).freezeReserve(weth.address),
|
2020-09-16 12:09:42 +00:00
|
|
|
CALLER_NOT_AAVE_ADMIN
|
|
|
|
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-09-16 12:09:42 +00:00
|
|
|
it('Check the onlyAaveAdmin on unfreezeReserve ', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, users, weth} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await expect(
|
2020-08-13 11:06:23 +00:00
|
|
|
configurator.connect(users[2].signer).unfreezeReserve(weth.address),
|
2020-09-16 12:09:42 +00:00
|
|
|
CALLER_NOT_AAVE_ADMIN
|
|
|
|
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
it('Deactivates the ETH reserve for borrowing', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, pool, weth} = testEnv;
|
|
|
|
await configurator.disableBorrowingOnReserve(weth.address);
|
|
|
|
const {borrowingEnabled} = await pool.getReserveConfigurationData(weth.address);
|
2020-06-27 02:13:32 +00:00
|
|
|
expect(borrowingEnabled).to.be.equal(false);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
it('Activates the ETH reserve for borrowing', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
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);
|
2020-06-27 02:13:32 +00:00
|
|
|
expect(borrowingEnabled).to.be.equal(true);
|
|
|
|
expect(variableBorrowIndex.toString()).to.be.equal(RAY);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-09-16 12:09:42 +00:00
|
|
|
it('Check the onlyAaveAdmin on disableBorrowingOnReserve ', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, users, weth} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await expect(
|
2020-08-13 11:06:23 +00:00
|
|
|
configurator.connect(users[2].signer).disableBorrowingOnReserve(weth.address),
|
2020-09-16 12:09:42 +00:00
|
|
|
CALLER_NOT_AAVE_ADMIN
|
|
|
|
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-09-16 12:09:42 +00:00
|
|
|
it('Check the onlyAaveAdmin on enableBorrowingOnReserve ', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, users, weth} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await expect(
|
2020-08-13 11:06:23 +00:00
|
|
|
configurator.connect(users[2].signer).enableBorrowingOnReserve(weth.address, true),
|
2020-09-16 12:09:42 +00:00
|
|
|
CALLER_NOT_AAVE_ADMIN
|
|
|
|
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
it('Deactivates the ETH reserve as collateral', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, pool, weth} = testEnv;
|
|
|
|
await configurator.disableReserveAsCollateral(weth.address);
|
|
|
|
const {usageAsCollateralEnabled} = await pool.getReserveConfigurationData(weth.address);
|
2020-06-27 02:13:32 +00:00
|
|
|
expect(usageAsCollateralEnabled).to.be.equal(false);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
it('Activates the ETH reserve as collateral', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, pool, weth} = testEnv;
|
|
|
|
await configurator.enableReserveAsCollateral(weth.address, '75', '80', '105');
|
2020-07-13 08:54:08 +00:00
|
|
|
|
2020-08-13 11:06:23 +00:00
|
|
|
const {usageAsCollateralEnabled} = await pool.getReserveConfigurationData(weth.address);
|
2020-06-27 02:13:32 +00:00
|
|
|
expect(usageAsCollateralEnabled).to.be.equal(true);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-09-16 12:09:42 +00:00
|
|
|
it('Check the onlyAaveAdmin on disableReserveAsCollateral ', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, users, weth} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await expect(
|
2020-08-13 11:06:23 +00:00
|
|
|
configurator.connect(users[2].signer).disableReserveAsCollateral(weth.address),
|
2020-09-16 12:09:42 +00:00
|
|
|
CALLER_NOT_AAVE_ADMIN
|
|
|
|
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-09-16 12:09:42 +00:00
|
|
|
it('Check the onlyAaveAdmin on enableReserveAsCollateral ', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, users, weth} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await expect(
|
|
|
|
configurator
|
|
|
|
.connect(users[2].signer)
|
2020-08-13 11:06:23 +00:00
|
|
|
.enableReserveAsCollateral(weth.address, '75', '80', '105'),
|
2020-09-16 12:09:42 +00:00
|
|
|
CALLER_NOT_AAVE_ADMIN
|
|
|
|
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
it('Disable stable borrow rate on the ETH reserve', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, pool, weth} = testEnv;
|
|
|
|
await configurator.disableReserveStableRate(weth.address);
|
|
|
|
const {stableBorrowRateEnabled} = await pool.getReserveConfigurationData(weth.address);
|
2020-06-27 02:13:32 +00:00
|
|
|
expect(stableBorrowRateEnabled).to.be.equal(false);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
it('Enables stable borrow rate on the ETH reserve', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, pool, weth} = testEnv;
|
|
|
|
await configurator.enableReserveStableRate(weth.address);
|
|
|
|
const {stableBorrowRateEnabled} = await pool.getReserveConfigurationData(weth.address);
|
2020-06-27 02:13:32 +00:00
|
|
|
expect(stableBorrowRateEnabled).to.be.equal(true);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-09-16 12:09:42 +00:00
|
|
|
it('Check the onlyAaveAdmin on disableReserveStableRate', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, users, weth} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await expect(
|
2020-08-13 11:06:23 +00:00
|
|
|
configurator.connect(users[2].signer).disableReserveStableRate(weth.address),
|
2020-09-16 12:09:42 +00:00
|
|
|
CALLER_NOT_AAVE_ADMIN
|
|
|
|
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-09-16 12:09:42 +00:00
|
|
|
it('Check the onlyAaveAdmin on enableReserveStableRate', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, users, weth} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await expect(
|
2020-08-13 11:06:23 +00:00
|
|
|
configurator.connect(users[2].signer).enableReserveStableRate(weth.address),
|
2020-09-16 12:09:42 +00:00
|
|
|
CALLER_NOT_AAVE_ADMIN
|
|
|
|
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
it('Changes LTV of the reserve', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, pool, weth} = testEnv;
|
|
|
|
await configurator.setLtv(weth.address, '60');
|
2020-08-19 12:23:41 +00:00
|
|
|
const {ltv} = await pool.getReserveConfigurationData(weth.address);
|
|
|
|
expect(ltv.toString()).to.be.bignumber.equal('60', 'Invalid LTV');
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-09-16 12:09:42 +00:00
|
|
|
it('Check the onlyAaveAdmin on setLtv', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, users, weth} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await expect(
|
2020-08-13 11:06:23 +00:00
|
|
|
configurator.connect(users[2].signer).setLtv(weth.address, '75'),
|
2020-09-16 12:09:42 +00:00
|
|
|
CALLER_NOT_AAVE_ADMIN
|
|
|
|
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-09-10 11:52:07 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Check the onlyLendingPoolManager on setReserveFactor', async () => {
|
|
|
|
const {configurator, users, weth} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator.connect(users[2].signer).setReserveFactor(weth.address, '2000'),
|
|
|
|
CALLER_NOT_LENDING_POOL_MANAGER
|
|
|
|
).to.be.revertedWith(CALLER_NOT_LENDING_POOL_MANAGER);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
it('Changes liquidation threshold of the reserve', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, pool, weth} = testEnv;
|
|
|
|
await configurator.setLiquidationThreshold(weth.address, '75');
|
2020-08-19 12:23:41 +00:00
|
|
|
const {liquidationThreshold} = await pool.getReserveConfigurationData(weth.address);
|
|
|
|
expect(liquidationThreshold.toString()).to.be.bignumber.equal(
|
|
|
|
'75',
|
|
|
|
'Invalid Liquidation threshold'
|
|
|
|
);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-09-16 12:09:42 +00:00
|
|
|
it('Check the onlyAaveAdmin on setLiquidationThreshold', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, users, weth} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await expect(
|
2020-08-13 11:06:23 +00:00
|
|
|
configurator.connect(users[2].signer).setLiquidationThreshold(weth.address, '80'),
|
2020-09-16 12:09:42 +00:00
|
|
|
CALLER_NOT_AAVE_ADMIN
|
|
|
|
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
it('Changes liquidation bonus of the reserve', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, pool, weth} = testEnv;
|
|
|
|
await configurator.setLiquidationBonus(weth.address, '110');
|
|
|
|
const {liquidationBonus} = await pool.getReserveConfigurationData(weth.address);
|
2020-08-19 12:23:41 +00:00
|
|
|
expect(liquidationBonus.toString()).to.be.bignumber.equal(
|
|
|
|
'110',
|
|
|
|
'Invalid Liquidation discount'
|
|
|
|
);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-09-16 12:09:42 +00:00
|
|
|
it('Check the onlyAaveAdmin on setLiquidationBonus', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, users, weth} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await expect(
|
2020-08-13 11:06:23 +00:00
|
|
|
configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'),
|
2020-09-16 12:09:42 +00:00
|
|
|
CALLER_NOT_AAVE_ADMIN
|
|
|
|
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-09-16 12:09:42 +00:00
|
|
|
it('Check the onlyAaveAdmin on setReserveDecimals', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, users, weth} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await expect(
|
2020-08-13 11:06:23 +00:00
|
|
|
configurator.connect(users[2].signer).setReserveDecimals(weth.address, '80'),
|
2020-09-16 12:09:42 +00:00
|
|
|
CALLER_NOT_AAVE_ADMIN
|
|
|
|
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-09-16 12:09:42 +00:00
|
|
|
it('Check the onlyAaveAdmin on setLiquidationBonus', async () => {
|
2020-08-13 11:06:23 +00:00
|
|
|
const {configurator, users, weth} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await expect(
|
2020-08-13 11:06:23 +00:00
|
|
|
configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'),
|
2020-09-16 12:09:42 +00:00
|
|
|
CALLER_NOT_AAVE_ADMIN
|
|
|
|
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
it('Reverts when trying to disable the DAI reserve with liquidity on it', async () => {
|
|
|
|
const {dai, pool, configurator} = testEnv;
|
2020-09-09 10:47:27 +00:00
|
|
|
const userAddress = await pool.signer.getAddress();
|
2020-07-13 08:54:08 +00:00
|
|
|
await dai.mint(await convertToCurrencyDecimals(dai.address, '1000'));
|
2020-06-12 07:41:30 +00:00
|
|
|
|
|
|
|
//approve protocol to access depositor wallet
|
2020-06-20 23:40:03 +00:00
|
|
|
await dai.approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL);
|
2020-07-13 08:54:08 +00:00
|
|
|
const amountDAItoDeposit = await convertToCurrencyDecimals(dai.address, '1000');
|
2020-06-12 07:41:30 +00:00
|
|
|
|
|
|
|
//user 1 deposits 1000 DAI
|
2020-09-09 10:47:27 +00:00
|
|
|
await pool.deposit(dai.address, amountDAItoDeposit, userAddress, '0');
|
2020-06-12 07:41:30 +00:00
|
|
|
|
|
|
|
await expect(
|
|
|
|
configurator.deactivateReserve(dai.address),
|
2020-09-02 15:54:34 +00:00
|
|
|
RESERVE_LIQUIDITY_NOT_0
|
|
|
|
).to.be.revertedWith(RESERVE_LIQUIDITY_NOT_0);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
});
|