referrerpolicy=no-referrer-when-downgrade

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§

source

type Balance: Balance

Measure units of the asset classes for swapping.

source

type AssetKind

Kind of assets that are going to be swapped.

source

type Credit

Credit implying a negative imbalance in the system that can be placed into an account or alter the total supply.

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

source

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.

Object Safety§

This trait is not object safe.

Implementors§

source§

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

§

type Balance = <T as Config>::Balance

§

type AssetKind = <T as Config>::AssetKind

§

type Credit = Imbalance<<<T as Config>::Assets as Inspect<<T as Config>::AccountId>>::AssetId, <<T as Config>::Assets as Inspect<<T as Config>::AccountId>>::Balance, <<T as Config>::Assets as Balanced<<T as Config>::AccountId>>::OnDropCredit, <<T as Config>::Assets as Balanced<<T as Config>::AccountId>>::OnDropDebt>