diff --git a/Cargo.lock b/Cargo.lock index af054d52..7e0f0526 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -999,6 +999,7 @@ dependencies = [ "pallet-bounties", "pallet-cacher", "pallet-cess-staking", + "pallet-cess-treasury", "pallet-child-bounties", "pallet-collective", "pallet-contracts", @@ -1026,7 +1027,6 @@ dependencies = [ "pallet-scheduler-credit", "pallet-session", "pallet-sminer", - "pallet-sminer-reward", "pallet-storage-handler", "pallet-sudo", "pallet-tee-worker", @@ -5830,6 +5830,7 @@ dependencies = [ "pallet-bags-list", "pallet-balances", "pallet-cess-staking", + "pallet-cess-treasury", "pallet-file-bank", "pallet-oss", "pallet-preimage", @@ -5837,7 +5838,6 @@ dependencies = [ "pallet-scheduler-credit", "pallet-session", "pallet-sminer", - "pallet-sminer-reward", "pallet-storage-handler", "pallet-tee-worker", "pallet-timestamp", @@ -5996,6 +5996,18 @@ dependencies = [ "substrate-test-utils", ] +[[package]] +name = "pallet-cess-treasury" +version = "0.7.4" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-child-bounties" version = "4.0.0-dev" @@ -6518,9 +6530,9 @@ dependencies = [ "log", "pallet-balances", "pallet-cess-staking", + "pallet-cess-treasury", "pallet-preimage", "pallet-scheduler", - "pallet-sminer-reward", "pallet-storage-handler", "pallet-tee-worker", "pallet-timestamp", @@ -6534,18 +6546,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-sminer-reward" -version = "0.7.4" -dependencies = [ - "frame-support", - "frame-system", - "parity-scale-codec", - "scale-info", - "sp-runtime", - "sp-std", -] - [[package]] name = "pallet-staking-reward-curve" version = "4.0.0-dev" @@ -6567,7 +6567,7 @@ dependencies = [ "frame-system", "log", "pallet-balances", - "pallet-sminer-reward", + "pallet-cess-treasury", "parity-scale-codec", "scale-info", "serde", diff --git a/c-pallets/audit/Cargo.toml b/c-pallets/audit/Cargo.toml index dbd829be..28637316 100644 --- a/c-pallets/audit/Cargo.toml +++ b/c-pallets/audit/Cargo.toml @@ -23,7 +23,7 @@ cp-bloom-filter = { path = '../../primitives/bloom-filter', default-features = f cp-scheduler-credit = { path = '../../primitives/scheduler-credit', default-features = false } cp-cess-common = { path = '../../primitives/common', default-features = false } cp-enclave-verify = { path = '../../primitives/enclave-verify', default-features = false } -pallet-sminer-reward = { default-features = false, path = "../sminer-reward" } +pallet-cess-treasury = { default-features = false, path = "../cess-treasury" } [dependencies.frame-benchmarking] default-features = false @@ -145,7 +145,7 @@ std = [ "pallet-tee-worker/std", "cp-cess-common/std", "cp-cess-common/std", - "pallet-sminer-reward/std", + "pallet-cess-treasury/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/c-pallets/sminer-reward/Cargo.toml b/c-pallets/cess-treasury/Cargo.toml similarity index 97% rename from c-pallets/sminer-reward/Cargo.toml rename to c-pallets/cess-treasury/Cargo.toml index 1e8598f8..e041a65c 100644 --- a/c-pallets/sminer-reward/Cargo.toml +++ b/c-pallets/cess-treasury/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pallet-sminer-reward" +name = "pallet-cess-treasury" authors = ["CESS LAB"] version = "0.7.4" edition = "2021" diff --git a/c-pallets/cess-treasury/src/lib.rs b/c-pallets/cess-treasury/src/lib.rs new file mode 100644 index 00000000..d6db3ed3 --- /dev/null +++ b/c-pallets/cess-treasury/src/lib.rs @@ -0,0 +1,239 @@ +#![cfg_attr(not(feature = "std"), no_std)] +use frame_support::{ + traits::{ + Currency, ReservableCurrency, WithdrawReasons, Imbalance, + ExistenceRequirement::KeepAlive, OnUnbalanced, + }, + dispatch::{DispatchResult}, PalletId, + pallet_prelude::{Weight, StorageValue, ValueQuery, Get, IsType}, +}; +// use sp_std::prelude::*; +use sp_runtime::{ + SaturatedConversion, + traits::{CheckedAdd, CheckedSub, AccountIdConversion}, +}; +use frame_system::{ + pallet_prelude::OriginFor, + ensure_signed, ensure_root, +}; + +pub use pallet::*; + +type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; + +type AccountOf = ::AccountId; + +pub type PositiveImbalanceOf = <::Currency as Currency< + ::AccountId, +>>::PositiveImbalance; + +type NegativeImbalanceOf = <::Currency as Currency< + ::AccountId, +>>::NegativeImbalance; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + + #[pallet::pallet] + pub struct Pallet(sp_std::marker::PhantomData); + + #[pallet::config] + pub trait Config: frame_system::Config { + /// The overarching event type. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + /// The currency trait. + type Currency: ReservableCurrency; + + type MinerRewardId: Get; + + type PunishTreasuryId: Get; + + type SpaceTreasuryId: Get; + + type BurnDestination: OnUnbalanced>; + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + Deposit { + balance: BalanceOf, + }, + } + + #[pallet::error] + pub enum Error { + Overflow, + } + + #[pallet::storage] + #[pallet::getter(fn currency_reward)] + pub(super) type CurrencyReward = StorageValue<_, BalanceOf, ValueQuery>; + + #[pallet::call] + impl Pallet { + #[pallet::call_index(0)] + // FIX ME! + #[pallet::weight(Weight::zero())] + pub fn send_funds_to_pid( + origin: OriginFor, + funds: BalanceOf, + ) -> DispatchResult { + let sender = ensure_signed(origin)?; + + Self::send_to_pid(sender, funds)?; + + Ok(()) + } + + #[pallet::call_index(1)] + // FIX ME! + #[pallet::weight(Weight::zero())] + pub fn send_funds_to_sid( + origin: OriginFor, + funds: BalanceOf, + ) -> DispatchResult { + let sender = ensure_signed(origin)?; + + Self::send_to_sid(sender, funds)?; + + Ok(()) + } + + #[pallet::call_index(2)] + // FIX ME! + #[pallet::weight(Weight::zero())] + pub fn pid_burn_funds( + origin: OriginFor, + burn_amount: BalanceOf, + ) -> DispatchResult { + let _ = ensure_root(origin)?; + + let pid = T::PunishTreasuryId::get().into_account_truncating(); + + let (debit, credit) = T::Currency::pair(burn_amount); + + T::BurnDestination::on_unbalanced(credit); + + if let Err(problem) = T::Currency::settle(&pid, debit, WithdrawReasons::TRANSFER, KeepAlive) { + drop(problem); + } + + Ok(()) + } + + #[pallet::call_index(3)] + // FIX ME! + #[pallet::weight(Weight::zero())] + pub fn sid_burn_funds( + origin: OriginFor, + burn_amount: BalanceOf, + ) -> DispatchResult { + let _ = ensure_root(origin)?; + + let sid = T::SpaceTreasuryId::get().into_account_truncating(); + + let (debit, credit) = T::Currency::pair(burn_amount); + + T::BurnDestination::on_unbalanced(credit); + + if let Err(problem) = T::Currency::settle(&sid, debit, WithdrawReasons::TRANSFER, KeepAlive) { + drop(problem); + } + + Ok(()) + } + } +} + +impl Pallet { + pub fn add_miner_reward_pool(amount: BalanceOf) -> DispatchResult { + >::mutate(|v| -> DispatchResult { + // The total issuance amount will not exceed u128::Max, so there is no overflow risk + *v = v.checked_add(&amount).ok_or(Error::::Overflow)?; + + Ok(()) + }) + } + + pub fn send_to_pid(acc: AccountOf, amount: BalanceOf) -> DispatchResult { + let pid = T::PunishTreasuryId::get().into_account_truncating(); + ::Currency::transfer(&acc, &pid, amount, KeepAlive) + } + + pub fn send_to_sid(acc: AccountOf, amount: BalanceOf) -> DispatchResult { + let sid = T::SpaceTreasuryId::get().into_account_truncating(); + ::Currency::transfer(&acc, &sid, amount, KeepAlive) + } +} + +pub trait RewardPool { + fn get_reward() -> Balance; + fn get_reward_128() -> u128; + fn add_reward(amount: Balance) -> DispatchResult; + fn sub_reward(amount: Balance) -> DispatchResult; + fn send_reward_to_miner(miner: AccountId, amount: Balance) -> DispatchResult; +} + +impl RewardPool, BalanceOf> for Pallet { + fn get_reward() -> BalanceOf { + >::get() + } + + fn get_reward_128() -> u128 { + >::get().saturated_into() + } + + fn add_reward(amount: BalanceOf) -> DispatchResult { + Self::add_miner_reward_pool(amount)?; + + Ok(()) + } + + fn sub_reward(amount: BalanceOf) -> DispatchResult { + >::mutate(|v| -> DispatchResult { + // The total issuance amount will not exceed u128::Max, so there is no overflow risk + *v = v.checked_sub(&amount).ok_or(Error::::Overflow)?; + + Ok(()) + })?; + + Ok(()) + } + + fn send_reward_to_miner(beneficiary: AccountOf, amount: BalanceOf) -> DispatchResult { + let reward_acc = T::MinerRewardId::get().into_account_truncating(); + ::Currency::transfer(&reward_acc, &beneficiary, amount, KeepAlive) + } +} + +pub trait TreasuryHandle { + fn send_to_pid(acc: AccountId, amount: Balance) -> DispatchResult; + fn send_to_sid(acc: AccountId, amount: Balance) -> DispatchResult; +} + +impl TreasuryHandle, BalanceOf> for Pallet { + fn send_to_pid(acc: AccountOf, amount: BalanceOf) -> DispatchResult { + Self::send_to_pid(acc, amount) + } + + fn send_to_sid(acc: AccountOf, amount: BalanceOf) -> DispatchResult { + Self::send_to_sid(acc, amount) + } +} + +impl OnUnbalanced> for Pallet { + fn on_nonzero_unbalanced(amount: NegativeImbalanceOf) { + let numeric_amount = amount.peek(); + + // Must resolve into existing but better to be safe. + let _ = T::Currency::resolve_creating(&T::MinerRewardId::get().into_account_truncating(), amount); + // The total issuance amount will not exceed u128::Max, so there is no overflow risk + Self::add_miner_reward_pool(numeric_amount).unwrap(); + + Self::deposit_event(Event::Deposit { balance: numeric_amount }); + } +} \ No newline at end of file diff --git a/c-pallets/file-bank/src/lib.rs b/c-pallets/file-bank/src/lib.rs index d6256793..5515c384 100755 --- a/c-pallets/file-bank/src/lib.rs +++ b/c-pallets/file-bank/src/lib.rs @@ -547,7 +547,8 @@ pub mod pallet { /// - `file_hash`: The unique hash identifier of the file to be transferred #[pallet::call_index(2)] #[transactional] - #[pallet::weight(1_000_000_000)] + /// FIX ME + #[pallet::weight(Weight::zero())] pub fn ownership_transfer( origin: OriginFor, target_brief: UserBrief, @@ -1185,7 +1186,7 @@ pub mod pallet { #[pallet::call_index(21)] #[transactional] - #[pallet::weight(10_000_000_000)] + #[pallet::weight(Weight::zero())] pub fn miner_clear_failed_count(origin: OriginFor) -> DispatchResult { let sender = ensure_signed(origin)?; diff --git a/c-pallets/sminer-reward/src/lib.rs b/c-pallets/sminer-reward/src/lib.rs deleted file mode 100644 index 3eb5b6cc..00000000 --- a/c-pallets/sminer-reward/src/lib.rs +++ /dev/null @@ -1,81 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] -use frame_support::{ - traits::{ - Currency, ReservableCurrency, - }, - dispatch::{DispatchResult}, - pallet_prelude::{StorageValue, ValueQuery}, -}; -// use sp_std::prelude::*; -use sp_runtime::{ - SaturatedConversion, - traits::{CheckedAdd, CheckedSub}, -}; -// use frame_system::pallet_prelude::*; - -pub use pallet::*; - -type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; - -#[frame_support::pallet] -pub mod pallet { - use super::*; - - #[pallet::pallet] - pub struct Pallet(sp_std::marker::PhantomData); - - #[pallet::config] - pub trait Config: frame_system::Config { - /// The currency trait. - type Currency: ReservableCurrency; - } - - #[pallet::error] - pub enum Error { - Overflow, - } - - #[pallet::storage] - #[pallet::getter(fn currency_reward)] - pub(super) type CurrencyReward = StorageValue<_, BalanceOf, ValueQuery>; -} - -pub trait RewardPool { - fn get_reward() -> Balance; - fn get_reward_128() -> u128; - fn add_reward(amount: Balance) -> DispatchResult; - fn sub_reward(amount: Balance) -> DispatchResult; -} - -impl RewardPool> for Pallet { - fn get_reward() -> BalanceOf { - >::get() - } - - fn get_reward_128() -> u128 { - >::get().saturated_into() - } - - fn add_reward(amount: BalanceOf) -> DispatchResult { - >::mutate(|v| -> DispatchResult { - // The total issuance amount will not exceed u128::Max, so there is no overflow risk - *v = v.checked_add(&amount).ok_or(Error::::Overflow)?; - - Ok(()) - })?; - - Ok(()) - } - - fn sub_reward(amount: BalanceOf) -> DispatchResult { - >::mutate(|v| -> DispatchResult { - // The total issuance amount will not exceed u128::Max, so there is no overflow risk - *v = v.checked_sub(&amount).ok_or(Error::::Overflow)?; - - Ok(()) - })?; - - Ok(()) - } -} \ No newline at end of file diff --git a/c-pallets/sminer/Cargo.toml b/c-pallets/sminer/Cargo.toml index ab1ca193..3b28eb66 100644 --- a/c-pallets/sminer/Cargo.toml +++ b/c-pallets/sminer/Cargo.toml @@ -22,7 +22,7 @@ pallet-preimage = { version = "4.0.0-dev", default-features = false, git = 'http #local crate pallet-tee-worker = { default-features = false, path = '../tee-worker' } pallet-storage-handler = { default-features = false, path = '../storage-handler' } -pallet-sminer-reward = { default-features = false, path = "../sminer-reward" } +pallet-cess-treasury = { default-features = false, path = "../cess-treasury" } pallet-cess-staking = { default-features = false, path = '../staking' } cp-enclave-verify = { path = '../../primitives/enclave-verify', default-features = false } cp-bloom-filter = { path = '../../primitives/bloom-filter', default-features = false } @@ -114,7 +114,7 @@ std = [ "pallet-scheduler/std", "frame-benchmarking/std", "cp-cess-common/std", - "pallet-sminer-reward/std", + "pallet-cess-treasury/std", ] runtime-benchmarks = [ diff --git a/c-pallets/sminer/src/functions.rs b/c-pallets/sminer/src/functions.rs index 1cbac229..18a032e6 100644 --- a/c-pallets/sminer/src/functions.rs +++ b/c-pallets/sminer/src/functions.rs @@ -39,18 +39,14 @@ impl Pallet { pub(super) fn deposit_punish(miner: &AccountOf, punish_amount: BalanceOf) -> DispatchResult { >::try_mutate(miner, |miner_info_opt| -> DispatchResult { let miner_info = miner_info_opt.as_mut().ok_or(Error::::NotMiner)?; - - let reward_pot = T::PalletId::get().into_account_truncating(); if miner_info.collaterals > punish_amount { T::Currency::unreserve(miner, punish_amount); - T::Currency::transfer(miner, &reward_pot, punish_amount, KeepAlive)?; - T::RewardPool::add_reward(punish_amount)?; + T::CessTreasuryHandle::send_to_pid(miner.clone(), punish_amount)?; miner_info.collaterals = miner_info.collaterals.checked_sub(&punish_amount).ok_or(Error::::Overflow)?; } else { T::Currency::unreserve(miner, miner_info.collaterals); - T::Currency::transfer(miner, &reward_pot, miner_info.collaterals, KeepAlive)?; - T::RewardPool::add_reward(miner_info.collaterals)?; + T::CessTreasuryHandle::send_to_pid(miner.clone(), miner_info.collaterals)?; miner_info.collaterals = BalanceOf::::zero(); miner_info.debt = punish_amount.checked_sub(&miner_info.collaterals).ok_or(Error::::Overflow)?; } diff --git a/c-pallets/sminer/src/lib.rs b/c-pallets/sminer/src/lib.rs index 25cd6581..2467fc2f 100644 --- a/c-pallets/sminer/src/lib.rs +++ b/c-pallets/sminer/src/lib.rs @@ -23,7 +23,7 @@ use frame_support::{ traits::{ Currency, ExistenceRequirement::KeepAlive, - Get, Imbalance, OnUnbalanced, ReservableCurrency, + Get, ReservableCurrency, schedule::{self, Anon as ScheduleAnon, DispatchTime, Named as ScheduleNamed}, }, dispatch::{Dispatchable, DispatchResult}, @@ -43,7 +43,7 @@ use cp_enclave_verify::verify_rsa; use pallet_tee_worker::TeeWorkerHandler; use cp_bloom_filter::BloomFilter; use pallet_storage_handler::StorageHandle; -use pallet_sminer_reward::RewardPool; +use pallet_cess_treasury::{RewardPool, TreasuryHandle}; pub use pallet::*; @@ -71,9 +71,6 @@ pub use weights::WeightInfo; type AccountOf = ::AccountId; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; -type NegativeImbalanceOf = <::Currency as Currency< - ::AccountId, ->>::NegativeImbalance; type BlockNumberOf = ::BlockNumber; #[frame_support::pallet] @@ -95,9 +92,6 @@ pub mod pallet { type TeeWorkerHandler: TeeWorkerHandler; /// The treasury's pallet id, used for deriving its sovereign account ID. #[pallet::constant] - type PalletId: Get; - /// The treasury's pallet id, used for deriving its sovereign account ID. - #[pallet::constant] type FaucetId: Get; #[pallet::constant] @@ -108,7 +102,9 @@ pub mod pallet { /// The WeightInfo. type WeightInfo: WeightInfo; - type RewardPool: RewardPool>; + type RewardPool: RewardPool, BalanceOf>; + + type CessTreasuryHandle: TreasuryHandle, BalanceOf>; type FScheduler: ScheduleNamed; @@ -414,10 +410,10 @@ pub mod pallet { if miner_info.debt > collaterals { miner_info.debt = miner_info.debt.checked_sub(&collaterals).ok_or(Error::::Overflow)?; remaining = BalanceOf::::zero(); - T::RewardPool::add_reward(collaterals)?; + T::CessTreasuryHandle::send_to_pid(sender.clone(), collaterals)?; } else { remaining = remaining.checked_sub(&miner_info.debt).ok_or(Error::::Overflow)?; - T::RewardPool::add_reward(miner_info.debt)?; + T::CessTreasuryHandle::send_to_pid(sender.clone(), miner_info.debt)?; miner_info.debt = BalanceOf::::zero(); } } @@ -507,7 +503,7 @@ pub mod pallet { /// - `origin`: The origin from which the function is called, ensuring the caller's authorization. Typically, this is the account of a registered Miner. #[pallet::call_index(6)] #[transactional] - #[pallet::weight(100_000_000_000)] + #[pallet::weight(Weight::zero())] pub fn receive_reward( origin: OriginFor, ) -> DispatchResult { @@ -523,8 +519,7 @@ pub mod pallet { let reward = opt_reward.as_mut().ok_or(Error::::Unexpected)?; ensure!(reward.currently_available_reward != 0u32.saturated_into(), Error::::NoReward); - let reward_pot = T::PalletId::get().into_account_truncating(); - ::Currency::transfer(&reward_pot, &miner.beneficiary, reward.currently_available_reward.clone(), KeepAlive)?; + T::RewardPool::send_reward_to_miner(miner.beneficiary, reward.currently_available_reward.clone())?; reward.reward_issued = reward.reward_issued .checked_add(&reward.currently_available_reward).ok_or(Error::::Overflow)?; @@ -693,7 +688,7 @@ pub mod pallet { /// FOR TEST #[pallet::call_index(14)] #[transactional] - #[pallet::weight(35_000_000)] + #[pallet::weight(Weight::zero())] pub fn faucet(origin: OriginFor, to: AccountOf) -> DispatchResult { let _ = ensure_signed(origin)?; @@ -786,19 +781,6 @@ pub mod pallet { } } -impl OnUnbalanced> for Pallet { - fn on_nonzero_unbalanced(amount: NegativeImbalanceOf) { - let numeric_amount = amount.peek(); - - // Must resolve into existing but better to be safe. - let _ = T::Currency::resolve_creating(&T::PalletId::get().into_account_truncating(), amount); - // The total issuance amount will not exceed u128::Max, so there is no overflow risk - T::RewardPool::add_reward(numeric_amount).unwrap(); - - Self::deposit_event(Event::Deposit { balance: numeric_amount }); - } -} - pub trait MinerControl { fn add_miner_idle_space(acc: &AccountId, accumulator: Accumulator, rear: u64, tee_sig: TeeRsaSignature) -> Result; // fn sub_miner_idle_space(acc: &AccountId, accumulator: Accumulator, rear: u64) -> DispatchResult; diff --git a/c-pallets/storage-handler/Cargo.toml b/c-pallets/storage-handler/Cargo.toml index 5cca59d0..acbbcf90 100644 --- a/c-pallets/storage-handler/Cargo.toml +++ b/c-pallets/storage-handler/Cargo.toml @@ -24,7 +24,7 @@ frame-benchmarking = { version = '4.0.0-dev', git = 'https://github.com/CESSProj # local dependencies cp-cess-common = { path = '../../primitives/common', default-features = false } -pallet-sminer-reward = { default-features = false, path = "../sminer-reward" } +pallet-cess-treasury = { default-features = false, path = "../cess-treasury" } [features] default = ["std"] @@ -37,7 +37,7 @@ std = [ "sp-std/std", "sp-runtime/std", "frame-benchmarking/std", - "pallet-sminer-reward/std", + "pallet-cess-treasury/std", ] try-runtime = [ "frame-support/try-runtime" ] diff --git a/c-pallets/storage-handler/src/lib.rs b/c-pallets/storage-handler/src/lib.rs index 333e56bb..30b5f03f 100644 --- a/c-pallets/storage-handler/src/lib.rs +++ b/c-pallets/storage-handler/src/lib.rs @@ -8,13 +8,13 @@ use frame_support::{ Blake2_128Concat, PalletId, weights::Weight, ensure, transactional, storage::bounded_vec::BoundedVec, traits::{ - StorageVersion, Currency, ReservableCurrency, ExistenceRequirement::KeepAlive, + StorageVersion, Currency, ReservableCurrency, }, pallet_prelude::*, }; use sp_runtime::{ traits::{ - AccountIdConversion, CheckedAdd, CheckedMul, CheckedDiv, CheckedSub, + CheckedAdd, CheckedMul, CheckedDiv, CheckedSub, SaturatedConversion, }, RuntimeDebug, @@ -24,7 +24,7 @@ use sp_std::{convert::TryInto, prelude::*, str}; use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use cp_cess_common::*; -use pallet_sminer_reward::RewardPool; +use pallet_cess_treasury::{TreasuryHandle}; pub mod weights; use weights::WeightInfo; @@ -77,7 +77,7 @@ pub mod pallet { #[pallet::constant] type FrozenDays: Get> + Clone + Eq + PartialEq; - type RewardPool: RewardPool>; + type CessTreasuryHandle: TreasuryHandle, BalanceOf>; } #[pallet::event] @@ -196,18 +196,12 @@ pub mod pallet { .checked_mul(&gib_count.saturated_into()) .ok_or(Error::::Overflow)?; - let price = price.checked_div(&2u32.saturated_into()).ok_or(Error::::Overflow)?; - ensure!( ::Currency::can_slash(&sender, price.clone()), Error::::InsufficientBalance ); - let r_acc = T::RewardPalletId::get().into_account_truncating(); - let t_acc = T::TreasuryPalletId::get().into_account_truncating(); - T::RewardPool::add_reward(price.into())?; - ::Currency::transfer(&sender, &r_acc, price.clone(), KeepAlive)?; - ::Currency::transfer(&sender, &t_acc, price.clone(), KeepAlive)?; + T::CessTreasuryHandle::send_to_sid(sender.clone(), price)?; Self::deposit_event(Event::::BuySpace { acc: sender, storage_capacity: space, spend: price }); Ok(()) @@ -273,13 +267,7 @@ pub mod pallet { Self::expension_puchased_package(sender.clone(), space)?; - let r_acc = T::RewardPalletId::get().into_account_truncating(); - let t_acc = T::TreasuryPalletId::get().into_account_truncating(); - - T::RewardPool::add_reward(price.into())?; - - ::Currency::transfer(&sender, &t_acc, price.clone(), KeepAlive)?; - ::Currency::transfer(&sender, &r_acc, price.clone(), KeepAlive)?; + T::CessTreasuryHandle::send_to_sid(sender.clone(), price.clone())?; Self::deposit_event(Event::::ExpansionSpace { acc: sender, @@ -327,13 +315,8 @@ pub mod pallet { Error::::InsufficientBalance ); - let r_acc = T::RewardPalletId::get().into_account_truncating(); - let t_acc = T::TreasuryPalletId::get().into_account_truncating(); - - T::RewardPool::add_reward(price.into())?; + T::CessTreasuryHandle::send_to_sid(sender.clone(), price.clone())?; - ::Currency::transfer(&sender, &t_acc, price.clone(), KeepAlive)?; - ::Currency::transfer(&sender, &r_acc, price.clone(), KeepAlive)?; Self::update_puchased_package(sender.clone(), days)?; Self::deposit_event(Event::::RenewalSpace { acc: sender, diff --git a/c-pallets/tee-worker/src/lib.rs b/c-pallets/tee-worker/src/lib.rs index e067a075..d9016098 100644 --- a/c-pallets/tee-worker/src/lib.rs +++ b/c-pallets/tee-worker/src/lib.rs @@ -217,7 +217,7 @@ pub mod pallet { /// - `origin`: The origin from which the function is called, representing the account of the TEE Worker. This should be the controller account of the TEE Worker. #[pallet::call_index(2)] #[transactional] - #[pallet::weight(100_000_000)] + #[pallet::weight(Weight::zero())] pub fn exit(origin: OriginFor) -> DispatchResult { let sender = ensure_signed(origin)?; diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index c645f6ec..edbb9977 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -111,7 +111,7 @@ pallet-scheduler-credit = { default-features = false, path = "../c-pallets/sched # local dependencies pallet-sminer = { default-features = false, path = "../c-pallets/sminer" } -pallet-sminer-reward = { default-features = false, path = "../c-pallets/sminer-reward" } +pallet-cess-treasury = { default-features = false, path = "../c-pallets/cess-treasury" } pallet-audit = { default-features = false, path = "../c-pallets/audit" } pallet-file-bank = { default-features = false, path = "../c-pallets/file-bank" } pallet-tee-worker = { default-features = false, path = "../c-pallets/tee-worker" } @@ -167,7 +167,7 @@ std = [ "pallet-storage-handler/std", "pallet-oss/std", "pallet-cacher/std", - "pallet-sminer-reward/std", + "pallet-cess-treasury/std", "pallet-preimage/std", "pallet-assets/std", "pallet-child-bounties/std", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index cce11c68..c6ae616d 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -168,7 +168,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 115, + spec_version: 100, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -570,7 +570,7 @@ impl pallet_cess_staking::Config for Runtime { const FIRST_YEAR_SMINER_REWARDS: Balance = 477_000_000 * DOLLARS; const REWARD_DECREASE_RATIO: Perbill = Perbill::from_perthousand(841); const REWARD_DECREASE_YEARS: u64 = 30; - type SminerRewardPool = Sminer; + type SminerRewardPool = CessTreasury; type MaxNominations = MaxNominations; type Currency = Balances; type CurrencyBalance = Balance; @@ -937,7 +937,6 @@ impl pallet_evm_chain_id::Config for Runtime {} * Add This Block */ parameter_types! { - pub const RewardPalletId: PalletId = PalletId(*b"rewardpt"); pub const FaucetId: PalletId = PalletId(*b"facuetid"); } @@ -945,7 +944,6 @@ impl pallet_sminer::Config for Runtime { type Currency = Balances; // The ubiquitous event type. type RuntimeEvent = RuntimeEvent; - type PalletId = RewardPalletId; type FaucetId = FaucetId; type WeightInfo = pallet_sminer::weights::SubstrateWeight; type ItemLimit = ConstU32<200000>; @@ -956,11 +954,23 @@ impl pallet_sminer::Config for Runtime { type SPalletsOrigin = OriginCaller; type SProposal = RuntimeCall; type StorageHandle = StorageHandler; - type RewardPool = SminerReward; + type RewardPool = CessTreasury; + type CessTreasuryHandle = CessTreasury; } -impl pallet_sminer_reward::Config for Runtime { +parameter_types! { + pub const RewardPalletId: PalletId = PalletId(*b"rewardpt"); + pub const PunishTreasuryId: PalletId = PalletId(*b"punisdpt"); + pub const SpaceTreasuryId: PalletId = PalletId(*b"spacedpt"); +} + +impl pallet_cess_treasury::Config for Runtime { + type RuntimeEvent = RuntimeEvent; type Currency = Balances; + type MinerRewardId = RewardPalletId; + type PunishTreasuryId = PunishTreasuryId; + type SpaceTreasuryId = SpaceTreasuryId; + type BurnDestination = (); } parameter_types! { @@ -976,10 +986,10 @@ impl pallet_storage_handler::Config for Runtime { type WeightInfo = pallet_storage_handler::weights::SubstrateWeight; type OneDay = OneDay; type RewardPalletId = RewardPalletId; - type RewardPool = SminerReward; type TreasuryPalletId = TreasuryPalletId; type StateStringMax = StateStringMax; type FrozenDays = FrozenDays; + type CessTreasuryHandle = CessTreasury; } parameter_types! { @@ -1555,7 +1565,7 @@ construct_runtime!( SchedulerCredit: pallet_scheduler_credit = 65, Oss: pallet_oss = 66, Cacher: pallet_cacher = 67, - SminerReward: pallet_sminer_reward = 68, + CessTreasury: pallet_cess_treasury = 68, } );