-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CodeSee Demo Review Fork #3
Conversation
…rors for T::Currency::set_freeze/thaw;
…942-capacity-replace-currency-trait-with-fungible-trait
@@ -100,6 +101,16 @@ pub mod pallet { | |||
}; | |||
use sp_runtime::traits::{AtLeast32BitUnsigned, MaybeDisplay}; | |||
|
|||
/// A reason for freezing funds. | |||
#[pallet::composite_enum] | |||
pub enum FreezeReason { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FreezeReason is required for the fungible traits. The enum is defined and used by capacity and time-release. Comments in the Parity deprecation pr indicated that there should only be one enum:
Both Holds and Freezes require an identifier which is configurable and is expected to be an enum aggregated across all pallet instances of the runtime.
This enum is scoped to each pallet, but we may want to move it to a common location within the runtime, if possible.
/// Function that allows a balance to be locked. | ||
type Currency: LockableCurrency<Self::AccountId, Moment = BlockNumberFor<Self>>; | ||
/// Functions that allow a fungible balance to be changed or frozen. | ||
type Currency: MutateFreeze<Self::AccountId, Id = Self::RuntimeFreezeReason> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating Frequency's type Currency
with the traits from frame_support::traits::tokens::fungible
@@ -562,7 +579,7 @@ impl<T: Config> Pallet<T> { | |||
staker: &T::AccountId, | |||
proposed_amount: BalanceOf<T>, | |||
) -> BalanceOf<T> { | |||
let account_balance = T::Currency::free_balance(&staker); | |||
let account_balance = T::Currency::balance(&staker); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some fungible methods require name changes: free_balance -> balance
@@ -589,9 +606,9 @@ impl<T: Config> Pallet<T> { | |||
let staking_account = Self::get_staking_account_for(staker).unwrap_or_default(); | |||
let total_locked = staking_account.active.saturating_add(total_unlocking); | |||
if total_locked.is_zero() { | |||
T::Currency::remove_lock(STAKING_ID, &staker); | |||
T::Currency::thaw(&FreezeReason::Staked.into(), staker)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove_lock
was infallible and did not return anything. thaw
returns a result, so do_withdraw_unstaked
needs to propagate any errors.
type RuntimeFreezeReason: From<FreezeReason>; | ||
|
||
/// We need MaybeSerializeDeserialize because of the genesis config. | ||
type Balance: Balance + MaybeSerializeDeserialize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In time-release
, the Frequency type Balance
needed to be updated to include the serialize/deserialize traits.
@@ -467,6 +468,7 @@ pub type MaxReleaseSchedules = ConstU32<{ MAX_RELEASE_SCHEDULES }>; | |||
// the descriptions of these configs. | |||
impl pallet_time_release::Config for Runtime { | |||
type RuntimeEvent = RuntimeEvent; | |||
type Balance = Balance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we update type Balance
because time-release
adds the MaybeSerializeDeserialize
trait.
…942-capacity-replace-currency-trait-with-fungible-trait
#[codec(index = 0)] | ||
Staked, | ||
/// Funds are currently locked and are not yet liquid. | ||
NotYetVested, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this value if enum stays in this pallet.
assert_eq!(14u64, Balances::locks(&staker)[0].amount); | ||
assert_eq!( | ||
14u64, | ||
<Test as Config>::Currency::balance_frozen(&FreezeReason::Staked.into(), &staker) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check to see if line can be shorter by removing Test as Config.
"Account do not have enough balance" | ||
); | ||
|
||
T::Currency::set_lock( | ||
RELEASE_LOCK_ID, | ||
let _ = T::Currency::set_freeze( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle Result.
type MaxHolds = ConstU32<0>; | ||
type MaxFreezes = ConstU32<0>; | ||
type MaxHolds = BalancesMaxHolds; | ||
type MaxFreezes = BalancesMaxFreezes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need more research on Locks/Freezes and how they affect time-release pallet, etc.
Goal
The goal of this PR is to replace the
Currency
trait with thefungible
trait.Closes frequency-chain#942
Closes frequency-chain#1532
Discussion
The following Parity issues/PRs were used as references for changes:
Deprecate Currency - PR 12951 (Explanation of necessary changes.)
FRAME: Move pallets over to use fungible traits (Issue to track Parity's efforts to update their pallets.)
pallet vesting / update to use fungible (Example of some necessary changes.)
Changes
.cargo-deny.toml
Added "multiformats" forcid
crate to fix warning.vscode/settings.json
Added script that sets up the source map for the rust std library files for debugging.Cargo.lock
cargo updated.e2e/package-lock.json
npm updated.tokens::fungible::
InspectFungible
forbalance()
andreducible_balance()
InspectFreeze
forbalance_frozen()
Mutate
forset_balance()
,mint_into()
MutateFreeze
forset_freeze()
, andthaw()
pub enum FreezeReason
to supportfreezes
set_freeze()
andthaw()
can fail, so errors needed to be propagated..expect()
whereset_freeze()
orthaw()
can fail.FreezeIdentifier
andRuntimeFreezeReason
configured with defaults.How to Review
set_freeze()
andthaw()
which can now fail and make sure all error states are propagated correctly without possibility forpanic
balance()
is used correctly, or should be changed toreducible_balance()
. The calculations evaluating the Existential Deposit (ED) have been updated and Parity comments indicate thatreducible_balance()
is most likely the value needed.Checklist