Giter Club home page Giter Club logo

go-merkle-distributor's Introduction

Go Merkle Distributor

This repo is a golang implementation (using sol-merkle-tree-go) that generates the required data for a MerkleDrop. It takes in a JSON of address->balances (both in strings) and writes a file containing the data neccessary for a cliam transaction (index, address, amount, and proof).

Usage

go-merkle-distributor --json-file=/path/to/input.json --output-file=/path/to/output.json

Example output

./go-merkle-distributor --json-file=example-balances.json
2020/12/25 01:27:55 Generating claim info for /home/kiwi/Work/tools/go-merkle-distributor/example-balances.json
2020/12/25 01:27:55 Root: 0x8f18c9e313036848cbbcb8b34676105ce866ee33bf29d16dee82bd1a8411163d
2020/12/25 01:27:55 Created claim info file at addr-to-claim.json

Helper functions

// CreateDistributionTree uses sol-merkle-tree-go to construct a tree of balance items and returns a 
// human readable mapping of address to claim info such as the proof, amount, and index. 
func CreateDistributionTree(holderArray []*TokenHolder) (*solTree.MerkleTree, map[string]ClaimInfo, error)

// ArrayFromAddrBalMap takes a string mapping of address -> balance and converts it into an array for sorting and easier usage. 
func ArrayFromAddrBalMap(stringMap map[string]string) ([]*TokenHolder, error)

// BalancesAndSupplyAtBlock takes in a go-ethereum client, token address and traces 
// through transfer logs from the startBlock, to the endBlock.
func BalancesAndSupplyAtBlock(client *ethclient.Client, tokenAddress common.Address, startBlock int64, endBlock int64) (map[common.Address]*big.Int, *big.Int, error)

Example input

{
    "0xffd342920aD20AE56769b9fC3ba4DD0E5AC75688":"1000000000000000000",
    "0x00dF49020aD20AE56769b9fC341bDD0E5AC75688":"15000000000000000000",
    "0x12dF43220D650AE56769b9fC3b4dDD0E5AC75688":"100000000000000000000",
    "0xf5dF46020aD20AE56769b9fC3da04D0E5AC75688":"1500000000000000000"
}

Example Output

{
    "0x00dF49020AD20Ae56769B9fc341bdd0E5AC75688": {
        "Index": 1,
        "Amount": "15000000000000000000",
        "Proof": [
            "0x21bc7a62dae272690dd4c8b808490d31b99bcb26628732f2ed499c632f04c97a",
            "0x7962ac1a7b4dc9e2befa1d1b063ea0dbb2d29519325718c7688bac06c34505bd"
        ]
    },
    "0x12DF43220d650ae56769b9FC3b4ddD0e5ac75688": {
        "Index": 0,
        "Amount": "100000000000000000000",
        "Proof": [
            "0x9055b91635dde0567458347be8d078524a72dcb754613a122bc5a8b2eb1676d4",
            "0x57e7cdb442d4d4498bbedfe5fbb29278e3b919fe42d3af5913983437f1c2a370"
        ]
    },
    "0xF5DF46020AD20Ae56769B9fC3Da04D0e5Ac75688": {
        "Index": 2,
        "Amount": "1500000000000000000",
        "Proof": [
            "0x17936c9a0951dcca9726377608802c03040c3c5901e0659cf6465a17b80b04dd",
            "0x7962ac1a7b4dc9e2befa1d1b063ea0dbb2d29519325718c7688bac06c34505bd"
        ]
    },
    "0xffd342920aD20aE56769B9FC3BA4DD0E5AC75688": {
        "Index": 3,
        "Amount": "1000000000000000000",
        "Proof": [
            "0x3811a5ba731e1016403500e277995d096d5f0a6e8344070c7b468f8e38e75e7e",
            "0x57e7cdb442d4d4498bbedfe5fbb29278e3b919fe42d3af5913983437f1c2a370"
        ]
    },
    "root": {
        "Index": 0,
        "Amount": "",
        "Proof": [
            "0x00bfd4c68462ab5f09d52c2e9680b52c2a55db9a7cea62d55164d726eeb36f8c"
        ]
    }
}

go-merkle-distributor's People

Contributors

0xkiwi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.