Skip to content

Commit

Permalink
account for ED when taking staking pot issuance
Browse files Browse the repository at this point in the history
  • Loading branch information
talhadaar committed Nov 22, 2024
1 parent abb8596 commit faa5f66
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pallets/parachain-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@ pub mod pallet {
pallet_prelude::*,
storage::bounded_btree_map::BoundedBTreeMap,
traits::{
Currency, EstimateNextSessionRotation, ExistenceRequirement::KeepAlive, Get,
LockIdentifier, LockableCurrency, ReservableCurrency, StorageVersion, WithdrawReasons,
tokens::{fungible::Inspect, Fortitude, Preservation},
Currency, EstimateNextSessionRotation,
ExistenceRequirement::KeepAlive,
Get, LockIdentifier, LockableCurrency, ReservableCurrency, StorageVersion,
WithdrawReasons,
},
BoundedVec, PalletId,
};
Expand Down Expand Up @@ -228,6 +231,7 @@ pub mod pallet {
type Currency: Currency<Self::AccountId, Balance = Self::CurrencyBalance>
+ ReservableCurrency<Self::AccountId, Balance = Self::CurrencyBalance>
+ LockableCurrency<Self::AccountId, Balance = Self::CurrencyBalance>
+ Inspect<Self::AccountId, Balance = Self::CurrencyBalance>
+ Eq;

/// Just the `Currency::Balance` type; we have this item to allow us to
Expand Down Expand Up @@ -2863,9 +2867,15 @@ pub mod pallet {
pub(crate) fn pot_issuance() -> (Weight, BalanceOf<T>) {
let pot = Self::account_id();
let weight = Weight::from_parts(1, 0);
let issuance = T::Currency::free_balance(&pot)
.checked_sub(&T::Currency::minimum_balance())
.unwrap_or_else(Zero::zero);
let ed = <T::Currency as frame_support::traits::fungible::Inspect<T::AccountId>>::minimum_balance();
let issuance = if ed == T::CurrencyBalance::from(0_u32) {
T::Currency::reducible_balance(&pot, Preservation::Preserve, Fortitude::Polite)
// Avoid the pot complaint no balance there
.checked_sub(&T::CurrencyBalance::from(10_u32))
.unwrap_or_else(Zero::zero)
} else {
T::Currency::reducible_balance(&pot, Preservation::Preserve, Fortitude::Polite)
};

(weight, issuance)
}
Expand Down

0 comments on commit faa5f66

Please sign in to comment.