Skip to content

Commit

Permalink
Gpsanant/current stakes (#846)
Browse files Browse the repository at this point in the history
* feat: add getCurrent

* chore: fmt

* chore: storoage report

* chore: new storage
  • Loading branch information
gpsanant authored Oct 23, 2024
1 parent f0b746d commit 5ca71fc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/release/slashing/AllocationManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Slashing updates storage in a way that instantly updates all view functions to r

## View Functions

### `getMinDelegatedAndSlashableOperatorShares`
### `getMinDelegatedAndSlashableOperatorSharesBefore`

```solidity
/**
Expand All @@ -163,7 +163,7 @@ Slashing updates storage in a way that instantly updates all view functions to r
* @param strategies the strategies to get the shares for
* @param beforeTimestamp the timestamp to get the shares at
*/
function getMinDelegatedAndSlashableOperatorShares(
function getMinDelegatedAndSlashableOperatorSharesBefore(
OperatorSet calldata operatorSet,
address[] calldata operators,
IStrategy[] calldata strategies,
Expand Down
16 changes: 13 additions & 3 deletions src/contracts/core/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,23 @@ contract AllocationManager is
}

/// @inheritdoc IAllocationManager
function getMinDelegatedAndSlashableOperatorShares(
function getCurrentDelegatedAndSlashableOperatorShares(
OperatorSet calldata operatorSet,
address[] calldata operators,
IStrategy[] calldata strategies
) external view returns (uint256[][] memory, uint256[][] memory) {
return
getMinDelegatedAndSlashableOperatorSharesBefore(operatorSet, operators, strategies, uint32(block.timestamp));
}

/// @inheritdoc IAllocationManager
function getMinDelegatedAndSlashableOperatorSharesBefore(
OperatorSet calldata operatorSet,
address[] calldata operators,
IStrategy[] calldata strategies,
uint32 beforeTimestamp
) external view returns (uint256[][] memory, uint256[][] memory) {
require(beforeTimestamp > block.timestamp, InvalidTimestamp());
) public view returns (uint256[][] memory, uint256[][] memory) {
require(beforeTimestamp >= block.timestamp, InvalidTimestamp());
bytes32 operatorSetKey = _encodeOperatorSet(operatorSet);
uint256[][] memory delegatedShares = delegation.getOperatorsShares(operators, strategies);
uint256[][] memory slashableShares = new uint256[][](operators.length);
Expand Down
15 changes: 14 additions & 1 deletion src/contracts/interfaces/IAllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,19 @@ interface IAllocationManager is ISignatureUtils, IAllocationManagerErrors, IAllo
address operator
) external view returns (bool isSet, uint32 delay);

/**
* @notice returns the current operatorShares and the slashableOperatorShares for an operator, list of strategies,
* and an operatorSet
* @param operatorSet the operatorSet to get the shares for
* @param operators the operators to get the shares for
* @param strategies the strategies to get the shares for
*/
function getCurrentDelegatedAndSlashableOperatorShares(
OperatorSet calldata operatorSet,
address[] calldata operators,
IStrategy[] calldata strategies
) external view returns (uint256[][] memory, uint256[][] memory);

/**
* @notice returns the minimum operatorShares and the slashableOperatorShares for an operator, list of strategies,
* and an operatorSet before a given timestamp. This is used to get the shares to weight operators by given ones slashing window.
Expand All @@ -306,7 +319,7 @@ interface IAllocationManager is ISignatureUtils, IAllocationManagerErrors, IAllo
* @param strategies the strategies to get the shares for
* @param beforeTimestamp the timestamp to get the shares at
*/
function getMinDelegatedAndSlashableOperatorShares(
function getMinDelegatedAndSlashableOperatorSharesBefore(
OperatorSet calldata operatorSet,
address[] calldata operators,
IStrategy[] calldata strategies,
Expand Down
8 changes: 4 additions & 4 deletions src/test/unit/AllocationManagerUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1025,13 +1025,13 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
// Get slashable shares for each operatorSet
address[] memory operatorArray = new address[](1);
operatorArray[0] = defaultOperator;
(, uint256[][] memory slashableSharesOpset1_preSlash) = allocationManager.getMinDelegatedAndSlashableOperatorShares(
(, uint256[][] memory slashableSharesOpset1_preSlash) = allocationManager.getMinDelegatedAndSlashableOperatorSharesBefore(
_operatorSet(defaultAVS, 1),
operatorArray,
_strategyMockArray(),
uint32(block.timestamp + 1)
);
(, uint256[][] memory slashableSharesOpset2_preSlash) = allocationManager.getMinDelegatedAndSlashableOperatorShares(
(, uint256[][] memory slashableSharesOpset2_preSlash) = allocationManager.getMinDelegatedAndSlashableOperatorSharesBefore(
_operatorSet(defaultAVS, 2),
operatorArray,
_strategyMockArray(),
Expand Down Expand Up @@ -1060,13 +1060,13 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
delegationManagerMock.setOperatorShares(defaultOperator, strategyMock, 80e18);

// Check storage
(, uint256[][] memory slashableSharesOpset1_postSlash) = allocationManager.getMinDelegatedAndSlashableOperatorShares(
(, uint256[][] memory slashableSharesOpset1_postSlash) = allocationManager.getMinDelegatedAndSlashableOperatorSharesBefore(
_operatorSet(defaultAVS, 1),
operatorArray,
_strategyMockArray(),
uint32(block.timestamp + 1)
);
(, uint256[][] memory slashableSharesOpset2_postSlash) = allocationManager.getMinDelegatedAndSlashableOperatorShares(
(, uint256[][] memory slashableSharesOpset2_postSlash) = allocationManager.getMinDelegatedAndSlashableOperatorSharesBefore(
_operatorSet(defaultAVS, 2),
operatorArray,
_strategyMockArray(),
Expand Down

0 comments on commit 5ca71fc

Please sign in to comment.