Skip to content

Use TaoCurrency for pallet balances balance type#2417

Open
gztensor wants to merge 8 commits intodevnet-readyfrom
chore/imbalances
Open

Use TaoCurrency for pallet balances balance type#2417
gztensor wants to merge 8 commits intodevnet-readyfrom
chore/imbalances

Conversation

@gztensor
Copy link
Contributor

Description

Replace u64 with TaoCurrency for pallet balances balance and all over the subtensor code.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe): Cleanup

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run ./scripts/fix_rust.sh to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

ales-otf
ales-otf previously approved these changes Feb 11, 2026
Copy link
Contributor

@ales-otf ales-otf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my comments are just stylistic preferences. additionally i didn't understand why you needed to add this _u64 specifier everywhere.

other than that i think this change is safe, because there is an entrypoint for this Balance type (the alias) so if you change it, the rest is compiler-driven refactoring. the inconsistency might appear only in places outside of this type or where we had a mixed type errors (alpha/tao used interchangeably). the first thing is unlikely for the balance value, the second can have a place. so far there still persists this issue with StakeThreshold, but i didn't see anything else in your PR

@gztensor gztensor added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Feb 11, 2026
Comment on lines +132 to +136
impl From<i32> for $currency_type {
fn from(value: i32) -> Self {
Self(value.unsigned_abs().into())
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lossy conversion, maybe it should use try_from?

fn rem(self, rhs: Self) -> Self::Output {
let lhs_u64: u64 = self.into();
let rhs_u64: u64 = rhs.into();
(lhs_u64 % rhs_u64).into()
Copy link
Collaborator

@l0r1s l0r1s Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This panics if rhs_u64 is 0. (playground)

impl RemAssign for TaoCurrency {
#[allow(clippy::arithmetic_side_effects)]
fn rem_assign(&mut self, rhs: Self) {
*self = *self % rhs;
Copy link
Collaborator

@l0r1s l0r1s Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rhs == 0 panics, do we want to keep the behavior as close as possible to the normal one maybe?

Comment on lines 434 to 439
pub struct ExistentialDeposit;
impl frame_support::traits::Get<TaoCurrency> for ExistentialDeposit {
fn get() -> TaoCurrency {
TaoCurrency::new(500)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use parameter_types! for automatic implem

l0r1s
l0r1s previously approved these changes Feb 11, 2026
Copy link
Collaborator

@l0r1s l0r1s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small remarks around the code that can panic.

It adds a lot of type safety and pave the way for more, great stuff!

Note for later: I was thinking about the naming of TaoCurrency and AlphaCurrency, a more appropriate name to match with Substrate primitives would be TaoBalance and AlphaBalance with the CustomBalance trait (as supertrait of Balance) because Currency as actually a full fledged system where you can make transfer, slash, burn, emit, etc...

@gztensor gztensor dismissed stale reviews from l0r1s and ales-otf via ade8b6f February 11, 2026 22:45
Currency -> Token
AlphaCurrency -> AlphaBalance
TaoCurrency -> TaoBalance
CurrencyReserve -> TokenReserve
@gztensor
Copy link
Contributor Author

Small remarks around the code that can panic.

It adds a lot of type safety and pave the way for more, great stuff!

Note for later: I was thinking about the naming of TaoCurrency and AlphaCurrency, a more appropriate name to match with Substrate primitives would be TaoBalance and AlphaBalance with the CustomBalance trait (as supertrait of Balance) because Currency as actually a full fledged system where you can make transfer, slash, burn, emit, etc...

Good point! I renamed the following:

Currency -> Token
AlphaCurrency -> AlphaBalance
TaoCurrency -> TaoBalance
CurrencyReserve -> TokenReserve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants