fix: Complete snowbridge pezpallet rebrand and critical bug fixes

- snowbridge-pezpallet-* → pezsnowbridge-pezpallet-* (201 refs)
- pallet/ directories → pezpallet/ (4 locations)
- Fixed pezpallet.rs self-include recursion bug
- Fixed sc-chain-spec hardcoded crate name in derive macro
- Reverted .pezpallet_by_name() to .pallet_by_name() (subxt API)
- Added BizinikiwiConfig type alias for zombienet tests
- Deleted obsolete session state files

Verified: pezsnowbridge-pezpallet-*, pezpallet-staking,
pezpallet-staking-async, pezframe-benchmarking-cli all pass cargo check
This commit is contained in:
2025-12-16 09:57:23 +03:00
parent eea003e14d
commit 3139ffa25e
3022 changed files with 42157 additions and 23579 deletions
@@ -6,7 +6,7 @@ edition.workspace = true
license = "Apache-2.0"
homepage.workspace = true
repository.workspace = true
description = "FRAME delegated staking pallet"
description = "FRAME delegated staking pezpallet"
documentation = "https://docs.rs/pezpallet-delegated-staking"
[package.metadata.docs.rs]
@@ -20,7 +20,7 @@
use super::*;
use pezsp_staking::{DelegationInterface, DelegationMigrator, OnStakingUpdate};
impl<T: Config> DelegationInterface for Pallet<T> {
impl<T: Config> DelegationInterface for Pezpallet<T> {
type Balance = BalanceOf<T>;
type AccountId = T::AccountId;
@@ -46,7 +46,7 @@ impl<T: Config> DelegationInterface for Pallet<T> {
agent: Agent<Self::AccountId>,
reward_account: &Self::AccountId,
) -> DispatchResult {
Pallet::<T>::register_agent(
Pezpallet::<T>::register_agent(
RawOrigin::Signed(agent.clone().get()).into(),
reward_account.clone(),
)
@@ -54,7 +54,7 @@ impl<T: Config> DelegationInterface for Pallet<T> {
/// Remove `Agent` registration.
fn remove_agent(agent: Agent<Self::AccountId>) -> DispatchResult {
Pallet::<T>::remove_agent(RawOrigin::Signed(agent.clone().get()).into())
Pezpallet::<T>::remove_agent(RawOrigin::Signed(agent.clone().get()).into())
}
/// Add more delegation to the `Agent` account.
@@ -63,7 +63,7 @@ impl<T: Config> DelegationInterface for Pallet<T> {
agent: Agent<Self::AccountId>,
amount: Self::Balance,
) -> DispatchResult {
Pallet::<T>::delegate_to_agent(RawOrigin::Signed(who.get()).into(), agent.get(), amount)
Pezpallet::<T>::delegate_to_agent(RawOrigin::Signed(who.get()).into(), agent.get(), amount)
}
/// Withdraw delegation of `delegator` to `Agent`.
@@ -76,7 +76,7 @@ impl<T: Config> DelegationInterface for Pallet<T> {
amount: Self::Balance,
num_slashing_spans: u32,
) -> DispatchResult {
Pallet::<T>::release_delegation(
Pezpallet::<T>::release_delegation(
RawOrigin::Signed(agent.get()).into(),
delegator.get(),
amount,
@@ -95,11 +95,11 @@ impl<T: Config> DelegationInterface for Pallet<T> {
value: Self::Balance,
maybe_reporter: Option<Self::AccountId>,
) -> pezsp_runtime::DispatchResult {
Pallet::<T>::do_slash(agent, delegator, value, maybe_reporter)
Pezpallet::<T>::do_slash(agent, delegator, value, maybe_reporter)
}
}
impl<T: Config> DelegationMigrator for Pallet<T> {
impl<T: Config> DelegationMigrator for Pezpallet<T> {
type Balance = BalanceOf<T>;
type AccountId = T::AccountId;
@@ -107,14 +107,14 @@ impl<T: Config> DelegationMigrator for Pallet<T> {
agent: Agent<Self::AccountId>,
reward_account: &Self::AccountId,
) -> DispatchResult {
Pallet::<T>::migrate_to_agent(RawOrigin::Signed(agent.get()).into(), reward_account.clone())
Pezpallet::<T>::migrate_to_agent(RawOrigin::Signed(agent.get()).into(), reward_account.clone())
}
fn migrate_delegation(
agent: Agent<Self::AccountId>,
delegator: Delegator<Self::AccountId>,
value: Self::Balance,
) -> DispatchResult {
Pallet::<T>::migrate_delegation(
Pezpallet::<T>::migrate_delegation(
RawOrigin::Signed(agent.get()).into(),
delegator.get(),
value,
@@ -138,7 +138,7 @@ impl<T: Config> DelegationMigrator for Pallet<T> {
}
}
impl<T: Config> OnStakingUpdate<T::AccountId, BalanceOf<T>> for Pallet<T> {
impl<T: Config> OnStakingUpdate<T::AccountId, BalanceOf<T>> for Pezpallet<T> {
fn on_slash(
who: &T::AccountId,
_slashed_active: BalanceOf<T>,
@@ -15,9 +15,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! # Delegated Staking Pallet
//! # Delegated Staking Pezpallet
//!
//! This pallet implements [`pezsp_staking::DelegationInterface`] that provides delegation
//! This pezpallet implements [`pezsp_staking::DelegationInterface`] that provides delegation
//! functionality to `delegators` and `agents`. It is designed to be used in conjunction with
//! [`StakingInterface`] and relies on [`Config::CoreStaking`] to provide primitive staking
//! functions.
@@ -38,24 +38,24 @@
//!
//! ## Goals
//!
//! Direct nomination on the Staking pallet does not scale well. Nominations pools were created to
//! Direct nomination on the Staking pezpallet does not scale well. Nominations pools were created to
//! address this by pooling delegator funds into one account and then staking it. This though had
//! a very critical limitation that the funds were moved from delegator account to pool account
//! and hence the delegator lost control over their funds for using it for other purposes such as
//! governance. This pallet aims to solve this by extending the staking pallet to support a new
//! governance. This pezpallet aims to solve this by extending the staking pezpallet to support a new
//! primitive function: delegation of funds to an `agent` with the intent of staking. The agent can
//! then stake the delegated funds to [`Config::CoreStaking`] on behalf of the delegators.
//!
//! ### Withdrawal Management
//! Agent unbonding does not regulate ordering of consequent withdrawal for delegators. This is upto
//! the consumer of this pallet to implement in what order unbondable funds from
//! the consumer of this pezpallet to implement in what order unbondable funds from
//! [`Config::CoreStaking`] can be withdrawn by the delegators.
//!
//! ### Reward and Slashing
//! This pallet does not enforce any specific strategy for how rewards or slashes are applied. It
//! This pezpallet does not enforce any specific strategy for how rewards or slashes are applied. It
//! is upto the `agent` account to decide how to apply the rewards and slashes.
//!
//! This importantly allows clients of this pallet to build their own strategies for reward/slashes.
//! This importantly allows clients of this pezpallet to build their own strategies for reward/slashes.
//! For example, an `agent` account can choose to first slash the reward pot before slashing the
//! delegators. Or part of the reward can go to an insurance fund that can be used to cover any
//! potential future slashes. The goal is to eventually allow foreign MultiLocations
@@ -64,42 +64,42 @@
//! ## Core functions
//!
//! - Allow an account to receive delegations. See [`Pallet::register_agent`].
//! - Delegate funds to an `agent` account. See [`Pallet::delegate_to_agent`].
//! - Allow an account to receive delegations. See [`Pezpallet::register_agent`].
//! - Delegate funds to an `agent` account. See [`Pezpallet::delegate_to_agent`].
//! - Release delegated funds from an `agent` account to the `delegator`. See
//! [`Pallet::release_delegation`].
//! - Migrate a `Nominator` account to an `agent` account. See [`Pallet::migrate_to_agent`].
//! [`Pezpallet::release_delegation`].
//! - Migrate a `Nominator` account to an `agent` account. See [`Pezpallet::migrate_to_agent`].
//! Explained in more detail in the `Migration` section.
//! - Migrate unclaimed delegated funds from `agent` to delegator. When a nominator migrates to an
//! agent, the funds are held in a proxy account. This function allows the delegator to claim
//! their share of the funds from the proxy account. See [`Pallet::migrate_delegation`].
//! their share of the funds from the proxy account. See [`Pezpallet::migrate_delegation`].
//!
//! ## Lazy Slashing
//! One of the reasons why direct nominators on staking pallet cannot scale well is because all
//! One of the reasons why direct nominators on staking pezpallet cannot scale well is because all
//! nominators are slashed at the same time. This is expensive and needs to be bounded operation.
//!
//! This pallet implements a lazy slashing mechanism. Any slashes to the `agent` are posted in its
//! This pezpallet implements a lazy slashing mechanism. Any slashes to the `agent` are posted in its
//! `AgentLedger` as a pending slash. Since the actual amount is held in the multiple
//! `delegator` accounts, this pallet has no way to know how to apply slash. It is the `agent`'s
//! responsibility to apply slashes for each delegator, one at a time. Staking pallet ensures the
//! `delegator` accounts, this pezpallet has no way to know how to apply slash. It is the `agent`'s
//! responsibility to apply slashes for each delegator, one at a time. Staking pezpallet ensures the
//! pending slash never exceeds staked amount and would freeze further withdraws until all pending
//! slashes are cleared.
//!
//! The user of this pallet can apply slash using
//! The user of this pezpallet can apply slash using
//! [DelegationInterface::delegator_slash](pezsp_staking::DelegationInterface::delegator_slash).
//!
//! ## Migration from Nominator to Agent
//! More details [here](https://hackmd.io/@ak0n/454-np-governance).
//!
//! ## Nomination Pool vs Delegation Staking
//! This pallet is not a replacement for Nomination Pool but adds a new primitive in addition to
//! staking pallet that can be used by Nomination Pool to support delegation based staking. It can
//! be thought of as an extension to the Staking Pallet in relation to Nomination Pools.
//! This pezpallet is not a replacement for Nomination Pool but adds a new primitive in addition to
//! staking pezpallet that can be used by Nomination Pool to support delegation based staking. It can
//! be thought of as an extension to the Staking Pezpallet in relation to Nomination Pools.
//! Technically, these changes could be made in one of those pallets as well but that would have
//! meant significant refactoring and high chances of introducing a regression. With this approach,
//! we can keep the existing pallets with minimal changes and introduce a new pallet that can be
//! we can keep the existing pallets with minimal changes and introduce a new pezpallet that can be
//! optionally used by Nomination Pool. The vision is to build this in a configurable way such that
//! runtime can choose whether to use this pallet or not.
//! runtime can choose whether to use this pezpallet or not.
//!
//! With that said, following is the main difference between
//! #### Nomination Pool without delegation support
@@ -108,14 +108,14 @@
//!
//! #### Nomination Pool with delegation support
//! 1) delegate fund from delegator to pool account, and
//! 2) stake from pool account as an `Agent` account on the staking pallet.
//! 2) stake from pool account as an `Agent` account on the staking pezpallet.
//!
//! The difference being, in the second approach, the delegated funds will be locked in-place in
//! user's account enabling them to participate in use cases that allows use of `held` funds such
//! as participation in governance voting.
//!
//! Nomination pool still does all the heavy lifting around pool administration, reward
//! distribution, lazy slashing and as such, is not meant to be replaced with this pallet.
//! distribution, lazy slashing and as such, is not meant to be replaced with this pezpallet.
//!
//! ## Limitations
//! - Rewards can not be auto-compounded.
@@ -135,7 +135,7 @@ pub mod types;
extern crate alloc;
pub use pallet::*;
pub use pezpallet::*;
use types::*;
@@ -160,7 +160,7 @@ use pezsp_runtime::{
};
use pezsp_staking::{Agent, Delegator, EraIndex, StakingInterface, StakingUnchecked};
/// The log target of this pallet.
/// The log target of this pezpallet.
pub const LOG_TARGET: &str = "runtime::delegated-staking";
// syntactic sugar for logging.
#[macro_export]
@@ -168,7 +168,7 @@ macro_rules! log {
($level:tt, $patter:expr $(, $values:expr)* $(,)?) => {
log::$level!(
target: $crate::LOG_TARGET,
concat!("[{:?}] 🏊‍♂️ ", $patter), <pezframe_system::Pallet<T>>::block_number() $(, $values)*
concat!("[{:?}] 🏊‍♂️ ", $patter), <pezframe_system::Pezpallet<T>>::block_number() $(, $values)*
)
};
}
@@ -177,24 +177,24 @@ pub type BalanceOf<T> =
use pezframe_system::{ensure_signed, pezpallet_prelude::*, RawOrigin};
#[pezframe_support::pallet]
pub mod pallet {
#[pezframe_support::pezpallet]
pub mod pezpallet {
use super::*;
/// The in-code storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(0);
#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(PhantomData<T>);
#[pezpallet::pezpallet]
#[pezpallet::storage_version(STORAGE_VERSION)]
pub struct Pezpallet<T>(PhantomData<T>);
#[pallet::config]
#[pezpallet::config]
pub trait Config: pezframe_system::Config {
/// The overarching event type.
#[allow(deprecated)]
type RuntimeEvent: From<Event<Self>> + IsType<<Self as pezframe_system::Config>::RuntimeEvent>;
/// Injected identifier for the pallet.
#[pallet::constant]
/// Injected identifier for the pezpallet.
#[pezpallet::constant]
type PalletId: Get<pezframe_support::PalletId>;
/// Currency type.
@@ -206,7 +206,7 @@ pub mod pallet {
type OnSlash: OnUnbalanced<Credit<Self::AccountId, Self::Currency>>;
/// Fraction of the slash that is rewarded to the caller of pending slash to the agent.
#[pallet::constant]
#[pezpallet::constant]
type SlashRewardFraction: Get<Perbill>;
/// Overarching hold reason.
@@ -216,7 +216,7 @@ pub mod pallet {
type CoreStaking: StakingUnchecked<Balance = BalanceOf<Self>, AccountId = Self::AccountId>;
}
#[pallet::error]
#[pezpallet::error]
pub enum Error<T> {
/// The account cannot perform this operation.
NotAllowed,
@@ -244,20 +244,20 @@ pub mod pallet {
NothingToSlash,
/// Failed to withdraw amount from Core Staking.
WithdrawFailed,
/// Operation not supported by this pallet.
/// Operation not supported by this pezpallet.
NotSupported,
}
/// A reason for placing a hold on funds.
#[pallet::composite_enum]
#[pezpallet::composite_enum]
pub enum HoldReason {
/// Funds held for stake delegation to another account.
#[codec(index = 0)]
StakingDelegation,
}
#[pallet::event]
#[pallet::generate_deposit(pub (super) fn deposit_event)]
#[pezpallet::event]
#[pezpallet::generate_deposit(pub (super) fn deposit_event)]
pub enum Event<T: Config> {
/// Funds delegated by a delegator.
Delegated { agent: T::AccountId, delegator: T::AccountId, amount: BalanceOf<T> },
@@ -273,19 +273,19 @@ pub mod pallet {
///
/// Implementation note: We are not using a double map with `delegator` and `agent` account
/// as keys since we want to restrict delegators to delegate only to one account at a time.
#[pallet::storage]
#[pezpallet::storage]
pub type Delegators<T: Config> =
CountedStorageMap<_, Twox64Concat, T::AccountId, Delegation<T>, OptionQuery>;
/// Map of `Agent` to their `Ledger`.
#[pallet::storage]
#[pezpallet::storage]
pub type Agents<T: Config> =
CountedStorageMap<_, Twox64Concat, T::AccountId, AgentLedger<T>, OptionQuery>;
// This pallet is not currently written with the intention of exposing any calls. But the
// This pezpallet is not currently written with the intention of exposing any calls. But the
// functions defined in the following impl block should act as a good reference for how the
// exposed calls would look like when exposed.
impl<T: Config> Pallet<T> {
impl<T: Config> Pezpallet<T> {
/// Register an account to become a stake `Agent`. Sometimes also called a `Delegatee`.
///
/// Delegators can authorize `Agent`s to stake on their behalf by delegating their funds to
@@ -450,8 +450,8 @@ pub mod pallet {
}
}
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
#[pezpallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pezpallet<T> {
#[cfg(feature = "try-runtime")]
fn try_state(_n: BlockNumberFor<T>) -> Result<(), pezsp_runtime::TryRuntimeError> {
Self::do_try_state()
@@ -459,7 +459,7 @@ pub mod pallet {
}
}
impl<T: Config> Pallet<T> {
impl<T: Config> Pezpallet<T> {
/// Derive an account from the migrating agent account where the unclaimed delegation funds
/// are held.
pub fn generate_proxy_delegator(agent: Agent<T::AccountId>) -> Delegator<T::AccountId> {
@@ -765,7 +765,7 @@ impl<T: Config> Pallet<T> {
use alloc::collections::btree_map::BTreeMap;
#[cfg(any(test, feature = "try-runtime"))]
impl<T: Config> Pallet<T> {
impl<T: Config> Pezpallet<T> {
pub(crate) fn do_try_state() -> Result<(), pezsp_runtime::TryRuntimeError> {
// build map to avoid reading storage multiple times.
let delegation_map = Delegators::<T>::iter().collect::<BTreeMap<_, _>>();
@@ -48,11 +48,11 @@ pub mod unversioned {
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 0));
let new_proxy =
Pallet::<T>::generate_proxy_delegator(Agent::from(agent.clone()));
Pezpallet::<T>::generate_proxy_delegator(Agent::from(agent.clone()));
// accrue read writes for `do_migrate_delegation`
weight.saturating_accrue(T::DbWeight::get().reads_writes(8, 8));
let _ = Pallet::<T>::do_migrate_delegation(
let _ = Pezpallet::<T>::do_migrate_delegation(
Delegator::from(old_proxy.clone()),
new_proxy.clone(),
delegation.amount,
@@ -84,7 +84,7 @@ pub mod unversioned {
Agents::<T>::iter_keys().take(MaxAgents::get() as usize).for_each(|agent| {
let old_proxy: T::AccountId = old_proxy_delegator(agent.clone());
let held_balance = Pallet::<T>::held_balance_of(Delegator::from(old_proxy.clone()));
let held_balance = Pezpallet::<T>::held_balance_of(Delegator::from(old_proxy.clone()));
let delegation = Delegation::<T>::get(&old_proxy);
if delegation.is_some() || !held_balance.is_zero() {
log!(
@@ -106,7 +106,7 @@ impl onchain::Config for OnChainSeqPhragmen {
impl pezpallet_staking::Config for Runtime {
type OldCurrency = Balances;
type Currency = Balances;
type UnixTime = pezpallet_timestamp::Pallet<Self>;
type UnixTime = pezpallet_timestamp::Pezpallet<Self>;
type AdminOrigin = pezframe_system::EnsureRoot<Self::AccountId>;
type EraPayout = pezpallet_staking::ConvertCurve<RewardCurve>;
type ElectionProvider = onchain::OnChainExecution<OnChainSeqPhragmen>;
@@ -236,7 +236,7 @@ impl ExtBuilder {
ext.execute_with(|| {
// for events to be deposited.
pezframe_system::Pallet::<Runtime>::set_block_number(1);
pezframe_system::Pezpallet::<Runtime>::set_block_number(1);
// set era for staking.
start_era(0);
});
@@ -250,7 +250,7 @@ impl ExtBuilder {
ext.execute_with(|| {
#[cfg(feature = "try-runtime")]
<AllPalletsWithSystem as pezframe_support::traits::TryState<u64>>::try_state(
pezframe_system::Pallet::<Runtime>::block_number(),
pezframe_system::Pezpallet::<Runtime>::block_number(),
pezframe_support::traits::TryStateSelect::All,
)
.unwrap();
@@ -650,7 +650,7 @@ mod staking_integration {
DelegatedStaking::generate_proxy_delegator(Agent::from(agent)).get();
assert_ok!(DelegatedStaking::migrate_to_agent(RawOrigin::Signed(agent).into(), 201));
// after migration, no provider left since free balance is 0 and staking pallet released
// after migration, no provider left since free balance is 0 and staking pezpallet released
// all funds.
assert_eq!(System::providers(&agent), 0);
assert_eq!(Balances::free_balance(agent), 0);
@@ -73,12 +73,12 @@ impl<T: Config> Delegation<T> {
if self.amount == Zero::zero() {
<Delegators<T>>::remove(key);
// Remove provider if no delegation left.
let _ = pezframe_system::Pallet::<T>::dec_providers(key).defensive();
let _ = pezframe_system::Pezpallet::<T>::dec_providers(key).defensive();
return;
}
} else {
// this is a new delegation. Provide for this account.
pezframe_system::Pallet::<T>::inc_providers(key);
pezframe_system::Pezpallet::<T>::inc_providers(key);
}
<Delegators<T>>::insert(key, self);