Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compound like Governance Contracts #57

Merged
merged 36 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3c0a91a
repo init
ametel01 Apr 7, 2024
4ea0ddb
added token events
ametel01 Apr 7, 2024
76e0915
added token models
ametel01 Apr 7, 2024
858ad20
added token interface
ametel01 Apr 7, 2024
6fb7771
renamed spawn -> constructor for gov token
ametel01 Apr 7, 2024
15647c0
removed delegate by signature
ametel01 Apr 7, 2024
d5615ee
renamed delegate -> delegatee to prevent clash with fn naming
ametel01 Apr 7, 2024
943bb1f
added gov token contract
ametel01 Apr 7, 2024
39387d9
added timelock contracts to lib
ametel01 Apr 7, 2024
7626083
added timelock events
ametel01 Apr 7, 2024
ecd04ca
setup governor modules
ametel01 Apr 7, 2024
71db7c3
added timelock models
ametel01 Apr 7, 2024
632aec2
added empty timelock test
ametel01 Apr 7, 2024
9c87b5a
added timelock contract
ametel01 Apr 7, 2024
5755757
added timelock interface
ametel01 Apr 7, 2024
c013dd3
fmt
ametel01 Apr 7, 2024
e19dd28
renamed constructor -> initialize
ametel01 Apr 8, 2024
d4f31c4
added default for ContractAddress + ClassHash
ametel01 Apr 8, 2024
08bd234
add governor events
ametel01 Apr 8, 2024
984693e
add governor models
ametel01 Apr 8, 2024
d52c25e
add governor interface
ametel01 Apr 8, 2024
2a84909
add governor contract
ametel01 Apr 8, 2024
e334318
moved timelock fn from impl + interface to free
ametel01 Apr 8, 2024
7d7f099
moved token fn from impl + interface to free
ametel01 Apr 8, 2024
f2e42f2
added option for abstain vote
ametel01 Apr 8, 2024
8778574
removed custom default impl for enum
ametel01 Apr 8, 2024
4133cb5
cleanup
ametel01 Apr 8, 2024
a311cbd
reexposed fn that were prev free
ametel01 Apr 8, 2024
6e604ed
add #[abi(embed_v0)] to impl
ametel01 Apr 8, 2024
8d75827
Merge remote-tracking branch 'origin/main' into governance
ametel01 Apr 26, 2024
a1d00b0
fix on token tests
ametel01 Apr 26, 2024
6e83810
partial tests + fixes for governor
ametel01 Apr 27, 2024
0a785b8
added readme + examples
ametel01 Apr 27, 2024
f578c22
added ci tests for governance
ametel01 Apr 27, 2024
79f29c3
fmt
ametel01 Apr 27, 2024
84f9b24
moved examples to root of package
ametel01 Apr 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ name = "dojo_plugin"
version = "0.3.11"
source = "git+https://github.com/dojoengine/dojo?tag=v0.3.11#1e651b5d4d3b79b14a7d8aa29a92062fcb9e6659"

[[package]]
name = "governance"
version = "0.0.0"
dependencies = [
"dojo",
]

[[package]]
name = "hex_map"
version = "0.0.0"
Expand Down
1 change: 1 addition & 0 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"examples/market",
"examples/projectile",
"token",
"governance"
]

[workspace.package]
Expand Down
16 changes: 16 additions & 0 deletions governance/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "dojo"
version = "0.6.0"
source = "git+https://github.com/dojoengine/dojo?tag=v0.6.0#fc5ad790c1993713e59f3fc65739160f132f29f0"
dependencies = [
"dojo_plugin",
]

[[package]]
name = "dojo_plugin"
version = "0.3.11"
source = "git+https://github.com/dojoengine/dojo?tag=v0.3.11#1e651b5d4d3b79b14a7d8aa29a92062fcb9e6659"

15 changes: 15 additions & 0 deletions governance/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "governance"
version = "0.0.0"
description = "Implementations of Compound Governance standards for the Dojo framework."
homepage = "https://github.com/dojoengine/origami/tree/governance"

[dependencies]
dojo.workspace = true

[tool.fmt]
sort-module-level-items = true

[lib]

[[target.dojo]]
23 changes: 23 additions & 0 deletions governance/scripts/default_auth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -euo pipefail
pushd $(dirname "$0")/..

export RPC_URL="http://localhost:5050"

export WORLD_ADDRESS=$(cat ./manifests/deployments/KATANA.json | jq -r '.world.address')

export ACTIONS_ADDRESS=$(cat ./manifests/deployments/KATANA.json | jq -r '.contracts[] | select(.name == "dojo_starter::systems::actions::actions" ).address')

echo "---------------------------------------------------------------------------"
echo world : $WORLD_ADDRESS
echo " "
echo actions : $ACTIONS_ADDRESS
echo "---------------------------------------------------------------------------"

