Skip to content

Commit

Permalink
chore: cleanup (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
lrazovic committed Jul 8, 2024
1 parent 12c5ca9 commit dfd4507
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 82 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

10 changes: 3 additions & 7 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -138,7 +136,5 @@ std = [
"xcm-executor/std",
"xcm/std",
]
development-settings = [
"polimec-runtime/development-settings",
]
development-settings = [ "polimec-runtime/development-settings" ]

8 changes: 2 additions & 6 deletions nodes/parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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" ]
11 changes: 5 additions & 6 deletions pallets/funding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/functions/1_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<T: Config> Pallet<T> {
let maybe_active_project = DidWithActiveProjects::<T>::get(did.clone());

// * Validity checks *
ensure!(maybe_active_project == None, Error::<T>::HasActiveProject);
ensure!(maybe_active_project.is_none(), Error::<T>::HasActiveProject);

let (project_metadata, project_details, bucket) =
Self::project_validation(project_metadata, issuer.clone(), did.clone())?;
Expand Down
18 changes: 8 additions & 10 deletions pallets/funding/src/functions/2_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ impl<T: Config> Pallet<T> {
};

// * 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::<T>::end_evaluation_success(insertion_attempts)),
Expand All @@ -161,13 +162,10 @@ impl<T: Config> Pallet<T> {
};

// * 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::<T>::end_evaluation_failure(insertion_attempts)),
pays_fee: Pays::Yes,
Expand Down
11 changes: 5 additions & 6 deletions pallets/funding/src/functions/3_auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ impl<T: Config> Pallet<T> {
project_details.status = ProjectStatus::AuctionOpening;
ProjectsDetails::<T>::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 {
Expand Down
24 changes: 12 additions & 12 deletions pallets/funding/src/functions/5_funding_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,18 @@ impl<T: Config> Pallet<T> {
ensure!(project_details.status == ProjectStatus::AwaitingProjectDecision, Error::<T>::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::<T>::decide_project_outcome(iterations)),
pays_fee: Pays::Yes,
},
error: Error::<T>::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::<T>::decide_project_outcome(iterations)),
pays_fee: Pays::Yes,
},
error: Error::<T>::TooManyInsertionAttempts.into(),
}),
};

Self::deposit_event(Event::ProjectOutcomeDecided { project_id, decision });

