From e6eaff3ff47ba0f69039f94ffcda59a9e6d94a5c Mon Sep 17 00:00:00 2001 From: DaveVodrazka Date: Fri, 27 Sep 2024 15:57:28 +0200 Subject: [PATCH] feat: add arbitrary proposal to add options --- src/arbitrary_proposal_add_options.cairo | 49 ++++++++++++++++++++++++ src/lib.cairo | 1 + 2 files changed, 50 insertions(+) create mode 100644 src/arbitrary_proposal_add_options.cairo diff --git a/src/arbitrary_proposal_add_options.cairo b/src/arbitrary_proposal_add_options.cairo new file mode 100644 index 0000000..3f9f7b8 --- /dev/null +++ b/src/arbitrary_proposal_add_options.cairo @@ -0,0 +1,49 @@ +use starknet::contract_address::{ContractAddress}; + +#[starknet::interface] +trait IArbitraryProposalAddOptions { + fn execute_arbitrary_proposal(ref self: TContractState); +} + +#[starknet::contract] +pub mod ArbitraryProposalAddOptions { + use konoha::types::{CustomProposalConfig}; + use konoha::contract::IGovernanceDispatcher; + use konoha::contract::IGovernanceDispatcherTrait; + use starknet::{ContractAddress, ClassHash, get_contract_address}; + + #[storage] + struct Storage { + governance_address: ContractAddress, + option_deployer_class_hash: ClassHash, + custom_proposal_added: bool + } + + #[constructor] + fn constructor( + ref self: ContractState, gov_addr: ContractAddress, option_deployer_class_hash: ClassHash + ) { + self.governance_address.write(gov_addr); + self.option_deployer_class_hash.write(option_deployer_class_hash); + self.custom_proposal_added.write(false); + } + + #[abi(embed_v0)] + impl ArbitraryProposalAddOptions of super::IArbitraryProposalAddOptions { + fn execute_arbitrary_proposal(ref self: ContractState) { + assert(!self.custom_proposal_added.read(), 'custom proposal already added'); + let add_options = CustomProposalConfig { + target: self.option_deployer_class_hash.read().try_into().unwrap(), + selector: selector!("add_options"), + library_call: true + }; + + let governance = IGovernanceDispatcher { + contract_address: self.governance_address.read() + }; + governance.proposals.add_custom_proposal_config(add_options); + + self.custom_proposal_added.write(true); + } + } +} diff --git a/src/lib.cairo b/src/lib.cairo index 605cd6a..0770094 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -8,3 +8,4 @@ mod traits; mod types; mod upgrades; pub mod vecarm; +mod arbitrary_proposal_add_options;