mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 06:27:58 +00:00
Pay tx fee with assets by using the asset conversion pallet (#14340)
* Pay tx by swapping the assets * Change liquidity structure * Uncomment the event * Update frame/transaction-payment/asset-tx-payment/src/payment.rs Co-authored-by: Squirrel <gilescope@gmail.com> * New approach * Fix bounds * Clearer version * Change IsType with Into and From * Enable event * Check ED + fix the logic * Add temp comments * Rework the refund * Clean up * Improve readability * Getting closer * fix * Use fungible instead of Currency * Test account without ed * Final push * Fixed * Rename to pallet-asset-conversion-tx-payment * Bring back the old pallet * Update versions * Update docs * Update readme * Wrong readme updated * Revert back doc change * Fix import * Fix kitchensink * Fix * One more time.. * Wait pls * Update frame/asset-conversion/src/lib.rs Co-authored-by: Squirrel <gilescope@gmail.com> * Update frame/support/src/traits/tokens/fungibles/regular.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update docs/comments * Docs improvement * Update frame/transaction-payment/asset-conversion-tx-payment/src/lib.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update frame/transaction-payment/asset-conversion-tx-payment/src/lib.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update frame/transaction-payment/asset-conversion-tx-payment/src/lib.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update frame/transaction-payment/asset-conversion-tx-payment/src/lib.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Update frame/transaction-payment/asset-conversion-tx-payment/src/lib.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Payed -> paid * Docs * Update frame/transaction-payment/asset-conversion-tx-payment/README.md Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com> * Rewrite docs * Try to clean the deps * Add debug assert * Return back frame-benchmarking * Update cargo * Update frame/transaction-payment/asset-conversion-tx-payment/src/mock.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Rename * clearer error message * Docs for Pay by Swap (#14445) * docs * better error name * more comments * more docs on swap trait * Fix compile errors * Another fix * Refactoring * Update frame/transaction-payment/asset-conversion-tx-payment/src/payment.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * Emit an error if we fail to swap the refund back * Add integrity_test * Update frame/asset-conversion/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Fmt * Use defensive_ok_or * child PR: Tidy swap event (#14441) * Dedup raising swap event * use expect rather than unwrap * Additional checks for future defence. * cargo fmt * Update frame/asset-conversion/src/lib.rs Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> --------- Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> --------- Co-authored-by: Squirrel <gilescope@gmail.com> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -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, SwapForNative, Unbalanced,
|
||||
Balanced, DecreaseIssuance, Dust, IncreaseIssuance, Inspect, Mutate, SwapNative, Unbalanced,
|
||||
};
|
||||
|
||||
@@ -584,9 +584,16 @@ pub trait Balanced<AccountId>: Inspect<AccountId> + Unbalanced<AccountId> {
|
||||
fn done_withdraw(_asset: Self::AssetId, _who: &AccountId, _amount: Self::Balance) {}
|
||||
}
|
||||
|
||||
/// Use an on-chain exchange to convert the asset to the equivalent in native tokens.
|
||||
pub trait SwapForNative<Origin, AccountId, Balance, AssetBalance, AssetId> {
|
||||
// If successful returns the amount in native tokens.
|
||||
/// 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,
|
||||
@@ -595,4 +602,21 @@ pub trait SwapForNative<Origin, AccountId, Balance, AssetBalance, AssetId> {
|
||||
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>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user