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