diff --git a/pallets/posts/src/lib.rs b/pallets/posts/src/lib.rs index 8f80a08..6a3d68e 100644 --- a/pallets/posts/src/lib.rs +++ b/pallets/posts/src/lib.rs @@ -33,7 +33,7 @@ use pallet_support::{ WhoAndWhen, WhoAndWhenOf, }; -#[frame_support::pallet] +#[frame_support::pallet(dev_mode)] pub mod pallet { use super::*; use frame_support::pallet_prelude::*; @@ -188,7 +188,7 @@ pub mod pallet { /// Create post /// Who can post, does kyc validation required?? #[pallet::call_index(0)] - #[pallet::weight(Weight::from_parts(10_000, u64::MAX) + T::DbWeight::get().writes(1))] + #[pallet::weight(0)] pub fn create_post( origin: OriginFor, space_id_opt: Option, @@ -221,7 +221,7 @@ pub mod pallet { } #[pallet::call_index(1)] - #[pallet::weight(Weight::from_parts(10_000, u64::MAX) + T::DbWeight::get().writes(1))] + #[pallet::weight(0)] pub fn update_post( origin: OriginFor, post_id: PostId, diff --git a/pallets/project-tips/src/extras.rs b/pallets/project-tips/src/extras.rs index 90ea0ea..85de13f 100644 --- a/pallets/project-tips/src/extras.rs +++ b/pallets/project-tips/src/extras.rs @@ -1,8 +1,7 @@ use crate::*; - +use types::{TippingName, TippingValue}; impl Pallet { - pub(super) fn get_phase_data() -> PhaseData { T::SchellingGameSharedSource::create_phase_data(50, 5, 3, 100, (100, 100)) } @@ -23,4 +22,29 @@ impl Pallet { pub(super) fn u64_to_block_saturated(input: u64) -> BlockNumberOf { input.saturated_into::>() } + + pub(super) fn value_of_tipping_name(tipping: TippingName) -> TippingValue> { + match tipping { + TippingName::SmallTipper => TippingValue { + max_tipping_value: 10_000u64.saturated_into::>(), + stake_required: 10u64.saturated_into::>(), + }, + TippingName::BigTipper => TippingValue { + max_tipping_value: 100_000u64.saturated_into::>(), + stake_required: 50u64.saturated_into::>(), + }, + TippingName::SmallSpender => TippingValue { + max_tipping_value: 1_000_000u64.saturated_into::>(), + stake_required: 100u64.saturated_into::>(), + }, + TippingName::MediumSpender => TippingValue { + max_tipping_value: 10_000_000u64.saturated_into::>(), + stake_required: 200u64.saturated_into::>(), + }, + TippingName::BigSpender => TippingValue { + max_tipping_value: 100_000_000u64.saturated_into::>(), + stake_required: 500u64.saturated_into::>(), + }, + } + } } diff --git a/pallets/project-tips/src/lib.rs b/pallets/project-tips/src/lib.rs index 07e347f..8da760e 100644 --- a/pallets/project-tips/src/lib.rs +++ b/pallets/project-tips/src/lib.rs @@ -24,7 +24,7 @@ use frame_support::sp_runtime::SaturatedConversion; use frame_support::sp_std::prelude::*; use frame_support::{ dispatch::{DispatchError, DispatchResult}, - ensure, fail, + ensure }; use frame_support::{ traits::{Currency, ExistenceRequirement, Get, ReservableCurrency, WithdrawReasons}, @@ -45,7 +45,7 @@ pub type BlockNumberOf = ::BlockNumber; pub type SumTreeNameType = SumTreeName, BlockNumberOf>; type DeparmentId = u128; -#[frame_support::pallet] +#[frame_support::pallet(dev_mode)] pub mod pallet { use super::*; use frame_support::pallet_prelude::*; @@ -133,23 +133,29 @@ pub mod pallet { impl Pallet { #[pallet::call_index(0)] - #[pallet::weight(Weight::from_parts(10_000, u64::MAX) + T::DbWeight::get().writes(1))] - pub fn add_department_stake( + #[pallet::weight(0)] + pub fn add_project_stake( origin: OriginFor, department_id: DeparmentId, - deposit: BalanceOf, + tipping_name: TippingName, ) -> DispatchResult { let who = ensure_signed(origin)?; + + let tipping_value = Self::value_of_tipping_name(tipping_name); + + + + // Check user has done kyc let _ = ::Currency::withdraw( &who, - deposit, + tipping_value.stake_required, WithdrawReasons::TRANSFER, ExistenceRequirement::AllowDeath, )?; - let stake = DepartmentStakeBalance::::get(department_id); - let total_balance = stake.saturating_add(deposit); - DepartmentStakeBalance::::insert(department_id, total_balance); + // let stake = DepartmentStakeBalance::::get(department_id); + // let total_balance = stake.saturating_add(deposit); + // DepartmentStakeBalance::::insert(department_id, total_balance); // emit event Ok(()) @@ -169,10 +175,11 @@ pub mod pallet { // } #[pallet::call_index(1)] - #[pallet::weight(Weight::from_parts(10_000, u64::MAX) + T::DbWeight::get().writes(1))] + #[pallet::weight(0)] pub fn apply_staking_period( origin: OriginFor, department_id: DeparmentId, + ) -> DispatchResult { let who = ensure_signed(origin)?; @@ -212,7 +219,7 @@ pub mod pallet { } #[pallet::call_index(2)] - #[pallet::weight(Weight::from_parts(10_000, u64::MAX) + T::DbWeight::get().writes(1))] + #[pallet::weight(0)] pub fn apply_jurors_positive_externality( origin: OriginFor, department_id: DeparmentId, @@ -238,7 +245,7 @@ pub mod pallet { } #[pallet::call_index(3)] - #[pallet::weight(Weight::from_parts(10_000, u64::MAX) + T::DbWeight::get().writes(1))] + #[pallet::weight(0)] pub fn pass_period(origin: OriginFor, department_id: DeparmentId) -> DispatchResult { let _who = ensure_signed(origin)?; @@ -257,7 +264,7 @@ pub mod pallet { } #[pallet::call_index(4)] - #[pallet::weight(Weight::from_parts(10_000, u64::MAX) + T::DbWeight::get().writes(1))] + #[pallet::weight(0)] pub fn draw_jurors_positive_externality( origin: OriginFor, department_id: DeparmentId, @@ -282,7 +289,7 @@ pub mod pallet { // Unstaking // Stop drawn juror to unstake ✔️ #[pallet::call_index(5)] - #[pallet::weight(Weight::from_parts(10_000, u64::MAX) + T::DbWeight::get().writes(1))] + #[pallet::weight(0)] pub fn unstaking(origin: OriginFor, department_id: DeparmentId) -> DispatchResult { let who = ensure_signed(origin)?; let pe_block_number = >::get(department_id); @@ -297,7 +304,7 @@ pub mod pallet { } #[pallet::call_index(6)] - #[pallet::weight(Weight::from_parts(10_000, u64::MAX) + T::DbWeight::get().writes(1))] + #[pallet::weight(0)] pub fn commit_vote( origin: OriginFor, department_id: DeparmentId, @@ -316,7 +323,7 @@ pub mod pallet { } #[pallet::call_index(7)] - #[pallet::weight(Weight::from_parts(10_000, u64::MAX) + T::DbWeight::get().writes(1))] + #[pallet::weight(0)] pub fn reveal_vote( origin: OriginFor, department_id: DeparmentId, @@ -339,7 +346,7 @@ pub mod pallet { } #[pallet::call_index(8)] - #[pallet::weight(Weight::from_parts(10_000, u64::MAX) + T::DbWeight::get().writes(1))] + #[pallet::weight(0)] pub fn get_incentives(origin: OriginFor, department_id: DeparmentId) -> DispatchResult { let _who = ensure_signed(origin)?; let pe_block_number = >::get(department_id); diff --git a/pallets/project-tips/src/types.rs b/pallets/project-tips/src/types.rs index 95f3a96..8556397 100644 --- a/pallets/project-tips/src/types.rs +++ b/pallets/project-tips/src/types.rs @@ -1,25 +1,20 @@ use super::*; use codec::{Decode, Encode, EncodeLike, MaxEncodedLen}; -use scale_info::TypeInfo; use frame_support::pallet_prelude::*; - - +use scale_info::TypeInfo; #[derive(Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, TypeInfo)] pub enum TippingName { - SmallTipper, - BigTipper, - SmallSpender, - MediumSpender, - BigSpender, + SmallTipper, + BigTipper, + SmallSpender, + MediumSpender, + BigSpender, } -fn max_value_of_tipping_name(tipping: TippingName) -> u32 { - match tipping { - TippingName::SmallTipper => 1_000, - TippingName::BigTipper => 10_000, - TippingName::SmallSpender => 100_000, - TippingName::MediumSpender => 1_000_000, - TippingName::BigSpender => 10_000_000, - } +#[derive(Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, TypeInfo)] +pub struct TippingValue { + pub max_tipping_value: Balance, + pub stake_required: Balance, } +