Because of this, the protocol denies to the user the possibility to reduce the amount of collateral that the liquidators will be able to seize.
In general, the collateral provided by the user is a token that he/she does not want to directly sell to purchase the debt token but he/she is willing to put it as collateral to later be able to repay the debt and redeem the whole collateral.
Because of this, the protocol denies to the user the possibility to reduce the amount of collateral that the liquidators will be able to seize.
The protocol is denying to the user the possibility to reduce the amount of collateral that the liquidators will be able to seize.
pragma solidity 0.8.19;
import {DSCEngine} from "../../src/DSCEngine.sol";
import {DecentralizedStableCoin} from "../../src/DecentralizedStableCoin.sol";
import {HelperConfig} from "../../script/HelperConfig.s.sol";
import {ERC20Mock} from "@openzeppelin/contracts/mocks/ERC20Mock.sol";
import {Test, console} from "forge-std/Test.sol";
import {StdCheats} from "forge-std/StdCheats.sol";
import {MockV3Aggregator} from "../mocks/MockV3Aggregator.sol";
contract PartialRepayTest is StdCheats, Test {
DSCEngine public dsce;
DecentralizedStableCoin public dsc;
HelperConfig public helperConfig;
address[] public tokenAddresses;
address[] public priceFeedAddresses;
address public ethUsdPriceFeed;
address public btcUsdPriceFeed;
address public weth;
address public wbtc;
uint256 public deployerKey;
uint256 amountCollateral = 10 ether;
uint256 amountToMint = 100 ether;
address public user = address(1);
uint256 public constant STARTING_USER_BALANCE = 10 ether;
uint256 public constant MIN_HEALTH_FACTOR = 1e18;
uint256 public constant LIQUIDATION_THRESHOLD = 50;
function setUp() external {
helperConfig = new HelperConfig();
(ethUsdPriceFeed, btcUsdPriceFeed, weth, wbtc, deployerKey) = helperConfig.activeNetworkConfig();
tokenAddresses = [weth, wbtc];
priceFeedAddresses = [ethUsdPriceFeed, btcUsdPriceFeed];
dsc = new DecentralizedStableCoin();
dsce = new DSCEngine(tokenAddresses, priceFeedAddresses, address(dsc));
dsc.transferOwnership(address(dsce));
if (block.chainid == 31337) {
vm.deal(user, STARTING_USER_BALANCE);
}
ERC20Mock(weth).mint(user, STARTING_USER_BALANCE);
ERC20Mock(wbtc).mint(user, STARTING_USER_BALANCE);
}
function testBurnRevertIfHFBelow() public {
vm.startPrank(user);
ERC20Mock(weth).approve(address(dsce), amountCollateral);
dsce.depositCollateralAndMintDsc(weth, amountCollateral, amountToMint);
vm.stopPrank();
int256 ethUsdUpdatedPrice = 18e8;
MockV3Aggregator(ethUsdPriceFeed).updateAnswer(ethUsdUpdatedPrice);
assertLt(dsce.getHealthFactor(user), 1e18);
vm.startPrank(user);
dsc.approve(address(dsce), 1);
vm.expectRevert();
dsce.burnDsc(1);
vm.stopPrank();
}
}