|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity ^0.8.17; |
| 3 | + |
| 4 | +import {Script, console2} from "forge-std/Script.sol"; |
| 5 | +import {stdJson} from "forge-std/StdJson.sol"; |
| 6 | + |
| 7 | +import {IDAO} from "@aragon/osx/core/dao/DAO.sol"; |
| 8 | +import {PluginRepoFactory} from "@aragon/osx/framework/plugin/repo/PluginRepoFactory.sol"; |
| 9 | +import {PluginRepo} from "@aragon/osx/framework/plugin/repo/PluginRepo.sol"; |
| 10 | +import {hashHelpers, PluginSetupRef} from "@aragon/osx/framework/plugin/setup/PluginSetupProcessorHelpers.sol"; |
| 11 | +import {TokenVotingSetup} from "../src/TokenVotingSetup.sol"; |
| 12 | +import {GovernanceERC20} from "../src/erc20/GovernanceERC20.sol"; |
| 13 | +import {GovernanceWrappedERC20} from "../src/erc20/GovernanceWrappedERC20.sol"; |
| 14 | +import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; |
| 15 | + |
| 16 | +/** |
| 17 | + * This script performs the following tasks: |
| 18 | + * - Deploys a new PluginRepo |
| 19 | + * - Publishes the first version (release 1, build 1) |
| 20 | + * |
| 21 | + * The full plugin deployment should be made from the Protocol Factory. |
| 22 | + * This script is provided for separate ad-hoc deployments. |
| 23 | + */ |
| 24 | +contract DeployPluginRepoScript is Script { |
| 25 | + using stdJson for string; |
| 26 | + |
| 27 | + address deployer; |
| 28 | + PluginRepoFactory pluginRepoFactory; |
| 29 | + string pluginEnsSubdomain; |
| 30 | + address pluginRepoMaintainerAddress; |
| 31 | + |
| 32 | + // Artifacts |
| 33 | + PluginRepo myPluginRepo; |
| 34 | + TokenVotingSetup pluginSetup; |
| 35 | + |
| 36 | + modifier broadcast() { |
| 37 | + uint256 privKey = vm.envUint("DEPLOYMENT_PRIVATE_KEY"); |
| 38 | + vm.startBroadcast(privKey); |
| 39 | + |
| 40 | + deployer = vm.addr(privKey); |
| 41 | + console2.log("General"); |
| 42 | + console2.log("- Deploying from: ", deployer); |
| 43 | + console2.log("- Chain ID: ", block.chainid); |
| 44 | + console2.log(""); |
| 45 | + |
| 46 | + _; |
| 47 | + |
| 48 | + vm.stopBroadcast(); |
| 49 | + } |
| 50 | + |
| 51 | + function setUp() public { |
| 52 | + // Pick the contract addresses from |
| 53 | + // https://github.com/aragon/osx/blob/main/packages/artifacts/src/addresses.json |
| 54 | + |
| 55 | + // Prepare the OSx factories for the current network |
| 56 | + pluginRepoFactory = PluginRepoFactory(vm.envAddress("PLUGIN_REPO_FACTORY_ADDRESS")); |
| 57 | + vm.label(address(pluginRepoFactory), "PluginRepoFactory"); |
| 58 | + |
| 59 | + // Read the rest of environment variables |
| 60 | + pluginEnsSubdomain = vm.envOr("PLUGIN_ENS_SUBDOMAIN", string("")); |
| 61 | + |
| 62 | + // Using a random subdomain if empty |
| 63 | + if (bytes(pluginEnsSubdomain).length == 0) { |
| 64 | + pluginEnsSubdomain = string.concat("my-token-voting-plugin-", vm.toString(block.timestamp)); |
| 65 | + } |
| 66 | + |
| 67 | + pluginRepoMaintainerAddress = vm.envAddress("PLUGIN_REPO_MAINTAINER_ADDRESS"); |
| 68 | + vm.label(pluginRepoMaintainerAddress, "Maintainer"); |
| 69 | + } |
| 70 | + |
| 71 | + function run() public broadcast { |
| 72 | + // Publish the first version in a new plugin repo |
| 73 | + deployPluginRepo(); |
| 74 | + |
| 75 | + // Done |
| 76 | + printDeployment(); |
| 77 | + |
| 78 | + // Write the addresses to a JSON file |
| 79 | + if (!vm.envOr("SIMULATION", false)) { |
| 80 | + writeJsonArtifacts(); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + function deployPluginRepo() public { |
| 85 | + // Dependency implementations |
| 86 | + GovernanceERC20 governanceERC20 = new GovernanceERC20( |
| 87 | + IDAO(address(0)), "", "", GovernanceERC20.MintSettings(new address[](0), new uint256[](0)), new address[](0) |
| 88 | + ); |
| 89 | + GovernanceWrappedERC20 governanceWrappedERC20 = |
| 90 | + new GovernanceWrappedERC20(IERC20Upgradeable(address(0)), "", "", new address[](0)); |
| 91 | + |
| 92 | + // Plugin setup (the installer) |
| 93 | + pluginSetup = new TokenVotingSetup(governanceERC20, governanceWrappedERC20); |
| 94 | + |
| 95 | + // The new plugin repository |
| 96 | + // Publish the plugin in a new repo as release 1, build 1 |
| 97 | + myPluginRepo = pluginRepoFactory.createPluginRepoWithFirstVersion( |
| 98 | + pluginEnsSubdomain, address(pluginSetup), pluginRepoMaintainerAddress, " ", " " |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + function printDeployment() public view { |
| 103 | + console2.log("TokenVoting plugin:"); |
| 104 | + console2.log("- Plugin repo: ", address(myPluginRepo)); |
| 105 | + console2.log("- Plugin repo maintainer: ", pluginRepoMaintainerAddress); |
| 106 | + console2.log("- ENS: ", string.concat(pluginEnsSubdomain, ".plugin.dao.eth")); |
| 107 | + console2.log(""); |
| 108 | + } |
| 109 | + |
| 110 | + function writeJsonArtifacts() internal { |
| 111 | + string memory artifacts = "output"; |
| 112 | + artifacts.serialize("pluginRepo", address(myPluginRepo)); |
| 113 | + artifacts.serialize("pluginRepoMaintainer", pluginRepoMaintainerAddress); |
| 114 | + artifacts = artifacts.serialize("pluginEnsDomain", string.concat(pluginEnsSubdomain, ".plugin.dao.eth")); |
| 115 | + |
| 116 | + string memory networkName = vm.envString("NETWORK_NAME"); |
| 117 | + string memory filePath = string.concat( |
| 118 | + vm.projectRoot(), "/artifacts/deployment-", networkName, "-", vm.toString(block.timestamp), ".json" |
| 119 | + ); |
| 120 | + artifacts.write(filePath); |
| 121 | + |
| 122 | + console2.log("Deployment artifacts written to", filePath); |
| 123 | + } |
| 124 | +} |
0 commit comments