Skip to content

Commit 6ae6c8d

Browse files
committed
refactor: remove unneeded helpers
1 parent a6b0bc4 commit 6ae6c8d

9 files changed

Lines changed: 83 additions & 143 deletions

src/contracts/interfaces/IDurationVaultStrategy.sol

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ import "./IDelegationManager.sol";
88
import "./IAllocationManager.sol";
99
import "../libraries/OperatorSetLib.sol";
1010

11-
/**
12-
* @title Interface for time-bound EigenLayer vault strategies.
13-
* @author Layr Labs, Inc.
14-
* @notice Terms of Service: https://docs.eigenlayer.xyz/overview/terms-of-service
15-
*/
11+
/// @title Interface for time-bound EigenLayer vault strategies.
12+
/// @author Layr Labs, Inc.
13+
/// @notice Terms of Service: https://docs.eigenlayer.xyz/overview/terms-of-service
1614
interface IDurationVaultStrategy is IStrategy {
1715
enum VaultState {
18-
Deposits,
19-
Allocations,
20-
Withdrawals
16+
UNINITIALIZED,
17+
DEPOSITS,
18+
ALLOCATIONS,
19+
WITHDRAWALS
2120
}
2221

2322
struct VaultConfig {
@@ -68,35 +67,20 @@ interface IDurationVaultStrategy is IStrategy {
6867

6968
event VaultMatured(uint32 maturedAt);
7069

71-
event VaultAdminUpdated(address indexed previousAdmin, address indexed newAdmin);
72-
7370
event MetadataURIUpdated(string newMetadataURI);
7471

75-
/**
76-
* @notice Locks the vault, preventing further deposits / withdrawals until maturity.
77-
*/
72+
/// @notice Locks the vault, preventing further deposits / withdrawals until maturity.
7873
function lock() external;
7974

80-
/**
81-
* @notice Marks the vault as matured once the configured duration has elapsed.
82-
* @dev After maturation, withdrawals are permitted while deposits remain disabled.
83-
*/
75+
/// @notice Marks the vault as matured once the configured duration has elapsed.
76+
/// @dev After maturation, withdrawals are permitted while deposits remain disabled.
8477
function markMatured() external;
8578

86-
/**
87-
* @notice Updates the vault metadata URI.
88-
*/
79+
/// @notice Updates the vault metadata URI.
8980
function updateMetadataURI(
9081
string calldata newMetadataURI
9182
) external;
9283

93-
/**
94-
* @notice Transfers vault admin privileges to a new address.
95-
*/
96-
function transferVaultAdmin(
97-
address newVaultAdmin
98-
) external;
99-
10084
function vaultAdmin() external view returns (address);
10185
function duration() external view returns (uint32);
10286
function lockedAt() external view returns (uint32);

src/contracts/interfaces/IStrategyFactory.sol

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,18 @@ interface IStrategyFactory {
4949
IERC20 token
5050
) external returns (IStrategy newStrategy);
5151

52-
/**
53-
* @notice Deploys a new duration-bound vault strategy contract.
54-
* @dev Enforces the same blacklist semantics as vanilla strategies.
55-
*/
52+
/// @notice Deploys a new duration-bound vault strategy contract.
53+
/// @dev Enforces the same blacklist semantics as vanilla strategies.
5654
function deployDurationVaultStrategy(
5755
IDurationVaultStrategy.VaultConfig calldata config
5856
) external returns (IDurationVaultStrategy newVault);
5957

60-
/**
61-
* @notice Returns all duration vaults that have ever been deployed for a given token.
62-
*/
58+
/// @notice Returns all duration vaults that have ever been deployed for a given token.
6359
function getDurationVaults(
6460
IERC20 token
6561
) external view returns (IDurationVaultStrategy[] memory);
6662

67-
/**
68-
* @notice Owner-only function to pass through a call to `StrategyManager.addStrategiesToDepositWhitelist`
69-
*/
63+
/// @notice Owner-only function to pass through a call to `StrategyManager.addStrategiesToDepositWhitelist`
7064
function whitelistStrategies(
7165
IStrategy[] calldata strategiesToWhitelist
7266
) external;
@@ -76,9 +70,7 @@ interface IStrategyFactory {
7670
IStrategy[] calldata strategiesToRemoveFromWhitelist
7771
) external;
7872

79-
/**
80-
* @notice Owner-only function to update the beacon used for deploying duration vault strategies.
81-
*/
73+
/// @notice Owner-only function to update the beacon used for deploying duration vault strategies.
8274
function setDurationVaultBeacon(
8375
IBeacon newDurationVaultBeacon
8476
) external;

src/contracts/strategies/DurationVaultStrategy.sol

Lines changed: 43 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,12 @@ import "../interfaces/IDelegationManager.sol";
88
import "../interfaces/IAllocationManager.sol";
99
import "../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
1614
contract 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
}

src/contracts/strategies/DurationVaultStrategyStorage.sol

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ pragma solidity ^0.8.27;
44
import "../interfaces/IDurationVaultStrategy.sol";
55
import "../libraries/OperatorSetLib.sol";
66

7-
/**
8-
* @title Storage layout for DurationVaultStrategy.
9-
* @author Layr Labs, Inc.
10-
* @notice Terms of Service: https://docs.eigenlayer.xyz/overview/terms-of-service
11-
*/
7+
/// @title Storage layout for DurationVaultStrategy.
8+
/// @author Layr Labs, Inc.
9+
/// @notice Terms of Service: https://docs.eigenlayer.xyz/overview/terms-of-service
1210
abstract contract DurationVaultStrategyStorage is IDurationVaultStrategy {
11+
/// @notice Constant representing the full allocation magnitude (1 WAD) for allocation manager calls.
12+
uint64 internal constant FULL_ALLOCATION = 1e18;
13+
14+
/// @notice Maximum allowable duration (approximately 2 years).
15+
uint32 internal constant MAX_DURATION = uint32(2 * 365 days);
16+
1317
/// @notice Address empowered to configure and lock the vault.
1418
address public vaultAdmin;
1519

@@ -34,17 +38,7 @@ abstract contract DurationVaultStrategyStorage is IDurationVaultStrategy {
3438
/// @notice Tracks the lifecycle of the vault (deposits -> allocations -> withdrawals).
3539
VaultState internal _state;
3640

37-
/// @notice True when allocations are currently active (i.e. slashable) for the configured operator set.
38-
bool public allocationsActive;
39-
40-
/// @notice True when the vault remains registered for the operator set.
41-
bool public operatorSetRegistered;
42-
43-
/**
44-
* @dev This empty reserved space is put in place to allow future versions to add new
45-
* variables without shifting down storage in the inheritance chain.
46-
*/
47-
uint256[41] private __gap;
41+
/// @dev This empty reserved space is put in place to allow future versions to add new
42+
/// variables without shifting down storage in the inheritance chain.
43+
uint256[43] private __gap;
4844
}
49-
50-

0 commit comments

Comments
 (0)