Skip to content

Commit

Permalink
chore: refactor scripts to remove --via-ir need
Browse files Browse the repository at this point in the history
  • Loading branch information
stevennevins committed Dec 19, 2024
1 parent 3d4b0b8 commit 0c912a5
Show file tree
Hide file tree
Showing 2 changed files with 249 additions and 137 deletions.
207 changes: 132 additions & 75 deletions script/utils/CoreDeploymentLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,63 @@ library CoreDeploymentLib {
address permissionController;
}

struct DeploymentAddresses {
address delegationManagerImpl;
address avsDirectoryImpl;
address strategyManagerImpl;
address strategyFactoryImpl;
address eigenPodManagerImpl;
address rewardsCoordinatorImpl;
address eigenPodImpl;
address eigenPodBeaconImpl;
address baseStrategyImpl;
address pauserRegistryImpl;
}

function deployCoreFromScratch(
address proxyAdmin,
DeploymentConfig memory config
) internal returns (DeploymentData memory) {
DeploymentData memory result;
DeploymentAddresses memory addrs;

// Deploy empty proxies
result = _deployEmptyProxies(proxyAdmin, result);

// Deploy implementations
(
addrs.delegationManagerImpl,
addrs.avsDirectoryImpl,
addrs.strategyManagerImpl,
addrs.strategyFactoryImpl
) = _deployMainImplementations(result, config);

address ethPOSDeposit = _getEthPOSDeposit();

(
addrs.eigenPodManagerImpl,
addrs.rewardsCoordinatorImpl,
addrs.eigenPodImpl,
addrs.eigenPodBeaconImpl,
addrs.baseStrategyImpl,
addrs.pauserRegistryImpl
) = _deployRemainingImplementations(result, config, ethPOSDeposit);

// Deploy strategy beacon
result.strategyBeacon = address(new UpgradeableBeacon(addrs.baseStrategyImpl));

// Upgrade all contracts
_upgradeAllContracts(
result,
config,
proxyAdmin,
addrs
);

return result;
}

