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 c590033 commit 8151325
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 688 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
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,
// >;
// }
Loading

0 comments on commit 8151325

Please sign in to comment.