Skip to content

Commit

Permalink
Paseo config
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Jun 17, 2024
1 parent b9595a8 commit 6a17cd7
Show file tree
Hide file tree
Showing 34 changed files with 1,060 additions and 814 deletions.
1 change: 1 addition & 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 chain-specs/paseo/polimec-paseo-genesis-state
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x000000000000000000000000000000000000000000000000000000000000000000e3d00f53cef01891a48d68de366914bb30c947b53f6a0c9a40a3242be05ac92003170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400
1 change: 1 addition & 0 deletions chain-specs/paseo/polimec-paseo-genesis-wasm

Large diffs are not rendered by default.

250 changes: 250 additions & 0 deletions chain-specs/paseo/polimec-paseo-live-spec.plain.json

Large diffs are not rendered by default.

134 changes: 134 additions & 0 deletions chain-specs/paseo/polimec-paseo-live-spec.raw.json

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions nodes/parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ cumulus-client-consensus-proposer.workspace = true
cumulus-client-service.workspace = true
cumulus-primitives-core.workspace = true
cumulus-relay-chain-interface.workspace = true
itertools = "0.10.5"

[build-dependencies]
substrate-build-script-utils.workspace = true
Expand Down
5 changes: 3 additions & 2 deletions nodes/parachain/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ use serde::{Deserialize, Serialize};
use sp_core::{Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};

pub mod polimec;
pub mod politest;
pub mod common;
pub mod polimec_paseo;
pub mod polimec_rococo;

const DEFAULT_PARA_ID: ParaId = LOWEST_PUBLIC_ID;

Expand Down
193 changes: 193 additions & 0 deletions nodes/parachain/src/chain_spec/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
use crate::chain_spec::{get_account_id_from_seed, get_properties, Extensions, GenericChainSpec, DEFAULT_PARA_ID};
use cumulus_primitives_core::ParaId;
use frame_support::traits::fungible::Inspect;
use itertools::Itertools;
use polimec_runtime::{
pallet_parachain_staking,
pallet_parachain_staking::{
inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR},
InflationInfo, Range,
},
AccountId, AuraId as AuthorityId, Balance, MinCandidateStk, OracleProvidersMembershipConfig, Runtime,
RuntimeGenesisConfig, PLMC,
};
use sc_service::ChainType;
use sp_core::{crypto::UncheckedInto, sr25519};
use sp_runtime::{bounded_vec, traits::AccountIdConversion, Perbill, Percent};
pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig, Extensions>;

/// The default XCM version to set in genesis config.
pub const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;
pub const COLLATOR_COMMISSION: Perbill = Perbill::from_percent(10);
pub const PARACHAIN_BOND_RESERVE_PERCENT: Percent = Percent::from_percent(0);
pub const BLOCKS_PER_ROUND: u32 = 2 * 10;
pub const NUM_SELECTED_CANDIDATES: u32 = 5;

// This account is derived from PalletId("plmc/stk") in the pallet-parachain-staking runtime config.
// This operation can be done using https://www.shawntabrizi.com/substrate-js-utilities/
// 1. "Module ID" to Address plmc/stk -> 5EYCAe5ij8xKJ2biBy4zUGNwdNhpz3BaS5iiuseJqTEtWQTc
// 2. AccountId to Hex -> 0x6d6f646c706c6d632f73746b0000000000000000000000000000000000000000
pub const BLOCKCHAIN_OPERATION_TREASURY: [u8; 32] =
hex_literal::hex!["6d6f646c706c6d632f73746b0000000000000000000000000000000000000000"];

pub fn polimec_inflation_config() -> InflationInfo<Balance> {
fn to_round_inflation(annual: Range<Perbill>) -> Range<Perbill> {
perbill_annual_to_perbill_round(
annual,
// rounds per year
BLOCKS_PER_YEAR / BLOCKS_PER_ROUND,
)
}

let annual =
Range { min: Perbill::from_percent(2), ideal: Perbill::from_percent(3), max: Perbill::from_percent(3) };

InflationInfo {
// staking expectations
expect: Range { min: 100_000 * PLMC, ideal: 200_000 * PLMC, max: 500_000 * PLMC },
// annual inflation
annual,
round: to_round_inflation(annual),
}
}

pub fn get_polimec_session_keys(keys: AuthorityId) -> polimec_runtime::SessionKeys {
polimec_runtime::SessionKeys { aura: keys }
}

