Module 0xa5::interchain_token_service
use 0x1::ascii;
use 0x1::type_name;
use 0x1::vector;
use 0x2::balance;
use 0x2::clock;
use 0x2::coin;
use 0x2::object;
use 0x2::transfer;
use 0x2::tx_context;
use 0x2::versioned;
use 0xa1::channel;
use 0xa1::message_ticket;
use 0xa5::coin_info;
use 0xa5::coin_management;
use 0xa5::interchain_token_service_v0;
use 0xa5::interchain_transfer_ticket;
use 0xa5::operator_cap;
use 0xa5::owner_cap;
use 0xa5::token_id;
use 0xa5::trusted_addresses;
use 0xaa::discovery;
use 0xaa::transaction;
use 0xb0::version_control;
Resource InterchainTokenService
struct InterchainTokenService has key
Fields
-
id: object::UID
-
-
inner: versioned::Versioned
-
Constants
const VERSION: u64 = 0;
const DATA_VERSION: u64 = 0;
Function init
fun init(ctx: &mut tx_context::TxContext)
Implementation
fun init(ctx: &mut TxContext) {
let inner = versioned::create(
DATA_VERSION,
interchain_token_service_v0::new(
version_control(),
ctx,
),
ctx,
);
// Share the its object for anyone to use.
transfer::share_object(InterchainTokenService {
id: object::new(ctx),
inner,
});
transfer::public_transfer(
owner_cap::create(ctx),
ctx.sender(),
);
transfer::public_transfer(
operator_cap::create(ctx),
ctx.sender(),
);
}
Function allow_function
entry fun allow_function(self: &mut interchain_token_service::InterchainTokenService, _: &owner_cap::OwnerCap, version: u64, function_name: ascii::String)
Implementation
entry fun allow_function(
self: &mut InterchainTokenService,
_: &OwnerCap,
version: u64,
function_name: String,
) {
self.value_mut!(b"allow_function").allow_function(version, function_name);
}
Function disallow_function
entry fun disallow_function(self: &mut interchain_token_service::InterchainTokenService, _: &owner_cap::OwnerCap, version: u64, function_name: ascii::String)
Implementation
entry fun disallow_function(
self: &mut InterchainTokenService,
_: &OwnerCap,
version: u64,
function_name: String,
) {
self
.value_mut!(b"disallow_function")
.disallow_function(version, function_name);
}
Function register_coin
public fun register_coin<T>(self: &mut interchain_token_service::InterchainTokenService, coin_info: coin_info::CoinInfo<T>, coin_management: coin_management::CoinManagement<T>): token_id::TokenId
Implementation
public fun register_coin<T>(
self: &mut InterchainTokenService,
coin_info: CoinInfo<T>,
coin_management: CoinManagement<T>,
): TokenId {
let value = self.value_mut!(b"register_coin");
value.register_coin(coin_info, coin_management)
}
Function deploy_remote_interchain_token
public fun deploy_remote_interchain_token<T>(self: &interchain_token_service::InterchainTokenService, token_id: token_id::TokenId, destination_chain: ascii::String): message_ticket::MessageTicket
Implementation
public fun deploy_remote_interchain_token<T>(
self: &InterchainTokenService,
token_id: TokenId,
destination_chain: String,
): MessageTicket {
let value = self.value!(b"deploy_remote_interchain_token");
value.deploy_remote_interchain_token<T>(token_id, destination_chain)
}
Function prepare_interchain_transfer
public fun prepare_interchain_transfer<T>(token_id: token_id::TokenId, coin: coin::Coin<T>, destination_chain: ascii::String, destination_address: vector<u8>, metadata: vector<u8>, source_channel: &channel::Channel): interchain_transfer_ticket::InterchainTransferTicket<T>
Implementation
public fun prepare_interchain_transfer<T>(
token_id: TokenId,
coin: Coin<T>,
destination_chain: String,
destination_address: vector<u8>,
metadata: vector<u8>,
source_channel: &Channel,
): InterchainTransferTicket<T> {
interchain_transfer_ticket::new<T>(
token_id,
coin.into_balance(),
source_channel.to_address(),
destination_chain,
destination_address,
metadata,
VERSION,
)
}
Function send_interchain_transfer
public fun send_interchain_transfer<T>(self: &mut interchain_token_service::InterchainTokenService, ticket: interchain_transfer_ticket::InterchainTransferTicket<T>, clock: &clock::Clock): message_ticket::MessageTicket
Implementation
public fun send_interchain_transfer<T>(
self: &mut InterchainTokenService,
ticket: InterchainTransferTicket<T>,
clock: &Clock,
): MessageTicket {
let value = self.value_mut!(b"send_interchain_transfer");
value.send_interchain_transfer<T>(
ticket,
VERSION,
clock,
)
}
Function receive_interchain_transfer
public fun receive_interchain_transfer<T>(self: &mut interchain_token_service::InterchainTokenService, approved_message: channel::ApprovedMessage, clock: &clock::Clock, ctx: &mut tx_context::TxContext)
Implementation
public fun receive_interchain_transfer<T>(
self: &mut InterchainTokenService,
approved_message: ApprovedMessage,
clock: &Clock,
ctx: &mut TxContext,
) {
let value = self.value_mut!(b"receive_interchain_transfer");
value.receive_interchain_transfer<T>(approved_message, clock, ctx);
}
Function receive_interchain_transfer_with_data
public fun receive_interchain_transfer_with_data<T>(self: &mut interchain_token_service::InterchainTokenService, approved_message: channel::ApprovedMessage, channel: &channel::Channel, clock: &clock::Clock, ctx: &mut tx_context::TxContext): (ascii::String, vector<u8>, vector<u8>, coin::Coin<T>)
Implementation
public fun receive_interchain_transfer_with_data<T>(
self: &mut InterchainTokenService,
approved_message: ApprovedMessage,
channel: &Channel,
clock: &Clock,
ctx: &mut TxContext,
): (String, vector<u8>, vector<u8>, Coin<T>) {
let value = self.value_mut!(b"receive_interchain_transfer_with_data");
value.receive_interchain_transfer_with_data<T>(
approved_message,
channel,
clock,
ctx,
)
}
Function receive_deploy_interchain_token
public fun receive_deploy_interchain_token<T>(self: &mut interchain_token_service::InterchainTokenService, approved_message: channel::ApprovedMessage)
Implementation
public fun receive_deploy_interchain_token<T>(
self: &mut InterchainTokenService,
approved_message: ApprovedMessage,
) {
let value = self.value_mut!(b"receive_deploy_interchain_token");
value.receive_deploy_interchain_token<T>(approved_message);
}
Function give_unregistered_coin
public fun give_unregistered_coin<T>(self: &mut interchain_token_service::InterchainTokenService, treasury_cap: coin::TreasuryCap<T>, coin_metadata: coin::CoinMetadata<T>)
Implementation
public fun give_unregistered_coin<T>(
self: &mut InterchainTokenService,
treasury_cap: TreasuryCap<T>,
coin_metadata: CoinMetadata<T>,
) {
let value = self.value_mut!(b"give_unregistered_coin");
value.give_unregistered_coin<T>(treasury_cap, coin_metadata);
}
Function mint_as_distributor
public fun mint_as_distributor<T>(self: &mut interchain_token_service::InterchainTokenService, channel: &channel::Channel, token_id: token_id::TokenId, amount: u64, ctx: &mut tx_context::TxContext): coin::Coin<T>
Implementation
public fun mint_as_distributor<T>(
self: &mut InterchainTokenService,
channel: &Channel,
token_id: TokenId,
amount: u64,
ctx: &mut TxContext,
): Coin<T> {
let value = self.value_mut!(b"mint_as_distributor");
value.mint_as_distributor<T>(
channel,
token_id,
amount,
ctx,
)
}
Function mint_to_as_distributor
public fun mint_to_as_distributor<T>(self: &mut interchain_token_service::InterchainTokenService, channel: &channel::Channel, token_id: token_id::TokenId, to: address, amount: u64, ctx: &mut tx_context::TxContext)
Implementation
public fun mint_to_as_distributor<T>(
self: &mut InterchainTokenService,
channel: &Channel,
token_id: TokenId,
to: address,
amount: u64,
ctx: &mut TxContext,
) {
let value = self.value_mut!(b"mint_to_as_distributor");
value.mint_to_as_distributor<T>(
channel,
token_id,
to,
amount,
ctx,
);
}
Function burn_as_distributor
public fun burn_as_distributor<T>(self: &mut interchain_token_service::InterchainTokenService, channel: &channel::Channel, token_id: token_id::TokenId, coin: coin::Coin<T>)
Implementation
public fun burn_as_distributor<T>(
self: &mut InterchainTokenService,
channel: &Channel,
token_id: TokenId,
coin: Coin<T>,
) {
let value = self.value_mut!(b"mint_to_as_distributor");
value.burn_as_distributor<T>(
channel,
token_id,
coin,
);
}
Function set_flow_limit_as_token_operator
public fun set_flow_limit_as_token_operator<T>(self: &mut interchain_token_service::InterchainTokenService, channel: &channel::Channel, token_id: token_id::TokenId, limit: u64)
Implementation
public fun set_flow_limit_as_token_operator<T>(
self: &mut InterchainTokenService,
channel: &Channel,
token_id: TokenId,
limit: u64,
) {
let value = self.value_mut!(b"set_flow_limit_as_token_operator");
value.set_flow_limit_as_token_operator<T>(
channel,
token_id,
limit,
);
}
Function set_flow_limit
public fun set_flow_limit<T>(self: &mut interchain_token_service::InterchainTokenService, _: &operator_cap::OperatorCap, token_ids: token_id::TokenId, limits: u64)
Implementation
public fun set_flow_limit<T>(
self: &mut InterchainTokenService,
_: &OperatorCap,
token_ids: TokenId,
limits: u64,
) {
let value = self.value_mut!(b"set_flow_limit");
value.set_flow_limit<T>(
token_ids,
limits,
);
}
Function set_trusted_addresses
public fun set_trusted_addresses(self: &mut interchain_token_service::InterchainTokenService, _owner_cap: &owner_cap::OwnerCap, trusted_addresses: trusted_addresses::TrustedAddresses)
Implementation
public fun set_trusted_addresses(
self: &mut InterchainTokenService,
_owner_cap: &OwnerCap,
trusted_addresses: TrustedAddresses,
) {
let value = self.value_mut!(b"set_trusted_addresses");
value.set_trusted_addresses(trusted_addresses);
}
Function remove_trusted_addresses
public fun remove_trusted_addresses(self: &mut interchain_token_service::InterchainTokenService, _owner_cap: &owner_cap::OwnerCap, chain_names: vector<ascii::String>)
Implementation
public fun remove_trusted_addresses(
self: &mut InterchainTokenService,
_owner_cap: &OwnerCap,
chain_names: vector<String>,
) {
let value = self.value_mut!(b"remove_trusted_addresses");
value.remove_trusted_addresses(chain_names);
}
Function registered_coin_type
public fun registered_coin_type(self: &interchain_token_service::InterchainTokenService, token_id: token_id::TokenId): &type_name::TypeName
Implementation
public fun registered_coin_type(self: &InterchainTokenService, token_id: TokenId): &TypeName {
self.package_value().registered_coin_type(token_id)
}
Function channel_address
public fun channel_address(self: &interchain_token_service::InterchainTokenService): address
Implementation
public fun channel_address(self: &InterchainTokenService): address {
self.package_value().channel_address()
}
Function package_value
public(friend) fun package_value(self: &interchain_token_service::InterchainTokenService): &interchain_token_service_v0::InterchainTokenService_v0
Implementation
public(package) fun package_value(self: &InterchainTokenService): &InterchainTokenService_v0 {
self.inner.load_value<InterchainTokenService_v0>()
}
Function register_transaction
public(friend) fun register_transaction(self: &mut interchain_token_service::InterchainTokenService, discovery: &mut discovery::RelayerDiscovery, transaction: transaction::Transaction)
Implementation
public(package) fun register_transaction(
self: &mut InterchainTokenService,
discovery: &mut RelayerDiscovery,
transaction: Transaction,
) {
let value = self.value_mut!(b"register_transaction");
value.set_relayer_discovery_id(discovery);
discovery.register_transaction(
value.channel(),
transaction,
);
}
Function version_control
fun version_control(): version_control::VersionControl
Implementation
fun version_control(): VersionControl {
version_control::new(vector[
// Version 0
vector[
b"register_coin",
b"deploy_remote_interchain_token",
b"send_interchain_transfer",
b"receive_interchain_transfer",
b"receive_interchain_transfer_with_data",
b"receive_deploy_interchain_token",
b"give_unregistered_coin",
b"mint_as_distributor",
b"mint_to_as_distributor",
b"burn_as_distributor",
b"set_trusted_addresses",
b"remove_trusted_addresses",
b"register_transaction",
b"set_flow_limit",
b"set_flow_limit_as_token_operator",
b"allow_function",
b"disallow_function",
].map!(|function_name| function_name.to_ascii_string()),
])
}