Skip to content

Commit

Permalink
simplifications part 4
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Jul 22, 2024
1 parent 67bf472 commit 5d4ca77
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 702 deletions.
23 changes: 0 additions & 23 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions pallets/funding/src/functions/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,7 @@ impl<T: Config> Pallet<T> {
// * Update storage *
ProjectsDetails::<T>::insert(project_id, project_details);

// TODO: FIX event transmition by either doing it outside function or map ProjectStatus
// -> ProjectPhase
// * Emit events *
// // * Emit events *
// Self::deposit_event(Event::ProjectPhaseTransition { project_id, phase: next_round });

Ok(())
Expand Down
18 changes: 6 additions & 12 deletions pallets/funding/src/instantiator/chain_interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl<
});

let created_project_id = self.execute(|| NextProjectId::<T>::get().saturating_sub(One::one()));
self.creation_assertions(created_project_id, maybe_did, project_metadata, now);
self.creation_assertions(created_project_id, maybe_did, project_metadata);
created_project_id
}

Expand Down Expand Up @@ -692,13 +692,7 @@ impl<
matches!(project_details.status, ProjectStatus::FundingSuccessful | ProjectStatus::FundingFailed),
"Project should be in Finished status"
);
if project_details.status == ProjectStatus::AwaitingProjectDecision {
if let Some(decision) = force_decision {
self.execute(|| {
crate::Pallet::<T>::do_project_decision(project_id, decision).unwrap();
});
}
}

Ok(())
}

Expand Down Expand Up @@ -1162,10 +1156,10 @@ impl<
remainder_contributions,
),
ProjectStatus::CommunityRound(..) =>
self.create_community_contributing_project(project_metadata, issuer, evaluations, bids),
ProjectStatus::Auction => self.create_auctioning_project(project_metadata, issuer, evaluations),
ProjectStatus::EvaluationRound => self.create_evaluating_project(project_metadata, issuer),
ProjectStatus::Application => self.create_new_project(project_metadata, issuer),
self.create_community_contributing_project(project_metadata, issuer, None, evaluations, bids),
ProjectStatus::Auction => self.create_auctioning_project(project_metadata, issuer, None, evaluations),
ProjectStatus::EvaluationRound => self.create_evaluating_project(project_metadata, issuer, None),
ProjectStatus::Application => self.create_new_project(project_metadata, issuer, None),
_ => panic!("unsupported project creation in that status"),
}
}
Expand Down
296 changes: 148 additions & 148 deletions pallets/funding/src/storage_migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,151 +9,151 @@ use serde::{Deserialize, Serialize};
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);
pub const LOG: &str = "runtime::funding::migration";
use frame_support::traits::OnRuntimeUpgrade;

pub mod v3tov4 {
use super::*;
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
pub struct OldProjectDetails<
AccountId,
Did,
BlockNumber,
Price: FixedPointNumber,
Balance: BalanceT,
EvaluationRoundInfo,
> {
pub issuer_account: AccountId,
pub issuer_did: Did,
/// Whether the project is frozen, so no `metadata` changes are allowed.
pub is_frozen: bool,
/// The price in USD per token decided after the Auction Round
pub weighted_average_price: Option<Price>,
/// The current status of the project
pub status: OldProjectStatus,
/// When the different project phases start and end
pub phase_transition_points: PhaseTransitionPoints<BlockNumber>,
/// Fundraising target amount in USD (6 decimals)
pub fundraising_target_usd: Balance,
/// The amount of Contribution Tokens that have not yet been sold
pub remaining_contribution_tokens: Balance,
/// Funding reached amount in USD (6 decimals)
pub funding_amount_reached_usd: Balance,
/// Information about the total amount bonded, and the outcome in regards to reward/slash/nothing
pub evaluation_round_info: EvaluationRoundInfo,
/// If the auction was oversubscribed, how much USD was raised across all winning bids
pub usd_bid_on_oversubscription: Option<Balance>,
/// When the Funding Round ends
pub funding_end_block: Option<BlockNumber>,
/// ParaId of project
pub parachain_id: Option<ParaId>,
/// Migration readiness check
pub migration_readiness_check: Option<MigrationReadinessCheck>,
/// HRMP Channel status
pub hrmp_channel_status: HRMPChannelStatus,
}

#[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct MigrationReadinessCheck {
pub holding_check: (xcm::v3::QueryId, CheckOutcome),
pub pallet_check: (xcm::v3::QueryId, CheckOutcome),
}

