Skip to content

Commit

Permalink
add an airdrop claim check contract
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Mar 21, 2024
1 parent a9b968e commit 264e811
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/airdrop_claim_check.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use starknet::{ContractAddress};
use governance::airdrop::{IAirdropDispatcher};

#[derive(Serde, Copy, Drop)]
struct CheckParams {
airdrop: IAirdropDispatcher,
claim_id: u64,
amount: u128,
}

#[derive(Serde, Copy, Drop)]
struct CheckResult {
claimed: bool,
funded: bool,
}

#[starknet::interface]
trait IAirdropClaimCheck<TContractState> {
fn check(self: @TContractState, claims: Span<CheckParams>) -> Span<CheckResult>;
}

#[starknet::contract]
mod AirdropClaimCheck {
use super::{IAirdropClaimCheck, IAirdropDispatcher, CheckParams, CheckResult};
use governance::airdrop::{IAirdropDispatcherTrait};
use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait};
use core::array::{SpanTrait};
use core::option::{OptionTrait};

#[storage]
struct Storage {}

#[abi(embed_v0)]
impl AirdropClaimCheckImpl of IAirdropClaimCheck<ContractState> {
fn check(self: @ContractState, mut claims: Span<CheckParams>) -> Span<CheckResult> {
let mut result: Array<CheckResult> = array![];

while let Option::Some(claim_check) = claims
.pop_front() {
let token = IERC20Dispatcher {
contract_address: (*claim_check.airdrop).get_token()
};
let claimed = (*claim_check.airdrop).is_claimed(*claim_check.claim_id);
let funded = token
.balanceOf(
*claim_check.airdrop.contract_address
) >= ((*claim_check.amount).into());
result.append(CheckResult { claimed, funded });
};

result.span()
}
}
}
1 change: 1 addition & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod airdrop_claim_check;
pub mod airdrop;

#[cfg(test)]
Expand Down

0 comments on commit 264e811

Please sign in to comment.