├── LICENSE ├── README.md └── src ├── .gitignore ├── DAOConfig.json ├── DAOConfigCodegen ├── DAOConfigCodegen.ts ├── configParser.ts └── configToSolidity.ts ├── README.md ├── contracts ├── DAOConfig.sol ├── DAOConfigSample.sol ├── FastDAO.sol ├── Greeter.sol ├── StockManager.sol └── safeMath.sol ├── hardhat.config.ts ├── package-lock.json ├── package.json ├── scripts └── dummyScript.ts ├── test └── fastDAOUnitTest.ts └── tsconfig.json /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fastDAO 2 | A fast decentralized autonomous organization(DAO) framework on Ethereum 3 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | coverage 4 | coverage.json 5 | typechain 6 | 7 | #Hardhat files 8 | cache 9 | artifacts 10 | -------------------------------------------------------------------------------- /src/DAOConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "fastDAOVersion":"1", 3 | "fastDAOName":"fastDAO", 4 | "fastDAOAddress":"0x0000000000000000000000000000000000000000" 5 | } -------------------------------------------------------------------------------- /src/DAOConfigCodegen/DAOConfigCodegen.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import * as hre from 'hardhat'; 3 | import { configParser } from './configParser'; 4 | import { configToSolidity } from './configToSolidity'; 5 | 6 | /* 7 | * This is the main function of DAO Configuration Codegenerator. 8 | */ 9 | 10 | function generatedDAOConfig() :string{ 11 | 12 | let DAOConfigJSON = configParser(); 13 | const strDAOConfigurationCode = configToSolidity(DAOConfigJSON); 14 | return strDAOConfigurationCode; 15 | } 16 | 17 | 18 | 19 | /* 20 | * Get the DAO configuration solidity source code's file name. 21 | */ 22 | 23 | function getDAOConfigFileName() :string { 24 | return "DAOConfig.sol"; 25 | } 26 | 27 | /* 28 | */ 29 | function getDAOConfigPath() :string { 30 | return ".//contracts//" + getDAOConfigFileName(); 31 | } 32 | 33 | 34 | 35 | /* 36 | * This is the main entry point for the codegen. 37 | */ 38 | 39 | async function DAOConfigCodegen() { 40 | console.log("Starting for DAO Configuration Codegenerator..."); 41 | 42 | 43 | try{ 44 | 45 | // Write the DAO configuration solidity source code to the file. 46 | fs.writeFile(getDAOConfigPath(), generatedDAOConfig(), err => { 47 | if (err) { 48 | console.error(err); 49 | return; 50 | } 51 | console.log("The file was saved!") 52 | }); 53 | } 54 | catch(err) { 55 | console.error(err) 56 | } 57 | 58 | // After the DAO configuration solidity source code is generated, we can run the compile task. 59 | await hre.run("compile").then(() => { 60 | console.log("Compilation finished after DAO configuration generated!"); 61 | }).catch((err) => { 62 | console.log("Compilation failed after DAO configuration generated!"); 63 | console.error(err); 64 | }); 65 | } 66 | 67 | 68 | /* 69 | * Call the main function. 70 | */ 71 | DAOConfigCodegen(); 72 | 73 | export { 74 | generatedDAOConfig, 75 | DAOConfigCodegen 76 | }; -------------------------------------------------------------------------------- /src/DAOConfigCodegen/configParser.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * Read the DAOConfig.json file, parse the JSON data and export as a JSON object. 5 | */ 6 | 7 | 8 | import fs from "fs"; 9 | function readDAOConfigJSONFile():JSON { 10 | return JSON.parse(fs.readFileSync(getDAOConfigJSONFileName(), "utf8")); 11 | } 12 | 13 | 14 | /* 15 | * Get the DAO configuration json file name. 16 | */ 17 | function getDAOConfigJSONFileName() { 18 | return "DAOConfig.json"; 19 | } 20 | 21 | /* 22 | * Validate the DAO configuration json file and check 23 | if the required fields are present. 24 | */ 25 | function validateDAOConfigJSONstructure(DAOConfigJSON: JSON){ 26 | console.log(DAOConfigJSON); 27 | /* 28 | for (const x in DAOConfigJSON) { 29 | if (DAOConfigJSON.hasOwnProperty(x)) { 30 | const element = DAOConfigJSON[x]; 31 | if (element === null || element === undefined) { 32 | throw new Error("DAOConfigJSON: " + x + " is missing!"); 33 | } 34 | } 35 | } 36 | */ 37 | } 38 | 39 | /* 40 | * The core function of the DAO configuration JSON file parser 41 | */ 42 | function configParser():JSON { 43 | const DAOConfigJSON = readDAOConfigJSONFile(); 44 | validateDAOConfigJSONstructure(DAOConfigJSON); 45 | return DAOConfigJSON; 46 | } 47 | 48 | 49 | export { 50 | configParser 51 | } -------------------------------------------------------------------------------- /src/DAOConfigCodegen/configToSolidity.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * The core function to generate the DAO configuration solidity source code from ConfigJSON. 3 | */ 4 | function configToSolidity(DAOConfigJSON: JSON):string { 5 | let strDAOConfigurationCode = ""; 6 | strDAOConfigurationCode += generateHdeader(); 7 | strDAOConfigurationCode += generateTail(); 8 | return strDAOConfigurationCode; 9 | } 10 | 11 | 12 | /* 13 | * Generate the solidity header. 14 | */ 15 | function generateHdeader() { 16 | const strHeader = "pragma solidity >=0.8.9;\n\ncontract DAOConfig{\n\n"; 17 | return strHeader; 18 | } 19 | 20 | /* 21 | * Generate the solidity tail. 22 | */ 23 | function generateTail() { 24 | const strTail = "\n\n}\n"; 25 | return strTail; 26 | } 27 | 28 | 29 | export{ 30 | configToSolidity 31 | } -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | # Basic Sample Hardhat Project 2 | 3 | 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. 4 | 5 | Try running some of the following tasks: 6 | 7 | ```shell 8 | npx hardhat accounts 9 | npx hardhat compile 10 | npx hardhat clean 11 | npx hardhat test 12 | npx hardhat node 13 | node scripts/sample-script.js 14 | npx hardhat help 15 | ``` 16 | -------------------------------------------------------------------------------- /src/contracts/DAOConfig.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.8.9; 2 | 3 | contract DAOConfig{ 4 | 5 | 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/contracts/DAOConfigSample.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: UNLICENSED 2 | pragma solidity >=0.8.9; 3 | 4 | contract DAOConfig { 5 | 6 | /* 7 | * stock owner is the owner of the stock 8 | */ 9 | struct structStockOwner { 10 | address ownerAddress; 11 | uint256 stockOnwerIndex; 12 | string ownerName; 13 | string emailAddress; 14 | string website; 15 | } 16 | 17 | 18 | /* 19 | * stock is the stock that is being traded 20 | */ 21 | struct StockProperty { 22 | string stockName; 23 | string stockSymbol; 24 | uint256 stockIndex; 25 | uint256 stockTotalSupply; 26 | uint256 stockVoteWeight; 27 | uint256 stockDividendWeight; 28 | uint256 stockTransactionCooldown; 29 | bool isStockDilutable; 30 | bool isStockMintable; 31 | bool isStockBurnable; 32 | bool isStockTransferable; 33 | uint256 stockMaximumSupply; 34 | } 35 | 36 | /* 37 | * basic information about the DAO 38 | */ 39 | uint256 constant fastDAOVersion = 1; 40 | string constant fastDAOName = "FastDAO"; 41 | string constant fastDAODescription = "A DAO for the Ethereum blockchain"; 42 | string constant fastDAOWebsite = "http://foo.bar"; 43 | string constant fastDAOEmail = "fast@dao.com"; 44 | string constant fastDAOLogoURL = "http://foo.bar/logo.png"; 45 | 46 | 47 | /* 48 | stock owner information 49 | */ 50 | string[] public stockOwnerNames = ["Peter Wang","Julia Smiths"]; 51 | uint256[] public stockOwnerIndexes = [1,2]; 52 | address[] public stockOwnerAddresses = [ 53 | 0x0000000000000000000000000000000000000000, 54 | 0x0000000000000000000000000000000000000000 55 | ]; 56 | string[] public stockOwnerEmailAddresses = ["peter@gmail.com","julia@gmail.com"]; 57 | string[] public stockOwnerWebsites = ["www.peter.com","www.julia.com"]; 58 | uint256 public stockOwnerCount = 2; 59 | 60 | /* 61 | stock information 62 | */ 63 | string[] public stockNames = ["FastDao Inc. Stock Type 1","FastDao Inc. Stock Type 2"]; 64 | string[] public stockSymbols = ["FDST1","FDST2"]; 65 | uint256[] public stockIndices = [1,2]; 66 | uint256[] public stockTotalSupplies = [100,1000]; 67 | uint256[] public stockVoteWeights = [100,1]; 68 | uint256[] public stockDividendWeights = [10,1]; 69 | uint256[] public stockTransactionCooldowns = [1,1]; 70 | bool[] public stockIsDilutable = [true,true]; 71 | bool[] public stockIsMintable = [true,true]; 72 | bool[] public stockIsBurnable = [true,true]; 73 | bool[] public stockIsTransferable = [true,true]; 74 | uint256[] public stockMaximumSupplies = [1000,1000]; 75 | uint256 public stockCount = 2; 76 | 77 | /* 78 | * DAO CEO information and configuration 79 | */ 80 | address public managerAddress = 0x0000000000000000000000000000000000000000; 81 | bool isManagerReplacementAllowed = true; 82 | uint256 maximumAmountOfTransactionPerDay = 10; 83 | uint256 maximumAmountOfTransactionPerYear = 300; 84 | uint256 maximumValueOfEachTransaction = 200; 85 | uint256 maximumValueOfTransactionPerDay = 20; 86 | uint256 maximumValueOfTransactionPerYear = 2000; 87 | uint256 maximumValueOfDividendUnitPerYear = 2; 88 | enum TransactionType { 89 | TRANSACTION_TYPE_TRANSFER, 90 | TRANSACTION_TYPE_DIVIDEND, 91 | TRANSACTION_TYPE_VOTE, 92 | TRANSACTION_TYPE_MINT, 93 | TRANSACTION_TYPE_BURN, 94 | TRANSACTION_TYPE_PURCHASE, 95 | TRANSACTION_TYPE_UNKNOWN 96 | } 97 | 98 | 99 | 100 | 101 | /* 102 | * DAO opeartion configurations 103 | */ 104 | 105 | 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/contracts/FastDAO.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: Unlicense 2 | pragma solidity ^0.8.10; 3 | 4 | import "hardhat/console.sol"; 5 | import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; 6 | import './DAOConfig.sol'; 7 | 8 | contract FastDAO is ERC1155 { 9 | string private greeting; 10 | 11 | uint256[] private myArray; 12 | 13 | 14 | function append( string memory a, string memory b) internal pure returns (string memory) { 15 | return string(abi.encodePacked(a, b)); 16 | } 17 | 18 | function greet() public view returns (string memory) { 19 | return greeting; 20 | } 21 | 22 | function setGreeting(string memory _greeting) public { 23 | console.log("Changing greeting from '%s' to '%s'", greeting, _greeting); 24 | greeting = _greeting; 25 | } 26 | 27 | constructor() ERC1155("") { 28 | 29 | greeting = "Hello"; 30 | //_mint(DAOConfig.USER_INDEX_1, DAOConfig.ClaassAIndex, DAOConfig.ClaassAAmount, ""); 31 | 32 | for (uint8 i = 0; i < 10; i++) { 33 | myArray.push(i); 34 | } 35 | 36 | for (uint8 i = 0; i < 10; i++) { 37 | console.log("myArray[%d] = %d", i, myArray[i]); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /src/contracts/Greeter.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: Unlicense 2 | pragma solidity ^0.8.0; 3 | 4 | import "hardhat/console.sol"; 5 | import "./safeMath.sol"; 6 | import "./FastDAO.sol"; 7 | 8 | contract Greeter { 9 | string private greeting; 10 | uint256 greeter_a = 1; 11 | uint256 greeter_b = 1; 12 | 13 | FastDAO public myFastDAOInstance; 14 | 15 | constructor(string memory _greeting) { 16 | console.log("Deploying a Greeter with greeting:", _greeting); 17 | greeting = _greeting; 18 | 19 | 20 | // create a new FastDAO instance 21 | myFastDAOInstance = new FastDAO(); 22 | 23 | } 24 | 25 | 26 | function append( string memory a, string memory b) internal pure returns (string memory) { 27 | return string(abi.encodePacked(a, b)); 28 | } 29 | 30 | function greet() public view returns (string memory) { 31 | return greeting; 32 | } 33 | 34 | function setA(uint256 a) public { 35 | greeter_a = a; 36 | } 37 | 38 | function setB(uint256 b) public { 39 | greeter_b = b; 40 | } 41 | 42 | function getA() public view returns (uint) { 43 | return greeter_a; 44 | } 45 | 46 | function getB() public view returns (uint) { 47 | return greeter_b; 48 | } 49 | 50 | function add(uint256 a, uint256 b) public pure returns (uint256 result) { 51 | return safeMath.add(a, b); 52 | } 53 | 54 | function setGreeting(string memory _greeting) public { 55 | console.log("Changing greeting from '%s' to '%s'", greeting, _greeting); 56 | greeting = _greeting; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/contracts/StockManager.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: Unlicense 2 | pragma solidity ^0.8.10; 3 | 4 | import "hardhat/console.sol"; 5 | import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; 6 | import './DAOConfig.sol'; 7 | 8 | contract StockManager is ERC1155 { 9 | constructor() ERC1155("") { 10 | console.log("StockManager constructor"); 11 | } 12 | } -------------------------------------------------------------------------------- /src/contracts/safeMath.sol: -------------------------------------------------------------------------------- 1 | library safeMath { 2 | /** 3 | * @dev Returns the addition of two unsigned integers, reverting on overflow. 4 | * 5 | * Counterpart to Solidity's `+` operator. 6 | * 7 | * Requirements: 8 | * - Addition cannot overflow. 9 | */ 10 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 11 | uint256 c = a + b; 12 | require(c >= a, "SafeMath: addition overflow"); 13 | 14 | return c; 15 | } 16 | 17 | /** 18 | * @dev Returns the addition of two unsigned integers, reverting with custom message on overflow. 19 | * 20 | * Counterpart to Solidity's `+` operator. 21 | * 22 | * Requirements: 23 | * - Addition cannot overflow. 24 | */ 25 | function add(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 26 | uint256 c = a + b; 27 | require(c >= a, errorMessage); 28 | 29 | return c; 30 | } 31 | 32 | /** 33 | * @dev Returns the subtraction of two unsigned integers, reverting on underflow (when the result is negative). 34 | * 35 | * Counterpart to Solidity's `-` operator. 36 | * 37 | * Requirements: 38 | * - Subtraction cannot underflow. 39 | */ 40 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 41 | return sub(a, b, "SafeMath: subtraction underflow"); 42 | } 43 | 44 | /** 45 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on underflow (when the result is negative). 46 | * 47 | * Counterpart to Solidity's `-` operator. 48 | * 49 | * Requirements: 50 | * - Subtraction cannot underflow. 51 | */ 52 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 53 | require(b <= a, errorMessage); 54 | uint256 c = a - b; 55 | 56 | return c; 57 | } 58 | 59 | /** 60 | * @dev Returns the multiplication of two unsigned integers, reverting on overflow. 61 | * 62 | * Counterpart to Solidity's `*` operator. 63 | * 64 | * Requirements: 65 | * - Multiplication cannot overflow. 66 | */ 67 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 68 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 69 | // benefit is lost if 'b' is also tested. 70 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 71 | if (a == 0) { 72 | return 0; 73 | } 74 | 75 | uint256 c = a * b; 76 | require(c / a == b, "SafeMath: multiplication overflow"); 77 | 78 | return c; 79 | } 80 | 81 | /** 82 | * @dev Returns the multiplication of two unsigned integers, reverting on overflow. 83 | * 84 | * Counterpart to Solidity's `*` operator. 85 | * 86 | * Requirements: 87 | * - Multiplication cannot overflow. 88 | */ 89 | function mul(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 90 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 91 | // benefit is lost if 'b' is also tested. 92 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 93 | if (a == 0) { 94 | return 0; 95 | } 96 | 97 | uint256 c = a * b; 98 | require(c / a == b, errorMessage); 99 | 100 | return c; 101 | } 102 | 103 | /** 104 | * @dev Returns the integer division of two unsigned integers. 105 | * Reverts on division by zero. The result is rounded towards zero. 106 | * 107 | * Counterpart to Solidity's `/` operator. Note: this function uses a 108 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 109 | * uses an invalid opcode to revert (consuming all remaining gas). 110 | * 111 | * Requirements: 112 | * - The divisor cannot be zero. 113 | */ 114 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 115 | return div(a, b, "SafeMath: division by zero"); 116 | } 117 | 118 | /** 119 | * @dev Returns the integer division of two unsigned integers. 120 | * Reverts with custom message on division by zero. The result is rounded towards zero. 121 | * 122 | * Counterpart to Solidity's `/` operator. Note: this function uses a 123 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 124 | * uses an invalid opcode to revert (consuming all remaining gas). 125 | * 126 | * Requirements: 127 | * - The divisor cannot be zero. 128 | */ 129 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 130 | // Solidity only automatically asserts when dividing by 0 131 | require(b > 0, errorMessage); 132 | uint256 c = a / b; 133 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 134 | 135 | return c; 136 | } 137 | 138 | /** 139 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 140 | * Reverts when dividing by zero. 141 | * 142 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 143 | * opcode (which leaves remaining gas untouched) while Solidity uses an 144 | * invalid opcode to revert (consuming all remaining gas). 145 | * 146 | * Requirements: 147 | * - The divisor cannot be zero. 148 | */ 149 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 150 | return mod(a, b, "SafeMath: modulo by zero"); 151 | } 152 | 153 | /** 154 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 155 | * Reverts with custom message when dividing by zero. 156 | * 157 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 158 | * opcode (which leaves remaining gas untouched) while Solidity uses an 159 | * invalid opcode to revert (consuming all remaining gas). 160 | * 161 | * Requirements: 162 | * - The divisor cannot be zero. 163 | */ 164 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 165 | require(b != 0, errorMessage); 166 | return a % b; 167 | } 168 | } -------------------------------------------------------------------------------- /src/hardhat.config.ts: -------------------------------------------------------------------------------- 1 | import { task } from "hardhat/config"; 2 | import "@nomiclabs/hardhat-waffle"; 3 | import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; 4 | import { BigNumber } from "ethers"; 5 | 6 | // This is a sample Hardhat task. To learn how to create your own go to 7 | // https://hardhat.org/guides/create-task.html 8 | task("accounts", "Prints the list of accounts", async (args, hre) => { 9 | const accounts = await hre.ethers.getSigners(); 10 | 11 | for (const account of accounts) { 12 | console.log(await account.address); 13 | } 14 | }); 15 | 16 | 17 | task("balances", "Prints the list of AVAX account balances", async (args, hre): Promise => { 18 | const accounts: SignerWithAddress[] = await hre.ethers.getSigners() 19 | for(const account of accounts){ 20 | const balance: BigNumber = await hre.ethers.provider.getBalance( 21 | account.address 22 | ); 23 | console.log(`${account.address} has balance ${balance.toString()}`); 24 | } 25 | }) 26 | 27 | // You need to export an object to set up your config 28 | // Go to https://hardhat.org/config/ to learn more 29 | 30 | /** 31 | * @type import('hardhat/config').HardhatUserConfig 32 | */ 33 | module.exports = { 34 | solidity: "0.8.10", 35 | }; -------------------------------------------------------------------------------- /src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "@nomiclabs/hardhat-ethers": "^2.0.4", 4 | "@nomiclabs/hardhat-waffle": "^2.0.1", 5 | "@types/chai": "^4.3.0", 6 | "@types/mocha": "^9.1.0", 7 | "@types/node": "^17.0.21", 8 | "chai": "^4.3.6", 9 | "ethereum-waffle": "^3.4.0", 10 | "ethers": "^5.5.3", 11 | "hardhat": "^2.8.3", 12 | "ts-node": "^10.4.0", 13 | "typescript": "^4.5.5" 14 | }, 15 | "dependencies": { 16 | "@openzeppelin/contracts": "^4.4.2" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/scripts/dummyScript.ts: -------------------------------------------------------------------------------- 1 | 2 | // We require the Hardhat Runtime Environment explicitly here. This is optional 3 | // but useful for running the script in a standalone fashion through `node