-
Notifications
You must be signed in to change notification settings - Fork 2
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
Build a basic stake controlled governance contract #36
Comments
Hello @mariopil and @geofmureithi , from now you can follow up the work on this draft PR: #51 . I will try to push commits frequently. Feel free to comment anything you would like to change at any point :) |
Alright ! here is an status update of the work done till now: Currently, the contract can manage the staking part, which means the following API is available: #[contractimpl]
impl GovernanceContract {
pub fn init(env: Env, curator: Address, token: Address) {
// ...
}
pub fn join(env: Env, participant_addr: Address, amount: i128) -> Result<(), Error> {
// ...
}
pub fn stake(env: Env, participant: Address, amount: i128) -> Result<(), Error> {
// ...
}
pub fn leave(env: Env, participant: Address) -> Result<(), Error> {
// ...
}
pub fn withdraw(env: Env, participant: Address, amount: i128) -> Result<(), Error> {
// ...
}
} I am now continuing implementing the proposal/voting API, taking into account the I think i am going to proceed and implement all the functionality first. Probably composability for the UI is not going to be the best in the first POC. But i just want to see the patterns in code. Then we can discuss how to refactor it. I will continue pushing this little summaries for keeping you up to date @geofmureithi @mariopil |
First POC version (proposal)During the last days we were able to implement a first version of a stake controlled governance contract that accomplishes most of the previously commented objectives. All the code is available in the related PR, but lest do a walk through the most important aspects, so the later review will be easier. OverviewThe proposal is to re-use our current voting contract in a way the call tree is like this: graph LR;
user--> GovernanceContract -- only_admin_mode --> VotingContract
The The Authorizations from participants are being forwarded accordingly during the cross contract calls. API surfaceHeres is the updated API surface. Hope is enough intuititve. #[contractimpl]
impl GovernanceContract {
pub fn init(env: Env, curator: Address, token: Address) {
// ...
}
pub fn join(env: Env, participant_addr: Address, amount: i128) -> Result<(), Error> {
// ...
}
pub fn stake(env: Env, participant: Address, amount: i128) -> Result<(), Error> {
// ...
}
pub fn leave(env: Env, participant: Address) -> Result<(), Error> {
// ...
}
pub fn withdraw(env: Env, participant: Address, amount: i128) -> Result<(), Error> {
// ...
}
pub fn new_proposal(env: Env, participant: Address, id: u64, kind: ProposalType, new_contract_hash: BytesN<32>) -> Result<(), Error> {
// ...
}
pub fn vote(env: Env, participant: Address, id: u64) -> Result<(), Error> {
// ...
}
pub fn execute_proposal(env: Env, participant: Address, id: u64) -> Result<(), Error> {
// ...
}
} Regarding the stateDuring the voting phase, the I have certain concerns here regarding how this would work at scale. Maybe a good test for this would be to simulate a contract with millions of participants and proposals, while drawing a fee curve x->(participants+proposals) y->(fee per operation) and see if it grows. Published events should be used by Quasar (indexer) to provide a near-realtime view of the status of a proposal, as all staked amounts and voting operations are being reflected in published events (see below). Supported proposalsThe current design should allow the code to be easily extended with more proposal types. Here are the current ones:
Generalization of the Voting contractSome changes have been done in the Strategy with eventsWe have 2 contracts on this equation ( There is an initial event published by the The following events should be synchronized with the developments in Events of the Governance contractenv.events().publish(
(Symbol::new(&env, "participant_joined"), participant_addr),
(),
); env.events()
.publish((Symbol::new(env, "stake"), participant.address()), amount); env.events()
.publish((Symbol::new(&env, "participant_left"), &participant), ()); env.events().publish(
(Symbol::new(env, "withdraw"), participant.address()),
amount,
); env.events()
.publish((Symbol::new(&env, "participant_whitelisted"),), participant); env.events().publish(
(Symbol::new(&env, "proposal_executed"), &participant, id),
(),
); Events of the Voting contractenv.events().publish(
(Symbol::new(&env, "proposal_created"), id, kind, proposer),
()
); env.events().publish(
(Symbol::new(&env, "proposal_voted"), id, voter),
updated_approval_rate,
); Deviations from the initial plan (see issue description)
Having a status field on a proposal is tricky. Because we would depend in contract invokations in order to update it. So the status is calculated each time someone invokes
The current approach is to preserve the current participation system, as it is naturally aligned with the current voting system of the
Yes, for whitelisting participants. But whitelisting proposals is probably too much, so it was initially not implemented. Only the whitelisted participants balance will be taken into account for approval rates calculation. Exceeding the Fee budgetWhile testing the env.budget().reset_unlimited() This could be seen as a bad practice, but taking into account Stellar network is still determining this limits (See #42 ) , i think the proper thing should be to check Discord regarding this. IMO, we are not doing many calls, but limits looks too much conservative. New tools creationSome little experimentation has been done in order to improve the readbility of the code (see linked PR) like:
Other ideas and thoughts
Conclusions
Possible next steps (Heading to production code)In order of priority i would:
Let me know your thoughts ! Any feedback is welcome. Moving this issue and PR to review ⏩ |
Hello @geofmureithi @mariopil , there are some improvements in the governance contract. Please check last commits in the PR they have reasonable descriptions and are atomic enough IMO. Moving #51 for review again ! thanks ! ⏩ The main difference is that now cross contract calls are performed through |
While adding docs i felt i was repeating things and thought about this #86 , let me know your thoughts there :) |
Context
Possible interesting links:
Goal
Governance contract invariants
Aside thoughts:
The text was updated successfully, but these errors were encountered: