Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬆️ 0.7.5 Release Polimec/Politest #315

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 97 additions & 1 deletion pallets/funding/src/storage_migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use frame_support::traits::StorageVersion;

/// The current storage version
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(3);
pub const LOG: &str = "runtime::funding::migration";

pub mod v2 {
Expand Down Expand Up @@ -152,3 +152,99 @@ pub mod v2 {
<T as frame_system::Config>::DbWeight,
>;
}

pub mod v3 {
use crate::{
AccountIdOf, BalanceOf, Config, EvaluationRoundInfoOf, HRMPChannelStatus, MigrationReadinessCheck,
PhaseTransitionPoints, PriceOf, ProjectDetailsOf, ProjectStatus,
};
use frame_support::{
pallet_prelude::Get,
traits::{tokens::Balance as BalanceT, OnRuntimeUpgrade},
};
use frame_system::pallet_prelude::BlockNumberFor;
use polimec_common::credentials::Did;
use polkadot_parachain_primitives::primitives::Id as ParaId;
use scale_info::TypeInfo;
use sp_arithmetic::FixedPointNumber;
use sp_core::{Decode, Encode, MaxEncodedLen, RuntimeDebug};
use sp_std::marker::PhantomData;

#[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: ProjectStatus,
/// 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,
/// 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,
}
type OldProjectDetailsOf<T> =
OldProjectDetails<AccountIdOf<T>, Did, BlockNumberFor<T>, PriceOf<T>, BalanceOf<T>, EvaluationRoundInfoOf<T>>;

pub struct UncheckedMigrationToV3<T: Config>(PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for UncheckedMigrationToV3<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;
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: item.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: None,
funding_end_block: item.funding_end_block,
parachain_id: item.parachain_id,
migration_readiness_check: item.migration_readiness_check,
hrmp_channel_status: item.hrmp_channel_status,
})
};

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

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

pub type MigrationToV3<T> = frame_support::migrations::VersionedMigration<
2,
3,
UncheckedMigrationToV3<T>,
crate::Pallet<T>,
<T as frame_system::Config>::DbWeight,
>;
}
7 changes: 4 additions & 3 deletions runtimes/polimec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,11 @@ pub type Migrations = migrations::Unreleased;
/// The runtime migrations per release.
#[allow(missing_docs)]
pub mod migrations {
use crate::{custom_migrations::init_pallet::InitializePallet, DmpQueue};
use crate::Runtime;

/// Unreleased migrations. Add new ones here:
#[allow(unused_parens)]
pub type Unreleased = (InitializePallet<DmpQueue>);
pub type Unreleased = (pallet_funding::storage_migrations::v3::MigrationToV3<Runtime>);
}

/// Executive: handles dispatch to the various modules.
Expand Down Expand Up @@ -206,7 +207,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("polimec-mainnet"),
impl_name: create_runtime_str!("polimec-mainnet"),
authoring_version: 1,
spec_version: 0_007_001,
spec_version: 0_007_002,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down
6 changes: 4 additions & 2 deletions runtimes/politest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ pub type Migrations = migrations::Unreleased;
/// The runtime migrations per release.
#[allow(missing_docs)]
pub mod migrations {
use crate::Runtime;

/// Unreleased migrations. Add new ones here:
pub type Unreleased = ();
pub type Unreleased = (pallet_funding::storage_migrations::v3::MigrationToV3<Runtime>);
}

/// Executive: handles dispatch to the various modules.
Expand Down Expand Up @@ -213,7 +215,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("politest"),
impl_name: create_runtime_str!("politest"),
authoring_version: 1,
spec_version: 0_007_004,
spec_version: 0_007_005,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down