|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity 0.8.21; |
| 3 | + |
| 4 | +import {Test} from "forge-std/Test.sol"; |
| 5 | +import {StorageRegistry} from "../src/StorageRegistry.sol"; |
| 6 | +import {IdRegistry} from "../src/IdRegistry.sol"; |
| 7 | +import {IdGateway} from "../src/IdGateway.sol"; |
| 8 | +import {KeyRegistry, IKeyRegistry} from "../src/KeyRegistry.sol"; |
| 9 | +import {KeyGateway} from "../src/KeyGateway.sol"; |
| 10 | +import {SignedKeyRequestValidator} from "../src/validators/SignedKeyRequestValidator.sol"; |
| 11 | +import {Bundler, IBundler} from "../src/Bundler.sol"; |
| 12 | +import {RecoveryProxy} from "../src/RecoveryProxy.sol"; |
| 13 | +import {console, ImmutableCreate2Deployer} from "./abstract/ImmutableCreate2Deployer.sol"; |
| 14 | + |
| 15 | +contract UpgradeBundler is ImmutableCreate2Deployer, Test { |
| 16 | + struct Salts { |
| 17 | + bytes32 bundler; |
| 18 | + } |
| 19 | + |
| 20 | + struct DeploymentParams { |
| 21 | + Salts salts; |
| 22 | + } |
| 23 | + |
| 24 | + struct Addresses { |
| 25 | + address storageRegistry; |
| 26 | + address idRegistry; |
| 27 | + address idGateway; |
| 28 | + address keyRegistry; |
| 29 | + address keyGateway; |
| 30 | + address signedKeyRequestValidator; |
| 31 | + address bundler; |
| 32 | + address recoveryProxy; |
| 33 | + } |
| 34 | + |
| 35 | + struct Contracts { |
| 36 | + StorageRegistry storageRegistry; |
| 37 | + IdRegistry idRegistry; |
| 38 | + IdGateway idGateway; |
| 39 | + KeyRegistry keyRegistry; |
| 40 | + KeyGateway keyGateway; |
| 41 | + SignedKeyRequestValidator signedKeyRequestValidator; |
| 42 | + Bundler bundler; |
| 43 | + RecoveryProxy recoveryProxy; |
| 44 | + } |
| 45 | + |
| 46 | + function run() public { |
| 47 | + runSetup(runDeploy(loadDeploymentParams())); |
| 48 | + } |
| 49 | + |
| 50 | + function runDeploy( |
| 51 | + DeploymentParams memory params |
| 52 | + ) public returns (Contracts memory) { |
| 53 | + return runDeploy(params, true); |
| 54 | + } |
| 55 | + |
| 56 | + function runDeploy(DeploymentParams memory params, bool broadcast) public returns (Contracts memory) { |
| 57 | + Addresses memory addrs; |
| 58 | + |
| 59 | + // No changes |
| 60 | + addrs.storageRegistry = address(0x00000000fcCe7f938e7aE6D3c335bD6a1a7c593D); |
| 61 | + addrs.idRegistry = address(0x00000000Fc6c5F01Fc30151999387Bb99A9f489b); |
| 62 | + addrs.idGateway = payable(address(0x00000000Fc25870C6eD6b6c7E41Fb078b7656f69)); |
| 63 | + addrs.keyRegistry = address(0x00000000Fc1237824fb747aBDE0FF18990E59b7e); |
| 64 | + addrs.keyGateway = address(0x00000000fC56947c7E7183f8Ca4B62398CaAdf0B); |
| 65 | + addrs.signedKeyRequestValidator = address(0x00000000FC700472606ED4fA22623Acf62c60553); |
| 66 | + addrs.recoveryProxy = address(0x00000000FcB080a4D6c39a9354dA9EB9bC104cd7); |
| 67 | + |
| 68 | + // Deploy new Bundler |
| 69 | + addrs.bundler = register( |
| 70 | + "Bundler", params.salts.bundler, type(Bundler).creationCode, abi.encode(addrs.idGateway, addrs.keyGateway) |
| 71 | + ); |
| 72 | + deploy(broadcast); |
| 73 | + |
| 74 | + return Contracts({ |
| 75 | + storageRegistry: StorageRegistry(addrs.storageRegistry), |
| 76 | + idRegistry: IdRegistry(addrs.idRegistry), |
| 77 | + idGateway: IdGateway(payable(addrs.idGateway)), |
| 78 | + keyRegistry: KeyRegistry(addrs.keyRegistry), |
| 79 | + keyGateway: KeyGateway(payable(addrs.keyGateway)), |
| 80 | + signedKeyRequestValidator: SignedKeyRequestValidator(addrs.signedKeyRequestValidator), |
| 81 | + bundler: Bundler(payable(addrs.bundler)), |
| 82 | + recoveryProxy: RecoveryProxy(addrs.recoveryProxy) |
| 83 | + }); |
| 84 | + } |
| 85 | + |
| 86 | + function runSetup(Contracts memory contracts, DeploymentParams memory, bool) public { |
| 87 | + if (deploymentChanged()) { |
| 88 | + console.log("Running setup"); |
| 89 | + |
| 90 | + // Check bundler deploy parameters |
| 91 | + assertEq(address(contracts.bundler.idGateway()), address(contracts.idGateway)); |
| 92 | + assertEq(address(contracts.bundler.keyGateway()), address(contracts.keyGateway)); |
| 93 | + } else { |
| 94 | + console.log("No changes, skipping setup"); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + function runSetup( |
| 99 | + Contracts memory contracts |
| 100 | + ) public { |
| 101 | + DeploymentParams memory params = loadDeploymentParams(); |
| 102 | + runSetup(contracts, params, true); |
| 103 | + } |
| 104 | + |
| 105 | + function loadDeploymentParams() internal returns (DeploymentParams memory) { |
| 106 | + return DeploymentParams({salts: Salts({bundler: vm.envOr("BUNDLER_CREATE2_SALT", bytes32(0))})}); |
| 107 | + } |
| 108 | +} |
0 commit comments