Skip to content

Commit

Permalink
collateralisation % should not be lower than before redemption
Browse files Browse the repository at this point in the history
  • Loading branch information
ewansheldon committed Jan 2, 2025
1 parent ff4ef5b commit bfcf167
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion contracts/SmartVaultV4.sol
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ contract SmartVaultV4 is ISmartVault, IRedeemable {
IERC20(_collateralToken).forceApprove(_yieldManager, 0);
}

function calculateCollaralPercentage() private returns (uint256) {
return 100 * usdCollateral() / minted;
}

function autoRedemption(
address _swapRouterAddress,
address _quoterAddress,
Expand All @@ -349,6 +353,8 @@ contract SmartVaultV4 is ISmartVault, IRedeemable {
uint256 _USDsTargetAmount,
address _hypervisor
) external onlyAutoRedemption returns (uint256 _redeemed) {
if (undercollateralised()) revert Undercollateralised();
uint256 _preCollateralisationLevel = calculateCollaralPercentage();
uint256 _withdrawn;
if (_hypervisor != address(0)) {
address _yieldManager = ISmartVaultManager(manager).yieldManager();
Expand All @@ -372,7 +378,7 @@ contract SmartVaultV4 is ISmartVault, IRedeemable {
redeposit(_withdrawn, _collateralBalance, _collateralToken);
}
}
if (undercollateralised()) revert Undercollateralised();
if (calculateCollaralPercentage() < _preCollateralisationLevel) revert Overrepay();
}

function addUniqueHypervisor(address _hypervisor) private {
Expand Down

0 comments on commit bfcf167

Please sign in to comment.