diff --git a/Cargo.lock b/Cargo.lock index 42d1488a5..1894c50a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6972,7 +6972,6 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "futures", "itertools 0.10.5", "log", "macros", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 0dfd6fb00..56c1b883b 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -79,10 +79,8 @@ polimec-runtime.workspace = true penpal-runtime = { path = "penpal", default-features = false } [features] -default = [ "instant-mode", "std", "development-settings"] -instant-mode = [ - "polimec-runtime/instant-mode", -] +default = [ "development-settings", "instant-mode", "std" ] +instant-mode = [ "polimec-runtime/instant-mode" ] std = [ "asset-hub-polkadot-runtime/std", "cumulus-pallet-xcm/std", @@ -138,7 +136,5 @@ std = [ "xcm-executor/std", "xcm/std", ] -development-settings = [ - "polimec-runtime/development-settings", -] +development-settings = [ "polimec-runtime/development-settings" ] diff --git a/nodes/parachain/Cargo.toml b/nodes/parachain/Cargo.toml index ab0df6c62..f2db29fd2 100644 --- a/nodes/parachain/Cargo.toml +++ b/nodes/parachain/Cargo.toml @@ -81,9 +81,7 @@ substrate-build-script-utils.workspace = true [features] default = [] fast-mode = [ "polimec-runtime/fast-mode" ] -instant-mode = [ - "polimec-runtime/instant-mode", -] +instant-mode = [ "polimec-runtime/instant-mode" ] runtime-benchmarks = [ "cumulus-primitives-core/runtime-benchmarks", "frame-benchmarking-cli/runtime-benchmarks", @@ -124,7 +122,5 @@ std = [ "sp-timestamp/std", "xcm/std", ] -on-chain-release-build = [ - "polimec-runtime/on-chain-release-build", -] +on-chain-release-build = [ "polimec-runtime/on-chain-release-build" ] development-settings = [ "polimec-runtime/development-settings" ] diff --git a/pallets/funding/Cargo.toml b/pallets/funding/Cargo.toml index 6c2b6f833..818c0aab0 100644 --- a/pallets/funding/Cargo.toml +++ b/pallets/funding/Cargo.toml @@ -18,13 +18,10 @@ parity-scale-codec = { workspace = true, features = [ scale-info = { workspace = true, default-features = false, features = [ "derive", ] } -futures = { version = "0.3.29", optional = true, default-features = false} log.workspace = true -itertools.workspace = true variant_count = "1.1.0" # Substrate dependencies -frame-benchmarking = { workspace = true, optional = true } frame-support.workspace = true frame-system.workspace = true sp-std.workspace = true @@ -34,12 +31,16 @@ polimec-common.workspace = true parachains-common.workspace = true sp-core.workspace = true pallet-balances.workspace = true -sp-io.workspace = true xcm.workspace = true polimec-xcm-executor.workspace = true pallet-xcm.workspace = true polkadot-parachain-primitives.workspace = true polimec-common-test-utils = { workspace = true, optional = true } +frame-benchmarking = { workspace = true, optional = true } + +# Used in the instantiator. +itertools.workspace = true +sp-io.workspace = true [dev-dependencies] pallet-insecure-randomness-collective-flip.workspace = true @@ -58,8 +59,6 @@ std = [ "frame-benchmarking?/std", "frame-support/std", "frame-system/std", - "futures", - "futures?/std", "itertools/use_std", "log/std", "pallet-assets/std", diff --git a/pallets/funding/src/functions/1_application.rs b/pallets/funding/src/functions/1_application.rs index 2f6c855ba..27498df80 100644 --- a/pallets/funding/src/functions/1_application.rs +++ b/pallets/funding/src/functions/1_application.rs @@ -70,7 +70,7 @@ impl Pallet { let maybe_active_project = DidWithActiveProjects::::get(did.clone()); // * Validity checks * - ensure!(maybe_active_project == None, Error::::HasActiveProject); + ensure!(maybe_active_project.is_none(), Error::::HasActiveProject); let (project_metadata, project_details, bucket) = Self::project_validation(project_metadata, issuer.clone(), did.clone())?; diff --git a/pallets/funding/src/functions/2_evaluation.rs b/pallets/funding/src/functions/2_evaluation.rs index d757dc364..7656703c8 100644 --- a/pallets/funding/src/functions/2_evaluation.rs +++ b/pallets/funding/src/functions/2_evaluation.rs @@ -136,9 +136,10 @@ impl Pallet { }; // * Emit events * - Self::deposit_event( - Event::ProjectPhaseTransition { project_id, phase: ProjectPhases::AuctionInitializePeriod }.into(), - ); + Self::deposit_event(Event::ProjectPhaseTransition { + project_id, + phase: ProjectPhases::AuctionInitializePeriod, + }); return Ok(PostDispatchInfo { actual_weight: Some(WeightInfoOf::::end_evaluation_success(insertion_attempts)), @@ -161,13 +162,10 @@ impl Pallet { }; // * Emit events * - Self::deposit_event( - Event::ProjectPhaseTransition { - project_id, - phase: ProjectPhases::FundingFinalization(ProjectOutcome::EvaluationFailed), - } - .into(), - ); + Self::deposit_event(Event::ProjectPhaseTransition { + project_id, + phase: ProjectPhases::FundingFinalization(ProjectOutcome::EvaluationFailed), + }); return Ok(PostDispatchInfo { actual_weight: Some(WeightInfoOf::::end_evaluation_failure(insertion_attempts)), pays_fee: Pays::Yes, diff --git a/pallets/funding/src/functions/3_auction.rs b/pallets/funding/src/functions/3_auction.rs index b8dd237ca..a82da3a43 100644 --- a/pallets/funding/src/functions/3_auction.rs +++ b/pallets/funding/src/functions/3_auction.rs @@ -59,13 +59,12 @@ impl Pallet { project_details.status = ProjectStatus::AuctionOpening; ProjectsDetails::::insert(project_id, project_details); - let insertion_attempts; // Schedule for automatic transition to auction closing round - match Self::add_to_update_store(opening_end_block + 1u32.into(), (&project_id, UpdateType::AuctionClosingStart)) - { - Ok(iterations) => { - insertion_attempts = iterations; - }, + let insertion_attempts = match Self::add_to_update_store( + opening_end_block + 1u32.into(), + (&project_id, UpdateType::AuctionClosingStart), + ) { + Ok(iterations) => iterations, Err(insertion_attempts) => return Err(DispatchErrorWithPostInfo { post_info: PostDispatchInfo { diff --git a/pallets/funding/src/functions/5_funding_end.rs b/pallets/funding/src/functions/5_funding_end.rs index 94bf91f00..941c694cd 100644 --- a/pallets/funding/src/functions/5_funding_end.rs +++ b/pallets/funding/src/functions/5_funding_end.rs @@ -169,18 +169,18 @@ impl Pallet { ensure!(project_details.status == ProjectStatus::AwaitingProjectDecision, Error::::IncorrectRound); // * Update storage * - let insertion_attempts: u32; - match Self::add_to_update_store(now + 1u32.into(), (&project_id, UpdateType::ProjectDecision(decision))) { - Ok(iterations) => insertion_attempts = iterations, - Err(iterations) => - return Err(DispatchErrorWithPostInfo { - post_info: PostDispatchInfo { - actual_weight: Some(WeightInfoOf::::decide_project_outcome(iterations)), - pays_fee: Pays::Yes, - }, - error: Error::::TooManyInsertionAttempts.into(), - }), - }; + let insertion_attempts = + match Self::add_to_update_store(now + 1u32.into(), (&project_id, UpdateType::ProjectDecision(decision))) { + Ok(iterations) => iterations, + Err(iterations) => + return Err(DispatchErrorWithPostInfo { + post_info: PostDispatchInfo { + actual_weight: Some(WeightInfoOf::::decide_project_outcome(iterations)), + pays_fee: Pays::Yes, + }, + error: Error::::TooManyInsertionAttempts.into(), + }), + }; Self::deposit_event(Event::ProjectOutcomeDecided { project_id, decision }); diff --git a/pallets/funding/src/functions/6_settlement.rs b/pallets/funding/src/functions/6_settlement.rs index 5e57e2fc3..48a4d3622 100644 --- a/pallets/funding/src/functions/6_settlement.rs +++ b/pallets/funding/src/functions/6_settlement.rs @@ -87,7 +87,7 @@ impl Pallet { pub fn do_settle_successful_evaluation(evaluation: EvaluationInfoOf, project_id: ProjectId) -> DispatchResult { let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectDetailsNotFound)?; - ensure!(matches!(project_details.funding_end_block, Some(_)), Error::::SettlementNotStarted); + ensure!(project_details.funding_end_block.is_some(), Error::::SettlementNotStarted); ensure!(matches!(project_details.status, ProjectStatus::FundingSuccessful), Error::::WrongSettlementOutcome); // Based on the results of the funding round, the evaluator is either: @@ -137,7 +137,7 @@ impl Pallet { pub fn do_settle_failed_evaluation(evaluation: EvaluationInfoOf, project_id: ProjectId) -> DispatchResult { let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectDetailsNotFound)?; - ensure!(matches!(project_details.funding_end_block, Some(_)), Error::::SettlementNotStarted); + ensure!(project_details.funding_end_block.is_some(), Error::::SettlementNotStarted); ensure!(matches!(project_details.status, ProjectStatus::FundingFailed), Error::::WrongSettlementOutcome); let bond = if matches!(project_details.evaluation_round_info.evaluators_outcome, EvaluatorsOutcome::Slashed) { @@ -171,7 +171,7 @@ impl Pallet { let project_metadata = ProjectsMetadata::::get(project_id).ok_or(Error::::ProjectMetadataNotFound)?; let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectDetailsNotFound)?; - ensure!(matches!(project_details.funding_end_block, Some(_)), Error::::SettlementNotStarted); + ensure!(project_details.funding_end_block.is_some(), Error::::SettlementNotStarted); ensure!(matches!(project_details.status, ProjectStatus::FundingSuccessful), Error::::WrongSettlementOutcome); ensure!( matches!(bid.status, BidStatus::Accepted | BidStatus::PartiallyAccepted(..)), @@ -234,7 +234,7 @@ impl Pallet { pub fn do_settle_failed_bid(bid: BidInfoOf, project_id: ProjectId) -> DispatchResult { let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectDetailsNotFound)?; - ensure!(matches!(project_details.funding_end_block, Some(_)), Error::::SettlementNotStarted); + ensure!(project_details.funding_end_block.is_some(), Error::::SettlementNotStarted); ensure!(matches!(project_details.status, ProjectStatus::FundingFailed), Error::::WrongSettlementOutcome); let bidder = bid.bidder; @@ -262,7 +262,7 @@ impl Pallet { // Ensure that: // 1. The project is in the FundingSuccessful state // 2. The contribution token exists - ensure!(matches!(project_details.funding_end_block, Some(_)), Error::::SettlementNotStarted); + ensure!(project_details.funding_end_block.is_some(), Error::::SettlementNotStarted); ensure!(matches!(project_details.status, ProjectStatus::FundingSuccessful), Error::::WrongSettlementOutcome); ensure!(T::ContributionTokenCurrency::asset_exists(project_id), Error::::TooEarlyForRound); @@ -321,7 +321,7 @@ impl Pallet { pub fn do_settle_failed_contribution(contribution: ContributionInfoOf, project_id: ProjectId) -> DispatchResult { let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectDetailsNotFound)?; - ensure!(matches!(project_details.funding_end_block, Some(_)), Error::::SettlementNotStarted); + ensure!(project_details.funding_end_block.is_some(), Error::::SettlementNotStarted); ensure!(matches!(project_details.status, ProjectStatus::FundingFailed), Error::::WrongSettlementOutcome); // Check if the bidder has a future deposit held @@ -373,7 +373,7 @@ impl Pallet { T::FundingCurrency::transfer( asset.to_assethub_id(), &project_pot, - &participant, + participant, amount, Preservation::Expendable, )?; @@ -388,7 +388,7 @@ impl Pallet { // Release the held PLMC bond T::NativeCurrency::release( &HoldReason::Participation(project_id).into(), - &participant, + participant, amount, Precision::Exact, )?; @@ -421,7 +421,7 @@ impl Pallet { evaluation: &EvaluationInfoOf, info: &RewardInfoOf, ) -> Result<(BalanceOf, BalanceOf), DispatchError> { - let reward = Self::calculate_evaluator_reward(evaluation, &info); + let reward = Self::calculate_evaluator_reward(evaluation, info); Self::mint_contribution_tokens(project_id, &evaluation.evaluator, reward)?; Ok((evaluation.current_plmc_bond, reward)) @@ -454,7 +454,7 @@ impl Pallet { ); let migration_origin = MigrationOrigin { user: multilocation_user, id, participation_type }; let vesting_time: u64 = vesting_time.try_into().map_err(|_| Error::::BadMath)?; - let migration_info: MigrationInfo = (ct_amount.into(), vesting_time.into()).into(); + let migration_info: MigrationInfo = (ct_amount.into(), vesting_time).into(); let migration = Migration::new(migration_origin, migration_info); if let Some((_, migrations)) = maybe_migrations { migrations.try_push(migration).map_err(|_| Error::::TooManyMigrations)?; diff --git a/pallets/funding/src/functions/misc.rs b/pallets/funding/src/functions/misc.rs index dcc8b86b2..aae5b1174 100644 --- a/pallets/funding/src/functions/misc.rs +++ b/pallets/funding/src/functions/misc.rs @@ -1,5 +1,4 @@ use super::*; -use itertools::Itertools; // Helper functions // ATTENTION: if this is called directly, it will not be transactional @@ -27,7 +26,7 @@ impl Pallet { return Ok(i); } } - return Err(T::MaxProjectsToUpdateInsertionAttempts::get()); + Err(T::MaxProjectsToUpdateInsertionAttempts::get()) } pub fn create_bucket_from_metadata(metadata: &ProjectMetadataOf) -> Result, DispatchError> { @@ -153,7 +152,7 @@ impl Pallet { let project_metadata = ProjectsMetadata::::get(project_id).ok_or(Error::::ProjectMetadataNotFound)?; let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectDetailsNotFound)?; // Rejected bids were deleted in the previous block. - let accepted_bids = Bids::::iter_prefix_values((project_id,)).collect_vec(); + let accepted_bids = Bids::::iter_prefix_values((project_id,)).collect::>(); let project_account = Self::fund_account_id(project_id); let plmc_price = T::PriceProvider::get_decimals_aware_price(PLMC_FOREIGN_ID, USD_DECIMALS, PLMC_DECIMALS) .ok_or(Error::::PriceNotFound)?; diff --git a/pallets/funding/src/instantiator/mod.rs b/pallets/funding/src/instantiator/mod.rs index 111062f2a..1b23f903d 100644 --- a/pallets/funding/src/instantiator/mod.rs +++ b/pallets/funding/src/instantiator/mod.rs @@ -35,8 +35,6 @@ use frame_system::pallet_prelude::BlockNumberFor; use itertools::Itertools; use parity_scale_codec::Decode; use polimec_common::{credentials::InvestorType, migration_types::MigrationOrigin}; -#[cfg(any(test, feature = "std", feature = "runtime-benchmarks"))] -use polimec_common_test_utils::generate_did_from_account; use sp_arithmetic::{ traits::{SaturatedConversion, Saturating, Zero}, FixedPointNumber, Percent, Perquintill, @@ -52,13 +50,20 @@ use sp_std::{ marker::PhantomData, }; +#[cfg(any(test, feature = "std", feature = "runtime-benchmarks"))] +use polimec_common_test_utils::generate_did_from_account; + #[cfg(any(feature = "std", feature = "runtime-benchmarks"))] pub mod macros; + pub mod types; pub use types::*; + pub mod traits; pub use traits::*; + #[cfg(any(feature = "std", feature = "runtime-benchmarks"))] pub mod calculations; + #[cfg(any(feature = "std", feature = "runtime-benchmarks"))] pub mod chain_interactions; diff --git a/pallets/funding/src/lib.rs b/pallets/funding/src/lib.rs index 4a67b0471..e258aa1d5 100644 --- a/pallets/funding/src/lib.rs +++ b/pallets/funding/src/lib.rs @@ -139,20 +139,24 @@ use sp_std::{marker::PhantomData, prelude::*}; pub use types::*; use xcm::v3::{opaque::Instruction, prelude::*, SendXcm}; -#[cfg(test)] -pub mod mock; +mod functions; pub mod storage_migrations; +pub mod traits; pub mod types; pub mod weights; +#[cfg(test)] +pub mod mock; + #[cfg(test)] pub mod tests; +// TODO: This is used only in tests. Should we use #[cfg(test)]? +// If we do that the integration-tests will complain about the missing `use` statement :( +pub mod instantiator; + #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; -mod functions; -pub mod instantiator; -pub mod traits; pub type AccountIdOf = ::AccountId; pub type ProjectId = u32; @@ -361,10 +365,6 @@ pub mod pallet { #[pallet::constant] type PalletId: Get; - /// The maximum size of a preimage allowed, expressed in bytes. - #[pallet::constant] - type PreImageLimit: Get; - /// Type that represents the value of something in USD type Price: FixedPointNumber + Parameter + Copy + MaxEncodedLen + MaybeSerializeDeserialize; @@ -404,7 +404,7 @@ pub mod pallet { + Into::RuntimeOrigin>>; /// test and benchmarking helper to set the prices of assets - #[cfg(any(feature = "runtime-benchmarks"))] + #[cfg(feature = "runtime-benchmarks")] type SetPrices: traits::SetPrices; /// The maximum length of data stored on-chain. diff --git a/pallets/funding/src/mock.rs b/pallets/funding/src/mock.rs index f18e835cc..5c0a08849 100644 --- a/pallets/funding/src/mock.rs +++ b/pallets/funding/src/mock.rs @@ -425,7 +425,6 @@ impl Config for TestRuntime { type Multiplier = Multiplier; type NativeCurrency = Balances; type PalletId = FundingPalletId; - type PreImageLimit = ConstU32<1024>; type Price = FixedU128; type PriceProvider = ConstPriceProvider; type Randomness = RandomnessCollectiveFlip; @@ -436,7 +435,7 @@ impl Config for TestRuntime { type RuntimeEvent = RuntimeEvent; type RuntimeHoldReason = RuntimeHoldReason; type RuntimeOrigin = RuntimeOrigin; - #[cfg(any(feature = "runtime-benchmarks"))] + #[cfg(feature = "runtime-benchmarks")] type SetPrices = (); type StringLimit = ConstU32<64>; type SuccessToSettlementTime = SuccessToSettlementTime; diff --git a/pallets/polimec-receiver/Cargo.toml b/pallets/polimec-receiver/Cargo.toml index aca3e8dee..d8fd00c08 100644 --- a/pallets/polimec-receiver/Cargo.toml +++ b/pallets/polimec-receiver/Cargo.toml @@ -47,6 +47,7 @@ runtime-benchmarks = [ ] std = [ "codec/std", + "cumulus-pallet-xcm/std", "frame-benchmarking/std", "frame-support/std", "frame-system/std", @@ -59,8 +60,10 @@ std = [ "sp-io/std", "sp-runtime/std", "sp-std/std", + "xcm/std", ] try-runtime = [ + "cumulus-pallet-xcm/try-runtime", "frame-support/try-runtime", "frame-system/try-runtime", "polimec-common/try-runtime", diff --git a/pallets/sandbox/src/mock.rs b/pallets/sandbox/src/mock.rs index 47fe3283d..d9c5b4884 100644 --- a/pallets/sandbox/src/mock.rs +++ b/pallets/sandbox/src/mock.rs @@ -184,7 +184,6 @@ // type Multiplier = (); // type NativeCurrency = Balances; // type PalletId = FundingPalletId; -// type PreImageLimit = ConstU32<1024>; // type Price = FixedU128; // type PriceProvider = (); // type ProjectIdentifier = Identifier; diff --git a/runtimes/polimec/Cargo.toml b/runtimes/polimec/Cargo.toml index 3c2414031..316d919eb 100644 --- a/runtimes/polimec/Cargo.toml +++ b/runtimes/polimec/Cargo.toml @@ -278,6 +278,4 @@ try-runtime = [ # to make it smaller, like logging for example. on-chain-release-build = [ "sp-api/disable-logging" ] -development-settings = [ - "shared-configuration/development-settings", -] +development-settings = [ "shared-configuration/development-settings" ] diff --git a/runtimes/polimec/src/lib.rs b/runtimes/polimec/src/lib.rs index f49035dc8..f25495240 100644 --- a/runtimes/polimec/src/lib.rs +++ b/runtimes/polimec/src/lib.rs @@ -1061,7 +1061,6 @@ impl pallet_funding::Config for Runtime { type Multiplier = pallet_funding::types::Multiplier; type NativeCurrency = Balances; type PalletId = FundingPalletId; - type PreImageLimit = ConstU32<1024>; type Price = Price; type PriceProvider = OraclePriceProvider; type Randomness = Random; @@ -1072,7 +1071,7 @@ impl pallet_funding::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeHoldReason = RuntimeHoldReason; type RuntimeOrigin = RuntimeOrigin; - #[cfg(any(feature = "runtime-benchmarks"))] + #[cfg(feature = "runtime-benchmarks")] type SetPrices = crate::benchmarks::helpers::SetOraclePrices; type StringLimit = ConstU32<64>; type SuccessToSettlementTime = SuccessToSettlementTime;