Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c4-010 Compensate is prevented if user is underwater #129

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/Size.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {Events} from "@src/libraries/Events.sol";
import {IMulticall} from "@src/interfaces/IMulticall.sol";
import {ISize} from "@src/interfaces/ISize.sol";
import {ISizeAdmin} from "@src/interfaces/ISizeAdmin.sol";
import {Errors} from "@src/libraries/Errors.sol";

bytes32 constant KEEPER_ROLE = keccak256("KEEPER_ROLE");
bytes32 constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
Expand Down Expand Up @@ -106,6 +107,16 @@ contract Size is ISize, SizeView, Initializable, AccessControlUpgradeable, Pausa

function _authorizeUpgrade(address newImplementation) internal override onlyRole(DEFAULT_ADMIN_ROLE) {}

/// @notice Validate that the user has not put themselves in underwater state
modifier shouldNotEndUpUnderwater() {
bool isUserUnderwaterBefore = state.isUserUnderwater(msg.sender);
_;
bool isUserUnderwaterAfter = state.isUserUnderwater(msg.sender);
if (!isUserUnderwaterBefore && isUserUnderwaterAfter) {
revert Errors.USER_IS_UNDERWATER(msg.sender, state.collateralRatio(msg.sender));
}
}

/// @inheritdoc ISizeAdmin
function updateConfig(UpdateConfigParams calldata params)
external
Expand Down Expand Up @@ -244,10 +255,15 @@ contract Size is ISize, SizeView, Initializable, AccessControlUpgradeable, Pausa
}

/// @inheritdoc ISize
function compensate(CompensateParams calldata params) external payable override(ISize) whenNotPaused {
function compensate(CompensateParams calldata params)
external
payable
override(ISize)
whenNotPaused
shouldNotEndUpUnderwater
{
state.validateCompensate(params);
state.executeCompensate(params);
state.validateUserIsNotUnderwater(msg.sender);
}

/// @inheritdoc ISize
Expand Down
10 changes: 0 additions & 10 deletions src/libraries/RiskLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,6 @@ library RiskLibrary {
return collateralRatio(state, account) < state.riskConfig.crLiquidation;
}

/// @notice Validate that the user is not underwater
/// @dev Reverts if the user is underwater
/// @param state The state
/// @param account The account
function validateUserIsNotUnderwater(State storage state, address account) external view {
if (isUserUnderwater(state, account)) {
revert Errors.USER_IS_UNDERWATER(account, collateralRatio(state, account));
}
}

/// @notice Validate that the user is not below the opening limit borrow CR
/// @dev Reverts if the user is below the opening limit borrow CR
/// The user can set a custom opening limit borrow CR using SetUserConfiguration
Expand Down
Loading