Skip to content

Commit 3f1c841

Browse files
committed
[wip] Deposit side
- No longer supports 32E deposits - Will support any deposit size the same way (eg, 16E or 8E)
1 parent a81179b commit 3f1c841

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

contracts/contract/minipool/RocketMinipoolDelegate.sol

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pragma solidity 0.7.6;
55
import "@openzeppelin/contracts/math/SafeMath.sol";
66

77
import "./RocketMinipoolStorageLayout.sol";
8+
import "../../interface/RocketVaultInterface.sol";
89
import "../../interface/casper/DepositInterface.sol";
910
import "../../interface/deposit/RocketDepositPoolInterface.sol";
1011
import "../../interface/minipool/RocketMinipoolInterface.sol";
@@ -17,6 +18,7 @@ import "../../interface/node/RocketNodeStakingInterface.sol";
1718
import "../../interface/dao/protocol/settings/RocketDAOProtocolSettingsMinipoolInterface.sol";
1819
import "../../interface/dao/node/settings/RocketDAONodeTrustedSettingsMinipoolInterface.sol";
1920
import "../../interface/dao/protocol/settings/RocketDAOProtocolSettingsNodeInterface.sol";
21+
import "../../interface/dao/protocol/settings/RocketDAOProtocolSettingsDepositInterface.sol";
2022
import "../../interface/dao/node/RocketDAONodeTrustedInterface.sol";
2123
import "../../interface/network/RocketNetworkFeesInterface.sol";
2224
import "../../interface/token/RocketTokenRETHInterface.sol";
@@ -31,6 +33,7 @@ contract RocketMinipoolDelegate is RocketMinipoolStorageLayout, RocketMinipoolIn
3133
uint8 public constant version = 2; // Used to identify which delegate contract each minipool is using
3234
uint256 constant calcBase = 1 ether;
3335
uint256 constant prelaunchAmount = 16 ether; // The amount of ETH initially deposited when minipool is created
36+
uint256 constant efficientprelaunchAmount = 1 ether; // The amount of ETH initially deposited when minipool is created
3437
uint256 constant distributionCooldown = 100; // Number of blocks that must pass between calls to distributeBalance
3538

3639
// Libs
@@ -131,16 +134,20 @@ contract RocketMinipoolDelegate is RocketMinipoolStorageLayout, RocketMinipoolIn
131134
function nodeDeposit(bytes calldata _validatorPubkey, bytes calldata _validatorSignature, bytes32 _depositDataRoot) override external payable onlyLatestContract("rocketNodeDeposit", msg.sender) onlyInitialised {
132135
// Check current status & node deposit status
133136
require(status == MinipoolStatus.Initialised, "The node deposit can only be assigned while initialised");
134-
require(!nodeDepositAssigned, "The node deposit has already been assigned");
135-
// Progress full minipool to prelaunch
136-
if (depositType == MinipoolDeposit.Full) { setStatus(MinipoolStatus.Prelaunch); }
137-
// Update node deposit details
138-
nodeDepositBalance = msg.value;
139-
nodeDepositAssigned = true;
137+
require(nodeDepositBalance == 0, "The minipool already has a previous nodeDeposit");
138+
140139
// Emit ether deposited event
141140
emit EtherDeposited(msg.sender, msg.value, block.timestamp);
142141
// Perform the pre-stake to lock in withdrawal credentials on beacon chain
143142
preStake(_validatorPubkey, _validatorSignature, _depositDataRoot);
143+
144+
nodeDepositBalance = msg.value;
145+
nodeDepositAssigned = 0; // should be 0 from initialization anyhow
146+
147+
// Deposit ETH (except the ETH needed to preStake) without minting rETH
148+
// Transfer to vault directly instead of via processDeposits to avoid assigning twice
149+
RocketVaultInterface rocketVault = RocketVaultInterface(getContractAddress("rocketVault"));
150+
rocketVault.depositEther{value: msg.value.sub(efficientprelaunchAmount)}();
144151
}
145152

146153
// Assign user deposited ETH to the minipool and mark it as prelaunch
@@ -220,7 +227,11 @@ contract RocketMinipoolDelegate is RocketMinipoolStorageLayout, RocketMinipoolIn
220227
DepositInterface casperDeposit = DepositInterface(getContractAddress("casperDeposit"));
221228
RocketMinipoolManagerInterface rocketMinipoolManager = RocketMinipoolManagerInterface(getContractAddress("rocketMinipoolManager"));
222229
// Get launch amount
223-
uint256 launchAmount = rocketDAOProtocolSettingsMinipool.getLaunchBalance().sub(prelaunchAmount);
230+
if (depositType == MinipoolDeposit.Efficient) {
231+
uint256 launchAmount = rocketDAOProtocolSettingsMinipool.getLaunchBalance().sub(efficientprelaunchAmount);
232+
} else {
233+
uint256 launchAmount = rocketDAOProtocolSettingsMinipool.getLaunchBalance().sub(prelaunchAmount);
234+
}
224235
// Check minipool balance
225236
require(address(this).balance >= launchAmount, "Insufficient balance to begin staking");
226237
// Retrieve validator pubkey from storage
@@ -237,17 +248,17 @@ contract RocketMinipoolDelegate is RocketMinipoolStorageLayout, RocketMinipoolIn
237248
DepositInterface casperDeposit = DepositInterface(getContractAddress("casperDeposit"));
238249
RocketMinipoolManagerInterface rocketMinipoolManager = RocketMinipoolManagerInterface(getContractAddress("rocketMinipoolManager"));
239250
// Check minipool balance
240-
require(address(this).balance >= prelaunchAmount, "Insufficient balance to pre-stake");
251+
require(address(this).balance >= efficientprelaunchAmount, "Insufficient balance to pre-stake");
241252
// Check validator pubkey is not in use
242253
require(rocketMinipoolManager.getMinipoolByPubkey(_validatorPubkey) == address(0x0), "Validator pubkey is in use");
243254
// Set minipool pubkey
244255
rocketMinipoolManager.setMinipoolPubkey(_validatorPubkey);
245256
// Get withdrawal credentials
246257
bytes memory withdrawalCredentials = rocketMinipoolManager.getMinipoolWithdrawalCredentials(address(this));
247258
// Send staking deposit to casper
248-
casperDeposit.deposit{value : prelaunchAmount}(_validatorPubkey, withdrawalCredentials, _validatorSignature, _depositDataRoot);
259+
casperDeposit.deposit{value : efficientprelaunchAmount}(_validatorPubkey, withdrawalCredentials, _validatorSignature, _depositDataRoot);
249260
// Emit event
250-
emit MinipoolPrestaked(_validatorPubkey, _validatorSignature, _depositDataRoot, prelaunchAmount, withdrawalCredentials, block.timestamp);
261+
emit MinipoolPrestaked(_validatorPubkey, _validatorSignature, _depositDataRoot, efficientprelaunchAmount, withdrawalCredentials, block.timestamp);
251262
}
252263

253264
// Mark the minipool as withdrawable

0 commit comments

Comments
 (0)