Skip to content

Commit 4ea9663

Browse files
committed
Fix decimals in gas fees (max_fee_per_gas and max_priority_fee_per_gas)
1 parent 40fff23 commit 4ea9663

File tree

5 files changed

+41
-47
lines changed

5 files changed

+41
-47
lines changed

Cargo.lock

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/src/lib.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,24 +1093,20 @@ parameter_types! {
10931093
/// difference factor is 9 decimals, or 10^9
10941094
const EVM_DECIMALS_FACTOR: u64 = 1_000_000_000_u64;
10951095

1096-
pub struct SubtensorEvmBalanceConverter<F>(PhantomData<F>);
1097-
impl<T: pallet_evm::Config> BalanceConverter<T> for SubtensorEvmBalanceConverter<T>
1098-
where
1099-
pallet_evm::BalanceOf<T>: TryFrom<U256> + Into<U256>,
1096+
pub struct SubtensorEvmBalanceConverter;
1097+
impl BalanceConverter for SubtensorEvmBalanceConverter
11001098
{
1101-
fn into_evm_balance(
1102-
value: <
1103-
<T as pallet_evm::Config>::Currency as frame_support::traits::tokens::fungible::Inspect<<T as frame_system::Config>::AccountId>
1104-
>::Balance,
1105-
) -> Option<U256> {
1099+
fn into_evm_balance(value: U256) -> Option<U256> {
11061100
U256::from(UniqueSaturatedInto::<u128>::unique_saturated_into(value))
11071101
.checked_mul(U256::from(EVM_DECIMALS_FACTOR))
11081102
}
11091103

1110-
fn into_substrate_balance(value: U256) -> Option<pallet_evm::BalanceOf<T>> {
1111-
value
1112-
.checked_div(U256::from(EVM_DECIMALS_FACTOR))
1113-
.and_then(|result| result.try_into().ok())
1104+
fn into_substrate_balance(value: U256) -> Option<U256> {
1105+
if value <= U256::from(u64::MAX) {
1106+
value.checked_div(U256::from(EVM_DECIMALS_FACTOR))
1107+
} else {
1108+
None
1109+
}
11141110
}
11151111
}
11161112

@@ -1136,7 +1132,7 @@ impl pallet_evm::Config for Runtime {
11361132
type SuicideQuickClearLimit = SuicideQuickClearLimit;
11371133
type Timestamp = Timestamp;
11381134
type WeightInfo = pallet_evm::weights::SubstrateWeight<Self>;
1139-
type BalanceConverter = SubtensorEvmBalanceConverter<Self>;
1135+
type BalanceConverter = SubtensorEvmBalanceConverter;
11401136
}
11411137

11421138
parameter_types! {
@@ -1159,7 +1155,7 @@ impl pallet_dynamic_fee::Config for Runtime {
11591155
}
11601156

11611157
parameter_types! {
1162-
pub DefaultBaseFeePerGas: U256 = U256::from(20);
1158+
pub DefaultBaseFeePerGas: U256 = U256::from(20_000_000_000_u128);
11631159
pub DefaultElasticity: Permill = Permill::from_parts(125_000);
11641160
}
11651161
pub struct BaseFeeThreshold;

runtime/src/precompiles/balance_transfer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use pallet_evm::{
44
PrecompileOutput, PrecompileResult,
55
};
66
use sp_core::U256;
7-
use sp_runtime::traits::Dispatchable;
7+
use sp_runtime::traits::{Dispatchable, UniqueSaturatedInto};
88
use sp_std::vec;
99

1010
use crate::{Runtime, RuntimeCall};
@@ -44,7 +44,7 @@ impl BalanceTransferPrecompile {
4444
let call =
4545
RuntimeCall::Balances(pallet_balances::Call::<Runtime>::transfer_allow_death {
4646
dest: account_id_dst.into(),
47-
value: amount_sub,
47+
value: amount_sub.unique_saturated_into(),
4848
});
4949

5050
let result = call.dispatch(RawOrigin::Signed(account_id_src).into());

runtime/src/precompiles/ed25519.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg_attr(not(feature = "std"), no_std)]
2-
31
extern crate alloc;
42

53
use alloc::vec::Vec;

runtime/src/precompiles/staking.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use pallet_evm::{
3232
};
3333
use sp_core::crypto::Ss58Codec;
3434
use sp_core::U256;
35-
use sp_runtime::traits::BlakeTwo256;
35+
use sp_runtime::traits::{BlakeTwo256, UniqueSaturatedInto};
3636
use sp_runtime::traits::Dispatchable;
3737
use sp_runtime::AccountId32;
3838

@@ -75,7 +75,7 @@ impl StakingPrecompile {
7575
// Create the add_stake call
7676
let call = RuntimeCall::SubtensorModule(pallet_subtensor::Call::<Runtime>::add_stake {
7777
hotkey,
78-
amount_staked: amount_sub,
78+
amount_staked: amount_sub.unique_saturated_into(),
7979
});
8080
// Dispatch the add_stake call
8181
Self::dispatch(handle, call)
@@ -96,7 +96,7 @@ impl StakingPrecompile {
9696

9797
let call = RuntimeCall::SubtensorModule(pallet_subtensor::Call::<Runtime>::remove_stake {
9898
hotkey,
99-
amount_unstaked: amount_sub,
99+
amount_unstaked: amount_sub.unique_saturated_into(),
100100
});
101101
Self::dispatch(handle, call)
102102
}
@@ -164,7 +164,7 @@ impl StakingPrecompile {
164164
let transfer_call =
165165
RuntimeCall::Balances(pallet_balances::Call::<Runtime>::transfer_allow_death {
166166
dest: account_id.clone().into(),
167-
value: amount_sub,
167+
value: amount_sub.unique_saturated_into(),
168168
});
169169

170170
// Execute the transfer

0 commit comments

Comments
 (0)