Skip to content

Commit

Permalink
Add some additional sanity checks to excess collateral deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
kanewallmann committed Jul 20, 2021
1 parent 2ed15be commit 50c2668
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions contracts/contract/minipool/RocketMinipoolDelegate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,12 @@ contract RocketMinipoolDelegate is RocketMinipoolStorageLayout, RocketMinipoolIn
// Only the owner can destroy a minipool
require(nodeWithdrawalAddress == msg.sender || nodeAddress == msg.sender, "Only node operator can destroy minipool");
// Send any remaining balance to rETH contract
payable(rocketTokenRETH).transfer(address(this).balance.sub(refundAmount));
// Send any overcollateralised ETH to the deposit pool
RocketTokenRETHInterface(rocketTokenRETH).depositExcessCollateral();
uint256 userAmount = address(this).balance.sub(refundAmount);
if (userAmount > 0) {
payable(rocketTokenRETH).transfer(userAmount);
// Send any overcollateralised ETH to the deposit pool
RocketTokenRETHInterface(rocketTokenRETH).depositExcessCollateral();
}
// Self destruct the refund amount to node withdrawal address
selfdestruct(payable(nodeWithdrawalAddress));
}
Expand Down
11 changes: 7 additions & 4 deletions contracts/contract/token/RocketTokenRETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,14 @@ contract RocketTokenRETH is RocketBase, ERC20, RocketTokenRETHInterface {
uint256 targetCollateralRate = rocketDAOProtocolSettingsNetwork.getTargetRethCollateralRate();
// Check if we are in excess
if (collateralRate > targetCollateralRate) {
// Calculate ETH excess
// Calculate our target collateral in ETH
uint256 targetCollateral = address(this).balance.mul(targetCollateralRate).div(collateralRate);
uint256 excessCollateral = address(this).balance.sub(targetCollateral);
// Send excess to deposit pool
rocketDepositPool.recycleExcessCollateral{value: excessCollateral}();
// If we have excess
if (address(this).balance > targetCollateral) {
// Send that excess to deposit pool
uint256 excessCollateral = address(this).balance.sub(targetCollateral);
rocketDepositPool.recycleExcessCollateral{value: excessCollateral}();
}
}
}

Expand Down

0 comments on commit 50c2668

Please sign in to comment.