@@ -1194,15 +1194,15 @@ parameter_types! {
1194
1194
/// The difference between EVM decimals and Substrate decimals.
1195
1195
/// Substrate balances has 9 decimals, while EVM has 18, so the
1196
1196
/// 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 ;
1198
1198
1199
1199
pub struct SubtensorEvmBalanceConverter ;
1200
1200
1201
1201
impl BalanceConverter for SubtensorEvmBalanceConverter {
1202
1202
/// Convert from Substrate balance (u64) to EVM balance (U256)
1203
1203
fn into_evm_balance ( value : U256 ) -> Option < U256 > {
1204
1204
value
1205
- . checked_mul ( U256 :: from ( EVM_DECIMALS_FACTOR ) )
1205
+ . checked_mul ( U256 :: from ( EVM_TO_SUBSTRATE_DECIMALS ) )
1206
1206
. and_then ( |evm_value| {
1207
1207
// Ensure the result fits within the maximum U256 value
1208
1208
if evm_value <= U256 :: MAX {
@@ -1216,7 +1216,7 @@ impl BalanceConverter for SubtensorEvmBalanceConverter {
1216
1216
/// Convert from EVM balance (U256) to Substrate balance (u64)
1217
1217
fn into_substrate_balance ( value : U256 ) -> Option < U256 > {
1218
1218
value
1219
- . checked_div ( U256 :: from ( EVM_DECIMALS_FACTOR ) )
1219
+ . checked_div ( U256 :: from ( EVM_TO_SUBSTRATE_DECIMALS ) )
1220
1220
. and_then ( |substrate_value| {
1221
1221
// Ensure the result fits within the TAO balance type (u64)
1222
1222
if substrate_value <= U256 :: from ( u64:: MAX ) {
@@ -2141,7 +2141,7 @@ fn test_into_substrate_balance_valid() {
2141
2141
#[ test]
2142
2142
fn test_into_substrate_balance_large_value ( ) {
2143
2143
// 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
2145
2145
let expected_substrate_balance = U256 :: from ( u64:: MAX ) ;
2146
2146
2147
2147
let result = SubtensorEvmBalanceConverter :: into_substrate_balance ( evm_balance) ;
@@ -2151,7 +2151,7 @@ fn test_into_substrate_balance_large_value() {
2151
2151
#[ test]
2152
2152
fn test_into_substrate_balance_exceeds_u64 ( ) {
2153
2153
// 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 ) ;
2155
2155
2156
2156
let result = SubtensorEvmBalanceConverter :: into_substrate_balance ( evm_balance) ;
2157
2157
assert_eq ! ( result, None ) ; // Exceeds u64, should return None
@@ -2191,7 +2191,7 @@ fn test_into_evm_balance_valid() {
2191
2191
fn test_into_evm_balance_overflow ( ) {
2192
2192
// Substrate balance larger than u64::MAX but valid within U256
2193
2193
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 ) ;
2195
2195
2196
2196
let result = SubtensorEvmBalanceConverter :: into_evm_balance ( substrate_balance) ;
2197
2197
assert_eq ! ( result, Some ( expected_evm_balance) ) ; // Should return the scaled value
0 commit comments