Skip to content

Commit e64c0f7

Browse files
feat: explore ghost fns (#1650)
**Motivation:** Due to our proxy pattern with split contracts (separate view/storage/main contracts), Etherscan only displays the functions directly in the main contract when users visit its address. This means view functions defined in separate view contracts are not visible or easily accessible on Etherscan, making it difficult for users to query protocol state. **Modifications:** - Added "ghost funcitons" in `AllocationManager` **Result:** `AllocationManager` once agian supports Etherscan for view functions.
2 parents cee6410 + 6b2f0b6 commit e64c0f7

File tree

4 files changed

+191
-12
lines changed

4 files changed

+191
-12
lines changed

foundry.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
]
5656
# An array of file paths from which warnings should be ignored during compilation.
5757
ignored_warnings_from = [
58-
"src/test"
58+
"src/test",
59+
"src/contracts/core/AllocationManager.sol" # TODO: Remove
5960
]
6061

6162
# Test Configuration

script/utils/ExistingDeploymentParser.sol

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import "../../src/contracts/core/DelegationManager.sol";
1010
import "../../src/contracts/core/AVSDirectory.sol";
1111
import "../../src/contracts/core/RewardsCoordinator.sol";
1212
import "../../src/contracts/core/AllocationManager.sol";
13+
import "../../src/contracts/core/AllocationManagerView.sol";
1314
import "../../src/contracts/permissions/PermissionController.sol";
1415

