0x1::ModifyDaoConfigProposal
A proposal module which is used to modify Token’s DAO configuration.
DaoConfigModifyCapability
DaoConfigUpdate
plugin
propose
execute
use 0x1::Config;
use 0x1::Dao;
use 0x1::Errors;
use 0x1::Signer;
use 0x1::Token;
DaoConfigModifyCapability
A wrapper of Config::ModifyConfigCapability<Dao::DaoConfig<TokenT>>
.
struct DaoConfigModifyCapability<TokenT: copy, drop, store> has key
cap: Config::ModifyConfigCapability<Dao::DaoConfig<TokenT>>
DaoConfigUpdate
a proposal action to update dao config.
if any field is 0
, that means the proposal want to update.
struct DaoConfigUpdate has copy, drop, store
voting_delay: u64
voting_period: u64
voting_quorum_rate: u8
min_action_delay: u64
const ERR_NOT_AUTHORIZED: u64 = 401;
const ERR_QUORUM_RATE_INVALID: u64 = 402;
plugin
Plugin method of the module. Should be called by token issuer.
public fun plugin<TokenT: copy, drop, store>(signer: &signer)
public fun plugin<TokenT: copy + drop + store>(signer: &signer) {
let token_issuer = Token::token_address<TokenT>();
assert!(Signer::address_of(signer) == token_issuer, Errors::requires_address(ERR_NOT_AUTHORIZED));
let dao_config_modify_cap = Config::extract_modify_config_capability<
Dao::DaoConfig<TokenT>,
>(signer);
assert!(Config::account_address(&dao_config_modify_cap) == token_issuer, Errors::requires_address(ERR_NOT_AUTHORIZED));
let cap = DaoConfigModifyCapability { cap: dao_config_modify_cap };
move_to(signer, cap);
}
pragma aborts_if_is_partial = false;
let sender = Signer::address_of(signer);
aborts_if sender != Token::SPEC_TOKEN_TEST_ADDRESS();
include Config::AbortsIfCapNotExist<Dao::DaoConfig<TokenT>>{address: sender};
let config_cap = Config::spec_cap<Dao::DaoConfig<TokenT>>(sender);
aborts_if Option::is_none(config_cap);
aborts_if Option::borrow(config_cap).account_address != sender;
aborts_if exists<DaoConfigModifyCapability<TokenT>>(sender);
ensures exists<DaoConfigModifyCapability<TokenT>>(sender);
propose
Entrypoint for the proposal.
public entry fun propose<TokenT: copy, drop, store>(signer: signer, voting_delay: u64, voting_period: u64, voting_quorum_rate: u8, min_action_delay: u64, exec_delay: u64)
public entry fun propose<TokenT: copy + drop + store>(
signer: signer,
voting_delay: u64,
voting_period: u64,
voting_quorum_rate: u8,
min_action_delay: u64,
exec_delay: u64,
) {
assert!(voting_quorum_rate <= 100, Errors::invalid_argument(ERR_QUORUM_RATE_INVALID));
let action = DaoConfigUpdate {
voting_delay,
voting_period,
voting_quorum_rate,
min_action_delay,
};
Dao::propose<TokenT, DaoConfigUpdate>(&signer, action, exec_delay);
}
pragma aborts_if_is_partial = false;
aborts_if voting_quorum_rate > 100;
include Dao::AbortIfDaoConfigNotExist<TokenT>;
include Dao::AbortIfDaoInfoNotExist<TokenT>;
aborts_if !exists<Timestamp::CurrentTimeMilliseconds>(CoreAddresses::GENESIS_ADDRESS());
aborts_if exec_delay > 0 && exec_delay < Dao::spec_dao_config<TokenT>().min_action_delay;
include Dao::CheckQuorumVotes<TokenT>;
let sender = Signer::address_of(signer);
aborts_if exists<Dao::Proposal<TokenT, DaoConfigUpdate>>(sender);
execute
Once the proposal is agreed, anyone can call the method to make the proposal happen.
public entry fun execute<TokenT: copy, drop, store>(proposer_address: address, proposal_id: u64)
public entry fun execute<TokenT: copy + drop + store>(proposer_address: address, proposal_id: u64)
acquires DaoConfigModifyCapability {
let DaoConfigUpdate {
voting_delay,
voting_period,
voting_quorum_rate,
min_action_delay,
} = Dao::extract_proposal_action<TokenT, DaoConfigUpdate>(proposer_address, proposal_id);
let cap = borrow_global_mut<DaoConfigModifyCapability<TokenT>>(
Token::token_address<TokenT>(),
);
Dao::modify_dao_config(
&mut cap.cap,
voting_delay,
voting_period,
voting_quorum_rate,
min_action_delay,
);
}
pragma aborts_if_is_partial = true;
aborts_if !exists<DaoConfigModifyCapability<TokenT>>(Token::SPEC_TOKEN_TEST_ADDRESS());
pragma verify = false;
pragma aborts_if_is_strict;
pragma aborts_if_is_partial;