Skip to content

Commit

Permalink
Revert "Fix v12 (#210)"
Browse files Browse the repository at this point in the history
This reverts commit bfd8fa6.
  • Loading branch information
nkysg committed Mar 2, 2023
1 parent 4b7eb6f commit 04b5a07
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 46 deletions.
Binary file not shown.
4 changes: 2 additions & 2 deletions build/StarcoinFramework/docs/InstallPluginProposalPlugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ every plugin should provide a entry function to create proposal to install self.



<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="InstallPluginProposalPlugin.md#0x1_InstallPluginProposalPlugin_execute_proposal_entry">execute_proposal_entry</a>&lt;DAOT: store, ToInstallPluginT: store&gt;(sender: signer, proposal_id: u64)
<pre><code><b>public</b>(<b>script</b>) <b>fun</b> <a href="InstallPluginProposalPlugin.md#0x1_InstallPluginProposalPlugin_execute_proposal_entry">execute_proposal_entry</a>&lt;DAOT: store, ToInstallPluginT: <b>copy</b>, drop, store&gt;(sender: signer, proposal_id: u64)
</code></pre>


Expand All @@ -223,7 +223,7 @@ every plugin should provide a entry function to create proposal to install self.
<summary>Implementation</summary>


<pre><code><b>public</b> (<b>script</b>) <b>fun</b> <a href="InstallPluginProposalPlugin.md#0x1_InstallPluginProposalPlugin_execute_proposal_entry">execute_proposal_entry</a>&lt;DAOT: store, ToInstallPluginT: store&gt;(sender: signer, proposal_id: u64) {
<pre><code><b>public</b> (<b>script</b>) <b>fun</b> <a href="InstallPluginProposalPlugin.md#0x1_InstallPluginProposalPlugin_execute_proposal_entry">execute_proposal_entry</a>&lt;DAOT: store, ToInstallPluginT: <b>copy</b> + drop + store&gt;(sender: signer, proposal_id: u64) {
<a href="InstallPluginProposalPlugin.md#0x1_InstallPluginProposalPlugin_execute_proposal">execute_proposal</a>&lt;DAOT, ToInstallPluginT&gt;(&sender, proposal_id);
}
</code></pre>
Expand Down
Binary file not shown.
30 changes: 20 additions & 10 deletions integration-tests/daospaceplugin/stake_to_sbt_plugin.exp
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,53 @@ task 6 'run'. lines 62-98:
"status": "Executed"
}

task 7 'run'. lines 100-117:
task 7 'run'. lines 100-110:
{
"gas_used": 62324,
"status": "Executed"
"gas_used": 38600,
"status": {
"MoveAbort": {
"location": {
"Module": {
"address": "0x00000000000000000000000000000001",
"name": "StakeToSBTPlugin"
}
},
"abort_code": "257025"
}
}
}

task 9 'run'. lines 121-139:
task 9 'run'. lines 114-127:
{
"gas_used": 313635,
"gas_used": 273200,
"status": "Executed"
}

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

task 12 'run'. lines 161-174:
task 12 'run'. lines 149-162:
{
"gas_used": 417670,
"status": "Executed"
}

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

task 15 'run'. lines 196-211:
task 15 'run'. lines 184-199:
{
"gas_used": 261857,
"status": "Executed"
}

