From 45d2302754d14a31358c096bd1ac9bf89142e33c Mon Sep 17 00:00:00 2001 From: Kresh Date: Wed, 10 Jul 2024 17:59:56 +0400 Subject: [PATCH] add type getter to entity --- src/contracts/common/Entity.sol | 8 ++++- src/contracts/common/Factory.sol | 12 +++---- src/contracts/delegator/BaseDelegator.sol | 5 +-- .../delegator/FullRestakeDelegator.sol | 6 ++-- .../delegator/NetworkRestakeDelegator.sol | 6 ++-- src/contracts/slasher/BaseSlasher.sol | 5 +-- src/contracts/slasher/Slasher.sol | 6 ++-- src/contracts/slasher/VetoSlasher.sol | 6 ++-- src/interfaces/common/IEntity.sol | 6 ++++ src/interfaces/common/IFactory.sol | 18 +++++----- test/DelegatorFactory.t.sol | 12 ++++--- test/SlasherFactory.t.sol | 12 ++++--- test/VaultConfigurator.t.sol | 12 ++++--- test/VaultFactory.t.sol | 12 ++++--- test/common/Entity.t.sol | 10 +++++- test/common/Factory.t.sol | 31 ++++++++++------ test/delegator/FullRestakeDelegator.t.sol | 12 ++++--- test/delegator/NetworkRestakeDelegator.t.sol | 12 ++++--- test/mocks/FakeEntity.sol | 22 ++++++++++++ test/mocks/SimpleEntity.sol | 2 +- test/slasher/Slasher.t.sol | 12 ++++--- test/slasher/VetoSlasher.t.sol | 12 ++++--- test/vault/Vault.t.sol | 36 ++++++++++++------- 23 files changed, 190 insertions(+), 85 deletions(-) create mode 100644 test/mocks/FakeEntity.sol diff --git a/src/contracts/common/Entity.sol b/src/contracts/common/Entity.sol index 12b927ef..7ce2cf8c 100644 --- a/src/contracts/common/Entity.sol +++ b/src/contracts/common/Entity.sol @@ -11,10 +11,16 @@ abstract contract Entity is Initializable, IEntity { */ address public immutable FACTORY; - constructor(address factory) { + /** + * @inheritdoc IEntity + */ + uint64 public immutable TYPE; + + constructor(address factory, uint64 type_) { _disableInitializers(); FACTORY = factory; + TYPE = type_; } /** diff --git a/src/contracts/common/Factory.sol b/src/contracts/common/Factory.sol index 6106ba90..0ca64682 100644 --- a/src/contracts/common/Factory.sol +++ b/src/contracts/common/Factory.sol @@ -21,22 +21,22 @@ contract Factory is Registry, Ownable, IFactory { /** * @inheritdoc IFactory */ - function totalImplementations() public view returns (uint64) { + function totalTypes() public view returns (uint64) { return uint64(_whitelistedImplementations.length()); } /** * @inheritdoc IFactory */ - function implementation(uint64 index) public view returns (address) { - return _whitelistedImplementations.at(index); + function implementation(uint64 type_) public view returns (address) { + return _whitelistedImplementations.at(type_); } /** * @inheritdoc IFactory */ function whitelist(address implementation_) external onlyOwner { - if (IEntity(implementation_).FACTORY() != address(this)) { + if (IEntity(implementation_).FACTORY() != address(this) || IEntity(implementation_).TYPE() != totalTypes()) { revert InvalidImplementation(); } if (!_whitelistedImplementations.add(implementation_)) { @@ -47,8 +47,8 @@ contract Factory is Registry, Ownable, IFactory { /** * @inheritdoc IFactory */ - function create(uint64 index, bool withInitialize, bytes memory data) external returns (address entity_) { - entity_ = implementation(index).cloneDeterministic(keccak256(abi.encode(totalEntities(), index, data))); + function create(uint64 type_, bool withInitialize, bytes memory data) external returns (address entity_) { + entity_ = implementation(type_).cloneDeterministic(keccak256(abi.encode(totalEntities(), type_, data))); _addEntity(entity_); diff --git a/src/contracts/delegator/BaseDelegator.sol b/src/contracts/delegator/BaseDelegator.sol index c1c2dac6..2ded0467 100644 --- a/src/contracts/delegator/BaseDelegator.sol +++ b/src/contracts/delegator/BaseDelegator.sol @@ -67,8 +67,9 @@ contract BaseDelegator is Entity, AccessControlUpgradeable, IBaseDelegator { address vaultFactory, address operatorVaultOptInService, address operatorNetworkOptInService, - address delegatorFactory - ) Entity(delegatorFactory) { + address delegatorFactory, + uint64 entityType + ) Entity(delegatorFactory, entityType) { NETWORK_REGISTRY = networkRegistry; VAULT_FACTORY = vaultFactory; OPERATOR_VAULT_OPT_IN_SERVICE = operatorVaultOptInService; diff --git a/src/contracts/delegator/FullRestakeDelegator.sol b/src/contracts/delegator/FullRestakeDelegator.sol index 005ccb11..0fb34f34 100644 --- a/src/contracts/delegator/FullRestakeDelegator.sol +++ b/src/contracts/delegator/FullRestakeDelegator.sol @@ -38,14 +38,16 @@ contract FullRestakeDelegator is BaseDelegator, IFullRestakeDelegator { address vaultFactory, address operatorVaultOptInService, address operatorNetworkOptInService, - address delegatorFactory + address delegatorFactory, + uint64 entityType ) BaseDelegator( networkRegistry, vaultFactory, operatorVaultOptInService, operatorNetworkOptInService, - delegatorFactory + delegatorFactory, + entityType ) {} diff --git a/src/contracts/delegator/NetworkRestakeDelegator.sol b/src/contracts/delegator/NetworkRestakeDelegator.sol index bc9d72cb..9567d0c3 100644 --- a/src/contracts/delegator/NetworkRestakeDelegator.sol +++ b/src/contracts/delegator/NetworkRestakeDelegator.sol @@ -38,14 +38,16 @@ contract NetworkRestakeDelegator is BaseDelegator, INetworkRestakeDelegator { address vaultFactory, address operatorVaultOptInService, address operatorNetworkOptInService, - address delegatorFactory + address delegatorFactory, + uint64 entityType ) BaseDelegator( networkRegistry, vaultFactory, operatorVaultOptInService, operatorNetworkOptInService, - delegatorFactory + delegatorFactory, + entityType ) {} diff --git a/src/contracts/slasher/BaseSlasher.sol b/src/contracts/slasher/BaseSlasher.sol index 582c2077..f3aafbfd 100644 --- a/src/contracts/slasher/BaseSlasher.sol +++ b/src/contracts/slasher/BaseSlasher.sol @@ -64,8 +64,9 @@ abstract contract BaseSlasher is Entity, IBaseSlasher { address networkVaultOptInService, address operatorVaultOptInService, address operatorNetworkOptInService, - address slasherFactory - ) Entity(slasherFactory) { + address slasherFactory, + uint64 entityType + ) Entity(slasherFactory, entityType) { VAULT_FACTORY = vaultFactory; NETWORK_MIDDLEWARE_SERVICE = networkMiddlewareService; NETWORK_VAULT_OPT_IN_SERVICE = networkVaultOptInService; diff --git a/src/contracts/slasher/Slasher.sol b/src/contracts/slasher/Slasher.sol index 567e6ce9..8cfe8a7f 100644 --- a/src/contracts/slasher/Slasher.sol +++ b/src/contracts/slasher/Slasher.sol @@ -17,7 +17,8 @@ contract Slasher is BaseSlasher, ISlasher { address networkVaultOptInService, address operatorVaultOptInService, address operatorNetworkOptInService, - address slasherFactory + address slasherFactory, + uint64 entityType ) BaseSlasher( vaultFactory, @@ -25,7 +26,8 @@ contract Slasher is BaseSlasher, ISlasher { networkVaultOptInService, operatorVaultOptInService, operatorNetworkOptInService, - slasherFactory + slasherFactory, + entityType ) {} diff --git a/src/contracts/slasher/VetoSlasher.sol b/src/contracts/slasher/VetoSlasher.sol index 7794aea8..75138813 100644 --- a/src/contracts/slasher/VetoSlasher.sol +++ b/src/contracts/slasher/VetoSlasher.sol @@ -64,7 +64,8 @@ contract VetoSlasher is BaseSlasher, AccessControlUpgradeable, IVetoSlasher { address operatorVaultOptInService, address operatorNetworkOptInService, address networkRegistry, - address slasherFactory + address slasherFactory, + uint64 entityType ) BaseSlasher( vaultFactory, @@ -72,7 +73,8 @@ contract VetoSlasher is BaseSlasher, AccessControlUpgradeable, IVetoSlasher { networkVaultOptInService, operatorVaultOptInService, operatorNetworkOptInService, - slasherFactory + slasherFactory, + entityType ) { NETWORK_REGISTRY = networkRegistry; diff --git a/src/interfaces/common/IEntity.sol b/src/interfaces/common/IEntity.sol index 78dfc83d..074a4284 100644 --- a/src/interfaces/common/IEntity.sol +++ b/src/interfaces/common/IEntity.sol @@ -8,6 +8,12 @@ interface IEntity { */ function FACTORY() external view returns (address); + /** + * @notice Get the entity's type. + * @return type of the entity + */ + function TYPE() external view returns (uint64); + /** * @notice Initialize this entity contract 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 d09e5a67..58003f21 100644 --- a/src/interfaces/common/IFactory.sol +++ b/src/interfaces/common/IFactory.sol @@ -8,30 +8,30 @@ interface IFactory is IRegistry { error InvalidImplementation(); /** - * @notice Get the total number of whitelisted implementations. - * @return total number of implementations + * @notice Get the total number of whitelisted types. + * @return total number of types */ - function totalImplementations() external view returns (uint64); + function totalTypes() external view returns (uint64); /** - * @notice Get the implementation for a given index. - * @param index position to get the implementation at + * @notice Get the implementation for a given type. + * @param type_ position to get the implementation at * @return address of the implementation */ - function implementation(uint64 index) external view returns (address); + function implementation(uint64 type_) external view returns (address); /** - * @notice Whitelist a new implementation for entities. + * @notice Whitelist a new type of entities. * @param implementation address of the new implementation */ function whitelist(address implementation) external; /** * @notice Create a new entity at the factory. - * @param index `index`-th implementation to use + * @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 */ - function create(uint64 index, bool withInitialize, bytes memory data) external returns (address); + function create(uint64 type_, bool withInitialize, bytes memory data) external returns (address); } diff --git a/test/DelegatorFactory.t.sol b/test/DelegatorFactory.t.sol index 8544e517..f75ba48a 100644 --- a/test/DelegatorFactory.t.sol +++ b/test/DelegatorFactory.t.sol @@ -76,7 +76,8 @@ contract DelegatorFactoryTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(networkRestakeDelegatorImpl); @@ -87,7 +88,8 @@ contract DelegatorFactoryTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(fullRestakeDelegatorImpl); @@ -99,7 +101,8 @@ contract DelegatorFactoryTest is Test { address(networkVaultOptInService), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(slasherImpl); @@ -112,7 +115,8 @@ contract DelegatorFactoryTest is Test { address(operatorVaultOptInService), address(operatorNetworkOptInService), address(networkRegistry), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(vetoSlasherImpl); diff --git a/test/SlasherFactory.t.sol b/test/SlasherFactory.t.sol index 2697276b..fa60e94d 100644 --- a/test/SlasherFactory.t.sol +++ b/test/SlasherFactory.t.sol @@ -77,7 +77,8 @@ contract SlasherFactoryTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(networkRestakeDelegatorImpl); @@ -88,7 +89,8 @@ contract SlasherFactoryTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(fullRestakeDelegatorImpl); @@ -100,7 +102,8 @@ contract SlasherFactoryTest is Test { address(networkVaultOptInService), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(slasherImpl); @@ -113,7 +116,8 @@ contract SlasherFactoryTest is Test { address(operatorVaultOptInService), address(operatorNetworkOptInService), address(networkRegistry), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(vetoSlasherImpl); diff --git a/test/VaultConfigurator.t.sol b/test/VaultConfigurator.t.sol index 17808211..abef86c7 100644 --- a/test/VaultConfigurator.t.sol +++ b/test/VaultConfigurator.t.sol @@ -80,7 +80,8 @@ contract VaultConfiguratorTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(networkRestakeDelegatorImpl); @@ -91,7 +92,8 @@ contract VaultConfiguratorTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(fullRestakeDelegatorImpl); @@ -103,7 +105,8 @@ contract VaultConfiguratorTest is Test { address(networkVaultOptInService), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(slasherImpl); @@ -116,7 +119,8 @@ contract VaultConfiguratorTest is Test { address(operatorVaultOptInService), address(operatorNetworkOptInService), address(networkRegistry), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(vetoSlasherImpl); diff --git a/test/VaultFactory.t.sol b/test/VaultFactory.t.sol index 1668fd58..18ebfaaf 100644 --- a/test/VaultFactory.t.sol +++ b/test/VaultFactory.t.sol @@ -76,7 +76,8 @@ contract VaultFactoryTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(networkRestakeDelegatorImpl); @@ -87,7 +88,8 @@ contract VaultFactoryTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(fullRestakeDelegatorImpl); @@ -99,7 +101,8 @@ contract VaultFactoryTest is Test { address(networkVaultOptInService), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(slasherImpl); @@ -112,7 +115,8 @@ contract VaultFactoryTest is Test { address(operatorVaultOptInService), address(operatorNetworkOptInService), address(networkRegistry), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(vetoSlasherImpl); diff --git a/test/common/Entity.t.sol b/test/common/Entity.t.sol index 091fa6cc..a7915b5a 100644 --- a/test/common/Entity.t.sol +++ b/test/common/Entity.t.sol @@ -28,12 +28,20 @@ contract EntityTest is Test { } function test_Create() public { - address impl = address(new SimpleEntity(address(factory))); + address impl = address(new SimpleEntity(address(factory), factory.totalTypes())); assertEq(IEntity(impl).FACTORY(), address(factory)); factory.whitelist(impl); address entity = factory.create(0, true, ""); assertEq(IEntity(entity).FACTORY(), address(factory)); + assertEq(IEntity(entity).TYPE(), 0); + + impl = address(new SimpleEntity(address(factory), factory.totalTypes())); + factory.whitelist(impl); + + entity = factory.create(1, true, ""); + assertEq(IEntity(entity).FACTORY(), address(factory)); + assertEq(IEntity(entity).TYPE(), 1); vm.expectRevert(); IEntity(entity).initialize(""); diff --git a/test/common/Factory.t.sol b/test/common/Factory.t.sol index 6627ec7b..4ea684cb 100644 --- a/test/common/Factory.t.sol +++ b/test/common/Factory.t.sol @@ -9,6 +9,7 @@ import {IFactory} from "src/interfaces/common/IFactory.sol"; import {IEntity} from "src/interfaces/common/IEntity.sol"; import {SimpleEntity} from "test/mocks/SimpleEntity.sol"; +import {FakeEntity} from "test/mocks/FakeEntity.sol"; contract FactoryTest is Test { address owner; @@ -28,20 +29,20 @@ contract FactoryTest is Test { } function test_Create() public { - assertEq(factory.totalImplementations(), 0); + assertEq(factory.totalTypes(), 0); vm.expectRevert(); factory.implementation(0); - address impl = address(new SimpleEntity(address(factory))); + address impl = address(new SimpleEntity(address(factory), factory.totalTypes())); factory.whitelist(impl); - assertEq(factory.totalImplementations(), 1); + assertEq(factory.totalTypes(), 1); assertEq(factory.implementation(0), impl); - impl = address(new SimpleEntity(address(factory))); + impl = address(new SimpleEntity(address(factory), factory.totalTypes())); factory.whitelist(impl); - assertEq(factory.totalImplementations(), 2); + assertEq(factory.totalTypes(), 2); assertEq(factory.implementation(1), impl); assertEq(factory.isEntity(alice), false); @@ -50,10 +51,10 @@ contract FactoryTest is Test { } function test_CreateRevertInvalidIndex() public { - address impl = address(new SimpleEntity(address(factory))); + address impl = address(new SimpleEntity(address(factory), factory.totalTypes())); factory.whitelist(impl); - impl = address(new SimpleEntity(address(factory))); + impl = address(new SimpleEntity(address(factory), factory.totalTypes())); factory.whitelist(impl); vm.expectRevert(); @@ -63,16 +64,26 @@ contract FactoryTest is Test { factory.create(3, true, ""); } - function test_WhitelistRevertInvalidImplementation() public { - address impl = address(new SimpleEntity(address(address(1)))); + function test_WhitelistRevertInvalidImplementation1() public { + address impl = address(new SimpleEntity(address(address(1)), factory.totalTypes())); + vm.expectRevert(IFactory.InvalidImplementation.selector); + factory.whitelist(impl); + } + + function test_WhitelistRevertInvalidImplementation2() public { + address impl = address(new SimpleEntity(address(factory), factory.totalTypes())); + factory.whitelist(impl); + + impl = address(new SimpleEntity(address(factory), factory.totalTypes() - 1)); vm.expectRevert(IFactory.InvalidImplementation.selector); factory.whitelist(impl); } function test_WhitelistRevertAlreadyWhitelisted() public { - address impl = address(new SimpleEntity(address(factory))); + address impl = address(new FakeEntity(address(factory), factory.totalTypes())); factory.whitelist(impl); + FakeEntity(impl).setType(factory.totalTypes()); vm.expectRevert(IFactory.AlreadyWhitelisted.selector); factory.whitelist(impl); } diff --git a/test/delegator/FullRestakeDelegator.t.sol b/test/delegator/FullRestakeDelegator.t.sol index bc2c3a9c..d90a09a6 100644 --- a/test/delegator/FullRestakeDelegator.t.sol +++ b/test/delegator/FullRestakeDelegator.t.sol @@ -83,7 +83,8 @@ contract FullRestakeDelegatorTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(networkRestakeDelegatorImpl); @@ -94,7 +95,8 @@ contract FullRestakeDelegatorTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(fullRestakeDelegatorImpl); @@ -106,7 +108,8 @@ contract FullRestakeDelegatorTest is Test { address(networkVaultOptInService), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(slasherImpl); @@ -119,7 +122,8 @@ contract FullRestakeDelegatorTest is Test { address(operatorVaultOptInService), address(operatorNetworkOptInService), address(networkRegistry), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(vetoSlasherImpl); diff --git a/test/delegator/NetworkRestakeDelegator.t.sol b/test/delegator/NetworkRestakeDelegator.t.sol index 891be5b9..e0d4f911 100644 --- a/test/delegator/NetworkRestakeDelegator.t.sol +++ b/test/delegator/NetworkRestakeDelegator.t.sol @@ -85,7 +85,8 @@ contract NetworkRestakeDelegatorTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(networkRestakeDelegatorImpl); @@ -96,7 +97,8 @@ contract NetworkRestakeDelegatorTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(fullRestakeDelegatorImpl); @@ -108,7 +110,8 @@ contract NetworkRestakeDelegatorTest is Test { address(networkVaultOptInService), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(slasherImpl); @@ -121,7 +124,8 @@ contract NetworkRestakeDelegatorTest is Test { address(operatorVaultOptInService), address(operatorNetworkOptInService), address(networkRegistry), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(vetoSlasherImpl); diff --git a/test/mocks/FakeEntity.sol b/test/mocks/FakeEntity.sol new file mode 100644 index 00000000..1d9e691c --- /dev/null +++ b/test/mocks/FakeEntity.sol @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +contract FakeEntity { + address public immutable FACTORY; + uint64 public TYPE; + + uint256 public a; + + constructor(address factory, uint64 type_) { + FACTORY = factory; + TYPE = type_; + } + + function setType(uint64 type_) external returns (uint64) { + TYPE = type_; + } + + function setA(uint256 _a) public { + a = _a; + } +} diff --git a/test/mocks/SimpleEntity.sol b/test/mocks/SimpleEntity.sol index 793f35d5..c07a22bd 100644 --- a/test/mocks/SimpleEntity.sol +++ b/test/mocks/SimpleEntity.sol @@ -6,7 +6,7 @@ import {Entity} from "src/contracts/common/Entity.sol"; contract SimpleEntity is Entity { uint256 public a; - constructor(address factory) Entity(factory) {} + constructor(address factory, uint64 type_) Entity(factory, type_) {} function setA(uint256 _a) public { a = _a; diff --git a/test/slasher/Slasher.t.sol b/test/slasher/Slasher.t.sol index 16deeb51..0c4d5e04 100644 --- a/test/slasher/Slasher.t.sol +++ b/test/slasher/Slasher.t.sol @@ -85,7 +85,8 @@ contract SlasherTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(networkRestakeDelegatorImpl); @@ -96,7 +97,8 @@ contract SlasherTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(fullRestakeDelegatorImpl); @@ -108,7 +110,8 @@ contract SlasherTest is Test { address(networkVaultOptInService), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(slasherImpl); @@ -121,7 +124,8 @@ contract SlasherTest is Test { address(operatorVaultOptInService), address(operatorNetworkOptInService), address(networkRegistry), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(vetoSlasherImpl); diff --git a/test/slasher/VetoSlasher.t.sol b/test/slasher/VetoSlasher.t.sol index 6d6d4009..900ec7c2 100644 --- a/test/slasher/VetoSlasher.t.sol +++ b/test/slasher/VetoSlasher.t.sol @@ -87,7 +87,8 @@ contract VetoSlasherTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(networkRestakeDelegatorImpl); @@ -98,7 +99,8 @@ contract VetoSlasherTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(fullRestakeDelegatorImpl); @@ -110,7 +112,8 @@ contract VetoSlasherTest is Test { address(networkVaultOptInService), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(slasherImpl); @@ -123,7 +126,8 @@ contract VetoSlasherTest is Test { address(operatorVaultOptInService), address(operatorNetworkOptInService), address(networkRegistry), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(vetoSlasherImpl); diff --git a/test/vault/Vault.t.sol b/test/vault/Vault.t.sol index 6d87d79a..c69fc8b7 100644 --- a/test/vault/Vault.t.sol +++ b/test/vault/Vault.t.sol @@ -85,7 +85,8 @@ contract VaultTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(networkRestakeDelegatorImpl); @@ -96,7 +97,8 @@ contract VaultTest is Test { address(vaultFactory), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(delegatorFactory) + address(delegatorFactory), + delegatorFactory.totalTypes() ) ); delegatorFactory.whitelist(fullRestakeDelegatorImpl); @@ -108,7 +110,8 @@ contract VaultTest is Test { address(networkVaultOptInService), address(operatorVaultOptInService), address(operatorNetworkOptInService), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(slasherImpl); @@ -121,7 +124,8 @@ contract VaultTest is Test { address(operatorVaultOptInService), address(operatorNetworkOptInService), address(networkRegistry), - address(slasherFactory) + address(slasherFactory), + slasherFactory.totalTypes() ) ); slasherFactory.whitelist(vetoSlasherImpl); @@ -1189,7 +1193,8 @@ contract VaultTest is Test { - vault.withdrawals(vault.currentEpoch() + 1) <= 2 ); assertEq( - vault.activeSupply(), activeSupply1 - activeSupply1.mulDiv(slashAmountSlashed2, depositAmount - slashAmountReal1) + vault.activeSupply(), + activeSupply1 - activeSupply1.mulDiv(slashAmountSlashed2, depositAmount - slashAmountReal1) ); } else { uint256 slashAmountReal1 = Math.min(slashAmount1, depositAmount - withdrawAmount1 - withdrawAmount2); @@ -1200,9 +1205,12 @@ contract VaultTest is Test { assertEq(collateral.balanceOf(address(vault.burner())) - tokensBeforeBurner, slashAmountReal1); uint256 activeSupply1 = depositAmount - withdrawAmount1 - withdrawAmount2 - - (depositAmount - withdrawAmount1 - withdrawAmount2).mulDiv(slashAmountReal1, depositAmount - withdrawAmount1); + - (depositAmount - withdrawAmount1 - withdrawAmount2).mulDiv( + slashAmountReal1, depositAmount - withdrawAmount1 + ); uint256 withdrawals1 = withdrawAmount1; - uint256 nextWithdrawals1 = withdrawAmount2 - withdrawAmount2.mulDiv(slashAmountReal1, depositAmount - withdrawAmount1); + uint256 nextWithdrawals1 = + withdrawAmount2 - withdrawAmount2.mulDiv(slashAmountReal1, depositAmount - withdrawAmount1); assertEq(vault.totalSupply(), depositAmount - slashAmountReal1); assertEq(vault.withdrawals(vault.currentEpoch()), withdrawals1); assertTrue(nextWithdrawals1 - vault.withdrawals(vault.currentEpoch() + 1) <= 1); @@ -1217,15 +1225,17 @@ contract VaultTest is Test { assertEq(collateral.balanceOf(address(vault.burner())) - tokensBeforeBurner, slashAmountSlashed2); assertEq(vault.totalSupply(), depositAmount - slashAmountReal1 - slashAmountSlashed2); - assertEq( - vault.withdrawals(vault.currentEpoch()), withdrawals1 - ); + assertEq(vault.withdrawals(vault.currentEpoch()), withdrawals1); assertTrue( - (nextWithdrawals1 - nextWithdrawals1.mulDiv(slashAmountSlashed2, depositAmount - withdrawAmount1 - slashAmountReal1)) - - vault.withdrawals(vault.currentEpoch() + 1) <= 2 + ( + nextWithdrawals1 + - nextWithdrawals1.mulDiv(slashAmountSlashed2, depositAmount - withdrawAmount1 - slashAmountReal1) + ) - vault.withdrawals(vault.currentEpoch() + 1) <= 2 ); assertEq( - vault.activeSupply(), activeSupply1 - activeSupply1.mulDiv(slashAmountSlashed2, depositAmount - withdrawAmount1 - slashAmountReal1) + vault.activeSupply(), + activeSupply1 + - activeSupply1.mulDiv(slashAmountSlashed2, depositAmount - withdrawAmount1 - slashAmountReal1) ); } }