Skip to content

Commit

Permalink
🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonpete32 committed Apr 12, 2023
0 parents commit 9a2730d
Show file tree
Hide file tree
Showing 31 changed files with 9,455 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ETH_KEY=<Private-Key>
ETHERSCAN_KEY=<Etherscan-Api-Key>
POLYGONSCAN_KEY=<Polygonscan-Api-Key>
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
artifacts
cache
coverage
21 changes: 21 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
env: {
browser: false,
es2021: true,
mocha: true,
node: true,
},
plugins: ['@typescript-eslint'],
extends: [
'standard',
'plugin:prettier/recommended',
'plugin:node/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 12,
},
rules: {
'node/no-unsupported-features/es-syntax': ['error', {ignores: ['modules']}],
},
};
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
.env
coverage
coverage.json
typechain
typechain-types

#Hardhat files
cache
artifacts

2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
auto-install-peers = true
strict-peer-dependencies = false
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
artifacts
cache
coverage*
gasReporterOutput.json
Releases.md
7 changes: 7 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "solhint:recommended",
"rules": {
"compiler-version": ["error", "^0.8.0"],
"func-visibility": ["warn", {"ignoreConstructors": true}]
}
}
1 change: 1 addition & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"solidity.compileUsingRemoteVersion": "v0.8.17"
}
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Sample Hardhat Project

This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract.

Try running some of the following tasks:

```shell
npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
npx hardhat run scripts/deploy.ts
```
59 changes: 59 additions & 0 deletions contracts/TemplatePlugin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import {PluginUUPSUpgradeable, IDAO} from "@aragon/osx/core/plugin/PluginUUPSUpgradeable.sol";
import {ITemplate} from "./interfaces/ITemplate.sol";

/// @title TEMPLATE_PLUGIN
/// @author DAO Box - 2023
/// @notice A plugin that <does something>.
/// @dev This contract is a template for a plugin
contract TemplatePlugin is ITemplate, PluginUUPSUpgradeable {
/// @notice The ID of the permission required to call the `sensative` function.
bytes32 public constant SOME_PERMISSION_ID = keccak256("SOME_PERMISSION");

/// @notice The number that does something important.
uint256 private someNumber;

/// @notice The [ERC-165](https://eips.ethereum.org/EIPS/eip-165) interface ID of the contract.
bytes4 internal constant TEMPLATE_PLUGIN_INTERFACE_ID =
this.initialize.selector ^ this.getSomeNumber.selector;

/// @notice Initializes the component.
/// @dev This method is required to support [ERC-1822](https://eips.ethereum.org/EIPS/eip-1822).
/// @param _dao The IDAO interface of the associated DAO.
/// @param _someNumber A number that does something important
function initialize(IDAO _dao, uint256 _someNumber) external initializer {
__PluginUUPSUpgradeable_init(_dao);
someNumber = _someNumber;
}

/// @notice Checks if this or the parent contract supports an interface by its ID.
/// @param _interfaceId The ID of the interface.
/// @return Returns `true` if the interface is supported.
function supportsInterface(
bytes4 _interfaceId
) public view virtual override returns (bool) {
return
_interfaceId == TEMPLATE_PLUGIN_INTERFACE_ID ||
super.supportsInterface(_interfaceId);
}

/// @notice Gets the number that does something important.
/// @return Returns the number that does something important.
function getSomeNumber() external view returns (uint256) {
return someNumber;
}

/// @notice Does something that requires a permission
function execute(
IDAO.Action[] calldata _actions
) external auth(SOME_PERMISSION_ID) {
revert("Not implemented.");
}

/// @dev This empty reserved space is put in place to allow future versions to add new
/// variables without shifting down storage in the inheritance chain.
/// https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
uint256[49] private __gap;
}
123 changes: 123 additions & 0 deletions contracts/TemplateSetup.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
import {PluginSetup, IPluginSetup} from "@aragon/osx/framework/plugin/setup/PluginSetup.sol";

import {IDAO} from "@aragon/osx/core/dao/IDAO.sol";
import {DAO} from "@aragon/osx/core/dao/DAO.sol";
import {PermissionLib} from "@aragon/osx/core/permission/PermissionLib.sol";

import {TemplatePlugin} from "./TemplatePlugin.sol";

