Skip to content

Commit

Permalink
Add depositAndMint
Browse files Browse the repository at this point in the history
  • Loading branch information
xrchz committed Nov 14, 2022
1 parent f50109b commit 9c90a38
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions contracts/contract/node/RocketNodeDeposit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import "../../interface/dao/node/settings/RocketDAONodeTrustedSettingsMembersInt
import "../../types/MinipoolDeposit.sol";
import "../../interface/node/RocketNodeManagerInterface.sol";
import "../../interface/RocketVaultInterface.sol";
import "../../interface/token/RocketTokenRETHInterface.sol";

// Handles node deposits and minipool creation

Expand Down Expand Up @@ -63,6 +64,26 @@ contract RocketNodeDeposit is RocketBase, RocketNodeDepositInterface {
_deposit(msg.value, _minimumNodeFee, _validatorPubkey, _validatorSignature, _depositDataRoot, _salt, _expectedMinipoolAddress);
}

function depositAndMint(uint256 _mintEthAmount, uint256 _minimumNodeFee, bytes calldata _validatorPubkey, bytes calldata _validatorSignature, bytes32 _depositDataRoot, uint256 _salt, address _expectedMinipoolAddress) override external payable onlyLatestContract("rocketNodeDeposit", address(this)) onlyRegisteredNode(msg.sender) {
require(_mintEthAmount <= msg.value, "Requested to mint rETH with more ether than provided");
// Deposit the minipool
_deposit(msg.value - _mintEthAmount, _minimumNodeFee, _validatorPubkey, _validatorSignature, _depositDataRoot, _salt, _expectedMinipoolAddress);
// Mint rETH for the caller
_mint(_mintEthAmount);
}

function _mint(uint256 _mintEthAmount) private {
// Save current rETH balance (for calculating how much rETH is minted)
RocketTokenRETHInterface rocketTokenRETH = RocketTokenRETHInterface(getContractAddress("rocketTokenRETH"));
uint256 rETHBefore = rocketTokenRETH.balanceOf(address(this));
// Deposit ETH to mint rETH
RocketDepositPoolInterface rocketDepositPool = RocketDepositPoolInterface(getContractAddress("rocketDepositPool"));
rocketDepositPool.deposit{value: _mintEthAmount}();
// Transfer minted rETH back to the caller
rocketTokenRETH.transfer(msg.sender, rocketTokenRETH.balanceOf(address(this)) - rETHBefore);
}


// Accept a node deposit and create a new minipool under the node
// Only accepts calls from registered nodes
function _deposit(uint256 _value, uint256 _minimumNodeFee, bytes calldata _validatorPubkey, bytes calldata _validatorSignature, bytes32 _depositDataRoot, uint256 _salt, address _expectedMinipoolAddress) private {
Expand Down
1 change: 1 addition & 0 deletions contracts/interface/node/RocketNodeDepositInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ interface RocketNodeDepositInterface {
function increaseDepositCreditBalance(address _nodeOperator, uint256 _amount) external;
function depositWithCredit(uint256 _creditUsed, uint256 _minimumNodeFee, bytes calldata _validatorPubkey, bytes calldata _validatorSignature, bytes32 _depositDataRoot, uint256 _salt, address _expectedMinipoolAddress) external payable;
function deposit(uint256 _minimumNodeFee, bytes calldata _validatorPubkey, bytes calldata _validatorSignature, bytes32 _depositDataRoot, uint256 _salt, address _expectedMinipoolAddress) external payable;
function depositAndMint(uint256 _mintEthAmount, uint256 _minimumNodeFee, bytes calldata _validatorPubkey, bytes calldata _validatorSignature, bytes32 _depositDataRoot, uint256 _salt, address _expectedMinipoolAddress) external payable;
}

0 comments on commit 9c90a38

Please sign in to comment.