From 30788059973f177be9e607eabca2a7f81826f65d Mon Sep 17 00:00:00 2001 From: Carlos Juarez Date: Tue, 16 Apr 2024 10:07:58 +0200 Subject: [PATCH] feat: adding a realistic deployment script for the plugin --- script/Deploy.s.sol | 103 +++++++++++++++++++++++++++++++++++++++++++ scripts/Deploy.s.sol | 12 ----- 2 files changed, 103 insertions(+), 12 deletions(-) create mode 100644 script/Deploy.s.sol delete mode 100644 scripts/Deploy.s.sol diff --git a/script/Deploy.s.sol b/script/Deploy.s.sol new file mode 100644 index 0000000..81d8716 --- /dev/null +++ b/script/Deploy.s.sol @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.24; + +import {Script, console2} from "forge-std/Script.sol"; +import {Vm} from "forge-std/Vm.sol"; + +import {DAOFactory} from "@aragon/osx/framework/dao/DAOFactory.sol"; +import {PluginRepoFactory} from "@aragon/osx/framework/plugin/repo/PluginRepoFactory.sol"; +import {PluginRepo} from "@aragon/osx/framework/plugin/repo/PluginRepo.sol"; +import {hashHelpers, PluginSetupRef} from "@aragon/osx/framework/plugin/setup/PluginSetupProcessorHelpers.sol"; + +import {MyPlugin} from "../src/MyPlugin.sol"; +import {MyPluginSetup} from "../src/MyPluginSetup.sol"; + +contract MyPluginScript is Script { + address pluginRepoFactory; + DAOFactory daoFactory; + string nameWithEntropy; + address[] pluginAddress; + + function setUp() public { + pluginRepoFactory = vm.envAddress("PLUGIN_REPO_FACTORY"); + daoFactory = DAOFactory(vm.envAddress("DAO_FACTORY")); + nameWithEntropy = string.concat("my-plugin-", vm.toString(block.timestamp)); + } + + function run() public { + // 0. Setting up Foundry + vm.startBroadcast(vm.envUint("PRIVATE_KEY")); + + // 1. Deploying the Plugin Setup + MyPluginSetup pluginSetup = deployPluginSetup(); + + // 2. Publishing it in the Aragon OSx Protocol + PluginRepo pluginRepo = deployPluginRepo(address(pluginSetup)); + + // 3. Defining the DAO Settings + DAOFactory.DAOSettings memory daoSettings = getDAOSettings(); + + // 4. Defining the plugin settings + DAOFactory.PluginSettings[] memory pluginSettings = getPluginSettings(pluginRepo); + + // 5. Deploying the DAO + vm.recordLogs(); + address createdDAO = address(daoFactory.createDao(daoSettings, pluginSettings)); + + // 6. Getting the Plugin Address + Vm.Log[] memory logEntries = vm.getRecordedLogs(); + + for (uint256 i = 0; i < logEntries.length; i++) { + if ( + logEntries[i].topics[0] == + keccak256("InstallationApplied(address,address,bytes32,bytes32)") + ) { + pluginAddress.push(address(uint160(uint256(logEntries[i].topics[2])))); + } + } + + vm.stopBroadcast(); + + // 7. Logging the resulting addresses + console2.log("Plugin Setup: ", address(pluginSetup)); + console2.log("Plugin Repo: ", address(pluginRepo)); + console2.log("Created DAO: ", address(createdDAO)); + console2.log("Installed Plugins: "); + for (uint256 i = 0; i < pluginAddress.length; i++) { + console2.log("- ", pluginAddress[i]); + } + } + + function deployPluginSetup() public returns (MyPluginSetup) { + MyPluginSetup pluginSetup = new MyPluginSetup(); + return pluginSetup; + } + + function deployPluginRepo(address pluginSetup) public returns (PluginRepo pluginRepo) { + pluginRepo = PluginRepoFactory(pluginRepoFactory).createPluginRepoWithFirstVersion( + nameWithEntropy, + pluginSetup, + msg.sender, + "0x00", // TODO: Give these actual values on prod + "0x00" + ); + } + + function getDAOSettings() public view returns (DAOFactory.DAOSettings memory) { + return DAOFactory.DAOSettings(address(0), "", nameWithEntropy, ""); + } + + function getPluginSettings( + PluginRepo pluginRepo + ) public pure returns (DAOFactory.PluginSettings[] memory pluginSettings) { + uint256 pluginCounterNumber = 1; + bytes memory pluginSettingsData = abi.encode(pluginCounterNumber); + + PluginRepo.Tag memory tag = PluginRepo.Tag(1, 1); + pluginSettings = new DAOFactory.PluginSettings[](1); + pluginSettings[0] = DAOFactory.PluginSettings( + PluginSetupRef(tag, pluginRepo), + pluginSettingsData + ); + } +} diff --git a/scripts/Deploy.s.sol b/scripts/Deploy.s.sol deleted file mode 100644 index c7293c9..0000000 --- a/scripts/Deploy.s.sol +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.24; - -import {Script, console2} from "forge-std/Script.sol"; - -contract MyPluginScript is Script { - function setUp() public {} - - function run() public { - vm.broadcast(); - } -}