diff --git a/runtime/common/src/handlers.rs b/runtime/common/src/handlers.rs index 11d54620946788232c47d7681782c22013f72b70..27200baecab1e63f4fe8401075b0cd999973e114 100644 --- a/runtime/common/src/handlers.rs +++ b/runtime/common/src/handlers.rs @@ -182,22 +182,24 @@ impl< } } -type CreditOf<Runtime, Balances> = - frame_support::traits::tokens::fungible::Credit<Runtime, Balances>; -pub struct HandleFees<Runtime, Balances>( - frame_support::pallet_prelude::PhantomData<Runtime>, +type CreditOf<T, Balances> = frame_support::traits::tokens::fungible::Credit<T, Balances>; +pub struct HandleFees<T, TreasuryAccount, Balances>( + frame_support::pallet_prelude::PhantomData<T>, + frame_support::pallet_prelude::PhantomData<TreasuryAccount>, frame_support::pallet_prelude::PhantomData<Balances>, ); -impl<Runtime, Balances> frame_support::traits::OnUnbalanced<CreditOf<Runtime::AccountId, Balances>> - for HandleFees<Runtime, Balances> +impl<T, TreasuryAccount, Balances> + frame_support::traits::OnUnbalanced<CreditOf<T::AccountId, Balances>> + for HandleFees<T, TreasuryAccount, Balances> where - Runtime: pallet_treasury::Config, - Balances: frame_support::traits::fungible::Balanced<Runtime::AccountId>, + T: frame_system::Config, + TreasuryAccount: Get<T::AccountId>, + Balances: frame_support::traits::fungible::Balanced<T::AccountId>, { - fn on_nonzero_unbalanced(amount: CreditOf<Runtime::AccountId, Balances>) { + fn on_nonzero_unbalanced(amount: CreditOf<T::AccountId, Balances>) { // fee is moved to treasury let _ = Balances::deposit( - &pallet_treasury::Pallet::<Runtime>::account_id(), + &TreasuryAccount::get(), amount.peek(), frame_support::traits::tokens::Precision::Exact, ); diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index f9bf0f1ce207f2f7277ae3dc3aef4b74720c584c..a5d56933c9423d115e60f3c7ae9b293776da4f60 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -105,30 +105,21 @@ macro_rules! pallets_config { impl pallet_duniter_account::Config for Runtime { // does currency adapter in any case, but adds "refund with quota" feature type InnerOnChargeTransaction = - FungibleAdapter<Balances, HandleFees<Runtime, Balances>>; + FungibleAdapter<Balances, HandleFees<Runtime, TreasuryAccount, Balances>>; type Refund = Quota; type RuntimeEvent = RuntimeEvent; type WeightInfo = weights::pallet_duniter_account::WeightInfo<Runtime>; } - // QUOTA // - pub struct TreasuryAccountId; - impl frame_support::pallet_prelude::Get<AccountId> for TreasuryAccountId { - fn get() -> AccountId { - // TODO optimize: make this a constant - // calling Treasury.account_id() actually requires computation - Treasury::account_id() - } - } parameter_types! { - pub const ReloadRate: BlockNumber = 1 * HOURS; // faster than DAYS - pub const MaxQuota: Balance = 1000; // 10 ÄžD - pub const MaxNominators: u32 = 64; - pub TreasuryAccount: AccountId = Treasury::account_id(); // TODO - } + pub const ReloadRate: BlockNumber = 1 * HOURS; // faster than DAYS + pub const MaxQuota: Balance = 1000; // 10 ÄžD + pub const MaxNominators: u32 = 64; + pub TreasuryAccount: AccountId = Treasury::account_id(); + } impl pallet_quota::Config for Runtime { type MaxQuota = MaxQuota; - type RefundAccount = TreasuryAccountId; + type RefundAccount = TreasuryAccount; type ReloadRate = ReloadRate; type RuntimeEvent = RuntimeEvent; type WeightInfo = weights::pallet_quota::WeightInfo<Runtime>; @@ -163,7 +154,7 @@ macro_rules! pallets_config { impl pallet_balances::Config for Runtime { type AccountStore = Account; type Balance = Balance; - type DustRemoval = HandleFees<Runtime, Balances>; + type DustRemoval = HandleFees<Runtime, TreasuryAccount, Balances>; type ExistentialDeposit = ExistentialDeposit; type FreezeIdentifier = (); type MaxFreezes = frame_support::pallet_prelude::ConstU32<0>; @@ -323,7 +314,7 @@ macro_rules! pallets_config { type GetCurrentEpochIndex = GetCurrentEpochIndex<Self>; type MaxRequests = frame_support::traits::ConstU32<100>; type OnFilledRandomness = (); - type OnUnbalanced = HandleFees<Runtime, Balances>; + type OnUnbalanced = HandleFees<Runtime, TreasuryAccount, Balances>; type ParentBlockRandomness = pallet_babe::ParentBlockRandomness<Self>; type RandomnessFromOneEpochAgo = pallet_babe::RandomnessFromOneEpochAgo<Self>; type RequestPrice = frame_support::traits::ConstU64<2_000>; @@ -498,7 +489,7 @@ macro_rules! pallets_config { type EvaluationPrice = frame_support::traits::ConstU64<1000>; type MaxRefereeDistance = MaxRefereeDistance; type MinAccessibleReferees = MinAccessibleReferees; - type OnUnbalanced = HandleFees<Runtime, Balances>; + type OnUnbalanced = HandleFees<Runtime, TreasuryAccount, Balances>; type OnValidDistanceStatus = Wot; type RuntimeEvent = RuntimeEvent; type RuntimeHoldReason = RuntimeHoldReason;