Module sui::token
The Token module which implements a Closed Loop Token with a configurable policy. The policy is defined by a set of rules that must be satisfied for an action to be performed on the token.
The module is designed to be used with a TreasuryCap to allow for minting and burning of the Tokens. And can act as a replacement / extension or a companion to existing open-loop (Coin) systems.
Module: sui::balance sui::coin sui::token
Main type: Balance<T> Coin<T> Token<T>
Capability: Supply<T> <----> TreasuryCap<T> <----> TreasuryCap<T>
Abilities: store key + store key
```move
The Token system allows for fine-grained control over the actions performed
on the token. And hence it is highly suitable for applications that require
control over the currency which a simple open-loop system can't provide.
- [Struct `Token`](#sui_token_Token)
- [Struct `TokenPolicyCap`](#sui_token_TokenPolicyCap)
- [Struct `TokenPolicy`](#sui_token_TokenPolicy)
- [Struct `ActionRequest`](#sui_token_ActionRequest)
- [Struct `RuleKey`](#sui_token_RuleKey)
- [Struct `TokenPolicyCreated`](#sui_token_TokenPolicyCreated)
- [Constants](#@Constants_0)
- [Function `new_policy`](#sui_token_new_policy)
- [Function `share_policy`](#sui_token_share_policy)
- [Function `transfer`](#sui_token_transfer)
- [Function `spend`](#sui_token_spend)
- [Function `to_coin`](#sui_token_to_coin)
- [Function `from_coin`](#sui_token_from_coin)
- [Function `join`](#sui_token_join)
- [Function `split`](#sui_token_split)
- [Function `zero`](#sui_token_zero)
- [Function `destroy_zero`](#sui_token_destroy_zero)
- [Function `keep`](#sui_token_keep)
- [Function `new_request`](#sui_token_new_request)
- [Function `confirm_request`](#sui_token_confirm_request)
- [Function `confirm_request_mut`](#sui_token_confirm_request_mut)
- [Function `confirm_with_policy_cap`](#sui_token_confirm_with_policy_cap)
- [Function `confirm_with_treasury_cap`](#sui_token_confirm_with_treasury_cap)
- [Function `add_approval`](#sui_token_add_approval)
- [Function `add_rule_config`](#sui_token_add_rule_config)
- [Function `rule_config`](#sui_token_rule_config)
- [Function `rule_config_mut`](#sui_token_rule_config_mut)
- [Function `remove_rule_config`](#sui_token_remove_rule_config)
- [Function `has_rule_config`](#sui_token_has_rule_config)
- [Function `has_rule_config_with_type`](#sui_token_has_rule_config_with_type)
- [Function `allow`](#sui_token_allow)
- [Function `disallow`](#sui_token_disallow)
- [Function `add_rule_for_action`](#sui_token_add_rule_for_action)
- [Function `remove_rule_for_action`](#sui_token_remove_rule_for_action)
- [Function `mint`](#sui_token_mint)
- [Function `burn`](#sui_token_burn)
- [Function `flush`](#sui_token_flush)
- [Function `is_allowed`](#sui_token_is_allowed)
- [Function `rules`](#sui_token_rules)
- [Function `spent_balance`](#sui_token_spent_balance)
- [Function `value`](#sui_token_value)
- [Function `transfer_action`](#sui_token_transfer_action)
- [Function `spend_action`](#sui_token_spend_action)
- [Function `to_coin_action`](#sui_token_to_coin_action)
- [Function `from_coin_action`](#sui_token_from_coin_action)
- [Function `action`](#sui_token_action)
- [Function `amount`](#sui_token_amount)
- [Function `sender`](#sui_token_sender)
- [Function `recipient`](#sui_token_recipient)
- [Function `approvals`](#sui_token_approvals)
- [Function `spent`](#sui_token_spent)
- [Function `key`](#sui_token_key)
<pre><code><b>use</b> <a href="../std/address#std_address">std::address</a>;
<b>use</b> <a href="../std/ascii#std_ascii">std::ascii</a>;
<b>use</b> <a href="../std/bcs#std_bcs">std::bcs</a>;
<b>use</b> <a href="../std/option#std_option">std::option</a>;
<b>use</b> <a href="../std/string#std_string">std::string</a>;
<b>use</b> <a href="../std/type_name#std_type_name">std::type_name</a>;
<b>use</b> <a href="../std/vector#std_vector">std::vector</a>;
<b>use</b> <a href="../sui/accumulator#sui_accumulator">sui::accumulator</a>;
<b>use</b> <a href="../sui/address#sui_address">sui::address</a>;
<b>use</b> <a href="../sui/bag#sui_bag">sui::bag</a>;
<b>use</b> <a href="../sui/balance#sui_balance">sui::balance</a>;
<b>use</b> <a href="../sui/coin#sui_coin">sui::coin</a>;
<b>use</b> <a href="../sui/config#sui_config">sui::config</a>;
<b>use</b> <a href="../sui/deny_list#sui_deny_list">sui::deny_list</a>;
<b>use</b> <a href="../sui/dynamic_field#sui_dynamic_field">sui::dynamic_field</a>;
<b>use</b> <a href="../sui/dynamic_object_field#sui_dynamic_object_field">sui::dynamic_object_field</a>;
<b>use</b> <a href="../sui/event#sui_event">sui::event</a>;
<b>use</b> <a href="../sui/hex#sui_hex">sui::hex</a>;
<b>use</b> <a href="../sui/object#sui_object">sui::object</a>;
<b>use</b> <a href="../sui/party#sui_party">sui::party</a>;
<b>use</b> <a href="../sui/table#sui_table">sui::table</a>;
<b>use</b> <a href="../sui/transfer#sui_transfer">sui::transfer</a>;
<b>use</b> <a href="../sui/tx_context#sui_tx_context">sui::tx_context</a>;
<b>use</b> <a href="../sui/types#sui_types">sui::types</a>;
<b>use</b> <a href="../sui/url#sui_url">sui::url</a>;
<b>use</b> <a href="../sui/vec_map#sui_vec_map">sui::vec_map</a>;
<b>use</b> <a href="../sui/vec_set#sui_vec_set">sui::vec_set</a>;
</code></pre>
## Struct `Token` \{#sui_token_Token}
A single <a href="../sui/token#sui_token_Token">Token</a> with Balance inside. Can only be owned by an address,
and actions performed on it must be confirmed in a matching <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.
<pre><code><b>public</b> <b>struct</b> <a href="../sui/token#sui_token_Token">Token</a><<b>phantom</b> T> <b>has</b> <a href="../sui/token#sui_token_key">key</a>
</code></pre>
<details>
<summary>Fields</summary>
<dl>
<dt>
id: <a href="../sui/object#sui_object_UID">sui::object::UID</a>
</dt>
<dd>
</dd>
<dt>
<a href="../sui/balance#sui_balance">balance</a>: <a href="../sui/balance#sui_balance_Balance">sui::balance::Balance</a><T>
</dt>
<dd>
The Balance of the <a href="../sui/token#sui_token_Token">Token</a>.
</dd>
</dl>
</details>
## Struct `TokenPolicyCap` \{#sui_token_TokenPolicyCap}
A Capability that manages a single <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> specified in the <b>for</b>
field. Created together with <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> in the new function.
<pre><code><b>public</b> <b>struct</b> <a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a><<b>phantom</b> T> <b>has</b> <a href="../sui/token#sui_token_key">key</a>, store
</code></pre>
<details>
<summary>Fields</summary>
<dl>
<dt>
id: <a href="../sui/object#sui_object_UID">sui::object::UID</a>
</dt>
<dd>
</dd>
<dt>
<b>for</b>: <a href="../sui/object#sui_object_ID">sui::object::ID</a>
</dt>
<dd>
</dd>
</dl>
</details>
## Struct `TokenPolicy` \{#sui_token_TokenPolicy}
<a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> represents a set of rules that define what actions can be
performed on a <a href="../sui/token#sui_token_Token">Token</a> and which Rules must be satisfied for the
action to succeed.
- For the sake of availability, <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> is a <a href="../sui/token#sui_token_key">key</a>-only object.
- Each <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> is managed by a matching <a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a>.
- For an action to become available, there needs to be a record in the
<a href="../sui/token#sui_token_rules">rules</a> VecMap. To allow an action to be performed freely, there's an
<a href="../sui/token#sui_token_allow">allow</a> function that can be called by the <a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a> owner.
<pre><code><b>public</b> <b>struct</b> <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><<b>phantom</b> T> <b>has</b> <a href="../sui/token#sui_token_key">key</a>
</code></pre>
<details>
<summary>Fields</summary>
<dl>
<dt>
id: <a href="../sui/object#sui_object_UID">sui::object::UID</a>
</dt>
<dd>
</dd>
<dt>
<a href="../sui/token#sui_token_spent_balance">spent_balance</a>: <a href="../sui/balance#sui_balance_Balance">sui::balance::Balance</a><T>
</dt>
<dd>
The balance that is effectively spent by the user on the "spend"
action. However, actual decrease of the supply can only be done by
the TreasuryCap owner when <a href="../sui/token#sui_token_flush">flush</a> is called.
This balance is effectively spent and cannot be accessed by anyone
but the TreasuryCap owner.
</dd>
<dt>
<a href="../sui/token#sui_token_rules">rules</a>: <a href="../sui/vec_map#sui_vec_map_VecMap">sui::vec_map::VecMap</a><<a href="../std/string#std_string_String">std::string::String</a>, <a href="../sui/vec_set#sui_vec_set_VecSet">sui::vec_set::VecSet</a><<a href="../std/type_name#std_type_name_TypeName">std::type_name::TypeName</a>>>
</dt>
<dd>
The set of rules that define what actions can be performed on the
token. For each "action" there's a set of Rules that must be
satisfied for the <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a> to be confirmed.
</dd>
</dl>
</details>
## Struct `ActionRequest` \{#sui_token_ActionRequest}
A request to perform an "Action" on a token. Stores the information
about the action to be performed and must be consumed by the <a href="../sui/token#sui_token_confirm_request">confirm_request</a>
or <a href="../sui/token#sui_token_confirm_request_mut">confirm_request_mut</a> functions when the Rules are satisfied.
<pre><code><b>public</b> <b>struct</b> <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><<b>phantom</b> T>
</code></pre>
<details>
<summary>Fields</summary>
<dl>
<dt>
name: <a href="../std/string#std_string_String">std::string::String</a>
</dt>
<dd>
Name of the Action to look up in the Policy. Name can be one of the
default actions: <a href="../sui/transfer#sui_transfer">transfer</a>, <a href="../sui/token#sui_token_spend">spend</a>, <a href="../sui/token#sui_token_to_coin">to_coin</a>, <a href="../sui/token#sui_token_from_coin">from_coin</a> or a
custom action.
</dd>
<dt>
<a href="../sui/token#sui_token_amount">amount</a>: u64
</dt>
<dd>
Amount is present in all of the txs
</dd>
<dt>
<a href="../sui/token#sui_token_sender">sender</a>: <b>address</b>
</dt>
<dd>
Sender is a permanent field always
</dd>
<dt>
<a href="../sui/token#sui_token_recipient">recipient</a>: <a href="../std/option#std_option_Option">std::option::Option</a><<b>address</b>>
</dt>
<dd>
Recipient is only available in <a href="../sui/transfer#sui_transfer">transfer</a> action.
</dd>
<dt>
<a href="../sui/token#sui_token_spent_balance">spent_balance</a>: <a href="../std/option#std_option_Option">std::option::Option</a><<a href="../sui/balance#sui_balance_Balance">sui::balance::Balance</a><T>>
</dt>
<dd>
The balance to be "spent" in the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>, only available
in the <a href="../sui/token#sui_token_spend">spend</a> action.
</dd>
<dt>
<a href="../sui/token#sui_token_approvals">approvals</a>: <a href="../sui/vec_set#sui_vec_set_VecSet">sui::vec_set::VecSet</a><<a href="../std/type_name#std_type_name_TypeName">std::type_name::TypeName</a>>
</dt>
<dd>
Collected approvals (stamps) from completed Rules. They're matched
against <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.<a href="../sui/token#sui_token_rules">rules</a> to determine if the request can be
confirmed.
</dd>
</dl>
</details>
## Struct `RuleKey` \{#sui_token_RuleKey}
Dynamic field key for the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> to store the Config for a
specific action Rule. There can be only one configuration per
Rule per <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.
<pre><code><b>public</b> <b>struct</b> <a href="../sui/token#sui_token_RuleKey">RuleKey</a><<b>phantom</b> T> <b>has</b> <b>copy</b>, drop, store
</code></pre>
<details>
<summary>Fields</summary>
<dl>
<dt>
is_protected: bool
</dt>
<dd>
</dd>
</dl>
</details>
## Struct `TokenPolicyCreated` \{#sui_token_TokenPolicyCreated}
An event emitted when a <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> is created and shared. Because
<a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> can only be shared (and potentially frozen in the future),
we emit this event in the <a href="../sui/token#sui_token_share_policy">share_policy</a> function and mark it as mutable.
<pre><code><b>public</b> <b>struct</b> <a href="../sui/token#sui_token_TokenPolicyCreated">TokenPolicyCreated</a><<b>phantom</b> T> <b>has</b> <b>copy</b>, drop
</code></pre>
<details>
<summary>Fields</summary>
<dl>
<dt>
id: <a href="../sui/object#sui_object_ID">sui::object::ID</a>
</dt>
<dd>
ID of the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> that was created.
</dd>
<dt>
is_mutable: bool
</dt>
<dd>
Whether the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> is "shared" (mutable) or "frozen"
(immutable) - TBD.
</dd>
</dl>
</details>
<a style='scroll-margin-top:80px' id="@Constants_0"></a>
## Constants
<a style='scroll-margin-top:80px' id="sui_token_EUnknownAction"></a>
The action is not allowed (defined) in the policy.
<pre><code><b>const</b> <a href="../sui/token#sui_token_EUnknownAction">EUnknownAction</a>: u64 = 0;
</code></pre>
<a style='scroll-margin-top:80px' id="sui_token_ENotApproved"></a>
The rule was not approved.
<pre><code><b>const</b> <a href="../sui/token#sui_token_ENotApproved">ENotApproved</a>: u64 = 1;
</code></pre>
<a style='scroll-margin-top:80px' id="sui_token_ENotAuthorized"></a>
Trying to perform an admin action with a wrong cap.
<pre><code><b>const</b> <a href="../sui/token#sui_token_ENotAuthorized">ENotAuthorized</a>: u64 = 2;
</code></pre>
<a style='scroll-margin-top:80px' id="sui_token_EBalanceTooLow"></a>
The balance is too low to perform the action.
<pre><code><b>const</b> <a href="../sui/token#sui_token_EBalanceTooLow">EBalanceTooLow</a>: u64 = 3;
</code></pre>
<a style='scroll-margin-top:80px' id="sui_token_ENotZero"></a>
The balance is not zero.
<pre><code><b>const</b> <a href="../sui/token#sui_token_ENotZero">ENotZero</a>: u64 = 4;
</code></pre>
<a style='scroll-margin-top:80px' id="sui_token_ECantConsumeBalance"></a>
The balance is not zero when trying to confirm with TransferPolicyCap.
<pre><code><b>const</b> <a href="../sui/token#sui_token_ECantConsumeBalance">ECantConsumeBalance</a>: u64 = 5;
</code></pre>
<a style='scroll-margin-top:80px' id="sui_token_ENoConfig"></a>
Rule is trying to access a missing config (with type).
<pre><code><b>const</b> <a href="../sui/token#sui_token_ENoConfig">ENoConfig</a>: u64 = 6;
</code></pre>
<a style='scroll-margin-top:80px' id="sui_token_EUseImmutableConfirm"></a>
Using <a href="../sui/token#sui_token_confirm_request_mut">confirm_request_mut</a> without <a href="../sui/token#sui_token_spent_balance">spent_balance</a>. Immutable version
of the function must be used instead.
<pre><code><b>const</b> <a href="../sui/token#sui_token_EUseImmutableConfirm">EUseImmutableConfirm</a>: u64 = 7;
</code></pre>
<a style='scroll-margin-top:80px' id="sui_token_SPEND"></a>
A Tag for the <a href="../sui/token#sui_token_spend">spend</a> action.
<pre><code><b>const</b> <a href="../sui/token#sui_token_SPEND">SPEND</a>: vector<u8> = vector[115, 112, 101, 110, 100];
</code></pre>
<a style='scroll-margin-top:80px' id="sui_token_TRANSFER"></a>
A Tag for the <a href="../sui/transfer#sui_transfer">transfer</a> action.
<pre><code><b>const</b> <a href="../sui/token#sui_token_TRANSFER">TRANSFER</a>: vector<u8> = vector[116, 114, 97, 110, 115, 102, 101, 114];
</code></pre>
<a style='scroll-margin-top:80px' id="sui_token_TO_COIN"></a>
A Tag for the <a href="../sui/token#sui_token_to_coin">to_coin</a> action.
<pre><code><b>const</b> <a href="../sui/token#sui_token_TO_COIN">TO_COIN</a>: vector<u8> = vector[116, 111, 95, 99, 111, 105, 110];
</code></pre>
<a style='scroll-margin-top:80px' id="sui_token_FROM_COIN"></a>
A Tag for the <a href="../sui/token#sui_token_from_coin">from_coin</a> action.
<pre><code><b>const</b> <a href="../sui/token#sui_token_FROM_COIN">FROM_COIN</a>: vector<u8> = vector[102, 114, 111, 109, 95, 99, 111, 105, 110];
</code></pre>
## Function `new_policy` \{#sui_token_new_policy}
Create a new <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> and a matching <a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a>.
The <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> must then be shared using the <a href="../sui/token#sui_token_share_policy">share_policy</a> method.
TreasuryCap guarantees full ownership over the currency, and is unique,
hence it is safe to use it for authorization.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_new_policy">new_policy</a><T>(_treasury_cap: &<a href="../sui/coin#sui_coin_TreasuryCap">sui::coin::TreasuryCap</a><T>, ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): (<a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>, <a href="../sui/token#sui_token_TokenPolicyCap">sui::token::TokenPolicyCap</a><T>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_new_policy">new_policy</a><T>(
_treasury_cap: &TreasuryCap<T>,
ctx: &<b>mut</b> TxContext,
): (<a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>, <a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a><T>) {
<b>let</b> policy = <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> {
id: <a href="../sui/object#sui_object_new">object::new</a>(ctx),
<a href="../sui/token#sui_token_spent_balance">spent_balance</a>: <a href="../sui/balance#sui_balance_zero">balance::zero</a>(),
<a href="../sui/token#sui_token_rules">rules</a>: <a href="../sui/vec_map#sui_vec_map_empty">vec_map::empty</a>(),
};
<b>let</b> cap = <a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a> {
id: <a href="../sui/object#sui_object_new">object::new</a>(ctx),
`<b>for</b>`: <a href="../sui/object#sui_object_id">object::id</a>(&policy),
};
(policy, cap)
}
</code></pre>
</details>
## Function `share_policy` \{#sui_token_share_policy}
Share the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>. Due to <a href="../sui/token#sui_token_key">key</a>-only restriction, it must be
shared after initialization.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_share_policy">share_policy</a><T>(policy: <a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_share_policy">share_policy</a><T>(policy: <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>) {
<a href="../sui/event#sui_event_emit">event::emit</a>(<a href="../sui/token#sui_token_TokenPolicyCreated">TokenPolicyCreated</a><T> {
id: <a href="../sui/object#sui_object_id">object::id</a>(&policy),
is_mutable: <b>true</b>,
});
<a href="../sui/transfer#sui_transfer_share_object">transfer::share_object</a>(policy)
}
</code></pre>
</details>
## Function `transfer` \{#sui_token_transfer}
Transfer a <a href="../sui/token#sui_token_Token">Token</a> to a <a href="../sui/token#sui_token_recipient">recipient</a>. Creates an <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a> for the
"transfer" action. The <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a> contains the <a href="../sui/token#sui_token_recipient">recipient</a> field
to be used in verification.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/transfer#sui_transfer">transfer</a><T>(t: <a href="../sui/token#sui_token_Token">sui::token::Token</a><T>, <a href="../sui/token#sui_token_recipient">recipient</a>: <b>address</b>, ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): <a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/transfer#sui_transfer">transfer</a><T>(t: <a href="../sui/token#sui_token_Token">Token</a><T>, <a href="../sui/token#sui_token_recipient">recipient</a>: <b>address</b>, ctx: &<b>mut</b> TxContext): <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T> {
<b>let</b> <a href="../sui/token#sui_token_amount">amount</a> = t.<a href="../sui/balance#sui_balance">balance</a>.<a href="../sui/token#sui_token_value">value</a>();
<a href="../sui/transfer#sui_transfer_transfer">transfer::transfer</a>(t, <a href="../sui/token#sui_token_recipient">recipient</a>);
<a href="../sui/token#sui_token_new_request">new_request</a>(
<a href="../sui/token#sui_token_transfer_action">transfer_action</a>(),
<a href="../sui/token#sui_token_amount">amount</a>,
option::some(<a href="../sui/token#sui_token_recipient">recipient</a>),
option::none(),
ctx,
)
}
</code></pre>
</details>
## Function `spend` \{#sui_token_spend}
Spend a <a href="../sui/token#sui_token_Token">Token</a> by unwrapping it and storing the Balance in the
<a href="../sui/token#sui_token_ActionRequest">ActionRequest</a> for the "spend" action. The <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a> contains
the <a href="../sui/token#sui_token_spent_balance">spent_balance</a> field to be used in verification.
Spend action requires <a href="../sui/token#sui_token_confirm_request_mut">confirm_request_mut</a> to be called to confirm the
request and join the spent balance with the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_spend">spend</a><T>(t: <a href="../sui/token#sui_token_Token">sui::token::Token</a><T>, ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): <a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_spend">spend</a><T>(t: <a href="../sui/token#sui_token_Token">Token</a><T>, ctx: &<b>mut</b> TxContext): <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T> {
<b>let</b> <a href="../sui/token#sui_token_Token">Token</a> { id, <a href="../sui/balance#sui_balance">balance</a> } = t;
id.delete();
<a href="../sui/token#sui_token_new_request">new_request</a>(
<a href="../sui/token#sui_token_spend_action">spend_action</a>(),
<a href="../sui/balance#sui_balance">balance</a>.<a href="../sui/token#sui_token_value">value</a>(),
option::none(),
option::some(<a href="../sui/balance#sui_balance">balance</a>),
ctx,
)
}
</code></pre>
</details>
## Function `to_coin` \{#sui_token_to_coin}
Convert <a href="../sui/token#sui_token_Token">Token</a> into an open Coin. Creates an <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a> for the
"to_coin" action.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_to_coin">to_coin</a><T>(t: <a href="../sui/token#sui_token_Token">sui::token::Token</a><T>, ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): (<a href="../sui/coin#sui_coin_Coin">sui::coin::Coin</a><T>, <a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_to_coin">to_coin</a><T>(t: <a href="../sui/token#sui_token_Token">Token</a><T>, ctx: &<b>mut</b> TxContext): (Coin<T>, <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T>) {
<b>let</b> <a href="../sui/token#sui_token_Token">Token</a> { id, <a href="../sui/balance#sui_balance">balance</a> } = t;
<b>let</b> <a href="../sui/token#sui_token_amount">amount</a> = <a href="../sui/balance#sui_balance">balance</a>.<a href="../sui/token#sui_token_value">value</a>();
id.delete();
(
<a href="../sui/balance#sui_balance">balance</a>.into_coin(ctx),
<a href="../sui/token#sui_token_new_request">new_request</a>(
<a href="../sui/token#sui_token_to_coin_action">to_coin_action</a>(),
<a href="../sui/token#sui_token_amount">amount</a>,
option::none(),
option::none(),
ctx,
),
)
}
</code></pre>
</details>
## Function `from_coin` \{#sui_token_from_coin}
Convert an open Coin into a <a href="../sui/token#sui_token_Token">Token</a>. Creates an <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a> for
the "from_coin" action.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_from_coin">from_coin</a><T>(<a href="../sui/coin#sui_coin">coin</a>: <a href="../sui/coin#sui_coin_Coin">sui::coin::Coin</a><T>, ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): (<a href="../sui/token#sui_token_Token">sui::token::Token</a><T>, <a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_from_coin">from_coin</a><T>(<a href="../sui/coin#sui_coin">coin</a>: Coin<T>, ctx: &<b>mut</b> TxContext): (<a href="../sui/token#sui_token_Token">Token</a><T>, <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T>) {
<b>let</b> <a href="../sui/token#sui_token_amount">amount</a> = <a href="../sui/coin#sui_coin">coin</a>.<a href="../sui/token#sui_token_value">value</a>();
<b>let</b> <a href="../sui/token#sui_token">token</a> = <a href="../sui/token#sui_token_Token">Token</a> {
id: <a href="../sui/object#sui_object_new">object::new</a>(ctx),
<a href="../sui/balance#sui_balance">balance</a>: <a href="../sui/coin#sui_coin">coin</a>.into_balance(),
};
(
<a href="../sui/token#sui_token">token</a>,
<a href="../sui/token#sui_token_new_request">new_request</a>(
<a href="../sui/token#sui_token_from_coin_action">from_coin_action</a>(),
<a href="../sui/token#sui_token_amount">amount</a>,
option::none(),
option::none(),
ctx,
),
)
}
</code></pre>
</details>
## Function `join` \{#sui_token_join}
Join two <a href="../sui/token#sui_token_Token">Token</a>s into one, always available.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_join">join</a><T>(<a href="../sui/token#sui_token">token</a>: &<b>mut</b> <a href="../sui/token#sui_token_Token">sui::token::Token</a><T>, another: <a href="../sui/token#sui_token_Token">sui::token::Token</a><T>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_join">join</a><T>(<a href="../sui/token#sui_token">token</a>: &<b>mut</b> <a href="../sui/token#sui_token_Token">Token</a><T>, another: <a href="../sui/token#sui_token_Token">Token</a><T>) {
<b>let</b> <a href="../sui/token#sui_token_Token">Token</a> { id, <a href="../sui/balance#sui_balance">balance</a> } = another;
<a href="../sui/token#sui_token">token</a>.<a href="../sui/balance#sui_balance">balance</a>.<a href="../sui/token#sui_token_join">join</a>(<a href="../sui/balance#sui_balance">balance</a>);
id.delete();
}
</code></pre>
</details>
## Function `split` \{#sui_token_split}
Split a <a href="../sui/token#sui_token_Token">Token</a> with <a href="../sui/token#sui_token_amount">amount</a>.
Aborts if the <a href="../sui/token#sui_token_Token">Token</a>.<a href="../sui/balance#sui_balance">balance</a> is lower than <a href="../sui/token#sui_token_amount">amount</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_split">split</a><T>(<a href="../sui/token#sui_token">token</a>: &<b>mut</b> <a href="../sui/token#sui_token_Token">sui::token::Token</a><T>, <a href="../sui/token#sui_token_amount">amount</a>: u64, ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): <a href="../sui/token#sui_token_Token">sui::token::Token</a><T>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_split">split</a><T>(<a href="../sui/token#sui_token">token</a>: &<b>mut</b> <a href="../sui/token#sui_token_Token">Token</a><T>, <a href="../sui/token#sui_token_amount">amount</a>: u64, ctx: &<b>mut</b> TxContext): <a href="../sui/token#sui_token_Token">Token</a><T> {
<b>assert</b>!(<a href="../sui/token#sui_token">token</a>.<a href="../sui/balance#sui_balance">balance</a>.<a href="../sui/token#sui_token_value">value</a>() >= <a href="../sui/token#sui_token_amount">amount</a>, <a href="../sui/token#sui_token_EBalanceTooLow">EBalanceTooLow</a>);
<a href="../sui/token#sui_token_Token">Token</a> {
id: <a href="../sui/object#sui_object_new">object::new</a>(ctx),
<a href="../sui/balance#sui_balance">balance</a>: <a href="../sui/token#sui_token">token</a>.<a href="../sui/balance#sui_balance">balance</a>.<a href="../sui/token#sui_token_split">split</a>(<a href="../sui/token#sui_token_amount">amount</a>),
}
}
</code></pre>
</details>
## Function `zero` \{#sui_token_zero}
Create a zero <a href="../sui/token#sui_token_Token">Token</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_zero">zero</a><T>(ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): <a href="../sui/token#sui_token_Token">sui::token::Token</a><T>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_zero">zero</a><T>(ctx: &<b>mut</b> TxContext): <a href="../sui/token#sui_token_Token">Token</a><T> {
<a href="../sui/token#sui_token_Token">Token</a> {
id: <a href="../sui/object#sui_object_new">object::new</a>(ctx),
<a href="../sui/balance#sui_balance">balance</a>: <a href="../sui/balance#sui_balance_zero">balance::zero</a>(),
}
}
</code></pre>
</details>
## Function `destroy_zero` \{#sui_token_destroy_zero}
Destroy an empty <a href="../sui/token#sui_token_Token">Token</a>, fails if the balance is non-zero.
Aborts if the <a href="../sui/token#sui_token_Token">Token</a>.<a href="../sui/balance#sui_balance">balance</a> is not zero.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_destroy_zero">destroy_zero</a><T>(<a href="../sui/token#sui_token">token</a>: <a href="../sui/token#sui_token_Token">sui::token::Token</a><T>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_destroy_zero">destroy_zero</a><T>(<a href="../sui/token#sui_token">token</a>: <a href="../sui/token#sui_token_Token">Token</a><T>) {
<b>let</b> <a href="../sui/token#sui_token_Token">Token</a> { id, <a href="../sui/balance#sui_balance">balance</a> } = <a href="../sui/token#sui_token">token</a>;
<b>assert</b>!(<a href="../sui/balance#sui_balance">balance</a>.<a href="../sui/token#sui_token_value">value</a>() == 0, <a href="../sui/token#sui_token_ENotZero">ENotZero</a>);
<a href="../sui/balance#sui_balance">balance</a>.<a href="../sui/token#sui_token_destroy_zero">destroy_zero</a>();
id.delete();
}
</code></pre>
</details>
## Function `keep` \{#sui_token_keep}
Transfer the <a href="../sui/token#sui_token_Token">Token</a> to the transaction sender.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_keep">keep</a><T>(<a href="../sui/token#sui_token">token</a>: <a href="../sui/token#sui_token_Token">sui::token::Token</a><T>, ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_keep">keep</a><T>(<a href="../sui/token#sui_token">token</a>: <a href="../sui/token#sui_token_Token">Token</a><T>, ctx: &<b>mut</b> TxContext) {
<a href="../sui/transfer#sui_transfer_transfer">transfer::transfer</a>(<a href="../sui/token#sui_token">token</a>, ctx.<a href="../sui/token#sui_token_sender">sender</a>())
}
</code></pre>
</details>
## Function `new_request` \{#sui_token_new_request}
Create a new <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a>.
Publicly available method to allow for custom actions.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_new_request">new_request</a><T>(name: <a href="../std/string#std_string_String">std::string::String</a>, <a href="../sui/token#sui_token_amount">amount</a>: u64, <a href="../sui/token#sui_token_recipient">recipient</a>: <a href="../std/option#std_option_Option">std::option::Option</a><<b>address</b>>, <a href="../sui/token#sui_token_spent_balance">spent_balance</a>: <a href="../std/option#std_option_Option">std::option::Option</a><<a href="../sui/balance#sui_balance_Balance">sui::balance::Balance</a><T>>, ctx: &<a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): <a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_new_request">new_request</a><T>(
name: String,
<a href="../sui/token#sui_token_amount">amount</a>: u64,
<a href="../sui/token#sui_token_recipient">recipient</a>: Option<<b>address</b>>,
<a href="../sui/token#sui_token_spent_balance">spent_balance</a>: Option<Balance<T>>,
ctx: &TxContext,
): <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T> {
<a href="../sui/token#sui_token_ActionRequest">ActionRequest</a> {
name,
<a href="../sui/token#sui_token_amount">amount</a>,
<a href="../sui/token#sui_token_recipient">recipient</a>,
<a href="../sui/token#sui_token_spent_balance">spent_balance</a>,
<a href="../sui/token#sui_token_sender">sender</a>: ctx.<a href="../sui/token#sui_token_sender">sender</a>(),
<a href="../sui/token#sui_token_approvals">approvals</a>: <a href="../sui/vec_set#sui_vec_set_empty">vec_set::empty</a>(),
}
}
</code></pre>
</details>
## Function `confirm_request` \{#sui_token_confirm_request}
Confirm the request against the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> and return the parameters
of the request: (Name, Amount, Sender, Recipient).
Cannot be used for <a href="../sui/token#sui_token_spend">spend</a> and similar actions that deliver <a href="../sui/token#sui_token_spent_balance">spent_balance</a>
to the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>. For those actions use <a href="../sui/token#sui_token_confirm_request_mut">confirm_request_mut</a>.
Aborts if:
- the action is not allowed (missing record in <a href="../sui/token#sui_token_rules">rules</a>)
- action contains <a href="../sui/token#sui_token_spent_balance">spent_balance</a> (use <a href="../sui/token#sui_token_confirm_request_mut">confirm_request_mut</a>)
- the <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a> does not meet the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> rules for the action
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_confirm_request">confirm_request</a><T>(policy: &<a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>, request: <a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>, _ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): (<a href="../std/string#std_string_String">std::string::String</a>, u64, <b>address</b>, <a href="../std/option#std_option_Option">std::option::Option</a><<b>address</b>>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_confirm_request">confirm_request</a><T>(
policy: &<a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>,
request: <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T>,
_ctx: &<b>mut</b> TxContext,
): (String, u64, <b>address</b>, Option<<b>address</b>>) {
<b>assert</b>!(request.<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.is_none(), <a href="../sui/token#sui_token_ECantConsumeBalance">ECantConsumeBalance</a>);
<b>assert</b>!(policy.<a href="../sui/token#sui_token_rules">rules</a>.contains(&request.name), <a href="../sui/token#sui_token_EUnknownAction">EUnknownAction</a>);
<b>let</b> <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a> {
name,
<a href="../sui/token#sui_token_approvals">approvals</a>,
<a href="../sui/token#sui_token_spent_balance">spent_balance</a>,
<a href="../sui/token#sui_token_amount">amount</a>,
<a href="../sui/token#sui_token_sender">sender</a>,
<a href="../sui/token#sui_token_recipient">recipient</a>,
} = request;
<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.destroy_none();
<b>let</b> <a href="../sui/token#sui_token_rules">rules</a> = &(*policy.<a href="../sui/token#sui_token_rules">rules</a>.get(&name)).into_keys();
<b>let</b> rules_len = <a href="../sui/token#sui_token_rules">rules</a>.length();
<b>let</b> <b>mut</b> i = 0;
<b>while</b> (i < rules_len) {
<b>let</b> rule = &<a href="../sui/token#sui_token_rules">rules</a>[i];
<b>assert</b>!(<a href="../sui/token#sui_token_approvals">approvals</a>.contains(rule), <a href="../sui/token#sui_token_ENotApproved">ENotApproved</a>);
i = i + 1;
};
(name, <a href="../sui/token#sui_token_amount">amount</a>, <a href="../sui/token#sui_token_sender">sender</a>, <a href="../sui/token#sui_token_recipient">recipient</a>)
}
</code></pre>
</details>
## Function `confirm_request_mut` \{#sui_token_confirm_request_mut}
Confirm the request against the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> and return the parameters
of the request: (Name, Amount, Sender, Recipient).
Unlike <a href="../sui/token#sui_token_confirm_request">confirm_request</a> this function requires mutable access to the
<a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> and must be used on <a href="../sui/token#sui_token_spend">spend</a> action. After dealing with the
spent balance it calls <a href="../sui/token#sui_token_confirm_request">confirm_request</a> internally.
See <a href="../sui/token#sui_token_confirm_request">confirm_request</a> for the list of abort conditions.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_confirm_request_mut">confirm_request_mut</a><T>(policy: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>, request: <a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>, ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): (<a href="../std/string#std_string_String">std::string::String</a>, u64, <b>address</b>, <a href="../std/option#std_option_Option">std::option::Option</a><<b>address</b>>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_confirm_request_mut">confirm_request_mut</a><T>(
policy: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>,
<b>mut</b> request: <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T>,
ctx: &<b>mut</b> TxContext,
): (String, u64, <b>address</b>, Option<<b>address</b>>) {
<b>assert</b>!(policy.<a href="../sui/token#sui_token_rules">rules</a>.contains(&request.name), <a href="../sui/token#sui_token_EUnknownAction">EUnknownAction</a>);
<b>assert</b>!(request.<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.is_some(), <a href="../sui/token#sui_token_EUseImmutableConfirm">EUseImmutableConfirm</a>);
policy.<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.<a href="../sui/token#sui_token_join">join</a>(request.<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.extract());
<a href="../sui/token#sui_token_confirm_request">confirm_request</a>(policy, request, ctx)
}
</code></pre>
</details>
## Function `confirm_with_policy_cap` \{#sui_token_confirm_with_policy_cap}
Confirm an <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a> as the <a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a> owner. This function
allows <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> owner to perform Capability-gated actions ignoring
the ruleset specified in the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.
Aborts if request contains <a href="../sui/token#sui_token_spent_balance">spent_balance</a> due to inability of the
<a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a> to decrease supply. For scenarios like this a
TreasuryCap is required (see <a href="../sui/token#sui_token_confirm_with_treasury_cap">confirm_with_treasury_cap</a>).
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_confirm_with_policy_cap">confirm_with_policy_cap</a><T>(_policy_cap: &<a href="../sui/token#sui_token_TokenPolicyCap">sui::token::TokenPolicyCap</a><T>, request: <a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>, _ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): (<a href="../std/string#std_string_String">std::string::String</a>, u64, <b>address</b>, <a href="../std/option#std_option_Option">std::option::Option</a><<b>address</b>>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_confirm_with_policy_cap">confirm_with_policy_cap</a><T>(
_policy_cap: &<a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a><T>,
request: <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T>,
_ctx: &<b>mut</b> TxContext,
): (String, u64, <b>address</b>, Option<<b>address</b>>) {
<b>assert</b>!(request.<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.is_none(), <a href="../sui/token#sui_token_ECantConsumeBalance">ECantConsumeBalance</a>);
<b>let</b> <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a> {
name,
<a href="../sui/token#sui_token_amount">amount</a>,
<a href="../sui/token#sui_token_sender">sender</a>,
<a href="../sui/token#sui_token_recipient">recipient</a>,
<a href="../sui/token#sui_token_approvals">approvals</a>: _,
<a href="../sui/token#sui_token_spent_balance">spent_balance</a>,
} = request;
<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.destroy_none();
(name, <a href="../sui/token#sui_token_amount">amount</a>, <a href="../sui/token#sui_token_sender">sender</a>, <a href="../sui/token#sui_token_recipient">recipient</a>)
}
</code></pre>
</details>
## Function `confirm_with_treasury_cap` \{#sui_token_confirm_with_treasury_cap}
Confirm an <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a> as the TreasuryCap owner. This function
allows TreasuryCap owner to perform Capability-gated actions ignoring
the ruleset specified in the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.
Unlike <a href="../sui/token#sui_token_confirm_with_policy_cap">confirm_with_policy_cap</a> this function allows <a href="../sui/token#sui_token_spent_balance">spent_balance</a>
to be consumed, decreasing the total_supply of the <a href="../sui/token#sui_token_Token">Token</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_confirm_with_treasury_cap">confirm_with_treasury_cap</a><T>(treasury_cap: &<b>mut</b> <a href="../sui/coin#sui_coin_TreasuryCap">sui::coin::TreasuryCap</a><T>, request: <a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>, _ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): (<a href="../std/string#std_string_String">std::string::String</a>, u64, <b>address</b>, <a href="../std/option#std_option_Option">std::option::Option</a><<b>address</b>>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_confirm_with_treasury_cap">confirm_with_treasury_cap</a><T>(
treasury_cap: &<b>mut</b> TreasuryCap<T>,
request: <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T>,
_ctx: &<b>mut</b> TxContext,
): (String, u64, <b>address</b>, Option<<b>address</b>>) {
<b>let</b> <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a> {
name,
<a href="../sui/token#sui_token_amount">amount</a>,
<a href="../sui/token#sui_token_sender">sender</a>,
<a href="../sui/token#sui_token_recipient">recipient</a>,
<a href="../sui/token#sui_token_approvals">approvals</a>: _,
<a href="../sui/token#sui_token_spent_balance">spent_balance</a>,
} = request;
<b>if</b> (<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.is_some()) {
treasury_cap.supply_mut().decrease_supply(<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.destroy_some());
} <b>else</b> {
<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.destroy_none();
};
(name, <a href="../sui/token#sui_token_amount">amount</a>, <a href="../sui/token#sui_token_sender">sender</a>, <a href="../sui/token#sui_token_recipient">recipient</a>)
}
</code></pre>
</details>
## Function `add_approval` \{#sui_token_add_approval}
Add an "approval" to the <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a> by providing a Witness.
Intended to be used by Rules to add their own approvals, however, can
be used to add arbitrary approvals to the request (not only the ones
required by the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>).
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_add_approval">add_approval</a><T, W: drop>(_t: W, request: &<b>mut</b> <a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>, _ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_add_approval">add_approval</a><T, W: drop>(_t: W, request: &<b>mut</b> <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T>, _ctx: &<b>mut</b> TxContext) {
request.<a href="../sui/token#sui_token_approvals">approvals</a>.insert(type_name::get<W>())
}
</code></pre>
</details>
## Function `add_rule_config` \{#sui_token_add_rule_config}
Add a Config for a Rule in the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>. Rule configuration is
independent from the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.<a href="../sui/token#sui_token_rules">rules</a> and needs to be managed by the
Rule itself. Configuration is stored per Rule and not per Rule per
Action to allow reuse in different actions.
- Rule witness guarantees that the Config is approved by the Rule.
- <a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a> guarantees that the Config setup is initiated by
the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> owner.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_add_rule_config">add_rule_config</a><T, Rule: drop, Config: store>(_rule: Rule, self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>, cap: &<a href="../sui/token#sui_token_TokenPolicyCap">sui::token::TokenPolicyCap</a><T>, <a href="../sui/config#sui_config">config</a>: Config, _ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_add_rule_config">add_rule_config</a><T, Rule: drop, Config: store>(
_rule: Rule,
self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>,
cap: &<a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a><T>,
<a href="../sui/config#sui_config">config</a>: Config,
_ctx: &<b>mut</b> TxContext,
) {
<b>assert</b>!(<a href="../sui/object#sui_object_id">object::id</a>(self) == cap.`<b>for</b>`, <a href="../sui/token#sui_token_ENotAuthorized">ENotAuthorized</a>);
df::add(&<b>mut</b> self.id, <a href="../sui/token#sui_token_key">key</a><Rule>(), <a href="../sui/config#sui_config">config</a>)
}
</code></pre>
</details>
## Function `rule_config` \{#sui_token_rule_config}
Get a Config for a Rule in the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>. Requires Rule
witness, hence can only be read by the Rule itself. This requirement
guarantees safety of the stored Config and allows for simpler dynamic
field management inside the Rule Config (custom type keys are not needed
for access gating).
Aborts if the Config is not present.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_rule_config">rule_config</a><T, Rule: drop, Config: store>(_rule: Rule, self: &<a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>): &Config
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_rule_config">rule_config</a><T, Rule: drop, Config: store>(_rule: Rule, self: &<a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>): &Config {
<b>assert</b>!(<a href="../sui/token#sui_token_has_rule_config_with_type">has_rule_config_with_type</a><T, Rule, Config>(self), <a href="../sui/token#sui_token_ENoConfig">ENoConfig</a>);
df::borrow(&self.id, <a href="../sui/token#sui_token_key">key</a><Rule>())
}
</code></pre>
</details>
## Function `rule_config_mut` \{#sui_token_rule_config_mut}
Get mutable access to the Config for a Rule in the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.
Requires Rule witness, hence can only be read by the Rule itself,
as well as <a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a> to guarantee that the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> owner
is the one who initiated the Config modification.
Aborts if:
- the Config is not present
- <a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a> is not matching the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_rule_config_mut">rule_config_mut</a><T, Rule: drop, Config: store>(_rule: Rule, self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>, cap: &<a href="../sui/token#sui_token_TokenPolicyCap">sui::token::TokenPolicyCap</a><T>): &<b>mut</b> Config
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_rule_config_mut">rule_config_mut</a><T, Rule: drop, Config: store>(
_rule: Rule,
self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>,
cap: &<a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a><T>,
): &<b>mut</b> Config {
<b>assert</b>!(<a href="../sui/token#sui_token_has_rule_config_with_type">has_rule_config_with_type</a><T, Rule, Config>(self), <a href="../sui/token#sui_token_ENoConfig">ENoConfig</a>);
<b>assert</b>!(<a href="../sui/object#sui_object_id">object::id</a>(self) == cap.`<b>for</b>`, <a href="../sui/token#sui_token_ENotAuthorized">ENotAuthorized</a>);
df::borrow_mut(&<b>mut</b> self.id, <a href="../sui/token#sui_token_key">key</a><Rule>())
}
</code></pre>
</details>
## Function `remove_rule_config` \{#sui_token_remove_rule_config}
Remove a Config for a Rule in the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.
Unlike the <a href="../sui/token#sui_token_add_rule_config">add_rule_config</a>, this function does not require a Rule
witness, hence can be performed by the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> owner on their own.
Rules need to make sure that the Config is present when performing
verification of the <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a>.
Aborts if:
- the Config is not present
- <a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a> is not matching the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_remove_rule_config">remove_rule_config</a><T, Rule, Config: store>(self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>, cap: &<a href="../sui/token#sui_token_TokenPolicyCap">sui::token::TokenPolicyCap</a><T>, _ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): Config
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_remove_rule_config">remove_rule_config</a><T, Rule, Config: store>(
self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>,
cap: &<a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a><T>,
_ctx: &<b>mut</b> TxContext,
): Config {
<b>assert</b>!(<a href="../sui/token#sui_token_has_rule_config_with_type">has_rule_config_with_type</a><T, Rule, Config>(self), <a href="../sui/token#sui_token_ENoConfig">ENoConfig</a>);
<b>assert</b>!(<a href="../sui/object#sui_object_id">object::id</a>(self) == cap.`<b>for</b>`, <a href="../sui/token#sui_token_ENotAuthorized">ENotAuthorized</a>);
df::remove(&<b>mut</b> self.id, <a href="../sui/token#sui_token_key">key</a><Rule>())
}
</code></pre>
</details>
## Function `has_rule_config` \{#sui_token_has_rule_config}
Check if a config for a Rule is set in the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> without
checking the type of the Config.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_has_rule_config">has_rule_config</a><T, Rule>(self: &<a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>): bool
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_has_rule_config">has_rule_config</a><T, Rule>(self: &<a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>): bool {
df::exists_<<a href="../sui/token#sui_token_RuleKey">RuleKey</a><Rule>>(&self.id, <a href="../sui/token#sui_token_key">key</a><Rule>())
}
</code></pre>
</details>
## Function `has_rule_config_with_type` \{#sui_token_has_rule_config_with_type}
Check if a Config for a Rule is set in the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a> and that
it matches the type provided.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_has_rule_config_with_type">has_rule_config_with_type</a><T, Rule, Config: store>(self: &<a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>): bool
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_has_rule_config_with_type">has_rule_config_with_type</a><T, Rule, Config: store>(self: &<a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>): bool {
df::exists_with_type<<a href="../sui/token#sui_token_RuleKey">RuleKey</a><Rule>, Config>(&self.id, <a href="../sui/token#sui_token_key">key</a><Rule>())
}
</code></pre>
</details>
## Function `allow` \{#sui_token_allow}
Allows an <a href="../sui/token#sui_token_action">action</a> to be performed on the <a href="../sui/token#sui_token_Token">Token</a> freely by adding an
empty set of Rules for the <a href="../sui/token#sui_token_action">action</a>.
Aborts if the <a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a> is not matching the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_allow">allow</a><T>(self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>, cap: &<a href="../sui/token#sui_token_TokenPolicyCap">sui::token::TokenPolicyCap</a><T>, <a href="../sui/token#sui_token_action">action</a>: <a href="../std/string#std_string_String">std::string::String</a>, _ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_allow">allow</a><T>(
self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>,
cap: &<a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a><T>,
<a href="../sui/token#sui_token_action">action</a>: String,
_ctx: &<b>mut</b> TxContext,
) {
<b>assert</b>!(<a href="../sui/object#sui_object_id">object::id</a>(self) == cap.`<b>for</b>`, <a href="../sui/token#sui_token_ENotAuthorized">ENotAuthorized</a>);
self.<a href="../sui/token#sui_token_rules">rules</a>.insert(<a href="../sui/token#sui_token_action">action</a>, <a href="../sui/vec_set#sui_vec_set_empty">vec_set::empty</a>());
}
</code></pre>
</details>
## Function `disallow` \{#sui_token_disallow}
Completely disallows an <a href="../sui/token#sui_token_action">action</a> on the <a href="../sui/token#sui_token_Token">Token</a> by removing the record
from the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.<a href="../sui/token#sui_token_rules">rules</a>.
Aborts if the <a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a> is not matching the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_disallow">disallow</a><T>(self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>, cap: &<a href="../sui/token#sui_token_TokenPolicyCap">sui::token::TokenPolicyCap</a><T>, <a href="../sui/token#sui_token_action">action</a>: <a href="../std/string#std_string_String">std::string::String</a>, _ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_disallow">disallow</a><T>(
self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>,
cap: &<a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a><T>,
<a href="../sui/token#sui_token_action">action</a>: String,
_ctx: &<b>mut</b> TxContext,
) {
<b>assert</b>!(<a href="../sui/object#sui_object_id">object::id</a>(self) == cap.`<b>for</b>`, <a href="../sui/token#sui_token_ENotAuthorized">ENotAuthorized</a>);
self.<a href="../sui/token#sui_token_rules">rules</a>.remove(&<a href="../sui/token#sui_token_action">action</a>);
}
</code></pre>
</details>
## Function `add_rule_for_action` \{#sui_token_add_rule_for_action}
Adds a Rule for an action with name in the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.
Aborts if the <a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a> is not matching the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_add_rule_for_action">add_rule_for_action</a><T, Rule: drop>(self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>, cap: &<a href="../sui/token#sui_token_TokenPolicyCap">sui::token::TokenPolicyCap</a><T>, <a href="../sui/token#sui_token_action">action</a>: <a href="../std/string#std_string_String">std::string::String</a>, ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_add_rule_for_action">add_rule_for_action</a><T, Rule: drop>(
self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>,
cap: &<a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a><T>,
<a href="../sui/token#sui_token_action">action</a>: String,
ctx: &<b>mut</b> TxContext,
) {
<b>assert</b>!(<a href="../sui/object#sui_object_id">object::id</a>(self) == cap.`<b>for</b>`, <a href="../sui/token#sui_token_ENotAuthorized">ENotAuthorized</a>);
<b>if</b> (!self.<a href="../sui/token#sui_token_rules">rules</a>.contains(&<a href="../sui/token#sui_token_action">action</a>)) {
<a href="../sui/token#sui_token_allow">allow</a>(self, cap, <a href="../sui/token#sui_token_action">action</a>, ctx);
};
self.<a href="../sui/token#sui_token_rules">rules</a>.get_mut(&<a href="../sui/token#sui_token_action">action</a>).insert(type_name::get<Rule>())
}
</code></pre>
</details>
## Function `remove_rule_for_action` \{#sui_token_remove_rule_for_action}
Removes a rule for an action with name in the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>. Returns
the config object to be handled by the sender (or a Rule itself).
Aborts if the <a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a> is not matching the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_remove_rule_for_action">remove_rule_for_action</a><T, Rule: drop>(self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>, cap: &<a href="../sui/token#sui_token_TokenPolicyCap">sui::token::TokenPolicyCap</a><T>, <a href="../sui/token#sui_token_action">action</a>: <a href="../std/string#std_string_String">std::string::String</a>, _ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_remove_rule_for_action">remove_rule_for_action</a><T, Rule: drop>(
self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>,
cap: &<a href="../sui/token#sui_token_TokenPolicyCap">TokenPolicyCap</a><T>,
<a href="../sui/token#sui_token_action">action</a>: String,
_ctx: &<b>mut</b> TxContext,
) {
<b>assert</b>!(<a href="../sui/object#sui_object_id">object::id</a>(self) == cap.`<b>for</b>`, <a href="../sui/token#sui_token_ENotAuthorized">ENotAuthorized</a>);
self.<a href="../sui/token#sui_token_rules">rules</a>.get_mut(&<a href="../sui/token#sui_token_action">action</a>).remove(&type_name::get<Rule>())
}
</code></pre>
</details>
## Function `mint` \{#sui_token_mint}
Mint a <a href="../sui/token#sui_token_Token">Token</a> with a given <a href="../sui/token#sui_token_amount">amount</a> using the TreasuryCap.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_mint">mint</a><T>(cap: &<b>mut</b> <a href="../sui/coin#sui_coin_TreasuryCap">sui::coin::TreasuryCap</a><T>, <a href="../sui/token#sui_token_amount">amount</a>: u64, ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): <a href="../sui/token#sui_token_Token">sui::token::Token</a><T>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_mint">mint</a><T>(cap: &<b>mut</b> TreasuryCap<T>, <a href="../sui/token#sui_token_amount">amount</a>: u64, ctx: &<b>mut</b> TxContext): <a href="../sui/token#sui_token_Token">Token</a><T> {
<b>let</b> <a href="../sui/balance#sui_balance">balance</a> = cap.supply_mut().increase_supply(<a href="../sui/token#sui_token_amount">amount</a>);
<a href="../sui/token#sui_token_Token">Token</a> { id: <a href="../sui/object#sui_object_new">object::new</a>(ctx), <a href="../sui/balance#sui_balance">balance</a> }
}
</code></pre>
</details>
## Function `burn` \{#sui_token_burn}
Burn a <a href="../sui/token#sui_token_Token">Token</a> using the TreasuryCap.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_burn">burn</a><T>(cap: &<b>mut</b> <a href="../sui/coin#sui_coin_TreasuryCap">sui::coin::TreasuryCap</a><T>, <a href="../sui/token#sui_token">token</a>: <a href="../sui/token#sui_token_Token">sui::token::Token</a><T>)
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_burn">burn</a><T>(cap: &<b>mut</b> TreasuryCap<T>, <a href="../sui/token#sui_token">token</a>: <a href="../sui/token#sui_token_Token">Token</a><T>) {
<b>let</b> <a href="../sui/token#sui_token_Token">Token</a> { id, <a href="../sui/balance#sui_balance">balance</a> } = <a href="../sui/token#sui_token">token</a>;
cap.supply_mut().decrease_supply(<a href="../sui/balance#sui_balance">balance</a>);
id.delete();
}
</code></pre>
</details>
## Function `flush` \{#sui_token_flush}
Flush the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.<a href="../sui/token#sui_token_spent_balance">spent_balance</a> into the TreasuryCap. This
action is only available to the TreasuryCap owner.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_flush">flush</a><T>(self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>, cap: &<b>mut</b> <a href="../sui/coin#sui_coin_TreasuryCap">sui::coin::TreasuryCap</a><T>, _ctx: &<b>mut</b> <a href="../sui/tx_context#sui_tx_context_TxContext">sui::tx_context::TxContext</a>): u64
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_flush">flush</a><T>(
self: &<b>mut</b> <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>,
cap: &<b>mut</b> TreasuryCap<T>,
_ctx: &<b>mut</b> TxContext,
): u64 {
<b>let</b> <a href="../sui/token#sui_token_amount">amount</a> = self.<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.<a href="../sui/token#sui_token_value">value</a>();
<b>let</b> <a href="../sui/balance#sui_balance">balance</a> = self.<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.<a href="../sui/token#sui_token_split">split</a>(<a href="../sui/token#sui_token_amount">amount</a>);
cap.supply_mut().decrease_supply(<a href="../sui/balance#sui_balance">balance</a>)
}
</code></pre>
</details>
## Function `is_allowed` \{#sui_token_is_allowed}
Check whether an action is present in the rules VecMap.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_is_allowed">is_allowed</a><T>(self: &<a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>, <a href="../sui/token#sui_token_action">action</a>: &<a href="../std/string#std_string_String">std::string::String</a>): bool
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_is_allowed">is_allowed</a><T>(self: &<a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>, <a href="../sui/token#sui_token_action">action</a>: &String): bool {
self.<a href="../sui/token#sui_token_rules">rules</a>.contains(<a href="../sui/token#sui_token_action">action</a>)
}
</code></pre>
</details>
## Function `rules` \{#sui_token_rules}
Returns the rules required for a specific action.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_rules">rules</a><T>(self: &<a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>, <a href="../sui/token#sui_token_action">action</a>: &<a href="../std/string#std_string_String">std::string::String</a>): <a href="../sui/vec_set#sui_vec_set_VecSet">sui::vec_set::VecSet</a><<a href="../std/type_name#std_type_name_TypeName">std::type_name::TypeName</a>>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_rules">rules</a><T>(self: &<a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>, <a href="../sui/token#sui_token_action">action</a>: &String): VecSet<TypeName> {
*self.<a href="../sui/token#sui_token_rules">rules</a>.get(<a href="../sui/token#sui_token_action">action</a>)
}
</code></pre>
</details>
## Function `spent_balance` \{#sui_token_spent_balance}
Returns the <a href="../sui/token#sui_token_spent_balance">spent_balance</a> of the <a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_spent_balance">spent_balance</a><T>(self: &<a href="../sui/token#sui_token_TokenPolicy">sui::token::TokenPolicy</a><T>): u64
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_spent_balance">spent_balance</a><T>(self: &<a href="../sui/token#sui_token_TokenPolicy">TokenPolicy</a><T>): u64 {
self.<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.<a href="../sui/token#sui_token_value">value</a>()
}
</code></pre>
</details>
## Function `value` \{#sui_token_value}
Returns the <a href="../sui/balance#sui_balance">balance</a> of the <a href="../sui/token#sui_token_Token">Token</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_value">value</a><T>(t: &<a href="../sui/token#sui_token_Token">sui::token::Token</a><T>): u64
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_value">value</a><T>(t: &<a href="../sui/token#sui_token_Token">Token</a><T>): u64 {
t.<a href="../sui/balance#sui_balance">balance</a>.<a href="../sui/token#sui_token_value">value</a>()
}
</code></pre>
</details>
## Function `transfer_action` \{#sui_token_transfer_action}
Name of the Transfer action.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_transfer_action">transfer_action</a>(): <a href="../std/string#std_string_String">std::string::String</a>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_transfer_action">transfer_action</a>(): String {
<b>let</b> transfer_str = <a href="../sui/token#sui_token_TRANSFER">TRANSFER</a>;
transfer_str.to_string()
}
</code></pre>
</details>
## Function `spend_action` \{#sui_token_spend_action}
Name of the Spend action.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_spend_action">spend_action</a>(): <a href="../std/string#std_string_String">std::string::String</a>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_spend_action">spend_action</a>(): String {
<b>let</b> spend_str = <a href="../sui/token#sui_token_SPEND">SPEND</a>;
spend_str.to_string()
}
</code></pre>
</details>
## Function `to_coin_action` \{#sui_token_to_coin_action}
Name of the ToCoin action.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_to_coin_action">to_coin_action</a>(): <a href="../std/string#std_string_String">std::string::String</a>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_to_coin_action">to_coin_action</a>(): String {
<b>let</b> to_coin_str = <a href="../sui/token#sui_token_TO_COIN">TO_COIN</a>;
to_coin_str.to_string()
}
</code></pre>
</details>
## Function `from_coin_action` \{#sui_token_from_coin_action}
Name of the FromCoin action.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_from_coin_action">from_coin_action</a>(): <a href="../std/string#std_string_String">std::string::String</a>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_from_coin_action">from_coin_action</a>(): String {
<b>let</b> from_coin_str = <a href="../sui/token#sui_token_FROM_COIN">FROM_COIN</a>;
from_coin_str.to_string()
}
</code></pre>
</details>
## Function `action` \{#sui_token_action}
The Action in the <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_action">action</a><T>(self: &<a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>): <a href="../std/string#std_string_String">std::string::String</a>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_action">action</a><T>(self: &<a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T>): String { self.name }
</code></pre>
</details>
## Function `amount` \{#sui_token_amount}
Amount of the <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_amount">amount</a><T>(self: &<a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>): u64
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_amount">amount</a><T>(self: &<a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T>): u64 { self.<a href="../sui/token#sui_token_amount">amount</a> }
</code></pre>
</details>
## Function `sender` \{#sui_token_sender}
Sender of the <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_sender">sender</a><T>(self: &<a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>): <b>address</b>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_sender">sender</a><T>(self: &<a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T>): <b>address</b> { self.<a href="../sui/token#sui_token_sender">sender</a> }
</code></pre>
</details>
## Function `recipient` \{#sui_token_recipient}
Recipient of the <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_recipient">recipient</a><T>(self: &<a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>): <a href="../std/option#std_option_Option">std::option::Option</a><<b>address</b>>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_recipient">recipient</a><T>(self: &<a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T>): Option<<b>address</b>> {
self.<a href="../sui/token#sui_token_recipient">recipient</a>
}
</code></pre>
</details>
## Function `approvals` \{#sui_token_approvals}
Approvals of the <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_approvals">approvals</a><T>(self: &<a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>): <a href="../sui/vec_set#sui_vec_set_VecSet">sui::vec_set::VecSet</a><<a href="../std/type_name#std_type_name_TypeName">std::type_name::TypeName</a>>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_approvals">approvals</a><T>(self: &<a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T>): VecSet<TypeName> {
self.<a href="../sui/token#sui_token_approvals">approvals</a>
}
</code></pre>
</details>
## Function `spent` \{#sui_token_spent}
Burned balance of the <a href="../sui/token#sui_token_ActionRequest">ActionRequest</a>.
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_spent">spent</a><T>(self: &<a href="../sui/token#sui_token_ActionRequest">sui::token::ActionRequest</a><T>): <a href="../std/option#std_option_Option">std::option::Option</a><u64>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>public</b> <b>fun</b> <a href="../sui/token#sui_token_spent">spent</a><T>(self: &<a href="../sui/token#sui_token_ActionRequest">ActionRequest</a><T>): Option<u64> {
<b>if</b> (self.<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.is_some()) {
option::some(self.<a href="../sui/token#sui_token_spent_balance">spent_balance</a>.<a href="../sui/borrow#sui_borrow">borrow</a>().<a href="../sui/token#sui_token_value">value</a>())
} <b>else</b> {
option::none()
}
}
</code></pre>
</details>
## Function `key` \{#sui_token_key}
Create a new <a href="../sui/token#sui_token_RuleKey">RuleKey</a> for a Rule. The is_protected field is kept
for potential future use, if Rules were to have a freely modifiable
storage as addition / replacement for the Config system.
The goal of is_protected is to potentially allow Rules store a mutable
version of their configuration and mutate state on user action.
<pre><code><b>fun</b> <a href="../sui/token#sui_token_key">key</a><Rule>(): <a href="../sui/token#sui_token_RuleKey">sui::token::RuleKey</a><Rule>
</code></pre>
<details>
<summary>Implementation</summary>
<pre><code><b>fun</b> <a href="../sui/token#sui_token_key">key</a><Rule>(): <a href="../sui/token#sui_token_RuleKey">RuleKey</a><Rule> { <a href="../sui/token#sui_token_RuleKey">RuleKey</a> { is_protected: <b>true</b> } }
</code></pre>
</details>