Skip to content

Commit

Permalink
updated scripts and contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
afkbyte committed Dec 24, 2024
1 parent 6c1434b commit 9e16d9c
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 117 deletions.
2 changes: 1 addition & 1 deletion contracts/anvil/contracts-deployed-anvil-state.json

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions contracts/anvil/deploy-contracts-save-anvil-state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ root_dir=$(realpath $anvil_dir/../..)
set -a
source $anvil_dir/utils.sh
# we overwrite some variables here because should always deploy to anvil (localhost)
ETH_HTTP_URL=http://localhost:8545
DEPLOYER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
export ETH_HTTP_URL=http://localhost:8545
export DEPLOYER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
set +a

# start an empty anvil chain in the background and dump its state to a json file upon exit
Expand All @@ -40,19 +40,21 @@ CHAIN_ID=$(cast chain-id)

# DEPLOY CONTRACT REGISTRY
cd $root_dir/contracts
echo "DIRECTORY: ${root_dir}/contracts"
set -x
forge create src/ContractsRegistry.sol:ContractsRegistry --rpc-url $ETH_HTTP_URL --private-key $DEPLOYER_PRIVATE_KEY

# DEPLOY EIGENLAYER
EIGEN_CONTRACTS_DIR=$root_dir/contracts/lib/eigenlayer-middleware/lib/eigenlayer-contracts
DEVNET_OUTPUT_DIR=$EIGEN_CONTRACTS_DIR/script/output/devnet
export EIGEN_CONTRACTS_DIR=$root_dir/contracts/lib/eigenlayer-middleware/lib/eigenlayer-contracts
export DEVNET_OUTPUT_DIR=$EIGEN_CONTRACTS_DIR/script/output/devnet
# deployment overwrites this file, so we save it as backup, because we want that output in our local files, and not in the eigenlayer-contracts submodule files
mv $DEVNET_OUTPUT_DIR/M2_from_scratch_deployment_data.json $DEVNET_OUTPUT_DIR/M2_from_scratch_deployment_data.json.bak
mv $DEVNET_OUTPUT_DIR/SLASHING_deploy_from_scratch_deployment_data.json $DEVNET_OUTPUT_DIR/SLASHING_deploy_from_scratch_deployment_data.json.bak
cd $EIGEN_CONTRACTS_DIR
forge script script/deploy/devnet/M2_Deploy_From_Scratch.s.sol --rpc-url $ETH_HTTP_URL \
forge script script/deploy/local/deploy_from_scratch.slashing.s.sol --rpc-url $ETH_HTTP_URL \
--private-key $DEPLOYER_PRIVATE_KEY --broadcast \
--sig "run(string memory configFileName)" -- M2_deploy_from_scratch.anvil.config.json
mv $DEVNET_OUTPUT_DIR/M2_from_scratch_deployment_data.json $root_dir/contracts/script/output/${CHAIN_ID:?}/eigenlayer_deployment_output.json
mv $DEVNET_OUTPUT_DIR/M2_from_scratch_deployment_data.json.bak $DEVNET_OUTPUT_DIR/M2_from_scratch_deployment_data.json
--sig "run(string memory configFileName)" -- local/deploy_from_scratch.slashing.anvil.config.json
mv $DEVNET_OUTPUT_DIR/SLASHING_deploy_from_scratch_deployment_data.json $root_dir/contracts/script/output/${CHAIN_ID:?}/eigenlayer_deployment_output.json
mv $DEVNET_OUTPUT_DIR/SLASHING_deploy_from_scratch_deployment_data.json $DEVNET_OUTPUT_DIR/SLASHING_deploy_from_scratch_deployment_data.json

# DEPLOY MOCKAVS
cd $root_dir/contracts
Expand Down
2 changes: 1 addition & 1 deletion contracts/anvil/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e -o nounset

parent_path=$(
cd "$(dirname "${BASH_SOURCE[0]}")"
cd "$(dirname "${0:A}")" || exit 1
pwd -P
)

