Skip to content
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

Use proper governor #464

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions .github/workflows/l1-contracts-foundry-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,15 @@ jobs:
working-directory: ./l1-contracts-foundry
run: forge script ./script/DeployL1.s.sol --ffi --rpc-url $ANVIL_RPC_URL --broadcast --private-key $ANVIL_PRIVATE_KEY

- name: Run RegisterHyperchain script
working-directory: ./l1-contracts-foundry
run: |
cat ./script-out/output-deploy-l1.toml >> ./script-config/register-hyperchain.toml
forge script ./script/RegisterHyperchain.s.sol --ffi --rpc-url $ANVIL_RPC_URL --broadcast --private-key $ANVIL_PRIVATE_KEY

- name: Run DeployErc20 script
working-directory: ./l1-contracts-foundry
run: forge script ./script/DeployErc20.s.sol --ffi --rpc-url $ANVIL_RPC_URL --broadcast --private-key $ANVIL_PRIVATE_KEY

- name: Run InitializeL2WethToken script
working-directory: ./l1-contracts-foundry
run: forge script ./script/InitializeL2WethToken.s.sol --ffi --rpc-url $ANVIL_RPC_URL --broadcast --private-key $ANVIL_PRIVATE_KEY
# TODO restore scripts verification
# - name: Run RegisterHyperchain script
# working-directory: ./l1-contracts-foundry
# run: |
# cat ./script-out/output-deploy-l1.toml >> ./script-config/register-hyperchain.toml
# forge script ./script/RegisterHyperchain.s.sol --ffi --rpc-url $ANVIL_RPC_URL --broadcast --private-key $ANVIL_PRIVATE_KEY
# - name: Run InitializeL2WethToken script
# working-directory: ./l1-contracts-foundry
# run: forge script ./script/InitializeL2WethToken.s.sol --ffi --rpc-url $ANVIL_RPC_URL --broadcast --private-key $ANVIL_PRIVATE_KEY
31 changes: 31 additions & 0 deletions l1-contracts-foundry/script/AcceptAdmin.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import {Script} from "forge-std/Script.sol";
import {stdToml} from "forge-std/StdToml.sol";

import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {Utils} from "./Utils.sol";

contract AcceptAdmin is Script {
using stdToml for string;

// This function should be called by the owner to accept the admin role
function run() public {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-config/config-accept-admin.toml");
string memory toml = vm.readFile(path);
address admin = toml.readAddress("$.target_addr");
address governor = toml.readAddress("$.governor");
Ownable2Step adminContract = Ownable2Step(admin);

Utils.executeUpgrade({
_governor: governor,
_salt: bytes32(0),
_target: admin,
_data: abi.encodeCall(adminContract.acceptOwnership, ()),
_value: 0,
_delay: 0
});
}
}
15 changes: 11 additions & 4 deletions l1-contracts-foundry/script/InitializeSharedBridgeOnL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract DeployL2Script is Script {
deployFactoryDeps();
deploySharedBridge();
deploySharedBridgeProxy();
initialize_chain();
initializeChain();

saveOutput();
}
Expand Down Expand Up @@ -143,9 +143,16 @@ contract DeployL2Script is Script {
});
}

