Skip to content

Commit

Permalink
Fix some entry function and do some clean (#203)
Browse files Browse the repository at this point in the history
* [daospace] fix some entry functions

* [daospace] rename description to extend

* [daospace] Remove some TODO

* update build file

* fixup fix test

* fixup
  • Loading branch information
jolestar authored Nov 11, 2022
1 parent 3bae7fd commit 884f648
Show file tree
Hide file tree
Showing 19 changed files with 150 additions and 162 deletions.
Binary file modified build/StarcoinFramework/bytecode_modules/MemberProposalPlugin.mv
Binary file not shown.
9 changes: 6 additions & 3 deletions build/StarcoinFramework/docs/InstallPluginProposalPlugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@

## Function `create_proposal`

Create a proposal to install a plugin.
We do not provide a entry function for create_proposal, because we can not use CapType as an entry function parameter,
every plugin should provide a entry function to create proposal to install self.


<pre><code><b>public</b> <b>fun</b> <a href="InstallPluginProposalPlugin.md#0x1_InstallPluginProposalPlugin_create_proposal">create_proposal</a>&lt;DAOT: store, ToInstallPluginT: store&gt;(sender: &signer, required_caps: vector&lt;<a href="DAOSpace.md#0x1_DAOSpace_CapType">DAOSpace::CapType</a>&gt;, title: vector&lt;u8&gt;, introduction: vector&lt;u8&gt;, description: vector&lt;u8&gt;, action_delay: u64)
<pre><code><b>public</b> <b>fun</b> <a href="InstallPluginProposalPlugin.md#0x1_InstallPluginProposalPlugin_create_proposal">create_proposal</a>&lt;DAOT: store, ToInstallPluginT: store&gt;(sender: &signer, required_caps: vector&lt;<a href="DAOSpace.md#0x1_DAOSpace_CapType">DAOSpace::CapType</a>&gt;, title: vector&lt;u8&gt;, introduction: vector&lt;u8&gt;, extend: vector&lt;u8&gt;, action_delay: u64)
</code></pre>


Expand All @@ -159,15 +162,15 @@
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="InstallPluginProposalPlugin.md#0x1_InstallPluginProposalPlugin_create_proposal">create_proposal</a>&lt;DAOT: store, ToInstallPluginT: store&gt;(sender: &signer, required_caps: vector&lt;CapType&gt;, title:vector&lt;u8&gt;, introduction:vector&lt;u8&gt;, description: vector&lt;u8&gt;, action_delay: u64){
<pre><code><b>public</b> <b>fun</b> <a href="InstallPluginProposalPlugin.md#0x1_InstallPluginProposalPlugin_create_proposal">create_proposal</a>&lt;DAOT: store, ToInstallPluginT: store&gt;(sender: &signer, required_caps: vector&lt;CapType&gt;, title:vector&lt;u8&gt;, introduction:vector&lt;u8&gt;, extend: vector&lt;u8&gt;, action_delay: u64){
<b>let</b> witness = <a href="InstallPluginProposalPlugin.md#0x1_InstallPluginProposalPlugin">InstallPluginProposalPlugin</a>{};

<b>let</b> cap = <a href="DAOSpace.md#0x1_DAOSpace_acquire_proposal_cap">DAOSpace::acquire_proposal_cap</a>&lt;DAOT, <a href="InstallPluginProposalPlugin.md#0x1_InstallPluginProposalPlugin">InstallPluginProposalPlugin</a>&gt;(&witness);
<b>let</b> action = <a href="InstallPluginProposalPlugin.md#0x1_InstallPluginProposalPlugin_InstallPluginAction">InstallPluginAction</a>&lt;ToInstallPluginT&gt;{
required_caps,
};

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

Expand Down
24 changes: 12 additions & 12 deletions build/StarcoinFramework/docs/MemberProposalPlugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@



<pre><code><b>public</b> <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_create_proposal">create_proposal</a>&lt;DAOT: store&gt;(sender: &signer, title: vector&lt;u8&gt;, introduction: vector&lt;u8&gt;, description: vector&lt;u8&gt;, member: <b>address</b>, image_data: vector&lt;u8&gt;, image_url: vector&lt;u8&gt;, init_sbt: u128, action_delay: u64)
<pre><code><b>public</b> <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_create_proposal">create_proposal</a>&lt;DAOT: store&gt;(sender: &signer, title: vector&lt;u8&gt;, introduction: vector&lt;u8&gt;, extend: vector&lt;u8&gt;, member: <b>address</b>, image_data: vector&lt;u8&gt;, image_url: vector&lt;u8&gt;, init_sbt: u128, action_delay: u64)
</code></pre>


Expand All @@ -206,7 +206,7 @@
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_create_proposal">create_proposal</a>&lt;DAOT: store&gt;(sender: &signer, title:vector&lt;u8&gt;, introduction:vector&lt;u8&gt;, description: vector&lt;u8&gt;, member: <b>address</b>, image_data:vector&lt;u8&gt;, image_url:vector&lt;u8&gt;, init_sbt: u128, action_delay: u64){
<pre><code><b>public</b> <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_create_proposal">create_proposal</a>&lt;DAOT: store&gt;(sender: &signer, title:vector&lt;u8&gt;, introduction:vector&lt;u8&gt;, extend: vector&lt;u8&gt;, member: <b>address</b>, image_data:vector&lt;u8&gt;, image_url:vector&lt;u8&gt;, init_sbt: u128, action_delay: u64){
<b>let</b> witness = <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin">MemberProposalPlugin</a>{};
<b>let</b> cap = <a href="DAOSpace.md#0x1_DAOSpace_acquire_proposal_cap">DAOSpace::acquire_proposal_cap</a>&lt;DAOT, <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin">MemberProposalPlugin</a>&gt;(&witness);
<b>let</b> action = <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_MemberJoinAction">MemberJoinAction</a>{
Expand All @@ -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, title, introduction, description, action_delay, <a href="Option.md#0x1_Option_none">Option::none</a>&lt;u8&gt;());
<a href="DAOSpace.md#0x1_DAOSpace_create_proposal">DAOSpace::create_proposal</a>(&cap, sender, action, title, introduction, extend, action_delay, <a href="Option.md#0x1_Option_none">Option::none</a>&lt;u8&gt;());
}
</code></pre>

Expand All @@ -231,7 +231,7 @@



<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_create_proposal_entry">create_proposal_entry</a>&lt;DAOT: store&gt;(sender: signer, title: vector&lt;u8&gt;, introduction: vector&lt;u8&gt;, description: vector&lt;u8&gt;, member: <b>address</b>, image_data: vector&lt;u8&gt;, image_url: vector&lt;u8&gt;, init_sbt: u128, action_delay: u64)
<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_create_proposal_entry">create_proposal_entry</a>&lt;DAOT: store&gt;(sender: signer, title: vector&lt;u8&gt;, introduction: vector&lt;u8&gt;, extend: vector&lt;u8&gt;, member: <b>address</b>, image_data: vector&lt;u8&gt;, image_url: vector&lt;u8&gt;, init_sbt: u128, action_delay: u64)
</code></pre>


Expand All @@ -240,8 +240,8 @@
<summary>Implementation</summary>


<pre><code><b>public</b> (<b>script</b>) <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_create_proposal_entry">create_proposal_entry</a>&lt;DAOT: store&gt;(sender: signer, title:vector&lt;u8&gt;, introduction:vector&lt;u8&gt;, description: vector&lt;u8&gt;, member: <b>address</b>, image_data:vector&lt;u8&gt;, image_url:vector&lt;u8&gt;, init_sbt: u128, action_delay: u64){
<a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_create_proposal">create_proposal</a>&lt;DAOT&gt;(&sender, title, introduction, description, member, image_data, image_url, init_sbt, action_delay);
<pre><code><b>public</b> (<b>script</b>) <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_create_proposal_entry">create_proposal_entry</a>&lt;DAOT: store&gt;(sender: signer, title:vector&lt;u8&gt;, introduction:vector&lt;u8&gt;, extend: vector&lt;u8&gt;, member: <b>address</b>, image_data:vector&lt;u8&gt;, image_url:vector&lt;u8&gt;, init_sbt: u128, action_delay: u64){
<a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_create_proposal">create_proposal</a>&lt;DAOT&gt;(&sender, title, introduction, extend, member, image_data, image_url, init_sbt, action_delay);
}
</code></pre>

