Skip to content
Open
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
40 changes: 38 additions & 2 deletions contracts/governance/FeeSharingCollector/FeeSharingCollector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ contract FeeSharingCollector is
address indexed newLoanTokenWrbtc
);

/// @notice An event emitted when contract is frozen
event Frozen(address indexed sender);

/// @notice An event emitted when contract is unfrozen
event Unfrozen(address indexed sender);

/* Modifier */
modifier oneTimeExecution(bytes4 _funcSig) {
require(
Expand All @@ -126,6 +132,16 @@ contract FeeSharingCollector is
isFunctionExecuted[_funcSig] = true;
}

modifier whenNotFrozen() {
require(!frozen, "FeeSharingCollector: contract is frozen");
_;
}

modifier whenFrozen() {
require(frozen, "FeeSharingCollector: contract is not frozen");
_;
}

/* Functions */

/// @dev fallback function to support rbtc transfer when unwrap the wrbtc.
Expand Down Expand Up @@ -177,6 +193,26 @@ contract FeeSharingCollector is
loanTokenWrbtcAddress = newLoanTokenWrbtcAddress;
}

/**
* @notice Freeze the contract to prevent withdrawals.
*
* Only owner can perform this action.
* */
function freeze() external onlyOwner whenNotFrozen {
frozen = true;
emit Frozen(msg.sender);
}

/**
* @notice Unfreeze the contract to allow withdrawals.
*
* Only owner can perform this action.
* */
function unfreeze() external onlyOwner whenFrozen {
frozen = false;
emit Unfrozen(msg.sender);
}

/**
* @notice Withdraw fees for the given token:
* lendingFee + tradingFee + borrowingFee
Expand Down Expand Up @@ -398,7 +434,7 @@ contract FeeSharingCollector is
address _token,
uint32 _maxCheckpoints,
address _receiver
) public nonReentrant {
) public nonReentrant whenNotFrozen {
_withdraw(_token, _maxCheckpoints, _receiver);
}

Expand Down Expand Up @@ -561,7 +597,7 @@ contract FeeSharingCollector is
TokenWithSkippedCheckpointsWithdraw[] calldata _tokensWithSkippedCheckpoints,
uint32 _maxCheckpoints,
address _receiver
) external nonReentrant {
) external nonReentrant whenNotFrozen {
uint256 totalProcessedCheckpoints;

/** Process normal multiple withdrawal for RBTC based tokens */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ contract FeeSharingCollectorStorage is Ownable {
*/
address public loanTokenWrbtcAddress;

/**
* @dev Contract frozen state
*/
bool public frozen;

/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* If you mark a function `nonReentrant`, you should also
Expand Down
Loading
Loading