Skip to content

Commit

Permalink
custom proposal's quorum_votes
Browse files Browse the repository at this point in the history
  • Loading branch information
pause125 committed Oct 13, 2022
1 parent daa971f commit da263ef
Show file tree
Hide file tree
Showing 24 changed files with 52 additions and 31 deletions.
Binary file not shown.
Binary file modified build/StarcoinFramework/bytecode_modules/MemberProposalPlugin.mv
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
required_caps,
};

<a href="DAOSpace.md#0x1_DAOSpace_create_proposal">DAOSpace::create_proposal</a>(&cap, sender, action, description, action_delay);
<a href="DAOSpace.md#0x1_DAOSpace_create_proposal">DAOSpace::create_proposal</a>(&cap, sender, action, description, action_delay, <a href="Option.md#0x1_Option_none">Option::none</a>&lt;u8&gt;());
}
</code></pre>

Expand Down
2 changes: 1 addition & 1 deletion build/StarcoinFramework/docs/MemberProposalPlugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
};
<b>assert</b>!(!<a href="DAOSpace.md#0x1_DAOSpace_is_exist_member_offer">DAOSpace::is_exist_member_offer</a>&lt;DAOT&gt;(member), <a href="Errors.md#0x1_Errors_already_published">Errors::already_published</a>(<a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_ERR_MEMBER_OFFER_EXIST">ERR_MEMBER_OFFER_EXIST</a>));
<b>assert</b>!(!<a href="DAOSpace.md#0x1_DAOSpace_is_member">DAOSpace::is_member</a>&lt;DAOT&gt;(member), <a href="Errors.md#0x1_Errors_already_published">Errors::already_published</a>(<a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_ERR_MEMBER_EXIST">ERR_MEMBER_EXIST</a>));
<a href="DAOSpace.md#0x1_DAOSpace_create_proposal">DAOSpace::create_proposal</a>(&cap, sender, action, description, action_delay);
<a href="DAOSpace.md#0x1_DAOSpace_create_proposal">DAOSpace::create_proposal</a>(&cap, sender, action, description, action_delay, <a href="Option.md#0x1_Option_none">Option::none</a>&lt;u8&gt;());
}
</code></pre>

Expand Down
Binary file not shown.
Binary file modified build/StarcoinFramework/source_maps/MemberProposalPlugin.mvsm
Binary file not shown.
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": 476235,
"gas_used": 488194,
"status": "Executed"
}

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/daospace/dao_proposal.move
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module creator::DAOHelper {
total,
receiver,
};
let proposal_id = DAOSpace::create_proposal(&cap, sender, action, b"ipfs://description", action_delay);
let proposal_id = DAOSpace::create_proposal(&cap, sender, action, b"ipfs://description", action_delay, Option::none<u8>());
checkpoint<DAOT>(proposal_id);

proposal_id
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/daospace/dao_proposal_rejected.move
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module creator::DAOHelper {
total,
receiver,
};
let proposal_id = DAOSpace::create_proposal(&cap, sender, action, b"ipfs://description", action_delay);
let proposal_id = DAOSpace::create_proposal(&cap, sender, action, b"ipfs://description", action_delay, Option::none<u8>());
checkpoint<DAOT>(proposal_id);

proposal_id
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 @@ -32,7 +32,7 @@ task 16 'run'. lines 142-151:

task 17 'run'. lines 154-179:
{
"gas_used": 449602,
"gas_used": 461561,
"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": 450230,
"gas_used": 462189,
"status": "Executed"
}

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/daospaceplugin/salary_gov_plugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ module creator::SalaryGovPlugin {
let action = BossProposalAction<DAOT> {
boss: Signer::address_of(&sender)
};
DAOSpace::create_proposal(&cap, &sender, action, description, action_delay);
DAOSpace::create_proposal(&cap, &sender, action, description, action_delay, Option::none<u8>());
}

public(script) fun execute_proposal<DAOT: store>(sender: signer, proposal_id: u64) {
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": 448939,
"gas_used": 460898,
"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": 434673,
"gas_used": 446632,
"status": "Executed"
}

Expand Down
22 changes: 19 additions & 3 deletions sources/daospace/DAOSpace.move
Original file line number Diff line number Diff line change
Expand Up @@ -1664,12 +1664,14 @@ 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.
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>,
): u64 acquires DAO, GlobalProposals, DAOAccountCapHolder, ProposalActions, ProposalEvent, GlobalProposalActions {
// check DAO member
let sender_addr = Signer::address_of(sender);
Expand All @@ -1687,7 +1689,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>();
let quorum_votes = quorum_votes<DAOT>(additional_quorum_votes_rate);
let voting_period = voting_period<DAOT>();

let (block_number,state_root) = block_number_and_state_root();
Expand Down Expand Up @@ -2416,9 +2418,23 @@ module StarcoinFramework::DAOSpace {
}

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

let market_cap = Token::market_cap<DAOT>();
let rate = voting_quorum_rate<DAOT>();
let rate = voting_quorum_rate<DAOT>() + additional_rate;
assert!(
rate > 0 && rate <= 100,
Errors::invalid_argument(ERR_CONFIG_PARAM_INVALID),
);
let rate = (rate as u128);
market_cap * rate / 100
}
Expand Down
2 changes: 1 addition & 1 deletion sources/daospaceplugin/ConfigProposalPlugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module StarcoinFramework::ConfigProposalPlugin {
DAOSpace::create_proposal<
DAOT,
ConfigProposalPlugin,
ConfigProposalAction<ConfigT>>(&cap, sender, action, description, action_delay);
ConfigProposalAction<ConfigT>>(&cap, sender, action, description, action_delay, Option::none<u8>());
}

public fun execute_proposal<DAOT: store, ConfigT: copy + drop + store>(sender: &signer, proposal_id: u64) {
Expand Down
4 changes: 2 additions & 2 deletions sources/daospaceplugin/GasOracleProposalPlugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module StarcoinFramework::GasOracleProposalPlugin {
let action = OracleSourceAddAction<TokenType>{
source_address
};
DAOSpace::create_proposal(&cap, &sender, action, description, action_delay);
DAOSpace::create_proposal(&cap, &sender, action, description, action_delay, Option::none<u8>());
}

public(script) fun execute_oracle_add_proposal<DAOT: store, TokenType: store>(sender: signer, proposal_id: u64) {
Expand Down Expand Up @@ -95,7 +95,7 @@ module StarcoinFramework::GasOracleProposalPlugin {
let action = OracleSourceRemoveAction<TokenType>{
source_address
};
DAOSpace::create_proposal(&cap, &sender, action, description, action_delay);
DAOSpace::create_proposal(&cap, &sender, action, description, action_delay, Option::none<u8>());
}

public(script) fun execute_oracle_remove_proposal<DAOT: store, TokenType: store>(sender: signer, proposal_id: u64) {
Expand Down
4 changes: 2 additions & 2 deletions sources/daospaceplugin/GrantProposalPlugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module StarcoinFramework::GrantProposalPlugin{
start_time:start_time,
period:period
};
DAOSpace::create_proposal(&cap, sender, action, description, action_delay);
DAOSpace::create_proposal(&cap, sender, action, description, action_delay, Option::none<u8>());
}

public (script) fun create_grant_proposal_entry<DAOT: store, TokenT:store>(sender: signer, description: vector<u8>,grantee: address, total: u128, start_time:u64, period: u64, action_delay:u64){
Expand All @@ -94,7 +94,7 @@ module StarcoinFramework::GrantProposalPlugin{
let witness = GrantProposalPlugin{};
let cap = DAOSpace::acquire_proposal_cap<DAOT, GrantProposalPlugin>(&witness);
let action = GrantRevokeAction<TokenT>{ grantee };
DAOSpace::create_proposal(&cap, sender, action, description, action_delay);
DAOSpace::create_proposal(&cap, sender, action, description, action_delay, Option::none<u8>());
}

public (script) fun create_grant_revoke_proposal_entry<DAOT: store, TokenT:store>(sender: signer, description: vector<u8>, grantee:address, action_delay:u64){
Expand Down
2 changes: 1 addition & 1 deletion sources/daospaceplugin/InstallPluginProposalPlugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module StarcoinFramework::InstallPluginProposalPlugin{
required_caps,
};

DAOSpace::create_proposal(&cap, sender, action, description, action_delay);
DAOSpace::create_proposal(&cap, sender, action, description, action_delay, Option::none<u8>());
}

public fun execute_proposal<DAOT: store, ToInstallPluginT: store>(sender: &signer, proposal_id: u64){
Expand Down
2 changes: 1 addition & 1 deletion sources/daospaceplugin/MemberProposalPlugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module StarcoinFramework::MemberProposalPlugin{
};
assert!(!DAOSpace::is_exist_member_offer<DAOT>(member), Errors::already_published(ERR_MEMBER_OFFER_EXIST));
assert!(!DAOSpace::is_member<DAOT>(member), Errors::already_published(ERR_MEMBER_EXIST));
DAOSpace::create_proposal(&cap, sender, action, description, action_delay);
DAOSpace::create_proposal(&cap, sender, action, description, action_delay, Option::none<u8>());
}

public (script) fun create_proposal_entry<DAOT: store>(sender: signer, description: vector<u8>, member: address, image_data:vector<u8>, image_url:vector<u8>, init_sbt: u128, action_delay: u64){
Expand Down
2 changes: 1 addition & 1 deletion sources/daospaceplugin/MintProposalPlugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module StarcoinFramework::MintProposalPlugin{
receiver,
amount,
};
DAOSpace::create_proposal(&cap, sender, action, description, action_delay);
DAOSpace::create_proposal(&cap, sender, action, description, action_delay, Option::none<u8>());
}

public (script) fun create_mint_proposal_entry<DAOT: store, TokenT:store>(sender: signer, description: vector<u8>, receiver: address, amount: u128, action_delay: u64){
Expand Down
6 changes: 4 additions & 2 deletions sources/daospaceplugin/StakeToSBTPlugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ module StarcoinFramework::StakeToSBTPlugin {
weight,
},
description,
action_delay);
action_delay,
Option::none<u8>());
}

public(script) fun create_weight_proposal_entry<DAOT: store, TokenT: store>(
Expand Down Expand Up @@ -503,7 +504,8 @@ module StarcoinFramework::StakeToSBTPlugin {
sender,
AcceptTokenCap<DAOT, TokenT> {},
description,
action_delay
action_delay,
Option::none<u8>()
);
}

Expand Down
5 changes: 4 additions & 1 deletion sources/daospaceplugin/TreasuryPlugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ module StarcoinFramework::TreasuryPlugin {
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;

struct TreasuryPlugin has store, drop {}

/// A wrapper of Token MintCapability.
Expand Down Expand Up @@ -95,7 +98,7 @@ module StarcoinFramework::TreasuryPlugin {
amount,
period,
};
DAOSpace::create_proposal(&cap, sender, action, description, action_delay);
DAOSpace::create_proposal(&cap, sender, action, description, action_delay, Option::some(ADDITIONAL_QUORUM_VOTES_RATE));
}

public(script) fun create_withdraw_proposal_entry<DAOT: store, TokenT: store>(
Expand Down
14 changes: 7 additions & 7 deletions sources/daospaceplugin/UpgradeModulePlugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ module StarcoinFramework::UpgradeModulePlugin {
let witness = UpgradeModulePlugin{};
let cap = DAOSpace::acquire_proposal_cap<DAOT, UpgradeModulePlugin>(&witness);
let action = UpgradeModuleAction{
package_hash: package_hash,
version: version,
enforced: enforced
package_hash,
version,
enforced
};
DAOSpace::create_proposal<
DAOT,
UpgradeModulePlugin,
UpgradeModuleAction>(&cap, sender, action, description, action_delay);
UpgradeModuleAction>(&cap, sender, action, description, action_delay, Option::none<u8>());
}

public (script) fun create_proposal_entry <DAOT: store>(sender: signer, description: vector<u8>, action_delay:u64, package_hash: vector<u8>, version: u64, enforced: bool) {
Expand All @@ -67,9 +67,9 @@ module StarcoinFramework::UpgradeModulePlugin {
DAOSpace::acquire_upgrade_module_cap<DAOT, UpgradeModulePlugin>(&witness);

let UpgradeModuleAction{
package_hash: package_hash,
version: version,
enforced: enforced
package_hash,
version,
enforced
} = DAOSpace::execute_proposal<
DAOT,
UpgradeModulePlugin,
Expand Down

0 comments on commit da263ef

Please sign in to comment.