Skip to content

Conversation

@sherlock-admin
Copy link
Contributor

@sherlock-admin sherlock-admin commented Aug 15, 2025

Fix Review of

Repo: cap-labs-dev/cap-contracts
Commit Hash: 403326df39f6987359bba648b7c09f81bd53da62

Comment on lines +98 to +99
uint256 slashShareOfCollateral =
_slashShare == 1e18 ? totalSlashableCollateral : (totalSlashableCollateral * _slashShare / 1e18) + 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

balances = new uint256[](assetsLength);
for (uint256 i; i < assetsLength; ++i) {
address asset = _assets[i];
if (asset == address(0)) revert InvalidAsset();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +39 to +41
/// @dev Asset must be non-zero address
error InvalidAsset();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +217 to +221
if (realizedInterest > 0) {
IVault(reserve.vault).borrow(_asset, realizedInterest, $.delegation);
IDelegation($.delegation).distributeRewards(_agent, _asset);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +25 to +27
/// @notice No debt to liquidate
error NoDebt();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +71 to +72
if (totalDebt == 0) revert NoDebt();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +97 to +99
(,,,,, health) = ViewLogic.agent($, params.agent);
if (health >= 1e27) _closeLiquidation($, params.agent);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint256 excess = _utilization - slopes.kink;
utilizationData.multiplier = utilizationData.multiplier
* (1e27 + (1e27 * excess / (1e27 - slopes.kink)) * (_elapsed * $.rate / 1e27)) / 1e27;
* (1e27 + (1e27 * excess / (1e27 - slopes.kink)) * _elapsed * $.rate / 1e27) / 1e27;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else {
utilizationData.multiplier = utilizationData.multiplier * 1e27
/ (1e27 + (1e27 * (slopes.kink - _utilization) / slopes.kink) * (_elapsed * $.rate / 1e27));
/ (1e27 + (1e27 * (slopes.kink - _utilization) / slopes.kink) * _elapsed * $.rate / 1e27);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +64 to +66

_burn(msg.sender, _amountIn);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_burn(msg.sender, _amountIn);

divest(_asset, amountOut + fee);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +91 to +93

_burn(msg.sender, _amountIn);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

divestMany(assets(), totalDivestAmounts);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +142 to +145
if ($.vault[_asset] != address(0)) {
IERC4626($.vault[_asset]).withdraw(claimableInterest($, _asset), $.interestReceiver, address(this));
emit FractionalReserveInterestRealized(_asset);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +157 to +158
if ($.vault[_asset] == address(0)) return 0;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +98 to +99
uint256 slashShareOfCollateral =
_slashShare == 1e18 ? totalSlashableCollateral : (totalSlashableCollateral * _slashShare / 1e18) + 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

balances = new uint256[](assetsLength);
for (uint256 i; i < assetsLength; ++i) {
address asset = _assets[i];
if (asset == address(0)) revert InvalidAsset();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +39 to +41
/// @dev Asset must be non-zero address
error InvalidAsset();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +217 to +221
if (realizedInterest > 0) {
IVault(reserve.vault).borrow(_asset, realizedInterest, $.delegation);
IDelegation($.delegation).distributeRewards(_agent, _asset);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +25 to +27
/// @notice No debt to liquidate
error NoDebt();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +75 to +76
if (totalDebt == 0) revert NoDebt();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +102 to +104
(,,,,, health) = ViewLogic.agent($, params.agent);
if (health >= 1e27) _closeLiquidation($, params.agent);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint256 excess = _utilization - slopes.kink;
utilizationData.multiplier = utilizationData.multiplier
* (1e27 + (1e27 * excess / (1e27 - slopes.kink)) * (_elapsed * $.rate / 1e27)) / 1e27;
* (1e27 + (1e27 * excess / (1e27 - slopes.kink)) * _elapsed * $.rate / 1e27) / 1e27;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else {
utilizationData.multiplier = utilizationData.multiplier * 1e27
/ (1e27 + (1e27 * (slopes.kink - _utilization) / slopes.kink) * (_elapsed * $.rate / 1e27));
/ (1e27 + (1e27 * (slopes.kink - _utilization) / slopes.kink) * _elapsed * $.rate / 1e27);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +64 to +66

_burn(msg.sender, _amountIn);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_burn(msg.sender, _amountIn);

divest(_asset, amountOut + fee);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +91 to +93

_burn(msg.sender, _amountIn);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

divestMany(assets(), totalDivestAmounts);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +148 to +151
if ($.vault[_asset] != address(0)) {
IERC4626($.vault[_asset]).withdraw(claimableInterest($, _asset), $.interestReceiver, address(this));
emit FractionalReserveInterestRealized(_asset);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +163 to +164
if ($.vault[_asset] == address(0)) return 0;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants