Skip to content

Commit

Permalink
feat: get live proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveVodrazka committed Dec 18, 2023
1 parent a74c50a commit 7a51665
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ build:
# STARKNET_ACCOUNT - path to account file
# STARKNET_KEYSTORE - path to keystore file
# STARKNET_RPC - RPC node URL - network will be selected based on RPC network
_declare:
starkli declare target/dev/governance_Governance.contract_class.json


declare: build declare
declare:
@FILE_PATH=$(shell find target/dev -type f -name "*.contract_class.json"); \
echo $${FILE_PATH}; \
starkli declare $${FILE_PATH}
6 changes: 6 additions & 0 deletions src/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ trait IGovernance<TContractState> {
fn get_vote_counts(self: @TContractState, prop_id: u32) -> VoteCount;
fn submit_proposal(ref self: TContractState, impl_hash: felt252, to_upgrade: u8) -> u32;
fn get_proposal_status(self: @TContractState, prop_id: u32) -> PropStatus;
fn get_live_proposals(self: @TContractState) -> Array<u32>;

// UPGRADES

Expand All @@ -36,6 +37,7 @@ mod Governance {
BlockNumber, ContractType, PropDetails, PropStatus, VoteStatus, VoteCount
};
use governance::proposals::Proposals;
use governance::proposals::Proposals::get_free_prop_id_timestamp;
use governance::upgrades::Upgrades;
use governance::options::Options;
use governance::airdrop::airdrop as airdrop_component;
Expand Down Expand Up @@ -124,6 +126,10 @@ mod Governance {
Proposals::get_proposal_status(prop_id)
}

fn get_live_proposals(self: @ContractState) -> Array<u32> {
Proposals::get_live_proposals()
}

// UPGRADES

fn get_governance_token_address(self: @ContractState) -> ContractAddress {
Expand Down
24 changes: 23 additions & 1 deletion src/proposals.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,27 @@ mod Proposals {
}
}

fn get_live_proposals() -> Array<u32> {
let max = get_free_prop_id_timestamp();
let mut i: u32 = 0;
let mut arr = ArrayTrait::<u32>::new();

loop {
if i >= max {
break;
}
let current_status = get_proposal_status(i);

if current_status.code == 2 {
arr.append(i);
}

i += 1;
};

arr
}

fn submit_proposal(payload: felt252, to_upgrade: u8) -> u32 {
assert_correct_contract_type(to_upgrade);
let mut state = Governance::unsafe_new_contract_state();
Expand All @@ -117,7 +138,8 @@ mod Proposals {
state.proposal_details.write(prop_id, prop_details);

let current_timestamp: u64 = get_block_timestamp();
let end_timestamp: u64 = current_timestamp + 600; // ten minutes
let end_timestamp: u64 = current_timestamp
+ 600; // TODO: change back to current_timestamp + constants::PROPOSAL_VOTING_SECONDS
state.proposal_vote_end_timestamp.write(prop_id, end_timestamp);

state.emit(Governance::Proposed { prop_id, payload, to_upgrade });
Expand Down

0 comments on commit 7a51665

Please sign in to comment.