This commit is contained in:
eboado 2020-09-13 10:08:14 +02:00
parent 7794839f3c
commit 0911f907a8
4 changed files with 79 additions and 0 deletions

View File

@ -385,6 +385,8 @@ contract LendingPool is VersionedInitializable, ILendingPool {
uint256 purchaseAmount, uint256 purchaseAmount,
bool receiveAToken bool receiveAToken
) external override { ) external override {
ValidationLogic.validateLiquidation(_reserves[collateral], _reserves[asset]);
address liquidationManager = _addressesProvider.getLendingPoolLiquidationManager(); address liquidationManager = _addressesProvider.getLendingPoolLiquidationManager();
//solium-disable-next-line //solium-disable-next-line
@ -444,6 +446,8 @@ contract LendingPool is VersionedInitializable, ILendingPool {
require(!_flashLiquidationLocked, Errors.REENTRANCY_NOT_ALLOWED); require(!_flashLiquidationLocked, Errors.REENTRANCY_NOT_ALLOWED);
_flashLiquidationLocked = true; _flashLiquidationLocked = true;
ValidationLogic.validateLiquidation(_reserves[collateral], _reserves[principal]);
address liquidationManager = _addressesProvider.getLendingPoolLiquidationManager(); address liquidationManager = _addressesProvider.getLendingPoolLiquidationManager();
//solium-disable-next-line //solium-disable-next-line

View File

@ -329,4 +329,20 @@ library ValidationLogic {
require(premium > 0, Errors.REQUESTED_AMOUNT_TOO_SMALL); require(premium > 0, Errors.REQUESTED_AMOUNT_TOO_SMALL);
require(mode <= uint256(ReserveLogic.InterestRateMode.VARIABLE), Errors.INVALID_FLASHLOAN_MODE); require(mode <= uint256(ReserveLogic.InterestRateMode.VARIABLE), Errors.INVALID_FLASHLOAN_MODE);
} }
/**
* @dev Validates configurations for liquidation actions, both liquidationCall() and repayWithCollateral()
* @param collateralReserve The reserve data of the collateral
* @param principalReserve The reserve data of the principal
**/
function validateLiquidation(
ReserveLogic.ReserveData storage collateralReserve,
ReserveLogic.ReserveData storage principalReserve
) internal view {
require(
collateralReserve.configuration.getActive() &&
principalReserve.configuration.getActive(),
Errors.NO_ACTIVE_RESERVE
);
}
} }

View File

@ -7,6 +7,7 @@ import {makeSuite} from './helpers/make-suite';
import {ProtocolErrors, RateMode} from '../helpers/types'; import {ProtocolErrors, RateMode} from '../helpers/types';
import {calcExpectedStableDebtTokenBalance} from './helpers/utils/calculations'; import {calcExpectedStableDebtTokenBalance} from './helpers/utils/calculations';
import {getUserData} from './helpers/utils/helpers'; import {getUserData} from './helpers/utils/helpers';
import {parseEther} from 'ethers/lib/utils';
const chai = require('chai'); const chai = require('chai');
@ -23,6 +24,26 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
BigNumber.config({DECIMAL_PLACES: 20, ROUNDING_MODE: BigNumber.ROUND_HALF_UP}); BigNumber.config({DECIMAL_PLACES: 20, ROUNDING_MODE: BigNumber.ROUND_HALF_UP});
}); });
it("It's not possible to liquidate on a non-active collateral or a non active principal", async () => {
const {configurator, weth, pool, users, dai} = testEnv;
const user = users[1];
await configurator.deactivateReserve(weth.address);
await expect(
pool.liquidationCall(weth.address, dai.address, user.address, parseEther('1000'), false)
).to.be.revertedWith('2');
await configurator.activateReserve(weth.address);
await configurator.deactivateReserve(dai.address);
await expect(
pool.liquidationCall(weth.address, dai.address, user.address, parseEther('1000'), false)
).to.be.revertedWith('2');
await configurator.activateReserve(dai.address);
});
it('LIQUIDATION - Deposits WETH, borrows DAI', async () => { it('LIQUIDATION - Deposits WETH, borrows DAI', async () => {
const {dai, weth, users, pool, oracle} = testEnv; const {dai, weth, users, pool, oracle} = testEnv;
const depositor = users[0]; const depositor = users[0];

View File

@ -39,6 +39,44 @@ export const expectRepayWithCollateralEvent = (
}; };
makeSuite('LendingPool. repayWithCollateral()', (testEnv: TestEnv) => { makeSuite('LendingPool. repayWithCollateral()', (testEnv: TestEnv) => {
it("It's not possible to repayWithCollateral() on a non-active collateral or a non active principal", async () => {
const {configurator, weth, pool, users, dai, mockSwapAdapter} = testEnv;
const user = users[1];
await configurator.deactivateReserve(weth.address);
await expect(
pool
.connect(user.signer)
.repayWithCollateral(
weth.address,
dai.address,
user.address,
parseEther('100'),
mockSwapAdapter.address,
'0x'
)
).to.be.revertedWith('2');
await configurator.activateReserve(weth.address);
await configurator.deactivateReserve(dai.address);
await expect(
pool
.connect(user.signer)
.repayWithCollateral(
weth.address,
dai.address,
user.address,
parseEther('100'),
mockSwapAdapter.address,
'0x'
)
).to.be.revertedWith('2');
await configurator.activateReserve(dai.address);
});
it('User 1 provides some liquidity for others to borrow', async () => { it('User 1 provides some liquidity for others to borrow', async () => {
const {pool, weth, dai, usdc, deployer} = testEnv; const {pool, weth, dai, usdc, deployer} = testEnv;