@@ -8,20 +8,12 @@ import "../interfaces/IDelegationManager.sol";
88import "../interfaces/IAllocationManager.sol " ;
99import "../libraries/OperatorSetLib.sol " ;
1010
11- /**
12- * @title Duration-bound EigenLayer vault strategy with configurable deposit caps and windows.
13- * @author Layr Labs, Inc.
14- * @notice Terms of Service: https://docs.eigenlayer.xyz/overview/terms-of-service
15- */
11+ /// @title Duration-bound EigenLayer vault strategy with configurable deposit caps and windows.
12+ /// @author Layr Labs, Inc.
13+ /// @notice Terms of Service: https://docs.eigenlayer.xyz/overview/terms-of-service
1614contract DurationVaultStrategy is DurationVaultStrategyStorage , StrategyBaseTVLLimits {
1715 using OperatorSetLib for OperatorSet;
1816
19- /// @notice Constant representing the full allocation magnitude (1 WAD) for allocation manager calls.
20- uint64 internal constant FULL_ALLOCATION = 1e18 ;
21-
22- /// @notice Maximum allowable duration (approximately 2 years).
23- uint32 internal constant MAX_DURATION = uint32 (2 * 365 days);
24-
2517 /// @notice Delegation manager reference used to register the vault as an operator.
2618 IDelegationManager public immutable override delegationManager;
2719
@@ -36,10 +28,9 @@ contract DurationVaultStrategy is DurationVaultStrategyStorage, StrategyBaseTVLL
3628 constructor (
3729 IStrategyManager _strategyManager ,
3830 IPauserRegistry _pauserRegistry ,
39- string memory _version ,
4031 IDelegationManager _delegationManager ,
4132 IAllocationManager _allocationManager
42- ) StrategyBaseTVLLimits (_strategyManager, _pauserRegistry, _version ) {
33+ ) StrategyBaseTVLLimits (_strategyManager, _pauserRegistry) {
4334 require (
4435 address (_delegationManager) != address (0 ) && address (_allocationManager) != address (0 ),
4536 OperatorIntegrationInvalid ()
@@ -48,9 +39,7 @@ contract DurationVaultStrategy is DurationVaultStrategyStorage, StrategyBaseTVLL
4839 allocationManager = _allocationManager;
4940 }
5041
51- /**
52- * @notice Initializes the vault configuration.
53- */
42+ /// @notice Initializes the vault configuration.
5443 function initialize (
5544 VaultConfig memory config
5645 ) public initializer {
@@ -64,85 +53,72 @@ contract DurationVaultStrategy is DurationVaultStrategyStorage, StrategyBaseTVLL
6453 metadataURI = config.metadataURI;
6554
6655 _configureOperatorIntegration (config);
67- _state = VaultState.Deposits ;
56+ _state = VaultState.DEPOSITS ;
6857
6958 emit VaultInitialized (
70- vaultAdmin, config.underlyingToken, duration, config.maxPerDeposit, config.stakeCap, metadataURI
59+ vaultAdmin,
60+ config.underlyingToken,
61+ duration,
62+ config.maxPerDeposit,
63+ config.stakeCap,
64+ metadataURI
7165 );
7266 }
7367
74- /**
75- * @notice Locks the vault, preventing new deposits and withdrawals until maturity.
76- */
68+ /// @notice Locks the vault, preventing new deposits and withdrawals until maturity.
7769 function lock () external override onlyVaultAdmin {
78- require (_state == VaultState.Deposits , VaultAlreadyLocked ());
70+ require (_state == VaultState.DEPOSITS , VaultAlreadyLocked ());
7971
80- uint32 currentTimestamp = _currentTimestamp ( );
72+ uint32 currentTimestamp = uint32 ( block . timestamp );
8173 lockedAt = currentTimestamp;
8274 uint32 newUnlockAt = currentTimestamp + duration;
8375 require (newUnlockAt >= currentTimestamp, InvalidDuration ());
8476 unlockAt = newUnlockAt;
8577
86- _state = VaultState.Allocations ;
78+ _state = VaultState.ALLOCATIONS ;
8779
8880 emit VaultLocked (lockedAt, unlockAt);
8981
9082 _allocateFullMagnitude ();
9183 }
9284
93- /**
94- * @notice Marks the vault as matured once the configured duration elapses. Callable by anyone.
95- */
85+ /// @notice Marks the vault as matured once the configured duration elapses. Callable by anyone.
9686 function markMatured () external override {
97- if (_state == VaultState.Withdrawals ) {
87+ if (_state == VaultState.WITHDRAWALS ) {
9888 // already recorded; noop
9989 return ;
10090 }
101- require (_state == VaultState.Allocations , DurationNotElapsed ());
91+ require (_state == VaultState.ALLOCATIONS , DurationNotElapsed ());
10292 require (block .timestamp >= unlockAt, DurationNotElapsed ());
103-
104- _state = VaultState.Withdrawals;
105- maturedAt = _currentTimestamp ();
93+ _state = VaultState.WITHDRAWALS;
94+ maturedAt = uint32 (block .timestamp );
10695 emit VaultMatured (maturedAt);
10796
10897 _deallocateAll ();
10998 _deregisterFromOperatorSet ();
11099 }
111100
112- /**
113- * @notice Updates the metadata URI describing the vault.
114- */
101+ /// @notice Updates the metadata URI describing the vault.
115102 function updateMetadataURI (
116103 string calldata newMetadataURI
117104 ) external override onlyVaultAdmin {
118105 metadataURI = newMetadataURI;
119106 emit MetadataURIUpdated (newMetadataURI);
120107 }
121108
122- /**
123- * @notice Transfers admin privileges to a new address.
124- */
125- function transferVaultAdmin (
126- address newVaultAdmin
127- ) external override onlyVaultAdmin {
128- require (newVaultAdmin != address (0 ), InvalidVaultAdmin ());
129- emit VaultAdminUpdated (vaultAdmin, newVaultAdmin);
130- vaultAdmin = newVaultAdmin;
131- }
132-
133109 /// @inheritdoc IDurationVaultStrategy
134110 function unlockTimestamp () public view override returns (uint32 ) {
135111 return unlockAt;
136112 }
137113
138114 /// @inheritdoc IDurationVaultStrategy
139115 function isLocked () public view override returns (bool ) {
140- return _state != VaultState.Deposits ;
116+ return _state != VaultState.DEPOSITS ;
141117 }
142118
143119 /// @inheritdoc IDurationVaultStrategy
144120 function isMatured () public view override returns (bool ) {
145- return _state == VaultState.Withdrawals ;
121+ return _state == VaultState.WITHDRAWALS ;
146122 }
147123
148124 /// @inheritdoc IDurationVaultStrategy
@@ -157,12 +133,12 @@ contract DurationVaultStrategy is DurationVaultStrategyStorage, StrategyBaseTVLL
157133
158134 /// @inheritdoc IDurationVaultStrategy
159135 function depositsOpen () public view override returns (bool ) {
160- return _state == VaultState.Deposits ;
136+ return _state == VaultState.DEPOSITS ;
161137 }
162138
163139 /// @inheritdoc IDurationVaultStrategy
164140 function withdrawalsOpen () public view override returns (bool ) {
165- return _state != VaultState.Allocations ;
141+ return _state != VaultState.ALLOCATIONS ;
166142 }
167143
168144 /// @inheritdoc IDurationVaultStrategy
@@ -175,12 +151,27 @@ contract DurationVaultStrategy is DurationVaultStrategyStorage, StrategyBaseTVLL
175151 return (_operatorSet.avs, _operatorSet.id);
176152 }
177153
178- function _beforeDeposit (IERC20 token , uint256 amount ) internal virtual override {
154+ function operatorSetRegistered () public view override returns (bool ) {
155+ return _state == VaultState.DEPOSITS || _state == VaultState.ALLOCATIONS;
156+ }
157+
158+ function allocationsActive () public view override returns (bool ) {
159+ return _state == VaultState.ALLOCATIONS;
160+ }
161+
162+ function _beforeDeposit (
163+ IERC20 token ,
164+ uint256 amount
165+ ) internal virtual override {
179166 require (depositsOpen (), DepositsLocked ());
180167 super ._beforeDeposit (token, amount);
181168 }
182169
183- function _beforeWithdrawal (address recipient , IERC20 token , uint256 amountShares ) internal virtual override {
170+ function _beforeWithdrawal (
171+ address recipient ,
172+ IERC20 token ,
173+ uint256 amountShares
174+ ) internal virtual override {
184175 require (withdrawalsOpen (), WithdrawalsLocked ());
185176 super ._beforeWithdrawal (recipient, token, amountShares);
186177 }
@@ -201,7 +192,6 @@ contract DurationVaultStrategy is DurationVaultStrategyStorage, StrategyBaseTVLL
201192 params.operatorSetIds[0 ] = config.operatorSet.id;
202193 params.data = config.operatorSetRegistrationData;
203194 allocationManager.registerForOperatorSets (address (this ), params);
204- operatorSetRegistered = true ;
205195 }
206196
207197 function _allocateFullMagnitude () internal {
@@ -212,7 +202,6 @@ contract DurationVaultStrategy is DurationVaultStrategyStorage, StrategyBaseTVLL
212202 params[0 ].newMagnitudes = new uint64 [](1 );
213203 params[0 ].newMagnitudes[0 ] = FULL_ALLOCATION;
214204 allocationManager.modifyAllocations (address (this ), params);
215- allocationsActive = true ;
216205 }
217206
218207 function _deallocateAll () internal {
@@ -223,7 +212,6 @@ contract DurationVaultStrategy is DurationVaultStrategyStorage, StrategyBaseTVLL
223212 params[0 ].newMagnitudes = new uint64 [](1 );
224213 params[0 ].newMagnitudes[0 ] = 0 ;
225214 allocationManager.modifyAllocations (address (this ), params);
226- allocationsActive = false ;
227215 }
228216
229217 function _deregisterFromOperatorSet () internal {
@@ -233,16 +221,5 @@ contract DurationVaultStrategy is DurationVaultStrategyStorage, StrategyBaseTVLL
233221 params.operatorSetIds = new uint32 [](1 );
234222 params.operatorSetIds[0 ] = _operatorSet.id;
235223 allocationManager.deregisterFromOperatorSets (params);
236- operatorSetRegistered = false ;
237- }
238-
239- /**
240- * @dev This empty reserved space is put in place to allow future versions to add new
241- * variables without shifting down storage in the inheritance chain.
242- */
243- function _currentTimestamp () internal view returns (uint32 ) {
244- uint256 ts = block .timestamp ;
245- require (ts <= type (uint32 ).max, TimestampOverflow ());
246- return uint32 (ts);
247224 }
248225}
0 commit comments