diff --git a/script/deploy/Vault.s.sol b/script/deploy/Vault.s.sol index d35480c6..d45536f4 100644 --- a/script/deploy/Vault.s.sol +++ b/script/deploy/Vault.s.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.13; import "forge-std/Script.sol"; import {IMigratablesRegistry} from "src/interfaces/base/IMigratablesRegistry.sol"; -import {IVaultDelegation} from "src/interfaces/IVaultDelegation.sol"; +import {IVault} from "src/interfaces/IVault.sol"; contract VaultScript is Script { function run( @@ -25,7 +25,7 @@ contract VaultScript is Script { IMigratablesRegistry(vaultRegistry).create( IMigratablesRegistry(vaultRegistry).lastVersion(), abi.encode( - IVaultDelegation.InitParams({ + IVault.InitParams({ owner: owner, collateral: collateral, epochDuration: epochDuration, diff --git a/src/contracts/Vault.sol b/src/contracts/Vault.sol index edb83f5c..646572d0 100644 --- a/src/contracts/Vault.sol +++ b/src/contracts/Vault.sol @@ -2,12 +2,15 @@ pragma solidity 0.8.25; import {IVault} from "src/interfaces/IVault.sol"; +import {IRegistry} from "src/interfaces/base/IRegistry.sol"; +import {IMigratableEntity} from "src/interfaces/base/IMigratableEntity.sol"; import {ICollateral} from "src/interfaces/base/ICollateral.sol"; import {IMiddlewarePlugin} from "src/interfaces/plugins/IMiddlewarePlugin.sol"; import {INetworkOptInPlugin} from "src/interfaces/plugins/INetworkOptInPlugin.sol"; import {IOperatorOptInPlugin} from "src/interfaces/plugins/IOperatorOptInPlugin.sol"; -import {VaultDelegation} from "./VaultDelegation.sol"; +import {VaultStorage} from "./VaultStorage.sol"; +import {MigratableEntity} from "./base/MigratableEntity.sol"; import {ERC4626Math} from "./libraries/ERC4626Math.sol"; import {Checkpoints} from "./libraries/Checkpoints.sol"; @@ -15,29 +18,12 @@ import {Checkpoints} from "./libraries/Checkpoints.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; import {Time} from "@openzeppelin/contracts/utils/types/Time.sol"; +import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; -contract Vault is VaultDelegation, IVault { +contract Vault is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVault { using Checkpoints for Checkpoints.Trace256; using Math for uint256; - constructor( - address networkRegistry, - address operatorRegistry, - address networkMiddlewarePlugin, - address networkVaultOptInPlugin, - address operatorVaultOptInPlugin, - address operatorNetworkOptInPlugin - ) - VaultDelegation( - networkRegistry, - operatorRegistry, - networkMiddlewarePlugin, - networkVaultOptInPlugin, - operatorVaultOptInPlugin, - operatorNetworkOptInPlugin - ) - {} - /** * @inheritdoc IVault */ @@ -77,6 +63,77 @@ contract Vault is VaultDelegation, IVault { return Math.min(totalSupply(), Math.min(networkLimit(network, resolver), operatorLimit(operator, network))); } + /** + * @inheritdoc IVault + */ + function networkLimit(address network, address resolver) public view returns (uint256) { + return _getLimit(_networkLimit[network][resolver], nextNetworkLimit[network][resolver]); + } + + /** + * @inheritdoc IVault + */ + function operatorLimit(address operator, address network) public view returns (uint256) { + return _getLimit(_operatorLimit[operator][network], nextOperatorLimit[operator][network]); + } + + constructor( + address networkRegistry, + address operatorRegistry, + address networkMiddlewarePlugin, + address networkVaultOptInPlugin, + address operatorVaultOptInPlugin, + address operatorNetworkOptInPlugin + ) + VaultStorage( + networkRegistry, + operatorRegistry, + networkMiddlewarePlugin, + networkVaultOptInPlugin, + operatorVaultOptInPlugin, + operatorNetworkOptInPlugin + ) + {} + + /** + * @inheritdoc IMigratableEntity + */ + function initialize(uint64 version_, bytes memory data) public override reinitializer(version_) { + (IVault.InitParams memory params) = abi.decode(data, (IVault.InitParams)); + + if (params.epochDuration == 0) { + revert InvalidEpochDuration(); + } + + if (params.vetoDuration + params.slashDuration > params.epochDuration) { + revert InvalidSlashDuration(); + } + + if (params.adminFee > ADMIN_FEE_BASE) { + revert InvalidAdminFee(); + } + + _initialize(params.owner); + + collateral = params.collateral; + + epochDurationInit = Time.timestamp(); + epochDuration = params.epochDuration; + + vetoDuration = params.vetoDuration; + slashDuration = params.slashDuration; + + adminFee = params.adminFee; + depositWhitelist = params.depositWhitelist; + + _grantRole(DEFAULT_ADMIN_ROLE, params.owner); + _grantRole(NETWORK_LIMIT_SET_ROLE, params.owner); + _grantRole(OPERATOR_LIMIT_SET_ROLE, params.owner); + if (params.depositWhitelist) { + _grantRole(DEPOSITOR_WHITELIST_ROLE, params.owner); + } + } + /** * @inheritdoc IVault */ @@ -317,4 +374,151 @@ contract Vault is VaultDelegation, IVault { emit VetoSlash(slashIndex); } + + /** + * @inheritdoc IVault + */ + function setMaxNetworkLimit(address resolver, uint256 amount) external { + if (maxNetworkLimit[msg.sender][resolver] == amount) { + revert AlreadySet(); + } + + if (!IRegistry(NETWORK_REGISTRY).isEntity(msg.sender)) { + revert NotNetwork(); + } + + maxNetworkLimit[msg.sender][resolver] = amount; + + Limit storage limit = _networkLimit[msg.sender][resolver]; + DelayedLimit storage nextLimit = nextNetworkLimit[msg.sender][resolver]; + + _updateLimit(limit, nextLimit); + + if (limit.amount > amount) { + limit.amount = amount; + } + if (nextLimit.amount > amount) { + nextLimit.amount = amount; + } + + emit SetMaxNetworkLimit(msg.sender, resolver, amount); + } + + /** + * @inheritdoc IVault + */ + function setAdminFee(uint256 adminFee_) external onlyRole(ADMIN_FEE_SET_ROLE) { + if (adminFee == adminFee_) { + revert AlreadySet(); + } + + if (adminFee_ > ADMIN_FEE_BASE) { + revert InvalidAdminFee(); + } + + adminFee = adminFee_; + + emit SetAdminFee(adminFee_); + } + + /** + * @inheritdoc IVault + */ + function setDepositWhitelist(bool status) external onlyRole(DEPOSIT_WHITELIST_SET_ROLE) { + if (depositWhitelist == status) { + revert AlreadySet(); + } + + depositWhitelist = status; + + emit SetDepositWhitelist(status); + } + + /** + * @inheritdoc IVault + */ + function setDepositorWhitelistStatus(address account, bool status) external onlyRole(DEPOSITOR_WHITELIST_ROLE) { + if (isDepositorWhitelisted[account] == status) { + revert AlreadySet(); + } + + if (status && !depositWhitelist) { + revert NoDepositWhitelist(); + } + + isDepositorWhitelisted[account] = status; + + emit SetDepositorWhitelistStatus(account, status); + } + + /** + * @inheritdoc IVault + */ + function setNetworkLimit( + address network, + address resolver, + uint256 amount + ) external onlyRole(NETWORK_LIMIT_SET_ROLE) { + if (amount > maxNetworkLimit[network][resolver]) { + revert ExceedsMaxNetworkLimit(); + } + + Limit storage limit = _networkLimit[network][resolver]; + DelayedLimit storage nextLimit = nextNetworkLimit[network][resolver]; + + _setLimit(limit, nextLimit, amount); + + emit SetNetworkLimit(network, resolver, amount); + } + + /** + * @inheritdoc IVault + */ + function setOperatorLimit( + address operator, + address network, + uint256 amount + ) external onlyRole(OPERATOR_LIMIT_SET_ROLE) { + Limit storage limit = _operatorLimit[operator][network]; + DelayedLimit storage nextLimit = nextOperatorLimit[operator][network]; + + _setLimit(limit, nextLimit, amount); + + emit SetOperatorLimit(operator, network, amount); + } + + function _getLimit(Limit storage limit, DelayedLimit storage nextLimit) private view returns (uint256) { + if (nextLimit.timestamp == 0 || Time.timestamp() < nextLimit.timestamp) { + return limit.amount; + } + return nextLimit.amount; + } + + function _setLimit(Limit storage limit, DelayedLimit storage nextLimit, uint256 amount) private { + _updateLimit(limit, nextLimit); + + if (amount < limit.amount) { + nextLimit.amount = amount; + nextLimit.timestamp = currentEpochStart() + 2 * epochDuration; + } else { + limit.amount = amount; + nextLimit.amount = 0; + nextLimit.timestamp = 0; + } + } + + function _updateLimit(Limit storage limit, DelayedLimit storage nextLimit) internal { + if (nextLimit.timestamp != 0 && nextLimit.timestamp <= Time.timestamp()) { + limit.amount = nextLimit.amount; + nextLimit.timestamp = 0; + nextLimit.amount = 0; + } + } + + /** + * @inheritdoc IMigratableEntity + */ + function migrate(bytes memory) public override { + revert(); + } } diff --git a/src/contracts/VaultDelegation.sol b/src/contracts/VaultDelegation.sol deleted file mode 100644 index f2bf85e5..00000000 --- a/src/contracts/VaultDelegation.sol +++ /dev/null @@ -1,240 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.25; - -import {IVaultDelegation} from "src/interfaces/IVaultDelegation.sol"; -import {IRegistry} from "src/interfaces/base/IRegistry.sol"; -import {INetworkOptInPlugin} from "src/interfaces/plugins/INetworkOptInPlugin.sol"; -import {IOperatorOptInPlugin} from "src/interfaces/plugins/IOperatorOptInPlugin.sol"; -import {IMigratableEntity} from "src/interfaces/base/IMigratableEntity.sol"; - -import {MigratableEntity} from "./base/MigratableEntity.sol"; -import {VaultStorage} from "./VaultStorage.sol"; - -import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; -import {Time} from "@openzeppelin/contracts/utils/types/Time.sol"; -import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; - -contract VaultDelegation is VaultStorage, MigratableEntity, AccessControlUpgradeable, IVaultDelegation { - using Strings for string; - - constructor( - address networkRegistry, - address operatorRegistry, - address networkMiddlewarePlugin, - address networkVaultOptInPlugin, - address operatorVaultOptInPlugin, - address operatorNetworkOptInPlugin - ) - VaultStorage( - networkRegistry, - operatorRegistry, - networkMiddlewarePlugin, - networkVaultOptInPlugin, - operatorVaultOptInPlugin, - operatorNetworkOptInPlugin - ) - {} - - /** - * @inheritdoc IVaultDelegation - */ - function networkLimit(address network, address resolver) public view returns (uint256) { - return _getLimit(_networkLimit[network][resolver], nextNetworkLimit[network][resolver]); - } - - /** - * @inheritdoc IVaultDelegation - */ - function operatorLimit(address operator, address network) public view returns (uint256) { - return _getLimit(_operatorLimit[operator][network], nextOperatorLimit[operator][network]); - } - - /** - * @inheritdoc IMigratableEntity - */ - function initialize( - uint64 version_, - bytes memory data - ) public override(MigratableEntity, IMigratableEntity) reinitializer(version_) { - (IVaultDelegation.InitParams memory params) = abi.decode(data, (IVaultDelegation.InitParams)); - - if (params.epochDuration == 0) { - revert InvalidEpochDuration(); - } - - if (params.vetoDuration + params.slashDuration > params.epochDuration) { - revert InvalidSlashDuration(); - } - - if (params.adminFee > ADMIN_FEE_BASE) { - revert InvalidAdminFee(); - } - - _initialize(params.owner); - - collateral = params.collateral; - - epochDurationInit = Time.timestamp(); - epochDuration = params.epochDuration; - - vetoDuration = params.vetoDuration; - slashDuration = params.slashDuration; - - adminFee = params.adminFee; - depositWhitelist = params.depositWhitelist; - - _grantRole(DEFAULT_ADMIN_ROLE, params.owner); - _grantRole(NETWORK_LIMIT_SET_ROLE, params.owner); - _grantRole(OPERATOR_LIMIT_SET_ROLE, params.owner); - if (params.depositWhitelist) { - _grantRole(DEPOSITOR_WHITELIST_ROLE, params.owner); - } - } - - /** - * @inheritdoc IVaultDelegation - */ - function setMaxNetworkLimit(address resolver, uint256 amount) external { - if (maxNetworkLimit[msg.sender][resolver] == amount) { - revert AlreadySet(); - } - - if (!IRegistry(NETWORK_REGISTRY).isEntity(msg.sender)) { - revert NotNetwork(); - } - - maxNetworkLimit[msg.sender][resolver] = amount; - - Limit storage limit = _networkLimit[msg.sender][resolver]; - DelayedLimit storage nextLimit = nextNetworkLimit[msg.sender][resolver]; - - _updateLimit(limit, nextLimit); - - if (limit.amount > amount) { - limit.amount = amount; - } - if (nextLimit.amount > amount) { - nextLimit.amount = amount; - } - - emit SetMaxNetworkLimit(msg.sender, resolver, amount); - } - - /** - * @inheritdoc IVaultDelegation - */ - function setAdminFee(uint256 adminFee_) external onlyRole(ADMIN_FEE_SET_ROLE) { - if (adminFee == adminFee_) { - revert AlreadySet(); - } - - if (adminFee_ > ADMIN_FEE_BASE) { - revert InvalidAdminFee(); - } - - adminFee = adminFee_; - - emit SetAdminFee(adminFee_); - } - - /** - * @inheritdoc IVaultDelegation - */ - function setDepositWhitelist(bool status) external onlyRole(DEPOSIT_WHITELIST_SET_ROLE) { - if (depositWhitelist == status) { - revert AlreadySet(); - } - - depositWhitelist = status; - - emit SetDepositWhitelist(status); - } - - /** - * @inheritdoc IVaultDelegation - */ - function setDepositorWhitelistStatus(address account, bool status) external onlyRole(DEPOSITOR_WHITELIST_ROLE) { - if (isDepositorWhitelisted[account] == status) { - revert AlreadySet(); - } - - if (status && !depositWhitelist) { - revert NoDepositWhitelist(); - } - - isDepositorWhitelisted[account] = status; - - emit SetDepositorWhitelistStatus(account, status); - } - - /** - * @inheritdoc IVaultDelegation - */ - function setNetworkLimit( - address network, - address resolver, - uint256 amount - ) external onlyRole(NETWORK_LIMIT_SET_ROLE) { - if (amount > maxNetworkLimit[network][resolver]) { - revert ExceedsMaxNetworkLimit(); - } - - Limit storage limit = _networkLimit[network][resolver]; - DelayedLimit storage nextLimit = nextNetworkLimit[network][resolver]; - - _setLimit(limit, nextLimit, amount); - - emit SetNetworkLimit(network, resolver, amount); - } - - /** - * @inheritdoc IVaultDelegation - */ - function setOperatorLimit( - address operator, - address network, - uint256 amount - ) external onlyRole(OPERATOR_LIMIT_SET_ROLE) { - Limit storage limit = _operatorLimit[operator][network]; - DelayedLimit storage nextLimit = nextOperatorLimit[operator][network]; - - _setLimit(limit, nextLimit, amount); - - emit SetOperatorLimit(operator, network, amount); - } - - /** - * @inheritdoc IMigratableEntity - */ - function migrate(bytes memory) public override(MigratableEntity, IMigratableEntity) { - revert(); - } - - function _getLimit(Limit storage limit, DelayedLimit storage nextLimit) private view returns (uint256) { - if (nextLimit.timestamp == 0 || Time.timestamp() < nextLimit.timestamp) { - return limit.amount; - } - return nextLimit.amount; - } - - function _setLimit(Limit storage limit, DelayedLimit storage nextLimit, uint256 amount) private { - _updateLimit(limit, nextLimit); - - if (amount < limit.amount) { - nextLimit.amount = amount; - nextLimit.timestamp = currentEpochStart() + 2 * epochDuration; - } else { - limit.amount = amount; - nextLimit.amount = 0; - nextLimit.timestamp = 0; - } - } - - function _updateLimit(Limit storage limit, DelayedLimit storage nextLimit) internal { - if (nextLimit.timestamp != 0 && nextLimit.timestamp <= Time.timestamp()) { - limit.amount = nextLimit.amount; - nextLimit.timestamp = 0; - nextLimit.amount = 0; - } - } -} diff --git a/src/interfaces/IVault.sol b/src/interfaces/IVault.sol index fd6f2661..7786e4f4 100644 --- a/src/interfaces/IVault.sol +++ b/src/interfaces/IVault.sol @@ -1,9 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.25; -import {IVaultDelegation} from "./IVaultDelegation.sol"; +import {IVaultStorage} from "src/interfaces/IVaultStorage.sol"; -interface IVault is IVaultDelegation { +interface IVault is IVaultStorage { + error InvalidEpochDuration(); + error InvalidSlashDuration(); error NotNetworkMiddleware(); error NotWhitelistedDepositor(); error InsufficientDeposit(); @@ -19,6 +21,35 @@ interface IVault is IVaultDelegation { error SlashCompleted(); error NotResolver(); error VetoPeriodEnded(); + error InvalidAdminFee(); + error NotNetwork(); + error NotOperator(); + error NetworkNotOptedInVault(); + error ExceedsMaxNetworkLimit(); + error OperatorNotOptedInVault(); + error AlreadySet(); + error NoDepositWhitelist(); + + /** + * @notice Initial parameters needed for a vault deployment. + * @param owner owner of the vault (can set metadata and enable/disable deposit whitelist) + * The metadata should contain: name, description, external_url, image. + * @param collateral underlying vault collateral + * @param epochDuration duration of an vault epoch + * @param vetoDuration duration of the veto period for a slash request + * @param slashDuration duration of the slash period for a slash request (after veto period) + * @param adminFee admin fee (up to ADMIN_FEE_BASE inclusively) + * @param depositWhitelist enable/disable deposit whitelist + */ + struct InitParams { + address owner; + address collateral; + uint48 epochDuration; + uint48 vetoDuration; + uint48 slashDuration; + uint256 adminFee; + bool depositWhitelist; + } /** * @notice Emitted when a deposit is made. @@ -82,6 +113,49 @@ interface IVault is IVaultDelegation { */ event VetoSlash(uint256 indexed slashIndex); + /** + * @notice Emitted when a maximum network limit is set. + * @param network network for which the maximum limit is set + * @param resolver resolver for which the maximum limit is set + * @param amount maximum possible amount of the collateral that can be slashed + */ + event SetMaxNetworkLimit(address indexed network, address indexed resolver, uint256 amount); + + /** + * @notice Emitted when an admin fee is set. + * @param adminFee admin fee + */ + event SetAdminFee(uint256 adminFee); + + /** + * @notice Emitted when deposit whitelist status is set. + * @param depositWhitelist enable/disable deposit whitelist + */ + event SetDepositWhitelist(bool depositWhitelist); + + /** + * @notice Emitted when a depositor whitelist status is set. + * @param account account for which the whitelist status is set + * @param value whitelist status + */ + event SetDepositorWhitelistStatus(address indexed account, bool value); + + /** + * @notice Emitted when a network limit is set. + * @param network network for which the limit is set + * @param resolver resolver for which the limit is set + * @param amount amount of the collateral that can be slashed + */ + event SetNetworkLimit(address indexed network, address indexed resolver, uint256 amount); + + /** + * @notice Emitted when an operator limit is set. + * @param operator operator for which the limit is set + * @param network network for which the limit is set + * @param amount amount of the collateral that can be slashed + */ + event SetOperatorLimit(address indexed operator, address indexed network, uint256 amount); + /** * @notice Get a total amount of the collateral deposited in the vault. * @return total amount of the collateral deposited @@ -120,6 +194,22 @@ interface IVault is IVaultDelegation { */ function maxSlash(address network, address resolver, address operator) external view returns (uint256); + /** + * @notice Get a network limit for a particular network and resolver. + * @param network address of the network + * @param resolver address of the resolver + * @return network limit + */ + function networkLimit(address network, address resolver) external view returns (uint256); + + /** + * @notice Get an operator limit for a particular operator and network. + * @param operator address of the operator + * @param network address of the network + * @return operator limit + */ + function operatorLimit(address operator, address network) external view returns (uint256); + /** * @notice Deposit collateral into the vault. * @param onBehalfOf account that the deposit is made on behalf of @@ -173,4 +263,52 @@ interface IVault is IVaultDelegation { * @param slashIndex index of the slash request */ function vetoSlash(uint256 slashIndex) external; + + /** + * @notice Set a maximum network limit. + * @param resolver address of the resolver + * @param amount maximum amount of the collateral that can be slashed + * @dev Only network can call this function. + */ + function setMaxNetworkLimit(address resolver, uint256 amount) external; + + /** + * @notice Set an admin fee. + * @param adminFee admin fee (up to ADMIN_FEE_BASE inclusively) + * @dev Only ADMIN_FEE_SET_ROLE holder can call this function. + */ + function setAdminFee(uint256 adminFee) external; + + /** + * @notice Enable/disable deposit whitelist. + * @param status enable/disable deposit whitelist + * @dev Only DEPOSIT_WHITELIST_SET_ROLE holder can call this function. + */ + function setDepositWhitelist(bool status) external; + + /** + * @notice Set a depositor whitelist status. + * @param account account for which the whitelist status is set + * @param status whitelist status + * @dev Only DEPOSITOR_WHITELIST_ROLE holder can call this function. + */ + function setDepositorWhitelistStatus(address account, bool status) external; + + /** + * @notice Set a network limit for a particular network and resolver. + * @param network address of the network + * @param resolver address of the resolver + * @param amount maximum amount of the collateral that can be slashed + * @dev Only NETWORK_LIMIT_SET_ROLE holder can call this function. + */ + function setNetworkLimit(address network, address resolver, uint256 amount) external; + + /** + * @notice Set an operator limit for a particular operator and network. + * @param operator address of the operator + * @param network address of the network + * @param amount maximum amount of the collateral that can be slashed + * @dev Only OPERATOR_LIMIT_SET_ROLE holder can call this function. + */ + function setOperatorLimit(address operator, address network, uint256 amount) external; } diff --git a/src/interfaces/IVaultDelegation.sol b/src/interfaces/IVaultDelegation.sol deleted file mode 100644 index 064d104c..00000000 --- a/src/interfaces/IVaultDelegation.sol +++ /dev/null @@ -1,146 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.25; - -import {IVaultStorage} from "./IVaultStorage.sol"; -import {IMigratableEntity} from "src/interfaces/base/IMigratableEntity.sol"; - -interface IVaultDelegation is IVaultStorage, IMigratableEntity { - error InvalidEpochDuration(); - error InvalidSlashDuration(); - error InvalidAdminFee(); - error NotNetwork(); - error NotOperator(); - error NetworkNotOptedInVault(); - error ExceedsMaxNetworkLimit(); - error OperatorNotOptedInVault(); - error AlreadySet(); - error NoDepositWhitelist(); - - /** - * @notice Initial parameters needed for a vault deployment. - * @param owner owner of the vault (can set metadata and enable/disable deposit whitelist) - * The metadata should contain: name, description, external_url, image. - * @param collateral underlying vault collateral - * @param epochDuration duration of an vault epoch - * @param vetoDuration duration of the veto period for a slash request - * @param slashDuration duration of the slash period for a slash request (after veto period) - * @param adminFee admin fee (up to ADMIN_FEE_BASE inclusively) - * @param depositWhitelist enable/disable deposit whitelist - */ - struct InitParams { - address owner; - address collateral; - uint48 epochDuration; - uint48 vetoDuration; - uint48 slashDuration; - uint256 adminFee; - bool depositWhitelist; - } - - /** - * @notice Emitted when a maximum network limit is set. - * @param network network for which the maximum limit is set - * @param resolver resolver for which the maximum limit is set - * @param amount maximum possible amount of the collateral that can be slashed - */ - event SetMaxNetworkLimit(address indexed network, address indexed resolver, uint256 amount); - - /** - * @notice Emitted when an admin fee is set. - * @param adminFee admin fee - */ - event SetAdminFee(uint256 adminFee); - - /** - * @notice Emitted when deposit whitelist status is set. - * @param depositWhitelist enable/disable deposit whitelist - */ - event SetDepositWhitelist(bool depositWhitelist); - - /** - * @notice Emitted when a depositor whitelist status is set. - * @param account account for which the whitelist status is set - * @param value whitelist status - */ - event SetDepositorWhitelistStatus(address indexed account, bool value); - - /** - * @notice Emitted when a network limit is set. - * @param network network for which the limit is set - * @param resolver resolver for which the limit is set - * @param amount amount of the collateral that can be slashed - */ - event SetNetworkLimit(address indexed network, address indexed resolver, uint256 amount); - - /** - * @notice Emitted when an operator limit is set. - * @param operator operator for which the limit is set - * @param network network for which the limit is set - * @param amount amount of the collateral that can be slashed - */ - event SetOperatorLimit(address indexed operator, address indexed network, uint256 amount); - - /** - * @notice Get a network limit for a particular network and resolver. - * @param network address of the network - * @param resolver address of the resolver - * @return network limit - */ - function networkLimit(address network, address resolver) external view returns (uint256); - - /** - * @notice Get an operator limit for a particular operator and network. - * @param operator address of the operator - * @param network address of the network - * @return operator limit - */ - function operatorLimit(address operator, address network) external view returns (uint256); - - /** - * @notice Set a maximum network limit. - * @param resolver address of the resolver - * @param amount maximum amount of the collateral that can be slashed - * @dev Only network can call this function. - */ - function setMaxNetworkLimit(address resolver, uint256 amount) external; - - /** - * @notice Set an admin fee. - * @param adminFee admin fee (up to ADMIN_FEE_BASE inclusively) - * @dev Only ADMIN_FEE_SET_ROLE holder can call this function. - */ - function setAdminFee(uint256 adminFee) external; - - /** - * @notice Enable/disable deposit whitelist. - * @param status enable/disable deposit whitelist - * @dev Only DEPOSIT_WHITELIST_SET_ROLE holder can call this function. - */ - function setDepositWhitelist(bool status) external; - - /** - * @notice Set a depositor whitelist status. - * @param account account for which the whitelist status is set - * @param status whitelist status - * @dev Only DEPOSITOR_WHITELIST_ROLE holder can call this function. - */ - function setDepositorWhitelistStatus(address account, bool status) external; - - /** - * @notice Set a network limit for a particular network and resolver. - * @param network address of the network - * @param resolver address of the resolver - * @param amount maximum amount of the collateral that can be slashed - * @dev Only NETWORK_LIMIT_SET_ROLE holder can call this function. - */ - function setNetworkLimit(address network, address resolver, uint256 amount) external; - - /** - * @notice Set an operator limit for a particular operator and network. - * @param operator address of the operator - * @param network address of the network - * @param amount maximum amount of the collateral that can be slashed - * @dev Only OPERATOR_LIMIT_SET_ROLE holder can call this function. - */ - function setOperatorLimit(address operator, address network, uint256 amount) external; -} diff --git a/test/Vault.t.sol b/test/Vault.t.sol index 629bb9a3..2ccf657c 100644 --- a/test/Vault.t.sol +++ b/test/Vault.t.sol @@ -12,7 +12,7 @@ import {OperatorOptInPlugin} from "src/contracts/plugins/OperatorOptInPlugin.sol import {Vault} from "src/contracts/Vault.sol"; import {IVault} from "src/interfaces/IVault.sol"; -import {IVaultDelegation} from "src/interfaces/IVaultDelegation.sol"; +import {IVault} from "src/interfaces/IVault.sol"; import {Token} from "./mocks/Token.sol"; import {FeeOnTransferToken} from "test/mocks/FeeOnTransferToken.sol"; @@ -96,7 +96,7 @@ contract VaultTest is Test { vaultRegistry.create( vaultRegistry.lastVersion(), abi.encode( - IVaultDelegation.InitParams({ + IVault.InitParams({ owner: alice, collateral: address(collateral), epochDuration: epochDuration, @@ -769,7 +769,7 @@ contract VaultTest is Test { blockTimestamp = blockTimestamp + 1; vm.warp(blockTimestamp); - vm.expectRevert(IVaultDelegation.NetworkNotOptedInVault.selector); + vm.expectRevert(IVault.NetworkNotOptedInVault.selector); _requestSlash(bob, network, resolver, operator, toSlash); } @@ -871,7 +871,7 @@ contract VaultTest is Test { blockTimestamp = vault.currentEpochStart() + 2 * vault.epochDuration(); vm.warp(blockTimestamp); - vm.expectRevert(IVaultDelegation.OperatorNotOptedInVault.selector); + vm.expectRevert(IVault.OperatorNotOptedInVault.selector); _requestSlash(bob, network, resolver, operator, toSlash); } @@ -1500,12 +1500,12 @@ contract VaultTest is Test { uint48 vetoDuration = 0; uint64 lastVersion = vaultRegistry.lastVersion(); - vm.expectRevert(IVaultDelegation.InvalidEpochDuration.selector); + vm.expectRevert(IVault.InvalidEpochDuration.selector); vault = IVault( vaultRegistry.create( lastVersion, abi.encode( - IVaultDelegation.InitParams({ + IVault.InitParams({ owner: alice, collateral: address(collateral), epochDuration: epochDuration, @@ -1530,12 +1530,12 @@ contract VaultTest is Test { vm.assume(vetoDuration + slashDuration > epochDuration); uint64 lastVersion = vaultRegistry.lastVersion(); - vm.expectRevert(IVaultDelegation.InvalidSlashDuration.selector); + vm.expectRevert(IVault.InvalidSlashDuration.selector); vault = IVault( vaultRegistry.create( lastVersion, abi.encode( - IVaultDelegation.InitParams({ + IVault.InitParams({ owner: alice, collateral: address(collateral), epochDuration: epochDuration, @@ -1557,12 +1557,12 @@ contract VaultTest is Test { uint48 vetoDuration = 0; uint64 lastVersion = vaultRegistry.lastVersion(); - vm.expectRevert(IVaultDelegation.InvalidAdminFee.selector); + vm.expectRevert(IVault.InvalidAdminFee.selector); vault = IVault( vaultRegistry.create( lastVersion, abi.encode( - IVaultDelegation.InitParams({ + IVault.InitParams({ owner: alice, collateral: address(collateral), epochDuration: epochDuration, @@ -1720,7 +1720,7 @@ contract VaultTest is Test { _setMaxNetworkLimit(network, resolver, maxNetworkLimit); _optInNetworkVault(network, resolver); - vm.expectRevert(IVaultDelegation.ExceedsMaxNetworkLimit.selector); + vm.expectRevert(IVault.ExceedsMaxNetworkLimit.selector); _setNetworkLimit(alice, network, resolver, amount1); } @@ -1878,7 +1878,7 @@ contract VaultTest is Test { _setMaxNetworkLimit(network, resolver, amount); - vm.expectRevert(IVaultDelegation.AlreadySet.selector); + vm.expectRevert(IVault.AlreadySet.selector); _setMaxNetworkLimit(network, resolver, amount); } @@ -1894,7 +1894,7 @@ contract VaultTest is Test { address resolver = alice; - vm.expectRevert(IVaultDelegation.NotNetwork.selector); + vm.expectRevert(IVault.NotNetwork.selector); _setMaxNetworkLimit(network, resolver, amount); } @@ -1939,7 +1939,7 @@ contract VaultTest is Test { _grantAdminFeeSetRole(alice, alice); _setAdminFee(alice, adminFee); - vm.expectRevert(IVaultDelegation.AlreadySet.selector); + vm.expectRevert(IVault.AlreadySet.selector); _setAdminFee(alice, adminFee); } @@ -1952,7 +1952,7 @@ contract VaultTest is Test { vm.assume(adminFee > vault.ADMIN_FEE_BASE()); _grantAdminFeeSetRole(alice, alice); - vm.expectRevert(IVaultDelegation.InvalidAdminFee.selector); + vm.expectRevert(IVault.InvalidAdminFee.selector); _setAdminFee(alice, adminFee); } @@ -1999,7 +1999,7 @@ contract VaultTest is Test { _grantDepositWhitelistSetRole(alice, alice); _setDepositWhitelist(alice, true); - vm.expectRevert(IVaultDelegation.AlreadySet.selector); + vm.expectRevert(IVault.AlreadySet.selector); _setDepositWhitelist(alice, true); } @@ -2034,7 +2034,7 @@ contract VaultTest is Test { _grantDepositorWhitelistRole(alice, alice); - vm.expectRevert(IVaultDelegation.NoDepositWhitelist.selector); + vm.expectRevert(IVault.NoDepositWhitelist.selector); _setDepositorWhitelistStatus(alice, bob, true); } @@ -2052,7 +2052,7 @@ contract VaultTest is Test { _setDepositorWhitelistStatus(alice, bob, true); - vm.expectRevert(IVaultDelegation.AlreadySet.selector); + vm.expectRevert(IVault.AlreadySet.selector); _setDepositorWhitelistStatus(alice, bob, true); } @@ -2061,7 +2061,7 @@ contract VaultTest is Test { vaultRegistry.create( vaultRegistry.lastVersion(), abi.encode( - IVaultDelegation.InitParams({ + IVault.InitParams({ owner: alice, collateral: address(collateral), epochDuration: epochDuration, diff --git a/test/plugins/RewardsPlugin.t.sol b/test/plugins/RewardsPlugin.t.sol index bebf069c..e281168b 100644 --- a/test/plugins/RewardsPlugin.t.sol +++ b/test/plugins/RewardsPlugin.t.sol @@ -13,7 +13,7 @@ import {RewardsPlugin} from "src/contracts/plugins/RewardsPlugin.sol"; import {Vault} from "src/contracts/Vault.sol"; import {IVault} from "src/interfaces/IVault.sol"; -import {IVaultDelegation} from "src/interfaces/IVaultDelegation.sol"; +import {IVault} from "src/interfaces/IVault.sol"; import {IRewardsPlugin} from "src/interfaces/plugins/IRewardsPlugin.sol"; import {Token} from "test/mocks/Token.sol"; @@ -654,7 +654,7 @@ contract RewardsPluginTest is Test { vaultRegistry.create( vaultRegistry.lastVersion(), abi.encode( - IVaultDelegation.InitParams({ + IVault.InitParams({ owner: alice, collateral: address(collateral), epochDuration: epochDuration,