Expand Down
20 changes: 10 additions & 10 deletions pallets/funding/src/functions/6_settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<T: Config> Pallet<T> {

pub fn do_settle_successful_evaluation(evaluation: EvaluationInfoOf<T>, project_id: ProjectId) -> DispatchResult {
let project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
ensure!(matches!(project_details.funding_end_block, Some(_)), Error::<T>::SettlementNotStarted);
ensure!(project_details.funding_end_block.is_some(), Error::<T>::SettlementNotStarted);
ensure!(matches!(project_details.status, ProjectStatus::FundingSuccessful), Error::<T>::WrongSettlementOutcome);

// Based on the results of the funding round, the evaluator is either:
Expand Down Expand Up @@ -137,7 +137,7 @@ impl<T: Config> Pallet<T> {

pub fn do_settle_failed_evaluation(evaluation: EvaluationInfoOf<T>, project_id: ProjectId) -> DispatchResult {
let project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
ensure!(matches!(project_details.funding_end_block, Some(_)), Error::<T>::SettlementNotStarted);
ensure!(project_details.funding_end_block.is_some(), Error::<T>::SettlementNotStarted);
ensure!(matches!(project_details.status, ProjectStatus::FundingFailed), Error::<T>::WrongSettlementOutcome);

let bond = if matches!(project_details.evaluation_round_info.evaluators_outcome, EvaluatorsOutcome::Slashed) {
Expand Down Expand Up @@ -171,7 +171,7 @@ impl<T: Config> Pallet<T> {
let project_metadata = ProjectsMetadata::<T>::get(project_id).ok_or(Error::<T>::ProjectMetadataNotFound)?;
let project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;

ensure!(matches!(project_details.funding_end_block, Some(_)), Error::<T>::SettlementNotStarted);
ensure!(project_details.funding_end_block.is_some(), Error::<T>::SettlementNotStarted);
ensure!(matches!(project_details.status, ProjectStatus::FundingSuccessful), Error::<T>::WrongSettlementOutcome);
ensure!(
matches!(bid.status, BidStatus::Accepted | BidStatus::PartiallyAccepted(..)),
Expand Down Expand Up @@ -234,7 +234,7 @@ impl<T: Config> Pallet<T> {

pub fn do_settle_failed_bid(bid: BidInfoOf<T>, project_id: ProjectId) -> DispatchResult {
let project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
ensure!(matches!(project_details.funding_end_block, Some(_)), Error::<T>::SettlementNotStarted);
ensure!(project_details.funding_end_block.is_some(), Error::<T>::SettlementNotStarted);
ensure!(matches!(project_details.status, ProjectStatus::FundingFailed), Error::<T>::WrongSettlementOutcome);

let bidder = bid.bidder;
Expand Down Expand Up @@ -262,7 +262,7 @@ impl<T: Config> Pallet<T> {
// Ensure that:
// 1. The project is in the FundingSuccessful state
// 2. The contribution token exists
ensure!(matches!(project_details.funding_end_block, Some(_)), Error::<T>::SettlementNotStarted);
ensure!(project_details.funding_end_block.is_some(), Error::<T>::SettlementNotStarted);
ensure!(matches!(project_details.status, ProjectStatus::FundingSuccessful), Error::<T>::WrongSettlementOutcome);
ensure!(T::ContributionTokenCurrency::asset_exists(project_id), Error::<T>::TooEarlyForRound);

Expand Down Expand Up @@ -321,7 +321,7 @@ impl<T: Config> Pallet<T> {

pub fn do_settle_failed_contribution(contribution: ContributionInfoOf<T>, project_id: ProjectId) -> DispatchResult {
let project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
ensure!(matches!(project_details.funding_end_block, Some(_)), Error::<T>::SettlementNotStarted);
ensure!(project_details.funding_end_block.is_some(), Error::<T>::SettlementNotStarted);
ensure!(matches!(project_details.status, ProjectStatus::FundingFailed), Error::<T>::WrongSettlementOutcome);

// Check if the bidder has a future deposit held
Expand Down Expand Up @@ -373,7 +373,7 @@ impl<T: Config> Pallet<T> {
T::FundingCurrency::transfer(
asset.to_assethub_id(),
&project_pot,
&participant,
participant,
amount,
Preservation::Expendable,
)?;
Expand All @@ -388,7 +388,7 @@ impl<T: Config> Pallet<T> {
// Release the held PLMC bond
T::NativeCurrency::release(
&HoldReason::Participation(project_id).into(),
&participant,
participant,
amount,
Precision::Exact,
)?;
Expand Down Expand Up @@ -421,7 +421,7 @@ impl<T: Config> Pallet<T> {
evaluation: &EvaluationInfoOf<T>,
info: &RewardInfoOf<T>,
) -> Result<(BalanceOf<T>, BalanceOf<T>), 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))
Expand Down Expand Up @@ -454,7 +454,7 @@ impl<T: Config> Pallet<T> {
);
let migration_origin = MigrationOrigin { user: multilocation_user, id, participation_type };
let vesting_time: u64 = vesting_time.try_into().map_err(|_| Error::<T>::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::<T>::TooManyMigrations)?;
Expand Down
5 changes: 2 additions & 3 deletions pallets/funding/src/functions/misc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::*;
use itertools::Itertools;

// Helper functions
// ATTENTION: if this is called directly, it will not be transactional
Expand Down Expand Up @@ -27,7 +26,7 @@ impl<T: Config> Pallet<T> {
return Ok(i);
}
}
return Err(T::MaxProjectsToUpdateInsertionAttempts::get());
Err(T::MaxProjectsToUpdateInsertionAttempts::get())
}

pub fn create_bucket_from_metadata(metadata: &ProjectMetadataOf<T>) -> Result<BucketOf<T>, DispatchError> {
Expand Down Expand Up @@ -153,7 +152,7 @@ impl<T: Config> Pallet<T> {
let project_metadata = ProjectsMetadata::<T>::get(project_id).ok_or(Error::<T>::ProjectMetadataNotFound)?;
let project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
// Rejected bids were deleted in the previous block.
let accepted_bids = Bids::<T>::iter_prefix_values((project_id,)).collect_vec();
let accepted_bids = Bids::<T>::iter_prefix_values((project_id,)).collect::<Vec<_>>();
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::<T>::PriceNotFound)?;
Expand Down
9 changes: 7 additions & 2 deletions pallets/funding/src/instantiator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
20 changes: 10 additions & 10 deletions pallets/funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = <T as frame_system::Config>::AccountId;
pub type ProjectId = u32;
Expand Down Expand Up @@ -361,10 +365,6 @@ pub mod pallet {
#[pallet::constant]
type PalletId: Get<PalletId>;

/// The maximum size of a preimage allowed, expressed in bytes.
#[pallet::constant]
type PreImageLimit: Get<u32>;

/// Type that represents the value of something in USD
type Price: FixedPointNumber + Parameter + Copy + MaxEncodedLen + MaybeSerializeDeserialize;

Expand Down Expand Up @@ -404,7 +404,7 @@ pub mod pallet {
+ Into<Result<pallet_xcm::Origin, <Self as Config>::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.
Expand Down
3 changes: 1 addition & 2 deletions pallets/funding/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading

0 comments on commit dfd4507

Please sign in to comment.