├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── contracts ├── README.md ├── remappings.txt └── src │ ├── MerkleClaimERC20.sol │ └── test │ ├── MerkleClaimERC20.t.sol │ └── utils │ ├── MerkleClaimERC20Test.sol │ └── MerkleClaimERC20User.sol ├── frontend ├── .env.sample ├── .eslintrc.json ├── README.md ├── components │ ├── Footer.tsx │ ├── Header.tsx │ ├── Layout.tsx │ └── Meta.tsx ├── config.ts ├── next-env.d.ts ├── next.config.js ├── package-lock.json ├── package.json ├── pages │ ├── _app.tsx │ ├── _document.tsx │ ├── claim.tsx │ └── index.tsx ├── public │ ├── favicon.ico │ ├── icons │ │ ├── arrow.svg │ │ ├── discord.svg │ │ ├── github.svg │ │ ├── info.svg │ │ └── twitter.svg │ ├── logo.png │ └── meta.png ├── state │ ├── eth.ts │ ├── index.tsx │ └── token.ts ├── styles │ ├── components │ │ ├── Footer.module.scss │ │ ├── Header.module.scss │ │ └── Layout.module.scss │ ├── global.scss │ └── pages │ │ ├── Claim.module.scss │ │ └── Home.module.scss └── tsconfig.json └── generator ├── .eslintrc.json ├── .prettierrc.json ├── README.md ├── config.json ├── package-lock.json ├── package.json ├── src ├── app.ts ├── generator.ts └── utils │ └── logger.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Misc 2 | .DS_Store 3 | 4 | # Contracts 5 | contracts/cache 6 | contracts/out 7 | 8 | # Generator 9 | generator/node_modules 10 | generator/dist 11 | generator/*.log 12 | generator/merkle.json 13 | 14 | # Frontend 15 | frontend/.env.local 16 | frontend/node_modules 17 | frontend/out 18 | frontend/.next 19 | frontend/.vercel -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "contracts/lib/ds-test"] 2 | path = contracts/lib/ds-test 3 | url = https://github.com/dapphub/ds-test 4 | [submodule "contracts/lib/solmate"] 5 | path = contracts/lib/solmate 6 | url = https://github.com/rari-capital/solmate 7 | [submodule "contracts/lib/openzeppelin-contracts"] 8 | path = contracts/lib/openzeppelin-contracts 9 | url = https://github.com/OpenZeppelin/openzeppelin-contracts 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 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 Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Merkle Airdrop Starter 2 | 3 | Quickly bootstrap an ERC20 token airdrop to a Merkle tree of recipients. 4 | 5 | Steps: 6 | 7 | 1. Generate Merkle tree of recipients by following README in [generator/](https://github.com/Anish-Agnihotri/merkle-airdrop-starter/tree/master/generator) 8 | 2. Setup and deploy MerkleClaimERC20 contracts by following README in [contracts/](https://github.com/Anish-Agnihotri/merkle-airdrop-starter/tree/master/contracts) 9 | 3. Setup and deploy front-end by following README in [frontend/](https://github.com/Anish-Agnihotri/merkle-airdrop-starter/tree/master/frontend) 10 | 11 | ## Similar work and credits 12 | 13 | - [Astrodrop](https://astrodrop.xyz/)—Simpler way to spin up a airdrop with claim page, given existing token 14 | - [Uniswap Merkle Distributor](https://github.com/Uniswap/merkle-distributor)—Uniswap's merkle distribution smart contracts 15 | 16 | ## License 17 | 18 | [GNU Affero GPL v3.0](https://github.com/Anish-Agnihotri/merkle-airdrop-starter/blob/master/LICENSE) 19 | 20 | ## Disclaimer 21 | 22 | _These smart contracts are being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of the user interface or the smart contracts. They have not been audited and as such there can be no assurance they will work as intended, and users may experience delays, failures, errors, omissions or loss of transmitted information. Anish Agnihotri is not liable for any of the foregoing. Users should proceed with caution and use at their own risk._ 23 | -------------------------------------------------------------------------------- /contracts/README.md: -------------------------------------------------------------------------------- 1 | # MerkleClaimERC20 2 | 3 | ERC20 token claimable by members of a [Merkle tree](https://en.wikipedia.org/wiki/Merkle_tree). Useful for conducting Airdrops. Utilizes [Solmate ERC20](https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC20.sol) for modern ERC20 token implementation. 4 | 5 | ## Test 6 | 7 | Tests use [Foundry: Forge](https://github.com/gakonst/foundry). 8 | 9 | Install Foundry using the installation steps in the README of the linked repo. 10 | 11 | ### Run tests 12 | 13 | ```bash 14 | # Go to contracts directory, if not already there 15 | cd contracts/ 16 | 17 | # Get dependencies 18 | forge update 19 | 20 | # Run tests 21 | forge test --root . 22 | # Run tests with stack traces 23 | forge test --root . -vvvv 24 | ``` 25 | 26 | ## Deploy 27 | 28 | Follow the `forge create` instructions ([CLI README](https://github.com/gakonst/foundry/blob/master/cli/README.md#build)) to deploy your contracts or use [Remix](https://remix.ethereum.org/). 29 | 30 | You can specify the token `name`, `symbol`, `decimals`, and airdrop `merkleRoot` upon deploy. 31 | 32 | ## Credits 33 | 34 | - [@brockelmore](https://github.com/Anish-Agnihotri/merkle-airdrop-starter/issues?q=is%3Apr+author%3Abrockelmore) for [#1](https://github.com/Anish-Agnihotri/merkle-airdrop-starter/pull/1) 35 | - [@transmissions11](https://github.com/Anish-Agnihotri/merkle-airdrop-starter/issues?q=is%3Apr+author%3Atransmissions11) for [#2](https://github.com/Anish-Agnihotri/merkle-airdrop-starter/pull/2) 36 | - [@devanonon](https://github.com/Anish-Agnihotri/merkle-airdrop-starter/issues?q=is%3Apr+author%3Adevanonon) for [#3](https://github.com/Anish-Agnihotri/merkle-airdrop-starter/pull/8) 37 | -------------------------------------------------------------------------------- /contracts/remappings.txt: -------------------------------------------------------------------------------- 1 | ds-test/=lib/ds-test/src/ 2 | @solmate/=lib/solmate/src/ 3 | @openzeppelin/=lib/openzeppelin-contracts/contracts/ -------------------------------------------------------------------------------- /contracts/src/MerkleClaimERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0; 3 | 4 | /// ============ Imports ============ 5 | 6 | import { ERC20 } from "@solmate/tokens/ERC20.sol"; // Solmate: ERC20 7 | import { MerkleProof } from "@openzeppelin/utils/cryptography/MerkleProof.sol"; // OZ: MerkleProof 8 | 9 | /// @title MerkleClaimERC20 10 | /// @notice ERC20 claimable by members of a merkle tree 11 | /// @author Anish Agnihotri 12 | /// @dev Solmate ERC20 includes unused _burn logic that can be removed to optimize deployment cost 13 | contract MerkleClaimERC20 is ERC20 { 14 | 15 | /// ============ Immutable storage ============ 16 | 17 | /// @notice ERC20-claimee inclusion root 18 | bytes32 public immutable merkleRoot; 19 | 20 | /// ============ Mutable storage ============ 21 | 22 | /// @notice Mapping of addresses who have claimed tokens 23 | mapping(address => bool) public hasClaimed; 24 | 25 | /// ============ Errors ============ 26 | 27 | /// @notice Thrown if address has already claimed 28 | error AlreadyClaimed(); 29 | /// @notice Thrown if address/amount are not part of Merkle tree 30 | error NotInMerkle(); 31 | 32 | /// ============ Constructor ============ 33 | 34 | /// @notice Creates a new MerkleClaimERC20 contract 35 | /// @param _name of token 36 | /// @param _symbol of token 37 | /// @param _decimals of token 38 | /// @param _merkleRoot of claimees 39 | constructor( 40 | string memory _name, 41 | string memory _symbol, 42 | uint8 _decimals, 43 | bytes32 _merkleRoot 44 | ) ERC20(_name, _symbol, _decimals) { 45 | merkleRoot = _merkleRoot; // Update root 46 | } 47 | 48 | /// ============ Events ============ 49 | 50 | /// @notice Emitted after a successful token claim 51 | /// @param to recipient of claim 52 | /// @param amount of tokens claimed 53 | event Claim(address indexed to, uint256 amount); 54 | 55 | /// ============ Functions ============ 56 | 57 | /// @notice Allows claiming tokens if address is part of merkle tree 58 | /// @param to address of claimee 59 | /// @param amount of tokens owed to claimee 60 | /// @param proof merkle proof to prove address and amount are in tree 61 | function claim(address to, uint256 amount, bytes32[] calldata proof) external { 62 | // Throw if address has already claimed tokens 63 | if (hasClaimed[to]) revert AlreadyClaimed(); 64 | 65 | // Verify merkle proof, or revert if not in tree 66 | bytes32 leaf = keccak256(abi.encodePacked(to, amount)); 67 | bool isValidLeaf = MerkleProof.verify(proof, merkleRoot, leaf); 68 | if (!isValidLeaf) revert NotInMerkle(); 69 | 70 | // Set address to claimed 71 | hasClaimed[to] = true; 72 | 73 | // Mint tokens to address 74 | _mint(to, amount); 75 | 76 | // Emit claim event 77 | emit Claim(to, amount); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /contracts/src/test/MerkleClaimERC20.t.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Unlicense 2 | pragma solidity >=0.8.0; 3 | 4 | /// ============ Imports ============ 5 | 6 | import { MerkleClaimERC20Test } from "./utils/MerkleClaimERC20Test.sol"; // Test scaffolding 7 | 8 | /// @title Tests 9 | /// @notice MerkleClaimERC20 tests 10 | /// @author Anish Agnihotri 11 | contract Tests is MerkleClaimERC20Test { 12 | /// @notice Allow Alice to claim 100e18 tokens 13 | function testAliceClaim() public { 14 | // Setup correct proof for Alice 15 | bytes32[] memory aliceProof = new bytes32[](1); 16 | aliceProof[0] = 0xceeae64152a2deaf8c661fccd5645458ba20261b16d2f6e090fe908b0ac9ca88; 17 | 18 | // Collect Alice balance of tokens before claim 19 | uint256 alicePreBalance = ALICE.tokenBalance(); 20 | 21 | // Claim tokens 22 | ALICE.claim( 23 | // Claiming for Alice 24 | address(ALICE), 25 | // 100 tokens 26 | 100e18, 27 | // With valid proof 28 | aliceProof 29 | ); 30 | 31 | // Collect Alice balance of tokens after claim 32 | uint256 alicePostBalance = ALICE.tokenBalance(); 33 | 34 | // Assert Alice balance before + 100 tokens = after balance 35 | assertEq(alicePostBalance, alicePreBalance + 100e18); 36 | } 37 | 38 | /// @notice Prevent Alice from claiming twice 39 | function testFailAliceClaimTwice() public { 40 | // Setup correct proof for Alice 41 | bytes32[] memory aliceProof = new bytes32[](1); 42 | aliceProof[0] = 0xceeae64152a2deaf8c661fccd5645458ba20261b16d2f6e090fe908b0ac9ca88; 43 | 44 | // Claim tokens 45 | ALICE.claim( 46 | // Claiming for Alice 47 | address(ALICE), 48 | // 100 tokens 49 | 100e18, 50 | // With valid proof 51 | aliceProof 52 | ); 53 | 54 | // Claim tokens again 55 | ALICE.claim( 56 | // Claiming for Alice 57 | address(ALICE), 58 | // 100 tokens 59 | 100e18, 60 | // With valid proof 61 | aliceProof 62 | ); 63 | } 64 | 65 | /// @notice Prevent Alice from claiming with invalid proof 66 | function testFailAliceClaimInvalidProof() public { 67 | // Setup incorrect proof for Alice 68 | bytes32[] memory aliceProof = new bytes32[](1); 69 | aliceProof[0] = 0xc11ae64152a2deaf8c661fccd5645458ba20261b16d2f6e090fe908b0ac9ca88; 70 | 71 | // Claim tokens 72 | ALICE.claim( 73 | // Claiming for Alice 74 | address(ALICE), 75 | // 100 tokens 76 | 100e18, 77 | // With valid proof 78 | aliceProof 79 | ); 80 | } 81 | 82 | /// @notice Prevent Alice from claiming with invalid amount 83 | function testFailAliceClaimInvalidAmount() public { 84 | // Setup correct proof for Alice 85 | bytes32[] memory aliceProof = new bytes32[](1); 86 | aliceProof[0] = 0xceeae64152a2deaf8c661fccd5645458ba20261b16d2f6e090fe908b0ac9ca88; 87 | 88 | // Claim tokens 89 | ALICE.claim( 90 | // Claiming for Alice 91 | address(ALICE), 92 | // Incorrect: 1000 tokens 93 | 1000e18, 94 | // With valid proof (for 100 tokens) 95 | aliceProof 96 | ); 97 | } 98 | 99 | /// @notice Prevent Bob from claiming 100 | function testFailBobClaim() public { 101 | // Setup correct proof for Alice 102 | bytes32[] memory aliceProof = new bytes32[](1); 103 | aliceProof[0] = 0xceeae64152a2deaf8c661fccd5645458ba20261b16d2f6e090fe908b0ac9ca88; 104 | 105 | // Claim tokens 106 | BOB.claim( 107 | // Claiming for Bob 108 | address(BOB), 109 | // 100 tokens 110 | 100e18, 111 | // With valid proof (for Alice) 112 | aliceProof 113 | ); 114 | } 115 | 116 | /// @notice Let Bob claim on behalf of Alice 117 | function testBobClaimForAlice() public { 118 | // Setup correct proof for Alice 119 | bytes32[] memory aliceProof = new bytes32[](1); 120 | aliceProof[0] = 0xceeae64152a2deaf8c661fccd5645458ba20261b16d2f6e090fe908b0ac9ca88; 121 | 122 | // Collect Alice balance of tokens before claim 123 | uint256 alicePreBalance = ALICE.tokenBalance(); 124 | 125 | // Claim tokens 126 | BOB.claim( 127 | // Claiming for Alice 128 | address(ALICE), 129 | // 100 tokens 130 | 100e18, 131 | // With valid proof (for Alice) 132 | aliceProof 133 | ); 134 | 135 | // Collect Alice balance of tokens after claim 136 | uint256 alicePostBalance = ALICE.tokenBalance(); 137 | 138 | // Assert Alice balance before + 100 tokens = after balance 139 | assertEq(alicePostBalance, alicePreBalance + 100e18); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /contracts/src/test/utils/MerkleClaimERC20Test.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0; 3 | 4 | /// ============ Imports ============ 5 | 6 | import { DSTest } from "ds-test/test.sol"; // DSTest 7 | import { MerkleClaimERC20 } from "../../MerkleClaimERC20.sol"; // MerkleClaimERC20 8 | import { MerkleClaimERC20User } from "./MerkleClaimERC20User.sol"; // MerkleClaimERC20 user 9 | 10 | /// @title MerkleClaimERC20Test 11 | /// @notice Scaffolding for MerkleClaimERC20 tests 12 | /// @author Anish Agnihotri 13 | contract MerkleClaimERC20Test is DSTest { 14 | 15 | /// ============ Storage ============ 16 | 17 | /// @dev MerkleClaimERC20 contract 18 | MerkleClaimERC20 internal TOKEN; 19 | /// @dev User: Alice (in merkle tree) 20 | MerkleClaimERC20User internal ALICE; 21 | /// @dev User: Bob (not in merkle tree) 22 | MerkleClaimERC20User internal BOB; 23 | 24 | /// ============ Setup test suite ============ 25 | 26 | function setUp() public virtual { 27 | // Create airdrop token 28 | TOKEN = new MerkleClaimERC20( 29 | "My Token", 30 | "MT", 31 | 18, 32 | // Merkle root containing ALICE with 100e18 tokens but no BOB 33 | 0xd0aa6a4e5b4e13462921d7518eebdb7b297a7877d6cfe078b0c318827392fb55 34 | ); 35 | 36 | // Setup airdrop users 37 | ALICE = new MerkleClaimERC20User(TOKEN); // 0x185a4dc360ce69bdccee33b3784b0282f7961aea 38 | BOB = new MerkleClaimERC20User(TOKEN); // 0xefc56627233b02ea95bae7e19f648d7dcd5bb132 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /contracts/src/test/utils/MerkleClaimERC20User.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0; 3 | 4 | /// ============ Imports ============ 5 | 6 | import { MerkleClaimERC20 } from "../../MerkleClaimERC20.sol"; // MerkleClaimERC20 7 | 8 | /// @title MerkleClaimERC20User 9 | /// @notice Mock MerkleClaimERC20 user 10 | /// @author Anish Agnihotri 11 | contract MerkleClaimERC20User { 12 | 13 | /// ============ Immutable storage ============ 14 | 15 | /// @dev MerkleClaimERC20 contract 16 | MerkleClaimERC20 immutable internal TOKEN; 17 | 18 | /// ============ Constructor ============ 19 | 20 | /// @notice Creates a new MerkleClaimERC20User 21 | /// @param _TOKEN MerkleClaimERC20 contract 22 | constructor(MerkleClaimERC20 _TOKEN) { 23 | TOKEN = _TOKEN; 24 | } 25 | 26 | /// ============ Helper functions ============ 27 | 28 | /// @notice Returns users' token balance 29 | function tokenBalance() public view returns (uint256) { 30 | return TOKEN.balanceOf(address(this)); 31 | } 32 | 33 | /// ============ Inherited functionality ============ 34 | 35 | /// @notice Allows user to claim tokens from contract 36 | /// @param to address of claimee 37 | /// @param amount of tokens owed to claimee 38 | /// @param proof merkle proof to prove address and amount are in tree 39 | function claim(address to, uint256 amount, bytes32[] calldata proof) public { 40 | TOKEN.claim(to, amount, proof); 41 | } 42 | } -------------------------------------------------------------------------------- /frontend/.env.sample: -------------------------------------------------------------------------------- 1 | # Logo 2 | NEXT_PUBLIC_LOGO_PATH="/logo.png" 3 | 4 | # Home page 5 | NEXT_PUBLIC_URL="http://localhost:3000/" 6 | NEXT_PUBLIC_TOKEN_NAME="ΞTOKEN" 7 | NEXT_PUBLIC_HEADING="Some heading about airdrop" 8 | NEXT_PUBLIC_DESCRIPTION="Some incredibly long description about airdrop that tells the reader what they stand to benefit by spending their ETH, paying gas, and claiming your airdrop." 9 | 10 | # Social links 11 | NEXT_PUBLIC_DISCORD="https://discord.gg/" 12 | NEXT_PUBLIC_TWITTER="https://twitter.com/" 13 | NEXT_PUBLIC_ARTICLE="https://mirror.xyz/" 14 | NEXT_PUBLIC_GITHUB="https://github.com/" 15 | 16 | # Functionality 17 | NEXT_PUBLIC_CONTRACT_ADDRESS="0x..." 18 | NEXT_PUBLIC_RPC_NETWORK="4" 19 | NEXT_PUBLIC_RPC_URL="https://eth-rinkeby.alchemyapi.io/v2/your_api_key" -------------------------------------------------------------------------------- /frontend/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /frontend/README.md: -------------------------------------------------------------------------------- 1 | # frontend 2 | 3 | Accompanies [MerkleDropERC20](https://github.com/Anish-Agnihotri/merkle-airdrop-starter/tree/master/contracts) contracts; heavy similarity to the [GAS DAO airdrop frontend](https://www.gasdao.org/) (GAS DAO: implemented by [sax](https://twitter.com/0xsaxophone), originally inspired by work from [design @ens](https://twitter.com/dzneth) for the [$ENS airdrop claim](https://claim.ens.domains/)). 4 | 5 | Allows users to connect their wallet and claim airdrops, given they are part of the Merkle tree. 6 | 7 | ## Run + deploy 8 | 9 | The frontend is built to be fully configurable and ready-to-go in under 10 minutes of dev time. Steps to customize and deploy: 10 | 11 | 1. Modify `config.ts:L9` with exact config from `generator/config.json` 12 | 2. Copy environment variables (`cp .env.sample .env.local`) and modify parameters 13 | 3. Update the `logo.png` (recommended: 250x250) and `meta.png` (recommended: 1200x637) in `public/` 14 | 4. Then, `npm install` (install dependencies) and `npm run dev` to run development build 15 | -------------------------------------------------------------------------------- /frontend/components/Footer.tsx: -------------------------------------------------------------------------------- 1 | import Image from "next/image"; // Images 2 | import styles from "styles/components/Footer.module.scss"; // Component styles 3 | 4 | /** 5 | * Links to render in footer 6 | * @dev Does not render any links where url is undefined, allowing conditional rendering 7 | */ 8 | const footerLinks: { icon: string; url: string | undefined }[] = [ 9 | // Discord 10 | { icon: "/icons/discord.svg", url: process.env.NEXT_PUBLIC_DISCORD }, 11 | // Twitter 12 | { icon: "/icons/twitter.svg", url: process.env.NEXT_PUBLIC_TWITTER }, 13 | // Github 14 | { icon: "/icons/github.svg", url: process.env.NEXT_PUBLIC_GITHUB }, 15 | ]; 16 | 17 | export default function Footer() { 18 | return ( 19 |
20 | {footerLinks.map(({ icon, url }, i) => { 21 | // For each link in footer that is valid 22 | return url ? ( 23 | // Render link with icon image 24 | 25 | Social link 26 | 27 | ) : null; 28 | })} 29 |
30 | ); 31 | } 32 | -------------------------------------------------------------------------------- /frontend/components/Header.tsx: -------------------------------------------------------------------------------- 1 | import Link from "next/link"; // Dynamic routing 2 | import Image from "next/image"; // Images 3 | import { eth } from "state/eth"; // Global state 4 | import { useState } from "react"; // State management 5 | import styles from "styles/components/Header.module.scss"; // Component styles 6 | 7 | /** 8 | * Links to render in action menu 9 | * @dev Does not render any links where url is undefined, allowing conditional rendering 10 | */ 11 | const actionMenuLinks: { 12 | name: string; 13 | icon: string; 14 | url: string | undefined; 15 | }[] = [ 16 | { 17 | name: "About", 18 | icon: "/icons/info.svg", 19 | url: process.env.NEXT_PUBLIC_ARTICLE, 20 | }, 21 | { 22 | name: "Discord", 23 | icon: "/icons/discord.svg", 24 | url: process.env.NEXT_PUBLIC_DISCORD, 25 | }, 26 | { 27 | name: "Twitter", 28 | icon: "/icons/twitter.svg", 29 | url: process.env.NEXT_PUBLIC_TWITTER, 30 | }, 31 | { 32 | name: "GitHub", 33 | icon: "/icons/github.svg", 34 | url: process.env.NEXT_PUBLIC_GITHUB, 35 | }, 36 | ]; 37 | 38 | // Three dots image data (for second button) 39 | const threeDotsImage: string = 40 | "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEwAAC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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAmNr/A6j+W3ud4rC/AAAAAElFTkSuQmCC"; 41 | 42 | export default function Header() { 43 | // Global state 44 | const { address, unlock }: { address: string | null; unlock: Function } = 45 | eth.useContainer(); 46 | // Action menu open state 47 | const [menuOpen, setMenuOpen] = useState(false); 48 | 49 | return ( 50 |
51 | {/* Logo */} 52 |
53 | 54 | 55 | Logo 56 | 57 | 58 |
59 | 60 | {/* Auth + details */} 61 |
62 | {/* Unlock button */} 63 | 71 | 72 | {/* Actions button */} 73 | 77 |
78 | 79 | {menuOpen ? ( 80 | // Render actions menu if open 81 |
82 | {actionMenuLinks.map(({ name, icon, url }, i) => { 83 | // For each link with a defined url 84 | return url ? ( 85 | // Render action link containing name and image 86 | 87 | {name} 88 | {`${name} 89 | 90 | ) : null; 91 | })} 92 |
93 | ) : null} 94 |
95 | ); 96 | } 97 | -------------------------------------------------------------------------------- /frontend/components/Layout.tsx: -------------------------------------------------------------------------------- 1 | import Meta from "components/Meta"; // Components: Meta 2 | import Header from "components/Header"; // Components: Header 3 | import Footer from "components/Footer"; // Components: Footer 4 | import type { ReactElement } from "react"; // Types 5 | import styles from "styles/components/Layout.module.scss"; // Component styles 6 | 7 | export default function Layout({ 8 | children, 9 | }: { 10 | children: ReactElement | ReactElement[]; 11 | }) { 12 | return ( 13 | // Layout wrapper 14 |
15 | {/* Site meta */} 16 | 17 | 18 | {/* Global header */} 19 |
20 | 21 | {/* Injected child content */} 22 |
{children}
23 | 24 | {/* Global footer */} 25 |
26 |
27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /frontend/components/Meta.tsx: -------------------------------------------------------------------------------- 1 | import Head from "next/head"; // HTML Head 2 | 3 | // Setup project details 4 | const url: string = process.env.NEXT_PUBLIC_URL ?? "https://token.com/"; 5 | const tokenName: string = process.env.NEXT_PUBLIC_TOKEN_NAME ?? "Token Name"; 6 | const description: string = 7 | process.env.NEXT_PUBLIC_DESCRIPTION ?? "Some description"; 8 | 9 | export default function Meta() { 10 | return ( 11 | 12 | {/* Fonts: Inter */} 13 | 14 | 19 | 23 | 24 | {/* Primary Meta */} 25 | {tokenName} 26 | 27 | 28 | 29 | {/* Open Graph + Facebook */} 30 | 31 | 32 | 33 | 34 | 35 | 36 | {/* Twitter */} 37 | 38 | 39 | 40 | 41 | 42 | 43 | {/* Favicon */} 44 | 45 | 46 | ); 47 | } 48 | -------------------------------------------------------------------------------- /frontend/config.ts: -------------------------------------------------------------------------------- 1 | // Types 2 | type IConfig = { 3 | decimals: number; 4 | airdrop: Record; 5 | }; 6 | 7 | // Config from generator 8 | const config: IConfig = { 9 | decimals: 18, 10 | airdrop: { 11 | "0x016C8780e5ccB32E5CAA342a926794cE64d9C364": 10, 12 | "0x185a4dc360ce69bdccee33b3784b0282f7961aea": 100, 13 | }, 14 | }; 15 | 16 | // Export config 17 | export default config; 18 | -------------------------------------------------------------------------------- /frontend/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /frontend/next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | module.exports = { 3 | reactStrictMode: true, 4 | }; 5 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "bnc-onboard": "^1.37.0", 13 | "ethers": "^5.5.2", 14 | "keccak256": "^1.0.6", 15 | "merkletreejs": "^0.2.27", 16 | "next": "12.0.7", 17 | "react": "17.0.2", 18 | "react-dom": "17.0.2", 19 | "sass": "^1.45.1", 20 | "unstated-next": "^1.1.0" 21 | }, 22 | "devDependencies": { 23 | "@types/react": "17.0.38", 24 | "eslint": "8.5.0", 25 | "eslint-config-next": "12.0.7", 26 | "typescript": "4.5.4" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /frontend/pages/_app.tsx: -------------------------------------------------------------------------------- 1 | import "styles/global.scss"; // Global styles 2 | import StateProvider from "state"; // Global state provider 3 | import type { AppProps } from "next/app"; // Types 4 | 5 | // Export application 6 | export default function MerkleAirdropStarter({ 7 | Component, 8 | pageProps, 9 | }: AppProps) { 10 | return ( 11 | // Wrap application in global state provider 12 | 13 | 14 | 15 | ); 16 | } 17 | -------------------------------------------------------------------------------- /frontend/pages/_document.tsx: -------------------------------------------------------------------------------- 1 | // Document imports 2 | import Document, { 3 | DocumentContext, 4 | Html, 5 | Head, 6 | Main, 7 | NextScript, 8 | } from "next/document"; 9 | 10 | // Custom document class 11 | export default class MyDocument extends Document { 12 | // Collect and return props 13 | static async getInitialProps(ctx: DocumentContext) { 14 | const initialProps = await Document.getInitialProps(ctx); 15 | return { ...initialProps }; 16 | } 17 | 18 | render() { 19 | return ( 20 | // Wrap in html with custom lang param 21 | 22 | {/* Preload head */} 23 | 24 | 25 |
26 | 27 | 28 | 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /frontend/pages/claim.tsx: -------------------------------------------------------------------------------- 1 | import { eth } from "state/eth"; // Global state: ETH 2 | import { useState } from "react"; // State management 3 | import { token } from "state/token"; // Global state: Tokens 4 | import Layout from "components/Layout"; // Layout wrapper 5 | import styles from "styles/pages/Claim.module.scss"; // Page styles 6 | 7 | export default function Claim() { 8 | // Global ETH state 9 | const { address, unlock }: { address: string | null; unlock: Function } = 10 | eth.useContainer(); 11 | // Global token state 12 | const { 13 | dataLoading, 14 | numTokens, 15 | alreadyClaimed, 16 | claimAirdrop, 17 | }: { 18 | dataLoading: boolean; 19 | numTokens: number; 20 | alreadyClaimed: boolean; 21 | claimAirdrop: Function; 22 | } = token.useContainer(); 23 | // Local button loading 24 | const [buttonLoading, setButtonLoading] = useState(false); 25 | 26 | /** 27 | * Claims airdrop with local button loading 28 | */ 29 | const claimWithLoading = async () => { 30 | setButtonLoading(true); // Toggle 31 | await claimAirdrop(); // Claim 32 | setButtonLoading(false); // Toggle 33 | }; 34 | 35 | return ( 36 | 37 |
38 | {!address ? ( 39 | // Not authenticated 40 |
41 |

You are not authenticated.

42 |

Please connect with your wallet to check your airdrop.

43 | 44 |
45 | ) : dataLoading ? ( 46 | // Loading details about address 47 |
48 |

Loading airdrop details...

49 |

Please hold while we collect details about your address.

50 |
51 | ) : numTokens == 0 ? ( 52 | // Not part of airdrop 53 |
54 |

You do not qualify.

55 |

Unfortunately, your address does not qualify for the airdrop.

56 |
57 | ) : alreadyClaimed ? ( 58 | // Already claimed airdrop 59 |
60 |

Already claimed.

61 |

62 | Your address ({address}) has already claimed {numTokens} tokens. 63 |

64 |
65 | ) : ( 66 | // Claim your airdrop 67 |
68 |

Claim your airdrop.

69 |

Your address qualifies for {numTokens} tokens.

70 | 73 |
74 | )} 75 |
76 |
77 | ); 78 | } 79 | -------------------------------------------------------------------------------- /frontend/pages/index.tsx: -------------------------------------------------------------------------------- 1 | import Image from "next/image"; // Images 2 | import { eth } from "state/eth"; // State container 3 | import Layout from "components/Layout"; // Layout wrapper 4 | import { useRouter } from "next/router"; // Routing 5 | import styles from "styles/pages/Home.module.scss"; // Page styles 6 | 7 | // Setup project details 8 | const tokenName: string = process.env.NEXT_PUBLIC_TOKEN_NAME ?? "Token Name"; 9 | const heading: string = process.env.NEXT_PUBLIC_HEADING ?? "Some heading"; 10 | const description: string = 11 | process.env.NEXT_PUBLIC_DESCRIPTION ?? "Some description"; 12 | 13 | export default function Home() { 14 | // Routing 15 | const { push } = useRouter(); 16 | // Authentication status 17 | const { address }: { address: string | null } = eth.useContainer(); 18 | 19 | return ( 20 | 21 |
22 | {/* Project logo */} 23 |
24 | Logo 25 |
26 | 27 | {/* Project introduction article, if it exists */} 28 | {process.env.NEXT_PUBLIC_ARTICLE ? ( 29 | 34 | Introducing {tokenName}{" "} 35 | Arrow 36 | 37 | ) : null} 38 | 39 | {/* Project heading */} 40 |

