Skip to content

Commit

Permalink
feat: upgrade MevCommitAVS to v3 on Holesky (#399)
Browse files Browse the repository at this point in the history
* Create MevCommitAVSV3.sol

* integrate v3 contract w/ tests

* abi + binding for new contract

* upgrade script
  • Loading branch information
shaspitz authored Sep 11, 2024
1 parent 92b1efb commit 9407e4b
Show file tree
Hide file tree
Showing 9 changed files with 8,401 additions and 8 deletions.
1,564 changes: 1,564 additions & 0 deletions contracts-abi/abi/MevCommitAVSV3.abi

Large diffs are not rendered by default.

5,804 changes: 5,804 additions & 0 deletions contracts-abi/clients/MevCommitAVSV3/MevCommitAVSV3.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions contracts-abi/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ extract_and_save_abi "$BASE_DIR/out/BlockTracker.sol/BlockTracker.json" "$ABI_DI

extract_and_save_abi "$BASE_DIR/out/MevCommitAVS.sol/MevCommitAVS.json" "$ABI_DIR/MevCommitAVS.abi"

extract_and_save_abi "$BASE_DIR/out/MevCommitAVSV3.sol/MevCommitAVSV3.json" "$ABI_DIR/MevCommitAVSV3.abi"

extract_and_save_abi "$BASE_DIR/out/ValidatorOptInRouter.sol/ValidatorOptInRouter.json" "$ABI_DIR/ValidatorOptInRouter.abi"

echo "ABI files extracted successfully."
Expand Down Expand Up @@ -89,6 +91,8 @@ generate_go_code "$ABI_DIR/BlockTracker.abi" "BlockTracker" "blocktracker"

generate_go_code "$ABI_DIR/MevCommitAVS.abi" "MevCommitAVS" "mevcommitavs"

generate_go_code "$ABI_DIR/MevCommitAVSV3.abi" "MevCommitAVSV3" "mevcommitavsv3"

generate_go_code "$ABI_DIR/ValidatorOptInRouter.abi" "ValidatorOptInRouter" "validatoroptinrouter"

echo "Go code generated successfully in separate folders."
Expand Down
8 changes: 8 additions & 0 deletions contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ upgrade-avs-anvil:
--via-ir \
--broadcast

upgrade-avs-anvil-v2-to-v3:
forge clean
forge script scripts/validator-registry/avs/UpgradeAVSV2ToV3.s.sol:UpgradeAnvil \
--rpc-url http://localhost:8545 \
--private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
--via-ir \
--broadcast

run-stake-example:
forge script scripts/validator-registry/ValidatorExampleScript.s.sol:StakeExample --rpc-url http://localhost:8545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --via-ir --broadcast

Expand Down
211 changes: 211 additions & 0 deletions contracts/contracts/interfaces/IMevCommitAVSV3.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
// SPDX-License-Identifier: BSL 1.1
pragma solidity 0.8.20;

import {ISignatureUtils} from "eigenlayer-contracts/src/contracts/interfaces/ISignatureUtils.sol";
import {EventHeightLib} from "../utils/EventHeight.sol";
import {IDelegationManager} from "eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";
import {IEigenPodManager} from "eigenlayer-contracts/src/contracts/interfaces/IEigenPodManager.sol";
import {IStrategyManager} from "eigenlayer-contracts/src/contracts/interfaces/IStrategyManager.sol";
import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";

/// @title IMevCommitAVSV3
/// @notice Interface for MevCommitAVSV3, incorporating changes from https://github.com/primev/mev-commit/pull/393.
interface IMevCommitAVSV3 {

/// @notice Struct representing MevCommitAVS registration info for an operator
struct OperatorRegistrationInfo {
/// @notice Whether the operator is registered with MevCommitAVS
bool exists;
/// @notice Height at which the operator possibly requested deregistration
EventHeightLib.EventHeight deregRequestHeight;
}

/// @notice Struct representing MevCommitAVS registration info for a validator
struct ValidatorRegistrationInfo {
/// @notice Whether the validator is registered with MevCommitAVS
bool exists;
/// @notice Address of the pod owner for the validator
address podOwner;
/// @notice Height at which the validator was possibly frozen
EventHeightLib.EventHeight freezeHeight;
/// @notice Height at which the validator possibly requested deregistration
EventHeightLib.EventHeight deregRequestHeight;
}

/// @notice Struct representing MevCommitAVS registration info for a LST restaker
struct LSTRestakerRegistrationInfo {
/// @notice Whether the LST restaker is registered with MevCommitAVS
bool exists;
/// @notice Address of validator(s) chosen by the LST restaker, which equally represent the restaker
bytes[] chosenValidators;
/// @notice Total number of validators chosen by the LST restaker, where attribution is split evenly
uint256 numChosen;
/// @notice Height at which the LST restaker possibly requested deregistration
EventHeightLib.EventHeight deregRequestHeight;
}

/// @notice Emmitted when an operator is registered with MevCommitAVS
event OperatorRegistered(address indexed operator);

/// @notice Emmitted when a deregistration request is made for an operator
event OperatorDeregistrationRequested(address indexed operator);

/// @notice Emmitted when an operator is deregistered from MevCommitAVS
event OperatorDeregistered(address indexed operator);

/// @notice Emmitted when a validator is registered with MevCommitAVS
event ValidatorRegistered(bytes validatorPubKey, address indexed podOwner);

/// @notice Emmitted when a deregistration request is made for a validator
event ValidatorDeregistrationRequested(bytes validatorPubKey, address indexed podOwner);

/// @notice Emmitted when a validator is deregistered from MevCommitAVS
event ValidatorDeregistered(bytes validatorPubKey, address indexed podOwner);

/// @notice Emmitted when a LST restaker registers (chooses a validator) with MevCommitAVS
/// @dev numChosen is the total number of validators chosen by the LST restaker, where attribution is split evenly.
event LSTRestakerRegistered(bytes chosenValidator, uint256 numChosen, address indexed lstRestaker);

/// @notice Emmitted when a deregistration request is made by an LST restaker
/// @dev numChosen is the total number of validators chosen by the LST restaker, where attribution is split evenly.
event LSTRestakerDeregistrationRequested(bytes chosenValidator, uint256 numChosen, address indexed lstRestaker);

/// @notice Emmitted when a LST restaker is deregistered from MevCommitAVS
/// @dev numChosen is the total number of validators chosen by the LST restaker, where attribution is split evenly.
event LSTRestakerDeregistered(bytes chosenValidator, uint256 numChosen, address indexed lstRestaker);

/// @notice Emmitted when a validator is frozen by the oracle
event ValidatorFrozen(bytes validatorPubKey, address indexed podOwner);

/// @notice Emmitted when a validator is unfrozen
event ValidatorUnfrozen(bytes validatorPubKey, address indexed podOwner);

/// @notice Emitted when the AVS directory is set
event AVSDirectorySet(address indexed avsDirectory);

/// @notice Emitted when the strategy manager is set
event StrategyManagerSet(address indexed strategyManager);

/// @notice Emitted when the delegation manager is set
event DelegationManagerSet(address indexed delegationManager);

/// @notice Emitted when the EigenPod manager is set
event EigenPodManagerSet(address indexed eigenPodManager);

/// @notice Emitted when the restakeable strategies are set
event RestakeableStrategiesSet(address[] indexed restakeableStrategies);

/// @notice Emitted when the freeze oracle is set
event FreezeOracleSet(address indexed freezeOracle);

/// @notice Emitted when the unfreeze fee is set
event UnfreezeFeeSet(uint256 unfreezeFee);

/// @notice Emitted when the unfreeze receiver is set
event UnfreezeReceiverSet(address indexed unfreezeReceiver);

/// @notice Emitted when the unfreeze period is set
event UnfreezePeriodBlocksSet(uint256 unfreezePeriodBlocks);

/// @notice Emitted when the operator deregistration period is set
event OperatorDeregPeriodBlocksSet(uint256 operatorDeregPeriodBlocks);

/// @notice Emitted when the validator deregistration period is set
event ValidatorDeregPeriodBlocksSet(uint256 validatorDeregPeriodBlocks);

/// @notice Emitted when the LST restaker deregistration period is set
event LSTRestakerDeregPeriodBlocksSet(uint256 lstRestakerDeregPeriodBlocks);

/// @dev Registers an operator with the MevCommitAVS.
function registerOperator(ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature) external;

/// @dev Allows an operator to request deregistration from the MevCommitAVS.
function requestOperatorDeregistration(address operator) external;

/// @dev Allows an operator to deregister from the MevCommitAVS.
function deregisterOperator(address operator) external;

/// @dev Registers sets of validator pubkeys associated to one or more pod owners.
function registerValidatorsByPodOwners(bytes[][] calldata valPubKeys, address[] calldata podOwners) external;

/// @dev Allows a validator to request deregistration from the MevCommitAVS.
function requestValidatorsDeregistration(bytes[] calldata valPubKeys) external;

/// @dev Allows a validator to deregister from the MevCommitAVS.
function deregisterValidators(bytes[] calldata valPubKeys) external;

/// @dev Registers sender as an LST restaker with chosen validators.
function registerLSTRestaker(bytes[] calldata chosenValidators) external;

/// @dev Allows an LST restaker to request deregistration from the MevCommitAVS.
function requestLSTRestakerDeregistration() external;

/// @dev Allows an LST restaker to deregister from the MevCommitAVS.
function deregisterLSTRestaker() external;

/// @dev Allows the freeze oracle account to freeze validators which disobey the mev-commit protocol.
function freeze(bytes[] calldata valPubKeys) external;

/// @dev Allows any account to unfreeze validators which have been frozen, for a fee.
function unfreeze(bytes[] calldata valPubKeys) external payable;

/// @dev Pauses the contract, restricted to contract owner.
function pause() external;

/// @dev Unpauses the contract, restricted to contract owner.
function unpause() external;

/// @dev Sets the AVS directory, restricted to contract owner.
function setAVSDirectory(IAVSDirectory avsDirectory_) external;

/// @dev Sets the strategy manager, restricted to contract owner.
function setStrategyManager(IStrategyManager strategyManager_) external;

/// @dev Sets the delegation manager, restricted to contract owner.
function setDelegationManager(IDelegationManager delegationManager_) external;

/// @dev Sets the EigenPod manager, restricted to contract owner.
function setEigenPodManager(IEigenPodManager eigenPodManager_) external;

/// @dev Sets the restakeable strategies, restricted to contract owner.
function setRestakeableStrategies(address[] calldata restakeableStrategies_) external;

/// @dev Sets the freeze oracle account, restricted to contract owner.
function setFreezeOracle(address freezeOracle_) external;

/// @dev Sets the unfreeze fee, restricted to contract owner.
function setUnfreezeFee(uint256 unfreezeFee_) external;

/// @dev Sets the unfreeze receiver, restricted to contract owner.
function setUnfreezeReceiver(address unfreezeReceiver_) external;

/// @dev Sets the unfreeze period in blocks, restricted to contract owner.
function setUnfreezePeriodBlocks(uint256 unfreezePeriodBlocks_) external;

/// @dev Sets the operator deregistration period in blocks, restricted to contract owner.
function setOperatorDeregPeriodBlocks(uint256 operatorDeregPeriodBlocks_) external;

/// @dev Sets the validator deregistration period in blocks, restricted to contract owner.
function setValidatorDeregPeriodBlocks(uint256 validatorDeregPeriodBlocks_) external;

/// @dev Sets the LST restaker deregistration period in blocks, restricted to contract owner.
function setLstRestakerDeregPeriodBlocks(uint256 lstRestakerDeregPeriodBlocks_) external;

/// @dev Updates the eigenlayer metadata URI, restricted to contract owner.
function updateMetadataURI(string memory metadataURI_) external;

/// @dev Checks if a validator is opted-in.
function isValidatorOptedIn(bytes calldata valPubKey) external view returns (bool);

/// @dev Returns operator registration info.
function getOperatorRegInfo(address operator) external view returns (OperatorRegistrationInfo memory);

/// @dev Returns validator registration info.
function getValidatorRegInfo(bytes calldata valPubKey) external view returns (ValidatorRegistrationInfo memory);

/// @dev Returns LST restaker registration info.
function getLSTRestakerRegInfo(address lstRestaker) external view returns (LSTRestakerRegistrationInfo memory);

/// @dev Returns the address of AVS directory.
function avsDirectory() external view returns (address);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: BSL 1.1
pragma solidity 0.8.20;


import {IMevCommitAVSV3} from "../../interfaces/IMevCommitAVSV3.sol";
import {IDelegationManager} from "eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";
import {IEigenPodManager} from "eigenlayer-contracts/src/contracts/interfaces/IEigenPodManager.sol";
import {IStrategyManager} from "eigenlayer-contracts/src/contracts/interfaces/IStrategyManager.sol";
import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";

abstract contract MevCommitAVSStorageV3 {

/// @notice reference to eigenlayer core delegation manager contract
IDelegationManager internal _delegationManager;

/// @notice reference to eigenlayer core eigenpod manager contract
IEigenPodManager internal _eigenPodManager;

/// @notice reference to eigenlayer core strategy manager contract
IStrategyManager internal _strategyManager;

/// @notice reference to eigenlayer core AVS directory contract
IAVSDirectory internal _eigenAVSDirectory;

/// @notice Mapping of operator addresses to their registration info
mapping(address => IMevCommitAVSV3.OperatorRegistrationInfo) public operatorRegistrations;

/// @notice Mapping of validator pubkeys to their registration info
mapping(bytes => IMevCommitAVSV3.ValidatorRegistrationInfo) public validatorRegistrations;

/// @notice Mapping of LST restaker address to their registration info
mapping(address => IMevCommitAVSV3.LSTRestakerRegistrationInfo) public lstRestakerRegistrations;

/// @notice List of restakeable strategy addresses
address[] public restakeableStrategies;

/// @notice Address of the oracle responsible for freezing validators.
address public freezeOracle;

/// @notice Fee required to unfreeze a validator.
uint256 public unfreezeFee;

/// @notice Address that will receive unfreeze fees from frozen validators.
address public unfreezeReceiver;

/**
* @notice Number of blocks a validator must remain frozen before it can be unfrozen.
* This is param is optional to allow frozen validators to pay the fee immediately.
*/
uint256 public unfreezePeriodBlocks;

/// @notice Number of blocks an operator must wait after requesting deregistration before it is finalized.
uint256 public operatorDeregPeriodBlocks;

/// @notice Number of blocks a validator must wait after requesting deregistration before it is finalized.
uint256 public validatorDeregPeriodBlocks;

/// @notice Number of blocks a LST restaker must wait after requesting deregistration before it is finalized.
uint256 public lstRestakerDeregPeriodBlocks;
}
Loading

0 comments on commit 9407e4b

Please sign in to comment.