From 4428b50695f70801510136645b27116a5b6da3d5 Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 30 Aug 2021 17:22:02 +0800 Subject: [PATCH 1/7] chore(asset-index): clean outdated todos --- pallets/asset-index/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/asset-index/src/lib.rs b/pallets/asset-index/src/lib.rs index 58e997a4d6..6fab509fcd 100644 --- a/pallets/asset-index/src/lib.rs +++ b/pallets/asset-index/src/lib.rs @@ -342,7 +342,7 @@ pub mod pallet { /// into the sovereign account of either: /// - the given `recipient` if provided /// - the caller's account if `recipient` is `None` - #[pallet::weight(T::WeightInfo::remove_asset())] // TODO: Set weights + #[pallet::weight(T::WeightInfo::remove_asset())] pub fn remove_asset( origin: OriginFor, asset_id: T::AssetId, @@ -479,7 +479,7 @@ pub mod pallet { /// /// The distribution of the underlying assets will be equivalent to the /// ratio of the liquid assets in the index. - #[pallet::weight(T::WeightInfo::withdraw())] // TODO: Set weights + #[pallet::weight(T::WeightInfo::withdraw())] #[transactional] pub fn withdraw(origin: OriginFor, amount: T::Balance) -> DispatchResultWithPostInfo { let caller = ensure_signed(origin)?; @@ -564,7 +564,7 @@ pub mod pallet { /// as soon as the aforementioned conditions are met, regardless of /// whether the other `AssetWithdrawal`s in the same `PendingWithdrawal` set /// can also be closed successfully. - #[pallet::weight(T::WeightInfo::complete_withdraw())] // TODO: Set weights + #[pallet::weight(T::WeightInfo::complete_withdraw())] pub fn complete_withdraw(origin: OriginFor) -> DispatchResultWithPostInfo { let caller = ensure_signed(origin)?; From 285dbccd0b1e101eb3fda5fdf37938ff56be965e Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 30 Aug 2021 17:32:01 +0800 Subject: [PATCH 2/7] chore(runtime): move EnsureApprovedByCommittee to crate common --- runtime/common/src/lib.rs | 1 + runtime/common/src/types.rs | 9 +++++++++ runtime/dev/src/lib.rs | 12 +++--------- runtime/kusama/src/lib.rs | 12 +++--------- runtime/polkadot/src/lib.rs | 12 +++--------- 5 files changed, 19 insertions(+), 27 deletions(-) create mode 100644 runtime/common/src/types.rs diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 9587455dd2..5937bee8db 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -5,4 +5,5 @@ #![cfg_attr(not(feature = "std"), no_std)] pub mod constants; pub mod traits; +pub mod types; pub mod weights; diff --git a/runtime/common/src/types.rs b/runtime/common/src/types.rs new file mode 100644 index 0000000000..5c95efc8a5 --- /dev/null +++ b/runtime/common/src/types.rs @@ -0,0 +1,9 @@ +// Copyright 2021 ChainSafe Systems +// SPDX-License-Identifier: LGPL-3.0-only + +/// Origin that approved by committee +pub type EnsureApprovedByCommittee = frame_system::EnsureOneOf< + AccountId, + frame_system::EnsureRoot, + pallet_committee::EnsureApprovedByCommittee, +>; diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index 35f965fa0e..105ac52af3 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -55,7 +55,7 @@ use xcm_builder::{ use xcm_executor::XcmExecutor; use pallet_committee::EnsureMember; -pub use pint_runtime_common::{constants::*, weights}; +pub use pint_runtime_common::{constants::*, types::EnsureApprovedByCommittee, weights}; use primitives::traits::MultiAssetRegistry; pub use primitives::*; use xcm_calls::{ @@ -368,7 +368,7 @@ impl pallet_session::Config for Runtime { impl pallet_collator_selection::Config for Runtime { type Event = Event; type Currency = Balances; - type UpdateOrigin = EnsureApprovedByCommittee; + type UpdateOrigin = EnsureApprovedByCommittee; type PotId = PotId; type MaxCandidates = MaxCandidates; type MinCandidates = MinCandidates; @@ -400,12 +400,6 @@ impl pallet_saft_registry::Config for Runtime { type WeightInfo = weights::pallet_saft_registry::WeightInfo; } -type EnsureApprovedByCommittee = frame_system::EnsureOneOf< - AccountId, - frame_system::EnsureRoot, - pallet_committee::EnsureApprovedByCommittee, ->; - impl pallet_committee::Config for Runtime { type Origin = Origin; type Action = Call; @@ -415,7 +409,7 @@ impl pallet_committee::Config for Runtime { type MinCouncilVotes = MinCouncilVotes; type ProposalSubmissionOrigin = EnsureSigned; type ProposalExecutionOrigin = EnsureMember; - type ApprovedByCommitteeOrigin = EnsureApprovedByCommittee; + type ApprovedByCommitteeOrigin = EnsureApprovedByCommittee; type Event = Event; type WeightInfo = weights::pallet_committee::WeightInfo; } diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index 69d0f95354..cc9b0ec57e 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -55,7 +55,7 @@ use xcm_builder::{ use xcm_executor::XcmExecutor; use pallet_committee::EnsureMember; -pub use pint_runtime_common::{constants::*, weights}; +pub use pint_runtime_common::{constants::*, types::EnsureApprovedByCommittee, weights}; use primitives::traits::MultiAssetRegistry; pub use primitives::*; use xcm_calls::{ @@ -366,7 +366,7 @@ impl pallet_session::Config for Runtime { impl pallet_collator_selection::Config for Runtime { type Event = Event; type Currency = Balances; - type UpdateOrigin = EnsureApprovedByCommittee; + type UpdateOrigin = EnsureApprovedByCommittee; type PotId = PotId; type MaxCandidates = MaxCandidates; type MinCandidates = MinCandidates; @@ -398,12 +398,6 @@ impl pallet_saft_registry::Config for Runtime { type WeightInfo = weights::pallet_saft_registry::WeightInfo; } -type EnsureApprovedByCommittee = frame_system::EnsureOneOf< - AccountId, - frame_system::EnsureRoot, - pallet_committee::EnsureApprovedByCommittee, ->; - impl pallet_committee::Config for Runtime { type Origin = Origin; type Action = Call; @@ -413,7 +407,7 @@ impl pallet_committee::Config for Runtime { type MinCouncilVotes = MinCouncilVotes; type ProposalSubmissionOrigin = EnsureSigned; type ProposalExecutionOrigin = EnsureMember; - type ApprovedByCommitteeOrigin = EnsureApprovedByCommittee; + type ApprovedByCommitteeOrigin = EnsureApprovedByCommittee; type Event = Event; type WeightInfo = weights::pallet_committee::WeightInfo; } diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index 35f965fa0e..105ac52af3 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -55,7 +55,7 @@ use xcm_builder::{ use xcm_executor::XcmExecutor; use pallet_committee::EnsureMember; -pub use pint_runtime_common::{constants::*, weights}; +pub use pint_runtime_common::{constants::*, types::EnsureApprovedByCommittee, weights}; use primitives::traits::MultiAssetRegistry; pub use primitives::*; use xcm_calls::{ @@ -368,7 +368,7 @@ impl pallet_session::Config for Runtime { impl pallet_collator_selection::Config for Runtime { type Event = Event; type Currency = Balances; - type UpdateOrigin = EnsureApprovedByCommittee; + type UpdateOrigin = EnsureApprovedByCommittee; type PotId = PotId; type MaxCandidates = MaxCandidates; type MinCandidates = MinCandidates; @@ -400,12 +400,6 @@ impl pallet_saft_registry::Config for Runtime { type WeightInfo = weights::pallet_saft_registry::WeightInfo; } -type EnsureApprovedByCommittee = frame_system::EnsureOneOf< - AccountId, - frame_system::EnsureRoot, - pallet_committee::EnsureApprovedByCommittee, ->; - impl pallet_committee::Config for Runtime { type Origin = Origin; type Action = Call; @@ -415,7 +409,7 @@ impl pallet_committee::Config for Runtime { type MinCouncilVotes = MinCouncilVotes; type ProposalSubmissionOrigin = EnsureSigned; type ProposalExecutionOrigin = EnsureMember; - type ApprovedByCommitteeOrigin = EnsureApprovedByCommittee; + type ApprovedByCommitteeOrigin = EnsureApprovedByCommittee; type Event = Event; type WeightInfo = weights::pallet_committee::WeightInfo; } From e34d062a58fc082faf675cedecf9639e059cbfd7 Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 30 Aug 2021 17:39:53 +0800 Subject: [PATCH 3/7] feat(runtime): use committee origin as admin origin in asset-index --- runtime/polkadot/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index 105ac52af3..cca3562559 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -440,7 +440,7 @@ impl pallet_chainlink_feed::Config for Runtime { impl pallet_asset_index::Config for Runtime { // Using signed as the admin origin for testing now - type AdminOrigin = frame_system::EnsureSigned; + type AdminOrigin = EnsureApprovedByCommittee; type IndexToken = Balances; type Balance = Balance; type LockupPeriod = LockupPeriod; From 05eca8823c923060eb6347a20f995e7c8e34b79b Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 30 Aug 2021 18:45:48 +0800 Subject: [PATCH 4/7] feat(price-feed): supports creating feed in feature runtime-benchmarks --- pallets/asset-index/src/benchmarking.rs | 10 +++++-- pallets/price-feed/src/lib.rs | 37 ++++++++++++++++++++++++- pallets/price-feed/src/traits.rs | 7 ++++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/pallets/asset-index/src/benchmarking.rs b/pallets/asset-index/src/benchmarking.rs index ec2cfb99fb..d293ccb9d1 100644 --- a/pallets/asset-index/src/benchmarking.rs +++ b/pallets/asset-index/src/benchmarking.rs @@ -97,12 +97,18 @@ benchmarks! { deposit { // ASSET_A_ID - let asset_id = 1_u32.into(); + let asset_id = 42_u32.into(); let origin = T::AdminOrigin::successful_origin(); let depositor = whitelisted_account::("depositor", 0); let admin_deposit = 5u32.into(); - assert_ok!(AssetIndex::::add_asset(origin, asset_id, 100u32.into(),MultiLocation::Null,admin_deposit + assert_ok!(AssetIndex::::add_asset( + origin, + asset_id, + 100u32.into(), + MultiLocation::Null, + admin_deposit, )); + let units = 1_000u32.into(); assert_ok!(T::Currency::deposit(asset_id, &depositor, units)); let nav = AssetIndex::::nav().unwrap(); diff --git a/pallets/price-feed/src/lib.rs b/pallets/price-feed/src/lib.rs index 24c1193596..24b837ec3d 100644 --- a/pallets/price-feed/src/lib.rs +++ b/pallets/price-feed/src/lib.rs @@ -39,12 +39,17 @@ mod types; // this is requires as the #[pallet::event] proc macro generates code that violates this lint #[allow(clippy::unused_unit)] pub mod pallet { + #[cfg(feature = "runtime-benchmarks")] + pub use crate::traits::PriceFeedBenchmarks; pub use crate::{traits::PriceFeed, types::TimestampedValue}; #[cfg(feature = "std")] use frame_support::traits::GenesisBuild; use frame_support::{ pallet_prelude::*, - sp_runtime::{traits::CheckedDiv, FixedPointNumber, FixedPointOperand}, + sp_runtime::{ + traits::{CheckedDiv, Zero}, + FixedPointNumber, FixedPointOperand, + }, traits::{Get, Time}, }; use frame_system::pallet_prelude::*; @@ -260,6 +265,36 @@ pub mod pallet { } } + #[cfg(feature = "runtime-benchmarks")] + impl PriceFeedBenchmarks for Pallet { + fn create_feed( + caller: ::AccountId, + asset_id: T::AssetId, + ) -> DispatchResultWithPostInfo { + use frame_benchmarking::vec; + + pallet_chainlink_feed::Pallet::::create_feed( + >::Signed(caller.clone()).into(), + 600u32.into(), + Zero::zero(), + (1u8.into(), 100u8.into()), + 1u8.into(), + 5u8, + vec![1; T::StringLimit::get() as usize], + Zero::zero(), + vec![(caller.clone(), caller)], + None, + None, + )?; + + let _ = AssetFeeds::::mutate(&asset_id, |maybe_feed_id| { + maybe_feed_id.replace(>::get()) + }); + + Ok(().into()) + } + } + impl pallet_chainlink_feed::traits::OnAnswerHandler for Pallet { fn on_answer(feed_id: FeedIdFor, _: RoundData>) { LatestAnswerTimestamp::::insert(feed_id, T::Time::now()); diff --git a/pallets/price-feed/src/traits.rs b/pallets/price-feed/src/traits.rs index b9740aaf51..b64533bd67 100644 --- a/pallets/price-feed/src/traits.rs +++ b/pallets/price-feed/src/traits.rs @@ -1,7 +1,7 @@ // Copyright 2021 ChainSafe Systems // SPDX-License-Identifier: LGPL-3.0-only -use frame_support::dispatch::DispatchError; +use frame_support::dispatch::{DispatchError, DispatchResultWithPostInfo}; use primitives::{AssetPricePair, Price}; /// An interface to access price data @@ -15,3 +15,8 @@ pub trait PriceFeed { /// `base/quote` fn get_relative_price_pair(base: AssetId, quote: AssetId) -> Result, DispatchError>; } + +#[cfg(feature = "runtime-benchmarks")] +pub trait PriceFeedBenchmarks { + fn create_feed(caller: AccountId, asset_id: AssetId) -> DispatchResultWithPostInfo; +} From 007cc053f3e1d29c006439f6d2149e669c738b67 Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 30 Aug 2021 23:46:56 +0800 Subject: [PATCH 5/7] feat(price-feed): add trait PriceFeedBenchmark --- pallets/asset-index/src/benchmarking.rs | 15 ++++++++------- pallets/asset-index/src/lib.rs | 6 ++++++ pallets/price-feed/src/lib.rs | 23 ++++++++++++++++------- runtime/dev/src/lib.rs | 2 ++ runtime/kusama/src/lib.rs | 2 ++ runtime/polkadot/src/lib.rs | 2 ++ 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/pallets/asset-index/src/benchmarking.rs b/pallets/asset-index/src/benchmarking.rs index d293ccb9d1..b5628b59af 100644 --- a/pallets/asset-index/src/benchmarking.rs +++ b/pallets/asset-index/src/benchmarking.rs @@ -12,7 +12,7 @@ use frame_support::{ }; use frame_system::RawOrigin; use orml_traits::MultiCurrency; -use pallet_price_feed::PriceFeed; +use pallet_price_feed::{PriceFeed, PriceFeedBenchmarks}; use primitives::{traits::NavProvider, AssetAvailability}; use xcm::v0::MultiLocation; @@ -96,11 +96,12 @@ benchmarks! { } deposit { - // ASSET_A_ID let asset_id = 42_u32.into(); let origin = T::AdminOrigin::successful_origin(); let depositor = whitelisted_account::("depositor", 0); let admin_deposit = 5u32.into(); + let units = 1_000u32.into(); + assert_ok!(AssetIndex::::add_asset( origin, asset_id, @@ -109,17 +110,17 @@ benchmarks! { admin_deposit, )); - let units = 1_000u32.into(); + T::PriceFeedBenchmarks::create_feed(Default::default(), asset_id).unwrap(); assert_ok!(T::Currency::deposit(asset_id, &depositor, units)); - let nav = AssetIndex::::nav().unwrap(); }: _( RawOrigin::Signed(depositor.clone()), asset_id, units ) verify { - let deposit_value = T::PriceFeed::get_price(asset_id).unwrap().checked_mul_int(units.into()).unwrap(); - let received = nav.reciprocal().unwrap().saturating_mul_int(deposit_value); - assert_eq!(AssetIndex::::index_token_balance(&depositor).into(), received); + // let nav = AssetIndex::::nav().unwrap(); + // let deposit_value = T::PriceFeed::get_price(asset_id).unwrap().checked_mul_int(units.into()).unwrap(); + // let received = nav.reciprocal().unwrap().saturating_mul_int(deposit_value); + // assert_eq!(AssetIndex::::index_token_balance(&depositor).into(), received); } remove_asset { diff --git a/pallets/asset-index/src/lib.rs b/pallets/asset-index/src/lib.rs index 6fab509fcd..1845e95a28 100644 --- a/pallets/asset-index/src/lib.rs +++ b/pallets/asset-index/src/lib.rs @@ -45,6 +45,8 @@ pub mod pallet { use sp_core::U256; use xcm::v0::{Junction, MultiLocation}; + #[cfg(feature = "runtime-benchmarks")] + use pallet_price_feed::PriceFeedBenchmarks; use pallet_price_feed::{AssetPricePair, Price, PriceFeed}; use primitives::{ fee::{BaseFee, FeeRate}, @@ -107,6 +109,10 @@ pub mod pallet { /// The types that provides the necessary asset price pairs type PriceFeed: PriceFeed; + #[cfg(feature = "runtime-benchmarks")] + /// The type that provides benchmark features of pallet_price_feed + type PriceFeedBenchmarks: PriceFeedBenchmarks; + /// The type registry that stores all NAV for non liquid assets type SaftRegistry: SaftRegistry; diff --git a/pallets/price-feed/src/lib.rs b/pallets/price-feed/src/lib.rs index 24b837ec3d..f7d0149bfb 100644 --- a/pallets/price-feed/src/lib.rs +++ b/pallets/price-feed/src/lib.rs @@ -273,24 +273,33 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { use frame_benchmarking::vec; + pallet_chainlink_feed::Pallet::::set_feed_creator( + >::Signed(pallet_chainlink_feed::Pallet::::pallet_admin()).into(), + caller.clone(), + )?; + pallet_chainlink_feed::Pallet::::create_feed( >::Signed(caller.clone()).into(), - 600u32.into(), + 100u32.into(), Zero::zero(), (1u8.into(), 100u8.into()), 1u8.into(), - 5u8, + 8u8, vec![1; T::StringLimit::get() as usize], Zero::zero(), - vec![(caller.clone(), caller)], + vec![(caller.clone(), caller.clone())], None, None, )?; - let _ = AssetFeeds::::mutate(&asset_id, |maybe_feed_id| { - maybe_feed_id.replace(>::get()) - }); - + let feed_id = >::get() - 1.into(); + AssetFeeds::::insert(&asset_id, feed_id); + pallet_chainlink_feed::Pallet::::submit( + >::Signed(caller.clone()).into(), + feed_id, + 1_u32.into(), + 42.into(), + )?; Ok(().into()) } } diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index 105ac52af3..5f31fa5a6e 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -453,6 +453,8 @@ impl pallet_asset_index::Config for Runtime { type SelfAssetId = PINTAssetId; type Currency = Currencies; type PriceFeed = PriceFeed; + #[cfg(feature = "runtime-benchmarks")] + type PriceFeedBenchmarks = PriceFeed; type SaftRegistry = SaftRegistry; type BaseWithdrawalFee = BaseWithdrawalFee; type TreasuryPalletId = TreasuryPalletId; diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index cc9b0ec57e..fb38e414aa 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -451,6 +451,8 @@ impl pallet_asset_index::Config for Runtime { type SelfAssetId = PINTAssetId; type Currency = Currencies; type PriceFeed = PriceFeed; + #[cfg(feature = "runtime-benchmarks")] + type PriceFeedBenchmarks = PriceFeed; type SaftRegistry = SaftRegistry; type BaseWithdrawalFee = BaseWithdrawalFee; type TreasuryPalletId = TreasuryPalletId; diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index cca3562559..a360f14151 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -453,6 +453,8 @@ impl pallet_asset_index::Config for Runtime { type SelfAssetId = PINTAssetId; type Currency = Currencies; type PriceFeed = PriceFeed; + #[cfg(feature = "runtime-benchmarks")] + type PriceFeedBenchmarks = PriceFeed; type SaftRegistry = SaftRegistry; type BaseWithdrawalFee = BaseWithdrawalFee; type TreasuryPalletId = TreasuryPalletId; From 6b55b0b085387873c054a548cd90b87766c53742 Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 31 Aug 2021 11:08:15 +0800 Subject: [PATCH 6/7] feat(price-feed): fix tests --- pallets/asset-index/src/benchmarking.rs | 10 +++++----- pallets/asset-index/src/mock.rs | 15 +++++++++++++-- pallets/remote-asset-manager/src/mock.rs | 13 ++++++++++--- pallets/saft-registry/src/mock.rs | 15 +++++++++++++-- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/pallets/asset-index/src/benchmarking.rs b/pallets/asset-index/src/benchmarking.rs index b5628b59af..c47624bd33 100644 --- a/pallets/asset-index/src/benchmarking.rs +++ b/pallets/asset-index/src/benchmarking.rs @@ -96,7 +96,7 @@ benchmarks! { } deposit { - let asset_id = 42_u32.into(); + let asset_id = 2_u32.into(); let origin = T::AdminOrigin::successful_origin(); let depositor = whitelisted_account::("depositor", 0); let admin_deposit = 5u32.into(); @@ -117,10 +117,10 @@ benchmarks! { asset_id, units ) verify { - // let nav = AssetIndex::::nav().unwrap(); - // let deposit_value = T::PriceFeed::get_price(asset_id).unwrap().checked_mul_int(units.into()).unwrap(); - // let received = nav.reciprocal().unwrap().saturating_mul_int(deposit_value); - // assert_eq!(AssetIndex::::index_token_balance(&depositor).into(), received); + let nav = AssetIndex::::nav().unwrap(); + let deposit_value = T::PriceFeed::get_price(asset_id).unwrap().checked_mul_int(units.into()).unwrap(); + let received = nav.reciprocal().unwrap().saturating_mul_int(deposit_value).saturating_add(1u128); + assert_eq!(AssetIndex::::index_token_balance(&depositor).into(), received); } remove_asset { diff --git a/pallets/asset-index/src/mock.rs b/pallets/asset-index/src/mock.rs index 0ec29f4624..7e7c490cfb 100644 --- a/pallets/asset-index/src/mock.rs +++ b/pallets/asset-index/src/mock.rs @@ -6,13 +6,15 @@ use crate as pallet_asset_index; use frame_support::{ - ord_parameter_types, parameter_types, + ord_parameter_types, + pallet_prelude::DispatchResultWithPostInfo, + parameter_types, traits::{GenesisBuild, LockIdentifier, StorageMapShim}, PalletId, }; use frame_system as system; use orml_traits::parameter_type_with_key; -use pallet_price_feed::PriceFeed; +use pallet_price_feed::{PriceFeed, PriceFeedBenchmarks}; use primitives::{fee::FeeRate, traits::RemoteAssetManager, AssetPricePair, Price}; use sp_core::H256; use sp_std::cell::RefCell; @@ -166,6 +168,8 @@ impl pallet_asset_index::Config for Test { type SelfAssetId = PINTAssetId; type Currency = Currency; type PriceFeed = MockPriceFeed; + #[cfg(feature = "runtime-benchmarks")] + type PriceFeedBenchmarks = MockPriceFeed; type SaftRegistry = SaftRegistry; type BaseWithdrawalFee = BaseWithdrawalFee; type TreasuryPalletId = TreasuryPalletId; @@ -212,6 +216,13 @@ impl MockPriceFeed { } } +#[cfg(feature = "runtime-benchmarks")] +impl PriceFeedBenchmarks for MockPriceFeed { + fn create_feed(_caller: AccountId, _asset_id: AssetId) -> DispatchResultWithPostInfo { + Ok(().into()) + } +} + impl PriceFeed for MockPriceFeed { // mock price supposed to return the price pair with the same `quote` price, like USD fn get_price(asset: AssetId) -> Result { diff --git a/pallets/remote-asset-manager/src/mock.rs b/pallets/remote-asset-manager/src/mock.rs index 80e49ee36e..0b1b4925c0 100644 --- a/pallets/remote-asset-manager/src/mock.rs +++ b/pallets/remote-asset-manager/src/mock.rs @@ -53,7 +53,6 @@ pub use xcm_test_support::{relay, types::*, Relay}; pub const ALICE: AccountId = AccountId::new([0u8; 32]); pub const ADMIN_ACCOUNT: AccountId = AccountId::new([1u8; 32]); -pub const EMPTY_ACCOUNT: AccountId = AccountId::new([3u8; 32]); pub const INITIAL_BALANCE: Balance = 10_000; pub const PARA_ID: u32 = 1u32; pub const STATEMINT_PARA_ID: u32 = 200u32; @@ -188,10 +187,10 @@ pub mod para { *, }; use codec::Decode; - use frame_support::dispatch::DispatchError; + use frame_support::dispatch::{DispatchError, DispatchResultWithPostInfo}; use orml_currencies::BasicCurrencyAdapter; use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter}; - use pallet_price_feed::{AssetPricePair, Price, PriceFeed}; + use pallet_price_feed::{AssetPricePair, Price, PriceFeed, PriceFeedBenchmarks}; use sp_runtime::traits::Convert; parameter_types! { @@ -445,6 +444,7 @@ pub mod para { type RemoteAssetManager = RemoteAssetManager; type Currency = Currency; type PriceFeed = MockPriceFeed; + type PriceFeedBenchmarks = MockPriceFeed; type SaftRegistry = SaftRegistry; type TreasuryPalletId = TreasuryPalletId; type StringLimit = StringLimit; @@ -470,6 +470,13 @@ pub mod para { } } + #[cfg(feature = "runtime-benchmarks")] + impl PriceFeedBenchmarks for MockPriceFeed { + fn create_feed(_caller: AccountId, _asset_id: AssetId) -> DispatchResultWithPostInfo { + Ok(().into()) + } + } + impl pallet_remote_asset_manager::Config for Runtime { type Balance = Balance; type AssetId = AssetId; diff --git a/pallets/saft-registry/src/mock.rs b/pallets/saft-registry/src/mock.rs index 67ee890af3..a19e94860e 100644 --- a/pallets/saft-registry/src/mock.rs +++ b/pallets/saft-registry/src/mock.rs @@ -7,13 +7,15 @@ use crate as pallet_saft_registry; use core::cell::RefCell; use frame_support::{ - assert_ok, ord_parameter_types, parameter_types, + assert_ok, ord_parameter_types, + pallet_prelude::DispatchResultWithPostInfo, + parameter_types, traits::{LockIdentifier, StorageMapShim}, PalletId, }; use frame_system as system; use orml_traits::parameter_type_with_key; -use pallet_price_feed::{AssetPricePair, Price, PriceFeed}; +use pallet_price_feed::{AssetPricePair, Price, PriceFeed, PriceFeedBenchmarks}; use primitives::traits::RemoteAssetManager; use xcm::v0::MultiLocation; @@ -132,6 +134,8 @@ impl pallet_asset_index::Config for Test { type SelfAssetId = PINTAssetId; type Currency = Currency; type PriceFeed = MockPriceFeed; + #[cfg(feature = "runtime-benchmarks")] + type PriceFeedBenchmarks = MockPriceFeed; type SaftRegistry = SaftRegistry; type BaseWithdrawalFee = BaseWithdrawalFee; type TreasuryPalletId = TreasuryPalletId; @@ -179,6 +183,13 @@ impl PriceFeed for MockPriceFeed { } } +#[cfg(feature = "runtime-benchmarks")] +impl PriceFeedBenchmarks for MockPriceFeed { + fn create_feed(_caller: AccountId, _asset_id: AssetId) -> DispatchResultWithPostInfo { + Ok(().into()) + } +} + parameter_type_with_key! { pub ExistentialDeposits: |_asset_id: AssetId| -> Balance { Zero::zero() From ad41eb19c5f76eed6e6c11cdd0711057a75a5412 Mon Sep 17 00:00:00 2001 From: clearloop Date: Tue, 31 Aug 2021 14:51:08 +0800 Subject: [PATCH 7/7] feat(price-feed): clean dependencies --- pallets/price-feed/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pallets/price-feed/src/lib.rs b/pallets/price-feed/src/lib.rs index f7d0149bfb..bc4a354c18 100644 --- a/pallets/price-feed/src/lib.rs +++ b/pallets/price-feed/src/lib.rs @@ -41,15 +41,15 @@ mod types; pub mod pallet { #[cfg(feature = "runtime-benchmarks")] pub use crate::traits::PriceFeedBenchmarks; - pub use crate::{traits::PriceFeed, types::TimestampedValue}; + #[cfg(feature = "runtime-benchmarks")] + use frame_benchmarking::Zero; #[cfg(feature = "std")] use frame_support::traits::GenesisBuild; + + pub use crate::{traits::PriceFeed, types::TimestampedValue}; use frame_support::{ pallet_prelude::*, - sp_runtime::{ - traits::{CheckedDiv, Zero}, - FixedPointNumber, FixedPointOperand, - }, + sp_runtime::{traits::CheckedDiv, FixedPointNumber, FixedPointOperand}, traits::{Get, Time}, }; use frame_system::pallet_prelude::*;