Skip to content

Commit

Permalink
wip governance
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Jul 24, 2024
1 parent 5207ed7 commit f8fae8c
Show file tree
Hide file tree
Showing 40 changed files with 265 additions and 141 deletions.
7 changes: 7 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ dependencies = [
"cubit",
]

[[package]]
name = "origami_governance"
version = "0.1.0"
dependencies = [
"dojo",
]

[[package]]
name = "origami_map"
version = "0.1.0"
Expand Down
6 changes: 2 additions & 4 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
[workspace]
members = [
# Scarb dependent crates.
"crates/algebra",
"crates/defi",
"crates/map",
"crates/random",
"crates/rating",
"crates/security",

# Sozo dependent crates.
"crates/token",
# "governance"
# WIP porting Governance to Cairo 2.7 and Dojo 1.0.0.
# "crates/governance"
]

[workspace.dependencies]
Expand Down
9 changes: 6 additions & 3 deletions crates/governance/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "governance"
version = "0.0.0"
name = "origami_governance"
version = "0.1.0"
description = "Implementations of Compound Governance standards for the Dojo framework."
homepage = "https://github.com/dojoengine/origami/tree/governance"

Expand All @@ -12,4 +12,7 @@ sort-module-level-items = true

[lib]

[[target.dojo]]
[tool.dojo.world]
name = "governance"
seed = "governance"
namespace = { default = "origami_governance" }
56 changes: 35 additions & 21 deletions crates/governance/src/libraries/events.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
mod tokenevents {
use starknet::ContractAddress;

#[derive(Model, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::model]
#[dojo::event]
struct DelegateChanged {
#[key]
Expand All @@ -10,16 +11,18 @@ mod tokenevents {
to: ContractAddress,
}

#[derive(Model, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct DelegateVotesChanged {
#[key]
delegatee: ContractAddress,
prev_balance: u128,
new_balance: u128,
}

#[derive(Model, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::model]
#[dojo::event]
struct Transfer {
#[key]
Expand All @@ -28,7 +31,8 @@ mod tokenevents {
amount: u128,
}

#[derive(Model, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::model]
#[dojo::event]
struct Approval {
#[key]
Expand All @@ -41,68 +45,75 @@ mod tokenevents {
mod timelockevents {
use starknet::{ContractAddress, ClassHash};

#[derive(Model, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct NewAdmin {
#[key]
contract: ContractAddress,
contract_selector: felt252,
address: ContractAddress,
}

#[derive(Model, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct NewDelay {
#[key]
contract: ContractAddress,
contract_selector: felt252,
value: u64,
}

#[derive(Model, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct CancelTransaction {
#[key]
target: ContractAddress,
target_selector: felt252,
class_hash: ClassHash,
eta: u64,
}

#[derive(Model, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct ExecuteTransaction {
#[key]
target: ContractAddress,
target_selector: felt252,
class_hash: ClassHash,
eta: u64,
}

#[derive(Model, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct QueueTransaction {
#[key]
target: ContractAddress,
target_selector: felt252,
class_hash: ClassHash,
eta: u64,
}
}

mod governorevents {
use governance::models::governor::Support;
use origami_governance::models::governor::Support;
use starknet::{ContractAddress, ClassHash};

#[derive(Model, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct ProposalCreated {
#[key]
id: usize,
proposer: ContractAddress,
target: ContractAddress,
target_selector: felt252,
class_hash: ClassHash,
start_block: u64,
end_block: u64,
}

#[derive(Model, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct VoteCast {
#[key]
voter: ContractAddress,
Expand All @@ -111,24 +122,27 @@ mod governorevents {
votes: u128,
}

#[derive(Model, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct ProposalCanceled {
#[key]
id: usize,
cancelled: bool,
}

#[derive(Model, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct ProposalQueued {
#[key]
id: usize,
eta: u64,
}

#[derive(Model, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct ProposalExecuted {
#[key]
id: usize,
Expand Down
10 changes: 5 additions & 5 deletions crates/governance/src/models/governor.cairo
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use governance::libraries::traits::{ContractAddressDefault, ClassHashDefault};
use origami_governance::libraries::traits::{ContractAddressDefault, ClassHashDefault};
use starknet::{ContractAddress, ClassHash};

#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct GovernorParams {
#[key]
contract: ContractAddress,
contract_selector: felt252,
timelock: ContractAddress,
gov_token: ContractAddress,
guardian: ContractAddress,
Expand All @@ -15,7 +15,7 @@ struct GovernorParams {
#[derive(Copy, Drop, Serde)]
struct ProposalParams {
#[key]
contract: ContractAddress,
contract_selector: felt252,
quorum_votes: u128,
threshold: u128,
voting_delay: u64,
Expand All @@ -26,7 +26,7 @@ struct ProposalParams {
#[derive(Copy, Drop, Serde)]
struct ProposalCount {
#[key]
contract: ContractAddress,
contract_selector: felt252,
count: usize,
}

Expand Down Expand Up @@ -61,7 +61,7 @@ struct Proposal {
id: usize,
proposer: ContractAddress,
eta: u64,
target: ContractAddress,
target_selector: felt252,
class_hash: ClassHash,
start_block: u64,
end_block: u64,
Expand Down
6 changes: 3 additions & 3 deletions crates/governance/src/models/timelock.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use starknet::{ContractAddress, ClassHash};
#[derive(Copy, Drop, Serde)]
struct TimelockParams {
#[key]
contract: ContractAddress,
contract_selector: felt252,
admin: ContractAddress,
delay: u64,
}
Expand All @@ -14,15 +14,15 @@ struct TimelockParams {
#[derive(Copy, Drop, Serde)]
struct PendingAdmin {
#[key]
contract: ContractAddress,
contract_selector: felt252,
address: ContractAddress,
}

#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct QueuedTransactions {
#[key]
contract: ContractAddress,
contract_selector: felt252,
#[key]
class_hash: ClassHash,
queued: bool,
Expand Down
Loading

0 comments on commit f8fae8c

Please sign in to comment.