aave-protocol-v2/test/configurator.spec.ts

545 lines
18 KiB
TypeScript
Raw Normal View History

2020-07-13 08:54:08 +00:00
import {TestEnv, makeSuite} from './helpers/make-suite';
import {RAY} from '../helpers/constants';
2020-07-13 08:54:08 +00:00
import {convertToCurrencyDecimals} from '../helpers/contracts-helpers';
import {ProtocolErrors} from '../helpers/types';
import {CommonsConfig} from '../config/commons';
const APPROVAL_AMOUNT_LENDING_POOL =
CommonsConfig.ProtocolGlobalParams.ApprovalAmountLendingPoolCore;
2020-07-13 08:54:08 +00:00
const {expect} = require('chai');
makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
const {
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN,
2020-10-30 12:40:06 +00:00
LPC_RESERVE_LIQUIDITY_NOT_0,
RC_INVALID_LTV,
RC_INVALID_LIQ_THRESHOLD,
RC_INVALID_LIQ_BONUS,
RC_INVALID_DECIMALS,
RC_INVALID_RESERVE_FACTOR,
} = ProtocolErrors;
it('Reverts trying to set an invalid LTV', async () => {
const {configurator, weth} = testEnv;
const invalidLtv = 65536;
2020-10-30 12:40:06 +00:00
await expect(configurator.setLtv(weth.address, invalidLtv)).to.be.revertedWith(RC_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)
2020-10-30 12:40:06 +00:00
).to.be.revertedWith(RC_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)
2020-10-30 12:40:06 +00:00
).to.be.revertedWith(RC_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(
2020-10-30 12:40:06 +00:00
RC_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)
2020-10-30 12:40:06 +00:00
).to.be.revertedWith(RC_INVALID_RESERVE_FACTOR);
});
2020-07-13 08:54:08 +00:00
it('Deactivates the ETH reserve', async () => {
2020-10-12 18:07:17 +00:00
const {configurator, weth, helpersContract} = testEnv;
await configurator.deactivateReserve(weth.address);
2020-10-12 18:07:17 +00:00
const {isActive} = await helpersContract.getReserveConfigurationData(weth.address);
expect(isActive).to.be.equal(false);
});
2020-07-13 08:54:08 +00:00
it('Rectivates the ETH reserve', async () => {
2020-10-12 18:07:17 +00:00
const {configurator, weth, helpersContract} = testEnv;
await configurator.activateReserve(weth.address);
2020-10-12 18:07:17 +00:00
const {isActive} = await helpersContract.getReserveConfigurationData(weth.address);
expect(isActive).to.be.equal(true);
});
2020-09-16 12:09:42 +00:00
it('Check the onlyAaveAdmin on deactivateReserve ', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).deactivateReserve(weth.address),
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
2020-09-16 12:09:42 +00:00
it('Check the onlyAaveAdmin on activateReserve ', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).activateReserve(weth.address),
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
2020-07-13 08:54:08 +00:00
it('Freezes the ETH reserve', async () => {
2020-10-12 18:07:17 +00:00
const {configurator, pool, weth, helpersContract} = testEnv;
await configurator.freezeReserve(weth.address);
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
2020-10-12 18:07:17 +00:00
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true);
2020-10-12 18:07:17 +00:00
expect(isFrozen).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);
2020-10-06 09:02:34 +00:00
expect(reserveFactor).to.be.equal(0);
});
2020-07-13 08:54:08 +00:00
it('Unfreezes the ETH reserve', async () => {
2020-10-12 18:07:17 +00:00
const {configurator, helpersContract, weth} = testEnv;
await configurator.unfreezeReserve(weth.address);
2020-10-06 09:02:34 +00:00
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
2020-10-12 18:07:17 +00:00
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
2020-10-06 09:02:34 +00:00
expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true);
2020-10-12 18:07:17 +00:00
expect(isFrozen).to.be.equal(false);
2020-10-06 09:02:34 +00:00
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);
});
2020-09-16 12:09:42 +00:00
it('Check the onlyAaveAdmin on freezeReserve ', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).freezeReserve(weth.address),
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
2020-09-16 12:09:42 +00:00
it('Check the onlyAaveAdmin on unfreezeReserve ', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).unfreezeReserve(weth.address),
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
2020-07-13 08:54:08 +00:00
it('Deactivates the ETH reserve for borrowing', async () => {
2020-10-12 18:07:17 +00:00
const {configurator, helpersContract, weth} = testEnv;
await configurator.disableBorrowingOnReserve(weth.address);
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
2020-10-12 18:07:17 +00:00
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
2020-06-27 02:13:32 +00:00
expect(borrowingEnabled).to.be.equal(false);
expect(isActive).to.be.equal(true);
2020-10-12 18:07:17 +00:00
expect(isFrozen).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);
});
2020-07-13 08:54:08 +00:00
it('Activates the ETH reserve for borrowing', async () => {
2020-10-12 18:07:17 +00:00
const {configurator, weth, helpersContract} = testEnv;
await configurator.enableBorrowingOnReserve(weth.address, true);
2020-10-12 18:07:17 +00:00
const {variableBorrowIndex} = await helpersContract.getReserveData(weth.address);
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
2020-10-12 18:07:17 +00:00
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
2020-06-27 02:13:32 +00:00
expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true);
2020-10-12 18:07:17 +00:00
expect(isFrozen).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);
2020-06-27 02:13:32 +00:00
expect(variableBorrowIndex.toString()).to.be.equal(RAY);
});
2020-09-16 12:09:42 +00:00
it('Check the onlyAaveAdmin on disableBorrowingOnReserve ', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).disableBorrowingOnReserve(weth.address),
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
2020-09-16 12:09:42 +00:00
it('Check the onlyAaveAdmin on enableBorrowingOnReserve ', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).enableBorrowingOnReserve(weth.address, true),
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
2020-07-13 08:54:08 +00:00
it('Deactivates the ETH reserve as collateral', async () => {
2020-10-12 18:07:17 +00:00
const {configurator, helpersContract, weth} = testEnv;
2020-09-28 17:33:39 +00:00
await configurator.configureReserveAsCollateral(weth.address, 0, 0, 0);
2020-10-06 09:20:45 +00:00
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
2020-10-12 18:07:17 +00:00
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
2020-07-13 08:54:08 +00:00
2020-10-06 09:20:45 +00:00
expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true);
2020-10-12 18:07:17 +00:00
expect(isFrozen).to.be.equal(false);
2020-10-06 09:20:45 +00:00
expect(decimals).to.be.equal(18);
expect(ltv).to.be.equal(0);
2020-10-30 14:12:11 +00:00
expect(liquidationThreshold).to.be.equal(0);
expect(liquidationBonus).to.be.equal(0);
2020-10-06 09:20:45 +00:00
expect(stableBorrowRateEnabled).to.be.equal(true);
expect(reserveFactor).to.be.equal(0);
});
2020-07-13 08:54:08 +00:00
it('Activates the ETH reserve as collateral', async () => {
2020-10-12 18:07:17 +00:00
const {configurator, helpersContract, weth} = testEnv;
2020-10-30 14:12:11 +00:00
await configurator.configureReserveAsCollateral(weth.address, '7500', '8000', '10500');
2020-07-13 08:54:08 +00:00
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
2020-10-12 18:07:17 +00:00
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true);
2020-10-12 18:07:17 +00:00
expect(isFrozen).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);
});
2020-10-31 11:42:14 +00:00
it('Check the onlyAaveAdmin on configureReserveAsCollateral ', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator
.connect(users[2].signer)
2020-10-31 11:42:14 +00:00
.configureReserveAsCollateral(weth.address, '7500', '8000', '10500'),
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
2020-07-13 08:54:08 +00:00
it('Disable stable borrow rate on the ETH reserve', async () => {
2020-10-12 18:07:17 +00:00
const {configurator, helpersContract, weth} = testEnv;
await configurator.disableReserveStableRate(weth.address);
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
2020-10-12 18:07:17 +00:00
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true);
2020-10-12 18:07:17 +00:00
expect(isFrozen).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);
2020-06-27 02:13:32 +00:00
expect(stableBorrowRateEnabled).to.be.equal(false);
expect(reserveFactor).to.be.equal(0);
});
2020-07-13 08:54:08 +00:00
it('Enables stable borrow rate on the ETH reserve', async () => {
2020-10-12 18:07:17 +00:00
const {configurator, helpersContract, weth} = testEnv;
await configurator.enableReserveStableRate(weth.address);
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
2020-10-12 18:07:17 +00:00
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true);
2020-10-12 18:07:17 +00:00
expect(isFrozen).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);
2020-06-27 02:13:32 +00:00
expect(stableBorrowRateEnabled).to.be.equal(true);
expect(reserveFactor).to.be.equal(0);
});
2020-09-16 12:09:42 +00:00
it('Check the onlyAaveAdmin on disableReserveStableRate', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).disableReserveStableRate(weth.address),
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
2020-09-16 12:09:42 +00:00
it('Check the onlyAaveAdmin on enableReserveStableRate', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).enableReserveStableRate(weth.address),
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
2020-07-13 08:54:08 +00:00
it('Changes LTV of the reserve', async () => {
2020-10-12 18:07:17 +00:00
const {configurator, helpersContract, weth} = testEnv;
await configurator.setLtv(weth.address, '6000');
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
2020-10-12 18:07:17 +00:00
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true);
2020-10-12 18:07:17 +00:00
expect(isFrozen).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);
});
2020-09-16 12:09:42 +00:00
it('Check the onlyAaveAdmin on setLtv', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setLtv(weth.address, '75'),
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
2020-09-10 11:52:07 +00:00
it('Changes the reserve factor of the reserve', async () => {
2020-10-12 18:07:17 +00:00
const {configurator, helpersContract, weth} = testEnv;
2020-09-10 11:52:07 +00:00
await configurator.setReserveFactor(weth.address, '1000');
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
2020-10-12 18:07:17 +00:00
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true);
2020-10-12 18:07:17 +00:00
expect(isFrozen).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);
2020-09-10 11:52:07 +00:00
});
it('Check the onlyLendingPoolManager on setReserveFactor', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setReserveFactor(weth.address, '2000'),
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
2020-09-10 11:52:07 +00:00
});
2020-07-13 08:54:08 +00:00
it('Changes liquidation threshold of the reserve', async () => {
2020-10-12 18:07:17 +00:00
const {configurator, helpersContract, weth} = testEnv;
await configurator.setLiquidationThreshold(weth.address, '7500');
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
2020-10-12 18:07:17 +00:00
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true);
2020-10-12 18:07:17 +00:00
expect(isFrozen).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);
});
2020-09-16 12:09:42 +00:00
it('Check the onlyAaveAdmin on setLiquidationThreshold', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setLiquidationThreshold(weth.address, '80'),
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
2020-07-13 08:54:08 +00:00
it('Changes liquidation bonus of the reserve', async () => {
2020-10-12 18:07:17 +00:00
const {configurator, helpersContract, weth} = testEnv;
2020-10-06 09:36:29 +00:00
await configurator.setLiquidationBonus(weth.address, '11000');
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
2020-10-12 18:07:17 +00:00
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
2020-10-06 09:36:29 +00:00
expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true);
2020-10-12 18:07:17 +00:00
expect(isFrozen).to.be.equal(false);
2020-10-06 09:36:29 +00:00
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);
});
2020-09-16 12:09:42 +00:00
it('Check the onlyAaveAdmin on setLiquidationBonus', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'),
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
2020-09-16 12:09:42 +00:00
it('Check the onlyAaveAdmin on setReserveDecimals', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setReserveDecimals(weth.address, '80'),
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
2020-09-16 12:09:42 +00:00
it('Check the onlyAaveAdmin on setLiquidationBonus', async () => {
const {configurator, users, weth} = testEnv;
await expect(
configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'),
2020-11-05 11:35:50 +00:00
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(CALLER_NOT_POOL_ADMIN);
});
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'));
//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');
//user 1 deposits 1000 DAI
2020-09-09 10:47:27 +00:00
await pool.deposit(dai.address, amountDAItoDeposit, userAddress, '0');
await expect(
configurator.deactivateReserve(dai.address),
LPC_RESERVE_LIQUIDITY_NOT_0
).to.be.revertedWith(LPC_RESERVE_LIQUIDITY_NOT_0);
});
});