Expand Down Expand Up @@ -317,7 +317,7 @@



<pre><code><b>public</b> <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_install_plugin_proposal">install_plugin_proposal</a>&lt;DAOT: store&gt;(sender: &signer, title: vector&lt;u8&gt;, introduction: vector&lt;u8&gt;, description: vector&lt;u8&gt;, action_delay: u64)
<pre><code><b>public</b> <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_install_plugin_proposal">install_plugin_proposal</a>&lt;DAOT: store&gt;(sender: &signer, title: vector&lt;u8&gt;, introduction: vector&lt;u8&gt;, extend: vector&lt;u8&gt;, action_delay: u64)
</code></pre>


Expand All @@ -326,8 +326,8 @@
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_install_plugin_proposal">install_plugin_proposal</a>&lt;DAOT:store&gt;(sender:&signer, title:vector&lt;u8&gt;, introduction:vector&lt;u8&gt;, description: vector&lt;u8&gt;,action_delay:u64){
<a href="InstallPluginProposalPlugin.md#0x1_InstallPluginProposalPlugin_create_proposal">InstallPluginProposalPlugin::create_proposal</a>&lt;DAOT, <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_MemberJoinAction">MemberJoinAction</a>&gt;(sender, <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_required_caps">required_caps</a>(), title, introduction, description, action_delay);
<pre><code><b>public</b> <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_install_plugin_proposal">install_plugin_proposal</a>&lt;DAOT:store&gt;(sender:&signer, title:vector&lt;u8&gt;, introduction:vector&lt;u8&gt;, extend: vector&lt;u8&gt;,action_delay:u64){
<a href="InstallPluginProposalPlugin.md#0x1_InstallPluginProposalPlugin_create_proposal">InstallPluginProposalPlugin::create_proposal</a>&lt;DAOT, <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin">MemberProposalPlugin</a>&gt;(sender, <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_required_caps">required_caps</a>(), title, introduction, extend, action_delay);
}
</code></pre>

