Skip to content

Commit

Permalink
Add calculate address script
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed Oct 18, 2024
1 parent 57c64a2 commit b9cc374
Showing 1 changed file with 166 additions and 0 deletions.
166 changes: 166 additions & 0 deletions l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import {Script, console2 as console} from "forge-std/Script.sol";
import {Utils} from "./Utils.sol";
import {stdToml} from "forge-std/StdToml.sol";
import {L2ContractHelper} from "contracts/common/libraries/L2ContractHelper.sol";
import {AddressAliasHelper} from "contracts/vendor/AddressAliasHelper.sol";

Check failure on line 8 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

imported name AddressAliasHelper is not used

Check failure on line 8 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

imported name AddressAliasHelper is not used

Check failure on line 8 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

imported name AddressAliasHelper is not used

contract CalculateL2Bridge is Script {
using stdToml for string;

Config config;
ContractsBytecodes contracts;

struct Config {
address l1SharedBridgeProxy;
address governance;
address erc20BridgeProxy;
address sender;
uint256 chainId;
uint256 eraChainId;
}

struct ContractsBytecodes {
bytes l2StandardErc20FactoryBytecode;
bytes beaconProxy;
bytes l2StandardErc20Bytecode;
bytes l2SharedBridgeBytecode;
bytes l2SharedBridgeProxyBytecode;
bytes proxyAdminBytecode;
}


function loadContracts() internal {
//HACK: Meanwhile we are not integrated foundry zksync we use contracts that has been built using hardhat
contracts.l2StandardErc20FactoryBytecode = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol/UpgradeableBeacon.json"
);
contracts.beaconProxy = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol/BeaconProxy.json"
);
contracts.l2StandardErc20Bytecode = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/contracts/bridge/L2StandardERC20.sol/L2StandardERC20.json"
);

contracts.l2SharedBridgeBytecode = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/contracts/bridge/L2SharedBridge.sol/L2SharedBridge.json"
);

contracts.l2SharedBridgeProxyBytecode = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json"
);
contracts.proxyAdminBytecode = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol/ProxyAdmin.json"
);

}

function initializeConfig() internal {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-config/calculate.toml");
string memory toml = vm.readFile(path);
config.eraChainId = toml.readUint("$.era_chain_id");
config.sender = toml.readAddress("$.sender");
config.l1SharedBridgeProxy = toml.readAddress("$.l1_shared_bridge");
config.erc20BridgeProxy = toml.readAddress("$.erc20_bridge");
}

function run() public {
initializeConfig();
loadContracts();
address implAddr = sharedBridgeImplementation();
address proxyAdmin = proxyAdminAddr();
sharedBridgeProxyAddr(implAddr, proxyAdmin);

}

function calcualateAddress(

Check warning on line 79 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / typos

"calcualate" should be "calculate".
address sender,
bytes memory bytecode,
bytes memory constructorargs,
bytes32 create2salt
) internal returns (address) {

bytes32 bytecodeHash = L2ContractHelper.hashL2Bytecode(bytecode);

console.log("BytecodeHash");

Check failure on line 88 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 88 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 88 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.logBytes32(bytecodeHash);

Check failure on line 89 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 89 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 89 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.log("constructorargs");

Check failure on line 90 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 90 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 90 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.logBytes(constructorargs);

Check failure on line 91 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 91 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 91 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
bytes memory deployData = abi.encodeWithSignature(

Check failure on line 92 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Variable "deployData" is unused

Check failure on line 92 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Variable "deployData" is unused

Check failure on line 92 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Variable "deployData" is unused
"create2(bytes32,bytes32,bytes)",
create2salt,
bytecodeHash,
constructorargs
);

address contractAddress = L2ContractHelper.computeCreate2Address(
sender,
create2salt,
bytecodeHash,
keccak256(constructorargs)
);
return contractAddress;
}

function sharedBridgeImplementation() internal returns (address){
bytes memory constructorData = abi.encode(config.eraChainId);


address implAddr = calcualateAddress({

Check warning on line 112 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / typos

"calcualate" should be "calculate".
sender: config.sender,
bytecode: contracts.l2SharedBridgeBytecode,
constructorargs: constructorData,
create2salt: ""

});
return implAddr;
}

function proxyAdminAddr() internal returns (address){
bytes[] memory factoryDeps = new bytes[](0);

Check failure on line 123 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Variable "factoryDeps" is unused

Check failure on line 123 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Variable "factoryDeps" is unused

Check failure on line 123 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Variable "factoryDeps" is unused

address proxyAdminContract = calcualateAddress({

Check warning on line 125 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / typos

"calcualate" should be "calculate".
sender: config.sender,
bytecode: contracts.proxyAdminBytecode,
constructorargs: "",
create2salt: ""
});
return proxyAdminContract;
}

function sharedBridgeProxyAddr(address implAddr, address proxyadmin) internal {
address l2GovernorAddress = proxyadmin;
bytes32 l2StandardErc20BytecodeHash = L2ContractHelper.hashL2Bytecode(contracts.beaconProxy);

string memory functionSignature;

functionSignature = "initialize(address,address,bytes32,address)";
// solhint-disable-next-line func-named-parameters
bytes memory proxyInitializationParams = abi.encodeWithSignature(
functionSignature,
config.l1SharedBridgeProxy,
config.erc20BridgeProxy,
l2StandardErc20BytecodeHash,
l2GovernorAddress
);

bytes memory l2SharedBridgeProxyConstructorData = abi.encode(
implAddr,
l2GovernorAddress,
proxyInitializationParams
);

address l2SharedBridgeProxy = calcualateAddress({

Check warning on line 156 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / typos

"calcualate" should be "calculate".
sender: config.sender,
bytecode: contracts.l2SharedBridgeProxyBytecode,
constructorargs: l2SharedBridgeProxyConstructorData,
create2salt: ""
});

console.log("Final address");

Check failure on line 163 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 163 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 163 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.logAddress(l2SharedBridgeProxy);

Check failure on line 164 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 164 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 164 in l1-contracts/deploy-scripts/CalculateL2Bridge.s.sol

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}
}

0 comments on commit b9cc374

Please sign in to comment.