Trait pallet_asset_conversion::SwapCredit
source · pub trait SwapCredit<AccountId> {
type Balance: Balance;
type AssetKind;
type Credit;
// Required methods
fn max_path_len() -> u32;
fn swap_exact_tokens_for_tokens(
path: Vec<Self::AssetKind>,
credit_in: Self::Credit,
amount_out_min: Option<Self::Balance>,
) -> Result<Self::Credit, (Self::Credit, DispatchError)>;
fn swap_tokens_for_exact_tokens(
path: Vec<Self::AssetKind>,
credit_in: Self::Credit,
amount_out: Self::Balance,
) -> Result<(Self::Credit, Self::Credit), (Self::Credit, DispatchError)>;
}
Expand description
Trait 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(
path: Vec<Self::AssetKind>,
credit_in: Self::Credit,
amount_out_min: Option<Self::Balance>,
) -> Result<Self::Credit, (Self::Credit, DispatchError)>
fn swap_exact_tokens_for_tokens( path: Vec<Self::AssetKind>, credit_in: Self::Credit, amount_out_min: Option<Self::Balance>, ) -> Result<Self::Credit, (Self::Credit, DispatchError)>
Swap exactly credit_in
of asset path[0]
for asset path[last]
. If amount_out_min
is
provided and the swap can’t achieve at least this amount, an error is returned.
On a successful swap, the function returns the credit_out
of path[last]
obtained from
the credit_in
. On failure, it returns an Err
containing the original credit_in
and the
associated error code.
This operation is expected to be atomic.
sourcefn swap_tokens_for_exact_tokens(
path: Vec<Self::AssetKind>,
credit_in: Self::Credit,
amount_out: Self::Balance,
) -> Result<(Self::Credit, Self::Credit), (Self::Credit, DispatchError)>
fn swap_tokens_for_exact_tokens( path: Vec<Self::AssetKind>, credit_in: Self::Credit, amount_out: Self::Balance, ) -> Result<(Self::Credit, Self::Credit), (Self::Credit, DispatchError)>
Swaps a portion of credit_in
of path[0]
asset to obtain the desired amount_out
of
the path[last]
asset. The provided credit_in
must be adequate to achieve the target
amount_out
, or an error will occur.
On success, the function returns a (credit_out
, credit_change
) tuple, where credit_out
represents the acquired amount of the path[last]
asset, and credit_change
is the
remaining portion from the credit_in
. On failure, an Err
with the initial credit_in
and error code is returned.
This operation is expected to be atomic.