Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/crt constraints proposal #5103

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chain-metadata.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions query-node/chain-metadata/2003.json

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions runtime-modules/project-token/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,30 @@ benchmarks! {
where T: Config
}

// Worst case scenario:
// all parameters needs to be updated
update_governance_parameters {
let parameters = GovernanceParameters {
max_yearly_rate Some(YearlyRate(Permill::from_penrcent(15))),
ignazio-bovo marked this conversation as resolved.
Show resolved Hide resolved
min_amm_slope: Some(100u32.into()),
min_sale_duration: Some(10u32.into()),
min_revenue_split_duration: Some(10u32.into()),
min_revenue_split_time_to_start: Some(10u32.into()),
sale_platform_fee: Some(Permill::from_percent(1)),
amm_buy_tx_fees: Some(Permill::from_percent(1)),
amm_sell_tx_fees: Some(Permill::from_percent(1)),
bloat_bond: Some(1000u32.into()),
}
ignazio-bovo marked this conversation as resolved.
Show resolved Hide resolved
let origin = RawOrigin::root_account()
ignazio-bovo marked this conversation as resolved.
Show resolved Hide resolved
}: (origin, parameters.clone()) {

assert_last_event::<T>(
RawEvent::GovernanceParametersUpdated(
parameters
).into()
);
}

// Worst case scenario:
// - source_accout.vesting_schedules.len() is T::MaxVestingSchedulesPerAccountPerToken
// - source_account.split_staking_status is Some(_)
Expand Down
12 changes: 9 additions & 3 deletions runtime-modules/project-token/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![allow(clippy::unused_unit)]

use crate::types::{
AmmCurveOf, JoyBalanceOf, RevenueSplitId, TokenIssuanceParametersOf, TokenSaleId, TokenSaleOf,
TransferPolicyOf, ValidatedTransfersOf, YearlyRate,
AmmCurveOf, GovernanceParametersOf, JoyBalanceOf, RevenueSplitId, TokenIssuanceParametersOf,
TokenSaleId, TokenSaleOf, TransferPolicyOf, ValidatedTransfersOf, YearlyRate,
};
use common::MembershipTypes;
use frame_support::decl_event;
Expand All @@ -22,6 +22,7 @@ decl_event! {
ValidatedTransfers = ValidatedTransfersOf<T>,
TokenSale = TokenSaleOf<T>,
AmmCurve = AmmCurveOf<T>,
GovernanceParameters = GovernanceParametersOf<T>

{
/// Token amount is transferred from src to dst
Expand Down Expand Up @@ -189,6 +190,11 @@ decl_event! {
/// Pallet Frozen status toggled
/// Params:
/// - new frozen status (true | false)
FrozenStatusUpdated(bool)
FrozenStatusUpdated(bool),

/// Governance parameters updated
/// Params:
/// - governance parameters
GovernanceParametersUpdated(GovernanceParameters),
}
}
61 changes: 61 additions & 0 deletions runtime-modules/project-token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ use traits::PalletToken;
use types::*;

pub mod weights;
pub use types::GovernanceParametersOf;
pub use weights::WeightInfo;

type WeightInfoToken<T> = <T as Config>::WeightInfo;
Expand Down Expand Up @@ -214,6 +215,66 @@ decl_module! {
/// Predefined errors.
type Error = Error<T>;

/// Allow Governance to Set constraints
/// Preconditions:
/// - origin is signed by `root`
/// PostConditions:
/// - governance parameters storage value set to the provided values
/// <weight>
///
/// ## Weight
/// `O (1)`
/// # </weight>
#[weight = WeightInfoToken::<T>::update_governance_parameters()]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name change is not reflected in the function.

Suggested change
#[weight = WeightInfoToken::<T>::update_governance_parameters()]
#[weight = WeightInfoToken::<T>::update_token_constraints()]

pub fn update_governance_parameters(
origin,
parameters: GovernanceParametersOf<T>
) {
// update parameters via proposal
ensure_root(origin)?;

// == MUTATION SAFE ==

if let Some(new_max_yearly_rate) = parameters.max_yearly_rate {
MaxYearlyPatronageRate::put(new_max_yearly_rate);
}

if let Some(new_min_amm_slope) = parameters.min_amm_slope {
MinAmmSlopeParameter::<T>::put(new_min_amm_slope);
}

if let Some(new_min_sale_duration) = parameters.min_sale_duration {
MinSaleDuration::<T>::put(new_min_sale_duration);
}

if let Some(new_min_revenue_split_duration) = parameters.min_revenue_split_duration {
MinRevenueSplitDuration::<T>::put(new_min_revenue_split_duration);
}

if let Some(new_min_revenue_split_time_to_start) = parameters.min_revenue_split_time_to_start {
MinRevenueSplitDuration::<T>::put(new_min_revenue_split_time_to_start);
ignazio-bovo marked this conversation as resolved.
Show resolved Hide resolved
}

if let Some(new_sale_platform_fee) = parameters.sale_platform_fee {
SalePlatformFee::put(new_sale_platform_fee);
}

if let Some(new_amm_buy_tx_fee) = parameters.amm_buy_tx_fees {
AmmBuyTxFees::put(new_amm_buy_tx_fee);
}

if let Some(new_amm_sell_tx_fee) = parameters.amm_sell_tx_fees {
AmmSellTxFees::put(new_amm_sell_tx_fee);
}

if let Some(new_bloat_bond) = parameters.bloat_bond {
BloatBond::<T>::put(new_bloat_bond);
}

Self::deposit_event(RawEvent::GovernanceParametersUpdated(parameters));

}

/// Allow to transfer from `src_member_id` account to the various `outputs` beneficiaries
/// in the specified amounts.
///
Expand Down
23 changes: 23 additions & 0 deletions runtime-modules/project-token/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use storage::{BagId, DataObjectCreationParameters};
use crate::{errors::Error, Config, RepayableBloatBondOf};

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

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

/// Parameer pack for governance constraints
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo, MaxEncodedLen)]
pub struct GovernanceParameters<Balance, BlockNumber, JoyBalance> {
pub max_yearly_rate: Option<YearlyRate>,
pub min_amm_slope: Option<Balance>,
pub min_sale_duration: Option<BlockNumber>,
pub min_revenue_split_duration: Option<BlockNumber>,
pub min_revenue_split_time_to_start: Option<BlockNumber>,
pub sale_platform_fee: Option<Permill>,
pub amm_buy_tx_fees: Option<Permill>,
pub amm_sell_tx_fees: Option<Permill>,
pub bloat_bond: Option<JoyBalance>,
}

