tests: updated tests for the ltv validation

This commit is contained in:
The3D 2021-07-06 18:51:08 +02:00
parent 7f3bf12d23
commit c1db1f8953
6 changed files with 138 additions and 404 deletions

View File

@ -113,7 +113,7 @@ library GenericLogic {
vars.totalCollateralInETH = vars.totalCollateralInETH.add(vars.userBalanceETH);
vars.avgLtv = vars.avgLtv.add(vars.userBalanceETH.mul(vars.ltv));
vars.hasZeroLtvCollateral = vars.ltv == 0;
vars.hasZeroLtvCollateral = vars.hasZeroLtvCollateral || vars.ltv == 0;
vars.avgLiquidationThreshold = vars.avgLiquidationThreshold.add(
vars.userBalanceETH.mul(vars.liquidationThreshold)
);

View File

@ -21,7 +21,7 @@ import {IAToken} from '../../../interfaces/IAToken.sol';
import {DataTypes} from '../types/DataTypes.sol';
import {IPriceOracleGetter} from '../../../interfaces/IPriceOracleGetter.sol';
import {Address} from '../../../dependencies/openzeppelin/contracts/Address.sol';
import "hardhat/console.sol";
/**
* @title ReserveLogic library
* @author Aave
@ -552,6 +552,9 @@ library ValidationLogic {
vars.assetLtv = reserve.configuration.getLtvMemory();
console.log("asset ltv is ", vars.assetLtv);
console.log("has 0 ltv collateral ", vars.hasZeroLtvCollateral);
require(vars.assetLtv == 0 || !vars.hasZeroLtvCollateral, Errors.VL_LTV_VALIDATION_FAILED);
}

View File

@ -189,7 +189,7 @@ export enum ProtocolErrors {
RL_VARIABLE_DEBT_SUPPLY_NOT_ZERO = '90',
LP_CALLER_NOT_EOA = '91',
RC_INVALID_EXPOSURE_CAP = '92',
VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED = '93',
VL_LTV_VALIDATION_FAILED = '93',
VL_SAME_BLOCK_BORROW_REPAY = '94',
LPC_FLASHLOAN_PREMIUMS_MISMATCH = '95',
LPC_FLASHLOAN_PREMIUM_INVALID = '96',

View File

@ -229,7 +229,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -246,7 +246,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Unpauses the ETH reserve by pool admin ', async () => {
@ -264,7 +263,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -281,7 +280,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Pauses the ETH reserve by emergency admin', async () => {
const { configurator, weth, helpersContract, addressesProvider, users, emergencyAdmin } =
@ -298,7 +296,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -315,7 +313,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Unpauses the ETH reserve by emergency admin ', async () => {
@ -333,7 +330,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -350,7 +347,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Check the only admin or emergency admin can pauseReserve ', async () => {
@ -384,7 +380,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -401,7 +397,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Unfreezes the ETH reserve by Pool admin', async () => {
@ -419,7 +414,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -436,8 +431,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Freezes the ETH reserve by Risk Admin', async () => {
const { configurator, weth, helpersContract, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).freezeReserve(weth.address);
@ -452,7 +447,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -469,7 +464,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Unfreezes the ETH reserve by Risk admin', async () => {
@ -487,7 +481,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -504,7 +498,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Check the onlyRiskOrPoolAdmins on freezeReserve ', async () => {
@ -537,7 +530,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -554,7 +547,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Activates the ETH reserve for borrowing via pool admin', async () => {
@ -573,7 +565,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -590,7 +582,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
expect(variableBorrowIndex.toString()).to.be.equal(RAY);
});
@ -609,7 +600,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -626,7 +617,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Activates the ETH reserve for borrowing via risk admin', async () => {
@ -645,7 +635,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -662,7 +652,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
expect(variableBorrowIndex.toString()).to.be.equal(RAY);
});
@ -701,7 +690,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -718,7 +707,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Activates the ETH reserve as collateral via pool admin', async () => {
@ -736,7 +724,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -753,8 +741,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Deactivates the ETH reserve as collateral via risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator
@ -772,7 +760,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -789,7 +777,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Activates the ETH reserve as collateral via risk admin', async () => {
@ -809,7 +796,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -826,7 +813,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Check the onlyRiskOrPoolAdmin on configureReserveAsCollateral ', async () => {
@ -853,7 +839,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -870,7 +856,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Enables stable borrow rate on the ETH reserve via pool admin', async () => {
@ -887,7 +872,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -904,8 +889,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Disable stable borrow rate on the ETH reserve risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).disableReserveStableRate(weth.address);
@ -920,7 +905,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -937,7 +922,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Enables stable borrow rate on the ETH reserve risk admin', async () => {
@ -954,7 +938,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -971,7 +955,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Check the onlyRiskOrPoolAdmin on disableReserveStableRate', async () => {
@ -1012,13 +995,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_RISK_OR_POOL_ADMIN);
});
it('Check the onlyRiskOrPoolAdmin on setExposureCap', async () => {
const { configurator, users, weth, emergencyAdmin } = testEnv;
await expect(
configurator.connect(emergencyAdmin.signer).setExposureCap(weth.address, '3000000000'),
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_RISK_OR_POOL_ADMIN);
});
it('Changes the reserve factor of WETH via pool admin', async () => {
const { configurator, helpersContract, weth } = testEnv;
@ -1034,7 +1010,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -1050,7 +1026,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(stableBorrowRateEnabled).to.be.equal(strategyWETH.stableBorrowRateEnabled);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
expect(reserveFactor).to.be.equal(1000);
});
it('Changes the reserve factor of WETH risk admin', async () => {
@ -1067,7 +1042,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -1083,9 +1058,9 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(stableBorrowRateEnabled).to.be.equal(strategyWETH.stableBorrowRateEnabled);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
expect(reserveFactor).to.be.equal(1000);
});
it('Changes the reserve factor of WETH risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).setReserveFactor(weth.address, '1000');
@ -1146,7 +1121,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -1163,8 +1138,9 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).to.be.equal('3000000');
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Changes the borrow Cap of WETH risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).setBorrowCap(weth.address, '3000000');
@ -1179,7 +1155,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -1196,7 +1172,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).to.be.equal('3000000');
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Changes the supply Cap of WETH via pool admin', async () => {
@ -1213,7 +1188,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -1230,8 +1205,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).to.be.equal('3000000');
expect(supplyCap).to.be.equal('3000000');
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Changes the supply Cap of WETH via risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).setSupplyCap(weth.address, '3000000');
@ -1246,7 +1221,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -1263,74 +1238,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).to.be.equal('3000000');
expect(supplyCap).to.be.equal('3000000');
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Changes the exposure Cap of WETH via pool admin', async () => {
const { configurator, helpersContract, weth } = testEnv;
await configurator.setExposureCap(weth.address, '3000000');
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true);
expect(isPaused).to.be.equal(false);
expect(isFrozen).to.be.equal(false);
expect(decimals).to.be.equal(strategyWETH.reserveDecimals);
expect(ltv).to.be.equal(strategyWETH.baseLTVAsCollateral);
expect(liquidationThreshold).to.be.equal(strategyWETH.liquidationThreshold);
expect(liquidationBonus).to.be.equal(strategyWETH.liquidationBonus);
expect(stableBorrowRateEnabled).to.be.equal(strategyWETH.stableBorrowRateEnabled);
expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).to.be.equal('3000000');
expect(supplyCap).to.be.equal('3000000');
expect(exposureCap).to.be.equal('3000000');
});
it('Changes the exposure Cap of WETH via risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).setExposureCap(weth.address, '3000000');
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true);
expect(isPaused).to.be.equal(false);
expect(isFrozen).to.be.equal(false);
expect(decimals).to.be.equal(strategyWETH.reserveDecimals);
expect(ltv).to.be.equal(strategyWETH.baseLTVAsCollateral);
expect(liquidationThreshold).to.be.equal(strategyWETH.liquidationThreshold);
expect(liquidationBonus).to.be.equal(strategyWETH.liquidationBonus);
expect(stableBorrowRateEnabled).to.be.equal(strategyWETH.stableBorrowRateEnabled);
expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).to.be.equal('3000000');
expect(supplyCap).to.be.equal('3000000');
expect(exposureCap).to.be.equal('3000000');
});
it('Changes the supply Cap of WETH via risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).setSupplyCap(weth.address, '3000000');

View File

@ -1,276 +0,0 @@
import { TestEnv, makeSuite } from './helpers/make-suite';
import {
APPROVAL_AMOUNT_LENDING_POOL,
MAX_UINT_AMOUNT,
RAY,
MAX_EXPOSURE_CAP,
MOCK_CHAINLINK_AGGREGATORS_PRICES,
} from '../../helpers/constants';
import { ProtocolErrors } from '../../helpers/types';
import { MintableERC20, WETH9, WETH9Mocked } from '../../types';
import { parseEther } from '@ethersproject/units';
import { BigNumber } from '@ethersproject/bignumber';
import { strategyDAI } from '../../markets/amm/reservesConfigs';
import { strategyUSDC } from '../../markets/amm/reservesConfigs';
import { ethers } from 'ethers';
const { expect } = require('chai');
makeSuite('Exposure Cap', (testEnv: TestEnv) => {
const {
VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED,
RC_INVALID_EXPOSURE_CAP,
VL_COLLATERAL_CANNOT_COVER_NEW_BORROW,
} = ProtocolErrors;
const daiPrice = Number(MOCK_CHAINLINK_AGGREGATORS_PRICES.DAI);
const usdcPrice = Number(MOCK_CHAINLINK_AGGREGATORS_PRICES.USDC);
const daiLTV = Number(strategyDAI.baseLTVAsCollateral);
const usdcLTV = Number(strategyUSDC.baseLTVAsCollateral);
const unitParse = async (token: WETH9Mocked | MintableERC20, nb: string) =>
BigNumber.from(nb).mul(BigNumber.from('10').pow((await token.decimals()) - 3));
it('Reserves should initially have exposure cap disabled (exposureCap = 0)', async () => {
const {
weth,
pool,
dai,
usdc,
deployer,
helpersContract,
users: [user1],
} = testEnv;
const mintedAmount = parseEther('1000000000');
// minting for main user
await dai.mint(mintedAmount);
await weth.mint(mintedAmount);
await usdc.mint(mintedAmount);
// minting for lp user
await dai.connect(user1.signer).mint(mintedAmount);
await weth.connect(user1.signer).mint(mintedAmount);
await usdc.connect(user1.signer).mint(mintedAmount);
await dai.approve(pool.address, MAX_UINT_AMOUNT);
await weth.approve(pool.address, MAX_UINT_AMOUNT);
await usdc.approve(pool.address, MAX_UINT_AMOUNT);
await dai.connect(user1.signer).approve(pool.address, MAX_UINT_AMOUNT);
await weth.connect(user1.signer).approve(pool.address, MAX_UINT_AMOUNT);
await usdc.connect(user1.signer).approve(pool.address, MAX_UINT_AMOUNT);
await pool.deposit(weth.address, mintedAmount, deployer.address, 0);
let usdcExposureCap = (await helpersContract.getReserveCaps(usdc.address)).exposureCap;
let daiExposureCap = (await helpersContract.getReserveCaps(dai.address)).exposureCap;
expect(usdcExposureCap).to.be.equal('0');
expect(daiExposureCap).to.be.equal('0');
});
it('Deposit 10 Dai, 10 USDC, LTV for both should increase', async () => {
const {
pool,
dai,
usdc,
users: [user1],
} = testEnv;
const suppliedAmount = 10;
const precisionSuppliedAmount = (suppliedAmount * 1000).toString();
// user 1 deposit more dai and usdc to be able to borrow
let { ltv } = await pool.getUserAccountData(user1.address);
expect(ltv.toString()).to.be.equal('0');
await pool
.connect(user1.signer)
.deposit(dai.address, await unitParse(dai, precisionSuppliedAmount), user1.address, 0);
ltv = (await pool.getUserAccountData(user1.address)).ltv;
expect(ltv).to.be.equal(daiLTV);
await pool
.connect(user1.signer)
.deposit(usdc.address, await unitParse(usdc, precisionSuppliedAmount), user1.address, 0);
ltv = (await pool.getUserAccountData(user1.address)).ltv;
expect(Number(ltv)).to.be.equal(
Math.floor((daiLTV * daiPrice + usdcLTV * usdcPrice) / (daiPrice + usdcPrice))
);
});
it('Sets the exposure cap for DAI to 10 Units', async () => {
const {
configurator,
dai,
helpersContract,
users: [],
} = testEnv;
const newExposureCap = 10;
await configurator.setExposureCap(dai.address, newExposureCap);
const daiExposureCap = (await helpersContract.getReserveCaps(dai.address)).exposureCap;
expect(daiExposureCap).to.be.equal(newExposureCap);
});
it('should succeed to deposit 10 dai but dai ltv drops to 0', async () => {
const {
pool,
dai,
users: [user1],
} = testEnv;
const suppliedAmount = 10;
const precisionSuppliedAmount = (suppliedAmount * 1000).toString();
await pool
.connect(user1.signer)
.deposit(dai.address, await unitParse(dai, precisionSuppliedAmount), user1.address, 0);
let ltv = (await pool.getUserAccountData(user1.address)).ltv;
expect(ltv).to.be.equal(Math.floor((usdcLTV * usdcPrice) / (usdcPrice + 2 * daiPrice)));
});
it('should succeed to deposit 1 dai but avg ltv decreases', async () => {
const {
pool,
dai,
users: [user1],
} = testEnv;
const suppliedAmount = 1;
const precisionSuppliedAmount = (suppliedAmount * 1000).toString();
let ltv = (await pool.getUserAccountData(user1.address)).ltv;
await pool
.connect(user1.signer)
.deposit(dai.address, await unitParse(dai, precisionSuppliedAmount), user1.address, 0);
expect(ltv.toNumber()).to.be.gt((await pool.getUserAccountData(user1.address)).ltv.toNumber());
});
it('should succeed to deposit 1 usdc and ltv should increase', async () => {
const {
usdc,
pool,
users: [user1],
} = testEnv;
const suppliedAmount = 1;
const precisionSuppliedAmount = (suppliedAmount * 1000).toString();
let ltv = (await pool.getUserAccountData(user1.address)).ltv;
await pool
.connect(user1.signer)
.deposit(usdc.address, await unitParse(usdc, precisionSuppliedAmount), user1.address, 0);
expect(ltv.toNumber()).to.be.lt((await pool.getUserAccountData(user1.address)).ltv.toNumber());
});
it('Should not be able to borrow 15 USD of weth', async () => {
const {
pool,
weth,
users: [user1],
} = testEnv;
const precisionBorrowedUsdAmount = 15 * 1000;
const precisionBorrowedEthAmount = ethers.BigNumber.from(precisionBorrowedUsdAmount)
.mul(daiPrice)
.div(parseEther('1.0'))
.toString();
const borrowedAmount = await unitParse(weth, precisionBorrowedEthAmount);
await expect(
pool.connect(user1.signer).borrow(weth.address, borrowedAmount, 1, 0, user1.address)
).to.be.revertedWith(VL_COLLATERAL_CANNOT_COVER_NEW_BORROW);
});
it('should be able to borrow 15 USD of weth after dai exposure cap raised to 100', async () => {
const {
pool,
dai,
weth,
configurator,
helpersContract,
users: [user1],
} = testEnv;
const newExposureCap = 100;
await configurator.setExposureCap(dai.address, newExposureCap);
const daiExposureCap = (await helpersContract.getReserveCaps(dai.address)).exposureCap;
expect(daiExposureCap).to.be.equal(newExposureCap);
const precisionBorrowedUsdAmount = 15 * 1000;
const precisionBorrowedEthAmount = ethers.BigNumber.from(precisionBorrowedUsdAmount)
.mul(daiPrice)
.div(parseEther('1.0'))
.toString();
const borrowedAmount = await unitParse(weth, precisionBorrowedEthAmount);
pool.connect(user1.signer).borrow(weth.address, borrowedAmount, 1, 0, user1.address);
});
it('should not be able to withdraw 5 dai, transfer 5 aDai after cap decrease of usdc back to 10 (capped)', async () => {
const {
pool,
dai,
usdc,
aDai,
configurator,
helpersContract,
users: [user1, , , receiver],
} = testEnv;
const newExposureCap = 10;
await configurator.setExposureCap(usdc.address, newExposureCap);
const usdcExposureCap = (await helpersContract.getReserveCaps(usdc.address)).exposureCap;
expect(usdcExposureCap).to.be.equal(newExposureCap);
const precisionWithdrawnAmount = (5 * 1000).toString();
const withdrawnAmount = await unitParse(dai, precisionWithdrawnAmount);
await expect(
pool.connect(user1.signer).withdraw(dai.address, withdrawnAmount, user1.address)
).to.be.revertedWith(VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED);
await expect(
aDai.connect(user1.signer).transfer(receiver.address, withdrawnAmount)
).to.be.revertedWith(VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED);
});
it('should be able to withdraw 5 usdc and transfer 5 aUsdc', async () => {
const {
usdc,
pool,
aUsdc,
users: [user1, , , receiver],
} = testEnv;
const precisionWithdrawnAmount = (5 * 1000).toString();
const withdrawnAmount = await unitParse(usdc, precisionWithdrawnAmount);
await pool.connect(user1.signer).withdraw(usdc.address, withdrawnAmount, user1.address);
await aUsdc.connect(user1.signer).transfer(receiver.address, withdrawnAmount);
});
it('should be able to withdraw 5 dai, transfer 5 aDai after repaying weth Debt', async () => {
const {
pool,
dai,
weth,
aDai,
users: [user1, , , receiver],
} = testEnv;
const precisionWithdrawnAmount = (5 * 1000).toString();
const withdrawnAmount = await unitParse(dai, precisionWithdrawnAmount);
await (
await pool.connect(user1.signer).repay(weth.address, MAX_UINT_AMOUNT, 1, user1.address)
).wait();
pool.connect(user1.signer).withdraw(dai.address, withdrawnAmount, user1.address);
aDai.connect(user1.signer).transfer(receiver.address, withdrawnAmount);
});
it('Should fail to set the exposure cap for usdc and DAI to max cap + 1 Units', async () => {
const { configurator, usdc, dai } = testEnv;
const newCap = Number(MAX_EXPOSURE_CAP) + 1;
await expect(configurator.setExposureCap(usdc.address, newCap)).to.be.revertedWith(
RC_INVALID_EXPOSURE_CAP
);
await expect(configurator.setExposureCap(dai.address, newCap)).to.be.revertedWith(
RC_INVALID_EXPOSURE_CAP
);
});
});

View File

@ -0,0 +1,98 @@
import { TestEnv, makeSuite } from './helpers/make-suite';
import {
APPROVAL_AMOUNT_LENDING_POOL,
MAX_UINT_AMOUNT,
RAY,
MAX_EXPOSURE_CAP,
MOCK_CHAINLINK_AGGREGATORS_PRICES,
oneEther,
} from '../../helpers/constants';
import { ProtocolErrors } from '../../helpers/types';
import { MintableERC20, WETH9, WETH9Mocked } from '../../types';
import { parseEther } from '@ethersproject/units';
import { BigNumber } from '@ethersproject/bignumber';
import { strategyDAI } from '../../markets/amm/reservesConfigs';
import { strategyUSDC } from '../../markets/amm/reservesConfigs';
import { ethers } from 'ethers';
import { convertToCurrencyDecimals } from '../../helpers/contracts-helpers';
const { expect } = require('chai');
makeSuite('LTV validation tests', (testEnv: TestEnv) => {
const {
VL_LTV_VALIDATION_FAILED,
RC_INVALID_EXPOSURE_CAP,
VL_COLLATERAL_CANNOT_COVER_NEW_BORROW,
} = ProtocolErrors;
const daiPrice = Number(MOCK_CHAINLINK_AGGREGATORS_PRICES.DAI);
const usdcPrice = Number(MOCK_CHAINLINK_AGGREGATORS_PRICES.USDC);
const daiLTV = Number(strategyDAI.baseLTVAsCollateral);
const usdcLTV = Number(strategyUSDC.baseLTVAsCollateral);
it('User 1 deposits 10 Dai, 10 USDC, user 2 deposits 1 WETH', async () => {
const {
pool,
dai,
usdc,
weth,
users: [user1, user2],
} = testEnv;
const daiAmount = await convertToCurrencyDecimals(dai.address, '10');
const usdcAmount = await convertToCurrencyDecimals(usdc.address, '10');
const wethAmount = await convertToCurrencyDecimals(weth.address, '1');
await dai.connect(user1.signer).approve(pool.address, MAX_UINT_AMOUNT);
await usdc.connect(user1.signer).approve(pool.address, MAX_UINT_AMOUNT);
await weth.connect(user2.signer).approve(pool.address, MAX_UINT_AMOUNT);
await dai.connect(user1.signer).mint(daiAmount);
await usdc.connect(user1.signer).mint(usdcAmount);
await weth.connect(user2.signer).mint(wethAmount);
await pool.connect(user1.signer).deposit(dai.address, daiAmount, user1.address, 0);
await pool.connect(user1.signer).deposit(usdc.address, usdcAmount, user1.address, 0);
await pool.connect(user2.signer).deposit(weth.address, wethAmount, user2.address, 0);
});
it('Sets the ltv of DAI to 0', async () => {
const {
configurator,
dai,
helpersContract,
users: [],
} = testEnv;
await configurator.configureReserveAsCollateral(dai.address, 0, 8000, 10500);
const ltv = (await helpersContract.getReserveConfigurationData(dai.address)).ltv;
expect(ltv).to.be.equal(0);
});
it('Borrows 0.01 weth', async () => {
const {
pool,
weth,
users: [user1],
} = testEnv;
const borrowedAmount = await convertToCurrencyDecimals(weth.address, "0.01");
pool.connect(user1.signer).borrow(weth.address, borrowedAmount, 1, 0, user1.address);
});
it('Tries to withdraw USDC (revert expected)', async () => {
const {
pool,
usdc,
users: [user1, , , receiver],
} = testEnv;
const withdrawnAmount = await convertToCurrencyDecimals(usdc.address, "1");
await expect(
pool.connect(user1.signer).withdraw(usdc.address, withdrawnAmount, user1.address)
).to.be.revertedWith(VL_LTV_VALIDATION_FAILED);
});
});