Skip to content

Commit

Permalink
Use propergovernor
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed May 10, 2024
1 parent d253c68 commit 6b71e20
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 37 deletions.
25 changes: 25 additions & 0 deletions l1-contracts-foundry/script/AcceptAdmin.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import {Script, console2 as console} 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 {
console.log("Accept admin Hyperchain");

Check failure on line 15 in l1-contracts-foundry/script/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 15 in l1-contracts-foundry/script/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 15 in l1-contracts-foundry/script/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
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");
console.log(governor);

Check failure on line 21 in l1-contracts-foundry/script/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 21 in l1-contracts-foundry/script/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 21 in l1-contracts-foundry/script/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
Ownable2Step adminContract = Ownable2Step(admin);
Utils.executeUpgrade(governor, bytes32(0), admin, abi.encodeCall(adminContract.acceptOwnership, ()), 0, 0);

Check failure on line 23 in l1-contracts-foundry/script/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4

Check failure on line 23 in l1-contracts-foundry/script/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4

Check failure on line 23 in l1-contracts-foundry/script/AcceptAdmin.s.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4
}
}
9 changes: 5 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,10 @@ 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(bridge.owner(), bytes32(0), config.l1SharedBridgeProxy,

Check failure on line 148 in l1-contracts-foundry/script/InitializeSharedBridgeOnL2.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4

Check failure on line 148 in l1-contracts-foundry/script/InitializeSharedBridgeOnL2.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4

Check failure on line 148 in l1-contracts-foundry/script/InitializeSharedBridgeOnL2.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4
abi.encodeCall(bridge.initializeChainGovernance, (config.chainId, config.l2SharedBridgeProxy)), 0, 0
);
}
}
29 changes: 6 additions & 23 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,24 +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
Expand All @@ -93,7 +75,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 +117,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 +147,9 @@ 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 +164,7 @@ contract RegisterHyperchainScript is Script {
);

Utils.executeUpgrade({
_governor: config.bridgehubGovernance,
_governor: ownable.owner(),
_salt: bytes32(config.bridgehubCreateNewChainSalt),
_target: config.bridgehub,
_data: data,
Expand Down
31 changes: 22 additions & 9 deletions l1-contracts-foundry/script/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
pragma solidity 0.8.24;

import {Vm} from "forge-std/Vm.sol";
import {console2 as console} from "forge-std/Script.sol";

import {Bridgehub} from "contracts/bridgehub/Bridgehub.sol";
import {L2TransactionRequestDirect} from "contracts/bridgehub/IBridgehub.sol";
import {IGovernance} from "contracts/governance/IGovernance.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.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 @@ -18,7 +20,7 @@ library Utils {
// Create2Factory deterministic bytecode.
// https://github.com/Arachnid/deterministic-deployment-proxy
bytes internal constant CREATE2_FACTORY_BYTECODE =
hex"604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3";
hex"604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3";

address constant ADDRESS_ONE = 0x0000000000000000000000000000000000000001;
uint256 constant MAX_PRIORITY_TX_GAS = 72000000;
Expand Down Expand Up @@ -111,7 +113,7 @@ library Utils {
*/
function readSystemContractsBytecode(string memory filename) internal view returns (bytes memory) {
string memory file = vm.readFile(
// solhint-disable-next-line func-named-parameters
// solhint-disable-next-line func-named-parameters
string.concat(
"../system-contracts/artifacts-zk/contracts-preprocessed/",
filename,
Expand Down Expand Up @@ -231,7 +233,7 @@ library Utils {
gasPrice,
l2GasLimit,
REQUIRED_L2_GAS_PRICE_PER_PUBDATA
);
) * 2;

L2TransactionRequestDirect memory l2TransactionRequestDirect = L2TransactionRequestDirect({
chainId: chainId,
Expand All @@ -245,17 +247,23 @@ 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(bridgehub.owner(), bytes32(0), bridgehubAddress,

Check failure on line 259 in l1-contracts-foundry/script/Utils.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4

Check failure on line 259 in l1-contracts-foundry/script/Utils.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4

Check failure on line 259 in l1-contracts-foundry/script/Utils.sol

View workflow job for this annotation

GitHub Actions / lint

Named parameters missing. MIN unnamed argumenst is 4
abi.encodeCall(bridgehub.requestL2TransactionDirect,
(l2TransactionRequestDirect)
),
requiredValueToDeploy,
0
);

}

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

Ownable ownable = Ownable(_governor);
console.log(msg.sender);

Check failure on line 320 in l1-contracts-foundry/script/Utils.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 320 in l1-contracts-foundry/script/Utils.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 320 in l1-contracts-foundry/script/Utils.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.log(ownable.owner());

Check failure on line 321 in l1-contracts-foundry/script/Utils.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 321 in l1-contracts-foundry/script/Utils.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 321 in l1-contracts-foundry/script/Utils.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
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

0 comments on commit 6b71e20

Please sign in to comment.