Skip to content

Commit

Permalink
Asset price is used to calculate minimum contribution to asset purchase
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkazu committed Oct 17, 2023
1 parent 856699f commit b5a8632
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
29 changes: 23 additions & 6 deletions pallets/bidding/src/functions.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
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;



impl<T: Config> Pallet<T> {

pub fn process(){
pub fn process(collection_id: T::NftCollectionId, item_id: T::NftItemId){
//get asset price
let asset = Onboarding::Pallet::<T>::houses(collection_id,item_id).unwrap();
let asset_price = asset.price.unwrap();
//Max contribution from asset Price
//Min contribution from asset price

Expand All @@ -19,9 +21,11 @@ impl<T: Config> Pallet<T> {
Roles::InvestorLog::<T>::iter().map(|x| x.0).collect_into(&mut investors);
investors.retain(|x|{
let status = Houses::Pallet::<T>::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

});

Expand All @@ -30,4 +34,17 @@ impl<T: Config> Pallet<T> {
//let inv:BoundedVec<T,ConstU32<5>> = BoundedVec::truncate_from(inv_dist);
}

}
// Conversion of BalanceOf<T> to u128
pub fn hfund_bal_to_u128(input: Houses::BalanceOf<T>) -> Option<u128> {
input.try_into().ok()
}

// Conversion of BalanceOf<T> to u128
pub fn u128_to_onboarding_bal(input: u128) -> Option<Onboarding::BalanceOf<T>> {
input.try_into().ok()
}



}

4 changes: 3 additions & 1 deletion pallets/bidding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

Expand Down
4 changes: 3 additions & 1 deletion pallets/bidding/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub use scale_info::{prelude::vec, TypeInfo};
pub use serde::{Deserialize, Serialize};

pub type BalanceOf<T> =
<<T as Roles::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
<<T as Onboarding::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub type BalanceOf0<T> =
<<T as Houses::Config>::LocalCurrency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type BlockNumberOf<T> = BlockNumberFor<T>;
3 changes: 2 additions & 1 deletion pallets/onboarding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type Currency: ReservableCurrency<Self::AccountId>;
type Currency: ReservableCurrency<Self::AccountId>
+ IsType<<Self as HousingFund::Config>::LocalCurrency>;
type Prop: Parameter
+ UnfilteredDispatchable<RuntimeOrigin = <Self as frame_system::Config>::RuntimeOrigin>
+ From<Call<Self>>
Expand Down
1 change: 0 additions & 1 deletion pallets/onboarding/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub type BalanceOf<T> =
<<T as DEM::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub type CallOf<T> = <T as frame_system::Config>::RuntimeCall;
pub type BoundedCallOf<T> = Bounded<CallOf<T>>;
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;

pub use Nft::ItemInfoOf;

Expand Down

0 comments on commit b5a8632

Please sign in to comment.