referrerpolicy=no-referrer-when-downgrade

pallet_bounties/
lib.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! # Bounties Module ( pallet-bounties )
19//!
20//! ## Bounty
21//!
22//! > NOTE: This pallet is tightly coupled with pallet-treasury.
23//!
24//! A Bounty Spending is a reward for a specified body of work - or specified set of objectives -
25//! that needs to be executed for a predefined Treasury amount to be paid out. A curator is assigned
26//! after the bounty is approved and funded by Council, to be delegated with the responsibility of
27//! assigning a payout address once the specified set of objectives is completed.
28//!
29//! After the Council has activated a bounty, it delegates the work that requires expertise to a
30//! curator in exchange of a deposit. Once the curator accepts the bounty, they get to close the
31//! active bounty. Closing the active bounty enacts a delayed payout to the payout address, the
32//! curator fee and the return of the curator deposit. The delay allows for intervention through
33//! regular democracy. The Council gets to unassign the curator, resulting in a new curator
34//! election. The Council also gets to cancel the bounty if deemed necessary before assigning a
35//! curator or once the bounty is active or payout is pending, resulting in the slash of the
36//! curator's deposit.
37//!
38//! This pallet may opt into using a [`ChildBountyManager`] that enables bounties to be split into
39//! sub-bounties, as children of an established bounty (called the parent in the context of it's
40//! children).
41//!
42//! > NOTE: The parent bounty cannot be closed if it has a non-zero number of it has active child
43//! > bounties associated with it.
44//!
45//! ### Terminology
46//!
47//! Bounty:
48//!
49//! - **Bounty spending proposal:** A proposal to reward a predefined body of work upon completion
50//!   by the Treasury.
51//! - **Proposer:** An account proposing a bounty spending.
52//! - **Curator:** An account managing the bounty and assigning a payout address receiving the
53//!   reward for the completion of work.
54//! - **Deposit:** The amount held on deposit for placing a bounty proposal plus the amount held on
55//!   deposit per byte within the bounty description.
56//! - **Curator deposit:** The payment from a candidate willing to curate an approved bounty. The
57//!   deposit is returned when/if the bounty is completed.
58//! - **Bounty value:** The total amount that should be paid to the Payout Address if the bounty is
59//!   rewarded.
60//! - **Payout address:** The account to which the total or part of the bounty is assigned to.
61//! - **Payout Delay:** The delay period for which a bounty beneficiary needs to wait before
62//!   claiming.
63//! - **Curator fee:** The reserved upfront payment for a curator for work related to the bounty.
64//!
65//! ## Interface
66//!
67//! ### Dispatchable Functions
68//!
69//! Bounty protocol:
70//!
71//! - `propose_bounty` - Propose a specific treasury amount to be earmarked for a predefined set of
72//!   tasks and stake the required deposit.
73//! - `approve_bounty` - Accept a specific treasury amount to be earmarked for a predefined body of
74//!   work.
75//! - `propose_curator` - Assign an account to a bounty as candidate curator.
76//! - `approve_bounty_with_curator` - Accept a specific treasury amount for a predefined body of
77//!   work with assigned candidate curator account.
78//! - `accept_curator` - Accept a bounty assignment from the Council, setting a curator deposit.
79//! - `extend_bounty_expiry` - Extend the expiry block number of the bounty and stay active.
80//! - `award_bounty` - Close and pay out the specified amount for the completed work.
81//! - `claim_bounty` - Claim a specific bounty amount from the Payout Address.
82//! - `unassign_curator` - Unassign an accepted curator from a specific earmark.
83//! - `close_bounty` - Cancel the earmark for a specific treasury amount and close the bounty.
84
85#![recursion_limit = "512"]
86#![cfg_attr(not(feature = "std"), no_std)]
87
88#[cfg(feature = "runtime-benchmarks")]
89mod benchmarking;
90pub mod migrations;
91mod tests;
92pub mod weights;
93
94extern crate alloc;
95
96use alloc::vec::Vec;
97
98use frame_support::traits::{
99	fungibles::{Inspect as FungiblesInspect, Mutate as FungiblesMutate},
100	tokens::{Fortitude, Preservation},
101	Currency,
102	ExistenceRequirement::AllowDeath,
103	Get, Imbalance, OnUnbalanced, ReservableCurrency,
104};
105
106use sp_runtime::{
107	traits::{AccountIdConversion, BadOrigin, BlockNumberProvider, Saturating, StaticLookup, Zero},
108	Debug, DispatchResult, Permill,
109};
110
111use frame_support::{
112	dispatch::DispatchResultWithPostInfo, pallet_prelude::*, traits::EnsureOrigin,
113};
114use frame_system::pallet_prelude::{
115	ensure_signed, BlockNumberFor as SystemBlockNumberFor, OriginFor,
116};
117use scale_info::TypeInfo;
118pub use weights::WeightInfo;
119
120pub use pallet::*;
121
122type BalanceOf<T, I = ()> = pallet_treasury::BalanceOf<T, I>;
123
124type PositiveImbalanceOf<T, I = ()> = pallet_treasury::PositiveImbalanceOf<T, I>;
125
126/// An index of a bounty. Just a `u32`.
127pub type BountyIndex = u32;
128
129type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
130
131type BlockNumberFor<T, I = ()> =
132	<<T as pallet_treasury::Config<I>>::BlockNumberProvider as BlockNumberProvider>::BlockNumber;
133
134/// A bounty proposal.
135#[derive(
136	Encode, Decode, DecodeWithMemTracking, Clone, PartialEq, Eq, Debug, TypeInfo, MaxEncodedLen,
137)]
138pub struct Bounty<AccountId, Balance, BlockNumber> {
139	/// The account proposing it.
140	pub proposer: AccountId,
141	/// The (total) amount that should be paid if the bounty is rewarded.
142	pub value: Balance,
143	/// The curator fee. Included in value.
144	pub fee: Balance,
145	/// The deposit of curator.
146	pub curator_deposit: Balance,
147	/// The amount held on deposit (reserved) for making this proposal.
148	bond: Balance,
149	/// The status of this bounty.
150	status: BountyStatus<AccountId, BlockNumber>,
151}
152
153impl<AccountId: PartialEq + Clone + Ord, Balance, BlockNumber: Clone>
154	Bounty<AccountId, Balance, BlockNumber>
155{
156	/// Getter for bounty status, to be used for child bounties.
157	pub fn get_status(&self) -> BountyStatus<AccountId, BlockNumber> {
158		self.status.clone()
159	}
160}
161
162/// The status of a bounty proposal.
163#[derive(
164	Encode, Decode, DecodeWithMemTracking, Clone, PartialEq, Eq, Debug, TypeInfo, MaxEncodedLen,
165)]
166pub enum BountyStatus<AccountId, BlockNumber> {
167	/// The bounty is proposed and waiting for approval.
168	Proposed,
169	/// The bounty is approved and waiting to become active at next spend period.
170	Approved,
171	/// The bounty is funded and waiting for curator assignment.
172	Funded,
173	/// A curator has been proposed. Waiting for acceptance from the curator.
174	CuratorProposed {
175		/// The assigned curator of this bounty.
176		curator: AccountId,
177	},
178	/// The bounty is active and waiting to be awarded.
179	Active {
180		/// The curator of this bounty.
181		curator: AccountId,
182		/// An update from the curator is due by this block, else they are considered inactive.
183		update_due: BlockNumber,
184	},
185	/// The bounty is awarded and waiting to released after a delay.
186	PendingPayout {
187		/// The curator of this bounty.
188		curator: AccountId,
189		/// The beneficiary of the bounty.
190		beneficiary: AccountId,
191		/// When the bounty can be claimed.
192		unlock_at: BlockNumber,
193	},
194	/// The bounty is approved with curator assigned.
195	ApprovedWithCurator {
196		/// The assigned curator of this bounty.
197		curator: AccountId,
198	},
199}
200
201/// The child bounty manager.
202pub trait ChildBountyManager<Balance> {
203	/// Get the active child bounties for a parent bounty.
204	fn child_bounties_count(bounty_id: BountyIndex) -> BountyIndex;
205
206	/// Take total curator fees of children-bounty curators.
207	fn children_curator_fees(bounty_id: BountyIndex) -> Balance;
208
209	/// Hook called when a parent bounty is removed.
210	fn bounty_removed(bounty_id: BountyIndex);
211}
212
213/// Transfer all assets that an account holds.
214pub trait TransferAllAssets<AccountId> {
215	/// Transfer all assets from one account to another.
216	///
217	/// This will possibly dust and reap the origin account and endow the receiver.
218	fn force_transfer_all_assets(from: &AccountId, to: &AccountId) -> DispatchResult;
219}
220
221impl<AccountId> TransferAllAssets<AccountId> for () {
222	fn force_transfer_all_assets(_: &AccountId, _: &AccountId) -> DispatchResult {
223		Ok(())
224	}
225}
226
227/// Transfer all `RelevantAssets` of the `Fungibles` from one account to another.
228///
229/// The native asset should be the first in the list of `RelevantAssets`, otherwise the transfers
230/// of the other maybe fails.
231pub struct TransferAllFungibles<AccountId, Fungibles, RelevantAssets>(
232	core::marker::PhantomData<(AccountId, Fungibles, RelevantAssets)>,
233);
234impl<AccountId, Fungibles, RelevantAssets> TransferAllAssets<AccountId>
235	for TransferAllFungibles<AccountId, Fungibles, RelevantAssets>
236where
237	Fungibles: FungiblesMutate<AccountId>,
238	RelevantAssets: Get<Vec<<Fungibles as FungiblesInspect<AccountId>>::AssetId>>,
239	AccountId: Eq,
240{
241	fn force_transfer_all_assets(from: &AccountId, to: &AccountId) -> DispatchResult {
242		// We iterate through all assets twice in case that the Native asset was not last in the
243		// list and ED remained because of an insufficient asset at the end of the list.
244		let assets_twice =
245			RelevantAssets::get().into_iter().chain(RelevantAssets::get().into_iter());
246
247		for id in assets_twice {
248			let balance = Fungibles::reducible_balance(
249				id.clone(),
250				from,
251				Preservation::Expendable,
252				Fortitude::Force,
253			);
254			if balance.is_zero() {
255				continue;
256			}
257
258			// Ignore errors since this can only fail if the receiver does not exist.
259			let _ = Fungibles::transfer(id, from, to, balance, Preservation::Expendable);
260		}
261		Ok(())
262	}
263}
264
265#[frame_support::pallet]
266pub mod pallet {
267	use super::*;
268
269	const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);
270
271	#[pallet::pallet]
272	#[pallet::storage_version(STORAGE_VERSION)]
273	pub struct Pallet<T, I = ()>(_);
274
275	#[pallet::config]
276	pub trait Config<I: 'static = ()>: frame_system::Config + pallet_treasury::Config<I> {
277		/// The amount held on deposit for placing a bounty proposal.
278		#[pallet::constant]
279		type BountyDepositBase: Get<BalanceOf<Self, I>>;
280
281		/// The delay period for which a bounty beneficiary need to wait before claim the payout.
282		#[pallet::constant]
283		type BountyDepositPayoutDelay: Get<BlockNumberFor<Self, I>>;
284
285		/// The time limit for a curator to act before a bounty expires.
286		///
287		/// The period that starts when a curator is approved, during which they must execute or
288		/// update the bounty via `extend_bounty_expiry`. If missed, the bounty expires, and the
289		/// curator may be slashed. If `BlockNumberFor::MAX`, bounties stay active indefinitely,
290		/// removing the need for `extend_bounty_expiry`.
291		#[pallet::constant]
292		type BountyUpdatePeriod: Get<BlockNumberFor<Self, I>>;
293
294		/// The curator deposit is calculated as a percentage of the curator fee.
295		///
296		/// This deposit has optional upper and lower bounds with `CuratorDepositMax` and
297		/// `CuratorDepositMin`.
298		#[pallet::constant]
299		type CuratorDepositMultiplier: Get<Permill>;
300
301		/// Maximum amount of funds that should be placed in a deposit for making a proposal.
302		#[pallet::constant]
303		type CuratorDepositMax: Get<Option<BalanceOf<Self, I>>>;
304
305		/// Minimum amount of funds that should be placed in a deposit for making a proposal.
306		#[pallet::constant]
307		type CuratorDepositMin: Get<Option<BalanceOf<Self, I>>>;
308
309		/// Minimum value for a bounty.
310		#[pallet::constant]
311		type BountyValueMinimum: Get<BalanceOf<Self, I>>;
312
313		/// The amount held on deposit per byte within the tip report reason or bounty description.
314		#[pallet::constant]
315		type DataDepositPerByte: Get<BalanceOf<Self, I>>;
316
317		/// The overarching event type.
318		#[allow(deprecated)]
319		type RuntimeEvent: From<Event<Self, I>>
320			+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
321
322		/// Maximum acceptable reason length.
323		///
324		/// Benchmarks depend on this value, be sure to update weights file when changing this value
325		#[pallet::constant]
326		type MaximumReasonLength: Get<u32>;
327
328		/// Weight information for extrinsics in this pallet.
329		type WeightInfo: WeightInfo;
330
331		/// The child bounty manager.
332		type ChildBountyManager: ChildBountyManager<BalanceOf<Self, I>>;
333
334		/// Handler for the unbalanced decrease when slashing for a rejected bounty.
335		type OnSlash: OnUnbalanced<pallet_treasury::NegativeImbalanceOf<Self, I>>;
336
337		/// Means to transfer all assets from one account to another.
338		///
339		/// This is only used for bounty closure to ensure that all assets are returned to the
340		/// treasury.
341		type TransferAllAssets: TransferAllAssets<Self::AccountId>;
342	}
343
344	#[pallet::error]
345	pub enum Error<T, I = ()> {
346		/// Proposer's balance is too low.
347		InsufficientProposersBalance,
348		/// No proposal or bounty at that index.
349		InvalidIndex,
350		/// The reason given is just too big.
351		ReasonTooBig,
352		/// The bounty status is unexpected.
353		UnexpectedStatus,
354		/// Require bounty curator.
355		RequireCurator,
356		/// Invalid bounty value.
357		InvalidValue,
358		/// Invalid bounty fee.
359		InvalidFee,
360		/// A bounty payout is pending.
361		/// To cancel the bounty, you must unassign and slash the curator.
362		PendingPayout,
363		/// The bounties cannot be claimed/closed because it's still in the countdown period.
364		Premature,
365		/// The bounty cannot be closed because it has active child bounties.
366		HasActiveChildBounty,
367		/// Too many approvals are already queued.
368		TooManyQueued,
369		/// User is not the proposer of the bounty.
370		NotProposer,
371	}
372
373	#[pallet::event]
374	#[pallet::generate_deposit(pub(super) fn deposit_event)]
375	pub enum Event<T: Config<I>, I: 'static = ()> {
376		/// New bounty proposal.
377		BountyProposed { index: BountyIndex },
378		/// A bounty proposal was rejected; funds were slashed.
379		BountyRejected { index: BountyIndex, bond: BalanceOf<T, I> },
380		/// A bounty proposal is funded and became active.
381		BountyBecameActive { index: BountyIndex },
382		/// A bounty is awarded to a beneficiary.
383		BountyAwarded { index: BountyIndex, beneficiary: T::AccountId },
384		/// A bounty is claimed by beneficiary.
385		BountyClaimed { index: BountyIndex, payout: BalanceOf<T, I>, beneficiary: T::AccountId },
386		/// A bounty is cancelled.
387		BountyCanceled { index: BountyIndex },
388		/// A bounty expiry is extended.
389		BountyExtended { index: BountyIndex },
390		/// A bounty is approved.
391		BountyApproved { index: BountyIndex },
392		/// A bounty curator is proposed.
393		CuratorProposed { bounty_id: BountyIndex, curator: T::AccountId },
394		/// A bounty curator is unassigned.
395		CuratorUnassigned { bounty_id: BountyIndex },
396		/// A bounty curator is accepted.
397		CuratorAccepted { bounty_id: BountyIndex, curator: T::AccountId },
398		/// A bounty deposit has been poked.
399		DepositPoked {
400			bounty_id: BountyIndex,
401			proposer: T::AccountId,
402			old_deposit: BalanceOf<T, I>,
403			new_deposit: BalanceOf<T, I>,
404		},
405	}
406
407	/// Number of bounty proposals that have been made.
408	#[pallet::storage]
409	pub type BountyCount<T: Config<I>, I: 'static = ()> = StorageValue<_, BountyIndex, ValueQuery>;
410
411	/// Bounties that have been made.
412	#[pallet::storage]
413	pub type Bounties<T: Config<I>, I: 'static = ()> = StorageMap<
414		_,
415		Twox64Concat,
416		BountyIndex,
417		Bounty<T::AccountId, BalanceOf<T, I>, BlockNumberFor<T, I>>,
418	>;
419
420	/// The description of each bounty.
421	#[pallet::storage]
422	pub type BountyDescriptions<T: Config<I>, I: 'static = ()> =
423		StorageMap<_, Twox64Concat, BountyIndex, BoundedVec<u8, T::MaximumReasonLength>>;
424
425	/// Bounty indices that have been approved but not yet funded.
426	#[pallet::storage]
427	#[allow(deprecated)]
428	pub type BountyApprovals<T: Config<I>, I: 'static = ()> =
429		StorageValue<_, BoundedVec<BountyIndex, T::MaxApprovals>, ValueQuery>;
430
431	#[pallet::call]
432	impl<T: Config<I>, I: 'static> Pallet<T, I> {
433		/// Propose a new bounty.
434		///
435		/// The dispatch origin for this call must be _Signed_.
436		///
437		/// Payment: `TipReportDepositBase` will be reserved from the origin account, as well as
438		/// `DataDepositPerByte` for each byte in `reason`. It will be unreserved upon approval,
439		/// or slashed when rejected.
440		///
441		/// - `curator`: The curator account whom will manage this bounty.
442		/// - `fee`: The curator fee.
443		/// - `value`: The total payment amount of this bounty, curator fee included.
444		/// - `description`: The description of this bounty.
445		#[pallet::call_index(0)]
446		#[pallet::weight(<T as Config<I>>::WeightInfo::propose_bounty(description.len() as u32))]
447		pub fn propose_bounty(
448			origin: OriginFor<T>,
449			#[pallet::compact] value: BalanceOf<T, I>,
450			description: Vec<u8>,
451		) -> DispatchResult {
452			let proposer = ensure_signed(origin)?;
453			Self::create_bounty(proposer, description, value)?;
454			Ok(())
455		}
456
457		/// Approve a bounty proposal. At a later time, the bounty will be funded and become active
458		/// and the original deposit will be returned.
459		///
460		/// May only be called from `T::SpendOrigin`.
461		///
462		/// ## Complexity
463		/// - O(1).
464		#[pallet::call_index(1)]
465		#[pallet::weight(<T as Config<I>>::WeightInfo::approve_bounty())]
466		pub fn approve_bounty(
467			origin: OriginFor<T>,
468			#[pallet::compact] bounty_id: BountyIndex,
469		) -> DispatchResult {
470			let max_amount = T::SpendOrigin::ensure_origin(origin)?;
471			Bounties::<T, I>::try_mutate_exists(bounty_id, |maybe_bounty| -> DispatchResult {
472				let bounty = maybe_bounty.as_mut().ok_or(Error::<T, I>::InvalidIndex)?;
473				ensure!(
474					bounty.value <= max_amount,
475					pallet_treasury::Error::<T, I>::InsufficientPermission
476				);
477				ensure!(bounty.status == BountyStatus::Proposed, Error::<T, I>::UnexpectedStatus);
478
479				bounty.status = BountyStatus::Approved;
480
481				BountyApprovals::<T, I>::try_append(bounty_id)
482					.map_err(|()| Error::<T, I>::TooManyQueued)?;
483
484				Ok(())
485			})?;
486
487			Self::deposit_event(Event::<T, I>::BountyApproved { index: bounty_id });
488			Ok(())
489		}
490
491		/// Propose a curator to a funded bounty.
492		///
493		/// May only be called from `T::SpendOrigin`.
494		///
495		/// ## Complexity
496		/// - O(1).
497		#[pallet::call_index(2)]
498		#[pallet::weight(<T as Config<I>>::WeightInfo::propose_curator())]
499		pub fn propose_curator(
500			origin: OriginFor<T>,
501			#[pallet::compact] bounty_id: BountyIndex,
502			curator: AccountIdLookupOf<T>,
503			#[pallet::compact] fee: BalanceOf<T, I>,
504		) -> DispatchResult {
505			let max_amount = T::SpendOrigin::ensure_origin(origin)?;
506
507			let curator = T::Lookup::lookup(curator)?;
508			Bounties::<T, I>::try_mutate_exists(bounty_id, |maybe_bounty| -> DispatchResult {
509				let bounty = maybe_bounty.as_mut().ok_or(Error::<T, I>::InvalidIndex)?;
510				ensure!(
511					bounty.value <= max_amount,
512					pallet_treasury::Error::<T, I>::InsufficientPermission
513				);
514				match bounty.status {
515					BountyStatus::Funded => {},
516					_ => return Err(Error::<T, I>::UnexpectedStatus.into()),
517				};
518
519				ensure!(fee < bounty.value, Error::<T, I>::InvalidFee);
520
521				bounty.status = BountyStatus::CuratorProposed { curator: curator.clone() };
522				bounty.fee = fee;
523
524				Self::deposit_event(Event::<T, I>::CuratorProposed { bounty_id, curator });
525
526				Ok(())
527			})?;
528			Ok(())
529		}
530
531		/// Unassign curator from a bounty.
532		///
533		/// This function can only be called by the `RejectOrigin` a signed origin.
534		///
535		/// If this function is called by the `RejectOrigin`, we assume that the curator is
536		/// malicious or inactive. As a result, we will slash the curator when possible.
537		///
538		/// If the origin is the curator, we take this as a sign they are unable to do their job and
539		/// they willingly give up. We could slash them, but for now we allow them to recover their
540		/// deposit and exit without issue. (We may want to change this if it is abused.)
541		///
542		/// Finally, the origin can be anyone if and only if the curator is "inactive". This allows
543		/// anyone in the community to call out that a curator is not doing their due diligence, and
544		/// we should pick a new curator. In this case the curator should also be slashed.
545		///
546		/// ## Complexity
547		/// - O(1).
548		#[pallet::call_index(3)]
549		#[pallet::weight(<T as Config<I>>::WeightInfo::unassign_curator())]
550		pub fn unassign_curator(
551			origin: OriginFor<T>,
552			#[pallet::compact] bounty_id: BountyIndex,
553		) -> DispatchResult {
554			let maybe_sender = ensure_signed(origin.clone())
555				.map(Some)
556				.or_else(|_| T::RejectOrigin::ensure_origin(origin).map(|_| None))?;
557
558			Bounties::<T, I>::try_mutate_exists(bounty_id, |maybe_bounty| -> DispatchResult {
559				let bounty = maybe_bounty.as_mut().ok_or(Error::<T, I>::InvalidIndex)?;
560
561				let slash_curator =
562					|curator: &T::AccountId, curator_deposit: &mut BalanceOf<T, I>| {
563						let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0;
564						T::OnSlash::on_unbalanced(imbalance);
565						*curator_deposit = Zero::zero();
566					};
567
568				match bounty.status {
569					BountyStatus::Proposed | BountyStatus::Approved | BountyStatus::Funded => {
570						// No curator to unassign at this point.
571						return Err(Error::<T, I>::UnexpectedStatus.into());
572					},
573					BountyStatus::ApprovedWithCurator { ref curator } => {
574						// Bounty not yet funded, but bounty was approved with curator.
575						// `RejectOrigin` or curator himself can unassign from this bounty.
576						ensure!(maybe_sender.map_or(true, |sender| sender == *curator), BadOrigin);
577						// This state can only be while the bounty is not yet funded so we return
578						// bounty to the `Approved` state without curator
579						bounty.status = BountyStatus::Approved;
580						return Ok(());
581					},
582					BountyStatus::CuratorProposed { ref curator } => {
583						// A curator has been proposed, but not accepted yet.
584						// Either `RejectOrigin` or the proposed curator can unassign the curator.
585						ensure!(maybe_sender.map_or(true, |sender| sender == *curator), BadOrigin);
586					},
587					BountyStatus::Active { ref curator, ref update_due } => {
588						// The bounty is active.
589						match maybe_sender {
590							// If the `RejectOrigin` is calling this function, slash the curator.
591							None => {
592								slash_curator(curator, &mut bounty.curator_deposit);
593								// Continue to change bounty status below...
594							},
595							Some(sender) => {
596								// If the sender is not the curator, and the curator is inactive,
597								// slash the curator.
598								if sender != *curator {
599									let block_number = Self::treasury_block_number();
600									if *update_due < block_number {
601										slash_curator(curator, &mut bounty.curator_deposit);
602									// Continue to change bounty status below...
603									} else {
604										// Curator has more time to give an update.
605										return Err(Error::<T, I>::Premature.into());
606									}
607								} else {
608									// Else this is the curator, willingly giving up their role.
609									// Give back their deposit.
610									let err_amount =
611										T::Currency::unreserve(curator, bounty.curator_deposit);
612									debug_assert!(err_amount.is_zero());
613									bounty.curator_deposit = Zero::zero();
614									// Continue to change bounty status below...
615								}
616							},
617						}
618					},
619					BountyStatus::PendingPayout { ref curator, .. } => {
620						// The bounty is pending payout, so only council can unassign a curator.
621						// By doing so, they are claiming the curator is acting maliciously, so
622						// we slash the curator.
623						ensure!(maybe_sender.is_none(), BadOrigin);
624						slash_curator(curator, &mut bounty.curator_deposit);
625						// Continue to change bounty status below...
626					},
627				};
628
629				bounty.status = BountyStatus::Funded;
630				Ok(())
631			})?;
632
633			Self::deposit_event(Event::<T, I>::CuratorUnassigned { bounty_id });
634			Ok(())
635		}
636
637		/// Accept the curator role for a bounty.
638		/// A deposit will be reserved from curator and refund upon successful payout.
639		///
640		/// May only be called from the curator.
641		///
642		/// ## Complexity
643		/// - O(1).
644		#[pallet::call_index(4)]
645		#[pallet::weight(<T as Config<I>>::WeightInfo::accept_curator())]
646		pub fn accept_curator(
647			origin: OriginFor<T>,
648			#[pallet::compact] bounty_id: BountyIndex,
649		) -> DispatchResult {
650			let signer = ensure_signed(origin)?;
651
652			Bounties::<T, I>::try_mutate_exists(bounty_id, |maybe_bounty| -> DispatchResult {
653				let bounty = maybe_bounty.as_mut().ok_or(Error::<T, I>::InvalidIndex)?;
654
655				match bounty.status {
656					BountyStatus::CuratorProposed { ref curator } => {
657						ensure!(signer == *curator, Error::<T, I>::RequireCurator);
658
659						let deposit = Self::calculate_curator_deposit(&bounty.fee);
660						T::Currency::reserve(curator, deposit)?;
661						bounty.curator_deposit = deposit;
662
663						let update_due = Self::treasury_block_number()
664							.saturating_add(T::BountyUpdatePeriod::get());
665						bounty.status =
666							BountyStatus::Active { curator: curator.clone(), update_due };
667
668						Self::deposit_event(Event::<T, I>::CuratorAccepted {
669							bounty_id,
670							curator: signer,
671						});
672						Ok(())
673					},
674					_ => Err(Error::<T, I>::UnexpectedStatus.into()),
675				}
676			})?;
677			Ok(())
678		}
679
680		/// Award bounty to a beneficiary account. The beneficiary will be able to claim the funds
681		/// after a delay.
682		///
683		/// The dispatch origin for this call must be the curator of this bounty.
684		///
685		/// - `bounty_id`: Bounty ID to award.
686		/// - `beneficiary`: The beneficiary account whom will receive the payout.
687		///
688		/// ## Complexity
689		/// - O(1).
690		#[pallet::call_index(5)]
691		#[pallet::weight(<T as Config<I>>::WeightInfo::award_bounty())]
692		pub fn award_bounty(
693			origin: OriginFor<T>,
694			#[pallet::compact] bounty_id: BountyIndex,
695			beneficiary: AccountIdLookupOf<T>,
696		) -> DispatchResult {
697			let signer = ensure_signed(origin)?;
698			let beneficiary = T::Lookup::lookup(beneficiary)?;
699
700			Bounties::<T, I>::try_mutate_exists(bounty_id, |maybe_bounty| -> DispatchResult {
701				let bounty = maybe_bounty.as_mut().ok_or(Error::<T, I>::InvalidIndex)?;
702
703				// Ensure no active child bounties before processing the call.
704				ensure!(
705					T::ChildBountyManager::child_bounties_count(bounty_id) == 0,
706					Error::<T, I>::HasActiveChildBounty
707				);
708
709				match &bounty.status {
710					BountyStatus::Active { curator, .. } => {
711						ensure!(signer == *curator, Error::<T, I>::RequireCurator);
712					},
713					_ => return Err(Error::<T, I>::UnexpectedStatus.into()),
714				}
715				bounty.status = BountyStatus::PendingPayout {
716					curator: signer,
717					beneficiary: beneficiary.clone(),
718					unlock_at: Self::treasury_block_number() + T::BountyDepositPayoutDelay::get(),
719				};
720
721				Ok(())
722			})?;
723
724			Self::deposit_event(Event::<T, I>::BountyAwarded { index: bounty_id, beneficiary });
725			Ok(())
726		}
727
728		/// Claim the payout from an awarded bounty after payout delay.
729		///
730		/// The dispatch origin for this call must be the beneficiary of this bounty.
731		///
732		/// - `bounty_id`: Bounty ID to claim.
733		///
734		/// ## Complexity
735		/// - O(1).
736		#[pallet::call_index(6)]
737		#[pallet::weight(<T as Config<I>>::WeightInfo::claim_bounty())]
738		pub fn claim_bounty(
739			origin: OriginFor<T>,
740			#[pallet::compact] bounty_id: BountyIndex,
741		) -> DispatchResult {
742			ensure_signed(origin)?; // anyone can trigger claim
743
744			Bounties::<T, I>::try_mutate_exists(bounty_id, |maybe_bounty| -> DispatchResult {
745				let bounty = maybe_bounty.take().ok_or(Error::<T, I>::InvalidIndex)?;
746				if let BountyStatus::PendingPayout { curator, beneficiary, unlock_at } =
747					bounty.status
748				{
749					ensure!(Self::treasury_block_number() >= unlock_at, Error::<T, I>::Premature);
750					let bounty_account = Self::bounty_account_id(bounty_id);
751					let balance = T::Currency::free_balance(&bounty_account);
752					let fee = bounty.fee.min(balance); // just to be safe
753					let payout = balance.saturating_sub(fee);
754					let err_amount = T::Currency::unreserve(&curator, bounty.curator_deposit);
755					debug_assert!(err_amount.is_zero());
756
757					// Get total child bounties curator fees, and subtract it from the parent
758					// curator fee (the fee in present referenced bounty, `self`).
759					let children_fee = T::ChildBountyManager::children_curator_fees(bounty_id);
760					debug_assert!(children_fee <= fee);
761
762					let final_fee = fee.saturating_sub(children_fee);
763					let res =
764						T::Currency::transfer(&bounty_account, &curator, final_fee, AllowDeath); // should not fail
765					debug_assert!(res.is_ok());
766					let res =
767						T::Currency::transfer(&bounty_account, &beneficiary, payout, AllowDeath); // should not fail
768					debug_assert!(res.is_ok());
769
770					*maybe_bounty = None;
771
772					BountyDescriptions::<T, I>::remove(bounty_id);
773					T::ChildBountyManager::bounty_removed(bounty_id);
774
775					Self::deposit_event(Event::<T, I>::BountyClaimed {
776						index: bounty_id,
777						payout,
778						beneficiary,
779					});
780					Ok(())
781				} else {
782					Err(Error::<T, I>::UnexpectedStatus.into())
783				}
784			})?;
785			Ok(())
786		}
787
788		/// Cancel a proposed or active bounty. All the funds will be sent to treasury and
789		/// the curator deposit will be unreserved if possible.
790		///
791		/// Only `T::RejectOrigin` is able to cancel a bounty.
792		///
793		/// - `bounty_id`: Bounty ID to cancel.
794		///
795		/// ## Complexity
796		/// - O(1).
797		#[pallet::call_index(7)]
798		#[pallet::weight(<T as Config<I>>::WeightInfo::close_bounty_proposed()
799			.max(<T as Config<I>>::WeightInfo::close_bounty_active()))]
800		pub fn close_bounty(
801			origin: OriginFor<T>,
802			#[pallet::compact] bounty_id: BountyIndex,
803		) -> DispatchResultWithPostInfo {
804			T::RejectOrigin::ensure_origin(origin)?;
805
806			Bounties::<T, I>::try_mutate_exists(
807				bounty_id,
808				|maybe_bounty| -> DispatchResultWithPostInfo {
809					let bounty = maybe_bounty.as_ref().ok_or(Error::<T, I>::InvalidIndex)?;
810
811					// Ensure no active child bounties before processing the call.
812					ensure!(
813						T::ChildBountyManager::child_bounties_count(bounty_id) == 0,
814						Error::<T, I>::HasActiveChildBounty
815					);
816
817					match &bounty.status {
818						BountyStatus::Proposed => {
819							// The reject origin would like to cancel a proposed bounty.
820							BountyDescriptions::<T, I>::remove(bounty_id);
821							let value = bounty.bond;
822							let imbalance = T::Currency::slash_reserved(&bounty.proposer, value).0;
823							T::OnSlash::on_unbalanced(imbalance);
824							*maybe_bounty = None;
825
826							Self::deposit_event(Event::<T, I>::BountyRejected {
827								index: bounty_id,
828								bond: value,
829							});
830							// Return early, nothing else to do.
831							return Ok(
832								Some(<T as Config<I>>::WeightInfo::close_bounty_proposed()).into()
833							);
834						},
835						BountyStatus::Approved | BountyStatus::ApprovedWithCurator { .. } => {
836							// For weight reasons, we don't allow a council to cancel in this phase.
837							// We ask for them to wait until it is funded before they can cancel.
838							return Err(Error::<T, I>::UnexpectedStatus.into());
839						},
840						BountyStatus::Funded | BountyStatus::CuratorProposed { .. } => {
841							// Nothing extra to do besides the removal of the bounty below.
842						},
843						BountyStatus::Active { curator, .. } => {
844							// Cancelled by council, refund deposit of the working curator.
845							let err_amount =
846								T::Currency::unreserve(curator, bounty.curator_deposit);
847							debug_assert!(err_amount.is_zero());
848							// Then execute removal of the bounty below.
849						},
850						BountyStatus::PendingPayout { .. } => {
851							// Bounty is already pending payout. If council wants to cancel
852							// this bounty, it should mean the curator was acting maliciously.
853							// So the council should first unassign the curator, slashing their
854							// deposit.
855							return Err(Error::<T, I>::PendingPayout.into());
856						},
857					}
858
859					let bounty_account = Self::bounty_account_id(bounty_id);
860
861					BountyDescriptions::<T, I>::remove(bounty_id);
862
863					T::TransferAllAssets::force_transfer_all_assets(
864						&bounty_account,
865						&Self::account_id(),
866					)?;
867
868					*maybe_bounty = None;
869					T::ChildBountyManager::bounty_removed(bounty_id);
870
871					Self::deposit_event(Event::<T, I>::BountyCanceled { index: bounty_id });
872					Ok(Some(<T as Config<I>>::WeightInfo::close_bounty_active()).into())
873				},
874			)
875		}
876
877		/// Extend the expiry time of an active bounty.
878		///
879		/// The dispatch origin for this call must be the curator of this bounty.
880		///
881		/// - `bounty_id`: Bounty ID to extend.
882		/// - `remark`: additional information.
883		///
884		/// ## Complexity
885		/// - O(1).
886		#[pallet::call_index(8)]
887		#[pallet::weight(<T as Config<I>>::WeightInfo::extend_bounty_expiry())]
888		pub fn extend_bounty_expiry(
889			origin: OriginFor<T>,
890			#[pallet::compact] bounty_id: BountyIndex,
891			_remark: Vec<u8>,
892		) -> DispatchResult {
893			let signer = ensure_signed(origin)?;
894
895			Bounties::<T, I>::try_mutate_exists(bounty_id, |maybe_bounty| -> DispatchResult {
896				let bounty = maybe_bounty.as_mut().ok_or(Error::<T, I>::InvalidIndex)?;
897
898				match bounty.status {
899					BountyStatus::Active { ref curator, ref mut update_due } => {
900						ensure!(*curator == signer, Error::<T, I>::RequireCurator);
901						*update_due = Self::treasury_block_number()
902							.saturating_add(T::BountyUpdatePeriod::get())
903							.max(*update_due);
904					},
905					_ => return Err(Error::<T, I>::UnexpectedStatus.into()),
906				}
907
908				Ok(())
909			})?;
910
911			Self::deposit_event(Event::<T, I>::BountyExtended { index: bounty_id });
912			Ok(())
913		}
914
915		/// Approve bountry and propose a curator simultaneously.
916		/// This call is a shortcut to calling `approve_bounty` and `propose_curator` separately.
917		///
918		/// May only be called from `T::SpendOrigin`.
919		///
920		/// - `bounty_id`: Bounty ID to approve.
921		/// - `curator`: The curator account whom will manage this bounty.
922		/// - `fee`: The curator fee.
923		///
924		/// ## Complexity
925		/// - O(1).
926		#[pallet::call_index(9)]
927		#[pallet::weight(<T as Config<I>>::WeightInfo::approve_bounty_with_curator())]
928		pub fn approve_bounty_with_curator(
929			origin: OriginFor<T>,
930			#[pallet::compact] bounty_id: BountyIndex,
931			curator: AccountIdLookupOf<T>,
932			#[pallet::compact] fee: BalanceOf<T, I>,
933		) -> DispatchResult {
934			let max_amount = T::SpendOrigin::ensure_origin(origin)?;
935			let curator = T::Lookup::lookup(curator)?;
936			Bounties::<T, I>::try_mutate_exists(bounty_id, |maybe_bounty| -> DispatchResult {
937				// approve bounty
938				let bounty = maybe_bounty.as_mut().ok_or(Error::<T, I>::InvalidIndex)?;
939				ensure!(
940					bounty.value <= max_amount,
941					pallet_treasury::Error::<T, I>::InsufficientPermission
942				);
943				ensure!(bounty.status == BountyStatus::Proposed, Error::<T, I>::UnexpectedStatus);
944				ensure!(fee < bounty.value, Error::<T, I>::InvalidFee);
945
946				BountyApprovals::<T, I>::try_append(bounty_id)
947					.map_err(|()| Error::<T, I>::TooManyQueued)?;
948
949				bounty.status = BountyStatus::ApprovedWithCurator { curator: curator.clone() };
950				bounty.fee = fee;
951
952				Ok(())
953			})?;
954
955			Self::deposit_event(Event::<T, I>::BountyApproved { index: bounty_id });
956			Self::deposit_event(Event::<T, I>::CuratorProposed { bounty_id, curator });
957
958			Ok(())
959		}
960
961		/// Poke the deposit reserved for creating a bounty proposal.
962		///
963		/// This can be used by accounts to update their reserved amount.
964		///
965		/// The dispatch origin for this call must be _Signed_.
966		///
967		/// Parameters:
968		/// - `bounty_id`: The bounty id for which to adjust the deposit.
969		///
970		/// If the deposit is updated, the difference will be reserved/unreserved from the
971		/// proposer's account.
972		///
973		/// The transaction is made free if the deposit is updated and paid otherwise.
974		///
975		/// Emits `DepositPoked` if the deposit is updated.
976		#[pallet::call_index(10)]
977		#[pallet::weight(<T as Config<I>>::WeightInfo::poke_deposit())]
978		pub fn poke_deposit(
979			origin: OriginFor<T>,
980			#[pallet::compact] bounty_id: BountyIndex,
981		) -> DispatchResultWithPostInfo {
982			ensure_signed(origin)?;
983
984			let deposit_updated = Self::poke_bounty_deposit(bounty_id)?;
985
986			Ok(if deposit_updated { Pays::No } else { Pays::Yes }.into())
987		}
988	}
989
990	#[pallet::hooks]
991	impl<T: Config<I>, I: 'static> Hooks<SystemBlockNumberFor<T>> for Pallet<T, I> {
992		#[cfg(feature = "try-runtime")]
993		fn try_state(_n: SystemBlockNumberFor<T>) -> Result<(), sp_runtime::TryRuntimeError> {
994			Self::do_try_state()
995		}
996	}
997}
998
999#[cfg(any(feature = "try-runtime", test))]
1000impl<T: Config<I>, I: 'static> Pallet<T, I> {
1001	/// Ensure the correctness of the state of this pallet.
1002	///
1003	/// This should be valid before or after each state transition of this pallet.
1004	pub fn do_try_state() -> Result<(), sp_runtime::TryRuntimeError> {
1005		Self::try_state_bounties_count()?;
1006
1007		Ok(())
1008	}
1009
1010	/// # Invariants
1011	///
1012	/// * `BountyCount` should be greater or equals to the length of the number of items in
1013	///   `Bounties`.
1014	/// * `BountyCount` should be greater or equals to the length of the number of items in
1015	///   `BountyDescriptions`.
1016	/// * Number of items in `Bounties` should be the same as `BountyDescriptions` length.
1017	fn try_state_bounties_count() -> Result<(), sp_runtime::TryRuntimeError> {
1018		let bounties_length = Bounties::<T, I>::iter().count() as u32;
1019
1020		ensure!(
1021			<BountyCount<T, I>>::get() >= bounties_length,
1022			"`BountyCount` must be grater or equals the number of `Bounties` in storage"
1023		);
1024
1025		let bounties_description_length = BountyDescriptions::<T, I>::iter().count() as u32;
1026		ensure!(
1027			<BountyCount<T, I>>::get() >= bounties_description_length,
1028			"`BountyCount` must be grater or equals the number of `BountiesDescriptions` in storage."
1029		);
1030
1031		ensure!(
1032				bounties_length == bounties_description_length,
1033				"Number of `Bounties` in storage must be the same as the Number of `BountiesDescription` in storage."
1034		);
1035		Ok(())
1036	}
1037}
1038
1039impl<T: Config<I>, I: 'static> Pallet<T, I> {
1040	/// Get the block number used in the treasury pallet.
1041	///
1042	/// It may be configured to use the relay chain block number on a parachain.
1043	pub fn treasury_block_number() -> BlockNumberFor<T, I> {
1044		<T as pallet_treasury::Config<I>>::BlockNumberProvider::current_block_number()
1045	}
1046
1047	/// Calculate the deposit required for a curator.
1048	pub fn calculate_curator_deposit(fee: &BalanceOf<T, I>) -> BalanceOf<T, I> {
1049		let mut deposit = T::CuratorDepositMultiplier::get() * *fee;
1050
1051		if let Some(max_deposit) = T::CuratorDepositMax::get() {
1052			deposit = deposit.min(max_deposit)
1053		}
1054
1055		if let Some(min_deposit) = T::CuratorDepositMin::get() {
1056			deposit = deposit.max(min_deposit)
1057		}
1058
1059		deposit
1060	}
1061
1062	/// The account ID of the treasury pot.
1063	///
1064	/// This actually does computation. If you need to keep using it, then make sure you cache the
1065	/// value and only call this once.
1066	pub fn account_id() -> T::AccountId {
1067		T::PalletId::get().into_account_truncating()
1068	}
1069
1070	/// The account ID of a bounty account
1071	pub fn bounty_account_id(id: BountyIndex) -> T::AccountId {
1072		// only use two byte prefix to support 16 byte account id (used by test)
1073		// "modl" ++ "py/trsry" ++ "bt" is 14 bytes, and two bytes remaining for bounty index
1074		T::PalletId::get().into_sub_account_truncating(("bt", id))
1075	}
1076
1077	fn create_bounty(
1078		proposer: T::AccountId,
1079		description: Vec<u8>,
1080		value: BalanceOf<T, I>,
1081	) -> DispatchResult {
1082		let bounded_description: BoundedVec<_, _> =
1083			description.try_into().map_err(|_| Error::<T, I>::ReasonTooBig)?;
1084		ensure!(value >= T::BountyValueMinimum::get(), Error::<T, I>::InvalidValue);
1085
1086		let index = BountyCount::<T, I>::get();
1087
1088		// reserve deposit for new bounty
1089		let bond = Self::calculate_bounty_deposit(&bounded_description);
1090		T::Currency::reserve(&proposer, bond)
1091			.map_err(|_| Error::<T, I>::InsufficientProposersBalance)?;
1092
1093		BountyCount::<T, I>::put(index + 1);
1094
1095		let bounty = Bounty {
1096			proposer,
1097			value,
1098			fee: 0u32.into(),
1099			curator_deposit: 0u32.into(),
1100			bond,
1101			status: BountyStatus::Proposed,
1102		};
1103
1104		Bounties::<T, I>::insert(index, &bounty);
1105		BountyDescriptions::<T, I>::insert(index, bounded_description);
1106
1107		Self::deposit_event(Event::<T, I>::BountyProposed { index });
1108
1109		Ok(())
1110	}
1111
1112	/// Helper function to calculate the bounty storage deposit.
1113	fn calculate_bounty_deposit(
1114		description: &BoundedVec<u8, T::MaximumReasonLength>,
1115	) -> BalanceOf<T, I> {
1116		T::BountyDepositBase::get().saturating_add(
1117			T::DataDepositPerByte::get().saturating_mul((description.len() as u32).into()),
1118		)
1119	}
1120
1121	/// Helper function to poke the deposit reserved for proposing a bounty.
1122	///
1123	/// Returns true if the deposit was updated and false otherwise.
1124	fn poke_bounty_deposit(bounty_id: BountyIndex) -> Result<bool, DispatchError> {
1125		let mut bounty = Bounties::<T, I>::get(bounty_id).ok_or(Error::<T, I>::InvalidIndex)?;
1126		let bounty_description =
1127			BountyDescriptions::<T, I>::get(bounty_id).ok_or(Error::<T, I>::InvalidIndex)?;
1128		// ensure that the bounty status is proposed.
1129		ensure!(bounty.status == BountyStatus::Proposed, Error::<T, I>::UnexpectedStatus);
1130
1131		let new_bond = Self::calculate_bounty_deposit(&bounty_description);
1132		let old_bond = bounty.bond;
1133		if new_bond == old_bond {
1134			return Ok(false);
1135		}
1136		if new_bond > old_bond {
1137			let extra = new_bond.saturating_sub(old_bond);
1138			T::Currency::reserve(&bounty.proposer, extra)?;
1139		} else {
1140			let excess = old_bond.saturating_sub(new_bond);
1141			let remaining_unreserved = T::Currency::unreserve(&bounty.proposer, excess);
1142			if !remaining_unreserved.is_zero() {
1143				defensive!(
1144					"Failed to unreserve full amount. (Requested, Actual)",
1145					(excess, excess.saturating_sub(remaining_unreserved))
1146				);
1147			}
1148		}
1149		bounty.bond = new_bond;
1150		Bounties::<T, I>::insert(bounty_id, &bounty);
1151
1152		Self::deposit_event(Event::<T, I>::DepositPoked {
1153			bounty_id,
1154			proposer: bounty.proposer,
1155			old_deposit: old_bond,
1156			new_deposit: new_bond,
1157		});
1158
1159		Ok(true)
1160	}
1161}
1162
1163impl<T: Config<I>, I: 'static> pallet_treasury::SpendFunds<T, I> for Pallet<T, I> {
1164	fn spend_funds(
1165		budget_remaining: &mut BalanceOf<T, I>,
1166		imbalance: &mut PositiveImbalanceOf<T, I>,
1167		total_weight: &mut Weight,
1168		missed_any: &mut bool,
1169	) {
1170		let bounties_len = BountyApprovals::<T, I>::mutate(|v| {
1171			let bounties_approval_len = v.len() as u32;
1172			v.retain(|&index| {
1173				Bounties::<T, I>::mutate(index, |bounty| {
1174					// Should always be true, but shouldn't panic if false or we're screwed.
1175					if let Some(bounty) = bounty {
1176						if bounty.value <= *budget_remaining {
1177							*budget_remaining -= bounty.value;
1178
1179							// jump through the funded phase if we're already approved with curator
1180							if let BountyStatus::ApprovedWithCurator { curator } = &bounty.status {
1181								bounty.status =
1182									BountyStatus::CuratorProposed { curator: curator.clone() };
1183							} else {
1184								bounty.status = BountyStatus::Funded;
1185							}
1186
1187							// return their deposit.
1188							let err_amount = T::Currency::unreserve(&bounty.proposer, bounty.bond);
1189							debug_assert!(err_amount.is_zero());
1190
1191							// fund the bounty account
1192							imbalance.subsume(T::Currency::deposit_creating(
1193								&Self::bounty_account_id(index),
1194								bounty.value,
1195							));
1196
1197							Self::deposit_event(Event::<T, I>::BountyBecameActive { index });
1198							false
1199						} else {
1200							*missed_any = true;
1201							true
1202						}
1203					} else {
1204						false
1205					}
1206				})
1207			});
1208			bounties_approval_len
1209		});
1210
1211		*total_weight += <T as pallet::Config<I>>::WeightInfo::spend_funds(bounties_len);
1212	}
1213}
1214
1215// Default impl for when ChildBounties is not being used in the runtime.
1216impl<Balance: Zero> ChildBountyManager<Balance> for () {
1217	fn child_bounties_count(_bounty_id: BountyIndex) -> BountyIndex {
1218		Default::default()
1219	}
1220
1221	fn children_curator_fees(_bounty_id: BountyIndex) -> Balance {
1222		Zero::zero()
1223	}
1224
1225	fn bounty_removed(_bounty_id: BountyIndex) {}
1226}