mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Merge branch 'fix/no-swap-to-freezed' into 'master'
Disallow liquiditySwap with freezed reserve as to See merge request aave-tech/protocol-v2!50
This commit is contained in:
commit
9b2380c5bd
|
@ -514,6 +514,11 @@ contract LendingPoolLiquidationManager is VersionedInitializable {
|
|||
address(vars.toReserveAToken),
|
||||
vars.amountToReceive
|
||||
);
|
||||
|
||||
if (vars.toReserveAToken.balanceOf(msg.sender) == 0) {
|
||||
usersConfig[msg.sender].setUsingAsCollateral(toReserve.id, true);
|
||||
}
|
||||
|
||||
vars.toReserveAToken.mint(msg.sender, vars.amountToReceive, toReserve.liquidityIndex);
|
||||
toReserve.updateInterestRates(
|
||||
toAsset,
|
||||
|
|
|
@ -88,6 +88,7 @@ library Errors {
|
|||
NOT_ENOUGH_LIQUIDITY,
|
||||
NO_ACTIVE_RESERVE,
|
||||
HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD,
|
||||
INVALID_EQUAL_ASSETS_TO_SWAP
|
||||
INVALID_EQUAL_ASSETS_TO_SWAP,
|
||||
NO_UNFREEZED_RESERVE
|
||||
}
|
||||
}
|
||||
|
|
|
@ -452,16 +452,19 @@ library ValidationLogic {
|
|||
address fromAsset,
|
||||
address toAsset
|
||||
) internal view returns (uint256, string memory) {
|
||||
if (!fromReserve.configuration.getActive() || !toReserve.configuration.getActive()) {
|
||||
return (uint256(Errors.LiquidationErrors.NO_ACTIVE_RESERVE), Errors.NO_ACTIVE_RESERVE);
|
||||
}
|
||||
|
||||
if (fromAsset == toAsset) {
|
||||
return (
|
||||
uint256(Errors.LiquidationErrors.INVALID_EQUAL_ASSETS_TO_SWAP),
|
||||
Errors.INVALID_EQUAL_ASSETS_TO_SWAP
|
||||
);
|
||||
}
|
||||
(bool isToActive, bool isToFreezed, , ) = toReserve.configuration.getFlags();
|
||||
if (!fromReserve.configuration.getActive() || !isToActive) {
|
||||
return (uint256(Errors.LiquidationErrors.NO_ACTIVE_RESERVE), Errors.NO_ACTIVE_RESERVE);
|
||||
}
|
||||
if (isToFreezed) {
|
||||
return (uint256(Errors.LiquidationErrors.NO_UNFREEZED_RESERVE), Errors.NO_UNFREEZED_RESERVE);
|
||||
}
|
||||
|
||||
return (uint256(Errors.LiquidationErrors.NO_ERROR), Errors.NO_ERRORS);
|
||||
}
|
||||
|
|
|
@ -495,4 +495,4 @@
|
|||
"address": "0xBEF0d4b9c089a5883741fC14cbA352055f35DDA2"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -67,6 +67,7 @@ export enum ProtocolErrors {
|
|||
NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18', // 'User does not have a variable rate loan in progress on this reserve'
|
||||
UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19', // 'The underlying balance needs to be greater than 0'
|
||||
DEPOSIT_ALREADY_IN_USE = '20', // 'User deposit is already being used as collateral'
|
||||
INVALID_EQUAL_ASSETS_TO_SWAP = '56', // User can't use same reserve as destination of liquidity swap
|
||||
|
||||
// require error messages - LendingPool
|
||||
NOT_ENOUGH_STABLE_BORROW_BALANCE = '21', // 'User does not have any stable rate loan for this reserve'
|
||||
|
|
|
@ -13,12 +13,63 @@ const {expect} = require('chai');
|
|||
|
||||
makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => {
|
||||
let _mockSwapAdapter = {} as MockSwapAdapter;
|
||||
const {HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD} = ProtocolErrors;
|
||||
const {
|
||||
HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD,
|
||||
NO_UNFREEZED_RESERVE,
|
||||
NO_ACTIVE_RESERVE,
|
||||
INVALID_EQUAL_ASSETS_TO_SWAP,
|
||||
} = ProtocolErrors;
|
||||
|
||||
before(async () => {
|
||||
_mockSwapAdapter = await getMockSwapAdapter();
|
||||
});
|
||||
|
||||
it('Should not allow to swap if from equal to', async () => {
|
||||
const {pool, weth} = testEnv;
|
||||
|
||||
await expect(
|
||||
pool.swapLiquidity(
|
||||
_mockSwapAdapter.address,
|
||||
weth.address,
|
||||
weth.address,
|
||||
'1'.toString(),
|
||||
'0x10'
|
||||
)
|
||||
).to.be.revertedWith(INVALID_EQUAL_ASSETS_TO_SWAP);
|
||||
});
|
||||
|
||||
it('Should not allow to swap if from or to reserves are not active', async () => {
|
||||
const {pool, weth, dai, configurator} = testEnv;
|
||||
|
||||
await configurator.deactivateReserve(weth.address);
|
||||
|
||||
await expect(
|
||||
pool.swapLiquidity(
|
||||
_mockSwapAdapter.address,
|
||||
weth.address,
|
||||
dai.address,
|
||||
'1'.toString(),
|
||||
'0x10'
|
||||
)
|
||||
).to.be.revertedWith(NO_ACTIVE_RESERVE);
|
||||
await configurator.activateReserve(weth.address);
|
||||
|
||||
await configurator.deactivateReserve(dai.address);
|
||||
|
||||
await expect(
|
||||
pool.swapLiquidity(
|
||||
_mockSwapAdapter.address,
|
||||
weth.address,
|
||||
dai.address,
|
||||
'1'.toString(),
|
||||
'0x10'
|
||||
)
|
||||
).to.be.revertedWith(NO_ACTIVE_RESERVE);
|
||||
|
||||
//cleanup state
|
||||
await configurator.activateReserve(dai.address);
|
||||
});
|
||||
|
||||
it('Deposits WETH into the reserve', async () => {
|
||||
const {pool, weth, users} = testEnv;
|
||||
const amountToDeposit = ethers.utils.parseEther('1');
|
||||
|
@ -32,6 +83,7 @@ makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => {
|
|||
.deposit(weth.address, amountToDeposit, await signer.getAddress(), '0');
|
||||
}
|
||||
});
|
||||
|
||||
it('User tries to swap more then he can, revert expected', async () => {
|
||||
const {pool, weth, dai} = testEnv;
|
||||
await expect(
|
||||
|
@ -45,19 +97,6 @@ makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => {
|
|||
).to.be.revertedWith('55');
|
||||
});
|
||||
|
||||
it('User tries to swap asset on equal asset, revert expected', async () => {
|
||||
const {pool, weth} = testEnv;
|
||||
await expect(
|
||||
pool.swapLiquidity(
|
||||
_mockSwapAdapter.address,
|
||||
weth.address,
|
||||
weth.address,
|
||||
ethers.utils.parseEther('0.1'),
|
||||
'0x10'
|
||||
)
|
||||
).to.be.revertedWith('56');
|
||||
});
|
||||
|
||||
it('User tries to swap more then available on the reserve', async () => {
|
||||
const {pool, weth, dai, users, aEth, deployer} = testEnv;
|
||||
|
||||
|
@ -134,6 +173,9 @@ makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => {
|
|||
reserveBalanceDAIBefore.add(amountToReturn).toString(),
|
||||
'was received incorrect amount if reserve funds'
|
||||
);
|
||||
expect(
|
||||
(await pool.getUserReserveData(dai.address, userAddress)).usageAsCollateralEnabled
|
||||
).to.be.equal(true, 'usage as collateral was not enabled on destination reserve for the user');
|
||||
});
|
||||
|
||||
it('User tries to drop HF below one', async () => {
|
||||
|
@ -151,7 +193,7 @@ makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => {
|
|||
});
|
||||
|
||||
it('Should set usage as collateral to false if no leftovers after swap', async () => {
|
||||
const {pool, weth, dai, aEth, users} = testEnv;
|
||||
const {pool, weth, dai, users} = testEnv;
|
||||
const userAddress = await pool.signer.getAddress();
|
||||
|
||||
// add more liquidity to allow user 0 to swap everything he has
|
||||
|
@ -195,4 +237,22 @@ makeSuite('LendingPool SwapDeposit function', (testEnv: TestEnv) => {
|
|||
'usageAsCollateralEnabled are not set to false'
|
||||
);
|
||||
});
|
||||
it('Should not allow to swap if to reserve are freezed', async () => {
|
||||
const {pool, weth, dai, configurator} = testEnv;
|
||||
|
||||
await configurator.freezeReserve(dai.address);
|
||||
|
||||
await expect(
|
||||
pool.swapLiquidity(
|
||||
_mockSwapAdapter.address,
|
||||
weth.address,
|
||||
dai.address,
|
||||
'1'.toString(),
|
||||
'0x10'
|
||||
)
|
||||
).to.be.revertedWith(NO_UNFREEZED_RESERVE);
|
||||
|
||||
//cleanup state
|
||||
await configurator.unfreezeReserve(dai.address);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user