/// Source of tokens subject to vesting that were acquired by an account
/// either through purchase or during initial issuance
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
Expand Down Expand Up @@ -1677,3 +1693,10 @@ pub type AmmCurveOf<T> = AmmCurve<TokenBalanceOf<T>>;

/// Alias for the amm params
pub type AmmParamsOf<T> = AmmParams<TokenBalanceOf<T>>;

/// Alias for the governance parameters
pub type GovernanceParametersOf<T> = GovernanceParameters<
TokenBalanceOf<T>,
<T as frame_system::Config>::BlockNumber,
JoyBalanceOf<T>,
>;
8 changes: 8 additions & 0 deletions runtime-modules/project-token/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub trait WeightInfo {
fn buy_on_amm_with_account_creation() -> Weight;
fn buy_on_amm_with_existing_account() -> Weight;
fn sell_on_amm() -> Weight;
fn update_governance_parameters() -> Weight;
}

/// Weights for project_token using the Substrate node and recommended hardware.
Expand All @@ -64,6 +65,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof: Token PalletFrozen (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen)
// Storage: Membership MembershipById (r:25 w:0)
// Proof: Membership MembershipById (max_values: None, max_size: Some(125), added: 2600, mode: MaxEncodedLen)
fn update_governance_parameters() -> Weight {
Weight::from_parts(0, 0)
}
// Storage: Membership MembershipById (r:2 w:0)
// Storage: Token TokenInfoById (r:1 w:1)
// Proof: Token TokenInfoById (max_values: None, max_size: Some(352), added: 2827, mode: MaxEncodedLen)
// Storage: Token AccountInfoByTokenAndMember (r:25 w:25)
Expand Down Expand Up @@ -331,4 +336,7 @@ impl WeightInfo for () {
fn sell_on_amm() -> Weight {
Weight::from_parts(0, 0)
}
fn update_governance_parameters() -> Weight {
Weight::from_parts(0, 0)
}
}
68 changes: 36 additions & 32 deletions runtime-modules/proposals/codex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,47 @@ edition = '2018'

