-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: operator set migration-2-create quorum #287
Merged
stevennevins
merged 31 commits into
feat/operate-set-release-branch
from
feat/migration-2-create-quorum
Aug 12, 2024
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
2bc5224
chore: checkout migration branch
stevennevins ea886ab
feat: implement migration function
stevennevins 1e9f5ff
chore: update to release branch
stevennevins 70a0d46
feat: operator set creation for each quorum number
stevennevins 3eb3d83
feat: migration with merge sorted array of operators and their quorums
stevennevins 464d2fe
feat: operator set migration working
stevennevins 09d716e
chore: revert change from testing
stevennevins 01fa4cc
chore: revert change from testing
stevennevins 5d9ae5b
chore: remove extra logging and commented out asserts
stevennevins 367f45c
chore: remove unused file
stevennevins 09f7305
fix: remove console logs
stevennevins 3ed86c3
feat: create quorum post operator set migration
stevennevins ffab895
test(wip): create quorum test adds new operator set
stevennevins 75541cc
test: migration create quorum
stevennevins cff25e6
refactor: to view functions
stevennevins 97fb672
chore: nit and remove unneeded function
stevennevins 8b46f83
fix: remove duplication of looping for all the operators
stevennevins 415058d
chore: remove comment
stevennevins 011516e
fix: updates from bumping dep
stevennevins 951b832
Merge branch 'feat/migration' into feat/migration-2-create-quorum
stevennevins 3fcc68e
feat: allow migrating in two transactions
stevennevins c4665be
feat: finalization of migration
stevennevins 62dc6d2
chore: use string errors and fix migration issues
stevennevins ac6305c
Merge branch 'feat/migration' into feat/migration-2-create-quorum
stevennevins 39d56b1
chore: rename
stevennevins 2ee11df
feat: use library for merge sort
stevennevins 6f37c47
test: fuzz view function
stevennevins cd02131
Merge branch 'feat/migration' into feat/migration-2-create-quorum
stevennevins 37ed99e
fix: updates from merge
stevennevins 0ad7205
Merge branch 'feat/operate-set-release-branch' into feat/migration-2-…
stevennevins b69d253
chore: use interface
stevennevins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.12; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol"; | ||
import { | ||
RewardsCoordinator, | ||
IRewardsCoordinator, | ||
IERC20 | ||
} from "eigenlayer-contracts/src/contracts/core/RewardsCoordinator.sol"; | ||
import {StrategyBase} from "eigenlayer-contracts/src/contracts/strategies/StrategyBase.sol"; | ||
import {IServiceManagerBaseEvents} from "../events/IServiceManagerBaseEvents.sol"; | ||
import {AVSDirectoryHarness} from "../harnesses/AVSDirectoryHarness.sol"; | ||
|
||
import "../utils/MockAVSDeployer.sol"; | ||
|
||
contract RegistryCoordinatorMigrationUnit is MockAVSDeployer, IServiceManagerBaseEvents { | ||
// RewardsCoordinator config | ||
address rewardsUpdater = address(uint160(uint256(keccak256("rewardsUpdater")))); | ||
uint32 CALCULATION_INTERVAL_SECONDS = 7 days; | ||
uint32 MAX_REWARDS_DURATION = 70 days; | ||
uint32 MAX_RETROACTIVE_LENGTH = 84 days; | ||
uint32 MAX_FUTURE_LENGTH = 28 days; | ||
uint32 GENESIS_REWARDS_TIMESTAMP = 1_712_188_800; | ||
uint256 MAX_REWARDS_AMOUNT = 1e38 - 1; | ||
/// @notice Delay in timestamp before a posted root can be claimed against | ||
uint32 activationDelay = 7 days; | ||
/// @notice the commission for all operators across all avss | ||
uint16 globalCommissionBips = 1000; | ||
|
||
// Testing Config and Mocks | ||
address serviceManagerOwner; | ||
IERC20[] rewardTokens; | ||
uint256 mockTokenInitialSupply = 10e50; | ||
IStrategy strategyMock1; | ||
IStrategy strategyMock2; | ||
IStrategy strategyMock3; | ||
StrategyBase strategyImplementation; | ||
IRewardsCoordinator.StrategyAndMultiplier[] defaultStrategyAndMultipliers; | ||
AVSDirectoryHarness avsDirectoryHarness; | ||
|
||
// mapping to setting fuzzed inputs | ||
mapping(address => bool) public addressIsExcludedFromFuzzedInputs; | ||
|
||
modifier filterFuzzedAddressInputs(address fuzzedAddress) { | ||
cheats.assume(!addressIsExcludedFromFuzzedInputs[fuzzedAddress]); | ||
_; | ||
} | ||
|
||
function setUp() public virtual { | ||
numQuorums = maxQuorumsToRegisterFor; | ||
_deployMockEigenLayerAndAVS(); | ||
|
||
serviceManagerImplementation = new ServiceManagerMock( | ||
avsDirectory, | ||
IRewardsCoordinator(address(rewardsCoordinatorMock)), | ||
registryCoordinator, | ||
stakeRegistry | ||
); | ||
avsDirectoryHarness = new AVSDirectoryHarness(delegationMock); | ||
|
||
serviceManagerImplementation = new ServiceManagerMock( | ||
avsDirectory, | ||
rewardsCoordinatorMock, | ||
registryCoordinator, | ||
stakeRegistry | ||
); | ||
/// Needed to upgrade to a service manager that points to an AVS Directory that can track state | ||
vm.prank(proxyAdmin.owner()); | ||
proxyAdmin.upgrade( | ||
TransparentUpgradeableProxy(payable(address(serviceManager))), | ||
address(serviceManagerImplementation) | ||
); | ||
|
||
serviceManagerOwner = serviceManager.owner(); | ||
|
||
_setUpDefaultStrategiesAndMultipliers(); | ||
|
||
addressIsExcludedFromFuzzedInputs[address(pauserRegistry)] = true; | ||
addressIsExcludedFromFuzzedInputs[address(proxyAdmin)] = true; | ||
} | ||
|
||
function _setUpDefaultStrategiesAndMultipliers() internal virtual { | ||
// Deploy Mock Strategies | ||
IERC20 token1 = new ERC20PresetFixedSupply( | ||
"dog wif hat", "MOCK1", mockTokenInitialSupply, address(this) | ||
); | ||
IERC20 token2 = | ||
new ERC20PresetFixedSupply("jeo boden", "MOCK2", mockTokenInitialSupply, address(this)); | ||
IERC20 token3 = new ERC20PresetFixedSupply( | ||
"pepe wif avs", "MOCK3", mockTokenInitialSupply, address(this) | ||
); | ||
strategyImplementation = new StrategyBase(strategyManagerMock); | ||
strategyMock1 = StrategyBase( | ||
address( | ||
new TransparentUpgradeableProxy( | ||
address(strategyImplementation), | ||
address(proxyAdmin), | ||
abi.encodeWithSelector(StrategyBase.initialize.selector, token1, pauserRegistry) | ||
) | ||
) | ||
); | ||
strategyMock2 = StrategyBase( | ||
address( | ||
new TransparentUpgradeableProxy( | ||
address(strategyImplementation), | ||
address(proxyAdmin), | ||
abi.encodeWithSelector(StrategyBase.initialize.selector, token2, pauserRegistry) | ||
) | ||
) | ||
); | ||
strategyMock3 = StrategyBase( | ||
address( | ||
new TransparentUpgradeableProxy( | ||
address(strategyImplementation), | ||
address(proxyAdmin), | ||
abi.encodeWithSelector(StrategyBase.initialize.selector, token3, pauserRegistry) | ||
) | ||
) | ||
); | ||
IStrategy[] memory strategies = new IStrategy[](3); | ||
strategies[0] = strategyMock1; | ||
strategies[1] = strategyMock2; | ||
strategies[2] = strategyMock3; | ||
strategies = _sortArrayAsc(strategies); | ||
|
||
strategyManagerMock.setStrategyWhitelist(strategies[0], true); | ||
strategyManagerMock.setStrategyWhitelist(strategies[1], true); | ||
strategyManagerMock.setStrategyWhitelist(strategies[2], true); | ||
|
||
defaultStrategyAndMultipliers.push( | ||
IRewardsCoordinator.StrategyAndMultiplier(IStrategy(address(strategies[0])), 1e18) | ||
); | ||
defaultStrategyAndMultipliers.push( | ||
IRewardsCoordinator.StrategyAndMultiplier(IStrategy(address(strategies[1])), 2e18) | ||
); | ||
defaultStrategyAndMultipliers.push( | ||
IRewardsCoordinator.StrategyAndMultiplier(IStrategy(address(strategies[2])), 3e18) | ||
); | ||
} | ||
|
||
/// @dev Sort to ensure that the array is in ascending order for strategies | ||
function _sortArrayAsc(IStrategy[] memory arr) internal pure returns (IStrategy[] memory) { | ||
uint256 l = arr.length; | ||
for (uint256 i = 0; i < l; i++) { | ||
for (uint256 j = i + 1; j < l; j++) { | ||
if (address(arr[i]) > address(arr[j])) { | ||
IStrategy temp = arr[i]; | ||
arr[i] = arr[j]; | ||
arr[j] = temp; | ||
} | ||
} | ||
} | ||
return arr; | ||
} | ||
|
||
function test_migrateToOperatorSets() public { | ||
(uint32[] memory operatorSetsToCreate, uint32[][] memory operatorSetIdsToMigrate, address[] memory operators) = serviceManager.getOperatorsToMigrate(); | ||
cheats.startPrank(serviceManagerOwner); | ||
serviceManager.migrateAndCreateOperatorSetIds(operatorSetsToCreate); | ||
serviceManager.migrateToOperatorSets(operatorSetIdsToMigrate, operators); | ||
cheats.stopPrank(); | ||
|
||
assertTrue(avsDirectory.isOperatorSetAVS(address(serviceManager)), "AVS is not an operator set AVS"); | ||
} | ||
|
||
|
||
|
||
function test_createQuorum() public { | ||
(uint32[] memory operatorSetsToCreate, uint32[][] memory operatorSetIdsToMigrate, address[] memory operators) = serviceManager.getOperatorsToMigrate(); | ||
cheats.startPrank(serviceManagerOwner); | ||
serviceManager.migrateAndCreateOperatorSetIds(operatorSetsToCreate); | ||
serviceManager.migrateToOperatorSets(operatorSetIdsToMigrate, operators); | ||
cheats.stopPrank(); | ||
|
||
assertTrue(avsDirectory.isOperatorSetAVS(address(serviceManager)), "AVS is not an operator set AVS"); | ||
|
||
uint8 quorumNumber = registryCoordinator.quorumCount(); | ||
uint96 minimumStake = 1000; | ||
IRegistryCoordinator.OperatorSetParam memory operatorSetParams = IRegistryCoordinator.OperatorSetParam({ | ||
maxOperatorCount: 10, | ||
kickBIPsOfOperatorStake: 50, | ||
kickBIPsOfTotalStake: 2 | ||
}); | ||
IStakeRegistry.StrategyParams[] memory strategyParams = new IStakeRegistry.StrategyParams[](1); | ||
strategyParams[0] = | ||
IStakeRegistry.StrategyParams({ | ||
strategy: IStrategy(address(1000)), | ||
multiplier: 1e16 | ||
}); | ||
|
||
assertFalse(avsDirectory.isOperatorSet(address(serviceManager), quorumNumber), "Operator set already existed"); | ||
assertTrue(avsDirectory.isOperatorSet(address(serviceManager), quorumNumber-1), "Operator set doesn't already existed"); | ||
|
||
vm.prank(registryCoordinator.owner()); | ||
registryCoordinator.createQuorum(operatorSetParams, minimumStake, strategyParams); | ||
|
||
assertTrue(avsDirectory.isOperatorSet(address(serviceManager), quorumNumber), "Operator set was not created for the quorum"); | ||
|
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can we import interface? Does the interface not have all functions we need?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the interface was missing a function initially.
I'll double check if it's there now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was there now b69d253