Trait pallet_asset_conversion::Swap
source · pub trait Swap<AccountId> {
type Balance: Balance;
type AssetKind;
// Required methods
fn max_path_len() -> u32;
fn swap_exact_tokens_for_tokens(
sender: AccountId,
path: Vec<Self::AssetKind>,
amount_in: Self::Balance,
amount_out_min: Option<Self::Balance>,
send_to: AccountId,
keep_alive: bool,
) -> Result<Self::Balance, DispatchError>;
fn swap_tokens_for_exact_tokens(
sender: AccountId,
path: Vec<Self::AssetKind>,
amount_out: Self::Balance,
amount_in_max: Option<Self::Balance>,
send_to: AccountId,
keep_alive: bool,
) -> Result<Self::Balance, DispatchError>;
}
Expand description
Trait for providing methods to swap between the various asset classes.
Required Associated Types§
Required Methods§
sourcefn max_path_len() -> u32
fn max_path_len() -> u32
Returns the upper limit on the length of the swap path.
sourcefn swap_exact_tokens_for_tokens(
sender: AccountId,
path: Vec<Self::AssetKind>,
amount_in: Self::Balance,
amount_out_min: Option<Self::Balance>,
send_to: AccountId,
keep_alive: bool,
) -> Result<Self::Balance, DispatchError>
fn swap_exact_tokens_for_tokens( sender: AccountId, path: Vec<Self::AssetKind>, amount_in: Self::Balance, amount_out_min: Option<Self::Balance>, send_to: AccountId, keep_alive: bool, ) -> Result<Self::Balance, DispatchError>
Swap exactly amount_in
of asset path[0]
for asset path[last]
.
If an amount_out_min
is specified, it will return an error if it is unable to acquire
the amount desired.
Withdraws the path[0]
asset from sender
, deposits the path[last]
asset to send_to
,
respecting keep_alive
.
If successful, returns the amount of path[last]
acquired for the amount_in
.
This operation is expected to be atomic.
sourcefn swap_tokens_for_exact_tokens(
sender: AccountId,
path: Vec<Self::AssetKind>,
amount_out: Self::Balance,
amount_in_max: Option<Self::Balance>,
send_to: AccountId,
keep_alive: bool,
) -> Result<Self::Balance, DispatchError>
fn swap_tokens_for_exact_tokens( sender: AccountId, path: Vec<Self::AssetKind>, amount_out: Self::Balance, amount_in_max: Option<Self::Balance>, send_to: AccountId, keep_alive: bool, ) -> Result<Self::Balance, DispatchError>
Take the path[0]
asset and swap some amount for amount_out
of the path[last]
. If an
amount_in_max
is specified, it will return an error if acquiring amount_out
would be
too costly.
Withdraws path[0]
asset from sender
, deposits path[last]
asset to send_to
,
respecting keep_alive
.
If successful returns the amount of the path[0]
taken to provide path[last]
.
This operation is expected to be atomic.