[dependencies]
serde = { version = "1.0.101", optional = true, features = ["derive"] }
codec = { package = 'parity-scale-codec', version = '3.1.2', default-features = false, features = ['derive'] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
sp-std = { package = 'sp-std', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
frame-support = { package = 'frame-support', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
sp-arithmetic = { package = 'sp-arithmetic', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
frame-system = { package = 'frame-system', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
staking = { package = 'pallet-staking', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
pallet-timestamp = { package = 'pallet-timestamp', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
working-group = { package = 'pallet-working-group', default-features = false, path = '../../working-group'}
common = { package = 'pallet-common', default-features = false, path = '../../common'}
proposals-engine = { package = 'pallet-proposals-engine', default-features = false, path = '../engine'}
proposals-discussion = { package = 'pallet-proposals-discussion', default-features = false, path = '../discussion'}
constitution = { package = 'pallet-constitution', default-features = false, path = '../../constitution'}
membership = { package = 'pallet-membership', default-features = false, path = '../../membership'}
content = { package = 'pallet-content', default-features = false, path = '../../content'}
balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9', optional = true}
codec = { package = 'parity-scale-codec', version = '3.1.2', default-features = false, features = [
'derive',
] }
scale-info = { version = "2.1.1", default-features = false, features = [
"derive",
] }
sp-std = { package = 'sp-std', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
frame-support = { package = 'frame-support', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
sp-arithmetic = { package = 'sp-arithmetic', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
frame-system = { package = 'frame-system', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
staking = { package = 'pallet-staking', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
pallet-timestamp = { package = 'pallet-timestamp', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
working-group = { package = 'pallet-working-group', default-features = false, path = '../../working-group' }
common = { package = 'pallet-common', default-features = false, path = '../../common' }
proposals-engine = { package = 'pallet-proposals-engine', default-features = false, path = '../engine' }
proposals-discussion = { package = 'pallet-proposals-discussion', default-features = false, path = '../discussion' }
constitution = { package = 'pallet-constitution', default-features = false, path = '../../constitution' }
membership = { package = 'pallet-membership', default-features = false, path = '../../membership' }
content = { package = 'pallet-content', default-features = false, path = '../../content' }
balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9', optional = true }
token = { package = 'pallet-project-token', default-features = false, path = '../../project-token' }

# Benchmarking dependencies
frame-benchmarking = { package = 'frame-benchmarking', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9', optional = true}
council = { package = 'pallet-council', default-features = false, path = '../../council', optional = true}
frame-benchmarking = { package = 'frame-benchmarking', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9', optional = true }
council = { package = 'pallet-council', default-features = false, path = '../../council', optional = true }

[dev-dependencies]
sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
sp-staking = { package = 'sp-staking', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
pallet-staking-reward-curve = { package = 'pallet-staking-reward-curve', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
strum = {version = "0.19", default-features = false}
staking-handler = { package = 'pallet-staking-handler', default-features = false, path = '../../staking-handler'}
referendum = { package = 'pallet-referendum', default-features = false, path = '../../referendum'}
council = { package = 'pallet-council', default-features = false, path = '../../council'}
balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
frame-election-provider-support = { package = 'frame-election-provider-support', git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
pallet-bags-list = { package = 'pallet-bags-list', git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
sp-npos-elections = { package = 'sp-npos-elections', git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
sp-staking = { package = 'sp-staking', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
pallet-staking-reward-curve = { package = 'pallet-staking-reward-curve', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
strum = { version = "0.19", default-features = false }
staking-handler = { package = 'pallet-staking-handler', default-features = false, path = '../../staking-handler' }
referendum = { package = 'pallet-referendum', default-features = false, path = '../../referendum' }
council = { package = 'pallet-council', default-features = false, path = '../../council' }
balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
frame-election-provider-support = { package = 'frame-election-provider-support', git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
pallet-bags-list = { package = 'pallet-bags-list', git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
sp-npos-elections = { package = 'sp-npos-elections', git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }

[features]
default = ['std']
Expand Down
22 changes: 22 additions & 0 deletions runtime-modules/proposals/codex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub trait Config:
+ proposals_discussion::Config
+ common::membership::MembershipTypes
+ staking::Config
+ token::Config
+ proposals_engine::Config
+ working_group::Config<ForumWorkingGroupInstance>
+ working_group::Config<StorageWorkingGroupInstance>
Expand Down Expand Up @@ -279,6 +280,11 @@ pub trait Config:
type SetPalletFozenStatusProposalParameters: Get<
ProposalParameters<Self::BlockNumber, BalanceOf<Self>>,
>;

/// `Update pallet project token` proposal parameters
type UpdateTokenPalletGovernanceParameters: Get<
ProposalParameters<Self::BlockNumber, BalanceOf<Self>>,
>;
}

/// Specialized alias of GeneralProposalParams
Expand Down Expand Up @@ -385,6 +391,7 @@ decl_error! {

/// Arithmeic Error
ArithmeticError,

}
}

Expand Down Expand Up @@ -506,6 +513,9 @@ decl_module! {
const SetPalletFozenStatusProposalParameters:
ProposalParameters<T::BlockNumber, BalanceOf<T>> = T::SetPalletFozenStatusProposalParameters::get();

/// pallet token governance parameters proposal
const UpdateTokenPalletGovernanceParameters:
ProposalParameters<T::BlockNumber, BalanceOf<T>> = T::UpdateTokenPalletGovernanceParameters::get();

/// Create a proposal, the type of proposal depends on the `proposal_details` variant
///
Expand Down Expand Up @@ -877,6 +887,9 @@ impl<T: Config> Module<T> {
ProposalDetails::SetPalletFozenStatus(..) => {
// Note: No checks for this proposal for now
}
ProposalDetails::UpdateTokenPalletGovernanceParameters(..) => {
// Note: No checks for this proposal for now
}
}

Ok(())
Expand Down Expand Up @@ -947,6 +960,9 @@ impl<T: Config> Module<T> {
ProposalDetails::SetPalletFozenStatus(..) => {
T::SetPalletFozenStatusProposalParameters::get()
}
ProposalDetails::UpdateTokenPalletGovernanceParameters(..) => {
T::UpdateTokenPalletGovernanceParameters::get()
}
}
}

Expand Down Expand Up @@ -1114,6 +1130,12 @@ impl<T: Config> Module<T> {
to_kb(description_length.saturated_into()),
)
}
ProposalDetails::UpdateTokenPalletGovernanceParameters(..) => {
WeightInfoCodex::<T>::create_proposal_update_token_pallet_governance_parameters(
to_kb(title_length.saturated_into()),
to_kb(description_length.saturated_into()),
)
}
}
}
}
Expand Down
Loading
Loading