Skip to content

Commit

Permalink
Burn fees and add to authors the tips
Browse files Browse the repository at this point in the history
  • Loading branch information
Moliholy committed Dec 11, 2024
1 parent b28543c commit aa7ae69
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 34 deletions.
27 changes: 11 additions & 16 deletions runtime/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ pub use fee::WeightToFee;

use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use cumulus_primitives_core::{AggregateMessageOrigin, AssetId, ParaId};
use frame_support::traits::fungible::Balanced;
use frame_support::traits::{
fungible, AsEnsureOriginWithArg, Imbalance, InstanceFilter, OnUnbalanced, WithdrawReasons,
fungible, AsEnsureOriginWithArg, InstanceFilter, OnUnbalanced, WithdrawReasons,
};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use sp_api::impl_runtime_apis;
Expand All @@ -40,7 +41,7 @@ use frame_support::{
parameter_types,
traits::{
fungible::HoldConsideration,
tokens::{imbalance::ResolveTo, PayFromAccount, UnityAssetBalanceConversion},
tokens::{PayFromAccount, UnityAssetBalanceConversion},
ConstU32, ConstU64, ConstU8, EitherOfDiverse, LinearStoragePrice,
},
weights::{ConstantMultiplier, Weight},
Expand All @@ -50,10 +51,8 @@ use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot, EnsureSigned, EnsureWithSuccess,
};
use pallet_collator_staking::StakingPotAccountId;
use pallet_dmarket::{Item, TradeParams};
use pallet_nfts::PalletFeatures;
use pallet_treasury::TreasuryAccountId;
use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
use polkadot_primitives::Moment;
pub use runtime_common::{
Expand Down Expand Up @@ -131,7 +130,7 @@ pub type Executive = frame_executive::Executive<
pub struct DealWithFees<R>(PhantomData<R>);
impl<R> OnUnbalanced<fungible::Credit<R::AccountId, pallet_balances::Pallet<R>>> for DealWithFees<R>
where
R: pallet_balances::Config + pallet_collator_staking::Config + pallet_treasury::Config,
R: pallet_balances::Config + pallet_authorship::Config,
AccountIdOf<R>: From<account::AccountId20> + Into<account::AccountId20>,
<R as frame_system::Config>::RuntimeEvent: From<pallet_balances::Event<R>>,
{
Expand All @@ -140,18 +139,14 @@ where
Item = fungible::Credit<R::AccountId, pallet_balances::Pallet<R>>,
>,
) {
if let Some(mut fees) = fees_then_tips.next() {
if let Some(tips) = fees_then_tips.next() {
tips.merge_into(&mut fees);
// We discard the fees, as they will get burned.
let _ = fees_then_tips.next();

// If there is a tip for the author we deliver it.
if let Some(tips) = fees_then_tips.next() {
if let Some(author) = <pallet_authorship::Pallet<R>>::author() {
let _ = <pallet_balances::Pallet<R>>::resolve(&author, tips);
}
// Half goes to the staking pot, and half to treasury.
let (staking_pot_fees, treasury_fees) = fees.ration(50, 50);
ResolveTo::<StakingPotAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(
staking_pot_fees,
);
ResolveTo::<TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(
treasury_fees,
);
}
}
}
Expand Down
29 changes: 11 additions & 18 deletions runtime/testnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ use sp_runtime::{
ApplyExtrinsicResult, ExtrinsicInclusionMode,
};

use pallet_treasury::TreasuryAccountId;
use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use frame_support::traits::{
fungible,
fungible::HoldConsideration,
tokens::{imbalance::ResolveTo, PayFromAccount, UnityAssetBalanceConversion},
AsEnsureOriginWithArg, Imbalance, InstanceFilter, LinearStoragePrice, OnUnbalanced,
WithdrawReasons,
fungible::{Balanced, HoldConsideration},
tokens::{PayFromAccount, UnityAssetBalanceConversion},
AsEnsureOriginWithArg, InstanceFilter, LinearStoragePrice, OnUnbalanced, WithdrawReasons,
};
use frame_support::{
construct_runtime, derive_impl,
Expand All @@ -51,7 +49,6 @@ use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot, EnsureSigned, EnsureWithSuccess,
};
use pallet_collator_staking::StakingPotAccountId;
use pallet_dmarket::{Item, TradeParams};
use pallet_nfts::PalletFeatures;
use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
Expand Down Expand Up @@ -148,7 +145,7 @@ pub type Executive = frame_executive::Executive<
pub struct DealWithFees<R>(PhantomData<R>);
impl<R> OnUnbalanced<fungible::Credit<R::AccountId, pallet_balances::Pallet<R>>> for DealWithFees<R>
where
R: pallet_balances::Config + pallet_collator_staking::Config + pallet_treasury::Config,
R: pallet_balances::Config + pallet_authorship::Config,
AccountIdOf<R>: From<account::AccountId20> + Into<account::AccountId20>,
<R as frame_system::Config>::RuntimeEvent: From<pallet_balances::Event<R>>,
{
Expand All @@ -157,18 +154,14 @@ where
Item = fungible::Credit<R::AccountId, pallet_balances::Pallet<R>>,
>,
) {
if let Some(mut fees) = fees_then_tips.next() {
if let Some(tips) = fees_then_tips.next() {
tips.merge_into(&mut fees);
// We discard the fees, as they will get burned.
let _ = fees_then_tips.next();

// If there is a tip for the author we deliver it.
if let Some(tips) = fees_then_tips.next() {
if let Some(author) = <pallet_authorship::Pallet<R>>::author() {
let _ = <pallet_balances::Pallet<R>>::resolve(&author, tips);
}
// Half goes to the staking pot, and half to treasury.
let (staking_pot_fees, treasury_fees) = fees.ration(50, 50);
ResolveTo::<StakingPotAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(
staking_pot_fees,
);
ResolveTo::<TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(
treasury_fees,
);
}
}
}
Expand Down

0 comments on commit aa7ae69

Please sign in to comment.