Skip to content

Commit

Permalink
DDC pallets for the cere runtime (#189)
Browse files Browse the repository at this point in the history
Co-authored-by: yahortsaryk <[email protected]>
  • Loading branch information
Raid5594 and yahortsaryk authored Dec 19, 2023
1 parent ca57262 commit 5febf20
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 25 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

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

27 changes: 14 additions & 13 deletions runtime/cere-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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" }
Expand Down Expand Up @@ -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" }

Expand Down Expand Up @@ -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 = [
Expand Down
8 changes: 4 additions & 4 deletions runtime/cere-dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1367,8 +1367,8 @@ parameter_types! {
pub const PayoutsPalletId: PalletId = PalletId(*b"payouts_");
}

pub struct TreasureWrapper;
impl<T: frame_system::Config> PalletVisitor<T> for TreasureWrapper {
pub struct TreasuryWrapper;
impl<T: frame_system::Config> PalletVisitor<T> for TreasuryWrapper {
fn get_account_id() -> T::AccountId {
TreasuryPalletId::get().into_account_truncating()
}
Expand All @@ -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<Self>;
type ClusterCreator = DdcClusters;
type WeightInfo = pallet_ddc_payouts::weights::SubstrateWeight<Runtime>;
Expand Down
30 changes: 24 additions & 6 deletions runtime/cere/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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" }
Expand Down Expand Up @@ -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" }

Expand Down Expand Up @@ -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",
]
Expand All @@ -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",
Expand Down
80 changes: 78 additions & 2 deletions runtime/cere/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<Runtime>;
type ClusterCreator = pallet_ddc_clusters::Pallet<Runtime>;
type WeightInfo = pallet_ddc_customers::weights::SubstrateWeight<Runtime>;
}

impl pallet_ddc_clusters::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type NodeRepository = pallet_ddc_nodes::Pallet<Runtime>;
type StakingVisitor = pallet_ddc_staking::Pallet<Runtime>;
type StakerCreator = pallet_ddc_staking::Pallet<Runtime>;
type Currency = Balances;
type WeightInfo = pallet_ddc_clusters::weights::SubstrateWeight<Runtime>;
}

impl pallet_ddc_nodes::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type StakingVisitor = pallet_ddc_staking::Pallet<Runtime>;
type WeightInfo = pallet_ddc_nodes::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const PayoutsPalletId: PalletId = PalletId(*b"payouts_");
}

pub struct TreasuryWrapper;
impl<T: frame_system::Config> PalletVisitor<T> 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<Self>;
type ClusterCreator = DdcClusters;
type WeightInfo = pallet_ddc_payouts::weights::SubstrateWeight<Runtime>;
}

impl pallet_ddc_staking::Config for Runtime {
type Currency = Balances;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight<Runtime>;
type ClusterVisitor = pallet_ddc_clusters::Pallet<Runtime>;
type ClusterCreator = pallet_ddc_clusters::Pallet<Runtime>;
type ClusterManager = pallet_ddc_clusters::Pallet<Runtime>;
type NodeVisitor = pallet_ddc_nodes::Pallet<Runtime>;
type NodeCreator = pallet_ddc_nodes::Pallet<Runtime>;
}

construct_runtime!(
pub enum Runtime where
Block = Block,
Expand Down Expand Up @@ -1368,6 +1434,11 @@ construct_runtime!(
Erc721: pallet_erc721::{Pallet, Call, Storage, Event<T>},
Erc20: pallet_erc20::{Pallet, Call, Storage, Event<T>},
DdcMetricsOffchainWorker: pallet_ddc_metrics_offchain_worker::{Pallet, Call, Storage, Event<T>},
DdcStaking: pallet_ddc_staking,
DdcCustomers: pallet_ddc_customers,
DdcNodes: pallet_ddc_nodes,
DdcClusters: pallet_ddc_clusters,
DdcPayouts: pallet_ddc_payouts
}
);

Expand Down Expand Up @@ -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::<Runtime>]
Expand Down

0 comments on commit 5febf20

Please sign in to comment.