Skip to content

Commit da78e01

Browse files
committed
feat: update to vault
1 parent ed4f0c2 commit da78e01

File tree

14 files changed

+425
-259
lines changed

14 files changed

+425
-259
lines changed

src/contracts/vault/Vault.sol

Lines changed: 201 additions & 52 deletions
Large diffs are not rendered by default.

src/contracts/vault/VaultStorage.sol

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ abstract contract VaultStorage is StaticDelegateCallable, IVaultStorage {
6363
*/
6464
address public burner;
6565

66+
/**
67+
* @notice Initial timestamp for epoch calculation.
68+
* @dev DEPRECATED: This variable is kept for storage layout compatibility with previous versions.
69+
* It is no longer used in the contract logic. Use withdrawalDelay instead.
70+
*/
71+
uint48 public epochDurationInit;
72+
6673
/**
6774
* @notice Duration of the withdrawal delay (time before withdrawals become claimable).
6875
* @return duration of the withdrawal delay
@@ -100,28 +107,50 @@ abstract contract VaultStorage is StaticDelegateCallable, IVaultStorage {
100107
mapping(address account => bool value) public isDepositorWhitelisted;
101108

102109
/**
103-
* @notice Total pending withdrawal assets in the global withdrawal pool.
104-
* @dev Only withdrawals that are not yet claimable contribute to this pool.
110+
* @notice Withdrawal assets per epoch.
111+
* @dev DEPRECATED: This mapping is kept for storage layout compatibility with previous versions.
112+
* It is no longer used in the contract logic. Use the withdrawals() getter function instead.
105113
*/
106-
uint256 public withdrawals;
114+
mapping(uint256 epoch => uint256 amount) internal _withdrawalsEpoch;
107115

108116
/**
109-
* @notice Total pending withdrawal shares in the global withdrawal pool.
110-
* @dev Only withdrawals that are not yet claimable contribute to this pool.
117+
* @notice Withdrawal shares per epoch.
118+
* @dev DEPRECATED: This mapping is kept for storage layout compatibility with previous versions.
119+
* It is no longer used in the contract logic. Use the withdrawalShares() getter function instead.
111120
*/
112-
uint256 public withdrawalShares;
121+
mapping(uint256 epoch => uint256 amount) internal _withdrawalSharesEpoch;
122+
123+
/**
124+
* @notice Withdrawal shares per epoch per account.
125+
* @dev DEPRECATED: This mapping is kept for storage layout compatibility with previous versions.
126+
* It is no longer used in the contract logic. Use _withdrawalEntries mapping instead.
127+
*/
128+
mapping(uint256 epoch => mapping(address account => uint256 amount)) internal _withdrawalSharesOfEpoch;
129+
130+
/**
131+
* @notice Whether withdrawals have been claimed per epoch per account.
132+
* @dev DEPRECATED: This mapping is kept for storage layout compatibility with previous versions.
133+
* It is no longer used in the contract logic. Use _withdrawalEntries mapping instead.
134+
*/
135+
mapping(uint256 epoch => mapping(address account => bool value)) internal _isWithdrawalsClaimed;
136+
137+
Checkpoints.Trace256 internal _activeShares;
138+
139+
Checkpoints.Trace256 internal _activeStake;
140+
141+
mapping(address account => Checkpoints.Trace256 shares) internal _activeSharesOf;
113142

114143
/**
115-
* @notice Total claimable withdrawal assets in the global withdrawal pool.
116-
* @dev These withdrawals have finished their delay and are no longer slashable.
144+
* @notice Total pending withdrawal assets in the global withdrawal pool.
145+
* @dev Only withdrawals that are not yet claimable contribute to this pool.
117146
*/
118-
uint256 public claimableWithdrawals;
147+
uint256 public withdrawals;
119148

120149
/**
121-
* @notice Total claimable withdrawal shares in the global withdrawal pool.
122-
* @dev These withdrawals have finished their delay and are no longer slashable.
150+
* @notice Total pending withdrawal shares in the global withdrawal pool.
151+
* @dev Only withdrawals that are not yet claimable contribute to this pool.
123152
*/
124-
uint256 public claimableWithdrawalShares;
153+
uint256 public withdrawalShares;
125154

126155
/**
127156
* @notice Withdrawal entries for each account stored as a queue.
@@ -142,10 +171,25 @@ abstract contract VaultStorage is StaticDelegateCallable, IVaultStorage {
142171
uint256 internal _processedWithdrawalBucket;
143172

144173
/**
145-
* @notice Cumulative withdrawal shares per bucket, stored as prefix sums.
146-
* @dev `_withdrawalBucketCumulativeShares[i]` equals total shares across buckets `[0, i]`.
174+
* @notice Prefix sum entry containing cumulative shares and assets.
175+
* @dev Stores cumulative values up to and including a bucket index.
147176
*/
148-
uint256[] internal _withdrawalBucketCumulativeShares;
177+
struct PrefixSum {
178+
uint256 cumulativeShares;
179+
uint256 cumulativeAssets;
180+
}
181+
182+
/**
183+
* @notice Cumulative withdrawal shares and assets per bucket, stored as prefix sums.
184+
* @dev `_withdrawalPrefixSum[i]` equals cumulative shares and assets across buckets `[0, i]`.
185+
* Assets are only set when buckets mature; before maturity, cumulativeAssets equals the previous bucket's value.
186+
*/
187+
PrefixSum[] internal _withdrawalPrefixSum;
188+
189+
constructor(address delegatorFactory, address slasherFactory) {
190+
DELEGATOR_FACTORY = delegatorFactory;
191+
SLASHER_FACTORY = slasherFactory;
192+
}
149193

150194
/**
151195
* @notice Get total withdrawal shares for a particular account (for slashing).
@@ -194,38 +238,6 @@ abstract contract VaultStorage is StaticDelegateCallable, IVaultStorage {
194238
shares = packed >> 48;
195239
}
196240

197-
Checkpoints.Trace256 internal _activeShares;
198-
199-
Checkpoints.Trace256 internal _activeStake;
200-
201-
mapping(address account => Checkpoints.Trace256 shares) internal _activeSharesOf;
202-
203-
constructor(address delegatorFactory, address slasherFactory) {
204-
DELEGATOR_FACTORY = delegatorFactory;
205-
SLASHER_FACTORY = slasherFactory;
206-
}
207-
208-
/**
209-
* @notice Get the current timestamp.
210-
* @return current timestamp
211-
*/
212-
function currentTime() public view returns (uint48) {
213-
return Time.timestamp();
214-
}
215-
216-
/**
217-
* @notice Get all slashable unlock windows (windows where unlockAt > now).
218-
* @param now_ current timestamp
219-
* @return windows array of unlock windows that are still slashable
220-
* @dev This is a helper for iterating over slashable withdrawals.
221-
* In practice, we'll track the max unlock window and iterate backwards.
222-
*/
223-
function getSlashableWindows(uint48 now_) public view returns (uint48[] memory windows) {
224-
// This is a simplified version - in practice, you'd want to track active windows
225-
// For now, we'll calculate on-the-fly in the calling functions
226-
return windows;
227-
}
228-
229241
/**
230242
* @inheritdoc IVaultStorage
231243
*/

src/interfaces/vault/IVault.sol

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,20 @@ interface IVault is IMigratableEntity, IVaultStorage {
218218
function redeem(address claimer, uint256 shares) external returns (uint256 withdrawnAssets, uint256 mintedShares);
219219

220220
/**
221-
* @notice Claim all claimable collateral from the vault.
221+
* @notice Claim collateral from the vault for a specific withdrawal index.
222222
* @param recipient account that receives the collateral
223+
* @param index index of the withdrawal entry to claim
223224
* @return amount amount of the collateral claimed
224225
*/
225-
function claim(address recipient) external returns (uint256 amount);
226+
function claim(address recipient, uint256 index) external returns (uint256 amount);
227+
228+
/**
229+
* @notice Claim collateral from the vault for the first count claimable withdrawal entries.
230+
* @param recipient account that receives the collateral
231+
* @param count number of withdrawal entries to claim (from the front of the queue)
232+
* @return amount total amount of the collateral claimed
233+
*/
234+
function claimBatch(address recipient, uint256 count) external returns (uint256 amount);
226235

227236
/**
228237
* @notice Slash callback for burning collateral.

src/interfaces/vault/IVaultStorage.sol

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,6 @@ interface IVaultStorage {
163163
*/
164164
function withdrawalShares() external view returns (uint256);
165165

166-
/**
167-
* @notice Get total claimable withdrawal assets in the global withdrawal pool.
168-
* @return total amount of claimable withdrawal assets
169-
*/
170-
function claimableWithdrawals() external view returns (uint256);
171-
172-
/**
173-
* @notice Get total claimable withdrawal shares in the global withdrawal pool.
174-
* @return total number of claimable withdrawal shares
175-
*/
176-
function claimableWithdrawalShares() external view returns (uint256);
177166

178167
/**
179168
* @notice Get total withdrawal shares for a particular account (for slashing).

test/POCBase.t.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,13 +594,14 @@ contract POCBaseTest is Test {
594594

595595
function _claim(IVault vault, address user, uint256 epoch) internal returns (uint256 amount) {
596596
vm.startPrank(user);
597-
amount = vault.claim(user);
597+
amount = vault.claim(user, 0);
598598
vm.stopPrank();
599599
}
600600

601601
function _claimBatch(IVault vault, address user, uint256[] memory epochs) internal returns (uint256 amount) {
602602
vm.startPrank(user);
603-
amount = vault.claim(user);
603+
uint256 count = epochs.length > 0 ? epochs.length : 1;
604+
amount = vault.claimBatch(user, count);
604605
vm.stopPrank();
605606
}
606607

test/delegator/FullRestakeDelegator.t.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,13 +2004,14 @@ contract FullRestakeDelegatorTest is Test {
20042004

20052005
function _claim(address user, uint256 epoch) internal returns (uint256 amount) {
20062006
vm.startPrank(user);
2007-
amount = vault.claim(user);
2007+
amount = vault.claim(user, 0);
20082008
vm.stopPrank();
20092009
}
20102010

20112011
function _claimBatch(address user, uint256[] memory epochs) internal returns (uint256 amount) {
20122012
vm.startPrank(user);
2013-
amount = vault.claim(user);
2013+
uint256 count = epochs.length > 0 ? epochs.length : 1;
2014+
amount = vault.claimBatch(user, count);
20142015
vm.stopPrank();
20152016
}
20162017

test/delegator/NetworkRestakeDelegator.t.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,13 +2303,14 @@ contract NetworkRestakeDelegatorTest is Test {
23032303

23042304
function _claim(address user, uint256 epoch) internal returns (uint256 amount) {
23052305
vm.startPrank(user);
2306-
amount = vault.claim(user);
2306+
amount = vault.claim(user, 0);
23072307
vm.stopPrank();
23082308
}
23092309

23102310
function _claimBatch(address user, uint256[] memory epochs) internal returns (uint256 amount) {
23112311
vm.startPrank(user);
2312-
amount = vault.claim(user);
2312+
uint256 count = epochs.length > 0 ? epochs.length : 1;
2313+
amount = vault.claimBatch(user, count);
23132314
vm.stopPrank();
23142315
}
23152316

test/delegator/OperatorNetworkSpecificDelegator.t.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,13 +1448,14 @@ contract OperatorNetworkSpecificDelegatorTest is Test {
14481448

14491449
function _claim(address user, uint256 epoch) internal returns (uint256 amount) {
14501450
vm.startPrank(user);
1451-
amount = vault.claim(user);
1451+
amount = vault.claim(user, 0);
14521452
vm.stopPrank();
14531453
}
14541454

14551455
function _claimBatch(address user, uint256[] memory epochs) internal returns (uint256 amount) {
14561456
vm.startPrank(user);
1457-
amount = vault.claim(user);
1457+
uint256 count = epochs.length > 0 ? epochs.length : 1;
1458+
amount = vault.claimBatch(user, count);
14581459
vm.stopPrank();
14591460
}
14601461

test/delegator/OperatorSpecificDelegator.t.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,13 +1609,14 @@ contract OperatorSpecificDelegatorTest is Test {
16091609

16101610
function _claim(address user, uint256 epoch) internal returns (uint256 amount) {
16111611
vm.startPrank(user);
1612-
amount = vault.claim(user);
1612+
amount = vault.claim(user, 0);
16131613
vm.stopPrank();
16141614
}
16151615

16161616
function _claimBatch(address user, uint256[] memory epochs) internal returns (uint256 amount) {
16171617
vm.startPrank(user);
1618-
amount = vault.claim(user);
1618+
uint256 count = epochs.length > 0 ? epochs.length : 1;
1619+
amount = vault.claimBatch(user, count);
16191620
vm.stopPrank();
16201621
}
16211622

test/integration/base/SymbioticCoreBindingsBase.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ abstract contract SymbioticCoreBindingsBase is Test {
257257
broadcast(who)
258258
returns (uint256 amount)
259259
{
260-
amount = ISymbioticVault(vault).claim(recipient);
260+
amount = ISymbioticVault(vault).claim(recipient, 0);
261261
}
262262

263263
function _claim_SymbioticCore(address who, address vault, uint256 epoch) internal virtual returns (uint256 amount) {
@@ -270,7 +270,8 @@ abstract contract SymbioticCoreBindingsBase is Test {
270270
broadcast(who)
271271
returns (uint256 amount)
272272
{
273-
amount = ISymbioticVault(vault).claim(recipient);
273+
uint256 count = epochs.length > 0 ? epochs.length : 1;
274+
amount = ISymbioticVault(vault).claimBatch(recipient, count);
274275
}
275276

276277
function _claimBatch_SymbioticCore(address who, address vault, uint256[] memory epochs)

0 commit comments

Comments
 (0)