Skip to content

Commit

Permalink
Deploy Paymaster Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yberjon committed Jul 10, 2024
1 parent b3f72b2 commit c77880a
Show file tree
Hide file tree
Showing 7 changed files with 836 additions and 541 deletions.
551 changes: 29 additions & 522 deletions l1-contracts/deploy-scripts/DeployL1.s.sol

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions l1-contracts/deploy-scripts/DeployPaymaster.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ contract DeployPaymaster is Script {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/deploy-script-config-template/config-deploy-paymaster.toml");
string memory toml = vm.readFile(path);
config.bridgehubAddress = toml.readAddress("$.bridgehub");
config.l1SharedBridgeProxy = toml.readAddress("$.l1_shared_bridge");
config.chainId = toml.readUint("$.chain_id");

path = string.concat(root, "/script-out/output-deploy-l1.toml");
toml = vm.readFile(path);
config.bridgehubAddress = toml.readAddress("$.deployed_addresses.bridgehub.bridgehub_proxy_addr");
config.chainId = toml.readUint("$.era_chain_id");
}

function saveOutput() internal {
Expand All @@ -50,7 +53,6 @@ contract DeployPaymaster is Script {
bytes memory testnetPaymasterBytecode = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/contracts/TestnetPaymaster.sol/TestnetPaymaster.json"
);
console.log("addr", config.bridgehubAddress);
config.paymaster = Utils.deployThroughL1({
bytecode: testnetPaymasterBytecode,
constructorargs: "",
Expand Down
23 changes: 18 additions & 5 deletions l1-contracts/deploy-scripts/RegisterHyperchain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ contract RegisterHyperchainScript is Script {
function initializeConfig() internal {
// Grab config from output of l1 deployment
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-config/register-hyperchain.toml");
string memory path = string.concat(root, "/script-out/output-deploy-l1.toml");
string memory toml = vm.readFile(path);

config.deployerAddress = msg.sender;

// Config file must be parsed key by key, otherwise values returned
// are parsed alfabetically and not by key.
// https://book.getfoundry.sh/cheatcodes/parse-toml
config.ownerAddress = toml.readAddress("$.owner_address");
config.ownerAddress = toml.readAddress("$.owner_addr");

config.bridgehub = toml.readAddress("$.deployed_addresses.bridgehub.bridgehub_proxy_addr");
config.stateTransitionProxy = toml.readAddress(
Expand All @@ -82,6 +82,9 @@ contract RegisterHyperchainScript is Script {

config.diamondCutData = toml.readBytes("$.contracts_config.diamond_cut_data");

path = string.concat(root, "/deploy-script-config-template/register-hyperchain.toml");
toml = vm.readFile(path);

config.chainChainId = toml.readUint("$.chain.chain_chain_id");
config.bridgehubCreateNewChainSalt = toml.readUint("$.chain.bridgehub_create_new_chain_salt");
config.baseToken = toml.readAddress("$.chain.base_token_addr");
Expand All @@ -98,6 +101,16 @@ contract RegisterHyperchainScript is Script {
config.governanceSecurityCouncilAddress = toml.readAddress("$.chain.governance_security_council_address");
}

function getValidatorAdmin() public returns (address) {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-out/output-deploy-l1.toml");
string memory toml = vm.readFile(path);

address validatorAdmin = toml.readAddress("$.deployer_addr");

return validatorAdmin;
}

function checkTokenAddress() internal view {
if (config.baseToken == address(0)) {
revert("Token address is not set");
Expand Down Expand Up @@ -193,7 +206,7 @@ contract RegisterHyperchainScript is Script {
function addValidators() internal {
ValidatorTimelock validatorTimelock = ValidatorTimelock(config.validatorTimelock);

vm.startBroadcast();
vm.startBroadcast(getValidatorAdmin());
validatorTimelock.addValidator(config.chainChainId, config.validatorSenderOperatorCommitEth);
validatorTimelock.addValidator(config.chainChainId, config.validatorSenderOperatorBlobsEth);
vm.stopBroadcast();
Expand All @@ -204,7 +217,7 @@ contract RegisterHyperchainScript is Script {
function configureZkSyncStateTransition() internal {
IZkSyncHyperchain hyperchain = IZkSyncHyperchain(config.newDiamondProxy);

vm.startBroadcast();
vm.startBroadcast(getValidatorAdmin());
hyperchain.setTokenMultiplier(
config.baseTokenGasPriceMultiplierNominator,
config.baseTokenGasPriceMultiplierDenominator
Expand All @@ -221,7 +234,7 @@ contract RegisterHyperchainScript is Script {
function setPendingAdmin() internal {
IZkSyncHyperchain hyperchain = IZkSyncHyperchain(config.newDiamondProxy);

vm.broadcast();
vm.broadcast(getValidatorAdmin());
hyperchain.setPendingAdmin(config.governance);
console.log("Owner for ", config.newDiamondProxy, "set to", config.governance);
}
Expand Down
14 changes: 11 additions & 3 deletions l1-contracts/deploy-scripts/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ 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";
import {L2ContractHelper} from "contracts/common/libraries/L2ContractHelper.sol";
import {stdToml} from "forge-std/StdToml.sol";
import {console2 as console} from "forge-std/Script.sol";

library Utils {
using stdToml for string;
// Cheatcodes address, 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D.
address internal constant VM_ADDRESS = address(uint160(uint256(keccak256("hevm cheat code"))));
Vm internal constant vm = Vm(VM_ADDRESS);
Expand Down Expand Up @@ -182,7 +185,6 @@ library Utils {
address l1SharedBridgeProxy
) internal returns (address) {
bytes32 bytecodeHash = L2ContractHelper.hashL2Bytecode(bytecode);

bytes memory deployData = abi.encodeWithSignature(
"create2(bytes32,bytes32,bytes)",
create2salt,
Expand Down Expand Up @@ -215,6 +217,7 @@ library Utils {
bridgehubAddress: bridgehubAddress,
l1SharedBridgeProxy: l1SharedBridgeProxy
});

return contractAddress;
}

Expand All @@ -239,7 +242,7 @@ library Utils {
l2GasLimit,
REQUIRED_L2_GAS_PRICE_PER_PUBDATA
) * 2;

L2TransactionRequestDirect memory l2TransactionRequestDirect = L2TransactionRequestDirect({
chainId: chainId,
mintValue: requiredValueToDeploy,
Expand Down Expand Up @@ -303,6 +306,11 @@ library Utils {
uint256 _value,
uint256 _delay
) internal {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-out/output-deploy-l1.toml");
string memory toml = vm.readFile(path);
address ownerAddress = toml.readAddress("$.owner_addr");

IGovernance governance = IGovernance(_governor);

IGovernance.Call[] memory calls = new IGovernance.Call[](1);
Expand All @@ -314,7 +322,7 @@ library Utils {
salt: _salt
});

vm.startBroadcast();
vm.startBroadcast(ownerAddress);
governance.scheduleTransparent(operation, _delay);
if (_delay == 0) {
governance.execute{value: _value}(operation);
Expand Down
Loading

0 comments on commit c77880a

Please sign in to comment.