// Set up empty proxies for each contract
function _deployEmptyProxies(address proxyAdmin, DeploymentData memory result) private returns (DeploymentData memory) {
result.delegationManager = UpgradeableProxyLib.setUpEmptyProxy(proxyAdmin);
result.avsDirectory = UpgradeableProxyLib.setUpEmptyProxy(proxyAdmin);
result.strategyManager = UpgradeableProxyLib.setUpEmptyProxy(proxyAdmin);
Expand All @@ -129,9 +179,16 @@ library CoreDeploymentLib {
result.eigenPodBeacon = UpgradeableProxyLib.setUpEmptyProxy(proxyAdmin);
result.pauserRegistry = UpgradeableProxyLib.setUpEmptyProxy(proxyAdmin);
result.strategyFactory = UpgradeableProxyLib.setUpEmptyProxy(proxyAdmin);
return result;
}

// Deploy implementation contracts
address delegationManagerImpl = address(
function _deployMainImplementations(DeploymentData memory result, DeploymentConfig memory config) private returns (
address delegationManagerImpl,
address avsDirectoryImpl,
address strategyManagerImpl,
address strategyFactoryImpl
) {
delegationManagerImpl = address(
new DelegationManager(
IStrategyManager(result.strategyManager),
IEigenPodManager(result.eigenPodManager),
Expand All @@ -141,32 +198,51 @@ library CoreDeploymentLib {
uint32(config.delegationManager.initPausedStatus)
)
);
address avsDirectoryImpl = address(

avsDirectoryImpl = address(
new AVSDirectory(
IDelegationManager(result.delegationManager),
IPauserRegistry(result.pauserRegistry)
)
);
address strategyManagerImpl = address(

strategyManagerImpl = address(
new StrategyManager(
IDelegationManager(result.delegationManager),
IPauserRegistry(result.pauserRegistry)
)
);
address strategyFactoryImpl = address(new StrategyFactory(

strategyFactoryImpl = address(new StrategyFactory(
IStrategyManager(result.strategyManager),
IPauserRegistry(result.pauserRegistry)
));

address ethPOSDeposit;
return (delegationManagerImpl, avsDirectoryImpl, strategyManagerImpl, strategyFactoryImpl);
}

function _getEthPOSDeposit() private view returns (address) {
if (block.chainid == 1) {
ethPOSDeposit = 0x00000000219ab540356cBB839Cbe05303d7705Fa;
} else {
// Handle non-mainnet chains
/// TODO: Handle Eth pos
return 0x00000000219ab540356cBB839Cbe05303d7705Fa;
}
// Handle non-mainnet chains
/// TODO: Handle Eth pos
return address(0);
}

address eigenPodManagerImpl = address(
function _deployRemainingImplementations(
DeploymentData memory result,
DeploymentConfig memory config,
address ethPOSDeposit
) private returns (
address eigenPodManagerImpl,
address rewardsCoordinatorImpl,
address eigenPodImpl,
address eigenPodBeaconImpl,
address baseStrategyImpl,
address pauserRegistryImpl
) {
eigenPodManagerImpl = address(
new EigenPodManager(
IETHPOSDeposit(ethPOSDeposit),
IBeacon(result.eigenPodBeacon),
Expand All @@ -175,7 +251,7 @@ library CoreDeploymentLib {
)
);

address rewardsCoordinatorImpl = address(
rewardsCoordinatorImpl = address(
new RewardsCoordinator(
IDelegationManager(result.delegationManager),
IStrategyManager(result.strategyManager),
Expand All @@ -190,108 +266,89 @@ library CoreDeploymentLib {
)
);

address eigenPodImpl = address(
eigenPodImpl = address(
new EigenPod(
IETHPOSDeposit(ethPOSDeposit),
IEigenPodManager(result.eigenPodManager),
config.eigenPodManager.genesisTime
)
);
address eigenPodBeaconImpl = address(new UpgradeableBeacon(eigenPodImpl));
address baseStrategyImpl = address(new StrategyBase(IStrategyManager(result.strategyManager), IPauserRegistry(result.pauserRegistry)));

eigenPodBeaconImpl = address(new UpgradeableBeacon(eigenPodImpl));
baseStrategyImpl = address(new StrategyBase(IStrategyManager(result.strategyManager), IPauserRegistry(result.pauserRegistry)));

/// TODO: PauserRegistry isn't upgradeable
address pauserRegistryImpl = address(
pauserRegistryImpl = address(
new PauserRegistry(
new address[](0), // Empty array for pausers
proxyAdmin // ProxyAdmin as the unpauser
result.permissionController // ProxyAdmin as the unpauser
)
);

// Deploy and configure the strategy beacon
result.strategyBeacon = address(new UpgradeableBeacon(baseStrategyImpl));
return (
eigenPodManagerImpl,
rewardsCoordinatorImpl,
eigenPodImpl,
eigenPodBeaconImpl,
baseStrategyImpl,
pauserRegistryImpl
);
}

function _upgradeAllContracts(
DeploymentData memory result,
DeploymentConfig memory config,
address proxyAdmin,
DeploymentAddresses memory addrs
) private {
bytes memory upgradeCall;

// Upgrade contracts
/// TODO: Get from config
bytes memory upgradeCall = abi.encodeCall(
upgradeCall = abi.encodeCall(
DelegationManager.initialize,
(
proxyAdmin, // initialOwner
config.delegationManager.initPausedStatus // initialPausedStatus
)
);
UpgradeableProxyLib.upgradeAndCall(
result.delegationManager, delegationManagerImpl, upgradeCall
(proxyAdmin, config.delegationManager.initPausedStatus)
);
UpgradeableProxyLib.upgradeAndCall(result.delegationManager, addrs.delegationManagerImpl, upgradeCall);

// Upgrade StrategyManager contract
upgradeCall = abi.encodeCall(
StrategyManager.initialize,
(
proxyAdmin, // initialOwner
result.strategyFactory, // initialStrategyWhitelister
config.strategyManager.initPausedStatus // initialPausedStatus
)
(proxyAdmin, result.strategyFactory, config.strategyManager.initPausedStatus)
);
UpgradeableProxyLib.upgradeAndCall(result.strategyManager, strategyManagerImpl, upgradeCall);
UpgradeableProxyLib.upgradeAndCall(result.strategyManager, addrs.strategyManagerImpl, upgradeCall);

// Upgrade StrategyFactory contract
upgradeCall = abi.encodeCall(
StrategyFactory.initialize,
(
proxyAdmin, // initialOwner
config.strategyFactory.initPausedStatus, // initialPausedStatus
IBeacon(result.strategyBeacon) // _strategyBeacon
)
(proxyAdmin, config.strategyFactory.initPausedStatus, IBeacon(result.strategyBeacon))
);
UpgradeableProxyLib.upgradeAndCall(result.strategyFactory, strategyFactoryImpl, upgradeCall);
UpgradeableProxyLib.upgradeAndCall(result.strategyFactory, addrs.strategyFactoryImpl, upgradeCall);

// Upgrade EigenPodManager contract
upgradeCall = abi.encodeCall(
EigenPodManager.initialize,
(
proxyAdmin, // initialOwner
config.eigenPodManager.initPausedStatus // initialPausedStatus
)
(proxyAdmin, config.eigenPodManager.initPausedStatus)
);
UpgradeableProxyLib.upgradeAndCall(result.eigenPodManager, eigenPodManagerImpl, upgradeCall);
UpgradeableProxyLib.upgradeAndCall(result.eigenPodManager, addrs.eigenPodManagerImpl, upgradeCall);

// Upgrade AVSDirectory contract
upgradeCall = abi.encodeCall(
AVSDirectory.initialize,
(
proxyAdmin, // initialOwner
config.avsDirectory.initialPausedStatus // initialPausedStatus
)
(proxyAdmin, config.avsDirectory.initialPausedStatus)
);
UpgradeableProxyLib.upgradeAndCall(result.avsDirectory, avsDirectoryImpl, upgradeCall);
UpgradeableProxyLib.upgradeAndCall(result.avsDirectory, addrs.avsDirectoryImpl, upgradeCall);

// Upgrade RewardsCoordinator contract
upgradeCall = abi.encodeCall(
RewardsCoordinator.initialize,
(
proxyAdmin, // initialOwner
config.rewardsCoordinator.initPausedStatus, // initialPausedStatus
config.rewardsCoordinator.rewardsUpdater, // rewardsUpdater
uint32(config.rewardsCoordinator.activationDelay), // _activationDelay
uint16(config.rewardsCoordinator.defaultOperatorSplitBips) // _defaultSplitBips
proxyAdmin,
config.rewardsCoordinator.initPausedStatus,
config.rewardsCoordinator.rewardsUpdater,
uint32(config.rewardsCoordinator.activationDelay),
uint16(config.rewardsCoordinator.defaultOperatorSplitBips)
)
);
UpgradeableProxyLib.upgradeAndCall(
result.rewardsCoordinator, rewardsCoordinatorImpl, upgradeCall
);
UpgradeableProxyLib.upgradeAndCall(result.rewardsCoordinator, addrs.rewardsCoordinatorImpl, upgradeCall);

// Upgrade EigenPod contract
upgradeCall = abi.encodeCall(
EigenPod.initialize,
// TODO: Double check this
(address(result.eigenPodManager)) // _podOwner
);
UpgradeableProxyLib.upgradeAndCall(result.eigenPodBeacon, eigenPodImpl, upgradeCall);

return result;
upgradeCall = abi.encodeCall(EigenPod.initialize, (address(result.eigenPodManager)));
UpgradeableProxyLib.upgradeAndCall(result.eigenPodBeacon, addrs.eigenPodImpl, upgradeCall);
}


function readCoreDeploymentJson(string memory path, uint256 chainId) internal returns (CoreDeploymentLib.DeploymentData memory) {
string memory filePath = string(abi.encodePacked(path, "/", vm.toString(chainId), ".json"));
return parseZeusJson(filePath);
Expand Down
Loading

0 comments on commit 0c912a5

Please sign in to comment.