From 17f7316489f9fcfe5ae825824a601c46ae37282a Mon Sep 17 00:00:00 2001 From: Glory Agatevure Date: Fri, 26 May 2023 02:34:33 +0100 Subject: [PATCH 1/8] investment dao --- InvestmentDAO/.gitattributes | 2 + InvestmentDAO/.gitignore | 42 + InvestmentDAO/LICENSE | 201 + InvestmentDAO/README.md | 43 + InvestmentDAO/netlify.toml | 12 + InvestmentDAO/package.json | 40 + InvestmentDAO/packages/hardhat/.envexample | 3 + InvestmentDAO/packages/hardhat/.gitignore | 14 + InvestmentDAO/packages/hardhat/.npmrc | 1 + InvestmentDAO/packages/hardhat/README.md | 124 + .../packages/hardhat/account_keys.json | 1 + .../hardhat/contracts/DaoAnalyzer.sol | 142 + .../packages/hardhat/contracts/Token.sol | 71 + .../packages/hardhat/deploy/00-deploy.js | 64 + .../packages/hardhat/hardhat.config.js | 98 + InvestmentDAO/packages/hardhat/package.json | 52 + .../packages/hardhat/scripts/deploy.js | 32 + .../packages/hardhat/scripts/watch.js | 18 + .../packages/hardhat/test/auction-test.js | 34 + InvestmentDAO/packages/hardhat/yarn.lock | 7981 ++++++++ .../packages/react-app/.eslintignore | 2 + .../packages/react-app/.eslintrc.json | 3 + InvestmentDAO/packages/react-app/.gitignore | 36 + InvestmentDAO/packages/react-app/README.md | 39 + .../react-app/assets/img/app-hero.png | Bin 0 -> 197123 bytes .../react-app/assets/img/guest-hero.png | Bin 0 -> 129593 bytes .../components/CreateProposalForm.tsx | 23 + .../react-app/components/DashboardHeader.tsx | 73 + .../react-app/components/DashboardLayout.tsx | 22 + .../packages/react-app/components/Footer.tsx | 49 + .../react-app/components/GuestHeader.tsx | 87 + .../react-app/components/GuestLayout.tsx | 22 + .../react-app/components/Proposals.tsx | 46 + .../react-app/components/Treasury.tsx | 0 .../packages/react-app/next.config.js | 33 + .../packages/react-app/package-lock.json | 16893 ++++++++++++++++ InvestmentDAO/packages/react-app/package.json | 38 + .../packages/react-app/pages/_app.tsx | 70 + .../packages/react-app/pages/api/hello.ts | 13 + .../packages/react-app/pages/app.tsx | 26 + .../packages/react-app/pages/index.tsx | 26 + .../packages/react-app/postcss.config.js | 6 + .../packages/react-app/public/favicon.ico | Bin 0 -> 44688 bytes .../packages/react-app/public/logo.svg | 17 + .../packages/react-app/rainbowkit-celo.d.ts | 27 + .../packages/react-app/styles/globals.css | 11 + .../packages/react-app/tailwind.config.js | 38 + .../packages/react-app/tsconfig.json | 25 + .../packages/react-app/utils/constants.js | 15 + .../packages/react-app/utils/helpers.js | 15 + .../packages/react-app/utils/index.js | 3 + .../packages/react-app/utils/interact.js | 172 + InvestmentDAO/packages/react-app/yarn.lock | 7802 +++++++ InvestmentDAO/yarn.lock | 16540 +++++++++++++++ 54 files changed, 51147 insertions(+) create mode 100644 InvestmentDAO/.gitattributes create mode 100644 InvestmentDAO/.gitignore create mode 100644 InvestmentDAO/LICENSE create mode 100644 InvestmentDAO/README.md create mode 100644 InvestmentDAO/netlify.toml create mode 100644 InvestmentDAO/package.json create mode 100644 InvestmentDAO/packages/hardhat/.envexample create mode 100644 InvestmentDAO/packages/hardhat/.gitignore create mode 100644 InvestmentDAO/packages/hardhat/.npmrc create mode 100644 InvestmentDAO/packages/hardhat/README.md create mode 100644 InvestmentDAO/packages/hardhat/account_keys.json create mode 100644 InvestmentDAO/packages/hardhat/contracts/DaoAnalyzer.sol create mode 100644 InvestmentDAO/packages/hardhat/contracts/Token.sol create mode 100644 InvestmentDAO/packages/hardhat/deploy/00-deploy.js create mode 100644 InvestmentDAO/packages/hardhat/hardhat.config.js create mode 100644 InvestmentDAO/packages/hardhat/package.json create mode 100644 InvestmentDAO/packages/hardhat/scripts/deploy.js create mode 100644 InvestmentDAO/packages/hardhat/scripts/watch.js create mode 100644 InvestmentDAO/packages/hardhat/test/auction-test.js create mode 100644 InvestmentDAO/packages/hardhat/yarn.lock create mode 100644 InvestmentDAO/packages/react-app/.eslintignore create mode 100644 InvestmentDAO/packages/react-app/.eslintrc.json create mode 100644 InvestmentDAO/packages/react-app/.gitignore create mode 100644 InvestmentDAO/packages/react-app/README.md create mode 100644 InvestmentDAO/packages/react-app/assets/img/app-hero.png create mode 100644 InvestmentDAO/packages/react-app/assets/img/guest-hero.png create mode 100644 InvestmentDAO/packages/react-app/components/CreateProposalForm.tsx create mode 100644 InvestmentDAO/packages/react-app/components/DashboardHeader.tsx create mode 100644 InvestmentDAO/packages/react-app/components/DashboardLayout.tsx create mode 100644 InvestmentDAO/packages/react-app/components/Footer.tsx create mode 100644 InvestmentDAO/packages/react-app/components/GuestHeader.tsx create mode 100644 InvestmentDAO/packages/react-app/components/GuestLayout.tsx create mode 100644 InvestmentDAO/packages/react-app/components/Proposals.tsx create mode 100644 InvestmentDAO/packages/react-app/components/Treasury.tsx create mode 100644 InvestmentDAO/packages/react-app/next.config.js create mode 100644 InvestmentDAO/packages/react-app/package-lock.json create mode 100644 InvestmentDAO/packages/react-app/package.json create mode 100644 InvestmentDAO/packages/react-app/pages/_app.tsx create mode 100644 InvestmentDAO/packages/react-app/pages/api/hello.ts create mode 100644 InvestmentDAO/packages/react-app/pages/app.tsx create mode 100644 InvestmentDAO/packages/react-app/pages/index.tsx create mode 100644 InvestmentDAO/packages/react-app/postcss.config.js create mode 100644 InvestmentDAO/packages/react-app/public/favicon.ico create mode 100755 InvestmentDAO/packages/react-app/public/logo.svg create mode 100644 InvestmentDAO/packages/react-app/rainbowkit-celo.d.ts create mode 100644 InvestmentDAO/packages/react-app/styles/globals.css create mode 100644 InvestmentDAO/packages/react-app/tailwind.config.js create mode 100644 InvestmentDAO/packages/react-app/tsconfig.json create mode 100644 InvestmentDAO/packages/react-app/utils/constants.js create mode 100644 InvestmentDAO/packages/react-app/utils/helpers.js create mode 100644 InvestmentDAO/packages/react-app/utils/index.js create mode 100644 InvestmentDAO/packages/react-app/utils/interact.js create mode 100644 InvestmentDAO/packages/react-app/yarn.lock create mode 100644 InvestmentDAO/yarn.lock diff --git a/InvestmentDAO/.gitattributes b/InvestmentDAO/.gitattributes new file mode 100644 index 00000000..dfe07704 --- /dev/null +++ b/InvestmentDAO/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/InvestmentDAO/.gitignore b/InvestmentDAO/.gitignore new file mode 100644 index 00000000..59e04893 --- /dev/null +++ b/InvestmentDAO/.gitignore @@ -0,0 +1,42 @@ +node_modules +.env +packages/*/.env +packages/*/.env.* + +# IntelliJ project files +*.iml +*.ipr +*.iws +.idea + +*.gitkeep + +# eclipse project file +.settings/ +.classpath +.project + +# NetBeans specific +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +nbactions.xml +nb-configuration.xml + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# OS +.DS_Store + +# Miscellaneous +*.class +*.log +*.pyc +*.swp + +PROPOSAL.md diff --git a/InvestmentDAO/LICENSE b/InvestmentDAO/LICENSE new file mode 100644 index 00000000..261eeb9e --- /dev/null +++ b/InvestmentDAO/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/InvestmentDAO/README.md b/InvestmentDAO/README.md new file mode 100644 index 00000000..911c9641 --- /dev/null +++ b/InvestmentDAO/README.md @@ -0,0 +1,43 @@ +# Investment DAO + +## Description +DAOalyzer is a data visualization platform that aggregates and displays key metrics of investment activity within an investment DAO. The platform will be designed to provide value to both existing and potential investors in the DAO, and enable them to make informed decisions about their investments. + +‌ + +Features: + +Real-time visualization: The platform will display investment data and key performance metrics in real-time. This will include data on assets invested, performance of those assets, investment strategies employed, and more. + +Customizable dashboard: The platform will allow users to customize their dashboard to display only the metrics that matter most to them. + +Historical data: Users can also view historical data on investment activity. This can be used to track the performance of investments over time and make better-informed investment decisions. + +Comparison features: The platform will allow users to compare the performance of various assets and investment strategies within the DAO. This can help investors understand which investments are performing best and why. + +Investment functionality: The platform will enable investors to make investments in the DAO directly from the platform. + + + +## Requirements + +- [Remix](https://remix.ethereum.org/) - Online editor for writing smart contracts or any code editor you choose. +- [Metamask](https://metamask.io/) - For managing our wallet. +- [Hardhat](https://hardhat.org/) - For compiling and deploying the smart contract +- [Alfajores Testnet Account](https://developers.celo.org/3-simple-steps-to-connect-your-metamask-wallet-to-celo-732d4a139587) - Required to connect to the dApp and make test transactions. +- [Node.js](https://nodejs.org/en/) - From V12. or higher +- [Celo Composer](https://github.com/celo-org/celo-composer) - For quick web3 project scaffolding +- [Open Zeppelin Defender Account](https://defender.openzeppelin.com/) — You need an account with Open Zeppelin for automating on-chain data. + +## Installation + +```js +npm install +``` + +## Start + +```js +npm run dev +``` + diff --git a/InvestmentDAO/netlify.toml b/InvestmentDAO/netlify.toml new file mode 100644 index 00000000..d14bf083 --- /dev/null +++ b/InvestmentDAO/netlify.toml @@ -0,0 +1,12 @@ +# Settings in the [build] context are global and are applied to +# all contexts unless otherwise overridden by more specific contexts. +[build] + # Directory to change to before starting a build. + # This is where we will look for package.json/.nvmrc/etc. + # If not set, defaults to the root directory. + base = "/" + publish = "packages/react-app/.next" + command = "yarn build-ui" + +[[plugins]] +package = "@netlify/plugin-nextjs" \ No newline at end of file diff --git a/InvestmentDAO/package.json b/InvestmentDAO/package.json new file mode 100644 index 00000000..ec2d6308 --- /dev/null +++ b/InvestmentDAO/package.json @@ -0,0 +1,40 @@ +{ + "name": "doa-app", + "version": "1.0.0", + "description": "Custom Celo Composer project.", + "private": true, + "author": "Celo", + "license": "MIT", + "scripts": { + "react-app:dev": "yarn workspace @doa-app/react-app dev", + "react-app:build": "yarn workspace @doa-app/react-app build", + "react-app:start": "yarn workspace @doa-app/react-app start", + "react-app:lint": "yarn workspace @doa-app/react-app lint", + "hardhat:test": "yarn workspace @doa-app/hardhat test", + "hardhat:test-local": "yarn workspace @doa-app/hardhat test-local", + "hardhat:accounts": "yarn workspace @doa-app/hardhat accounts", + "hardhat:devchain": "yarn workspace @doa-app/hardhat devchain", + "hardhat:deploy": "yarn workspace @doa-app/hardhat deploy", + "hardhat:deploy-reset-watch": "yarn workspace @doa-app/hardhat deploy-reset-watch", + "hardhat:watch": "yarn workspace @doa-app/hardhat watch", + "hardhat:fork-mainnet": "yarn workspace @doa-app/hardhat fork-mainnet" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/celo-org/celo-composer.git" + }, + "bugs": { + "url": "https://github.com/celo-org/celo-composer/issues" + }, + "homepage": "https://github.com/celo-org/celo-composer/blob/main/README.md", + "workspaces": [ + "packages/*" + ], + "keywords": [ + "celo-composer", + "celo" + ], + "dependencies": { + "web3": "^1.9.0" + } +} diff --git a/InvestmentDAO/packages/hardhat/.envexample b/InvestmentDAO/packages/hardhat/.envexample new file mode 100644 index 00000000..389ae223 --- /dev/null +++ b/InvestmentDAO/packages/hardhat/.envexample @@ -0,0 +1,3 @@ +MNEMONIC="" +PRIVATE_KEY="" +CELOSCAN_API_KEY="" \ No newline at end of file diff --git a/InvestmentDAO/packages/hardhat/.gitignore b/InvestmentDAO/packages/hardhat/.gitignore new file mode 100644 index 00000000..d03cbbaf --- /dev/null +++ b/InvestmentDAO/packages/hardhat/.gitignore @@ -0,0 +1,14 @@ +node_modules +.env +.idea +coverage +coverage.json +typechain + +#Hardhat files +cache +artifacts +deployments + +# hardhat typechain generated files +types/ diff --git a/InvestmentDAO/packages/hardhat/.npmrc b/InvestmentDAO/packages/hardhat/.npmrc new file mode 100644 index 00000000..4fd02195 --- /dev/null +++ b/InvestmentDAO/packages/hardhat/.npmrc @@ -0,0 +1 @@ +engine-strict=true \ No newline at end of file diff --git a/InvestmentDAO/packages/hardhat/README.md b/InvestmentDAO/packages/hardhat/README.md new file mode 100644 index 00000000..c0a0adef --- /dev/null +++ b/InvestmentDAO/packages/hardhat/README.md @@ -0,0 +1,124 @@ +# Hardhat | Celo Composer + +This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts. + +## Setup & Installation + +### Alfajores Testnet Setup + +**Note** This setup is not required when using a local development blockchain (like celo-devchain or Ganache). + +1. Create a `.env` file similar to `.envexample`. +2. Paste the private key in `.env`. +> note: depending on how you generate your private key, you may have to prepend `0x` in the private key does not already have it prepended. +3. Faucet your account with the Alfajores testnet faucet [here](https://celo.org/developers/faucet). + +## Develop + +1. Write your contracts in `./contracts`. +2. Update contract deployment scripts in `./deploy`. +3. Deploy contracts with `yarn deploy` from the **root directory**. Optionally add the reset flag (`yarn deploy --reset`) to overwrite previous deployment info. The default deployment network is specified in `hardhat.config.js` and is set to `alfajores` initially. You can also overwrite previous deployments and redeploy when there are changes to the deployment script or contracts automatically by running `yarn deploy-reset-watch`. You can specify a specific network deployment directly with + +```bash +npx hardhat deploy --network [network name] +``` + +Network configs are defined in `hardhat.config.js`. + +## [Celo devchain](https://github.com/terminal-fi/celo-devchain) + +Run a local development Celo chain with `yarn devchain` in the `packages/hardhat` folder. You can print the addresses of the [Celo protocol contracts](https://github.com/celo-org/celo-monorepo/tree/master/packages/protocol) with `npx @terminal-fi/celo-devchain --test`. + +This is a version of Ganache (@celo/ganache-cli) that deploys the Celo core protocol contracts when it starts. + +**NOTE:** @celo/ganache-cli works only with Node 10 or Node 12 versions. Using Node 14 or later will result in errors. + +**NOTE:** @celo/ganache-cli currently doesn't support locally signed transactions. If you send a locally signed transaction it will throw: Error: Number can only safely store up to 53 bits error and crash. Thus you have to make sure your ContractKit doesn't actually have the private keys for test addresses and send transactions to be signed by ganache-cli itself. + +### Start + +```bash +npx celo-devchain --port 8545 +``` + +or + +```bash +yarn devchain +``` + +### Generate Typescript bindings + +This setting defaults to the web3 v1 bindings because that is what is used by use-contractkit in `packages/react-app`. + +You can change the output directory and target in `hardhat.config.js`. + +```bash +npx hardhat typechain +``` + +Read more about Typechain [here](https://github.com/dethcrypto/TypeChain) and more about the hardhat plugin [here](https://github.com/dethcrypto/TypeChain/tree/master/packages/hardhat). + +### Run sanity tests and print all core contract addresses + +```bash +npx @terminal-fi/celo-devchain --test +``` + +## Fork mainnet with [Ganache](https://trufflesuite.com/blog/introducing-ganache-7/index.html#1-zero-config-mainnet-forking) + +You can get a local copy of mainnet by forking with Ganache. Learn more about [forking mainnet with Ganache here.](https://trufflesuite.com/blog/introducing-ganache-7/index.html#1-zero-config-mainnet-forking) + +There is a script provided (`yarn fork-mainnet`) to fork mainnet and fund the same test accounts that come with Celo devchain. Sometimes sending transactions from the first account (which defaults to `0x5409ED021D9299bf6814279A6A1411A7e866A631`) is delayed and sending test transactions from the other accounts works better for some reason. :shrug: The private keys of the associated test accounts are printed in `account_keys.json`. + +## Verify your contracts + +### hardhat-celo + +You can easily verify your contracts deployed to the associated networks with hardhat-celo. + +[Reference](https://docs.celo.org/developer/verify/hardhat) + +```bash +npx hardhat verify smart-contract-address parameter(s) --network alfajores +``` + +On Mainnet: + +```bash +npx hardhat verify smart-contract-address parameter(s) --network celo +``` + +### Sourcify + +Additionally, you can easily verify your contracts deployed to the associated networks with the following commands. + +[Reference](https://docs.celo.org/blog/hardhat-deploy-verify) + +On Alfajores: + +```bash +npx hardhat --network alfajores sourcify +``` + +On Mainnet: + +```bash +npx hardhat --network celo sourcify +``` + +## Deploy with [Figment Datahub](https://datahub.figment.io/) + +Figment Datahub provides RPC & REST APIs for Celo network. To learn more about Datahub refer this doc - [https://docs.figment.io/introduction/what-is-datahub](https://docs.figment.io/introduction/what-is-datahub). Follow these steps to deploy your smart contract with Figment datahub's RPC. + +- Create account on [Datahub](https://datahub.figment.io/). +- On the dashboard, click on `Create new app` and select **Celo** from the protocol list. +- Once you have created an app, copy the api key. +- Edit `hardhat.config.js` and update `alfajoresDatahub` and `celoDatahub` with the API Key. +- Run the test or deploy the contract with following commands. + +```bash +npx hardhat run scripts/run.ts --network alfajoresDatahub + +npx hardhat run scripts/deploy.ts --network celoDatahub +``` diff --git a/InvestmentDAO/packages/hardhat/account_keys.json b/InvestmentDAO/packages/hardhat/account_keys.json new file mode 100644 index 00000000..03627dd9 --- /dev/null +++ b/InvestmentDAO/packages/hardhat/account_keys.json @@ -0,0 +1 @@ +{"addresses":{"0x5409ed021d9299bf6814279a6a1411a7e866a631":"0x5409ed021d9299bf6814279a6a1411a7e866a631","0x6ecbe1db9ef729cbe972c83fb886247691fb6beb":"0x6ecbe1db9ef729cbe972c83fb886247691fb6beb","0xe36ea790bc9d7ab70c55260c66d52b1eca985f84":"0xe36ea790bc9d7ab70c55260c66d52b1eca985f84","0xe834ec434daba538cd1b9fe1582052b880bd7e63":"0xe834ec434daba538cd1b9fe1582052b880bd7e63","0x78dc5d2d739606d31509c31d654056a45185ecb6":"0x78dc5d2d739606d31509c31d654056a45185ecb6","0xa8dda8d7f5310e4a9e24f8eba77e091ac264f872":"0xa8dda8d7f5310e4a9e24f8eba77e091ac264f872","0x06cef8e666768cc40cc78cf93d9611019ddcb628":"0x06cef8e666768cc40cc78cf93d9611019ddcb628","0x4404ac8bd8f9618d27ad2f1485aa1b2cfd82482d":"0x4404ac8bd8f9618d27ad2f1485aa1b2cfd82482d","0x7457d5e02197480db681d3fdf256c7aca21bdc12":"0x7457d5e02197480db681d3fdf256c7aca21bdc12","0x91c987bf62d25945db517bdaa840a6c661374402":"0x91c987bf62d25945db517bdaa840a6c661374402"},"private_keys":{"0x5409ed021d9299bf6814279a6a1411a7e866a631":"0xf2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e0164837257d","0x6ecbe1db9ef729cbe972c83fb886247691fb6beb":"0x5d862464fe9303452126c8bc94274b8c5f9874cbd219789b3eb2128075a76f72","0xe36ea790bc9d7ab70c55260c66d52b1eca985f84":"0xdf02719c4df8b9b8ac7f551fcb5d9ef48fa27eef7a66453879f4d8fdc6e78fb1","0xe834ec434daba538cd1b9fe1582052b880bd7e63":"0xff12e391b79415e941a94de3bf3a9aee577aed0731e297d5cfa0b8a1e02fa1d0","0x78dc5d2d739606d31509c31d654056a45185ecb6":"0x752dd9cf65e68cfaba7d60225cbdbc1f4729dd5e5507def72815ed0d8abc6249","0xa8dda8d7f5310e4a9e24f8eba77e091ac264f872":"0xefb595a0178eb79a8df953f87c5148402a224cdf725e88c0146727c6aceadccd","0x06cef8e666768cc40cc78cf93d9611019ddcb628":"0x83c6d2cc5ddcf9711a6d59b417dc20eb48afd58d45290099e5987e3d768f328f","0x4404ac8bd8f9618d27ad2f1485aa1b2cfd82482d":"0xbb2d3f7c9583780a7d3904a2f55d792707c345f21de1bacb2d389934d82796b2","0x7457d5e02197480db681d3fdf256c7aca21bdc12":"0xb2fd4d29c1390b71b8795ae81196bfd60293adf99f9d32a0aff06288fcdac55f","0x91c987bf62d25945db517bdaa840a6c661374402":"0x23cb7121166b9a2f93ae0b7c05bde02eae50d64449b2cbb42bc84e9d38d6cc89"}} \ No newline at end of file diff --git a/InvestmentDAO/packages/hardhat/contracts/DaoAnalyzer.sol b/InvestmentDAO/packages/hardhat/contracts/DaoAnalyzer.sol new file mode 100644 index 00000000..0d3b61d5 --- /dev/null +++ b/InvestmentDAO/packages/hardhat/contracts/DaoAnalyzer.sol @@ -0,0 +1,142 @@ + +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; + +contract DaoAnalyzer { + + IERC20 public token; + + uint256 public proposalCount; + uint256 public votingThreshold; + uint256 public proposalThreshold; + Member[] public members; + Proposal[] public proposals; + Voter[] public voters; + + mapping(address => Member) public membersMap; + mapping(address => mapping(uint256 => bool)) hasVoted; + + struct Member { + address memberAddress; + uint256 tokenBalance; + } + + struct Proposal { + address creator; + string title; + string description; + uint256 yesVotes; + uint256 noVotes; + bool executed; + uint256 start; + uint256 end; + } + + struct Voter { + uint256 proposalIndex; + address voterAddress; + bool inSupport; + } + + event ProposalCreated(uint proposalId, address creator, string description); + event Voted(uint proposalId, address voter, bool inSupport); + event ProposalExecuted(uint proposalId, address executor); + event AddMember(address memberAddress, uint256 tokenBalance); + + constructor(address _tokenAddress) { + token = IERC20(_tokenAddress); + votingThreshold = 50; + proposalThreshold = 100; + } + + function joinDao() public { + require(msg.sender != address(0), "Invalid address"); + + // Check if member already exists + require(membersMap[msg.sender].memberAddress == address(0), "Already a member"); + + // Add new member + Member storage member = membersMap[msg.sender]; + member.memberAddress = msg.sender; + member.tokenBalance = token.balanceOf(msg.sender); + members.push(Member(msg.sender, token.balanceOf(msg.sender))); + + emit AddMember(msg.sender, token.balanceOf(msg.sender)); + } + + function createProposal(string memory _title, string memory _description, uint256 _start, uint256 _end) public { + + require(_start > block.timestamp, "Proposal start time must be in the future"); + require(_end > _start, "Proposal end time must be after start time"); + require(membersMap[msg.sender].memberAddress == msg.sender, "You are not yet a member of this community"); + require(token.balanceOf(msg.sender) >= proposalThreshold , "Did not meet proposal threshold"); + + proposals.push(Proposal(msg.sender, _title, _description, 0, 0, false, _start, _end)); + + proposalCount++; + + emit ProposalCreated(proposalCount, msg.sender, _description); + } + + function getProposal(uint256 _index) public view returns(address, string memory, string memory, uint, uint, bool, uint256, uint256) { + + Proposal storage proposal = proposals[_index]; + + return ( + proposal.creator, + proposal.title, + proposal.description, + proposal.yesVotes, + proposal.noVotes, + proposal.executed, + proposal.start, + proposal.end + ); + } + + function getAllProposals() public view returns(Proposal[] memory){ + return proposals; + } + + function getMembers() public view returns(Member[] memory){ + return members; + } + + + function vote(uint _proposalId, bool _inSupport) public { + Proposal storage proposal = proposals[_proposalId]; + + require(proposal.creator != address(0), "Proposal does not exist"); + require(!proposal.executed, "Proposal has already been executed"); + require(!hasVoted[msg.sender][_proposalId], "You have already voted for this proposal"); + + if (_inSupport) { + proposal.yesVotes++; + } else { + proposal.noVotes++; + } + + voters.push(Voter(_proposalId, msg.sender, _inSupport)); + hasVoted[msg.sender][_proposalId] = true; + emit Voted(_proposalId, msg.sender, _inSupport); + } + + function executeProposal(uint _proposalId) public { + Proposal storage proposal = proposals[_proposalId]; + require(proposal.creator != address(0), "Proposal does not exist"); + require(!proposal.executed, "Proposal has already been executed"); + + uint totalVotes = proposal.yesVotes + proposal.noVotes; + require(totalVotes > 0, "No votes cast for the proposal"); + + require(proposal.yesVotes > proposal.noVotes, "Proposal did not pass"); + + proposal.executed = true; + + emit ProposalExecuted(_proposalId, msg.sender); + } + + function memberBalance(address _memberAddress) private view returns(uint256) { + return token.balanceOf(_memberAddress); + } + +} \ No newline at end of file diff --git a/InvestmentDAO/packages/hardhat/contracts/Token.sol b/InvestmentDAO/packages/hardhat/contracts/Token.sol new file mode 100644 index 00000000..4e255447 --- /dev/null +++ b/InvestmentDAO/packages/hardhat/contracts/Token.sol @@ -0,0 +1,71 @@ +// SPDX-License-Identifier:GPL-3.0 + +pragma solidity ^0.8.0; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; + +contract Token is IERC20 { + + string public name; + string public symbol; + uint8 public decimals; + uint256 private _totalSupply; + + mapping(address => uint256) private _balances; + mapping(address => mapping(address => uint256)) private _allowances; + + constructor() { + _totalSupply = 200000000000000000000000; + _balances[msg.sender] = _totalSupply; + name = "InvestmentToken"; + symbol = "IT"; + decimals = 18; + + emit Transfer(address(0), msg.sender, _totalSupply); + } + + function totalSupply() public view override returns (uint256) { + return _totalSupply; + } + + function balanceOf(address account) public view override returns (uint256) { + return _balances[account]; + } + + function transfer(address recipient, uint256 amount) public override returns (bool) { + require(recipient != address(0), "ERC20: transfer to the zero address"); + require(_balances[msg.sender] >= amount, "ERC20: transfer amount exceeds balance"); + + _balances[msg.sender] -= amount; + _balances[recipient] += amount; + + emit Transfer(msg.sender, recipient, amount); + + return true; + } + + function allowance(address owner, address spender) public view override returns (uint256) { + return _allowances[owner][spender]; + } + + function approve(address spender, uint256 amount) public override returns (bool) { + _allowances[msg.sender][spender] = amount; + + emit Approval(msg.sender, spender, amount); + + return true; + } + + function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { + require(recipient != address(0), "ERC20: transfer to the zero address"); + require(_balances[sender] >= amount, "ERC20: transfer amount exceeds balance"); + require(_allowances[sender][msg.sender] >= amount, "ERC20: transfer amount exceeds allowance"); + + _balances[sender] -= amount; + _balances[recipient] += amount; + _allowances[sender][msg.sender] -= amount; + + emit Transfer(sender, recipient, amount); + + return true; + } +} \ No newline at end of file diff --git a/InvestmentDAO/packages/hardhat/deploy/00-deploy.js b/InvestmentDAO/packages/hardhat/deploy/00-deploy.js new file mode 100644 index 00000000..c3bd49aa --- /dev/null +++ b/InvestmentDAO/packages/hardhat/deploy/00-deploy.js @@ -0,0 +1,64 @@ +// deploy/00_deploy_my_contract.js + +// const { ethers } = require("hardhat"); + +// const sleep = (ms) => +// new Promise((r) => +// setTimeout(() => { +// console.log(`waited for ${(ms / 1000).toFixed(3)} seconds`); +// r(); +// }, ms) +// ); + +module.exports = async ({ getNamedAccounts, deployments }) => { + const { deploy } = deployments; + const { deployer } = await getNamedAccounts(); + + + + const res = await deploy("Token", { + // Learn more about args here: https://www.npmjs.com/package/hardhat-deploy#deploymentsdeploy + from: deployer, + //args: [ "Hello", ethers.utils.parseEther("1.5") ], + log: true, + }); + + await deploy("DaoAnalyzer", { + from: deployer, + args: [res.address], + log: true, + }); + + + // Getting a previously deployed contract + // const Greeter = new ethers.Contract("Greeter", deployer); + + // await Greeter.setGreeting("Hello Celo!"); + + /* + // If you want to send value to an address from the deployer + + const deployerWallet = ethers.provider.getSigner() + await deployerWallet.sendTransaction({ + to: "0x34aA3F359A9D614239015126635CE7732c18fDF3", + value: ethers.utils.parseEther("0.001") + }) + */ + + /* + //If you want to send some CELO to a contract on deploy (make your constructor payable!) + const yourContract = await deploy("YourContract", [], { + value: ethers.utils.parseEther("0.05") + }); + */ + + /* + //If you want to link a library into your contract: + // reference: https://github.com/austintgriffith/scaffold-eth/blob/using-libraries-example/packages/hardhat/scripts/deploy.js#L19 + const yourContract = await deploy("YourContract", [], {}, { + LibraryName: **LibraryAddress** + }); + */ +}; + +module.exports.tags = ["DaoAnalyzer", "Token"]; diff --git a/InvestmentDAO/packages/hardhat/hardhat.config.js b/InvestmentDAO/packages/hardhat/hardhat.config.js new file mode 100644 index 00000000..a9627e55 --- /dev/null +++ b/InvestmentDAO/packages/hardhat/hardhat.config.js @@ -0,0 +1,98 @@ +require("@nomicfoundation/hardhat-chai-matchers"); +require("dotenv").config({ path: ".env" }); +require("hardhat-deploy"); +const { task } = require("hardhat/config"); +require("@nomiclabs/hardhat-ethers"); +require("@typechain/hardhat"); +require("hardhat-celo"); + +const defaultNetwork = "alfajores"; +const mnemonicPath = "m/44'/52752'/0'/0"; // derivation path used by Celo + +// This is the mnemonic used by celo-devchain +const DEVCHAIN_MNEMONIC = + "concert load couple harbor equip island argue ramp clarify fence smart topic"; + +// You need to export an object to set up your config +// Go to https://hardhat.org/config/ to learn more + +/** + * @type import('hardhat/config').HardhatUserConfig + */ +module.exports = { + defaultNetwork, + networks: { + localhost: { + url: "http://127.0.0.1:8545", + accounts: { + mnemonic: DEVCHAIN_MNEMONIC, + }, + }, + alfajores: { + url: "https://alfajores-forno.celo-testnet.org", + accounts: [process.env.PRIVATE_KEY], + chainId: 44787, + }, + celo: { + url: "https://forno.celo.org", + accounts: [process.env.PRIVATE_KEY], + chainId: 42220, + }, + }, + etherscan: { + apiKey: { + alfajores: process.env.CELOSCAN_API_KEY, + celo: process.env.CELOSCAN_API_KEY, + }, + }, + solidity: { + version: "0.8.17", + }, + namedAccounts: { + deployer: 0, + }, + typechain: { + outDir: "types", + target: "web3-v1", + alwaysGenerateOverloads: false, // should overloads with full signatures like deposit(uint256) be generated always, even if there are no overloads? + externalArtifacts: ["externalArtifacts/*.json"], // optional array of glob patterns with external artifacts to process (for example external libs from node_modules) + }, +}; + +// This is a sample Hardhat task. To learn how to create your own go to +// https://hardhat.org/guides/create-task.html + +task("accounts", "Prints the list of accounts", async (taskArgs, hre) => { + const accounts = await hre.ethers.getSigners(); + + for (const account of accounts) { + console.log(account.address); + } +}); + +task( + "devchain-keys", + "Prints the private keys associated with the devchain", + async (taskArgs, hre) => { + const accounts = await hre.ethers.getSigners(); + const hdNode = hre.ethers.utils.HDNode.fromMnemonic(DEVCHAIN_MNEMONIC); + for (let i = 0; i < accounts.length; i++) { + const account = hdNode.derivePath(`m/44'/60'/0'/0/${i}`); + console.log( + `Account ${i}\nAddress: ${account.address}\nKey: ${account.privateKey}` + ); + } + } +); + +task("create-account", "Prints a new private key", async (taskArgs, hre) => { + const wallet = new hre.ethers.Wallet.createRandom(); + console.log(`PRIVATE_KEY="` + wallet.privateKey + `"`); + console.log(); + console.log(`Your account address: `, wallet.address); +}); + +task("print-account", "Prints the address of the account", () => { + const wallet = new hre.ethers.Wallet(process.env.PRIVATE_KEY); + console.log(`Account: `, wallet.address); +}); diff --git a/InvestmentDAO/packages/hardhat/package.json b/InvestmentDAO/packages/hardhat/package.json new file mode 100644 index 00000000..cf9f082b --- /dev/null +++ b/InvestmentDAO/packages/hardhat/package.json @@ -0,0 +1,52 @@ +{ + "name": "@doa-app/hardhat", + "version": "1.0.0", + "license": "MIT", + "scripts": { + "test": "hardhat test", + "test-local": "hardhat test --network hardhat", + "accounts": "hardhat accounts", + "devchain": "npx celo-devchain --port 8545", + "deploy": "hardhat deploy --export-all deployments/hardhat_contracts.json", + "deploy-reset-watch": "hardhat deploy --reset --watch --export-all deployments/hardhat_contracts.json", + "watch": "node scripts/watch.js", + "fork-mainnet": "ganache --fork.url https://forno.celo.org --wallet.mnemonic 'concert load couple harbor equip island argue ramp clarify fence smart topic' --wallet.accountKeysPath './account_keys.json' --gasPrice 875000000" + }, + "devDependencies": { + "@nomicfoundation/hardhat-chai-matchers": "^1.0.0", + "@nomicfoundation/hardhat-network-helpers": "^1.0.0", + "@nomiclabs/hardhat-ethers": "^2.2.1", + "@nomiclabs/hardhat-etherscan": "^3.0.0", + "@terminal-fi/celo-devchain": "^4.0.1", + "@typechain/ethers-v5": "^10.1.0", + "@typechain/hardhat": "^6.1.3", + "@typechain/web3-v1": "^6.0.1", + "@types/mocha": "^9.1.0", + "bip39": "^3.0.4", + "chai": "^4.3.6", + "dotenv": "^16.0.3", + "ethereumjs-util": "^7.1.5", + "ethereumjs-wallet": "^1.0.2", + "ethers": "^5.7.2", + "hardhat": "^2.12.1", + "hardhat-celo": "^0.0.3", + "hardhat-deploy": "^0.11.19", + "hardhat-gas-reporter": "^1.0.8", + "node-watch": "^0.7.3", + "solidity-coverage": "^0.7.21", + "ts-node": ">=8.0.0", + "typechain": "^8.1.0" + }, + "dependencies": { + "@ethersproject/abi": "^5.7.0", + "@ethersproject/bytes": "^5.7.0", + "@ethersproject/providers": "^5.7.2", + "@redstone-finance/evm-connector": "^0.0.15", + "ganache": "^7.5.0", + "source-map-support": "^0.5.21", + "typescript": "^4.8.4", + "web3": "^1.8.0", + "web3-core": "^1.8.0", + "web3-eth-contract": "^1.8.0" + } +} diff --git a/InvestmentDAO/packages/hardhat/scripts/deploy.js b/InvestmentDAO/packages/hardhat/scripts/deploy.js new file mode 100644 index 00000000..e16f72a0 --- /dev/null +++ b/InvestmentDAO/packages/hardhat/scripts/deploy.js @@ -0,0 +1,32 @@ +// We require the Hardhat Runtime Environment explicitly here. This is optional +// but useful for running the script in a standalone fashion through `node