-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add arbitrary proposal to add options
- Loading branch information
1 parent
8dce4d7
commit e6eaff3
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,49 @@ | ||
use starknet::contract_address::{ContractAddress}; | ||
|
||
#[starknet::interface] | ||
trait IArbitraryProposalAddOptions<TContractState> { | ||
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<ContractState> { | ||
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); | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -8,3 +8,4 @@ mod traits; | |
mod types; | ||
mod upgrades; | ||
pub mod vecarm; | ||
mod arbitrary_proposal_add_options; |