Skip to content

Commit

Permalink
Allow the treasury to have a maximum bound on the bond (paritytech#10689
Browse files Browse the repository at this point in the history
)

* Allow the treasury to have a maximum bound on the bond

* Update frame/treasury/src/lib.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
  • Loading branch information
2 people authored and ark0f committed Feb 27, 2023
1 parent 60f350e commit ebe266f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ impl pallet_treasury::Config for Runtime {
type OnSlash = ();
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type ProposalBondMaximum = ();
type SpendPeriod = SpendPeriod;
type Burn = Burn;
type BurnDestination = ();
Expand Down
1 change: 1 addition & 0 deletions docs/Upgrading-2.0-to-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ As mentioned above, Bounties, Tips and Lottery have been extracted out of treasu
type OnSlash = ();
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type ProposalBondMaximum = ();
type SpendPeriod = SpendPeriod;
type Burn = Burn;
+ type BurnDestination = ();
Expand Down
1 change: 1 addition & 0 deletions frame/bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl pallet_treasury::Config for Test {
type OnSlash = ();
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ConstU64<1>;
type ProposalBondMaximum = ();
type SpendPeriod = ConstU64<2>;
type Burn = Burn;
type BurnDestination = (); // Just gets burned.
Expand Down
1 change: 1 addition & 0 deletions frame/child-bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl pallet_treasury::Config for Test {
type OnSlash = ();
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ConstU64<1>;
type ProposalBondMaximum = ();
type SpendPeriod = ConstU64<2>;
type Burn = Burn;
type BurnDestination = ();
Expand Down
1 change: 1 addition & 0 deletions frame/tips/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl pallet_treasury::Config for Test {
type OnSlash = ();
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ConstU64<1>;
type ProposalBondMaximum = ();
type SpendPeriod = ConstU64<2>;
type Burn = Burn;
type BurnDestination = (); // Just gets burned.
Expand Down
10 changes: 9 additions & 1 deletion frame/treasury/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ pub mod pallet {
#[pallet::constant]
type ProposalBondMinimum: Get<BalanceOf<Self, I>>;

/// Maximum amount of funds that should be placed in a deposit for making a proposal.
#[pallet::constant]
type ProposalBondMaximum: Get<Option<BalanceOf<Self, I>>>;

/// Period between successive spends.
#[pallet::constant]
type SpendPeriod: Get<Self::BlockNumber>;
Expand Down Expand Up @@ -404,7 +408,11 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {

/// The needed bond for a proposal whose spend is `value`.
fn calculate_bond(value: BalanceOf<T, I>) -> BalanceOf<T, I> {
T::ProposalBondMinimum::get().max(T::ProposalBond::get() * value)
let mut r = T::ProposalBondMinimum::get().max(T::ProposalBond::get() * value);
if let Some(m) = T::ProposalBondMaximum::get() {
r = r.min(m);
}
r
}

/// Spend some money! returns number of approvals before spend.
Expand Down
1 change: 1 addition & 0 deletions frame/treasury/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl Config for Test {
type OnSlash = ();
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ConstU64<1>;
type ProposalBondMaximum = ();
type SpendPeriod = ConstU64<2>;
type Burn = Burn;
type BurnDestination = (); // Just gets burned.
Expand Down

0 comments on commit ebe266f

Please sign in to comment.