Skip to content

Commit

Permalink
feat: add get_proposal_status
Browse files Browse the repository at this point in the history
  • Loading branch information
pscott committed Aug 30, 2023
1 parent aaa5b80 commit eb04552
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 9 deletions.
11 changes: 11 additions & 0 deletions starknet/src/execution_strategies/eth_relayer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,16 @@ mod EthRelayerExecutionStrategy {

send_message_to_l1_syscall(l1_destination, message_payload);
}

fn get_proposal_status(
self: @TContractState,
proposal: Proposal,
votes_for: u256,
votes_against: u256,
votes_abstain: u256,
) -> ProposalStatus {
panic_with_felt252('unimplemented');
ProposalStatus::Cancelled(())
}
}
}
2 changes: 1 addition & 1 deletion starknet/src/execution_strategies/simple_quorum.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod SimpleQuorumExecutionStrategy {
proposal: @Proposal,
votes_for: u256,
votes_against: u256,
votes_abstain: u256
votes_abstain: u256,
) -> ProposalStatus {
let accepted = _quorum_reached(self._quorum.read(), votes_for, votes_against, votes_abstain)
& _supported(votes_for, votes_against);
Expand Down
24 changes: 17 additions & 7 deletions starknet/src/execution_strategies/vanilla.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ mod VanillaExecutionStrategy {
votes_abstain: u256,
payload: Array<felt252>
) {
// TODO: this is probably wrong.
let mut state: SimpleQuorumExecutionStrategy::ContractState =
SimpleQuorumExecutionStrategy::unsafe_new_contract_state();

let proposal_status = SimpleQuorumExecutionStrategy::get_proposal_status(
@state, @proposal, votes_for, votes_against, votes_abstain
);
let proposal_status = self
.get_proposal_status(proposal, votes_for, votes_against, votes_abstain,);
assert(
(proposal_status == ProposalStatus::Accepted(()))
| (proposal_status == ProposalStatus::VotingPeriodAccepted(())),
Expand All @@ -34,6 +29,21 @@ mod VanillaExecutionStrategy {
self._num_executed.write(self._num_executed.read() + 1);
}

fn get_proposal_status(
self: @ContractState,
proposal: Proposal,
votes_for: u256,
votes_against: u256,
votes_abstain: u256,
) -> ProposalStatus {
let mut state: SimpleQuorumExecutionStrategy::ContractState =
SimpleQuorumExecutionStrategy::unsafe_new_contract_state();

SimpleQuorumExecutionStrategy::get_proposal_status(
@state, @proposal, votes_for, votes_against, votes_abstain,
)
}

fn get_strategy_type(self: @ContractState) -> felt252 {
'SimpleQuorumVanilla'
}
Expand Down
11 changes: 10 additions & 1 deletion starknet/src/interfaces/i_execution_strategy.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use array::ArrayTrait;
use sx::types::Proposal;
use sx::types::{Proposal, ProposalStatus};
use serde::Serde;

#[starknet::interface]
trait IExecutionStrategy<TContractState> {
Expand All @@ -12,5 +13,13 @@ trait IExecutionStrategy<TContractState> {
payload: Array<felt252>
);

fn get_proposal_status(
self: @TContractState,
proposal: Proposal,
votes_for: u256,
votes_against: u256,
votes_abstain: u256,
) -> ProposalStatus;

fn get_strategy_type(self: @TContractState) -> felt252;
}
22 changes: 22 additions & 0 deletions starknet/src/tests/mocks/executor.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ mod ExecutorExecutionStrategy {
call_contract_syscall(tx.target, tx.selector, tx.data.span()).unwrap();
}

fn get_proposal_status(
self: @ContractState,
proposal: Proposal,
votes_for: u256,
votes_against: u256,
votes_abstain: u256,
) -> ProposalStatus {
panic_with_felt252('unimplemented');
ProposalStatus::Cancelled(())
}

fn get_strategy_type(self: @ContractState) -> felt252 {
'Executor'
}
Expand Down Expand Up @@ -65,6 +76,17 @@ mod ExecutorWithoutTxExecutionStrategy {
payload: Array<felt252>
) {}

fn get_proposal_status(
self: @ContractState,
proposal: Proposal,
votes_for: u256,
votes_against: u256,
votes_abstain: u256,
) -> ProposalStatus {
panic_with_felt252('unimplemented');
ProposalStatus::Cancelled(())
}

fn get_strategy_type(self: @ContractState) -> felt252 {
'ExecutorWithoutTx'
}
Expand Down

0 comments on commit eb04552

Please sign in to comment.