function initialize_chain() public {
function initializeChain() public {
L1SharedBridge bridge = L1SharedBridge(config.l1SharedBridgeProxy);
vm.broadcast();
bridge.initializeChainGovernance(config.chainId, config.l2SharedBridgeProxy);

Utils.executeUpgrade({
_governor: bridge.owner(),
_salt: bytes32(0),
_target: config.l1SharedBridgeProxy,
_data: abi.encodeCall(bridge.initializeChainGovernance, (config.chainId, config.l2SharedBridgeProxy)),
_value: 0,
_delay: 0
});
}
}
29 changes: 5 additions & 24 deletions l1-contracts-foundry/script/RegisterHyperchain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {Script, console2 as console} from "forge-std/Script.sol";
import {Vm} from "forge-std/Vm.sol";
import {stdToml} from "forge-std/StdToml.sol";

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
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";
Expand All @@ -32,7 +33,6 @@ contract RegisterHyperchainScript is Script {
uint128 baseTokenGasPriceMultiplierNominator;
uint128 baseTokenGasPriceMultiplierDenominator;
address bridgehub;
address bridgehubGovernance;
address stateTransitionProxy;
address validatorTimelock;
bytes diamondCutData;
Expand Down Expand Up @@ -60,25 +60,6 @@ contract RegisterHyperchainScript is Script {
saveOutput();
}

// This function should be called by the owner to accept the admin role
function acceptAdmin() public {
console.log("Accept admin Hyperchain");
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-config/accept-admin.toml");
string memory toml = vm.readFile(path);
address diamondProxy = toml.readAddress("$.diamond_proxy_addr");
IZkSyncHyperchain zkSyncStateTransition = IZkSyncHyperchain(diamondProxy);
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 {
// Grab config from output of l1 deployment
string memory root = vm.projectRoot();
Expand All @@ -93,7 +74,6 @@ 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 @@ -136,13 +116,14 @@ contract RegisterHyperchainScript is Script {

function registerTokenOnBridgehub() internal {
IBridgehub bridgehub = IBridgehub(config.bridgehub);
Ownable ownable = Ownable(config.bridgehub);

if (bridgehub.tokenIsRegistered(config.baseToken)) {
console.log("Token already registered on Bridgehub");
} else {
bytes memory data = abi.encodeCall(bridgehub.addToken, (config.baseToken));
Utils.executeUpgrade({
_governor: config.bridgehubGovernance,
_governor: ownable.owner(),
_salt: bytes32(config.bridgehubCreateNewChainSalt),
_target: config.bridgehub,
_data: data,
Expand All @@ -165,8 +146,8 @@ contract RegisterHyperchainScript is Script {

function registerHyperchain() internal {
IBridgehub bridgehub = IBridgehub(config.bridgehub);
Ownable ownable = Ownable(config.bridgehub);

vm.broadcast();
vm.recordLogs();
bytes memory data = abi.encodeCall(
bridgehub.createNewChain,
Expand All @@ -181,7 +162,7 @@ contract RegisterHyperchainScript is Script {
);

Utils.executeUpgrade({
_governor: config.bridgehubGovernance,
_governor: ownable.owner(),
_salt: bytes32(config.bridgehubCreateNewChainSalt),
_target: config.bridgehub,
_data: data,
Expand Down
25 changes: 16 additions & 9 deletions l1-contracts-foundry/script/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ library Utils {

vm.broadcast();
(bool success, bytes memory data) = _factory.call(abi.encodePacked(_salt, _bytecode));
contractAddress = Utils.bytesToAddress(data);
contractAddress = bytesToAddress(data);

if (!success || contractAddress == address(0) || contractAddress.code.length == 0) {
revert("Failed to deploy contract via create2");
Expand Down Expand Up @@ -231,7 +231,7 @@ library Utils {
gasPrice,
l2GasLimit,
REQUIRED_L2_GAS_PRICE_PER_PUBDATA
);
) * 2;

L2TransactionRequestDirect memory l2TransactionRequestDirect = L2TransactionRequestDirect({
chainId: chainId,
Expand All @@ -245,17 +245,22 @@ library Utils {
refundRecipient: msg.sender
});

vm.startBroadcast();
address baseTokenAddress = bridgehub.baseToken(chainId);
if (ADDRESS_ONE != baseTokenAddress) {
IERC20 baseToken = IERC20(baseTokenAddress);
baseToken.approve(l1SharedBridgeProxy, requiredValueToDeploy * 2);
vm.broadcast();
baseToken.approve(l1SharedBridgeProxy, requiredValueToDeploy);
requiredValueToDeploy = 0;
}

bridgehub.requestL2TransactionDirect{value: requiredValueToDeploy}(l2TransactionRequestDirect);

vm.stopBroadcast();
executeUpgrade({
_governor: bridgehub.owner(),
_salt: bytes32(0),
_target: l1SharedBridgeProxy,
_data: abi.encodeCall(bridgehub.requestL2TransactionDirect, (l2TransactionRequestDirect)),
_value: requiredValueToDeploy,
_delay: 0
});
}

/**
Expand Down Expand Up @@ -293,7 +298,7 @@ library Utils {
address _governor,
bytes32 _salt,
address _target,
bytes calldata _data,
bytes memory _data,
uint256 _value,
uint256 _delay
) public {
Expand All @@ -307,10 +312,12 @@ library Utils {
predecessor: bytes32(0),
salt: _salt
});
vm.broadcast();

vm.startBroadcast();
governance.scheduleTransparent(operation, _delay);
if (_delay == 0) {
governance.execute{value: _value}(operation);
}
vm.stopBroadcast();
}
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6028,7 +6028,7 @@ [email protected]:
dependencies:
path-parse "^1.0.6"

resolve@^1.1.6, resolve@^1.10.0, resolve@^1.22.4, resolve@^1.8.1:
resolve@^1.1.6, resolve@^1.22.4, resolve@^1.8.1:
version "1.22.8"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.8.tgz#b6c87a9f2aa06dfab52e3d70ac8cde321fa5a48d"
integrity sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==
Expand Down
Loading