From 5b15e1eab437127d6abaa7656137a33095056f54 Mon Sep 17 00:00:00 2001 From: Michael Sun <35479365+8sunyuan@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:50:44 -0500 Subject: [PATCH] feat: view func for avssync (#423) --- src/contracts/core/DelegationManager.sol | 12 ++++++++++++ src/contracts/interfaces/IDelegationManager.sol | 8 ++++++++ src/test/mocks/DelegationManagerMock.sol | 5 +++++ 3 files changed, 25 insertions(+) diff --git a/src/contracts/core/DelegationManager.sol b/src/contracts/core/DelegationManager.sol index 3f678fca4..e9ae3ef4e 100644 --- a/src/contracts/core/DelegationManager.sol +++ b/src/contracts/core/DelegationManager.sol @@ -852,6 +852,18 @@ contract DelegationManager is Initializable, OwnableUpgradeable, Pausable, Deleg return _operatorDetails[operator].stakerOptOutWindowBlocks; } + /// @notice Given array of strategies, returns array of shares for the operator + 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 number of actively-delegatable shares a staker has across all strategies. * @dev Returns two empty arrays in the case that the Staker has no actively-delegateable shares. diff --git a/src/contracts/interfaces/IDelegationManager.sol b/src/contracts/interfaces/IDelegationManager.sol index 19ae7cf88..5b663d4e8 100644 --- a/src/contracts/interfaces/IDelegationManager.sol +++ b/src/contracts/interfaces/IDelegationManager.sol @@ -337,6 +337,14 @@ interface IDelegationManager is ISignatureUtils { */ function stakerOptOutWindowBlocks(address operator) external view returns (uint256); + /** + * @notice Given array of strategies, returns array of shares for the operator + */ + function getOperatorShares( + address operator, + IStrategy[] memory strategies + ) external view returns (uint256[] memory); + /** * @notice Given a list of strategies, return the minimum number of blocks that must pass to withdraw * from all the inputted strategies. Return value is >= minWithdrawalDelayBlocks as this is the global min withdrawal delay. diff --git a/src/test/mocks/DelegationManagerMock.sol b/src/test/mocks/DelegationManagerMock.sol index f4405e1f2..a55dbd50b 100644 --- a/src/test/mocks/DelegationManagerMock.sol +++ b/src/test/mocks/DelegationManagerMock.sol @@ -86,6 +86,11 @@ contract DelegationManagerMock is IDelegationManager, Test { function strategyWithdrawalDelayBlocks(IStrategy /*strategy*/) external pure returns (uint256) { return 0; } + + function getOperatorShares( + address operator, + IStrategy[] memory strategies + ) external view returns (uint256[] memory) {} function getWithdrawalDelay(IStrategy[] calldata /*strategies*/) public pure returns (uint256) { return 0;