├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── contracts ├── Aave.sol ├── Arrays.sol ├── Assembly.sol ├── BulkSend.sol ├── Callback.sol ├── ChainlinkCCIP.sol ├── ContractBalance.sol ├── CustomError.sol ├── Deploy.sol ├── ERC1155.sol ├── ERC20.sol ├── ERC721.sol ├── Enums.sol ├── Events.sol ├── Factory.sol ├── FixedRateStaking.sol ├── Interface.sol ├── IsContract.sol ├── LayerZeroOFT.sol ├── Library.sol ├── Loops.sol ├── Mapping.sol ├── MaxUint256.sol ├── Merkle.sol ├── Modifier.sol ├── MultipleReturns.sol ├── NatspecComments.sol ├── Oracle.sol ├── Override.sol ├── Ownable.sol ├── PassFunction.sol ├── PaymentDivider.sol ├── Pen.sol ├── Random.sol ├── Rewards.sol ├── Shares.sol ├── Shuffle.sol ├── StaggeredSale.sol ├── Structs.sol ├── TernaryOperators.sol ├── TransparentProxy.sol ├── UintToString.sol ├── Uniswap.sol ├── UniswapFlashLoan.sol ├── VCTerms.sol ├── Variables.sol ├── Vault.sol ├── Whitelist.sol ├── encodeCall.sol └── escrow.sol ├── hardhat.config.js ├── package-lock.json ├── package.json ├── scripts ├── merkleGenerator.js ├── sample-script.js └── signInWithEthereum.html └── test └── sample-test.js /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # parcel-bundler cache (https://parceljs.org/) 61 | .cache 62 | 63 | # next.js build output 64 | .next 65 | 66 | # nuxt.js build output 67 | .nuxt 68 | 69 | # vuepress build output 70 | .vuepress/dist 71 | 72 | # Serverless directories 73 | .serverless 74 | 75 | # FuseBox cache 76 | .fusebox/ 77 | 78 | node_modules 79 | .env 80 | coverage 81 | coverage.json 82 | typechain 83 | 84 | #Hardhat files 85 | cache 86 | artifacts 87 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | This is a personal dumping ground of untested Solidity code. 4 | 5 | Solidity Tutorials: 6 | https://jamesbachini.com/category/development/solidity/ 7 | 8 | All code is for demonstration purposes and should not be used for financial transactions. 9 | -------------------------------------------------------------------------------- /contracts/Aave.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 5 | 6 | interface IAave { 7 | function deposit(address asset,uint amount,address onBehalfOf,uint16 referralCode) external; 8 | function borrow(address asset,uint amount,uint interestRateMode,uint16 referralCode,address onBehalfOf) external; 9 | function repay(address asset,uint amount,uint rateMode,address onBehalfOf) external returns (uint); 10 | function withdraw(address asset,uint amount,address to) external returns (uint); 11 | function getUserAccountData(address user) external view returns (uint totalCollateralETH, uint totalDebtETH, uint availableBorrowsETH, uint currentLiquidationThreshold, uint ltv, uint healthFactor); 12 | } 13 | 14 | contract Borrowing { 15 | address public aave = 0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9; 16 | address public steth = 0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84; 17 | address public weth = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; 18 | 19 | function borrow() payable public { 20 | uint balance = 1e18; // Assumes contract holds stETH balance 21 | IAave(aave).deposit(steth,balance,address(this),0); 22 | uint borrowAmount = balance * 6 / 10; // 60% collateral to loan 23 | IAave(aave).borrow(weth,borrowAmount,2,0,address(this)); 24 | } 25 | } -------------------------------------------------------------------------------- /contracts/Arrays.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | // Arrays Example 5 | contract Arrays { 6 | 7 | uint[] public myArray = [2,4,6,8,10,12]; 8 | uint[4] public myFixedArray = [3,5,1,8]; 9 | uint[][] public nestedArray; 10 | 11 | function arrayPush(uint _newNumber) public { 12 | myArray.push(_newNumber); 13 | } 14 | 15 | function arrayLoop() public view { 16 | for (uint i=0; i=0.8.0; 3 | 4 | contract StoringData { 5 | function setDataToMemeory(uint newValue) public { 6 | assembly { 7 | sstore(0, newValue) 8 | } 9 | } 10 | 11 | function getDataFromMemory() public view returns(uint) { 12 | assembly { 13 | let v := sload(0) 14 | mstore(0x80, v) 15 | return(0x80, 32) 16 | } 17 | } 18 | } 19 | 20 | contract SendETH { 21 | address[2] owners = [0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2,0xdD870fA1b7C4700F2BD7f44238821C26f7392148]; 22 | function withdrawETH(address _to, uint _amount) external payable { 23 | bool success; 24 | assembly { 25 | for { let i := 0 } lt(i, 2) { i := add(i, 1) } { 26 | let owner := sload(i) 27 | if eq(_to, owner) { 28 | success := call(gas(), _to, _amount, 0, 0, 0, 0) 29 | } 30 | } 31 | } 32 | require(success, "Failed to send ETH"); 33 | } 34 | } 35 | 36 | contract UselessEncryption { 37 | function encrypt(string memory _input, bool _decrypt) external pure returns (string memory) { 38 | bytes32 output; 39 | assembly { 40 | function stringToBytes(a) -> b { 41 | b := mload(add(a, 32)) 42 | } 43 | function addToBytes(bs,decrypt) -> r { 44 | if eq(decrypt, false) { 45 | mstore(0x0, add(bs,0x0101010101010101010101010101010101010101010101010101010101010101)) 46 | } 47 | if eq(decrypt, true) { 48 | mstore(0x0, sub(bs,0x0101010101010101010101010101010101010101010101010101010101010101)) 49 | } 50 | r := mload(0x0) 51 | } 52 | let byteString := stringToBytes(_input) 53 | output := addToBytes(byteString,_decrypt) 54 | } 55 | bytes memory bytesArray = new bytes(32); 56 | for (uint i; i < 32; i++) bytesArray[i] = output[i]; 57 | return string(bytesArray); 58 | } 59 | } -------------------------------------------------------------------------------- /contracts/BulkSend.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 5 | import "@openzeppelin/contracts/access/Ownable.sol"; 6 | 7 | /* 8 | This contract shows how to send tokens and ETH to multiple addresses. 9 | Can easily handle 500 addresses in a single transaction via remix, perhaps more. 10 | Send ETH and tokens to the contract prior to executing sendOutFunds 11 | */ 12 | 13 | contract BulkSend is Ownable(msg.sender) { 14 | address token = 0x2f3A40A3db8a7e3D09B0adfEfbCe4f6F81927557; // Token Contract Address (Goerli USDC) 15 | uint tokenAmount = 5000 * 1e6; // 5000 tokens 16 | uint ethAmount = 5000000000000000; // 0.005 ETH 17 | 18 | function sendOutFunds(address[] memory _to) public onlyOwner { 19 | for (uint i = 0; i < _to.length; i++) { 20 | IERC20(token).transfer(_to[i], tokenAmount); 21 | payable(_to[i]).transfer(ethAmount); 22 | } 23 | } 24 | 25 | function withdraw() public onlyOwner { 26 | payable(msg.sender).transfer(address(this).balance); 27 | } 28 | 29 | function reclaimToken(IERC20 _token) public onlyOwner { 30 | require(address(_token) != address(0)); 31 | uint balance = _token.balanceOf(address(this)); 32 | _token.transfer(msg.sender, balance); 33 | } 34 | 35 | receive() external payable {} 36 | fallback() external payable {} 37 | } -------------------------------------------------------------------------------- /contracts/Callback.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | contract Parent { 5 | uint public parentVariable; 6 | 7 | function parentFunc(uint _parentVariable, function(uint) external _callback) public { 8 | parentVariable = _parentVariable; 9 | _callback(_parentVariable * 2); 10 | } 11 | } 12 | 13 | contract Child { 14 | address public parentAddress; 15 | uint public childVariable; 16 | 17 | constructor(address _parentAddress) { 18 | parentAddress = _parentAddress; 19 | } 20 | 21 | function run(uint _newVar) public { 22 | Parent(parentAddress).parentFunc(_newVar, this.callback); 23 | } 24 | 25 | function callback(uint _childVariable) external { 26 | childVariable = _childVariable * 2; 27 | } 28 | } -------------------------------------------------------------------------------- /contracts/ChainlinkCCIP.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.19; 3 | 4 | import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol"; 5 | import {OwnerIsCreator} from "@chainlink/contracts-ccip/src/v0.8/shared/access/OwnerIsCreator.sol"; 6 | import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol"; 7 | import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/token/ERC20/IERC20.sol"; 8 | import {LinkTokenInterface} from "@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol"; 9 | 10 | contract ChainlinkCCIP is OwnerIsCreator { 11 | error NotEnoughBalance(uint256 currentBalance, uint256 calculatedFees); 12 | 13 | IRouterClient router; 14 | LinkTokenInterface linkToken; 15 | 16 | constructor(address _router, address _link) { 17 | router = IRouterClient(_router); 18 | linkToken = LinkTokenInterface(_link); 19 | } 20 | 21 | function transferTokens( 22 | uint64 _destinationChainSelector, 23 | address _receiver, 24 | address _token, 25 | uint256 _amount 26 | ) 27 | external 28 | onlyOwner 29 | returns (bytes32 messageId) 30 | { 31 | Client.EVM2AnyMessage memory evm2AnyMessage = _buildCCIPMessage( 32 | _receiver, 33 | _token, 34 | _amount, 35 | address(0) 36 | ); 37 | uint256 fees = router.getFee(_destinationChainSelector, evm2AnyMessage); 38 | if (fees > address(this).balance) 39 | revert NotEnoughBalance(address(this).balance, fees); 40 | IERC20(_token).approve(address(router), _amount); 41 | messageId = router.ccipSend{value: fees}( 42 | _destinationChainSelector, 43 | evm2AnyMessage 44 | ); 45 | return messageId; 46 | } 47 | 48 | function _buildCCIPMessage( 49 | address _receiver, 50 | address _token, 51 | uint256 _amount, 52 | address _feeTokenAddress 53 | ) internal pure returns (Client.EVM2AnyMessage memory) { 54 | Client.EVMTokenAmount[] 55 | memory tokenAmounts = new Client.EVMTokenAmount[](1); 56 | Client.EVMTokenAmount memory tokenAmount = Client.EVMTokenAmount({ 57 | token: _token, 58 | amount: _amount 59 | }); 60 | tokenAmounts[0] = tokenAmount; 61 | Client.EVM2AnyMessage memory evm2AnyMessage = Client.EVM2AnyMessage({ 62 | receiver: abi.encode(_receiver), 63 | data: "", 64 | tokenAmounts: tokenAmounts, 65 | extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: 0, strict: false})), 66 | feeToken: _feeTokenAddress 67 | }); 68 | return evm2AnyMessage; 69 | } 70 | 71 | function withdraw(address _beneficiary, address _token) public onlyOwner { 72 | uint256 amountToken = IERC20(_token).balanceOf(address(this)); 73 | IERC20(_token).transfer(_beneficiary, amountToken); 74 | } 75 | 76 | receive() external payable {} 77 | } -------------------------------------------------------------------------------- /contracts/ContractBalance.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | // import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 5 | interface IERC20 { 6 | function balanceOf(address account) external view returns (uint); 7 | } 8 | 9 | contract BalanceExample { 10 | uint public ethBalance = address(this).balance; 11 | address private wethTokenAddress = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; 12 | uint public wethBalance = IERC20(wethTokenAddress).balanceOf(address(this)); 13 | } 14 | -------------------------------------------------------------------------------- /contracts/CustomError.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.4; 3 | 4 | error MyCustomError(uint var1, uint var2); 5 | 6 | contract CustomErrors { 7 | function test() pure public { 8 | if (1 > 0) revert MyCustomError(1,2); 9 | } 10 | } -------------------------------------------------------------------------------- /contracts/Deploy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 5 | 6 | contract MyToken is ERC20 { 7 | constructor() ERC20("MyToken", "MYTKN") { 8 | _mint(msg.sender, 1e30); 9 | } 10 | } 11 | 12 | contract Deployer { 13 | address public myToken; 14 | constructor() { 15 | myToken = address(new MyToken()); 16 | } 17 | // Contract owns all the tokens 18 | } 19 | -------------------------------------------------------------------------------- /contracts/ERC1155.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; 5 | 6 | contract MyNFT is ERC1155 { 7 | uint256 public constant gameItem1 = 1; 8 | uint256 public constant gameItem2 = 2; 9 | uint256 public constant gameItem3 = 3; 10 | 11 | constructor() ERC1155("https://ethereumhacker.com/nfts/{id}.json") { 12 | _mint(msg.sender, gameItem1, 1, ""); 13 | _mint(msg.sender, gameItem2, 1, ""); 14 | _mint(msg.sender, gameItem3, 100, ""); 15 | } 16 | } -------------------------------------------------------------------------------- /contracts/ERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 5 | 6 | contract MyToken is ERC20 { 7 | constructor() ERC20("MyToken", "MYTKN") { 8 | _mint(msg.sender, 1000000 ether); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/ERC721.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; 5 | import "@openzeppelin/contracts/utils/Base64.sol"; 6 | 7 | contract MyNFT is ERC721 { 8 | uint public tokenId; 9 | uint public maxSupply = 1000; 10 | 11 | constructor() ERC721("My NFT", "MFT") { 12 | } 13 | 14 | function tokenURI(uint) override public pure returns (string memory) { 15 | string memory json = Base64.encode(bytes(string( 16 | abi.encodePacked('{"name": "My NFT", "description": "Whatever", "image": "https://ethereumhacker.com/img/nft.png"}') 17 | ))); 18 | return string(abi.encodePacked('data:application/json;base64,', json)); 19 | } 20 | 21 | function mint() public { 22 | require(tokenId < maxSupply, "All tokens have been minted"); 23 | _safeMint(msg.sender, tokenId); 24 | tokenId = tokenId + 1; 25 | } 26 | } -------------------------------------------------------------------------------- /contracts/Enums.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | contract Enums { 5 | enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } 6 | 7 | function getNextDay(Day _currentDay) public pure returns (Day) { 8 | if (_currentDay == Day.Sunday) return Day.Monday; 9 | return Day(uint(_currentDay) + 1); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/Events.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | contract Events { 5 | event LogThis(string msg); 6 | 7 | function test() external { 8 | emit LogThis('Hello World'); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/Factory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 5 | 6 | contract Token is ERC20 { 7 | constructor(string memory _name, string memory _ticker, uint _supply) ERC20(_name, _ticker) { 8 | _mint(msg.sender, _supply); 9 | } 10 | } 11 | 12 | contract Factory { 13 | address[] public tokens; 14 | uint public tokenCount; 15 | event TokenDeployed(address tokenAddress); 16 | 17 | function deployToken(string calldata _name, string calldata _ticker, uint _supply) public returns (address) { 18 | Token token = new Token(_name, _ticker, _supply); 19 | token.transfer(msg.sender, _supply); 20 | tokens.push(address(token)); 21 | tokenCount += 1; 22 | emit TokenDeployed(address(token)); 23 | return address(token); 24 | } 25 | } -------------------------------------------------------------------------------- /contracts/FixedRateStaking.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 5 | 6 | contract FixedStaking is ERC20 { 7 | mapping(address => uint) public staked; 8 | mapping(address => uint) private stakedFromTS; 9 | 10 | constructor() ERC20("Fixed Staking", "FIX") { 11 | _mint(msg.sender,1000000000000000000); 12 | } 13 | 14 | function stake(uint amount) external { 15 | require(amount > 0, "amount is <= 0"); 16 | require(balanceOf(msg.sender) >= amount, "balance is <= amount"); 17 | _transfer(msg.sender, address(this), amount); 18 | if (staked[msg.sender] > 0) { 19 | claim(); 20 | } 21 | stakedFromTS[msg.sender] = block.timestamp; 22 | staked[msg.sender] += amount; 23 | } 24 | 25 | function unstake(uint amount) external { 26 | require(amount > 0, "amount is <= 0"); 27 | require(staked[msg.sender] >= amount, "amount is > staked"); 28 | claim(); 29 | staked[msg.sender] -= amount; 30 | _transfer(address(this), msg.sender, amount); 31 | } 32 | 33 | function claim() public { 34 | require(staked[msg.sender] > 0, "staked is <= 0"); 35 | uint secondsStaked = block.timestamp - stakedFromTS[msg.sender]; 36 | uint rewards = staked[msg.sender] * secondsStaked / 3.154e7; 37 | _mint(msg.sender,rewards); 38 | stakedFromTS[msg.sender] = block.timestamp; 39 | } 40 | } -------------------------------------------------------------------------------- /contracts/Interface.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 5 | 6 | interface AlternateIERC20 { 7 | function totalSupply() external view returns (uint); 8 | function balanceOf(address account) external view returns (uint); 9 | function transfer(address recipient, uint amount) external returns (bool); 10 | function allowance(address owner, address spender) external view returns (uint); 11 | function approve(address spender, uint amount) external returns (bool); 12 | function transferFrom(address sender, address recipient, uint amount) external returns (bool); 13 | event Transfer(address indexed from, address indexed to, uint value); 14 | event Approval(address indexed owner, address indexed spender, uint value); 15 | } 16 | 17 | interface IWEth is IERC20 { 18 | function withdraw(uint wad) external; 19 | function deposit() external payable; 20 | } 21 | 22 | interface IAave { 23 | function deposit(address asset,uint amount,address onBehalfOf,uint16 referralCode) external; 24 | function borrow(address asset,uint amount,uint interestRateMode,uint16 referralCode,address onBehalfOf) external; 25 | function repay(address asset,uint amount,uint rateMode,address onBehalfOf) external returns (uint); 26 | function withdraw(address asset,uint amount,address to) external returns (uint); 27 | function getUserAccountData(address user) external view returns (uint totalCollateralETH, uint totalDebtETH, uint availableBorrowsETH, uint currentLiquidationThreshold, uint ltv, uint healthFactor); 28 | } 29 | 30 | contract InterfaceExample { 31 | address private wethAddress = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; 32 | address private aaveAddress = 0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9; 33 | 34 | function depositWeth() external { 35 | uint wethBalance = IWEth(wethAddress).balanceOf(address(this)); 36 | IAave(aaveAddress).deposit(wethAddress,wethBalance,address(this),0); 37 | } 38 | } -------------------------------------------------------------------------------- /contracts/IsContract.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | contract IsContract { 5 | 6 | function isContract(address account) private view returns (bool) { 7 | uint256 size; 8 | assembly { 9 | size := extcodesize(account) 10 | } 11 | return size > 0; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /contracts/LayerZeroOFT.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.18; 3 | 4 | /* 5 | // https://layerzero.gitbook.io/docs/technical-reference/testnet/testnet-addresses 6 | Goerli lzEndpointAddress = 0xbfD2135BFfbb0B5378b56643c2Df8a87552Bfa23 7 | chainId: 10121 deploymentAddress = 8 | Optimism-Goerli lzEndpointAddress = 0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1 9 | chainId: 10132 deploymentAddress = 10 | */ 11 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 12 | import "https://github.com/LayerZero-Labs/solidity-examples/blob/main/contracts/token/oft/OFTCore.sol"; 13 | import "https://github.com/LayerZero-Labs/solidity-examples/blob/main/contracts/token/oft/IOFT.sol"; 14 | 15 | contract LayerZeroOFT is OFTCore, ERC20, IOFT { 16 | address constant lzEndpointAddress = 0xbfD2135BFfbb0B5378b56643c2Df8a87552Bfa23; 17 | 18 | constructor() ERC20("LayerZeroOFT", "LZOFT") OFTCore(lzEndpointAddress) { 19 | if (block.chainid == 5) { // Only mint initial supply on Goerli 20 | _mint(msg.sender, 1_000_000 * 10 ** decimals()); 21 | } 22 | } 23 | 24 | function supportsInterface(bytes4 interfaceId) public view virtual override(OFTCore, IERC165) returns (bool) { 25 | return interfaceId == type(IOFT).interfaceId || interfaceId == type(IERC20).interfaceId || super.supportsInterface(interfaceId); 26 | } 27 | 28 | function token() public view virtual override returns (address) { 29 | return address(this); 30 | } 31 | 32 | function circulatingSupply() public view virtual override returns (uint) { 33 | return totalSupply(); 34 | } 35 | 36 | function _debitFrom(address _from, uint16, bytes memory, uint _amount) internal virtual override returns(uint) { 37 | address spender = _msgSender(); 38 | if (_from != spender) _spendAllowance(_from, spender, _amount); 39 | _burn(_from, _amount); 40 | return _amount; 41 | } 42 | 43 | function _creditTo(uint16, address _toAddress, uint _amount) internal virtual override returns(uint) { 44 | _mint(_toAddress, _amount); 45 | return _amount; 46 | } 47 | } -------------------------------------------------------------------------------- /contracts/Library.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | library TestLibrary { 5 | function subtract(uint a, uint b) internal pure returns (uint) { 6 | return a - b; 7 | } 8 | } 9 | 10 | // import "./TestLibrary.sol"; 11 | 12 | contract MyContract { 13 | function func(uint a, uint b) public pure returns (uint) { 14 | return TestLibrary.subtract(a, b); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /contracts/Loops.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.21; 3 | 4 | contract Loops { 5 | uint[20] public values; 6 | 7 | function replaceValue(uint _breakPoint) public { 8 | for (uint i = 0; i < values.length; i++) { 9 | if (i == 5) { 10 | continue; // skip to next i 11 | } else if (i >= _breakPoint) { 12 | break; // break out of loop 13 | } else { 14 | values[i] = i; 15 | } 16 | } 17 | } 18 | 19 | function automate() external { 20 | uint x = 10; 21 | while (values[12] == 0) { 22 | replaceValue(x); 23 | x ++; 24 | } 25 | } 26 | 27 | function uglyAutomate() external { 28 | uint x = 10; 29 | do { 30 | replaceValue(x); 31 | x ++; 32 | } while (values[12] == 0); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /contracts/Mapping.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | // Mapping Addresses To Balances 5 | contract AddressMap { 6 | mapping(address => uint) public balances; 7 | 8 | function addFunds() public { 9 | balances[msg.sender] = 1000; 10 | } 11 | 12 | function checkFunds(address _addr) public view returns(uint) { 13 | return balances[_addr]; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /contracts/MaxUint256.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | contract MaxUint256 { 5 | function uintMax() external pure returns(uint256) { 6 | return type(uint256).max; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /contracts/Merkle.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | // https://github.com/dragonfly-xyz/useful-solidity-patterns/ 5 | 6 | contract Merkle { 7 | bytes32 public immutable MerkleRoot; 8 | mapping (address => bool) public hasClaimed; 9 | 10 | constructor(bytes32 _root) payable { 11 | MerkleRoot = _root; 12 | } 13 | 14 | function prove(bytes32 leaf, bytes32[] memory _siblings) public view returns (bool) { 15 | require(leaf != 0, 'invalid leaf value'); 16 | bytes32 node = leaf; 17 | for (uint i = 0; i < _siblings.length; ++i) { 18 | bytes32 sibling = _siblings[i]; 19 | node = keccak256(node > sibling ? abi.encode(sibling, node) : abi.encode(node, sibling)); 20 | } 21 | return node == MerkleRoot; 22 | } 23 | 24 | function claim(address payable member, uint _claimAmount, bytes32[] memory _proof) external { 25 | require(prove(~keccak256(abi.encode(member, _claimAmount)), _proof), 'bad proof'); 26 | hasClaimed[member] = true; 27 | member.transfer(_claimAmount); 28 | } 29 | } 30 | 31 | contract MerkleHelper { 32 | function constructTree(address[] memory _members, uint[] memory _claimAmounts) external pure returns (bytes32 root, bytes32[][] memory tree) { 33 | require(_members.length != 0 && _members.length == _claimAmounts.length); 34 | uint height = 0; 35 | { 36 | uint n = _members.length; 37 | while (n != 0) { 38 | n = n == 1 ? 0 : (n + 1) / 2; 39 | ++height; 40 | } 41 | } 42 | tree = new bytes32[][](height); 43 | bytes32[] memory nodes = tree[0] = new bytes32[](_members.length); 44 | for (uint i = 0; i < _members.length; ++i) { 45 | nodes[i] = ~keccak256(abi.encode(_members[i], _claimAmounts[i])); 46 | } 47 | for (uint h = 1; h < height; ++h) { 48 | uint nHashes = (nodes.length + 1) / 2; 49 | bytes32[] memory hashes = new bytes32[](nHashes); 50 | for (uint i = 0; i < nodes.length; i += 2) { 51 | bytes32 a = nodes[i]; 52 | bytes32 b = i + 1 < nodes.length ? nodes[i + 1] : bytes32(0); 53 | hashes[i / 2] = keccak256(a > b ? abi.encode(b, a) : abi.encode(a, b)); 54 | } 55 | tree[h] = nodes = hashes; 56 | } 57 | root = tree[height - 1][0]; 58 | } 59 | 60 | function createProof(uint _memberIndex, bytes32[][] memory _tree) external pure returns (bytes32[] memory _proof) { 61 | uint leafIndex = _memberIndex; 62 | uint height = _tree.length; 63 | _proof = new bytes32[](height - 1); 64 | for (uint h = 0; h < _proof.length; ++h) { 65 | uint siblingIndex = leafIndex % 2 == 0 ? leafIndex + 1 : leafIndex - 1; 66 | if (siblingIndex < _tree[h].length) { 67 | _proof[h] = _tree[h][siblingIndex]; 68 | } 69 | leafIndex /= 2; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /contracts/Modifier.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | contract Modifier { 5 | modifier onlyVitalik() { 6 | require(msg.sender == 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045); 7 | _; 8 | } 9 | 10 | function doSomething() external onlyVitalik { 11 | // Only vitalik's wallet can call this function 12 | } 13 | } -------------------------------------------------------------------------------- /contracts/MultipleReturns.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | contract MultipleReturns { 5 | function returnVars() internal pure returns(uint,uint,uint) { 6 | uint var1 = 1; 7 | uint var2 = 2; 8 | uint var3 = 3; 9 | return (var1,var2,var3); 10 | } 11 | 12 | function getVar() external pure returns(uint) { 13 | // (uint a, uint b, uint c) = returnVars(); 14 | (,uint b,) = returnVars(); 15 | return b; 16 | } 17 | } -------------------------------------------------------------------------------- /contracts/NatspecComments.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.21; 3 | 4 | /** 5 | * @title Example Comment Contract 6 | * @author James Bachini 7 | * @notice notes for normies, code with ASCII cat art is better 8 | * @dev Notes for devs, https://ascii-generator.site/t/ 9 | * @custom:experimental This is an experimental contract. 10 | * |\__/,| (` 11 | * __|o o |___ ) 12 | * -(((---(((-------- 13 | */ 14 | 15 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 16 | import "@openzeppelin/contracts/access/Ownable.sol"; 17 | 18 | contract Comments is ERC20, Ownable { 19 | 20 | /** 21 | * @dev Constructor method initializes the ERC20 Token. 22 | */ 23 | constructor() ERC20("Commment Token", "CT") Ownable(msg.sender) {} 24 | 25 | /** 26 | * @notice Mints new tokens 27 | * @dev This can only be called by the owner (contract deployer) 28 | * @param {address} _to The address to send newly minted partner tokens to 29 | * @param {uint} _amount The number of tokens to mint 30 | * @return {uint} always returns 1337 31 | */ 32 | function mint(address _to, uint _amount) public onlyOwner returns (uint) { 33 | _mint(_to, _amount); // internal ERC20 function mints new tokens 34 | return 1337; 35 | } 36 | 37 | /** 38 | * @notice custom after transfer fuction 39 | * @dev overrides ERC20 internal function 40 | * @inheritdoc ERC20 41 | */ 42 | function _update(address, address _to, uint256 _amount) internal override { 43 | // nothing to see here 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /contracts/Oracle.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | interface EACAggregatorProxy { 5 | function latestAnswer() external view returns (int256); 6 | } 7 | 8 | // Get ETH price from Chainlink oracle service 9 | contract PainLink { 10 | int256 public ethPrice = 0; 11 | address public chainLinkETHUSDAddress = 0x9326BFA02ADD2366b30bacB125260Af641031331; // Kovan, more addresses here: https://docs.chain.link/docs/reference-contracts/ 12 | function updateEthPrice() public returns (int256) { 13 | ethPrice = EACAggregatorProxy(chainLinkETHUSD).latestAnswer(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /contracts/Override.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 5 | 6 | contract MyToken is ERC20 { 7 | bool paused = true; 8 | 9 | constructor() ERC20("My Paused Token", "TOKEN") { 10 | _mint(msg.sender, 1000000); 11 | } 12 | 13 | function letsGo() external { 14 | paused = false; 15 | } 16 | 17 | function _beforeTokenTransfer(address from, address to, uint amount) internal virtual override(ERC20) { 18 | super._beforeTokenTransfer(from, to, amount); 19 | require(paused == false, "Token transfer is paused"); 20 | } 21 | } -------------------------------------------------------------------------------- /contracts/Ownable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | import "@openzeppelin/contracts/access/Ownable.sol"; 5 | 6 | contract OwnableExample1 is Ownable(msg.sender) { 7 | function adminFunctionExample() public onlyOwner { 8 | // Avoid Decentralisation Here 9 | } 10 | } 11 | 12 | // Ownable Contracts Using Modifier 13 | contract OwnableExample2 { 14 | address public owner; 15 | 16 | constructor() { 17 | owner = msg.sender; 18 | } 19 | 20 | modifier onlyOwner() { 21 | require(msg.sender == owner, "not owner"); 22 | _; 23 | } 24 | 25 | function setOwner(address _newOwner) public onlyOwner { 26 | owner = _newOwner; 27 | } 28 | 29 | function adminFunctionExample() public onlyOwner { 30 | // Avoid Decentralisation Here 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /contracts/PassFunction.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | contract PassFunction { 5 | uint public n; 6 | 7 | function exec(uint _a) internal pure returns (uint) { 8 | return _a * 2; 9 | } 10 | 11 | function run(function(uint) internal returns (uint) _func, uint _x) internal { 12 | n = _func(_x); 13 | } 14 | 15 | function test() external { 16 | run(exec,8); 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /contracts/PaymentDivider.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.17; 3 | 4 | contract Distributor { 5 | address developer = 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2; 6 | address lawfirm = 0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db; 7 | address bizdev = 0x78731D3Ca6b7E34aC0F824c42a7cC18A495cabaB; 8 | 9 | fallback() external payable { 10 | uint developerAmount = msg.value * 90 / 100; 11 | uint lawfirmAmount = msg.value * 5 / 100; 12 | uint bizdevAmount = msg.value - developerAmount - lawfirmAmount; 13 | 14 | payable(developer).transfer(developerAmount); 15 | payable(lawfirm).transfer(lawfirmAmount); 16 | payable(bizdev).transfer(bizdevAmount); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /contracts/Pen.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.23; 3 | 4 | /* ____ __ _ __ ___ ______ _ ___ _ 5 | * / __/__ / / / / |/ /__ /_ __/ / ( )__ / _ \___ __ | | 6 | * _\ \/ -_/ / / / /|_/ / -_/ / / / \/ ( _/ / ___/ -_) \ / \ 7 | * /___/\__/_/_/ /_/ /_/\__/ /_/ /_/_/_/__/ /_/ \__/_/_/ \|/ 8 | * 9 | * Etch your words permanently on the Ethereum blockchain where they will outlive 10 | * you & create an everlasting record of your thoughts, contemplations & predictions. 11 | * This is your chance to leave an eternal mark and express your presence in the 12 | * digital age while being rewarded with a "Write to Earn" token. 13 | * 14 | * Deployed to Ethereum: 0x7eae7422f633429EE72BA991Ac293197B80D5976 15 | */ 16 | 17 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 18 | 19 | contract Pen is ERC20 { 20 | uint maxSupply = 1_000_000 * 10 ** decimals(); 21 | uint reward = 1_000 * 10 ** decimals(); 22 | mapping(address => string) public paper; 23 | mapping(address => bool) public rewarded; 24 | event LogThis(string msg); 25 | 26 | constructor() ERC20("Pen", "PEN") {} 27 | 28 | function write(string memory _msg) public { 29 | paper[msg.sender] = _msg; 30 | emit LogThis(_msg); 31 | distributeRewards(); 32 | } 33 | 34 | function read(address _writer) public view returns (string memory) { 35 | return paper[_writer]; 36 | } 37 | 38 | function distributeRewards() internal { 39 | if (totalSupply() + reward < maxSupply && rewarded[msg.sender] == false) { 40 | rewarded[msg.sender] = true; 41 | _mint(msg.sender, reward); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /contracts/Random.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.18; 3 | 4 | // Generate a random enough number for most applications 5 | contract RandomishNumbers { 6 | 7 | function newRandom() private view returns (uint) { 8 | uint randomNumber = block.prevrandao; 9 | return randomNumber; 10 | } 11 | 12 | function oldRandom() private view returns (uint) { 13 | uint hashNumber = uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, msg.sender))); 14 | return hashNumber % 100; 15 | } 16 | } 17 | 18 | // For more secure randomness consider an off-chain oracle service such as https://docs.chain.link/docs/chainlink-vrf/ 19 | -------------------------------------------------------------------------------- /contracts/Rewards.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 5 | 6 | // Send out ERC20 Rewards 7 | contract Rewards { 8 | address rewardToken = 0xd0A1E359811322d97991E03f863a0C30C2cF029C; // Kovan WETH 9 | 10 | mapping(address => uint) public startTS; 11 | 12 | uint public deployedTS; 13 | uint rewardsPerDay = 1e18; // wei, 18 decimals 14 | 15 | constructor() { 16 | deployedTS = block.timestamp; 17 | } 18 | 19 | function addMe() public { 20 | // logic to decide who deserves rewards 21 | startTS[msg.sender] = block.timestamp; 22 | } 23 | 24 | function claimRewards() public { 25 | require(startTS[msg.sender] != 0, "No record of user account"); 26 | require(startTS[msg.sender] < block.timestamp - 1 days, "No Rewards Due On First Day"); 27 | uint rewardAmount = block.timestamp - startTS[msg.sender] * rewardsPerDay / 1 days; 28 | startTS[msg.sender] = block.timestamp; 29 | IERC20(rewardToken).transfer(msg.sender, rewardAmount); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /contracts/Shares.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.21; 3 | 4 | /** 5 | * A simplified permissionless version of FriendtechSharesV1 contract 6 | */ 7 | 8 | contract Shares { 9 | address public protocolFeeDestination; 10 | uint256 public protocolFeePercent; 11 | 12 | constructor() { 13 | protocolFeeDestination = msg.sender; 14 | protocolFeePercent = 1e15; 15 | } 16 | 17 | event Trade(address trader, address subject, bool isBuy, uint256 shareAmount, uint256 ethAmount, uint256 protocolEthAmount, uint256 supply); 18 | 19 | mapping(address => mapping(address => uint256)) public sharesBalance; 20 | mapping(address => uint256) public sharesSupply; 21 | 22 | function getPrice(uint256 supply, uint256 amount) public pure returns (uint256) { 23 | uint256 sum1 = supply == 0 ? 0 : (supply - 1 )* (supply) * (2 * (supply - 1) + 1) / 6; 24 | uint256 sum2 = supply == 0 && amount == 1 ? 0 : (supply - 1 + amount) * (supply + amount) * (2 * (supply - 1 + amount) + 1) / 6; 25 | uint256 summation = sum2 - sum1; 26 | return summation * 1 ether / 16000; 27 | } 28 | 29 | function getBuyPrice(address sharesSubject, uint256 amount) public view returns (uint256) { 30 | return getPrice(sharesSupply[sharesSubject], amount); 31 | } 32 | 33 | function getSellPrice(address sharesSubject, uint256 amount) public view returns (uint256) { 34 | return getPrice(sharesSupply[sharesSubject] - amount, amount); 35 | } 36 | 37 | function getBuyPriceAfterFee(address sharesSubject, uint256 amount) public view returns (uint256) { 38 | uint256 price = getBuyPrice(sharesSubject, amount); 39 | uint256 protocolFee = price * protocolFeePercent / 1 ether; 40 | return price + protocolFee; 41 | } 42 | 43 | function getSellPriceAfterFee(address sharesSubject, uint256 amount) public view returns (uint256) { 44 | uint256 price = getSellPrice(sharesSubject, amount); 45 | uint256 protocolFee = price * protocolFeePercent / 1 ether; 46 | return price - protocolFee; 47 | } 48 | 49 | function buyShares(address sharesSubject, uint256 amount) public payable { 50 | uint256 supply = sharesSupply[sharesSubject]; 51 | require(supply > 0 || sharesSubject == msg.sender, "Only the shares' subject can buy the first share"); 52 | uint256 price = getPrice(supply, amount); 53 | uint256 protocolFee = price * protocolFeePercent / 1 ether; 54 | require(msg.value >= price + protocolFee, "Insufficient payment"); 55 | sharesBalance[sharesSubject][msg.sender] = sharesBalance[sharesSubject][msg.sender] + amount; 56 | sharesSupply[sharesSubject] = supply + amount; 57 | emit Trade(msg.sender, sharesSubject, true, amount, price, protocolFee, supply + amount); 58 | (bool success1, ) = protocolFeeDestination.call{value: protocolFee}(""); 59 | require(success1, "Unable to send funds"); 60 | } 61 | 62 | function sellShares(address sharesSubject, uint256 amount) public payable { 63 | uint256 supply = sharesSupply[sharesSubject]; 64 | require(supply > amount, "Cannot sell the last share"); 65 | uint256 price = getPrice(supply - amount, amount); 66 | uint256 protocolFee = price * protocolFeePercent / 1 ether; 67 | require(sharesBalance[sharesSubject][msg.sender] >= amount, "Insufficient shares"); 68 | sharesBalance[sharesSubject][msg.sender] = sharesBalance[sharesSubject][msg.sender] - amount; 69 | sharesSupply[sharesSubject] = supply - amount; 70 | emit Trade(msg.sender, sharesSubject, false, amount, price, protocolFee, supply - amount); 71 | (bool success1, ) = msg.sender.call{value: price - protocolFee}(""); 72 | (bool success2, ) = protocolFeeDestination.call{value: protocolFee}(""); 73 | require(success1 && success2, "Unable to send funds"); 74 | } 75 | } -------------------------------------------------------------------------------- /contracts/Shuffle.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.19; 3 | 4 | contract Shuffle { 5 | struct Card { 6 | uint8 suit; // 1-4 7 | uint8 rank; // 1-13 8 | } 9 | 10 | Card[] public deck; 11 | 12 | constructor() { 13 | // Create a deck of cards 14 | for (uint8 suit = 1; suit <= 4; suit++) { 15 | for (uint8 rank = 1; rank <= 13; rank++) { 16 | deck.push(Card(suit, rank)); 17 | } 18 | } 19 | } 20 | 21 | function shuffle() public { 22 | uint256 deckSize = deck.length; 23 | for (uint256 i = 0; i < deckSize; i++) { 24 | uint256 j = uint256(keccak256(abi.encode(block.prevrandao, i))) % deckSize; 25 | Card memory tmpCard = deck[i]; 26 | deck[i] = deck[j]; 27 | deck[j] = tmpCard; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /contracts/StaggeredSale.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.21; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 5 | import "@openzeppelin/contracts/access/Ownable.sol"; 6 | 7 | contract StaggeredSale is ERC20, Ownable { 8 | uint public immutable deployedTimestamp; 9 | uint private immutable mintLimit = 90_000_000 * 10 ** decimals(); 10 | uint public saleMinted; 11 | uint public startDate; 12 | uint public endDate; 13 | uint startPricePerToken = 0.0001 ether; 14 | uint endPricePerToken = 0.00013 ether; 15 | bool tokenLive; 16 | event PublicSale(address to, uint amountReceived, uint ethContributed); 17 | 18 | constructor() ERC20("Staggered Sale Token", "SST") Ownable(msg.sender) { 19 | deployedTimestamp = block.timestamp; 20 | startDate = deployedTimestamp + 7 days; 21 | endDate = deployedTimestamp + 37 days; 22 | tokenLive = true; 23 | // mint team tokens 24 | _mint(msg.sender, 10_000_000 * 10 ** decimals()); 25 | tokenLive = false; 26 | } 27 | 28 | function pricePerDay(uint _day) public view returns (uint) { 29 | uint startDay = 0; 30 | uint endDay = (endDate - startDate) / 1 days; 31 | uint timeProgress = _day - startDay; 32 | uint totalDuration = endDay - startDay; 33 | uint priceProgress = ((endPricePerToken - startPricePerToken) * timeProgress) / totalDuration; 34 | uint currentPrice = startPricePerToken + priceProgress; 35 | return currentPrice; 36 | } 37 | 38 | function nextPriceUpdate() public view returns (uint, uint) { 39 | uint daysPassed = (block.timestamp - startDate) / 1 days; 40 | uint nextUpdateTS = startDate + ((daysPassed + 1) * 1 days); 41 | uint secondsLeft = nextUpdateTS - block.timestamp; 42 | uint nextPrice = pricePerDay(daysPassed + 1); 43 | return (secondsLeft, nextPrice); 44 | } 45 | 46 | function staggeredPublicSalePrice() public view returns (uint) { 47 | uint daysPassed = (block.timestamp - startDate) / 1 days; 48 | uint currentPrice = pricePerDay(daysPassed); 49 | return currentPrice; 50 | } 51 | 52 | // function not used but if you want to do a linear price increase this is how 53 | function linearPublicSalePrice() public view returns (uint) { 54 | uint timeProgress = block.timestamp - startDate; 55 | uint totalDuration = endDate - startDate; 56 | uint priceProgress = ((endPricePerToken - startPricePerToken) * timeProgress) / totalDuration; 57 | uint currentPrice = startPricePerToken + priceProgress; 58 | return currentPrice; 59 | } 60 | 61 | function buyTokens() external payable { 62 | require(block.timestamp > startDate, "too soon"); 63 | require(block.timestamp < endDate, "too late"); 64 | require(msg.value > 0.00001 ether, "min amount in not met"); 65 | uint _price = staggeredPublicSalePrice(); 66 | uint _amount = msg.value / _price * 10 ** decimals(); 67 | require(_amount > 0, "min amount out not met"); 68 | require(saleMinted + _amount < mintLimit, "sold out"); 69 | saleMinted += _amount; 70 | payable(owner()).transfer(msg.value); 71 | tokenLive = true; 72 | _mint(msg.sender, _amount); 73 | tokenLive = false; 74 | emit PublicSale(msg.sender, _amount, msg.value); 75 | } 76 | 77 | function goLive() external onlyOwner { 78 | require(block.timestamp > endDate, "too soon"); 79 | tokenLive = true; 80 | uint unsoldTokens = mintLimit - saleMinted; 81 | saleMinted += unsoldTokens; 82 | if (unsoldTokens > 0) 83 | _mint(owner(), unsoldTokens); 84 | } 85 | 86 | function _update(address from, address to, uint256 amount) internal override { 87 | require(tokenLive == true, "Token transfers not enabled yet"); 88 | super._update(from, to, amount); 89 | } 90 | } -------------------------------------------------------------------------------- /contracts/Structs.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | // Struct Structure Example 5 | contract Structural { 6 | struct Newb { 7 | string name; 8 | uint age; 9 | address addy; 10 | } 11 | Newb[] public newbies; // an array 12 | 13 | mapping (address => Newb) public newbs; // a mapping 14 | 15 | function addMe public () { 16 | newbies.push(Newb('James',21,msg.sender)); 17 | } 18 | 19 | function whatsMyAgeAgain public view returns(uint) { 20 | return newbies[0].age; 21 | } 22 | 23 | function remove(uint _i) public { 24 | delete newbies[_i]; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /contracts/TernaryOperators.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.21; 3 | 4 | contract TernaryOperators { 5 | 6 | function lowerValue(uint _a, uint _b) public pure returns (uint) { 7 | // (query ? true : false) 8 | uint value = (_a < _b ? _a : _b); 9 | return value; 10 | } 11 | 12 | } -------------------------------------------------------------------------------- /contracts/TransparentProxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; 5 | import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; 6 | 7 | contract ProxyDeployer { 8 | address public admin; 9 | address public proxy; 10 | constructor(address _implementation) { 11 | ProxyAdmin adminInstance = new ProxyAdmin(msg.sender); 12 | admin = address(adminInstance); 13 | TransparentUpgradeableProxy proxyInstance = new TransparentUpgradeableProxy(_implementation, admin, ""); 14 | proxy = address(proxyInstance); 15 | } 16 | } -------------------------------------------------------------------------------- /contracts/UintToString.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.17; 3 | 4 | contract UintToString { 5 | 6 | function uint2string(uint _i) internal pure returns (string memory str) { 7 | if (_i == 0) return "0"; 8 | uint j = _i; 9 | uint length; 10 | while (j != 0) { 11 | length++; 12 | j /= 10; 13 | } 14 | bytes memory bstr = new bytes(length); 15 | uint k = length; 16 | j = _i; 17 | while (j != 0) { 18 | bstr[--k] = bytes1(uint8(48 + j % 10)); 19 | j /= 10; 20 | } 21 | str = string(bstr); 22 | } 23 | 24 | function tokenURI(uint _tokenId) public pure returns (string memory) { 25 | return string.concat("https://jamesbachini.com/", uint2string(_tokenId), ".json"); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /contracts/Uniswap.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 5 | import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol'; 6 | 7 | contract SwapTokens { 8 | address public _uinswapV3RouterAddress = 0xE592427A0AEce92De3Edee1F18E0157C05861564; 9 | address private _daiAddress = 0x6B175474E89094C44Da98b954EedeAC495271d0F; 10 | address private _wethAddress = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; 11 | 12 | function buyWeth(uint amountUSD) internal { 13 | uint256 deadline = block.timestamp + 15; 14 | uint24 fee = 3000; 15 | address recipient = address(this); 16 | uint256 amountIn = amountUSD; // includes 18 decimals 17 | uint256 amountOutMinimum = 0; 18 | uint160 sqrtPriceLimitX96 = 0; 19 | require(IERC20(_daiAddress).approve(address(_uinswapV3RouterAddress), amountIn), 'DAI approve failed'); 20 | 21 | ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams( 22 | _daiAddress, 23 | _wethAddress, 24 | fee, 25 | recipient, 26 | deadline, 27 | amountIn, 28 | amountOutMinimum, 29 | sqrtPriceLimitX96 30 | ); 31 | ISwapRouter(_uinswapV3RouterAddress).exactInputSingle(params); 32 | } 33 | } -------------------------------------------------------------------------------- /contracts/UniswapFlashLoan.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.18; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 5 | 6 | interface IPool { 7 | function flash(address recipient, uint amount0, uint amount1, bytes calldata data) external; 8 | function token0() external view returns (address); 9 | function token1() external view returns (address); 10 | } 11 | 12 | interface IFactory { 13 | function getPool(address token0, address token1, uint24 fee) external view returns (address); 14 | } 15 | 16 | contract UniswapFlashLoan { 17 | address public pool; 18 | address public factory; 19 | address public token0; 20 | address public token1; 21 | uint public balanceCheck0; 22 | uint public balanceCheck1; 23 | 24 | constructor(address _token0, address _token1, uint24 _fee) { 25 | // 0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6, 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984, 3000 26 | factory = 0x1F98431c8aD98523631AE4a59f267346ea31F984; // Uniswap V3 Factory Contract 27 | pool = IFactory(factory).getPool(_token0, _token1, _fee); 28 | token0 = IPool(pool).token0(); // note they get swapped around 29 | token1 = IPool(pool).token1(); 30 | } 31 | 32 | function flashLoan(uint _token0Amount, uint _token1Amount) external { 33 | bytes memory data = abi.encode(_token0Amount, _token1Amount, msg.sender); 34 | IPool(pool).flash(address(this), _token0Amount, _token1Amount, data); 35 | } 36 | 37 | function uniswapV3FlashCallback(uint _fee0, uint _fee1, bytes calldata _data) external { 38 | require(msg.sender == address(pool), "Only Callback"); 39 | (uint token0Amount, uint token1Amount, address msgSender) = abi.decode(_data, (uint, uint, address)); 40 | // do something to generate enough to payback the loan and fee 41 | balanceCheck0 = IERC20(token0).balanceOf(address(this)); 42 | balanceCheck1 = IERC20(token1).balanceOf(address(this)); 43 | if (_fee0 > 0) IERC20(token0).transfer(address(pool), token0Amount + _fee0); 44 | if (_fee1 > 0) IERC20(token1).transfer(address(pool), token1Amount + _fee1); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /contracts/VCTerms.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | /* 5 | A contract designed for vested tokens with a flexible 6 | lockup and linear distribution period 7 | */ 8 | 9 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 10 | 11 | contract VCTerms { 12 | address public owner; 13 | mapping(address => uint) public contributed; 14 | mapping(address => uint) public claimed; 15 | uint public priceMultiplier = 100; // 100 tokens per ETH 16 | uint public cliffPeriodEnds; 17 | 18 | event Contribution(address user, uint amount); 19 | event Claim(address user, uint amount); 20 | 21 | constructor() { 22 | owner = msg.sender; 23 | cliffPeriodEnds = 1767139200; // End 2025 Unix Timestamp 24 | } 25 | 26 | function contribute() external payable { 27 | require(msg.value > 0, "Send some Eth"); 28 | contributed[msg.sender] += msg.value; 29 | emit Contribution(msg.sender, msg.value); 30 | } 31 | 32 | function checkClaim(address _user) public view returns (uint) { 33 | if (block.timestamp < cliffPeriodEnds) return 0; 34 | uint totalOwed = contributed[_user] * priceMultiplier; 35 | uint vestingPeriod = 156 weeks; 36 | uint secondsPassed = block.timestamp - cliffPeriodEnds; 37 | if (secondsPassed > vestingPeriod) secondsPassed = vestingPeriod; 38 | uint unlocked = totalOwed * secondsPassed / vestingPeriod; 39 | uint amountToClaim = unlocked - claimed[msg.sender]; 40 | return amountToClaim; 41 | } 42 | 43 | function claim(address _token) external returns (uint) { 44 | uint amountAvailable = checkClaim(msg.sender); 45 | require(amountAvailable > 0, "Nothing to claim"); 46 | claimed[msg.sender] += amountAvailable; 47 | IERC20(_token).transfer(msg.sender,amountAvailable); 48 | emit Claim(msg.sender, amountAvailable); 49 | return amountAvailable; 50 | } 51 | 52 | function claimToken(address _token) external { 53 | require(msg.sender == owner, "only owner has access"); 54 | uint balance = IERC20(_token).balanceOf(address(this)); 55 | IERC20(_token).transfer(msg.sender, balance); 56 | } 57 | 58 | function claimETH() external { 59 | require(msg.sender == owner, "only owner has access"); 60 | payable(msg.sender).transfer(address(this).balance); 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /contracts/Variables.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | contract Variables { 5 | uint256 public myUint; 6 | int256 public myInt; 7 | bool public myBool; 8 | address public myAddress; 9 | bytes32 public myBytes32; 10 | string public myString; 11 | uint256[] public myArray; 12 | 13 | enum State { INACTIVE, ACTIVE } 14 | State public myState = State.INACTIVE; 15 | 16 | struct Person { 17 | string username; 18 | uint256 age; 19 | } 20 | Person public myPerson; 21 | 22 | constructor() { 23 | myUint = 123; 24 | myInt = -456; 25 | myBool = true; 26 | myAddress = msg.sender; 27 | myBytes32 = 0x0; 28 | myString = "Hello, world!"; 29 | myArray = [1, 2, 3, 4, 5]; 30 | myPerson = Person("Alice", 30); 31 | } 32 | 33 | function setUint(uint256 _newValue) public { 34 | myUint = _newValue; 35 | } 36 | 37 | function setPerson(string memory _username, uint256 _age) public { 38 | myPerson = Person(_username, _age); 39 | } 40 | 41 | function addToArray(uint256 _newValue) public { 42 | myArray.push(_newValue); 43 | } 44 | } -------------------------------------------------------------------------------- /contracts/Vault.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 5 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 6 | 7 | contract Vault is ERC20 { 8 | IERC20 public immutable token; 9 | 10 | constructor(address _token) ERC20("Vault Receipt Token", "RECEIPT") { 11 | token = IERC20(_token); 12 | } 13 | 14 | function deposit(uint _amount) external { 15 | uint receiptTokens; 16 | if (totalSupply() == 0) { 17 | receiptTokens = _amount; 18 | } else { 19 | receiptTokens = (_amount * totalSupply()) / token.balanceOf(address(this)); 20 | } 21 | _mint(msg.sender, receiptTokens); 22 | token.transferFrom(msg.sender, address(this), _amount); 23 | } 24 | 25 | function withdraw(uint _receiptTokens) external { 26 | uint amount = (_receiptTokens * token.balanceOf(address(this))) / totalSupply(); 27 | _burn(msg.sender, _receiptTokens); 28 | token.transfer(msg.sender, amount); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /contracts/Whitelist.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.17; 3 | 4 | import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol"; 5 | 6 | contract Whitelist { 7 | address public test; 8 | bytes32 public merkleRoot; 9 | 10 | constructor(bytes32 _merkleRoot) { 11 | merkleRoot = _merkleRoot; 12 | } 13 | 14 | function claim(bytes32[] memory _proof, address _account) public { 15 | bytes32 leaf = keccak256(abi.encodePacked(_account)); 16 | require(MerkleProof.verify(_proof, merkleRoot, leaf), "Invalid proof"); 17 | test = _account; // whitelisted addresses can access this logic 18 | } 19 | } -------------------------------------------------------------------------------- /contracts/encodeCall.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.11; 3 | 4 | interface IERC20 { 5 | function transfer(address recipient, uint amount) external returns (bool); 6 | } 7 | 8 | contract encodeCall { 9 | function encodeCallData(address _to, uint _value) public pure returns (bytes memory) { 10 | return abi.encodeCall(IERC20.transfer, (_to, _value)); 11 | } 12 | } -------------------------------------------------------------------------------- /contracts/escrow.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract Escrow { 5 | 6 | struct Agreement { 7 | address bob; 8 | address alice; 9 | address arbitrator; 10 | uint amount; 11 | bool bobIn; 12 | bool aliceIn; 13 | } 14 | 15 | Agreement[] public agreements; 16 | 17 | function newAgreement(address _bob, address _alice, uint _amount) external returns (uint) { 18 | require(_bob != _alice, "same buyer and seller"); 19 | agreements.push(Agreement(_bob,_alice,msg.sender,_amount,false,false)); 20 | return agreements.length - 1; 21 | } 22 | 23 | function deposit(uint _id) external payable { 24 | if (msg.sender == agreements[_id].bob && msg.value == agreements[_id].amount) { 25 | agreements[_id].bobIn = true; 26 | } 27 | else if (msg.sender == agreements[_id].alice && msg.value == agreements[_id].amount) { 28 | agreements[_id].aliceIn = true; 29 | } 30 | } 31 | 32 | function refund(uint _id) external { 33 | if (msg.sender == agreements[_id].bob && agreements[_id].bobIn == true) { 34 | agreements[_id].bobIn = false; 35 | payable(agreements[_id].bob).transfer(agreements[_id].amount); 36 | } 37 | if (msg.sender == agreements[_id].alice && agreements[_id].aliceIn == true) { 38 | agreements[_id].aliceIn = false; 39 | payable(agreements[_id].alice).transfer(agreements[_id].amount); 40 | } 41 | } 42 | 43 | function complete(uint _id, address _winner) external { 44 | require(msg.sender == agreements[_id].arbitrator, "Only arbitrator can complete"); 45 | require(agreements[_id].bobIn == true, "Bob has not paid"); 46 | require(agreements[_id].aliceIn == true, "Alice has not paid"); 47 | 48 | if (agreements[_id].bob == _winner) { 49 | agreements[_id].bobIn = false; 50 | agreements[_id].aliceIn = false; 51 | payable(agreements[_id].bob).transfer(agreements[_id].amount * 2); 52 | } 53 | else if (agreements[_id].alice == _winner) { 54 | agreements[_id].bobIn = false; 55 | agreements[_id].aliceIn = false; 56 | payable(agreements[_id].alice).transfer(agreements[_id].amount * 2); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /hardhat.config.js: -------------------------------------------------------------------------------- 1 | require("@nomiclabs/hardhat-waffle"); 2 | 3 | // This is a sample Hardhat task. To learn how to create your own go to 4 | // https://hardhat.org/guides/create-task.html 5 | task("accounts", "Prints the list of accounts", async (taskArgs, hre) => { 6 | const accounts = await hre.ethers.getSigners(); 7 | 8 | for (const account of accounts) { 9 | console.log(account.address); 10 | } 11 | }); 12 | 13 | // You need to export an object to set up your config 14 | // Go to https://hardhat.org/config/ to learn more 15 | 16 | /** 17 | * @type import('hardhat/config').HardhatUserConfig 18 | */ 19 | module.exports = { 20 | solidity: "0.8.4", 21 | }; 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "solidity-snippets", 3 | "dependencies": { 4 | "@remix-project/remixd": "^0.6.9" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /scripts/merkleGenerator.js: -------------------------------------------------------------------------------- 1 | const {MerkleTree} = require("merkletreejs"); 2 | const keccak256 = require("keccak256"); 3 | const whitelist = ['0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef','0xBE0eB53F46cd790Cd13851d5EFf43D12404d33E8']; 4 | const leaves = whitelist.map(addr => keccak256(addr)); 5 | const merkleTree = new MerkleTree(leaves, keccak256, {sortPairs: true}); 6 | const rootHash = merkleTree.getRoot().toString('hex'); 7 | console.log(`Whitelist Merkle Root: 0x${rootHash}`); 8 | whitelist.forEach((address) => { 9 | const proof = merkleTree.getHexProof(keccak256(address)); 10 | console.log(`Adddress: ${address} Proof: ${proof}`); 11 | }); 12 | -------------------------------------------------------------------------------- /scripts/sample-script.js: -------------------------------------------------------------------------------- 1 | // We require the Hardhat Runtime Environment explicitly here. This is optional 2 | // but useful for running the script in a standalone fashion through `node 7 | 43 | 44 | -------------------------------------------------------------------------------- /test/sample-test.js: -------------------------------------------------------------------------------- 1 | const { expect } = require("chai"); 2 | const { ethers } = require("hardhat"); 3 | 4 | describe("Greeter", function () { 5 | it("Should return the new greeting once it's changed", async function () { 6 | const Greeter = await ethers.getContractFactory("Greeter"); 7 | const greeter = await Greeter.deploy("Hello, world!"); 8 | await greeter.deployed(); 9 | 10 | expect(await greeter.greet()).to.equal("Hello, world!"); 11 | 12 | const setGreetingTx = await greeter.setGreeting("Hola, mundo!"); 13 | 14 | // wait until the transaction is mined 15 | await setGreetingTx.wait(); 16 | 17 | expect(await greeter.greet()).to.equal("Hola, mundo!"); 18 | }); 19 | }); 20 | --------------------------------------------------------------------------------