{heading}

41 | 42 | {/* Project description */} 43 |

{description}

44 | 45 | {/* Claim button */} 46 | {!address ? ( 47 | // If not authenticated, disabled 48 | 49 | ) : ( 50 | // Else, reroute to /claim 51 | 52 | )} 53 |
54 |
55 | ); 56 | } 57 | -------------------------------------------------------------------------------- /frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Anish-Agnihotri/merkle-airdrop-starter/b5fad7cb1cf4da27812011a71e8f1dec419028c7/frontend/public/favicon.ico -------------------------------------------------------------------------------- /frontend/public/icons/arrow.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/icons/discord.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/icons/github.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/icons/info.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/icons/twitter.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Anish-Agnihotri/merkle-airdrop-starter/b5fad7cb1cf4da27812011a71e8f1dec419028c7/frontend/public/logo.png -------------------------------------------------------------------------------- /frontend/public/meta.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Anish-Agnihotri/merkle-airdrop-starter/b5fad7cb1cf4da27812011a71e8f1dec419028c7/frontend/public/meta.png -------------------------------------------------------------------------------- /frontend/state/eth.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from "ethers"; // Ethers 2 | import Onboard from "bnc-onboard"; // Onboard.js 3 | import { useEffect, useState } from "react"; // React 4 | import { createContainer } from "unstated-next"; // State management 5 | 6 | // Types 7 | import type { 8 | API, 9 | WalletInitOptions, 10 | WalletModule, 11 | } from "bnc-onboard/dist/src/interfaces"; 12 | import type { Web3Provider } from "@ethersproject/providers"; 13 | 14 | // Network 15 | const networkId = process.env.NEXT_PUBLIC_RPC_NETWORK 16 | ? // Use network 17 | Number(process.env.NEXT_PUBLIC_RPC_NETWORK) 18 | : // Else, default to Rinkeby 19 | 4; 20 | 21 | // Onboard.js wallet providers 22 | const wallets: (WalletModule | WalletInitOptions)[] = [ 23 | { walletName: "metamask" }, 24 | { 25 | walletName: "walletConnect", 26 | networkId, 27 | rpc: { 28 | [networkId]: process.env.NEXT_PUBLIC_RPC_URL ?? "", 29 | }, 30 | }, 31 | ]; 32 | 33 | // Token name 34 | const tokenName: string = process.env.NEXT_PUBLIC_TOKEN_NAME ?? "Token Name"; 35 | 36 | /** 37 | * Provides functionality for Eth account/state management 38 | */ 39 | function useEth() { 40 | const [address, setAddress] = useState(null); // User address 41 | const [onboard, setOnboard] = useState(null); // Onboard provider 42 | const [provider, setProvider] = useState(null); // Ethers provider 43 | 44 | /** 45 | * Unlock wallet, store ethers provider and address 46 | */ 47 | const unlock = async () => { 48 | // Enables wallet selection via BNC onboard 49 | if (onboard) { 50 | // Initialize wallet 51 | const walletSelected: boolean = await onboard.walletSelect(); 52 | // If initialized, ready wallet 53 | if (walletSelected) { 54 | await onboard.walletCheck(); 55 | } 56 | } 57 | }; 58 | 59 | /** 60 | * Initialize onboard instance and store 61 | */ 62 | const initializeOnboard = () => { 63 | // Onboard provider 64 | const onboard = Onboard({ 65 | networkId, 66 | // Hide Blocknative branding 67 | hideBranding: true, 68 | // Setup custom wallets for selection 69 | walletSelect: { 70 | heading: `Connect to ${tokenName}`, 71 | description: `Please select a wallet to authenticate with ${tokenName}.`, 72 | wallets: wallets, 73 | }, 74 | // Track subscriptions 75 | subscriptions: { 76 | // On address update 77 | address: async (address) => { 78 | // Update address 79 | setAddress(address); 80 | // If no address, nullify provider 81 | if (!address) { 82 | setProvider(null); 83 | } 84 | }, 85 | // On wallet update 86 | wallet: async (wallet) => { 87 | // If wallet provider exists 88 | if (wallet.provider) { 89 | // Collect ethers provider 90 | const provider = new ethers.providers.Web3Provider(wallet.provider); 91 | 92 | // Update provider 93 | setProvider(provider); 94 | 95 | // Update selected wallet 96 | window.localStorage.setItem("selectedWallet", wallet.name ?? ""); 97 | } else { 98 | // Nullify data 99 | setProvider(null); 100 | } 101 | }, 102 | }, 103 | // Force connect on walletCheck for WalletConnect 104 | walletCheck: [{ checkName: "connect" }, { checkName: "network" }], 105 | }); 106 | 107 | // Update onboard 108 | setOnboard(onboard); 109 | }; 110 | 111 | // --> Lifecycle: on mount 112 | useEffect(initializeOnboard, []); 113 | useEffect(() => { 114 | // If wallet was already selected and onboard exists 115 | const previouslySelectedWallet = 116 | window.localStorage.getItem("selectedWallet"); 117 | if (previouslySelectedWallet && onboard) { 118 | // Select, existing wallet 119 | onboard.walletSelect(previouslySelectedWallet); 120 | } 121 | }, [onboard]); 122 | 123 | return { address, provider, unlock }; 124 | } 125 | 126 | // Create unstated-next container 127 | export const eth = createContainer(useEth); 128 | -------------------------------------------------------------------------------- /frontend/state/index.tsx: -------------------------------------------------------------------------------- 1 | import { eth } from "state/eth"; // Eth state provider 2 | import { token } from "state/token"; // Token state provider 3 | import type { ReactElement } from "react"; // Types 4 | 5 | /** 6 | * State providing wrapper 7 | * @param {ReactElement | ReactElement[]} children to inject 8 | * @returns {ReactElement} wrapper 9 | */ 10 | export default function StateProvider({ 11 | children, 12 | }: { 13 | children: ReactElement | ReactElement[]; 14 | }): ReactElement { 15 | return ( 16 | // Wrap in sub-providers 17 | 18 | {children} 19 | 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /frontend/state/token.ts: -------------------------------------------------------------------------------- 1 | import config from "config"; // Airdrop config 2 | import { eth } from "state/eth"; // ETH state provider 3 | import { ethers } from "ethers"; // Ethers 4 | import keccak256 from "keccak256"; // Keccak256 hashing 5 | import MerkleTree from "merkletreejs"; // MerkleTree.js 6 | import { useEffect, useState } from "react"; // React 7 | import { createContainer } from "unstated-next"; // State management 8 | 9 | /** 10 | * Generate Merkle Tree leaf from address and value 11 | * @param {string} address of airdrop claimee 12 | * @param {string} value of airdrop tokens to claimee 13 | * @returns {Buffer} Merkle Tree node 14 | */ 15 | function generateLeaf(address: string, value: string): Buffer { 16 | return Buffer.from( 17 | // Hash in appropriate Merkle format 18 | ethers.utils 19 | .solidityKeccak256(["address", "uint256"], [address, value]) 20 | .slice(2), 21 | "hex" 22 | ); 23 | } 24 | 25 | // Setup merkle tree 26 | const merkleTree = new MerkleTree( 27 | // Generate leafs 28 | Object.entries(config.airdrop).map(([address, tokens]) => 29 | generateLeaf( 30 | ethers.utils.getAddress(address), 31 | ethers.utils.parseUnits(tokens.toString(), config.decimals).toString() 32 | ) 33 | ), 34 | // Hashing function 35 | keccak256, 36 | { sortPairs: true } 37 | ); 38 | 39 | function useToken() { 40 | // Collect global ETH state 41 | const { 42 | address, 43 | provider, 44 | }: { 45 | address: string | null; 46 | provider: ethers.providers.Web3Provider | null; 47 | } = eth.useContainer(); 48 | 49 | // Local state 50 | const [dataLoading, setDataLoading] = useState(true); // Data retrieval status 51 | const [numTokens, setNumTokens] = useState(0); // Number of claimable tokens 52 | const [alreadyClaimed, setAlreadyClaimed] = useState(false); // Claim status 53 | 54 | /** 55 | * Get contract 56 | * @returns {ethers.Contract} signer-initialized contract 57 | */ 58 | const getContract = (): ethers.Contract => { 59 | return new ethers.Contract( 60 | // Contract address 61 | process.env.NEXT_PUBLIC_CONTRACT_ADDRESS ?? "", 62 | [ 63 | // hasClaimed mapping 64 | "function hasClaimed(address) public view returns (bool)", 65 | // Claim function 66 | "function claim(address to, uint256 amount, bytes32[] calldata proof) external", 67 | ], 68 | // Get signer from authed provider 69 | provider?.getSigner() 70 | ); 71 | }; 72 | 73 | /** 74 | * Collects number of tokens claimable by a user from Merkle tree 75 | * @param {string} address to check 76 | * @returns {number} of tokens claimable 77 | */ 78 | const getAirdropAmount = (address: string): number => { 79 | // If address is in airdrop. convert address to correct checksum 80 | address = ethers.utils.getAddress(address) 81 | 82 | if (address in config.airdrop) { 83 | // Return number of tokens available 84 | return config.airdrop[address]; 85 | } 86 | 87 | // Else, return 0 tokens 88 | return 0; 89 | }; 90 | 91 | /** 92 | * Collects claim status for an address 93 | * @param {string} address to check 94 | * @returns {Promise} true if already claimed, false if available 95 | */ 96 | const getClaimedStatus = async (address: string): Promise => { 97 | // Collect token contract 98 | const token: ethers.Contract = getContract(); 99 | // Return claimed status 100 | return await token.hasClaimed(address); 101 | }; 102 | 103 | const claimAirdrop = async (): Promise => { 104 | // If not authenticated throw 105 | if (!address) { 106 | throw new Error("Not Authenticated"); 107 | } 108 | 109 | // Collect token contract 110 | const token: ethers.Contract = getContract(); 111 | // Get properly formatted address 112 | const formattedAddress: string = ethers.utils.getAddress(address); 113 | // Get tokens for address 114 | const numTokens: string = ethers.utils 115 | .parseUnits(config.airdrop[ethers.utils.getAddress(address)].toString(), config.decimals) 116 | .toString(); 117 | 118 | // Generate hashed leaf from address 119 | const leaf: Buffer = generateLeaf(formattedAddress, numTokens); 120 | // Generate airdrop proof 121 | const proof: string[] = merkleTree.getHexProof(leaf); 122 | 123 | // Try to claim airdrop and refresh sync status 124 | try { 125 | const tx = await token.claim(formattedAddress, numTokens, proof); 126 | await tx.wait(1); 127 | await syncStatus(); 128 | } catch (e) { 129 | console.error(`Error when claiming tokens: ${e}`); 130 | } 131 | }; 132 | 133 | /** 134 | * After authentication, update number of tokens to claim + claim status 135 | */ 136 | const syncStatus = async (): Promise => { 137 | // Toggle loading 138 | setDataLoading(true); 139 | 140 | // Force authentication 141 | if (address) { 142 | // Collect number of tokens for address 143 | const tokens = getAirdropAmount(address); 144 | setNumTokens(tokens); 145 | 146 | // Collect claimed status for address, if part of airdrop (tokens > 0) 147 | if (tokens > 0) { 148 | const claimed = await getClaimedStatus(address); 149 | setAlreadyClaimed(claimed); 150 | } 151 | } 152 | 153 | // Toggle loading 154 | setDataLoading(false); 155 | }; 156 | 157 | // On load: 158 | useEffect(() => { 159 | syncStatus(); 160 | }, [address]); 161 | 162 | return { 163 | dataLoading, 164 | numTokens, 165 | alreadyClaimed, 166 | claimAirdrop, 167 | }; 168 | } 169 | 170 | // Create unstated-next container 171 | export const token = createContainer(useToken); 172 | -------------------------------------------------------------------------------- /frontend/styles/components/Footer.module.scss: -------------------------------------------------------------------------------- 1 | // Footer 2 | .footer { 3 | // Spacey margin 4 | margin: 1rem 4rem; 5 | // Align right on desktop 6 | text-align: right; 7 | height: calc(70px - 2rem); 8 | 9 | // Individual social links 10 | > a { 11 | margin: 0.5rem; 12 | transition: 100ms ease; 13 | 14 | &:hover { 15 | opacity: 0.7; 16 | } 17 | } 18 | } 19 | 20 | // Responsive 21 | @media screen and (max-width: 728px) { 22 | .footer { 23 | // Align links center on mobile 24 | text-align: center; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /frontend/styles/components/Header.module.scss: -------------------------------------------------------------------------------- 1 | // Header 2 | .header { 3 | padding: 1.5rem 3rem; 4 | display: flex; 5 | justify-content: space-between; 6 | -webkit-box-pack: justify; 7 | align-items: center; 8 | 9 | // Non-action-menu divs (seperate space-between) 10 | > div:nth-child(1), 11 | > div:nth-child(2) { 12 | width: auto; 13 | flex: 1 1 50%; 14 | display: flex; 15 | align-items: center; 16 | } 17 | } 18 | 19 | // Header: Logo 20 | .header__logo { 21 | justify-content: flex-start; 22 | 23 | > a { 24 | transition: 0.5s ease; 25 | 26 | &:hover { 27 | transform: rotate(10deg); 28 | } 29 | } 30 | } 31 | 32 | // Header: Connect Wallet + Actions menu 33 | .header__actions { 34 | justify-content: flex-end; 35 | 36 | // Universal hover colors 37 | > button { 38 | &:hover { 39 | border-color: rgb(201, 201, 201) !important; 40 | } 41 | } 42 | 43 | // Connect Wallet 44 | > button:nth-of-type(1) { 45 | min-width: 150px; 46 | line-height: 1.15; 47 | font-size: 16px; 48 | border-radius: 12px; 49 | padding: 1rem; 50 | margin: 0px 1rem; 51 | border: 1px solid rgb(255, 255, 255); 52 | color: rgb(0, 93, 194); 53 | background-color: rgb(186, 206, 255); 54 | } 55 | 56 | // Actions menu 57 | > button:nth-of-type(2) { 58 | border-radius: 12px; 59 | background: white; 60 | display: flex; 61 | align-items: center; 62 | justify-content: center; 63 | padding: 12px; 64 | border: 1px solid rgb(255, 255, 255); 65 | 66 | > img { 67 | display: flex; 68 | height: 25px; 69 | width: 25px; 70 | } 71 | } 72 | } 73 | 74 | // Header: Action menu 75 | .header__actionMenu { 76 | background-color: white; 77 | border-radius: 12px; 78 | width: 9rem; 79 | position: absolute; 80 | top: 88px; 81 | right: 3rem; 82 | box-shadow: 0 2px 4px 0 rgb(34 36 38 / 12%), 0 2px 10px 0 rgb(34 36 38 / 15%); 83 | z-index: 999; 84 | 85 | > a { 86 | color: #9e9e9e; 87 | font-size: 16px; 88 | display: flex; 89 | padding: 0.5rem; 90 | justify-content: space-between; 91 | -webkit-box-pack: justify; 92 | align-items: center; 93 | transition: 50ms ease; 94 | 95 | &:hover { 96 | opacity: 0.7; 97 | } 98 | } 99 | } 100 | 101 | // Responsive 102 | @media screen and (max-width: 728px) { 103 | .header { 104 | padding: 2rem 1rem; 105 | } 106 | 107 | .header__actionMenu { 108 | top: 96px; 109 | right: 1rem; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /frontend/styles/components/Layout.module.scss: -------------------------------------------------------------------------------- 1 | // Layout: Content 2 | .layout__content { 3 | // Force minimum height (to push footer to bottom without flexbox) 4 | min-height: calc(100vh - calc(70px - 2rem) - 150px); 5 | } 6 | -------------------------------------------------------------------------------- /frontend/styles/global.scss: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | // Fix spacing 4 | margin: 0px; 5 | padding: 0px; 6 | 7 | // Font 8 | font-feature-settings: "ss01"; 9 | text-rendering: optimizeLegibility; 10 | font-family: "Inter", sans-serif; 11 | 12 | // Background 13 | background-color: rgb(247, 248, 250); 14 | } 15 | 16 | // Override default link styles 17 | a { 18 | color: inherit; 19 | text-decoration: none; 20 | } 21 | 22 | // Fix fonts for buttons and inputs 23 | button, 24 | input { 25 | font-feature-settings: "ss01"; 26 | text-rendering: optimizeLegibility; 27 | font-family: "Inter", sans-serif; 28 | cursor: pointer; 29 | } 30 | -------------------------------------------------------------------------------- /frontend/styles/pages/Claim.module.scss: -------------------------------------------------------------------------------- 1 | // Claim page 2 | .claim { 3 | // Sizing 4 | max-width: 600px; 5 | margin: 0px auto 50px auto; 6 | text-align: center; 7 | padding: 1rem; 8 | } 9 | 10 | // Individual card container 11 | .card { 12 | background: white; 13 | border-radius: 1rem; 14 | border: 1px solid rgb(227, 227, 227); 15 | padding: 2rem; 16 | width: calc(100% - 4rem - 20px); 17 | max-width: 500px; 18 | box-shadow: rgb(117 117 117 / 10%) 0px 10px 20px 5px; 19 | text-align: left; 20 | 21 | // Header 22 | > h1 { 23 | margin: 0px; 24 | line-height: 1.2; 25 | font-size: 25px; 26 | } 27 | 28 | // Description 29 | > p { 30 | line-height: 1.5; 31 | margin: 1rem 0px; 32 | } 33 | 34 | // Main blue button 35 | > button { 36 | width: 100%; 37 | margin-top: 1rem; 38 | font-weight: 500; 39 | border-radius: 12px; 40 | padding: 1rem; 41 | font-size: 16px; 42 | border: 1px solid rgb(255, 255, 255); 43 | color: rgb(0, 93, 194); 44 | background-color: rgb(186, 206, 255); 45 | 46 | &:hover { 47 | border-color: rgb(201, 201, 201); 48 | } 49 | 50 | // Disable border color change on disabled hover 51 | &:disabled:hover { 52 | border-color: rgb(255, 255, 255) !important; 53 | } 54 | 55 | &:disabled { 56 | opacity: 0.5; 57 | border-color: rgb(255, 255, 255) !important; 58 | cursor: not-allowed; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /frontend/styles/pages/Home.module.scss: -------------------------------------------------------------------------------- 1 | .home { 2 | // Sizing 3 | max-width: 500px; 4 | margin: 0px auto 50px auto; 5 | text-align: center; 6 | padding: 1rem; 7 | 8 | // Logo 9 | > div { 10 | margin: 2.5rem; 11 | } 12 | 13 | // Article link 14 | > a { 15 | color: #9e9e9e; 16 | font-weight: 800; 17 | font-size: 18px; 18 | transition: 100ms ease; 19 | 20 | &:hover { 21 | opacity: 0.7; 22 | } 23 | } 24 | 25 | // Header 26 | > h1 { 27 | font-size: 44px; 28 | font-weight: bold; 29 | line-height: 1.2; 30 | margin: 1rem; 31 | color: #107cf1; 32 | } 33 | 34 | > p { 35 | font-size: 18px; 36 | color: rgb(113, 113, 113); 37 | line-height: 1.5; 38 | margin: 1rem; 39 | } 40 | 41 | > button { 42 | min-width: 150px; 43 | font-weight: 500; 44 | border-radius: 12px; 45 | padding: 1rem; 46 | margin: 0px 1rem; 47 | font-size: 16px; 48 | border: 1px solid rgb(255, 255, 255); 49 | color: rgb(0, 93, 194); 50 | background-color: rgb(186, 206, 255); 51 | 52 | &:disabled { 53 | opacity: 0.5; 54 | border-color: rgb(255, 255, 255); 55 | cursor: not-allowed; 56 | } 57 | } 58 | } 59 | 60 | // Responsive 61 | @media screen and (max-width: 728px) { 62 | .home { 63 | padding: 1rem; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /frontend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "noEmit": true, 10 | "esModuleInterop": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "jsx": "preserve", 16 | "baseUrl": "./", 17 | "incremental": true 18 | }, 19 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], 20 | "exclude": ["node_modules"] 21 | } 22 | -------------------------------------------------------------------------------- /generator/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["airbnb", "plugin:prettier/recommended"], 3 | "env": { 4 | "browser": true, 5 | "commonjs": true, 6 | "es6": true, 7 | "jest": true, 8 | "node": true 9 | }, 10 | "rules": { 11 | "max-len": [ 12 | "warn", 13 | { 14 | "code": 120, 15 | "tabWidth": 2, 16 | "comments": 120, 17 | "ignoreComments": false, 18 | "ignoreTrailingComments": true, 19 | "ignoreUrls": true, 20 | "ignoreStrings": true, 21 | "ignoreTemplateLiterals": true, 22 | "ignoreRegExpLiterals": true 23 | } 24 | ] 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /generator/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 80, 3 | "singleQuote": false, 4 | "trailingComma": "none" 5 | } -------------------------------------------------------------------------------- /generator/README.md: -------------------------------------------------------------------------------- 1 | # Generator 2 | 3 | Given a `decimals` count for a token and list of airdrop recipients, outputs: 4 | 5 | 1. A merkle root for use in a MerkleClaimERC20 contract 6 | 2. A merkle tree for use in a front-end 7 | 8 | ## Run locally 9 | 10 | ```bash 11 | # Navigate to generator directory, if not already there 12 | cd generator/ 13 | 14 | # Install dependencies 15 | npm install 16 | 17 | # Edit config.json 18 | vim config.json 19 | 20 | # Run script 21 | npm run start 22 | ``` 23 | 24 | Outputs a `merkle.json`, in the following format: 25 | 26 | ```json 27 | { 28 | "root": "0x6a0b89fc219e9e72ad683e00d9c152532ec8e5c559600e04160d310936400a00", 29 | "tree": { 30 | "duplicateOdd": false, 31 | "hashLeaves": false, 32 | "isBitcoinTree": false, 33 | "leaves": [ 34 | ... 35 | ], 36 | "layers": [ 37 | [...], 38 | [...] 39 | ], 40 | "sortLeaves": false, 41 | "sortPairs": true, 42 | "sort": false, 43 | "fillDefaultHash": null 44 | } 45 | } 46 | ``` 47 | -------------------------------------------------------------------------------- /generator/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "decimals": 18, 3 | "airdrop": { 4 | "0x016C8780e5ccB32E5CAA342a926794cE64d9C364": 10, 5 | "0x185a4dc360ce69bdccee33b3784b0282f7961aea": 100 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /generator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator", 3 | "version": "1.0.0", 4 | "description": "Script to generate Merkle tree root from inputs", 5 | "scripts": { 6 | "start": "ts-node src/app.ts" 7 | }, 8 | "author": "Anish Agnihotri", 9 | "license": "AGPL-3.0-only", 10 | "keywords": [ 11 | "merkle", 12 | "root", 13 | "generator" 14 | ], 15 | "devDependencies": { 16 | "@types/node": "^17.0.5", 17 | "eslint-config-airbnb": "^19.0.4", 18 | "eslint-config-prettier": "^8.3.0", 19 | "eslint-plugin-import": "^2.25.3", 20 | "prettier": "^2.5.1", 21 | "ts-node": "^10.4.0", 22 | "typescript": "^4.5.4" 23 | }, 24 | "dependencies": { 25 | "ethers": "^5.5.2", 26 | "keccak256": "^1.0.6", 27 | "merkletreejs": "^0.2.27", 28 | "winston": "^3.3.3" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /generator/src/app.ts: -------------------------------------------------------------------------------- 1 | import fs from "fs"; // Filesystem 2 | import path from "path"; // Path routing 3 | import Generator from "./generator"; // Generator 4 | import { logger } from "./utils/logger"; // Logging 5 | 6 | // Config file path 7 | const configPath: string = path.join(__dirname, "../config.json"); 8 | 9 | /** 10 | * Throws error and exists process 11 | * @param {string} erorr to log 12 | */ 13 | function throwErrorAndExit(error: string): void { 14 | logger.error(error); 15 | process.exit(1); 16 | } 17 | 18 | (async () => { 19 | // Check if config exists 20 | if (!fs.existsSync(configPath)) { 21 | throwErrorAndExit("Missing config.json. Please add."); 22 | } 23 | 24 | // Read config 25 | const configFile: Buffer = await fs.readFileSync(configPath); 26 | const configData = JSON.parse(configFile.toString()); 27 | 28 | // Check if config contains airdrop key 29 | if (configData["airdrop"] === undefined) { 30 | throwErrorAndExit("Missing airdrop param in config. Please add."); 31 | } 32 | 33 | // Collect config 34 | const decimals: number = configData.decimals ?? 18; 35 | const airdrop: Record = configData.airdrop; 36 | 37 | // Initialize and call generator 38 | const generator = new Generator(decimals, airdrop); 39 | await generator.process(); 40 | })(); 41 | -------------------------------------------------------------------------------- /generator/src/generator.ts: -------------------------------------------------------------------------------- 1 | import fs from "fs"; // Filesystem 2 | import path from "path"; // Path 3 | import keccak256 from "keccak256"; // Keccak256 hashing 4 | import MerkleTree from "merkletreejs"; // MerkleTree.js 5 | import { logger } from "./utils/logger"; // Logging 6 | import { getAddress, parseUnits, solidityKeccak256 } from "ethers/lib/utils"; // Ethers utils 7 | 8 | // Output file path 9 | const outputPath: string = path.join(__dirname, "../merkle.json"); 10 | 11 | // Airdrop recipient addresses and scaled token values 12 | type AirdropRecipient = { 13 | // Recipient address 14 | address: string; 15 | // Scaled-to-decimals token value 16 | value: string; 17 | }; 18 | 19 | export default class Generator { 20 | // Airdrop recipients 21 | recipients: AirdropRecipient[] = []; 22 | 23 | /** 24 | * Setup generator 25 | * @param {number} decimals of token 26 | * @param {Record} airdrop address to token claim mapping 27 | */ 28 | constructor(decimals: number, airdrop: Record) { 29 | // For each airdrop entry 30 | for (const [address, tokens] of Object.entries(airdrop)) { 31 | // Push: 32 | this.recipients.push({ 33 | // Checksum address 34 | address: getAddress(address), 35 | // Scaled number of tokens claimable by recipient 36 | value: parseUnits(tokens.toString(), decimals).toString() 37 | }); 38 | } 39 | } 40 | 41 | /** 42 | * Generate Merkle Tree leaf from address and value 43 | * @param {string} address of airdrop claimee 44 | * @param {string} value of airdrop tokens to claimee 45 | * @returns {Buffer} Merkle Tree node 46 | */ 47 | generateLeaf(address: string, value: string): Buffer { 48 | return Buffer.from( 49 | // Hash in appropriate Merkle format 50 | solidityKeccak256(["address", "uint256"], [address, value]).slice(2), 51 | "hex" 52 | ); 53 | } 54 | 55 | async process(): Promise { 56 | logger.info("Generating Merkle tree."); 57 | 58 | // Generate merkle tree 59 | const merkleTree = new MerkleTree( 60 | // Generate leafs 61 | this.recipients.map(({ address, value }) => 62 | this.generateLeaf(address, value) 63 | ), 64 | // Hashing function 65 | keccak256, 66 | { sortPairs: true } 67 | ); 68 | 69 | // Collect and log merkle root 70 | const merkleRoot: string = merkleTree.getHexRoot(); 71 | logger.info(`Generated Merkle root: ${merkleRoot}`); 72 | 73 | // Collect and save merkle tree + root 74 | await fs.writeFileSync( 75 | // Output to merkle.json 76 | outputPath, 77 | // Root + full tree 78 | JSON.stringify({ 79 | root: merkleRoot, 80 | tree: merkleTree 81 | }) 82 | ); 83 | logger.info("Generated merkle tree and root saved to Merkle.json."); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /generator/src/utils/logger.ts: -------------------------------------------------------------------------------- 1 | import * as winston from "winston"; // Logging 2 | 3 | // Setup winston logger 4 | export const logger = winston.createLogger({ 5 | level: "info", 6 | // Simple line-by-line output 7 | format: winston.format.simple(), 8 | transports: [ 9 | // Print to console 10 | new winston.transports.Console(), 11 | // + Output to generator logfile 12 | new winston.transports.File({ filename: "generator.log" }) 13 | ] 14 | }); 15 | -------------------------------------------------------------------------------- /generator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["es5", "es6", "esnext"], 4 | "target": "es5", 5 | "module": "commonjs", 6 | "moduleResolution": "node", 7 | "outDir": "./dist", 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "sourceMap": true, 11 | "esModuleInterop": true, 12 | "strict": true 13 | } 14 | } 15 | --------------------------------------------------------------------------------