Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions Cargo.lock

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

30 changes: 15 additions & 15 deletions pallets/salp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use sp_std::convert::TryFrom;
pub trait WeightInfo {
fn contribute() -> Weight;
fn unlock() -> Weight;
fn batch_unlock(k: u32) -> Weight;
fn refund() -> Weight;
fn redeem() -> Weight;
}
Expand Down Expand Up @@ -197,6 +198,8 @@ pub mod pallet {

type EnsureConfirmAsMultiSig: EnsureOrigin<<Self as frame_system::Config>::Origin>;

type EnsureConfirmAsGovernance: EnsureOrigin<<Self as frame_system::Config>::Origin>;

type BifrostXcmExecutor: BifrostXcmExecutor;

#[pallet::constant]
Expand Down Expand Up @@ -351,7 +354,7 @@ pub mod pallet {
origin: OriginFor<T>,
#[pallet::compact] index: ParaId,
) -> DispatchResult {
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;
T::EnsureConfirmAsGovernance::ensure_origin(origin)?;

let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
ensure!(fund.status == FundStatus::Ongoing, Error::<T>::InvalidFundStatus);
Expand All @@ -368,7 +371,7 @@ pub mod pallet {
Pays::No
))]
pub fn fund_fail(origin: OriginFor<T>, #[pallet::compact] index: ParaId) -> DispatchResult {
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;
T::EnsureConfirmAsGovernance::ensure_origin(origin)?;

// crownload is failed, so enable the withdrawal function of vsToken/vsBond
let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
Expand All @@ -389,7 +392,7 @@ pub mod pallet {
origin: OriginFor<T>,
#[pallet::compact] index: ParaId,
) -> DispatchResult {
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;
T::EnsureConfirmAsGovernance::ensure_origin(origin)?;

let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
ensure!(fund.status == FundStatus::Success, Error::<T>::InvalidFundStatus);
Expand All @@ -406,7 +409,7 @@ pub mod pallet {
Pays::No
))]
pub fn fund_end(origin: OriginFor<T>, #[pallet::compact] index: ParaId) -> DispatchResult {
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;
T::EnsureConfirmAsGovernance::ensure_origin(origin)?;

let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
ensure!(
Expand Down Expand Up @@ -462,17 +465,13 @@ pub mod pallet {
}

/// Unlock the reserved vsToken/vsBond after fund success
#[pallet::weight((
0,
DispatchClass::Normal,
Pays::No
))]
#[pallet::weight(T::WeightInfo::batch_unlock(T::RemoveKeysLimit::get()))]
#[transactional]
pub fn batch_unlock(
origin: OriginFor<T>,
#[pallet::compact] index: ParaId,
) -> DispatchResult {
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;
ensure_signed(origin)?;

let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
ensure!(
Expand Down Expand Up @@ -532,7 +531,7 @@ pub mod pallet {
#[pallet::compact] first_slot: LeasePeriod,
#[pallet::compact] last_slot: LeasePeriod,
) -> DispatchResult {
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;
T::EnsureConfirmAsGovernance::ensure_origin(origin)?;

ensure!(!Funds::<T>::contains_key(index), Error::<T>::FundAlreadyCreated);

Expand Down Expand Up @@ -701,7 +700,7 @@ pub mod pallet {
))]
#[transactional]
pub fn withdraw(origin: OriginFor<T>, #[pallet::compact] index: ParaId) -> DispatchResult {
T::EnsureConfirmAsMultiSig::ensure_origin(origin.clone())?;
T::EnsureConfirmAsGovernance::ensure_origin(origin.clone())?;

let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
let can = fund.status == FundStatus::Failed || fund.status == FundStatus::Retired;
Expand Down Expand Up @@ -839,7 +838,7 @@ pub mod pallet {
))]
#[transactional]
pub fn dissolve(origin: OriginFor<T>, #[pallet::compact] index: ParaId) -> DispatchResult {
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;
T::EnsureConfirmAsGovernance::ensure_origin(origin)?;

let mut fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
ensure!(fund.status == FundStatus::End, Error::<T>::InvalidFundStatus);
Expand Down Expand Up @@ -876,7 +875,7 @@ pub mod pallet {
))]
#[transactional]
pub fn add_proxy(origin: OriginFor<T>, delegate: AccountIdOf<T>) -> DispatchResult {
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;
T::EnsureConfirmAsGovernance::ensure_origin(origin)?;

Self::xcm_ump_add_proxy(delegate.clone()).map_err(|_| Error::<T>::XcmFailed)?;

Expand All @@ -894,7 +893,7 @@ pub mod pallet {
))]
#[transactional]
pub fn remove_proxy(origin: OriginFor<T>, delegate: AccountIdOf<T>) -> DispatchResult {
T::EnsureConfirmAsMultiSig::ensure_origin(origin)?;
T::EnsureConfirmAsGovernance::ensure_origin(origin)?;

Self::xcm_ump_remove_proxy(delegate.clone()).map_err(|_| Error::<T>::XcmFailed)?;

Expand Down Expand Up @@ -1069,6 +1068,7 @@ pub mod pallet {
who.using_encoded(|b| child::kill(&Self::id_from_index(index), b));
}

#[allow(dead_code)]
pub(crate) fn set_balance(who: &AccountIdOf<T>, value: BalanceOf<T>) -> DispatchResult {
T::MultiCurrency::deposit(T::RelayChainToken::get(), who, value)
}
Expand Down
5 changes: 5 additions & 0 deletions pallets/salp/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ impl salp::Config for Test {
type BaseXcmWeight = BaseXcmWeight;
type ContributionWeight = ContributionWeight;
type EnsureConfirmAsMultiSig = EnsureConfirmAsMultiSig;
type EnsureConfirmAsGovernance = EnsureConfirmAsMultiSig;
type AddProxyWeight = AddProxyWeight;
type XcmTransfer = MockXTokens;
type SovereignSubAccountLocation = RelaychainSovereignSubAccount;
Expand All @@ -328,6 +329,10 @@ impl WeightInfo for SalpWeightInfo {
fn refund() -> Weight {
0
}

fn batch_unlock(_k: u32) -> Weight {
0
}
}

// To control the result returned by `MockXcmExecutor`
Expand Down
21 changes: 6 additions & 15 deletions runtime/asgard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ pub mod constants;
use bifrost_flexible_fee::fee_dealer::{FeeDealer, FixedCurrencyFeeRate};
use bifrost_runtime_common::{
constants::parachains,
create_x2_multilocation,
xcm_impl::{
BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert,
BifrostFilteredAssets, BifrostXcmTransactFilter, MultiWeightTraders,
},
SlowAdjustingFeeUpdate,
EnsureRootOrAllTechnicalCommittee, SlowAdjustingFeeUpdate,
};
use codec::{Decode, Encode, MaxEncodedLen};
use constants::{currency::*, time::*};
Expand All @@ -100,9 +101,7 @@ use pallet_xcm::XcmPassthrough;
use polkadot_parachain::primitives::Sibling;
use sp_runtime::traits::ConvertInto;
use static_assertions::const_assert;
use xcm::v0::{
BodyId, Junction, Junction::*, MultiAsset, MultiLocation, MultiLocation::*, NetworkId,
};
use xcm::v0::{BodyId, Junction::*, MultiAsset, MultiLocation, MultiLocation::*, NetworkId};
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin,
FixedRateOfConcreteFungible, FixedWeightBounds, IsConcrete, LocationInverter,
Expand Down Expand Up @@ -990,16 +989,6 @@ impl bifrost_minter_reward::Config for Runtime {
type WeightInfo = weights::bifrost_minter_reward::WeightInfo<Runtime>;
}

pub fn create_x2_parachain_multilocation(index: u16) -> MultiLocation {
MultiLocation::X2(
Junction::Parent,
Junction::AccountId32 {
network: NetworkId::Any,
id: Utility::derivative_account_id(ParachainInfo::get().into_account(), index).into(),
},
)
}

pub struct EnsureConfirmAsMultiSig;
impl EnsureOrigin<Origin> for EnsureConfirmAsMultiSig {
type Success = AccountId;
Expand Down Expand Up @@ -1040,7 +1029,7 @@ parameter_types! {
hex!["8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48"].into(), // bob
hex!["90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22"].into(), // charlie
],2);
pub RelaychainSovereignSubAccount: MultiLocation = create_x2_parachain_multilocation(ParachainDerivedProxyAccountType::Salp as u16);
pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(Utility::derivative_account_id(ParachainInfo::get().into_account(), ParachainDerivedProxyAccountType::Salp as u16));
pub SalpTransactType: ParachainTransactType = ParachainTransactType::Xcm;
pub SalpProxyType: ParachainTransactProxyType = ParachainTransactProxyType::Derived;
}
Expand All @@ -1066,6 +1055,8 @@ impl bifrost_salp::Config for Runtime {
type BaseXcmWeight = XcmWeight;
type EnsureConfirmAsMultiSig =
EnsureOneOf<AccountId, MoreThanHalfCouncil, EnsureConfirmAsMultiSig>;
type EnsureConfirmAsGovernance =
EnsureOneOf<AccountId, MoreThanHalfCouncil, EnsureRootOrAllTechnicalCommittee>;
type AddProxyWeight = AddProxyWeight;
type XcmTransfer = XTokens;
type SovereignSubAccountLocation = RelaychainSovereignSubAccount;
Expand Down
9 changes: 9 additions & 0 deletions runtime/asgard/src/weights/bifrost_salp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,13 @@ impl<T: frame_system::Config> bifrost_salp::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(9 as Weight))
.saturating_add(T::DbWeight::get().writes(8 as Weight))
}

