Skip to content

Commit

Permalink
Allow describing proposals on-chain
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Apr 11, 2024
1 parent 264e811 commit 489e243
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/airdrop_claim_check.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use starknet::{ContractAddress};
use governance::airdrop::{IAirdropDispatcher};
use starknet::{ContractAddress};

#[derive(Serde, Copy, Drop)]
struct CheckParams {
Expand All @@ -21,11 +21,11 @@ trait IAirdropClaimCheck<TContractState> {

#[starknet::contract]
mod AirdropClaimCheck {
use super::{IAirdropClaimCheck, IAirdropDispatcher, CheckParams, CheckResult};
use governance::airdrop::{IAirdropDispatcherTrait};
use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait};
use core::array::{SpanTrait};
use core::option::{OptionTrait};
use governance::airdrop::{IAirdropDispatcherTrait};
use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait};
use super::{IAirdropClaimCheck, IAirdropDispatcher, CheckParams, CheckResult};

#[storage]
struct Storage {}
Expand Down
21 changes: 20 additions & 1 deletion src/governor.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::array::{Array};
use core::byte_array::{ByteArray};
use core::integer::{u128_safe_divmod};
use core::option::{Option, OptionTrait};
use core::traits::{Into, TryInto};
Expand Down Expand Up @@ -49,6 +50,9 @@ pub trait IGovernor<TContractState> {
// Execute the given proposal.
fn execute(ref self: TContractState, call: Call) -> Span<felt252>;

// Attaches the given text to the proposal. Triggers an event containing the proposal description.
fn describe(ref self: TContractState, id: felt252, description: ByteArray);

// Get the configuration for this governor contract.
fn get_staker(self: @TContractState) -> IStakerDispatcher;

Expand All @@ -68,7 +72,7 @@ pub mod Governor {
use starknet::{get_block_timestamp, get_caller_address, contract_address_const};
use super::{
IStakerDispatcher, ContractAddress, Array, IGovernor, Config, ProposalInfo, Call,
ExecutionState
ExecutionState, ByteArray
};


Expand All @@ -79,6 +83,12 @@ pub mod Governor {
pub call: Call,
}

#[derive(starknet::Event, Drop)]
pub struct Described {
pub id: felt252,
pub description: ByteArray,
}

#[derive(starknet::Event, Drop)]
pub struct Voted {
pub id: felt252,
Expand All @@ -101,6 +111,7 @@ pub mod Governor {
#[event]
enum Event {
Proposed: Proposed,
Described: Described,
Voted: Voted,
Canceled: Canceled,
Executed: Executed,
Expand Down Expand Up @@ -183,6 +194,14 @@ pub mod Governor {
id
}

fn describe(ref self: ContractState, id: felt252, description: ByteArray) {
let proposal = self.proposals.read(id);
assert(proposal.proposer == get_caller_address(), 'NOT_PROPOSER');
assert(proposal.execution_state.executed.is_zero(), 'ALREADY_EXECUTED');
assert(proposal.execution_state.canceled.is_zero(),'CANCELED');
self.emit(Described { id, description });
}

fn vote(ref self: ContractState, id: felt252, yea: bool) {
let mut proposal = self.proposals.read(id);

Expand Down
2 changes: 1 addition & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod airdrop_claim_check;
pub mod airdrop;
mod airdrop_claim_check;

#[cfg(test)]
pub(crate) mod airdrop_test;
Expand Down

0 comments on commit 489e243

Please sign in to comment.