|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +import { Script, console2 } from "forge-std/Script.sol"; |
| 5 | +import { SafeSingletonDeployer } from "safe-singleton-deployer/SafeSingletonDeployer.sol"; |
| 6 | +import { Registry } from "src/Registry.sol"; |
| 7 | +import "@openzeppelin/contracts/utils/Strings.sol"; |
| 8 | +import { MockResolver } from "test/mocks/MockResolver.sol"; |
| 9 | +import { MockSchemaValidator } from "test/mocks/MockSchemaValidator.sol"; |
| 10 | + |
| 11 | +import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; |
| 12 | + |
| 13 | +struct Proxy { |
| 14 | + address implementation; |
| 15 | + address proxy; |
| 16 | +} |
| 17 | + |
| 18 | +struct EnvironmentSingletons { |
| 19 | + address deployer; |
| 20 | + address registry; |
| 21 | + Proxy schemaValidator; |
| 22 | + Proxy resolver; |
| 23 | +} |
| 24 | + |
| 25 | +contract DeployAll is Script { |
| 26 | + address constant SAFE_PROXY_FACTORY = address(0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67); |
| 27 | + address constant SAFE_SINGLETON = address(0x29fcB43b46531BcA003ddC8FCB67FFE91900C762); |
| 28 | + address constant MULTI_SEND = address(0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526); |
| 29 | + address constant ENTRYPOINT = address(0x0000000071727De22E5E9d8BAf0edAc6f37da032); |
| 30 | + |
| 31 | + function run() public virtual { |
| 32 | + console2.log("Deployment on chainId:", block.chainid); |
| 33 | + |
| 34 | + uint256 privKey = vm.envUint("PRIVATE_KEY"); |
| 35 | + console2.log("Deployer Addr: ", vm.addr(privKey)); |
| 36 | + EnvironmentSingletons memory env; |
| 37 | + env.registry = _registry(privKey); |
| 38 | + |
| 39 | + env.schemaValidator.implementation = _schemaValidator(privKey); |
| 40 | + env.resolver.implementation = _resolver(privKey, env.registry); |
| 41 | + // env.schemaValidator.proxy = _proxy({ |
| 42 | + // pKey: privKey, |
| 43 | + // implementation: env.schemaValidator.implementation, |
| 44 | + // admin: env.attesterSafe, |
| 45 | + // salt: vm.envBytes32("SCHEMA_VALIDATOR_PROXY_SALT"), |
| 46 | + // initializer: "" |
| 47 | + // }); |
| 48 | + // env.resolver.proxy = _proxy({ |
| 49 | + // pKey: privKey, |
| 50 | + // implementation: env.resolver.implementation, |
| 51 | + // admin: env.attesterSafe, |
| 52 | + // salt: vm.envBytes32("RESOLVER_PROXY_SALT"), |
| 53 | + // initializer: "" |
| 54 | + // }); |
| 55 | + |
| 56 | + _logJson(env); |
| 57 | + _print(env); |
| 58 | + } |
| 59 | + |
| 60 | + function _registry(uint256 pKey) internal returns (address registry) { |
| 61 | + registry = SafeSingletonDeployer.broadcastDeploy({ |
| 62 | + deployerPrivateKey: pKey, |
| 63 | + creationCode: type(Registry).creationCode, |
| 64 | + salt: vm.envBytes32("REGISTRY_SALT") |
| 65 | + }); |
| 66 | + _initCode("Registry", type(Registry).creationCode, ""); |
| 67 | + } |
| 68 | + |
| 69 | + function _schemaValidator(uint256 pKey) internal returns (address schemaValidator) { |
| 70 | + schemaValidator = SafeSingletonDeployer.broadcastDeploy({ |
| 71 | + deployerPrivateKey: pKey, |
| 72 | + creationCode: type(MockSchemaValidator).creationCode, |
| 73 | + args: abi.encode(true), |
| 74 | + salt: vm.envBytes32("SCHEMA_VALIDATOR_SALT") |
| 75 | + }); |
| 76 | + } |
| 77 | + |
| 78 | + function _proxy( |
| 79 | + uint256 pKey, |
| 80 | + address implementation, |
| 81 | + address admin, |
| 82 | + bytes32 salt, |
| 83 | + bytes memory initializer |
| 84 | + ) |
| 85 | + internal |
| 86 | + returns (address proxy) |
| 87 | + { |
| 88 | + proxy = SafeSingletonDeployer.broadcastDeploy({ |
| 89 | + deployerPrivateKey: pKey, |
| 90 | + creationCode: type(TransparentUpgradeableProxy).creationCode, |
| 91 | + args: abi.encode(implementation, admin, initializer), |
| 92 | + salt: salt |
| 93 | + }); |
| 94 | + } |
| 95 | + |
| 96 | + function _resolver(uint256 pKey, address registry) internal returns (address resolver) { |
| 97 | + resolver = SafeSingletonDeployer.broadcastDeploy({ |
| 98 | + deployerPrivateKey: pKey, |
| 99 | + creationCode: type(MockResolver).creationCode, |
| 100 | + args: abi.encode(true), |
| 101 | + salt: vm.envBytes32("RESOLVER_SALT") |
| 102 | + }); |
| 103 | + } |
| 104 | + |
| 105 | + function _logJson(EnvironmentSingletons memory env) internal { |
| 106 | + string memory root = "some key"; |
| 107 | + vm.serializeUint(root, "chainId", block.chainid); |
| 108 | + vm.serializeAddress(root, "broadcastEOA", env.deployer); |
| 109 | + |
| 110 | + string memory deployments = "deployments"; |
| 111 | + |
| 112 | + string memory item = "registry"; |
| 113 | + vm.serializeAddress(item, "address", env.registry); |
| 114 | + vm.serializeBytes32(item, "salt", vm.envBytes32("REGISTRY_SALT")); |
| 115 | + vm.serializeAddress(item, "deployer", env.deployer); |
| 116 | + item = vm.serializeAddress(item, "factory", SafeSingletonDeployer.SAFE_SINGLETON_FACTORY); |
| 117 | + vm.serializeString(deployments, "registry", item); |
| 118 | + |
| 119 | + string memory schemaValidator = "schemaValidator"; |
| 120 | + string memory implementation = "schemaValidator implementation"; |
| 121 | + vm.serializeAddress(implementation, "address", env.schemaValidator.implementation); |
| 122 | + vm.serializeBytes32(implementation, "salt", vm.envBytes32("SCHEMA_VALIDATOR_SALT")); |
| 123 | + vm.serializeAddress(implementation, "deployer", env.deployer); |
| 124 | + implementation = vm.serializeAddress(implementation, "factory", SafeSingletonDeployer.SAFE_SINGLETON_FACTORY); |
| 125 | + vm.serializeString(schemaValidator, "implementation", implementation); |
| 126 | + |
| 127 | + string memory schemaValidatorProxy = "schemaValidator proxy"; |
| 128 | + vm.serializeAddress(schemaValidatorProxy, "address", env.schemaValidator.proxy); |
| 129 | + vm.serializeBytes32(schemaValidatorProxy, "salt", vm.envBytes32("SCHEMA_VALIDATOR_PROXY_SALT")); |
| 130 | + vm.serializeAddress(schemaValidatorProxy, "deployer", env.deployer); |
| 131 | + schemaValidatorProxy = vm.serializeAddress(schemaValidatorProxy, "factory", SafeSingletonDeployer.SAFE_SINGLETON_FACTORY); |
| 132 | + schemaValidator = vm.serializeString(schemaValidator, "proxy", schemaValidatorProxy); |
| 133 | + |
| 134 | + vm.serializeString(deployments, "schemaValidator", schemaValidator); |
| 135 | + |
| 136 | + string memory resolver = "resolver"; |
| 137 | + string memory resolverImplementation = "resolver implementation"; |
| 138 | + vm.serializeAddress(resolverImplementation, "address", env.resolver.implementation); |
| 139 | + vm.serializeBytes32(resolverImplementation, "salt", vm.envBytes32("SCHEMA_VALIDATOR_SALT")); |
| 140 | + vm.serializeAddress(resolverImplementation, "deployer", env.deployer); |
| 141 | + resolverImplementation = vm.serializeAddress(resolverImplementation, "factory", SafeSingletonDeployer.SAFE_SINGLETON_FACTORY); |
| 142 | + vm.serializeString(resolver, "implementation", resolverImplementation); |
| 143 | + |
| 144 | + string memory resolverProxy = "resolverProxy proxy"; |
| 145 | + vm.serializeAddress(resolverProxy, "address", env.resolver.proxy); |
| 146 | + vm.serializeBytes32(resolverProxy, "salt", vm.envBytes32("SCHEMA_VALIDATOR_PROXY_SALT")); |
| 147 | + vm.serializeAddress(resolverProxy, "deployer", env.deployer); |
| 148 | + resolverProxy = vm.serializeAddress(resolverProxy, "factory", SafeSingletonDeployer.SAFE_SINGLETON_FACTORY); |
| 149 | + resolver = vm.serializeString(resolver, "proxy", resolverProxy); |
| 150 | + |
| 151 | + vm.serializeString(deployments, "resolver", resolver); |
| 152 | + |
| 153 | + string memory output = vm.serializeUint(deployments, "timestamp", block.timestamp); |
| 154 | + string memory finalJson = vm.serializeString(root, "deployments", output); |
| 155 | + |
| 156 | + string memory fileName = string(abi.encodePacked("./deployments/", Strings.toString(block.chainid), ".json")); |
| 157 | + console2.log("Writing to file: ", fileName); |
| 158 | + |
| 159 | + vm.writeJson(finalJson, fileName); |
| 160 | + } |
| 161 | + |
| 162 | + function _print(EnvironmentSingletons memory env) internal pure { |
| 163 | + console2.log("-------------------------------------------------------"); |
| 164 | + console2.log("registry:", env.registry); |
| 165 | + console2.log("schemaValidator:", env.schemaValidator.implementation); |
| 166 | + console2.log("schemaValidatorProxy:", env.schemaValidator.proxy); |
| 167 | + console2.log("resolver:", env.resolver.implementation); |
| 168 | + console2.log("resolverProxy:", env.resolver.proxy); |
| 169 | + console2.log("-------------------------------------------------------"); |
| 170 | + } |
| 171 | + |
| 172 | + function _initCode(string memory component, bytes memory creationCode, bytes memory args) private pure { |
| 173 | + console2.log("InitCodeHash: ", component); |
| 174 | + console2.logBytes32(keccak256(abi.encodePacked(creationCode, args))); |
| 175 | + console2.log("\n"); |
| 176 | + } |
| 177 | +} |
0 commit comments