Trait frame_support::traits::tokens::fungibles::SwapNative
source · pub trait SwapNative<Origin, AccountId, Balance, AssetBalance, AssetId> {
// Required methods
fn swap_tokens_for_exact_native(
sender: AccountId,
asset_id: AssetId,
amount_out: Balance,
amount_in_max: Option<AssetBalance>,
send_to: AccountId,
keep_alive: bool,
) -> Result<AssetBalance, DispatchError>;
fn swap_exact_native_for_tokens(
sender: AccountId,
asset_id: AssetId,
amount_in: Balance,
amount_out_min: Option<AssetBalance>,
send_to: AccountId,
keep_alive: bool,
) -> Result<AssetBalance, DispatchError>;
}
Expand description
Trait for providing methods to swap between the chain’s native token and other asset classes.
Required Methods§
sourcefn swap_tokens_for_exact_native(
sender: AccountId,
asset_id: AssetId,
amount_out: Balance,
amount_in_max: Option<AssetBalance>,
send_to: AccountId,
keep_alive: bool,
) -> Result<AssetBalance, DispatchError>
fn swap_tokens_for_exact_native( sender: AccountId, asset_id: AssetId, amount_out: Balance, amount_in_max: Option<AssetBalance>, send_to: AccountId, keep_alive: bool, ) -> Result<AssetBalance, DispatchError>
Take an asset_id
and swap some amount for amount_out
of the chain’s native asset. If an
amount_in_max
is specified, it will return an error if acquiring amount_out
would be
too costly.
Withdraws asset_id
from sender
, deposits native asset to send_to
, respecting
keep_alive
.
If successful returns the amount of the asset_id
taken to provide amount_out
.
sourcefn swap_exact_native_for_tokens(
sender: AccountId,
asset_id: AssetId,
amount_in: Balance,
amount_out_min: Option<AssetBalance>,
send_to: AccountId,
keep_alive: bool,
) -> Result<AssetBalance, DispatchError>
fn swap_exact_native_for_tokens( sender: AccountId, asset_id: AssetId, amount_in: Balance, amount_out_min: Option<AssetBalance>, send_to: AccountId, keep_alive: bool, ) -> Result<AssetBalance, DispatchError>
Take an asset_id
and swap amount_in
of the chain’s native asset for it. If an
amount_out_min
is specified, it will return an error if it is unable to acquire the amount
desired.
Withdraws native asset from sender
, deposits asset_id
to send_to
, respecting
keep_alive
.
If successful, returns the amount of asset_id
acquired for the amount_in
.