-
Notifications
You must be signed in to change notification settings - Fork 77
Optimistic governance #396
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
base: develop
Are you sure you want to change the base?
Changes from all commits
31dd49b
a303f5c
81064fd
2e85455
7f458ea
63ed333
8606360
6702eaf
69a4b61
27962d0
2aa4420
0d55d11
5d012b1
c98ce2e
484e7ad
62e4d8a
a1acfaf
4731cf6
d05c432
98dfe15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| use super::*; | ||
|
|
||
| #[derive(Accounts)] | ||
| #[event_cpi] | ||
| pub struct FinalizeOptimisticProposal<'info> { | ||
| #[account(mut, seeds = [squads_multisig_program::SEED_PREFIX, squads_multisig_program::SEED_MULTISIG, dao.key().as_ref()], bump, seeds::program = squads_program)] | ||
| pub squads_multisig: Account<'info, squads_multisig_program::Multisig>, | ||
| #[account(mut, address = dao.optimistic_proposal.as_ref().unwrap().squads_proposal)] | ||
| pub squads_proposal: Box<Account<'info, squads_multisig_program::Proposal>>, | ||
|
|
||
| #[account(mut, has_one = squads_multisig)] | ||
| pub dao: Box<Account<'info, Dao>>, | ||
|
|
||
| pub squads_program: Program<'info, squads_multisig_program::program::SquadsMultisigProgram>, | ||
| } | ||
|
|
||
| impl FinalizeOptimisticProposal<'_> { | ||
| pub fn validate(&self) -> Result<()> { | ||
| require_keys_eq!(self.squads_proposal.multisig, self.dao.squads_multisig); | ||
|
|
||
| // A minimum of proposal duration must have passed since the the optimistic proposal was enqueued | ||
| // We know that the optimistic proposal is not None, because the address constraint would have already panicked | ||
| require_gte!( | ||
| Clock::get()?.unix_timestamp, | ||
| self.dao | ||
| .optimistic_proposal | ||
| .as_ref() | ||
| .unwrap() | ||
| .enqueued_timestamp | ||
| + self.dao.seconds_per_proposal as i64, | ||
| FutarchyError::ProposalTooYoung | ||
| ); | ||
|
|
||
| // Pool must be in spot state - no active proposals | ||
| // This should never be hit, but it's here for completeness | ||
| require!( | ||
| matches!(self.dao.amm.state, PoolState::Spot { .. }), | ||
| FutarchyError::PoolNotInSpotState | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn handle(ctx: Context<Self>) -> Result<()> { | ||
| let Self { | ||
| squads_multisig, | ||
| squads_proposal, | ||
| dao, | ||
| event_authority: _, | ||
| program: _, | ||
| squads_program, | ||
| } = ctx.accounts; | ||
|
|
||
| let dao_nonce = &dao.nonce.to_le_bytes(); | ||
| let dao_creator_key = dao.dao_creator.as_ref(); | ||
| let dao_seeds = &[b"dao".as_ref(), dao_creator_key, dao_nonce, &[dao.pda_bump]]; | ||
|
|
||
| let dao_signer = &[&dao_seeds[..]]; | ||
|
|
||
| squads_multisig_program::cpi::proposal_approve( | ||
| CpiContext::new_with_signer( | ||
| squads_program.to_account_info(), | ||
| squads_multisig_program::cpi::accounts::ProposalVote { | ||
| proposal: squads_proposal.to_account_info(), | ||
| multisig: squads_multisig.to_account_info(), | ||
| member: dao.to_account_info(), // DAO can approve the proposal | ||
| }, | ||
| dao_signer, | ||
| ), | ||
| squads_multisig_program::ProposalVoteArgs { memo: None }, | ||
| )?; | ||
|
|
||
| // Update the DAO state | ||
| dao.optimistic_proposal = None; | ||
| dao.seq_num += 1; | ||
|
|
||
| emit_cpi!(FinalizeOptimisticProposalEvent { | ||
| common: CommonFields::new(&Clock::get()?, dao.seq_num), | ||
| dao: dao.key(), | ||
| squads_proposal: squads_proposal.key(), | ||
| }); | ||
|
|
||
| Ok(()) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,6 +212,8 @@ impl InitializeDao<'_> { | |
| }, | ||
| team_sponsored_pass_threshold_bps, | ||
| team_address, | ||
| optimistic_proposal: None, | ||
| is_optimistic_governance_enabled: false, | ||
|
Comment on lines
+215
to
+216
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't we need to add some update account instructions again here
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. theoretically this could be a separate PR but I prefer it in this one
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }); | ||
|
|
||
| dao.invariant()?; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.