Skip to content

Commit

Permalink
[compiler-v2] add for features dao
Browse files Browse the repository at this point in the history
  • Loading branch information
welbon committed Dec 19, 2024
1 parent 87da71a commit e8c0de9
Show file tree
Hide file tree
Showing 13 changed files with 597 additions and 10 deletions.
8 changes: 4 additions & 4 deletions vm/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ pub mod shared {

pub fn starcoin_framework_named_addresses() -> BTreeMap<String, NumericalAddress> {
let mapping = [
// ("VMReserved", "0x0"),
// ("Genesis", "0x1"),
// ("StarcoinFramework", "0x1"),
// ("StarcoinAssociation", "0xA550C18"),
("VMReserved", "0x0"),
("Genesis", "0x1"),
("StarcoinFramework", "0x1"),
("StarcoinAssociation", "0xA550C18"),
("vm", "0x0"),
("vm_reserved", "0x0"),
("std", "0x1"),
Expand Down
140 changes: 140 additions & 0 deletions vm/framework/cached-packages/src/starcoin_framework_sdk_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,24 @@ pub enum EntryFunctionCall {
proposal_id: u64,
},

/// Once the proposal is agreed, anyone can call the method to make the proposal happen.
DaoFeatuersProposalExecute {
proposal_adderss: AccountAddress,
proposal_id: u64,
},

DaoFeatuersProposalExecuteUrgent {
enable: Vec<u64>,
disable: Vec<u64>,
},

/// Entrypoint for the proposal.
DaoFeatuersProposalPropose {
enable: Vec<u64>,
disable: Vec<u64>,
exec_delay: u64,
},

/// Once the proposal is agreed, anyone can call the method to make the proposal happen.
DaoModifyConfigProposalExecute {
token_t: TypeTag,
Expand Down Expand Up @@ -645,6 +663,18 @@ impl EntryFunctionCall {
proposer_address,
proposal_id,
} => dao_queue_proposal_action(token_t, action_t, proposer_address, proposal_id),
DaoFeatuersProposalExecute {
proposal_adderss,
proposal_id,
} => dao_featuers_proposal_execute(proposal_adderss, proposal_id),
DaoFeatuersProposalExecuteUrgent { enable, disable } => {
dao_featuers_proposal_execute_urgent(enable, disable)
}
DaoFeatuersProposalPropose {
enable,
disable,
exec_delay,
} => dao_featuers_proposal_propose(enable, disable, exec_delay),
DaoModifyConfigProposalExecute {
token_t,
proposer_address,
Expand Down Expand Up @@ -1331,6 +1361,64 @@ pub fn dao_queue_proposal_action(
))
}

/// Once the proposal is agreed, anyone can call the method to make the proposal happen.
pub fn dao_featuers_proposal_execute(
proposal_adderss: AccountAddress,
proposal_id: u64,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]),
ident_str!("dao_featuers_proposal").to_owned(),
),
ident_str!("execute").to_owned(),
vec![],
vec![
bcs::to_bytes(&proposal_adderss).unwrap(),
bcs::to_bytes(&proposal_id).unwrap(),
],
))
}

pub fn dao_featuers_proposal_execute_urgent(
enable: Vec<u64>,
disable: Vec<u64>,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]),
ident_str!("dao_featuers_proposal").to_owned(),
),
ident_str!("execute_urgent").to_owned(),
vec![],
vec![
bcs::to_bytes(&enable).unwrap(),
bcs::to_bytes(&disable).unwrap(),
],
))
}

/// Entrypoint for the proposal.
pub fn dao_featuers_proposal_propose(
enable: Vec<u64>,
disable: Vec<u64>,
exec_delay: u64,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]),
ident_str!("dao_featuers_proposal").to_owned(),
),
ident_str!("propose").to_owned(),
vec![],
vec![
bcs::to_bytes(&enable).unwrap(),
bcs::to_bytes(&disable).unwrap(),
bcs::to_bytes(&exec_delay).unwrap(),
],
))
}

/// Once the proposal is agreed, anyone can call the method to make the proposal happen.
pub fn dao_modify_config_proposal_execute(
token_t: TypeTag,
Expand Down Expand Up @@ -2515,6 +2603,46 @@ mod decoder {
}
}

pub fn dao_featuers_proposal_execute(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::DaoFeatuersProposalExecute {
proposal_adderss: bcs::from_bytes(script.args().get(0)?).ok()?,
proposal_id: bcs::from_bytes(script.args().get(1)?).ok()?,
})
} else {
None
}
}

pub fn dao_featuers_proposal_execute_urgent(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::DaoFeatuersProposalExecuteUrgent {
enable: bcs::from_bytes(script.args().get(0)?).ok()?,
disable: bcs::from_bytes(script.args().get(1)?).ok()?,
})
} else {
None
}
}

