Skip to content

Commit

Permalink
custom quorum scale factor by DAO
Browse files Browse the repository at this point in the history
  • Loading branch information
pause125 committed Oct 15, 2022
1 parent d220640 commit 3631066
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 17 deletions.
2 changes: 1 addition & 1 deletion integration-tests/daospace/dao_proposal.exp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ task 22 'run'. lines 300-311:

task 23 'run'. lines 314-338:
{
"gas_used": 488194,
"gas_used": 488299,
"status": "Executed"
}

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/daospaceplugin/gas_oracle_plugin.exp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ task 16 'run'. lines 140-149:

task 17 'run'. lines 152-177:
{
"gas_used": 461561,
"gas_used": 461666,
"status": "Executed"
}

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/daospaceplugin/mint_proposal_plugin.exp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ task 19 'run'. lines 164-173:

task 20 'run'. lines 175-206:
{
"gas_used": 462189,
"gas_used": 462294,
"status": "Executed"
}

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/starcoin_dao/starcoin_onchain_config.exp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ task 21 'run'. lines 111-120:

task 22 'run'. lines 123-132:
{
"gas_used": 460898,
"gas_used": 461003,
"status": "Executed"
}

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/starcoin_dao/starcoin_upgrade_module.exp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ task 21 'run'. lines 111-120:

task 23 'run'. lines 127-137:
{
"gas_used": 446632,
"gas_used": 446737,
"status": "Executed"
}

Expand Down
18 changes: 10 additions & 8 deletions sources/daospace/DAOSpace.move
Original file line number Diff line number Diff line change
Expand Up @@ -1664,14 +1664,15 @@ module StarcoinFramework::DAOSpace {
/// propose a proposal.
/// `action`: the actual action to execute.
/// `action_delay`: the delay to execute after the proposal is agreed
/// `additional_quorum_votes_rate`: used to increase the base quorum_votes_rate.
/// `quorum_scale_factor`: used to scale up the base quorum_votes_rate.
/// The final quorum_votes_rate = (1.0 + scale / 100) * quorum_votes_rate
public fun create_proposal<DAOT: store, PluginT, ActionT: store+drop>(
_cap: &DAOProposalCap<DAOT, PluginT>,
sender: &signer,
action: ActionT,
description: vector<u8>,
action_delay: u64,
additional_quorum_votes_rate: Option::Option<u8>,
quorum_scale_factor: Option::Option<u8>,
): u64 acquires DAO, GlobalProposals, DAOAccountCapHolder, ProposalActions, ProposalEvent, GlobalProposalActions {
// check DAO member
let sender_addr = Signer::address_of(sender);
Expand All @@ -1689,7 +1690,7 @@ module StarcoinFramework::DAOSpace {
let proposal_id = next_proposal_id<DAOT>();
let proposer = Signer::address_of(sender);
let start_time = Timestamp::now_milliseconds() + voting_delay<DAOT>();
let quorum_votes = quorum_votes<DAOT>(additional_quorum_votes_rate);
let quorum_votes = quorum_votes<DAOT>(quorum_scale_factor);
let voting_period = voting_period<DAOT>();

let (block_number,state_root) = block_number_and_state_root();
Expand Down Expand Up @@ -2418,19 +2419,20 @@ module StarcoinFramework::DAOSpace {
}

/// Quorum votes to make proposal valid.
public fun quorum_votes<DAOT: store>(additional: Option::Option<u8>): u128 {
let additional_rate = if (Option::is_none(&additional)) {
public fun quorum_votes<DAOT: store>(scale_factor: Option::Option<u8>): u128 {
let scale_factor = if (Option::is_none(&scale_factor)) {
0u8
} else {
Option::extract(&mut additional)
Option::extract(&mut scale_factor)
};
assert!(
additional_rate >= 0 && additional_rate < 100,
scale_factor >= 0 && scale_factor <= 100,
Errors::invalid_argument(ERR_CONFIG_PARAM_INVALID),
);

let market_cap = Token::market_cap<DAOT>();
let rate = voting_quorum_rate<DAOT>() + additional_rate;
let rate = voting_quorum_rate<DAOT>();
let rate = rate + rate * scale_factor / 100;
assert!(
rate > 0 && rate <= 100,
Errors::invalid_argument(ERR_CONFIG_PARAM_INVALID),
Expand Down
34 changes: 30 additions & 4 deletions sources/daospaceplugin/TreasuryPlugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ module StarcoinFramework::TreasuryPlugin {
/// The withdraw amount of propose is too many.
const ERR_TOO_MANY_WITHDRAW_AMOUNT: u64 = 103;
const ERR_CAPABILITY_NOT_EXIST: u64 = 104;

// TODO: confirm the value
const ADDITIONAL_QUORUM_VOTES_RATE: u8 = 10;
const ERR_INVALID_SCALE_FACTOR: u64 = 105;

struct TreasuryPlugin has store, drop {}

Expand All @@ -27,6 +25,13 @@ module StarcoinFramework::TreasuryPlugin {
cap: Treasury::WithdrawCapability<TokenT>,
}

/// Scale up quorum_votes for withdraw proposal.
/// `scale` must be in [0, 100].
/// The final quorum_votes = (1.0 + scale / 100) * base_quorum_votes
struct QuorumScale has copy, drop, store {
scale: u8,
}

/// WithdrawToken request.
struct WithdrawTokenAction<phantom TokenT> has copy, drop, store {
/// the receiver of withdraw tokens.
Expand Down Expand Up @@ -98,7 +103,14 @@ module StarcoinFramework::TreasuryPlugin {
amount,
period,
};
DAOSpace::create_proposal(&cap, sender, action, description, action_delay, Option::some(ADDITIONAL_QUORUM_VOTES_RATE));

let scale = if (!DAOSpace::exists_custom_config<DAOT, QuorumScale>()) {
set_scale_factor_inner<DAOT>(0u8);
0u8
} else {
DAOSpace::get_custom_config<DAOT, QuorumScale>().scale
};
DAOSpace::create_proposal(&cap, sender, action, description, action_delay, Option::some(scale));
}

public(script) fun create_withdraw_proposal_entry<DAOT: store, TokenT: store>(
Expand Down Expand Up @@ -138,4 +150,18 @@ module StarcoinFramework::TreasuryPlugin {
let cap = borrow_global_mut<WithdrawCapabilityHolder<TokenT>>(Signer::address_of(signer));
Treasury::withdraw_with_capability(&mut cap.cap, reward)
}

public fun set_scale_factor<DAOT: store>(scale: u8, _witness: &DAOT) {
assert!(
scale >= 0 && scale <= 100,
Errors::invalid_argument(ERR_INVALID_SCALE_FACTOR),
);
set_scale_factor_inner<DAOT>(scale);
}

fun set_scale_factor_inner<DAOT: store>(scale: u8) {
let plugin = TreasuryPlugin {};
let cap = DAOSpace::acquire_modify_config_cap<DAOT, TreasuryPlugin>(&plugin);
DAOSpace::set_custom_config<DAOT, TreasuryPlugin, QuorumScale>(&mut cap, QuorumScale { scale });
}
}

0 comments on commit 3631066

Please sign in to comment.