Module sui::coin_regulation
Protocol-level address freezing, coin pausing, and seizing for regulated coins.
Seizing from an address is allowed only in an epoch after it was frozen. An address can be unfrozen only in an epoch after the last SeizeAuth for it was destroyed.
use std::address;
use std::ascii;
use std::bcs;
use std::internal;
use std::option;
use std::string;
use std::type_name;
use std::u128;
use std::vector;
use sui::accumulator;
use sui::accumulator_settlement;
use sui::address;
use sui::bag;
use sui::balance;
use sui::bcs;
use sui::coin;
use sui::config;
use sui::deny_list;
use sui::dynamic_field;
use sui::dynamic_object_field;
use sui::event;
use sui::funds_accumulator;
use sui::hash;
use sui::hex;
use sui::object;
use sui::party;
use sui::protocol_config;
use sui::scratch;
use sui::table;
use sui::transfer;
use sui::tx_context;
use sui::types;
use sui::url;
use sui::vec_map;
use sui::vec_set;
Struct FreezeList
Singleton shared object holding the freeze and pause state of regulated coins.
public struct FreezeList has key
Fields
- id: sui::object::UID
Struct ComplianceCap
Authorizes freezing, seizing, and pausing coin type T. A cap migrated from a DenyCapV2 keeps its object ID.
public struct ComplianceCap<phantom T> has key, store
Fields
- id: sui::object::UID
- allow_global_pause: bool
- Whether this cap may globally pause T.
Struct SeizeAuth
Authorizes seizing coin type T from frozen_address.
public struct SeizeAuth<phantom T> has key
Fields
- id: sui::object::UID
- frozen_address: address
- The address this authorizes seizing from.
- frozen_epoch: u64
- The epoch in which frozen_address was frozen.
Struct CoinTypeKey
Dynamic field key on FreezeList. A missing key means T is not paused and has no frozen addresses.
public struct CoinTypeKey<phantom T> has copy, drop, store
Struct CoinTypeState
The value under CoinTypeKey<T>: the freeze and pause state of T.
public struct CoinTypeState has store
Fields
- paused: bool
- Whether every transaction touching T is rejected.
- num_frozen_addresses: u64
- The number of addresses frozen for T.
Struct FrozenAddressKey
Dynamic field key on FreezeList, holding the frozen address. Exists iff that address is frozen for T.
public struct FrozenAddressKey<phantom T> has copy, drop, store
Fields
- 0: address
Struct FrozenAddressState
The value under FrozenAddressKey<T>: the state of one frozen address.
public struct FrozenAddressState has store
Fields
- seize_auths: sui::vec_set::VecSet<sui::object::ID>
- The IDs of the outstanding SeizeAuths for this address.
- frozen_epoch: u64
- The epoch in which this address was frozen.
- unfreeze_lock: sui::coin_regulation::UnfreezeLock
- The restriction on unfreezing this address.
Struct FreezeCountKey
Scratch key counting the addresses newly frozen in the current transaction.
public struct FreezeCountKey has copy, drop
Struct AddressFrozen
Event: the address was frozen for T.
public struct AddressFrozen<phantom T> has copy, drop
Fields
- 0: address
Struct AddressUnfrozen
Event: the address was unfrozen for T.
public struct AddressUnfrozen<phantom T> has copy, drop
Fields
- 0: address
Struct AddressPermanentlyFrozen
Event: the address was permanently frozen for T.
public struct AddressPermanentlyFrozen<phantom T> has copy, drop
Fields
- 0: address
Struct SeizeAuthIssued
Event: a SeizeAuth<T> was issued for frozen_address.
public struct SeizeAuthIssued<phantom T> has copy, drop
Fields
- id: sui::object::ID
- The ID of the issued SeizeAuth.
- frozen_address: address
- The address it authorizes seizing from.
Struct SeizeAuthDestroyed
Event: a SeizeAuth<T> for frozen_address was destroyed.
public struct SeizeAuthDestroyed<phantom T> has copy, drop
Fields
- id: sui::object::ID
- The ID of the destroyed SeizeAuth.
- frozen_address: address
- The address it authorized seizing from.
Struct CoinTypePaused
Event: T was globally paused.
public struct CoinTypePaused<phantom T> has copy, drop
Struct CoinTypeUnpaused
Event: the global pause of T was lifted.
public struct CoinTypeUnpaused<phantom T> has copy, drop
Struct DenyCapMigrated
Event: the DenyCapV2 for T was replaced by the ComplianceCap cap, keeping its ID.
public struct DenyCapMigrated<phantom T> has copy, drop
Fields
- cap: sui::object::ID
- The ID of the ComplianceCap, which is also the ID of the replaced DenyCapV2.
Enum UnfreezeLock
A restriction on unfreezing an address, in addition to its outstanding SeizeAuths.
public enum UnfreezeLock has copy, drop, store
Variants
- Variant None
- No restriction.
- Variant UntilEpoch
- Unfreezing is allowed only from this epoch on, the epoch after the last destroy_seize_auth.
- 0: u64
- Variant Permanent
- The address can never be unfrozen.
Constants
#[error]
const ENotSystemAddress: vector<u8> = b"Only the system can create the freeze list.";
#[error]
const EAlreadyFrozen: vector<u8> = b"The address is already frozen for this coin type.";
#[error]
const ENotFrozen: vector<u8> = b"The address is not frozen for this coin type.";
#[error]
const ESeizeAuthsOutstanding: vector<u8> = b"The address cannot be unfrozen while any SeizeAuth for it exists.";
#[error]
const EPermanentlyFrozen: vector<u8> = b"The address is permanently frozen for this coin type.";
#[error]
const EGlobalPauseNotAllowed: vector<u8> = b"The ComplianceCap does not allow global pause.";
#[error]
const EUnfreezeTooEarly: vector<u8> = b"The address cannot be unfrozen until the epoch after its last SeizeAuth was destroyed.";
#[error]
const ECoinTypeStateExists: vector<u8> = b"The coin type already has freeze list state.";
#[error]
const ETooManyFreezes: vector<u8> = b"Too many addresses frozen in this transaction.";
The maximum number of addresses newly frozen by freeze_address or permanently_freeze_address in one transaction.
const MAX_FREEZES_PER_TRANSACTION: u64 = 8;
Function freeze_address
Freeze addr for T.
Aborts if addr is already frozen.
Aborts if the transaction already froze MAX_FREEZES_PER_TRANSACTION addresses.
public fun freeze_address<T>(list: &mut sui::coin_regulation::FreezeList, _cap: &mut sui::coin_regulation::ComplianceCap<T>, addr: address, ctx: &mut sui::tx_context::TxContext)
Function unfreeze_address
Unfreeze addr for T. Aborts unless addr is frozen, not permanently, has no outstanding SeizeAuth, and the current epoch is later than that of its last SeizeAuth destroy, if any.
public fun unfreeze_address<T>(list: &mut sui::coin_regulation::FreezeList, _cap: &mut sui::coin_regulation::ComplianceCap<T>, addr: address, ctx: &mut sui::tx_context::TxContext)
Function permanently_freeze_address
Freeze addr for T if it is not frozen, and prevent it from ever being unfrozen.
Aborts if addr is newly frozen and the transaction already froze
MAX_FREEZES_PER_TRANSACTION addresses.
public fun permanently_freeze_address<T>(list: &mut sui::coin_regulation::FreezeList, _cap: &mut sui::coin_regulation::ComplianceCap<T>, addr: address, ctx: &mut sui::tx_context::TxContext)
Function issue_seize_auth
Issue a SeizeAuth for the frozen addr. Aborts if addr is not frozen.
public fun issue_seize_auth<T>(list: &mut sui::coin_regulation::FreezeList, _cap: &mut sui::coin_regulation::ComplianceCap<T>, addr: address, ctx: &mut sui::tx_context::TxContext): sui::coin_regulation::SeizeAuth<T>
Function destroy_seize_auth
Destroy auth and remove it from its address's outstanding SeizeAuths.
public fun destroy_seize_auth<T>(list: &mut sui::coin_regulation::FreezeList, auth: sui::coin_regulation::SeizeAuth<T>, ctx: &mut sui::tx_context::TxContext)
Function transfer_seize_auth
Transfer auth to recipient.
public fun transfer_seize_auth<T>(auth: sui::coin_regulation::SeizeAuth<T>, recipient: address)
Function enable_global_pause
Globally pause T. Aborts if cap does not allow global pause.
public fun enable_global_pause<T>(list: &mut sui::coin_regulation::FreezeList, cap: &mut sui::coin_regulation::ComplianceCap<T>, _ctx: &mut sui::tx_context::TxContext)
Function disable_global_pause
Lift the global pause of T. Aborts if cap does not allow global pause.
public fun disable_global_pause<T>(list: &mut sui::coin_regulation::FreezeList, cap: &mut sui::coin_regulation::ComplianceCap<T>, _ctx: &mut sui::tx_context::TxContext)
Function is_frozen
Whether addr is frozen for T.
public fun is_frozen<T>(list: &sui::coin_regulation::FreezeList, addr: address): bool
Function is_permanently_frozen
Whether addr is permanently frozen for T.
public fun is_permanently_frozen<T>(list: &sui::coin_regulation::FreezeList, addr: address): bool
Function is_global_pause_enabled
Whether T is globally paused.
public fun is_global_pause_enabled<T>(list: &sui::coin_regulation::FreezeList): bool
Function seize_auths
The IDs of the outstanding SeizeAuths for addr, empty if addr is not frozen.
public fun seize_auths<T>(list: &sui::coin_regulation::FreezeList, addr: address): vector<sui::object::ID>
Function allow_global_pause
Whether cap may globally pause T.
public fun allow_global_pause<T>(cap: &sui::coin_regulation::ComplianceCap<T>): bool
Function frozen_address
The address auth authorizes seizing from.
public fun frozen_address<T>(auth: &sui::coin_regulation::SeizeAuth<T>): address
Function frozen_epoch
The epoch in which frozen_address was frozen. Seizing is only allowed in a later epoch.
public fun frozen_epoch<T>(auth: &sui::coin_regulation::SeizeAuth<T>): u64
Function new_compliance_cap
A new ComplianceCap for T, for a coin created through the coin registry.
public(package) fun new_compliance_cap<T>(allow_global_pause: bool, ctx: &mut sui::tx_context::TxContext): sui::coin_regulation::ComplianceCap<T>
Function migrate_from_deny_list
Replace cap with a ComplianceCap that keeps its object ID, carrying over T's legacy next-epoch global pause and freezing each of frozen_addresses denied in the legacy next-epoch list.
public(package) fun migrate_from_deny_list<T>(list: &mut sui::coin_regulation::FreezeList, deny_list: &mut sui::deny_list::DenyList, cap: sui::coin::DenyCapV2<T>, frozen_addresses: vector<address>, ctx: &sui::tx_context::TxContext): sui::coin_regulation::ComplianceCap<T>
Function create
Create and share the FreezeList. Only callable by genesis or change_epoch transactions.
fun create(ctx: &sui::tx_context::TxContext)
Function add_frozen_address
Freeze addr for T and count it in T's state. Aborts if addr is already frozen.
fun add_frozen_address<T>(list: &mut sui::coin_regulation::FreezeList, addr: address, unfreeze_lock: sui::coin_regulation::UnfreezeLock, ctx: &sui::tx_context::TxContext)
Function count_freeze
Count a newly frozen address against this transaction's limit.
fun count_freeze(ctx: &mut sui::tx_context::TxContext)
Function coin_type_state_mut_or_add
The state of T, added if T has none.
fun coin_type_state_mut_or_add<T>(list: &mut sui::coin_regulation::FreezeList): &mut sui::coin_regulation::CoinTypeState