2020-06-12 07:41:30 +00:00
|
|
|
import {TestEnv, makeSuite} from "./helpers/make-suite";
|
|
|
|
import {
|
|
|
|
MOCK_ETH_ADDRESS,
|
|
|
|
RAY,
|
2020-06-20 23:40:03 +00:00
|
|
|
APPROVAL_AMOUNT_LENDING_POOL,
|
2020-06-12 07:41:30 +00:00
|
|
|
} from "../helpers/constants";
|
|
|
|
import {convertToCurrencyDecimals} from "../helpers/contracts-helpers";
|
2020-06-12 08:39:42 +00:00
|
|
|
import {ProtocolErrors} from "../helpers/types";
|
2020-06-12 07:41:30 +00:00
|
|
|
|
|
|
|
const {expect} = require("chai");
|
|
|
|
|
2020-06-12 08:39:42 +00:00
|
|
|
makeSuite("LendingPoolConfigurator", (testEnv: TestEnv) => {
|
|
|
|
const {INVALID_POOL_MANAGER_CALLER_MSG} = ProtocolErrors;
|
|
|
|
|
2020-06-12 07:41:30 +00:00
|
|
|
it("Deactivates the ETH reserve", async () => {
|
2020-06-20 23:40:03 +00:00
|
|
|
const {configurator, pool} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await configurator.deactivateReserve(MOCK_ETH_ADDRESS);
|
2020-06-27 02:13:32 +00:00
|
|
|
const {isActive} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS);
|
2020-06-12 07:41:30 +00:00
|
|
|
expect(isActive).to.be.equal(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Rectivates the ETH reserve", async () => {
|
2020-06-20 23:40:03 +00:00
|
|
|
const {configurator, pool} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await configurator.activateReserve(MOCK_ETH_ADDRESS);
|
|
|
|
|
2020-06-27 02:13:32 +00:00
|
|
|
const {isActive} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS);
|
2020-06-12 07:41:30 +00:00
|
|
|
expect(isActive).to.be.equal(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Check the onlyLendingPoolManager on deactivateReserve ", async () => {
|
|
|
|
const {configurator, users} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator.connect(users[2].signer).deactivateReserve(MOCK_ETH_ADDRESS),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_POOL_MANAGER_CALLER_MSG
|
|
|
|
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Check the onlyLendingPoolManager on activateReserve ", async () => {
|
|
|
|
const {configurator, users} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator.connect(users[2].signer).activateReserve(MOCK_ETH_ADDRESS),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_POOL_MANAGER_CALLER_MSG
|
|
|
|
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Freezes the ETH reserve", async () => {
|
2020-06-20 23:40:03 +00:00
|
|
|
const {configurator, pool} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await configurator.freezeReserve(MOCK_ETH_ADDRESS);
|
2020-06-27 02:13:32 +00:00
|
|
|
const {isFreezed} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS);
|
2020-06-12 07:41:30 +00:00
|
|
|
expect(isFreezed).to.be.equal(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Unfreezes the ETH reserve", async () => {
|
2020-06-20 23:40:03 +00:00
|
|
|
const {configurator, pool} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await configurator.unfreezeReserve(MOCK_ETH_ADDRESS);
|
|
|
|
|
2020-06-27 02:13:32 +00:00
|
|
|
const {isFreezed} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS);
|
2020-06-12 07:41:30 +00:00
|
|
|
expect(isFreezed).to.be.equal(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Check the onlyLendingPoolManager on freezeReserve ", async () => {
|
|
|
|
const {configurator, users} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator.connect(users[2].signer).freezeReserve(MOCK_ETH_ADDRESS),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_POOL_MANAGER_CALLER_MSG
|
|
|
|
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Check the onlyLendingPoolManager on unfreezeReserve ", async () => {
|
|
|
|
const {configurator, users} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator.connect(users[2].signer).unfreezeReserve(MOCK_ETH_ADDRESS),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_POOL_MANAGER_CALLER_MSG
|
|
|
|
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Deactivates the ETH reserve for borrowing", async () => {
|
2020-06-20 23:40:03 +00:00
|
|
|
const {configurator, pool} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await configurator.disableBorrowingOnReserve(MOCK_ETH_ADDRESS);
|
2020-06-27 02:13:32 +00:00
|
|
|
const {borrowingEnabled} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS);
|
|
|
|
expect(borrowingEnabled).to.be.equal(false);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Activates the ETH reserve for borrowing", async () => {
|
2020-06-20 23:40:03 +00:00
|
|
|
const {configurator, pool} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await configurator.enableBorrowingOnReserve(MOCK_ETH_ADDRESS, true);
|
2020-06-27 02:13:32 +00:00
|
|
|
const {borrowingEnabled} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS);
|
|
|
|
const {variableBorrowIndex} = await pool.getReserveData(
|
2020-06-12 07:41:30 +00:00
|
|
|
MOCK_ETH_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
|
|
|
});
|
|
|
|
|
|
|
|
it("Check the onlyLendingPoolManager on disableBorrowingOnReserve ", async () => {
|
|
|
|
const {configurator, users} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator
|
|
|
|
.connect(users[2].signer)
|
|
|
|
.disableBorrowingOnReserve(MOCK_ETH_ADDRESS),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_POOL_MANAGER_CALLER_MSG
|
|
|
|
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Check the onlyLendingPoolManager on enableBorrowingOnReserve ", async () => {
|
|
|
|
const {configurator, users} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator
|
|
|
|
.connect(users[2].signer)
|
|
|
|
.enableBorrowingOnReserve(MOCK_ETH_ADDRESS, true),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_POOL_MANAGER_CALLER_MSG
|
|
|
|
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Deactivates the ETH reserve as collateral", async () => {
|
2020-06-20 23:40:03 +00:00
|
|
|
const {configurator, pool} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await configurator.disableReserveAsCollateral(MOCK_ETH_ADDRESS);
|
2020-06-27 02:13:32 +00:00
|
|
|
const {usageAsCollateralEnabled} = await pool.getReserveConfigurationData(
|
2020-06-12 07:41:30 +00:00
|
|
|
MOCK_ETH_ADDRESS
|
|
|
|
);
|
2020-06-27 02:13:32 +00:00
|
|
|
expect(usageAsCollateralEnabled).to.be.equal(false);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Activates the ETH reserve as collateral", async () => {
|
2020-06-20 23:40:03 +00:00
|
|
|
const {configurator, pool} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await configurator.enableReserveAsCollateral(
|
|
|
|
MOCK_ETH_ADDRESS,
|
|
|
|
"75",
|
|
|
|
"80",
|
|
|
|
"105"
|
|
|
|
);
|
|
|
|
|
2020-06-27 02:13:32 +00:00
|
|
|
const {usageAsCollateralEnabled} = await pool.getReserveConfigurationData(
|
2020-06-12 07:41:30 +00:00
|
|
|
MOCK_ETH_ADDRESS
|
|
|
|
);
|
2020-06-27 02:13:32 +00:00
|
|
|
expect(usageAsCollateralEnabled).to.be.equal(true);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Check the onlyLendingPoolManager on disableReserveAsCollateral ", async () => {
|
|
|
|
const {configurator, users} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator
|
|
|
|
.connect(users[2].signer)
|
|
|
|
.disableReserveAsCollateral(MOCK_ETH_ADDRESS),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_POOL_MANAGER_CALLER_MSG
|
|
|
|
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Check the onlyLendingPoolManager on enableReserveAsCollateral ", async () => {
|
|
|
|
const {configurator, users} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator
|
|
|
|
.connect(users[2].signer)
|
|
|
|
.enableReserveAsCollateral(MOCK_ETH_ADDRESS, "75", "80", "105"),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_POOL_MANAGER_CALLER_MSG
|
|
|
|
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Disable stable borrow rate on the ETH reserve", async () => {
|
2020-06-20 23:40:03 +00:00
|
|
|
const {configurator, pool} = testEnv;
|
2020-06-27 02:13:32 +00:00
|
|
|
await configurator.disableReserveStableRate(MOCK_ETH_ADDRESS);
|
|
|
|
const {stableBorrowRateEnabled} = await pool.getReserveConfigurationData(
|
2020-06-12 07:41:30 +00:00
|
|
|
MOCK_ETH_ADDRESS
|
|
|
|
);
|
2020-06-27 02:13:32 +00:00
|
|
|
expect(stableBorrowRateEnabled).to.be.equal(false);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Enables stable borrow rate on the ETH reserve", async () => {
|
2020-06-20 23:40:03 +00:00
|
|
|
const {configurator, pool} = testEnv;
|
2020-06-27 02:13:32 +00:00
|
|
|
await configurator.enableReserveStableRate(MOCK_ETH_ADDRESS);
|
|
|
|
const {stableBorrowRateEnabled} = await pool.getReserveConfigurationData(
|
2020-06-12 07:41:30 +00:00
|
|
|
MOCK_ETH_ADDRESS
|
|
|
|
);
|
2020-06-27 02:13:32 +00:00
|
|
|
expect(stableBorrowRateEnabled).to.be.equal(true);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-06-27 02:13:32 +00:00
|
|
|
it("Check the onlyLendingPoolManager on disableReserveStableRate", async () => {
|
2020-06-12 07:41:30 +00:00
|
|
|
const {configurator, users} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator
|
|
|
|
.connect(users[2].signer)
|
2020-06-27 02:13:32 +00:00
|
|
|
.disableReserveStableRate(MOCK_ETH_ADDRESS),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_POOL_MANAGER_CALLER_MSG
|
|
|
|
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
2020-06-27 02:13:32 +00:00
|
|
|
it("Check the onlyLendingPoolManager on enableReserveStableRate", async () => {
|
2020-06-12 07:41:30 +00:00
|
|
|
const {configurator, users} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator
|
|
|
|
.connect(users[2].signer)
|
2020-06-27 02:13:32 +00:00
|
|
|
.enableReserveStableRate(MOCK_ETH_ADDRESS),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_POOL_MANAGER_CALLER_MSG
|
|
|
|
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Changes LTV of the reserve", async () => {
|
|
|
|
const {configurator, pool} = testEnv;
|
|
|
|
await configurator.setReserveBaseLTVasCollateral(MOCK_ETH_ADDRESS, "60");
|
|
|
|
const {ltv}: any = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS);
|
|
|
|
expect(ltv).to.be.bignumber.equal("60", "Invalid LTV");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Check the onlyLendingPoolManager on setReserveBaseLTVasCollateral", async () => {
|
|
|
|
const {configurator, users} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator
|
|
|
|
.connect(users[2].signer)
|
|
|
|
.setReserveBaseLTVasCollateral(MOCK_ETH_ADDRESS, "75"),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_POOL_MANAGER_CALLER_MSG
|
|
|
|
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Changes liquidation threshold of the reserve", async () => {
|
|
|
|
const {configurator, pool} = testEnv;
|
|
|
|
await configurator.setReserveLiquidationThreshold(MOCK_ETH_ADDRESS, "75");
|
|
|
|
const {liquidationThreshold}: any = await pool.getReserveConfigurationData(
|
|
|
|
MOCK_ETH_ADDRESS
|
|
|
|
);
|
|
|
|
expect(liquidationThreshold).to.be.bignumber.equal(
|
|
|
|
"75",
|
|
|
|
"Invalid Liquidation threshold"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Check the onlyLendingPoolManager on setReserveLiquidationThreshold", async () => {
|
|
|
|
const {configurator, users} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator
|
|
|
|
.connect(users[2].signer)
|
|
|
|
.setReserveLiquidationThreshold(MOCK_ETH_ADDRESS, "80"),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_POOL_MANAGER_CALLER_MSG
|
|
|
|
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Changes liquidation bonus of the reserve", async () => {
|
2020-06-20 23:40:03 +00:00
|
|
|
const {configurator, pool} = testEnv;
|
2020-06-12 07:41:30 +00:00
|
|
|
await configurator.setReserveLiquidationBonus(MOCK_ETH_ADDRESS, "110");
|
2020-06-27 02:13:32 +00:00
|
|
|
const {liquidationBonus} = await pool.getReserveConfigurationData(
|
2020-06-12 07:41:30 +00:00
|
|
|
MOCK_ETH_ADDRESS
|
|
|
|
);
|
|
|
|
expect(liquidationBonus).to.be.bignumber.equal(
|
|
|
|
"110",
|
|
|
|
"Invalid Liquidation discount"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Check the onlyLendingPoolManager on setReserveLiquidationBonus", async () => {
|
|
|
|
const {configurator, users} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator
|
|
|
|
.connect(users[2].signer)
|
|
|
|
.setReserveLiquidationBonus(MOCK_ETH_ADDRESS, "80"),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_POOL_MANAGER_CALLER_MSG
|
|
|
|
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Check the onlyLendingPoolManager on setReserveDecimals", async () => {
|
|
|
|
const {configurator, users} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator
|
|
|
|
.connect(users[2].signer)
|
|
|
|
.setReserveDecimals(MOCK_ETH_ADDRESS, "80"),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_POOL_MANAGER_CALLER_MSG
|
|
|
|
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Check the onlyLendingPoolManager on setReserveLiquidationBonus", async () => {
|
|
|
|
const {configurator, users} = testEnv;
|
|
|
|
await expect(
|
|
|
|
configurator
|
|
|
|
.connect(users[2].signer)
|
|
|
|
.setReserveLiquidationBonus(MOCK_ETH_ADDRESS, "80"),
|
2020-06-12 08:39:42 +00:00
|
|
|
INVALID_POOL_MANAGER_CALLER_MSG
|
|
|
|
).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG);
|
2020-06-12 07:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Reverts when trying to disable the DAI reserve with liquidity on it", async () => {
|
2020-06-20 23:40:03 +00:00
|
|
|
const {dai, pool, configurator} = testEnv;
|
2020-06-12 07:41:30 +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-06-12 07:41:30 +00:00
|
|
|
const amountDAItoDeposit = await convertToCurrencyDecimals(
|
|
|
|
dai.address,
|
|
|
|
"1000"
|
|
|
|
);
|
|
|
|
|
|
|
|
//user 1 deposits 1000 DAI
|
|
|
|
await pool.deposit(dai.address, amountDAItoDeposit, "0");
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
configurator.deactivateReserve(dai.address),
|
|
|
|
"The liquidity of the reserve needs to be 0"
|
|
|
|
).to.be.revertedWith("The liquidity of the reserve needs to be 0");
|
|
|
|
});
|
|
|
|
});
|