Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce collectives_polkadot_runtime_constants and removed hard-coded numbers usage for indexes #182

Merged
Show file tree
Hide file tree
Changes from 9 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.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ members = [
"system-parachains/bridge-hubs/bridge-hub-polkadot",
"system-parachains/bridge-hubs/bridge-hub-polkadot/primitives",
"system-parachains/collectives/collectives-polkadot",
"system-parachains/collectives/collectives-polkadot/constants",
"system-parachains/constants",
"system-parachains/encointer",
"system-parachains/gluttons/glutton-kusama",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ cumulus-pallet-parachain-system = { features = ["parameterized-consensus-hook"],

# Local
asset-hub-polkadot-runtime = { path = "../../../../../system-parachains/asset-hubs/asset-hub-polkadot" }
collectives-polkadot-runtime-constants = { path = "../../../../../system-parachains/collectives/collectives-polkadot/constants"}
bkchr marked this conversation as resolved.
Show resolved Hide resolved
integration-tests-helpers = { path = "../../../helpers" }
polkadot-runtime = { path = "../../../../../relay/polkadot" }
polkadot-system-emulated-network = { path = "../../../networks/polkadot-system" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ fn create_and_claim_treasury_spend() {
// treasury location from a sibling parachain.
let treasury_location: MultiLocation = MultiLocation::new(
1,
X2(Parachain(CollectivesPolkadot::para_id().into()), PalletInstance(65)),
X2(
Parachain(CollectivesPolkadot::para_id().into()),
PalletInstance(
collectives_polkadot_runtime_constants::FELLOWSHIP_TREASURY_PALLET_INDEX,
),
),
);
// treasury account on a sibling parachain.
let treasury_account =
Expand Down
2 changes: 2 additions & 0 deletions system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bp-asset-hub-kusama = { path = "../asset-hub-kusama/primitives", default-feature
bp-asset-hub-polkadot = { path = "./primitives", default-features = false}
bp-bridge-hub-kusama = { path = "../../bridge-hubs/bridge-hub-kusama/primitives", default-features = false}
bp-bridge-hub-polkadot = { path = "../../bridge-hubs/bridge-hub-polkadot/primitives", default-features = false}
collectives-polkadot-runtime-constants = { path = "../../collectives/collectives-polkadot/constants", default-features = false}
bkchr marked this conversation as resolved.
Show resolved Hide resolved
kusama-runtime-constants = { path = "../../../relay/kusama/constants", default-features = false}
polkadot-runtime-constants = { path = "../../../relay/polkadot/constants", default-features = false}

Expand Down Expand Up @@ -170,6 +171,7 @@ std = [
"bp-bridge-hub-kusama/std",
"bp-bridge-hub-polkadot/std",
"codec/std",
"collectives-polkadot-runtime-constants/std",
bkchr marked this conversation as resolved.
Show resolved Hide resolved
"cumulus-pallet-aura-ext/std",
"cumulus-pallet-dmp-queue/std",
"cumulus-pallet-parachain-system/std",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ parameter_types! {
pub TrustBackedAssetsPalletLocation: MultiLocation =
PalletInstance(<Assets as PalletInfoAccess>::index() as u8).into();
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
pub FellowshipLocation: MultiLocation = MultiLocation::new(1, Parachain(1001));
pub FellowshipLocation: MultiLocation = MultiLocation::new(1, Parachain(polkadot_runtime_constants::system_parachain::COLLECTIVES_ID));
pub const GovernanceLocation: MultiLocation = MultiLocation::parent();
pub RelayTreasuryLocation: MultiLocation = (Parent, PalletInstance(polkadot_runtime_constants::TREASURY_PALLET_ID)).into();
pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
Expand Down Expand Up @@ -190,11 +190,11 @@ match_types! {
};
pub type FellowshipEntities: impl Contains<MultiLocation> = {
// Fellowship Plurality
MultiLocation { parents: 1, interior: X2(Parachain(1001), Plurality { id: BodyId::Technical, ..}) } |
MultiLocation { parents: 1, interior: X2(Parachain(polkadot_runtime_constants::system_parachain::COLLECTIVES_ID), Plurality { id: BodyId::Technical, ..}) } |
// Fellowship Salary Pallet
MultiLocation { parents: 1, interior: X2(Parachain(1001), PalletInstance(64)) } |
MultiLocation { parents: 1, interior: X2(Parachain(polkadot_runtime_constants::system_parachain::COLLECTIVES_ID), PalletInstance(collectives_polkadot_runtime_constants::FELLOWSHIP_SALARY_PALLET_INDEX)) } |
// Fellowship Treasury Pallet
MultiLocation { parents: 1, interior: X2(Parachain(1001), PalletInstance(65)) }
MultiLocation { parents: 1, interior: X2(Parachain(polkadot_runtime_constants::system_parachain::COLLECTIVES_ID), PalletInstance(collectives_polkadot_runtime_constants::FELLOWSHIP_TREASURY_PALLET_INDEX)) }
};
}

Expand Down Expand Up @@ -718,7 +718,8 @@ fn foreign_pallet_has_correct_local_account() {
use xcm_executor::traits::ConvertLocation;

const COLLECTIVES_PARAID: u32 = 1001;
const FELLOWSHIP_SALARY_PALLET_ID: u8 = 64;
const FELLOWSHIP_SALARY_PALLET_ID: u8 =
collectives_polkadot_runtime_constants::FELLOWSHIP_SALARY_PALLET_INDEX;
let fellowship_salary =
(Parent, Parachain(COLLECTIVES_PARAID), PalletInstance(FELLOWSHIP_SALARY_PALLET_ID));
let account = LocationToAccountId::convert_location(&fellowship_salary.into()).unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ parameter_types! {
X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into()));
pub const MaxInstructions: u32 = 100;
pub const MaxAssetsIntoHolding: u32 = 64;
pub FellowshipLocation: MultiLocation = MultiLocation::new(1, Parachain(1001));
pub FellowshipLocation: MultiLocation = MultiLocation::new(1, Parachain(polkadot_runtime_constants::system_parachain::COLLECTIVES_ID));
pub const GovernanceLocation: MultiLocation = MultiLocation::parent();
pub RelayTreasuryLocation: MultiLocation = (Parent, PalletInstance(polkadot_runtime_constants::TREASURY_PALLET_ID)).into();
pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
Expand Down Expand Up @@ -123,7 +123,7 @@ match_types! {
MultiLocation { parents: 1, interior: X1(Plurality { .. }) }
};
pub type FellowsPlurality: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: X2(Parachain(1001), Plurality { id: BodyId::Technical, ..}) }
MultiLocation { parents: 1, interior: X2(Parachain(polkadot_runtime_constants::system_parachain::COLLECTIVES_ID), Plurality { id: BodyId::Technical, ..}) }
};
}
/// A call filter for the XCM Transact instruction. This is a temporary measure until we properly
Expand Down
3 changes: 3 additions & 0 deletions system-parachains/collectives/collectives-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ parachain-info = { package = "staging-parachain-info", default-features = false
parachains-common = { default-features = false , version = "7.0.0" }
system-parachains-constants = { path = "../../constants", default-features = false }

[dev-dependencies]
collectives-polkadot-runtime-constants = { path = "constants" }

[build-dependencies]
substrate-wasm-builder = { optional = true , version = "17.0.0" }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "collectives-polkadot-runtime-constants"
repository.workspace = true
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true

[features]
default = ["std"]
std = []
bkchr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

#![cfg_attr(not(feature = "std"), no_std)]
bkontur marked this conversation as resolved.
Show resolved Hide resolved
bkchr marked this conversation as resolved.
Show resolved Hide resolved

/// Polkadot Collectives Salary pallet instance.
pub const FELLOWSHIP_SALARY_PALLET_INDEX: u8 = 64;

/// Polkadot Collectives Treasury pallet instance.
pub const FELLOWSHIP_TREASURY_PALLET_INDEX: u8 = 65;
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
use polkadot_runtime_common::impls::{
LocatableAssetConverter, VersionedLocatableAsset, VersionedMultiLocationConverter,
};
use polkadot_runtime_constants::{currency::GRAND, time::HOURS, xcm::body::FELLOWSHIP_ADMIN_INDEX};
use polkadot_runtime_constants::{
currency::GRAND, system_parachain, time::HOURS, xcm::body::FELLOWSHIP_ADMIN_INDEX,
};
use sp_arithmetic::Permill;
use sp_core::{ConstU128, ConstU32};
use sp_runtime::traits::{ConstU16, ConvertToValue, IdentityLookup, Replace, TakeFirst};
Expand Down Expand Up @@ -206,15 +208,16 @@ pub type FellowshipSalaryInstance = pallet_salary::Instance1;
use xcm::prelude::*;

parameter_types! {
pub AssetHub: MultiLocation = (Parent, Parachain(1000)).into();
pub AssetHub: MultiLocation = (Parent, Parachain(system_parachain::ASSET_HUB_ID)).into();
pub AssetHubUsdtId: AssetId = (PalletInstance(50), GeneralIndex(1984)).into();
pub UsdtAsset: LocatableAssetId = LocatableAssetId {
location: AssetHub::get(),
asset_id: AssetHubUsdtId::get(),
};
// The interior location on AssetHub for the paying account. This is the Fellowship Salary
// pallet instance (which sits at index 64). This sovereign account will need funding.
pub Interior: InteriorMultiLocation = PalletInstance(64).into();
// pallet instance. This sovereign account will need funding.
pub Interior: InteriorMultiLocation =
PalletInstance(<crate::FellowshipSalary as PalletInfoAccess>::index() as u8).into();
}

const USDT_UNITS: u128 = 1_000_000;
Expand Down Expand Up @@ -261,7 +264,7 @@ parameter_types! {
pub const Burn: Permill = Permill::from_percent(0);
pub const MaxBalance: Balance = Balance::max_value();
// The asset's interior location for the paying account. This is the Fellowship Treasury
// pallet instance (which sits at index 65).
// pallet instance.
pub FellowshipTreasuryInteriorLocation: InteriorMultiLocation =
PalletInstance(<crate::FellowshipTreasury as PalletInfoAccess>::index() as u8).into();
}
Expand Down
14 changes: 8 additions & 6 deletions system-parachains/collectives/collectives-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,22 +1037,24 @@ cumulus_pallet_parachain_system::register_validate_block! {
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
}

// TODO: Move these pallet index declarations to some `system-parachains/common` so that other
// runtimes can import them without depending on the entire remote runtime.
// Part of https://github.com/polkadot-fellows/runtimes/issues/59

#[test]
fn fellowship_salary_pallet_index() {
use frame_support::pallet_prelude::PalletInfoAccess;
// Remote accounts with funds depend on this pallet staying in the same index.
assert_eq!(<FellowshipSalary as PalletInfoAccess>::index() as u8, 64u8);
assert_eq!(
<FellowshipSalary as PalletInfoAccess>::index() as u8,
collectives_polkadot_runtime_constants::FELLOWSHIP_SALARY_PALLET_INDEX
);
}

#[test]
fn fellowship_treasury_pallet_index() {
use frame_support::pallet_prelude::PalletInfoAccess;
// Remote accounts with funds depend on this pallet staying in the same index.
assert_eq!(<FellowshipTreasury as PalletInfoAccess>::index() as u8, 65u8);
assert_eq!(
<FellowshipTreasury as PalletInfoAccess>::index() as u8,
collectives_polkadot_runtime_constants::FELLOWSHIP_TREASURY_PALLET_INDEX
);
}

#[test]
Expand Down
Loading