Skip to content

Commit

Permalink
check for 0 minted before collateral ratio check
Browse files Browse the repository at this point in the history
  • Loading branch information
ewansheldon committed Jan 10, 2025
1 parent 7346460 commit aa4d5df
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion contracts/SmartVaultV4.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ contract SmartVaultV4 is ISmartVault, IRedeemable {
error InvalidToken();
error DeadlineExpired();
error CollateralRatioDecrease();
error InvalidAutoRedemption();

constructor(bytes32 _native, address _manager, address _owner, address _usds, address _priceCalculator) {
NATIVE = _native;
Expand Down Expand Up @@ -369,6 +370,7 @@ contract SmartVaultV4 is ISmartVault, IRedeemable {
address _hypervisor
) external onlyAutoRedemption returns (uint256 _redeemed) {
if (undercollateralised()) revert Undercollateralised();
if (minted == 0) revert InvalidAutoRedemption();
uint256 _preCollateralisationPercentage = calculateCollateralPercentage();
uint256 _withdrawn;
if (_hypervisor != address(0)) {
Expand All @@ -394,7 +396,9 @@ contract SmartVaultV4 is ISmartVault, IRedeemable {
redeposit(_withdrawn, _collateralBalance, _collateralToken);
}
}
if (calculateCollateralPercentage() < _preCollateralisationPercentage) revert CollateralRatioDecrease();
if (minted > 0 && calculateCollateralPercentage() < _preCollateralisationPercentage) {
revert CollateralRatioDecrease();
}
}

function addUniqueHypervisor(address _hypervisor) private {
Expand Down

0 comments on commit aa4d5df

Please sign in to comment.