referrerpolicy=no-referrer-when-downgrade
pallet_asset_conversion

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

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> SwapCredit<<T as Config>::AccountId> for Pallet<T>

Source§

type Balance = <T as Config>::Balance

Source§

type AssetKind = <T as Config>::AssetKind

Source§

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>