Skip to content

Commit 6b09787

Browse files
committed
rename EVM_TO_SUBSTRATE_DECIMALS
1 parent d261f67 commit 6b09787

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

runtime/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,15 +1194,15 @@ parameter_types! {
11941194
/// The difference between EVM decimals and Substrate decimals.
11951195
/// Substrate balances has 9 decimals, while EVM has 18, so the
11961196
/// difference factor is 9 decimals, or 10^9
1197-
const EVM_DECIMALS_FACTOR: u64 = 1_000_000_000_u64;
1197+
const EVM_TO_SUBSTRATE_DECIMALS: u64 = 1_000_000_000_u64;
11981198

11991199
pub struct SubtensorEvmBalanceConverter;
12001200

12011201
impl BalanceConverter for SubtensorEvmBalanceConverter {
12021202
/// Convert from Substrate balance (u64) to EVM balance (U256)
12031203
fn into_evm_balance(value: U256) -> Option<U256> {
12041204
value
1205-
.checked_mul(U256::from(EVM_DECIMALS_FACTOR))
1205+
.checked_mul(U256::from(EVM_TO_SUBSTRATE_DECIMALS))
12061206
.and_then(|evm_value| {
12071207
// Ensure the result fits within the maximum U256 value
12081208
if evm_value <= U256::MAX {
@@ -1216,7 +1216,7 @@ impl BalanceConverter for SubtensorEvmBalanceConverter {
12161216
/// Convert from EVM balance (U256) to Substrate balance (u64)
12171217
fn into_substrate_balance(value: U256) -> Option<U256> {
12181218
value
1219-
.checked_div(U256::from(EVM_DECIMALS_FACTOR))
1219+
.checked_div(U256::from(EVM_TO_SUBSTRATE_DECIMALS))
12201220
.and_then(|substrate_value| {
12211221
// Ensure the result fits within the TAO balance type (u64)
12221222
if substrate_value <= U256::from(u64::MAX) {
@@ -2141,7 +2141,7 @@ fn test_into_substrate_balance_valid() {
21412141
#[test]
21422142
fn test_into_substrate_balance_large_value() {
21432143
// Maximum valid balance for u64
2144-
let evm_balance = U256::from(u64::MAX) * U256::from(EVM_DECIMALS_FACTOR); // Max u64 TAO in EVM
2144+
let evm_balance = U256::from(u64::MAX) * U256::from(EVM_TO_SUBSTRATE_DECIMALS); // Max u64 TAO in EVM
21452145
let expected_substrate_balance = U256::from(u64::MAX);
21462146

21472147
let result = SubtensorEvmBalanceConverter::into_substrate_balance(evm_balance);
@@ -2151,7 +2151,7 @@ fn test_into_substrate_balance_large_value() {
21512151
#[test]
21522152
fn test_into_substrate_balance_exceeds_u64() {
21532153
// EVM balance that exceeds u64 after conversion
2154-
let evm_balance = (U256::from(u64::MAX) + U256::from(1)) * U256::from(EVM_DECIMALS_FACTOR);
2154+
let evm_balance = (U256::from(u64::MAX) + U256::from(1)) * U256::from(EVM_TO_SUBSTRATE_DECIMALS);
21552155

21562156
let result = SubtensorEvmBalanceConverter::into_substrate_balance(evm_balance);
21572157
assert_eq!(result, None); // Exceeds u64, should return None
@@ -2191,7 +2191,7 @@ fn test_into_evm_balance_valid() {
21912191
fn test_into_evm_balance_overflow() {
21922192
// Substrate balance larger than u64::MAX but valid within U256
21932193
let substrate_balance = U256::from(u64::MAX) + U256::from(1); // Large balance
2194-
let expected_evm_balance = substrate_balance * U256::from(EVM_DECIMALS_FACTOR);
2194+
let expected_evm_balance = substrate_balance * U256::from(EVM_TO_SUBSTRATE_DECIMALS);
21952195

21962196
let result = SubtensorEvmBalanceConverter::into_evm_balance(substrate_balance);
21972197
assert_eq!(result, Some(expected_evm_balance)); // Should return the scaled value

0 commit comments

Comments
 (0)