pub fn alice() -> polimec_runtime::AccountId {
get_account_id_from_seed::<sr25519::Public>("Alice")
}
pub fn bob() -> polimec_runtime::AccountId {
get_account_id_from_seed::<sr25519::Public>("Bob")
}
pub fn charlie() -> polimec_runtime::AccountId {
get_account_id_from_seed::<sr25519::Public>("Charlie")
}
pub fn dave() -> polimec_runtime::AccountId {
get_account_id_from_seed::<sr25519::Public>("Dave")
}
pub fn eve() -> polimec_runtime::AccountId {
get_account_id_from_seed::<sr25519::Public>("Eve")
}
pub fn ferdie() -> polimec_runtime::AccountId {
get_account_id_from_seed::<sr25519::Public>("Ferdie")
}

pub struct GenesisConfigParams {
pub stakers: Vec<AccountId>,
pub council_members: Vec<AccountId>,
pub technical_committee_members: Vec<AccountId>,
pub oracle_members: Vec<AccountId>,
// Do not include system accounts or the funding asset owner.
pub endowed_accounts: Vec<(AccountId, Balance)>,
pub funding_assets_owner: AccountId,
pub id: ParaId,
}
pub fn genesis_config(genesis_config_params: GenesisConfigParams) -> serde_json::Value {
let GenesisConfigParams {
stakers,
council_members,
technical_committee_members,
oracle_members,
mut endowed_accounts,
funding_assets_owner,
id,
} = genesis_config_params;

let mut system_accounts = vec![
(
<Runtime as pallet_funding::Config>::ProtocolGrowthTreasury::get(),
<Runtime as pallet_funding::Config>::NativeCurrency::minimum_balance(),
),
(
<Runtime as pallet_funding::Config>::ContributionTreasury::get(),
<Runtime as pallet_funding::Config>::NativeCurrency::minimum_balance(),
),
// Need this to have enough for staking rewards
(<Runtime as pallet_parachain_staking::Config>::PayMaster::get(), 10_000_000 * PLMC),
];
endowed_accounts.append(&mut system_accounts.clone());

#[cfg(not(feature = "runtime-benchmarks"))]
let staking_candidates = stakers.clone().into_iter().map(|account| (account, MinCandidateStk::get())).collect_vec();
#[cfg(feature = "runtime-benchmarks")]
let staking_candidates: Vec<(AccountId, Balance)> = vec![];

let accounts = endowed_accounts.iter().map(|(account, _)| account.clone()).collect::<Vec<_>>();
let usdt_id = pallet_funding::types::AcceptedFundingAsset::USDT.to_assethub_id();
let usdc_id = pallet_funding::types::AcceptedFundingAsset::USDC.to_assethub_id();
let dot_id = pallet_funding::types::AcceptedFundingAsset::DOT.to_assethub_id();

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![
(usdt_id, b"Local USDT", b"USDT", 6),
(usdc_id, b"Local USDC", b"USDC", 6),
(dot_id, b"Local DOT ", b"DOT ", 10)
],
// (id, account_id, amount)
"accounts": vec![
(usdt_id, funding_assets_owner.clone(), 1000000000000u64),
(usdc_id, funding_assets_owner.clone(), 1000000000000u64),
(dot_id, funding_assets_owner.clone(), 1000000000000u64)
],
},
"parachainStaking": {
"candidates": staking_candidates,
"inflationConfig": polimec_inflation_config(),
"delegations": [],
"collatorCommission": COLLATOR_COMMISSION,
"parachainBondReservePercent": PARACHAIN_BOND_RESERVE_PERCENT,
"blocksPerRound": BLOCKS_PER_ROUND,
"numSelectedCandidates": NUM_SELECTED_CANDIDATES
},
"session": {
"keys": stakers.iter().map(|account| {
(
account.clone(),
account.clone(),
get_polimec_session_keys(Into::<[u8; 32]>::into(account.clone()).unchecked_into())
)
}).collect::<Vec<_>>()
},
"polkadotXcm": {
"safeXcmVersion": SAFE_XCM_VERSION
},
"oracleProvidersMembership": OracleProvidersMembershipConfig {
members: oracle_members.try_into().unwrap(),
phantom: Default::default(),
},
"council": {
"members": council_members
},
"technicalCommittee": {
"members": technical_committee_members
},
})
}
Loading

0 comments on commit 6a17cd7

Please sign in to comment.