{"id":24997906,"url":"https://github.com/gavin-chua/codefordao-contracts","last_synced_at":"2025-09-11T21:32:44.705Z","repository":{"id":275052272,"uuid":"916471661","full_name":"gavin-chua/CodeforDAO-Contracts","owner":"gavin-chua","description":"Solidity smart contracts of CodeforDAO","archived":false,"fork":false,"pushed_at":"2025-01-14T06:56:37.000Z","size":519,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-22T23:53:39.472Z","etag":null,"topics":["contracts","cryptos","dao","evm","solidity","web3"],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gavin-chua.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["guo-yu"]}},"created_at":"2025-01-14T06:52:22.000Z","updated_at":"2025-01-14T06:58:03.000Z","dependencies_parsed_at":"2025-01-30T22:45:29.677Z","dependency_job_id":null,"html_url":"https://github.com/gavin-chua/CodeforDAO-Contracts","commit_stats":null,"previous_names":["gavin-chua/codefordao-contracts"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gavin-chua/CodeforDAO-Contracts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavin-chua%2FCodeforDAO-Contracts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavin-chua%2FCodeforDAO-Contracts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavin-chua%2FCodeforDAO-Contracts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavin-chua%2FCodeforDAO-Contracts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gavin-chua","download_url":"https://codeload.github.com/gavin-chua/CodeforDAO-Contracts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavin-chua%2FCodeforDAO-Contracts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274709015,"owners_count":25335305,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["contracts","cryptos","dao","evm","solidity","web3"],"created_at":"2025-02-04T17:26:30.367Z","updated_at":"2025-09-11T21:32:44.681Z","avatar_url":"https://github.com/gavin-chua.png","language":"Solidity","funding_links":["https://github.com/sponsors/guo-yu"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://twitter.com/codefordao\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/97301607?s=200\u0026u=d0a9f88d13d7d7dd5b37c09fdd802c9fe378d029\u0026v=4\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003ch2 align=\"center\"\u003e\n  CodeforDAO Contracts\n\u003c/h2\u003e\n\u003cp align=\"center\"\u003e\n  Base on, build upon and code for DAOs.\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  Make DAO the next generation of productivity tools for global collaboration.\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  Follow us on Twitter \u003ca href=\"https://twitter.com/codefordao\"\u003e@codefordao\u003c/a\u003e.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/CodeforDAO/contracts/\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/license-MIT-green.svg\" alt=\"mit license\"/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003e **This project is a work in progress, it has not been audited for code security and is being deployed in local development and test networks and is not gas optimized at this time. Please use with caution.**\n\nThe CodeforDAO contract is a set of DAO infrastructure and efficiency tools with member NFT at its core.\n\nIt is centered on a set of membership contracts for the `ERC721` protocol, the creation of its counterpart share contracts, two parallel governance frameworks and a timelock vault contract.\n\nIt introduces some basic features to DAO, including vault contracts for self-service participation in investments, a set of modular frameworks to support aggressive governance.\n\n## Core Concepts\n\nWe believe that DAO will be a very powerful tool and, for now, it has become an important concept trusted by developers worldwide and by a large number of users familiar with Web3. Many people who are unfamiliar with each other are spread all over the world, but are contributing to a DAO at the same time.\n\nBut we have to admit that, at the moment, while DAO has achieved an important foundation of trust, its infrastructure is still very imperfect, especially in terms of efficiency tools, and we cannot guarantee that DAO will be able to run continuously and efficiently like any large organization, such as a traditional shareholding company. This is exactly what CodeforDAO aims to do.\n\nBy improving aggressive governance, and continuously contributing infrastructure and modules to the DAO, and even introducing AI automated governance, we hope to take the DAO to a new level of efficiency.\n\n## Structures\n\nThis is a brief introduction to the structure of the contract, if you are interested in more, please read our contract code, which is located in the `./contracts` folder.\n\n### Membership\n\nThe Member Contract is the entry point for other subcontracts, and it is an `ERC721` contract. It includes a simple allowlist invitation function and provides the `investMint(to)` method to ensure that external investors get a corresponding membership (similar to a board of managers)\n\n### Share\n\nThe share contract is a simple `ERC20` full-featured contract, the ownership of which will be delegated to the vault contract upon creation\n\n### Treasury\n\nAfter the initialization function is completed, the vault contract is the owner of all contracts. It stores all the assets and contract permissions of the DAO. It provides an invest method that allows external investors to participate in the financing of the DAO and issues corresponding shares for these investors. The vault contract also operates with a specific module, which is authorized to use some of the assets for the daily management of the DAO.\n\n### Governor\n\nThe governance contract allows voting using `ERC721` and `ERC20`, after the initialization function is completed we will have two governance contracts, one supporting voting using the member NFT (1:1) it's role is similar to the founding team voting and the other supporting voting using shares (similar to class B shares on the board)\n\n### Module\n\nThe core module contract provides a set of methods that allow modules and vaults to interact. At the same time, it is an actively governed multi-signature contract that allows proposing, confirming, scheduling and executing module-related operations, and you can see the usage of these hook functions in specific modules.\n\n## Get started\n\nIn order to start developing, you must be familiar with some basic knowledge of smart contracts and install the corresponding development environment.\n\n```bash\n$ npm install\n```\n\n**Note:** these smart contracts are not designed to be library contracts, and you can fork these contracts locally to modify them yourself, rather than importing them directly by a git link.\n\nIf you encounter a dependency conflict during installation, this is due to the version number of the `hardhat-deploy-ethers` module being incompatible with the `@nomiclabs/hardhat-waffle` required `@nomiclabs/hardhat-ethers` module version number. Make sure to add `--force` flag to `$ npm install` to resolve this problem.\n\n### Membership NFT\n\nCurrently, the membership NFT contract (`contracts/contracts/core/Membership.sol`) is the entry point for all contracts and the creator of all contracts.\n\nThis means that deploying this contract will deploy a full set of DAO governance contracts, including the vault, an ERC20 token contract, and two sets of governance contracts.\n\nAfter deployment, you need to call the `setupGovernor` method to release important permissions and hand them over to the vault contract, which secures the governance of the DAO.\n\n**Note:** In the future, the way the membership contract is initialized may change, and in order to optimize gas fees, we may modify it to allow external scripts to modify permissions.\n\nRun the `npm run deploy:test` command to deploy the contract, or you can refer to the `. /tests` folder for test cases.\n\n### Work with Web UI\n\nTo use the contract with the Web UI, we need to run the hardhat network locally and export the `ABI` of the contracts in the directory where the UI is located, which by default is: `../website/contracts/`.\n\nTo run the hardhat network locally with contracts deployed:\n\n```bash\n$ npm run dev\n```\n\nYou could also set a `TEST_STAGE` to `npm run dev`, the stage flag is for Web UI testing propose as it will make sure localhost blockchain starts with contracts states.\n\n```bash\n$ npm run dev:mint_ready\n```\n\nThis is same as:\n\n```bash\n$ TEST_STAGE=MINT_READY npm run dev\n```\n\nAnd, add the `MulticallV1` contract address to `.env.local` of the Web UI project without `0x` prefix. (Make sure to replace with the address you just deployed, not the sample one)\n\n```\nNEXT_PUBLIC_LOCALHOST_MULTICALL_ADDRESS=Cf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9\n```\n\nThis is useful for third party web module like `multicall.js` or `useDapp`\n\n### Extending Modules\n\nModules are an important part of aggressive governance. By writing your own modules, you can expand any business to be part of DAO.\n\nUsing the `Payroll` module as an example, we can take a look at how to write our own module.\n\n```solidity\ncontract Payroll is Module {\n  using Strings for uint256;\n  using Address for address payable;\n\n  constructor(\n    address membership,\n    uint256[] memory operators,\n    uint256 delay\n  ) Module('Payroll', 'Payroll Module V1', membership, operators, delay) {}\n}\n\n```\n\nBy inheriting from the core module, Payroll needs to initialize the constructor of the core module, which will automatically get a timelock contract `payroll.timelock()`.\n\nThe module must pass three parameters, which are the address of the member NFT contract, the list of operator IDs (NFT tokenID) and the time for which the time lock delay proposal will be executed.\n\nYou can easily define structured data and events in the module.\n\n```solidity\nstruct PayrollDetail {\n  uint256 amount;\n  PayrollType paytype;\n  PayrollPeriod period;\n  PayrollInTokens tokens;\n}\n\nevent PayrollAdded(uint256 indexed memberId, PayrollDetail payroll);\nevent Payrollscheduled(uint256 indexed memberId, bytes32 proposalId);\n\nmapping(uint256 =\u003e mapping(PayrollPeriod =\u003e PayrollDetail[])) private _payrolls;\n```\n\nThe application module must perform the proposal function of the core module; simply put, it must implement an external method to allow operators to make proposals.\n\n```solidity\n/**\n * @dev Schedule Payroll\n * Adding a member's compensation proposal to the compensation cycle\n */\nfunction schedulePayroll(uint256 memberId, PayrollPeriod period)\n  public\n  onlyOperator\n  returns (bytes32 _proposalId)\n{\n  // Create proposal payload\n  PayrollDetail[] memory payrolls = GetPayroll(memberId, period);\n  address[] memory targets = new address[](payrolls.length);\n  uint256[] memory values;\n  bytes[] memory calldatas;\n  string memory description = string(\n    abi.encodePacked(\n      _payrollPeriods[uint256(period)],\n      ' Payroll for #',\n      memberId.toString(),\n      '(',\n      _payrollTypes[uint256(payrolls[0].paytype)],\n      ')',\n      '@',\n      block.timestamp.toString()\n    )\n  );\n\n  // You can use the methods of the core module to get the corresponding address\n  address memberWallet = getAddressByMemberId(memberId);\n\n  for (uint256 i = 0; i \u003c payrolls.length; i++) {\n    PayrollDetail memory payroll = payrolls[i];\n    targets[i] = address(this);\n    values[i] = payroll.amount;\n\n    // Fullfill proposal payload calldatas\n    calldatas[i] = abi.encodeWithSignature(\n      'execTransfer(address,address[],uint256[])',\n      memberWallet,\n      payroll.tokens.tokens,\n      payroll.tokens.amounts\n    );\n  }\n\n  // Propose It.\n  _proposalId = propose(targets, values, calldatas, description);\n\n  // Trigger your event\n  emit Payrollscheduled(memberId, _proposalId);\n}\n\n```\n\nCorrespondingly, the application module sea needs to implement specific proposal execution methods. In this case, the method is `execTransfer`.\n\nCheck the [Payroll module](./contracts/modules/Payroll.sol) to see the detail implementation.\n\nBy default, proposals in the module need to be confirmed by all operators before they can enter the queue and wait for execution. Its lifecycle must go through four stages: proposal, confirm, queue and execution. Since it is aggressively governed, module proposals do not need to go through a full DAO vote.\n\nThe application module's timelock contract allows the use of the vault's assets within certain limits, and you can license and invoke these assets with `approveModulePayment()` and `pullModulePayment()` in the vault contract. `pullPayments()` method in core module is also useful.\n\n**Notice**: `approveModulePayment()` require a vote of the DAO\n\n### Running tests\n\nThis project currently uses `hardhat-deploy` for multiple environment deployments and to increase the speed of testing.\n\n```bash\n$ npm run test\n```\n\nRunning spec tests where you can find them in `./test` folder\n\n```bash\n$ npm run test:membership\n```\n\nor\n\n```bash\n$ npm run test:governor\n```\n\nIf you need a test coverage report:\n\n```bash\n$ npm run test:coverage\n```\n\n### About Gas optimization\n\nThe contract code in this project is not currently systematically gas optimized, so they will be quite expensive to deploy on the eth mainnet. At this point, we do not recommend that using them on the mainnet.\n\nAs a result, the base libraries that the contract code in this project relies on will change very frequently and may be replaced by more efficient libraries, but we will try to find a balance between audited reliable contracts and efficiency.\n\n### MIT license\n\nCopyright (c) 2022 CodeforDAO \u0026lt;contact@codefordao.org\u0026gt;\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavin-chua%2Fcodefordao-contracts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgavin-chua%2Fcodefordao-contracts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavin-chua%2Fcodefordao-contracts/lists"}