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

Polimec runtime upgrade 0.7.0 #274

Merged
merged 6 commits into from
Apr 30, 2024
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
5 changes: 5 additions & 0 deletions Cargo.lock

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

45 changes: 41 additions & 4 deletions nodes/parachain/src/chain_spec/polimec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
use cumulus_primitives_core::ParaId;
use sc_service::ChainType;
use sp_core::{crypto::UncheckedInto, sr25519};
use sp_runtime::{traits::ConstU32, BoundedVec, Perbill, Percent};
use sp_runtime::{traits::AccountIdConversion, Perbill, Percent};

use crate::chain_spec::{get_account_id_from_seed, get_properties, Extensions, GenericChainSpec, DEFAULT_PARA_ID};
use polimec_runtime::{
pallet_parachain_staking::{
inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR},
InflationInfo, Range,
},
AccountId, AuraId as AuthorityId, Balance, MinCandidateStk, RuntimeGenesisConfig, PLMC,
AccountId, AuraId as AuthorityId, Balance, MinCandidateStk, OracleProvidersMembershipConfig, Runtime,
RuntimeGenesisConfig, PLMC,
};

pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig, Extensions>;
Expand Down Expand Up @@ -88,6 +89,7 @@ pub fn get_local_chain_spec() -> GenericChainSpec {
vec![
(get_account_id_from_seed::<sr25519::Public>("Alice"), None, MinCandidateStk::get()),
(get_account_id_from_seed::<sr25519::Public>("Bob"), None, MinCandidateStk::get()),
(get_account_id_from_seed::<sr25519::Public>("Charlie"), None, MinCandidateStk::get()),
],
polimec_inflation_config(),
vec![get_account_id_from_seed::<sr25519::Public>("Alice"), get_account_id_from_seed::<sr25519::Public>("Bob")],
Expand Down Expand Up @@ -192,13 +194,47 @@ fn base_testnet_genesis(
#[cfg(feature = "runtime-benchmarks")]
let staking_candidates: Vec<(AccountId, Balance)> = vec![];

let accounts = endowed_accounts.iter().map(|(account, _)| account.clone()).collect::<Vec<_>>();

serde_json::json!({
"balances": {
"balances": endowed_accounts.clone()
},
"parachainInfo": {
"parachainId": id
},
"foreignAssets": {
"assets": vec![(
pallet_funding::types::AcceptedFundingAsset::USDT.to_assethub_id(),
&AccountIdConversion::<AccountId>::into_account_truncating(&<Runtime as pallet_funding::Config>::PalletId::get()),
true,
70000,
),
(
pallet_funding::types::AcceptedFundingAsset::USDC.to_assethub_id(),
&AccountIdConversion::<AccountId>::into_account_truncating(&<Runtime as pallet_funding::Config>::PalletId::get()),
true,
70000,
),
(
pallet_funding::types::AcceptedFundingAsset::DOT.to_assethub_id(),
&AccountIdConversion::<AccountId>::into_account_truncating(&<Runtime as pallet_funding::Config>::PalletId::get()),
true,
70000,
)],
// (id, name, symbol, decimals)
"metadata": vec![
(pallet_funding::types::AcceptedFundingAsset::USDT.to_assethub_id(), b"Local USDT", b"USDT", 6),
(pallet_funding::types::AcceptedFundingAsset::USDC.to_assethub_id(), b"Local USDC", b"USDC", 6),
(pallet_funding::types::AcceptedFundingAsset::DOT.to_assethub_id(), b"Local DOT ", b"DOT ", 10)
],
// (id, account_id, amount)
"accounts": vec![
(pallet_funding::types::AcceptedFundingAsset::USDT.to_assethub_id(), accounts[0].clone(), 1000000000000u64),
(pallet_funding::types::AcceptedFundingAsset::USDC.to_assethub_id(), accounts[0].clone(), 1000000000000u64),
(pallet_funding::types::AcceptedFundingAsset::DOT.to_assethub_id(), accounts[0].clone(), 1000000000000u64)
],
},
"parachainStaking": {
"candidates": staking_candidates,
"inflationConfig": inflation_config,
Expand All @@ -220,8 +256,9 @@ fn base_testnet_genesis(
"polkadotXcm": {
"safeXcmVersion": SAFE_XCM_VERSION
},
"oracleProvidersMembership": {
"members": BoundedVec::<AccountId,ConstU32<50>>::truncate_from(initial_authorities),
"oracleProvidersMembership": OracleProvidersMembershipConfig {
members: accounts.clone().into_iter().take(3).collect::<Vec<AccountId>>().try_into().unwrap(),
phantom: Default::default(),
},
"elections": {
"members": endowed_accounts.iter().map(|(member, _)| member).take((endowed_accounts.len() + 1) / 2).cloned().map(|member| (member, STASH)).collect::<Vec<_>>()
Expand Down
2 changes: 1 addition & 1 deletion nodes/parachain/src/chain_spec/politest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ fn testnet_genesis(
"metadata": vec![
(pallet_funding::types::AcceptedFundingAsset::USDT.to_assethub_id(), b"Local USDT", b"USDT", 6),
(pallet_funding::types::AcceptedFundingAsset::USDC.to_assethub_id(), b"Local USDC", b"USDC", 6),
(pallet_funding::types::AcceptedFundingAsset::DOT.to_assethub_id(), b"Local DOT ", b"DOT ", 6)
(pallet_funding::types::AcceptedFundingAsset::DOT.to_assethub_id(), b"Local DOT ", b"DOT ", 10)
],
// (id, account_id, amount)
"accounts": vec![
Expand Down
1 change: 1 addition & 0 deletions polimec-common/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use frame_support::{sp_runtime::app_crypto::sp_core::bytes::to_hex, traits::ConstU32, BoundedVec, Parameter};
use jwt_compact::{alg::Ed25519, AlgorithmExt, Header};
use parity_scale_codec::alloc::string::ToString;
use polimec_common::credentials::{Did, InvestorType, SampleClaims, UntrustedToken};

/// Fetches a JWT from a dummy Polimec JWT producer that will return a JWT with the specified investor type
Expand Down
23 changes: 21 additions & 2 deletions runtimes/polimec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ scale-info = { workspace= true, default-features = false, features = [
sp-debug-derive = { workspace = true, features = ["force-debug"]}


# Local
pallet-parachain-staking.workspace = true
# Polimec specific
pallet-dispenser.workspace = true
pallet-funding.workspace = true
pallet-oracle-ocw.workspace = true
pallet-linear-release.workspace = true
shared-configuration.workspace = true
polimec-common.workspace = true
pallet-parachain-staking.workspace = true

# Substrate
frame-benchmarking = { workspace = true, optional = true }
Expand All @@ -47,6 +51,7 @@ pallet-collective.workspace = true
pallet-democracy.workspace = true
pallet-elections-phragmen.workspace = true
pallet-identity.workspace = true
pallet-insecure-randomness-collective-flip.workspace = true
pallet-membership.workspace = true
pallet-message-queue.workspace = true
pallet-multisig.workspace = true
Expand Down Expand Up @@ -128,8 +133,12 @@ std = [
"pallet-balances/std",
"pallet-collective/std",
"pallet-democracy/std",
"pallet-dispenser/std",
"pallet-elections-phragmen/std",
"pallet-funding/std",
"pallet-identity/std",
"pallet-insecure-randomness-collective-flip/std",
"pallet-linear-release/std",
"pallet-membership/std",
"pallet-message-queue/std",
"pallet-multisig/std",
Expand All @@ -149,6 +158,7 @@ std = [
"parachain-info/std",
"parachains-common/std",
"parity-scale-codec/std",
"polimec-common/std",
"polimec-xcm-executor/std",
"polkadot-parachain-primitives/std",
"polkadot-runtime-common/std",
Expand Down Expand Up @@ -186,8 +196,11 @@ runtime-benchmarks = [
"pallet-balances/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
"pallet-dispenser/runtime-benchmarks",
"pallet-elections-phragmen/runtime-benchmarks",
"pallet-funding/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-linear-release/runtime-benchmarks",
"pallet-membership/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
Expand All @@ -202,6 +215,7 @@ runtime-benchmarks = [
"pallet-vesting/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"polimec-common/runtime-benchmarks",
"polimec-xcm-executor/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
"polkadot-runtime-common/runtime-benchmarks",
Expand All @@ -227,8 +241,12 @@ try-runtime = [
"pallet-balances/try-runtime",
"pallet-collective/try-runtime",
"pallet-democracy/try-runtime",
"pallet-dispenser/try-runtime",
"pallet-elections-phragmen/try-runtime",
"pallet-funding/try-runtime",
"pallet-identity/try-runtime",
"pallet-insecure-randomness-collective-flip/try-runtime",
"pallet-linear-release/try-runtime",
"pallet-membership/try-runtime",
"pallet-message-queue/try-runtime",
"pallet-multisig/try-runtime",
Expand All @@ -245,6 +263,7 @@ try-runtime = [
"pallet-vesting/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
"polimec-common/try-runtime",
"polimec-xcm-executor/try-runtime",
"polkadot-runtime-common/try-runtime",
"shared-configuration/try-runtime",
Expand Down
35 changes: 35 additions & 0 deletions runtimes/polimec/src/benchmarks/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::{Oracle, Runtime, RuntimeOrigin};
pub use frame_support::BoundedVec;
pub use pallet_funding::{traits::SetPrices, AcceptedFundingAsset};
use scale_info::prelude::vec;
pub use sp_runtime::FixedU128;
pub struct SetOraclePrices;
impl SetPrices for SetOraclePrices {
fn set_prices() {
let dot = (AcceptedFundingAsset::DOT.to_assethub_id(), FixedU128::from_rational(69, 1));
let usdc = (AcceptedFundingAsset::USDT.to_assethub_id(), FixedU128::from_rational(1, 1));
let usdt = (AcceptedFundingAsset::USDT.to_assethub_id(), FixedU128::from_rational(1, 1));
let plmc = (pallet_funding::PLMC_FOREIGN_ID, FixedU128::from_rational(840, 100));

let values: BoundedVec<(u32, FixedU128), <Runtime as orml_oracle::Config>::MaxFeedValues> =
vec![dot, usdc, usdt, plmc].try_into().expect("benchmarks can panic");
let alice: [u8; 32] = [
212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205,
227, 154, 86, 132, 231, 165, 109, 162, 125,
];
let bob: [u8; 32] = [
142, 175, 4, 21, 22, 135, 115, 99, 38, 201, 254, 161, 126, 37, 252, 82, 135, 97, 54, 147, 201, 18, 144,
156, 178, 38, 170, 71, 148, 242, 106, 72,
];
let charlie: [u8; 32] = [
144, 181, 171, 32, 92, 105, 116, 201, 234, 132, 27, 230, 136, 134, 70, 51, 220, 156, 168, 163, 87, 132, 62,
234, 207, 35, 20, 100, 153, 101, 254, 34,
];

frame_support::assert_ok!(Oracle::feed_values(RuntimeOrigin::signed(alice.clone().into()), values.clone()));

frame_support::assert_ok!(Oracle::feed_values(RuntimeOrigin::signed(bob.clone().into()), values.clone()));

frame_support::assert_ok!(Oracle::feed_values(RuntimeOrigin::signed(charlie.clone().into()), values.clone()));
}
}
2 changes: 2 additions & 0 deletions runtimes/polimec/src/benchmarks/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[cfg(any(feature = "runtime-benchmarks", feature = "std"))]
pub mod helpers;
Loading