mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 04:51:01 +00:00
Several tweaks needed for Governance 2.0 (#11124)
* Add stepped curve for referenda * Treasury SpendOrigin * Add tests * Better Origin Or-gating * Reciprocal curve * Tests for reciprical and rounding in PerThings * Tweaks and new quad curve * Const derivation of reciprocal curve parameters * Remove some unneeded code * Actually useful linear curve * Fixes * Provisional curves * Rejig 'turnout' as 'support' * Use TypedGet * Fixes * Enable curve's ceil to be configured * Formatting * Fixes * Fixes * Fixes * Remove EnsureOneOf * Fixes * Fixes * Fixes * Formatting * Fixes * Update frame/support/src/traits/dispatch.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Grumbles * Formatting * Fixes * APIs of VoteTally should include class * Fixes * Fix overlay prefix removal result * Second part of the overlay prefix removal fix. * Formatting * Fixes * Add some tests and make clear rounding algo * Fixes * Formatting * Revert questionable fix * Introduce test for kill_prefix * Fixes * Formatting * Fixes * Fix possible overflow * Docs * Add benchmark test * Formatting * Update frame/referenda/src/types.rs Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> * Docs * Fixes * Use latest API in tests * Formatting * Whitespace * Use latest API in tests Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
@@ -198,6 +198,11 @@ pub mod pallet {
|
||||
/// NOTE: This parameter is also used within the Bounties Pallet extension if enabled.
|
||||
#[pallet::constant]
|
||||
type MaxApprovals: Get<u32>;
|
||||
|
||||
/// The origin required for approving spends from the treasury outside of the proposal
|
||||
/// process. The `Success` value is the maximum amount that this origin is allowed to
|
||||
/// spend at a time.
|
||||
type SpendOrigin: EnsureOrigin<Self::Origin, Success = BalanceOf<Self, I>>;
|
||||
}
|
||||
|
||||
/// Number of proposals that have been made.
|
||||
@@ -275,6 +280,12 @@ pub mod pallet {
|
||||
Rollover { rollover_balance: BalanceOf<T, I> },
|
||||
/// Some funds have been deposited.
|
||||
Deposit { value: BalanceOf<T, I> },
|
||||
/// A new spend proposal has been approved.
|
||||
SpendApproved {
|
||||
proposal_index: ProposalIndex,
|
||||
amount: BalanceOf<T, I>,
|
||||
beneficiary: T::AccountId,
|
||||
},
|
||||
}
|
||||
|
||||
/// Error for the treasury pallet.
|
||||
@@ -286,6 +297,9 @@ pub mod pallet {
|
||||
InvalidIndex,
|
||||
/// Too many approvals in the queue.
|
||||
TooManyApprovals,
|
||||
/// The spend origin is valid but the amount it is allowed to spend is lower than the
|
||||
/// amount to be spent.
|
||||
InsufficientPermission,
|
||||
/// Proposal has not been approved.
|
||||
ProposalNotApproved,
|
||||
}
|
||||
@@ -393,6 +407,40 @@ pub mod pallet {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Propose and approve a spend of treasury funds.
|
||||
///
|
||||
/// - `origin`: Must be `SpendOrigin` with the `Success` value being at least `amount`.
|
||||
/// - `amount`: The amount to be transferred from the treasury to the `beneficiary`.
|
||||
/// - `beneficiary`: The destination account for the transfer.
|
||||
///
|
||||
/// NOTE: For record-keeping purposes, the proposer is deemed to be equivalent to the
|
||||
/// beneficiary.
|
||||
#[pallet::weight(T::WeightInfo::spend())]
|
||||
pub fn spend(
|
||||
origin: OriginFor<T>,
|
||||
#[pallet::compact] amount: BalanceOf<T, I>,
|
||||
beneficiary: <T::Lookup as StaticLookup>::Source,
|
||||
) -> DispatchResult {
|
||||
let max_amount = T::SpendOrigin::ensure_origin(origin)?;
|
||||
let beneficiary = T::Lookup::lookup(beneficiary)?;
|
||||
|
||||
ensure!(amount <= max_amount, Error::<T, I>::InsufficientPermission);
|
||||
let proposal_index = Self::proposal_count();
|
||||
Approvals::<T, I>::try_append(proposal_index)
|
||||
.map_err(|_| Error::<T, I>::TooManyApprovals)?;
|
||||
let proposal = Proposal {
|
||||
proposer: beneficiary.clone(),
|
||||
value: amount,
|
||||
beneficiary: beneficiary.clone(),
|
||||
bond: Default::default(),
|
||||
};
|
||||
Proposals::<T, I>::insert(proposal_index, proposal);
|
||||
ProposalCount::<T, I>::put(proposal_index + 1);
|
||||
|
||||
Self::deposit_event(Event::SpendApproved { proposal_index, amount, beneficiary });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Force a previously approved proposal to be removed from the approval queue.
|
||||
/// The original deposit will no longer be returned.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user