Skip to content

Latest commit

 

History

History
166 lines (134 loc) · 7.6 KB

README.md

File metadata and controls

166 lines (134 loc) · 7.6 KB

How to use this repo

Overview

本レポはトークンをエアドロあるいは賞金を配るために用いられる。

  • This repository is for delivering token to a group of addresses and it can set their amounts to be received.
  • Distributing token address can be set as you wish.
  • The Distributor contracts are upgradeable.
  • This repository is modified for Polygon, but it can be customized for other network as well.

Hardhat & Frontend, npm installation

前準備

  • $ git clone ...
  • $ cd frontend
  • $ npm install
  • $ cd hardhat
  • $ npm install

How to set the recievers' addresses and amount

rawRecipientsInfo.jsonファイルを使って受取人と金額を設定

  • Change the rawRecipientsInfo.json file into what you want. The uniquekey needs to be the same.
  • uniqueKey: To handle duplications of recipients, specify unique key for the pair of address and amount. Please see the detail of the data structure used in this contract.

Set .env file

前準備 .envファイルを設定

  • Add all the information in the .env file.
    • MATIC_URL: Your API key from 3rd party service
    • MATIC_PRIVATE_KEY_OWNER: your account's private key
    • MATIC_ERC20_CONTRACT_ADDRESS: The distributing token's contract address.
    • MATIC_DISTRIBUTER_CONTRACT_ADDRESS: No need to fill. It will be filled automatically when you deploy the contracts.
    • POLYSCAN_API_KEY: Polyscan's API key for verifying contracts.
    • MATIC_PRIVATE_KEY_OTHER1: No need to fill only if you want.

How to deploy and withdraw

デプロイやウィズドロー

  • $ cd hardhat

  • $ npx hardhat run scripts/deploy.ts --network matic

  • $ npx hardhat run scrippts/withdraw.ts --network matic

Frontend, prepare webserver

  • $ cd frontend
  • $ npm start

How to test

  • cd hardhat
  • npx hardhat test

Contracts' structures

contractArchitecture


Contents below was written by the original creator terrier-lover

Rewards Distributer

This software provides a functionality to distribute tokens as rewards to target users. The distribution is based on Merkle Tree algorithm. Admins of the contract can specify any tokens to distribute to their users.

Technical stacks are as follows:

  • Solidity
  • Hardhat
  • Typescript
  • React (React Query)

Solidity source codes use following techniques or algorithms:

Currently provides Simple Distributer and Versioning Distributer (Versioning Distributer is not yet ready as of Jan 27, 2022). Functionalities of Simple Distributer are as follows:

  • Admins or moderators can specify target address who should receive tokens as rewards and their eligible amounts
  • Users can only claim their rewards once as default. Admins or moderators need to change isClaimed flag to false per user.
  • It supports upgradeablity provided by Hardhat and OpenZeppelin

Versioning Distributer is designed to accomodate more compilicated cases such as following:

  • Users can receive multiple rewards at different timing. Admins or moderators do not need to reset isClaimed flag
  • Specs TBD...

Demo

demo website

  • If you want to receive USDC on Rinkeby network, please add your request here

demo images

How to install

Preparation

Following files must be updated prioer to the installation process.

  • hardhat/.env
    • ***_URL
      • required
      • Set URL of RPC network that you want to use (For example, Alchemy or others).
    • ***_ERC20_CONTRACT_ADDRESS
      • required when setting own ERC20 token
      • This is required when setting own ERC20 token.
    • ***_PRIVATE_KEY_OWNER
      • required for non-localhost
      • Set private key of main account. This account will deploy contracts, so it needs to have enough tokens which are needed for the deployment.
    • ***_PRIVATE_KEY_OTHER1
      • optional
      • Set private key of other account. Not required.
  • hardhat/rawRecipientsInfo.json
    • Specify information of recipients. Set following values:
      • address: address of recipient
      • amount: reward amount for recipient.
      • uniqueKey: To handle duplications of recipients, specify unique key for the pair of address and amount. Please see the detail of the data structure used in this contract.
  • hardhat/hardhat.config.ts
    • Set appropriate values for config variable
  • frontend/src/CustomInputs.ts
    • TOKEN_IMAGE_URL
      • required
      • Set image used in the website
    • SUPPORTED_CHAIN_IDS_IN_WEB
      • required
      • Chain IDs which should be shown in the website
    • NETWORK_NAMES, CHAIN_IDS, CHAINS_IDS_AND_NETWORK_NAME_MAPPINGS
      • optional
      • Definitions of network and chainIds

Hardhat & Frontend, npm installation

  • $ cd frontend
  • $ npm install
  • $ cd hardhat
  • $ npm install

Hardhat, deploy

  • $ cd hardhat
  • Prepare .env using .env.example.

If you want to use localnet, do followings:

  • $ npx hardhat node
  • $ npx hardhat run scripts/deploy.ts --network localhost

Whenever hardhat compiles and produces new typechains (this is exported under ./hardhat/typechain), copy typechains in hardhat/typechain/ to /frontend/src/typechain/ so that frontend code can use latest definitions. In addition, change the front-end codebase accordingly.

Frontend, prepare webserver

  • $ cd frontend
  • $ npm start

How to test

  • cd hardhat
  • npx hardhat test

Future work

  • Bug fixes
    • Feel free to create issues here
  • Add more test cases
  • Support Matic network

References

License - MIT License

Copyright 2022 TerrierLover

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.