From 5febf20f08414068877132c1522607fa0b6190aa Mon Sep 17 00:00:00 2001 From: Raid5594 <52794079+Raid5594@users.noreply.github.com> Date: Tue, 19 Dec 2023 14:36:11 +0100 Subject: [PATCH] DDC pallets for the `cere` runtime (#189) Co-authored-by: yahortsaryk --- Cargo.lock | 6 +++ runtime/cere-dev/Cargo.toml | 27 +++++++------ runtime/cere-dev/src/lib.rs | 8 ++-- runtime/cere/Cargo.toml | 30 +++++++++++--- runtime/cere/src/lib.rs | 80 ++++++++++++++++++++++++++++++++++++- 5 files changed, 126 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 68d46882e..5a86e9baf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -968,6 +968,7 @@ version = "4.8.2" dependencies = [ "cere-runtime-common", "cere-runtime-constants", + "ddc-traits", "frame-benchmarking", "frame-election-provider-support", "frame-executive", @@ -991,7 +992,12 @@ dependencies = [ "pallet-collective", "pallet-contracts", "pallet-contracts-primitives", + "pallet-ddc-clusters", + "pallet-ddc-customers", "pallet-ddc-metrics-offchain-worker", + "pallet-ddc-nodes", + "pallet-ddc-payouts", + "pallet-ddc-staking", "pallet-democracy", "pallet-election-provider-multi-phase", "pallet-election-provider-support-benchmarking", diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index 4ef882790..daf3ca346 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -37,9 +37,6 @@ sp-transaction-pool = { default-features = false, git = "https://github.com/pari sp-version = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } # frame dependencies -cere-dev-runtime-constants = { path = "./constants", default-features = false } -cere-runtime-common = { path = "../common", default-features = false } -ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31", optional = true } frame-election-provider-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } frame-executive = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } @@ -54,24 +51,15 @@ pallet-babe = { default-features = false, git = "https://github.com/paritytech/s pallet-bags-list = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-bounties = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } -pallet-cere-ddc = { version = "4.8.2", default-features = false, path = "../../pallets/ddc" } pallet-chainbridge = { version = "4.8.2", default-features = false, path = "../../pallets/chainbridge" } pallet-child-bounties = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-collective = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-contracts = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-contracts-primitives = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } -pallet-ddc-clusters = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-clusters" } -pallet-ddc-customers = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-customers" } -pallet-ddc-metrics-offchain-worker = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } -pallet-ddc-nodes = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-nodes" } -pallet-ddc-payouts = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-payouts" } -pallet-ddc-staking = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-staking" } pallet-democracy = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-election-provider-multi-phase = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-election-provider-support-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31", optional = true } pallet-elections-phragmen = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } -pallet-erc20 = { version = "4.8.2", default-features = false, path = "../../pallets/erc20" } -pallet-erc721 = { version = "4.8.2", default-features = false, path = "../../pallets/erc721" } pallet-fast-unstake = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.31" } pallet-grandpa = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-identity = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } @@ -102,6 +90,20 @@ pallet-treasury = { default-features = false, git = "https://github.com/parityte pallet-utility = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-vesting = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } +# cere dependencies +cere-dev-runtime-constants = { path = "./constants", default-features = false } +cere-runtime-common = { path = "../common", default-features = false } +ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } +pallet-cere-ddc = { version = "4.8.2", default-features = false, path = "../../pallets/ddc" } +pallet-ddc-clusters = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-clusters" } +pallet-ddc-customers = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-customers" } +pallet-ddc-metrics-offchain-worker = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } +pallet-ddc-nodes = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-nodes" } +pallet-ddc-payouts = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-payouts" } +pallet-ddc-staking = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-staking" } +pallet-erc20 = { version = "4.8.2", default-features = false, path = "../../pallets/erc20" } +pallet-erc721 = { version = "4.8.2", default-features = false, path = "../../pallets/erc721" } + [build-dependencies] substrate-wasm-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } @@ -182,7 +184,6 @@ std = [ "cere-runtime-common/std", "cere-dev-runtime-constants/std", "pallet-ddc-customers/std", - "pallet-ddc-nodes/std", "pallet-ddc-clusters/std", ] runtime-benchmarks = [ diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 5b0d59c14..1cb03a695 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1335,7 +1335,7 @@ impl pallet_ddc_staking::Config for Runtime { parameter_types! { pub const DdcCustomersPalletId: PalletId = PalletId(*b"accounts"); // DDC maintainer's stake - pub const UnlockingDelay: BlockNumber = 5256000u32; // 1 hour * 24 * 365 = 1 day; (1 hour is 600 blocks) + pub const UnlockingDelay: BlockNumber = 100800_u32; // 1 hour * 24 * 7 = 7 days; (1 hour is 600 blocks) } impl pallet_ddc_customers::Config for Runtime { @@ -1367,8 +1367,8 @@ parameter_types! { pub const PayoutsPalletId: PalletId = PalletId(*b"payouts_"); } -pub struct TreasureWrapper; -impl PalletVisitor for TreasureWrapper { +pub struct TreasuryWrapper; +impl PalletVisitor for TreasuryWrapper { fn get_account_id() -> T::AccountId { TreasuryPalletId::get().into_account_truncating() } @@ -1381,7 +1381,7 @@ impl pallet_ddc_payouts::Config for Runtime { type CustomerCharger = DdcCustomers; type CustomerDepositor = DdcCustomers; type ClusterVisitor = DdcClusters; - type TreasuryVisitor = TreasureWrapper; + type TreasuryVisitor = TreasuryWrapper; type ValidatorList = pallet_staking::UseValidatorsMap; type ClusterCreator = DdcClusters; type WeightInfo = pallet_ddc_payouts::weights::SubstrateWeight; diff --git a/runtime/cere/Cargo.toml b/runtime/cere/Cargo.toml index c320c3dda..d2da2b23e 100644 --- a/runtime/cere/Cargo.toml +++ b/runtime/cere/Cargo.toml @@ -37,8 +37,6 @@ sp-transaction-pool = { default-features = false, git = "https://github.com/pari sp-version = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } # frame dependencies -cere-runtime-common = { path = "../common", default-features = false } -cere-runtime-constants = { path = "./constants", default-features = false } frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31", optional = true } frame-election-provider-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } frame-executive = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } @@ -53,19 +51,15 @@ pallet-babe = { default-features = false, git = "https://github.com/paritytech/s pallet-bags-list = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-bounties = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } -pallet-cere-ddc = { version = "4.8.2", default-features = false, path = "../../pallets/ddc" } pallet-chainbridge = { version = "4.8.2", default-features = false, path = "../../pallets/chainbridge" } pallet-child-bounties = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-collective = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-contracts = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-contracts-primitives = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } -pallet-ddc-metrics-offchain-worker = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } pallet-democracy = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-election-provider-multi-phase = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-election-provider-support-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31", optional = true } pallet-elections-phragmen = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } -pallet-erc20 = { version = "4.8.2", default-features = false, path = "../../pallets/erc20" } -pallet-erc721 = { version = "4.8.2", default-features = false, path = "../../pallets/erc721" } pallet-fast-unstake = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.31" } pallet-grandpa = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-identity = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } @@ -96,6 +90,20 @@ pallet-treasury = { default-features = false, git = "https://github.com/parityte pallet-utility = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } pallet-vesting = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } +# cere dependencies +cere-runtime-common = { path = "../common", default-features = false } +cere-runtime-constants = { path = "./constants", default-features = false } +ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } +pallet-cere-ddc = { version = "4.8.2", default-features = false, path = "../../pallets/ddc" } +pallet-ddc-clusters = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-clusters" } +pallet-ddc-customers = { version = "0.1.0", default-features = false, path = "../../pallets/ddc-customers" } +pallet-ddc-metrics-offchain-worker = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-metrics-offchain-worker" } +pallet-ddc-nodes = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-nodes" } +pallet-ddc-payouts = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-payouts" } +pallet-ddc-staking = { version = "4.8.2", default-features = false, path = "../../pallets/ddc-staking" } +pallet-erc20 = { version = "4.8.2", default-features = false, path = "../../pallets/erc20" } +pallet-erc721 = { version = "4.8.2", default-features = false, path = "../../pallets/erc721" } + [build-dependencies] substrate-wasm-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.31" } @@ -170,6 +178,11 @@ std = [ "sp-io/std", "pallet-child-bounties/std", "pallet-ddc-metrics-offchain-worker/std", + "pallet-ddc-clusters/std", + "pallet-ddc-customers/std", + "pallet-ddc-nodes/std", + "pallet-ddc-payouts/std", + "pallet-ddc-staking/std", "cere-runtime-common/std", "cere-runtime-constants/std", ] @@ -185,6 +198,11 @@ runtime-benchmarks = [ "pallet-child-bounties/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-contracts/runtime-benchmarks", + "pallet-ddc-customers/runtime-benchmarks", + "pallet-ddc-clusters/runtime-benchmarks", + "pallet-ddc-nodes/runtime-benchmarks", + "pallet-ddc-staking/runtime-benchmarks", + "pallet-ddc-payouts/runtime-benchmarks", "pallet-democracy/runtime-benchmarks", "pallet-election-provider-multi-phase/runtime-benchmarks", "pallet-election-provider-support-benchmarking/runtime-benchmarks", diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index 16b3fbb53..40fbf4fd3 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -23,6 +23,7 @@ #![recursion_limit = "256"] use codec::{Decode, Encode, MaxEncodedLen}; +use ddc_traits::pallet::PalletVisitor; use frame_election_provider_support::{onchain, BalancingConfig, SequentialPhragmen, VoteWeight}; use frame_support::{ construct_runtime, @@ -77,8 +78,8 @@ use sp_runtime::{ curve::PiecewiseLinear, generic, impl_opaque_keys, traits::{ - self, BlakeTwo256, Block as BlockT, Bounded, ConvertInto, NumberFor, OpaqueKeys, - SaturatedConversion, StaticLookup, + self, AccountIdConversion, BlakeTwo256, Block as BlockT, Bounded, ConvertInto, NumberFor, + OpaqueKeys, SaturatedConversion, StaticLookup, }, transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perbill, Percent, Permill, Perquintill, @@ -1317,6 +1318,71 @@ impl pallet_ddc_metrics_offchain_worker::Config for Runtime { type RuntimeCall = RuntimeCall; } +parameter_types! { + pub const DdcCustomersPalletId: PalletId = PalletId(*b"accounts"); // DDC maintainer's stake + pub const UnlockingDelay: BlockNumber = 100800_u32; // 1 hour * 24 * 7 = 7 days; (1 hour is 600 blocks) +} + +impl pallet_ddc_customers::Config for Runtime { + type UnlockingDelay = UnlockingDelay; + type Currency = Balances; + type PalletId = DdcCustomersPalletId; + type RuntimeEvent = RuntimeEvent; + type ClusterVisitor = pallet_ddc_clusters::Pallet; + type ClusterCreator = pallet_ddc_clusters::Pallet; + type WeightInfo = pallet_ddc_customers::weights::SubstrateWeight; +} + +impl pallet_ddc_clusters::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type NodeRepository = pallet_ddc_nodes::Pallet; + type StakingVisitor = pallet_ddc_staking::Pallet; + type StakerCreator = pallet_ddc_staking::Pallet; + type Currency = Balances; + type WeightInfo = pallet_ddc_clusters::weights::SubstrateWeight; +} + +impl pallet_ddc_nodes::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type StakingVisitor = pallet_ddc_staking::Pallet; + type WeightInfo = pallet_ddc_nodes::weights::SubstrateWeight; +} + +parameter_types! { + pub const PayoutsPalletId: PalletId = PalletId(*b"payouts_"); +} + +pub struct TreasuryWrapper; +impl PalletVisitor for TreasuryWrapper { + fn get_account_id() -> T::AccountId { + TreasuryPalletId::get().into_account_truncating() + } +} + +impl pallet_ddc_payouts::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type PalletId = PayoutsPalletId; + type Currency = Balances; + type CustomerCharger = DdcCustomers; + type CustomerDepositor = DdcCustomers; + type ClusterVisitor = DdcClusters; + type TreasuryVisitor = TreasuryWrapper; + type ValidatorList = pallet_staking::UseValidatorsMap; + type ClusterCreator = DdcClusters; + type WeightInfo = pallet_ddc_payouts::weights::SubstrateWeight; +} + +impl pallet_ddc_staking::Config for Runtime { + type Currency = Balances; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; + type ClusterVisitor = pallet_ddc_clusters::Pallet; + type ClusterCreator = pallet_ddc_clusters::Pallet; + type ClusterManager = pallet_ddc_clusters::Pallet; + type NodeVisitor = pallet_ddc_nodes::Pallet; + type NodeCreator = pallet_ddc_nodes::Pallet; +} + construct_runtime!( pub enum Runtime where Block = Block, @@ -1368,6 +1434,11 @@ construct_runtime!( Erc721: pallet_erc721::{Pallet, Call, Storage, Event}, Erc20: pallet_erc20::{Pallet, Call, Storage, Event}, DdcMetricsOffchainWorker: pallet_ddc_metrics_offchain_worker::{Pallet, Call, Storage, Event}, + DdcStaking: pallet_ddc_staking, + DdcCustomers: pallet_ddc_customers, + DdcNodes: pallet_ddc_nodes, + DdcClusters: pallet_ddc_clusters, + DdcPayouts: pallet_ddc_payouts } ); @@ -1441,6 +1512,11 @@ mod benches { [pallet_child_bounties, ChildBounties] [pallet_collective, Council] [pallet_contracts, Contracts] + [pallet_ddc_customers, DdcCustomers] + [pallet_ddc_clusters, DdcClusters] + [pallet_ddc_staking, DdcStaking] + [pallet_ddc_nodes, DdcNodes] + [pallet_ddc_payouts, DdcPayouts] [pallet_democracy, Democracy] [pallet_election_provider_multi_phase, ElectionProviderMultiPhase] [pallet_election_provider_support_benchmarking, EPSBench::]