From 36269ce6788f4b34929ac368f7e91b743e702527 Mon Sep 17 00:00:00 2001 From: Just van Stam Date: Fri, 19 Jul 2024 13:24:04 +0200 Subject: [PATCH] fix most warnings --- pallets/funding/src/functions/2_evaluation.rs | 2 +- pallets/funding/src/functions/3_auction.rs | 15 +++-------- .../funding/src/functions/4_contribution.rs | 3 ++- .../funding/src/functions/5_funding_end.rs | 1 - pallets/funding/src/functions/misc.rs | 5 ++-- .../src/instantiator/chain_interactions.rs | 4 +-- pallets/funding/src/lib.rs | 25 +++---------------- pallets/funding/src/types.rs | 2 +- 8 files changed, 13 insertions(+), 44 deletions(-) diff --git a/pallets/funding/src/functions/2_evaluation.rs b/pallets/funding/src/functions/2_evaluation.rs index 9b7ee3d89..aeb8ea11b 100644 --- a/pallets/funding/src/functions/2_evaluation.rs +++ b/pallets/funding/src/functions/2_evaluation.rs @@ -73,7 +73,7 @@ impl Pallet { #[transactional] pub fn do_evaluation_end(project_id: ProjectId) -> DispatchResult { // * Get variables * - let mut project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectDetailsNotFound)?; + let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectDetailsNotFound)?; // * Calculate new variables * let usd_total_amount_bonded = project_details.evaluation_round_info.total_bonded_usd; diff --git a/pallets/funding/src/functions/3_auction.rs b/pallets/funding/src/functions/3_auction.rs index 398a8aa3c..a8f40f615 100644 --- a/pallets/funding/src/functions/3_auction.rs +++ b/pallets/funding/src/functions/3_auction.rs @@ -45,7 +45,7 @@ impl Pallet { #[transactional] pub fn do_end_auction(project_id: ProjectId) -> DispatchResultWithPostInfo { // * Get variables * - let mut project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectDetailsNotFound)?; + let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectDetailsNotFound)?; let project_metadata = ProjectsMetadata::::get(project_id).ok_or(Error::::ProjectMetadataNotFound)?; let bucket = Buckets::::get(project_id).ok_or(Error::::BucketNotFound)?; @@ -240,19 +240,10 @@ impl Pallet { ensure!(total_bids_by_bidder < T::MaxBidsPerUser::get(), Error::::TooManyUserParticipations); ensure!(total_bids_for_project < T::MaxBidsPerProject::get(), Error::::TooManyProjectParticipations); - let funding_asset_id = funding_asset.to_assethub_id(); - let funding_asset_decimals = T::FundingCurrency::decimals(funding_asset_id); - let funding_asset_usd_price = - T::PriceProvider::get_decimals_aware_price(funding_asset_id, USD_DECIMALS, funding_asset_decimals) - .ok_or(Error::::PriceNotFound)?; - // * Calculate new variables * let plmc_bond = Self::calculate_plmc_bond(ticket_size, multiplier).map_err(|_| Error::::BadMath)?; - - let funding_asset_amount_locked = - funding_asset_usd_price.reciprocal().ok_or(Error::::BadMath)?.saturating_mul_int(ticket_size); - let asset_id = funding_asset.to_assethub_id(); + let funding_asset_amount_locked = Self::calculate_funding_asset_amount(ticket_size, funding_asset)?; let new_bid = BidInfoOf:: { id: bid_id, @@ -272,7 +263,7 @@ impl Pallet { }; Self::try_plmc_participation_lock(bidder, project_id, plmc_bond)?; - Self::try_funding_asset_hold(bidder, project_id, funding_asset_amount_locked, asset_id)?; + Self::try_funding_asset_hold(bidder, project_id, funding_asset_amount_locked, funding_asset.to_assethub_id())?; Bids::::insert((project_id, bidder, bid_id), &new_bid); NextBidId::::set(bid_id.saturating_add(One::one())); diff --git a/pallets/funding/src/functions/4_contribution.rs b/pallets/funding/src/functions/4_contribution.rs index 6dd1c7b70..c71bb3309 100644 --- a/pallets/funding/src/functions/4_contribution.rs +++ b/pallets/funding/src/functions/4_contribution.rs @@ -24,7 +24,6 @@ impl Pallet { ) -> DispatchResultWithPostInfo { let mut project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectDetailsNotFound)?; let did_has_winning_bid = DidWithWinningBids::::get(project_id, did.clone()); - let round_start_block = project_details.round_duration.start().ok_or(Error::::ImpossibleState)?; let remainder_start = match project_details.status { ProjectStatus::CommunityRound(remainder_start) => remainder_start, @@ -33,7 +32,9 @@ impl Pallet { let now = >::block_number(); let remainder_started = now > remainder_start; + let round_end = project_details.round_duration.end().ok_or(Error::::ImpossibleState)?; ensure!(!did_has_winning_bid || remainder_started, Error::::UserHasWinningBid); + ensure!(now < round_end, Error::::TooLateForRound); let buyable_tokens = token_amount.min(project_details.remaining_contribution_tokens); project_details.remaining_contribution_tokens.saturating_reduce(buyable_tokens); diff --git a/pallets/funding/src/functions/5_funding_end.rs b/pallets/funding/src/functions/5_funding_end.rs index 5adb403cc..e4e47b8e2 100644 --- a/pallets/funding/src/functions/5_funding_end.rs +++ b/pallets/funding/src/functions/5_funding_end.rs @@ -34,7 +34,6 @@ impl Pallet { pub fn do_end_funding(project_id: ProjectId) -> DispatchResultWithPostInfo { // * Get variables * let mut project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectDetailsNotFound)?; - let project_metadata = ProjectsMetadata::::get(project_id).ok_or(Error::::ProjectMetadataNotFound)?; let remaining_cts = project_details.remaining_contribution_tokens; let round_end_block = project_details.round_duration.end().ok_or(Error::::ImpossibleState)?; let now = >::block_number(); diff --git a/pallets/funding/src/functions/misc.rs b/pallets/funding/src/functions/misc.rs index 5c57536cf..efeb321c6 100644 --- a/pallets/funding/src/functions/misc.rs +++ b/pallets/funding/src/functions/misc.rs @@ -113,7 +113,7 @@ impl Pallet { .partition(|bid| matches!(bid.status, BidStatus::Accepted | BidStatus::PartiallyAccepted(..))); let accepted_bid_len = accepted_bids.len() as u32; - let mut total_auction_allocation_usd: BalanceOf = accepted_bids.into_iter() + let total_auction_allocation_usd: BalanceOf = accepted_bids.into_iter() .try_fold(Zero::zero(), |acc: BalanceOf, bid: BidInfoOf| { bid.final_ct_usd_price.checked_mul_int(bid.final_ct_amount).and_then( |ticket| acc.checked_add(&ticket) @@ -131,7 +131,7 @@ impl Pallet { } })?; - Ok((accepted_bid_len, 0)) + Ok((accepted_bid_len, rejected_bids.len() as u32)) } @@ -193,7 +193,6 @@ impl Pallet { // Determine how much funding has been achieved. let funding_amount_reached = project_details.funding_amount_reached_usd; - let fundraising_target = project_details.fundraising_target_usd; let fee_usd = Self::compute_total_fee_from_brackets(funding_amount_reached); let fee_percentage = Perquintill::from_rational(fee_usd, funding_amount_reached); diff --git a/pallets/funding/src/instantiator/chain_interactions.rs b/pallets/funding/src/instantiator/chain_interactions.rs index 69a13e31c..b0cddb378 100644 --- a/pallets/funding/src/instantiator/chain_interactions.rs +++ b/pallets/funding/src/instantiator/chain_interactions.rs @@ -287,7 +287,6 @@ impl< &mut self, project_id: ProjectId, expected_metadata: ProjectMetadataOf, - creation_start_block: BlockNumberFor, ) { let metadata = self.get_project_metadata(project_id); let details = self.get_project_details(project_id); @@ -388,7 +387,6 @@ impl< } pub fn create_new_project(&mut self, project_metadata: ProjectMetadataOf, issuer: AccountIdOf) -> ProjectId { - let now = self.current_block(); // one ED for the issuer, one ED for the escrow account self.mint_plmc_to(vec![UserToPLMCBalance::new(issuer.clone(), self.get_ed() * 2u64.into())]); @@ -404,7 +402,7 @@ impl< }); let created_project_id = self.execute(|| NextProjectId::::get().saturating_sub(One::one())); - self.creation_assertions(created_project_id, project_metadata, now); + self.creation_assertions(created_project_id, project_metadata); created_project_id } diff --git a/pallets/funding/src/lib.rs b/pallets/funding/src/lib.rs index 98737a6c3..84f4c7087 100644 --- a/pallets/funding/src/lib.rs +++ b/pallets/funding/src/lib.rs @@ -712,10 +712,9 @@ pub mod pallet { IncorrectRound, /// Too early to execute the action. The action can likely be called again at a later stage. TooEarlyForRound, - /// A round transition was already executed, so the transition cannot be - /// executed again. This is likely to happen when the issuer manually transitions the project, - /// after which the automatic transition is executed. - RoundTransitionAlreadyHappened, + /// Too late to execute the action. Round has already ended, but transition to new + /// round has still to be executed. + TooLateForRound, /// A project's transition point (block number) was not set. TransitionPointNotSet, @@ -1184,24 +1183,6 @@ pub mod pallet { Self::do_mark_project_ct_migration_as_finished(project_id) } } - - fn update_weight(used_weight: &mut Weight, call: DispatchResultWithPostInfo, fallback_weight: Weight) { - match call { - Ok(post_dispatch_info) => - if let Some(actual_weight) = post_dispatch_info.actual_weight { - *used_weight = used_weight.saturating_add(actual_weight); - } else { - *used_weight = used_weight.saturating_add(fallback_weight); - }, - Err(DispatchErrorWithPostInfo:: { error: _error, post_info }) => { - if let Some(actual_weight) = post_info.actual_weight { - *used_weight = used_weight.saturating_add(actual_weight); - } else { - *used_weight = used_weight.saturating_add(fallback_weight); - } - }, - } - } } pub mod xcm_executor_impl { diff --git a/pallets/funding/src/types.rs b/pallets/funding/src/types.rs index 07e4531d8..eb65bbd9f 100644 --- a/pallets/funding/src/types.rs +++ b/pallets/funding/src/types.rs @@ -27,7 +27,7 @@ use polimec_common::USD_DECIMALS; use polkadot_parachain_primitives::primitives::Id as ParaId; use serde::{Deserialize, Serialize}; use sp_arithmetic::{FixedPointNumber, FixedPointOperand, Percent}; -use sp_runtime::traits::{CheckedDiv, CheckedMul, One, Saturating, Zero}; +use sp_runtime::traits::{CheckedDiv, CheckedMul, One}; use sp_std::{cmp::Eq, prelude::*}; pub use storage_types::*;