0xa6::transfers
SuiTransferSwapData
ItsTransferSwapData
new_sui_transfer_swap_data
new_its_transfer_swap_data
sui_estimate
its_estimate
sui_transfer
its_transfer
sui_estimate_move_call
its_estimate_move_call
sui_transfer_move_call
its_transfer_move_call
use 0x1::ascii;
use 0x1::option;
use 0x1::type_name;
use 0x2::balance;
use 0x2::bcs;
use 0x2::clock;
use 0x2::coin;
use 0x2::transfer;
use 0x2::tx_context;
use 0x2::versioned;
use 0xa1::channel;
use 0xa1::gateway;
use 0xa1::message_ticket;
use 0xa5::interchain_token_service;
use 0xa5::interchain_transfer_ticket;
use 0xa5::token_id;
use 0xa6::coin_bag;
use 0xa6::squid;
use 0xa6::squid_v0;
use 0xa6::swap_info;
use 0xa6::swap_type;
use 0xaa::transaction;
use 0xb0::version_control;
SuiTransferSwapData
fallback states whether this transfer happens normally or only on fallback mode.
struct SuiTransferSwapData has drop
swap_type: swap_type::SwapType
coin_type: ascii::String
recipient: address
fallback: bool
ItsTransferSwapData
fallback states whether this transfer happens normally or only on fallback mode.
struct ItsTransferSwapData has drop
swap_type: swap_type::SwapType
coin_type: ascii::String
token_id: token_id::TokenId
destination_chain: ascii::String
destination_address: vector<u8>
metadata: vector<u8>
fallback: bool
#[error]
const EWrongCoinType: vector<u8> = b"expected coin type does not match type argument";
#[error]
const EWrongSwapType: vector<u8> = b"wrong swap type";
new_sui_transfer_swap_data
fun new_sui_transfer_swap_data(bcs: &mut bcs::BCS): transfers::SuiTransferSwapData
fun new_sui_transfer_swap_data(bcs: &mut BCS): SuiTransferSwapData {
SuiTransferSwapData {
swap_type: swap_type::peel(bcs),
coin_type: ascii::string(bcs.peel_vec_u8()),
recipient: bcs.peel_address(),
fallback: bcs.peel_bool(),
}
}
new_its_transfer_swap_data
fun new_its_transfer_swap_data(bcs: &mut bcs::BCS): transfers::ItsTransferSwapData
fun new_its_transfer_swap_data(bcs: &mut BCS): ItsTransferSwapData {
ItsTransferSwapData {
swap_type: swap_type::peel(bcs),
coin_type: ascii::string(bcs.peel_vec_u8()),
token_id: token_id::from_address(bcs.peel_address()),
destination_chain: ascii::string(bcs.peel_vec_u8()),
destination_address: bcs.peel_vec_u8(),
metadata: bcs.peel_vec_u8(),
fallback: bcs.peel_bool(),
}
}
sui_estimate
public fun sui_estimate<T>(swap_info: &mut swap_info::SwapInfo)
public fun sui_estimate<T>(swap_info: &mut SwapInfo) {
let (data, fallback) = swap_info.data_estimating();
if (fallback) return;
let swap_data = peel!(data, |data| new_sui_transfer_swap_data(data));
assert!(swap_data.swap_type == swap_type::sui_transfer(), EWrongSwapType);
assert!(
&swap_data.coin_type == &type_name::get<T>().into_string(),
EWrongCoinType,
);
swap_info.coin_bag().estimate<T>();
}
its_estimate
public fun its_estimate<T>(swap_info: &mut swap_info::SwapInfo)
public fun its_estimate<T>(swap_info: &mut SwapInfo) {
let (data, fallback) = swap_info.data_estimating();
if (fallback) return;
let swap_data = peel!(data, |data| new_its_transfer_swap_data(data));
assert!(swap_data.swap_type == swap_type::its_transfer(), EWrongSwapType);
assert!(
&swap_data.coin_type == &type_name::get<T>().into_string(),
EWrongCoinType,
);
swap_info.coin_bag().estimate<T>();
}
sui_transfer
public fun sui_transfer<T>(swap_info: &mut swap_info::SwapInfo, ctx: &mut tx_context::TxContext)
public fun sui_transfer<T>(swap_info: &mut SwapInfo, ctx: &mut TxContext) {
let (data, fallback) = swap_info.data_swapping();
let swap_data = peel!(data, |data| new_sui_transfer_swap_data(data));
// This check allows to skip the transfer if the `fallback` state does not
// match the state of the transaction here.
if (fallback != swap_data.fallback) return;
assert!(swap_data.swap_type == swap_type::sui_transfer(), EWrongSwapType);
assert!(
&swap_data.coin_type == &type_name::get<T>().into_string(),
EWrongCoinType,
);
let option = swap_info.coin_bag().balance<T>();
if (option.is_none()) {
option.destroy_none();
return
};
transfer::public_transfer(
coin::from_balance(option.destroy_some(), ctx),
swap_data.recipient,
);
}
its_transfer
public fun its_transfer<T>(swap_info: &mut swap_info::SwapInfo, squid: &squid::Squid, its: &mut interchain_token_service::InterchainTokenService, gateway: &gateway::Gateway, clock: &clock::Clock, ctx: &mut tx_context::TxContext)
public fun its_transfer<T>(
swap_info: &mut SwapInfo,
squid: &Squid,
its: &mut InterchainTokenService,
gateway: &Gateway,
clock: &Clock,
ctx: &mut TxContext,
) {
let value = squid.value!(b"its_transfer");
let (data, fallback) = swap_info.data_swapping();
if (data.length() == 0) return;
let swap_data = peel!(data, |data| new_its_transfer_swap_data(data));
// This check allows to skip the transfer if the `fallback` state does not
// match the state of the transaction here.
if (fallback != swap_data.fallback) return;
assert!(swap_data.swap_type == swap_type::its_transfer(), EWrongSwapType);
assert!(
&swap_data.coin_type == &type_name::get<T>().into_string(),
EWrongCoinType,
);
let option = swap_info.coin_bag().balance<T>();
if (option.is_none()) {
option.destroy_none();
return
};
let interchain_transfer_ticket = interchain_token_service::prepare_interchain_transfer(
swap_data.token_id,
coin::from_balance(option.destroy_some(), ctx),
swap_data.destination_chain,
swap_data.destination_address,
swap_data.metadata,
value.channel(),
);
let message_ticket = its.send_interchain_transfer(
interchain_transfer_ticket,
clock,
);
gateway.send_message(message_ticket);
}
sui_estimate_move_call
public(friend) fun sui_estimate_move_call(package_id: address, bcs: bcs::BCS, swap_info_arg: vector<u8>): transaction::MoveCall
public(package) fun sui_estimate_move_call(
package_id: address,
mut bcs: BCS,
swap_info_arg: vector<u8>,
): MoveCall {
let type_arg = ascii::string(bcs.peel_vec_u8());
transaction::new_move_call(
transaction::new_function(
package_id,
ascii::string(b"transfers"),
ascii::string(b"sui_estimate"),
),
vector[swap_info_arg],
vector[type_arg],
)
}
its_estimate_move_call
public(friend) fun its_estimate_move_call(package_id: address, bcs: bcs::BCS, swap_info_arg: vector<u8>): transaction::MoveCall
public(package) fun its_estimate_move_call(
package_id: address,
mut bcs: BCS,
swap_info_arg: vector<u8>,
): MoveCall {
let type_arg = ascii::string(bcs.peel_vec_u8());
transaction::new_move_call(
transaction::new_function(
package_id,
ascii::string(b"transfers"),
ascii::string(b"its_estimate"),
),
vector[swap_info_arg],
vector[type_arg],
)
}
sui_transfer_move_call
public(friend) fun sui_transfer_move_call(package_id: address, bcs: bcs::BCS, swap_info_arg: vector<u8>): transaction::MoveCall
public(package) fun sui_transfer_move_call(
package_id: address,
mut bcs: BCS,
swap_info_arg: vector<u8>,
): MoveCall {
let type_arg = ascii::string(bcs.peel_vec_u8());
transaction::new_move_call(
transaction::new_function(
package_id,
ascii::string(b"transfers"),
ascii::string(b"sui_transfer"),
),
vector[swap_info_arg],
vector[type_arg],
)
}
its_transfer_move_call
public(friend) fun its_transfer_move_call(package_id: address, bcs: bcs::BCS, swap_info_arg: vector<u8>, squid_arg: vector<u8>, its_arg: vector<u8>, gateway_arg: vector<u8>): transaction::MoveCall
public(package) fun its_transfer_move_call(
package_id: address,
mut bcs: BCS,
swap_info_arg: vector<u8>,
squid_arg: vector<u8>,
its_arg: vector<u8>,
gateway_arg: vector<u8>,
): MoveCall {
let type_arg = ascii::string(bcs.peel_vec_u8());
transaction::new_move_call(
transaction::new_function(
package_id,
ascii::string(b"transfers"),
ascii::string(b"its_transfer"),
),
vector[swap_info_arg, squid_arg, its_arg, gateway_arg, vector[0, 6]],
vector[type_arg],
)
}