-
Notifications
You must be signed in to change notification settings - Fork 84
Remove proposal #415
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
Remove proposal #415
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ee7dd1d
fix up messy integer handling
pileks bd780a3
Merge remote-tracking branch 'origin/develop' into crit
pileks e7c2feb
removes proposal when called by admin
pileks 049c097
Merge remote-tracking branch 'origin/develop' into remove-proposal
pileks c8a54ba
add comment
pileks 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
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
51 changes: 51 additions & 0 deletions
51
programs/futarchy/src/instructions/admin_remove_proposal.rs
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,51 @@ | ||
| use super::*; | ||
|
|
||
| pub mod admin { | ||
| use anchor_lang::prelude::declare_id; | ||
| declare_id!("tSTp6B6kE9o6ZaTmHm2ZwnJBBtgd3x112tapxFhmBEQ"); | ||
| } | ||
|
|
||
| #[derive(Accounts)] | ||
| #[event_cpi] | ||
| pub struct AdminRemoveProposal<'info> { | ||
| #[account(mut, has_one = dao)] | ||
| pub proposal: Box<Account<'info, Proposal>>, | ||
| #[account(mut)] | ||
| pub dao: Box<Account<'info, Dao>>, | ||
| #[account(mut)] | ||
| pub admin: Signer<'info>, | ||
| } | ||
|
|
||
| impl AdminRemoveProposal<'_> { | ||
| pub fn validate(&self) -> Result<()> { | ||
| #[cfg(feature = "production")] | ||
| require_keys_eq!(self.admin.key(), admin::ID, FutarchyError::InvalidAdmin); | ||
|
|
||
| // TODO: See how we'd handle cancelling a proposal that has already been launched (in Pending state) | ||
| require!( | ||
| matches!(self.proposal.state, ProposalState::Draft { .. }), | ||
| FutarchyError::ProposalNotInDraftState | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn handle(ctx: Context<Self>) -> Result<()> { | ||
| let proposal = &mut ctx.accounts.proposal; | ||
| let dao = &mut ctx.accounts.dao; | ||
|
|
||
| proposal.state = ProposalState::Removed; | ||
|
|
||
| dao.seq_num += 1; | ||
| let clock = Clock::get()?; | ||
|
|
||
| emit_cpi!(RemoveProposalEvent { | ||
| common: CommonFields::new(&clock, dao.seq_num), | ||
| proposal: proposal.key(), | ||
| dao: dao.key(), | ||
| admin: ctx.accounts.admin.key(), | ||
| }); | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
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
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
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,44 @@ | ||
| import * as anchor from "@coral-xyz/anchor"; | ||
| import { | ||
| CONDITIONAL_VAULT_PROGRAM_ID, | ||
| FUTARCHY_PROGRAM_ID, | ||
| FutarchyClient, | ||
| } from "@metadaoproject/futarchy/v0.7"; | ||
| import { PublicKey } from "@solana/web3.js"; | ||
|
|
||
| // Set the proposal address before running the script | ||
| const proposal = new PublicKey(""); | ||
|
|
||
| const provider = anchor.AnchorProvider.env(); | ||
|
|
||
| // Payer MUST be the admin signer - tSTp6B6kE9o6ZaTmHm2ZwnJBBtgd3x112tapxFhmBEQ | ||
| const payer = provider.wallet["payer"]; | ||
|
|
||
| const futarchy: FutarchyClient = new FutarchyClient( | ||
| provider, | ||
| FUTARCHY_PROGRAM_ID, | ||
| CONDITIONAL_VAULT_PROGRAM_ID, | ||
| [], | ||
| ); | ||
|
|
||
| export const removeProposal = async () => { | ||
| // Fetch the proposal to get the DAO address | ||
| const proposalAccount = await futarchy.getProposal(proposal); | ||
|
|
||
| console.log(`Removing proposal at address: ${proposal.toBase58()}`); | ||
| console.log(`DAO: ${proposalAccount.dao.toBase58()}`); | ||
| console.log(`Current state: ${JSON.stringify(proposalAccount.state)}`); | ||
|
|
||
| const tx = await futarchy.autocrat.methods | ||
| .adminRemoveProposal() | ||
| .accounts({ | ||
| proposal, | ||
| dao: proposalAccount.dao, | ||
| admin: payer.publicKey, | ||
| }) | ||
| .rpc(); | ||
|
|
||
| console.log(`Proposal removed successfully. Signature: ${tx}`); | ||
| }; | ||
|
|
||
| removeProposal().catch(console.error); |
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
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.