Refactor the asset-conversion-tx-payment pallet (#14558)

* Code refactoring

* Fix imports

* Typo

* Update frame/asset-conversion/src/types.rs

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

* Sync docs

---------

Co-authored-by: parity-processbot <>
Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
This commit is contained in:
Jegor Sidorenko
2023-07-13 15:44:05 +02:00
committed by GitHub
parent 5e7b27e98c
commit c4e880c155
7 changed files with 218 additions and 168 deletions
@@ -36,5 +36,5 @@ pub use hold::{
pub use imbalance::{Credit, Debt, HandleImbalanceDrop, Imbalance};
pub use lifetime::{Create, Destroy};
pub use regular::{
Balanced, DecreaseIssuance, Dust, IncreaseIssuance, Inspect, Mutate, SwapNative, Unbalanced,
Balanced, DecreaseIssuance, Dust, IncreaseIssuance, Inspect, Mutate, Unbalanced,
};
@@ -583,40 +583,3 @@ pub trait Balanced<AccountId>: Inspect<AccountId> + Unbalanced<AccountId> {
fn done_deposit(_asset: Self::AssetId, _who: &AccountId, _amount: Self::Balance) {}
fn done_withdraw(_asset: Self::AssetId, _who: &AccountId, _amount: Self::Balance) {}
}
/// Trait for providing methods to swap between the chain's native token and other asset classes.
pub trait SwapNative<Origin, AccountId, Balance, AssetBalance, AssetId> {
/// Take an `asset_id` and swap some amount for `amount_out` of the chain's native asset. If an
/// `amount_in_max` is specified, it will return an error if acquiring `amount_out` would be
/// too costly.
///
/// Withdraws `asset_id` from `sender`, deposits native asset to `send_to`, respecting
/// `keep_alive`.
///
/// If successful returns the amount of the `asset_id` taken to provide `amount_out`.
fn swap_tokens_for_exact_native(
sender: AccountId,
asset_id: AssetId,
amount_out: Balance,
amount_in_max: Option<AssetBalance>,
send_to: AccountId,
keep_alive: bool,
) -> Result<AssetBalance, DispatchError>;
/// Take an `asset_id` and swap `amount_in` of the chain's native asset for it. If an
/// `amount_out_min` is specified, it will return an error if it is unable to acquire the amount
/// desired.
///
/// Withdraws native asset from `sender`, deposits `asset_id` to `send_to`, respecting
/// `keep_alive`.
///
/// If successful, returns the amount of `asset_id` acquired for the `amount_in`.
fn swap_exact_native_for_tokens(
sender: AccountId,
asset_id: AssetId,
amount_in: Balance,
amount_out_min: Option<AssetBalance>,
send_to: AccountId,
keep_alive: bool,
) -> Result<AssetBalance, DispatchError>;
}