diff --git a/pallets/bidding/src/functions.rs b/pallets/bidding/src/functions.rs index 4bbd7d74..f1d38e70 100644 --- a/pallets/bidding/src/functions.rs +++ b/pallets/bidding/src/functions.rs @@ -1,7 +1,7 @@ pub use super::*; use rand::Rng; use rand::distributions::Slice; -use sp_runtime::BoundedVec; +use sp_runtime::{BoundedVec,Percent}; use frame_support::pallet_prelude::ConstU32; use Onboarding::Zero; @@ -9,8 +9,10 @@ use Onboarding::Zero; impl Pallet { - pub fn process(){ + pub fn process(collection_id: T::NftCollectionId, item_id: T::NftItemId){ //get asset price + let asset = Onboarding::Pallet::::houses(collection_id,item_id).unwrap(); + let asset_price = asset.price.unwrap(); //Max contribution from asset Price //Min contribution from asset price @@ -19,9 +21,11 @@ impl Pallet { Roles::InvestorLog::::iter().map(|x| x.0).collect_into(&mut investors); investors.retain(|x|{ let status = Houses::Pallet::::contributions(x.clone()).unwrap(); - let contribution = status.contributed_balance; - //user contributed more than 2x_min_contribution - contribution > Zero::zero() //should be minimun contribution calculated from asset price. + let contribution0 = Self::hfund_bal_to_u128(status.contributed_balance).unwrap(); + let contribution = Self::u128_to_onboarding_bal(contribution0).unwrap(); + //user contributed more than 5% of asset_price + contribution > Percent::from_percent(5) * asset_price //should be minimun contribution calculated from asset price. + //true }); @@ -30,4 +34,17 @@ impl Pallet { //let inv:BoundedVec> = BoundedVec::truncate_from(inv_dist); } -} \ No newline at end of file + // Conversion of BalanceOf to u128 + pub fn hfund_bal_to_u128(input: Houses::BalanceOf) -> Option { + input.try_into().ok() + } + + // Conversion of BalanceOf to u128 + pub fn u128_to_onboarding_bal(input: u128) -> Option> { + input.try_into().ok() + } + + + +} + diff --git a/pallets/bidding/src/lib.rs b/pallets/bidding/src/lib.rs index 04c06b95..46d10e09 100644 --- a/pallets/bidding/src/lib.rs +++ b/pallets/bidding/src/lib.rs @@ -19,6 +19,7 @@ pub use pallet_onboarding as Onboarding; pub use pallet_roles as Roles; pub use pallet_housing_fund as Houses; pub use pallet_finalizer as Finalizer; +pub use pallet_nft as Nft; // All pallet logic is defined in its own module and must be annotated by the `pallet` attribute. @@ -43,7 +44,8 @@ pub mod pallet { pub trait Config: frame_system::Config + Roles::Config + Onboarding::Config - + Houses::Config { + + Houses::Config + + Nft::Config { /// The overarching runtime event type. type RuntimeEvent: From> + IsType<::RuntimeEvent>; diff --git a/pallets/bidding/src/types.rs b/pallets/bidding/src/types.rs index 9b23fc8d..7d25cc37 100644 --- a/pallets/bidding/src/types.rs +++ b/pallets/bidding/src/types.rs @@ -17,6 +17,8 @@ pub use scale_info::{prelude::vec, TypeInfo}; pub use serde::{Deserialize, Serialize}; pub type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; + <::Currency as Currency<::AccountId>>::Balance; +pub type BalanceOf0 = +<::LocalCurrency as Currency<::AccountId>>::Balance; pub type AccountIdOf = ::AccountId; pub type BlockNumberOf = BlockNumberFor; \ No newline at end of file diff --git a/pallets/onboarding/src/lib.rs b/pallets/onboarding/src/lib.rs index 1420b31c..9544f55a 100644 --- a/pallets/onboarding/src/lib.rs +++ b/pallets/onboarding/src/lib.rs @@ -96,7 +96,8 @@ pub mod pallet { { /// Because this pallet emits events, it depends on the runtime's definition of an event. type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type Currency: ReservableCurrency; + type Currency: ReservableCurrency + + IsType<::LocalCurrency>; type Prop: Parameter + UnfilteredDispatchable::RuntimeOrigin> + From> diff --git a/pallets/onboarding/src/types.rs b/pallets/onboarding/src/types.rs index fbd79578..861dcd06 100644 --- a/pallets/onboarding/src/types.rs +++ b/pallets/onboarding/src/types.rs @@ -34,7 +34,6 @@ pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; pub type CallOf = ::RuntimeCall; pub type BoundedCallOf = Bounded>; -type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; pub use Nft::ItemInfoOf;