mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 05:51:02 +00:00
Migrate fee payment from Currency to fungible (#2292)
Part of https://github.com/paritytech/polkadot-sdk/issues/226 Related https://github.com/paritytech/polkadot-sdk/issues/1833 - Deprecate `CurrencyAdapter` and introduce `FungibleAdapter` - Deprecate `ToStakingPot` and replace usage with `ResolveTo` - Required creating a new `StakingPotAccountId` struct that implements `TypedGet` for the staking pot account ID - Update parachain common utils `DealWithFees`, `ToAuthor` and `AssetsToBlockAuthor` implementations to use `fungible` - Update runtime XCM Weight Traders to use `ResolveTo` instead of `ToStakingPot` - Update runtime Transaction Payment pallets to use `FungibleAdapter` instead of `CurrencyAdapter` - [x] Blocked by https://github.com/paritytech/polkadot-sdk/pull/1296, needs the `Unbalanced::decrease_balance` fix
This commit is contained in:
@@ -83,10 +83,6 @@ type CurrencyOf<T> = <<T as Config>::Auctioneer as Auctioneer<BlockNumberFor<T>>
|
||||
type LeasePeriodOf<T> = <<T as Config>::Auctioneer as Auctioneer<BlockNumberFor<T>>>::LeasePeriod;
|
||||
type BalanceOf<T> = <CurrencyOf<T> as Currency<<T as frame_system::Config>::AccountId>>::Balance;
|
||||
|
||||
#[allow(dead_code)]
|
||||
type NegativeImbalanceOf<T> =
|
||||
<CurrencyOf<T> as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
|
||||
|
||||
type FundIndex = u32;
|
||||
|
||||
pub trait WeightInfo {
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
|
||||
//! Auxiliary `struct`/`enum`s for polkadot runtime.
|
||||
|
||||
use crate::NegativeImbalance;
|
||||
use frame_support::traits::{Currency, Imbalance, OnUnbalanced};
|
||||
use frame_support::traits::{
|
||||
fungible::{Balanced, Credit},
|
||||
tokens::imbalance::ResolveTo,
|
||||
Imbalance, OnUnbalanced,
|
||||
};
|
||||
use pallet_treasury::TreasuryAccountId;
|
||||
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
|
||||
use primitives::Balance;
|
||||
use sp_runtime::{traits::TryConvert, Perquintill, RuntimeDebug};
|
||||
@@ -25,28 +29,31 @@ use xcm::VersionedLocation;
|
||||
|
||||
/// Logic for the author to get a portion of fees.
|
||||
pub struct ToAuthor<R>(sp_std::marker::PhantomData<R>);
|
||||
impl<R> OnUnbalanced<NegativeImbalance<R>> for ToAuthor<R>
|
||||
impl<R> OnUnbalanced<Credit<R::AccountId, pallet_balances::Pallet<R>>> for ToAuthor<R>
|
||||
where
|
||||
R: pallet_balances::Config + pallet_authorship::Config,
|
||||
<R as frame_system::Config>::AccountId: From<primitives::AccountId>,
|
||||
<R as frame_system::Config>::AccountId: Into<primitives::AccountId>,
|
||||
{
|
||||
fn on_nonzero_unbalanced(amount: NegativeImbalance<R>) {
|
||||
fn on_nonzero_unbalanced(
|
||||
amount: Credit<<R as frame_system::Config>::AccountId, pallet_balances::Pallet<R>>,
|
||||
) {
|
||||
if let Some(author) = <pallet_authorship::Pallet<R>>::author() {
|
||||
<pallet_balances::Pallet<R>>::resolve_creating(&author, amount);
|
||||
let _ = <pallet_balances::Pallet<R>>::resolve(&author, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DealWithFees<R>(sp_std::marker::PhantomData<R>);
|
||||
impl<R> OnUnbalanced<NegativeImbalance<R>> for DealWithFees<R>
|
||||
impl<R> OnUnbalanced<Credit<R::AccountId, pallet_balances::Pallet<R>>> for DealWithFees<R>
|
||||
where
|
||||
R: pallet_balances::Config + pallet_treasury::Config + pallet_authorship::Config,
|
||||
pallet_treasury::Pallet<R>: OnUnbalanced<NegativeImbalance<R>>,
|
||||
R: pallet_balances::Config + pallet_authorship::Config + pallet_treasury::Config,
|
||||
<R as frame_system::Config>::AccountId: From<primitives::AccountId>,
|
||||
<R as frame_system::Config>::AccountId: Into<primitives::AccountId>,
|
||||
{
|
||||
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance<R>>) {
|
||||
fn on_unbalanceds<B>(
|
||||
mut fees_then_tips: impl Iterator<Item = Credit<R::AccountId, pallet_balances::Pallet<R>>>,
|
||||
) {
|
||||
if let Some(fees) = fees_then_tips.next() {
|
||||
// for fees, 80% to treasury, 20% to author
|
||||
let mut split = fees.ration(80, 20);
|
||||
@@ -54,8 +61,7 @@ where
|
||||
// for tips, if any, 100% to author
|
||||
tips.merge_into(&mut split.1);
|
||||
}
|
||||
use pallet_treasury::Pallet as Treasury;
|
||||
<Treasury<R> as OnUnbalanced<_>>::on_unbalanced(split.0);
|
||||
ResolveTo::<TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(split.0);
|
||||
<ToAuthor<R> as OnUnbalanced<_>>::on_unbalanced(split.1);
|
||||
}
|
||||
}
|
||||
@@ -366,8 +372,14 @@ mod tests {
|
||||
#[test]
|
||||
fn test_fees_and_tip_split() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let fee = Balances::issue(10);
|
||||
let tip = Balances::issue(20);
|
||||
let fee =
|
||||
<pallet_balances::Pallet<Test> as frame_support::traits::fungible::Balanced<
|
||||
AccountId,
|
||||
>>::issue(10);
|
||||
let tip =
|
||||
<pallet_balances::Pallet<Test> as frame_support::traits::fungible::Balanced<
|
||||
AccountId,
|
||||
>>::issue(20);
|
||||
|
||||
assert_eq!(Balances::free_balance(Treasury::account_id()), 0);
|
||||
assert_eq!(Balances::free_balance(TEST_ACCOUNT), 0);
|
||||
|
||||
@@ -63,6 +63,9 @@ pub use sp_runtime::BuildStorage;
|
||||
/// Implementations of some helper traits passed into runtime modules as associated types.
|
||||
pub use impls::ToAuthor;
|
||||
|
||||
#[deprecated(
|
||||
note = "Please use fungible::Credit instead. This type will be removed some time after March 2024."
|
||||
)]
|
||||
pub type NegativeImbalance<T> = <pallet_balances::Pallet<T> as Currency<
|
||||
<T as frame_system::Config>::AccountId,
|
||||
>>::NegativeImbalance;
|
||||
|
||||
Reference in New Issue
Block a user