axelar-cgp-sui

Module 0xa5::its

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 0xa2::discovery;
use 0xa2::transaction;
use 0xa5::coin_info;
use 0xa5::coin_management;
use 0xa5::interchain_transfer_ticket;
use 0xa5::its_v0;
use 0xa5::owner_cap;
use 0xa5::token_id;
use 0xa5::trusted_addresses;
use 0xb0::version_control;

Resource ITS

struct ITS 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,
        its_v0::new(
            version_control(),
            ctx,
        ),
        ctx,
    );

    // Share the its object for anyone to use.
    transfer::share_object(ITS {
        id: object::new(ctx),
        inner,
    });

    transfer::public_transfer(
        owner_cap::create(ctx),
        ctx.sender(),
    )
}

Function register_coin

public fun register_coin<T>(self: &mut its::ITS, coin_info: coin_info::CoinInfo<T>, coin_management: coin_management::CoinManagement<T>): token_id::TokenId
Implementation
public fun register_coin<T>(
    self: &mut ITS,
    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: &its::ITS, token_id: token_id::TokenId, destination_chain: ascii::String): message_ticket::MessageTicket
Implementation
public fun deploy_remote_interchain_token<T>(
    self: &ITS,
    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 its::ITS, ticket: interchain_transfer_ticket::InterchainTransferTicket<T>, clock: &clock::Clock): message_ticket::MessageTicket
Implementation
public fun send_interchain_transfer<T>(
    self: &mut ITS,
    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 its::ITS, approved_message: channel::ApprovedMessage, clock: &clock::Clock, ctx: &mut tx_context::TxContext)
Implementation
public fun receive_interchain_transfer<T>(
    self: &mut ITS,
    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 its::ITS, 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 ITS,
    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 its::ITS, approved_message: channel::ApprovedMessage)
Implementation
public fun receive_deploy_interchain_token<T>(
    self: &mut ITS,
    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 its::ITS, treasury_cap: coin::TreasuryCap<T>, coin_metadata: coin::CoinMetadata<T>)
Implementation
public fun give_unregistered_coin<T>(
    self: &mut ITS,
    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 its::ITS, 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 ITS,
    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 its::ITS, 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 ITS,
    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 its::ITS, channel: &channel::Channel, token_id: token_id::TokenId, coin: coin::Coin<T>)
Implementation
public fun burn_as_distributor<T>(
    self: &mut ITS,
    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_trusted_addresses

public fun set_trusted_addresses(self: &mut its::ITS, _owner_cap: &owner_cap::OwnerCap, trusted_addresses: trusted_addresses::TrustedAddresses)
Implementation
public fun set_trusted_addresses(
    self: &mut ITS,
    _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 its::ITS, _owner_cap: &owner_cap::OwnerCap, chain_names: vector<ascii::String>)
Implementation
public fun remove_trusted_addresses(
    self: &mut ITS,
    _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: &its::ITS, token_id: token_id::TokenId): &type_name::TypeName
Implementation
public fun registered_coin_type(self: &ITS, token_id: TokenId): &TypeName {
    self.package_value().registered_coin_type(token_id)
}

Function channel_address

public fun channel_address(self: &its::ITS): address
Implementation
public fun channel_address(self: &ITS): address {
    self.package_value().channel_address()
}

Function package_value

public(friend) fun package_value(self: &its::ITS): &its_v0::ITS_v0
Implementation
public(package) fun package_value(self: &ITS): &ITS_v0 {
    self.inner.load_value<ITS_v0>()
}

Function register_transaction

public(friend) fun register_transaction(self: &mut its::ITS, discovery: &mut discovery::RelayerDiscovery, transaction: transaction::Transaction)
Implementation
public(package) fun register_transaction(
    self: &mut ITS,
    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"register_transaction",
        ].map!(|function_name| function_name.to_ascii_string()),
    ])
}