diff --git a/Cargo.lock b/Cargo.lock index 2faa3e1d6..225f471a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7493,29 +7493,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-sandbox" -version = "0.1.0" -dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", - "pallet-assets", - "pallet-balances", - "pallet-funding", - "pallet-insecure-randomness-collective-flip", - "parachains-common", - "parity-scale-codec", - "polimec-common", - "scale-info", - "serde", - "sp-arithmetic", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", -] - [[package]] name = "pallet-scheduler" version = "29.0.0" diff --git a/pallets/funding/src/functions/3_auction.rs b/pallets/funding/src/functions/3_auction.rs index aa11a91f7..f203a6573 100644 --- a/pallets/funding/src/functions/3_auction.rs +++ b/pallets/funding/src/functions/3_auction.rs @@ -45,6 +45,7 @@ impl Pallet { #[transactional] pub fn do_end_auction(project_id: ProjectId) -> DispatchResultWithPostInfo { // * Get variables * + let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectDetailsNotFound)?; let project_metadata = ProjectsMetadata::::get(project_id).ok_or(Error::::ProjectMetadataNotFound)?; let bucket = Buckets::::get(project_id).ok_or(Error::::BucketNotFound)?; diff --git a/pallets/funding/src/functions/6_settlement.rs b/pallets/funding/src/functions/6_settlement.rs index 40007143f..253393e2f 100644 --- a/pallets/funding/src/functions/6_settlement.rs +++ b/pallets/funding/src/functions/6_settlement.rs @@ -4,9 +4,9 @@ use frame_support::{ dispatch::DispatchResult, ensure, traits::{ - fungible::MutateHold as FungibleMutateHold, + fungible::{Inspect, MutateHold as FungibleMutateHold}, fungibles::Mutate as FungiblesMutate, - tokens::{Fortitude, Precision, Preservation, Restriction}, + tokens::{DepositConsequence, Fortitude, Precision, Preservation, Provenance, Restriction}, Get, }, }; @@ -261,8 +261,8 @@ impl Pallet { let new_plmc_bond = Self::calculate_plmc_bond(new_ticket_size, bid.multiplier)?; let new_funding_asset_amount = Self::calculate_funding_asset_amount(new_ticket_size, bid.funding_asset)?; - let refund_plmc = bid.plmc_bond.saturating_sub(new_plmc_bond); - let refund_funding_asset = bid.funding_asset_amount_locked.saturating_sub(new_funding_asset_amount); + let mut refund_plmc = bid.plmc_bond.saturating_sub(new_plmc_bond); + let mut refund_funding_asset = bid.funding_asset_amount_locked.saturating_sub(new_funding_asset_amount); if T::FundingCurrency::can_deposit( bid.funding_asset.to_assethub_id(), &bid.bidder, diff --git a/pallets/funding/src/functions/misc.rs b/pallets/funding/src/functions/misc.rs index 7c5df2075..fb2138c5e 100644 --- a/pallets/funding/src/functions/misc.rs +++ b/pallets/funding/src/functions/misc.rs @@ -410,9 +410,7 @@ impl Pallet { // * Update storage * ProjectsDetails::::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(()) diff --git a/pallets/funding/src/instantiator/chain_interactions.rs b/pallets/funding/src/instantiator/chain_interactions.rs index 567de7f06..8fb2e8437 100644 --- a/pallets/funding/src/instantiator/chain_interactions.rs +++ b/pallets/funding/src/instantiator/chain_interactions.rs @@ -384,7 +384,7 @@ impl< self.execute(|| ProjectsDetails::::get(project_id).expect("Project details exists")) } - pub fn get_update_block(&mut self, project_id: ProjectId, update_type: &UpdateType) -> Option> { + pub fn get_update_block(&mut self, _project_id: ProjectId, _update_type: &UpdateType) -> Option> { Some(BlockNumberFor::::zero()) // TODO: FIX } @@ -395,7 +395,6 @@ impl< issuer: AccountIdOf, maybe_did: Option, ) -> 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())]); @@ -408,7 +407,7 @@ impl< }); let created_project_id = self.execute(|| NextProjectId::::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 } @@ -677,7 +676,7 @@ impl< pub fn finish_funding( &mut self, project_id: ProjectId, - force_decision: Option, + _force_decision: Option, ) -> Result<(), DispatchError> { if let Some(update_block) = self.get_update_block(project_id, &UpdateType::RemainderFundingStart) { self.execute(|| frame_system::Pallet::::set_block_number(update_block - One::one())); @@ -692,13 +691,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::::do_project_decision(project_id, decision).unwrap(); - }); - } - } + Ok(()) } @@ -1162,10 +1155,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"), } } diff --git a/pallets/funding/src/storage_migrations.rs b/pallets/funding/src/storage_migrations.rs index 7754406d9..d426703ef 100644 --- a/pallets/funding/src/storage_migrations.rs +++ b/pallets/funding/src/storage_migrations.rs @@ -1,159 +1,5 @@ //! A module that is responsible for migration of storage. -use super::*; -use frame_support::{ - pallet_prelude::*, - traits::{tokens::Balance as BalanceT, StorageVersion}, -}; -use serde::{Deserialize, Serialize}; +use frame_support::traits::StorageVersion; /// The current storage version 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, - /// The current status of the project - pub status: OldProjectStatus, - /// When the different project phases start and end - pub phase_transition_points: PhaseTransitionPoints, - /// 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, - /// When the Funding Round ends - pub funding_end_block: Option, - /// ParaId of project - pub parachain_id: Option, - /// Migration readiness check - pub migration_readiness_check: Option, - /// 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), - 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 = - OldProjectDetails, Did, BlockNumberFor, PriceOf, BalanceOf, EvaluationRoundInfoOf>; - - pub struct UncheckedMigrationToV4(PhantomData); - impl OnRuntimeUpgrade for UncheckedMigrationToV4 { - fn on_runtime_upgrade() -> frame_support::weights::Weight { - let mut items = 0; - let mut translate = |_key, item: OldProjectDetailsOf| -> Option> { - 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:: { - 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::::translate(|key, object: OldProjectDetailsOf| translate(key, object)); - - T::DbWeight::get().reads_writes(items, items) - } - } - - pub type MigrationToV4 = frame_support::migrations::VersionedMigration< - 3, - 4, - UncheckedMigrationToV4, - crate::Pallet, - ::DbWeight, - >; -} diff --git a/pallets/funding/src/tests/mod.rs b/pallets/funding/src/tests/mod.rs index 216864deb..43803e434 100644 --- a/pallets/funding/src/tests/mod.rs +++ b/pallets/funding/src/tests/mod.rs @@ -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(); } diff --git a/pallets/funding/src/tests/runtime_api.rs b/pallets/funding/src/tests/runtime_api.rs index 4d5bc2e24..66001f2e9 100644 --- a/pallets/funding/src/tests/runtime_api.rs +++ b/pallets/funding/src/tests/runtime_api.rs @@ -574,7 +574,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, diff --git a/pallets/sandbox/Cargo.toml b/pallets/sandbox/Cargo.toml deleted file mode 100644 index f46bf3bb5..000000000 --- a/pallets/sandbox/Cargo.toml +++ /dev/null @@ -1,85 +0,0 @@ -[package] -name = "pallet-sandbox" -authors = ["Anonymous"] -description = "FRAME pallet to test new features" -version = "0.1.0" -license = "Unlicense" -homepage = "https://substrate.io" -repository = "https://github.com/paritytech/substrate/" -edition = "2021" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -parity-scale-codec = { version = "3.6.5", features = ["derive"], default-features = false } -scale-info = { version = "2.9.0", default-features = false, features = ["derive"] } - -# Local dependencies - -# Substrate dependencies -frame-support.workspace = true -frame-system.workspace = true -sp-std.workspace = true -sp-runtime.workspace = true -sp-arithmetic.workspace = true -parachains-common.workspace = true -pallet-funding.workspace = true - -# Benchmarking dependencies -frame-benchmarking = { workspace = true, optional = true } -polimec-common.workspace = true - -[dev-dependencies] -serde = { version = "1.0.188" } - -# Substrate -sp-core.workspace = true -sp-io.workspace = true -sp-runtime.workspace = true -pallet-balances.workspace = true -pallet-insecure-randomness-collective-flip.workspace = true -pallet-assets.workspace = true - - -[features] -default = [ "std" ] -runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-assets/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-funding/runtime-benchmarks", - "parachains-common/runtime-benchmarks", - "polimec-common/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", -] -std = [ - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", - "pallet-assets/std", - "pallet-balances/std", - "pallet-funding/std", - "pallet-insecure-randomness-collective-flip/std", - "parachains-common/std", - "parity-scale-codec/std", - "polimec-common/std", - "scale-info/std", - "sp-arithmetic/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", - "sp-std/std", -] -try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "pallet-assets/try-runtime", - "pallet-balances/try-runtime", - "pallet-funding/try-runtime", - "pallet-insecure-randomness-collective-flip/try-runtime", - "polimec-common/try-runtime", - "sp-runtime/try-runtime", -] diff --git a/pallets/sandbox/README.md b/pallets/sandbox/README.md deleted file mode 100644 index bf8f1b147..000000000 --- a/pallets/sandbox/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# Sandbox Pallet - diff --git a/pallets/sandbox/src/lib.rs b/pallets/sandbox/src/lib.rs deleted file mode 100644 index 6d81d82a0..000000000 --- a/pallets/sandbox/src/lib.rs +++ /dev/null @@ -1,97 +0,0 @@ -// Polimec Blockchain – https://www.polimec.org/ -// Copyright (C) Polimec 2022. All rights reserved. - -// The Polimec Blockchain is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Polimec Blockchain is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#![cfg_attr(not(feature = "std"), no_std)] - -pub use pallet::*; - -#[cfg(test)] -mod tests; - -#[cfg(test)] -mod mock; - -use pallet_funding::{self as funding, ProjectId}; - -#[frame_support::pallet(dev_mode)] -pub mod pallet { - use super::*; - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; - use funding::AcceptedFundingAsset; - use pallet_funding::{MultiplierOf, ProjectsDetails}; - - #[pallet::pallet] - pub struct Pallet(_); - - #[pallet::config] - pub trait Config: frame_system::Config + funding::Config {} - - #[pallet::call] - impl Pallet { - /// Buy tokens for a project in the community round if it achieved at least 500k USDT funding - #[pallet::weight(0)] - pub fn buy_if_popular( - origin: OriginFor, - project_id: ProjectId, - amount: ::Balance, - asset_id: AcceptedFundingAsset, - did: polimec_common::credentials::Did, - investor_type: polimec_common::credentials::InvestorType, - whitelisted_policy: polimec_common::credentials::Cid, - ) -> DispatchResultWithPostInfo { - let retail_user = ensure_signed(origin)?; - let project_id: ProjectId = project_id; - // Check project is in the community round - let project_info = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectNotFound)?; - ensure!( - project_info.status == funding::ProjectStatus::CommunityRound, - "Project is not in the community round" - ); - - // Calculate how much funding was done already - let project_contributions: ::Balance = - funding::Contributions::::iter_prefix_values((project_id,)) - .fold(0u64.into(), |total_tokens_bought, contribution| { - total_tokens_bought + contribution.funding_asset_amount - }); - - ensure!( - project_contributions >= 500_000_0_000_000_000u64.into(), - "Project did not achieve at least 500k USDT funding" - ); - - let multiplier: MultiplierOf = 1u8.try_into().map_err(|_| Error::::ProjectNotFound)?; - - // Buy tokens with the default multiplier - >::do_contribute( - &retail_user, - project_id, - amount, - multiplier, - asset_id, - did, - investor_type, - whitelisted_policy, - ) - } - } - - #[pallet::error] - pub enum Error { - ProjectNotFound, - } -} diff --git a/pallets/sandbox/src/mock.rs b/pallets/sandbox/src/mock.rs deleted file mode 100644 index 314c59794..000000000 --- a/pallets/sandbox/src/mock.rs +++ /dev/null @@ -1,215 +0,0 @@ -// // // Polimec Blockchain – https://www.polimec.org/ -// // // Copyright (C) Polimec 2022. All rights reserved. -// -// // // The Polimec Blockchain is free software: you can redistribute it and/or modify -// // // it under the terms of the GNU General Public License as published by -// // // the Free Software Foundation, either version 3 of the License, or -// // // (at your option) any later version. -// -// // // The Polimec Blockchain is distributed in the hope that it will be useful, -// // // but WITHOUT ANY WARRANTY; without even the implied warranty of -// // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// // // GNU General Public License for more details. -// -// // // You should have received a copy of the GNU General Public License -// // // along with this program. If not, see . -// -// use sp_std::collections::btree_map::BTreeMap; -// use frame_support::{ -// parameter_types, -// traits::{AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32}, -// PalletId, -// }; -// use frame_system as system; -// use parachains_common::HOURS; -// use sp_arithmetic::{FixedU128, Percent}; -// use sp_core::H256; -// use sp_runtime::{ -// testing::Header, -// traits::{BlakeTwo256, IdentityLookup}, -// BuildStorage, -// }; -// use system::EnsureSigned; -// -// type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -// type Block = frame_system::mocking::MockBlock; -// -// pub type AccountId = u64; -// pub type Balance = u128; -// pub type BlockNumber = u64; -// pub type Identifier = u32; -// pub type AssetId = u32; -// pub const PLMC: u128 = 10_000_000_000_u128; -// const USD_UNIT: u128 = 1_0_000_000_000u128; -// -// // Configure a mock runtime to test the pallet. -// frame_support::construct_runtime!( -// pub enum TestRuntime where -// Block = Block, -// NodeBlock = Block, -// UncheckedExtrinsic = UncheckedExtrinsic, -// { -// System: frame_system, -// RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip, -// Assets: pallet_assets, -// Balances: pallet_balances, -// PolimecFunding: pallet_funding, -// Sandbox: crate, -// } -// ); -// -// impl crate::Config for TestRuntime {} -// -// parameter_types! { -// pub const BlockHashCount: u32 = 250; -// } -// -// impl system::Config for TestRuntime { -// type AccountData = pallet_balances::AccountData; -// type AccountId = AccountId; -// type BaseCallFilter = frame_support::traits::Everything; -// type BlockHashCount = BlockHashCount; -// type BlockLength = (); -// type BlockNumber = BlockNumber; -// type BlockWeights = (); -// type DbWeight = (); -// type Hash = H256; -// type Hashing = BlakeTwo256; -// type Header = Header; -// type Index = u64; -// type Lookup = IdentityLookup; -// type MaxConsumers = frame_support::traits::ConstU32<16>; -// type OnKilledAccount = (); -// type OnNewAccount = (); -// type OnSetCode = (); -// type PalletInfo = PalletInfo; -// type RuntimeCall = RuntimeCall; -// type RuntimeEvent = RuntimeEvent; -// type RuntimeOrigin = RuntimeOrigin; -// type SS58Prefix = ConstU16<42>; -// type SystemWeightInfo = (); -// type Version = (); -// } -// -// parameter_types! { -// pub static ExistentialDeposit: Balance = 1; -// } -// -// impl pallet_balances::Config for TestRuntime { -// type AccountStore = System; -// type Balance = Balance; -// type DustRemoval = (); -// type ExistentialDeposit = ExistentialDeposit; -// type FreezeIdentifier = pallet_funding::types::LockType; -// type HoldIdentifier = pallet_funding::types::LockType; -// type MaxFreezes = (); -// type MaxHolds = (); -// type MaxLocks = frame_support::traits::ConstU32<1024>; -// type MaxReserves = frame_support::traits::ConstU32<1024>; -// type ReserveIdentifier = pallet_funding::types::LockType; -// type RuntimeEvent = RuntimeEvent; -// type WeightInfo = (); -// } -// -// impl pallet_insecure_randomness_collective_flip::Config for TestRuntime {} -// -// impl pallet_assets::Config for TestRuntime { -// type ApprovalDeposit = ConstU128<1>; -// type AssetAccountDeposit = ConstU128<10>; -// type AssetDeposit = ConstU128<1>; -// type AssetId = Identifier; -// type AssetIdParameter = Identifier; -// type Balance = Balance; -// #[cfg(feature = "runtime-benchmarks")] -// type BenchmarkHelper = (); -// type CallbackHandle = (); -// type CreateOrigin = AsEnsureOriginWithArg>; -// type Currency = Balances; -// type Extra = (); -// type ForceOrigin = frame_system::EnsureRoot; -// type Freezer = (); -// type MetadataDepositBase = ConstU128<1>; -// type MetadataDepositPerByte = ConstU128<1>; -// type RemoveItemsLimit = frame_support::traits::ConstU32<1000>; -// type RuntimeEvent = RuntimeEvent; -// type StringLimit = ConstU32<50>; -// type WeightInfo = (); -// } -// -// // REMARK: In the production configuration we use DAYS instead of HOURS. -// parameter_types! { -// pub const EvaluationDuration: BlockNumber = (28 * HOURS) as BlockNumber; -// pub const AuctionInitializePeriodDuration: BlockNumber = (7 * HOURS) as BlockNumber; -// pub const AuctionOpeningDuration: BlockNumber = (2 * HOURS) as BlockNumber; -// pub const AuctionClosingDuration: BlockNumber = (3 * HOURS) as BlockNumber; -// pub const CommunityRoundDuration: BlockNumber = (5 * HOURS) as BlockNumber; -// pub const RemainderFundingDuration: BlockNumber = (1 * HOURS) as BlockNumber; -// pub const FundingPalletId: PalletId = PalletId(*b"py/cfund"); -// pub const ManualAcceptanceDuration: BlockNumber = (3 * HOURS) as BlockNumber; -// pub const SuccessToSettlementTime: BlockNumber =(4 * HOURS) as BlockNumber; -// pub PriceMap: BTreeMap = BTreeMap::from_iter(vec![ -// (0u32, FixedU128::from_float(69f64)), // DOT -// (1337u32, FixedU128::from_float(0.97f64)), // USDC -// (1984u32, FixedU128::from_float(0.95f64)), // USDT -// (3344u32, FixedU128::from_float(8.4f64)), // PLMC -// ]); -// pub FeeBrackets: Vec<(Percent, Balance)> = vec![ -// (Percent::from_percent(10), 1_000_000 * USD_UNIT), -// (Percent::from_percent(8), 5_000_000 * USD_UNIT), -// (Percent::from_percent(6), u128::MAX), // Making it max signifies the last bracket -// ]; -// pub EarlyEvaluationThreshold: Percent = Percent::from_percent(10); -// } -// -// impl pallet_funding::Config for TestRuntime { -// type AuctionInitializePeriodDuration = AuctionInitializePeriodDuration; -// type Balance = Balance; -// #[cfg(feature = "runtime-benchmarks")] -// type BenchmarkHelper = (); -// type AuctionClosingDuration = AuctionClosingDuration; -// type CommunityFundingDuration = CommunityRoundDuration; -// type ContributionTokenCurrency = (); -// type ContributionVesting = ConstU32<4>; -// type AuctionOpeningDuration = AuctionOpeningDuration; -// type EvaluationDuration = EvaluationDuration; -// type EvaluationSuccessThreshold = EarlyEvaluationThreshold; -// type FeeBrackets = FeeBrackets; -// type FundingCurrency = (); -// type ManualAcceptanceDuration = ManualAcceptanceDuration; -// // Low values to simplify the tests -// type MaxBidsPerUser = ConstU32<4>; -// type MaxContributionsPerUser = ConstU32<4>; -// type MaxEvaluationsPerUser = ConstU32<4>; -// type Multiplier = (); -// type NativeCurrency = Balances; -// type PalletId = FundingPalletId; -// type Price = FixedU128; -// type PriceProvider = (); -// type ProjectIdentifier = Identifier; -// type Randomness = RandomnessCollectiveFlip; -// type RemainderFundingDuration = RemainderFundingDuration; -// type RuntimeEvent = RuntimeEvent; -// type StringLimit = ConstU32<64>; -// type SuccessToSettlementTime = SuccessToSettlementTime; -// type Vesting = (); -// type WeightInfo = (); -// } -// -// // Build genesis storage according to the mock runtime. -// #[allow(dead_code)] -// pub fn new_test_ext() -> sp_io::TestExternalities { -// let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); -// -// GenesisConfig { balances: BalancesConfig { balances: vec![] }, ..Default::default() } -// .assimilate_storage(&mut t) -// .unwrap(); -// -// let mut ext = sp_io::TestExternalities::new(t); -// // In order to emit events the block number must be more than 0 -// ext.execute_with(|| System::set_block_number(1)); -// ext -// } -// -// pub fn hashed(data: impl AsRef<[u8]>) -> H256 { -// ::hash(data.as_ref()) -// } diff --git a/pallets/sandbox/src/tests.rs b/pallets/sandbox/src/tests.rs deleted file mode 100644 index 5e2db9940..000000000 --- a/pallets/sandbox/src/tests.rs +++ /dev/null @@ -1,108 +0,0 @@ -// use crate::mock::*; -// use frame_support::{ -// assert_ok, -// dispatch::Weight, -// traits::{OnFinalize, OnIdle, OnInitialize}, -// }; -// use pallet_funding::{CurrencyMetadata, ParticipantsSize, ProjectMetadata, TicketSize}; -// use sp_core::{bounded::BoundedVec, ConstU32}; -// use sp_runtime::BuildStorage; - -// #[test] -// fn test_buy_if_popular() { -// new_test_ext().execute_with(|| { -// let creator = 1; -// let evaluator = 2; -// let bidder = 3; -// let contributor = 4; - -// let project = default_project(0); -// assert_ok!(PolimecFunding::create(RuntimeOrigin::signed(creator), project.clone(),)); -// assert_ok!(PolimecFunding::start_evaluation(RuntimeOrigin::signed(creator), 0)); -// assert_ok!(PolimecFunding::bond_evaluation(RuntimeOrigin::signed(evaluator), 0, 120_000 * PLMC)); - -// // advance time -// for _block in 0..::EvaluationDuration::get() + 10 { -// >::on_finalize(System::block_number()); -// >::on_idle(System::block_number(), Weight::MAX); -// System::set_block_number(System::block_number() + 1); -// >::on_initialize(System::block_number()); -// } - -// assert_ok!(PolimecFunding::start_auction(RuntimeOrigin::signed(creator), 0)); - -// // advance time -// for _block in 0..2 { -// >::on_finalize(System::block_number()); -// >::on_idle(System::block_number(), Weight::MAX); -// System::set_block_number(System::block_number() + 1); -// >::on_initialize(System::block_number()); -// } - -// assert_ok!(PolimecFunding::bid(RuntimeOrigin::signed(bidder), 0, 1000, 100 * PLMC, None, 1984)); - -// // advance time -// for _block in 0..(::AuctionOpeningDuration::get() + -// ::AuctionClosingDuration::get() + -// 5) -// { -// >::on_finalize(System::block_number()); -// >::on_idle(System::block_number(), Weight::MAX); -// System::set_block_number(System::block_number() + 1); -// >::on_initialize(System::block_number()); -// } - -// assert_ok!(PolimecFunding::contribute(RuntimeOrigin::signed(contributor), 0, 1, None, 1984)); - -// assert!(Sandbox::buy_if_popular(RuntimeOrigin::signed(4), 0, 1000, 1984).is_err()); - -// assert_ok!(PolimecFunding::contribute(RuntimeOrigin::signed(contributor), 0, 10000, None, 1984)); - -// assert_ok!(Sandbox::buy_if_popular(RuntimeOrigin::signed(4), 0, 1000, 1984)); -// }); -// } - -// const ASSET_DECIMALS: u8 = 12; -// const IPFS_CID: &str = r#" -// { -// "whitepaper":"ipfs_url", -// "team_description":"ipfs_url", -// "tokenomics":"ipfs_url", -// "roadmap":"ipfs_url", -// "usage_of_founds":"ipfs_url" -// }"#; - -// pub fn default_project(nonce: u64) -> pallet_funding::ProjectMetadataOf { -// let bounded_name = bounded_name(); -// let bounded_symbol = bounded_symbol(); -// let metadata_hash = ipfs_hash(); -// ProjectMetadata { -// total_allocation_size: 1_000_000, -// minimum_price: 1 * PLMC, -// ticket_size: TicketSize { minimum: Some(1), maximum: None }, -// participants_size: ParticipantsSize { minimum: Some(2), maximum: None }, -// funding_thresholds: Default::default(), -// conversion_rate: 0, -// participation_currencies: Default::default(), -// policy_ipfs_cid: Some(metadata_hash), -// token_information: CurrencyMetadata { name: bounded_name, symbol: bounded_symbol, decimals: ASSET_DECIMALS }, -// } -// } - -// pub fn new_test_ext() -> sp_io::TestExternalities { -// let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - -// GenesisConfig { -// balances: BalancesConfig { -// balances: vec![(1, 1_000_000 * PLMC), (2, 1_000_000 * PLMC), (3, 1_000_000 * PLMC), (4, 10_000_000 * PLMC)], -// }, -// ..Default::default() -// } -// .assimilate_storage(&mut t) -// .unwrap(); - -// let mut ext = sp_io::TestExternalities::new(t); -// // In order to emit events the block number must be more than 0 -// ext.execute_with(|| System::set_block_number(1)); -// ext -// } diff --git a/runtimes/polimec/src/lib.rs b/runtimes/polimec/src/lib.rs index 5c12e881e..b0cca3ff1 100644 --- a/runtimes/polimec/src/lib.rs +++ b/runtimes/polimec/src/lib.rs @@ -56,7 +56,7 @@ use sp_runtime::{ IdentifyAccount, IdentityLookup, OpaqueKeys, Verify, }, transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, FixedU128, MultiSignature, SaturatedConversion, + ApplyExtrinsicResult, FixedU128, MultiSignature, Perquintill, SaturatedConversion, }; use sp_std::{cmp::Ordering, prelude::*}; use sp_version::RuntimeVersion; @@ -159,11 +159,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: #[allow(unused_parens)] - pub type Unreleased = (pallet_funding::storage_migrations::v3tov4::MigrationToV4); + pub type Unreleased = (); } /// Executive: handles dispatch to the various modules. @@ -243,15 +242,13 @@ impl Contains for BaseCallFilter { pallet_funding::Call::start_evaluation { .. } | pallet_funding::Call::end_evaluation { .. } | pallet_funding::Call::evaluate { .. } | + pallet_funding::Call::end_evaluation { .. } | pallet_funding::Call::start_auction { .. } | - pallet_funding::Call::root_do_auction_opening { .. } | - pallet_funding::Call::root_do_start_auction_closing { .. } | pallet_funding::Call::bid { .. } | - pallet_funding::Call::root_do_end_auction { .. } | + pallet_funding::Call::end_auction { .. } | pallet_funding::Call::contribute { .. } | - pallet_funding::Call::root_do_community_funding { .. } | - pallet_funding::Call::root_do_end_funding { .. } | - pallet_funding::Call::root_do_start_settlement { .. } | + pallet_funding::Call::end_funding { .. } | + pallet_funding::Call::start_settlement { .. } | pallet_funding::Call::settle_successful_evaluation { .. } | pallet_funding::Call::settle_failed_evaluation { .. } | pallet_funding::Call::settle_successful_bid { .. } | @@ -1046,6 +1043,7 @@ impl pallet_funding::Config for Runtime { type EvaluatorSlash = EvaluatorSlash; type FeeBrackets = FeeBrackets; type FundingCurrency = ForeignAssets; + type FundingSuccessThreshold = FundingSuccessThreshold; type InvestorOrigin = EnsureInvestor; type ManualAcceptanceDuration = ManualAcceptanceDuration; type MaxBidsPerProject = ConstU32<512>; diff --git a/runtimes/shared-configuration/src/funding.rs b/runtimes/shared-configuration/src/funding.rs index 85f9efb7e..b7de80cc2 100644 --- a/runtimes/shared-configuration/src/funding.rs +++ b/runtimes/shared-configuration/src/funding.rs @@ -20,6 +20,7 @@ use pallet_funding::types::AcceptedFundingAsset; use parachains_common::AssetIdForTrustBackedAssets; use polimec_common::USD_UNIT; use sp_arithmetic::{FixedU128, Percent}; +use sp_runtime::Perquintill; use sp_std::{collections::btree_map::BTreeMap, vec, vec::Vec}; #[cfg(not(feature = "instant-mode"))] @@ -113,4 +114,5 @@ parameter_types! { ]; pub EarlyEvaluationThreshold: Percent = Percent::from_percent(10); pub EvaluatorSlash: Percent = Percent::from_percent(20); + pub FundingSuccessThreshold: Perquintill = Perquintill::from_percent(33); }