-
Notifications
You must be signed in to change notification settings - Fork 54
Governance base contract #563
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
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
98c55e0
wip
ozgunozerk ba57bed
wip
ozgunozerk 8173627
base implementations are done
ozgunozerk 185d0e6
inline docs
ozgunozerk a13014a
quorum and get_votes integration
ozgunozerk 79b1b44
fmt
ozgunozerk c21e74e
quorum extracted
ozgunozerk 2abca20
Merge branch 'main' into governance-base-contract
ozgunozerk 6b54744
suggestions
ozgunozerk a229f74
fmt
ozgunozerk 4858385
suggestions
ozgunozerk 289006c
blacklist instead of whitelist states for cancel
ozgunozerk 9af9fdf
state inline docs
ozgunozerk 537cbd1
also comment trait method
ozgunozerk fcc80d4
Merge branch 'main' into governance-base-contract
ozgunozerk 25c5287
Update packages/governance/src/governor/mod.rs
ozgunozerk 5483c45
Update packages/governance/src/governor/storage.rs
ozgunozerk efb640b
Update packages/governance/src/governor/mod.rs
ozgunozerk d8aa73f
suggestions
ozgunozerk 98d4372
pending vs active state
ozgunozerk 7994a9a
quorum and counting
ozgunozerk 0b58ae2
suggestions
ozgunozerk 7fe4fd5
Merge branch 'counting' into governance-base-contract
ozgunozerk 5186a4d
merge quorum/counting into governor, and tests
ozgunozerk cacf3ba
Merge branch 'main' into governance-base-contract
ozgunozerk d9e6227
example contract
ozgunozerk 99a676d
suggestions
ozgunozerk 5e14335
suggestion
ozgunozerk cf2321a
suggestions
ozgunozerk aec779f
fmt
ozgunozerk 2de0f1b
queue logic better integration
ozgunozerk 8b8aa63
fix comments
ozgunozerk e85ef37
Merge branch 'main' into governance-base-contract
ozgunozerk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| [package] | ||
| name = "fungible-governor-example" | ||
| edition.workspace = true | ||
| license.workspace = true | ||
| repository.workspace = true | ||
| publish = false | ||
| version.workspace = true | ||
|
|
||
| [lib] | ||
| crate-type = ["cdylib"] | ||
| doctest = false | ||
|
|
||
| [dependencies] | ||
| soroban-sdk = { workspace = true } | ||
| stellar-access = { workspace = true } | ||
| stellar-governance = { workspace = true } | ||
| stellar-macros = { workspace = true } | ||
| stellar-tokens = { workspace = true } | ||
|
|
||
| [dev-dependencies] | ||
| soroban-sdk = { workspace = true, features = ["testutils"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| use soroban_sdk::{contract, contractimpl, Address, BytesN, Env, String, Symbol, Val, Vec}; | ||
| use stellar_governance::governor::{ | ||
| storage::{self, set_token_contract}, | ||
| Governor, ProposalState, | ||
| }; | ||
|
|
||
| #[contract] | ||
| pub struct GovernorContract; | ||
|
|
||
| #[contractimpl] | ||
| impl GovernorContract { | ||
| pub fn __constructor( | ||
| e: &Env, | ||
| token_contract: Address, | ||
| voting_delay: u32, | ||
| voting_period: u32, | ||
| proposal_threshold: u128, | ||
| quorum: u128, | ||
| ) { | ||
| storage::set_name(e, String::from_str(e, "ExampleGovernor")); | ||
| storage::set_version(e, String::from_str(e, "1.0.0")); | ||
| set_token_contract(e, &token_contract); | ||
| storage::set_voting_delay(e, voting_delay); | ||
| storage::set_voting_period(e, voting_period); | ||
| storage::set_proposal_threshold(e, proposal_threshold); | ||
| storage::set_quorum(e, quorum); | ||
| } | ||
| } | ||
|
|
||
| #[contractimpl(contracttrait)] | ||
| impl Governor for GovernorContract { | ||
| fn execute( | ||
| e: &Env, | ||
| targets: Vec<Address>, | ||
| functions: Vec<Symbol>, | ||
| args: Vec<Vec<Val>>, | ||
| description_hash: BytesN<32>, | ||
| executor: Address, | ||
| ) -> BytesN<32> { | ||
| // Open execution: any account can trigger a succeeded proposal, | ||
| // as long as they authenticate themselves as `executor`. | ||
| executor.require_auth(); | ||
| storage::execute( | ||
| e, | ||
| targets, | ||
| functions, | ||
| args, | ||
| &description_hash, | ||
| Self::proposal_needs_queuing(e), | ||
| ) | ||
| } | ||
|
|
||
| fn cancel( | ||
| e: &Env, | ||
| targets: Vec<Address>, | ||
| functions: Vec<Symbol>, | ||
| args: Vec<Vec<Val>>, | ||
| description_hash: BytesN<32>, | ||
| operator: Address, | ||
| ) -> BytesN<32> { | ||
| // Restricted cancellation: only the original proposer can cancel. | ||
| let proposal_id = storage::hash_proposal(e, &targets, &functions, &args, &description_hash); | ||
| let proposer = storage::get_proposal_proposer(e, &proposal_id); | ||
| assert!(operator == proposer); | ||
| operator.require_auth(); | ||
| storage::cancel(e, targets, functions, args, &description_hash) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #![no_std] | ||
|
|
||
| mod governor; | ||
| mod token; | ||
|
|
||
| #[cfg(test)] | ||
| mod test; | ||
|
|
||
| pub use governor::*; | ||
| pub use token::*; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.