Skip to content
Open
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
2 changes: 1 addition & 1 deletion Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ pallet-nfts = { workspace = true }
pallet-nfts-runtime-api = { workspace = true }
pallet-nomination-pools = { workspace = true }
pallet-nomination-pools-runtime-api = { workspace = true }
pallet-parameters = { workspace = true }
pallet-pgas-allowance = { workspace = true }
pallet-preimage = { workspace = true }
pallet-proxy = { workspace = true }
Expand Down Expand Up @@ -210,7 +209,6 @@ runtime-benchmarks = [
"pallet-nft-fractionalization/runtime-benchmarks",
"pallet-nfts/runtime-benchmarks",
"pallet-nomination-pools/runtime-benchmarks",
"pallet-parameters/runtime-benchmarks",
"pallet-pgas-allowance/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
Expand Down Expand Up @@ -296,7 +294,6 @@ try-runtime = [
"pallet-nft-fractionalization/try-runtime",
"pallet-nfts/try-runtime",
"pallet-nomination-pools/try-runtime",
"pallet-parameters/try-runtime",
"pallet-pgas-allowance/try-runtime",
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
Expand Down Expand Up @@ -390,7 +387,6 @@ std = [
"pallet-nfts/std",
"pallet-nomination-pools-runtime-api/std",
"pallet-nomination-pools/std",
"pallet-parameters/std",
"pallet-pgas-allowance/std",
"pallet-preimage/std",
"pallet-proxy/std",
Expand Down
171 changes: 33 additions & 138 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ use cumulus_primitives_core::{
use frame_support::{
construct_runtime, derive_impl,
dispatch::DispatchClass,
dynamic_params::{dynamic_pallet_params, dynamic_params},
genesis_builder_helper::{build_state, get_preset},
ord_parameter_types, parameter_types,
traits::{
Expand Down Expand Up @@ -1422,17 +1421,19 @@ parameter_types! {
pub MbmServiceWeight: Weight = Perbill::from_percent(80) * RuntimeBlockWeights::get().max_block;
pub FastUnstakeName: &'static str = "FastUnstake";
pub PsmName: &'static str = "Psm";
pub ParametersName: &'static str = "Parameters";
}

/// One-shot migration: writes `pallet_psm`'s on-chain storage version to v2.
/// One-shot migration: writes `pallet_psm`'s on-chain storage version to v1.
/// Required because `RemovePallet<PsmName>` (above in the migration tuple)
/// wipes the pallet's `:__STORAGE_VERSION__:` key, and `InitializePsm` doesn't
/// re-seed it. Without this, try-runtime's post-upgrade check sees in-code = 2,
/// on-chain = 0 and panics.
pub struct SetPsmStorageVersionV2;
impl frame_support::traits::OnRuntimeUpgrade for SetPsmStorageVersionV2 {
/// wipes the pallet's `:__STORAGE_VERSION__:` key, and nothing else re-seeds it
/// (PSMs are now created on demand via the permissionless `create_psm` extrinsic).
/// Without this, try-runtime's post-upgrade check sees in-code = 1, on-chain = 0
/// and panics.
pub struct SetPsmStorageVersionV1;
impl frame_support::traits::OnRuntimeUpgrade for SetPsmStorageVersionV1 {
fn on_runtime_upgrade() -> Weight {
frame_support::traits::StorageVersion::new(2).put::<pallet_psm::Pallet<Runtime>>();
frame_support::traits::StorageVersion::new(1).put::<pallet_psm::Pallet<Runtime>>();
<Runtime as frame_system::Config>::DbWeight::get().writes(1)
}

Expand All @@ -1441,8 +1442,8 @@ impl frame_support::traits::OnRuntimeUpgrade for SetPsmStorageVersionV2 {
use frame_support::{ensure, traits::GetStorageVersion};
ensure!(
pallet_psm::Pallet::<Runtime>::on_chain_storage_version() ==
frame_support::traits::StorageVersion::new(2),
"PSM on-chain storage version was not set to 2"
frame_support::traits::StorageVersion::new(1),
"PSM on-chain storage version was not set to 1"
);
Ok(())
}
Expand Down Expand Up @@ -1573,98 +1574,14 @@ impl pallet_verify_signature::Config for Runtime {
type BenchmarkHelper = ();
}

// Dynamic parameters configurable via governance.
/// One pUSD (6 decimals).
const PUSD: Balance = 1_000_000;

#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::<Runtime>)]
pub mod dynamic_params {
use super::*;

#[dynamic_pallet_params]
#[codec(index = 0)]
pub mod pusd {
/// Maximum pUSD issuance across the system (50 million pUSD) with precision 1e6.
#[codec(index = 0)]
pub static MaximumIssuance: Balance = 50_000_000 * PUSD;
}
}

#[cfg(feature = "runtime-benchmarks")]
impl Default for RuntimeParameters {
fn default() -> Self {
use frame_support::traits::Get;
RuntimeParameters::Pusd(dynamic_params::pusd::Parameters::MaximumIssuance(
dynamic_params::pusd::MaximumIssuance,
Some(dynamic_params::pusd::MaximumIssuance::get()),
))
}
}

/// Origin check for dynamic parameter changes — only Root can modify.
pub struct DynamicParameterOrigin;
impl frame_support::traits::EnsureOriginWithArg<RuntimeOrigin, RuntimeParametersKey>
for DynamicParameterOrigin
{
type Success = ();
fn try_origin(
origin: RuntimeOrigin,
_key: &RuntimeParametersKey,
) -> Result<Self::Success, RuntimeOrigin> {
frame_system::ensure_root(origin.clone()).map_err(|_| origin)
}
#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin(_key: &RuntimeParametersKey) -> Result<RuntimeOrigin, ()> {
Ok(RuntimeOrigin::root())
}
}

impl pallet_parameters::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeParameters = RuntimeParameters;
type AdminOrigin = DynamicParameterOrigin;
type WeightInfo = weights::pallet_parameters::WeightInfo<Runtime>;
}

// PSM configuration.
parameter_types! {
/// The pUSD stablecoin asset ID (trust-backed asset).
pub const PsmStablecoinAssetId: AssetIdForTrustBackedAssets = 50000342;
/// Minimum swap amount for PSM operations (1 pUSD).
pub const PsmMinSwapAmount: Balance = PUSD;
/// Minimum swap amount for PSM operations (1 unit at 6-decimal precision).
pub const PsmMinSwapAmount: Balance = 1_000_000;
/// Native-currency deposit reserved when permissionlessly creating a PSM.
pub const PsmCreationDeposit: Balance = deposit(1, 68);
/// PalletId for deriving the PSM system account.
pub const PsmPalletId: PalletId = PalletId(*b"py/pegsm");
/// Fee revenue destination: pUSD insurance fund account.
pub const PsmFeeDestinationPalletId: PalletId = PalletId(*b"pusd/ins");
pub PsmFeeDestination: AccountId = PsmFeeDestinationPalletId::get().into_account_truncating();
}

/// pUSD as a single-asset fungible, backed by trust-backed assets (Instance1).
type PsmInternalAsset =
frame_support::traits::fungible::ItemOf<Assets, PsmStablecoinAssetId, AccountId>;

/// EnsureOrigin for PSM management with privilege levels.
/// - Root gets Full privileges (all parameter changes).
/// - MonetaryGuard gets Emergency privileges (circuit breaker only).
pub struct EnsurePsmManager;
impl frame_support::traits::EnsureOrigin<RuntimeOrigin> for EnsurePsmManager {
type Success = pallet_psm::PsmManagerLevel;

fn try_origin(o: RuntimeOrigin) -> Result<Self::Success, RuntimeOrigin> {
// Try Root first.
let o = match o.clone().into() {
Ok(frame_system::RawOrigin::Root) => return Ok(pallet_psm::PsmManagerLevel::Full),
_ => o,
};
// Try MonetaryGuard — circuit breaker only.
pallet_custom_origins::MonetaryGuard::try_origin(o)
.map(|_| pallet_psm::PsmManagerLevel::Emergency)
}

#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin() -> Result<RuntimeOrigin, ()> {
Ok(RuntimeOrigin::root())
}
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -1703,46 +1620,19 @@ impl pallet_psm::BenchmarkHelper<xcm::v5::Location, AccountId> for PsmBenchmarkH

impl pallet_psm::Config for Runtime {
type Fungibles = LocalAndForeignAssets;
type Currency = Balances;
type RuntimeOrigin = RuntimeOrigin;
type PalletsOrigin = OriginCaller;
type AssetId = xcm::v5::Location;
type MaximumIssuance = dynamic_params::pusd::MaximumIssuance;
type ManagerOrigin = EnsurePsmManager;
type WeightInfo = weights::pallet_psm::WeightInfo<Runtime>;
type InternalAsset = PsmInternalAsset;
type FeeDestination = PsmFeeDestination;
type PalletId = PsmPalletId;
type MinSwapAmount = PsmMinSwapAmount;
type MaxExternalAssets = ConstU32<3>;
type MaxExternalAssetsPerPsm = ConstU32<3>;
type CreationDeposit = PsmCreationDeposit;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = PsmBenchmarkHelper;
}

/// Initial PSM configuration applied via the init migration.
///
/// Sets up USDT (trust-backed asset `1984`, addressed by its `Location`) as the
/// first external asset.
pub struct PsmInitialConfig;
impl pallet_psm::migrations::init::InitialPsmConfig<Runtime> for PsmInitialConfig {
fn max_psm_debt_of_total() -> Permill {
// USDT PSM cap is 5M out of 50M total issuance = 10%.
Permill::from_percent(10)
}
fn asset_configs(
) -> alloc::collections::btree_map::BTreeMap<xcm::v5::Location, (Permill, Permill, Permill)> {
use xcm::latest::prelude::*;
let usdt_location = xcm::v5::Location::new(0, [PalletInstance(50), GeneralIndex(1984)]);
[(
usdt_location,
(
Permill::zero(), // 0% minting fee
Permill::from_rational(1u32, 10_000u32), // 0.01% redemption fee
Permill::from_percent(100), // ceiling weight
),
)]
.into_iter()
.collect()
}
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime
Expand Down Expand Up @@ -1791,7 +1681,6 @@ construct_runtime!(
Indices: pallet_indices = 43,
MetaTx: pallet_meta_tx = 44,
VerifySignature: pallet_verify_signature = 45,
Parameters: pallet_parameters = 46,
Recovery: pallet_recovery = 47,

// The main stage.
Expand Down Expand Up @@ -2006,14 +1895,20 @@ pub type Migrations = (

// start: PSM reset

// `RemovePallet` wipes ALL of PSM's storage (entries + CountedStorageMap
// counters + the storage version key). `InitializePsm` then re-seeds data
// under the new `Location` AssetId, and `SetPsmStorageVersionV2` writes
// the on-chain storage version that `RemovePallet` cleared.
// `RemovePallet` wipes the old PSM deployment (entries + storage version
// key). `SetPsmStorageVersionV1` re-seeds the storage version key that
// `RemovePallet` cleared.
frame_support::migrations::RemovePallet<PsmName, <Runtime as frame_system::Config>::DbWeight>,
pallet_psm::migrations::init::InitializePsm<Runtime, PsmInitialConfig>,
SetPsmStorageVersionV2,
SetPsmStorageVersionV1,
// end: PSM reset

// `pallet_parameters` only ever hosted the now-removed system-wide PSM issuance cap
// (the per-PSM `max_debt` replaced it). Wipe its on-chain storage now that the pallet
// is gone from the runtime.
frame_support::migrations::RemovePallet<
ParametersName,
<Runtime as frame_system::Config>::DbWeight,
>,
pallet_dap::migrations::MigrateV1ToV2<
Runtime,
DapLastIssuanceTimestamp,
Expand Down Expand Up @@ -2243,8 +2138,8 @@ mod benches {
[pallet_nft_fractionalization, NftFractionalization]
[pallet_nfts, Nfts]
[pallet_proxy, Proxy]
[pallet_psm, Psm]
[pallet_parameters, Parameters]
[pallet_psm, Psm]
[pallet_recovery, Recovery]
[pallet_session, SessionBench::<Runtime>]
[pallet_staking_async, Staking]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ pub mod pallet_multisig;
pub mod pallet_nft_fractionalization;
pub mod pallet_nfts;
pub mod pallet_nomination_pools;
pub mod pallet_parameters;
pub mod pallet_pgas_allowance;
pub mod pallet_preimage;
pub mod pallet_proxy;
Expand Down

This file was deleted.

Loading
Loading