Module sui::transfer_policy
Defines the
TransferPolicy type and the logic to approve TransferRequests.
-
TransferPolicy - is a highly customizable primitive, which provides an interface for the type owner to set custom transfer rules for every deal performed in the
Kioskor a similar system that integrates with TP. -
Once a
is created for and shared (or frozen), the typeTransferPolicy<T>Tbecomes tradable inKiosks. On every purchase operation, a
is created and needs to be confirmed by theTransferRequest
hot potato or transaction will fail.TransferPolicy -
Type owner (creator) can set any Rules as long as the ecosystem supports them. All of the Rules need to be resolved within a single transaction (eg pay royalty and pay fixed commission). Once required actions are performed, the
can be "confirmed" viaTransferRequest
call.confirm_request -
aims to be the main interface for creators to control trades of their types and collect profits if a fee is required on sales. Custom policies can be removed at any moment, and the change will affect all instances of the type at once.TransferPolicy
use std::address;
use std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::type_name;
use std::vector;
use sui::accumulator;
use sui::accumulator_metadata;
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::package;
use sui::party;
use sui::sui;
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 TransferRequest
A "Hot Potato" forcing the buyer to get a transfer permission
from the item type (T) owner on purchase attempt.
public struct TransferRequest<phantom T>
Fields
-
item: sui::object::ID -
The ID of the transferred item. Although the
Thas no constraints, the main use case for this module is to work with Objects. -
paid: u64 - Amount of SUI paid for the item. Can be used to calculate the fee / transfer policy enforcement.
-
from: sui::object::ID - The ID of the Kiosk / Safe the object is being sold from. Can be used by the TransferPolicy implementors.
-
receipts: sui::vec_set::VecSet<std::type_name::TypeName> -
Collected Receipts. Used to verify that all of the rules
were followed and
can be confirmed.TransferRequest
Struct TransferPolicy
A unique capability that allows the owner of the T to authorize
transfers. Can only be created with the Publisher object. Although
there's no limitation to how many policies can be created, for most
of the cases there's no need to create more than one since any of the
policies can be used to confirm the
TransferRequest.
public struct TransferPolicy<phantom T> has key, store
Fields
-
id: sui::object::UID -
balance: sui::balance::Balance<sui::sui::SUI> -
The Balance of the
which collectsTransferPolicySUI. By default, transfer policy does not collect anything , and it's a matter of an implementation of a specific rule - whether to add to balance and how much. -
rules: sui::vec_set::VecSet<std::type_name::TypeName> -
Set of types of attached rules - used to verify
receiptswhen a
is received inTransferRequest
function. Additionally provides a way to look up currently attached Rules.confirm_request