diff --git a/pallets/funding/src/functions.rs b/pallets/funding/src/functions.rs index 19ee763c1..094f3a507 100644 --- a/pallets/funding/src/functions.rs +++ b/pallets/funding/src/functions.rs @@ -18,10 +18,6 @@ //! Functions for the Funding pallet. -use super::*; -use sp_std::marker::PhantomData; - -use crate::traits::{BondingRequirementCalculation, ProvideStatemintPrice, VestingDurationCalculation}; use frame_support::{ dispatch::DispatchResult, ensure, @@ -33,13 +29,18 @@ use frame_support::{ Get, }, }; - -use sp_arithmetic::Perquintill; +use sp_arithmetic::{ + traits::{CheckedDiv, CheckedSub, Zero}, + Perquintill, +}; +use sp_runtime::traits::Convert; +use sp_std::marker::PhantomData; use polimec_traits::ReleaseSchedule; -use sp_arithmetic::traits::{CheckedDiv, CheckedSub, Zero}; -use sp_runtime::traits::Convert; -use sp_std::prelude::*; + +use crate::traits::{BondingRequirementCalculation, ProvideStatemintPrice, VestingDurationCalculation}; + +use super::*; // Round transition functions impl Pallet { @@ -769,7 +770,7 @@ impl Pallet { let mut project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectInfoNotFound)?; let now = >::block_number(); let evaluation_id = Self::next_evaluation_id(); - let caller_existing_evaluations: Vec<(StorageItemIdOf, EvaluationInfoOf)> = + let caller_existing_evaluations: Vec<(u32, EvaluationInfoOf)> = Evaluations::::iter_prefix((project_id, evaluator.clone())).collect(); let plmc_usd_price = T::PriceProvider::get_price(PLMC_STATEMINT_ID).ok_or(Error::::PLMCPriceNotAvailable)?; let early_evaluation_reward_threshold_usd = @@ -1132,7 +1133,7 @@ impl Pallet { releaser: AccountIdOf, project_id: T::ProjectIdentifier, bidder: AccountIdOf, - bid_id: T::StorageItemId, + bid_id: u32, ) -> DispatchResult { // * Get variables * let mut bid = Bids::::get((project_id, bidder.clone(), bid_id)).ok_or(Error::::BidNotFound)?; @@ -1167,7 +1168,7 @@ impl Pallet { releaser: AccountIdOf, project_id: T::ProjectIdentifier, contributor: AccountIdOf, - contribution_id: T::StorageItemId, + contribution_id: u32, ) -> DispatchResult { // * Get variables * let mut contribution = Contributions::::get((project_id, contributor.clone(), contribution_id)) @@ -1202,7 +1203,7 @@ impl Pallet { releaser: AccountIdOf, project_id: T::ProjectIdentifier, evaluator: AccountIdOf, - evaluation_id: T::StorageItemId, + evaluation_id: u32, ) -> Result<(), DispatchError> { // * Get variables * let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectInfoNotFound)?; @@ -1244,7 +1245,7 @@ impl Pallet { caller: AccountIdOf, project_id: T::ProjectIdentifier, evaluator: AccountIdOf, - evaluation_id: StorageItemIdOf, + evaluation_id: u32, ) -> Result<(), DispatchError> { // * Get variables * let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectInfoNotFound)?; @@ -1301,7 +1302,7 @@ impl Pallet { caller: AccountIdOf, project_id: T::ProjectIdentifier, evaluator: AccountIdOf, - evaluation_id: StorageItemIdOf, + evaluation_id: u32, ) -> Result<(), DispatchError> { // * Get variables * let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectInfoNotFound)?; @@ -1355,7 +1356,7 @@ impl Pallet { caller: AccountIdOf, project_id: T::ProjectIdentifier, bidder: AccountIdOf, - bid_id: StorageItemIdOf, + bid_id: u32, ) -> Result<(), DispatchError> { // * Get variables * let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectInfoNotFound)?; @@ -1401,7 +1402,7 @@ impl Pallet { caller: AccountIdOf, project_id: T::ProjectIdentifier, contributor: AccountIdOf, - contribution_id: StorageItemIdOf, + contribution_id: u32, ) -> Result<(), DispatchError> { // * Get variables * let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectInfoNotFound)?; @@ -1473,7 +1474,7 @@ impl Pallet { caller: AccountIdOf, project_id: T::ProjectIdentifier, bidder: AccountIdOf, - bid_id: StorageItemIdOf, + bid_id: u32, ) -> Result<(), DispatchError> { // * Get variables * let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectInfoNotFound)?; @@ -1518,7 +1519,7 @@ impl Pallet { caller: AccountIdOf, project_id: T::ProjectIdentifier, bidder: AccountIdOf, - bid_id: StorageItemIdOf, + bid_id: u32, ) -> Result<(), DispatchError> { // * Get variables * let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectInfoNotFound)?; @@ -1551,7 +1552,7 @@ impl Pallet { caller: AccountIdOf, project_id: T::ProjectIdentifier, contributor: AccountIdOf, - contribution_id: StorageItemIdOf, + contribution_id: u32, ) -> Result<(), DispatchError> { // * Get variables * let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectInfoNotFound)?; @@ -1593,7 +1594,7 @@ impl Pallet { caller: AccountIdOf, project_id: T::ProjectIdentifier, contributor: AccountIdOf, - contribution_id: StorageItemIdOf, + contribution_id: u32, ) -> Result<(), DispatchError> { // * Get variables * let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectInfoNotFound)?; @@ -1627,7 +1628,7 @@ impl Pallet { caller: AccountIdOf, project_id: T::ProjectIdentifier, bidder: AccountIdOf, - bid_id: StorageItemIdOf, + bid_id: u32, ) -> Result<(), DispatchError> { // * Get variables * let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectInfoNotFound)?; @@ -1673,7 +1674,7 @@ impl Pallet { caller: AccountIdOf, project_id: T::ProjectIdentifier, contributor: AccountIdOf, - contribution_id: StorageItemIdOf, + contribution_id: u32, ) -> Result<(), DispatchError> { // * Get variables * let project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectInfoNotFound)?; diff --git a/pallets/funding/src/impls.rs b/pallets/funding/src/impls.rs index ca06dc59d..f0b18252c 100644 --- a/pallets/funding/src/impls.rs +++ b/pallets/funding/src/impls.rs @@ -1,7 +1,8 @@ -use crate::{traits::DoRemainingOperation, *}; use frame_support::{traits::Get, weights::Weight}; use sp_runtime::{traits::AccountIdConversion, DispatchError}; -use sp_std::{marker::PhantomData, prelude::*}; +use sp_std::marker::PhantomData; + +use crate::{traits::DoRemainingOperation, *}; impl Cleaner { pub fn has_remaining_operations(&self) -> bool { diff --git a/pallets/funding/src/lib.rs b/pallets/funding/src/lib.rs index c689b14e0..2857919a1 100644 --- a/pallets/funding/src/lib.rs +++ b/pallets/funding/src/lib.rs @@ -133,9 +133,9 @@ //! ); //! //! 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, AcceptedFundingAsset::USDT)?; +//! let multiplier: MultiplierOf = 1u8.try_into().map_err(|_| Error::::ProjectNotFound)?; +//! // Buy tokens with the default multiplier +//! >::do_contribute(retail_user, project_id, amount, multiplier, AcceptedFundingAsset::USDT)?; //! //! Ok(()) //! } @@ -176,6 +176,23 @@ // we add more without this limit. #![cfg_attr(feature = "runtime-benchmarks", recursion_limit = "512")] +use frame_support::{ + traits::{ + tokens::{fungible, fungibles, Balance}, + Randomness, + }, + BoundedVec, PalletId, +}; +use parity_scale_codec::{Decode, Encode}; +use sp_arithmetic::traits::{One, Saturating}; +use sp_runtime::{traits::AccountIdConversion, FixedPointNumber, FixedPointOperand, FixedU128}; +use sp_std::prelude::*; + +pub use pallet::*; +pub use types::*; + +pub use crate::weights::WeightInfo; + pub mod functions; pub mod types; pub mod weights; @@ -191,32 +208,12 @@ pub mod benchmarking; pub mod impls; pub mod traits; -pub use pallet::*; -pub use types::*; - -pub use crate::weights::WeightInfo; -use frame_support::{ - pallet_prelude::ValueQuery, - traits::{ - tokens::{fungible, fungibles, Balance}, - Get, Randomness, - }, - BoundedVec, PalletId, Parameter, -}; -use parity_scale_codec::{Decode, Encode}; - -use sp_arithmetic::traits::{One, Saturating}; - -use sp_runtime::{traits::AccountIdConversion, FixedPointNumber, FixedPointOperand, FixedU128}; -use sp_std::prelude::*; - pub type AccountIdOf = ::AccountId; pub type BlockNumberOf = ::BlockNumber; pub type ProjectIdOf = ::ProjectIdentifier; pub type MultiplierOf = ::Multiplier; pub type BalanceOf = ::Balance; pub type PriceOf = ::Price; -pub type StorageItemIdOf = ::StorageItemId; pub type StringLimitOf = ::StringLimit; pub type HashOf = ::Hash; pub type AssetIdOf = @@ -231,10 +228,9 @@ pub type ProjectDetailsOf = ProjectDetails, BlockNumberOf, PriceOf, BalanceOf, EvaluationRoundInfoOf>; pub type EvaluationRoundInfoOf = EvaluationRoundInfo>; pub type VestingInfoOf = VestingInfo, BalanceOf>; -pub type EvaluationInfoOf = - EvaluationInfo, ProjectIdOf, AccountIdOf, BalanceOf, BlockNumberOf>; +pub type EvaluationInfoOf = EvaluationInfo, AccountIdOf, BalanceOf, BlockNumberOf>; pub type BidInfoOf = BidInfo< - StorageItemIdOf, + u32, ProjectIdOf, BalanceOf, PriceOf, @@ -243,14 +239,8 @@ pub type BidInfoOf = BidInfo< MultiplierOf, VestingInfoOf, >; -pub type ContributionInfoOf = ContributionInfo< - StorageItemIdOf, - ProjectIdOf, - AccountIdOf, - BalanceOf, - MultiplierOf, - VestingInfoOf, ->; +pub type ContributionInfoOf = + ContributionInfo, AccountIdOf, BalanceOf, MultiplierOf, VestingInfoOf>; pub type BondTypeOf = LockType>; const PLMC_STATEMINT_ID: u32 = 2069; @@ -258,14 +248,17 @@ const PLMC_STATEMINT_ID: u32 = 2069; // TODO: PLMC-152. Remove `dev_mode` attribute when extrinsics API are stable #[frame_support::pallet(dev_mode)] pub mod pallet { - use super::*; - use crate::traits::{BondingRequirementCalculation, ProvideStatemintPrice, VestingDurationCalculation}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; - use local_macros::*; use sp_arithmetic::Percent; use sp_runtime::traits::Convert; + use local_macros::*; + + use crate::traits::{BondingRequirementCalculation, ProvideStatemintPrice, VestingDurationCalculation}; + + use super::*; + #[pallet::pallet] pub struct Pallet(_); @@ -314,9 +307,6 @@ pub mod pallet { type PriceProvider: ProvideStatemintPrice; - /// Unique identifier for any bid in the system. - type StorageItemId: Parameter + Copy + Saturating + One + Default; - /// Something that provides randomness in the runtime. type Randomness: Randomness; @@ -416,15 +406,15 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn next_evaluation_id)] - pub type NextEvaluationId = StorageValue<_, T::StorageItemId, ValueQuery>; + pub type NextEvaluationId = StorageValue<_, u32, ValueQuery>; #[pallet::storage] #[pallet::getter(fn next_bid_id)] - pub type NextBidId = StorageValue<_, T::StorageItemId, ValueQuery>; + pub type NextBidId = StorageValue<_, u32, ValueQuery>; #[pallet::storage] #[pallet::getter(fn next_contribution_id)] - pub type NextContributionId = StorageValue<_, T::StorageItemId, ValueQuery>; + pub type NextContributionId = StorageValue<_, u32, ValueQuery>; #[pallet::storage] #[pallet::getter(fn nonce)] @@ -472,7 +462,7 @@ pub mod pallet { ( NMapKey, NMapKey>, - NMapKey>, + NMapKey, ), EvaluationInfoOf, >; @@ -485,7 +475,7 @@ pub mod pallet { ( NMapKey, NMapKey>, - NMapKey>, + NMapKey, ), BidInfoOf, >; @@ -498,22 +488,30 @@ pub mod pallet { ( NMapKey, NMapKey>, - NMapKey>, + NMapKey, ), ContributionInfoOf, >; #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] + #[pallet::generate_deposit(pub (super) fn deposit_event)] pub enum Event { /// A project was created. - Created { project_id: T::ProjectIdentifier }, + Created { + project_id: T::ProjectIdentifier, + }, /// The metadata of a project was modified. - MetadataEdited { project_id: T::ProjectIdentifier }, + MetadataEdited { + project_id: T::ProjectIdentifier, + }, /// The evaluation phase of a project started. - EvaluationStarted { project_id: T::ProjectIdentifier }, + EvaluationStarted { + project_id: T::ProjectIdentifier, + }, /// The evaluation phase of a project ended without reaching the minimum threshold of evaluation bonds. - EvaluationFailed { project_id: T::ProjectIdentifier }, + EvaluationFailed { + project_id: T::ProjectIdentifier, + }, /// The period an issuer has to start the auction phase of the project. AuctionInitializePeriod { project_id: T::ProjectIdentifier, @@ -521,13 +519,25 @@ pub mod pallet { end_block: T::BlockNumber, }, /// The auction round of a project started. - EnglishAuctionStarted { project_id: T::ProjectIdentifier, when: T::BlockNumber }, + EnglishAuctionStarted { + project_id: T::ProjectIdentifier, + when: T::BlockNumber, + }, /// The candle auction part of the auction started for a project - CandleAuctionStarted { project_id: T::ProjectIdentifier, when: T::BlockNumber }, + CandleAuctionStarted { + project_id: T::ProjectIdentifier, + when: T::BlockNumber, + }, /// The auction round of a project ended. - AuctionFailed { project_id: T::ProjectIdentifier }, + AuctionFailed { + project_id: T::ProjectIdentifier, + }, /// A `bonder` bonded an `amount` of PLMC for `project_id`. - FundsBonded { project_id: T::ProjectIdentifier, amount: BalanceOf, bonder: AccountIdOf }, + FundsBonded { + project_id: T::ProjectIdentifier, + amount: BalanceOf, + bonder: AccountIdOf, + }, /// Someone paid for the release of a user's PLMC bond for a project. BondReleased { project_id: T::ProjectIdentifier, @@ -536,7 +546,12 @@ pub mod pallet { releaser: AccountIdOf, }, /// A bid was made for a project - Bid { project_id: T::ProjectIdentifier, amount: BalanceOf, price: T::Price, multiplier: MultiplierOf }, + Bid { + project_id: T::ProjectIdentifier, + amount: BalanceOf, + price: T::Price, + multiplier: MultiplierOf, + }, /// A contribution was made for a project. i.e token purchase Contribution { project_id: T::ProjectIdentifier, @@ -545,18 +560,28 @@ pub mod pallet { multiplier: MultiplierOf, }, /// A project is now in its community funding round - CommunityFundingStarted { project_id: T::ProjectIdentifier }, + CommunityFundingStarted { + project_id: T::ProjectIdentifier, + }, /// A project is now in the remainder funding round - RemainderFundingStarted { project_id: T::ProjectIdentifier }, + RemainderFundingStarted { + project_id: T::ProjectIdentifier, + }, /// A project has now finished funding - FundingEnded { project_id: T::ProjectIdentifier, outcome: FundingOutcome }, + FundingEnded { + project_id: T::ProjectIdentifier, + outcome: FundingOutcome, + }, /// Something was not properly initialized. Most likely due to dev error manually calling do_* functions or updating storage - TransitionError { project_id: T::ProjectIdentifier, error: DispatchError }, + TransitionError { + project_id: T::ProjectIdentifier, + error: DispatchError, + }, /// Something terribly wrong happened where the bond could not be unbonded. Most likely a programming error EvaluationUnbondFailed { project_id: ProjectIdOf, evaluator: AccountIdOf, - id: StorageItemIdOf, + id: u32, error: DispatchError, }, /// Contribution tokens were minted to a user @@ -567,98 +592,100 @@ pub mod pallet { amount: BalanceOf, }, /// A transfer of tokens failed, but because it was done inside on_initialize it cannot be solved. - TransferError { error: DispatchError }, + TransferError { + error: DispatchError, + }, EvaluationRewardFailed { project_id: ProjectIdOf, evaluator: AccountIdOf, - id: StorageItemIdOf, + id: u32, error: DispatchError, }, EvaluationSlashFailed { project_id: ProjectIdOf, evaluator: AccountIdOf, - id: StorageItemIdOf, + id: u32, error: DispatchError, }, ReleaseBidFundsFailed { project_id: ProjectIdOf, bidder: AccountIdOf, - id: StorageItemIdOf, + id: u32, error: DispatchError, }, BidUnbondFailed { project_id: ProjectIdOf, bidder: AccountIdOf, - id: StorageItemIdOf, + id: u32, error: DispatchError, }, ReleaseContributionFundsFailed { project_id: ProjectIdOf, contributor: AccountIdOf, - id: StorageItemIdOf, + id: u32, error: DispatchError, }, ContributionUnbondFailed { project_id: ProjectIdOf, contributor: AccountIdOf, - id: StorageItemIdOf, + id: u32, error: DispatchError, }, PayoutContributionFundsFailed { project_id: ProjectIdOf, contributor: AccountIdOf, - id: StorageItemIdOf, + id: u32, error: DispatchError, }, PayoutBidFundsFailed { project_id: ProjectIdOf, bidder: AccountIdOf, - id: StorageItemIdOf, + id: u32, error: DispatchError, }, EvaluationRewarded { project_id: ProjectIdOf, evaluator: AccountIdOf, - id: StorageItemIdOf, + id: u32, amount: BalanceOf, caller: AccountIdOf, }, EvaluationSlashed { project_id: ProjectIdOf, evaluator: AccountIdOf, - id: StorageItemIdOf, + id: u32, amount: BalanceOf, caller: AccountIdOf, }, CTMintFailed { project_id: ProjectIdOf, claimer: AccountIdOf, - id: StorageItemIdOf, + id: u32, error: DispatchError, }, StartBidderVestingScheduleFailed { project_id: ProjectIdOf, bidder: AccountIdOf, - id: StorageItemIdOf, + id: u32, error: DispatchError, }, StartContributionVestingScheduleFailed { project_id: ProjectIdOf, contributor: AccountIdOf, - id: StorageItemIdOf, + id: u32, error: DispatchError, }, BidPlmcVestingScheduled { project_id: ProjectIdOf, bidder: AccountIdOf, - id: StorageItemIdOf, + id: u32, amount: BalanceOf, caller: AccountIdOf, }, ContributionPlmcVestingScheduled { project_id: ProjectIdOf, contributor: AccountIdOf, - id: StorageItemIdOf, + id: u32, amount: BalanceOf, caller: AccountIdOf, }, @@ -671,28 +698,28 @@ pub mod pallet { BidFundingPaidOut { project_id: ProjectIdOf, bidder: AccountIdOf, - id: StorageItemIdOf, + id: u32, amount: BalanceOf, caller: AccountIdOf, }, ContributionFundingPaidOut { project_id: ProjectIdOf, contributor: AccountIdOf, - id: StorageItemIdOf, + id: u32, amount: BalanceOf, caller: AccountIdOf, }, BidFundingReleased { project_id: ProjectIdOf, bidder: AccountIdOf, - id: StorageItemIdOf, + id: u32, amount: BalanceOf, caller: AccountIdOf, }, ContributionFundingReleased { project_id: ProjectIdOf, contributor: AccountIdOf, - id: StorageItemIdOf, + id: u32, amount: BalanceOf, caller: AccountIdOf, }, @@ -887,7 +914,7 @@ pub mod pallet { origin: OriginFor, project_id: T::ProjectIdentifier, #[pallet::compact] amount: BalanceOf, - multiplier:MultiplierOf, + multiplier: MultiplierOf, asset: AcceptedFundingAsset, ) -> DispatchResult { let contributor = ensure_signed(origin)?; @@ -900,7 +927,7 @@ pub mod pallet { origin: OriginFor, project_id: T::ProjectIdentifier, evaluator: AccountIdOf, - bond_id: T::StorageItemId, + bond_id: u32, ) -> DispatchResult { let releaser = ensure_signed(origin)?; Self::do_evaluation_unbond_for(releaser, project_id, evaluator, bond_id) @@ -911,7 +938,7 @@ pub mod pallet { origin: OriginFor, project_id: T::ProjectIdentifier, evaluator: AccountIdOf, - bond_id: T::StorageItemId, + bond_id: u32, ) -> DispatchResult { let caller = ensure_signed(origin)?; Self::do_evaluation_slash_for(caller, project_id, evaluator, bond_id) @@ -922,7 +949,7 @@ pub mod pallet { origin: OriginFor, project_id: T::ProjectIdentifier, evaluator: AccountIdOf, - bond_id: T::StorageItemId, + bond_id: u32, ) -> DispatchResult { let caller = ensure_signed(origin)?; Self::do_evaluation_reward_payout_for(caller, project_id, evaluator, bond_id) @@ -933,7 +960,7 @@ pub mod pallet { origin: OriginFor, project_id: T::ProjectIdentifier, bidder: AccountIdOf, - bid_id: T::StorageItemId, + bid_id: u32, ) -> DispatchResult { let caller = ensure_signed(origin)?; Self::do_bid_ct_mint_for(caller, project_id, bidder, bid_id) @@ -944,7 +971,7 @@ pub mod pallet { origin: OriginFor, project_id: T::ProjectIdentifier, contributor: AccountIdOf, - contribution_id: T::StorageItemId, + contribution_id: u32, ) -> DispatchResult { let caller = ensure_signed(origin)?; Self::do_contribution_ct_mint_for(caller, project_id, contributor, contribution_id) @@ -955,7 +982,7 @@ pub mod pallet { origin: OriginFor, project_id: T::ProjectIdentifier, bidder: AccountIdOf, - bid_id: T::StorageItemId, + bid_id: u32, ) -> DispatchResult { let caller = ensure_signed(origin)?; Self::do_start_bid_vesting_schedule_for(caller, project_id, bidder, bid_id) @@ -966,7 +993,7 @@ pub mod pallet { origin: OriginFor, project_id: T::ProjectIdentifier, contributor: AccountIdOf, - contribution_id: T::StorageItemId, + contribution_id: u32, ) -> DispatchResult { let caller = ensure_signed(origin)?; Self::do_start_contribution_vesting_schedule_for(caller, project_id, contributor, contribution_id) @@ -977,7 +1004,7 @@ pub mod pallet { origin: OriginFor, project_id: T::ProjectIdentifier, bidder: AccountIdOf, - bid_id: T::StorageItemId, + bid_id: u32, ) -> DispatchResult { let caller = ensure_signed(origin)?; Self::do_payout_bid_funds_for(caller, project_id, bidder, bid_id) @@ -988,7 +1015,7 @@ pub mod pallet { origin: OriginFor, project_id: T::ProjectIdentifier, contributor: AccountIdOf, - contribution_id: T::StorageItemId, + contribution_id: u32, ) -> DispatchResult { let caller = ensure_signed(origin)?; Self::do_payout_contribution_funds_for(caller, project_id, contributor, contribution_id) @@ -1009,7 +1036,7 @@ pub mod pallet { origin: OriginFor, project_id: T::ProjectIdentifier, bidder: AccountIdOf, - bid_id: T::StorageItemId, + bid_id: u32, ) -> DispatchResult { let caller = ensure_signed(origin)?; Self::do_release_bid_funds_for(caller, project_id, bidder, bid_id) @@ -1020,7 +1047,7 @@ pub mod pallet { origin: OriginFor, project_id: T::ProjectIdentifier, bidder: AccountIdOf, - bid_id: T::StorageItemId, + bid_id: u32, ) -> DispatchResult { let caller = ensure_signed(origin)?; Self::do_bid_unbond_for(caller, project_id, bidder, bid_id) @@ -1031,7 +1058,7 @@ pub mod pallet { origin: OriginFor, project_id: T::ProjectIdentifier, contributor: AccountIdOf, - contribution_id: T::StorageItemId, + contribution_id: u32, ) -> DispatchResult { let caller = ensure_signed(origin)?; Self::do_release_contribution_funds_for(caller, project_id, contributor, contribution_id) @@ -1042,7 +1069,7 @@ pub mod pallet { origin: OriginFor, project_id: T::ProjectIdentifier, contributor: AccountIdOf, - contribution_id: T::StorageItemId, + contribution_id: u32, ) -> DispatchResult { let caller = ensure_signed(origin)?; Self::do_contribution_unbond_for(caller, project_id, contributor, contribution_id) diff --git a/pallets/funding/src/mock.rs b/pallets/funding/src/mock.rs index 5d799810b..ee335ad30 100644 --- a/pallets/funding/src/mock.rs +++ b/pallets/funding/src/mock.rs @@ -272,7 +272,6 @@ impl pallet_funding::Config for TestRuntime { type Randomness = RandomnessCollectiveFlip; type RemainderFundingDuration = RemainderFundingDuration; type RuntimeEvent = RuntimeEvent; - type StorageItemId = u32; type StringLimit = ConstU32<64>; type SuccessToSettlementTime = SuccessToSettlementTime; type TreasuryAccount = TreasuryAccount; diff --git a/pallets/funding/src/tests.rs b/pallets/funding/src/tests.rs index 27b30c114..7db1f447a 100644 --- a/pallets/funding/src/tests.rs +++ b/pallets/funding/src/tests.rs @@ -29,7 +29,7 @@ use frame_support::{ Mutate as FungiblesMutate, }, tokens::Balance as BalanceT, - OnFinalize, OnIdle, OnInitialize, + Get, OnFinalize, OnIdle, OnInitialize, }, weights::Weight, }; @@ -121,7 +121,7 @@ pub struct BidInfoFilter, } type BidInfoFilterOf = BidInfoFilter< - ::StorageItemId, + u32, ::ProjectIdentifier, BalanceOf, PriceOf, @@ -236,7 +236,6 @@ const USDT_STATEMINT_ID: AssetId = 1984u32; const USDT_UNIT: u128 = 10_000_000_000_u128; pub const US_DOLLAR: u128 = 1_0_000_000_000; -pub const US_CENT: u128 = 0_0_100_000_000; const METADATA: &str = r#" { @@ -1275,7 +1274,7 @@ mod defaults { pub mod helper_functions { use super::*; - + pub fn get_ed() -> BalanceOf { ::ExistentialDeposit::get() } @@ -1315,10 +1314,7 @@ pub mod helper_functions { let final_price = if bid.price < price { bid.price } else { price }; let usd_ticket_size = final_price.saturating_mul_int(bid.amount); - let usd_bond = bid - .multiplier - .calculate_bonding_requirement::(usd_ticket_size) - .unwrap(); + let usd_bond = bid.multiplier.calculate_bonding_requirement::(usd_ticket_size).unwrap(); let plmc_bond = plmc_price.reciprocal().unwrap().saturating_mul_int(usd_bond); output.push((bid.bidder, plmc_bond)); } @@ -1344,10 +1340,7 @@ pub mod helper_functions { let mut output = UserToPLMCBalance::new(); for cont in contributions { let usd_ticket_size = token_usd_price.saturating_mul_int(cont.amount); - let usd_bond = cont - .multiplier - .calculate_bonding_requirement::(usd_ticket_size) - .unwrap(); + let usd_bond = cont.multiplier.calculate_bonding_requirement::(usd_ticket_size).unwrap(); let plmc_bond = plmc_price.reciprocal().unwrap().saturating_mul_int(usd_bond); output.push((cont.contributor, plmc_bond)); } @@ -2879,13 +2872,7 @@ mod auction_round_success { 10u8.try_into().unwrap(), AcceptedFundingAsset::USDT, ), - TestBid::new( - BIDDER_3, - 20_000 * ASSET_UNIT, - 17.into(), - 2u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestBid::new(BIDDER_3, 20_000 * ASSET_UNIT, 17.into(), 2u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestBid::new( BIDDER_4, 88_000 * ASSET_UNIT, @@ -3923,10 +3910,10 @@ mod community_round_success { assert_eq!(community_funding_project.get_project_details().status, ProjectStatus::FundingSuccessful); let reserved_plmc = plmc_fundings.swap_remove(0).1; - let remaining_plmc: Balance = plmc_fundings.iter().fold(0_u128, |acc, (_, amount)| acc + amount); + let remaining_plmc: BalanceOf = plmc_fundings.iter().fold(0_u128, |acc, (_, amount)| acc + amount); let actual_funding_transferred = statemint_asset_fundings.swap_remove(0).1; - let remaining_statemint_assets: Balance = + let remaining_statemint_assets: BalanceOf = statemint_asset_fundings.iter().fold(0_u128, |acc, (_, amount, _)| acc + amount); test_env.do_free_plmc_assertions(vec![(BOB, remaining_plmc)]); @@ -4708,13 +4695,7 @@ mod community_round_success { 10u8.try_into().unwrap(), AcceptedFundingAsset::USDT, ), - TestBid::new( - BIDDER_3, - 20_000 * ASSET_UNIT, - 17.into(), - 2u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestBid::new(BIDDER_3, 20_000 * ASSET_UNIT, 17.into(), 2u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestBid::new( BIDDER_4, 88_000 * ASSET_UNIT, @@ -5005,12 +4986,7 @@ mod community_round_failure { let bids = generate_bids_from_total_usd(project.total_allocation_size / 2, project.minimum_price); let community_contributions = vec![ - TestContribution::new( - BUYER_1, - 1_000 * ASSET_UNIT, - 2u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestContribution::new(BUYER_1, 1_000 * ASSET_UNIT, 2u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_2, 500 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_3, 73 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), ]; @@ -5126,12 +5102,7 @@ mod community_round_failure { let bids = generate_bids_from_total_usd(project.total_allocation_size / 2, project.minimum_price); let community_contributions = vec![ - TestContribution::new( - BUYER_1, - 1_000 * ASSET_UNIT, - 2u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestContribution::new(BUYER_1, 1_000 * ASSET_UNIT, 2u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_2, 500 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_3, 73 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), ]; @@ -5277,12 +5248,7 @@ mod community_round_failure { let bids = generate_bids_from_total_usd(project.total_allocation_size / 2, project.minimum_price); let community_contributions = vec![ - TestContribution::new( - BUYER_1, - 1_000 * ASSET_UNIT, - 2u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestContribution::new(BUYER_1, 1_000 * ASSET_UNIT, 2u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_2, 500 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_3, 73 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), ]; @@ -5668,10 +5634,10 @@ mod remainder_round_success { assert_eq!(remainder_funding_project.get_project_details().status, ProjectStatus::FundingSuccessful); let reserved_plmc = plmc_fundings.swap_remove(0).1; - let remaining_plmc: Balance = plmc_fundings.iter().fold(0_u128, |acc, (_, amount)| acc + amount); + let remaining_plmc: BalanceOf = plmc_fundings.iter().fold(0_u128, |acc, (_, amount)| acc + amount); let actual_funding_transferred = statemint_asset_fundings.swap_remove(0).1; - let remaining_statemint_assets: Balance = + let remaining_statemint_assets: BalanceOf = statemint_asset_fundings.iter().fold(0_u128, |acc, (_, amount, _)| acc + amount); test_env.do_free_plmc_assertions(vec![(BOB, remaining_plmc)]); @@ -6682,28 +6648,13 @@ mod remainder_round_failure { let bids = generate_bids_from_total_usd(project.total_allocation_size / 2, project.minimum_price); let community_contributions = vec![ - TestContribution::new( - BUYER_1, - 1_000 * ASSET_UNIT, - 2u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestContribution::new(BUYER_1, 1_000 * ASSET_UNIT, 2u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_2, 500 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_3, 73 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), ]; let remainder_contributions = vec![ - TestContribution::new( - EVALUATOR_1, - 250 * ASSET_UNIT, - 1u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), - TestContribution::new( - BIDDER_1, - 130_400 * ASSET_UNIT, - 3u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestContribution::new(EVALUATOR_1, 250 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), + TestContribution::new(BIDDER_1, 130_400 * ASSET_UNIT, 3u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_1, 42 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), ]; @@ -6806,28 +6757,13 @@ mod remainder_round_failure { let bids = generate_bids_from_total_usd(project.total_allocation_size / 2, project.minimum_price); let community_contributions = vec![ - TestContribution::new( - BUYER_1, - 1_000 * ASSET_UNIT, - 2u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestContribution::new(BUYER_1, 1_000 * ASSET_UNIT, 2u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_2, 500 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_3, 73 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), ]; let remainder_contributions = vec![ - TestContribution::new( - EVALUATOR_1, - 250 * ASSET_UNIT, - 1u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), - TestContribution::new( - BIDDER_1, - 130_400 * ASSET_UNIT, - 3u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestContribution::new(EVALUATOR_1, 250 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), + TestContribution::new(BIDDER_1, 130_400 * ASSET_UNIT, 3u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_1, 42 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), ]; @@ -6962,28 +6898,13 @@ mod remainder_round_failure { let bids = generate_bids_from_total_usd(project.total_allocation_size / 2, project.minimum_price); let community_contributions = vec![ - TestContribution::new( - BUYER_1, - 1_000 * ASSET_UNIT, - 2u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestContribution::new(BUYER_1, 1_000 * ASSET_UNIT, 2u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_2, 500 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_3, 73 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), ]; let remainder_contributions = vec![ - TestContribution::new( - EVALUATOR_1, - 250 * ASSET_UNIT, - 1u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), - TestContribution::new( - BIDDER_1, - 130_400 * ASSET_UNIT, - 3u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestContribution::new(EVALUATOR_1, 250 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), + TestContribution::new(BIDDER_1, 130_400 * ASSET_UNIT, 3u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_1, 42 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), ]; @@ -7021,12 +6942,7 @@ mod remainder_round_failure { 3u8.try_into().unwrap(), AcceptedFundingAsset::USDT, ), - TestContribution::new( - BUYER_1, - 42 * ASSET_UNIT, - 1u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestContribution::new(BUYER_1, 42 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), ], final_price, ); @@ -7099,28 +7015,13 @@ mod remainder_round_failure { let bids = generate_bids_from_total_usd(project.total_allocation_size / 2, project.minimum_price); let community_contributions = vec![ - TestContribution::new( - BUYER_1, - 1_000 * ASSET_UNIT, - 2u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestContribution::new(BUYER_1, 1_000 * ASSET_UNIT, 2u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_2, 500 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_3, 73 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), ]; let remainder_contributions = vec![ - TestContribution::new( - EVALUATOR_1, - 250 * ASSET_UNIT, - 1u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), - TestContribution::new( - BIDDER_1, - 130_400 * ASSET_UNIT, - 3u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestContribution::new(EVALUATOR_1, 250 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), + TestContribution::new(BIDDER_1, 130_400 * ASSET_UNIT, 3u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestContribution::new(BUYER_1, 42 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), ]; @@ -7158,12 +7059,7 @@ mod remainder_round_failure { 3u8.try_into().unwrap(), AcceptedFundingAsset::USDT, ), - TestContribution::new( - BUYER_1, - 42 * ASSET_UNIT, - 1u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestContribution::new(BUYER_1, 42 * ASSET_UNIT, 1u8.try_into().unwrap(), AcceptedFundingAsset::USDT), ], final_price, ); @@ -7638,34 +7534,10 @@ mod funding_end { 2u8.try_into().unwrap(), AcceptedFundingAsset::USDT, ), - TestBid::new( - BIDDER_4, - 20_000 * ASSET_UNIT, - 17.into(), - 3u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), - TestBid::new( - BIDDER_5, - 9_000 * ASSET_UNIT, - 18.into(), - 19u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), - TestBid::new( - BIDDER_6, - 1_000 * ASSET_UNIT, - 18.into(), - 20u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), - TestBid::new( - BIDDER_7, - 8_000 * ASSET_UNIT, - 18.into(), - 24u8.try_into().unwrap(), - AcceptedFundingAsset::USDT, - ), + TestBid::new(BIDDER_4, 20_000 * ASSET_UNIT, 17.into(), 3u8.try_into().unwrap(), AcceptedFundingAsset::USDT), + TestBid::new(BIDDER_5, 9_000 * ASSET_UNIT, 18.into(), 19u8.try_into().unwrap(), AcceptedFundingAsset::USDT), + TestBid::new(BIDDER_6, 1_000 * ASSET_UNIT, 18.into(), 20u8.try_into().unwrap(), AcceptedFundingAsset::USDT), + TestBid::new(BIDDER_7, 8_000 * ASSET_UNIT, 18.into(), 24u8.try_into().unwrap(), AcceptedFundingAsset::USDT), TestBid::new( BIDDER_8, 68_000 * ASSET_UNIT, diff --git a/pallets/sandbox/src/lib.rs b/pallets/sandbox/src/lib.rs index bd135a9f8..c64f39247 100644 --- a/pallets/sandbox/src/lib.rs +++ b/pallets/sandbox/src/lib.rs @@ -16,7 +16,7 @@ pub mod pallet { use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; use funding::AcceptedFundingAsset; - use pallet_funding::{MultiplierOf}; + use pallet_funding::MultiplierOf; #[pallet::pallet] pub struct Pallet(_); diff --git a/runtimes/standalone/src/lib.rs b/runtimes/standalone/src/lib.rs index 903c1d399..a4e181c89 100644 --- a/runtimes/standalone/src/lib.rs +++ b/runtimes/standalone/src/lib.rs @@ -387,7 +387,6 @@ impl pallet_funding::Config for Runtime { type Randomness = Random; type RemainderFundingDuration = RemainderFundingDuration; type RuntimeEvent = RuntimeEvent; - type StorageItemId = u128; type StringLimit = ConstU32<64>; type SuccessToSettlementTime = SuccessToSettlementTime; type TreasuryAccount = TreasuryAccount; diff --git a/runtimes/testnet/src/lib.rs b/runtimes/testnet/src/lib.rs index 0b73d880d..6658797d6 100644 --- a/runtimes/testnet/src/lib.rs +++ b/runtimes/testnet/src/lib.rs @@ -514,7 +514,6 @@ impl pallet_funding::Config for Runtime { type Randomness = Random; type RemainderFundingDuration = RemainderFundingDuration; type RuntimeEvent = RuntimeEvent; - type StorageItemId = u128; type StringLimit = ConstU32<64>; type SuccessToSettlementTime = SuccessToSettlementTime; type TreasuryAccount = TreasuryAccount;