Expand All @@ -341,7 +341,7 @@



<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_install_plugin_proposal_entry">install_plugin_proposal_entry</a>&lt;DAOT: store&gt;(sender: signer, title: vector&lt;u8&gt;, introduction: vector&lt;u8&gt;, description: vector&lt;u8&gt;, action_delay: u64)
<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_install_plugin_proposal_entry">install_plugin_proposal_entry</a>&lt;DAOT: store&gt;(sender: signer, title: vector&lt;u8&gt;, introduction: vector&lt;u8&gt;, extend: vector&lt;u8&gt;, action_delay: u64)
</code></pre>


Expand All @@ -350,8 +350,8 @@
<summary>Implementation</summary>


<pre><code><b>public</b> (<b>script</b>) <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_install_plugin_proposal_entry">install_plugin_proposal_entry</a>&lt;DAOT:store&gt;(sender:signer, title:vector&lt;u8&gt;, introduction:vector&lt;u8&gt;, description: vector&lt;u8&gt;, action_delay:u64){
<a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_install_plugin_proposal">install_plugin_proposal</a>&lt;DAOT&gt;(&sender, title, introduction, description, action_delay);
<pre><code><b>public</b> (<b>script</b>) <b>fun</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_install_plugin_proposal_entry">install_plugin_proposal_entry</a>&lt;DAOT:store&gt;(sender:signer, title:vector&lt;u8&gt;, introduction:vector&lt;u8&gt;, extend: vector&lt;u8&gt;, action_delay:u64){
<a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_install_plugin_proposal">install_plugin_proposal</a>&lt;DAOT&gt;(&sender, title, introduction, extend, action_delay);
}
</code></pre>

