Skip to content

Commit b9cdb62

Browse files
committed
treasury: redirect burns to DAP
1 parent eec29a6 commit b9cdb62

File tree

7 files changed

+42
-6
lines changed

7 files changed

+42
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cumulus/parachains/runtimes/assets/asset-hub-westend/src/governance/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl pallet_treasury::Config for Runtime {
131131
type RuntimeEvent = RuntimeEvent;
132132
type SpendPeriod = SpendPeriod;
133133
type Burn = Burn;
134-
type BurnDestination = ();
134+
type BurnDestination = pallet_dap::BurnToDap<Runtime, Balances>;
135135
type MaxApprovals = MaxApprovals;
136136
type WeightInfo = weights::pallet_treasury::WeightInfo<Runtime>;
137137
type SpendFunds = ();

substrate/frame/dap/src/lib.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use frame_support::{
3434
traits::{
3535
fungible::{Balanced, Credit, Inspect, Mutate},
3636
tokens::{FundingSink, FundingSource, Preservation},
37-
Imbalance, OnUnbalanced,
37+
Currency, Imbalance, OnUnbalanced,
3838
},
3939
PalletId,
4040
};
@@ -122,10 +122,11 @@ impl<T: Config> FundingSink<T::AccountId, BalanceOf<T>> for ReturnToDap<T> {
122122
}
123123

124124
/// Type alias for credit (negative imbalance - funds that were slashed/removed).
125+
/// This is for the `fungible::Balanced` trait as used by staking-async.
125126
pub type CreditOf<T> = Credit<<T as frame_system::Config>::AccountId, <T as Config>::Currency>;
126127

127-
/// Implementation of OnUnbalanced that deposits slashed funds into the DAP buffer.
128-
/// Use this as `type Slash = SlashToDap<Runtime>` in staking config.
128+
/// Implementation of OnUnbalanced for the fungible::Balanced trait.
129+
/// Use this as `type Slash = SlashToDap<Runtime>` in staking-async config.
129130
pub struct SlashToDap<T>(core::marker::PhantomData<T>);
130131

131132
impl<T: Config> OnUnbalanced<CreditOf<T>> for SlashToDap<T> {
@@ -143,6 +144,29 @@ impl<T: Config> OnUnbalanced<CreditOf<T>> for SlashToDap<T> {
143144
}
144145
}
145146

147+
/// Implementation of OnUnbalanced for the old Currency trait (still used by treasury).
148+
/// Use this as `type BurnDestination = BurnToDap<Runtime, Balances>` e.g. in treasury config.
149+
pub struct BurnToDap<T, C>(core::marker::PhantomData<(T, C)>);
150+
151+
impl<T, C> OnUnbalanced<C::NegativeImbalance> for BurnToDap<T, C>
152+
where
153+
T: Config,
154+
C: Currency<T::AccountId>,
155+
{
156+
fn on_nonzero_unbalanced(amount: C::NegativeImbalance) {
157+
let buffer = Pallet::<T>::buffer_account();
158+
let numeric_amount = amount.peek();
159+
160+
// Resolve the imbalance by depositing into the buffer account
161+
C::resolve_creating(&buffer, amount);
162+
163+
log::debug!(
164+
target: LOG_TARGET,
165+
"Deposited burn of {numeric_amount:?} to DAP buffer"
166+
);
167+
}
168+
}
169+
146170
#[cfg(test)]
147171
mod tests {
148172
use super::*;

substrate/frame/staking-async/runtimes/parachain/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ cumulus-primitives-aura = { workspace = true }
118118
cumulus-primitives-core = { workspace = true }
119119
cumulus-primitives-utility = { workspace = true }
120120
pallet-collator-selection = { workspace = true }
121+
pallet-dap = { workspace = true }
121122
pallet-message-queue = { workspace = true }
122123
parachain-info = { workspace = true }
123124
parachains-common = { workspace = true }
@@ -169,6 +170,7 @@ runtime-benchmarks = [
169170
"pallet-balances/runtime-benchmarks",
170171
"pallet-collator-selection/runtime-benchmarks",
171172
"pallet-conviction-voting/runtime-benchmarks",
173+
"pallet-dap/runtime-benchmarks",
172174
"pallet-delegated-staking/runtime-benchmarks",
173175
"pallet-election-provider-multi-block/runtime-benchmarks",
174176
"pallet-fast-unstake/runtime-benchmarks",
@@ -234,6 +236,7 @@ try-runtime = [
234236
"pallet-balances/try-runtime",
235237
"pallet-collator-selection/try-runtime",
236238
"pallet-conviction-voting/try-runtime",
239+
"pallet-dap/try-runtime",
237240
"pallet-delegated-staking/try-runtime",
238241
"pallet-election-provider-multi-block/try-runtime",
239242
"pallet-fast-unstake/try-runtime",
@@ -305,6 +308,7 @@ std = [
305308
"pallet-balances/std",
306309
"pallet-collator-selection/std",
307310
"pallet-conviction-voting/std",
311+
"pallet-dap/std",
308312
"pallet-delegated-staking/std",
309313
"pallet-election-provider-multi-block/std",
310314
"pallet-fast-unstake/std",

substrate/frame/staking-async/runtimes/parachain/src/governance/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl pallet_treasury::Config for Runtime {
138138
type RuntimeEvent = RuntimeEvent;
139139
type SpendPeriod = SpendPeriod;
140140
type Burn = Burn;
141-
type BurnDestination = ();
141+
type BurnDestination = pallet_dap::BurnToDap<Runtime, Balances>;
142142
type MaxApprovals = MaxApprovals;
143143
type WeightInfo = weights::pallet_treasury::WeightInfo<Runtime>;
144144
type SpendFunds = ();

substrate/frame/staking-async/runtimes/parachain/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,9 @@ construct_runtime!(
11961196
Treasury: pallet_treasury = 96,
11971197
AssetRate: pallet_asset_rate = 97,
11981198

1199+
// Dynamic Allocation Pool / Issuance buffer
1200+
Dap: pallet_dap = 98,
1201+
11991202
// Balances.
12001203
Vesting: pallet_vesting = 100,
12011204

substrate/frame/staking-async/runtimes/parachain/src/staking.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl pallet_staking_async::Config for Runtime {
432432
type RuntimeHoldReason = RuntimeHoldReason;
433433
type CurrencyToVote = sp_staking::currency_to_vote::SaturatingCurrencyToVote;
434434
type RewardRemainder = ();
435-
type Slash = ();
435+
type Slash = pallet_dap::SlashToDap<Runtime>;
436436
type Reward = ();
437437
type SessionsPerEra = SessionsPerEra;
438438
type BondingDuration = BondingDuration;
@@ -464,6 +464,10 @@ impl pallet_staking_async_rc_client::Config for Runtime {
464464
type MaxValidatorSetRetries = ConstU32<5>;
465465
}
466466

467+
impl pallet_dap::Config for Runtime {
468+
type Currency = Balances;
469+
}
470+
467471
parameter_types! {
468472
pub StakingXcmDestination: Location = Location::parent();
469473
}

0 commit comments

Comments
 (0)