Expand Down
3 changes: 2 additions & 1 deletion contracts/script/DeployMockAvs.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ contract DeployMockAvs is DeployMockAvsRegistries {
mockAvsServiceManagerImplementation = new MockAvsServiceManager(
registryCoordinator,
eigenlayerContracts.avsDirectory,
eigenlayerContracts.rewardsCoordinator
eigenlayerContracts.rewardsCoordinator,
eigenlayerContracts.allocationManager
);

mockAvsProxyAdmin.upgradeAndCall(
Expand Down
162 changes: 73 additions & 89 deletions contracts/script/DeployMockAvsRegistries.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ contract DeployMockAvsRegistries is
MockAvsServiceManager mockAvsServiceManager,
MockAvsServiceManager mockAvsServiceManagerImplementation
) internal returns (MockAvsContracts memory) {
// deploy pauser registry
{
{ // Pauser registry scope
address[] memory pausers = new address[](2);
pausers[0] = addressConfig.pauser;
pausers[1] = addressConfig.communityMultisig;
Expand All @@ -83,93 +82,94 @@ contract DeployMockAvsRegistries is
addressConfig.communityMultisig
);
}
/**
* First, deploy upgradeable proxy contracts that **will point** to the implementations. Since the implementation contracts are
* not yet deployed, we give these proxies an empty contract as the initial implementation, to act as if they have no code.
*/
registryCoordinator = blsregcoord.RegistryCoordinator(
address(
new TransparentUpgradeableProxy(
address(emptyContract),
address(mockAvsProxyAdmin),
""

{ // Proxy deployments scope
registryCoordinator = blsregcoord.RegistryCoordinator(
address(
new TransparentUpgradeableProxy(
address(emptyContract),
address(mockAvsProxyAdmin),
""
)
)
)
);
blsApkRegistry = IBLSApkRegistry(
address(
new TransparentUpgradeableProxy(
address(emptyContract),
address(mockAvsProxyAdmin),
""
);
blsApkRegistry = IBLSApkRegistry(
address(
new TransparentUpgradeableProxy(
address(emptyContract),
address(mockAvsProxyAdmin),
""
)
)
)
);
indexRegistry = IIndexRegistry(
address(
new TransparentUpgradeableProxy(
address(emptyContract),
address(mockAvsProxyAdmin),
""
);
indexRegistry = IIndexRegistry(
address(
new TransparentUpgradeableProxy(
address(emptyContract),
address(mockAvsProxyAdmin),
""
)
)
)
);
stakeRegistry = IStakeRegistry(
address(
new TransparentUpgradeableProxy(
address(emptyContract),
address(mockAvsProxyAdmin),
""
);
stakeRegistry = IStakeRegistry(
address(
new TransparentUpgradeableProxy(
address(emptyContract),
address(mockAvsProxyAdmin),
""
)
)
)
);
);
}

operatorStateRetriever = new OperatorStateRetriever();

// Second, deploy the *implementation* contracts, using the *proxy contracts* as inputs
blsApkRegistryImplementation = new BLSApkRegistry(registryCoordinator);
{ // Implementation deployments scope
blsApkRegistryImplementation = new BLSApkRegistry(registryCoordinator);

mockAvsProxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(blsApkRegistry))),
address(blsApkRegistryImplementation)
);

indexRegistryImplementation = new IndexRegistry(registryCoordinator);
mockAvsProxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(blsApkRegistry))),
address(blsApkRegistryImplementation)
);

mockAvsProxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(indexRegistry))),
address(indexRegistryImplementation)
);
indexRegistryImplementation = new IndexRegistry(registryCoordinator);

{
stakeRegistryImplementation = new StakeRegistry(
registryCoordinator,
eigenlayerContracts.delegationManager
mockAvsProxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(indexRegistry))),
address(indexRegistryImplementation)
);

mockAvsProxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(stakeRegistry))),
address(stakeRegistryImplementation)
{ // Stake registry scope
stakeRegistryImplementation = new StakeRegistry(
registryCoordinator,
eigenlayerContracts.delegationManager,
eigenlayerContracts.avsDirectory,
mockAvsServiceManager
);

mockAvsProxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(stakeRegistry))),
address(stakeRegistryImplementation)
);
}

