Skip to content

Commit

Permalink
fix: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gpsanant committed Oct 13, 2024
1 parent 2a8b543 commit 4664df8
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 7 deletions.
10 changes: 5 additions & 5 deletions docs/release/slashing/AllocationManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,21 @@ Slashing updates storage in a way that instantly updates all view functions to r
```solidity
/**
* @notice returns the minimum operatorShares and the slashableOperatorShares for an operator, list of strategies,
* and an operatorSet before a given timestamp
* @param operator the operator to get the shares for
* and an operatorSet before a given timestamp. This is used to get the shares to weight operators by given ones slashing window.
* @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
* @param beforeTimestamp the timestamp to get the shares at
*/
function getMinDelegatedAndSlashableOperatorShares(
address operator,
OperatorSet calldata operatorSet,
address[] calldata operators,
IStrategy[] calldata strategies,
uint32 beforeTimestamp
) external view returns (uint256[] memory, uint256[] memory);
) external view returns (uint256[][] memory, uint256[][] memory)
```

This function returns the minimum operator shares and the slashable operator shares for an operator, list of strategies, and an operator set before a given timestamp. This is used by AVSs to pessimistically estimate the operator's slashable stake allocation for a given strategy and operator set within their slashability windows.
This function returns the minimum operator shares and the slashable operator shares for an operator, list of strategies, and an operator set before a given timestamp. This is used by AVSs to pessimistically estimate the operator's slashable stake allocation for a given strategy and operator set within their slashability windows. If an AVS calls this function every week and creates tasks that are slashable for a week after they're created, then `beforeTimestamp` should be 2 weeks in the future to account for the latest task that may be created against stale stakes. More on this in new docs soon.

### Additional View Functions

Expand Down
59 changes: 58 additions & 1 deletion src/contracts/core/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ contract AllocationManager is
) external view returns (OperatorSet[] memory, MagnitudeInfo[] memory) {
OperatorSet[] memory operatorSets = avsDirectory.getOperatorSetsOfOperator(operator, 0, type(uint256).max);
MagnitudeInfo[] memory infos = getAllocationInfo(operator, strategy, operatorSets);

return (operatorSets, infos);
}

Expand Down Expand Up @@ -401,6 +400,32 @@ contract AllocationManager is
return infos;
}

/// @inheritdoc IAllocationManager
function getAllocationInfo(
OperatorSet calldata operatorSet,
IStrategy[] calldata strategies,
address[] calldata operators
) public view returns (MagnitudeInfo[][] memory) {
MagnitudeInfo[][] memory infos = new MagnitudeInfo[][](operators.length);
for (uint256 i = 0; i < operators.length; ++i) {
for (uint256 j = 0; j < strategies.length; ++j) {
PendingMagnitudeInfo memory info = _getPendingMagnitudeInfo({
operator: operators[i],
strategy: strategies[j],
operatorSetKey: _encodeOperatorSet(operatorSet)
});

infos[i][j] = MagnitudeInfo({
currentMagnitude: info.currentMagnitude,
pendingDiff: info.pendingDiff,
effectTimestamp: info.effectTimestamp
});
}
}

return infos;
}

/// @inheritdoc IAllocationManager
function getAllocatableMagnitude(address operator, IStrategy strategy) external view returns (uint64) {
// This method needs to simulate clearing any pending allocation modifications.
Expand Down Expand Up @@ -487,4 +512,36 @@ contract AllocationManager is
isSet = delay != 0;
return (isSet, delay);
}

/// @inheritdoc IAllocationManager
function getMinDelegatedAndSlashableOperatorShares(
OperatorSet calldata operatorSet,
address[] calldata operators,
IStrategy[] calldata strategies,
uint32 beforeTimestamp
) external 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);

for (uint256 i = 0; i < operators.length; ++i) {
address operator = operators[i];
slashableShares[i] = new uint256[](strategies.length);
for (uint256 j = 0; j < strategies.length; ++j) {
IStrategy strategy = strategies[j];
MagnitudeInfo memory mInfo = _operatorMagnitudeInfo[operator][strategy][operatorSetKey];
uint64 slashableMagnitude = mInfo.currentMagnitude;
if (mInfo.effectTimestamp <= beforeTimestamp) {
slashableMagnitude = _addInt128(slashableMagnitude, mInfo.pendingDiff);
}
slashableShares[i][j] =
delegatedShares[i][j]
.mulWad(slashableMagnitude)
.divWad(_maxMagnitudeHistory[operator][strategy].latest());
}
}

return (delegatedShares, slashableShares);
}
}
34 changes: 33 additions & 1 deletion src/contracts/interfaces/IAllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ interface IAllocationManagerErrors {
error SaltSpent();
/// @dev Thrown when attempting to slash an operator that has already been slashed at the given timestamp.
error AlreadySlashedForTimestamp();
/// @dev Thrown when calling a view function that requires a valid timestamp.
error InvalidTimestamp();
}

interface IAllocationManagerTypes {
Expand Down Expand Up @@ -216,14 +218,29 @@ interface IAllocationManager is ISignatureUtils, IAllocationManagerErrors, IAllo
* @param operator the operator to query
* @param strategy the strategy to get allocation info for
* @param operatorSets the operatorSets to get allocation info for
* @return The current effective magnitude info for each operator set, for the given strategy
* @return The magnitude info for each operator set
*/
function getAllocationInfo(
address operator,
IStrategy strategy,
OperatorSet[] calldata operatorSets
) external view returns (MagnitudeInfo[] memory);

/**
* @notice Returns the effective magnitude info for each operator for each strategy for the operatorSet This method
* automatically applies any completable modifications, returning the effective
* current and pending allocations for each operator set.
* @param operatorSet the operator set to query
* @param strategies the strategies to get allocation info for
* @param operators the operators to get allocation info for
* @return The magnitude info for each operator for each strategy
*/
function getAllocationInfo(
OperatorSet calldata operatorSet,
IStrategy[] calldata strategies,
address[] calldata operators
) external view returns (MagnitudeInfo[][] memory);

/**
* @notice For a strategy, get the amount of magnitude not currently allocated to any operator set
* @param operator the operator to query
Expand Down Expand Up @@ -269,4 +286,19 @@ interface IAllocationManager is ISignatureUtils, IAllocationManagerErrors, IAllo
function getAllocationDelay(
address operator
) external view returns (bool isSet, uint32 delay);

/**
* @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.
* @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
* @param beforeTimestamp the timestamp to get the shares at
*/
function getMinDelegatedAndSlashableOperatorShares(
OperatorSet calldata operatorSet,
address[] calldata operators,
IStrategy[] calldata strategies,
uint32 beforeTimestamp
) external view returns (uint256[][] memory, uint256[][] memory);
}

0 comments on commit 4664df8

Please sign in to comment.