Sui Tears💧 Airdrop modules are "pulled" based. The modules store the root of a Merkle tree that consists of the address of the user and the airdrop amount. Users are required to submit a Merkle proof to claim their airdrops. The leafs are constructed by hashing (sha3256) the sender's address concatenated with the amount.
Please check here on how to construct the Merkle Tree.
struct Airdrop<phantom T> has key, store {
id: UID,
balance: Balance<T>,
root: vector<u8>,
start: u64,
map: Bitmap
}
balance - Coins to airdrop
root - The root of the Merkle tree
start - The timestamp in which users can claim the airdrop
map - Bitmap keeps track of airdrop claims.
It creates the Airdrop object.
public fun new(airdrop_coin: Coin<T>, root: vector<u8>, start: u64, c: &Clock, ctx: &mut TxContext): Airdrop<T>
@param airdrop_coin: The coin that will be distributed in the airdrop.
@param root: The Merkle tree root that keeps track of all the airdrops.
@param start: The start timestamp of the airdrop in milliseconds.
@param c: The sui::clock::Clock
shared object.
@return Airdrop<T>
Aborts
root is empty.
start time of the airdrop is in the past.
Returns the current amount of airdrop coins in the Airdrop object.
public fun balance<T>(self: &Airdrop<T>): u64
@param: self The shared Airdrop object
@return u64
Returns the root of the Merkle tree for the airdrop.
public fun root<T>(self: &Airdrop<T>): vector<u8>
@param: self The shared Airdrop object.
@return vector<u8>.
Returns the start timestamp of the airdrop. Users can claim after this date.
public fun start<T>(self: &Airdrop<T>): u64
@param: self The shared Airdrop object.
@return u64.
Returns an immutable reference of the Bitmap. It keeps track of the claimed airdrops.
public fun borrow_map<T>(self: &Airdrop<T>): &Bitmap
@param: self The shared Airdrop object.
@return &Bitmap.
Checks if a user has already claimed his airdrop.
public fun has_account_claimed<T>(
self: &Airdrop<T>,
proof: vector<vector<u8>>,
amount: u64,
user: address
): bool
@param self: The shared Airdrop object.
@param proof: The proof that the sender can redeem the amount
from the airdrop.
@param amount: Number of coins the sender can redeem.
@param address: A user address.
@return bool. True if he has claimed the airdrop already.
Aborts
If the proof
is not valid.
Allows a user to claim his airdrop by proving that his address and amount are in the Merkle tree.
public fun get_airdrop<T>(
self: &mut Airdrop<T>,
proof: vector<vector<u8>>,
c: &Clock,
amount: u64,
ctx: &mut TxContext
): Coin<T>
@param self: The shared Airdrop object.
@param proof: The proof that the sender can redeem the amount
from the airdrop.
@param c: The sui::clock::Clock
shared object.
@param amount: Number of coins the sender can redeem.
@return Coin<T>. The airdrop Coin.
Aborts
If the proof
is not valid.
The airdrop has not started yet.
The user already claimed it
Destroys an empty Airdrop object.
public fun destroy_zero<T>(self: Airdrop<T>)
@param self: The shared {Airdrop} object.
Aborts
The self
has left over coins.
Airdrop utils module contains the verify function to check if a Merkle proof combined with an address and amount are part of the Merkle tree root.
Checks if the sender is allowed to redeem an amount
from an airdrop using Merkle proofs. It returns the index of his Merkle proof to add to the Bitmap struct.
public fun verify(
root: vector<u8>,
proof: vector<vector<u8>>,
amount: u64,
sender: address
): u256
@param root: The Merkle tree root that keeps track of all the airdrops.
@param proof: The proof that the sender can redeem the amount
from the airdrop.
@param amount: The airdrop amount.
@param sender: The address of the airdrop user.
@return u256. An index.
Aborts
if the leaf or proof are invalid.
Sui Tears💧 Airdrop modules are "pulled" based. The modules store the root of a Merkle tree that consists of the address of the user and the airdrop amount. Users are required to submit a Merkle proof to claim their airdrops. The leafs are constructed by hashing (sha3256) the sender's address with the amount. This module returns the airdrop inside a linear vesting airdrop wallet.
Please check here on how to construct the Merkle Tree.
struct Airdrop<phantom T> has key, store {
id: UID,
balance: Balance<T>,
root: vector<u8>,
start: u64,
duration: u64,
map: Bitmap
}
balance - Coins to airdrop
root - The root of the Merkle tree
start - The timestamp in which the vesting schedule starts.
duration - The duration of the vesting schedule.
map - Bitmap keeps track of airdrop claims.
Creates a linear vested airdrop.
public fun new<T>(airdrop_coin: Coin<T>, root: vector<u8>, start: u64, duration: u64, c: &Clock, ctx: &mut TxContext): Airdrop<T>
@param airdrop_coin: The coin that will be distributed in the airdrop.
@param root: The Merkle tree root that keeps track of all the airdrops.
@param start: The start timestamp of the vesting schedule.
@param duration: The duration of the vesting schedule.
@param c: The sui::clock::Clock
shared object.
@return Airdrop<T>
Aborts
root is empty.
start time of the airdrop is in the past.
Returns the current amount of airdrop coins in the Airdrop object.
public fun balance<T>(self: &Airdrop<T>): u64
@param: self The shared Airdrop object
@return u64
Returns the root of the Merkle tree for the airdrop.
public fun root<T>(self: &Airdrop<T>): vector<u8>
@param: self The shared Airdrop object.
@return vector<u8>.
Returns the start timestamp of the airdrop. Users can claim after this date.
public fun start<T>(self: &Airdrop<T>): u64
@param: self The shared Airdrop object.
@return u64.
Returns the duration of the vesting schedule.
public fun duration<T>(self: &Airdrop<T>): u64
@param: self The shared Airdrop object.
@return u64.
Returns an immutable reference of the Bitmap. It keeps track of the claimed airdrops.
public fun borrow_map<T>(self: &Airdrop<T>): &Bitmap
@param: self The shared Airdrop object.
@return &Bitmap.
Checks if a user has already claimed his airdrop.
public fun has_account_claimed<T>(
self: &Airdrop<T>,
proof: vector<vector<u8>>,
amount: u64,
user: address
): bool
@param self: The shared Airdrop object.
@param proof: The proof that the sender can redeem the amount
from the airdrop.
@param amount: Number of coins the sender can redeem.
@param address: A user address.
@return bool. True if he has claimed the airdrop already.
Aborts
If the proof
is not valid.
Allows a user to claim his airdrop by proving that his address and amount are in the Merkle tree.
public fun get_airdrop<T>(
self: &mut Airdrop<T>,
proof: vector<vector<u8>>,
clock_object: &Clock,
amount: u64,
ctx: &mut TxContext
): Wallet<T>
@param self: The shared Airdrop object.
@param proof: The proof that the sender can redeem the amount
from the airdrop.
@param c: The sui::clock::Clock
shared object.
@param amount: Number of coins the sender can redeem.
@return Wallet. The airdrop Coin locked in a linear vested {Wallet}.
Aborts
If the proof
is not valid.
The user already claimed it
Destroys an empty Airdrop.
public fun destroy_zero<T>(self: Airdrop<T>)
@param self: The shared {Airdrop} object.
Aborts
The self
has left over coins.