impl MigrationReadinessCheck {
pub fn is_ready(&self) -> bool {
self.holding_check.1 == CheckOutcome::Passed(None) &&
matches!(self.pallet_check.1, CheckOutcome::Passed(Some(_)))
}
}

pub type PalletIndex = u8;
#[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub enum CheckOutcome {
AwaitingResponse,
Passed(Option<PalletIndex>),
Failed,
}

#[derive(
Default, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen, Serialize, Deserialize,
)]
pub enum OldProjectStatus {
#[default]
Application,
EvaluationRound,
AuctionInitializePeriod,
AuctionOpening,
AuctionClosing,
CalculatingWAP,
CommunityRound,
RemainderRound,
FundingFailed,
AwaitingProjectDecision,
FundingSuccessful,
ReadyToStartMigration,
MigrationCompleted,
}

type OldProjectDetailsOf<T> =
OldProjectDetails<AccountIdOf<T>, Did, BlockNumberFor<T>, PriceOf<T>, BalanceOf<T>, EvaluationRoundInfoOf<T>>;

pub struct UncheckedMigrationToV4<T: Config>(PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for UncheckedMigrationToV4<T> {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
let mut items = 0;
let mut translate = |_key, item: OldProjectDetailsOf<T>| -> Option<ProjectDetailsOf<T>> {
items += 1;
let new_status = match item.status {
OldProjectStatus::Application => ProjectStatus::Application,
OldProjectStatus::EvaluationRound => ProjectStatus::EvaluationRound,
OldProjectStatus::AuctionInitializePeriod => ProjectStatus::AuctionInitializePeriod,
OldProjectStatus::AuctionOpening => ProjectStatus::AuctionOpening,
OldProjectStatus::AuctionClosing => ProjectStatus::AuctionClosing,
OldProjectStatus::CalculatingWAP => ProjectStatus::CalculatingWAP,
OldProjectStatus::CommunityRound => ProjectStatus::CommunityRound,
OldProjectStatus::RemainderRound => ProjectStatus::RemainderRound,
OldProjectStatus::FundingFailed => ProjectStatus::FundingFailed,
OldProjectStatus::AwaitingProjectDecision => ProjectStatus::AwaitingProjectDecision,
OldProjectStatus::FundingSuccessful => {
debug_assert!(item.funding_end_block.is_none(), "Settlement shouldn't have started yet");
ProjectStatus::FundingSuccessful
},

OldProjectStatus::ReadyToStartMigration => {
debug_assert!(false, "No project should be in this state when upgrading to v4");
ProjectStatus::CTMigrationStarted
},
OldProjectStatus::MigrationCompleted => {
debug_assert!(false, "No project should be in this state when upgrading to v4");
ProjectStatus::CTMigrationFinished
},
};
Some(ProjectDetailsOf::<T> {
issuer_account: item.issuer_account,
issuer_did: item.issuer_did,
is_frozen: item.is_frozen,
weighted_average_price: item.weighted_average_price,
status: new_status,
phase_transition_points: item.phase_transition_points,
fundraising_target_usd: item.fundraising_target_usd,
remaining_contribution_tokens: item.remaining_contribution_tokens,
funding_amount_reached_usd: item.funding_amount_reached_usd,
evaluation_round_info: item.evaluation_round_info,
usd_bid_on_oversubscription: item.usd_bid_on_oversubscription,
funding_end_block: item.funding_end_block,
migration_type: None,
})
};

crate::ProjectsDetails::<T>::translate(|key, object: OldProjectDetailsOf<T>| translate(key, object));

T::DbWeight::get().reads_writes(items, items)
}
}