Expand Down
Binary file not shown.
Binary file modified build/StarcoinFramework/source_maps/MemberProposalPlugin.mvsm
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
processed 17 tasks

task 5 'run'. lines 72-80:
task 5 'run'. lines 52-60:
{
"gas_used": 1887227,
"status": "Executed"
}

task 6 'run'. lines 82-118:
task 6 'run'. lines 62-98:
{
"gas_used": 1022609,
"status": "Executed"
}

task 7 'run'. lines 120-131:
task 7 'run'. lines 100-110:
{
"gas_used": 38552,
"gas_used": 38600,
"status": {
"MoveAbort": {
"location": {
Expand All @@ -28,37 +28,37 @@ task 7 'run'. lines 120-131:
}
}

task 9 'run'. lines 135-148:
task 9 'run'. lines 114-127:
{
"gas_used": 267609,
"gas_used": 273200,
"status": "Executed"
}

task 10 'run'. lines 150-166:
task 10 'run'. lines 129-145:
{
"gas_used": 458467,
"status": "Executed"
}

task 12 'run'. lines 170-183:
task 12 'run'. lines 149-162:
{
"gas_used": 412079,
"gas_used": 417670,
"status": "Executed"
}

task 13 'run'. lines 185-201:
task 13 'run'. lines 164-180:
{
"gas_used": 592341,
"status": "Executed"
}

task 15 'run'. lines 205-220:
task 15 'run'. lines 184-199:
{
"gas_used": 256266,
"gas_used": 261857,
"status": "Executed"
}

task 16 'run'. lines 222-233:
task 16 'run'. lines 201-212:
{
"gas_used": 656139,
"status": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,6 @@

//# block --author 0x1 --timestamp 86400000

// //# run --signers creator
// script {
// use StarcoinFramework::StdlibUpgradeScripts;
//
// fun upgrade_from_v11_to_v12() {
// StdlibUpgradeScripts::upgrade_from_v11_to_v12();
// }
// }
// // check: EXECUTED

// //# run --signers creator
// script {
// use StarcoinFramework::StdlibUpgradeScripts;

// fun upgrade_from_v11_to_v12() {
// StdlibUpgradeScripts::upgrade_from_v12_to_v12_1();
// }
// }
// // check: EXECUTED

//# publish
module creator::XDAO {
use StarcoinFramework::DAOAccount;
Expand Down Expand Up @@ -122,10 +102,9 @@ script {
use creator::XDAO;
use StarcoinFramework::StakeToSBTPlugin;
use StarcoinFramework::STC;
use StarcoinFramework::Signer;

fun unstake_all_failed(sender: signer) {
StakeToSBTPlugin::unstake_all<XDAO::X, STC::STC>(Signer::address_of(&sender));
StakeToSBTPlugin::unstake_all<XDAO::X, STC::STC>(&sender);
}
}
// check: ABORTED, 257025
Expand All @@ -140,9 +119,9 @@ script {
use StarcoinFramework::Signer;

fun stake(sender: signer) {
let user = Signer::address_of(&sender);
StakeToSBTPlugin::unstake_all<XDAO::X, STC::STC>(user);
assert!(StakeToSBTPlugin::query_stake_count<XDAO::X, STC::STC>(user) <= 0, 10001);
let sender_addr = Signer::address_of(&sender);
StakeToSBTPlugin::unstake_all<XDAO::X, STC::STC>(&sender);
assert!(StakeToSBTPlugin::query_stake_count<XDAO::X, STC::STC>(sender_addr) <= 0, 10001);
}
}
// check: CHECKED
Expand Down Expand Up @@ -176,7 +155,7 @@ script {

fun stake_again(sender: signer) {
let sender_addr = Signer::address_of(&sender);
StakeToSBTPlugin::unstake_by_id<XDAO::X, STC::STC>(sender_addr, 2);
StakeToSBTPlugin::unstake_by_id<XDAO::X, STC::STC>(&sender, 2);
assert!(StakeToSBTPlugin::query_stake_count<XDAO::X, STC::STC>(sender_addr) <= 0, 10003);
}
}
Expand Down Expand Up @@ -213,7 +192,7 @@ script {
fun quit_and_unstake(sender: signer) {
let sender_addr = Signer::address_of(&sender);
assert!(!DAOSpace::is_member<XDAO::X>(sender_addr), 10005);
StakeToSBTPlugin::unstake_by_id<XDAO::X, STC::STC>(sender_addr, 3);
StakeToSBTPlugin::unstake_by_id<XDAO::X, STC::STC>(&sender, 3);
assert!(StakeToSBTPlugin::query_stake_count<XDAO::X, STC::STC>(sender_addr) <= 0, 10006);
}
}
Expand Down
5 changes: 4 additions & 1 deletion sources/daospace/DAOSpace.move
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,9 @@ module StarcoinFramework::DAOSpace {
}

/// propose a proposal.
/// `title`: title of the proposal
/// `introduction`: short introduction of the proposal
/// `extend`: extend of proposal , ipfs:// | { "title":"xxxxx",........ }
/// `action`: the actual action to execute.
/// `action_delay`: the delay to execute after the proposal is agreed
/// `quorum_scale_factor`: used to scale up the base quorum_votes_rate.
Expand Down Expand Up @@ -2098,7 +2101,7 @@ module StarcoinFramework::DAOSpace {
let dao_address = dao_address<DAOT>();
assert!(exists<ProposalActions<ActionT>>(dao_address), Errors::invalid_state(ERR_PROPOSAL_ACTIONS_NOT_EXIST));
let (_, token) = take_proposal_action<ActionT>(dao_address, proposal_id);
// Part of the token is awarded to whoever executes this method , TODO: 10 %
// Part of the token is awarded to whoever executes this method , current: 10 %
let award_amount = Token::value(&token) / 10;
let (burn_token , award_token) = Token::split(token, award_amount);
Account::deposit(Signer::address_of(sender), award_token);
Expand Down
2 changes: 0 additions & 2 deletions sources/daospace/SBTVoteStrategy.move
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ module StarcoinFramework::SBTVoteStrategy{
/// deserialize snapshot vote value from state
public fun get_voting_power(state: &vector<u8>) : u128 {
let sbt_value = deserialize_sbt_value_from_bcs_state(state);

//TODO support calculate weight_factor
sbt_value
}

Expand Down
10 changes: 5 additions & 5 deletions sources/daospaceplugin/AnyMemberPlugin.move
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//TODO find more good name
/// This plugin let every can join the DAO, and auto get 1 sbt.
module StarcoinFramework::AnyMemberPlugin{
use StarcoinFramework::DAOPluginMarketplace;
use StarcoinFramework::DAOSpace::{Self, CapType};
Expand Down Expand Up @@ -62,12 +62,12 @@ module StarcoinFramework::AnyMemberPlugin{
join<DAOT>(&sender, image_data, image_url);
}

public fun install_plugin_proposal<DAOT:store>(sender:&signer, title:vector<u8>, introduction:vector<u8>, description: vector<u8>, action_delay:u64){
InstallPluginProposalPlugin::create_proposal<DAOT, AnyMemberPlugin>(sender, required_caps(), title, introduction, description, action_delay);
public fun install_plugin_proposal<DAOT:store>(sender:&signer, title:vector<u8>, introduction:vector<u8>, extend: vector<u8>, action_delay:u64){
InstallPluginProposalPlugin::create_proposal<DAOT, AnyMemberPlugin>(sender, required_caps(), title, introduction, extend, action_delay);
}

public (script) fun install_plugin_proposal_entry<DAOT:store>(sender:signer, title:vector<u8>, introduction:vector<u8>, description: vector<u8>, action_delay:u64){
install_plugin_proposal<DAOT>(&sender, title, introduction, description, action_delay);
public (script) fun install_plugin_proposal_entry<DAOT:store>(sender:signer, title:vector<u8>, introduction:vector<u8>, extend: vector<u8>, action_delay:u64){
install_plugin_proposal<DAOT>(&sender, title, introduction, extend, action_delay);
}

}
Loading

0 comments on commit 884f648

Please sign in to comment.