Module iota::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 Token
s. And can act as a replacement / extension or a
companion to existing open-loop (Coin
) systems.
Module: iota::balance iota::coin iota::token
Main type: `Balance<T>` `Coin<T>` `Token<T>`
Capability: `Supply<T>` <----> `TreasuryCap<T>` <----> `TreasuryCap<T>`
Abilities: store key + store key
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
- Struct
TokenPolicyCap
- Struct
TokenPolicy
- Struct
ActionRequest
- Struct
RuleKey
- Struct
TokenPolicyCreated
- Constants
- Function
new_policy
- Function
share_policy
- Function
transfer
- Function
spend
- Function
to_coin
- Function
from_coin
- Function
join
- Function
split
- Function
zero
- Function
destroy_zero
- Function
keep
- Function
new_request
- Function
confirm_request
- Function
confirm_request_mut
- Function
confirm_with_policy_cap
- Function
confirm_with_treasury_cap
- Function
add_approval
- Function
add_rule_config
- Function
rule_config
- Function
rule_config_mut
- Function
remove_rule_config
- Function
has_rule_config
- Function
has_rule_config_with_type
- Function
allow
- Function
disallow
- Function
add_rule_for_action
- Function
remove_rule_for_action
- Function
mint
- Function
burn
- Function
flush
- Function
is_allowed
- Function
rules
- Function
spent_balance
- Function
value
- Function
transfer_action
- Function
spend_action
- Function
to_coin_action
- Function
from_coin_action
- Function
action
- Function
amount
- Function
sender
- Function
recipient
- Function
approvals
- Function
spent
- Function
key
use iota::address;
use iota::bag;
use iota::balance;
use iota::coin;
use iota::config;
use iota::deny_list;
use iota::dynamic_field;
use iota::dynamic_object_field;
use iota::event;
use iota::hex;
use iota::object;
use iota::transfer;
use iota::tx_context;
use iota::types;
use iota::url;
use iota::vec_map;
use iota::vec_set;
use std::address;
use std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::type_name;
use std::vector;
Struct Token
A single Token
with Balance
inside. Can only be owned by an address,
and actions performed on it must be confirmed in a matching TokenPolicy
.
Fields
id: iota::object::UID
balance: iota::balance::Balance<T>
The Balance of the
Token
.
Struct TokenPolicyCap
A Capability that manages a single TokenPolicy
specified in the for
field. Created together with TokenPolicy
in the new
function.
public struct TokenPolicyCap<phantom T> has key, store
Fields
id: iota::object::UID
for: iota::object::ID
Struct TokenPolicy
TokenPolicy
represents a set of rules that define what actions can be
performed on a Token
and which Rules
must be satisfied for the
action to succeed.
- For the sake of availability,
TokenPolicy
is akey
-only object. - Each
TokenPolicy
is managed by a matchingTokenPolicyCap
. - For an action to become available, there needs to be a record in the
rules
VecMap. To allow an action to be performed freely, there's anallow
function that can be called by theTokenPolicyCap
owner.
public struct TokenPolicy<phantom T> has key
Fields
id: iota::object::UID
spent_balance: iota::balance::Balance<T>
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 whenflush
is called. This balance is effectively spent and cannot be accessed by anyone but theTreasuryCap
owner.rules: iota::vec_map::VecMap<std::string::String, iota::vec_set::VecSet<std::type_name::TypeName>>
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
ActionRequest
to be confirmed.
Struct 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 confirm_request
or confirm_request_mut
functions when the Rules are satisfied.
public struct ActionRequest<phantom T>
Fields
name: std::string::String
Name of the Action to look up in the Policy. Name can be one of the default actions:
transfer
,spend
,to_coin
,from_coin
or a custom action.amount: u64
Amount is present in all of the txs
sender: address
Sender is a permanent field always
recipient: std::option::Option<address>
Recipient is only available in
transfer
action.spent_balance: std::option::Option<iota::balance::Balance<T>>
The balance to be "spent" in the
TokenPolicy
, only available in thespend
action.approvals: iota::vec_set::VecSet<std::type_name::TypeName>
Collected approvals (stamps) from completed
Rules
. They're matched againstTokenPolicy.rules
to determine if the request can be confirmed.
Struct RuleKey
Dynamic field key for the TokenPolicy
to store the Config
for a
specific action Rule
. There can be only one configuration per
Rule
per TokenPolicy
.
public struct RuleKey<phantom T> has copy, drop, store
Fields
is_protected: bool
Struct TokenPolicyCreated
An event emitted when a TokenPolicy
is created and shared. Because
TokenPolicy
can only be shared (and potentially frozen in the future),
we emit this event in the share_policy
function and mark it as mutable.
public struct TokenPolicyCreated<phantom T> has copy, drop
Fields
id: iota::object::ID
ID of the
TokenPolicy
that was created.is_mutable: bool
Whether the
TokenPolicy
is "shared" (mutable) or "frozen" (immutable) - TBD.