-
Notifications
You must be signed in to change notification settings - Fork 550
/
Copy pathinterface.sw
115 lines (105 loc) · 3.7 KB
/
interface.sw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
library;
use ::data_structures::ClaimState;
abi AirdropDistributor {
/// This function will let users claim their airdrop.
///
/// # Additional Information
///
/// A Merkle proof will need to be provided to claim the airdrop. This is then verified against
/// the merkle root and a hash of the (`Identity`, `u64`) tuple as the leaf.
/// This function uses the Binary Merkle Proof library in Sway-Libs and inherits it's specs.
///
/// # Arguments
///
/// * `amount`: [u64] - The quantity of coins allotted to the user to claim.
/// * `key`: [u64] - The index of the leaf which will be proven on the Merkle Tree.
/// * `proof`: [Vec<b256>] - The Merkle proof to verify the user is authorized to claim.
/// * `to`: [Identity] - The user which has been allotted a quantity of the coins.
///
/// # Reverts
///
/// * When the claiming period has ended.
/// * When the `to` `Identity` has already claimed.
/// * When the contract's balance is less than the `amount` to claim.
/// * When the merkle proof verification failed.
#[storage(read, write)]
fn claim(amount: u64, key: u64, proof: Vec<b256>, to: Identity);
/// Returns any unclaimed coins to 'admin' when the claiming period of the airdrop has ended.
///
/// # Reverts
///
/// * When the sender is not the contract's admin.
/// * When the claiming period is still active.
/// * When there are no coins to claim.
#[storage(read)]
fn clawback();
/// Initializes the contract and starts the airdrop.
///
/// # Arguments
///
/// * `admin`: [Identity] - The user which has the ability to clawback any unclaimed coins.
/// * `claim_time`: [u64] - The number fo blocks the claiming period should last.
/// * `merkleRoot`: [b256] - The root of the merkle proof used to verify claiming.
/// * `num_leaves`: [u64] - The number of leaves in the Merkle Tree.
///
/// # Reverts
///
/// * When the constructor has already been called.
/// * When no coins are sent to the airdrop contract.
#[payable]
#[storage(read, write)]
fn constructor(
admin: Identity,
claim_time: u32,
merkle_root: b256,
num_leaves: u64,
);
}
abi Info {
/// Returns the user which has the ability to clawback any unclaimed coins.
///
/// # Returns
///
/// * [Option<Identity>] - The user which has the ability to clawback any unclaimed coins.
#[storage(read)]
fn admin() -> Option<Identity>;
/// Returns the claim data stored on the given identity.
///
/// # Arguments
///
/// * `identity`: [Identity] - The user whose ClaimState will be returned.
///
/// # Returns
///
/// * [ClaimState] - The ClaimState of the given identity.
#[storage(read)]
fn claim_data(identity: Identity) -> ClaimState;
/// Returns the block at which the airdrop ends
///
/// # Returns
///
/// * [u32] - The block at which the airdrop ends.
#[storage(read)]
fn end_block() -> u32;
/// Returns whether the airdrop is active and coins can be claimed.
///
/// # Returns
///
/// * [bool] - Whether the airdrop is active and coins can be claimed.
#[storage(read)]
fn is_active() -> bool;
/// Returns the merkle root of the airdrop used to verify proofs.
///
/// # Returns
///
/// * [Option<b256>] - The merkle root of the airdrop used to verify proofs.
#[storage(read)]
fn merkle_root() -> Option<b256>;
/// Returns the number of leaves within the merkle tree.
///
/// # Returns
///
/// * [u64] - The number of leaves within the merkle tree.
#[storage(read)]
fn number_of_leaves() -> u64;
}