-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
80 additions
and
747 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
examples/gno.land/p/demo/airdrop/grc20_merkle_airdrop/doc.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Package airdrop implements a Merkle airdrop mechanism in Gno. | ||
// | ||
// A Merkle airdrop is a secure and efficient way to distribute tokens or rewards to a list of recipients | ||
// using a Merkle tree for proof verification. This implementation is compliant with the `merkletreejs` | ||
// JavaScript package, ensuring compatibility with proofs generated off-chain. | ||
// | ||
// Note: | ||
// This package expects data to adhere to the structure defined in `gno.land/p/demo/airdrop.AirdropData`. | ||
// | ||
// Compatibility: | ||
// - Proofs and trees generated using the `merkletreejs` package (https://www.npmjs.com/package/merkletreejs) are supported. | ||
// - Uses SHA256 as the hash function with a sorted-pair configuration. | ||
// | ||
// Reference: | ||
// For more information on Merkle trees, refer to the documentation for the `merkletreejs` package: | ||
// https://www.npmjs.com/package/merkletreejs | ||
package grc20_merkle_airdrop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Package foo20_airdrop implements an airdrop mechanism for the Foo20 GRC20 in Gno. | ||
// | ||
// This package extends the functionality of `gno.land/p/demo/airdrop` to support Foo20 token distribution. | ||
// It enables secure and efficient token distribution to recipients using Merkle proofs. | ||
// | ||
// Usage: | ||
// To execute an airdrop, use the claim function and provide the necessary proof and recipient data. | ||
// | ||
// const { MerkleTree } = require("merkletreejs"); | ||
// const crypto = require("crypto"); | ||
// const SHA256 = require("crypto-js/sha256"); | ||
// const secp256k1 = require("secp256k1"); | ||
// const { bech32 } = require("bech32"); | ||
// | ||
// Example of using the ClaimJSON function: | ||
// | ||
// // This function reproduce the output of std.DerivePkgAddr | ||
// | ||
// function derive_pkg_addr(str) { | ||
// const hash = crypto | ||
// .createHash("sha256") | ||
// .update("pkgPath:" + str) | ||
// .digest(); | ||
// | ||
// let hash_bytes = new Uint8Array(hash).slice(0, 20); | ||
// | ||
// const words = bech32.toWords(hash_bytes); | ||
// return bech32.encode("g", words); | ||
// } | ||
// | ||
// const addresses = Array.from({ length: 10 }, (_, i) => | ||
// | ||
// derive_pkg_addr(`gno.land/r/test/${i}`), | ||
// | ||
// ); | ||
// | ||
// const leaves = addresses.map((addr) => | ||
// | ||
// SHA256(JSON.stringify({ address: addr, amount: "10000" })), | ||
// | ||
// ); | ||
// | ||
// const tree = new MerkleTree(leaves, SHA256); | ||
// const root = tree.getRoot().toString("hex"); | ||
// | ||
// const proof = tree.getProof(leaves[5]).map((p) => ({ | ||
// data: p.data.toString("hex"), | ||
// position: p.position === "left" ? 1 : 0, | ||
// })); | ||
// | ||
// console.log("proof", proof); // This as JSON can be sent | ||
// | ||
// Data Structure: | ||
// This package relies on the AirdropData structure from `gno.land/p/demo/airdrop`: | ||
// | ||
// Reference Implementation: | ||
// The `foo20_airdrop` package builds on the `airdrop` package's foundation. Refer to its documentation for | ||
// additional details: gno.land/p/demo/airdrop/doc.gno | ||
// | ||
// Notes: | ||
// - Ensure your Merkle tree and proofs are generated off-chain using a compatible library such as `merkletreejs`. | ||
// - Hash function: SHA256 | ||
package foo20_airdrop |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.