referrerpolicy=no-referrer-when-downgrade

Module pallet_collective::deposit

source ·
Expand description

Types implementing various cost strategies for a given proposal count.

These types implement Convert trait and can be used with types like HoldConsideration implementing Consideration trait.

§Example:

  1. Linear increasing with helper types.
#[test]
fn deposit_types_with_linear_work() {
	type LinearWithSlop2 = crate::deposit::Linear<ConstU32<2>, ConstU128<10>>;
	assert_eq!(<LinearWithSlop2 as Convert<_, u128>>::convert(0), 10);
	assert_eq!(<LinearWithSlop2 as Convert<_, u128>>::convert(1), 12);
	assert_eq!(<LinearWithSlop2 as Convert<_, u128>>::convert(2), 14);
	assert_eq!(<LinearWithSlop2 as Convert<_, u128>>::convert(3), 16);
	assert_eq!(<LinearWithSlop2 as Convert<_, u128>>::convert(4), 18);

	type SteppedWithStep3 = crate::deposit::Stepped<ConstU32<3>, LinearWithSlop2>;
	assert_eq!(<SteppedWithStep3 as Convert<_, u128>>::convert(0), 10);
	assert_eq!(<SteppedWithStep3 as Convert<_, u128>>::convert(1), 10);
	assert_eq!(<SteppedWithStep3 as Convert<_, u128>>::convert(2), 10);
	assert_eq!(<SteppedWithStep3 as Convert<_, u128>>::convert(3), 12);
	assert_eq!(<SteppedWithStep3 as Convert<_, u128>>::convert(4), 12);
	assert_eq!(<SteppedWithStep3 as Convert<_, u128>>::convert(5), 12);
	assert_eq!(<SteppedWithStep3 as Convert<_, u128>>::convert(6), 14);

	type DelayedWithDelay4 = crate::deposit::Delayed<ConstU32<4>, SteppedWithStep3>;
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(0), 0);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(3), 0);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(4), 10);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(5), 10);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(6), 10);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(7), 12);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(9), 12);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(10), 14);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(13), 16);

	type WithCeil13 = crate::deposit::WithCeil<ConstU128<13>, DelayedWithDelay4>;
	assert_eq!(<WithCeil13 as Convert<_, u128>>::convert(0), 0);
	assert_eq!(<WithCeil13 as Convert<_, u128>>::convert(4), 10);
	assert_eq!(<WithCeil13 as Convert<_, u128>>::convert(9), 12);
	assert_eq!(<WithCeil13 as Convert<_, u128>>::convert(10), 13);
	assert_eq!(<WithCeil13 as Convert<_, u128>>::convert(11), 13);
	assert_eq!(<WithCeil13 as Convert<_, u128>>::convert(13), 13);
}
  1. Geometrically increasing with helper types.
