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

migrate TreasuryWithdrawDaoProposal to DAOSpace TreasuryPlugin #175

Merged
merged 2 commits into from
Oct 10, 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/BlockReward.mv
Binary file not shown.
Binary file modified build/StarcoinFramework/bytecode_modules/StdlibUpgradeScripts.mv
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions build/StarcoinFramework/docs/BlockReward.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The module provide block rewarding calculation logic.
<b>use</b> <a href="Timestamp.md#0x1_Timestamp">0x1::Timestamp</a>;
<b>use</b> <a href="Token.md#0x1_Token">0x1::Token</a>;
<b>use</b> <a href="Treasury.md#0x1_Treasury">0x1::Treasury</a>;
<b>use</b> <a href="TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal">0x1::TreasuryWithdrawDaoProposal</a>;
<b>use</b> <a href="TreasuryPlugin.md#0x1_TreasuryPlugin">0x1::TreasuryPlugin</a>;
<b>use</b> <a href="Vector.md#0x1_Vector">0x1::Vector</a>;
</code></pre>

Expand Down Expand Up @@ -317,7 +317,7 @@ Process the given block rewards.
block_reward = treasury_balance;
};
<b>if</b> (block_reward &gt; 0) {
<b>let</b> reward = <a href="TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal_withdraw_for_block_reward">TreasuryWithdrawDaoProposal::withdraw_for_block_reward</a>&lt;<a href="STC.md#0x1_STC">STC</a>&gt;(account, block_reward);
<b>let</b> reward = <a href="TreasuryPlugin.md#0x1_TreasuryPlugin_withdraw_for_block_reward">TreasuryPlugin::withdraw_for_block_reward</a>&lt;<a href="STC.md#0x1_STC">STC</a>&gt;(account, block_reward);
<a href="Token.md#0x1_Token_deposit">Token::deposit</a>(&<b>mut</b> total_reward, reward);
};
};
Expand Down
1 change: 1 addition & 0 deletions build/StarcoinFramework/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ This is the root document for the Move StarcoinFramework module documentation. T
- [`0x1::TransactionTimeoutConfig`](TransactionTimeoutConfig.md#0x1_TransactionTimeoutConfig)
- [`0x1::TransferScripts`](TransferScripts.md#0x1_TransferScripts)
- [`0x1::Treasury`](Treasury.md#0x1_Treasury)
- [`0x1::TreasuryPlugin`](TreasuryPlugin.md#0x1_TreasuryPlugin)
- [`0x1::TreasuryScripts`](TreasuryScripts.md#0x1_TreasuryScripts)
- [`0x1::TreasuryWithdrawDaoProposal`](TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal)
- [`0x1::TypeInfo`](TypeInfo.md#0x1_TypeInfo)
Expand Down
6 changes: 6 additions & 0 deletions build/StarcoinFramework/docs/StdlibUpgradeScripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ The module for StdlibUpgrade init scripts
<b>use</b> <a href="Timestamp.md#0x1_Timestamp">0x1::Timestamp</a>;
<b>use</b> <a href="Token.md#0x1_Token">0x1::Token</a>;
<b>use</b> <a href="Treasury.md#0x1_Treasury">0x1::Treasury</a>;
<b>use</b> <a href="TreasuryPlugin.md#0x1_TreasuryPlugin">0x1::TreasuryPlugin</a>;
<b>use</b> <a href="TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal">0x1::TreasuryWithdrawDaoProposal</a>;
<b>use</b> <a href="UpgradeModulePlugin.md#0x1_UpgradeModulePlugin">0x1::UpgradeModulePlugin</a>;
</code></pre>
Expand Down Expand Up @@ -368,13 +369,18 @@ deprecated, use <code>do_upgrade_from_v6_to_v7_with_language_version</code>.
<a href="StakeToSBTPlugin.md#0x1_StakeToSBTPlugin_initialize">StakeToSBTPlugin::initialize</a>(&genessis_signer);
<a href="UpgradeModulePlugin.md#0x1_UpgradeModulePlugin_initialize">UpgradeModulePlugin::initialize</a>(&genessis_signer);
<a href="GasOracleProposalPlugin.md#0x1_GasOracleProposalPlugin_initialize">GasOracleProposalPlugin::initialize</a>(&genessis_signer);
<a href="TreasuryPlugin.md#0x1_TreasuryPlugin_initialize">TreasuryPlugin::initialize</a>(&genessis_signer);

//TODO : config rate need mind
// voting_delay: 60000 ms
// voting_period: 3600000 ms
// voting_quorum_rate: 4
// min_action_delay: 3600000 ms
<a href="StarcoinDAO.md#0x1_StarcoinDAO_create_dao">StarcoinDAO::create_dao</a>( <a href="Dao.md#0x1_Dao_voting_delay">Dao::voting_delay</a>&lt;<a href="STC.md#0x1_STC">STC</a>&gt;(), <a href="Dao.md#0x1_Dao_voting_period">Dao::voting_period</a>&lt;<a href="STC.md#0x1_STC">STC</a>&gt;(), <a href="Dao.md#0x1_Dao_voting_quorum_rate">Dao::voting_quorum_rate</a>&lt;<a href="STC.md#0x1_STC">STC</a>&gt;(), <a href="Dao.md#0x1_Dao_min_action_delay">Dao::min_action_delay</a>&lt;<a href="STC.md#0x1_STC">STC</a>&gt;(), 1000 * 1000 * 1000 * 1000);

<b>let</b> signer = <a href="GenesisSignerCapability.md#0x1_GenesisSignerCapability_get_genesis_signer">GenesisSignerCapability::get_genesis_signer</a>();
<b>let</b> cap = <a href="TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal_takeout_withdraw_capability">TreasuryWithdrawDaoProposal::takeout_withdraw_capability</a>&lt;<a href="STC.md#0x1_STC">STC</a>&gt;(&signer);
<a href="TreasuryPlugin.md#0x1_TreasuryPlugin_delegate_capability">TreasuryPlugin::delegate_capability</a>&lt;<a href="STC.md#0x1_STC">STC</a>&gt;(&signer, cap);
}
</code></pre>

Expand Down
47 changes: 44 additions & 3 deletions build/StarcoinFramework/docs/TreasuryWithdrawDaoProposal.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ TreasuryWithdrawDaoProposal is a dao proposal for withdraw Token from Treasury.
- [Struct `WithdrawToken`](#0x1_TreasuryWithdrawDaoProposal_WithdrawToken)
- [Constants](#@Constants_0)
- [Function `plugin`](#0x1_TreasuryWithdrawDaoProposal_plugin)
- [Function `takeout_withdraw_capability`](#0x1_TreasuryWithdrawDaoProposal_takeout_withdraw_capability)
- [Function `propose_withdraw`](#0x1_TreasuryWithdrawDaoProposal_propose_withdraw)
- [Function `execute_withdraw_proposal`](#0x1_TreasuryWithdrawDaoProposal_execute_withdraw_proposal)
- [Function `withdraw_for_block_reward`](#0x1_TreasuryWithdrawDaoProposal_withdraw_for_block_reward)
Expand Down Expand Up @@ -108,12 +109,11 @@ WithdrawToken request.



<a name="0x1_TreasuryWithdrawDaoProposal_ERR_NEED_RECEIVER_TO_EXECUTE"></a>
<a name="0x1_TreasuryWithdrawDaoProposal_ERR_CAPABILITY_NOT_EXIST"></a>

Only receiver can execute TreasuryWithdrawDaoProposal


<pre><code><b>const</b> <a href="TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal_ERR_NEED_RECEIVER_TO_EXECUTE">ERR_NEED_RECEIVER_TO_EXECUTE</a>: u64 = 102;
<pre><code><b>const</b> <a href="TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal_ERR_CAPABILITY_NOT_EXIST">ERR_CAPABILITY_NOT_EXIST</a>: u64 = 104;
</code></pre>


Expand All @@ -128,6 +128,16 @@ The withdraw amount of propose is too many.



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

Only receiver can execute TreasuryWithdrawDaoProposal


<pre><code><b>const</b> <a href="TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal_ERR_NEED_RECEIVER_TO_EXECUTE">ERR_NEED_RECEIVER_TO_EXECUTE</a>: u64 = 102;
</code></pre>



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

## Function `plugin`
Expand Down Expand Up @@ -172,6 +182,37 @@ Should be called by token issuer.



</details>

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

## Function `takeout_withdraw_capability`

withdraw Treasury::WithdrawCapability


<pre><code><b>public</b> <b>fun</b> <a href="TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal_takeout_withdraw_capability">takeout_withdraw_capability</a>&lt;TokenT: store&gt;(sender: &signer): <a href="Treasury.md#0x1_Treasury_WithdrawCapability">Treasury::WithdrawCapability</a>&lt;TokenT&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal_takeout_withdraw_capability">takeout_withdraw_capability</a>&lt;TokenT: store&gt;(sender: &signer): <a href="Treasury.md#0x1_Treasury_WithdrawCapability">Treasury::WithdrawCapability</a>&lt;TokenT&gt;
<b>acquires</b> <a href="TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal_WrappedWithdrawCapability">WrappedWithdrawCapability</a> {
<b>let</b> token_issuer = <a href="Token.md#0x1_Token_token_address">Token::token_address</a>&lt;TokenT&gt;();
<b>assert</b>!(<a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(sender) == token_issuer, <a href="Errors.md#0x1_Errors_requires_address">Errors::requires_address</a>(<a href="TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal_ERR_NOT_AUTHORIZED">ERR_NOT_AUTHORIZED</a>));

<b>assert</b>!(<b>exists</b>&lt;<a href="TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal_WrappedWithdrawCapability">WrappedWithdrawCapability</a>&lt;TokenT&gt;&gt;(<a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(sender)), <a href="Errors.md#0x1_Errors_not_published">Errors::not_published</a>(<a href="TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal_ERR_CAPABILITY_NOT_EXIST">ERR_CAPABILITY_NOT_EXIST</a>));
<b>let</b> <a href="TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal_WrappedWithdrawCapability">WrappedWithdrawCapability</a>&lt;TokenT&gt; { cap } = <b>move_from</b>&lt;<a href="TreasuryWithdrawDaoProposal.md#0x1_TreasuryWithdrawDaoProposal_WrappedWithdrawCapability">WrappedWithdrawCapability</a>&lt;TokenT&gt;&gt;(<a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(sender));
cap
}
</code></pre>



</details>

<a name="0x1_TreasuryWithdrawDaoProposal_propose_withdraw"></a>
Expand Down
Binary file modified build/StarcoinFramework/source_maps/BlockReward.mvsm
Binary file not shown.
Binary file modified build/StarcoinFramework/source_maps/StdlibUpgradeScripts.mvsm
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ task 8 'run'. lines 66-74:

task 9 'view'. lines 76-76:
store key 0x00000000000000000000000000000001::DAOPluginMarketplace::PluginEntry<0x662ba5a1a1da0f1c70a9762c7eeb7aaf::TestPlugin::TestPlugin> {
id: 10
id: 11
name: 54657374506c7567696e
description: 697066733a2f2f6465736372697074696f6e
labels: [
Expand Down Expand Up @@ -63,7 +63,7 @@ task 10 'run'. lines 78-91:

task 11 'view'. lines 93-93:
store key 0x00000000000000000000000000000001::DAOPluginMarketplace::PluginEntry<0x662ba5a1a1da0f1c70a9762c7eeb7aaf::TestPlugin::TestPlugin> {
id: 10
id: 11
name: 54657374506c7567696e
description: 697066733a2f2f6465736372697074696f6e
labels: [
Expand Down Expand Up @@ -154,7 +154,7 @@ task 12 'run'. lines 95-103:

task 13 'view'. lines 105-105:
store key 0x00000000000000000000000000000001::DAOPluginMarketplace::PluginEntry<0x662ba5a1a1da0f1c70a9762c7eeb7aaf::TestPlugin::TestPlugin> {
id: 10
id: 11
name: 54657374506c7567696e
description: 697066733a2f2f6465736372697074696f6e
labels: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ task 10 'run'. lines 87-95:

task 11 'view'. lines 97-97:
store key 0x00000000000000000000000000000001::DAOPluginMarketplace::PluginEntry<0x662ba5a1a1da0f1c70a9762c7eeb7aaf::TestPlugin2::TestPlugin2> {
id: 11
id: 12
name: 54657374506c7567696e32
description: 697066733a2f2f6465736372697074696f6e
labels: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ task 9 'run'. lines 82-93:

task 10 'view'. lines 95-95:
store key 0x00000000000000000000000000000001::DAOPluginMarketplace::PluginEntry<0x662ba5a1a1da0f1c70a9762c7eeb7aaf::TestPlugin::TestPlugin> {
id: 10
id: 11
name: 54657374506c7567696e
description: 697066733a2f2f6465736372697074696f6e
labels: [
Expand All @@ -57,7 +57,7 @@ task 11 'run'. lines 98-109:

task 12 'view'. lines 111-111:
store key 0x00000000000000000000000000000001::DAOPluginMarketplace::PluginEntry<0x662ba5a1a1da0f1c70a9762c7eeb7aaf::TestPlugin::TestPlugin> {
id: 10
id: 11
name: 54657374506c7567696e
description: 697066733a2f2f6465736372697074696f6e
labels: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ task 6 'run'. lines 46-54:

task 7 'view'. lines 56-56:
store key 0x00000000000000000000000000000001::DAOPluginMarketplace::PluginEntry<0x662ba5a1a1da0f1c70a9762c7eeb7aaf::TestPlugin::TestPlugin> {
id: 10
id: 11
name: 54657374506c7567696e
description: 697066733a2f2f6465736372697074696f6e
labels: [
Expand Down Expand Up @@ -45,7 +45,7 @@ task 9 'run'. lines 68-76:

task 10 'view'. lines 78-78:
store key 0x00000000000000000000000000000001::DAOPluginMarketplace::PluginEntry<0x662ba5a1a1da0f1c70a9762c7eeb7aaf::TestPlugin::TestPlugin> {
id: 10
id: 11
name: 54657374506c7567696e
description: 697066733a2f2f6465736372697074696f6e32
labels: [
Expand Down
4 changes: 2 additions & 2 deletions sources/BlockReward.move
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module BlockReward {
use StarcoinFramework::Config;
use StarcoinFramework::Event;
use StarcoinFramework::Treasury;
use StarcoinFramework::TreasuryWithdrawDaoProposal;
use StarcoinFramework::TreasuryPlugin;

spec module {
pragma verify = false;
Expand Down Expand Up @@ -122,7 +122,7 @@ module BlockReward {
block_reward = treasury_balance;
};
if (block_reward > 0) {
let reward = TreasuryWithdrawDaoProposal::withdraw_for_block_reward<STC>(account, block_reward);
let reward = TreasuryPlugin::withdraw_for_block_reward<STC>(account, block_reward);
Token::deposit(&mut total_reward, reward);
};
};
Expand Down
2 changes: 2 additions & 0 deletions sources/StarcoinDAO.move
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module StarcoinFramework::StarcoinDAO{
use StarcoinFramework::TransactionTimeoutConfig;
use StarcoinFramework::GasOracleProposalPlugin::GasOracleProposalPlugin;
use StarcoinFramework::GasOracleProposalPlugin;
use StarcoinFramework::TreasuryPlugin::{Self, TreasuryPlugin};

friend StarcoinFramework::Genesis;
friend StarcoinFramework::StdlibUpgradeScripts;
Expand Down Expand Up @@ -59,6 +60,7 @@ module StarcoinFramework::StarcoinDAO{
DAOSpace::install_plugin_with_root_cap<StarcoinDAO, ConfigProposalPlugin>(&dao_root_cap, ConfigProposalPlugin::required_caps());
DAOSpace::install_plugin_with_root_cap<StarcoinDAO, StakeToSBTPlugin>(&dao_root_cap, StakeToSBTPlugin::required_caps());
DAOSpace::install_plugin_with_root_cap<StarcoinDAO, GasOracleProposalPlugin>(&dao_root_cap, GasOracleProposalPlugin::required_caps());
DAOSpace::install_plugin_with_root_cap<StarcoinDAO, TreasuryPlugin>(&dao_root_cap, TreasuryPlugin::required_caps());

StakeToSBTPlugin::accept_token_with_root_cap<StarcoinDAO, STC>(&dao_root_cap);
StakeToSBTPlugin::set_sbt_weight_with_root_cap<StarcoinDAO, STC>(&dao_root_cap, 60000, 1000);
Expand Down
8 changes: 7 additions & 1 deletion sources/StdlibUpgradeScripts.move
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ module StdlibUpgradeScripts {
use StarcoinFramework::StarcoinDAO;
use StarcoinFramework::GasOracleProposalPlugin;
use StarcoinFramework::Dao;

use StarcoinFramework::TreasuryPlugin;

spec module {
pragma verify = false;
pragma aborts_if_is_strict = true;
Expand Down Expand Up @@ -136,13 +137,18 @@ module StdlibUpgradeScripts {
StakeToSBTPlugin::initialize(&genessis_signer);
UpgradeModulePlugin::initialize(&genessis_signer);
GasOracleProposalPlugin::initialize(&genessis_signer);
TreasuryPlugin::initialize(&genessis_signer);

//TODO : config rate need mind
// voting_delay: 60000 ms
// voting_period: 3600000 ms
// voting_quorum_rate: 4
// min_action_delay: 3600000 ms
StarcoinDAO::create_dao( Dao::voting_delay<STC>(), Dao::voting_period<STC>(), Dao::voting_quorum_rate<STC>(), Dao::min_action_delay<STC>(), 1000 * 1000 * 1000 * 1000);

let signer = GenesisSignerCapability::get_genesis_signer();
let cap = TreasuryWithdrawDaoProposal::takeout_withdraw_capability<STC>(&signer);
TreasuryPlugin::delegate_capability<STC>(&signer, cap);
}
}
}
12 changes: 12 additions & 0 deletions sources/TreasuryWithdrawDaoProposal.move
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module TreasuryWithdrawDaoProposal {
const ERR_NEED_RECEIVER_TO_EXECUTE: u64 = 102;
/// The withdraw amount of propose is too many.
const ERR_TOO_MANY_WITHDRAW_AMOUNT: u64 = 103;
const ERR_CAPABILITY_NOT_EXIST: u64 = 104;

/// Plugin method of the module.
/// Should be called by token issuer.
Expand All @@ -43,6 +44,17 @@ module TreasuryWithdrawDaoProposal {
move_to(signer, WrappedWithdrawCapability<TokenT> { cap: cap });
}

/// withdraw Treasury::WithdrawCapability
public fun takeout_withdraw_capability<TokenT: store>(sender: &signer): Treasury::WithdrawCapability<TokenT>
acquires WrappedWithdrawCapability {
let token_issuer = Token::token_address<TokenT>();
assert!(Signer::address_of(sender) == token_issuer, Errors::requires_address(ERR_NOT_AUTHORIZED));

assert!(exists<WrappedWithdrawCapability<TokenT>>(Signer::address_of(sender)), Errors::not_published(ERR_CAPABILITY_NOT_EXIST));
let WrappedWithdrawCapability<TokenT> { cap } = move_from<WrappedWithdrawCapability<TokenT>>(Signer::address_of(sender));
cap
}

spec plugin {
pragma aborts_if_is_partial = false;
let sender = Signer::address_of(signer);
Expand Down
Loading