Skip to content

Commit

Permalink
feat: adding a realistic deployment script for the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosgj94 committed Apr 16, 2024
1 parent ec9d19d commit 3078805
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 12 deletions.
103 changes: 103 additions & 0 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -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";

Check warning on line 10 in script/Deploy.s.sol

View workflow job for this annotation

GitHub Actions / lint-and-format

imported name hashHelpers is not used

import {MyPlugin} from "../src/MyPlugin.sol";

Check warning on line 12 in script/Deploy.s.sol

View workflow job for this annotation

GitHub Actions / lint-and-format

imported name MyPlugin is not used
import {MyPluginSetup} from "../src/MyPluginSetup.sol";

contract MyPluginScript is Script {
address pluginRepoFactory;

Check warning on line 16 in script/Deploy.s.sol

View workflow job for this annotation

GitHub Actions / lint-and-format

Explicitly mark visibility of state
DAOFactory daoFactory;

Check warning on line 17 in script/Deploy.s.sol

View workflow job for this annotation

GitHub Actions / lint-and-format

Explicitly mark visibility of state
string nameWithEntropy;

Check warning on line 18 in script/Deploy.s.sol

View workflow job for this annotation

GitHub Actions / lint-and-format

Explicitly mark visibility of state
address[] pluginAddress;

Check warning on line 19 in script/Deploy.s.sol

View workflow job for this annotation

GitHub Actions / lint-and-format

Explicitly mark visibility of state

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
);
}
}
12 changes: 0 additions & 12 deletions scripts/Deploy.s.sol

This file was deleted.

0 comments on commit 3078805

Please sign in to comment.