CoinCoinCoinuse 0x1::type_name;
use 0x2::balance;
use 0x2::deny_list;
+use 0x2::dynamic_field;
use 0x2::object;
use 0x2::transfer;
use 0x2::tx_context;
@@ -285,6 +290,35 @@ all addresses were added to the deny list.
+
+
+
+
+## Struct `RegulatedMarker`
+
+A dynamic field key added to CoinMetadata
objects created after protocol version 63.
+This is bound to a RegulatedInfo
enum
+
+
+struct RegulatedMarker has copy, drop, store
+
+
+
+
+
+Fields
+
+
+
+-
+
dummy_field: bool
+
+-
+
+
+
+
+
@@ -341,6 +375,40 @@ interacting with the coin as an input to a transaction.
+
+
+
+
+## Enum `RegulatedInfo`
+
+Auxiliary metadata about the regulated operations supported by the coin (if any)
+
+
+public enum RegulatedInfo has copy, drop, store
+
+
+
+
+
+Variants
+
+
+
+-
+Variant
Ordinary
+
+-
+ An ordinary coin that does not support a denylist or global pause
+
+-
+Variant
Regulated
+
+-
+ A regulated coin that supports a denylist, and (maybe) global paus
+
+
+
+
@@ -852,10 +920,51 @@ type, ensuring that there's only one vector<u8>,
icon_url: Option<Url>,
ctx: &mut TxContext,
+): (TreasuryCap<T>, CoinMetadata<T>) {
+ let (treasury_cap, mut metadata) = create_currency_(
+ witness,
+ decimals,
+ symbol,
+ name,
+ description,
+ icon_url,
+ ctx,
+ );
+ dynamic_field::add(&mut metadata.id, RegulatedMarker(), RegulatedInfo::Ordinary);
+ (treasury_cap, metadata)
+}
+
+
+
+
+
+
+
+
+## Function `create_currency_`
+
+
+
+fun create_currency_<T: drop>(witness: T, decimals: u8, symbol: vector<u8>, name: vector<u8>, description: vector<u8>, icon_url: option::Option<url::Url>, ctx: &mut tx_context::TxContext): (coin::TreasuryCap<T>, coin::CoinMetadata<T>)
+
+
+
+
+
+Implementation
+
+
+fun create_currency_<T: drop>(
+ witness: T,
+ decimals: u8,
+ symbol: vector<u8>,
+ name: vector<u8>,
+ description: vector<u8>,
+ icon_url: Option<Url>,
+ ctx: &mut TxContext,
): (TreasuryCap<T>, CoinMetadata<T>) {
// Make sure there's only one instance of the type T
assert!(sui::types::is_one_time_witness(&witness), EBadWitness);
-
(
TreasuryCap {
id: object::new(ctx),
@@ -910,7 +1019,7 @@ will not change the result of the "contains" APIs.
allow_global_pause: bool,
ctx: &mut TxContext,
): (TreasuryCap<T>, DenyCapV2<T>, CoinMetadata<T>) {
- let (treasury_cap, metadata) = create_currency(
+ let (treasury_cap, mut metadata) = create_currency_(
witness,
decimals,
symbol,
@@ -928,12 +1037,49 @@ will not change the result of the "contains" APIs.
coin_metadata_object: object::id(&metadata),
deny_cap_object: object::id(&deny_cap),
});
+ dynamic_field::add(
+ &mut metadata.id,
+ RegulatedMarker(),
+ RegulatedInfo::Regulated,
+ );
(treasury_cap, deny_cap, metadata)
}
+
+
+
+
+## Function `is_regulated_currency`
+
+Return Some(true) if T
is a regulated currency, Some(false) if it is an ordinary currency.
+Return None if T was created at a protocol version prior to 63
+
+
+public fun is_regulated_currency<T>(metadata: &coin::CoinMetadata<T>): option::Option<bool>
+
+
+
+
+
+Implementation
+
+
+public fun is_regulated_currency<T>(metadata: &CoinMetadata<T>): Option<bool> {
+ if (!dynamic_field::exists_(&metadata.id, RegulatedMarker())) {
+ return option::none()
+ };
+ match (dynamic_field::borrow(&metadata.id, RegulatedMarker())) {
+ RegulatedInfo::Ordinary => option::some(false),
+ RegulatedInfo::Regulated => option::some(true),
+ }
+}
+
+
+
+
@@ -1622,7 +1768,7 @@ with the coin as input objects.
icon_url: Option<Url>,
ctx: &mut TxContext,
): (TreasuryCap<T>, DenyCap<T>, CoinMetadata<T>) {
- let (treasury_cap, metadata) = create_currency(
+ let (treasury_cap, mut metadata) = create_currency_(
witness,
decimals,
symbol,
@@ -1639,6 +1785,11 @@ with the coin as input objects.
coin_metadata_object: object::id(&metadata),
deny_cap_object: object::id(&deny_cap),
});
+ dynamic_field::add(
+ &mut metadata.id,
+ RegulatedMarker(),
+ RegulatedInfo::Regulated,
+ );
(treasury_cap, deny_cap, metadata)
}
diff --git a/crates/sui-framework/packages/sui-framework/sources/coin.move b/crates/sui-framework/packages/sui-framework/sources/coin.move
index 92dfc3d59832a..e9a0b52d96264 100644
--- a/crates/sui-framework/packages/sui-framework/sources/coin.move
+++ b/crates/sui-framework/packages/sui-framework/sources/coin.move
@@ -11,6 +11,7 @@ use std::string;
use std::type_name;
use sui::balance::{Self, Balance, Supply};
use sui::deny_list::DenyList;
+use sui::dynamic_field;
use sui::url::{Self, Url};
// Allows calling `.split_vec(amounts, ctx)` on `coin`
@@ -88,6 +89,18 @@ public struct DenyCapV2