Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 32f332a

Browse files
gavofyorkKiChjangggwpez
authored and
Ross Bulat
committed
NIS should retain funds in reserve (#12928)
* Keep funds with receipt holder * Counterpart is optional * Use named reserves * Tests * Benchmarks * Fixes * Update frame/nis/src/lib.rs Co-authored-by: Keith Yeung <[email protected]> * Update frame/nis/src/lib.rs Co-authored-by: Keith Yeung <[email protected]> * Update frame/nis/src/lib.rs * Update frame/nis/src/lib.rs * Update frame/nis/src/tests.rs * Update frame/nis/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Update frame/nis/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Update frame/nis/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Update frame/nis/src/lib.rs * Update frame/nis/src/lib.rs * Update frame/nis/src/lib.rs * Update frame/nis/src/lib.rs * Formatting Co-authored-by: Keith Yeung <[email protected]> Co-authored-by: Oliver Tale-Yazdi <[email protected]>
1 parent 28e72a8 commit 32f332a

File tree

7 files changed

+828
-309
lines changed

7 files changed

+828
-309
lines changed

bin/node/runtime/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,7 @@ parameter_types! {
14991499
pub const ThawThrottle: (Perquintill, BlockNumber) = (Perquintill::from_percent(25), 5);
15001500
pub Target: Perquintill = Perquintill::zero();
15011501
pub const NisPalletId: PalletId = PalletId(*b"py/nis ");
1502+
pub const NisReserveId: [u8; 8] = *b"py/nis ";
15021503
}
15031504

15041505
impl pallet_nis::Config for Runtime {
@@ -1522,6 +1523,7 @@ impl pallet_nis::Config for Runtime {
15221523
type IntakePeriod = IntakePeriod;
15231524
type MaxIntakeWeight = MaxIntakeWeight;
15241525
type ThawThrottle = ThawThrottle;
1526+
type ReserveId = NisReserveId;
15251527
}
15261528

15271529
parameter_types! {

frame/nis/src/benchmarking.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
use super::*;
2323
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
24-
use frame_support::traits::{Currency, EnsureOrigin, Get};
24+
use frame_support::traits::{nonfungible::Inspect, Currency, EnsureOrigin, Get};
2525
use frame_system::RawOrigin;
2626
use sp_arithmetic::Perquintill;
2727
use sp_runtime::{
@@ -106,6 +106,7 @@ benchmarks! {
106106
T::Currency::make_free_balance_be(&caller, bid);
107107
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), bid, 1)?;
108108
Nis::<T>::process_queues(Perquintill::one(), 1, 1, &mut WeightCounter::unlimited());
109+
Nis::<T>::communify(RawOrigin::Signed(caller.clone()).into(), 0)?;
109110
let original = T::Currency::free_balance(&Nis::<T>::account_id());
110111
T::Currency::make_free_balance_be(&Nis::<T>::account_id(), BalanceOf::<T>::min_value());
111112
}: _<T::RuntimeOrigin>(origin)
@@ -116,7 +117,7 @@ benchmarks! {
116117
assert!(missing <= Perquintill::one() / 100_000);
117118
}
118119

119-
thaw {
120+
thaw_private {
120121
let caller: T::AccountId = whitelisted_caller();
121122
T::Currency::make_free_balance_be(&caller, T::MinBid::get() * BalanceOf::<T>::from(3u32));
122123
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?;
@@ -128,6 +129,42 @@ benchmarks! {
128129
assert!(Receipts::<T>::get(0).is_none());
129130
}
130131

132+
thaw_communal {
133+
let caller: T::AccountId = whitelisted_caller();
134+
T::Currency::make_free_balance_be(&caller, T::MinBid::get() * BalanceOf::<T>::from(3u32));
135+
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?;
136+
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?;
137+
Nis::<T>::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited());
138+
Receipts::<T>::mutate(0, |m_g| if let Some(ref mut g) = m_g { g.expiry = Zero::zero() });
139+
Nis::<T>::communify(RawOrigin::Signed(caller.clone()).into(), 0)?;
140+
}: _(RawOrigin::Signed(caller.clone()), 0)
141+
verify {
142+
assert!(Receipts::<T>::get(0).is_none());
143+
}
144+
145+
privatize {
146+
let caller: T::AccountId = whitelisted_caller();
147+
T::Currency::make_free_balance_be(&caller, T::MinBid::get() * BalanceOf::<T>::from(3u32));
148+
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?;
149+
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?;
150+
Nis::<T>::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited());
151+
Nis::<T>::communify(RawOrigin::Signed(caller.clone()).into(), 0)?;
152+
}: _(RawOrigin::Signed(caller.clone()), 0)
153+
verify {
154+
assert_eq!(Nis::<T>::owner(&0), Some(caller));
155+
}
156+
157+
communify {
158+
let caller: T::AccountId = whitelisted_caller();
159+
T::Currency::make_free_balance_be(&caller, T::MinBid::get() * BalanceOf::<T>::from(3u32));
160+
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?;
161+
Nis::<T>::place_bid(RawOrigin::Signed(caller.clone()).into(), T::MinBid::get(), 1)?;
162+
Nis::<T>::process_queues(Perquintill::one(), 1, 2, &mut WeightCounter::unlimited());
163+
}: _(RawOrigin::Signed(caller.clone()), 0)
164+
verify {
165+
assert_eq!(Nis::<T>::owner(&0), None);
166+
}
167+
131168
process_queues {
132169
fill_queues::<T>()?;
133170
}: {

0 commit comments

Comments
 (0)