/// @title TemplatePluginSetup
/// @author DAO BOX
/// @notice The setup contract of the `TemplatePlugin` contract.
contract TemplateSetup is PluginSetup {
using Address for address;
using Clones for address;
using ERC165Checker for address;

/// @notice The address of the `TemplatePlugin` base contract.
TemplatePlugin private immutable templatePlugin;

/// @notice The error thrown when the helpers array length is not x.
error WrongHelpersArrayLength(uint length);

/// @notice The contract constructor, that deployes the bases.
constructor() {
templatePlugin = new TemplatePlugin();
}

/// @inheritdoc IPluginSetup
function prepareInstallation(
address _dao,
bytes calldata _data
)
external
returns (address plugin, PreparedSetupData memory preparedSetupData)
{
// Decode `_data` to extract the params needed for deploying and initializing `TemplatePlugin` plugin,
// and the required helpers
uint256 someNumber = abi.decode(_data, (uint256));

// Prepare and deploy plugin proxy.
plugin = createERC1967Proxy(
address(templatePlugin),
abi.encodeWithSelector(
TemplatePlugin.initialize.selector,
_dao,
someNumber
)
);

// Prepare permissions
PermissionLib.MultiTargetPermission[]
memory permissions = new PermissionLib.MultiTargetPermission[](2);

// Set plugin permissions to be granted.
// Grant the list of prmissions of the plugin to the DAO.
permissions[0] = PermissionLib.MultiTargetPermission(
PermissionLib.Operation.Grant,
plugin,
_dao,
PermissionLib.NO_CONDITION,
templatePlugin.SOME_PERMISSION_ID()
);

// Grant `EXECUTE_PERMISSION` of the DAO to the plugin.
permissions[1] = PermissionLib.MultiTargetPermission(
PermissionLib.Operation.Grant,
_dao,
plugin,
PermissionLib.NO_CONDITION,
DAO(payable(_dao)).EXECUTE_PERMISSION_ID()
);

preparedSetupData.permissions = permissions;
}

/// @inheritdoc IPluginSetup
function prepareUninstallation(
address _dao,
SetupPayload calldata _payload
)
external
view
returns (PermissionLib.MultiTargetPermission[] memory permissions)
{
// Prepare permissions.
uint256 helperLength = _payload.currentHelpers.length;
if (helperLength != 0) {
revert WrongHelpersArrayLength({length: helperLength});
}

permissions = new PermissionLib.MultiTargetPermission[](2);

// Set plugin permissions to be Revoked.
// Grant the list of prmissions of the plugin to the DAO.
permissions[0] = PermissionLib.MultiTargetPermission(
PermissionLib.Operation.Revoke,
_payload.plugin,
_dao,
PermissionLib.NO_CONDITION,
templatePlugin.SOME_PERMISSION_ID()
);

// Revoke `EXECUTE_PERMISSION` of the DAO to the plugin.
permissions[1] = PermissionLib.MultiTargetPermission(
PermissionLib.Operation.Revoke,
_dao,
_payload.plugin,
PermissionLib.NO_CONDITION,
DAO(payable(_dao)).EXECUTE_PERMISSION_ID()
);
}

/// @inheritdoc IPluginSetup
function implementation() external view virtual override returns (address) {
return address(templatePlugin);
}
}
15 changes: 15 additions & 0 deletions contracts/build-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"ui": "",
"change": "",
"pluginSetupABI": {
"prepareInstallation": [
""
],
"prepareUpdate": [
""
],
"prepareUninstallation": [
""
]
}
}
11 changes: 11 additions & 0 deletions contracts/interfaces/ITemplate.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title ITemplate
/// @dev This interface defines the methods that must be implemented by a template in a smart contract system.
/// @author DAO Box
interface ITemplate {
/// @dev Returns a uint256 value.
/// @return The uint256 value returned by the plugin.
function getSomeNumber() external view returns (uint256);
}
5 changes: 5 additions & 0 deletions contracts/release-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "TEMPLATE_PLUGIN",
"description": "",
"images": {}
}
19 changes: 19 additions & 0 deletions deploy/10_create_TEMPLATE_setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";

const func: DeployFunction = async function ({
deployments,
getNamedAccounts,
}: HardhatRuntimeEnvironment) {
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

console.log(`\n10: Creating TEMPLATE_SETUP.`);
await deploy("TEMPLATE_SETUP", {
from: deployer,
log: true,
});
};

export default func;
func.tags = ["CreateTEMPLATE_SETUP"];
33 changes: 33 additions & 0 deletions deploy/20_create_TEMPLATE_repo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { newPluginRepo } from "./helpers";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, ethers, network } = hre;
const { get } = deployments;
const { deployer } = await getNamedAccounts();
const signer = await ethers.getSigner(deployer);
const { address: setupAddress } = await get("Template");

const networkName = network.name === "local" ? "mainnet" : network.name;

const buildMetadataCid = "";
const releaseMetadataCid ="";

console.warn(
`\n20: Creating Template repo \nPlease make sure pluginRepo is not created more than once with the same subdomain.`
);

await newPluginRepo({
subdomain: "Template",
setupAddress,
deployer,
networkName,
signer,
buildMetadataCid,
releaseMetadataCid,
});
};

export default func;
func.tags = ["CreateTemplateRepo"];
Loading

0 comments on commit 9a2730d

Please sign in to comment.