Skip to content

Commit

Permalink
Implement switching between networks
Browse files Browse the repository at this point in the history
  • Loading branch information
sandstone-ag committed Aug 23, 2024
1 parent a688b64 commit 8555018
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 14 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MAINNET_RPC_URL=<your RPC url>

# Deploy script env vars
CHAIN=<"mainnet" OR "holesky">
DEPLOYER_PRIVATE_KEY=...
EMERGENCY_ACTIVATION_COMMITTEE_MEMBERS=addr1,addr2,addr3
EMERGENCY_EXECUTION_COMMITTEE_MEMBERS=addr1,addr2,addr3
Expand Down
7 changes: 7 additions & 0 deletions addresses/holesky-addresses.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

address constant DAO_VOTING = 0xdA7d2573Df555002503F29aA4003e398d28cc00f;
address constant ST_ETH = 0x3F1c547b21f65e10480dE3ad8E19fAAC46C95034;
address constant WST_ETH = 0x8d09a4502Cc8Cf1547aD300E066060D043f6982D;
address constant WITHDRAWAL_QUEUE = 0xc7cc160b58F8Bb0baC94b80847E2CF2800565C50;
51 changes: 51 additions & 0 deletions scripts/deploy/Config.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,31 @@ pragma solidity 0.8.26;

import {Script} from "forge-std/Script.sol";
import {console} from "forge-std/console.sol";
import {IStETH} from "contracts/interfaces/IStETH.sol";
import {IWstETH} from "contracts/interfaces/IWstETH.sol";
import {IWithdrawalQueue} from "contracts/interfaces/IWithdrawalQueue.sol";
import {IAragonVoting} from "test/utils/interfaces/IAragonVoting.sol"; // TODO: move to a proper location
import {
ST_ETH as MAINNET_ST_ETH,
WST_ETH as MAINNET_WST_ETH,
WITHDRAWAL_QUEUE as MAINNET_WITHDRAWAL_QUEUE,
DAO_VOTING as MAINNET_DAO_VOTING
} from "addresses/mainnet-addresses.sol";
import {
ST_ETH as HOLESKY_ST_ETH,
WST_ETH as HOLESKY_WST_ETH,
WITHDRAWAL_QUEUE as HOLESKY_WITHDRAWAL_QUEUE,
DAO_VOTING as HOLESKY_DAO_VOTING
} from "addresses/holesky-addresses.sol";
import {Durations, Duration} from "contracts/types/Duration.sol";
import {PercentD16, PercentsD16} from "contracts/types/PercentD16.sol";

string constant ARRAY_SEPARATOR = ",";
bytes32 constant CHAIN_NAME_MAINNET_HASH = keccak256(bytes("mainnet"));
bytes32 constant CHAIN_NAME_HOLESKY_HASH = keccak256(bytes("holesky"));

