Skip to content

Commit

Permalink
migrate to depositId
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbir committed Jun 11, 2024
1 parent 0412408 commit ae4c51c
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 227 deletions.
4 changes: 2 additions & 2 deletions contracts/constants/P2pConstants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pragma solidity 0.8.10;
/// https://ethereum.stackexchange.com/questions/144120/maximum-calldata-size-per-block
uint256 constant VALIDATORS_MAX_AMOUNT = 400;

/// @dev Collateral size of 1 validator
uint256 constant COLLATERAL = 32 ether;
/// @dev EIP-7251 MIN_ACTIVATION_BALANCE
uint256 constant MIN_ACTIVATION_BALANCE = 32 ether;

/// @dev EIP-7251 MAX_EFFECTIVE_BALANCE
uint256 constant MAX_EFFECTIVE_BALANCE = 2048 ether;
Expand Down
13 changes: 0 additions & 13 deletions contracts/feeDistributor/BaseFeeDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,6 @@ abstract contract BaseFeeDistributor is Erc4337Account, OwnableTokenRecoverer, O
}
}

/// @inheritdoc IFeeDistributor
function increaseDepositedCount(uint32 _validatorCountToAdd) external virtual {
// Do nothing by default. Can be overridden.
}

/// @inheritdoc IFeeDistributor
function voluntaryExit(bytes[] calldata _pubkeys) public virtual onlyClient {
emit FeeDistributor__VoluntaryExit(_pubkeys);
}

/// @inheritdoc IFeeDistributor
function factory() external view returns (address) {
return address(i_factory);
Expand Down Expand Up @@ -185,9 +175,6 @@ abstract contract BaseFeeDistributor is Erc4337Account, OwnableTokenRecoverer, O
return s_referrerConfig.basisPoints;
}

/// @inheritdoc IFeeDistributor
function eth2WithdrawalCredentialsAddress() external virtual view returns (address);

/// @inheritdoc ERC165
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IFeeDistributor).interfaceId || super.supportsInterface(interfaceId);
Expand Down
26 changes: 0 additions & 26 deletions contracts/feeDistributor/IFeeDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ interface IFeeDistributor is IERC165 {
uint256 _referrerAmount
);

/// @notice Emits on request for a voluntary exit of validators
/// @param _pubkeys pubkeys of validators
event FeeDistributor__VoluntaryExit(
bytes[] _pubkeys
);

/// @notice Emits if case there was some ether left after `withdraw` and it has been sent successfully.
/// @param _to destination address for ether.
/// @param _amount how much wei the destination address received.
Expand All @@ -55,20 +49,6 @@ interface IFeeDistributor is IERC165 {
FeeRecipient calldata _referrerConfig
) external;

/// @notice Increase the number of deposited validators.
/// @dev DEPRECATED. Need to keep it to preserve the interface.
/// @param _validatorCountToAdd number of newly deposited validators
function increaseDepositedCount(
uint32 _validatorCountToAdd
) external;

/// @notice Request a voluntary exit of validators
/// @dev Should be called by the client when they want to signal P2P that certain validators need to be exited
/// @param _pubkeys pubkeys of validators
function voluntaryExit(
bytes[] calldata _pubkeys
) external;

