Skip to content

Commit 50c2668

Browse files
committed
Add some additional sanity checks to excess collateral deposit
1 parent 2ed15be commit 50c2668

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

contracts/contract/minipool/RocketMinipoolDelegate.sol

+6-3
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,12 @@ contract RocketMinipoolDelegate is RocketMinipoolStorageLayout, RocketMinipoolIn
405405
// Only the owner can destroy a minipool
406406
require(nodeWithdrawalAddress == msg.sender || nodeAddress == msg.sender, "Only node operator can destroy minipool");
407407
// Send any remaining balance to rETH contract
408-
payable(rocketTokenRETH).transfer(address(this).balance.sub(refundAmount));
409-
// Send any overcollateralised ETH to the deposit pool
410-
RocketTokenRETHInterface(rocketTokenRETH).depositExcessCollateral();
408+
uint256 userAmount = address(this).balance.sub(refundAmount);
409+
if (userAmount > 0) {
410+
payable(rocketTokenRETH).transfer(userAmount);
411+
// Send any overcollateralised ETH to the deposit pool
412+
RocketTokenRETHInterface(rocketTokenRETH).depositExcessCollateral();
413+
}
411414
// Self destruct the refund amount to node withdrawal address
412415
selfdestruct(payable(nodeWithdrawalAddress));
413416
}

contracts/contract/token/RocketTokenRETH.sol

+7-4
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,14 @@ contract RocketTokenRETH is RocketBase, ERC20, RocketTokenRETHInterface {
142142
uint256 targetCollateralRate = rocketDAOProtocolSettingsNetwork.getTargetRethCollateralRate();
143143
// Check if we are in excess
144144
if (collateralRate > targetCollateralRate) {
145-
// Calculate ETH excess
145+
// Calculate our target collateral in ETH
146146
uint256 targetCollateral = address(this).balance.mul(targetCollateralRate).div(collateralRate);
147-
uint256 excessCollateral = address(this).balance.sub(targetCollateral);
148-
// Send excess to deposit pool
149-
rocketDepositPool.recycleExcessCollateral{value: excessCollateral}();
147+
// If we have excess
148+
if (address(this).balance > targetCollateral) {
149+
// Send that excess to deposit pool
150+
uint256 excessCollateral = address(this).balance.sub(targetCollateral);
151+
rocketDepositPool.recycleExcessCollateral{value: excessCollateral}();
152+
}
150153
}
151154
}
152155

0 commit comments

Comments
 (0)