struct ConfigValues {
string CHAIN;
uint256 DEPLOYER_PRIVATE_KEY;
Duration AFTER_SUBMIT_DELAY;
Duration MAX_AFTER_SUBMIT_DELAY;
Expand Down Expand Up @@ -52,9 +71,17 @@ struct ConfigValues {
uint256[3] RAGE_QUIT_ETH_WITHDRAWALS_TIMELOCK_GROWTH_COEFFS;
}

struct LidoAddresses {
IStETH stETH;
IWstETH wstETH;
IWithdrawalQueue withdrawalQueue;
IAragonVoting voting;
}

contract DGDeployConfig is Script {
error InvalidRageQuitETHWithdrawalsTimelockGrowthCoeffs(uint256[] coeffs);
error InvalidQuorum(string committee, uint256 quorum);
error InvalidChain(string chainName);

uint256 internal immutable DEFAULT_AFTER_SUBMIT_DELAY = 3 days;
uint256 internal immutable DEFAULT_MAX_AFTER_SUBMIT_DELAY = 45 days;
Expand Down Expand Up @@ -100,6 +127,7 @@ contract DGDeployConfig is Script {

function loadAndValidate() external returns (ConfigValues memory config) {
config = ConfigValues({
CHAIN: vm.envString("CHAIN"),
DEPLOYER_PRIVATE_KEY: vm.envUint("DEPLOYER_PRIVATE_KEY"),
AFTER_SUBMIT_DELAY: Durations.from(vm.envOr("AFTER_SUBMIT_DELAY", DEFAULT_AFTER_SUBMIT_DELAY)),
MAX_AFTER_SUBMIT_DELAY: Durations.from(vm.envOr("MAX_AFTER_SUBMIT_DELAY", DEFAULT_MAX_AFTER_SUBMIT_DELAY)),
Expand Down Expand Up @@ -208,6 +236,11 @@ contract DGDeployConfig is Script {
}

function validateConfig(ConfigValues memory config) internal pure {
bytes32 chainNameHash = keccak256(bytes(config.CHAIN));
if (chainNameHash != CHAIN_NAME_MAINNET_HASH && chainNameHash != CHAIN_NAME_HOLESKY_HASH) {
revert InvalidChain(config.CHAIN);
}

if (
config.EMERGENCY_ACTIVATION_COMMITTEE_QUORUM == 0
|| config.EMERGENCY_ACTIVATION_COMMITTEE_QUORUM > config.EMERGENCY_ACTIVATION_COMMITTEE_MEMBERS.length
Expand Down Expand Up @@ -299,4 +332,22 @@ contract DGDeployConfig is Script {
}
console.log("=================================================");
}

function lidoAddresses(ConfigValues memory config) external pure returns (LidoAddresses memory) {
if (keccak256(bytes(config.CHAIN)) == CHAIN_NAME_MAINNET_HASH) {
return LidoAddresses({
stETH: IStETH(MAINNET_ST_ETH),
wstETH: IWstETH(MAINNET_WST_ETH),
withdrawalQueue: IWithdrawalQueue(MAINNET_WITHDRAWAL_QUEUE),
voting: IAragonVoting(MAINNET_DAO_VOTING)
});
}

return LidoAddresses({
stETH: IStETH(HOLESKY_ST_ETH),
wstETH: IWstETH(HOLESKY_WST_ETH),
withdrawalQueue: IWithdrawalQueue(HOLESKY_WITHDRAWAL_QUEUE),
voting: IAragonVoting(HOLESKY_DAO_VOTING)
});
}
}
30 changes: 16 additions & 14 deletions scripts/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ import {ResealCommittee} from "contracts/committees/ResealCommittee.sol";
import {TiebreakerCore} from "contracts/committees/TiebreakerCore.sol";
import {TiebreakerSubCommittee} from "contracts/committees/TiebreakerSubCommittee.sol";

import {LidoUtils} from "test/utils/lido-utils.sol"; // TODO: del!
import {DGDeployConfig, ConfigValues} from "./Config.s.sol";
import {DGDeployConfig, ConfigValues, LidoAddresses} from "./Config.s.sol";

contract DeployDG is Script {
LidoUtils.Context internal _lido = LidoUtils.mainnet(); // TODO: del!
LidoAddresses internal lidoAddresses;
ConfigValues private dgDeployConfig;

// Emergency Protected Timelock Contracts
Expand Down Expand Up @@ -63,6 +62,9 @@ contract DeployDG is Script {
DGDeployConfig configProvider = new DGDeployConfig();
dgDeployConfig = configProvider.loadAndValidate();

// TODO: check chain id?

lidoAddresses = configProvider.lidoAddresses(dgDeployConfig);
deployer = vm.addr(dgDeployConfig.DEPLOYER_PRIVATE_KEY);
vm.startBroadcast(dgDeployConfig.DEPLOYER_PRIVATE_KEY);

Expand Down Expand Up @@ -92,7 +94,7 @@ contract DeployDG is Script {
dualGovernance = deployDualGovernance({configProvider: dualGovernanceConfigProvider});

tiebreakerCoreCommittee = deployEmptyTiebreakerCoreCommittee({
owner: deployer, // temporary set owner to deployer, to add sub committees manually TODO: check
owner: deployer, // temporary set owner to deployer, to add sub committees manually
timelockSeconds: dgDeployConfig.TIEBREAKER_EXECUTION_DELAY.toSeconds()
});

Expand All @@ -108,7 +110,7 @@ contract DeployDG is Script {
adminExecutor.execute(
address(dualGovernance),
0,
abi.encodeCall(dualGovernance.registerProposer, (address(_lido.voting), address(adminExecutor))) // TODO: check
abi.encodeCall(dualGovernance.registerProposer, (address(lidoAddresses.voting), address(adminExecutor)))
);
adminExecutor.execute(
address(dualGovernance),
Expand All @@ -123,7 +125,9 @@ contract DeployDG is Script {
adminExecutor.execute(
address(dualGovernance),
0,
abi.encodeCall(dualGovernance.addTiebreakerSealableWithdrawalBlocker, address(_lido.withdrawalQueue)) // TODO: check
abi.encodeCall(
dualGovernance.addTiebreakerSealableWithdrawalBlocker, address(lidoAddresses.withdrawalQueue)
)
);
adminExecutor.execute(
address(dualGovernance), 0, abi.encodeCall(dualGovernance.setResealCommittee, address(resealCommittee))
Expand Down Expand Up @@ -151,15 +155,15 @@ contract DeployDG is Script {
emergencyActivationCommittee = deployEmergencyActivationCommittee({
quorum: dgDeployConfig.EMERGENCY_ACTIVATION_COMMITTEE_QUORUM,
members: dgDeployConfig.EMERGENCY_ACTIVATION_COMMITTEE_MEMBERS,
owner: address(adminExecutor) // TODO: check
owner: address(adminExecutor)
});

emergencyExecutionCommittee = deployEmergencyExecutionCommittee({
quorum: dgDeployConfig.EMERGENCY_EXECUTION_COMMITTEE_QUORUM,
members: dgDeployConfig.EMERGENCY_EXECUTION_COMMITTEE_MEMBERS,
owner: address(adminExecutor) // TODO: check
owner: address(adminExecutor)
});
emergencyGovernance = deployTimelockedGovernance({governance: address(_lido.voting)});
emergencyGovernance = deployTimelockedGovernance({governance: address(lidoAddresses.voting)});

adminExecutor.execute(
address(timelock),
Expand Down Expand Up @@ -188,8 +192,6 @@ contract DeployDG is Script {
adminExecutor.execute(
address(timelock), 0, abi.encodeCall(timelock.setEmergencyGovernance, (address(emergencyGovernance)))
);

// TODO: timelock. transferExecutorOwnership ???
}

function deployExecutor(address owner) internal returns (Executor) {
Expand Down Expand Up @@ -258,9 +260,9 @@ contract DeployDG is Script {
function deployDualGovernance(IDualGovernanceConfigProvider configProvider) internal returns (DualGovernance) {
return new DualGovernance({
dependencies: DualGovernance.ExternalDependencies({
stETH: _lido.stETH, // TODO: mainnet addr?
wstETH: _lido.wstETH,
withdrawalQueue: _lido.withdrawalQueue,
stETH: lidoAddresses.stETH,
wstETH: lidoAddresses.wstETH,
withdrawalQueue: lidoAddresses.withdrawalQueue,
timelock: timelock,
resealManager: resealManager,
configProvider: configProvider
Expand Down

0 comments on commit 8555018

Please sign in to comment.