4

I am implementing a pallet which interacts with pallet_balances via Currency trait. For some reason, when I call any operation on currency trait (like Slash on screen below), it is not aligned to number of decimals and unit is not shown. In explorer all fee related payments are scaled (here Withdraw), but all calls done by my pallet not.

Missing currency and decimals recalculation

impl my_pallet::Config for Runtime {
    type RuntimeEvent = RuntimeEvent;
    type Currency = Balances;
    type ReserveIdentifier = <Runtime as pallet_balances::Config>::ReserveIdentifier;
}
#[pallet::config]
pub trait Config: frame_system::Config {
    /// Because this pallet emits events, it depends on the runtime's definition of an event.
    type RuntimeEvent: From<Event<Self>>
        + IsType<<Self as frame_system::Config>::RuntimeEvent>
        + TryInto<Event<Self>>;

    /// The Currency handler for pallet.
    type Currency: NamedReservableCurrency<
        Self::AccountId,
        ReserveIdentifier = Self::ReserveIdentifier,
    >;

    /// The id type for named reserves.
    type ReserveIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy + From<[u8; 8]>;
}
type AccountOf<T> = <T as frame_system::Config>::AccountId;
pub type BalanceOf<T> =
    <<T as Config>::Currency as frame_support::traits::Currency<AccountOf<T>>>::Balance;
pub type ReserveIdentifierOf<T> =
    <<T as Config>::Currency as NamedReservableCurrency<AccountOf<T>>>::ReserveIdentifier;
type NegativeImbalanceOf<T> =
    <<T as Config>::Currency as Currency<AccountOf<T>>>::NegativeImbalance;

#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::my_extrinsic())]
#[frame_support::transactional]
pub fn my_extrinsic(
    origin: OriginFor<T>,
) -> DispatchResult {
    let origin = ensure_signed(origin)?;
    T::Currency::slash(&origin, 100_000_000_u32.into());
    Ok(())
}

Please note, that it occurs even I call RAW Currency trait, not ReservableCurrency or NamedReservableCurrency.

Do you have any ideas how to fix it?

2
  • Not sure I understand your question. What were you expecting to see in the explorer? Make sure you have your chain's tokenDecimals and tokenSymbol configured properly.
    – Bruno
    Jun 22 at 18:48
  • For Withdraw operation done by pallet_transaction_payment value in explorer is adjusted with decimals and in the right side is exposed currency symbol (USDC). But for operation done by my pallet call, there is RAW amount. Of course if I divide it by 6 decimals then value will be correct, but I am curious why it is not done automatically, even both calls use the same trait abstraction to access pallet_balances
    – Klapeyron
    Jun 26 at 7:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.