npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

celogive

v0.0.1

Published

📦 Celo rewards CLI that uses a smart contract that distributes a balance of tokens according to a merkle root

Downloads

7

Readme

@uniswap/merkle-distributor

Tests Lint

Local Development

The following assumes the use of node@>=10.

Install Dependencies

yarn

Compile Contracts

yarn compile

Run Tests

yarn test

Use CLI to calculate CELO rewards and distribute rewards

To get complete documentation for each command and its parameters use the --help flag.

  ./bin/run rewards:generatemerkle --help

1) Temporarily allocate more memory to node since aggregating events can take up a lot of space

export NODE_OPTIONS="--max-old-space-size=8192"

2) Fetch transfer and attestation events for rewards calculation

It's best to fetch events until January, then fetch the rest and store in separate files, or else JSON can get too big for nodejs. Begin fetching next batch exactly one block after the previous batch ended using the --fromBlock flag. There will soon be a fix to do this automatically.

./bin/run rewards:fetchevents --toDate 01/01/2021 --env mainnet
  • Outputs two files:
    • Transfer Events: transfer-cusd-events-<fromBlock>-<toBlock>.json
    • Attestation Events: attestation-events-<fromBlock<-<toBlock>.json

3) Use json files from previous command to calculate rewards

./bin/run rewards:generatemerkle \
  --attestationEvents <attestation-events1.json> <attestation-events2.json>\
  --transferEvents <transfer-events1.json> <transfer-events2.json>\
  --balanceFromBlock 2000000 \
  --balanceToBlock 3000000 \
  --celoToUsd 3.08 \
  --env mainnet
  • Outputs three files:
    • Merkle Tree representing rewards: merkleTree.json
    • Mapping of account to reward amount: rewardsByAddress.json
    • JSON with intermediate state to reach these reward amounts: rewardsCalculationState.json

4) Deploy contract with merkle root from previous step

./bin/run rewards:deploydistributor --merkleTree merkleTree.json --env local --from <address>
  • Console logs important distributor information:
Distibutor address:  0xEdCF1a0003f84A97E4a28c904d888C6a2811fe
Merkle root:  0xb0071a0dc946557f936a848dfcdf7d8d06a01edbbadfca5fd034eb48110535af
Token address:  0xF194afDf50B03e69Bd7D057c1Aa9e10c9954E4C9
Total rewards:  849487996068222610

5) Distribute rewards

./bin/run rewards:distribute --merkleTree merkleTree.json --address <distributor address> --env local --from <address> 
  • Outputs a file distribution-<distributor address>.json with a mapping of each account to the transactionHash of their distribution tx.
  • This is an asynchronous script that distibutes all unclaimed rewards.
  • If any of the transactions failed to complete, or returned an error, simply run the script again to retry all incomplete distributions.
  • Rewards are distributed fully when the output json distribution-<distributor-address>.json and rewardsByAddress.json mapping accounts keys match (same number of lines in each json file).

Use CLI to verify merkle root of a deployed Merkle Distribution contract for a rewards round

1) Follow steps 1 and 2 from above so you're ready to compute a merkle root

2) Follow step 3 and use all the parameters given for the rewards round plus the verifyAgainstContract parameter with the contract address used in the rewards round. Parameters can be found in recent discussion on the rewards forum post found here.

   ./bin/run rewards:generatemerkle \
    --verifyAgainstContract <merkle distributor address>
    --attestationEvents <attestation-events1.json> <attestation-events2.json>\
    --transferEvents <transfer-events1.json> <transfer-events2.json>\
    --balanceFromDate 02/01/2021 \
    --balanceToDate 02/08/2021 \
    --celoToUsd 3.08 \
    --env mainnet
  • The console output will verify whether or not the merkle root computed matches the merkle root of the MerkleDistributor contract
  • Use the output files to verify all intermediary data used to calculate the final rewards and merkle root: merkleTree.json rewardsByAccount.json rewardsCalculationState.json