Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Member Grant Offer #174

Merged
merged 10 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified build/StarcoinFramework/bytecode_modules/MemberProposalPlugin.mv
Binary file not shown.
29 changes: 28 additions & 1 deletion build/StarcoinFramework/docs/MemberProposalPlugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

- [Struct `MemberProposalPlugin`](#0x1_MemberProposalPlugin_MemberProposalPlugin)
- [Struct `MemberJoinAction`](#0x1_MemberProposalPlugin_MemberJoinAction)
- [Constants](#@Constants_0)
- [Function `initialize`](#0x1_MemberProposalPlugin_initialize)
- [Function `required_caps`](#0x1_MemberProposalPlugin_required_caps)
- [Function `create_proposal`](#0x1_MemberProposalPlugin_create_proposal)
Expand All @@ -19,6 +20,7 @@

<pre><code><b>use</b> <a href="DAOPluginMarketplace.md#0x1_DAOPluginMarketplace">0x1::DAOPluginMarketplace</a>;
<b>use</b> <a href="DAOSpace.md#0x1_DAOSpace">0x1::DAOSpace</a>;
<b>use</b> <a href="Errors.md#0x1_Errors">0x1::Errors</a>;
<b>use</b> <a href="InstallPluginProposalPlugin.md#0x1_InstallPluginProposalPlugin">0x1::InstallPluginProposalPlugin</a>;
<b>use</b> <a href="Option.md#0x1_Option">0x1::Option</a>;
<b>use</b> <a href="Vector.md#0x1_Vector">0x1::Vector</a>;
Expand Down Expand Up @@ -98,6 +100,29 @@

</details>

<a name="@Constants_0"></a>

## Constants


<a name="0x1_MemberProposalPlugin_ERR_MEMBER_EXIST"></a>



<pre><code><b>const</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_ERR_MEMBER_EXIST">ERR_MEMBER_EXIST</a>: u64 = 101;
</code></pre>



<a name="0x1_MemberProposalPlugin_ERR_MEMBER_OFFER_EXIST"></a>



<pre><code><b>const</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_ERR_MEMBER_OFFER_EXIST">ERR_MEMBER_OFFER_EXIST</a>: u64 = 102;
</code></pre>



<a name="0x1_MemberProposalPlugin_initialize"></a>

## Function `initialize`
Expand Down Expand Up @@ -190,6 +215,8 @@
image_data,
image_url
};
<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);
}
</code></pre>
Expand Down Expand Up @@ -242,7 +269,7 @@
<b>let</b> proposal_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> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_MemberJoinAction">MemberJoinAction</a>{member, init_sbt, image_data, image_url} = <a href="DAOSpace.md#0x1_DAOSpace_execute_proposal">DAOSpace::execute_proposal</a>&lt;DAOT, <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin">MemberProposalPlugin</a>, <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_MemberJoinAction">MemberJoinAction</a>&gt;(&proposal_cap, sender, proposal_id);
<b>let</b> member_cap = <a href="DAOSpace.md#0x1_DAOSpace_acquire_member_cap">DAOSpace::acquire_member_cap</a>&lt;DAOT, <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin">MemberProposalPlugin</a>&gt;(&witness);
<a href="DAOSpace.md#0x1_DAOSpace_join_member">DAOSpace::join_member</a>(&member_cap, member, <a href="Option.md#0x1_Option_some">Option::some</a>(image_data), <a href="Option.md#0x1_Option_some">Option::some</a>(image_url) , init_sbt);
<a href="DAOSpace.md#0x1_DAOSpace_member_offer">DAOSpace::member_offer</a>(&member_cap, member, <a href="Option.md#0x1_Option_some">Option::some</a>(image_data), <a href="Option.md#0x1_Option_some">Option::some</a>(image_url) , init_sbt);
}
</code></pre>

Expand Down
Binary file modified build/StarcoinFramework/source_maps/MemberProposalPlugin.mvsm
Binary file not shown.
Binary file modified build/StarcoinFramework/source_maps/Offer.mvsm
Binary file not shown.
2 changes: 1 addition & 1 deletion integration-tests/daospace/dao_create.exp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ task 7 'run'. lines 59-67:

task 10 'run'. lines 73-84:
{
"gas_used": 1054663,
"gas_used": 1184587,
"status": "Executed"
}
2 changes: 1 addition & 1 deletion integration-tests/daospace/dao_ext.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ processed 9 tasks

task 6 'run'. lines 56-65:
{
"gas_used": 1008684,
"gas_used": 1035167,
"status": "Executed"
}

Expand Down
42 changes: 13 additions & 29 deletions integration-tests/daospace/dao_grant.exp
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
processed 17 tasks

task 5 'run'. lines 13-21:
task 8 'run'. lines 108-119:
{
"gas_used": 29077,
"status": {
"MoveAbort": {
"location": {
"Module": {
"address": "0x00000000000000000000000000000001",
"name": "Block"
}
},
"abort_code": "5382"
}
}
}

task 8 'run'. lines 123-134:
{
"gas_used": 1812265,
"gas_used": 1838748,
"status": "Executed"
}

task 9 'run'. lines 136-155:
task 9 'run'. lines 121-140:
{
"gas_used": 315396,
"gas_used": 427915,
"status": "Executed"
}

task 10 'run'. lines 157-191:
task 10 'run'. lines 142-174:
{
"gas_used": 561697,
"gas_used": 630999,
"status": "Executed"
}

task 12 'run'. lines 195-207:
task 12 'run'. lines 178-190:
{
"gas_used": 52853,
"status": {
Expand All @@ -50,20 +34,20 @@ task 12 'run'. lines 195-207:
}
}

task 13 'run'. lines 209-229:
task 13 'run'. lines 192-212:
{
"gas_used": 241369,
"gas_used": 253287,
"status": "Executed"
}

task 15 'run'. lines 233-253:
task 15 'run'. lines 216-236:
{
"gas_used": 229003,
"gas_used": 240921,
"status": "Executed"
}

task 16 'run'. lines 255-269:
task 16 'run'. lines 238-252:
{
"gas_used": 192361,
"gas_used": 345263,
"status": "Executed"
}
67 changes: 25 additions & 42 deletions integration-tests/daospace/dao_grant.move
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,21 @@

//# faucet --addr cindy --amount 10000000000

// TODO figure out how to call genesis init script in integration tests

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

fun main(){
StdlibUpgradeScripts::upgrade_from_v11_to_v12();
}
}
// check: EXECUTED
//# block --author 0x1 --timestamp 86200000

//# publish
module creator::DAOHelper {
use StarcoinFramework::DAOPluginMarketplace;
use StarcoinFramework::DAOAccount;
use StarcoinFramework::DAOSpace::{Self, CapType};
use StarcoinFramework::AnyMemberPlugin::{Self, AnyMemberPlugin};
use StarcoinFramework::InstallPluginProposalPlugin::{Self, InstallPluginProposalPlugin};
use StarcoinFramework::Vector;
use StarcoinFramework::STC;
use StarcoinFramework::Option;
use StarcoinFramework::Signer;
use StarcoinFramework::InstallPluginProposalPlugin::InstallPluginProposalPlugin;
use StarcoinFramework::AnyMemberPlugin::AnyMemberPlugin;
use StarcoinFramework::AnyMemberPlugin;
use StarcoinFramework::InstallPluginProposalPlugin;

struct X has store, copy, drop{}

Expand All @@ -45,8 +38,6 @@ module creator::DAOHelper {
min_proposal_deposit: u128,){
let dao_account_cap = DAOAccount::upgrade_to_dao(sender);


//let dao_signer = DAOAccount::dao_signer(&dao_account_cap);
let config = DAOSpace::new_dao_config(
voting_delay,
voting_period,
Expand All @@ -55,8 +46,8 @@ module creator::DAOHelper {
min_proposal_deposit,
);
let dao_root_cap = DAOSpace::create_dao<X>(dao_account_cap, *&NAME, Option::none<vector<u8>>(), Option::none<vector<u8>>(), b"ipfs://description", X{}, config);
DAOSpace::install_plugin_with_root_cap<X, InstallPluginProposalPlugin>(&dao_root_cap, InstallPluginProposalPlugin::required_caps());

DAOSpace::install_plugin_with_root_cap<X, InstallPluginProposalPlugin>(&dao_root_cap, InstallPluginProposalPlugin::required_caps());
DAOSpace::install_plugin_with_root_cap<X, AnyMemberPlugin>(&dao_root_cap, AnyMemberPlugin::required_caps());

DAOSpace::install_plugin_with_root_cap<X, XPlugin>(&dao_root_cap, required_caps());
Expand Down Expand Up @@ -101,21 +92,15 @@ module creator::DAOHelper {
public fun create_grant(sender:&signer, total:u128, start_time:u64,period:u64){
let witness = XPlugin{};
let grant_cap = DAOSpace::acquire_grant_cap<X, XPlugin>(&witness);
DAOSpace::create_grant<X,XPlugin,STC::STC>(&grant_cap,sender, total, start_time, period);
DAOSpace::grant_offer<X,XPlugin,STC::STC>(&grant_cap, Signer::address_of(sender), total, start_time, period);
DAOSpace::grant_accept_offer<X, XPlugin, STC::STC>(sender)
}

public fun grant_revoke(grantee:address){
let witness = XPlugin{};
let grant_cap = DAOSpace::acquire_grant_cap<X, XPlugin>(&witness);
DAOSpace::grant_revoke<X,XPlugin,STC::STC>(&grant_cap, grantee);
}

public fun grant_config(sender:&signer, grantee:address, total:u128, start_time:u64,period:u64){
let witness = XPlugin{};
let grant_cap = DAOSpace::acquire_grant_cap<X, XPlugin>(&witness);
DAOSpace::grant_config<X,XPlugin,STC::STC>(&grant_cap, grantee ,sender, total, start_time, period);

}
}

//# block --author 0x1 --timestamp 86400000
Expand All @@ -136,7 +121,7 @@ script{
//# run --signers alice
script{
use creator::DAOHelper::{Self, X, XPlugin};
use StarcoinFramework::DAOSpace::{query_grant, query_grant_can_withdraw};
use StarcoinFramework::DAOSpace::{query_grant, query_grant_withdrawable_amount};
use StarcoinFramework::DAOSpace;
use StarcoinFramework::STC;

Expand All @@ -149,15 +134,15 @@ script{
assert!(DAOSpace::query_grant_info_start_time(&grant_info) == 86400,1003);
assert!(DAOSpace::query_grant_info_period(&grant_info) == 3600,1004);

assert!(query_grant_can_withdraw<X, XPlugin, STC::STC>(@alice) == 0,1005);
assert!(query_grant_withdrawable_amount<X, XPlugin, STC::STC>(@alice) == 0,1005);
}
}
// check: EXECUTED

//# run --signers bob
script{
use creator::DAOHelper::{Self, X, XPlugin};
use StarcoinFramework::DAOSpace::{Self,query_grant, query_grant_can_withdraw, grant_withdraw};
use StarcoinFramework::DAOSpace::{Self,query_grant, query_grant_withdrawable_amount, grant_withdraw};
use StarcoinFramework::STC;
use StarcoinFramework::Account;

Expand All @@ -170,22 +155,20 @@ script{
assert!(DAOSpace::query_grant_info_start_time(&grant_info) == 86400,1007);
assert!(DAOSpace::query_grant_info_period(&grant_info) == 0,1008);

assert!(query_grant_can_withdraw<X, XPlugin, STC::STC>(@bob) == 1000000000,1009);
assert!(query_grant_withdrawable_amount<X, XPlugin, STC::STC>(@bob) == 1000000000,1009);

grant_withdraw<X, XPlugin, STC::STC>(&sender, 500000000u128);
assert!(Account::balance<STC::STC>(@bob) == 10000000000 + 500000000, 1010);

DAOHelper::grant_config(&sender, @bob, 500000000u128, 86400u64, 0u64);

let grant_info = query_grant<X, XPlugin, STC::STC>(@bob);
assert!(DAOSpace::query_grant_info_total(&grant_info) == 500000000,1011);
assert!(DAOSpace::query_grant_info_total(&grant_info) == 1000000000,1011);
assert!(DAOSpace::query_grant_info_withdraw(&grant_info)== 500000000,1012);
assert!(DAOSpace::query_grant_info_start_time(&grant_info) == 86400,1013);
assert!(DAOSpace::query_grant_info_period(&grant_info) == 0,1014);
assert!(query_grant_can_withdraw<X, XPlugin, STC::STC>(@bob) == 0,1015);
assert!(query_grant_withdrawable_amount<X, XPlugin, STC::STC>(@bob) == 500000000,1015);

DAOHelper::grant_revoke(@bob);
assert!(DAOSpace::is_have_grant<X, XPlugin, STC::STC>(@bob) == false, 1016);
assert!(DAOSpace::is_exist_grant<X, XPlugin, STC::STC>(@bob) == false, 1016);
}
}
// check: EXECUTED
Expand All @@ -195,12 +178,12 @@ script{
//# run --signers alice
script{
use creator::DAOHelper::{X, XPlugin};
use StarcoinFramework::DAOSpace::{Self, query_grant_can_withdraw};
use StarcoinFramework::DAOSpace::{Self, query_grant_withdrawable_amount};
use StarcoinFramework::STC;

//alice withdraw more grant
fun withdraw_grant(sender: signer){
assert!(query_grant_can_withdraw<X, XPlugin, STC::STC>(@alice) == 277777, 1001);
assert!(query_grant_withdrawable_amount<X, XPlugin, STC::STC>(@alice) == 277777, 1001);
DAOSpace::grant_withdraw<X, XPlugin, STC::STC>(&sender, 377777u128);
}
}
Expand All @@ -209,13 +192,13 @@ script{
//# run --signers alice
script{
use creator::DAOHelper::{X, XPlugin};
use StarcoinFramework::DAOSpace::{Self, query_grant, query_grant_can_withdraw};
use StarcoinFramework::DAOSpace::{Self, query_grant, query_grant_withdrawable_amount};
use StarcoinFramework::STC;
use StarcoinFramework::Account;

//alice withdraw grant
fun withdraw_grant(sender: signer){
assert!(query_grant_can_withdraw<X, XPlugin, STC::STC>(@alice) == 277777, 1001);
assert!(query_grant_withdrawable_amount<X, XPlugin, STC::STC>(@alice) == 277777, 1001);
let old_balance = Account::balance<STC::STC>(@alice);
DAOSpace::grant_withdraw<X, XPlugin, STC::STC>(&sender, 277777u128);
assert!(Account::balance<STC::STC>(@alice) == old_balance + 277777, 1002);
Expand All @@ -233,13 +216,13 @@ script{
//# run --signers alice
script{
use creator::DAOHelper::{X, XPlugin};
use StarcoinFramework::DAOSpace::{Self, query_grant, query_grant_can_withdraw};
use StarcoinFramework::DAOSpace::{Self, query_grant, query_grant_withdrawable_amount};
use StarcoinFramework::STC;
use StarcoinFramework::Account;

//alice withdraw grant
fun withdraw_grant(sender: signer){
assert!(query_grant_can_withdraw<X, XPlugin, STC::STC>(@alice) == 1000000000 - 277777, 1001);
assert!(query_grant_withdrawable_amount<X, XPlugin, STC::STC>(@alice) == 1000000000 - 277777, 1001);
let old_balance = Account::balance<STC::STC>(@alice);
DAOSpace::grant_withdraw<X, XPlugin, STC::STC>(&sender, 1000000000 - 277777);
assert!(Account::balance<STC::STC>(@alice) == old_balance + 1000000000 - 277777, 1002);
Expand All @@ -261,9 +244,9 @@ script{
//alice create grant to cindy
fun create_grant(sender: signer){
DAOHelper::create_grant(&sender, 1000000000u128, 90000u64, 3600u64);
assert!(DAOSpace::is_have_grant<X, XPlugin, STC::STC>(@cindy) == true, 1001);
assert!(DAOSpace::is_exist_grant<X, XPlugin, STC::STC>(@cindy) == true, 1001);
DAOSpace::refund_grant<X, XPlugin, STC::STC>(&sender);
assert!(DAOSpace::is_have_grant<X, XPlugin, STC::STC>(@cindy) == false, 1002);
assert!(DAOSpace::is_exist_grant<X, XPlugin, STC::STC>(@cindy) == false, 1002);
}
}
// check: EXECUTED
6 changes: 3 additions & 3 deletions integration-tests/daospace/dao_proposal.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ processed 42 tasks

task 7 'run'. lines 158-169:
{
"gas_used": 1809468,
"gas_used": 1835951,
"status": "Executed"
}

Expand All @@ -20,13 +20,13 @@ task 9 'run'. lines 187-212:

task 11 'run'. lines 217-233:
{
"gas_used": 239832,
"gas_used": 343273,
"status": "Executed"
}

task 12 'run'. lines 235-251:
{
"gas_used": 239832,
"gas_used": 343273,
"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 @@ -126,7 +126,7 @@ module creator::DAOHelper {
public fun member_join<DAOT:store>(to_address: address, init_sbt: u128){
let witness = XPlugin{};
let member_cap = DAOSpace::acquire_member_cap<DAOT, XPlugin>(&witness);
DAOSpace::join_member<DAOT, XPlugin>(&member_cap, to_address, Option::none<vector<u8>>(), Option::none<vector<u8>>(), init_sbt);
DAOSpace::join_member_with_member_cap<DAOT, XPlugin>(&member_cap, to_address, Option::none<vector<u8>>(), Option::none<vector<u8>>(), init_sbt);
}

struct Checkpoint<phantom DAOt:store> has key{
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/daospace/dao_proposal_rejected.exp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ processed 40 tasks

task 7 'run'. lines 126-135:
{
"gas_used": 1212834,
"gas_used": 1239317,
"status": {
"MoveAbort": {
"location": {
Expand Down
Loading