From 5ac4afeccfab26a7fb805873028338c54d7dbc67 Mon Sep 17 00:00:00 2001 From: Francisco Valentim Castilho Date: Fri, 23 Feb 2024 03:00:40 -0300 Subject: [PATCH 1/5] Feat: almost done with lib --- OCIF/README.md | 3 - OCIF/staking/src/lib.rs | 174 ++++++++++++++++++++++++++++++--- OCIF/staking/src/primitives.rs | 6 ++ 3 files changed, 168 insertions(+), 15 deletions(-) delete mode 100644 OCIF/README.md diff --git a/OCIF/README.md b/OCIF/README.md deleted file mode 100644 index bee15c0f..00000000 --- a/OCIF/README.md +++ /dev/null @@ -1,3 +0,0 @@ -[![Compatible with Substrate v3.0.0](https://img.shields.io/badge/Substrate-v3.0.0-E6007A)](https://github.com/paritytech/substrate/releases/tag/v3.0.0) - -# On-Chain Innovation Funding (OCIF) Substrate FRAME Pallets diff --git a/OCIF/staking/src/lib.rs b/OCIF/staking/src/lib.rs index 4d72590b..d946510a 100644 --- a/OCIF/staking/src/lib.rs +++ b/OCIF/staking/src/lib.rs @@ -85,6 +85,7 @@ pub mod weights; pub use weights::WeightInfo; +/// Staking lock dentifier. const LOCK_ID: LockIdentifier = *b"ocif-stk"; pub use pallet::*; @@ -98,30 +99,37 @@ pub mod pallet { use super::*; + /// The balance type of this pallet. pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; #[pallet::pallet] pub struct Pallet(PhantomData); + /// The opaque token type for an imbalance. This is returned by unbalanced operations and must be dealt with. type NegativeImbalanceOf = <::Currency as Currency< ::AccountId, >>::NegativeImbalance; + /// The core metadata type of this pallet. pub type CoreMetadataOf = CoreMetadata< BoundedVec::MaxNameLength>, BoundedVec::MaxDescriptionLength>, BoundedVec::MaxImageUrlLength>, >; + /// The core information type, containing a core's AccountId and CoreMetadataOf. pub type CoreInfoOf = CoreInfo<::AccountId, CoreMetadataOf>; + /// Counter for the number of eras that have passed. pub type Era = u32; #[pallet::config] pub trait Config: frame_system::Config + pallet_inv4::Config { + /// The overarching event type. type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// The staking balance. type Currency: LockableCurrency + ReservableCurrency; @@ -135,77 +143,107 @@ pub mod pallet { // + Clone // + From<::CoreId>; + /// Number of blocks per era. #[pallet::constant] type BlocksPerEra: Get>; + /// Deposit amount that will be reserved as part of new core registration. #[pallet::constant] type RegisterDeposit: Get>; + /// Maximum number of unique stakers per core. #[pallet::constant] type MaxStakersPerCore: Get; + /// Minimum amount user must have staked on a core. + /// User can stake less if they already have the minimum staking amount staked on that particular core. #[pallet::constant] type MinimumStakingAmount: Get>; + /// Account Identifier from which the internal Pot is generated. #[pallet::constant] type PotId: Get; + /// The minimum amount required to keep an account open. #[pallet::constant] type ExistentialDeposit: Get>; + /// Max number of unlocking chunks per account Id <-> core Id pairing. + /// If value is zero, unlocking becomes impossible. #[pallet::constant] type MaxUnlocking: Get; + /// Number of blocks that need to pass until unstaked value can be withdrawn. + /// When set to `0`, it's equal to having no unbonding period. #[pallet::constant] type UnbondingPeriod: Get; + /// Max number of unique `EraStake` values that can exist for a `(staker, core)` pairing. + /// When stakers claims rewards, they will either keep the number of `EraStake` values the same or they will reduce them by one. + /// Stakers cannot add an additional `EraStake` value by calling `bond&stake` or `unbond&unstake` if they've reached the max number of values. + /// + /// This ensures that history doesn't grow indefinitely - if there are too many chunks, stakers should first claim their former rewards + /// before adding additional `EraStake` values. #[pallet::constant] type MaxEraStakeValues: Get; + /// Reward ratio of the pot to be distributed between the core and stakers, respectively. #[pallet::constant] type RewardRatio: Get<(u32, u32)>; + /// Threshold of staked tokens necessary for the core to become active. #[pallet::constant] type StakeThresholdForActiveCore: Get>; + /// Maximum lenght of a core's name. #[pallet::constant] type MaxNameLength: Get; + /// Maximum lenght of a core's description. #[pallet::constant] type MaxDescriptionLength: Get; + /// Maximum lenght of a core's image url. #[pallet::constant] type MaxImageUrlLength: Get; + /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; } + /// General information about the staker. #[pallet::storage] #[pallet::getter(fn ledger)] pub type Ledger = StorageMap<_, Blake2_128Concat, T::AccountId, AccountLedger>, ValueQuery>; + /// The current era index. #[pallet::storage] #[pallet::getter(fn current_era)] pub type CurrentEra = StorageValue<_, Era, ValueQuery>; + /// Accumulator for block rewards during an era. It is reset at every new era #[pallet::storage] #[pallet::getter(fn reward_accumulator)] pub type RewardAccumulator = StorageValue<_, RewardInfo>, ValueQuery>; + /// Stores the block number of when the next era starts. #[pallet::storage] #[pallet::getter(fn next_era_starting_block)] pub type NextEraStartingBlock = StorageValue<_, T::BlockNumber, ValueQuery>; + /// Simple map where CoreId points to the respective core information. #[pallet::storage] #[pallet::getter(fn core_info)] pub(crate) type RegisteredCore = StorageMap<_, Blake2_128Concat, T::CoreId, CoreInfoOf>; + /// General information about an era. #[pallet::storage] #[pallet::getter(fn general_era_info)] pub type GeneralEraInfo = StorageMap<_, Twox64Concat, Era, EraInfo>>; + /// Staking information about a core in a particular era. #[pallet::storage] #[pallet::getter(fn core_stake_info)] pub type CoreEraStake = StorageDoubleMap< @@ -217,6 +255,7 @@ pub mod pallet { CoreStakeInfo>, >; + /// Info about stakers stakes on particular core. #[pallet::storage] #[pallet::getter(fn staker_info)] pub type GeneralStakerInfo = StorageDoubleMap< @@ -229,6 +268,7 @@ pub mod pallet { ValueQuery, >; + /// Denotes whether pallet is halted(disabled). #[pallet::storage] #[pallet::getter(fn is_halted)] pub type Halted = StorageValue<_, bool, ValueQuery>; @@ -236,49 +276,61 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { + /// Account has staked funds on a core. Staked { staker: T::AccountId, core: T::CoreId, amount: BalanceOf, }, + + /// Account has unstaked funds on a core. Unstaked { staker: T::AccountId, core: T::CoreId, amount: BalanceOf, }, + + /// Account has withdrawn unbonded funds. Withdrawn { staker: T::AccountId, amount: BalanceOf, }, - CoreRegistered { - core: T::CoreId, - }, - CoreUnregistered { - core: T::CoreId, - }, - NewEra { - era: u32, - }, + + /// New core added for staking. + CoreRegistered { core: T::CoreId }, + + /// Core removed. + CoreUnregistered { core: T::CoreId }, + + /// Beginning of a new era. + NewEra { era: u32 }, + + /// Staker claimed staking rewards. StakerClaimed { staker: T::AccountId, core: T::CoreId, era: u32, amount: BalanceOf, }, + + /// Core claimed staking rewards. CoreClaimed { core: T::CoreId, destination_account: T::AccountId, era: u32, amount: BalanceOf, }, - HaltChanged { - is_halted: bool, - }, + + /// Halted status changed. + HaltChanged { is_halted: bool }, + MetadataChanged { core: T::CoreId, old_metadata: CoreMetadata, Vec, Vec>, new_metadata: CoreMetadata, Vec, Vec>, }, + + /// Staker moved his stake. StakeMoved { staker: T::AccountId, from_core: T::CoreId, @@ -289,36 +341,66 @@ pub mod pallet { #[pallet::error] pub enum Error { + /// Staking nothing. StakingNothing, + /// Staker tried to stake less than the minimum staking amount. InsufficientBalance, + /// Maximum number of stakers reached. MaxStakersReached, + /// Core not found. CoreNotFound, + /// No stake available for withdrawal. NoStakeAvailable, + /// Core is not unregistered. NotUnregisteredCore, + /// Unclaimed rewards available. UnclaimedRewardsAvailable, + /// Unstaking nothing. UnstakingNothing, + /// Nothing available for withdrawal. NothingToWithdraw, + /// Core already registered. CoreAlreadyRegistered, + /// Unknown rewards for era. UnknownEraReward, + /// Unexpected stake info for era. UnexpectedStakeInfoEra, + /// Too many unlocking chunks. TooManyUnlockingChunks, + /// Reward already claimed. RewardAlreadyClaimed, + /// Incorrect era. IncorrectEra, + /// Too many era stake values. TooManyEraStakeValues, + /// Not a staker. NotAStaker, + /// No permission. NoPermission, + /// Name exceeds maximum length. MaxNameExceeded, + /// Description exceeds maximum length. MaxDescriptionExceeded, + /// Image url exceeds maximum length. MaxImageExceeded, + /// Core not registered. NotRegistered, + /// Halted. Halted, + /// No halt change. NoHaltChange, + /// Staker moved staking to the same core. MoveStakeToSameCore, } #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(now: BlockNumberFor) -> Weight { + // As long as pallet is disabled, we shouldn't allow any storage modifications. + // This means we might prolong an era but it's acceptable. + // Runtime upgrade should be timed so we ensure that we complete it before + // a new era is triggered. This code is just a safety net to ensure nothing is broken + // if we fail to do that. if Self::is_halted() { return T::DbWeight::get().reads(1); } @@ -326,6 +408,7 @@ pub mod pallet { let previous_era = Self::current_era(); let next_era_starting_block = Self::next_era_starting_block(); + // Value is compared to 1 since genesis block is ignored if now >= next_era_starting_block || previous_era.is_zero() { let blocks_per_era = T::BlocksPerEra::get(); let next_era = previous_era + 1; @@ -353,6 +436,16 @@ pub mod pallet { From<::RuntimeOrigin>, T::AccountId: From<[u8; 32]>, { + /// Used to register core for staking. + /// The origin has to be from the multisig of the core. + /// + /// Depending on the pallet configuration/state it is possible that developer needs to be whitelisted prior to registration. + /// + /// As part of this call, `RegisterDeposit` will be reserved from the core account. + /// + /// - `name`: Name of the core. + /// - `description`: Description of the core. + /// - `image`: Image url of the core. #[pallet::call_index(0)] #[pallet::weight( ::WeightInfo::register_core( @@ -402,6 +495,14 @@ pub mod pallet { }) } + /// Unregister existing core for staking, making it ineligible for rewards from current era onwards and + /// starts the unbonding period for the stakers. + /// + /// The origin has to be from the multisig of the core. + /// + /// Deposit is returned to the core account. + /// + /// - `core_id`: Id of the core to be unregistered. #[pallet::call_index(1)] #[pallet::weight( ::WeightInfo::unregister_core() + @@ -482,6 +583,11 @@ pub mod pallet { ) } + /// Used to change the metadata of a core. + /// + /// - `name`: Name of the core. + /// - `description`: Description of the core. + /// - `image`: Image url of the core. #[pallet::call_index(2)] #[pallet::weight( ::WeightInfo::change_core_metadata( @@ -534,6 +640,15 @@ pub mod pallet { }) } + /// Lock up and stake balance of the origin account. + /// + /// `value` must be more than the `minimum_stake` specified by `MinimumStakingAmount` + /// unless account already has bonded value equal or more than 'minimum_stake'. + /// + /// The dispatch origin for this call must be _Signed_ by the staker's account. + /// + /// - `core_id`: Id of the core to stake towards. + /// - `value`: Amount to stake. #[pallet::call_index(3)] #[pallet::weight(::WeightInfo::stake())] pub fn stake( @@ -588,6 +703,16 @@ pub mod pallet { Ok(().into()) } + /// Start unbonding process and unstake balance from the core. + /// + /// The unstaked amount will no longer be eligible for rewards but still won't be unlocked. + /// User needs to wait for the unbonding period to finish before being able to withdraw + /// the funds via `withdraw_unstaked` call. + /// + /// In case remaining staked balance on contract is below minimum staking amount, + /// entire stake for that contract will be unstaked. + /// + /// - `core_id`: Id of the core to unstake from. #[pallet::call_index(4)] #[pallet::weight(::WeightInfo::unstake())] pub fn unstake( @@ -643,6 +768,10 @@ pub mod pallet { Ok(().into()) } + /// Withdraw all funds that have completed the unbonding process. + /// + /// If there are unbonding chunks which will be fully unbonded in future eras, + /// they will remain and can be withdrawn later. #[pallet::call_index(5)] #[pallet::weight(::WeightInfo::withdraw_unstaked())] pub fn withdraw_unstaked(origin: OriginFor) -> DispatchResultWithPostInfo { @@ -924,6 +1053,8 @@ pub mod pallet { T::PotId::get().into_account_truncating() } + /// Update the ledger for a staker. This will also update the stash lock. + /// This lock will lock the entire funds except paying for further transactions. fn update_ledger(staker: &T::AccountId, ledger: AccountLedger>) { if ledger.is_empty() { Ledger::::remove(staker); @@ -939,6 +1070,11 @@ pub mod pallet { } } + /// The block rewards are accumulated on the pallets's account during an era. + /// This function takes a snapshot of the pallet's balance accrued during current era + /// and stores it for future distribution + /// + /// This is called just at the beginning of an era. fn reward_balance_snapshot( era: Era, rewards: RewardInfo>, @@ -962,6 +1098,9 @@ pub mod pallet { GeneralEraInfo::::insert(era, era_info); } + /// Adds `stakers` and `cores` rewards to the reward pool. + /// + /// - `inflation`: Total inflation for the era. pub fn rewards(inflation: NegativeImbalanceOf) { let (core_part, stakers_part) = ::RewardRatio::get(); @@ -979,6 +1118,7 @@ pub mod pallet { ); } + /// Updates staker info for a core. fn update_staker_info( staker: &T::AccountId, core_id: T::CoreId, @@ -991,6 +1131,7 @@ pub mod pallet { } } + /// Returns available staking balance for the potential staker. fn available_staking_balance( staker: &T::AccountId, ledger: &AccountLedger>, @@ -1001,6 +1142,9 @@ pub mod pallet { free_balance.saturating_sub(ledger.locked) } + /// Returns total value locked by core-staking. + /// + /// Note that this can differ from _total staked value_ since some funds might be undergoing the unbonding period. pub fn tvl() -> BalanceOf { let current_era = Self::current_era(); if let Some(era_info) = Self::general_era_info(current_era) { @@ -1010,6 +1154,9 @@ pub mod pallet { } } + /// Calculate reward split between core and stakers. + /// + /// Returns (core reward, joint stakers reward) pub(crate) fn core_stakers_split( core_info: &CoreStakeInfo>, era_info: &EraInfo>, @@ -1027,6 +1174,7 @@ pub mod pallet { (core_reward_part, stakers_joint_reward) } + /// Used to copy all `CoreStakeInfo` from the ending era over to the next era. fn rotate_staking_info(current_era: Era) -> (Weight, BalanceOf) { let next_era = current_era + 1; @@ -1058,10 +1206,12 @@ pub mod pallet { (consumed_weight, new_active_stake) } + /// Sets the halt state of the pallet. pub fn internal_halt_unhalt(halt: bool) { Halted::::put(halt); } + /// Ensure the pallet is not halted. pub fn ensure_not_halted() -> Result<(), Error> { if Self::is_halted() { Err(Error::::Halted) diff --git a/OCIF/staking/src/primitives.rs b/OCIF/staking/src/primitives.rs index 05058faf..55aa1cc9 100644 --- a/OCIF/staking/src/primitives.rs +++ b/OCIF/staking/src/primitives.rs @@ -1,3 +1,9 @@ +//! Pallet Primitives. +//! +//! ## Overview +//! +//! zzzz + use codec::{Decode, Encode, HasCompact, MaxEncodedLen}; use frame_support::traits::Currency; use scale_info::TypeInfo; From ca6ced10110b822f9514d4be992fca538b0b8d99 Mon Sep 17 00:00:00 2001 From: Francisco Valentim Castilho Date: Fri, 23 Feb 2024 14:30:30 -0300 Subject: [PATCH 2/5] Feat: completed --- OCIF/staking/README.md | 72 +++++++++++++++------------------- OCIF/staking/src/lib.rs | 72 +++++++++++++++++++++++++--------- OCIF/staking/src/primitives.rs | 40 ++++++++++++++++++- 3 files changed, 123 insertions(+), 61 deletions(-) diff --git a/OCIF/staking/README.md b/OCIF/staking/README.md index 59f6cb12..d7a01564 100644 --- a/OCIF/staking/README.md +++ b/OCIF/staking/README.md @@ -1,55 +1,47 @@ -# pallet-ocif-staking +# OCIF Staking Pallet -## OCIF Staking pallet -A pallet for for allowing INV-Cores to be staked towards. +## Overview +The OCIF Staking Pallet is a pallet designed to facilitate staking towards INV-Cores within a blockchain network. This pallet introduces a staking mechanism that allows two distinct sets of entities, namely Cores and Stakers, to participate in the distribution of tokens from a predefined pot. The allocation of rewards is determined based on the amount staked by each entity and the total stake towards each Core. -### Overview +### Cores -This pallet provides functionality to allow 2 sets of entities to participate in distribution of tokens -available in a predefined pot account. -The tokens provided to the pot account are to be handled by the Runtime, -either directly or with the assistance of another pallet. +Cores represent virtual accounts identified by unique IDs, which are responsible for registering themselves within the staking ecosystem. The primary role of Cores is to attract Stakers to lock tokens in their favor. The rewards allocated to Cores are proportional to the total amount staked towards them by Stakers. However, for a Core to be eligible for rewards, it must have a total stake above a predefined threshold, thereby becoming `active`. -The 2 entity sets will be referred to in code as Cores and Stakers: +### Stakers -#### Cores -Cores are virtual accounts that have an ID used to derive their own account address, -their task in the process is to register themselves and have Stakers lock tokens in favor of a specifc Core. -Cores receive their fraction of the pot rewards based on the total amount staked towards them by Stakers, -however, a Core must have total stake above the defined threshold (making it `active`), otherwise they won't be entitled to rewards. +Stakers are individual accounts that engage in locking tokens in favor of a Core. Unlike Cores, Stakers receive a fraction of the rewards based on their own stake. -#### Stakers -Stakers are any account existing on the chain, their task is to lock tokens in favor of a Core. -Unlike Cores, Stakers get their fraction of the rewards based on their own stake and regardless of -the `active` state of the Core they staked towards. +## Runtime Configuration Parameters +- `BlocksPerEra`: Defines the duration of an era in terms of block numbers. +- `RegisterDeposit`: Specifies the deposit amount required for Core registration. +- `MaxStakersPerCore`: Limits the maximum number of Stakers that can simultaneously stake towards a single Core. +- `MinimumStakingAmount`: Sets the minimum amount required for a Staker to participate in staking. +- `UnbondingPeriod`: Determines the period, in blocks, required for unbonding staked tokens. +- `RewardRatio`: Establishes the distribution ratio of rewards between Cores and Stakers. +- `StakeThresholdForActiveCore`: Sets the stake threshold required for a Core to become `active`. -### Relevant runtime configs +## Dispatchable Functions -* `BlocksPerEra` - Defines how many blocks constitute an era. -* `RegisterDeposit` - Defines the deposit amount for a Core to register in the system. -* `MaxStakersPerCore` - Defines the maximum amount of Stakers allowed to stake simultaneously towards the same Core. -* `MinimumStakingAmount` - Defines the minimum amount a Staker has to stake to participate. -* `UnbondingPeriod` - Defines the period, in blocks, that it takes to unbond a stake. -* `RewardRatio` - Defines the ratio of balance from the pot to distribute to Cores and Stakers, respectively. -* `StakeThresholdForActiveCore` - Defines the threshold of stake a Core needs to surpass to become active. +- `register_core`: Allows Cores to register themselves in the system. +- `unregister_core`: Enables Cores to unregister from the system, initiating the unbonding period for Stakers. +- `change_core_metadata`: Facilitates changes to the metadata associated with a Core. +- `stake`: Allows Stakers to lock tokens in favor of a Core. +- `unstake`: Permits Stakers to unlock tokens previously staked on a Core, starting the unbonding period. +- `withdraw_unstaked`: Enables Stakers to withdraw tokens that have completed the unbonding period. +- `staker_claim_rewards`: Allows Stakers to claim available rewards. +- `core_claim_rewards`: Enables Cores to claim available rewards. +- `halt_unhalt_pallet`: Grants Root permissions to halt or resume the staking operations within the pallet. -**Example Runtime implementation can be found in [src/testing/mock.rs](./src/testing/mock.rs)** +## Events -### Dispatchable Functions +The pallet emits events such as `Staked`, `Unstaked`, `CoreRegistered`, `CoreUnregistered`, and others to signal various operations and state changes within the staking ecosystem. -* `register_core` - Registers a Core in the system. -* `unregister_core` - Unregisters a Core from the system, starting the unbonding period for the Stakers. -* `change_core_metadata` - Changes the metadata tied to a Core. -* `stake` - Stakes tokens towards a Core. -* `untake` - Unstakes tokens from a core and starts the unbonding period for those tokens. -* `withdraw_unstaked` - Withdraws tokens that have already been through the unbonding period. -* `staker_claim_rewards` - Claims rewards available for a Staker. -* `core_claim_rewards` - Claims rewards available for a Core. -* `halt_unhalt_pallet` - Allows Root to trigger a halt of the system, eras will stop counting and rewards won't be distributed. +## Errors -[`Call`]: ./enum.Call.html -[`Config`]: ./trait.Config.html +Errors such as `StakingNothing`, `InsufficientBalance`, `MaxStakersReached`, and others are defined to handle exceptional scenarios encountered during pallet operations. -License: GPLv3 +## Example Runtime Implementation + +For an example runtime implementation that integrates this pallet, refer to [src/testing/mock.rs](./src/testing/mock.rs). diff --git a/OCIF/staking/src/lib.rs b/OCIF/staking/src/lib.rs index d946510a..4302adfb 100644 --- a/OCIF/staking/src/lib.rs +++ b/OCIF/staking/src/lib.rs @@ -1,6 +1,5 @@ //! # OCIF Staking pallet -//! A pallet for for allowing INV-Cores to be staked towards. -//! +//! A pallet for allowing INV-Cores to be staked towards. //! //! ## Overview //! @@ -22,12 +21,11 @@ //! Unlike Cores, Stakers get their fraction of the rewards based on their own stake and regardless of //! the `active` state of the Core they staked towards. //! -//! //! ## Relevant runtime configs //! //! * `BlocksPerEra` - Defines how many blocks constitute an era. //! * `RegisterDeposit` - Defines the deposit amount for a Core to register in the system. -//! * `MaxStakersPerCore` - Defines the maximum amount of Stakers allowed to stake simultaneously towards the same Core. +//! * `MaxStakersPerCore` - Defines the maximum amount of Stakers allowed staking simultaneously towards the same Core. //! * `MinimumStakingAmount` - Defines the minimum amount a Staker has to stake to participate. //! * `UnbondingPeriod` - Defines the period, in blocks, that it takes to unbond a stake. //! * `RewardRatio` - Defines the ratio of balance from the pot to distribute to Cores and Stakers, respectively. @@ -41,7 +39,7 @@ //! * `unregister_core` - Unregisters a Core from the system, starting the unbonding period for the Stakers. //! * `change_core_metadata` - Changes the metadata tied to a Core. //! * `stake` - Stakes tokens towards a Core. -//! * `untake` - Unstakes tokens from a core and starts the unbonding period for those tokens. +//! * `unstake` - Unstakes tokens from a core and starts the unbonding period for those tokens. //! * `withdraw_unstaked` - Withdraws tokens that have already been through the unbonding period. //! * `staker_claim_rewards` - Claims rewards available for a Staker. //! * `core_claim_rewards` - Claims rewards available for a Core. @@ -85,7 +83,7 @@ pub mod weights; pub use weights::WeightInfo; -/// Staking lock dentifier. +/// Staking lock identifier. const LOCK_ID: LockIdentifier = *b"ocif-stk"; pub use pallet::*; @@ -174,15 +172,16 @@ pub mod pallet { type MaxUnlocking: Get; /// Number of blocks that need to pass until unstaked value can be withdrawn. - /// When set to `0`, it's equal to having no unbonding period. + /// When set to `0`, it's equal to have no unbound period. #[pallet::constant] type UnbondingPeriod: Get; /// Max number of unique `EraStake` values that can exist for a `(staker, core)` pairing. + /// /// When stakers claims rewards, they will either keep the number of `EraStake` values the same or they will reduce them by one. /// Stakers cannot add an additional `EraStake` value by calling `bond&stake` or `unbond&unstake` if they've reached the max number of values. /// - /// This ensures that history doesn't grow indefinitely - if there are too many chunks, stakers should first claim their former rewards + /// This ensures that history doesn't grow indefinitely - if there are too many chunks, stakers should first claim their former rewards /// before adding additional `EraStake` values. #[pallet::constant] type MaxEraStakeValues: Get; @@ -195,15 +194,15 @@ pub mod pallet { #[pallet::constant] type StakeThresholdForActiveCore: Get>; - /// Maximum lenght of a core's name. + /// Maximum length of a core's name. #[pallet::constant] type MaxNameLength: Get; - /// Maximum lenght of a core's description. + /// Maximum length of a core's description. #[pallet::constant] type MaxDescriptionLength: Get; - /// Maximum lenght of a core's image url. + /// Maximum length of a core's image URL. #[pallet::constant] type MaxImageUrlLength: Get; @@ -222,7 +221,7 @@ pub mod pallet { #[pallet::getter(fn current_era)] pub type CurrentEra = StorageValue<_, Era, ValueQuery>; - /// Accumulator for block rewards during an era. It is reset at every new era + /// Accumulator for block rewards during an era. It is reset at every new era. #[pallet::storage] #[pallet::getter(fn reward_accumulator)] pub type RewardAccumulator = StorageValue<_, RewardInfo>, ValueQuery>; @@ -268,7 +267,7 @@ pub mod pallet { ValueQuery, >; - /// Denotes whether pallet is halted(disabled). + /// Denotes whether the pallet is halted(disabled). #[pallet::storage] #[pallet::getter(fn is_halted)] pub type Halted = StorageValue<_, bool, ValueQuery>; @@ -381,7 +380,7 @@ pub mod pallet { MaxNameExceeded, /// Description exceeds maximum length. MaxDescriptionExceeded, - /// Image url exceeds maximum length. + /// Image URL exceeds maximum length. MaxImageExceeded, /// Core not registered. NotRegistered, @@ -397,8 +396,8 @@ pub mod pallet { impl Hooks> for Pallet { fn on_initialize(now: BlockNumberFor) -> Weight { // As long as pallet is disabled, we shouldn't allow any storage modifications. - // This means we might prolong an era but it's acceptable. - // Runtime upgrade should be timed so we ensure that we complete it before + // This means we might prolong an era, but it's acceptable. + // Runtime upgrade should be timed, so we ensure that we complete it before // a new era is triggered. This code is just a safety net to ensure nothing is broken // if we fail to do that. if Self::is_halted() { @@ -445,7 +444,7 @@ pub mod pallet { /// /// - `name`: Name of the core. /// - `description`: Description of the core. - /// - `image`: Image url of the core. + /// - `image`: Image URL of the core. #[pallet::call_index(0)] #[pallet::weight( ::WeightInfo::register_core( @@ -585,9 +584,11 @@ pub mod pallet { /// Used to change the metadata of a core. /// + /// The origin has to be from the multisig of the core. + /// /// - `name`: Name of the core. /// - `description`: Description of the core. - /// - `image`: Image url of the core. + /// - `image`: Image URL of the core. #[pallet::call_index(2)] #[pallet::weight( ::WeightInfo::change_core_metadata( @@ -772,6 +773,8 @@ pub mod pallet { /// /// If there are unbonding chunks which will be fully unbonded in future eras, /// they will remain and can be withdrawn later. + /// + /// The dispatch origin for this call must be _Signed_ by the staker's account. #[pallet::call_index(5)] #[pallet::weight(::WeightInfo::withdraw_unstaked())] pub fn withdraw_unstaked(origin: OriginFor) -> DispatchResultWithPostInfo { @@ -805,6 +808,14 @@ pub mod pallet { Ok(().into()) } + /// Calculate the starker rewards. + /// + /// If successful, returns reward amount. + /// In case reward cannot be claimed or was already claimed, an error is raised. + /// + /// The dispatch origin for this call must be _Signed_ by the staker's account. + /// + /// - `core_id`: Id of the core to claim rewards from. #[pallet::call_index(6)] #[pallet::weight(::WeightInfo::staker_claim_rewards())] pub fn staker_claim_rewards( @@ -850,6 +861,13 @@ pub mod pallet { Ok(().into()) } + /// Calculate the core reward for the specified era. + /// + /// If successful, returns reward amount. + /// In case reward cannot be claimed or was already claimed, an error is raised. + /// + /// - `core_id`: Id of the core to claim rewards from. + /// - `era`: Era for which rewards are to be claimed. #[pallet::call_index(7)] #[pallet::weight(::WeightInfo::core_claim_rewards())] pub fn core_claim_rewards( @@ -903,6 +921,11 @@ pub mod pallet { Ok(().into()) } + /// Halt or unhalt the pallet. + /// + /// The dispatch origin for this call must be _Root_. + /// + /// - `halt`: `true` to halt, `false` to unhalt. #[pallet::call_index(8)] #[pallet::weight((::WeightInfo::halt_unhalt_pallet(), Pays::No))] pub fn halt_unhalt_pallet(origin: OriginFor, halt: bool) -> DispatchResultWithPostInfo { @@ -919,6 +942,13 @@ pub mod pallet { Ok(().into()) } + /// Move stake from one core to another. + /// + /// The dispatch origin for this call must be _Signed_ by the staker's account. + /// + /// - `from_core`: Id of the core to move stake from. + /// - `amount`: Amount to move. + /// - `to_core`: Id of the core to move stake to. #[pallet::call_index(9)] #[pallet::weight(::WeightInfo::move_stake())] pub fn move_stake( @@ -977,6 +1007,8 @@ pub mod pallet { } impl Pallet { + /// Internal function responsible for validating a stake and updating in-place + /// both the staker's and core staking info. fn internal_stake( staker_info: &mut StakerInfo>, staking_info: &mut CoreStakeInfo>, @@ -1011,6 +1043,8 @@ pub mod pallet { Ok(()) } + /// Internal function responsible for validating an unstake and updating in-place + /// both the staker's and core staking info. fn internal_unstake( staker_info: &mut StakerInfo>, core_stake_info: &mut CoreStakeInfo>, @@ -1070,7 +1104,7 @@ pub mod pallet { } } - /// The block rewards are accumulated on the pallets's account during an era. + /// The block rewards are accumulated on the pallet's account during an era. /// This function takes a snapshot of the pallet's balance accrued during current era /// and stores it for future distribution /// diff --git a/OCIF/staking/src/primitives.rs b/OCIF/staking/src/primitives.rs index 55aa1cc9..1256c496 100644 --- a/OCIF/staking/src/primitives.rs +++ b/OCIF/staking/src/primitives.rs @@ -1,8 +1,24 @@ -//! Pallet Primitives. +//! Provides supporting types and traits for the staking pallet. //! //! ## Overview //! -//! zzzz +//! Primitives provides the foundational types and traits for a staking pallet. +//! The staking pallet is likely a part of a blockchain system, given the use of terms like Balance, Era, and Stake. +//! +//! ## Types overview: +//! +//! - `BalanceOf` - A type alias for the balance of a currency in the system. +//! - `CoreMetadata` - A struct that holds metadata for a core entity in the system. +//! - `CoreInfo` - A struct that holds information about a core entity, including its account ID and metadata. +//! - `RewardInfo` - A struct that holds information about rewards, including the balance for stakers and the core. +//! - `EraInfo` - A struct that holds information about a specific era, including rewards, staked balance, active stake, and locked balance. +//! - `CoreStakeInfo` - A struct that holds information about a core's stake, including the total balance, +//! number of stakers, and whether a reward has been claimed. +//! - `EraStake` - A struct that holds information about the stake for a specific era. +//! - `StakerInfo` - A struct that holds information about a staker's stakes across different eras. +//! - `UnlockingChunk` - A struct that holds information about an unlocking chunk of balance. +//! - `UnbondingInfo` - A struct that holds information about unbonding chunks of balance. +//! - `AccountLedger` - A struct that holds information about an account's locked balance and unbonding information. use codec::{Decode, Encode, HasCompact, MaxEncodedLen}; use frame_support::traits::Currency; @@ -15,11 +31,13 @@ use sp_std::{ops::Add, prelude::*}; pub use crate::pallet::*; +/// The balance type of this pallet. pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; const MAX_ASSUMED_VEC_LEN: u32 = 10; +/// Metadata for a core entity in the system. #[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct CoreMetadata { pub name: Name, @@ -27,12 +45,14 @@ pub struct CoreMetadata { pub image: Image, } +/// Information about a core entity, including its account ID and metadata. #[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct CoreInfo { pub account: AccountId, pub metadata: Metadata, } +/// Information about rewards, including the balance for stakers and the core. #[derive(PartialEq, Eq, Clone, Default, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct RewardInfo { #[codec(compact)] @@ -41,6 +61,7 @@ pub struct RewardInfo { pub(crate) core: Balance, } +/// Information about a specific era, including rewards, staked balance, active stake, and locked balance. #[derive(PartialEq, Eq, Clone, Default, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct EraInfo { pub(crate) rewards: RewardInfo, @@ -52,6 +73,7 @@ pub struct EraInfo { pub(crate) locked: Balance, } +/// Information about a core's stake, including the total balance, number of stakers, and whether a reward has been claimed. #[derive(Clone, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct CoreStakeInfo { #[codec(compact)] @@ -62,6 +84,7 @@ pub struct CoreStakeInfo { pub(crate) active: bool, } +/// Information about the stake for a specific era. #[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub(crate) struct EraStake { #[codec(compact)] @@ -70,6 +93,7 @@ pub(crate) struct EraStake pub(crate) era: Era, } +/// Information about a staker's stakes across different eras. #[derive(Encode, Decode, Clone, Default, PartialEq, Eq, RuntimeDebug, TypeInfo)] pub struct StakerInfo { pub(crate) stakes: Vec>, @@ -95,6 +119,7 @@ impl StakerInfo { self.stakes.len() as u32 } + /// Stakes the given value in the current era, mutates StakerInfo in-place. pub(crate) fn stake(&mut self, current_era: Era, value: Balance) -> Result<(), &str> { if let Some(era_stake) = self.stakes.last_mut() { if era_stake.era > current_era { @@ -124,6 +149,7 @@ impl StakerInfo { Ok(()) } + /// Unstakes the given value in the current era, mutates StakerInfo in-place. pub(crate) fn unstake(&mut self, current_era: Era, value: Balance) -> Result<(), &str> { if let Some(era_stake) = self.stakes.last_mut() { if era_stake.era > current_era { @@ -151,6 +177,8 @@ impl StakerInfo { Ok(()) } + /// Claims the stake for the current era, mutates StakerInfo in-place. + /// Returns the era and the staked balance. pub(crate) fn claim(&mut self) -> (Era, Balance) { if let Some(era_stake) = self.stakes.first() { let era_stake = *era_stake; @@ -174,11 +202,13 @@ impl StakerInfo { } } + /// Returns the latest staked balance. pub(crate) fn latest_staked_value(&self) -> Balance { self.stakes.last().map_or(Zero::zero(), |x| x.staked) } } +/// A chunk of balance that is unlocked until a specific era. #[derive( Clone, PartialEq, Eq, Copy, Encode, Decode, Default, RuntimeDebug, TypeInfo, MaxEncodedLen, )] @@ -193,11 +223,13 @@ impl UnlockingChunk where Balance: Add + Copy + MaxEncodedLen, { + /// Adds the given amount to the chunk's amount. pub(crate) fn add_amount(&mut self, amount: Balance) { self.amount = self.amount + amount } } +/// Information about unbonding chunks of balance. #[derive(Clone, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo)] pub(crate) struct UnbondingInfo { pub(crate) unlocking_chunks: Vec>, @@ -228,6 +260,7 @@ where self.unlocking_chunks.is_empty() } + /// Returns the total amount of the unlocking chunks. pub(crate) fn sum(&self) -> Balance { self.unlocking_chunks .iter() @@ -236,6 +269,7 @@ where .unwrap_or_default() } + /// Adds the given chunk to the unbonding info. pub(crate) fn add(&mut self, chunk: UnlockingChunk) { match self .unlocking_chunks @@ -246,6 +280,7 @@ where } } + /// returns the chucks before and after a given era. pub(crate) fn partition(self, era: Era) -> (Self, Self) { let (matching_chunks, other_chunks): ( Vec>, @@ -266,6 +301,7 @@ where } } +/// Information about an account's locked balance and unbonding information. #[derive(Clone, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct AccountLedger { #[codec(compact)] From 441763cc4aa3a5bef2745c30d123347c575626ed Mon Sep 17 00:00:00 2001 From: Gabriel Facco de Arruda Date: Fri, 23 Feb 2024 16:21:45 -0700 Subject: [PATCH 3/5] Apply suggestions from code review --- OCIF/staking/README.md | 12 +++---- OCIF/staking/src/lib.rs | 66 ++++++++++++++++------------------ OCIF/staking/src/primitives.rs | 3 +- 3 files changed, 37 insertions(+), 44 deletions(-) diff --git a/OCIF/staking/README.md b/OCIF/staking/README.md index d7a01564..6b214267 100644 --- a/OCIF/staking/README.md +++ b/OCIF/staking/README.md @@ -18,7 +18,7 @@ Stakers are individual accounts that engage in locking tokens in favor of a Core - `RegisterDeposit`: Specifies the deposit amount required for Core registration. - `MaxStakersPerCore`: Limits the maximum number of Stakers that can simultaneously stake towards a single Core. - `MinimumStakingAmount`: Sets the minimum amount required for a Staker to participate in staking. -- `UnbondingPeriod`: Determines the period, in blocks, required for unbonding staked tokens. +- `UnbondingPeriod`: Determines the period, in eras, required for unbonding staked tokens. - `RewardRatio`: Establishes the distribution ratio of rewards between Cores and Stakers. - `StakeThresholdForActiveCore`: Sets the stake threshold required for a Core to become `active`. @@ -26,13 +26,13 @@ Stakers are individual accounts that engage in locking tokens in favor of a Core - `register_core`: Allows Cores to register themselves in the system. - `unregister_core`: Enables Cores to unregister from the system, initiating the unbonding period for Stakers. -- `change_core_metadata`: Facilitates changes to the metadata associated with a Core. +- `change_core_metadata`: Changes the metadata associated to a Core. - `stake`: Allows Stakers to lock tokens in favor of a Core. -- `unstake`: Permits Stakers to unlock tokens previously staked on a Core, starting the unbonding period. -- `withdraw_unstaked`: Enables Stakers to withdraw tokens that have completed the unbonding period. +- `unstake`: Unstakes tokens previously staked to a Core, starting the unbonding period. +- `withdraw_unstaked`: Allows Stakers to withdraw tokens that have completed the unbonding period. - `staker_claim_rewards`: Allows Stakers to claim available rewards. -- `core_claim_rewards`: Enables Cores to claim available rewards. -- `halt_unhalt_pallet`: Grants Root permissions to halt or resume the staking operations within the pallet. +- `core_claim_rewards`: Allows rewards to be claimed for Cores. +- `halt_unhalt_pallet`: Allows Root to trigger a halt of the system, eras will stop counting and rewards won't be distributed. ## Events diff --git a/OCIF/staking/src/lib.rs b/OCIF/staking/src/lib.rs index 4302adfb..0142265c 100644 --- a/OCIF/staking/src/lib.rs +++ b/OCIF/staking/src/lib.rs @@ -119,7 +119,7 @@ pub mod pallet { /// The core information type, containing a core's AccountId and CoreMetadataOf. pub type CoreInfoOf = CoreInfo<::AccountId, CoreMetadataOf>; - /// Counter for the number of eras that have passed. + /// Alias type for the era identifier type. pub type Era = u32; #[pallet::config] @@ -127,7 +127,7 @@ pub mod pallet { /// The overarching event type. type RuntimeEvent: From> + IsType<::RuntimeEvent>; - /// The staking balance. + /// The currency used in staking. type Currency: LockableCurrency + ReservableCurrency; @@ -154,7 +154,7 @@ pub mod pallet { type MaxStakersPerCore: Get; /// Minimum amount user must have staked on a core. - /// User can stake less if they already have the minimum staking amount staked on that particular core. + /// User can stake less if they already have the minimum staking amount staked. #[pallet::constant] type MinimumStakingAmount: Get>; @@ -171,8 +171,8 @@ pub mod pallet { #[pallet::constant] type MaxUnlocking: Get; - /// Number of blocks that need to pass until unstaked value can be withdrawn. - /// When set to `0`, it's equal to have no unbound period. + /// Number of eras that need to pass until unstaked value can be withdrawn. + /// When set to `0`, it's equal to having no unbonding period. #[pallet::constant] type UnbondingPeriod: Get; @@ -181,7 +181,7 @@ pub mod pallet { /// When stakers claims rewards, they will either keep the number of `EraStake` values the same or they will reduce them by one. /// Stakers cannot add an additional `EraStake` value by calling `bond&stake` or `unbond&unstake` if they've reached the max number of values. /// - /// This ensures that history doesn't grow indefinitely - if there are too many chunks, stakers should first claim their former rewards + /// This ensures that history doesn't grow indefinitely - if there are too many chunks, stakers should first claim their former rewards /// before adding additional `EraStake` values. #[pallet::constant] type MaxEraStakeValues: Get; @@ -190,7 +190,7 @@ pub mod pallet { #[pallet::constant] type RewardRatio: Get<(u32, u32)>; - /// Threshold of staked tokens necessary for the core to become active. + /// Threshold of staked tokens necessary for a core to become active. #[pallet::constant] type StakeThresholdForActiveCore: Get>; @@ -254,7 +254,7 @@ pub mod pallet { CoreStakeInfo>, >; - /// Info about stakers stakes on particular core. + /// Info about staker's stakes on a particular core. #[pallet::storage] #[pallet::getter(fn staker_info)] pub type GeneralStakerInfo = StorageDoubleMap< @@ -267,7 +267,7 @@ pub mod pallet { ValueQuery, >; - /// Denotes whether the pallet is halted(disabled). + /// Denotes whether the pallet is halted (disabled). #[pallet::storage] #[pallet::getter(fn is_halted)] pub type Halted = StorageValue<_, bool, ValueQuery>; @@ -275,14 +275,14 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - /// Account has staked funds on a core. + /// Account has staked funds to a core. Staked { staker: T::AccountId, core: T::CoreId, amount: BalanceOf, }, - /// Account has unstaked funds on a core. + /// Account has unstaked funds from a core. Unstaked { staker: T::AccountId, core: T::CoreId, @@ -295,16 +295,16 @@ pub mod pallet { amount: BalanceOf, }, - /// New core added for staking. + /// New core registered for staking. CoreRegistered { core: T::CoreId }, - /// Core removed. + /// Core unregistered. CoreUnregistered { core: T::CoreId }, /// Beginning of a new era. NewEra { era: u32 }, - /// Staker claimed staking rewards. + /// Staker claimed rewards. StakerClaimed { staker: T::AccountId, core: T::CoreId, @@ -312,7 +312,7 @@ pub mod pallet { amount: BalanceOf, }, - /// Core claimed staking rewards. + /// Rewards claimed for core. CoreClaimed { core: T::CoreId, destination_account: T::AccountId, @@ -320,16 +320,17 @@ pub mod pallet { amount: BalanceOf, }, - /// Halted status changed. + /// Halt status changed. HaltChanged { is_halted: bool }, +/// Core metadata changed. MetadataChanged { core: T::CoreId, old_metadata: CoreMetadata, Vec, Vec>, new_metadata: CoreMetadata, Vec, Vec>, }, - /// Staker moved his stake. + /// Staker moved an amount of stake to another core. StakeMoved { staker: T::AccountId, from_core: T::CoreId, @@ -342,7 +343,7 @@ pub mod pallet { pub enum Error { /// Staking nothing. StakingNothing, - /// Staker tried to stake less than the minimum staking amount. + /// Attempted to stake less than the minimum amount. InsufficientBalance, /// Maximum number of stakers reached. MaxStakersReached, @@ -388,18 +389,14 @@ pub mod pallet { Halted, /// No halt change. NoHaltChange, - /// Staker moved staking to the same core. + /// Attempted to move stake to the same core. MoveStakeToSameCore, } #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(now: BlockNumberFor) -> Weight { - // As long as pallet is disabled, we shouldn't allow any storage modifications. - // This means we might prolong an era, but it's acceptable. - // Runtime upgrade should be timed, so we ensure that we complete it before - // a new era is triggered. This code is just a safety net to ensure nothing is broken - // if we fail to do that. + // If the pallet is halted we don't process a new era. if Self::is_halted() { return T::DbWeight::get().reads(1); } @@ -407,7 +404,7 @@ pub mod pallet { let previous_era = Self::current_era(); let next_era_starting_block = Self::next_era_starting_block(); - // Value is compared to 1 since genesis block is ignored + // Process a new era if past the start block of next era or if this is the first ever era. if now >= next_era_starting_block || previous_era.is_zero() { let blocks_per_era = T::BlocksPerEra::get(); let next_era = previous_era + 1; @@ -436,9 +433,8 @@ pub mod pallet { T::AccountId: From<[u8; 32]>, { /// Used to register core for staking. - /// The origin has to be from the multisig of the core. + /// The origin has to be the core origin. /// - /// Depending on the pallet configuration/state it is possible that developer needs to be whitelisted prior to registration. /// /// As part of this call, `RegisterDeposit` will be reserved from the core account. /// @@ -497,7 +493,7 @@ pub mod pallet { /// Unregister existing core for staking, making it ineligible for rewards from current era onwards and /// starts the unbonding period for the stakers. /// - /// The origin has to be from the multisig of the core. + /// The origin has to be the core origin. /// /// Deposit is returned to the core account. /// @@ -584,7 +580,7 @@ pub mod pallet { /// Used to change the metadata of a core. /// - /// The origin has to be from the multisig of the core. + /// The origin has to be the core origin. /// /// - `name`: Name of the core. /// - `description`: Description of the core. @@ -710,8 +706,8 @@ pub mod pallet { /// User needs to wait for the unbonding period to finish before being able to withdraw /// the funds via `withdraw_unstaked` call. /// - /// In case remaining staked balance on contract is below minimum staking amount, - /// entire stake for that contract will be unstaked. + /// In case remaining staked balance is below minimum staking amount, + /// entire stake will be unstaked. /// /// - `core_id`: Id of the core to unstake from. #[pallet::call_index(4)] @@ -808,9 +804,8 @@ pub mod pallet { Ok(().into()) } - /// Calculate the starker rewards. + /// Claim the staker's rewards. /// - /// If successful, returns reward amount. /// In case reward cannot be claimed or was already claimed, an error is raised. /// /// The dispatch origin for this call must be _Signed_ by the staker's account. @@ -861,9 +856,8 @@ pub mod pallet { Ok(().into()) } - /// Calculate the core reward for the specified era. + /// Claim core reward for the specified era. /// - /// If successful, returns reward amount. /// In case reward cannot be claimed or was already claimed, an error is raised. /// /// - `core_id`: Id of the core to claim rewards from. @@ -1176,7 +1170,7 @@ pub mod pallet { free_balance.saturating_sub(ledger.locked) } - /// Returns total value locked by core-staking. + /// Returns total value locked by staking. /// /// Note that this can differ from _total staked value_ since some funds might be undergoing the unbonding period. pub fn tvl() -> BalanceOf { diff --git a/OCIF/staking/src/primitives.rs b/OCIF/staking/src/primitives.rs index 1256c496..ca9cfc67 100644 --- a/OCIF/staking/src/primitives.rs +++ b/OCIF/staking/src/primitives.rs @@ -3,7 +3,6 @@ //! ## Overview //! //! Primitives provides the foundational types and traits for a staking pallet. -//! The staking pallet is likely a part of a blockchain system, given the use of terms like Balance, Era, and Stake. //! //! ## Types overview: //! @@ -208,7 +207,7 @@ impl StakerInfo { } } -/// A chunk of balance that is unlocked until a specific era. +/// A chunk of balance that is unlocking until a specific era. #[derive( Clone, PartialEq, Eq, Copy, Encode, Decode, Default, RuntimeDebug, TypeInfo, MaxEncodedLen, )] From 5c8b84688cc33bdd2dfd95a22a5321a1fc05ec5d Mon Sep 17 00:00:00 2001 From: Francisco Valentim Castilho Date: Sat, 24 Feb 2024 16:15:05 -0300 Subject: [PATCH 4/5] Fix: cargo fmt --- OCIF/staking/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OCIF/staking/src/lib.rs b/OCIF/staking/src/lib.rs index 0142265c..18f3d698 100644 --- a/OCIF/staking/src/lib.rs +++ b/OCIF/staking/src/lib.rs @@ -27,7 +27,7 @@ //! * `RegisterDeposit` - Defines the deposit amount for a Core to register in the system. //! * `MaxStakersPerCore` - Defines the maximum amount of Stakers allowed staking simultaneously towards the same Core. //! * `MinimumStakingAmount` - Defines the minimum amount a Staker has to stake to participate. -//! * `UnbondingPeriod` - Defines the period, in blocks, that it takes to unbond a stake. +//! * `UnbondingPeriod` - Defines the period, in eras, that it takes to unbond a stake. //! * `RewardRatio` - Defines the ratio of balance from the pot to distribute to Cores and Stakers, respectively. //! * `StakeThresholdForActiveCore` - Defines the threshold of stake a Core needs to surpass to become active. //! @@ -323,7 +323,7 @@ pub mod pallet { /// Halt status changed. HaltChanged { is_halted: bool }, -/// Core metadata changed. + /// Core metadata changed. MetadataChanged { core: T::CoreId, old_metadata: CoreMetadata, Vec, Vec>, @@ -433,6 +433,7 @@ pub mod pallet { T::AccountId: From<[u8; 32]>, { /// Used to register core for staking. + /// /// The origin has to be the core origin. /// /// From 7d2fc7b80a980ca38ef2db53b63dd9f5ff5d27b9 Mon Sep 17 00:00:00 2001 From: Francisco Valentim Castilho Date: Sat, 24 Feb 2024 16:19:11 -0300 Subject: [PATCH 5/5] Fix: removed blank like --- OCIF/staking/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/OCIF/staking/src/lib.rs b/OCIF/staking/src/lib.rs index 18f3d698..1d471c9c 100644 --- a/OCIF/staking/src/lib.rs +++ b/OCIF/staking/src/lib.rs @@ -436,7 +436,6 @@ pub mod pallet { /// /// The origin has to be the core origin. /// - /// /// As part of this call, `RegisterDeposit` will be reserved from the core account. /// /// - `name`: Name of the core.