pub type MigrationToV4<T> = frame_support::migrations::VersionedMigration<
3,
4,
UncheckedMigrationToV4<T>,
crate::Pallet<T>,
<T as frame_system::Config>::DbWeight,
>;
}
//
// pub mod v3tov4 {
// use super::*;
// #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
// pub struct OldProjectDetails<
// AccountId,
// Did,
// BlockNumber,
// Price: FixedPointNumber,
// Balance: BalanceT,
// EvaluationRoundInfo,
// > {
// pub issuer_account: AccountId,
// pub issuer_did: Did,
// /// Whether the project is frozen, so no `metadata` changes are allowed.
// pub is_frozen: bool,
// /// The price in USD per token decided after the Auction Round
// pub weighted_average_price: Option<Price>,
// /// The current status of the project
// pub status: OldProjectStatus,
// /// When the different project phases start and end
// pub phase_transition_points: PhaseTransitionPoints<BlockNumber>,
// /// Fundraising target amount in USD (6 decimals)
// pub fundraising_target_usd: Balance,
// /// The amount of Contribution Tokens that have not yet been sold
// pub remaining_contribution_tokens: Balance,
// /// Funding reached amount in USD (6 decimals)
// pub funding_amount_reached_usd: Balance,
// /// Information about the total amount bonded, and the outcome in regards to reward/slash/nothing
// pub evaluation_round_info: EvaluationRoundInfo,
// /// If the auction was oversubscribed, how much USD was raised across all winning bids
// pub usd_bid_on_oversubscription: Option<Balance>,
// /// When the Funding Round ends
// pub funding_end_block: Option<BlockNumber>,
// /// ParaId of project
// pub parachain_id: Option<ParaId>,
// /// Migration readiness check
// pub migration_readiness_check: Option<MigrationReadinessCheck>,
// /// HRMP Channel status
// pub hrmp_channel_status: HRMPChannelStatus,
// }
//
// #[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
// pub struct MigrationReadinessCheck {
// pub holding_check: (xcm::v3::QueryId, CheckOutcome),
// pub pallet_check: (xcm::v3::QueryId, CheckOutcome),
// }
//
// impl MigrationReadinessCheck {
// pub fn is_ready(&self) -> bool {
// self.holding_check.1 == CheckOutcome::Passed(None) &&
// matches!(self.pallet_check.1, CheckOutcome::Passed(Some(_)))
// }
// }
//
// pub type PalletIndex = u8;
// #[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
// pub enum CheckOutcome {
// AwaitingResponse,
// Passed(Option<PalletIndex>),
// Failed,
// }
//
// #[derive(
// Default, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen, Serialize, Deserialize,
// )]
// pub enum OldProjectStatus {
// #[default]
// Application,
// EvaluationRound,
// AuctionInitializePeriod,
// AuctionOpening,
// AuctionClosing,
// CalculatingWAP,
// CommunityRound,
// RemainderRound,
// FundingFailed,
// AwaitingProjectDecision,
// FundingSuccessful,
// ReadyToStartMigration,
// MigrationCompleted,
// }
//
// type OldProjectDetailsOf<T> =
// OldProjectDetails<AccountIdOf<T>, Did, BlockNumberFor<T>, PriceOf<T>, BalanceOf<T>, EvaluationRoundInfoOf<T>>;
//
// pub struct UncheckedMigrationToV4<T: Config>(PhantomData<T>);
// impl<T: Config> OnRuntimeUpgrade for UncheckedMigrationToV4<T> {
// fn on_runtime_upgrade() -> frame_support::weights::Weight {
// let mut items = 0;
// let mut translate = |_key, item: OldProjectDetailsOf<T>| -> Option<ProjectDetailsOf<T>> {
// items += 1;
// let new_status = match item.status {
// OldProjectStatus::Application => ProjectStatus::Application,
// OldProjectStatus::EvaluationRound => ProjectStatus::EvaluationRound,
// OldProjectStatus::AuctionInitializePeriod => ProjectStatus::AuctionInitializePeriod,
// OldProjectStatus::AuctionOpening => ProjectStatus::AuctionOpening,
// OldProjectStatus::AuctionClosing => ProjectStatus::AuctionClosing,
// OldProjectStatus::CalculatingWAP => ProjectStatus::CalculatingWAP,
// OldProjectStatus::CommunityRound => ProjectStatus::CommunityRound,
// OldProjectStatus::RemainderRound => ProjectStatus::RemainderRound,
// OldProjectStatus::FundingFailed => ProjectStatus::FundingFailed,
// OldProjectStatus::AwaitingProjectDecision => ProjectStatus::AwaitingProjectDecision,
// OldProjectStatus::FundingSuccessful => {
// debug_assert!(item.funding_end_block.is_none(), "Settlement shouldn't have started yet");
// ProjectStatus::FundingSuccessful
// },
//
// OldProjectStatus::ReadyToStartMigration => {
// debug_assert!(false, "No project should be in this state when upgrading to v4");
// ProjectStatus::CTMigrationStarted
// },
// OldProjectStatus::MigrationCompleted => {
// debug_assert!(false, "No project should be in this state when upgrading to v4");
// ProjectStatus::CTMigrationFinished
// },
// };
// Some(ProjectDetailsOf::<T> {
// issuer_account: item.issuer_account,
// issuer_did: item.issuer_did,
// is_frozen: item.is_frozen,
// weighted_average_price: item.weighted_average_price,
// status: new_status,
// phase_transition_points: item.phase_transition_points,
// fundraising_target_usd: item.fundraising_target_usd,
// remaining_contribution_tokens: item.remaining_contribution_tokens,
// funding_amount_reached_usd: item.funding_amount_reached_usd,
// evaluation_round_info: item.evaluation_round_info,
// usd_bid_on_oversubscription: item.usd_bid_on_oversubscription,
// funding_end_block: item.funding_end_block,
// migration_type: None,
// })
// };
//
// crate::ProjectsDetails::<T>::translate(|key, object: OldProjectDetailsOf<T>| translate(key, object));
//
// T::DbWeight::get().reads_writes(items, items)
// }
// }
//
// pub type MigrationToV4<T> = frame_support::migrations::VersionedMigration<
// 3,
// 4,
// UncheckedMigrationToV4<T>,
// crate::Pallet<T>,
// <T as frame_system::Config>::DbWeight,
// >;
// }
2 changes: 1 addition & 1 deletion pallets/funding/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ pub fn create_finished_project_with_usd_raised(
inst.mint_foreign_asset_to(usdt_required);
inst.contribute_for_users(project_id, community_contributions).unwrap();
inst.start_remainder_or_end_funding(project_id).unwrap();
if inst.get_project_details(project_id).status == ProjectStatus::RemainderRound {
if matches!(inst.get_project_details(project_id).status, ProjectStatus::CommunityRound(_)) {
inst.finish_funding(project_id, Some(FundingOutcomeDecision::AcceptFunding)).unwrap();
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/tests/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ fn all_project_participations_by_did() {
let jwt =
get_mock_jwt_with_cid(contribution.contributor, InvestorType::Professional, did_user.clone(), cid.clone());
inst.execute(|| {
PolimecFunding::remaining_contribute(
PolimecFunding::contribute(
RuntimeOrigin::signed(contribution.contributor),
jwt,
project_id,
Expand Down
Loading

0 comments on commit 5d4ca77

Please sign in to comment.