From 7166610b692e1da94c7f5b48594d69d205377e56 Mon Sep 17 00:00:00 2001 From: Logachev Nikita Date: Fri, 29 Nov 2024 14:30:09 +0300 Subject: [PATCH] fix: minor fixes --- contracts/0.8.25/Accounting.sol | 5 +---- contracts/0.8.25/vaults/StakingVault.sol | 6 +++--- contracts/0.8.25/vaults/VaultHub.sol | 5 ++++- test/0.8.25/vaults/vault.test.ts | 4 ++-- test/0.8.25/vaults/vaultFactory.test.ts | 2 +- test/0.8.25/vaults/vaultStaffRoom.test.ts | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/contracts/0.8.25/Accounting.sol b/contracts/0.8.25/Accounting.sol index 9cb7314a1..af26cb8f2 100644 --- a/contracts/0.8.25/Accounting.sol +++ b/contracts/0.8.25/Accounting.sol @@ -99,10 +99,7 @@ contract Accounting is VaultHub { function initialize(address _admin) external initializer { if (_admin == address(0)) revert ZeroArgument("_admin"); - __AccessControlEnumerable_init(); - __VaultHub_init(); - - _grantRole(DEFAULT_ADMIN_ROLE, _admin); + __VaultHub_init(_admin); } /// @notice calculates all the state changes that is required to apply the report diff --git a/contracts/0.8.25/vaults/StakingVault.sol b/contracts/0.8.25/vaults/StakingVault.sol index e26315482..ca52f7d9d 100644 --- a/contracts/0.8.25/vaults/StakingVault.sol +++ b/contracts/0.8.25/vaults/StakingVault.sol @@ -44,14 +44,14 @@ contract StakingVault is IStakingVault, IBeaconProxy, VaultBeaconChainDepositor, } modifier onlyBeacon() { - if (msg.sender != getBeacon()) revert UnauthorizedSender(msg.sender); + if (msg.sender != getBeacon()) revert SenderShouldBeBeacon(msg.sender, getBeacon()); _; } /// @notice Initialize the contract storage explicitly. /// The initialize function selector is not changed. For upgrades use `_params` variable /// - /// @param _owner vaultStaffRoom address + /// @param _owner vault owner address /// @param _params the calldata for initialize contract after upgrades // solhint-disable-next-line no-unused-vars function initialize(address _owner, bytes calldata _params) external onlyBeacon initializer { @@ -229,5 +229,5 @@ contract StakingVault is IStakingVault, IBeaconProxy, VaultBeaconChainDepositor, error NotHealthy(); error NotAuthorized(string operation, address sender); error LockedCannotBeDecreased(uint256 locked); - error UnauthorizedSender(address sender); + error SenderShouldBeBeacon(address sender, address beacon); } diff --git a/contracts/0.8.25/vaults/VaultHub.sol b/contracts/0.8.25/vaults/VaultHub.sol index e8d2f28f9..29b62ecf2 100644 --- a/contracts/0.8.25/vaults/VaultHub.sol +++ b/contracts/0.8.25/vaults/VaultHub.sol @@ -75,9 +75,12 @@ abstract contract VaultHub is AccessControlEnumerableUpgradeable { _disableInitializers(); } - function __VaultHub_init() internal onlyInitializing { + function __VaultHub_init(address _admin) internal onlyInitializing { + __AccessControlEnumerable_init(); // stone in the elevator _getVaultHubStorage().sockets.push(VaultSocket(IHubVault(address(0)), 0, 0, 0, 0, 0)); + + _grantRole(DEFAULT_ADMIN_ROLE, _admin); } /// @notice added factory address to allowed list diff --git a/test/0.8.25/vaults/vault.test.ts b/test/0.8.25/vaults/vault.test.ts index 3d88614a0..b59db51aa 100644 --- a/test/0.8.25/vaults/vault.test.ts +++ b/test/0.8.25/vaults/vault.test.ts @@ -91,14 +91,14 @@ describe("StakingVault.sol", async () => { it("reverts on impl initialization", async () => { await expect(stakingVault.initialize(await owner.getAddress(), "0x")).to.be.revertedWithCustomError( vaultProxy, - "UnauthorizedSender", + "SenderShouldBeBeacon", ); }); it("reverts if already initialized", async () => { await expect(vaultProxy.initialize(await owner.getAddress(), "0x")).to.be.revertedWithCustomError( vaultProxy, - "UnauthorizedSender", + "SenderShouldBeBeacon", ); }); }); diff --git a/test/0.8.25/vaults/vaultFactory.test.ts b/test/0.8.25/vaults/vaultFactory.test.ts index 13fcdd2f8..f21dbcdf3 100644 --- a/test/0.8.25/vaults/vaultFactory.test.ts +++ b/test/0.8.25/vaults/vaultFactory.test.ts @@ -75,7 +75,7 @@ describe("VaultFactory.sol", () => { await accounting.connect(admin).grantRole(await accounting.VAULT_REGISTRY_ROLE(), admin); //the initialize() function cannot be called on a contract - await expect(implOld.initialize(stranger, "0x")).to.revertedWithCustomError(implOld, "UnauthorizedSender"); + await expect(implOld.initialize(stranger, "0x")).to.revertedWithCustomError(implOld, "SenderShouldBeBeacon"); }); beforeEach(async () => (originalState = await Snapshot.take())); diff --git a/test/0.8.25/vaults/vaultStaffRoom.test.ts b/test/0.8.25/vaults/vaultStaffRoom.test.ts index 203770bc9..1d815fdbb 100644 --- a/test/0.8.25/vaults/vaultStaffRoom.test.ts +++ b/test/0.8.25/vaults/vaultStaffRoom.test.ts @@ -66,7 +66,7 @@ describe("VaultStaffRoom.sol", () => { await accounting.connect(admin).grantRole(await accounting.VAULT_MASTER_ROLE(), admin); //the initialize() function cannot be called on a contract - await expect(implOld.initialize(stranger, "0x")).to.revertedWithCustomError(implOld, "UnauthorizedSender"); + await expect(implOld.initialize(stranger, "0x")).to.revertedWithCustomError(implOld, "SenderShouldBeBeacon"); }); beforeEach(async () => (originalState = await Snapshot.take()));