Skip to content

Commit

Permalink
able to update DAOExt (#108)
Browse files Browse the repository at this point in the history
* able to update DAOExt

* add DAOModifyExtCap

* fix DAOExt

* fix build info
  • Loading branch information
pause125 committed Sep 5, 2022
1 parent 7263b0a commit fc7ac4a
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: 695F4208154FB109E223367B79D9AD3C30261C91BF6F595A3B9D2226BC5103B0
source_digest: A710EE5A9CB99AFE86615AD5840E39342DB78E8FB0F5F9509550D55526BF054D
build_flags:
dev_mode: false
test_mode: false
Expand Down
19 changes: 19 additions & 0 deletions integration-tests/daospace/dao_ext.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
processed 9 tasks

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

task 7 'run'. lines 67-76:
{
"gas_used": 63423,
"status": "Executed"
}

task 8 'run'. lines 78-87:
{
"gas_used": 63423,
"status": "Executed"
}
87 changes: 87 additions & 0 deletions integration-tests/daospace/dao_ext.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//# init -n dev

//# faucet --addr creator --amount 100000000000

//# faucet --addr alice --amount 10000000000

//# faucet --addr bob --amount 10000000000

//# publish
module creator::DAOHelper {
use StarcoinFramework::DAOAccount;
use StarcoinFramework::DAOSpace;
use StarcoinFramework::Option;

struct X has store, copy, drop {
value: u64,
}

const NAME: vector<u8> = b"X";

/// directly upgrade the sender account to DAOAccount and create DAO
public(script) fun create_dao(
sender: signer,
voting_delay: u64,
voting_period: u64,
voting_quorum_rate: u8,
min_action_delay: u64,
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,
voting_quorum_rate,
min_action_delay,
min_proposal_deposit,
);
let dao_ext = X { value: 0};
let dao_root_cap = DAOSpace::create_dao<X>(dao_account_cap, *&NAME, Option::none<vector<u8>>(), Option::none<vector<u8>>(), b"ipfs://description", dao_ext, config);

DAOSpace::burn_root_cap(dao_root_cap);
}

public fun modify_ext(value: u64): u64 {
let witness = X { value: 0 };
let X { value: old_value } = DAOSpace::take_ext(&witness);
DAOSpace::save_ext(X { value });
old_value
}
}

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

//# run --signers creator
script {
use creator::DAOHelper;

fun main(sender: signer) {
// time unit is millsecond
DAOHelper::create_dao(sender, 10000, 3600000, 2, 10000, 10);
}
}
// check: EXECUTED

//# run --signers alice
script {
use creator::DAOHelper;

fun main(_sender: signer) {
let ext_value = DAOHelper::modify_ext(123);
assert!(ext_value == 0, 101);
}
}
// check: EXECUTED

//# run --signers bob
script {
use creator::DAOHelper;

fun main(_sender: signer) {
let ext_value = DAOHelper::modify_ext(234);
assert!(ext_value == 123, 101);
}
}
// check: EXECUTED
24 changes: 23 additions & 1 deletion sources/daospace/DAOSpace.move
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module StarcoinFramework::DAOSpace {
const ERR_NFT_ERROR: u64 = 104;
const ERR_ALREADY_INIT: u64 = 105;
const ERR_TOKEN_ERROR: u64 = 106;
const ERR_DAO_EXT: u64 = 107;

/// member
const ERR_EXPECT_MEMBER: u64 = 200;
Expand Down Expand Up @@ -193,6 +194,8 @@ module StarcoinFramework::DAOSpace {
Vector::push_back(&mut caps, member_cap_type());
Vector::push_back(&mut caps, proposal_cap_type());
Vector::push_back(&mut caps, grant_cap_type());
Vector::push_back(&mut caps, token_mint_cap_type());
Vector::push_back(&mut caps, token_burn_cap_type());
caps
}

Expand Down Expand Up @@ -340,12 +343,31 @@ module StarcoinFramework::DAOSpace {
DAORootCap<DAOT>{}
}

// Upgrade account to DAO account and create DAO
/// Upgrade account to DAO account and create DAO
public fun upgrade_to_dao<DAOT: store>(sender: signer, name: vector<u8>, image_data:Option::Option<vector<u8>>, image_url:Option::Option<vector<u8>>, description:vector<u8>, ext: DAOT, config: DAOConfig): DAORootCap<DAOT> acquires DAOEvent{
let cap = DAOAccount::upgrade_to_dao(sender);
create_dao<DAOT>(cap, name, image_data, image_url, description, ext, config)
}

/// Take ext from DAOExt
public fun take_ext<DAOT: store>(_witness: &DAOT): DAOT
acquires DAOExt {
let dao_addr = dao_address<DAOT>();
assert!(exists<DAOExt<DAOT>>(dao_addr), Errors::not_published(ERR_DAO_EXT));
let DAOExt<DAOT> { ext } = move_from<DAOExt<DAOT>>(dao_addr);
ext
}

/// Save ext to DAOExt
public fun save_ext<DAOT: store>(ext: DAOT) acquires DAOAccountCapHolder {
let dao_addr = dao_address<DAOT>();
assert!(!exists<DAOExt<DAOT>>(dao_addr), Errors::already_published(ERR_DAO_EXT));
let dao_signer = dao_signer<DAOT>();
move_to(&dao_signer, DAOExt{
ext
});
}

/// Burn the root cap after init the DAO
public fun burn_root_cap<DAOT>(cap: DAORootCap<DAOT>) {
let DAORootCap{} = cap;
Expand Down

0 comments on commit fc7ac4a

Please sign in to comment.