From d50f59304cb40f13cb5d162179d91b93e1fedef9 Mon Sep 17 00:00:00 2001 From: DaveVodrazka Date: Mon, 11 Dec 2023 10:24:39 +0100 Subject: [PATCH] feat: voting time one week --- src/constants.cairo | 1 + src/contract.cairo | 2 +- src/proposals.cairo | 24 ++++++++++-------------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/constants.cairo b/src/constants.cairo index 7930d5a8..fc1e6276 100644 --- a/src/constants.cairo +++ b/src/constants.cairo @@ -8,3 +8,4 @@ const OPTION_CALL: felt252 = 0; const OPTION_PUT: felt252 = 1; const TRADE_SIDE_LONG: felt252 = 0; const TRADE_SIDE_SHORT: felt252 = 1; +const ONE_WEEK_SECONDS: u64 = 604800; diff --git a/src/contract.cairo b/src/contract.cairo index 558f45d2..a276a4b7 100644 --- a/src/contract.cairo +++ b/src/contract.cairo @@ -54,7 +54,7 @@ mod Governance { #[storage] struct Storage { proposal_details: LegacyMap::, - proposal_vote_ends: LegacyMap::, + proposal_vote_ends: LegacyMap::, proposal_voted_by: LegacyMap::<(felt252, ContractAddress), VoteStatus>, proposal_total_yay: LegacyMap::, proposal_total_nay: LegacyMap::, diff --git a/src/proposals.cairo b/src/proposals.cairo index 61fa93de..6a110bbe 100644 --- a/src/proposals.cairo +++ b/src/proposals.cairo @@ -61,13 +61,12 @@ mod Proposals { fn assert_voting_in_progress(prop_id: felt252) { let state = Governance::unsafe_new_contract_state(); - let end_block_number_felt: felt252 = state.proposal_vote_ends.read(prop_id); - let end_block_number: u64 = end_block_number_felt.try_into().unwrap(); - assert(end_block_number != 0, 'prop_id not found'); + let end_timestamp: u64 = state.proposal_vote_ends.read(prop_id); + assert(end_timestamp != 0, 'prop_id not found'); - let current_block_number: u64 = get_block_info().unbox().block_number; + let current_timestamp: u64 = get_block_info().unbox().block_timestamp; - assert(end_block_number > current_block_number, 'voting concluded'); + assert(end_timestamp > current_timestamp, 'voting concluded'); } fn as_u256(high: u128, low: u128) -> u256 { @@ -106,11 +105,9 @@ mod Proposals { let prop_details = PropDetails { payload: payload, to_upgrade: to_upgrade }; state.proposal_details.write(prop_id, prop_details); - let current_block_number: u64 = get_block_info().unbox().block_number; - let end_block_number: BlockNumber = (current_block_number - + constants::PROPOSAL_VOTING_TIME_BLOCKS) - .into(); - state.proposal_vote_ends.write(prop_id, end_block_number); + let current_timestamp: u64 = get_block_info().unbox().block_timestamp; + let end_timestamp: u64 = current_timestamp + constants::ONE_WEEK_SECONDS; + state.proposal_vote_ends.write(prop_id, end_timestamp); state.emit(Governance::Proposed { prop_id, payload, to_upgrade }); prop_id @@ -303,11 +300,10 @@ mod Proposals { fn get_proposal_status(prop_id: felt252) -> felt252 { let state = Governance::unsafe_new_contract_state(); - let end_block_number_felt: felt252 = state.proposal_vote_ends.read(prop_id); - let end_block_number: u64 = end_block_number_felt.try_into().unwrap(); - let current_block_number: u64 = get_block_info().unbox().block_number; + let end_timestamp: u64 = state.proposal_vote_ends.read(prop_id); + let current_timestamp: u64 = get_block_info().unbox().block_timestamp; - if current_block_number <= end_block_number { + if current_timestamp <= end_timestamp { return check_proposal_passed_express(prop_id).into(); }