Skip to content

Commit

Permalink
Add parachain staking (#1494)
Browse files Browse the repository at this point in the history
* feat: 🎸 add buy-back

* Bifrost v0.10.001

* feat: 🎸 benchmark

* SLPx mint support commission id (#1261)

* Add vtoken exchange rate rpc (#1260)

* fix: 🐛 add event (#1263)

* add update_currency_metadata function (#1259)

* add update_currency_metadata function

* fix: 🐛 correct update_currency_metadata weight

* add the use of Vec (#1264)

* Add vtoken exchange rate rpc

* add the use of Vec

* Upgrade to Polkadot-SDK v1.7.0 (#1262)

* Bifrost v0.10.0

* fix: 🐛 clippy

* Fix chain spec (#1243)

* Upgrade to polkadot-v1.7.0

---------

Co-authored-by: SunTiebing <[email protected]>
Co-authored-by: Edwin Wang <[email protected]>

* feat: 🎸 add metadata-hash-extension (#1265)

* Fix compile (#1266)

* Fix/fix vtoken voting unlock (#1267)

* update the exchange rate of vtokenminting of vtokenvoting test

* Resolve the frozen anomaly when unlocking

* feat: 🎸 add parachain-staking

* feat: 🎸 add bifrost-polkadot-testnet

* refactor: 💡 rm pallet-collator-selection

* fix: 🐛 rm collatorSelection

* fix: 🐛 add parachainStaking into chain_spec

* fix: 🐛 balances

* [skip ci]: remove latest tag

* feat: 🎸 add membership

* [skip ci]:add chain-spec

* [skip ci]Update Dockerfile for testnet

* [skip ci] update chain spec

* [skip ci] update chain spec

* fix clippy

* fix code fmt

* Fix merge issues: update Dockerfile to use the main network configuration.

* add bifrost_parachain_staking InitGenesisMigration

* Update parameter configurations and implement data migration.

* remove unused files

* add latest tag

---------

Co-authored-by: yooml <[email protected]>
Co-authored-by: NingBo Wang <[email protected]>
Co-authored-by: Edwin Wang <[email protected]>
Co-authored-by: 战神西红柿 <[email protected]>
Co-authored-by: TomatoAres <[email protected]>
  • Loading branch information
6 people authored Nov 11, 2024
1 parent 18328f8 commit 393ddc9
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 41 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
8 changes: 5 additions & 3 deletions runtime/bifrost-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
]
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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.
Expand Down
127 changes: 93 additions & 34 deletions runtime/bifrost-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -344,6 +346,7 @@ pub enum ProxyType {
Governance = 2,
CancelProxy = 3,
IdentityJudgement = 4,
Staking = 5,
}

impl Default for ProxyType {
Expand Down Expand Up @@ -378,8 +381,12 @@ impl InstanceFilter<RuntimeCall> 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(..) |
Expand Down Expand Up @@ -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<AccountId> = 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<MoreThanHalfCouncil, EnsureRootOrAllTechnicalCommittee>;
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<Runtime>;
}

parameter_types! {
pub const Period: u32 = 6 * HOURS;
pub const Offset: u32 = 0;
Expand All @@ -842,20 +918,20 @@ parameter_types! {
impl pallet_session::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Keys = opaque::SessionKeys;
type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
type NextSessionRotation = ParachainStaking;
// Essentially just Aura, but lets be pedantic.
type SessionHandler =
<opaque::SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
type SessionManager = CollatorSelection;
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
type SessionManager = ParachainStaking;
type ShouldEndSession = ParachainStaking;
type ValidatorId = <Self as frame_system::Config>::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<Runtime>;
}

impl pallet_authorship::Config for Runtime {
type EventHandler = CollatorSelection;
type EventHandler = ParachainStaking;
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
}

Expand All @@ -867,28 +943,6 @@ impl pallet_aura::Config for Runtime {
type SlotDuration = ConstU64<SLOT_DURATION>;
}

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<AccountId>;
type ValidatorId = <Self as frame_system::Config>::AccountId;
type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
type ValidatorRegistration = Session;
type WeightInfo = ();
type MinEligibleCollators = ConstU32<5>;
}

// culumus runtime end

parameter_types! {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -1845,7 +1899,12 @@ pub mod migrations {
use super::*;

/// Unreleased migrations. Add new ones here:
pub type Unreleased = pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>;
pub type Unreleased = (
// permanent migration, do not remove
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
bifrost_parachain_staking::migrations::InitGenesisMigration<Runtime>,
frame_support::migrations::RemovePallet<CollatorSelectionName, RocksDbWeight>,
);
}

/// Executive: handles dispatch to the various modules.
Expand Down
1 change: 0 additions & 1 deletion runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 393ddc9

Please sign in to comment.