Skip to content

Commit

Permalink
complete vault tests
Browse files Browse the repository at this point in the history
  • Loading branch information
1kresh committed Jul 2, 2024
1 parent 6e57fe0 commit 1282aeb
Show file tree
Hide file tree
Showing 7 changed files with 381 additions and 55 deletions.
4 changes: 3 additions & 1 deletion src/contracts/delegator/BaseDelegator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ contract BaseDelegator is Entity, AccessControlUpgradeable, IBaseDelegator {

IBaseDelegator.BaseParams memory baseParams = _initializeInternal(vault_, data_);

_grantRole(DEFAULT_ADMIN_ROLE, baseParams.defaultAdminRoleHolder);
if (baseParams.defaultAdminRoleHolder != address(0)) {
_grantRole(DEFAULT_ADMIN_ROLE, baseParams.defaultAdminRoleHolder);
}
}
}
17 changes: 15 additions & 2 deletions src/contracts/delegator/FullRestakeDelegator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,21 @@ contract FullRestakeDelegator is BaseDelegator, IFullRestakeDelegator {
) internal override returns (IBaseDelegator.BaseParams memory) {
InitParams memory params = abi.decode(data, (InitParams));

_grantRole(NETWORK_LIMIT_SET_ROLE, params.networkLimitSetRoleHolder);
_grantRole(OPERATOR_NETWORK_LIMIT_SET_ROLE, params.operatorNetworkLimitSetRoleHolder);
if (
params.baseParams.defaultAdminRoleHolder == address(0)
&& (
params.networkLimitSetRoleHolder == address(0) || params.operatorNetworkLimitSetRoleHolder == address(0)
)
) {
revert MissingRoleHolders();
}

if (params.networkLimitSetRoleHolder != address(0)) {
_grantRole(NETWORK_LIMIT_SET_ROLE, params.networkLimitSetRoleHolder);
}
if (params.operatorNetworkLimitSetRoleHolder != address(0)) {
_grantRole(OPERATOR_NETWORK_LIMIT_SET_ROLE, params.operatorNetworkLimitSetRoleHolder);
}

return params.baseParams;
}
Expand Down
18 changes: 16 additions & 2 deletions src/contracts/delegator/NetworkRestakeDelegator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,22 @@ contract NetworkRestakeDelegator is BaseDelegator, INetworkRestakeDelegator {
) internal override returns (IBaseDelegator.BaseParams memory) {
InitParams memory params = abi.decode(data, (InitParams));

_grantRole(NETWORK_LIMIT_SET_ROLE, params.networkLimitSetRoleHolder);
_grantRole(OPERATOR_NETWORK_SHARES_SET_ROLE, params.operatorNetworkSharesSetRoleHolder);
if (
params.baseParams.defaultAdminRoleHolder == address(0)
&& (
params.networkLimitSetRoleHolder == address(0)
|| params.operatorNetworkSharesSetRoleHolder == address(0)
)
) {
revert MissingRoleHolders();
}

if (params.networkLimitSetRoleHolder != address(0)) {
_grantRole(NETWORK_LIMIT_SET_ROLE, params.networkLimitSetRoleHolder);
}
if (params.operatorNetworkSharesSetRoleHolder != address(0)) {
_grantRole(OPERATOR_NETWORK_SHARES_SET_ROLE, params.operatorNetworkSharesSetRoleHolder);
}

return params.baseParams;
}
Expand Down
14 changes: 10 additions & 4 deletions src/contracts/vault/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau
* @inheritdoc IVault
*/
function setSlasher(address slasher_) external onlyRole(SLASHER_SET_ROLE) {
if (!IRegistry(SLASHER_FACTORY).isEntity(slasher_)) {
if (slasher_ != address(0) && !IRegistry(SLASHER_FACTORY).isEntity(slasher_)) {
revert NotSlasher();
}

Expand Down Expand Up @@ -330,18 +330,24 @@ contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVau

slasherSetEpochsDelay = params.slasherSetEpochsDelay;

_grantRole(DEFAULT_ADMIN_ROLE, params.defaultAdminRoleHolder);
if (params.defaultAdminRoleHolder != address(0)) {
_grantRole(DEFAULT_ADMIN_ROLE, params.defaultAdminRoleHolder);
}

if (params.slasher == address(0)) {
_grantRole(SLASHER_SET_ROLE, params.slasherSetRoleHolder);
if (params.slasherSetRoleHolder != address(0)) {
_grantRole(SLASHER_SET_ROLE, params.slasherSetRoleHolder);
}
} else {
_slasher.address_ = params.slasher;
}

if (params.depositWhitelist) {
depositWhitelist = true;

_grantRole(DEPOSITOR_WHITELIST_ROLE, params.depositorWhitelistRoleHolder);
if (params.depositorWhitelistRoleHolder != address(0)) {
_grantRole(DEPOSITOR_WHITELIST_ROLE, params.depositorWhitelistRoleHolder);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/interfaces/delegator/IFullRestakeDelegator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {IBaseDelegator} from "./IBaseDelegator.sol";

interface IFullRestakeDelegator is IBaseDelegator {
error ExceedsMaxNetworkLimit();
error MissingRoleHolders();

/**
* @notice Initial parameters needed for a full restaking delegator deployment.
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/delegator/INetworkRestakeDelegator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {IBaseDelegator} from "./IBaseDelegator.sol";

interface INetworkRestakeDelegator is IBaseDelegator {
error ExceedsMaxNetworkLimit();
error MissingRoleHolders();

/**
* @notice Initial parameters needed for a full restaking delegator deployment.
Expand Down
Loading

0 comments on commit 1282aeb

Please sign in to comment.