Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ObolValidatorManager #154

Merged
merged 6 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,36 @@
pragma solidity ^0.8.19;

import "forge-std/Script.sol";
import {OptimisticWithdrawalRecipientV2Factory} from "../src/owr/OptimisticWithdrawalRecipientV2Factory.sol";
import {ObolValidatorManagerFactory} from "../src/ovm/ObolValidatorManagerFactory.sol";

//
// This script creates a new OptimisticWithdrawalRecipientV2 contract.
// This script creates a new ObolValidatorManager contract.
// To run this script, the following environment variables must be set:
// - PRIVATE_KEY: the private key of the account that will deploy the contract
// Example usage:
// forge script script/CreateOWRecipientScript.s.sol --sig "run(address)" \
// forge script script/CreateObolValidatorManagerScript.s.sol --sig "run(address)" \
// --rpc-url https://rpc.pectra-devnet-5.ethpandaops.io/ --broadcast "<factory_address>"
//
contract CreateOWRecipientScript is Script {
contract CreateObolValidatorManagerScript is Script {
function run(address deployedOWRV2Factory) external {
uint256 privKey = vm.envUint("PRIVATE_KEY");

vm.startBroadcast(privKey);

OptimisticWithdrawalRecipientV2Factory factory = OptimisticWithdrawalRecipientV2Factory(deployedOWRV2Factory);
ObolValidatorManagerFactory factory = ObolValidatorManagerFactory(deployedOWRV2Factory);

address owner = msg.sender;
address recoveryAddress = msg.sender;
address principalRecipient = msg.sender;
address rewardsRecipient = msg.sender;
uint256 trancheThreshold = 16 ether;
address owner = msg.sender;
uint64 principalThreshold = 16 ether / 1 gwei;

// Call the createOWRecipient function
factory.createOWRecipient(
recoveryAddress,
factory.createObolValidatorManager(
owner,
principalRecipient,
rewardsRecipient,
trancheThreshold,
owner
recoveryAddress,
principalThreshold
);

vm.stopBroadcast();
Expand Down
8 changes: 4 additions & 4 deletions script/DistributeFunds.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pragma solidity ^0.8.19;

import "forge-std/Script.sol";
import {OptimisticWithdrawalRecipientV2} from "src/owr/OptimisticWithdrawalRecipientV2.sol";
import {ObolValidatorManager} from "src/ovm/ObolValidatorManager.sol";

//
// This script calls distributeFunds() for a OptimisticWithdrawalRecipientV2 contract.
// This script calls distributeFunds() for a ObolValidatorManager contract.
// To run this script, the following environment variables must be set:
// - PRIVATE_KEY: the private key of the account that will deploy the contract
// Example usage:
Expand All @@ -18,8 +18,8 @@ contract DistributeFunds is Script {

vm.startBroadcast(privKey);

OptimisticWithdrawalRecipientV2 owr = OptimisticWithdrawalRecipientV2(deployedOWRV2);
owr.distributeFunds();
ObolValidatorManager ovm = ObolValidatorManager(payable(deployedOWRV2));
ovm.distributeFunds();

vm.stopBroadcast();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@
pragma solidity ^0.8.19;

import "forge-std/Script.sol";
import {OptimisticWithdrawalRecipientV2Factory} from "src/owr/OptimisticWithdrawalRecipientV2Factory.sol";
import "forge-std/console.sol";
import {ObolValidatorManagerFactory} from "src/ovm/ObolValidatorManagerFactory.sol";

//
// This script deploys a new OptimisticWithdrawalRecipientV2Factory contract.
// This script deploys a new ObolValidatorManagerFactory contract.
// To run this script, the following environment variables must be set:
// - PRIVATE_KEY: the private key of the account that will deploy the contract
// Please set ensReverseRegistrar before running this script.
// Example usage:
// forge script script/OWRV2FactoryScript.s.sol --sig "run(string)"
// forge script script/ObolValidatorManagerFactoryScript.s.sol --sig "run(string)"
// --rpc-url https://rpc.pectra-devnet-5.ethpandaops.io/ --broadcast "demo"
//
contract OWRV2FactoryScript is Script {
contract ObolValidatorManagerFactoryScript is Script {
// From https://github.com/ethereum/EIPs/blob/d96625a4dcbbe2572fa006f062bd02b4582eefd5/EIPS/eip-7251.md#execution-layer
address constant consolidationSysContract = 0x00431F263cE400f4455c2dCf564e53007Ca4bbBb;
// From https://github.com/ethereum/EIPs/blob/d96625a4dcbbe2572fa006f062bd02b4582eefd5/EIPS/eip-7002.md#configuration
address constant withdrawalSysContract = 0x0c15F14308530b7CDB8460094BbB9cC28b9AaaAA;

// By default the script is aiming devnet-6 (7072151312)
address constant depositSysContract = 0x4242424242424242424242424242424242424242;
// TBD
address ensReverseRegistrar = address(0x0);

Expand All @@ -28,17 +30,24 @@ contract OWRV2FactoryScript is Script {
if (ensReverseRegistrar == address(0x0)) {
revert("ensReverseRegistrar not set");
}

if (block.chainid != 7072151312) { // devnet-6
revert("update deposit contract address and chain id");
}

vm.startBroadcast(privKey);

new OptimisticWithdrawalRecipientV2Factory{salt: keccak256(bytes(name))}(
ObolValidatorManagerFactory factory = new ObolValidatorManagerFactory{salt: keccak256(bytes(name))}(
consolidationSysContract,
withdrawalSysContract,
depositSysContract,
name,
ensReverseRegistrar,
msg.sender,
consolidationSysContract,
withdrawalSysContract
msg.sender
);

console.log('ObolValidatorManagerFactory deployed at: ', address(factory));

vm.stopBroadcast();
}
}
8 changes: 4 additions & 4 deletions script/RequestConsolidation.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pragma solidity ^0.8.19;

import "forge-std/Script.sol";
import {OptimisticWithdrawalRecipientV2} from "src/owr/OptimisticWithdrawalRecipientV2.sol";
import {ObolValidatorManager} from "src/ovm/ObolValidatorManager.sol";

//
// This script calls requestConsolidation() for a OptimisticWithdrawalRecipientV2 contract.
// This script calls requestConsolidation() for a ObolValidatorManager contract.
// To run this script, the following environment variables must be set:
// - PRIVATE_KEY: the private key of the account that will deploy the contract
// Example usage:
Expand All @@ -19,14 +19,14 @@ contract RequestConsolidation is Script {

vm.startBroadcast(privKey);

OptimisticWithdrawalRecipientV2 owr = OptimisticWithdrawalRecipientV2(owrv2);
ObolValidatorManager ovm = ObolValidatorManager(payable(owrv2));

// Call the function on the deployed contract
bytes[] memory sourcePubKeys = new bytes[](1);
sourcePubKeys[0] = src;

// Estimated total gas used for script: 162523
owr.requestConsolidation{value: 100 wei}(sourcePubKeys, dst);
ovm.requestConsolidation{value: 100 wei}(sourcePubKeys, dst);

vm.stopBroadcast();
}
Expand Down
8 changes: 4 additions & 4 deletions script/RequestWithdrawal.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pragma solidity ^0.8.19;

import "forge-std/Script.sol";
import {OptimisticWithdrawalRecipientV2} from "src/owr/OptimisticWithdrawalRecipientV2.sol";
import {ObolValidatorManager} from "src/ovm/ObolValidatorManager.sol";

//
// This script calls requestWithdrawal() for a OptimisticWithdrawalRecipientV2 contract.
// This script calls requestWithdrawal() for a ObolValidatorManager contract.
// To run this script, the following environment variables must be set:
// - PRIVATE_KEY: the private key of the account that will deploy the contract
// Example usage:
Expand All @@ -19,7 +19,7 @@ contract RequestWithdrawal is Script {

vm.startBroadcast(privKey);

OptimisticWithdrawalRecipientV2 owr = OptimisticWithdrawalRecipientV2(owrv2);
ObolValidatorManager ovm = ObolValidatorManager(payable(owrv2));

bytes[] memory pubKeys = new bytes[](1);
pubKeys[0] = pubkey;
Expand All @@ -28,7 +28,7 @@ contract RequestWithdrawal is Script {
amounts[0] = amount;

// Estimated total gas used for script: 219325
owr.requestWithdrawal{value: 100 wei}(pubKeys, amounts);
ovm.requestWithdrawal{value: 100 wei}(pubKeys, amounts);

vm.stopBroadcast();
}
Expand Down
48 changes: 48 additions & 0 deletions src/interfaces/IDepositContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// ┏━━━┓━┏┓━┏┓━━┏━━━┓━━┏━━━┓━━━━┏━━━┓━━━━━━━━━━━━━━━━━━━┏┓━━━━━┏━━━┓━━━━━━━━━┏┓━━━━━━━━━━━━━━┏┓━
// ┃┏━━┛┏┛┗┓┃┃━━┃┏━┓┃━━┃┏━┓┃━━━━┗┓┏┓┃━━━━━━━━━━━━━━━━━━┏┛┗┓━━━━┃┏━┓┃━━━━━━━━┏┛┗┓━━━━━━━━━━━━┏┛┗┓
// ┃┗━━┓┗┓┏┛┃┗━┓┗┛┏┛┃━━┃┃━┃┃━━━━━┃┃┃┃┏━━┓┏━━┓┏━━┓┏━━┓┏┓┗┓┏┛━━━━┃┃━┗┛┏━━┓┏━┓━┗┓┏┛┏━┓┏━━┓━┏━━┓┗┓┏┛
// ┃┏━━┛━┃┃━┃┏┓┃┏━┛┏┛━━┃┃━┃┃━━━━━┃┃┃┃┃┏┓┃┃┏┓┃┃┏┓┃┃━━┫┣┫━┃┃━━━━━┃┃━┏┓┃┏┓┃┃┏┓┓━┃┃━┃┏┛┗━┓┃━┃┏━┛━┃┃━
// ┃┗━━┓━┃┗┓┃┃┃┃┃┃┗━┓┏┓┃┗━┛┃━━━━┏┛┗┛┃┃┃━┫┃┗┛┃┃┗┛┃┣━━┃┃┃━┃┗┓━━━━┃┗━┛┃┃┗┛┃┃┃┃┃━┃┗┓┃┃━┃┗┛┗┓┃┗━┓━┃┗┓
// ┗━━━┛━┗━┛┗┛┗┛┗━━━┛┗┛┗━━━┛━━━━┗━━━┛┗━━┛┃┏━┛┗━━┛┗━━┛┗┛━┗━┛━━━━┗━━━┛┗━━┛┗┛┗┛━┗━┛┗┛━┗━━━┛┗━━┛━┗━┛
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┃┃━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┗┛━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

// SPDX-License-Identifier: CC0-1.0

// pragma solidity 0.6.11 was the original version
pragma solidity 0.8.19;

// This interface is designed to be compatible with the Vyper version.
/// @notice This is the Ethereum 2.0 deposit contract interface.
/// For more information see the Phase 0 specification under https://github.com/ethereum/eth2.0-specs
interface IDepositContract {
/// @notice A processed deposit event.
event DepositEvent(
bytes pubkey,
bytes withdrawal_credentials,
bytes amount,
bytes signature,
bytes index
);

/// @notice Submit a Phase 0 DepositData object.
/// @param pubkey A BLS12-381 public key.
/// @param withdrawal_credentials Commitment to a public key for withdrawals.
/// @param signature A BLS12-381 signature.
/// @param deposit_data_root The SHA-256 hash of the SSZ-encoded DepositData object.
/// Used as a protection against malformed input.
function deposit(
bytes calldata pubkey,
bytes calldata withdrawal_credentials,
bytes calldata signature,
bytes32 deposit_data_root
) external payable;

/// @notice Query the current deposit root hash.
/// @return The deposit root hash.
function get_deposit_root() external view returns (bytes32);

/// @notice Query the current deposit count.
/// @return The deposit count encoded as a little endian 64-bit number.
function get_deposit_count() external view returns (bytes memory);
}
Loading