fn batch_unlock(k: u32) -> Weight {
(0 as Weight)
.saturating_add((45_890_000 as Weight).saturating_mul(k as Weight))
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(k as Weight)))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
.saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(k as Weight)))
}
}
26 changes: 6 additions & 20 deletions runtime/bifrost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ pub mod constants;
use bifrost_flexible_fee::fee_dealer::{FeeDealer, FixedCurrencyFeeRate};
use bifrost_runtime_common::{
constants::parachains,
create_x2_multilocation,
xcm_impl::{
BifrostAccountIdToMultiLocation, BifrostAssetMatcher, BifrostCurrencyIdConvert,
BifrostFilteredAssets, BifrostXcmTransactFilter, MultiWeightTraders,
},
SlowAdjustingFeeUpdate,
CouncilCollective, EnsureRootOrAllTechnicalCommittee, MoreThanHalfCouncil,
SlowAdjustingFeeUpdate, TechnicalCollective,
};
use codec::Encode;
use constants::{currency::*, time::*};
Expand Down Expand Up @@ -335,7 +337,6 @@ parameter_types! {
pub const CouncilMaxMembers: u32 = 100;
}

type CouncilCollective = pallet_collective::Instance1;
impl pallet_collective::Config<CouncilCollective> for Runtime {
type DefaultVote = pallet_collective::PrimeDefaultVote;
type Event = Event;
Expand All @@ -353,7 +354,6 @@ parameter_types! {
pub const TechnicalMaxMembers: u32 = 100;
}

type TechnicalCollective = pallet_collective::Instance2;
impl pallet_collective::Config<TechnicalCollective> for Runtime {
type DefaultVote = pallet_collective::PrimeDefaultVote;
type Event = Event;
Expand All @@ -365,12 +365,6 @@ impl pallet_collective::Config<TechnicalCollective> for Runtime {
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
}

type MoreThanHalfCouncil = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>,
>;

impl pallet_membership::Config<pallet_membership::Instance1> for Runtime {
type AddOrigin = MoreThanHalfCouncil;
type Event = Event;
Expand Down Expand Up @@ -932,16 +926,6 @@ impl bifrost_flexible_fee::Config for Runtime {
type WeightInfo = weights::bifrost_flexible_fee::WeightInfo<Runtime>;
}

pub fn create_x2_parachain_multilocation(index: u16) -> MultiLocation {
MultiLocation::X2(
Junction::Parent,
Junction::AccountId32 {
network: NetworkId::Any,
id: Utility::derivative_account_id(ParachainInfo::get().into_account(), index).into(),
},
)
}

pub struct EnsureConfirmAsMultiSig;
impl EnsureOrigin<Origin> for EnsureConfirmAsMultiSig {
type Success = AccountId;
Expand Down Expand Up @@ -977,7 +961,7 @@ parameter_types! {
pub ContributionWeight:XcmBaseWeight = 893125000.into();
pub AddProxyWeight:XcmBaseWeight = XCM_WEIGHT.into();
pub ConfirmMuitiSigAccount: AccountId = hex!["d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"].into();
pub RelaychainSovereignSubAccount: MultiLocation = create_x2_parachain_multilocation(ParachainDerivedProxyAccountType::Salp as u16);
pub RelaychainSovereignSubAccount: MultiLocation = create_x2_multilocation(Utility::derivative_account_id(ParachainInfo::get().into_account(), ParachainDerivedProxyAccountType::Salp as u16));
pub SalpTransactType: ParachainTransactType = ParachainTransactType::Xcm;
pub SalpProxyType: ParachainTransactProxyType = ParachainTransactProxyType::Derived;
}
Expand All @@ -1003,6 +987,8 @@ impl bifrost_salp::Config for Runtime {
type BaseXcmWeight = XcmWeight;
type EnsureConfirmAsMultiSig =
EnsureOneOf<AccountId, MoreThanHalfCouncil, EnsureConfirmAsMultiSig>;
type EnsureConfirmAsGovernance =
EnsureOneOf<AccountId, MoreThanHalfCouncil, EnsureRootOrAllTechnicalCommittee>;
type AddProxyWeight = AddProxyWeight;
type XcmTransfer = XTokens;
type SovereignSubAccountLocation = RelaychainSovereignSubAccount;
Expand Down
9 changes: 9 additions & 0 deletions runtime/bifrost/src/weights/bifrost_salp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,13 @@ impl<T: frame_system::Config> bifrost_salp::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(13 as Weight))
.saturating_add(T::DbWeight::get().writes(11 as Weight))
}

fn batch_unlock(k: u32) -> Weight {
(0 as Weight)
.saturating_add((45_890_000 as Weight).saturating_mul(k as Weight))
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(k as Weight)))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
.saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(k as Weight)))
}
}
16 changes: 15 additions & 1 deletion runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "pol
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
pallet-collective = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
pallet-membership = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
pallet-democracy = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
pallet-multisig = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }

# Cumulus dependencies
cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.9", default-features = false }
Expand Down Expand Up @@ -82,6 +89,14 @@ std = [
"sp-transaction-pool/std",
"sp-arithmetic/std",
"parachain-info/std",
"pallet-collective/std",
"pallet-democracy/std",
"pallet-multisig/std",
"pallet-membership/std",
"pallet-utility/std",
"pallet-treasury/std",
"pallet-scheduler/std",
"pallet-transaction-payment/std",
"cumulus-pallet-dmp-queue/std",
"cumulus-pallet-parachain-system/std",
"cumulus-pallet-xcmp-queue/std",
Expand All @@ -99,5 +114,4 @@ std = [
"xcm-support/std",
"zenlink-protocol/std",
"zenlink-protocol-runtime-api/std",
"pallet-transaction-payment/std"
]
Loading