Skip to content

Commit

Permalink
fix: add new view funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
gpsanant committed Oct 12, 2024
1 parent 5b4d415 commit 2a8b543
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/contracts/core/AVSDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,16 @@ contract AVSDirectory is
return _operatorSetMembers[_encodeOperatorSet(operatorSet)].at(index);
}

/**
* @notice Returns the number of operator sets an operator is registered to.
* @param operator the operator address to query
*/
function getNumOperatorSetsOfOperator(
address operator
) external view returns (uint256) {
return _operatorSetsMemberOf[operator].length();
}

/**
* @notice Returns an array of operator sets an operator is registered to.
* @param operator The operator address to query.
Expand Down
32 changes: 32 additions & 0 deletions src/contracts/core/DelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,38 @@ contract DelegationManager is
return _operatorDetails[operator].stakerOptOutWindowBlocks;
}

/**
* @notice Returns the shares that an operator has delegated to them in a set of strategies
* @param operator the operator to get shares for
* @param strategies the strategies to get shares for
*/
function getOperatorShares(
address operator,
IStrategy[] memory strategies
) public view returns (uint256[] memory) {
uint256[] memory shares = new uint256[](strategies.length);
for (uint256 i = 0; i < strategies.length; ++i) {
shares[i] = operatorShares[operator][strategies[i]];
}
return shares;
}

/**
* @notice Returns the shares that a set of operators have delegated to them in a set of strategies
* @param operators the operators to get shares for
* @param strategies the strategies to get shares for
*/
function getOperatorsShares(
address[] memory operators,
IStrategy[] memory strategies
) public view returns (uint256[][] memory) {
uint256[][] memory shares = new uint256[][](operators.length);
for (uint256 i = 0; i < operators.length; ++i) {
shares[i] = getOperatorShares(operators[i], strategies);
}
return shares;
}

/**
* @notice Given a staker and a set of strategies, return the shares they can queue for withdrawal.
* This value depends on which operator the staker is delegated to.
Expand Down
8 changes: 8 additions & 0 deletions src/contracts/interfaces/IAVSDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ interface IAVSDirectory is IAVSDirectoryEvents, IAVSDirectoryErrors, ISignatureU
*/
function operatorSetMemberAtIndex(OperatorSet memory operatorSet, uint256 index) external view returns (address);

/**
* @notice Returns the number of operator sets an operator is registered to.
* @param operator the operator address to query
*/
function getNumOperatorSetsOfOperator(
address operator
) external view returns (uint256);

/**
* @notice Returns an array of operator sets an operator is registered to.
* @param operator The operator address to query.
Expand Down
20 changes: 20 additions & 0 deletions src/contracts/interfaces/IDelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,26 @@ interface IDelegationManager is ISignatureUtils, IDelegationManagerErrors, IDele
address operator
) external view returns (uint256);

/**
* @notice Returns the shares that an operator has delegated to them in a set of strategies
* @param operator the operator to get shares for
* @param strategies the strategies to get shares for
*/
function getOperatorShares(
address operator,
IStrategy[] memory strategies
) external view returns (uint256[] memory);

/**
* @notice Returns the shares that a set of operators have delegated to them in a set of strategies
* @param operators the operators to get shares for
* @param strategies the strategies to get shares for
*/
function getOperatorsShares(
address[] memory operators,
IStrategy[] memory strategies
) external view returns (uint256[][] memory);

/**
* @notice Returns 'true' if `staker` *is* actively delegated, and 'false' otherwise.
*/
Expand Down

0 comments on commit 2a8b543

Please sign in to comment.