Skip to content

Commit

Permalink
feat: contracts and sdk refactoring (#36)
Browse files Browse the repository at this point in the history
* build: added version number to allow importing

* revert: remove osx dependency

* fix: use new IDAO

* feat: add former voting helpers

* feat: refactored helpers

* refactor: event function

* refactor: improved naming

* refactor: improve time helpers

* refactor: removed hardhat time

* fix: wrong import

* refactor: improve time constants

* docs: add todo comment

* refactor: move over plugin and plugin setups as well as permissions

* refactor: renaming and changed folder structure

* feat: added bitmap

* refactor: moved metadata into separate file

* refactor: moved events

* refactor: moved permissions

* revert: version bump of solhint

* refactor: improve folder structure

* refactor: folders structure, imports, yarn lock

* ci: fix

* fix: version mismatch with sdk

* revert: remove etherscan

* refactor: rename event constants

* ci: make sdk an alpha version

* feat: move permissions

* build: rename package

* refactor: structure

* build: save yarn lock

* build: use same typescript version

* refactor: imports

* build: contracts start with alpha version

* build: use commons-sdk

* fix: imports

* build: add files to index

* v0.0.1-alpha.1

* fix: bump version and fix import

* fix: imports

* fix: missing export

* chore: bump version

* chore: save lock file

* chore: bump version

* build: no postinstall

* chore: ignore DS_Store files

* v0.0.1-alpha.3

* refactor: remove proxy helper

* build: add protocol version

* v0.0.1-alpha.4

* feat: made ProtocolVersion non-abstract

* refactor: protocol version number

remove protocol version constant and bump osx-commons-contracts package version number to match with the protocol version

* revert: make ProtocolVersion abstract and use mock instead

* v1.4.0-alpha.1

* refactor: renamed function

* chore: maintain changelog

* build: improve build

* ci: added missing secret

* revert: remove duplicate

* build: remove osx-ethers dependencies

* revert: remove TestPlugin

* build: use files allowlist instead of .npmignore denylist

* refactor: improved mocks

* refactor: improved mocks further

* refactor: rename test

* refactor: remove placeholder setup

* feat: added test sekletons and todos

* revert: removed todo that has its own task already

* build: bump version number

* docs: improved plugin setup mock data

* refactor: renamed PluginMockData to PluginSetupMockData

* refactor: setup mocks

* build: remove src folder

* refactor: move and added todo

* refactor: move auth into dao folder

* build: adapt the hardhat solidity source path subtask

* refactor: move auth

* revert: src removal

* revert: delete storage

* refactor: move governance into extensions

* build: remove governance folder from package.json

* fix: wrong path

* refactor: harmonize mock contract naming and move CloneFactory

* revert: author comment for mock

* style: fix enum values

* feat: add custom event error

* chore: use new sdk

* ci: fixes labeler

---------

Co-authored-by: Mathias Scherer <[email protected]>
  • Loading branch information
heueristik and mathewmeconry authored Jan 11, 2024
1 parent d5575f6 commit 4cf06f4
Show file tree
Hide file tree
Showing 103 changed files with 2,865 additions and 3,498 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/contracts-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ jobs:
env:
INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}

- name: 'Build the typechain'
run: 'yarn typechain'
env:
INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}

- name: 'Test the contracts and generate the coverage report'
run: 'yarn coverage >> $GITHUB_STEP_SUMMARY'
env:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pull_request_labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ jobs:
triage:
runs-on: ubuntu-latest
steps:
- name: 'Check out the repo'
uses: 'actions/checkout@v3'

- uses: actions/labeler@v4
with:
sync-labels: true
13 changes: 6 additions & 7 deletions contracts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v0.0.1
## v1.4.0

### Added

