A Solidity smart contract for batch depositing ETH to the Ethereum 2.0 deposit contract.
The Twinstake Batch Depositor contract allows users to make multiple ETH deposits to the Ethereum 2.0 deposit contract in a single transaction. This is particularly useful for staking services and validators who need to make multiple deposits efficiently.
- Batch multiple deposits in a single transaction
- Pausable functionality for emergency situations
depositContract: Address of the Ethereum 2.0 deposit contractMAX_DEPOSITS_PER_BATCH: Maximum number of deposits allowed in a single batch (100)
struct Deposit {
bytes pubkey; // 48 bytes
bytes withdrawalCredentials; // 32 bytes
bytes signature; // 96 bytes
bytes32 depositDataRoot; // 32 bytes
uint256 amountWei; // Amount in wei
}constructor(address _depositContract)- Initializes the contract with the deposit contract address
- Reverts if the deposit contract address is zero
function batchDeposit(Deposit[] calldata deposits) external payable whenNotPaused nonReentrant- Processes multiple deposits in a single transaction
- Validates all deposit data before processing
- Ensures the total ETH sent matches the total deposit amounts
- Reverts if any validation fails
function pause() external onlyOwner
function unpause() external onlyOwner- Allows the owner to pause/unpause the contract
- Only callable by the contract owner
- Deposit contract address must not be zero
- Number of deposits must be between 1 and 100
- Each deposit must have:
- 48-byte public key
- 32-byte withdrawal credentials
- 96-byte signature
- Non-zero deposit data root
- Amount between 1 and 2048 ETH
- Amount must be a multiple of 1 gwei (1e9 wei)
- Total ETH sent must match the sum of all deposit amounts
- Direct ETH transfers are not allowed
InvalidDepositContractAddress(): Deposit contract address is zeroDirectEthTransfersNotAllowed(): Direct ETH transfers are not allowedInvalidNumberOfDeposits(): Number of deposits is invalidInvalidPubkeyLength(): Public key length is not 48 bytesInvalidWithdrawalCredentialsLength(): Withdrawal credentials length is not 32 bytesInvalidSignatureLength(): Signature length is not 96 bytesInvalidDepositDataRoot(): Deposit data root is zeroInvalidDepositAmount(): Deposit amount is invalidInvalidDepositAmountNotMultipleOfGwei(): Deposit amount is not a multiple of 1 gweiIncorrectEthAmountSent(): Total ETH sent does not match total deposit amounts
- Deploy the contract with the Ethereum 2.0 deposit contract address
- Prepare deposit data for each validator
- Call
batchDepositwith the deposit data and the total ETH amount - The contract will validate and process all deposits
The contract includes comprehensive tests covering:
- Constructor validation
- Batch deposit functionality
- Input validation
- Administrative functions
- Error handling
- Edge cases
Run the tests using:
forge test -vvMIT