diff --git a/build/StarcoinFramework/BuildInfo.yaml b/build/StarcoinFramework/BuildInfo.yaml index 6869e7bd..bf72404f 100644 --- a/build/StarcoinFramework/BuildInfo.yaml +++ b/build/StarcoinFramework/BuildInfo.yaml @@ -321,7 +321,7 @@ compiled_package_info: ? address: "0x00000000000000000000000000000001" name: YieldFarmingV2 : StarcoinFramework - source_digest: 5F39868CB8511B5984EA5AFAC56DD524087DB8401BE9901148BA2CBF177357E4 + source_digest: E9EBFB94E7BA4C1DB94C3F860A481AA819D6600B82D2F49971D1AE849AE3AA8F build_flags: dev_mode: false test_mode: false diff --git a/sources/daospaceplugin/StakeToSBTPlugin.move b/sources/daospaceplugin/StakeToSBTPlugin.move index b17ffca3..4fba70a2 100644 --- a/sources/daospaceplugin/StakeToSBTPlugin.move +++ b/sources/daospaceplugin/StakeToSBTPlugin.move @@ -20,11 +20,11 @@ module StarcoinFramework::StakeToSBTPlugin { const ERR_PLUGIN_ITEM_CANT_FOUND: u64 = 1006; const ERR_PLUGIN_NO_MATCH_LOCKTIME: u64 = 1007; - struct StakeToSBTPlugin has store, drop {} + struct StakeToSBTPlugin has store, drop{} public fun initialize() { let signer = GenesisSignerCapability::get_genesis_signer(); - + DAOPluginMarketplace::register_plugin( &signer, b"0x1::StakeToSBTPlugin", @@ -35,11 +35,11 @@ module StarcoinFramework::StakeToSBTPlugin { let implement_extpoints = Vector::empty>(); let depend_extpoints = Vector::empty>(); - let witness = StakeToSBTPlugin {}; + let witness = StakeToSBTPlugin{}; DAOPluginMarketplace::publish_plugin_version( &signer, - &witness, - b"v0.1.0", + &witness, + b"v0.1.0", *&implement_extpoints, *&depend_extpoints, b"inner-plugin://stake-to-sbt-plugin", @@ -137,7 +137,8 @@ module StarcoinFramework::StakeToSBTPlugin { } /// Set sbt weight by given DAO root capability - public fun set_sbt_weight_with_root_cap( + public fun set_sbt_weight_with_root_cap( _cap: &DAOSpace::DAORootCap, lock_time: u64, weight: u64 @@ -178,26 +179,17 @@ module StarcoinFramework::StakeToSBTPlugin { ); } - public fun stake( - sender: &signer, - token: Token::Token, - lock_time: u64 - ): u64 acquires StakeList { + public fun stake(sender: &signer, + token: Token::Token, + lock_time: u64): u64 acquires StakeList { let sender_addr = Signer::address_of(sender); // Increase SBT let witness = StakeToSBTPlugin {}; - let member_cap = - DAOSpace::acquire_member_cap(&witness); + let member_cap = DAOSpace::acquire_member_cap(&witness); if (!DAOSpace::is_member(sender_addr)) { IdentifierNFT::accept, DAOSpace::DAOMemberBody>(sender); - DAOSpace::join_member( - &member_cap, - sender_addr, - Option::none>(), - Option::none>(), - 0 - ); + DAOSpace::join_member(&member_cap, sender_addr, Option::none>(), Option::none>(), 0); }; if (!exists>(sender_addr)) { @@ -229,8 +221,7 @@ module StarcoinFramework::StakeToSBTPlugin { stake_list.next_id = id; let witness = StakeToSBTPlugin {}; - let plugin_event_cap = - DAOSpace::acquire_plugin_event_cap(&witness); + let plugin_event_cap = DAOSpace::acquire_plugin_event_cap(&witness); DAOSpace::emit_plugin_event( &plugin_event_cap, SBTStakeEvent { @@ -294,8 +285,7 @@ module StarcoinFramework::StakeToSBTPlugin { Account::deposit(member, unstake_item(member, poped_item)); let witness = StakeToSBTPlugin {}; - let plugin_event_cap = - DAOSpace::acquire_plugin_event_cap(&witness); + let plugin_event_cap = DAOSpace::acquire_plugin_event_cap(&witness); DAOSpace::emit_plugin_event( &plugin_event_cap, SBTUnstakeEvent { @@ -327,41 +317,24 @@ module StarcoinFramework::StakeToSBTPlugin { } /// Unstake a item from a item object - fun unstake_item( - member: address, - item: Stake - ): Token::Token { + fun unstake_item(_member: address, item: Stake): Token::Token { let Stake { id: _, token, lock_time, stake_time, weight: _, - sbt_amount, + sbt_amount: _, } = item; assert!((Timestamp::now_seconds() - stake_time) > lock_time, Errors::invalid_state(ERR_PLUGIN_STILL_LOCKED)); - // Deduct the corresponding SBT amount if the signer account is a DAO member while unstake - if (DAOSpace::is_member(member)) { - let witness = StakeToSBTPlugin {}; - let member_cap = - DAOSpace::acquire_member_cap(&witness); - - // Decrease the SBT using `sbt_amount` which from unwrapped Stake data, - // rather than the value that calculate a SBT amount from lock time and weight, - // because of the `weight` could change at any time - DAOSpace::decrease_member_sbt(&member_cap, member, sbt_amount); - }; - token } fun get_sbt_weight(lock_time: u64): Option::Option { - let config = - DAOSpace::get_custom_config>(); - let c = - &mut config.weight_vec; + let config = DAOSpace::get_custom_config>(); + let c = &mut config.weight_vec; let len = Vector::length(c); let idx = 0; @@ -377,8 +350,7 @@ module StarcoinFramework::StakeToSBTPlugin { } fun set_sbt_weight(lock_time: u64, weight: u64) { - let config = - DAOSpace::get_custom_config>(); + let config = DAOSpace::get_custom_config>(); let c = &mut config.weight_vec; let len = Vector::length(c); let idx = 0; @@ -413,10 +385,7 @@ module StarcoinFramework::StakeToSBTPlugin { }); } - fun find_item( - id: u64, - c: &vector> - ): Option::Option { + fun find_item(id: u64, c: &vector>): Option::Option { let len = Vector::length(c); let idx = 0; while (idx < len) { @@ -434,13 +403,11 @@ module StarcoinFramework::StakeToSBTPlugin { } /// Create proposal that to specific a weight for a locktime - public fun create_weight_proposal( - sender: &signer, - description: vector, - lock_time: u64, - weight: u64, - action_delay: u64 - ) { + public fun create_weight_proposal(sender: &signer, + description: vector, + lock_time: u64, + weight: u64, + action_delay: u64) { let witness = StakeToSBTPlugin {}; let cap = @@ -453,20 +420,15 @@ module StarcoinFramework::StakeToSBTPlugin { action_delay); } - public(script) fun create_weight_proposal_entry( - sender: signer, - description: vector, - lock_time: u64, - weight: u64, - action_delay: u64 - ) { - create_weight_proposal(&sender, description, lock_time, weight, action_delay); + public(script) fun create_weight_proposal_entry(sender: signer, + description:vector, + lock_time: u64, + weight: u64, + action_delay: u64) { + create_weight_proposal(&sender, description, lock_time, weight, action_delay); } - - public fun execute_weight_proposal( - sender: &signer, - proposal_id: u64 - ) { + public fun execute_weight_proposal(sender: &signer, + proposal_id: u64) { let witness = StakeToSBTPlugin {}; let proposal_cap = DAOSpace::acquire_proposal_cap(&witness); @@ -483,44 +445,30 @@ module StarcoinFramework::StakeToSBTPlugin { set_sbt_weight(lock_time, weight); } - public(script) fun execute_weight_proposal_entry( - sender: signer, - proposal_id: u64 - ) { + public(script) fun execute_weight_proposal_entry(sender: signer, + proposal_id: u64) { execute_weight_proposal(&sender, proposal_id); } /// Create proposal that to accept a token type, which allow user to convert amount of token to SBT - public fun create_token_accept_proposal( - sender: &signer, - description: vector, - action_delay: u64 - ) { + public fun create_token_accept_proposal(sender: &signer, + description: vector, + action_delay: u64) { let witness = StakeToSBTPlugin {}; let cap = DAOSpace::acquire_proposal_cap(&witness); - DAOSpace::create_proposal( - &cap, - sender, - AcceptTokenCap {}, - description, - action_delay - ); + DAOSpace::create_proposal(&cap, sender, AcceptTokenCap {}, description, action_delay); } - public(script) fun create_token_accept_proposal_entry( - sender: signer, - description: vector, - action_delay: u64 - ) { - create_token_accept_proposal(&sender, description, action_delay); + public(script) fun create_token_accept_proposal_entry(sender: signer, + description:vector, + action_delay: u64) { + create_token_accept_proposal(&sender, description, action_delay); } - public fun execute_token_accept_proposal( - sender: &signer, - proposal_id: u64 - ) { + public fun execute_token_accept_proposal(sender: &signer, + proposal_id: u64) { let witness = StakeToSBTPlugin {}; let proposal_cap = DAOSpace::acquire_proposal_cap(&witness); @@ -535,49 +483,30 @@ module StarcoinFramework::StakeToSBTPlugin { } - public(script) fun execute_token_accept_proposal_entry( - sender: signer, - proposal_id: u64 - ) { - execute_token_accept_proposal(&sender, proposal_id); + public(script) fun execute_token_accept_proposal_entry(sender: signer, + proposal_id: u64) { + execute_token_accept_proposal(&sender, proposal_id); } - public fun install_plugin_proposal( - sender: &signer, - description: vector, - action_delay: u64 - ) { - InstallPluginProposalPlugin::create_proposal( - sender, - required_caps(), - description, - action_delay - ); + public fun install_plugin_proposal(sender: &signer, description:vector, action_delay: u64) { + InstallPluginProposalPlugin::create_proposal(sender, required_caps(), description,action_delay); } - public(script) fun install_plugin_proposal_entry( - sender: signer, - description: vector, - action_delay: u64 - ) { + public (script) fun install_plugin_proposal_entry(sender:signer, description: vector, action_delay:u64){ install_plugin_proposal(&sender, description, action_delay); } /// Called by script - public(script) fun stake_entry( - sender: signer, - amount: u128, - lock_time: u64 - ) acquires StakeList { + public(script) fun stake_entry(sender: signer, + amount: u128, + lock_time: u64) acquires StakeList { let token = Account::withdraw(&sender, amount); stake(&sender, token, lock_time); } /// Called by script - public(script) fun unstake_item_entry( - member: address, - id: u64 - ) acquires StakeList { + public(script) fun unstake_item_entry(member: address, + id: u64) acquires StakeList { unstake_by_id(member, id); } }