Skip to content

Commit

Permalink
Use governor
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed May 9, 2024
1 parent aa879bc commit d253c68
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 14 deletions.
2 changes: 1 addition & 1 deletion l1-contracts-foundry/script/DeployL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ contract DeployL1Script is Script {
validatorTimelock.transferOwnership(config.ownerAddress);

Bridgehub bridgehub = Bridgehub(addresses.bridgehub.bridgehubProxy);
bridgehub.transferOwnership(config.ownerAddress);
bridgehub.transferOwnership(addresses.governance);

L1SharedBridge sharedBridge = L1SharedBridge(addresses.bridges.sharedBridgeProxy);
sharedBridge.transferOwnership(addresses.governance);
Expand Down
51 changes: 40 additions & 11 deletions l1-contracts-foundry/script/RegisterHyperchain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {IBridgehub} from "contracts/bridgehub/IBridgehub.sol";
import {IZkSyncHyperchain} from "contracts/state-transition/chain-interfaces/IZkSyncHyperchain.sol";
import {ValidatorTimelock} from "contracts/state-transition/ValidatorTimelock.sol";
import {Governance} from "contracts/governance/Governance.sol";
import {Utils} from "./Utils.sol";
import {PubdataPricingMode} from "contracts/state-transition/chain-deps/ZkSyncHyperchainStorage.sol";

contract RegisterHyperchainScript is Script {
Expand All @@ -31,6 +32,7 @@ contract RegisterHyperchainScript is Script {
uint128 baseTokenGasPriceMultiplierNominator;
uint128 baseTokenGasPriceMultiplierDenominator;
address bridgehub;
address bridgehubGovernance;
address stateTransitionProxy;
address validatorTimelock;
bytes diamondCutData;
Expand Down Expand Up @@ -66,8 +68,15 @@ contract RegisterHyperchainScript is Script {
string memory toml = vm.readFile(path);
address diamondProxy = toml.readAddress("$.diamond_proxy_addr");
IZkSyncHyperchain zkSyncStateTransition = IZkSyncHyperchain(diamondProxy);
vm.broadcast();
zkSyncStateTransition.acceptAdmin();
bytes memory data = abi.encodeCall(zkSyncStateTransition.acceptAdmin, ());
Utils.executeUpgrade({
_governor: config.bridgehubGovernance,
_salt: bytes32(config.bridgehubCreateNewChainSalt),
_target: config.bridgehub,
_data: data,
_value: 0,
_delay: 0
});
}

function initializeConfig() internal {
Expand All @@ -84,6 +93,7 @@ contract RegisterHyperchainScript is Script {
config.ownerAddress = toml.readAddress("$.owner_address");

config.bridgehub = toml.readAddress("$.deployed_addresses.bridgehub.bridgehub_proxy_addr");
config.bridgehubGovernance = toml.readAddress("$.deployed_addresses.bridge_governance");
config.stateTransitionProxy = toml.readAddress(
"$.deployed_addresses.state_transition.state_transition_proxy_addr"
);
Expand Down Expand Up @@ -130,8 +140,15 @@ contract RegisterHyperchainScript is Script {
if (bridgehub.tokenIsRegistered(config.baseToken)) {
console.log("Token already registered on Bridgehub");
} else {
vm.broadcast();
bridgehub.addToken(config.baseToken);
bytes memory data = abi.encodeCall(bridgehub.addToken, (config.baseToken));
Utils.executeUpgrade({
_governor: config.bridgehubGovernance,
_salt: bytes32(config.bridgehubCreateNewChainSalt),
_target: config.bridgehub,
_data: data,
_value: 0,
_delay: 0
});
console.log("Token registered on Bridgehub");
}
}
Expand All @@ -151,13 +168,25 @@ contract RegisterHyperchainScript is Script {

vm.broadcast();
vm.recordLogs();
bridgehub.createNewChain({
_chainId: config.hyperchainChainId,
_stateTransitionManager: config.stateTransitionProxy,
_baseToken: config.baseToken,
_salt: config.bridgehubCreateNewChainSalt,
_admin: msg.sender,
_initData: config.diamondCutData
bytes memory data = abi.encodeCall(
bridgehub.createNewChain,
(
config.hyperchainChainId,
config.stateTransitionProxy,
config.baseToken,
config.bridgehubCreateNewChainSalt,
msg.sender,
config.diamondCutData
)
);

Utils.executeUpgrade({
_governor: config.bridgehubGovernance,
_salt: bytes32(config.bridgehubCreateNewChainSalt),
_target: config.bridgehub,
_data: data,
_value: 0,
_delay: 0
});
console.log("Hyperchain registered");

Expand Down
29 changes: 27 additions & 2 deletions l1-contracts-foundry/script/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Vm} from "forge-std/Vm.sol";

import {Bridgehub} from "contracts/bridgehub/Bridgehub.sol";
import {L2TransactionRequestDirect} from "contracts/bridgehub/IBridgehub.sol";
import {IGovernance} from "contracts/governance/IGovernance.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {REQUIRED_L2_GAS_PRICE_PER_PUBDATA} from "contracts/common/Config.sol";
import {L2_DEPLOYER_SYSTEM_CONTRACT_ADDR} from "contracts/common/L2ContractAddresses.sol";
Expand All @@ -13,6 +14,7 @@ import {L2ContractHelper} from "contracts/common/libraries/L2ContractHelper.sol"
library Utils {
// Cheatcodes address, 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D.
address internal constant VM_ADDRESS = address(uint160(uint256(keccak256("hevm cheat code"))));
Vm internal constant vm = Vm(VM_ADDRESS);
// Create2Factory deterministic bytecode.
// https://github.com/Arachnid/deterministic-deployment-proxy
bytes internal constant CREATE2_FACTORY_BYTECODE =
Expand All @@ -21,8 +23,6 @@ library Utils {
address constant ADDRESS_ONE = 0x0000000000000000000000000000000000000001;
uint256 constant MAX_PRIORITY_TX_GAS = 72000000;

Vm internal constant vm = Vm(VM_ADDRESS);

/**
* @dev Get all selectors from the bytecode.
*
Expand Down Expand Up @@ -288,4 +288,29 @@ library Utils {
bytes memory bytecode = vm.parseJsonBytes(json, ".bytecode");
return bytecode;
}

function executeUpgrade(
address _governor,
bytes32 _salt,
address _target,
bytes calldata _data,
uint256 _value,
uint256 _delay
) public {
IGovernance governance = IGovernance(_governor);

IGovernance.Call[] memory calls = new IGovernance.Call[](1);
calls[0] = IGovernance.Call({target: _target, value: _value, data: _data});

IGovernance.Operation memory operation = IGovernance.Operation({
calls: calls,
predecessor: bytes32(0),
salt: _salt
});
vm.broadcast();
governance.scheduleTransparent(operation, _delay);
if (_delay == 0) {
governance.execute{value: _value}(operation);
}
}
}

0 comments on commit d253c68

Please sign in to comment.