pub fn dao_featuers_proposal_propose(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::DaoFeatuersProposalPropose {
enable: bcs::from_bytes(script.args().get(0)?).ok()?,
disable: bcs::from_bytes(script.args().get(1)?).ok()?,
exec_delay: bcs::from_bytes(script.args().get(2)?).ok()?,
})
} else {
None
}
}

pub fn dao_modify_config_proposal_execute(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
Expand Down Expand Up @@ -3307,6 +3435,18 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"dao_queue_proposal_action".to_string(),
Box::new(decoder::dao_queue_proposal_action),
);
map.insert(
"dao_featuers_proposal_execute".to_string(),
Box::new(decoder::dao_featuers_proposal_execute),
);
map.insert(
"dao_featuers_proposal_execute_urgent".to_string(),
Box::new(decoder::dao_featuers_proposal_execute_urgent),
);
map.insert(
"dao_featuers_proposal_propose".to_string(),
Box::new(decoder::dao_featuers_proposal_propose),
);
map.insert(
"dao_modify_config_proposal_execute".to_string(),
Box::new(decoder::dao_modify_config_proposal_execute),
Expand Down
4 changes: 2 additions & 2 deletions vm/framework/move-stdlib/doc/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ Lifetime: transient
Initialized from parameters


<pre><code><b>public</b> entry <b>fun</b> <a href="features.md#0x1_features_initialize">initialize</a>(framework: &<a href="signer.md#0x1_signer">signer</a>, <a href="features.md#0x1_features">features</a>: <a href="vector.md#0x1_vector">vector</a>&lt;u8&gt;)
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_initialize">initialize</a>(framework: &<a href="signer.md#0x1_signer">signer</a>, <a href="features.md#0x1_features">features</a>: <a href="vector.md#0x1_vector">vector</a>&lt;u8&gt;)
</code></pre>


Expand All @@ -943,7 +943,7 @@ Initialized from parameters
<summary>Implementation</summary>


<pre><code><b>public</b> entry <b>fun</b> <a href="features.md#0x1_features_initialize">initialize</a>(framework: &<a href="signer.md#0x1_signer">signer</a>, <a href="features.md#0x1_features">features</a>: <a href="vector.md#0x1_vector">vector</a>&lt;u8&gt;) {
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_initialize">initialize</a>(framework: &<a href="signer.md#0x1_signer">signer</a>, <a href="features.md#0x1_features">features</a>: <a href="vector.md#0x1_vector">vector</a>&lt;u8&gt;) {
<b>assert</b>!(<a href="signer.md#0x1_signer_address_of">signer::address_of</a>(framework) == @std, <a href="error.md#0x1_error_permission_denied">error::permission_denied</a>(<a href="features.md#0x1_features_EFRAMEWORK_SIGNER_NEEDED">EFRAMEWORK_SIGNER_NEEDED</a>));
<b>move_to</b>&lt;<a href="features.md#0x1_features_Features">Features</a>&gt;(framework, <a href="features.md#0x1_features_Features">Features</a> { <a href="features.md#0x1_features">features</a> })
}
Expand Down
8 changes: 6 additions & 2 deletions vm/framework/starcoin-framework/doc/dao.md
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,6 @@ propose a proposal.
action_delay: u64,
) <b>acquires</b> <a href="dao.md#0x1_dao_DaoGlobalInfo">DaoGlobalInfo</a> {
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&std::string::utf8(b"dao::proposal | Entered"));
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="../../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>));

<b>if</b> (action_delay == 0) {
action_delay = <a href="dao.md#0x1_dao_min_action_delay">min_action_delay</a>&lt;TokenT&gt;();
Expand All @@ -683,7 +682,9 @@ propose a proposal.
<b>let</b> start_time = <a href="timestamp.md#0x1_timestamp_now_milliseconds">timestamp::now_milliseconds</a>() + <a href="dao.md#0x1_dao_voting_delay">voting_delay</a>&lt;TokenT&gt;();
<b>let</b> quorum_votes = <a href="dao.md#0x1_dao_quorum_votes">quorum_votes</a>&lt;TokenT&gt;();

<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&std::string::utf8(b"dao::proposal | <a href="dao.md#0x1_dao_Proposal">Proposal</a> {"));
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&std::string::utf8(b"dao::proposal | <a href="dao.md#0x1_dao_Proposal">Proposal</a> "));
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&proposal_id);
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&start_time);

<b>let</b> proposal = <a href="dao.md#0x1_dao_Proposal">Proposal</a>&lt;TokenT, ActionT&gt; {
id: proposal_id,
Expand Down Expand Up @@ -1265,6 +1266,9 @@ Get the proposal state.
proposal: &<a href="dao.md#0x1_dao_Proposal">Proposal</a>&lt;TokenT, ActionT&gt;,
current_time: u64,
): u8 {
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&std::string::utf8(b"do_proposal_state | entered "));
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(proposal);

<b>if</b> (current_time &lt; proposal.start_time) {
// Pending
<a href="dao.md#0x1_dao_PENDING">PENDING</a>
Expand Down
Loading

0 comments on commit e8c0de9

Please sign in to comment.