task 16 'run'. lines 213-224:
task 16 'run'. lines 201-212:
{
"gas_used": 656139,
"status": {
Expand Down
20 changes: 4 additions & 16 deletions integration-tests/daospaceplugin/stake_to_sbt_plugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,12 @@ script {
use creator::XDAO;
use StarcoinFramework::StakeToSBTPlugin;
use StarcoinFramework::STC;
use StarcoinFramework::Account;
use StarcoinFramework::Signer;

fun unstake_all(sender: signer) {
let sender_addr = Signer::address_of(&sender);
let balance = Account::balance<STC::STC>(sender_addr);
fun unstake_all_failed(sender: signer) {
StakeToSBTPlugin::unstake_all<XDAO::X, STC::STC>(&sender);
let new_balance = Account::balance<STC::STC>(sender_addr);
assert!(balance == new_balance, 1001); // No item are available to unstake.
assert!(StakeToSBTPlugin::query_stake_count<XDAO::X, STC::STC>(sender_addr) == 1, 1002);
}
}
// check: EXECUTED
// check: ABORTED, 257025

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

Expand All @@ -124,16 +117,11 @@ script {
use StarcoinFramework::StakeToSBTPlugin;
use StarcoinFramework::STC;
use StarcoinFramework::Signer;
use StarcoinFramework::Account;
use StarcoinFramework::Token;

fun unstake_all(sender: signer) {
fun stake(sender: signer) {
let sender_addr = Signer::address_of(&sender);
let balance = Account::balance<STC::STC>(sender_addr);
StakeToSBTPlugin::unstake_all<XDAO::X, STC::STC>(&sender);
let new_balance = Account::balance<STC::STC>(sender_addr);
assert!(balance + 1 * Token::scaling_factor<STC::STC>() == new_balance, 1001);
assert!(StakeToSBTPlugin::query_stake_count<XDAO::X, STC::STC>(sender_addr) <= 0, 1002);
assert!(StakeToSBTPlugin::query_stake_count<XDAO::X, STC::STC>(sender_addr) <= 0, 10001);
}
}
// check: CHECKED
Expand Down
2 changes: 1 addition & 1 deletion sources/daospaceplugin/InstallPluginProposalPlugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module StarcoinFramework::InstallPluginProposalPlugin{
DAOSpace::install_plugin<DAOT, InstallPluginProposalPlugin, ToInstallPluginT>(&install_plugin_cap, required_caps);
}

public (script) fun execute_proposal_entry<DAOT: store, ToInstallPluginT: store>(sender: signer, proposal_id: u64) {
public (script) fun execute_proposal_entry<DAOT: store, ToInstallPluginT: copy + drop + store>(sender: signer, proposal_id: u64) {
execute_proposal<DAOT, ToInstallPluginT>(&sender, proposal_id);
}
}
23 changes: 6 additions & 17 deletions sources/daospaceplugin/StakeToSBTPlugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ module StarcoinFramework::StakeToSBTPlugin {
unstake_by_id<DAOT, TokenT>(&sender, id);
}

/// Unstake all expired items.
/// Unstake all staking items from sender,
/// No care whether the sender is member or not
public fun unstake_all<DAOT: store, TokenT: store>(sender: &signer) acquires StakeList {
let sender_addr = Signer::address_of(sender);
Expand All @@ -336,28 +336,17 @@ module StarcoinFramework::StakeToSBTPlugin {

let idx = 0;
while (idx < len) {
let item = Vector::borrow(&stake_list.items, idx);
if (can_item_unstake(item)) {
let item = Vector::remove(&mut stake_list.items, idx);
Account::deposit(sender_addr, unstake_item<DAOT, TokenT>(sender_addr, item));
len = len - 1;
} else {
idx = idx + 1;
};
let item = Vector::remove(&mut stake_list.items, idx);
Account::deposit(sender_addr, unstake_item<DAOT, TokenT>(sender_addr, item));
idx = idx + 1;
};
}

/// Unstake all expired items.
public(script) fun unstake_all_entry<DAOT: store, TokenT: store>(sender: signer) acquires StakeList {
unstake_all<DAOT, TokenT>(&sender);
}

/// Check if an item is available to unstake.
fun can_item_unstake<DAOT, TokenT>(item: &Stake<DAOT, TokenT>): bool {
Timestamp::now_seconds() - item.stake_time >= item.lock_time
}

/// Unstake an item from an item object
/// Unstake a item from a item object
fun unstake_item<DAOT: store, TokenT: store>(
member: address,
item: Stake<DAOT, TokenT>
Expand All @@ -371,7 +360,7 @@ module StarcoinFramework::StakeToSBTPlugin {
sbt_amount,
} = item;

assert!((Timestamp::now_seconds() - stake_time) >= lock_time, Errors::invalid_state(ERR_PLUGIN_STILL_LOCKED));
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<DAOT>(member)) {
Expand Down

0 comments on commit 04b5a07

Please sign in to comment.