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 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2f03263
feat: :sparkles: create proposal for setting crt parameters
ignazio-bovo Mar 9, 2023
6e33046
feat: :art: generate types and metadata
ignazio-bovo Mar 14, 2024
c63141d
feat: :sparkles: generate types & metadata
ignazio-bovo Mar 14, 2024
72231ee
Merge branch 'luxor' into pr/ignazio-bovo/5103
ignazio-bovo Mar 27, 2024
c179f7f
feat: :truck: rename GovernanceParameters -> Token Constraints
ignazio-bovo Mar 27, 2024
661d2de
fix: :green_heart: build errors
ignazio-bovo Mar 28, 2024
ad78e7c
Merge branch 'luxor' into pr/ignazio-bovo/5103
ignazio-bovo Mar 28, 2024
38e8a94
fix: :zap: address comments and fix build errorrs
ignazio-bovo Mar 28, 2024
48ea043
feat: :art: generate types and metadata
ignazio-bovo Mar 28, 2024
0506851
fix: :pencil2:
ignazio-bovo Mar 28, 2024
f2cea6d
fix: :zap: benchmarks
ignazio-bovo Mar 29, 2024
dac1968
fix: :zap: integration tests
ignazio-bovo Mar 29, 2024
8d1b1b2
Update runtime-modules/proposals/codex/src/types.rs
ignazio-bovo Apr 2, 2024
ac2716f
Update runtime-modules/project-token/src/benchmarking.rs
ignazio-bovo Apr 2, 2024
37c3066
Update runtime-modules/proposals/codex/src/types.rs
ignazio-bovo Apr 2, 2024
13bfd25
Update runtime-modules/project-token/src/benchmarking.rs
ignazio-bovo Apr 2, 2024
50cd923
fix: :zap: benchmark import
ignazio-bovo Apr 2, 2024
48712c1
fix: :art: benchmarks
ignazio-bovo Apr 2, 2024
52537b9
fix: :green_heart: ci fixes
ignazio-bovo Apr 2, 2024
a173dd5
fix: :zap: codex benchmarking
ignazio-bovo Apr 2, 2024
e115d51
fix: :wrench: update chain metadata and types
ignazio-bovo Apr 2, 2024
6a3cf56
Merge branch 'luxor' into pr/ignazio-bovo/5103
ignazio-bovo Apr 3, 2024
b2046dd
chore: :memo: update chain metadata and types
ignazio-bovo Apr 3, 2024
3dc4539
Update runtime-modules/project-token/src/lib.rs
ignazio-bovo Apr 3, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion chain-metadata.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion 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 = TokenConstraints {
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::TokenConstraintsUpdated(
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, JoyBalanceOf, RevenueSplitId, TokenConstraintsOf, 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>,
TokenConstraints = TokenConstraintsOf<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
TokenConstraintsUpdated(TokenConstraints),
}
}
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::TokenConstraintsOf;
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: TokenConstraintsOf<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::TokenConstraintsUpdated(parameters));

}

