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§

source

type Balance: Balance

Measure units of the asset classes for swapping.

source

type AssetKind

Kind of assets that are going to be swapped.

Required Methods§

source

fn max_path_len() -> u32

Returns the upper limit on the length of the swap path.

source

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.

source

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.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T: Config> Swap<<T as Config>::AccountId> for Pallet<T>

§

type Balance = <T as Config>::Balance

§

type AssetKind = <T as Config>::AssetKind