Skip to content

Commit 4268f95

Browse files
authored
Merge pull request #5103 from ignazio-bovo/feature/crt-constraints-proposal
Feature/crt constraints proposal
2 parents d6d184b + 3dc4539 commit 4268f95

File tree

29 files changed

+875
-502
lines changed

29 files changed

+875
-502
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chain-metadata.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

query-node/chain-metadata/2003.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

runtime-modules/project-token/src/benchmarking.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,30 @@ benchmarks! {
257257
where_clause {
258258
where T: Config
259259
}
260+
// Worst case scenario:
261+
// all parameters needs to be updated
262+
update_token_constraints {
263+
let parameters = TokenConstraints {
264+
max_yearly_rate: Some(YearlyRate(Permill::from_percent(15))),
265+
min_amm_slope: Some(100u32.into()),
266+
min_sale_duration: Some(10u32.into()),
267+
min_revenue_split_duration: Some(10u32.into()),
268+
min_revenue_split_time_to_start: Some(10u32.into()),
269+
sale_platform_fee: Some(Permill::from_percent(1)),
270+
amm_buy_tx_fees: Some(Permill::from_percent(1)),
271+
amm_sell_tx_fees: Some(Permill::from_percent(1)),
272+
bloat_bond: Some(1000u32.into()),
273+
};
274+
let origin = RawOrigin::Root;
275+
}: _(origin, parameters.clone())
276+
verify {
277+
278+
assert_last_event::<T>(
279+
RawEvent::TokenConstraintsUpdated(
280+
parameters
281+
).into()
282+
)
283+
}
260284

261285
// Worst case scenario:
262286
// - source_accout.vesting_schedules.len() is T::MaxVestingSchedulesPerAccountPerToken
@@ -791,4 +815,11 @@ mod tests {
791815
assert_ok!(Token::test_benchmark_sell_on_amm());
792816
});
793817
}
818+
819+
#[test]
820+
fn test_update_token_constraints() {
821+
build_test_externalities(GenesisConfigBuilder::new_empty().build()).execute_with(|| {
822+
assert_ok!(Token::test_benchmark_update_token_constraints());
823+
});
824+
}
794825
}

runtime-modules/project-token/src/events.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![allow(clippy::unused_unit)]
22

