Skip to content
Snippets Groups Projects
Unverified Commit effd4a97 authored by bgallois's avatar bgallois
Browse files

optimize TreasuryAccount

parent e88b9a4b
No related branches found
No related tags found
1 merge request!286Refactore Runtime handlers and providers
Pipeline #38574 passed
......@@ -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,
);
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment