From 1386def24eb253fb8a5d8d9226083e09c1fe66bd Mon Sep 17 00:00:00 2001 From: Kresh Date: Mon, 23 Sep 2024 23:35:52 +0400 Subject: [PATCH 1/2] feat: change init process --- script/deploy/Vault.s.sol | 30 +- src/contracts/VaultConfigurator.sol | 28 +- src/contracts/common/Entity.sol | 14 - src/contracts/common/Factory.sol | 6 +- src/contracts/common/MigratableEntity.sol | 20 +- src/contracts/common/MigratablesFactory.sol | 11 +- src/contracts/delegator/BaseDelegator.sol | 6 +- .../delegator/FullRestakeDelegator.sol | 7 +- .../delegator/NetworkRestakeDelegator.sol | 7 +- src/contracts/slasher/Slasher.sol | 2 +- src/contracts/slasher/VetoSlasher.sol | 15 +- src/contracts/vault/Vault.sol | 90 +- src/contracts/vault/VaultStorage.sol | 16 +- src/interfaces/IVaultConfigurator.sol | 4 +- src/interfaces/common/IEntity.sol | 6 - src/interfaces/common/IFactory.sol | 5 +- src/interfaces/common/IMigratableEntity.sol | 7 - src/interfaces/common/IMigratablesFactory.sol | 10 +- src/interfaces/vault/IVault.sol | 46 +- src/interfaces/vault/IVaultStorage.sol | 12 + test/DelegatorFactory.t.sol | 32 +- test/POCBase.t.sol | 150 +-- test/SlasherFactory.t.sol | 36 +- test/VaultConfigurator.t.sol | 89 +- test/VaultFactory.t.sol | 30 +- test/common/Entity.t.sol | 22 +- test/common/Factory.t.sol | 6 +- test/common/MigratableEntity.t.sol | 38 +- test/common/MigratableEntityProxy.t.sol | 2 +- test/common/MigratablesFactory.t.sol | 16 +- test/delegator/FullRestakeDelegator.t.sol | 128 ++- test/delegator/NetworkRestakeDelegator.t.sol | 128 ++- test/slasher/Slasher.t.sol | 64 +- test/slasher/VetoSlasher.t.sol | 145 +-- test/vault/Vault.t.sol | 907 +++++++++++------- 35 files changed, 1066 insertions(+), 1069 deletions(-) diff --git a/script/deploy/Vault.s.sol b/script/deploy/Vault.s.sol index 18ec5cb4..e695b9a3 100644 --- a/script/deploy/Vault.s.sol +++ b/script/deploy/Vault.s.sol @@ -36,21 +36,21 @@ contract VaultScript is Script { IVaultConfigurator.InitParams({ version: IMigratablesFactory(IVaultConfigurator(vaultConfigurator).VAULT_FACTORY()).lastVersion(), owner: owner, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: depositWhitelist, - isDepositLimit: depositLimit != 0, - depositLimit: depositLimit, - defaultAdminRoleHolder: owner, - depositWhitelistSetRoleHolder: owner, - depositorWhitelistRoleHolder: owner, - isDepositLimitSetRoleHolder: owner, - depositLimitSetRoleHolder: owner - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: depositWhitelist, + isDepositLimit: depositLimit != 0, + depositLimit: depositLimit, + defaultAdminRoleHolder: owner, + depositWhitelistSetRoleHolder: owner, + depositorWhitelistRoleHolder: owner, + isDepositLimitSetRoleHolder: owner, + depositLimitSetRoleHolder: owner + }) + ), delegatorIndex: delegatorIndex, delegatorParams: delegatorIndex == 0 ? abi.encode( diff --git a/src/contracts/VaultConfigurator.sol b/src/contracts/VaultConfigurator.sol index 2bff5df2..27c2e05e 100644 --- a/src/contracts/VaultConfigurator.sol +++ b/src/contracts/VaultConfigurator.sol @@ -36,30 +36,18 @@ contract VaultConfigurator is IVaultConfigurator { */ function create( InitParams memory params - ) public returns (address, address, address) { - if (params.vaultParams.delegator != address(0) || params.vaultParams.slasher != address(0)) { - revert DirtyInitParams(); - } - - address vault = - VaultFactory(VAULT_FACTORY).create(params.version, params.owner, false, abi.encode(params.vaultParams)); - - params.vaultParams.delegator = DelegatorFactory(DELEGATOR_FACTORY).create( - params.delegatorIndex, true, abi.encode(vault, params.delegatorParams) - ); - - bytes memory slasherData; - if (params.withSlasher) { - slasherData = abi.encode(vault, params.slasherParams); - params.vaultParams.slasher = SlasherFactory(SLASHER_FACTORY).create(params.slasherIndex, false, slasherData); - } + ) public returns (address vault, address delegator, address slasher) { + vault = VaultFactory(VAULT_FACTORY).create(params.version, params.owner, params.vaultParams); - Vault(vault).initialize(params.version, params.owner, abi.encode(params.vaultParams)); + delegator = + DelegatorFactory(DELEGATOR_FACTORY).create(params.delegatorIndex, abi.encode(vault, params.delegatorParams)); if (params.withSlasher) { - BaseSlasher(params.vaultParams.slasher).initialize(slasherData); + slasher = + SlasherFactory(SLASHER_FACTORY).create(params.slasherIndex, abi.encode(vault, params.slasherParams)); } - return (vault, params.vaultParams.delegator, params.vaultParams.slasher); + Vault(vault).setDelegator(delegator); + Vault(vault).setSlasher(slasher); } } diff --git a/src/contracts/common/Entity.sol b/src/contracts/common/Entity.sol index 435a7ab6..fec30d6c 100644 --- a/src/contracts/common/Entity.sol +++ b/src/contracts/common/Entity.sol @@ -16,13 +16,6 @@ abstract contract Entity is Initializable, IEntity { */ uint64 public immutable TYPE; - modifier initialized() { - if (!isInitialized()) { - revert NotInitialized(); - } - _; - } - constructor(address factory, uint64 type_) { _disableInitializers(); @@ -30,13 +23,6 @@ abstract contract Entity is Initializable, IEntity { TYPE = type_; } - /** - * @inheritdoc IEntity - */ - function isInitialized() public view returns (bool) { - return _getInitializedVersion() != 0; - } - /** * @inheritdoc IEntity */ diff --git a/src/contracts/common/Factory.sol b/src/contracts/common/Factory.sol index 14feedcf..f02a89af 100644 --- a/src/contracts/common/Factory.sol +++ b/src/contracts/common/Factory.sol @@ -84,13 +84,11 @@ contract Factory is Registry, Ownable, IFactory { /** * @inheritdoc IFactory */ - function create(uint64 type_, bool withInitialize, bytes calldata data) external returns (address entity_) { + function create(uint64 type_, bytes calldata data) external returns (address entity_) { entity_ = implementation(type_).cloneDeterministic(keccak256(abi.encode(totalEntities(), type_, data))); _addEntity(entity_); - if (withInitialize) { - IEntity(entity_).initialize(data); - } + IEntity(entity_).initialize(data); } } diff --git a/src/contracts/common/MigratableEntity.sol b/src/contracts/common/MigratableEntity.sol index 8f6d0742..b71c1394 100644 --- a/src/contracts/common/MigratableEntity.sol +++ b/src/contracts/common/MigratableEntity.sol @@ -21,15 +21,8 @@ abstract contract MigratableEntity is address private immutable SELF; - modifier initialized() { - if (!isInitialized()) { - revert NotInitialized(); - } - _; - } - modifier notInitialized() { - if (isInitialized()) { + if (_getInitializedVersion() != 0) { revert AlreadyInitialized(); } @@ -45,13 +38,6 @@ abstract contract MigratableEntity is SELF = address(this); } - /** - * @inheritdoc IMigratableEntity - */ - function isInitialized() public view returns (bool) { - return _getInitializedVersion() != 0; - } - /** * @inheritdoc IMigratableEntity */ @@ -67,10 +53,6 @@ abstract contract MigratableEntity is address owner_, bytes calldata data ) external notInitialized reinitializer(initialVersion) { - if (SELF != IMigratablesFactory(FACTORY).implementation(initialVersion)) { - revert InvalidInitialVersion(); - } - __ReentrancyGuard_init(); if (owner_ != address(0)) { diff --git a/src/contracts/common/MigratablesFactory.sol b/src/contracts/common/MigratablesFactory.sol index 12288f00..fbe32dbf 100644 --- a/src/contracts/common/MigratablesFactory.sol +++ b/src/contracts/common/MigratablesFactory.sol @@ -86,18 +86,11 @@ contract MigratablesFactory is Registry, Ownable, IMigratablesFactory { /** * @inheritdoc IMigratablesFactory */ - function create( - uint64 version, - address owner_, - bool withInitialize, - bytes calldata data - ) external returns (address entity_) { + function create(uint64 version, address owner_, bytes calldata data) external returns (address entity_) { entity_ = address( new MigratableEntityProxy{salt: keccak256(abi.encode(totalEntities(), version, owner_, data))}( implementation(version), - withInitialize - ? abi.encodeWithSelector(IMigratableEntity.initialize.selector, version, owner_, data) - : new bytes(0) + abi.encodeWithSelector(IMigratableEntity.initialize.selector, version, owner_, data) ) ); diff --git a/src/contracts/delegator/BaseDelegator.sol b/src/contracts/delegator/BaseDelegator.sol index 676d020f..6bbf5e8c 100644 --- a/src/contracts/delegator/BaseDelegator.sol +++ b/src/contracts/delegator/BaseDelegator.sol @@ -141,7 +141,7 @@ contract BaseDelegator is /** * @inheritdoc IBaseDelegator */ - function setMaxNetworkLimit(uint96 identifier, uint256 amount) external initialized nonReentrant { + function setMaxNetworkLimit(uint96 identifier, uint256 amount) external nonReentrant { if (!IRegistry(NETWORK_REGISTRY).isEntity(msg.sender)) { revert NotNetwork(); } @@ -163,7 +163,7 @@ contract BaseDelegator is */ function setHook( address hook_ - ) external initialized nonReentrant onlyRole(HOOK_SET_ROLE) { + ) external nonReentrant onlyRole(HOOK_SET_ROLE) { hook = hook_; emit SetHook(hook_); @@ -178,7 +178,7 @@ contract BaseDelegator is uint256 slashedAmount, uint48 captureTimestamp, bytes memory data - ) external initialized nonReentrant { + ) external nonReentrant { if (IVault(vault).slasher() != msg.sender) { revert NotSlasher(); } diff --git a/src/contracts/delegator/FullRestakeDelegator.sol b/src/contracts/delegator/FullRestakeDelegator.sol index 0d6b081a..24415631 100644 --- a/src/contracts/delegator/FullRestakeDelegator.sol +++ b/src/contracts/delegator/FullRestakeDelegator.sol @@ -87,10 +87,7 @@ contract FullRestakeDelegator is BaseDelegator, IFullRestakeDelegator { /** * @inheritdoc IFullRestakeDelegator */ - function setNetworkLimit( - bytes32 subnetwork, - uint256 amount - ) external initialized onlyRole(NETWORK_LIMIT_SET_ROLE) { + function setNetworkLimit(bytes32 subnetwork, uint256 amount) external onlyRole(NETWORK_LIMIT_SET_ROLE) { if (amount > maxNetworkLimit[subnetwork]) { revert ExceedsMaxNetworkLimit(); } @@ -107,7 +104,7 @@ contract FullRestakeDelegator is BaseDelegator, IFullRestakeDelegator { bytes32 subnetwork, address operator, uint256 amount - ) external initialized onlyRole(OPERATOR_NETWORK_LIMIT_SET_ROLE) { + ) external onlyRole(OPERATOR_NETWORK_LIMIT_SET_ROLE) { _operatorNetworkLimit[subnetwork][operator].push(Time.timestamp(), amount); emit SetOperatorNetworkLimit(subnetwork, operator, amount); diff --git a/src/contracts/delegator/NetworkRestakeDelegator.sol b/src/contracts/delegator/NetworkRestakeDelegator.sol index e63f2159..d18f78ed 100644 --- a/src/contracts/delegator/NetworkRestakeDelegator.sol +++ b/src/contracts/delegator/NetworkRestakeDelegator.sol @@ -109,10 +109,7 @@ contract NetworkRestakeDelegator is BaseDelegator, INetworkRestakeDelegator { /** * @inheritdoc INetworkRestakeDelegator */ - function setNetworkLimit( - bytes32 subnetwork, - uint256 amount - ) external initialized onlyRole(NETWORK_LIMIT_SET_ROLE) { + function setNetworkLimit(bytes32 subnetwork, uint256 amount) external onlyRole(NETWORK_LIMIT_SET_ROLE) { if (amount > maxNetworkLimit[subnetwork]) { revert ExceedsMaxNetworkLimit(); } @@ -129,7 +126,7 @@ contract NetworkRestakeDelegator is BaseDelegator, INetworkRestakeDelegator { bytes32 subnetwork, address operator, uint256 shares - ) external initialized onlyRole(OPERATOR_NETWORK_SHARES_SET_ROLE) { + ) external onlyRole(OPERATOR_NETWORK_SHARES_SET_ROLE) { _totalOperatorNetworkShares[subnetwork].push( Time.timestamp(), totalOperatorNetworkShares(subnetwork) - operatorNetworkShares(subnetwork, operator) + shares diff --git a/src/contracts/slasher/Slasher.sol b/src/contracts/slasher/Slasher.sol index 121025af..1d1648e3 100644 --- a/src/contracts/slasher/Slasher.sol +++ b/src/contracts/slasher/Slasher.sol @@ -27,7 +27,7 @@ contract Slasher is BaseSlasher, ISlasher { uint256 amount, uint48 captureTimestamp, bytes calldata hints - ) external initialized nonReentrant onlyNetworkMiddleware(subnetwork) returns (uint256 slashedAmount) { + ) external nonReentrant onlyNetworkMiddleware(subnetwork) returns (uint256 slashedAmount) { SlashHints memory slashHints; if (hints.length > 0) { slashHints = abi.decode(hints, (SlashHints)); diff --git a/src/contracts/slasher/VetoSlasher.sol b/src/contracts/slasher/VetoSlasher.sol index ab10e341..9967ff5a 100644 --- a/src/contracts/slasher/VetoSlasher.sol +++ b/src/contracts/slasher/VetoSlasher.sol @@ -83,7 +83,7 @@ contract VetoSlasher is BaseSlasher, IVetoSlasher { uint256 amount, uint48 captureTimestamp, bytes calldata hints - ) external initialized nonReentrant onlyNetworkMiddleware(subnetwork) returns (uint256 slashIndex) { + ) external nonReentrant onlyNetworkMiddleware(subnetwork) returns (uint256 slashIndex) { RequestSlashHints memory requestSlashHints; if (hints.length > 0) { requestSlashHints = abi.decode(hints, (RequestSlashHints)); @@ -126,7 +126,7 @@ contract VetoSlasher is BaseSlasher, IVetoSlasher { function executeSlash( uint256 slashIndex, bytes calldata hints - ) external initialized nonReentrant returns (uint256 slashedAmount) { + ) external nonReentrant returns (uint256 slashedAmount) { ExecuteSlashHints memory executeSlashHints; if (hints.length > 0) { executeSlashHints = abi.decode(hints, (ExecuteSlashHints)); @@ -189,7 +189,7 @@ contract VetoSlasher is BaseSlasher, IVetoSlasher { /** * @inheritdoc IVetoSlasher */ - function vetoSlash(uint256 slashIndex, bytes calldata hints) external initialized nonReentrant { + function vetoSlash(uint256 slashIndex, bytes calldata hints) external nonReentrant { VetoSlashHints memory vetoSlashHints; if (hints.length > 0) { vetoSlashHints = abi.decode(hints, (VetoSlashHints)); @@ -227,11 +227,7 @@ contract VetoSlasher is BaseSlasher, IVetoSlasher { emit VetoSlash(slashIndex, msg.sender); } - function setResolver( - uint96 identifier, - address resolver_, - bytes calldata hints - ) external initialized nonReentrant { + function setResolver(uint96 identifier, address resolver_, bytes calldata hints) external nonReentrant { SetResolverHints memory setResolverHints; if (hints.length > 0) { setResolverHints = abi.decode(hints, (SetResolverHints)); @@ -261,9 +257,6 @@ contract VetoSlasher is BaseSlasher, IVetoSlasher { (InitParams memory params) = abi.decode(data, (InitParams)); uint48 epochDuration = IVault(vault_).epochDuration(); - if (!IVault(vault_).isInitialized()) { - revert VaultNotInitialized(); - } if (params.vetoDuration >= epochDuration) { revert InvalidVetoDuration(); } diff --git a/src/contracts/vault/Vault.sol b/src/contracts/vault/Vault.sol index 2cab9d03..81a21fed 100644 --- a/src/contracts/vault/Vault.sol +++ b/src/contracts/vault/Vault.sol @@ -4,6 +4,8 @@ pragma solidity 0.8.25; import {MigratableEntity} from "../common/MigratableEntity.sol"; import {VaultStorage} from "./VaultStorage.sol"; +import {IBaseDelegator} from "../../interfaces/delegator/IBaseDelegator.sol"; +import {IBaseSlasher} from "../../interfaces/slasher/IBaseSlasher.sol"; import {IRegistry} from "../../interfaces/common/IRegistry.sol"; import {IVault} from "../../interfaces/vault/IVault.sol"; @@ -28,6 +30,13 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau address vaultFactory ) VaultStorage(delegatorFactory, slasherFactory) MigratableEntity(vaultFactory) {} + /** + * @inheritdoc IVault + */ + function isInitialized() external view returns (bool) { + return isDelegatorInitialized && isSlasherInitialized; + } + /** * @inheritdoc IVault */ @@ -84,7 +93,7 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau function deposit( address onBehalfOf, uint256 amount - ) external initialized nonReentrant returns (uint256 depositedAmount, uint256 mintedShares) { + ) external nonReentrant returns (uint256 depositedAmount, uint256 mintedShares) { if (onBehalfOf == address(0)) { revert InvalidOnBehalfOf(); } @@ -123,7 +132,7 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau function withdraw( address claimer, uint256 amount - ) external initialized nonReentrant returns (uint256 burnedShares, uint256 mintedShares) { + ) external nonReentrant returns (uint256 burnedShares, uint256 mintedShares) { if (claimer == address(0)) { revert InvalidClaimer(); } @@ -149,7 +158,7 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau function redeem( address claimer, uint256 shares - ) external initialized nonReentrant returns (uint256 withdrawnAssets, uint256 mintedShares) { + ) external nonReentrant returns (uint256 withdrawnAssets, uint256 mintedShares) { if (claimer == address(0)) { revert InvalidClaimer(); } @@ -172,7 +181,7 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau /** * @inheritdoc IVault */ - function claim(address recipient, uint256 epoch) external initialized nonReentrant returns (uint256 amount) { + function claim(address recipient, uint256 epoch) external nonReentrant returns (uint256 amount) { if (recipient == address(0)) { revert InvalidRecipient(); } @@ -187,10 +196,7 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau /** * @inheritdoc IVault */ - function claimBatch( - address recipient, - uint256[] calldata epochs - ) external initialized nonReentrant returns (uint256 amount) { + function claimBatch(address recipient, uint256[] calldata epochs) external nonReentrant returns (uint256 amount) { if (recipient == address(0)) { revert InvalidRecipient(); } @@ -212,7 +218,7 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau /** * @inheritdoc IVault */ - function onSlash(uint256 slashedAmount, uint48 captureTimestamp) external initialized nonReentrant { + function onSlash(uint256 slashedAmount, uint48 captureTimestamp) external nonReentrant { if (msg.sender != slasher) { revert NotSlasher(); } @@ -267,7 +273,7 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau */ function setDepositWhitelist( bool status - ) external initialized nonReentrant onlyRole(DEPOSIT_WHITELIST_SET_ROLE) { + ) external nonReentrant onlyRole(DEPOSIT_WHITELIST_SET_ROLE) { if (depositWhitelist == status) { revert AlreadySet(); } @@ -283,7 +289,7 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau function setDepositorWhitelistStatus( address account, bool status - ) external initialized nonReentrant onlyRole(DEPOSITOR_WHITELIST_ROLE) { + ) external nonReentrant onlyRole(DEPOSITOR_WHITELIST_ROLE) { if (account == address(0)) { revert InvalidAccount(); } @@ -306,7 +312,7 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau */ function setIsDepositLimit( bool status - ) external initialized nonReentrant onlyRole(IS_DEPOSIT_LIMIT_SET_ROLE) { + ) external nonReentrant onlyRole(IS_DEPOSIT_LIMIT_SET_ROLE) { if (isDepositLimit == status) { revert AlreadySet(); } @@ -321,7 +327,7 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau */ function setDepositLimit( uint256 limit - ) external initialized nonReentrant onlyRole(DEPOSIT_LIMIT_SET_ROLE) { + ) external nonReentrant onlyRole(DEPOSIT_LIMIT_SET_ROLE) { if (limit != 0 && !isDepositLimit) { revert NoDepositLimit(); } @@ -335,6 +341,52 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau emit SetDepositLimit(limit); } + function setDelegator( + address delegator_ + ) external nonReentrant { + if (isDelegatorInitialized) { + revert DelegatorAlreadyInitialized(); + } + + if (!IRegistry(DELEGATOR_FACTORY).isEntity(delegator_)) { + revert NotDelegator(); + } + + if (IBaseDelegator(delegator_).vault() != address(this)) { + revert InvalidDelegator(); + } + + delegator = delegator_; + + isDelegatorInitialized = true; + + emit SetDelegator(delegator_); + } + + function setSlasher( + address slasher_ + ) external nonReentrant { + if (isSlasherInitialized) { + revert SlasherAlreadyInitialized(); + } + + if (slasher_ != address(0)) { + if (!IRegistry(SLASHER_FACTORY).isEntity(slasher_)) { + revert NotSlasher(); + } + + if (IBaseSlasher(slasher_).vault() != address(this)) { + revert InvalidSlasher(); + } + + slasher = slasher_; + } + + isSlasherInitialized = true; + + emit SetSlasher(slasher_); + } + function _withdraw( address claimer, uint256 withdrawnAssets, @@ -386,14 +438,6 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau revert InvalidEpochDuration(); } - if (!IRegistry(DELEGATOR_FACTORY).isEntity(params.delegator)) { - revert NotDelegator(); - } - - if (params.slasher != address(0) && !IRegistry(SLASHER_FACTORY).isEntity(params.slasher)) { - revert NotSlasher(); - } - if (params.defaultAdminRoleHolder == address(0)) { if (params.depositWhitelistSetRoleHolder == address(0)) { if (params.depositWhitelist) { @@ -418,10 +462,6 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau collateral = params.collateral; - delegator = params.delegator; - - slasher = params.slasher; - burner = params.burner; epochDurationInit = Time.timestamp(); diff --git a/src/contracts/vault/VaultStorage.sol b/src/contracts/vault/VaultStorage.sol index 1e13b4e4..fe2dda6e 100644 --- a/src/contracts/vault/VaultStorage.sol +++ b/src/contracts/vault/VaultStorage.sol @@ -64,6 +64,16 @@ contract VaultStorage is StaticDelegateCallable, IVaultStorage { */ address public burner; + /** + * @inheritdoc IVaultStorage + */ + uint48 public epochDurationInit; + + /** + * @inheritdoc IVaultStorage + */ + uint48 public epochDuration; + /** * @inheritdoc IVaultStorage */ @@ -72,17 +82,17 @@ contract VaultStorage is StaticDelegateCallable, IVaultStorage { /** * @inheritdoc IVaultStorage */ - address public slasher; + bool public isDelegatorInitialized; /** * @inheritdoc IVaultStorage */ - uint48 public epochDurationInit; + address public slasher; /** * @inheritdoc IVaultStorage */ - uint48 public epochDuration; + bool public isSlasherInitialized; /** * @inheritdoc IVaultStorage diff --git a/src/interfaces/IVaultConfigurator.sol b/src/interfaces/IVaultConfigurator.sol index 54c740df..ed1e509d 100644 --- a/src/interfaces/IVaultConfigurator.sol +++ b/src/interfaces/IVaultConfigurator.sol @@ -1,8 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import {IVault} from "./vault/IVault.sol"; - interface IVaultConfigurator { error DirtyInitParams(); @@ -20,7 +18,7 @@ interface IVaultConfigurator { struct InitParams { uint64 version; address owner; - IVault.InitParams vaultParams; + bytes vaultParams; uint64 delegatorIndex; bytes delegatorParams; bool withSlasher; diff --git a/src/interfaces/common/IEntity.sol b/src/interfaces/common/IEntity.sol index bdfbe6b9..aa7bffb3 100644 --- a/src/interfaces/common/IEntity.sol +++ b/src/interfaces/common/IEntity.sol @@ -16,12 +16,6 @@ interface IEntity { */ function TYPE() external view returns (uint64); - /** - * @notice Get if the entity is initialized. - * @return if the entity is initialized - */ - function isInitialized() external view returns (bool); - /** * @notice Initialize this entity contract by using a given data. * @param data some data to use diff --git a/src/interfaces/common/IFactory.sol b/src/interfaces/common/IFactory.sol index b2dd4130..d6551079 100644 --- a/src/interfaces/common/IFactory.sol +++ b/src/interfaces/common/IFactory.sol @@ -67,12 +67,9 @@ interface IFactory is IRegistry { /** * @notice Create a new entity at the factory. * @param type_ type's implementation to use - * @param withInitialize whether to call `initialize()` on the entity * @param data initial data for the entity creation * @return address of the entity * @dev CREATE2 salt is constructed from the given parameters. - * However, the real parameters may differ if initialized later - * (not necessarily by the creator if there is no initialization during the creation's transaction). */ - function create(uint64 type_, bool withInitialize, bytes calldata data) external returns (address); + function create(uint64 type_, bytes calldata data) external returns (address); } diff --git a/src/interfaces/common/IMigratableEntity.sol b/src/interfaces/common/IMigratableEntity.sol index e6f74e58..b20ef377 100644 --- a/src/interfaces/common/IMigratableEntity.sol +++ b/src/interfaces/common/IMigratableEntity.sol @@ -3,7 +3,6 @@ pragma solidity ^0.8.0; interface IMigratableEntity { error AlreadyInitialized(); - error InvalidInitialVersion(); error NotFactory(); error NotInitialized(); @@ -20,12 +19,6 @@ interface IMigratableEntity { */ function version() external view returns (uint64); - /** - * @notice Get if the entity is initialized. - * @return if the entity is initialized - */ - function isInitialized() external view returns (bool); - /** * @notice Initialize this entity contract by using a given data and setting a particular version and owner. * @param initialVersion initial version of the entity diff --git a/src/interfaces/common/IMigratablesFactory.sol b/src/interfaces/common/IMigratablesFactory.sol index 11730fab..eea63d7b 100644 --- a/src/interfaces/common/IMigratablesFactory.sol +++ b/src/interfaces/common/IMigratablesFactory.sol @@ -79,19 +79,11 @@ interface IMigratablesFactory is IRegistry { * @notice Create a new entity at the factory. * @param version entity's version to use * @param owner initial owner of the entity - * @param withInitialize whether to call `initialize()` on the entity * @param data initial data for the entity creation * @return address of the entity * @dev CREATE2 salt is constructed from the given parameters. - * However, the real parameters may differ if initialized later - * (not necessarily by the creator if there is no initialization during the creation's transaction). */ - function create( - uint64 version, - address owner, - bool withInitialize, - bytes calldata data - ) external returns (address); + function create(uint64 version, address owner, bytes calldata data) external returns (address); /** * @notice Migrate a given entity to a given newer version. diff --git a/src/interfaces/vault/IVault.sol b/src/interfaces/vault/IVault.sol index 8e746467..9fbb73a1 100644 --- a/src/interfaces/vault/IVault.sol +++ b/src/interfaces/vault/IVault.sol @@ -7,6 +7,7 @@ import {IVaultStorage} from "./IVaultStorage.sol"; interface IVault is IMigratableEntity, IVaultStorage { error AlreadyClaimed(); error AlreadySet(); + error DelegatorAlreadyInitialized(); error DepositLimitReached(); error InsufficientClaim(); error InsufficientDeposit(); @@ -16,25 +17,26 @@ interface IVault is IMigratableEntity, IVaultStorage { error InvalidCaptureEpoch(); error InvalidClaimer(); error InvalidCollateral(); + error InvalidDelegator(); error InvalidEpoch(); error InvalidEpochDuration(); error InvalidLengthEpochs(); error InvalidOnBehalfOf(); error InvalidRecipient(); + error InvalidSlasher(); error MissingRoles(); error NoDepositLimit(); error NoDepositWhitelist(); error NotDelegator(); error NotSlasher(); error NotWhitelistedDepositor(); + error SlasherAlreadyInitialized(); error TooMuchRedeem(); error TooMuchWithdraw(); /** * @notice Initial parameters needed for a vault deployment. * @param collateral vault's underlying collateral - * @param delegator vault's delegator to delegate the stake to networks and operators - * @param slasher vault's slasher to provide a slashing mechanism to networks * @param burner vault's burner to issue debt to (e.g., 0xdEaD or some unwrapper contract) * @param epochDuration duration of the vault epoch (it determines sync points for withdrawals) * @param depositWhitelist if enabling deposit whitelist @@ -48,8 +50,6 @@ interface IVault is IMigratableEntity, IVaultStorage { */ struct InitParams { address collateral; - address delegator; - address slasher; address burner; uint48 epochDuration; bool depositWhitelist; @@ -157,6 +157,26 @@ interface IVault is IMigratableEntity, IVaultStorage { */ event SetDepositLimit(uint256 limit); + /** + * @notice Emitted when a delegator is set. + * @param delegator vault's delegator to delegate the stake to networks and operators + * @dev Can be set only once. + */ + event SetDelegator(address indexed delegator); + + /** + * @notice Emitted when a slasher is set. + * @param slasher vault's slasher to provide a slashing mechanism to networks + * @dev Can be set only once. + */ + event SetSlasher(address indexed slasher); + + /** + * @notice Check if the vault is fully initialized (a delegator and a slasher are set). + * @return if the vault is fully initialized + */ + function isInitialized() external view returns (bool); + /** * @notice Get a total amount of the collateral that can be slashed. * @return total amount of the slashable collateral @@ -289,4 +309,22 @@ interface IVault is IMigratableEntity, IVaultStorage { function setDepositLimit( uint256 limit ) external; + + /** + * @notice Set a delegator. + * @param delegator vault's delegator to delegate the stake to networks and operators + * @dev Can be set only once. + */ + function setDelegator( + address delegator + ) external; + + /** + * @notice Set a slasher. + * @param slasher vault's slasher to provide a slashing mechanism to networks + * @dev Can be set only once. + */ + function setSlasher( + address slasher + ) external; } diff --git a/src/interfaces/vault/IVaultStorage.sol b/src/interfaces/vault/IVaultStorage.sol index d0561e3c..188f0a56 100644 --- a/src/interfaces/vault/IVaultStorage.sol +++ b/src/interfaces/vault/IVaultStorage.sol @@ -59,12 +59,24 @@ interface IVaultStorage { */ function delegator() external view returns (address); + /** + * @notice Get if the delegator is initialized. + * @return if the delegator is initialized + */ + function isDelegatorInitialized() external view returns (bool); + /** * @notice Get a slasher (it provides networks a slashing mechanism). * @return address of the slasher */ function slasher() external view returns (address); + /** + * @notice Get if the slasher is initialized. + * @return if the slasher is initialized + */ + function isSlasherInitialized() external view returns (bool); + /** * @notice Get a time point of the epoch duration set. * @return time point of the epoch duration set diff --git a/test/DelegatorFactory.t.sol b/test/DelegatorFactory.t.sol index 4b7b108f..7aa538e8 100644 --- a/test/DelegatorFactory.t.sol +++ b/test/DelegatorFactory.t.sol @@ -128,21 +128,21 @@ contract DelegatorFactoryTest is Test { IVaultConfigurator.InitParams({ version: 1, owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: 1, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 1, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -165,7 +165,6 @@ contract DelegatorFactoryTest is Test { operatorNetworkSharesSetRoleHolders[0] = bob; address networkRestakeDelegator = delegatorFactory.create( 0, - true, abi.encode( vault_, abi.encode( @@ -189,7 +188,6 @@ contract DelegatorFactoryTest is Test { operatorNetworkLimitSetRoleHolders[0] = bob; address fullRestakeDelegator = delegatorFactory.create( 1, - true, abi.encode( vault_, abi.encode( diff --git a/test/POCBase.t.sol b/test/POCBase.t.sol index 5c3bf6eb..05917a13 100644 --- a/test/POCBase.t.sol +++ b/test/POCBase.t.sol @@ -168,21 +168,21 @@ contract POCBaseTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -215,21 +215,21 @@ contract POCBaseTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -262,21 +262,21 @@ contract POCBaseTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 1, delegatorParams: abi.encode( IFullRestakeDelegator.InitParams({ @@ -310,21 +310,21 @@ contract POCBaseTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -358,21 +358,21 @@ contract POCBaseTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 1, delegatorParams: abi.encode( IFullRestakeDelegator.InitParams({ diff --git a/test/SlasherFactory.t.sol b/test/SlasherFactory.t.sol index 68c5fe4f..43a6b507 100644 --- a/test/SlasherFactory.t.sol +++ b/test/SlasherFactory.t.sol @@ -129,21 +129,21 @@ contract SlasherFactoryTest is Test { IVaultConfigurator.InitParams({ version: 1, owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: 1, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 1, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -162,14 +162,12 @@ contract SlasherFactoryTest is Test { }) ); - address slasher = slasherFactory.create(0, true, abi.encode(vault_, "")); + address slasher = slasherFactory.create(0, abi.encode(vault_, "")); assertEq(Slasher(slasher).FACTORY(), address(slasherFactory)); assertEq(slasherFactory.isEntity(slasher), true); address vetoSlasher = slasherFactory.create( - 1, - true, - abi.encode(vault_, abi.encode(IVetoSlasher.InitParams({vetoDuration: 0, resolverSetEpochsDelay: 3}))) + 1, abi.encode(vault_, abi.encode(IVetoSlasher.InitParams({vetoDuration: 0, resolverSetEpochsDelay: 3}))) ); assertEq(VetoSlasher(vetoSlasher).FACTORY(), address(slasherFactory)); diff --git a/test/VaultConfigurator.t.sol b/test/VaultConfigurator.t.sol index 949285c2..265776b4 100644 --- a/test/VaultConfigurator.t.sol +++ b/test/VaultConfigurator.t.sol @@ -144,21 +144,21 @@ contract VaultConfiguratorTest is Test { IVaultConfigurator.InitParams({ version: 1, owner: owner_, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: burner, - epochDuration: epochDuration, - depositWhitelist: depositWhitelist, - isDepositLimit: isDepositLimit, - depositLimit: depositLimit, - defaultAdminRoleHolder: address(100), - depositWhitelistSetRoleHolder: address(99), - depositorWhitelistRoleHolder: address(101), - isDepositLimitSetRoleHolder: address(102), - depositLimitSetRoleHolder: address(103) - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: burner, + epochDuration: epochDuration, + depositWhitelist: depositWhitelist, + isDepositLimit: isDepositLimit, + depositLimit: depositLimit, + defaultAdminRoleHolder: address(100), + depositWhitelistSetRoleHolder: address(99), + depositorWhitelistRoleHolder: address(101), + isDepositLimitSetRoleHolder: address(102), + depositLimitSetRoleHolder: address(103) + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -209,64 +209,7 @@ contract VaultConfiguratorTest is Test { if (withSlasher) { assertEq(slasher.vault(), vault_); } - } - - function test_CreateRevertDirtyInitParams( - address owner_, - address burner, - uint48 epochDuration, - bool depositWhitelist, - bool withSlasher, - address hook, - address delegator_, - address slasher_ - ) public { - vm.assume(delegator_ != address(0) || slasher_ != address(0)); - epochDuration = uint48(bound(epochDuration, 1, 50 weeks)); - vm.assume(owner_ != address(0)); - - address[] memory networkLimitSetRoleHolders = new address[](1); - networkLimitSetRoleHolders[0] = address(106); - address[] memory operatorNetworkSharesSetRoleHolders = new address[](1); - operatorNetworkSharesSetRoleHolders[0] = address(107); - - vm.expectRevert(IVaultConfigurator.DirtyInitParams.selector); - vaultConfigurator.create( - IVaultConfigurator.InitParams({ - version: 1, - owner: owner_, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: delegator_, - slasher: slasher_, - burner: burner, - epochDuration: epochDuration, - depositWhitelist: depositWhitelist, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: address(100), - depositWhitelistSetRoleHolder: address(99), - depositorWhitelistRoleHolder: address(101), - isDepositLimitSetRoleHolder: address(102), - depositLimitSetRoleHolder: address(103) - }), - delegatorIndex: 0, - delegatorParams: abi.encode( - INetworkRestakeDelegator.InitParams({ - baseParams: IBaseDelegator.BaseParams({ - defaultAdminRoleHolder: address(104), - hook: hook, - hookSetRoleHolder: address(105) - }), - networkLimitSetRoleHolders: networkLimitSetRoleHolders, - operatorNetworkSharesSetRoleHolders: operatorNetworkSharesSetRoleHolders - }) - ), - withSlasher: withSlasher, - slasherIndex: 0, - slasherParams: "" - }) - ); + assertEq(vault.isInitialized(), true); } } diff --git a/test/VaultFactory.t.sol b/test/VaultFactory.t.sol index dfcd1152..c1624120 100644 --- a/test/VaultFactory.t.sol +++ b/test/VaultFactory.t.sol @@ -128,21 +128,21 @@ contract VaultFactoryTest is Test { IVaultConfigurator.InitParams({ version: 1, owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: 1, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 1, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ diff --git a/test/common/Entity.t.sol b/test/common/Entity.t.sol index fe137350..551ab31d 100644 --- a/test/common/Entity.t.sol +++ b/test/common/Entity.t.sol @@ -32,36 +32,18 @@ contract EntityTest is Test { assertEq(IEntity(impl).FACTORY(), address(factory)); factory.whitelist(impl); - address entity = factory.create(0, true, ""); + address entity = factory.create(0, ""); assertEq(IEntity(entity).FACTORY(), address(factory)); assertEq(IEntity(entity).TYPE(), 0); - assertEq(IEntity(entity).isInitialized(), true); impl = address(new SimpleEntity(address(factory), factory.totalTypes())); factory.whitelist(impl); - entity = factory.create(1, true, ""); + entity = factory.create(1, ""); assertEq(IEntity(entity).FACTORY(), address(factory)); assertEq(IEntity(entity).TYPE(), 1); - assertEq(IEntity(entity).isInitialized(), true); vm.expectRevert(); IEntity(entity).initialize(""); } - - function test_CreateWithoutInitialize() public { - address impl = address(new SimpleEntity(address(factory), factory.totalTypes())); - assertEq(IEntity(impl).FACTORY(), address(factory)); - factory.whitelist(impl); - - address entity = factory.create(0, false, ""); - assertEq(IEntity(entity).FACTORY(), address(factory)); - assertEq(IEntity(entity).TYPE(), 0); - assertEq(IEntity(entity).isInitialized(), false); - - IEntity(entity).initialize(""); - assertEq(IEntity(entity).FACTORY(), address(factory)); - assertEq(IEntity(entity).TYPE(), 0); - assertEq(IEntity(entity).isInitialized(), true); - } } diff --git a/test/common/Factory.t.sol b/test/common/Factory.t.sol index 56d33a88..615bd405 100644 --- a/test/common/Factory.t.sol +++ b/test/common/Factory.t.sol @@ -48,7 +48,7 @@ contract FactoryTest is Test { assertEq(factory.blacklisted(1), false); assertEq(factory.isEntity(alice), false); - address entity = factory.create(1, true, ""); + address entity = factory.create(1, ""); assertEq(factory.isEntity(entity), true); factory.blacklist(1); @@ -64,10 +64,10 @@ contract FactoryTest is Test { factory.whitelist(impl); vm.expectRevert(); - factory.create(2, true, ""); + factory.create(2, ""); vm.expectRevert(); - factory.create(3, true, ""); + factory.create(3, ""); } function test_WhitelistRevertInvalidImplementation1() public { diff --git a/test/common/MigratableEntity.t.sol b/test/common/MigratableEntity.t.sol index d260fe65..0eeca185 100644 --- a/test/common/MigratableEntity.t.sol +++ b/test/common/MigratableEntity.t.sol @@ -38,26 +38,9 @@ contract MigratableEntityTest is Test { assertEq(IMigratableEntity(impl).FACTORY(), address(factory)); factory.whitelist(impl); - address entity = factory.create(1, alice, true, ""); + address entity = factory.create(1, alice, ""); assertEq(IMigratableEntity(entity).FACTORY(), address(factory)); assertEq(IMigratableEntity(entity).version(), 1); - assertEq(IMigratableEntity(entity).isInitialized(), true); - } - - function test_CreateWithoutInitialize() public { - address impl = address(new SimpleMigratableEntity(address(factory))); - assertEq(IMigratableEntity(impl).FACTORY(), address(factory)); - factory.whitelist(impl); - - address entity = factory.create(1, alice, false, ""); - assertEq(IMigratableEntity(entity).FACTORY(), address(factory)); - assertEq(IMigratableEntity(entity).version(), 0); - assertEq(IMigratableEntity(entity).isInitialized(), false); - - IMigratableEntity(entity).initialize(1, alice, abi.encode(0)); - assertEq(IMigratableEntity(entity).FACTORY(), address(factory)); - assertEq(IMigratableEntity(entity).version(), 1); - assertEq(IMigratableEntity(entity).isInitialized(), true); } function test_ReinitRevertAlreadyInitialized() public { @@ -67,25 +50,12 @@ contract MigratableEntityTest is Test { impl = address(new SimpleMigratableEntity(address(factory))); factory.whitelist(impl); - address entity = factory.create(1, alice, true, ""); + address entity = factory.create(1, alice, ""); vm.expectRevert(IMigratableEntity.AlreadyInitialized.selector); SimpleMigratableEntity(entity).initialize(2, alice, abi.encode(0)); } - function test_InitRevertInvalidInitialVersion() public { - address impl = address(new SimpleMigratableEntity(address(factory))); - factory.whitelist(impl); - - impl = address(new SimpleMigratableEntity(address(factory))); - factory.whitelist(impl); - - address entity = factory.create(1, alice, false, ""); - - vm.expectRevert(IMigratableEntity.InvalidInitialVersion.selector); - SimpleMigratableEntity(entity).initialize(2, alice, abi.encode(0)); - } - function test_Migrate(uint256 a1, uint256 a2, uint256 b1, uint256 b2) public { a2 = bound(a2, 0, type(uint256).max - 1); @@ -95,7 +65,7 @@ contract MigratableEntityTest is Test { impl = address(new SimpleMigratableEntity(address(factory))); factory.whitelist(impl); - address entity = factory.create(2, alice, true, ""); + address entity = factory.create(2, alice, ""); address implV2 = address(new SimpleMigratableEntityV2(address(factory))); factory.whitelist(implV2); @@ -121,7 +91,7 @@ contract MigratableEntityTest is Test { address impl = address(new SimpleMigratableEntity(address(factory))); factory.whitelist(impl); - address entity = factory.create(1, alice, true, ""); + address entity = factory.create(1, alice, ""); address implV2 = address(new SimpleMigratableEntityV2(address(factory))); factory.whitelist(implV2); diff --git a/test/common/MigratableEntityProxy.t.sol b/test/common/MigratableEntityProxy.t.sol index 1ad5ee2d..687877fe 100644 --- a/test/common/MigratableEntityProxy.t.sol +++ b/test/common/MigratableEntityProxy.t.sol @@ -36,7 +36,7 @@ contract MigratableEntityProxyTest is Test { address impl = address(new SimpleMigratableEntity(address(factory))); factory.whitelist(impl); - address entity = factory.create(1, alice, true, ""); + address entity = factory.create(1, alice, ""); address implV2 = address(new SimpleMigratableEntityV2(address(factory))); factory.whitelist(implV2); diff --git a/test/common/MigratablesFactory.t.sol b/test/common/MigratablesFactory.t.sol index 261d821e..ebebb6bf 100644 --- a/test/common/MigratablesFactory.t.sol +++ b/test/common/MigratablesFactory.t.sol @@ -48,7 +48,7 @@ contract MigratablesFactoryTest is Test { assertEq(factory.blacklisted(2), false); assertEq(factory.isEntity(alice), false); - address entity = factory.create(2, alice, true, ""); + address entity = factory.create(2, alice, ""); assertEq(factory.isEntity(entity), true); impl = address(new SimpleMigratableEntity(address(factory))); @@ -70,13 +70,13 @@ contract MigratablesFactoryTest is Test { factory.whitelist(impl); vm.expectRevert(IMigratablesFactory.InvalidVersion.selector); - factory.create(0, alice, true, ""); + factory.create(0, alice, ""); vm.expectRevert(IMigratablesFactory.InvalidVersion.selector); - factory.create(2, alice, true, ""); + factory.create(2, alice, ""); vm.expectRevert(IMigratablesFactory.InvalidVersion.selector); - factory.create(3, alice, true, ""); + factory.create(3, alice, ""); } function test_Migrate( @@ -88,7 +88,7 @@ contract MigratablesFactoryTest is Test { impl = address(new SimpleMigratableEntity(address(factory))); factory.whitelist(impl); - address entity = factory.create(2, alice, true, ""); + address entity = factory.create(2, alice, ""); address implV2 = address(new SimpleMigratableEntityV2(address(factory))); factory.whitelist(implV2); @@ -105,7 +105,7 @@ contract MigratablesFactoryTest is Test { address impl = address(new SimpleMigratableEntity(address(factory))); factory.whitelist(impl); - address entity = factory.create(1, alice, true, ""); + address entity = factory.create(1, alice, ""); address implV2 = address(new SimpleMigratableEntityV2(address(factory))); factory.whitelist(implV2); @@ -121,7 +121,7 @@ contract MigratablesFactoryTest is Test { address impl = address(new SimpleMigratableEntity(address(factory))); factory.whitelist(impl); - address entity = factory.create(1, alice, true, ""); + address entity = factory.create(1, alice, ""); address implV2 = address(new SimpleMigratableEntityV2(address(factory))); factory.whitelist(implV2); @@ -137,7 +137,7 @@ contract MigratablesFactoryTest is Test { address impl = address(new SimpleMigratableEntity(address(factory))); factory.whitelist(impl); - address entity = factory.create(1, alice, true, ""); + address entity = factory.create(1, alice, ""); address implV2 = address(new SimpleMigratableEntityV2(address(factory))); factory.whitelist(implV2); diff --git a/test/delegator/FullRestakeDelegator.t.sol b/test/delegator/FullRestakeDelegator.t.sol index fe6aa643..695d5673 100644 --- a/test/delegator/FullRestakeDelegator.t.sol +++ b/test/delegator/FullRestakeDelegator.t.sol @@ -177,7 +177,6 @@ contract FullRestakeDelegatorTest is Test { vm.expectRevert(IBaseDelegator.NotVault.selector); delegatorFactory.create( 1, - true, abi.encode( address(1), abi.encode( @@ -209,7 +208,6 @@ contract FullRestakeDelegatorTest is Test { vm.expectRevert(IFullRestakeDelegator.MissingRoleHolders.selector); delegatorFactory.create( 1, - true, abi.encode( address(vault), abi.encode( @@ -242,7 +240,6 @@ contract FullRestakeDelegatorTest is Test { vm.expectRevert(IFullRestakeDelegator.ZeroAddressRoleHolder.selector); delegatorFactory.create( 1, - true, abi.encode( address(vault), abi.encode( @@ -275,7 +272,6 @@ contract FullRestakeDelegatorTest is Test { vm.expectRevert(IFullRestakeDelegator.ZeroAddressRoleHolder.selector); delegatorFactory.create( 1, - true, abi.encode( address(vault), abi.encode( @@ -309,7 +305,6 @@ contract FullRestakeDelegatorTest is Test { vm.expectRevert(IFullRestakeDelegator.DuplicateRoleHolder.selector); delegatorFactory.create( 1, - true, abi.encode( address(vault), abi.encode( @@ -343,7 +338,6 @@ contract FullRestakeDelegatorTest is Test { vm.expectRevert(IFullRestakeDelegator.DuplicateRoleHolder.selector); delegatorFactory.create( 1, - true, abi.encode( address(vault), abi.encode( @@ -938,21 +932,21 @@ contract FullRestakeDelegatorTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: 7 days, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 7 days, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 1, delegatorParams: abi.encode( IFullRestakeDelegator.InitParams({ @@ -1038,21 +1032,21 @@ contract FullRestakeDelegatorTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: 7 days, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 7 days, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 1, delegatorParams: abi.encode( IFullRestakeDelegator.InitParams({ @@ -1757,21 +1751,21 @@ contract FullRestakeDelegatorTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 1, delegatorParams: abi.encode( IFullRestakeDelegator.InitParams({ @@ -1804,21 +1798,21 @@ contract FullRestakeDelegatorTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 1, delegatorParams: abi.encode( IFullRestakeDelegator.InitParams({ @@ -1843,7 +1837,7 @@ contract FullRestakeDelegatorTest is Test { function _getSlasher( address vault_ ) internal returns (Slasher) { - return Slasher(slasherFactory.create(0, true, abi.encode(address(vault_), ""))); + return Slasher(slasherFactory.create(0, abi.encode(address(vault_), ""))); } function _registerOperator( diff --git a/test/delegator/NetworkRestakeDelegator.t.sol b/test/delegator/NetworkRestakeDelegator.t.sol index 050142a8..60622d94 100644 --- a/test/delegator/NetworkRestakeDelegator.t.sol +++ b/test/delegator/NetworkRestakeDelegator.t.sol @@ -180,7 +180,6 @@ contract NetworkRestakeDelegatorTest is Test { vm.expectRevert(IBaseDelegator.NotVault.selector); delegatorFactory.create( 0, - true, abi.encode( address(1), abi.encode( @@ -212,7 +211,6 @@ contract NetworkRestakeDelegatorTest is Test { vm.expectRevert(INetworkRestakeDelegator.MissingRoleHolders.selector); delegatorFactory.create( 0, - true, abi.encode( address(vault), abi.encode( @@ -245,7 +243,6 @@ contract NetworkRestakeDelegatorTest is Test { vm.expectRevert(INetworkRestakeDelegator.ZeroAddressRoleHolder.selector); delegatorFactory.create( 0, - true, abi.encode( address(vault), abi.encode( @@ -278,7 +275,6 @@ contract NetworkRestakeDelegatorTest is Test { vm.expectRevert(INetworkRestakeDelegator.ZeroAddressRoleHolder.selector); delegatorFactory.create( 0, - true, abi.encode( address(vault), abi.encode( @@ -312,7 +308,6 @@ contract NetworkRestakeDelegatorTest is Test { vm.expectRevert(INetworkRestakeDelegator.DuplicateRoleHolder.selector); delegatorFactory.create( 0, - true, abi.encode( address(vault), abi.encode( @@ -346,7 +341,6 @@ contract NetworkRestakeDelegatorTest is Test { vm.expectRevert(INetworkRestakeDelegator.DuplicateRoleHolder.selector); delegatorFactory.create( 0, - true, abi.encode( address(vault), abi.encode( @@ -1146,21 +1140,21 @@ contract NetworkRestakeDelegatorTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: 7 days, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 7 days, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -1249,21 +1243,21 @@ contract NetworkRestakeDelegatorTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: 7 days, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 7 days, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -2030,21 +2024,21 @@ contract NetworkRestakeDelegatorTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -2077,21 +2071,21 @@ contract NetworkRestakeDelegatorTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -2116,7 +2110,7 @@ contract NetworkRestakeDelegatorTest is Test { function _getSlasher( address vault_ ) internal returns (Slasher) { - return Slasher(slasherFactory.create(0, true, abi.encode(address(vault_), ""))); + return Slasher(slasherFactory.create(0, abi.encode(address(vault_), ""))); } function _registerOperator( diff --git a/test/slasher/Slasher.t.sol b/test/slasher/Slasher.t.sol index 6c38e935..fdce3b21 100644 --- a/test/slasher/Slasher.t.sol +++ b/test/slasher/Slasher.t.sol @@ -171,7 +171,7 @@ contract SlasherTest is Test { (vault,) = _getVaultAndDelegator(epochDuration); vm.expectRevert(IBaseSlasher.NotVault.selector); - slasherFactory.create(0, true, abi.encode(address(1), "")); + slasherFactory.create(0, abi.encode(address(1), "")); } function test_Slash( @@ -1319,21 +1319,21 @@ contract SlasherTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 1, delegatorParams: abi.encode( IFullRestakeDelegator.InitParams({ @@ -1366,21 +1366,21 @@ contract SlasherTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 1, delegatorParams: abi.encode( IFullRestakeDelegator.InitParams({ @@ -1405,7 +1405,7 @@ contract SlasherTest is Test { function _getSlasher( address vault_ ) internal returns (Slasher) { - return Slasher(slasherFactory.create(0, true, abi.encode(address(vault_), ""))); + return Slasher(slasherFactory.create(0, abi.encode(address(vault_), ""))); } function _registerOperator( diff --git a/test/slasher/VetoSlasher.t.sol b/test/slasher/VetoSlasher.t.sol index 77acd1ee..ca52ed48 100644 --- a/test/slasher/VetoSlasher.t.sol +++ b/test/slasher/VetoSlasher.t.sol @@ -182,7 +182,6 @@ contract VetoSlasherTest is Test { vm.expectRevert(IBaseSlasher.NotVault.selector); slasherFactory.create( 1, - true, abi.encode( address(1), abi.encode( @@ -207,7 +206,6 @@ contract VetoSlasherTest is Test { vm.expectRevert(IVetoSlasher.InvalidVetoDuration.selector); slasherFactory.create( 1, - true, abi.encode( address(vault), abi.encode( @@ -232,88 +230,6 @@ contract VetoSlasherTest is Test { vm.expectRevert(IVetoSlasher.InvalidResolverSetEpochsDelay.selector); slasherFactory.create( 1, - true, - abi.encode( - address(vault), - abi.encode( - IVetoSlasher.InitParams({vetoDuration: vetoDuration, resolverSetEpochsDelay: resolverSetEpochsDelay}) - ) - ) - ); - } - - function test_CreateRevertVaultNotInitialized( - uint48 epochDuration, - uint48 vetoDuration, - uint256 resolverSetEpochsDelay - ) public { - epochDuration = uint48(bound(epochDuration, 1, 50 weeks)); - vetoDuration = uint48(bound(vetoDuration, 0, type(uint48).max / 2)); - resolverSetEpochsDelay = bound(resolverSetEpochsDelay, 3, type(uint256).max); - vm.assume(vetoDuration < epochDuration); - - vault = Vault(vaultFactory.create(1, alice, false, "")); - - vm.expectRevert(IVetoSlasher.VaultNotInitialized.selector); - slasherFactory.create( - 1, - true, - abi.encode( - address(vault), - abi.encode( - IVetoSlasher.InitParams({vetoDuration: vetoDuration, resolverSetEpochsDelay: resolverSetEpochsDelay}) - ) - ) - ); - - address[] memory networkLimitSetRoleHolders = new address[](0); - address[] memory operatorNetworkLimitSetRoleHolders = new address[](0); - delegator = FullRestakeDelegator( - delegatorFactory.create( - 1, - true, - abi.encode( - address(vault), - abi.encode( - IFullRestakeDelegator.InitParams({ - baseParams: IBaseDelegator.BaseParams({ - defaultAdminRoleHolder: alice, - hook: address(0), - hookSetRoleHolder: alice - }), - networkLimitSetRoleHolders: networkLimitSetRoleHolders, - operatorNetworkLimitSetRoleHolders: operatorNetworkLimitSetRoleHolders - }) - ) - ) - ) - ); - - vault.initialize( - 1, - alice, - abi.encode( - IVault.InitParams({ - collateral: address(collateral), - delegator: address(delegator), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }) - ) - ); - - slasherFactory.create( - 1, - true, abi.encode( address(vault), abi.encode( @@ -2364,21 +2280,21 @@ contract VetoSlasherTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -2412,21 +2328,21 @@ contract VetoSlasherTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 1, delegatorParams: abi.encode( IFullRestakeDelegator.InitParams({ @@ -2452,7 +2368,6 @@ contract VetoSlasherTest is Test { return VetoSlasher( slasherFactory.create( 1, - true, abi.encode( vault_, abi.encode(IVetoSlasher.InitParams({vetoDuration: vetoDuration, resolverSetEpochsDelay: 3})) ) diff --git a/test/vault/Vault.t.sol b/test/vault/Vault.t.sol index 96692ce5..0e65e018 100644 --- a/test/vault/Vault.t.sol +++ b/test/vault/Vault.t.sol @@ -157,21 +157,21 @@ contract VaultTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: address(0), - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: burner, - epochDuration: epochDuration, - depositWhitelist: depositWhitelist, - isDepositLimit: isDepositLimit, - depositLimit: depositLimit, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: burner, + epochDuration: epochDuration, + depositWhitelist: depositWhitelist, + isDepositLimit: isDepositLimit, + depositLimit: depositLimit, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -231,6 +231,9 @@ contract VaultTest is Test { assertEq(vault.depositWhitelist(), depositWhitelist); assertEq(vault.isDepositorWhitelisted(alice), false); assertEq(vault.slashableBalanceOf(alice), 0); + assertEq(vault.isDelegatorInitialized(), true); + assertEq(vault.isSlasherInitialized(), true); + assertEq(vault.isInitialized(), true); blockTimestamp = blockTimestamp + vault.epochDuration() - 1; vm.warp(blockTimestamp); @@ -277,21 +280,21 @@ contract VaultTest is Test { IVaultConfigurator.InitParams({ version: lastVersion, owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -326,21 +329,21 @@ contract VaultTest is Test { IVaultConfigurator.InitParams({ version: lastVersion, owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(0), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(0), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -360,365 +363,557 @@ contract VaultTest is Test { ); } - function test_CreateRevertNotDelegator( + function test_CreateRevertMissingRoles1( uint48 epochDuration ) public { epochDuration = uint48(bound(epochDuration, 1, 50 weeks)); uint64 lastVersion = vaultFactory.lastVersion(); - vm.expectRevert(IVault.NotDelegator.selector); - vaultFactory.create( - lastVersion, - alice, - true, - abi.encode( - IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }) + + vm.expectRevert(IVault.MissingRoles.selector); + vault = Vault( + vaultFactory.create( + lastVersion, + alice, + abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: true, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: address(0), + depositWhitelistSetRoleHolder: address(0), + depositorWhitelistRoleHolder: address(0), + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: address(0) + }) + ) ) ); } - function test_CreateRevertNotSlasher( + function test_CreateRevertMissingRoles2( uint48 epochDuration ) public { epochDuration = uint48(bound(epochDuration, 1, 50 weeks)); uint64 lastVersion = vaultFactory.lastVersion(); - vault = Vault(vaultFactory.create(lastVersion, alice, false, "")); - address[] memory networkLimitSetRoleHolders = new address[](1); - networkLimitSetRoleHolders[0] = alice; - address[] memory operatorNetworkSharesSetRoleHolders = new address[](1); - operatorNetworkSharesSetRoleHolders[0] = alice; - address delegator_ = delegatorFactory.create( - 0, - true, - abi.encode( - address(vault), + vm.expectRevert(IVault.MissingRoles.selector); + vault = Vault( + vaultFactory.create( + lastVersion, + alice, abi.encode( - INetworkRestakeDelegator.InitParams({ - baseParams: IBaseDelegator.BaseParams({ - defaultAdminRoleHolder: alice, - hook: address(0), - hookSetRoleHolder: alice - }), - networkLimitSetRoleHolders: networkLimitSetRoleHolders, - operatorNetworkSharesSetRoleHolders: operatorNetworkSharesSetRoleHolders + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: true, + depositLimit: 0, + defaultAdminRoleHolder: address(0), + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: address(0), + isDepositLimitSetRoleHolder: address(0), + depositLimitSetRoleHolder: address(0) }) ) ) ); - - vm.expectRevert(IVault.NotSlasher.selector); - vault.initialize( - lastVersion, - alice, - abi.encode( - IVault.InitParams({ - collateral: address(collateral), - delegator: delegator_, - slasher: address(1), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }) - ) - ); } - function test_CreateRevertMissingRoles1( + function test_CreateRevertMissingRoles3( uint48 epochDuration ) public { epochDuration = uint48(bound(epochDuration, 1, 50 weeks)); uint64 lastVersion = vaultFactory.lastVersion(); - vault = Vault(vaultFactory.create(lastVersion, alice, false, "")); - address[] memory networkLimitSetRoleHolders = new address[](1); - networkLimitSetRoleHolders[0] = alice; - address[] memory operatorNetworkSharesSetRoleHolders = new address[](1); - operatorNetworkSharesSetRoleHolders[0] = alice; - address delegator_ = delegatorFactory.create( - 0, - true, - abi.encode( - address(vault), + vm.expectRevert(IVault.MissingRoles.selector); + vault = Vault( + vaultFactory.create( + lastVersion, + alice, abi.encode( - INetworkRestakeDelegator.InitParams({ - baseParams: IBaseDelegator.BaseParams({ - defaultAdminRoleHolder: alice, - hook: address(0), - hookSetRoleHolder: alice - }), - networkLimitSetRoleHolders: networkLimitSetRoleHolders, - operatorNetworkSharesSetRoleHolders: operatorNetworkSharesSetRoleHolders + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: address(0), + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: address(0), + isDepositLimitSetRoleHolder: address(0), + depositLimitSetRoleHolder: alice }) ) ) ); + } + + function test_CreateRevertMissingRoles4( + uint48 epochDuration + ) public { + epochDuration = uint48(bound(epochDuration, 1, 50 weeks)); + + uint64 lastVersion = vaultFactory.lastVersion(); vm.expectRevert(IVault.MissingRoles.selector); - vault.initialize( - lastVersion, - alice, - abi.encode( - IVault.InitParams({ - collateral: address(collateral), - delegator: delegator_, - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: true, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: address(0), - depositWhitelistSetRoleHolder: address(0), - depositorWhitelistRoleHolder: address(0), - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: address(0) - }) + vault = Vault( + vaultFactory.create( + lastVersion, + alice, + abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 1, + defaultAdminRoleHolder: address(0), + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: address(0), + isDepositLimitSetRoleHolder: address(0), + depositLimitSetRoleHolder: address(0) + }) + ) ) ); } - function test_CreateRevertMissingRoles2( + function test_CreateRevertMissingRoles5( uint48 epochDuration ) public { epochDuration = uint48(bound(epochDuration, 1, 50 weeks)); uint64 lastVersion = vaultFactory.lastVersion(); - vault = Vault(vaultFactory.create(lastVersion, alice, false, "")); - address[] memory networkLimitSetRoleHolders = new address[](1); - networkLimitSetRoleHolders[0] = alice; - address[] memory operatorNetworkSharesSetRoleHolders = new address[](1); - operatorNetworkSharesSetRoleHolders[0] = alice; - address delegator_ = delegatorFactory.create( - 0, - true, - abi.encode( - address(vault), + vm.expectRevert(IVault.MissingRoles.selector); + vault = Vault( + vaultFactory.create( + lastVersion, + alice, abi.encode( - INetworkRestakeDelegator.InitParams({ - baseParams: IBaseDelegator.BaseParams({ - defaultAdminRoleHolder: alice, - hook: address(0), - hookSetRoleHolder: alice - }), - networkLimitSetRoleHolders: networkLimitSetRoleHolders, - operatorNetworkSharesSetRoleHolders: operatorNetworkSharesSetRoleHolders + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: address(0), + depositWhitelistSetRoleHolder: address(0), + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: address(0) }) ) ) ); + } - vm.expectRevert(IVault.MissingRoles.selector); - vault.initialize( - lastVersion, - alice, - abi.encode( - IVault.InitParams({ - collateral: address(collateral), - delegator: delegator_, - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: true, - depositLimit: 0, - defaultAdminRoleHolder: address(0), - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: address(0), - isDepositLimitSetRoleHolder: address(0), - depositLimitSetRoleHolder: address(0) - }) + function test_SetDelegator() public { + uint64 lastVersion = vaultFactory.lastVersion(); + + vault = Vault( + vaultFactory.create( + lastVersion, + alice, + abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 7 days, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ) ) ); - } - function test_CreateRevertMissingRoles3( - uint48 epochDuration - ) public { - epochDuration = uint48(bound(epochDuration, 1, 50 weeks)); - - uint64 lastVersion = vaultFactory.lastVersion(); - vault = Vault(vaultFactory.create(lastVersion, alice, false, "")); + assertEq(vault.isDelegatorInitialized(), false); address[] memory networkLimitSetRoleHolders = new address[](1); networkLimitSetRoleHolders[0] = alice; - address[] memory operatorNetworkSharesSetRoleHolders = new address[](1); - operatorNetworkSharesSetRoleHolders[0] = alice; - address delegator_ = delegatorFactory.create( - 0, - true, - abi.encode( - address(vault), + address[] memory operatorNetworkLimitSetRoleHolders = new address[](1); + operatorNetworkLimitSetRoleHolders[0] = alice; + delegator = FullRestakeDelegator( + delegatorFactory.create( + 1, abi.encode( - INetworkRestakeDelegator.InitParams({ - baseParams: IBaseDelegator.BaseParams({ - defaultAdminRoleHolder: alice, - hook: address(0), - hookSetRoleHolder: alice - }), - networkLimitSetRoleHolders: networkLimitSetRoleHolders, - operatorNetworkSharesSetRoleHolders: operatorNetworkSharesSetRoleHolders + address(vault), + abi.encode( + IFullRestakeDelegator.InitParams({ + baseParams: IBaseDelegator.BaseParams({ + defaultAdminRoleHolder: alice, + hook: address(0), + hookSetRoleHolder: alice + }), + networkLimitSetRoleHolders: networkLimitSetRoleHolders, + operatorNetworkLimitSetRoleHolders: operatorNetworkLimitSetRoleHolders + }) + ) + ) + ) + ); + + vault.setDelegator(address(delegator)); + + assertEq(vault.delegator(), address(delegator)); + assertEq(vault.isDelegatorInitialized(), true); + assertEq(vault.isInitialized(), false); + } + + function test_SetDelegatorRevertDelegatorAlreadyInitialized() public { + uint64 lastVersion = vaultFactory.lastVersion(); + + vault = Vault( + vaultFactory.create( + lastVersion, + alice, + abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 7 days, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice }) ) ) ); - vm.expectRevert(IVault.MissingRoles.selector); - vault.initialize( - lastVersion, - alice, - abi.encode( - IVault.InitParams({ - collateral: address(collateral), - delegator: delegator_, - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: address(0), - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: address(0), - isDepositLimitSetRoleHolder: address(0), - depositLimitSetRoleHolder: alice - }) + address[] memory networkLimitSetRoleHolders = new address[](1); + networkLimitSetRoleHolders[0] = alice; + address[] memory operatorNetworkLimitSetRoleHolders = new address[](1); + operatorNetworkLimitSetRoleHolders[0] = alice; + delegator = FullRestakeDelegator( + delegatorFactory.create( + 1, + abi.encode( + address(vault), + abi.encode( + IFullRestakeDelegator.InitParams({ + baseParams: IBaseDelegator.BaseParams({ + defaultAdminRoleHolder: alice, + hook: address(0), + hookSetRoleHolder: alice + }), + networkLimitSetRoleHolders: networkLimitSetRoleHolders, + operatorNetworkLimitSetRoleHolders: operatorNetworkLimitSetRoleHolders + }) + ) + ) ) ); + + vault.setDelegator(address(delegator)); + + vm.expectRevert(IVault.DelegatorAlreadyInitialized.selector); + vault.setDelegator(address(delegator)); } - function test_CreateRevertMissingRoles4( - uint48 epochDuration - ) public { - epochDuration = uint48(bound(epochDuration, 1, 50 weeks)); + function test_SetDelegatorRevertNotDelegator() public { + uint64 lastVersion = vaultFactory.lastVersion(); + vault = Vault( + vaultFactory.create( + lastVersion, + alice, + abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 7 days, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ) + ) + ); + + vm.expectRevert(IVault.NotDelegator.selector); + vault.setDelegator(address(1)); + } + + function test_SetDelegatorRevertInvalidDelegator() public { uint64 lastVersion = vaultFactory.lastVersion(); - vault = Vault(vaultFactory.create(lastVersion, alice, false, "")); + + vault = Vault( + vaultFactory.create( + lastVersion, + alice, + abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 7 days, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ) + ) + ); + + Vault vault2 = Vault( + vaultFactory.create( + lastVersion, + alice, + abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 7 days, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ) + ) + ); address[] memory networkLimitSetRoleHolders = new address[](1); networkLimitSetRoleHolders[0] = alice; - address[] memory operatorNetworkSharesSetRoleHolders = new address[](1); - operatorNetworkSharesSetRoleHolders[0] = alice; - address delegator_ = delegatorFactory.create( - 0, - true, - abi.encode( - address(vault), + address[] memory operatorNetworkLimitSetRoleHolders = new address[](1); + operatorNetworkLimitSetRoleHolders[0] = alice; + delegator = FullRestakeDelegator( + delegatorFactory.create( + 1, abi.encode( - INetworkRestakeDelegator.InitParams({ - baseParams: IBaseDelegator.BaseParams({ - defaultAdminRoleHolder: alice, - hook: address(0), - hookSetRoleHolder: alice - }), - networkLimitSetRoleHolders: networkLimitSetRoleHolders, - operatorNetworkSharesSetRoleHolders: operatorNetworkSharesSetRoleHolders + address(vault2), + abi.encode( + IFullRestakeDelegator.InitParams({ + baseParams: IBaseDelegator.BaseParams({ + defaultAdminRoleHolder: alice, + hook: address(0), + hookSetRoleHolder: alice + }), + networkLimitSetRoleHolders: networkLimitSetRoleHolders, + operatorNetworkLimitSetRoleHolders: operatorNetworkLimitSetRoleHolders + }) + ) + ) + ) + ); + + vm.expectRevert(IVault.InvalidDelegator.selector); + vault.setDelegator(address(delegator)); + } + + function test_SetSlasher() public { + uint64 lastVersion = vaultFactory.lastVersion(); + + vault = Vault( + vaultFactory.create( + lastVersion, + alice, + abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 7 days, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice }) ) ) ); - vm.expectRevert(IVault.MissingRoles.selector); - vault.initialize( - lastVersion, - alice, - abi.encode( - IVault.InitParams({ - collateral: address(collateral), - delegator: delegator_, - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 1, - defaultAdminRoleHolder: address(0), - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: address(0), - isDepositLimitSetRoleHolder: address(0), - depositLimitSetRoleHolder: address(0) - }) + assertEq(vault.isSlasherInitialized(), false); + + slasher = Slasher(slasherFactory.create(0, abi.encode(address(vault), ""))); + + vault.setSlasher(address(slasher)); + + assertEq(vault.slasher(), address(slasher)); + assertEq(vault.isSlasherInitialized(), true); + assertEq(vault.isInitialized(), false); + } + + function test_SetSlasherRevertSlasherAlreadyInitialized() public { + uint64 lastVersion = vaultFactory.lastVersion(); + + vault = Vault( + vaultFactory.create( + lastVersion, + alice, + abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 7 days, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ) ) ); + + slasher = Slasher(slasherFactory.create(0, abi.encode(address(vault), ""))); + + vault.setSlasher(address(slasher)); + + vm.expectRevert(IVault.SlasherAlreadyInitialized.selector); + vault.setSlasher(address(slasher)); } - function test_CreateRevertMissingRoles5( - uint48 epochDuration - ) public { - epochDuration = uint48(bound(epochDuration, 1, 50 weeks)); + function test_SetSlasherRevertNotSlasher() public { + uint64 lastVersion = vaultFactory.lastVersion(); + vault = Vault( + vaultFactory.create( + lastVersion, + alice, + abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 7 days, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ) + ) + ); + + slasher = Slasher(slasherFactory.create(0, abi.encode(address(vault), ""))); + + vm.expectRevert(IVault.NotSlasher.selector); + vault.setSlasher(address(1)); + } + + function test_SetSlasherRevertInvalidSlasher() public { uint64 lastVersion = vaultFactory.lastVersion(); - vault = Vault(vaultFactory.create(lastVersion, alice, false, "")); - address[] memory networkLimitSetRoleHolders = new address[](1); - networkLimitSetRoleHolders[0] = alice; - address[] memory operatorNetworkSharesSetRoleHolders = new address[](1); - operatorNetworkSharesSetRoleHolders[0] = alice; - address delegator_ = delegatorFactory.create( - 0, - true, - abi.encode( - address(vault), + vault = Vault( + vaultFactory.create( + lastVersion, + alice, abi.encode( - INetworkRestakeDelegator.InitParams({ - baseParams: IBaseDelegator.BaseParams({ - defaultAdminRoleHolder: alice, - hook: address(0), - hookSetRoleHolder: alice - }), - networkLimitSetRoleHolders: networkLimitSetRoleHolders, - operatorNetworkSharesSetRoleHolders: operatorNetworkSharesSetRoleHolders + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 7 days, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice }) ) ) ); - vm.expectRevert(IVault.MissingRoles.selector); - vault.initialize( - lastVersion, - alice, - abi.encode( - IVault.InitParams({ - collateral: address(collateral), - delegator: delegator_, - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: address(0), - depositWhitelistSetRoleHolder: address(0), - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: address(0) - }) + Vault vault2 = Vault( + vaultFactory.create( + lastVersion, + alice, + abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 7 days, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ) + ) + ); + + slasher = Slasher(slasherFactory.create(0, abi.encode(address(vault2), ""))); + + vm.expectRevert(IVault.InvalidSlasher.selector); + vault.setSlasher(address(slasher)); + } + + function test_SetSlasherZeroAddress() public { + uint64 lastVersion = vaultFactory.lastVersion(); + + vault = Vault( + vaultFactory.create( + lastVersion, + alice, + abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: 7 days, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ) ) ); + + vault.setSlasher(address(0)); } function test_DepositTwice(uint256 amount1, uint256 amount2) public { @@ -900,21 +1095,21 @@ contract VaultTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(feeOnTransferCollateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(feeOnTransferCollateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -2477,21 +2672,21 @@ contract VaultTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 0, delegatorParams: abi.encode( INetworkRestakeDelegator.InitParams({ @@ -2524,21 +2719,21 @@ contract VaultTest is Test { IVaultConfigurator.InitParams({ version: vaultFactory.lastVersion(), owner: alice, - vaultParams: IVault.InitParams({ - collateral: address(collateral), - delegator: address(0), - slasher: address(0), - burner: address(0xdEaD), - epochDuration: epochDuration, - depositWhitelist: false, - isDepositLimit: false, - depositLimit: 0, - defaultAdminRoleHolder: alice, - depositWhitelistSetRoleHolder: alice, - depositorWhitelistRoleHolder: alice, - isDepositLimitSetRoleHolder: alice, - depositLimitSetRoleHolder: alice - }), + vaultParams: abi.encode( + IVault.InitParams({ + collateral: address(collateral), + burner: address(0xdEaD), + epochDuration: epochDuration, + depositWhitelist: false, + isDepositLimit: false, + depositLimit: 0, + defaultAdminRoleHolder: alice, + depositWhitelistSetRoleHolder: alice, + depositorWhitelistRoleHolder: alice, + isDepositLimitSetRoleHolder: alice, + depositLimitSetRoleHolder: alice + }) + ), delegatorIndex: 1, delegatorParams: abi.encode( IFullRestakeDelegator.InitParams({ From 114562827d2a92236268d99546c18a000469abc0 Mon Sep 17 00:00:00 2001 From: Kresh Date: Thu, 26 Sep 2024 21:16:40 +0400 Subject: [PATCH 2/2] refactor: remove redundant var --- src/contracts/common/MigratableEntity.sol | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/contracts/common/MigratableEntity.sol b/src/contracts/common/MigratableEntity.sol index b71c1394..e4297473 100644 --- a/src/contracts/common/MigratableEntity.sol +++ b/src/contracts/common/MigratableEntity.sol @@ -19,8 +19,6 @@ abstract contract MigratableEntity is */ address public immutable FACTORY; - address private immutable SELF; - modifier notInitialized() { if (_getInitializedVersion() != 0) { revert AlreadyInitialized(); @@ -35,7 +33,6 @@ abstract contract MigratableEntity is _disableInitializers(); FACTORY = factory; - SELF = address(this); } /**