- Copied files from [aragon/osx commit e7ba46](https://github.com/aragon/osx/tree/e7ba46026db96931d3e4a585e8f30c585906e1fc)

- interfaces `IMajorityVoting`, `IMembership`, `IProposal`, `IERC20MintableUpgradeable`, `IGovernanceWrappedERC20`
- abstract contracts `MajorityVotingBase`, `Addresslist`,`Proposal`, `ProposalUpgradeable`, `GovernanceERC20`, `GovernanceWrappedERC20`,
- contracts `PlaceholderSetup`,
- libraries `VersionComparisonLib`
- free functions `BitMap`, `Ratio`, and `UncheckedMath`
- test helpers `TestERC1155`, `TestERC20`, `TestERC721`, `TestGovernanceERC20`, `AddresslistMock`, `MajorityVotingMock`, `RatioTest`, `VersionComparisonLibTest`
- interfaces `IDAO`, `IPermissionCondition`, `IPlugin`, `IMembership`, `IProposal`, `IPluginSetup`, `IProtocolVersion`,
- abstract contracts `DaoAuthorizable`, `DaoAuthorizableUpgradeable`, `Plugin`, `PluginCloneable`, `PluginUUPSUpgradeable`, `PermissionCondition`, `PermissionConditionUpgradeable`, `Addresslist`, `Proposal`, `ProposalUpgradeable`, `PluginSetup`
- contracts `CloneFactory`
- libraries `PermissionLib`, `VersionComparisonLib`
- free functions `auth`, `Proxy`, `BitMap`, `Ratio`, `UncheckedMath`
1 change: 1 addition & 0 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const config: HardhatUserConfig = {
src: './contracts',
coinmarketcap: process.env.COINMARKETCAP_API_KEY,
},

networks,
paths: {
artifacts: './artifacts',
Expand Down
16 changes: 7 additions & 9 deletions contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{
"name": "@aragon/osx-commons",
"name": "@aragon/osx-commons-contracts",
"license": "AGPL-3.0-or-later",
"description": "The Aragon OSx contracts package containing common utilities",
"version": "0.0.1",
"version": "1.4.0-alpha.2",
"author": {
"name": "aragon",
"url": "https://github.com/aragon"
},
"devDependencies": {
"@aragon/osx-commons-sdk": "0.0.1-alpha.3",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/constants": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.6",
"@nomicfoundation/hardhat-network-helpers": "^1.0.8",
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@openzeppelin/hardhat-upgrades": "^1.28.0",
"@typechain/ethers-v5": "^10.1.1",
"@typechain/hardhat": "^6.1.4",
"@types/chai": "^4.3.4",
Expand All @@ -30,7 +33,6 @@
"hardhat": "^2.13.1",
"hardhat-deploy": "^0.11.26",
"hardhat-gas-reporter": "^1.0.9",
"ipfs-http-client": "^51.0.0",
"mocha": "^10.1.0",
"rimraf": "^5.0.5",
"solidity-coverage": "^0.8.2",
Expand All @@ -41,14 +43,11 @@
"typescript": "5.0.4"
},
"dependencies": {
"@aragon/osx": "aragon/osx#develop",
"@aragon/osx-ethers": "1.3.0",
"@openzeppelin/contracts": "4.9.5",
"@openzeppelin/contracts-upgradeable": "4.9.5",
"@openzeppelin/hardhat-upgrades": "^1.28.0"
"@openzeppelin/contracts-upgradeable": "4.9.5"
},
"files": [
"/src"
"src/{dao,permission,plugin,utils}/**/*.sol"
],
"keywords": [
"blockchain",
Expand All @@ -71,7 +70,6 @@
"lint": "yarn lint:sol && yarn lint:ts",
"lint:sol": "cd .. && yarn run lint:contracts:sol",
"lint:ts": "cd .. && yarn run lint:contracts:ts",
"postinstall": "DOTENV_CONFIG_PATH=../.env.example yarn typechain",
"test": "hardhat test",
"typechain": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat typechain",
"clean": "rimraf ./artifacts ./cache ./coverage ./types ./coverage.json && yarn typechain",
Expand Down
135 changes: 135 additions & 0 deletions contracts/src/dao/IDAO.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

pragma solidity ^0.8.8;

/// @title IDAO
/// @author Aragon Association - 2022-2023
/// @notice The interface required for DAOs within the Aragon App DAO framework.
/// @custom:security-contact [email protected]
interface IDAO {
/// @notice The action struct to be consumed by the DAO's `execute` function resulting in an external call.
/// @param to The address to call.
/// @param value The native token value to be sent with the call.
/// @param data The bytes-encoded function selector and calldata for the call.
struct Action {
address to;
uint256 value;
bytes data;
}

/// @notice Checks if an address has permission on a contract via a permission identifier and considers if `ANY_ADDRESS` was used in the granting process.
/// @param _where The address of the contract.
/// @param _who The address of a EOA or contract to give the permissions.
/// @param _permissionId The permission identifier.
/// @param _data The optional data passed to the `PermissionCondition` registered.
/// @return Returns true if the address has permission, false if not.
function hasPermission(
address _where,
address _who,
bytes32 _permissionId,
bytes memory _data
) external view returns (bool);

/// @notice Updates the DAO metadata (e.g., an IPFS hash).
/// @param _metadata The IPFS hash of the new metadata object.
function setMetadata(bytes calldata _metadata) external;

/// @notice Emitted when the DAO metadata is updated.
/// @param metadata The IPFS hash of the new metadata object.
event MetadataSet(bytes metadata);

/// @notice Executes a list of actions. If a zero allow-failure map is provided, a failing action reverts the entire execution. If a non-zero allow-failure map is provided, allowed actions can fail without the entire call being reverted.
/// @param _callId The ID of the call. The definition of the value of `callId` is up to the calling contract and can be used, e.g., as a nonce.
/// @param _actions The array of actions.
/// @param _allowFailureMap A bitmap allowing execution to succeed, even if individual actions might revert. If the bit at index `i` is 1, the execution succeeds even if the `i`th action reverts. A failure map value of 0 requires every action to not revert.
/// @return The array of results obtained from the executed actions in `bytes`.
/// @return The resulting failure map containing the actions have actually failed.
function execute(
bytes32 _callId,
Action[] memory _actions,
uint256 _allowFailureMap
) external returns (bytes[] memory, uint256);

/// @notice Emitted when a proposal is executed.
/// @param actor The address of the caller.
/// @param callId The ID of the call.
/// @param actions The array of actions executed.
/// @param allowFailureMap The allow failure map encoding which actions are allowed to fail.
/// @param failureMap The failure map encoding which actions have failed.
/// @param execResults The array with the results of the executed actions.
/// @dev The value of `callId` is defined by the component/contract calling the execute function. A `Plugin` implementation can use it, for example, as a nonce.
event Executed(
address indexed actor,
bytes32 callId,
Action[] actions,
uint256 allowFailureMap,
uint256 failureMap,
bytes[] execResults
);

/// @notice Emitted when a standard callback is registered.
/// @param interfaceId The ID of the interface.
/// @param callbackSelector The selector of the callback function.
/// @param magicNumber The magic number to be registered for the callback function selector.
event StandardCallbackRegistered(
bytes4 interfaceId,
bytes4 callbackSelector,
bytes4 magicNumber
);

/// @notice Deposits (native) tokens to the DAO contract with a reference string.
/// @param _token The address of the token or address(0) in case of the native token.
/// @param _amount The amount of tokens to deposit.
/// @param _reference The reference describing the deposit reason.
function deposit(address _token, uint256 _amount, string calldata _reference) external payable;

/// @notice Emitted when a token deposit has been made to the DAO.
/// @param sender The address of the sender.
/// @param token The address of the deposited token.
/// @param amount The amount of tokens deposited.
/// @param _reference The reference describing the deposit reason.
event Deposited(
address indexed sender,
address indexed token,
uint256 amount,
string _reference
);

/// @notice Emitted when a native token deposit has been made to the DAO.
/// @dev This event is intended to be emitted in the `receive` function and is therefore bound by the gas limitations for `send`/`transfer` calls introduced by [ERC-2929](https://eips.ethereum.org/EIPS/eip-2929).
/// @param sender The address of the sender.
/// @param amount The amount of native tokens deposited.
event NativeTokenDeposited(address sender, uint256 amount);

/// @notice Setter for the trusted forwarder verifying the meta transaction.
/// @param _trustedForwarder The trusted forwarder address.
function setTrustedForwarder(address _trustedForwarder) external;

/// @notice Getter for the trusted forwarder verifying the meta transaction.
/// @return The trusted forwarder address.
function getTrustedForwarder() external view returns (address);

/// @notice Emitted when a new TrustedForwarder is set on the DAO.
/// @param forwarder the new forwarder address.
event TrustedForwarderSet(address forwarder);

/// @notice Checks whether a signature is valid for a provided hash according to [ERC-1271](https://eips.ethereum.org/EIPS/eip-1271).
/// @param _hash The hash of the data to be signed.
/// @param _signature The signature byte array associated with `_hash`.
/// @return Returns the `bytes4` magic value `0x1626ba7e` if the signature is valid and `0xffffffff` if not.
function isValidSignature(bytes32 _hash, bytes memory _signature) external returns (bytes4);

/// @notice Registers an ERC standard having a callback by registering its [ERC-165](https://eips.ethereum.org/EIPS/eip-165) interface ID and callback function signature.
/// @param _interfaceId The ID of the interface.
/// @param _callbackSelector The selector of the callback function.
/// @param _magicNumber The magic number to be registered for the function signature.
function registerStandardCallback(
bytes4 _interfaceId,
bytes4 _callbackSelector,
bytes4 _magicNumber
) external;

/// @notice Removed function being left here to not corrupt the IDAO interface ID. Any call will revert.
/// @dev Introduced in v1.0.0. Removed in v1.4.0.
function setSignatureValidator(address) external;
}
97 changes: 0 additions & 97 deletions contracts/src/governance/majority-voting/IMajorityVoting.sol

This file was deleted.

Loading

0 comments on commit 4cf06f4

Please sign in to comment.