Last active
July 12, 2023 09:24
-
-
Save deuszx/b9db083e500de7351ab4bc0dd62ebe5d to your computer and use it in GitHub Desktop.
Airdropping - super duper PoC (not even an MVP!!!).
This file contains hidden or 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
#[ink::contract] | |
mod airdrop { | |
#[ink(storage)] | |
pub struct Contract { | |
participants: Mapping<u64, AccountId>, | |
last_added: u64, | |
last_ditributed: u64, | |
ready_to_distribute: bool, | |
aidrop_amount: u64, | |
} | |
impl Contract { | |
// TODO: AccessControl | |
#[ink(message)] | |
pub fn add_participant(&mut self, participant: AccountId) { | |
assert!(!self.ready_to_distribute); | |
self.participants.insert(last_added + 1, participant); | |
self.last_added = last_added + 1; | |
} | |
#[ink(message) | |
pub fn start_distribution(&mut self) { | |
self.ready_to_distribute = true; | |
} | |
#[ink(message)] | |
pub fn distribute(&mut self, batch_size: u64) { | |
for n in 0..batch_size { | |
let recipient = self.participants(last_distributed + n).unwrap(); | |
// PSP22 token here should be the one that is being airdropped | |
// transfer OR mint - depending on the design | |
PSP22Ref::transfer(airdrop_token, recipient, aidrop_amount).unwrap(); | |
} | |
self.last_distributed = self.last_distributed + batch_size; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment