Trait serai_dex_pallet::Swap
source · pub trait Swap<AccountId, Balance, MultiCoinId> {
// Required methods
fn swap_exact_tokens_for_tokens(
sender: AccountId,
path: Vec<MultiCoinId>,
amount_in: Balance,
amount_out_min: Option<Balance>,
send_to: AccountId,
) -> Result<Balance, DispatchError>;
fn swap_tokens_for_exact_tokens(
sender: AccountId,
path: Vec<MultiCoinId>,
amount_out: Balance,
amount_in_max: Option<Balance>,
send_to: AccountId,
) -> Result<Balance, DispatchError>;
}
Expand description
Trait for providing methods to swap between the various coin classes.
Required Methods§
sourcefn swap_exact_tokens_for_tokens(
sender: AccountId,
path: Vec<MultiCoinId>,
amount_in: Balance,
amount_out_min: Option<Balance>,
send_to: AccountId,
) -> Result<Balance, DispatchError>
fn swap_exact_tokens_for_tokens( sender: AccountId, path: Vec<MultiCoinId>, amount_in: Balance, amount_out_min: Option<Balance>, send_to: AccountId, ) -> Result<Balance, DispatchError>
Swap exactly amount_in
of coin path[0]
for coin path[1]
.
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]
coin from sender
, deposits the path[1]
coin to send_to
,
If successful, returns the amount of path[1]
acquired for the amount_in
.
sourcefn swap_tokens_for_exact_tokens(
sender: AccountId,
path: Vec<MultiCoinId>,
amount_out: Balance,
amount_in_max: Option<Balance>,
send_to: AccountId,
) -> Result<Balance, DispatchError>
fn swap_tokens_for_exact_tokens( sender: AccountId, path: Vec<MultiCoinId>, amount_out: Balance, amount_in_max: Option<Balance>, send_to: AccountId, ) -> Result<Balance, DispatchError>
Take the path[0]
coin and swap some amount for amount_out
of the path[1]
. If an
amount_in_max
is specified, it will return an error if acquiring amount_out
would be
too costly.
Withdraws path[0]
coin from sender
, deposits path[1]
coin to send_to
,
If successful returns the amount of the path[0]
taken to provide path[1]
.
Object Safety§
This trait is not object safe.