1516
import "../../src/contracts/strategies/StrategyFactory.sol";
@@ -237,9 +238,12 @@ contract ExistingDeploymentParser is Script, Logger {
237238
allocationManagerImplementation =
238239
IAllocationManager(json.readAddress(".addresses.allocationManagerImplementation"));
239240

240-
allocationManagerView = IAllocationManagerView(json.readAddress(".addresses.allocationManagerView"));
241-
allocationManagerViewImplementation =
242-
IAllocationManagerView(json.readAddress(".addresses.allocationManagerViewImplementation"));
241+
// allocationManagerView = IAllocationManagerView(json.readAddress(".addresses.allocationManagerView"));
242+
243+
// FIXME: hotfix - remove later...
244+
allocationManagerView = new AllocationManagerView(
245+
delegationManager, eigenStrategy, DEALLOCATION_DELAY, ALLOCATION_CONFIGURATION_DELAY
246+
);
243247

244248
// AVSDirectory
245249
avsDirectory = AVSDirectory(json.readAddress(".addresses.avsDirectory"));

src/contracts/core/AllocationManager.sol

Lines changed: 173 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ contract AllocationManager is
2121
SplitContractMixin,
2222
PermissionControllerMixin,
2323
SemVerMixin,
24-
IAllocationManagerActions
24+
IAllocationManager
2525
{
2626
using DoubleEndedQueue for DoubleEndedQueue.Bytes32Deque;
2727
using Snapshots for Snapshots.DefaultWadHistory;
@@ -642,6 +642,101 @@ contract AllocationManager is
642642
// TODO: Inherit doc
643643
// TODO: Make commonly used getters internal methods that can be easily shared between Actions and View contracts.
644644

645+
/**
646+
*
647+
* VIEW FUNCTIONS
648+
*
649+
*/
650+
651+
/// @inheritdoc IAllocationManagerView
652+
function getOperatorSetCount(
653+
address avs
654+
) external view returns (uint256) {
655+
_delegateView(secondHalf);
656+
}
657+
658+
/// @inheritdoc IAllocationManagerView
659+
function getAllocatedSets(
660+
address operator
661+
) external view returns (OperatorSet[] memory) {
662+
_delegateView(secondHalf);
663+
}
664+
665+
/// @inheritdoc IAllocationManagerView
666+
function getAllocatedStrategies(
667+
address operator,
668+
OperatorSet memory operatorSet
669+
) external view returns (IStrategy[] memory) {
670+
_delegateView(secondHalf);
671+
}
672+
673+
/// @inheritdoc IAllocationManagerView
674+
function getAllocation(
675+
address operator,
676+
OperatorSet memory operatorSet,
677+
IStrategy strategy
678+
) external view returns (Allocation memory) {
679+
_delegateView(secondHalf);
680+
}
681+
682+
/// @inheritdoc IAllocationManagerView
683+
function getAllocations(
684+
address[] memory operators,
685+
OperatorSet memory operatorSet,
686+
IStrategy strategy
687+
) external view returns (Allocation[] memory) {
688+
_delegateView(secondHalf);
689+
}
690+
691+
/// @inheritdoc IAllocationManagerView
692+
function getStrategyAllocations(
693+
address operator,
694+
IStrategy strategy
695+
) external view returns (OperatorSet[] memory, Allocation[] memory) {
696+
_delegateView(secondHalf);
697+
}
698+
699+
/// @inheritdoc IAllocationManagerView
700+
function getEncumberedMagnitude(address operator, IStrategy strategy) external view returns (uint64) {
701+
_delegateView(secondHalf);
702+
}
703+
704+
/// @inheritdoc IAllocationManagerView
705+
function getAllocatableMagnitude(address operator, IStrategy strategy) external view returns (uint64) {
706+
_delegateView(secondHalf);
707+
}
708+
709+
/// @inheritdoc IAllocationManagerView
710+
function getMaxMagnitude(address operator, IStrategy strategy) external view returns (uint64) {
711+
_delegateView(secondHalf);
712+
}
713+
714+
/// @inheritdoc IAllocationManagerView
715+
function getMaxMagnitudes(
716+
address operator,
717+
IStrategy[] calldata strategies
718+
) external view returns (uint64[] memory) {
719+
_delegateView(secondHalf);
720+
}
721+
722+
/// @inheritdoc IAllocationManagerView
723+
function getMaxMagnitudes(
724+
address[] calldata operators,
725+
IStrategy strategy
726+
) external view returns (uint64[] memory) {
727+
_delegateView(secondHalf);
728+
}
729+
730+
/// @inheritdoc IAllocationManagerView
731+
function getMaxMagnitudesAtBlock(
732+
address operator,
733+
IStrategy[] calldata strategies,
734+
uint32 blockNumber
735+
) external view returns (uint64[] memory) {
736+
_delegateView(secondHalf);
737+
}
738+
739+
/// @inheritdoc IAllocationManagerView
645740
function getAllocationDelay(
646741
address operator
647742
) public view returns (bool, uint32) {
@@ -659,6 +754,40 @@ contract AllocationManager is
659754
return (isSet, delay);
660755
}
661756

757+
/// @inheritdoc IAllocationManagerView
758+
function getRegisteredSets(
759+
address operator
760+
) external view returns (OperatorSet[] memory operatorSets) {
761+
_delegateView(secondHalf);
762+
}
763+
764+
/// @inheritdoc IAllocationManagerView
765+
function isMemberOfOperatorSet(address operator, OperatorSet memory operatorSet) external view returns (bool) {
766+
_delegateView(secondHalf);
767+
}
768+
769+
/// @inheritdoc IAllocationManagerView
770+
function isOperatorSet(
771+
OperatorSet memory operatorSet
772+
) external view returns (bool) {
773+
_delegateView(secondHalf);
774+
}
775+
776+
/// @inheritdoc IAllocationManagerView
777+
function getMembers(
778+
OperatorSet memory operatorSet
779+
) external view returns (address[] memory operators) {
780+
_delegateView(secondHalf);
781+
}
782+
783+
/// @inheritdoc IAllocationManagerView
784+
function getMemberCount(
785+
OperatorSet memory operatorSet
786+
) external view returns (uint256) {
787+
_delegateView(secondHalf);
788+
}
789+
790+
/// @inheritdoc IAllocationManagerView
662791
function getAVSRegistrar(
663792
address avs
664793
) public view returns (IAVSRegistrar) {
@@ -667,6 +796,33 @@ contract AllocationManager is
667796
return address(registrar) == address(0) ? IAVSRegistrar(avs) : registrar;
668797
}
669798

799+
/// @inheritdoc IAllocationManagerView
800+
function getStrategiesInOperatorSet(
801+
OperatorSet memory operatorSet
802+
) external view returns (IStrategy[] memory strategies) {
803+
_delegateView(secondHalf);
804+
}
805+
806+
/// @inheritdoc IAllocationManagerView
807+
function getMinimumSlashableStake(
808+
OperatorSet memory operatorSet,
809+
address[] memory operators,
810+
IStrategy[] memory strategies,
811+
uint32 futureBlock
812+
) external view returns (uint256[][] memory slashableStake) {
813+
_delegateView(secondHalf);
814+
}
815+
816+
/// @inheritdoc IAllocationManagerView
817+
function getAllocatedStake(
818+
OperatorSet memory operatorSet,
819+
address[] memory operators,
820+
IStrategy[] memory strategies
821+
) external view returns (uint256[][] memory slashableStake) {
822+
_delegateView(secondHalf);
823+
}
824+
825+
/// @inheritdoc IAllocationManagerView
670826
function isOperatorSlashable(address operator, OperatorSet memory operatorSet) public view returns (bool) {
671827
RegistrationStatus memory status = registrationStatus[operator][operatorSet.key()];
672828

@@ -675,6 +831,7 @@ contract AllocationManager is
675831
return status.registered || block.number <= status.slashableUntil;
676832
}
677833

834+
/// @inheritdoc IAllocationManagerView
678835
function getRedistributionRecipient(
679836
OperatorSet memory operatorSet
680837
) public view returns (address) {
@@ -683,9 +840,24 @@ contract AllocationManager is
683840
return redistributionRecipient == address(0) ? DEFAULT_BURN_ADDRESS : redistributionRecipient;
684841
}
685842

843+
/// @inheritdoc IAllocationManagerView
686844
function isRedistributingOperatorSet(
687845
OperatorSet memory operatorSet
688846
) public view returns (bool) {
689847
return getRedistributionRecipient(operatorSet) != DEFAULT_BURN_ADDRESS;
690848
}
849+
850+
/// @inheritdoc IAllocationManagerView
851+
function getSlashCount(
852+
OperatorSet memory operatorSet
853+
) external view returns (uint256) {
854+
_delegateView(secondHalf);
855+
}
856+
857+
/// @inheritdoc IAllocationManagerView
858+
function isOperatorRedistributable(
859+
address operator
860+
) external view returns (bool) {
861+
_delegateView(secondHalf);
862+
}
691863
}

src/contracts/mixins/SplitContractMixin.sol

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ abstract contract SplitContractMixin {
4141
}
4242
}
4343

44-
/**
45-
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
46-
* function in the contract matches the call data.
47-
* TODO: Explore if we want to static-delegatecall to ensure no state mutations are possible.
48-
*/
49-
fallback() external virtual {
50-
_delegate(secondHalf);
44+
function _delegateView(
45+
address implementation
46+
) internal view virtual {
47+
function(address) fn = _delegate;
48+
function(address) view fnView;
49+
assembly {
50+
fnView := fn
51+
}
52+
fnView(implementation);
5153
}
5254
}

0 commit comments

Comments
 (0)