diff --git a/Cargo.lock b/Cargo.lock index 96a3b6284e..1a525cb65e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1493,6 +1493,7 @@ dependencies = [ "bifrost-fee-share", "bifrost-flexible-fee", "bifrost-flexible-fee-rpc-runtime-api", + "bifrost-parachain-staking", "bifrost-primitives", "bifrost-runtime-common", "bifrost-salp", @@ -1554,7 +1555,6 @@ dependencies = [ "pallet-balances", "pallet-base-fee", "pallet-bounties", - "pallet-collator-selection", "pallet-collective", "pallet-conviction-voting", "pallet-democracy", @@ -1735,7 +1735,6 @@ dependencies = [ "orml-tokens", "orml-traits", "orml-xcm-support", - "pallet-collator-selection", "pallet-collective", "pallet-democracy", "pallet-membership", diff --git a/Cargo.toml b/Cargo.toml index e4e0b6a385..ac54297589 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -180,7 +180,6 @@ pallet-authority-discovery = { git = "https://github.com/parityt pallet-authorship = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.13.0", default-features = false } pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.13.0", default-features = false } pallet-bounties = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.13.0", default-features = false } -pallet-collator-selection = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.13.0", default-features = false } pallet-collective = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.13.0", default-features = false } pallet-conviction-voting = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.13.0", default-features = false } pallet-democracy = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.13.0", default-features = false } diff --git a/runtime/bifrost-polkadot/Cargo.toml b/runtime/bifrost-polkadot/Cargo.toml index d50840cb1d..80747c824a 100644 --- a/runtime/bifrost-polkadot/Cargo.toml +++ b/runtime/bifrost-polkadot/Cargo.toml @@ -81,7 +81,6 @@ cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } cumulus-primitives-timestamp = { workspace = true } cumulus-primitives-utility = { workspace = true } -pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } parachains-common = { workspace = true } @@ -165,6 +164,7 @@ bifrost-vstoken-conversion = { workspace = true } bifrost-vtoken-minting = { workspace = true } bifrost-vtoken-voting = { workspace = true, features = [ "polkadot" ] } bifrost-xcm-interface = { workspace = true } +bifrost-parachain-staking = { workspace = true } lend-market = { workspace = true } lend-market-rpc-runtime-api = { workspace = true } pallet-prices = { workspace = true } @@ -193,7 +193,6 @@ std = [ "pallet-aura/std", "pallet-balances/std", "pallet-bounties/std", - "pallet-collator-selection/std", "pallet-collective/std", "pallet-conviction-voting/std", "pallet-democracy/std", @@ -309,7 +308,9 @@ std = [ "pallet-evm-accounts/std", "pallet-evm-accounts-rpc-runtime-api/std", "bifrost-clouds-convert/std", + "bifrost-vtoken-minting-rpc-runtime-api/std", + "bifrost-parachain-staking/std", "substrate-wasm-builder" ] @@ -353,6 +354,7 @@ runtime-benchmarks = [ "bifrost-channel-commission/runtime-benchmarks", "bifrost-clouds-convert/runtime-benchmarks", "bifrost-buy-back/runtime-benchmarks", + "bifrost-parachain-staking/runtime-benchmarks", ] try-runtime = [ @@ -400,7 +402,6 @@ try-runtime = [ "pallet-authorship/try-runtime", "pallet-balances/try-runtime", "pallet-bounties/try-runtime", - "pallet-collator-selection/try-runtime", "pallet-collective/try-runtime", "pallet-conviction-voting/try-runtime", "pallet-democracy/try-runtime", @@ -431,6 +432,7 @@ try-runtime = [ "pallet-evm/try-runtime", "pallet-evm-chain-id/try-runtime", "pallet-dynamic-fee/try-runtime", + "bifrost-parachain-staking/try-runtime", ] # Enable the metadata hash generation in the wasm builder. diff --git a/runtime/bifrost-polkadot/src/lib.rs b/runtime/bifrost-polkadot/src/lib.rs index e54e65d976..149ad6d0d8 100644 --- a/runtime/bifrost-polkadot/src/lib.rs +++ b/runtime/bifrost-polkadot/src/lib.rs @@ -30,13 +30,15 @@ use bifrost_slp::{DerivativeAccountProvider, QueryResponseManager}; use core::convert::TryInto; use pallet_traits::evm::InspectEvmAccounts; // A few exports that help ease life for downstream crates. +pub use bifrost_parachain_staking::{InflationInfo, Range}; use bifrost_primitives::{ BifrostCrowdloanId, BifrostVsbondAccount, BuyBackAccount, BuybackPalletId, CloudsPalletId, CommissionPalletId, FarmingBoostPalletId, FarmingGaugeRewardIssuerPalletId, FarmingKeeperPalletId, FarmingRewardIssuerPalletId, FeeSharePalletId, FlexibleFeePalletId, IncentivePalletId, IncentivePoolAccount, LendMarketPalletId, LiquidityAccount, - LocalBncLocation, MerkleDirtributorPalletId, OraclePalletId, SlpEntrancePalletId, - SlpExitPalletId, SystemMakerPalletId, SystemStakingPalletId, TreasuryPalletId, + LocalBncLocation, MerkleDirtributorPalletId, OraclePalletId, ParachainStakingPalletId, + SlpEntrancePalletId, SlpExitPalletId, SystemMakerPalletId, SystemStakingPalletId, + TreasuryPalletId, }; use cumulus_pallet_parachain_system::{RelayNumberMonotonicallyIncreases, RelaychainDataProvider}; pub use frame_support::{ @@ -344,6 +346,7 @@ pub enum ProxyType { Governance = 2, CancelProxy = 3, IdentityJudgement = 4, + Staking = 5, } impl Default for ProxyType { @@ -378,8 +381,12 @@ impl InstanceFilter for ProxyType { // Specifically omitting Vesting `vested_transfer`, and `force_vested_transfer` RuntimeCall::Utility(..) | RuntimeCall::Proxy(..) | - RuntimeCall::Multisig(..) + RuntimeCall::Multisig(..) | + RuntimeCall::ParachainStaking(..) ), + ProxyType::Staking => { + matches!(c, RuntimeCall::ParachainStaking(..) | RuntimeCall::Utility(..)) + }, ProxyType::Governance => matches!( c, RuntimeCall::Democracy(..) | @@ -834,6 +841,75 @@ impl parachain_info::Config for Runtime {} impl cumulus_pallet_aura_ext::Config for Runtime {} +parameter_types! { + /// Minimum round length is 2 minutes (10 * 12 second block times) + pub const MinBlocksPerRound: u32 = 10; + /// Rounds before the collator leaving the candidates request can be executed + pub const LeaveCandidatesDelay: u32 = 84; + /// Rounds before the candidate bond increase/decrease can be executed + pub const CandidateBondLessDelay: u32 = 84; + /// Rounds before the delegator exit can be executed + pub const LeaveDelegatorsDelay: u32 = 84; + /// Rounds before the delegator revocation can be executed + pub const RevokeDelegationDelay: u32 = 84; + /// Rounds before the delegator bond increase/decrease can be executed + pub const DelegationBondLessDelay: u32 = 84; + /// Rounds before the reward is paid + pub const RewardPaymentDelay: u32 = 2; + /// Minimum collators selected per round, default at genesis and minimum forever after + pub const MinSelectedCandidates: u32 = prod_or_fast!(16,6); + /// Maximum top delegations per candidate + pub const MaxTopDelegationsPerCandidate: u32 = 300; + /// Maximum bottom delegations per candidate + pub const MaxBottomDelegationsPerCandidate: u32 = 50; + /// Maximum delegations per delegator + pub const MaxDelegationsPerDelegator: u32 = 100; + /// Minimum stake required to become a collator + pub MinCollatorStk: u128 = 5000 * BNCS; + /// Minimum stake required to be reserved to be a candidate + pub MinCandidateStk: u128 = 5000 * BNCS; + /// Minimum stake required to be reserved to be a delegator + pub MinDelegatorStk: u128 = 50 * BNCS; + pub AllowInflation: bool = false; + pub ToMigrateInvulnables: Vec = prod_or_fast!(vec![ + hex!["5c7e9ccd1045cac7f8c5c77a79c87f44019d1dda4f5032713bda89c5d73cb36b"].into(), + hex!["606b0aad375ae1715fbe6a07315136a8e9c1c84a91230f6a0c296c2953581335"].into(), + hex!["b6ba81e73bd39203e006fc99cc1e41976745de2ea2007bf62ed7c9a48ccc5b1d"].into(), + hex!["ce42cea2dd0d4ac87ccdd5f0f2e1010955467f5a37587cf6af8ee2b4ba781034"].into(), + ],vec![]); + pub PaymentInRound: u128 = 180 * BNCS; + pub InitSeedStk: u128 = 5000 * BNCS; +} +impl bifrost_parachain_staking::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type MonetaryGovernanceOrigin = + EitherOfDiverse; + type MinBlocksPerRound = MinBlocksPerRound; + type LeaveCandidatesDelay = LeaveCandidatesDelay; + type CandidateBondLessDelay = CandidateBondLessDelay; + type LeaveDelegatorsDelay = LeaveDelegatorsDelay; + type RevokeDelegationDelay = RevokeDelegationDelay; + type DelegationBondLessDelay = DelegationBondLessDelay; + type RewardPaymentDelay = RewardPaymentDelay; + type MinSelectedCandidates = MinSelectedCandidates; + type MaxTopDelegationsPerCandidate = MaxTopDelegationsPerCandidate; + type MaxBottomDelegationsPerCandidate = MaxBottomDelegationsPerCandidate; + type MaxDelegationsPerDelegator = MaxDelegationsPerDelegator; + type MinCollatorStk = MinCollatorStk; + type MinCandidateStk = MinCandidateStk; + type MinDelegation = MinDelegatorStk; + type MinDelegatorStk = MinDelegatorStk; + type AllowInflation = AllowInflation; + type PaymentInRound = PaymentInRound; + type ToMigrateInvulnables = ToMigrateInvulnables; + type PalletId = ParachainStakingPalletId; + type InitSeedStk = InitSeedStk; + type OnCollatorPayout = (); + type OnNewRound = (); + type WeightInfo = bifrost_parachain_staking::weights::SubstrateWeight; +} + parameter_types! { pub const Period: u32 = 6 * HOURS; pub const Offset: u32 = 0; @@ -842,20 +918,20 @@ parameter_types! { impl pallet_session::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Keys = opaque::SessionKeys; - type NextSessionRotation = pallet_session::PeriodicSessions; + type NextSessionRotation = ParachainStaking; // Essentially just Aura, but lets be pedantic. type SessionHandler = ::KeyTypeIdProviders; - type SessionManager = CollatorSelection; - type ShouldEndSession = pallet_session::PeriodicSessions; + type SessionManager = ParachainStaking; + type ShouldEndSession = ParachainStaking; type ValidatorId = ::AccountId; // we don't have stash and controller, thus we don't need the convert as well. - type ValidatorIdOf = pallet_collator_selection::IdentityCollator; + type ValidatorIdOf = ConvertInto; type WeightInfo = pallet_session::weights::SubstrateWeight; } impl pallet_authorship::Config for Runtime { - type EventHandler = CollatorSelection; + type EventHandler = ParachainStaking; type FindAuthor = pallet_session::FindAccountFromAuthorIndex; } @@ -867,28 +943,6 @@ impl pallet_aura::Config for Runtime { type SlotDuration = ConstU64; } -parameter_types! { - pub const PotId: PalletId = PalletId(*b"PotStake"); - pub const SessionLength: BlockNumber = 6 * HOURS; - pub const MaxInvulnerables: u32 = 100; -} - -impl pallet_collator_selection::Config for Runtime { - type Currency = Balances; - type RuntimeEvent = RuntimeEvent; - // should be a multiple of session or things will get inconsistent - type KickThreshold = Period; - type MaxCandidates = MaxCandidates; - type MaxInvulnerables = MaxInvulnerables; - type PotId = PotId; - type UpdateOrigin = EnsureRoot; - type ValidatorId = ::AccountId; - type ValidatorIdOf = pallet_collator_selection::IdentityCollator; - type ValidatorRegistration = Session; - type WeightInfo = (); - type MinEligibleCollators = ConstU32<5>; -} - // culumus runtime end parameter_types! { @@ -1117,7 +1171,7 @@ impl bifrost_slp::Config for Runtime { type SubstrateResponseManager = SubstrateResponseManager; type MaxTypeEntryPerBlock = MaxTypeEntryPerBlock; type MaxRefundPerBlock = MaxRefundPerBlock; - type ParachainStaking = (); + type ParachainStaking = ParachainStaking; type XcmTransfer = XTokens; type MaxLengthLimit = MaxLengthLimit; type XcmWeightAndFeeHandler = XcmInterface; @@ -1676,10 +1730,10 @@ construct_runtime! { // Collator support. the order of these 4 are important and shall not change. Authorship: pallet_authorship = 20, - CollatorSelection: pallet_collator_selection = 21, Session: pallet_session = 22, Aura: pallet_aura = 23, AuraExt: cumulus_pallet_aura_ext = 24, + ParachainStaking: bifrost_parachain_staking = 25, // Governance stuff Democracy: pallet_democracy = 30, @@ -1836,7 +1890,7 @@ impl cumulus_pallet_xcmp_queue::migration::v5::V5Config for Runtime { pub type Migrations = migrations::Unreleased; parameter_types! { - pub const SystemMakerName: &'static str = "SystemMaker"; + pub const CollatorSelectionName: &'static str = "CollatorSelection"; } /// The runtime migrations per release. @@ -1845,7 +1899,12 @@ pub mod migrations { use super::*; /// Unreleased migrations. Add new ones here: - pub type Unreleased = pallet_xcm::migration::MigrateToLatestXcmVersion; + pub type Unreleased = ( + // permanent migration, do not remove + pallet_xcm::migration::MigrateToLatestXcmVersion, + bifrost_parachain_staking::migrations::InitGenesisMigration, + frame_support::migrations::RemovePallet, + ); } /// Executive: handles dispatch to the various modules. diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 7937f5f935..c4907fdf9d 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -51,7 +51,6 @@ cumulus-primitives-utility = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } cumulus-pallet-xcm = { workspace = true } parachain-info = { workspace = true } -pallet-collator-selection = { workspace = true } # Polkadot dependencies polkadot-parachain-primitives = { workspace = true }