Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
pallets
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Nov 6, 2023
1 parent f1b9d45 commit 9b54e37
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 38 deletions.
6 changes: 3 additions & 3 deletions pallets/posts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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<T>,
space_id_opt: Option<SpaceId>,
Expand Down Expand Up @@ -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<T>,
post_id: PostId,
Expand Down
28 changes: 26 additions & 2 deletions pallets/project-tips/src/extras.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::*;

use types::{TippingName, TippingValue};

impl<T: Config> Pallet<T> {

pub(super) fn get_phase_data() -> PhaseData<T> {
T::SchellingGameSharedSource::create_phase_data(50, 5, 3, 100, (100, 100))
}
Expand All @@ -23,4 +22,29 @@ impl<T: Config> Pallet<T> {
pub(super) fn u64_to_block_saturated(input: u64) -> BlockNumberOf<T> {
input.saturated_into::<BlockNumberOf<T>>()
}

pub(super) fn value_of_tipping_name(tipping: TippingName) -> TippingValue<BalanceOf<T>> {
match tipping {
TippingName::SmallTipper => TippingValue {
max_tipping_value: 10_000u64.saturated_into::<BalanceOf<T>>(),
stake_required: 10u64.saturated_into::<BalanceOf<T>>(),
},
TippingName::BigTipper => TippingValue {
max_tipping_value: 100_000u64.saturated_into::<BalanceOf<T>>(),
stake_required: 50u64.saturated_into::<BalanceOf<T>>(),
},
TippingName::SmallSpender => TippingValue {
max_tipping_value: 1_000_000u64.saturated_into::<BalanceOf<T>>(),
stake_required: 100u64.saturated_into::<BalanceOf<T>>(),
},
TippingName::MediumSpender => TippingValue {
max_tipping_value: 10_000_000u64.saturated_into::<BalanceOf<T>>(),
stake_required: 200u64.saturated_into::<BalanceOf<T>>(),
},
TippingName::BigSpender => TippingValue {
max_tipping_value: 100_000_000u64.saturated_into::<BalanceOf<T>>(),
stake_required: 500u64.saturated_into::<BalanceOf<T>>(),
},
}
}
}
41 changes: 24 additions & 17 deletions pallets/project-tips/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -45,7 +45,7 @@ pub type BlockNumberOf<T> = <T as frame_system::Config>::BlockNumber;
pub type SumTreeNameType<T> = SumTreeName<AccountIdOf<T>, BlockNumberOf<T>>;
type DeparmentId = u128;

#[frame_support::pallet]
#[frame_support::pallet(dev_mode)]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
Expand Down Expand Up @@ -133,23 +133,29 @@ pub mod pallet {
impl<T: Config> Pallet<T> {

#[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<T>,
department_id: DeparmentId,
deposit: BalanceOf<T>,
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 _ = <T as pallet::Config>::Currency::withdraw(
&who,
deposit,
tipping_value.stake_required,
WithdrawReasons::TRANSFER,
ExistenceRequirement::AllowDeath,
)?;
let stake = DepartmentStakeBalance::<T>::get(department_id);
let total_balance = stake.saturating_add(deposit);
DepartmentStakeBalance::<T>::insert(department_id, total_balance);
// let stake = DepartmentStakeBalance::<T>::get(department_id);
// let total_balance = stake.saturating_add(deposit);
// DepartmentStakeBalance::<T>::insert(department_id, total_balance);

// emit event
Ok(())
Expand All @@ -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<T>,
department_id: DeparmentId,

) -> DispatchResult {
let who = ensure_signed(origin)?;

Expand Down Expand Up @@ -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<T>,
department_id: DeparmentId,
Expand All @@ -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<T>, department_id: DeparmentId) -> DispatchResult {
let _who = ensure_signed(origin)?;

Expand All @@ -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<T>,
department_id: DeparmentId,
Expand All @@ -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<T>, department_id: DeparmentId) -> DispatchResult {
let who = ensure_signed(origin)?;
let pe_block_number = <ValidationDepartmentBlock<T>>::get(department_id);
Expand All @@ -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<T>,
department_id: DeparmentId,
Expand All @@ -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<T>,
department_id: DeparmentId,
Expand All @@ -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<T>, department_id: DeparmentId) -> DispatchResult {
let _who = ensure_signed(origin)?;
let pe_block_number = <ValidationDepartmentBlock<T>>::get(department_id);
Expand Down
27 changes: 11 additions & 16 deletions pallets/project-tips/src/types.rs
Original file line number Diff line number Diff line change
@@ -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<Balance> {
pub max_tipping_value: Balance,
pub stake_required: Balance,
}

0 comments on commit 9b54e37

Please sign in to comment.