Skip to content

Commit

Permalink
whoops
Browse files Browse the repository at this point in the history
  • Loading branch information
sam0x17 committed Nov 15, 2024
1 parent 14c2ce7 commit de2049d
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,20 +1121,16 @@ const EVM_DECIMALS_FACTOR: u64 = 1_000_000_000_u64;
pub struct SubtensorEvmBalanceConverter;

impl BalanceConverter for SubtensorEvmBalanceConverter {
/// Convert from Substrate balance to EVM balance
fn into_evm_balance(value: U256) -> Option<U256> {
// Scale up by EVM_DECIMALS_FACTOR, ensuring no overflow
value.checked_mul(U256::from(EVM_DECIMALS_FACTOR))
}

/// Convert from EVM balance to Substrate balance
fn into_substrate_balance(value: U256) -> Option<U256> {
// Scale down by EVM_DECIMALS_FACTOR, truncating precision safely
value
.checked_div(U256::from(EVM_DECIMALS_FACTOR))
.and_then(|substrate_value| {
// Ensure the result fits in Substrate's Balance type (u128)
if substrate_value <= U256::from(u128::MAX) {
// Ensure the result fits within the Subtensor Balance type (u64)
if substrate_value <= U256::from(u64::MAX) {
Some(substrate_value)
} else {
None
Expand Down

0 comments on commit de2049d

Please sign in to comment.