use core::marker::PhantomData; use frame_support::dispatch::{DispatchInfo, GetDispatchInfo, PostDispatchInfo}; use frame_support::traits::IsSubType; use frame_system::RawOrigin; use pallet_evm::PrecompileHandle; use precompile_utils::EvmResult; use sp_core::{H256, U256}; use sp_runtime::traits::{AsSystemOriginSigner, Dispatchable, StaticLookup, UniqueSaturatedInto}; use crate::{PrecompileExt, PrecompileHandleExt}; pub struct BalanceTransferPrecompile(PhantomData); impl PrecompileExt for BalanceTransferPrecompile where R: frame_system::Config + pallet_balances::Config + pallet_evm::Config + pallet_subtensor::Config + pallet_shield::Config + pallet_subtensor_proxy::Config + Send + Sync + scale_info::TypeInfo, R::AccountId: From<[u8; 32]>, ::RuntimeOrigin: AsSystemOriginSigner + Clone, ::RuntimeCall: GetDispatchInfo + Dispatchable + IsSubType> + IsSubType> + IsSubType> + IsSubType>, ::RuntimeCall: From> + GetDispatchInfo + Dispatchable, <::Lookup as StaticLookup>::Source: From, ::Balance: TryFrom, { const INDEX: u64 = 2048; } #[precompile_utils::precompile] impl BalanceTransferPrecompile where R: frame_system::Config + pallet_balances::Config + pallet_evm::Config + pallet_subtensor::Config + pallet_shield::Config + pallet_subtensor_proxy::Config + Send + Sync + scale_info::TypeInfo, R::AccountId: From<[u8; 32]>, ::RuntimeOrigin: AsSystemOriginSigner + Clone, ::RuntimeCall: GetDispatchInfo + Dispatchable + IsSubType> + IsSubType> + IsSubType> + IsSubType>, ::RuntimeCall: From> + GetDispatchInfo + Dispatchable, <::Lookup as StaticLookup>::Source: From, ::Balance: TryFrom, { #[precompile::public("transfer(bytes32)")] #[precompile::payable] fn transfer(handle: &mut impl PrecompileHandle, address: H256) -> EvmResult<()> { let amount_sub = handle.try_convert_apparent_value::()?; if amount_sub.is_zero() { return Ok(()); } let dest = R::AccountId::from(address.0).into(); let call = pallet_balances::Call::::transfer_allow_death { dest, value: amount_sub.unique_saturated_into(), }; handle.try_dispatch_runtime_call::(call, RawOrigin::Signed(Self::account_id())) } }