Git Product home page Git Product logo

airdrop-contract's Introduction

CW20 Merkle Airdrop

This is a merkle airdrop smart contract that works with cw20 token specification Mass airdrop distributions made cheap and efficient.

Explanation of merkle airdrop: Medium Merkle Airdrop: the Basics

Traditional and non-efficient airdrops:

  • Distributor creates a list of airdrop
  • Sends bank send messages to send tokens to recipients

Or

  • Stores list of recipients on smart contract data
  • Recipient claims the airdrop

These two solutions are very ineffective when recipient list is big. First, costly because bank send cost for the distributor will be costly. Second, whole airdrop list stored in the state, again costly.

Merkle Airdrop is very efficient even when recipient number is massive.

This contract works with multiple airdrop rounds, meaning you can execute several airdrops using same instance.

Uses SHA256 for merkle root tree construction.

Procedure

  • Distributor of contract prepares a list of addresses with many entries and publishes this list in public static .js file in JSON format
  • Distributor reads this list, builds the merkle tree structure and writes down the Merkle root of it.
  • Distributor creates contract and places calculated Merkle root into it.
  • Distributor says to users, that they can claim their tokens, if they owe any of addresses, presented in list, published on distributor's site.
  • User wants to claim his N tokens, he also builds Merkle tree from public list and prepares Merkle proof, consisting from log2N hashes, describing the way to reach Merkle root
  • User sends transaction with Merkle proof to contract
  • Contract checks Merkle proof, and, if proof is correct, then sender's address is in list of allowed addresses, and contract does some action for this use.
  • Distributor sends token to the contract, and registers new merkle root for the next distribution round.

Spec

Messages

InstantiateMsg

InstantiateMsg instantiates contract with owner and cw20 token address. Airdrop stage is set to 0.

pub struct InstantiateMsg {
  pub owner: String,
  pub cw20_token_address: String,
}

ExecuteMsg

pub enum ExecuteMsg {
  UpdateConfig {
    owner: Option<String>,
  },
  RegisterMerkleRoot {
    merkle_root: String,
  },
  Claim {
    stage: u8,
    index: String,
    amount: Uint128,
    proof: Vec<String>,
  },
}
  • UpdateConfig{owner} updates configuration.
  • RegisterMerkleRoot {merkle_root} registers merkle tree root for further claim verification. Airdrop Stage increased by 1.
  • Claim{stage, amount, proof} recipient executes for claiming airdrop with stage, index, amount and proof data built using full list.

QueryMsg

pub enum QueryMsg {
    Config {},
    MerkleRoot { stage: u8 },
    LatestStage {},
    IsClaimed { stage: u8, index: String },
}
  • { config: {} } returns configuration, {"cw20_token_address": ..., "owner": ...}.
  • { merkle_root: { stage: "1" } returns merkle root of given stage, {"merkle_root": ... , "stage": ...}
  • { latest_stage: {}} returns current airdrop stage, {"latest_stage": ...}
  • { is_claimed: {stage: "stage", index: "wasm1..."} returns if address claimed airdrop, {"is_claimed": "true"}

Merkle Airdrop CLI

Merkle Airdrop CLI contains js helpers for generating root, generating and verifying proofs for given airdrop file.

Test Vector Generation

Test vector can be generated using commands at Merkle Airdrop CLI README

airdrop-contract's People

Contributors

dokywhale avatar

Stargazers

 avatar

Watchers

 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.