Skip to content

Commit

Permalink
refactor: change data types to handle ERC20 tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfalt committed Oct 11, 2024
1 parent 6556f6e commit dccfb7b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion contracts/src/constants/donator/donator_constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
// *************************************************************************
pub mod DonatorConstants {
pub const INITIAL_LEVEL: u32 = 1;
pub const INITIAL_MAX_STARKS_DONATION_TO_NEXT_LEVEL: u64 = 10;
pub const INITIAL_MAX_STARKS_DONATION_TO_NEXT_LEVEL: u256 = 10;
}
2 changes: 1 addition & 1 deletion contracts/src/constants/funds/fund_constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
pub mod FundConstants {
pub const UP_VOTES_NEEDED: u32 = 100;
pub const INITIAL_UP_VOTES: u32 = 0;
pub const INITIAL_GOAL: u64 = 0;
pub const INITIAL_GOAL: u256 = 0;
}
16 changes: 8 additions & 8 deletions contracts/src/donator.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use starknet::ContractAddress;
pub trait IDonator<TContractState> {
fn getOwner(self: @TContractState) -> ContractAddress;
fn getLevel(self: @TContractState) -> u32;
fn getTotalStarkDonations(self: @TContractState) -> u64;
fn getMaxStarkDonationsToNextLevel(self: @TContractState) -> u64;
fn updateDonatorValues(ref self: TContractState, donated_starks: u64);
fn getTotalStarkDonations(self: @TContractState) -> u256;
fn getMaxStarkDonationsToNextLevel(self: @TContractState) -> u256;
fn updateDonatorValues(ref self: TContractState, donated_starks: u256);
}

#[starknet::contract]
Expand All @@ -24,8 +24,8 @@ mod Donator {
struct Storage {
owner: ContractAddress,
level: u32,
total_stark_donations: u64,
max_stark_donations_to_next_level: u64
total_stark_donations: u256,
max_stark_donations_to_next_level: u256
}

// *************************************************************************
Expand All @@ -52,13 +52,13 @@ mod Donator {
fn getLevel(self: @ContractState) -> u32 {
return self.level.read();
}
fn getTotalStarkDonations(self: @ContractState) -> u64 {
fn getTotalStarkDonations(self: @ContractState) -> u256 {
return self.total_stark_donations.read();
}
fn getMaxStarkDonationsToNextLevel(self: @ContractState) -> u64 {
fn getMaxStarkDonationsToNextLevel(self: @ContractState) -> u256 {
return self.max_stark_donations_to_next_level.read();
}
fn updateDonatorValues(ref self: ContractState, donated_starks: u64) {
fn updateDonatorValues(ref self: ContractState, donated_starks: u256) {
let total_donator_pod = self.total_stark_donations.read() + donated_starks;
self.total_stark_donations.write(total_donator_pod);
if (total_donator_pod > self.max_stark_donations_to_next_level.read()) {
Expand Down
22 changes: 11 additions & 11 deletions contracts/src/fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ pub trait IFund<TContractState> {
fn getReason(self: @TContractState) -> ByteArray;
fn receiveVote(ref self: TContractState);
fn getUpVotes(self: @TContractState) -> u32;
fn setGoal(ref self: TContractState, goal: u64);
fn getGoal(self: @TContractState) -> u64;
fn receiveDonation(ref self: TContractState, strks: u64);
fn getCurrentGoalState(self: @TContractState) -> u64;
fn setGoal(ref self: TContractState, goal: u256);
fn getGoal(self: @TContractState) -> u256;
fn receiveDonation(ref self: TContractState, strks: u256);
fn getCurrentGoalState(self: @TContractState) -> u256;
fn setIsActive(ref self: TContractState, state: u8);
fn getIsActive(self: @TContractState) -> u8;
fn getVoter(self: @TContractState) -> u32;
Expand Down Expand Up @@ -41,8 +41,8 @@ mod Fund {
reason: ByteArray,
up_votes: u32,
voters: LegacyMap::<ContractAddress, u32>,
goal: u64,
current_goal_state: u64,
goal: u256,
current_goal_state: u256,
state: u8
}

Expand All @@ -51,7 +51,7 @@ mod Fund {
// *************************************************************************
#[constructor]
fn constructor(
ref self: ContractState, id: u128, owner: ContractAddress, name: felt252, goal: u64
ref self: ContractState, id: u128, owner: ContractAddress, name: felt252, goal: u256
) {
self.id.write(id);
self.owner.write(owner);
Expand Down Expand Up @@ -104,16 +104,16 @@ mod Fund {
fn getUpVotes(self: @ContractState) -> u32 {
return self.up_votes.read();
}
fn setGoal(ref self: ContractState, goal: u64) {
fn setGoal(ref self: ContractState, goal: u256) {
let caller = get_caller_address();
assert!(self.owner.read() == caller, "You are not the owner");
self.goal.write(goal);
}
fn getGoal(self: @ContractState) -> u64 {
fn getGoal(self: @ContractState) -> u256 {
return self.goal.read();
}
// TODO: implement the logic where user actually donates starks
fn receiveDonation(ref self: ContractState, strks: u64) {
fn receiveDonation(ref self: ContractState, strks: u256) {
assert(
self.state.read() == FundStates::RECOLLECTING_DONATIONS,
'Fund not recollecting dons!'
Expand All @@ -123,7 +123,7 @@ mod Fund {
self.state.write(FundStates::CLOSED);
}
}
fn getCurrentGoalState(self: @ContractState) -> u64 {
fn getCurrentGoalState(self: @ContractState) -> u256 {
return self.current_goal_state.read();
}
// TODO: Validate to change method to change setState and getState
Expand Down

0 comments on commit dccfb7b

Please sign in to comment.