33
use crate::types::{
4-
AmmCurveOf, JoyBalanceOf, RevenueSplitId, TokenIssuanceParametersOf, TokenSaleId, TokenSaleOf,
5-
TransferPolicyOf, ValidatedTransfersOf, YearlyRate,
4+
AmmCurveOf, JoyBalanceOf, RevenueSplitId, TokenConstraintsOf, TokenIssuanceParametersOf,
5+
TokenSaleId, TokenSaleOf, TransferPolicyOf, ValidatedTransfersOf, YearlyRate,
66
};
77
use common::MembershipTypes;
88
use frame_support::decl_event;
@@ -22,6 +22,7 @@ decl_event! {
2222
ValidatedTransfers = ValidatedTransfersOf<T>,
2323
TokenSale = TokenSaleOf<T>,
2424
AmmCurve = AmmCurveOf<T>,
25+
TokenConstraints = TokenConstraintsOf<T>
2526

2627
{
2728
/// Token amount is transferred from src to dst
@@ -189,6 +190,11 @@ decl_event! {
189190
/// Pallet Frozen status toggled
190191
/// Params:
191192
/// - new frozen status (true | false)
192-
FrozenStatusUpdated(bool)
193+
FrozenStatusUpdated(bool),
194+
195+
/// Governance parameters updated
196+
/// Params:
197+
/// - governance parameters
198+
TokenConstraintsUpdated(TokenConstraints),
193199
}
194200
}

runtime-modules/project-token/src/lib.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ use traits::PalletToken;
6565
use types::*;
6666

6767
pub mod weights;
68+
pub use types::TokenConstraintsOf;
6869
pub use weights::WeightInfo;
6970

7071
type WeightInfoToken<T> = <T as Config>::WeightInfo;
@@ -214,6 +215,66 @@ decl_module! {
214215
/// Predefined errors.
215216
type Error = Error<T>;
216217

218+
/// Allow Governance to Set constraints
219+
/// Preconditions:
220+
/// - origin is signed by `root`
221+
/// PostConditions:
222+
/// - governance parameters storage value set to the provided values
223+
/// <weight>
224+
///
225+
/// ## Weight
226+
/// `O (1)`
227+
/// # </weight>
228+
#[weight = WeightInfoToken::<T>::update_token_constraints()]
229+
pub fn update_token_constraints(
230+
origin,
231+
parameters: TokenConstraintsOf<T>
232+
) {
233+
// update parameters via proposal
234+
ensure_root(origin)?;
235+
236+
// == MUTATION SAFE ==
237+
238+
if let Some(new_max_yearly_rate) = parameters.max_yearly_rate {
239+
MaxYearlyPatronageRate::put(new_max_yearly_rate);
240+
}
241+
242+
if let Some(new_min_amm_slope) = parameters.min_amm_slope {
243+
MinAmmSlopeParameter::<T>::put(new_min_amm_slope);
244+
}
245+
246+
if let Some(new_min_sale_duration) = parameters.min_sale_duration {
247+
MinSaleDuration::<T>::put(new_min_sale_duration);
248+
}
249+
250+
if let Some(new_min_revenue_split_duration) = parameters.min_revenue_split_duration {
251+
MinRevenueSplitDuration::<T>::put(new_min_revenue_split_duration);
252+
}
253+
254+
if let Some(new_min_revenue_split_time_to_start) = parameters.min_revenue_split_time_to_start {
255+
MinRevenueSplitTimeToStart::<T>::put(new_min_revenue_split_time_to_start);
256+
}
257+
258+
if let Some(new_sale_platform_fee) = parameters.sale_platform_fee {
259+
SalePlatformFee::put(new_sale_platform_fee);
260+
}
261+
262+
if let Some(new_amm_buy_tx_fee) = parameters.amm_buy_tx_fees {
263+
AmmBuyTxFees::put(new_amm_buy_tx_fee);
264+
}
265+
266+
if let Some(new_amm_sell_tx_fee) = parameters.amm_sell_tx_fees {
267+
AmmSellTxFees::put(new_amm_sell_tx_fee);
268+
}
269+
270+
if let Some(new_bloat_bond) = parameters.bloat_bond {
271+
BloatBond::<T>::put(new_bloat_bond);
272+
}
273+
274+
Self::deposit_event(RawEvent::TokenConstraintsUpdated(parameters));
275+
276+
}
277+
217278
/// Allow to transfer from `src_member_id` account to the various `outputs` beneficiaries
218279
/// in the specified amounts.
219280
///

runtime-modules/project-token/src/types.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use storage::{BagId, DataObjectCreationParameters};
3333
use crate::{errors::Error, Config, RepayableBloatBondOf};
3434

3535
// trait "aliases"
36+
// `BlockNumber` will be implemented as `u64` in the runtime configuration
3637
pub trait BlockNumberTrait: Copy + AtLeast32BitUnsigned + Saturating + Default {}
3738
impl<T: Copy + AtLeast32BitUnsigned + Saturating + Default> BlockNumberTrait for T {}
3839

@@ -44,6 +45,21 @@ impl<T: BalanceTrait + FixedPointOperand + Sum> TokenBalanceTrait for T {}
4445
pub trait JoyTokenBalanceTrait: BalanceTrait {}
4546
impl<T: BalanceTrait> JoyTokenBalanceTrait for T {}
4647

48+
/// Parameer pack for governance constraints
49+
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
50+
#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo, MaxEncodedLen)]
51+
pub struct TokenConstraints<Balance, BlockNumber, JoyBalance> {
52+
pub max_yearly_rate: Option<YearlyRate>,
53+
pub min_amm_slope: Option<Balance>,
54+
pub min_sale_duration: Option<BlockNumber>,
55+
pub min_revenue_split_duration: Option<BlockNumber>,
56+
pub min_revenue_split_time_to_start: Option<BlockNumber>,
57+
pub sale_platform_fee: Option<Permill>,
58+
pub amm_buy_tx_fees: Option<Permill>,
59+
pub amm_sell_tx_fees: Option<Permill>,
60+
pub bloat_bond: Option<JoyBalance>,
61+
}
62+
4763
/// Source of tokens subject to vesting that were acquired by an account
4864
/// either through purchase or during initial issuance
4965
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
@@ -1677,3 +1693,7 @@ pub type AmmCurveOf<T> = AmmCurve<TokenBalanceOf<T>>;
16771693

16781694
/// Alias for the amm params
16791695
pub type AmmParamsOf<T> = AmmParams<TokenBalanceOf<T>>;
1696+
1697+
/// Alias for the governance parameters
1698+
pub type TokenConstraintsOf<T> =
1699+
TokenConstraints<TokenBalanceOf<T>, <T as frame_system::Config>::BlockNumber, JoyBalanceOf<T>>;

runtime-modules/project-token/src/weights.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub trait WeightInfo {
5555
fn buy_on_amm_with_account_creation() -> Weight;
5656
fn buy_on_amm_with_existing_account() -> Weight;
5757
fn sell_on_amm() -> Weight;
58+
fn update_token_constraints() -> Weight;
5859
}
5960

6061
/// Weights for project_token using the Substrate node and recommended hardware.
@@ -64,6 +65,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
6465
// Proof: Token PalletFrozen (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen)
6566
// Storage: Membership MembershipById (r:25 w:0)
6667
// Proof: Membership MembershipById (max_values: None, max_size: Some(125), added: 2600, mode: MaxEncodedLen)
68+
fn update_token_constraints() -> Weight {
69+
Weight::from_parts(0, 0)
70+
}
71+
// Storage: Membership MembershipById (r:2 w:0)
6772
// Storage: Token TokenInfoById (r:1 w:1)
6873
// Proof: Token TokenInfoById (max_values: None, max_size: Some(352), added: 2827, mode: MaxEncodedLen)
6974
// Storage: Token AccountInfoByTokenAndMember (r:25 w:25)
@@ -331,4 +336,7 @@ impl WeightInfo for () {
331336
fn sell_on_amm() -> Weight {
332337
Weight::from_parts(0, 0)
333338
}
339+
fn update_token_constraints() -> Weight {
340+
Weight::from_parts(0, 0)
341+
}
334342
}

runtime-modules/proposals/codex/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ token = { package = 'pallet-project-token', default-features = false, path = '..
3535
frame-benchmarking = { package = 'frame-benchmarking', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9', optional = true }
3636

3737
[dev-dependencies]
38+
storage = { package = 'pallet-storage', default-features = false, path = '../../storage' }
3839
sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
3940
sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
4041
sp-staking = { package = 'sp-staking', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
@@ -75,6 +76,7 @@ std = [
7576
'membership/std',
7677
'content/std',
7778
'token/std',
79+
'storage/std',
7880
'staking/std',
7981
'scale-info/std',
8082
'frame-election-provider-support/std',

runtime-modules/proposals/codex/src/benchmarking.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ use working_group::{
3232
const SEED: u32 = 0;
3333
const MAX_KILOBYTES_METADATA: u32 = 100;
3434

35+
pub type BalanceOf<T> = <T as balances::Config>::Balance;
36+
3537
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
3638
let events = System::<T>::events();
3739
let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();
@@ -65,7 +67,7 @@ fn member_funded_account<T: Config + membership::Config>() -> (T::AccountId, T::
6567
let handle = handle_from_id(member_id.saturated_into());
6668

6769
// Give balance for buying membership
68-
let _ = Balances::<T>::make_free_balance_be(&account_id, T::Balance::max_value());
70+
let _ = Balances::<T>::make_free_balance_be(&account_id, BalanceOf::<T>::max_value());
6971

7072
let params = membership::BuyMembershipParameters {
7173
root_account: account_id.clone(),
@@ -77,7 +79,7 @@ fn member_funded_account<T: Config + membership::Config>() -> (T::AccountId, T::
7779

7880
Membership::<T>::buy_membership(RawOrigin::Signed(account_id.clone()).into(), params).unwrap();
7981

80-
let _ = Balances::<T>::make_free_balance_be(&account_id, T::Balance::max_value());
82+
let _ = Balances::<T>::make_free_balance_be(&account_id, BalanceOf::<T>::max_value());
8183

8284
Membership::<T>::add_staking_account_candidate(
8385
RawOrigin::Signed(account_id.clone()).into(),
@@ -872,15 +874,15 @@ benchmarks! {
872874
size: u64::MAX,
873875
ipfs_content_id: Vec::from_iter((0..(i * 1000)).map(|v| u8::MAX))
874876
},
875-
expected_data_size_fee: u128::MAX.saturated_into::<T::Balance>(),
876-
expected_data_object_state_bloat_bond: u128::MAX.saturated_into::<T::Balance>()
877+
expected_data_size_fee: u128::MAX.saturated_into::<BalanceOf::<T>>(),
878+
expected_data_object_state_bloat_bond: u128::MAX.saturated_into::<BalanceOf::<T>>()
877879
};
878880
let proposal_details = ProposalDetails::UpdateChannelPayouts(
879881
content::UpdateChannelPayoutsParameters::<T> {
880882
commitment: Some(commitment),
881883
payload: Some(payload),
882-
min_cashout_allowed: Some(u128::MAX.saturated_into::<T::Balance>()),
883-
max_cashout_allowed: Some(u128::MAX.saturated_into::<T::Balance>()),
884+
min_cashout_allowed: Some(u128::MAX.saturated_into::<BalanceOf::<T>>()),
885+
max_cashout_allowed: Some(u128::MAX.saturated_into::<BalanceOf::<T>>()),
884886
channel_cashouts_enabled: Some(true),
885887
}
886888
);

0 commit comments

Comments
 (0)