Skip to content

Commit

Permalink
fix most warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vstam1 committed Jul 19, 2024
1 parent a00641a commit 36269ce
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 44 deletions.
2 changes: 1 addition & 1 deletion pallets/funding/src/functions/2_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<T: Config> Pallet<T> {
#[transactional]
pub fn do_evaluation_end(project_id: ProjectId) -> DispatchResult {
// * Get variables *
let mut project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
let project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;

// * Calculate new variables *
let usd_total_amount_bonded = project_details.evaluation_round_info.total_bonded_usd;
Expand Down
15 changes: 3 additions & 12 deletions pallets/funding/src/functions/3_auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<T: Config> Pallet<T> {
#[transactional]
pub fn do_end_auction(project_id: ProjectId) -> DispatchResultWithPostInfo {
// * Get variables *
let mut project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
let project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
let project_metadata = ProjectsMetadata::<T>::get(project_id).ok_or(Error::<T>::ProjectMetadataNotFound)?;
let bucket = Buckets::<T>::get(project_id).ok_or(Error::<T>::BucketNotFound)?;

Expand Down Expand Up @@ -240,19 +240,10 @@ impl<T: Config> Pallet<T> {
ensure!(total_bids_by_bidder < T::MaxBidsPerUser::get(), Error::<T>::TooManyUserParticipations);
ensure!(total_bids_for_project < T::MaxBidsPerProject::get(), Error::<T>::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::<T>::PriceNotFound)?;

// * Calculate new variables *
let plmc_bond =
Self::calculate_plmc_bond(ticket_size, multiplier).map_err(|_| Error::<T>::BadMath)?;

let funding_asset_amount_locked =
funding_asset_usd_price.reciprocal().ok_or(Error::<T>::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::<T> {
id: bid_id,
Expand All @@ -272,7 +263,7 @@ impl<T: Config> Pallet<T> {
};

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::<T>::insert((project_id, bidder, bid_id), &new_bid);
NextBidId::<T>::set(bid_id.saturating_add(One::one()));
Expand Down
3 changes: 2 additions & 1 deletion pallets/funding/src/functions/4_contribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ impl<T: Config> Pallet<T> {
) -> DispatchResultWithPostInfo {
let mut project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
let did_has_winning_bid = DidWithWinningBids::<T>::get(project_id, did.clone());
let round_start_block = project_details.round_duration.start().ok_or(Error::<T>::ImpossibleState)?;

let remainder_start = match project_details.status {
ProjectStatus::CommunityRound(remainder_start) => remainder_start,
Expand All @@ -33,7 +32,9 @@ impl<T: Config> Pallet<T> {

let now = <frame_system::Pallet<T>>::block_number();
let remainder_started = now > remainder_start;
let round_end = project_details.round_duration.end().ok_or(Error::<T>::ImpossibleState)?;
ensure!(!did_has_winning_bid || remainder_started, Error::<T>::UserHasWinningBid);
ensure!(now < round_end, Error::<T>::TooLateForRound);

let buyable_tokens = token_amount.min(project_details.remaining_contribution_tokens);
project_details.remaining_contribution_tokens.saturating_reduce(buyable_tokens);
Expand Down
1 change: 0 additions & 1 deletion pallets/funding/src/functions/5_funding_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ impl<T: Config> Pallet<T> {
pub fn do_end_funding(project_id: ProjectId) -> DispatchResultWithPostInfo {
// * Get variables *
let mut project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
let project_metadata = ProjectsMetadata::<T>::get(project_id).ok_or(Error::<T>::ProjectMetadataNotFound)?;
let remaining_cts = project_details.remaining_contribution_tokens;
let round_end_block = project_details.round_duration.end().ok_or(Error::<T>::ImpossibleState)?;
let now = <frame_system::Pallet<T>>::block_number();
Expand Down
5 changes: 2 additions & 3 deletions pallets/funding/src/functions/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<T: Config> Pallet<T> {
.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<T> = accepted_bids.into_iter()
let total_auction_allocation_usd: BalanceOf<T> = accepted_bids.into_iter()
.try_fold(Zero::zero(), |acc: BalanceOf<T>, bid: BidInfoOf<T>| {
bid.final_ct_usd_price.checked_mul_int(bid.final_ct_amount).and_then(
|ticket| acc.checked_add(&ticket)
Expand All @@ -131,7 +131,7 @@ impl<T: Config> Pallet<T> {
}
})?;

Ok((accepted_bid_len, 0))
Ok((accepted_bid_len, rejected_bids.len() as u32))
}


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

// 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);

Expand Down
4 changes: 1 addition & 3 deletions pallets/funding/src/instantiator/chain_interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ impl<
&mut self,
project_id: ProjectId,
expected_metadata: ProjectMetadataOf<T>,
creation_start_block: BlockNumberFor<T>,
) {
let metadata = self.get_project_metadata(project_id);
let details = self.get_project_details(project_id);
Expand Down Expand Up @@ -388,7 +387,6 @@ impl<
}

pub fn create_new_project(&mut self, project_metadata: ProjectMetadataOf<T>, issuer: AccountIdOf<T>) -> 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())]);

Expand All @@ -404,7 +402,7 @@ impl<
});

let created_project_id = self.execute(|| NextProjectId::<T>::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
}

Expand Down
25 changes: 3 additions & 22 deletions pallets/funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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::<PostDispatchInfo> { 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 {
Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down

0 comments on commit 36269ce

Please sign in to comment.