Skip to content

twinstake/twinstake-batch-deposit-contract

Repository files navigation

Twinstake Batch Depositor

A Solidity smart contract for batch depositing ETH to the Ethereum 2.0 deposit contract.

Overview

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.

Features

  • Batch multiple deposits in a single transaction
  • Pausable functionality for emergency situations

Contract Details

State Variables

  • depositContract: Address of the Ethereum 2.0 deposit contract
  • MAX_DEPOSITS_PER_BATCH: Maximum number of deposits allowed in a single batch (100)

Structs

struct Deposit {
    bytes pubkey;                    // 48 bytes
    bytes withdrawalCredentials;     // 32 bytes
    bytes signature;                 // 96 bytes
    bytes32 depositDataRoot;         // 32 bytes
    uint256 amountWei;              // Amount in wei
}

Functions

Constructor

constructor(address _depositContract)
  • Initializes the contract with the deposit contract address
  • Reverts if the deposit contract address is zero

Batch Deposit

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

Administrative Functions

function pause() external onlyOwner
function unpause() external onlyOwner
  • Allows the owner to pause/unpause the contract
  • Only callable by the contract owner

Validation Rules

  1. Deposit contract address must not be zero
  2. Number of deposits must be between 1 and 100
  3. 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)
  4. Total ETH sent must match the sum of all deposit amounts
  5. Direct ETH transfers are not allowed

Custom Errors

  • InvalidDepositContractAddress(): Deposit contract address is zero
  • DirectEthTransfersNotAllowed(): Direct ETH transfers are not allowed
  • InvalidNumberOfDeposits(): Number of deposits is invalid
  • InvalidPubkeyLength(): Public key length is not 48 bytes
  • InvalidWithdrawalCredentialsLength(): Withdrawal credentials length is not 32 bytes
  • InvalidSignatureLength(): Signature length is not 96 bytes
  • InvalidDepositDataRoot(): Deposit data root is zero
  • InvalidDepositAmount(): Deposit amount is invalid
  • InvalidDepositAmountNotMultipleOfGwei(): Deposit amount is not a multiple of 1 gwei
  • IncorrectEthAmountSent(): Total ETH sent does not match total deposit amounts

Usage

  1. Deploy the contract with the Ethereum 2.0 deposit contract address
  2. Prepare deposit data for each validator
  3. Call batchDeposit with the deposit data and the total ETH amount
  4. The contract will validate and process all deposits

Testing

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 -vv

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors