-
Notifications
You must be signed in to change notification settings - Fork 32
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
1 parent
a9b968e
commit 264e811
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
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,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() | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod airdrop_claim_check; | ||
pub mod airdrop; | ||
|
||
#[cfg(test)] | ||
|