referrerpolicy=no-referrer-when-downgrade

Trait 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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

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