diff --git a/build/StarcoinFramework/BuildInfo.yaml b/build/StarcoinFramework/BuildInfo.yaml index 8c8b8093..d6053e95 100644 --- a/build/StarcoinFramework/BuildInfo.yaml +++ b/build/StarcoinFramework/BuildInfo.yaml @@ -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 diff --git a/integration-tests/daospace/dao_ext.exp b/integration-tests/daospace/dao_ext.exp new file mode 100644 index 00000000..746d1a3e --- /dev/null +++ b/integration-tests/daospace/dao_ext.exp @@ -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" +} diff --git a/integration-tests/daospace/dao_ext.move b/integration-tests/daospace/dao_ext.move new file mode 100644 index 00000000..f4d05b6c --- /dev/null +++ b/integration-tests/daospace/dao_ext.move @@ -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 = 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(dao_account_cap, *&NAME, Option::none>(), Option::none>(), 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 diff --git a/sources/daospace/DAOSpace.move b/sources/daospace/DAOSpace.move index d05a006b..c0c1eb97 100644 --- a/sources/daospace/DAOSpace.move +++ b/sources/daospace/DAOSpace.move @@ -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; @@ -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 } @@ -340,12 +343,31 @@ module StarcoinFramework::DAOSpace { DAORootCap{} } - // Upgrade account to DAO account and create DAO + /// Upgrade account to DAO account and create DAO public fun upgrade_to_dao(sender: signer, name: vector, image_data:Option::Option>, image_url:Option::Option>, description:vector, ext: DAOT, config: DAOConfig): DAORootCap acquires DAOEvent{ let cap = DAOAccount::upgrade_to_dao(sender); create_dao(cap, name, image_data, image_url, description, ext, config) } + /// Take ext from DAOExt + public fun take_ext(_witness: &DAOT): DAOT + acquires DAOExt { + let dao_addr = dao_address(); + assert!(exists>(dao_addr), Errors::not_published(ERR_DAO_EXT)); + let DAOExt { ext } = move_from>(dao_addr); + ext + } + + /// Save ext to DAOExt + public fun save_ext(ext: DAOT) acquires DAOAccountCapHolder { + let dao_addr = dao_address(); + assert!(!exists>(dao_addr), Errors::already_published(ERR_DAO_EXT)); + let dao_signer = dao_signer(); + move_to(&dao_signer, DAOExt{ + ext + }); + } + /// Burn the root cap after init the DAO public fun burn_root_cap(cap: DAORootCap) { let DAORootCap{} = cap;