Skip to content

Commit

Permalink
Simplifications part 5
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Aug 5, 2024
1 parent b1d13b0 commit a498df9
Show file tree
Hide file tree
Showing 21 changed files with 11,767 additions and 11,982 deletions.
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 @@ -40,7 +40,7 @@ impl<T: Config> Pallet<T> {
evaluation_round_info: EvaluationRoundInfoOf::<T> {
total_bonded_usd: Zero::zero(),
total_bonded_plmc: Zero::zero(),
evaluators_outcome: EvaluatorsOutcome::Unchanged,
evaluators_outcome: None,
},
usd_bid_on_oversubscription: None,
funding_end_block: None,
Expand Down
11 changes: 6 additions & 5 deletions pallets/funding/src/functions/3_auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<T: Config> Pallet<T> {
project_id,
project_details,
ProjectStatus::AuctionInitializePeriod,
ProjectStatus::Auction,
ProjectStatus::AuctionRound,
T::AuctionOpeningDuration::get(),
skip_round_end_check,
)
Expand All @@ -45,7 +45,6 @@ impl<T: Config> Pallet<T> {
#[transactional]
pub fn do_end_auction(project_id: ProjectId) -> DispatchResultWithPostInfo {
// * Get variables *
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 All @@ -60,6 +59,8 @@ impl<T: Config> Pallet<T> {
project_metadata.auction_round_allocation_percentage * project_metadata.total_allocation_size,
weighted_token_price,
);
let updated_project_details =
ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;

match calculation_result {
Err(e) => return Err(DispatchErrorWithPostInfo { post_info: ().into(), error: e }),
Expand All @@ -68,8 +69,8 @@ impl<T: Config> Pallet<T> {
// * Transition Round *
Self::transition_project(
project_id,
project_details,
ProjectStatus::Auction,
updated_project_details,
ProjectStatus::AuctionRound,
ProjectStatus::CommunityRound(now.saturating_add(T::CommunityFundingDuration::get())),
T::CommunityFundingDuration::get() + T::RemainderFundingDuration::get(),
false,
Expand Down Expand Up @@ -151,7 +152,7 @@ impl<T: Config> Pallet<T> {

ensure!(ct_amount > Zero::zero(), Error::<T>::TooLow);
ensure!(did != project_details.issuer_did, Error::<T>::ParticipationToOwnProject);
ensure!(matches!(project_details.status, ProjectStatus::Auction), Error::<T>::IncorrectRound);
ensure!(matches!(project_details.status, ProjectStatus::AuctionRound), Error::<T>::IncorrectRound);
ensure!(
project_metadata.participation_currencies.contains(&funding_asset),
Error::<T>::FundingAssetNotAccepted
Expand Down
17 changes: 6 additions & 11 deletions pallets/funding/src/functions/5_funding_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,17 @@ impl<T: Config> Pallet<T> {

// * Update Storage *
DidWithActiveProjects::<T>::set(issuer_did, None);
let evaluator_outcome = match funding_ratio {
ratio if ratio <= Perquintill::from_percent(75u64) => EvaluatorsOutcome::Slashed,
ratio if ratio < Perquintill::from_percent(90u64) => EvaluatorsOutcome::Unchanged,
_ => {
let reward_info = Self::generate_evaluator_rewards_info(project_id)?;
EvaluatorsOutcome::Rewarded(reward_info)
},
};

project_details.evaluation_round_info.evaluators_outcome = evaluator_outcome;

let (next_status, duration, actual_weight) = if funding_ratio <= T::FundingSuccessThreshold::get() {
let (next_status, duration, actual_weight) = if funding_ratio < T::FundingSuccessThreshold::get() {
project_details.evaluation_round_info.evaluators_outcome = Some(EvaluatorsOutcome::Slashed);
(
ProjectStatus::FundingFailed,
1u32.into(),
WeightInfoOf::<T>::end_funding_automatically_rejected_evaluators_slashed(1),
)
} else {
let reward_info = Self::generate_evaluator_rewards_info(project_id)?;
project_details.evaluation_round_info.evaluators_outcome = Some(EvaluatorsOutcome::Rewarded(reward_info));
(
ProjectStatus::FundingSuccessful,
T::SuccessToSettlementTime::get(),
Expand All @@ -83,6 +76,8 @@ impl<T: Config> Pallet<T> {
let round_end = now.saturating_add(duration).saturating_sub(One::one());
project_details.round_duration.update(Some(now), Some(round_end));
project_details.status = next_status;
ProjectsDetails::<T>::insert(project_id, project_details.clone());
ProjectsDetails::<T>::insert(project_id, project_details);

Ok(PostDispatchInfo { actual_weight: Some(actual_weight), pays_fee: Pays::Yes })
}
Expand Down
Loading

0 comments on commit a498df9

Please sign in to comment.