registryCoordinatorImplementation = new blsregcoord.RegistryCoordinator(
blsregcoord.IServiceManager(address(mockAvsServiceManager)),
blsregcoord.IStakeRegistry(address(stakeRegistry)),
blsregcoord.IBLSApkRegistry(address(blsApkRegistry)),
blsregcoord.IIndexRegistry(address(indexRegistry)),
eigenlayerContracts.avsDirectory,
mockAvsPauserReg
);
}

registryCoordinatorImplementation = new blsregcoord.RegistryCoordinator(
blsregcoord.IServiceManager(address(mockAvsServiceManager)),
blsregcoord.IStakeRegistry(address(stakeRegistry)),
blsregcoord.IBLSApkRegistry(address(blsApkRegistry)),
blsregcoord.IIndexRegistry(address(indexRegistry))
);

{
{ // Registry coordinator initialization scope
uint numQuorums = 0;
// for each quorum to setup, we need to define
// quorumsOperatorSetParams, quorumsMinimumStake, and quorumsStrategyParams
blsregcoord.RegistryCoordinator.OperatorSetParam[]
memory quorumsOperatorSetParams = new blsregcoord.RegistryCoordinator.OperatorSetParam[](
numQuorums
);
for (uint i = 0; i < numQuorums; i++) {
// hard code these for now
quorumsOperatorSetParams[i] = blsregcoord
.IRegistryCoordinator
.OperatorSetParam({
Expand All @@ -178,27 +178,12 @@ contract DeployMockAvsRegistries is
kickBIPsOfTotalStake: 100
});
}
// set to 0 for every quorum
uint96[] memory quorumsMinimumStake = new uint96[](numQuorums);
IStakeRegistry.StrategyParams[][]
memory quorumsStrategyParams = new IStakeRegistry.StrategyParams[][](
numQuorums
);
// We don't setup up any quorums so this is commented out for now
// (since deployedStrategyArray doesn't exist)
// for (uint i = 0; i < numQuorums; i++) {
// quorumsStrategyParams[i] = new IStakeRegistry.StrategyParams[](numStrategies);
// for (uint j = 0; j < numStrategies; j++) {
// quorumsStrategyParams[i][j] = IStakeRegistry.StrategyParams({
// strategy: deployedStrategyArray[j],
// // setting this to 1 ether since the divisor is also 1 ether
// // therefore this allows an operator to register with even just 1 token
// // see https://github.com/Layr-Labs/eigenlayer-middleware/blob/m2-mainnet/src/StakeRegistry.sol#L484
// // weight += uint96(sharesAmount * strategyAndMultiplier.multiplier / WEIGHTING_DIVISOR);
// multiplier: 1 ether
// });
// }
// }

mockAvsProxyAdmin.upgradeAndCall(
TransparentUpgradeableProxy(
payable(address(registryCoordinator))
Expand All @@ -210,7 +195,7 @@ contract DeployMockAvsRegistries is
addressConfig.churner,
addressConfig.ejector,
addressConfig.pauser,
0, // 0 initialPausedStatus means everything unpaused
0,
quorumsOperatorSetParams,
quorumsMinimumStake,
quorumsStrategyParams
Expand All @@ -223,8 +208,7 @@ contract DeployMockAvsRegistries is
"Owner uninitialized"
);

// WRITE JSON DATA
{
{ // JSON output scope
string memory parent_object = "parent object";
string memory deployed_addresses = "addresses";
vm.serializeAddress(
Expand Down Expand Up @@ -258,7 +242,6 @@ contract DeployMockAvsRegistries is
address(operatorStateRetriever)
);

// serialize all the data
string memory finalJson = vm.serializeString(
parent_object,
deployed_addresses,
Expand All @@ -267,14 +250,15 @@ contract DeployMockAvsRegistries is

writeOutput(finalJson, "mockavs_deployment_output");
}

return
MockAvsContracts(
mockAvsServiceManager,
registryCoordinator,
operatorStateRetriever
);
}

function _writeContractsToRegistry(
ContractsRegistry contractsRegistry,
EigenlayerContracts memory eigenlayerContracts,
Expand Down
5 changes: 2 additions & 3 deletions contracts/script/DeployTokensStrategiesCreateQuorums.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ contract DeployTokensStrategiesCreateQuorums is
bool[] memory thirdPartyTransfersForbiddenValues = new bool[](1);
thirdPartyTransfersForbiddenValues[0] = false;
strategyManager.addStrategiesToDepositWhitelist(
strats,
thirdPartyTransfersForbiddenValues
strats
);

// WRITE JSON DATA
Expand Down Expand Up @@ -147,7 +146,7 @@ contract DeployTokensStrategiesCreateQuorums is
multiplier: 1 ether
});

regcoord.RegistryCoordinator(address(mockAvsRegCoord)).createQuorum(
regcoord.RegistryCoordinator(address(mockAvsRegCoord)).createTotalDelegatedStakeQuorum(
quorumOperatorSetParams,
quorumMinimumStake,
quorumStrategyParams
Expand Down
11 changes: 4 additions & 7 deletions contracts/script/RegisterOperatorsWithEigenlayer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,16 @@ contract RegisterOperators is
// Register operators with EigenLayer
for (uint256 i = 0; i < numberOfOperators; i++) {
address delegationApprover = address(0); // anyone can delegate to this operator
uint32 stakerOptOutWindowBlocks = 100;
uint32 allocationDelayBlocks = 100;
string memory metadataURI = string.concat(
"https://coolstuff.com/operator/",
vm.toString(i)
);
(, uint256 privateKey) = deriveRememberKey(mnemonic, uint32(i));
vm.startBroadcast(privateKey);
eigenlayerContracts.delegationManager.registerAsOperator(
IDelegationManager.OperatorDetails(
operators[i],
delegationApprover,
stakerOptOutWindowBlocks
),
delegationApprover,
allocationDelayBlocks,
metadataURI
);
eigenlayerContracts.strategyManager.depositIntoStrategy(
Expand All @@ -105,4 +102,4 @@ contract RegisterOperators is
}
}
}
}
}
2 changes: 1 addition & 1 deletion contracts/script/parsers/ConfigsReadWriter.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.12;
pragma solidity >0.8.12;

import "eigenlayer-middleware/src/interfaces/IRegistryCoordinator.sol";
import "eigenlayer-contracts/src/contracts/strategies/StrategyBase.sol";
Expand Down
9 changes: 9 additions & 0 deletions contracts/script/parsers/EigenlayerContractsParser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "eigenlayer-contracts/src/contracts/permissions/PauserRegistry.sol";

import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
import {IDelegationManager} from "eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";
import {IAllocationManager} from "eigenlayer-contracts/src/contracts/interfaces/IAllocationManager.sol";
import {IStrategyManager, IStrategy} from "eigenlayer-contracts/src/contracts/interfaces/IStrategyManager.sol";
import {StrategyBaseTVLLimits} from "eigenlayer-contracts/src/contracts/strategies/StrategyBaseTVLLimits.sol";
import {IRewardsCoordinator} from "eigenlayer-contracts/src/contracts/interfaces/IRewardsCoordinator.sol";
Expand All @@ -19,6 +20,7 @@ struct EigenlayerContracts {
IStrategyManager strategyManager;
IDelegationManager delegationManager;
IAVSDirectory avsDirectory;
IAllocationManager allocationManager;
IRewardsCoordinator rewardsCoordinator;
StrategyBaseTVLLimits baseStrategyImplementation;
}
Expand Down Expand Up @@ -63,6 +65,12 @@ contract EigenlayerContractsParser is ConfigsReadWriter {
".addresses.avsDirectory"
)
);
IAllocationManager allocationManager = IAllocationManager(
stdJson.readAddress(
eigenlayerDeployedContracts,
".addresses.allocationManager"
)
);
StrategyBaseTVLLimits baseStrategyImplementation = StrategyBaseTVLLimits(
stdJson.readAddress(
eigenlayerDeployedContracts,
Expand All @@ -83,6 +91,7 @@ contract EigenlayerContractsParser is ConfigsReadWriter {
strategyManager,
delegationManager,
avsDirectory,
allocationManager,
rewardsCoordinator,
baseStrategyImplementation
);
Expand Down
Loading

0 comments on commit 9e16d9c

Please sign in to comment.