From 99bf86dc0148a56a18b52530c2645ceb5dfb73cd Mon Sep 17 00:00:00 2001 From: Nathy-bajo Date: Wed, 15 Jan 2025 18:18:57 +0100 Subject: [PATCH] migrate pallet-asset-rate to use umbrella crate --- Cargo.lock | 7 +--- substrate/frame/asset-rate/Cargo.toml | 40 +++---------------- .../frame/asset-rate/src/benchmarking.rs | 5 +-- substrate/frame/asset-rate/src/lib.rs | 13 +----- substrate/frame/asset-rate/src/mock.rs | 9 ++--- substrate/frame/asset-rate/src/tests.rs | 3 +- substrate/frame/asset-rate/src/weights.rs | 2 +- substrate/frame/src/lib.rs | 11 +++-- 8 files changed, 23 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7725db743c41d..0d6128c899e81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12010,15 +12010,10 @@ dependencies = [ name = "pallet-asset-rate" version = "7.0.0" dependencies = [ - "frame-benchmarking 28.0.0", - "frame-support 28.0.0", - "frame-system 28.0.0", "pallet-balances 28.0.0", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "scale-info", - "sp-core 28.0.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", ] [[package]] diff --git a/substrate/frame/asset-rate/Cargo.toml b/substrate/frame/asset-rate/Cargo.toml index 01a5ca21b199b..c701b208f508e 100644 --- a/substrate/frame/asset-rate/Cargo.toml +++ b/substrate/frame/asset-rate/Cargo.toml @@ -15,45 +15,15 @@ workspace = true targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { features = [ - "derive", -], workspace = true } -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } +codec = { features = ["derive"], workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } scale-info = { features = ["derive"], workspace = true } -sp-core = { optional = true, workspace = true } -sp-runtime = { workspace = true } [dev-dependencies] pallet-balances = { workspace = true, default-features = true } -sp-core = { workspace = true } -sp-io = { workspace = true, default-features = true } [features] default = ["std"] -std = [ - "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", - "pallet-balances/std", - "scale-info/std", - "sp-core?/std", - "sp-io/std", - "sp-runtime/std", -] -runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "sp-core", - "sp-runtime/runtime-benchmarks", -] -try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "pallet-balances/try-runtime", - "sp-runtime/try-runtime", -] +std = ["codec/std", "frame/std", "pallet-balances/std", "scale-info/std"] +runtime-benchmarks = ["pallet-balances/runtime-benchmarks"] +try-runtime = ["pallet-balances/try-runtime", "frame/try-runtime"] diff --git a/substrate/frame/asset-rate/src/benchmarking.rs b/substrate/frame/asset-rate/src/benchmarking.rs index 6fcc7c7fadb24..764340107320e 100644 --- a/substrate/frame/asset-rate/src/benchmarking.rs +++ b/substrate/frame/asset-rate/src/benchmarking.rs @@ -21,10 +21,7 @@ use super::*; use crate::{pallet as pallet_asset_rate, Pallet as AssetRate}; use codec::Encode; -use frame_benchmarking::v2::*; -use frame_support::assert_ok; -use frame_system::RawOrigin; -use sp_core::crypto::FromEntropy; +use frame::{benchmarking::prelude::*, deps::sp_core::crypto::FromEntropy}; /// Trait describing the factory function for the `AssetKind` parameter. pub trait AssetKindFactory { diff --git a/substrate/frame/asset-rate/src/lib.rs b/substrate/frame/asset-rate/src/lib.rs index cfb013a73f5e8..1d4459ccb4687 100644 --- a/substrate/frame/asset-rate/src/lib.rs +++ b/substrate/frame/asset-rate/src/lib.rs @@ -62,14 +62,7 @@ extern crate alloc; use alloc::boxed::Box; -use frame_support::traits::{ - fungible::Inspect, - tokens::{ConversionFromAssetBalance, ConversionToAssetBalance}, -}; -use sp_runtime::{ - traits::{CheckedDiv, Zero}, - FixedPointNumber, FixedU128, -}; +use frame::{prelude::*, traits::fungible::Inspect}; pub use pallet::*; pub use weights::WeightInfo; @@ -91,11 +84,9 @@ type AssetKindOf = ::AssetKind; // Generic fungible balance type. type BalanceOf = <::Currency as Inspect>>::Balance; -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; #[pallet::pallet] pub struct Pallet(_); diff --git a/substrate/frame/asset-rate/src/mock.rs b/substrate/frame/asset-rate/src/mock.rs index c829d78afa886..21a1c9cd4364a 100644 --- a/substrate/frame/asset-rate/src/mock.rs +++ b/substrate/frame/asset-rate/src/mock.rs @@ -18,12 +18,11 @@ //! The crate's mock. use crate as pallet_asset_rate; -use frame_support::derive_impl; -use sp_runtime::BuildStorage; +use frame::testing_prelude::*; -type Block = frame_system::mocking::MockBlock; +type Block = MockBlock; -frame_support::construct_runtime!( +construct_runtime!( pub enum Test { System: frame_system, @@ -56,6 +55,6 @@ impl pallet_asset_rate::Config for Test { } // Build genesis storage according to the mock runtime. -pub fn new_test_ext() -> sp_io::TestExternalities { +pub fn new_test_ext() -> TestState { frame_system::GenesisConfig::::default().build_storage().unwrap().into() } diff --git a/substrate/frame/asset-rate/src/tests.rs b/substrate/frame/asset-rate/src/tests.rs index fc7bf2f150311..7f65a08338fc2 100644 --- a/substrate/frame/asset-rate/src/tests.rs +++ b/substrate/frame/asset-rate/src/tests.rs @@ -19,9 +19,8 @@ use super::*; use crate::pallet as pallet_asset_rate; -use frame_support::{assert_noop, assert_ok}; +use frame::testing_prelude::*; use mock::{new_test_ext, AssetRate, RuntimeOrigin, Test}; -use sp_runtime::FixedU128; const ASSET_ID: u32 = 42; diff --git a/substrate/frame/asset-rate/src/weights.rs b/substrate/frame/asset-rate/src/weights.rs index c1991dc4ebb21..dd21ecbd45595 100644 --- a/substrate/frame/asset-rate/src/weights.rs +++ b/substrate/frame/asset-rate/src/weights.rs @@ -46,7 +46,7 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use frame::weights_prelude::*; use core::marker::PhantomData; /// Weight functions needed for `pallet_asset_rate`. diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index f79a52bc6c5bf..5a0b607e5454e 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -206,6 +206,7 @@ pub mod prelude { pub use frame_support::{ defensive, defensive_assert, traits::{ + tokens::{ConversionFromAssetBalance, ConversionToAssetBalance}, Contains, EitherOf, EstimateNextSessionRotation, IsSubType, MapSuccess, NoOpPoll, OnRuntimeUpgrade, OneSessionHandler, RankedMembers, RankedMembersSwapHandler, }, @@ -231,9 +232,13 @@ pub mod prelude { /// Runtime traits #[doc(no_inline)] - pub use sp_runtime::traits::{ - BlockNumberProvider, Bounded, Convert, DispatchInfoOf, Dispatchable, ReduceBy, - ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput, + pub use sp_runtime::{ + traits::{ + BlockNumberProvider, Bounded, CheckedDiv, Convert, DispatchInfoOf, Dispatchable, + ReduceBy, ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup, + TrailingZeroInput, Zero, + }, + FixedPointNumber, FixedU128, }; /// Other error/result types for runtime #[doc(no_inline)]