|
| 1 | +// SPDX-License-Identifier: AGPL-3.0 |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +import { ScriptTools } from "dss-test/ScriptTools.sol"; |
| 5 | + |
| 6 | +import "forge-std/Script.sol"; |
| 7 | + |
| 8 | +import { CCTPForwarder } from "xchain-helpers/forwarders/CCTPForwarder.sol"; |
| 9 | + |
| 10 | +import { ControllerInstance } from "../deploy/ControllerInstance.sol"; |
| 11 | +import { ForeignControllerInit as ForeignInit } from "../deploy/ForeignControllerInit.sol"; |
| 12 | +import { MainnetControllerInit as MainnetInit } from "../deploy/MainnetControllerInit.sol"; |
| 13 | + |
| 14 | +contract UpgradeMainnetController is Script { |
| 15 | + |
| 16 | + using stdJson for string; |
| 17 | + using ScriptTools for string; |
| 18 | + |
| 19 | + function run() external { |
| 20 | + vm.setEnv("FOUNDRY_ROOT_CHAINID", "1"); |
| 21 | + vm.setEnv("FOUNDRY_EXPORTS_OVERWRITE_LATEST", "true"); |
| 22 | + |
| 23 | + vm.createSelectFork(getChain("mainnet").rpcUrl); |
| 24 | + |
| 25 | + console.log("Upgrading mainnet controller..."); |
| 26 | + |
| 27 | + string memory fileSlug = string(abi.encodePacked("mainnet-", vm.envString("ENV"))); |
| 28 | + |
| 29 | + address newController = vm.envAddress("NEW_CONTROLLER"); |
| 30 | + address oldController = vm.envAddress("OLD_CONTROLLER"); |
| 31 | + |
| 32 | + vm.startBroadcast(); |
| 33 | + |
| 34 | + string memory inputConfig = ScriptTools.readInput(fileSlug); |
| 35 | + |
| 36 | + ControllerInstance memory controllerInst = ControllerInstance({ |
| 37 | + almProxy : inputConfig.readAddress(".almProxy"), |
| 38 | + controller : newController, |
| 39 | + rateLimits : inputConfig.readAddress(".rateLimits") |
| 40 | + }); |
| 41 | + |
| 42 | + MainnetInit.ConfigAddressParams memory configAddresses = MainnetInit.ConfigAddressParams({ |
| 43 | + freezer : inputConfig.readAddress(".freezer"), |
| 44 | + relayer : inputConfig.readAddress(".relayer"), |
| 45 | + oldController : oldController |
| 46 | + }); |
| 47 | + |
| 48 | + MainnetInit.CheckAddressParams memory checkAddresses = MainnetInit.CheckAddressParams({ |
| 49 | + admin : inputConfig.readAddress(".admin"), |
| 50 | + proxy : inputConfig.readAddress(".almProxy"), |
| 51 | + rateLimits : inputConfig.readAddress(".rateLimits"), |
| 52 | + vault : inputConfig.readAddress(".allocatorVault"), |
| 53 | + psm : inputConfig.readAddress(".psm"), |
| 54 | + daiUsds : inputConfig.readAddress(".daiUsds"), |
| 55 | + cctp : inputConfig.readAddress(".cctpTokenMessenger") |
| 56 | + }); |
| 57 | + |
| 58 | + MainnetInit.MintRecipient[] memory mintRecipients = new MainnetInit.MintRecipient[](1); |
| 59 | + |
| 60 | + string memory baseInputConfig = ScriptTools.readInput(string(abi.encodePacked("base-", vm.envString("ENV")))); |
| 61 | + |
| 62 | + address baseAlmProxy = baseInputConfig.readAddress(".almProxy"); |
| 63 | + |
| 64 | + mintRecipients[0] = MainnetInit.MintRecipient({ |
| 65 | + domain : CCTPForwarder.DOMAIN_ID_CIRCLE_BASE, |
| 66 | + mintRecipient : bytes32(uint256(uint160(baseAlmProxy))) |
| 67 | + }); |
| 68 | + |
| 69 | + MainnetInit.upgradeController(controllerInst, configAddresses, checkAddresses, mintRecipients); |
| 70 | + |
| 71 | + vm.stopBroadcast(); |
| 72 | + |
| 73 | + console.log("ALMProxy updated at ", controllerInst.almProxy); |
| 74 | + console.log("RateLimits upgraded at ", controllerInst.rateLimits); |
| 75 | + console.log("Controller upgraded at ", newController); |
| 76 | + console.log("Old Controller deprecated at", oldController); |
| 77 | + } |
| 78 | + |
| 79 | +} |
| 80 | + |
| 81 | +contract UpgradeForeignController is Script { |
| 82 | + |
| 83 | + using stdJson for string; |
| 84 | + using ScriptTools for string; |
| 85 | + |
| 86 | + function run() external { |
| 87 | + vm.setEnv("FOUNDRY_ROOT_CHAINID", "1"); |
| 88 | + vm.setEnv("FOUNDRY_EXPORTS_OVERWRITE_LATEST", "true"); |
| 89 | + |
| 90 | + string memory chainName = vm.envString("CHAIN"); |
| 91 | + string memory fileSlug = string(abi.encodePacked(chainName, "-", vm.envString("ENV"))); |
| 92 | + |
| 93 | + address newController = vm.envAddress("NEW_CONTROLLER"); |
| 94 | + address oldController = vm.envAddress("OLD_CONTROLLER"); |
| 95 | + |
| 96 | + vm.createSelectFork(getChain(chainName).rpcUrl); |
| 97 | + |
| 98 | + console.log(string(abi.encodePacked("Upgrading ", chainName, " controller..."))); |
| 99 | + |
| 100 | + vm.startBroadcast(); |
| 101 | + |
| 102 | + string memory inputConfig = ScriptTools.readInput(fileSlug); |
| 103 | + |
| 104 | + ControllerInstance memory controllerInst = ControllerInstance({ |
| 105 | + almProxy : inputConfig.readAddress(".almProxy"), |
| 106 | + controller : newController, |
| 107 | + rateLimits : inputConfig.readAddress(".rateLimits") |
| 108 | + }); |
| 109 | + |
| 110 | + ForeignInit.ConfigAddressParams memory configAddresses = ForeignInit.ConfigAddressParams({ |
| 111 | + freezer : inputConfig.readAddress(".freezer"), |
| 112 | + relayer : inputConfig.readAddress(".relayer"), |
| 113 | + oldController : oldController |
| 114 | + }); |
| 115 | + |
| 116 | + ForeignInit.CheckAddressParams memory checkAddresses = ForeignInit.CheckAddressParams({ |
| 117 | + admin : inputConfig.readAddress(".admin"), |
| 118 | + psm : inputConfig.readAddress(".psm"), |
| 119 | + cctp : inputConfig.readAddress(".cctpTokenMessenger"), |
| 120 | + usdc : inputConfig.readAddress(".usdc"), |
| 121 | + susds : inputConfig.readAddress(".susds"), |
| 122 | + usds : inputConfig.readAddress(".usds") |
| 123 | + }); |
| 124 | + |
| 125 | + ForeignInit.MintRecipient[] memory mintRecipients = new ForeignInit.MintRecipient[](1); |
| 126 | + |
| 127 | + string memory mainnetInputConfig = ScriptTools.readInput(string(abi.encodePacked("mainnet-", vm.envString("ENV")))); |
| 128 | + |
| 129 | + address mainnetAlmProxy = mainnetInputConfig.readAddress(".almProxy"); |
| 130 | + |
| 131 | + mintRecipients[0] = ForeignInit.MintRecipient({ |
| 132 | + domain : CCTPForwarder.DOMAIN_ID_CIRCLE_ETHEREUM, |
| 133 | + mintRecipient : bytes32(uint256(uint160(mainnetAlmProxy))) |
| 134 | + }); |
| 135 | + |
| 136 | + ForeignInit.upgradeController(controllerInst, configAddresses, checkAddresses, mintRecipients); |
| 137 | + |
| 138 | + vm.stopBroadcast(); |
| 139 | + |
| 140 | + console.log("ALMProxy updated at ", controllerInst.almProxy); |
| 141 | + console.log("RateLimits upgraded at ", controllerInst.rateLimits); |
| 142 | + console.log("Controller upgraded at ", newController); |
| 143 | + console.log("Old controller deprecated at", oldController); |
| 144 | + } |
| 145 | + |
| 146 | +} |
0 commit comments