diff --git a/contracts/validator-manager/ACP99ValidatorManager.sol b/contracts/validator-manager/ACP99ValidatorManager.sol index 9a4078d40..711b7991b 100644 --- a/contracts/validator-manager/ACP99ValidatorManager.sol +++ b/contracts/validator-manager/ACP99ValidatorManager.sol @@ -5,11 +5,11 @@ import {IACP99SecurityModule} from "./interfaces/IACP99SecurityModule.sol"; import {ValidatorManager} from "./ValidatorManager.sol"; -import {ConversionData,ValidatorRegistrationInput} from "./interfaces/IValidatorManager.sol"; +import {IACP99ValidatorManager, ConversionData, ValidatorRegistrationInput} from "./interfaces/IACP99ValidatorManager.sol"; pragma solidity 0.8.25; -abstract contract ACP99ValidatorManager is ValidatorManager { +abstract contract ACP99ValidatorManager is IACP99ValidatorManager, ValidatorManager { IACP99SecurityModule public securityModule; // TODO: calling this should be restricted to...who? @@ -49,7 +49,11 @@ abstract contract ACP99ValidatorManager is ValidatorManager { securityModule.handleCompleteEndValidation(validationID); } - function initializeValidatorWeightChange() external{} + function initializeValidatorWeightChange(bytes32 validationID, uint64 weight, bytes calldata args) external{ + securityModule.handleInitializeValidatorWeightChange(validationID, weight, args); + } - function completeValidatorWeightChange() external{} + function completeValidatorWeightChange(bytes32 validationID, bytes calldata args) external{ + securityModule.handleCompleteValidatorWeightChange(validationID, args); + } } \ No newline at end of file diff --git a/contracts/validator-manager/ERC20TokenStakingManager.sol b/contracts/validator-manager/ERC20TokenStakingManager.sol index fa8cef2dd..8a637c544 100644 --- a/contracts/validator-manager/ERC20TokenStakingManager.sol +++ b/contracts/validator-manager/ERC20TokenStakingManager.sol @@ -7,8 +7,6 @@ pragma solidity 0.8.25; import {PoSValidatorManager} from "./PoSValidatorManager.sol"; import {PoSValidatorManagerSettings} from "./interfaces/IPoSValidatorManager.sol"; -import {ValidatorRegistrationInput} from "./interfaces/IValidatorManager.sol"; -import {IERC20TokenStakingManager} from "./interfaces/IERC20TokenStakingManager.sol"; import {IERC20Mintable} from "./interfaces/IERC20Mintable.sol"; import {ICMInitializable} from "@utilities/ICMInitializable.sol"; import {SafeERC20TransferFrom} from "@utilities/SafeERC20TransferFrom.sol"; diff --git a/contracts/validator-manager/NativeTokenStakingManager.sol b/contracts/validator-manager/NativeTokenStakingManager.sol index 3cce186a1..4d7f567e5 100644 --- a/contracts/validator-manager/NativeTokenStakingManager.sol +++ b/contracts/validator-manager/NativeTokenStakingManager.sol @@ -7,8 +7,6 @@ pragma solidity 0.8.25; import {PoSValidatorManager} from "./PoSValidatorManager.sol"; import {PoSValidatorManagerSettings} from "./interfaces/IPoSValidatorManager.sol"; -import {ValidatorRegistrationInput} from "./interfaces/IValidatorManager.sol"; -import {INativeTokenStakingManager} from "./interfaces/INativeTokenStakingManager.sol"; import {INativeMinter} from "@avalabs/subnet-evm-contracts@1.2.0/contracts/interfaces/INativeMinter.sol"; import {ICMInitializable} from "@utilities/ICMInitializable.sol"; diff --git a/contracts/validator-manager/PoAValidatorManager.sol b/contracts/validator-manager/PoAValidatorManager.sol index 9f786e6a3..c20ea1079 100644 --- a/contracts/validator-manager/PoAValidatorManager.sol +++ b/contracts/validator-manager/PoAValidatorManager.sol @@ -6,10 +6,8 @@ pragma solidity 0.8.25; import { - ValidatorManagerSettings, - ValidatorRegistrationInput + ValidatorManagerSettings } from "./interfaces/IValidatorManager.sol"; -import {IPoAValidatorManager} from "./interfaces/IPoAValidatorManager.sol"; import {ICMInitializable} from "@utilities/ICMInitializable.sol"; import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable@5.0.2/access/OwnableUpgradeable.sol"; diff --git a/contracts/validator-manager/PoSValidatorManager.sol b/contracts/validator-manager/PoSValidatorManager.sol index 15ba9041b..bb577323f 100644 --- a/contracts/validator-manager/PoSValidatorManager.sol +++ b/contracts/validator-manager/PoSValidatorManager.sol @@ -16,7 +16,6 @@ import { } from "./interfaces/IPoSValidatorManager.sol"; import { Validator, - ValidatorRegistrationInput, ValidatorStatus } from "./interfaces/IValidatorManager.sol"; import {IRewardCalculator} from "./interfaces/IRewardCalculator.sol"; diff --git a/contracts/validator-manager/ValidatorManager.sol b/contracts/validator-manager/ValidatorManager.sol index c6888ef50..7880abd26 100644 --- a/contracts/validator-manager/ValidatorManager.sol +++ b/contracts/validator-manager/ValidatorManager.sol @@ -7,14 +7,10 @@ pragma solidity 0.8.25; import {ValidatorMessages} from "./ValidatorMessages.sol"; import { - InitialValidator, IValidatorManager, - PChainOwner, - ConversionData, Validator, ValidatorChurnPeriod, ValidatorManagerSettings, - ValidatorRegistrationInput, ValidatorStatus } from "./interfaces/IValidatorManager.sol"; import { @@ -26,6 +22,7 @@ import {ContextUpgradeable} from import {Initializable} from "@openzeppelin/contracts-upgradeable@5.0.2/proxy/utils/Initializable.sol"; import {IACP99SecurityModule} from "./interfaces/IACP99SecurityModule.sol"; +import {ValidatorRegistrationInput, ConversionData, PChainOwner, InitialValidator} from "./interfaces/IACP99ValidatorManager.sol"; /** * @dev Implementation of the {IValidatorManager} interface. diff --git a/contracts/validator-manager/ValidatorMessages.sol b/contracts/validator-manager/ValidatorMessages.sol index 9adcdc8aa..0d39c479e 100644 --- a/contracts/validator-manager/ValidatorMessages.sol +++ b/contracts/validator-manager/ValidatorMessages.sol @@ -4,7 +4,7 @@ // SPDX-License-Identifier: Ecosystem pragma solidity 0.8.25; -import {PChainOwner, ConversionData} from "./interfaces/IValidatorManager.sol"; +import {PChainOwner, ConversionData} from "./interfaces/IACP99ValidatorManager.sol"; /** * @dev Packing utilities for the Warp message types used by the Validator Manager contracts, as specified in ACP-77: diff --git a/contracts/validator-manager/interfaces/IACP99ValidatorManager.sol b/contracts/validator-manager/interfaces/IACP99ValidatorManager.sol new file mode 100644 index 000000000..cc9d1ce89 --- /dev/null +++ b/contracts/validator-manager/interfaces/IACP99ValidatorManager.sol @@ -0,0 +1,71 @@ +// (c) 2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +// SPDX-License-Identifier: Ecosystem + +pragma solidity 0.8.25; + +/** + * @dev Specifies the owner of a validator's remaining balance or disable owner on the P-Chain. + * P-Chain addresses are also 20-bytes, so we use the address type to represent them. + */ +struct PChainOwner { + uint32 threshold; + address[] addresses; +} + +/** + * @dev Specifies an initial validator, used in the conversion data. + */ +struct InitialValidator { + bytes nodeID; + bytes blsPublicKey; + uint64 weight; +} + +/** + * @dev Description of the conversion data used to convert + * a subnet to an L1 on the P-Chain. + * This data is the pre-image of a hash that is authenticated by the P-Chain + * and verified by the Validator Manager. + */ +struct ConversionData { + bytes32 subnetID; + bytes32 validatorManagerBlockchainID; + address validatorManagerAddress; + InitialValidator[] initialValidators; +} + +/** + * @dev Specifies a validator to register. + */ +struct ValidatorRegistrationInput { + bytes nodeID; + bytes blsPublicKey; + uint64 registrationExpiry; + PChainOwner remainingBalanceOwner; + PChainOwner disableOwner; +} + +interface IACP99ValidatorManager { + function initializeValidatorSet( + ConversionData calldata conversionData, + uint32 messageIndex + ) external; + + function initializeValidatorRegistration( + ValidatorRegistrationInput calldata input, + uint64 weight, + bytes calldata args + ) external returns (bytes32); + + function completeValidatorRegistration(uint32 messageIndex) external; + + function initializeEndValidation(bytes32 validationID, bytes calldata args) external; + + function completeEndValidation(uint32 messageIndex) external; + + function initializeValidatorWeightChange(bytes32 validationID, uint64 weight, bytes calldata args) external; + + function completeValidatorWeightChange(bytes32 validationID, bytes calldata args) external; +} \ No newline at end of file diff --git a/contracts/validator-manager/interfaces/IERC20TokenStakingManager.sol b/contracts/validator-manager/interfaces/IERC20TokenStakingManager.sol deleted file mode 100644 index eb1b56a32..000000000 --- a/contracts/validator-manager/interfaces/IERC20TokenStakingManager.sol +++ /dev/null @@ -1,38 +0,0 @@ -// (c) 2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -// SPDX-License-Identifier: Ecosystem - -pragma solidity 0.8.25; - -import {ValidatorRegistrationInput} from "./IValidatorManager.sol"; -import {IPoSValidatorManager} from "./IPoSValidatorManager.sol"; - -/** - * Proof of Stake Validator Manager that stakes ERC20 tokens. - */ -interface IERC20TokenStakingManager is IPoSValidatorManager { - /** - * @notice Begins the validator registration process. Locks the specified ERC20 tokens in the contract as the stake. - * @param registrationInput The inputs for a validator registration. - * @param delegationFeeBips The fee that delegators must pay to delegate to this validator. - * @param minStakeDuration The minimum amount of time this validator must be staked for in seconds. - * @param stakeAmount The amount of tokens to stake. - */ - function initializeValidatorRegistration( - ValidatorRegistrationInput calldata registrationInput, - uint16 delegationFeeBips, - uint64 minStakeDuration, - uint256 stakeAmount - ) external returns (bytes32 validationID); - - /** - * @notice Begins the delegator registration process. Locks the specified ERC20 tokens in the contract as the stake. - * @param validationID The ID of the validator to stake to. - * @param stakeAmount The amount of tokens to stake. - */ - function initializeDelegatorRegistration( - bytes32 validationID, - uint256 stakeAmount - ) external returns (bytes32); -} diff --git a/contracts/validator-manager/interfaces/INativeTokenStakingManager.sol b/contracts/validator-manager/interfaces/INativeTokenStakingManager.sol deleted file mode 100644 index c1cc4a2c9..000000000 --- a/contracts/validator-manager/interfaces/INativeTokenStakingManager.sol +++ /dev/null @@ -1,35 +0,0 @@ -// (c) 2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -// SPDX-License-Identifier: Ecosystem - -pragma solidity 0.8.25; - -import {ValidatorRegistrationInput} from "./IValidatorManager.sol"; -import {IPoSValidatorManager} from "./IPoSValidatorManager.sol"; - -/** - * Proof of Stake Validator Manager that stakes the blockchain's native tokens. - */ -interface INativeTokenStakingManager is IPoSValidatorManager { - /** - * @notice Begins the validator registration process. Locks the provided native asset in the contract as the stake. - * @param registrationInput The inputs for a validator registration. - * @param delegationFeeBips The fee that delegators must pay to delegate to this validator. - * @param minStakeDuration The minimum amount of time this validator must be staked for in seconds. - */ - function initializeValidatorRegistration( - ValidatorRegistrationInput calldata registrationInput, - uint16 delegationFeeBips, - uint64 minStakeDuration - ) external payable returns (bytes32 validationID); - - /** - * @notice Begins the delegator registration process. Locks the provided native asset in the contract as the stake. - * @param validationID The ID of the validator to stake to. - */ - function initializeDelegatorRegistration(bytes32 validationID) - external - payable - returns (bytes32); -} diff --git a/contracts/validator-manager/interfaces/IPoAValidatorManager.sol b/contracts/validator-manager/interfaces/IPoAValidatorManager.sol deleted file mode 100644 index 94c1663d3..000000000 --- a/contracts/validator-manager/interfaces/IPoAValidatorManager.sol +++ /dev/null @@ -1,30 +0,0 @@ -// (c) 2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -// SPDX-License-Identifier: Ecosystem - -pragma solidity 0.8.25; - -import {IValidatorManager, ValidatorRegistrationInput} from "./IValidatorManager.sol"; - -/** - * @notice Interface for Proof of Authority Validator Manager contracts - */ -interface IPoAValidatorManager is IValidatorManager { - /** - * @notice Begins the validator registration process, and sets the {weight} of the validator. - * @param registrationInput The inputs for a validator registration. - * @param weight The weight of the validator being registered. - */ - function initializeValidatorRegistration( - ValidatorRegistrationInput calldata registrationInput, - uint64 weight - ) external returns (bytes32 validationID); - - /** - * @notice Begins the process of ending an active validation period. The validation period must have been previously - * started by a successful call to {completeValidatorRegistration} with the given validationID. - * @param validationID The ID of the validation period being ended. - */ - function initializeEndValidation(bytes32 validationID) external; -} diff --git a/contracts/validator-manager/interfaces/IValidatorManager.sol b/contracts/validator-manager/interfaces/IValidatorManager.sol index f04629bf5..a24d3bc22 100644 --- a/contracts/validator-manager/interfaces/IValidatorManager.sol +++ b/contracts/validator-manager/interfaces/IValidatorManager.sol @@ -5,6 +5,8 @@ pragma solidity 0.8.25; +import {ConversionData} from "./IACP99ValidatorManager.sol"; + /** * @dev Validator status */ @@ -17,15 +19,6 @@ enum ValidatorStatus { Invalidated } -/** - * @dev Specifies the owner of a validator's remaining balance or disable owner on the P-Chain. - * P-Chain addresses are also 20-bytes, so we use the address type to represent them. - */ -struct PChainOwner { - uint32 threshold; - address[] addresses; -} - /** * @dev Contains the active state of a Validator */ @@ -61,39 +54,6 @@ struct ValidatorManagerSettings { uint8 maximumChurnPercentage; } -/** - * @dev Description of the conversion data used to convert - * a subnet to an L1 on the P-Chain. - * This data is the pre-image of a hash that is authenticated by the P-Chain - * and verified by the Validator Manager. - */ -struct ConversionData { - bytes32 subnetID; - bytes32 validatorManagerBlockchainID; - address validatorManagerAddress; - InitialValidator[] initialValidators; -} - -/** - * @dev Specifies an initial validator, used in the conversion data. - */ -struct InitialValidator { - bytes nodeID; - bytes blsPublicKey; - uint64 weight; -} - -/** - * @dev Specifies a validator to register. - */ -struct ValidatorRegistrationInput { - bytes nodeID; - bytes blsPublicKey; - uint64 registrationExpiry; - PChainOwner remainingBalanceOwner; - PChainOwner disableOwner; -} - /** * @notice Interface for Validator Manager contracts that implement Subnet-only Validator management. */ @@ -171,16 +131,6 @@ interface IValidatorManager { bytes32 setWeightMessageID ); - /** - * @notice Verifies and sets the initial validator set for the chain through a P-Chain SubnetToL1ConversionMessage. - * @param conversionData The subnet conversion message data used to recompute and verify against the conversionID. - * @param messsageIndex The index that contains the SubnetToL1ConversionMessage Warp message containing the conversionID to be verified against the provided {ConversionData} - */ - function initializeValidatorSet( - ConversionData calldata conversionData, - uint32 messsageIndex - ) external; - /** * @notice Resubmits a validator registration message to be sent to the P-Chain. * Only necessary if the original message can't be delivered due to validator churn. @@ -188,28 +138,10 @@ interface IValidatorManager { */ function resendRegisterValidatorMessage(bytes32 validationID) external; - /** - * @notice Completes the validator registration process by returning an acknowledgement of the registration of a - * validationID from the P-Chain. - * @param messageIndex The index of the Warp message to be received providing the acknowledgement. - */ - function completeValidatorRegistration(uint32 messageIndex) external; - /** * @notice Resubmits a validator end message to be sent to the P-Chain. * Only necessary if the original message can't be delivered due to validator churn. * @param validationID The ID of the validation period being ended. */ function resendEndValidatorMessage(bytes32 validationID) external; - - /** - * @notice Completes the process of ending a validation period by receiving an acknowledgement from the P-Chain - * that the validation ID is not active and will never be active in the future. Returns the the stake associated - * with the validation. - * Note: This function can be used for successful validation periods that have been explicitly ended by calling - * {initializeEndValidation} or for validation periods that never began on the P-Chain due to the {registrationExpiry} being reached. - * @param messageIndex The index of the Warp message to be received providing the proof the validation is not active - * and never will be active on the P-Chain. - */ - function completeEndValidation(uint32 messageIndex) external; }