# enable system -> models authorizations
sozo auth grant --world $WORLD_ADDRESS --wait writer \
Position,$ACTIONS_ADDRESS \
Moves,$ACTIONS_ADDRESS \
>/dev/null

echo "Default authorizations have been successfully set."
12 changes: 12 additions & 0 deletions governance/scripts/spawn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -euo pipefail
pushd $(dirname "$0")/..

export RPC_URL="http://localhost:5050";

export WORLD_ADDRESS=$(cat ./manifests/deployments/KATANA.json | jq -r '.world.address')

export ACTIONS_ADDRESS=$(cat ./manifests/deployments/KATANA.json | jq -r '.contracts[] | select(.name == "dojo_starter::systems::actions::actions" ).address')

# sozo execute --world <WORLD_ADDRESS> <CONTRACT> <ENTRYPOINT>
sozo execute --world $WORLD_ADDRESS $ACTIONS_ADDRESS spawn --wait
28 changes: 28 additions & 0 deletions governance/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
mod libraries {
mod events;
}

mod models {
mod delegate;
mod delegator;
mod token;
}

mod systems {
mod delegate {
mod contract;
mod interface;
mod tests;
}
mod delegator {
mod contract;
mod interface;
mod tests;
}
mod token {
mod contract;
mod interface;
mod tests;
}
}

39 changes: 39 additions & 0 deletions governance/src/libraries/events.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
mod tokenevents {
use starknet::ContractAddress;

#[derive(Model, Copy, Drop, Serde)]
#[dojo::event]
struct DelegateChanged {
#[key]
delegator: ContractAddress,
from_delegate: ContractAddress,
to_delegate: ContractAddress,
}

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

#[derive(Model, Copy, Drop, Serde)]
#[dojo::event]
struct Transfer {
#[key]
from: ContractAddress,
to: ContractAddress,
amount: u128,
}

#[derive(Model, Copy, Drop, Serde)]
#[dojo::event]
struct Approval {
#[key]
owner: ContractAddress,
spender: ContractAddress,
amount: u128,
}
}
1 change: 1 addition & 0 deletions governance/src/models/delegate.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions governance/src/models/delegator.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

69 changes: 69 additions & 0 deletions governance/src/models/token.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use starknet::ContractAddress;

#[derive(Model, Copy, Drop, Serde)]
struct Metadata {
#[key]
token: ContractAddress,
name: felt252,
symbol: felt252,
decimals: u8,
}

#[derive(Model, Copy, Drop, Serde)]
struct TotalSupply {
#[key]
token: ContractAddress,
amount: u128,
}

#[derive(Model, Copy, Drop, Serde)]
struct Allowances {
#[key]
delegator: ContractAddress,
#[key]
delegate: ContractAddress,
amount: u128,
}

#[derive(Model, Copy, Drop, Serde)]
struct Balances {
#[key]
account: ContractAddress,
amount: u128,
}

#[derive(Model, Copy, Drop, Serde)]
struct Delegates {
#[key]
account: ContractAddress,
delegate: ContractAddress,
}

#[derive(Model, Copy, Drop, Serde)]
struct Checkpoints {
#[key]
account: ContractAddress,
#[key]
index: u128,
checkpoint: Checkpoint,
}

#[derive(Model, Copy, Drop, Serde)]
struct NumCheckpoints {
#[key]
account: ContractAddress,
count: u128,
}

#[derive(Model, Copy, Drop, Serde)]
struct Nonces {
#[key]
account: ContractAddress,
nonce: usize,
}

#[derive(Copy, Drop, Introspect, Serde)]
struct Checkpoint {
from_block: u64,
votes: u128,
}
1 change: 1 addition & 0 deletions governance/src/systems/delegate/contract.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions governance/src/systems/delegate/interface.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions governance/src/systems/delegate/tests.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions governance/src/systems/delegator/contract.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions governance/src/systems/delegator/interface.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions governance/src/systems/delegator/tests.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

21 changes: 21 additions & 0 deletions governance/src/systems/token/interface.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use starknet::ContractAddress;

#[dojo::interface]
trait IGovernanceToken {
fn spaw(
ametel01 marked this conversation as resolved.
Show resolved Hide resolved
name: felt252,
symbol: felt252,
decimals: u8,
initial_supply: u128,
recipient: ContractAddress
);
fn approve(spender: ContractAddress, amount: u128);
fn transfer(to: ContractAddress, amount: u128);
fn transfer_from(from: ContractAddress, to: ContractAddress, amount: u128);
fn delegate(delegatee: ContractAddress);
fn delegate_by_signature(
delegatee: ContractAddress, nonce: usize, expiry: u64, pk: felt252, r: felt252, s: felt252
);
fn get_current_votes(account: ContractAddress) -> u128;
fn get_prior_votes(account: ContractAddress, block_number: u64) -> u128;
}
1 change: 1 addition & 0 deletions governance/src/systems/token/tests.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading