Skip to content

Commit

Permalink
Remove deprecated treasury pallet calls
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin committed Mar 25, 2024
1 parent 463ccb8 commit d579b67
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 424 deletions.
12 changes: 12 additions & 0 deletions prdoc/pr_3800.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Remove deprecated calls from treasury pallet

doc:
- audience: Runtime Dev
description: |
This PR remove deprecated calls, relevant tests from `pallet-treasury`

crates:
- name: pallet-treasury
14 changes: 11 additions & 3 deletions substrate/frame/treasury/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ and use the funds to pay developers.
### Dispatchable Functions

General spending/proposal protocol:
- `propose_spend` - Make a spending proposal and stake the required deposit.
- `reject_proposal` - Reject a proposal, slashing the deposit.
- `approve_proposal` - Accept the proposal, returning the deposit.
- `spend_local` - Propose and approve a spend of treasury funds, enables the
creation of spends using the native currency of the chain, utilizing the funds
stored in the pot
- `spend` - Propose and approve a spend of treasury funds, allows spending any
asset kind managed by the treasury
- `remove_approval` - Force a previously approved proposal to be removed from
the approval queue
- `payout` - Claim a spend
- `check_status` - Check the status of the spend and remove it from the storage
if processed
- `void_spend` - Void previously approved spend
126 changes: 0 additions & 126 deletions substrate/frame/treasury/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ pub mod pallet {
/// The staking balance.
type Currency: Currency<Self::AccountId> + ReservableCurrency<Self::AccountId>;

/// Origin from which approvals must come.
type ApproveOrigin: EnsureOrigin<Self::RuntimeOrigin>;

/// Origin from which rejections must come.
type RejectOrigin: EnsureOrigin<Self::RuntimeOrigin>;

Expand Down Expand Up @@ -361,14 +358,10 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config<I>, I: 'static = ()> {
/// New proposal.
Proposed { proposal_index: ProposalIndex },
/// We have ended a spend period and will now allocate funds.
Spending { budget_remaining: BalanceOf<T, I> },
/// Some funds have been allocated.
Awarded { proposal_index: ProposalIndex, award: BalanceOf<T, I>, account: T::AccountId },
/// A proposal was rejected; funds were slashed.
Rejected { proposal_index: ProposalIndex, slashed: BalanceOf<T, I> },
/// Some of our funds have been burnt.
Burnt { burnt_funds: BalanceOf<T, I> },
/// Spending has finished; this is the amount that rolls over until next spend.
Expand Down Expand Up @@ -406,8 +399,6 @@ pub mod pallet {
/// Error for the treasury pallet.
#[pallet::error]
pub enum Error<T, I = ()> {
/// Proposer's balance is too low.
InsufficientProposersBalance,
/// No proposal, bounty or spend at that index.
InvalidIndex,
/// Too many approvals in the queue.
Expand Down Expand Up @@ -474,123 +465,6 @@ pub mod pallet {

#[pallet::call]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Put forward a suggestion for spending.
///
/// ## Dispatch Origin
///
/// Must be signed.
///
/// ## Details
/// A deposit proportional to the value is reserved and slashed if the proposal is rejected.
/// It is returned once the proposal is awarded.
///
/// ### Complexity
/// - O(1)
///
/// ## Events
///
/// Emits [`Event::Proposed`] if successful.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::propose_spend())]
#[allow(deprecated)]
#[deprecated(
note = "`propose_spend` will be removed in February 2024. Use `spend` instead."
)]
pub fn propose_spend(
origin: OriginFor<T>,
#[pallet::compact] value: BalanceOf<T, I>,
beneficiary: AccountIdLookupOf<T>,
) -> DispatchResult {
let proposer = ensure_signed(origin)?;
let beneficiary = T::Lookup::lookup(beneficiary)?;

let bond = Self::calculate_bond(value);
T::Currency::reserve(&proposer, bond)
.map_err(|_| Error::<T, I>::InsufficientProposersBalance)?;

let c = Self::proposal_count();
<ProposalCount<T, I>>::put(c + 1);
<Proposals<T, I>>::insert(c, Proposal { proposer, value, beneficiary, bond });

Self::deposit_event(Event::Proposed { proposal_index: c });
Ok(())
}

/// Reject a proposed spend.
///
/// ## Dispatch Origin
///
/// Must be [`Config::RejectOrigin`].
///
/// ## Details
/// The original deposit will be slashed.
///
/// ### Complexity
/// - O(1)
///
/// ## Events
///
/// Emits [`Event::Rejected`] if successful.
#[pallet::call_index(1)]
#[pallet::weight((T::WeightInfo::reject_proposal(), DispatchClass::Operational))]
#[allow(deprecated)]
#[deprecated(
note = "`reject_proposal` will be removed in February 2024. Use `spend` instead."
)]
pub fn reject_proposal(
origin: OriginFor<T>,
#[pallet::compact] proposal_id: ProposalIndex,
) -> DispatchResult {
T::RejectOrigin::ensure_origin(origin)?;

let proposal =
<Proposals<T, I>>::take(&proposal_id).ok_or(Error::<T, I>::InvalidIndex)?;
let value = proposal.bond;
let imbalance = T::Currency::slash_reserved(&proposal.proposer, value).0;
T::OnSlash::on_unbalanced(imbalance);

Self::deposit_event(Event::<T, I>::Rejected {
proposal_index: proposal_id,
slashed: value,
});
Ok(())
}

/// Approve a proposal.
///
/// ## Dispatch Origin
///
/// Must be [`Config::ApproveOrigin`].
///
/// ## Details
///
/// At a later time, the proposal will be allocated to the beneficiary and the original
/// deposit will be returned.
///
/// ### Complexity
/// - O(1).
///
/// ## Events
///
/// No events are emitted from this dispatch.
#[pallet::call_index(2)]
#[pallet::weight((T::WeightInfo::approve_proposal(T::MaxApprovals::get()), DispatchClass::Operational))]
#[allow(deprecated)]
#[deprecated(
note = "`approve_proposal` will be removed in February 2024. Use `spend` instead."
)]
pub fn approve_proposal(
origin: OriginFor<T>,
#[pallet::compact] proposal_id: ProposalIndex,
) -> DispatchResult {
T::ApproveOrigin::ensure_origin(origin)?;

ensure!(<Proposals<T, I>>::contains_key(proposal_id), Error::<T, I>::InvalidIndex);
Approvals::<T, I>::try_append(proposal_id)
.map_err(|_| Error::<T, I>::TooManyApprovals)?;
Ok(())
}

/// Propose and approve a spend of treasury funds.
///
/// ## Dispatch Origin
Expand Down
Loading

0 comments on commit d579b67

Please sign in to comment.