/// Allow to transfer from `src_member_id` account to the various `outputs` beneficiaries
/// in the specified amounts.
///
Expand Down
20 changes: 20 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 TokenConstraints<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,7 @@ 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 TokenConstraintsOf<T> =
TokenConstraints<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)
}
}
2 changes: 2 additions & 0 deletions runtime-modules/proposals/codex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ token = { package = 'pallet-project-token', default-features = false, path = '..
frame-benchmarking = { package = 'frame-benchmarking', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9', optional = true }

[dev-dependencies]
storage = { package = 'pallet-storage', default-features = false, path = '../../storage' }
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' }
Expand Down Expand Up @@ -74,6 +75,7 @@ std = [
'membership/std',
'content/std',
'token/std',
'storage/std',
'staking/std',
'scale-info/std',
'frame-election-provider-support/std',
Expand Down
21 changes: 21 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 @@ -281,6 +282,11 @@ pub trait Config:
ProposalParameters<Self::BlockNumber, BalanceOf<Self>>,
>;

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

/// `Decrease Council Budget` proposal parameters
type DecreaseCouncilBudgetProposalParameters: Get<
ProposalParameters<Self::BlockNumber, BalanceOf<Self>>,
Expand Down Expand Up @@ -520,6 +526,9 @@ decl_module! {
const SetPalletFozenStatusProposalParameters:
ProposalParameters<T::BlockNumber, BalanceOf<T>> = T::SetPalletFozenStatusProposalParameters::get();

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

/// Create a proposal, the type of proposal depends on the `proposal_details` variant
///
Expand Down Expand Up @@ -891,6 +900,9 @@ impl<T: Config> Module<T> {
ProposalDetails::SetPalletFozenStatus(..) => {
// Note: No checks for this proposal for now
}
ProposalDetails::UpdateTokenPalletTokenConstraints(..) => {
// Note: No checks for this proposal for now
}
ProposalDetails::DecreaseCouncilBudget(reduction_amount) => {
ensure!(
!(*reduction_amount).is_zero(),
Expand Down Expand Up @@ -967,6 +979,9 @@ impl<T: Config> Module<T> {
ProposalDetails::SetPalletFozenStatus(..) => {
T::SetPalletFozenStatusProposalParameters::get()
}
ProposalDetails::UpdateTokenPalletTokenConstraints(..) => {
T::UpdateTokenPalletTokenConstraints::get()
}
ProposalDetails::DecreaseCouncilBudget(..) => {
T::DecreaseCouncilBudgetProposalParameters::get()
}
Expand Down Expand Up @@ -1137,6 +1152,12 @@ impl<T: Config> Module<T> {
to_kb(description_length.saturated_into()),
)
}
ProposalDetails::UpdateTokenPalletTokenConstraints(..) => {
WeightInfoCodex::<T>::create_proposal_update_token_pallet_governance_parameters(
to_kb(title_length.saturated_into()),
to_kb(description_length.saturated_into()),
)
}
ProposalDetails::DecreaseCouncilBudget(..) => {
WeightInfoCodex::<T>::create_proposal_decrease_council_budget(
to_kb(title_length.saturated_into()),
Expand Down
74 changes: 73 additions & 1 deletion runtime-modules/proposals/codex/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ frame_support::construct_runtime!(
Balances: balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Staking: staking::{Pallet, Call, Config<T>, Storage, Event<T>},
BagsList: pallet_bags_list::{Pallet, Call, Storage, Event<T>},

Membership: membership::{Pallet, Call, Storage, Event<T>},
ProposalsCodex: proposals_codex::{Pallet, Call, Storage, Event<T>},
ProposalsEngine: proposals_engine::{Pallet, Call, Storage, Event<T>},
Expand All @@ -105,6 +104,8 @@ frame_support::construct_runtime!(
OperationsWorkingGroupGamma: working_group::<Instance8>::{Pallet, Call, Storage, Event<T>},
DistributionWorkingGroup: working_group::<Instance9>::{Pallet, Call, Storage, Event<T>},
Council: council::{Pallet, Call, Storage, Event<T>},
Storage: storage::{Pallet, Call, Storage, Event<T>},
Token: token::{Pallet, Call, Storage, Event<T>},
}
);

Expand Down Expand Up @@ -318,6 +319,76 @@ impl membership::Config for Test {
type DefaultMemberInvitesCount = DefaultMemberInvitesCount;
}

parameter_types! {
// constants for token::Config
pub const TokenModuleId: PalletId = PalletId(*b"m__Token");
pub const MaxVestingSchedulesPerAccountPerToken: u32 = 3;
pub const BlocksPerYear: u32 = 5259487; // blocks every 6s
pub const MaxOutputs: u32 = 256;
// constants for storage::Config
pub const MaxNumberOfDataObjectsPerBag: u64 = 4;
pub const MaxDistributionBucketFamilyNumber: u64 = 4;
pub const DataObjectDeletionPrize: u64 = 15;
pub const StorageModuleId: PalletId = PalletId(*b"mstorage"); // module storage
pub const BlacklistSizeLimit: u64 = 1;
pub const MaxNumberOfPendingInvitationsPerDistributionBucket: u32 = 1;
pub const InitialStorageBucketsNumberForDynamicBag: u64 = 3;
pub const MaxRandomIterationNumber: u64 = 3;
pub const DefaultMemberDynamicBagNumberOfStorageBuckets: u32 = 3;
pub const DefaultChannelDynamicBagNumberOfStorageBuckets: u32 = 4;
pub const MaxDataObjectSize: u64 = 1_000_000_000;
pub const MinStorageBucketsPerBag: u32 = 3;
pub const MaxStorageBucketsPerBag: u32 = 10;
pub const MinDistributionBucketsPerBag: u32 = 3;
pub const MaxDistributionBucketsPerBag: u32 = 10;
pub const MaxNumberOfOperatorsPerDistributionBucket: u32 = 5;
}

impl storage::Config for Test {
type RuntimeEvent = RuntimeEvent;
type DataObjectId = u64;
type StorageBucketId = u64;
type DistributionBucketIndex = u64;
type DistributionBucketFamilyId = u64;
type DistributionBucketOperatorId = u64;
type ChannelId = u64;
type BlacklistSizeLimit = BlacklistSizeLimit;
type ModuleId = StorageModuleId;
type MinStorageBucketsPerBag = MinStorageBucketsPerBag;
type MaxStorageBucketsPerBag = MaxStorageBucketsPerBag;
type MinDistributionBucketsPerBag = MinDistributionBucketsPerBag;
type MaxDistributionBucketsPerBag = MaxDistributionBucketsPerBag;
type DefaultMemberDynamicBagNumberOfStorageBuckets =
DefaultMemberDynamicBagNumberOfStorageBuckets;
type DefaultChannelDynamicBagNumberOfStorageBuckets =
DefaultChannelDynamicBagNumberOfStorageBuckets;
type MaxDistributionBucketFamilyNumber = MaxDistributionBucketFamilyNumber;
type MaxNumberOfPendingInvitationsPerDistributionBucket =
MaxNumberOfPendingInvitationsPerDistributionBucket;
type MaxNumberOfOperatorsPerDistributionBucket = MaxNumberOfOperatorsPerDistributionBucket;
type ContentId = u64;
type MaxDataObjectSize = MaxDataObjectSize;
type StorageWorkingGroup = Wg;
type DistributionWorkingGroup = Wg;
type ModuleAccountInitialBalance = ExistentialDeposit;
type WeightInfo = ();
}

impl token::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Balance = u64;
type TokenId = u64;
type DataObjectStorage = storage::Module<Self>;
type ModuleId = TokenModuleId;
type JoyExistentialDeposit = ExistentialDeposit;
type MaxVestingSchedulesPerAccountPerToken = MaxVestingSchedulesPerAccountPerToken;
type BlocksPerYear = BlocksPerYear;
type WeightInfo = ();
type MemberOriginValidator = membership::Module<Self>;
type MembershipInfoProvider = membership::Module<Self>;
type MaxOutputs = MaxOutputs;
}

pub struct Wg;
impl common::working_group::WorkingGroupBudgetHandler<u64, u64> for Wg {
fn get_budget() -> u64 {
Expand Down Expand Up @@ -670,6 +741,7 @@ impl crate::Config for Test {
type FundingRequestProposalMaxAccounts = FundingRequestProposalMaxAccounts;
type SetMaxValidatorCountProposalMaxValidators = SetMaxValidatorCountProposalMaxValidators;
type SetPalletFozenStatusProposalParameters = DefaultProposalParameters;
type UpdateTokenPalletTokenConstraints = DefaultProposalParameters;
type DecreaseCouncilBudgetProposalParameters = DefaultProposalParameters;
}

Expand Down
Loading
Loading