Skip to content

Commit 4a14bce

Browse files
authored
changing logic to make vaultManager compatible (#175)
1 parent e8ca2fb commit 4a14bce

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

contracts/vaultManager/VaultManager.sol

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ contract VaultManager is VaultManagerPermit, IVaultManagerFunctions {
403403
/// @param collateralAmount Amount by which increasing the collateral balance of
404404
function _addCollateral(uint256 vaultID, uint256 collateralAmount) internal {
405405
if (!_exists(vaultID)) revert NonexistentVault();
406-
_checkpointCollateral(vaultID, false);
406+
_checkpointCollateral(vaultID, collateralAmount, true);
407407
vaultData[vaultID].collateralAmount += collateralAmount;
408408
emit CollateralAmountUpdated(vaultID, collateralAmount, 1);
409409
}
@@ -420,7 +420,7 @@ contract VaultManager is VaultManagerPermit, IVaultManagerFunctions {
420420
uint256 oracleValue,
421421
uint256 interestAccumulator_
422422
) internal onlyApprovedOrOwner(msg.sender, vaultID) {
423-
_checkpointCollateral(vaultID, false);
423+
_checkpointCollateral(vaultID, collateralAmount, false);
424424
vaultData[vaultID].collateralAmount -= collateralAmount;
425425
(uint256 healthFactor, , ) = _isSolvent(vaultData[vaultID], oracleValue, interestAccumulator_);
426426
if (healthFactor <= BASE_PARAMS) revert InsolventVault();
@@ -678,7 +678,11 @@ contract VaultManager is VaultManagerPermit, IVaultManagerFunctions {
678678
uint256 collateralReleased = (amounts[i] * BASE_PARAMS * _collatBase) /
679679
(liqOpp.discount * liqData.oracleValue);
680680

681-
_checkpointCollateral(vaultIDs[i], vault.collateralAmount <= collateralReleased);
681+
_checkpointCollateral(
682+
vaultIDs[i],
683+
vault.collateralAmount <= collateralReleased ? vault.collateralAmount : collateralReleased,
684+
false
685+
);
682686
// Because we're rounding up in some divisions, `collateralReleased` can be greater than the `collateralAmount` of the vault
683687
// In this case, `stablecoinAmountToReceive` is still rounded up
684688
if (vault.collateralAmount <= collateralReleased) {
@@ -921,6 +925,12 @@ contract VaultManager is VaultManagerPermit, IVaultManagerFunctions {
921925

922926
/// @notice Hook called before any collateral internal changes
923927
/// @param vaultID Vault which sees its collateral amount changed
924-
/// @param burn Whether the vault was emptied from all its collateral
925-
function _checkpointCollateral(uint256 vaultID, bool burn) internal virtual {}
928+
/// @param amount Collateral amount balance of the owner of vaultID increase/decrease
929+
/// @param add Whether the balance should be increased/decreased
930+
/// @param vaultID Vault which sees its collateral amount changed
931+
function _checkpointCollateral(
932+
uint256 vaultID,
933+
uint256 amount,
934+
bool add
935+
) internal virtual {}
926936
}

0 commit comments

Comments
 (0)