#[test]
fn deposit_types_with_geometric_work() {
	parameter_types! {
		pub const Ratio2: FixedU128 = FixedU128::from_u32(2);
	}
	type WithRatio2Base10 = crate::deposit::Geometric<Ratio2, ConstU128<10>>;
	assert_eq!(<WithRatio2Base10 as Convert<_, u128>>::convert(0), 10);
	assert_eq!(<WithRatio2Base10 as Convert<_, u128>>::convert(1), 20);
	assert_eq!(<WithRatio2Base10 as Convert<_, u128>>::convert(2), 40);
	assert_eq!(<WithRatio2Base10 as Convert<_, u128>>::convert(3), 80);
	assert_eq!(<WithRatio2Base10 as Convert<_, u128>>::convert(4), 160);
	assert_eq!(<WithRatio2Base10 as Convert<_, u128>>::convert(5), 320);
	assert_eq!(<WithRatio2Base10 as Convert<_, u128>>::convert(6), 640);
	assert_eq!(<WithRatio2Base10 as Convert<_, u128>>::convert(7), 1280);
	assert_eq!(<WithRatio2Base10 as Convert<_, u128>>::convert(8), 2560);
	assert_eq!(<WithRatio2Base10 as Convert<_, u128>>::convert(9), 5120);

	type SteppedWithStep3 = crate::deposit::Stepped<ConstU32<3>, WithRatio2Base10>;
	assert_eq!(<SteppedWithStep3 as Convert<_, u128>>::convert(0), 10);
	assert_eq!(<SteppedWithStep3 as Convert<_, u128>>::convert(1), 10);
	assert_eq!(<SteppedWithStep3 as Convert<_, u128>>::convert(2), 10);
	assert_eq!(<SteppedWithStep3 as Convert<_, u128>>::convert(3), 20);
	assert_eq!(<SteppedWithStep3 as Convert<_, u128>>::convert(4), 20);
	assert_eq!(<SteppedWithStep3 as Convert<_, u128>>::convert(5), 20);
	assert_eq!(<SteppedWithStep3 as Convert<_, u128>>::convert(6), 40);

	type DelayedWithDelay4 = crate::deposit::Delayed<ConstU32<4>, SteppedWithStep3>;
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(0), 0);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(3), 0);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(4), 10);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(5), 10);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(6), 10);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(7), 20);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(9), 20);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(10), 40);
	assert_eq!(<DelayedWithDelay4 as Convert<_, u128>>::convert(13), 80);

	type WithCeil21 = crate::deposit::WithCeil<ConstU128<21>, DelayedWithDelay4>;
	assert_eq!(<WithCeil21 as Convert<_, u128>>::convert(0), 0);
	assert_eq!(<WithCeil21 as Convert<_, u128>>::convert(4), 10);
	assert_eq!(<WithCeil21 as Convert<_, u128>>::convert(9), 20);
	assert_eq!(<WithCeil21 as Convert<_, u128>>::convert(10), 21);
	assert_eq!(<WithCeil21 as Convert<_, u128>>::convert(11), 21);
	assert_eq!(<WithCeil21 as Convert<_, u128>>::convert(13), 21);
}
  1. Geometrically increasing with rounding.
#[test]
fn deposit_round_with_geometric_work() {
	parameter_types! {
		pub const Ratio1_5: FixedU128 = FixedU128::from_rational(3, 2);
	}
	type WithRatio1_5Base10 = crate::deposit::Geometric<Ratio1_5, ConstU128<10000>>;
	assert_eq!(<WithRatio1_5Base10 as Convert<_, u128>>::convert(0), 10000);
	assert_eq!(<WithRatio1_5Base10 as Convert<_, u128>>::convert(1), 15000);
	assert_eq!(<WithRatio1_5Base10 as Convert<_, u128>>::convert(2), 22500);
	assert_eq!(<WithRatio1_5Base10 as Convert<_, u128>>::convert(3), 33750);
	assert_eq!(<WithRatio1_5Base10 as Convert<_, u128>>::convert(4), 50625);
	assert_eq!(<WithRatio1_5Base10 as Convert<_, u128>>::convert(5), 75937);

	type RoundWithPrecision3 = crate::deposit::Round<ConstU32<3>, WithRatio1_5Base10>;
	assert_eq!(<RoundWithPrecision3 as Convert<_, u128>>::convert(0), 10000);
	assert_eq!(<RoundWithPrecision3 as Convert<_, u128>>::convert(1), 15000);
	assert_eq!(<RoundWithPrecision3 as Convert<_, u128>>::convert(2), 22000);
	assert_eq!(<RoundWithPrecision3 as Convert<_, u128>>::convert(3), 33000);
	assert_eq!(<RoundWithPrecision3 as Convert<_, u128>>::convert(4), 50000);
	assert_eq!(<RoundWithPrecision3 as Convert<_, u128>>::convert(5), 75000);
}

Structs§

  • Constant deposit amount regardless of current proposal count. Returns None if configured with zero deposit.
  • Defines Delay for supplied Step implementing [Convert] trait.
  • Geometrically increasing. f(x) = a * r^x, a = Base, x = proposal_count, r = Ratio.
  • Linear increasing with some offset. f(x) = ax + b, a = Slope, x = proposal_count, b = Offset.
  • Rounds a Deposit result with Precision. Particularly useful for types like Geometric that might produce deposits with high precision.
  • Defines Period for supplied Step implementing [Convert] trait.
  • Defines Ceil for supplied Step implementing [Convert] trait.