Skip to content

Commit

Permalink
add some methods to the airdrop and test some attributes of the airdr…
Browse files Browse the repository at this point in the history
…op in the factory
  • Loading branch information
moodysalem committed Nov 7, 2023
1 parent d7a7138 commit c025030
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/airdrop.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use governance::interfaces::erc20::{IERC20Dispatcher};
use starknet::{ContractAddress};
use array::{Array};

Expand All @@ -11,12 +12,21 @@ struct Claim {
trait IAirdrop<TStorage> {
// Claims the given allotment of tokens
fn claim(ref self: TStorage, claim: Claim, proof: Array::<felt252>);

// Return the root of the airdrop
fn get_root(self: @TStorage) -> felt252;

// Return the token being dropped
fn get_token(self: @TStorage) -> IERC20Dispatcher;

// Return whether the claim has been claimed (always false for invalid claims)
fn is_claimed(self: @TStorage, claim: Claim) -> bool;
}

#[starknet::contract]
mod Airdrop {
use super::{IAirdrop, ContractAddress, Claim};
use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait};
use super::{IAirdrop, ContractAddress, Claim, IERC20Dispatcher};
use governance::interfaces::erc20::{IERC20DispatcherTrait};
use hash::{LegacyHash};
use array::{ArrayTrait, SpanTrait};
use starknet::{ContractAddressIntoFelt252};
Expand Down Expand Up @@ -81,5 +91,17 @@ mod Airdrop {

self.emit(Claimed { claim });
}

fn get_root(self: @ContractState) -> felt252 {
self.root.read()
}

fn get_token(self: @ContractState) -> IERC20Dispatcher {
self.token.read()
}

fn is_claimed(self: @ContractState, claim: Claim) -> bool {
self.claimed.read(LegacyHash::hash(0, claim))
}
}
}
4 changes: 4 additions & 0 deletions src/factory_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ fn test_deploy() {
assert(erc20.balance_of(get_contract_address()) == 5678 - 1111, 'deployer balance');
// assert(erc20.balance_of(result.airdrop.unwrap().contract_address) == 1111, 'airdrop balance');

let drop = result.airdrop.unwrap();
assert(drop.get_root() == 'root', 'airdrop root');
assert(drop.get_token().contract_address == result.token.contract_address, 'airdrop token');

assert(
result.governor.get_voting_token().contract_address == result.token.contract_address,
'voting_token'
Expand Down

0 comments on commit c025030

Please sign in to comment.