/// @notice Returns the factory address
/// @return address factory address
function factory() external view returns (address);
Expand All @@ -92,10 +72,4 @@ interface IFeeDistributor is IERC165 {
/// @notice Returns the referrer basis points
/// @return uint256 referrer basis points
function referrerBasisPoints() external view returns (uint256);

/// @notice Returns the address for ETH2 0x01 withdrawal credentials associated with this FeeDistributor
/// @dev Return FeeDistributor's own address if FeeDistributor should be CL rewards recipient
/// Otherwise, return the client address
/// @return address address for ETH2 0x01 withdrawal credentials
function eth2WithdrawalCredentialsAddress() external view returns (address);
}
6 changes: 0 additions & 6 deletions contracts/feeDistributor/OracleFeeDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,4 @@ contract OracleFeeDistributor is BaseFeeDistributor {
function withdrawSelector() public pure override returns (bytes4) {
return OracleFeeDistributor.withdraw.selector;
}

/// @inheritdoc IFeeDistributor
/// @dev client address
function eth2WithdrawalCredentialsAddress() external override view returns (address) {
return s_clientConfig.recipient;
}
}
114 changes: 78 additions & 36 deletions contracts/p2pEth2Depositor/IP2pOrgUnlimitedEthDepositor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,63 @@ import "../structs/P2pStructs.sol";
interface IP2pOrgUnlimitedEthDepositor is IERC165 {

/// @notice Emits when a client adds ETH for staking
/// @param _depositId ID of client deposit (derived from ETH2 WithdrawalCredentials, ETH amount per validator in wei, fee distributor instance address)
/// @param _sender address who sent ETH
/// @param _feeDistributorInstance address of FeeDistributor instance that determines the terms of staking service
/// @param _eth2WithdrawalCredentials ETH2 withdrawal credentials
/// @param _amount sent amount of ETH in wei
/// @param _expiration block timestamp after which the client will be able to get a refund
/// @param _ethAmountPerValidatorInWei amount of ETH to deposit per 1 validator (should be >= 32 and <= 2048)
/// @param _extraData any other data to pass to the event listener
event P2pOrgUnlimitedEthDepositor__ClientEthAdded(
bytes32 indexed _depositId,
address indexed _sender,
address indexed _feeDistributorInstance,
bytes32 _eth2WithdrawalCredentials,
uint256 _amount,
uint40 _expiration
uint40 _expiration,
uint96 _ethAmountPerValidatorInWei,
bytes _extraData
);

/// @notice Emits when a refund has been sent to the client
/// @param _depositId ID of client deposit (derived from ETH2 WithdrawalCredentials, ETH amount per validator in wei, fee distributor instance address)
/// @param _feeDistributorInstance address of FeeDistributor instance that was associated with the client deposit
/// @param _client address who received the refunded ETH
/// @param _amount refunded amount of ETH in wei
event P2pOrgUnlimitedEthDepositor__Refund(
bytes32 indexed _depositId,
address indexed _feeDistributorInstance,
address indexed _client,
uint256 _amount
);

/// @notice Emits when P2P has made ETH2 deposits with client funds and withdrawal credentials
/// @param _feeDistributorAddress address of FeeDistributor instance that was associated with the client deposit
/// @param _depositId ID of client deposit (derived from ETH2 WithdrawalCredentials, ETH amount per validator in wei, fee distributor instance address)
/// @param _validatorCount number of validators that has been created
event P2pOrgUnlimitedEthDepositor__Eth2Deposit(
address indexed _feeDistributorAddress,
bytes32 indexed _depositId,
uint256 _validatorCount
);

/// @notice Emits when all the available ETH has been forwarded to Beacon DepositContract
/// @param _feeDistributorAddress address of FeeDistributor instance that was associated with the client deposit
/// @param _depositId ID of client deposit (derived from ETH2 WithdrawalCredentials, ETH amount per validator in wei, fee distributor instance address)
event P2pOrgUnlimitedEthDepositor__Eth2DepositCompleted(
address indexed _feeDistributorAddress
bytes32 indexed _depositId
);

/// @notice Emits when some (but not all) of the available ETH has been forwarded to Beacon DepositContract
/// @param _feeDistributorAddress address of FeeDistributor instance that was associated with the client deposit
/// @param _depositId ID of client deposit (derived from ETH2 WithdrawalCredentials, ETH amount per validator in wei, fee distributor instance address)
event P2pOrgUnlimitedEthDepositor__Eth2DepositInProgress(
address indexed _feeDistributorAddress
bytes32 indexed _depositId
);

/// @notice Emits when P2P rejects the service for a given FeeDistributor client instance.
/// The client can get a full refund immediately in this case.
/// @param _feeDistributorAddress address of FeeDistributor instance that was associated with the client deposit
/// @param _depositId ID of client deposit (derived from ETH2 WithdrawalCredentials, ETH amount per validator in wei, fee distributor instance address)
/// @param _reason optional reason why P2P decided not to provide service
event P2pOrgUnlimitedEthDepositor__ServiceRejected(
address indexed _feeDistributorAddress,
bytes32 indexed _depositId,
string _reason
);

Expand All @@ -71,74 +81,106 @@ interface IP2pOrgUnlimitedEthDepositor is IERC165 {

/// @notice Send unlimited amount of ETH along with the fixed terms of staking service
/// Callable by clients
/// @param _eth2WithdrawalCredentials ETH2 withdrawal credentials
/// @param _ethAmountPerValidatorInWei amount of ETH to deposit per 1 validator (should be >= 32 and <= 2048)
/// @param _referenceFeeDistributor address of FeeDistributor template that determines the terms of staking service
/// @param _clientConfig address and basis points (percent * 100) of the client
/// @param _referrerConfig address and basis points (percent * 100) of the referrer.
/// @return feeDistributorInstance client FeeDistributor instance corresponding to the passed template
/// @param _extraData any other data to pass to the event listener
/// @return depositId ID of client deposit (derived from ETH2 WithdrawalCredentials, ETH amount per validator in wei, fee distributor instance address)
function addEth(
bytes32 _eth2WithdrawalCredentials,
uint96 _ethAmountPerValidatorInWei,

address _referenceFeeDistributor,
FeeRecipient calldata _clientConfig,
FeeRecipient calldata _referrerConfig
) external payable returns(address feeDistributorInstance);
FeeRecipient calldata _referrerConfig,

/// @notice Reject the service for a given FeeDistributor client instance.
bytes calldata _extraData
) external payable returns(bytes32 depositId);

/// @notice Reject the service for a given ID of client deposit.
/// @dev Allows the client to avoid waiting for expiration to get a refund.
/// @dev Can be helpful if the client made a mistake while adding ETH.
/// @dev Callable by P2P
/// @param _feeDistributorInstance client FeeDistributor instance corresponding to the passed template
/// @param _depositId ID of client deposit (derived from ETH2 WithdrawalCredentials, ETH amount per validator in wei, fee distributor instance address)
/// @param _reason optional reason why P2P decided not to provide service
function rejectService(
address _feeDistributorInstance,
bytes32 _depositId,
string calldata _reason
) external;

/// @notice refund the unused for staking ETH after the expiration timestamp.
/// If not called, all multiples of 32 ETH will be used for staking eventually.
/// @param _eth2WithdrawalCredentials ETH2 withdrawal credentials
/// @param _ethAmountPerValidatorInWei amount of ETH to deposit per 1 validator (should be >= 32 and <= 2048)
/// @param _feeDistributorInstance client FeeDistributor instance that has non-zero ETH amount (can be checked by `depositAmount`)
function refund(address _feeDistributorInstance) external;

/// @notice Send ETH to ETH2 DepositContract on behalf of the client. Callable by P2P
/// @param _feeDistributorInstance user FeeDistributor instance that determines the terms of staking service
/// @param _pubkeys BLS12-381 public keys
/// @param _signatures BLS12-381 signatures
/// @param _depositDataRoots SHA-256 hashes of the SSZ-encoded DepositData objects
function makeBeaconDeposit(
address _feeDistributorInstance,
bytes[] calldata _pubkeys,
bytes[] calldata _signatures,
bytes32[] calldata _depositDataRoots
function refund(
bytes32 _eth2WithdrawalCredentials,
uint96 _ethAmountPerValidatorInWei,
address _feeDistributorInstance
) external;

/// @notice Send ETH to ETH2 DepositContract on behalf of the client. Callable by P2P
/// @param _eth2WithdrawalCredentials ETH2 withdrawal credentials
/// @param _ethAmountPerValidatorInWei amount of ETH to deposit per 1 validator (should be >= 32 and <= 2048)
/// @param _feeDistributorInstance user FeeDistributor instance that determines the terms of staking service
/// @param _pubkeys BLS12-381 public keys
/// @param _signatures BLS12-381 signatures
/// @param _depositDataRoots SHA-256 hashes of the SSZ-encoded DepositData objects
/// @param _ethAmountPerValidator amount of ETH to deposit per 1 validator (should be >= 32 and <= 2048)
function makeBeaconDeposit(
bytes32 _eth2WithdrawalCredentials,
uint96 _ethAmountPerValidatorInWei,
address _feeDistributorInstance,

bytes[] calldata _pubkeys,
bytes[] calldata _signatures,
bytes32[] calldata _depositDataRoots,
uint256 _ethAmountPerValidator
bytes32[] calldata _depositDataRoots
) external;

/// @notice Returns the total contract ETH balance in wei
/// @return uint256 total contract ETH balance in wei
function totalBalance() external view returns (uint256);

/// @notice Returns the ID of client deposit
/// @param _eth2WithdrawalCredentials ETH2 withdrawal credentials
/// @param _ethAmountPerValidatorInWei amount of ETH to deposit per 1 validator (should be >= 32 and <= 2048)
/// @param _feeDistributorInstance user FeeDistributor instance that determines the terms of staking service
/// @return bytes32 deposit ID
function getDepositId(
bytes32 _eth2WithdrawalCredentials,
uint96 _ethAmountPerValidatorInWei,
address _feeDistributorInstance
) external view returns (bytes32);

/// @notice Returns the ID of client deposit
/// @param _eth2WithdrawalCredentials ETH2 withdrawal credentials
/// @param _ethAmountPerValidatorInWei amount of ETH to deposit per 1 validator (should be >= 32 and <= 2048)
/// @param _referenceFeeDistributor address of FeeDistributor template that determines the terms of staking service
/// @param _clientConfig address and basis points (percent * 100) of the client
/// @param _referrerConfig address and basis points (percent * 100) of the referrer.
/// @return bytes32 deposit ID
function getDepositId(
bytes32 _eth2WithdrawalCredentials,
uint96 _ethAmountPerValidatorInWei,

address _referenceFeeDistributor,
FeeRecipient calldata _clientConfig,
FeeRecipient calldata _referrerConfig
) external view returns (bytes32);

/// @notice Returns the amount of ETH in wei that is associated with a client FeeDistributor instance
/// @param _feeDistributorInstance address of client FeeDistributor instance
/// @param _depositId ID of client deposit (derived from ETH2 WithdrawalCredentials, ETH amount per validator in wei, fee distributor instance address)
/// @return uint112 amount of ETH in wei
function depositAmount(address _feeDistributorInstance) external view returns (uint112);
function depositAmount(bytes32 _depositId) external view returns (uint112);

/// @notice Returns the block timestamp after which the client will be able to get a refund
/// @param _feeDistributorInstance address of client FeeDistributor instance
/// @param _depositId ID of client deposit (derived from ETH2 WithdrawalCredentials, ETH amount per validator in wei, fee distributor instance address)
/// @return uint40 block timestamp
function depositExpiration(address _feeDistributorInstance) external view returns (uint40);
function depositExpiration(bytes32 _depositId) external view returns (uint40);

/// @notice Returns the status of the deposit
/// @param _feeDistributorInstance address of client FeeDistributor instance
/// @param _depositId ID of client deposit (derived from ETH2 WithdrawalCredentials, ETH amount per validator in wei, fee distributor instance address)
/// @return ClientDepositStatus status
function depositStatus(address _feeDistributorInstance) external view returns (ClientDepositStatus);
function depositStatus(bytes32 _depositId) external view returns (ClientDepositStatus);
}
Loading

0 comments on commit ae4c51c

Please sign in to comment.