Skip to content

Commit 5ca71fc

Browse files
authored
Gpsanant/current stakes (#846)
* feat: add getCurrent * chore: fmt * chore: storoage report * chore: new storage
1 parent f0b746d commit 5ca71fc

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

docs/release/slashing/AllocationManager.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Slashing updates storage in a way that instantly updates all view functions to r
152152

153153
## View Functions
154154

155-
### `getMinDelegatedAndSlashableOperatorShares`
155+
### `getMinDelegatedAndSlashableOperatorSharesBefore`
156156

157157
```solidity
158158
/**
@@ -163,7 +163,7 @@ Slashing updates storage in a way that instantly updates all view functions to r
163163
* @param strategies the strategies to get the shares for
164164
* @param beforeTimestamp the timestamp to get the shares at
165165
*/
166-
function getMinDelegatedAndSlashableOperatorShares(
166+
function getMinDelegatedAndSlashableOperatorSharesBefore(
167167
OperatorSet calldata operatorSet,
168168
address[] calldata operators,
169169
IStrategy[] calldata strategies,

src/contracts/core/AllocationManager.sol

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,23 @@ contract AllocationManager is
494494
}
495495

496496
/// @inheritdoc IAllocationManager
497-
function getMinDelegatedAndSlashableOperatorShares(
497+
function getCurrentDelegatedAndSlashableOperatorShares(
498+
OperatorSet calldata operatorSet,
499+
address[] calldata operators,
500+
IStrategy[] calldata strategies
501+
) external view returns (uint256[][] memory, uint256[][] memory) {
502+
return
503+
getMinDelegatedAndSlashableOperatorSharesBefore(operatorSet, operators, strategies, uint32(block.timestamp));
504+
}
505+
506+
/// @inheritdoc IAllocationManager
507+
function getMinDelegatedAndSlashableOperatorSharesBefore(
498508
OperatorSet calldata operatorSet,
499509
address[] calldata operators,
500510
IStrategy[] calldata strategies,
501511
uint32 beforeTimestamp
502-
) external view returns (uint256[][] memory, uint256[][] memory) {
503-
require(beforeTimestamp > block.timestamp, InvalidTimestamp());
512+
) public view returns (uint256[][] memory, uint256[][] memory) {
513+
require(beforeTimestamp >= block.timestamp, InvalidTimestamp());
504514
bytes32 operatorSetKey = _encodeOperatorSet(operatorSet);
505515
uint256[][] memory delegatedShares = delegation.getOperatorsShares(operators, strategies);
506516
uint256[][] memory slashableShares = new uint256[][](operators.length);

src/contracts/interfaces/IAllocationManager.sol

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,19 @@ interface IAllocationManager is ISignatureUtils, IAllocationManagerErrors, IAllo
298298
address operator
299299
) external view returns (bool isSet, uint32 delay);
300300

301+
/**
302+
* @notice returns the current operatorShares and the slashableOperatorShares for an operator, list of strategies,
303+
* and an operatorSet
304+
* @param operatorSet the operatorSet to get the shares for
305+
* @param operators the operators to get the shares for
306+
* @param strategies the strategies to get the shares for
307+
*/
308+
function getCurrentDelegatedAndSlashableOperatorShares(
309+
OperatorSet calldata operatorSet,
310+
address[] calldata operators,
311+
IStrategy[] calldata strategies
312+
) external view returns (uint256[][] memory, uint256[][] memory);
313+
301314
/**
302315
* @notice returns the minimum operatorShares and the slashableOperatorShares for an operator, list of strategies,
303316
* and an operatorSet before a given timestamp. This is used to get the shares to weight operators by given ones slashing window.
@@ -306,7 +319,7 @@ interface IAllocationManager is ISignatureUtils, IAllocationManagerErrors, IAllo
306319
* @param strategies the strategies to get the shares for
307320
* @param beforeTimestamp the timestamp to get the shares at
308321
*/
309-
function getMinDelegatedAndSlashableOperatorShares(
322+
function getMinDelegatedAndSlashableOperatorSharesBefore(
310323
OperatorSet calldata operatorSet,
311324
address[] calldata operators,
312325
IStrategy[] calldata strategies,

src/test/unit/AllocationManagerUnit.t.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,13 +1025,13 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
10251025
// Get slashable shares for each operatorSet
10261026
address[] memory operatorArray = new address[](1);
10271027
operatorArray[0] = defaultOperator;
1028-
(, uint256[][] memory slashableSharesOpset1_preSlash) = allocationManager.getMinDelegatedAndSlashableOperatorShares(
1028+
(, uint256[][] memory slashableSharesOpset1_preSlash) = allocationManager.getMinDelegatedAndSlashableOperatorSharesBefore(
10291029
_operatorSet(defaultAVS, 1),
10301030
operatorArray,
10311031
_strategyMockArray(),
10321032
uint32(block.timestamp + 1)
10331033
);
1034-
(, uint256[][] memory slashableSharesOpset2_preSlash) = allocationManager.getMinDelegatedAndSlashableOperatorShares(
1034+
(, uint256[][] memory slashableSharesOpset2_preSlash) = allocationManager.getMinDelegatedAndSlashableOperatorSharesBefore(
10351035
_operatorSet(defaultAVS, 2),
10361036
operatorArray,
10371037
_strategyMockArray(),
@@ -1060,13 +1060,13 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
10601060
delegationManagerMock.setOperatorShares(defaultOperator, strategyMock, 80e18);
10611061

10621062
// Check storage
1063-
(, uint256[][] memory slashableSharesOpset1_postSlash) = allocationManager.getMinDelegatedAndSlashableOperatorShares(
1063+
(, uint256[][] memory slashableSharesOpset1_postSlash) = allocationManager.getMinDelegatedAndSlashableOperatorSharesBefore(
10641064
_operatorSet(defaultAVS, 1),
10651065
operatorArray,
10661066
_strategyMockArray(),
10671067
uint32(block.timestamp + 1)
10681068
);
1069-
(, uint256[][] memory slashableSharesOpset2_postSlash) = allocationManager.getMinDelegatedAndSlashableOperatorShares(
1069+
(, uint256[][] memory slashableSharesOpset2_postSlash) = allocationManager.getMinDelegatedAndSlashableOperatorSharesBefore(
10701070
_operatorSet(defaultAVS, 2),
10711071
operatorArray,
10721072
_strategyMockArray(),

0 commit comments

Comments
 (0)