1use crate::Config;2use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*};3use pallet_common::erc::{CommonEvmHandler, PrecompileHandle, PrecompileResult};4use pallet_evm_coder_substrate::{5 call, dispatch_to_evm,6 execution::{PreDispatch, Result},7 frontier_contract, WithRecorder, SubstrateRecorder,8};9use sp_core::{U256};10use sp_std::vec::Vec;1112frontier_contract! {13 macro_rules! NativeFungibleHandle_result {...}14 impl<T: Config> Contract for NativeFungibleHandle<T> {...}15}1617#[derive(ToLog)]18pub enum ERC20Events {19 Transfer {20 #[indexed]21 from: Address,22 #[indexed]23 to: Address,24 value: U256,25 },26 Approval {27 #[indexed]28 owner: Address,29 #[indexed]30 spender: Address,31 value: U256,32 },33}3435pub struct NativeFungibleHandle<T: Config>(SubstrateRecorder<T>);3637impl<T: Config> WithRecorder<T> for NativeFungibleHandle<T> {38 fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {39 &self.040 }41 fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {42 self.043 }44}4546#[solidity_interface(name = ERC20, events(ERC20Events), enum(derive(PreDispatch)), enum_attr(weight), expect_selector = 0x942e8b22)]47impl<T: Config> NativeFungibleHandle<T> {48 fn name(&self) -> Result<String> {49 50 51 52 todo!()53 }5455 fn symbol(&self) -> Result<String> {56 57 todo!()58 }59 fn total_supply(&self) -> Result<U256> {60 61 62 todo!()63 }6465 fn decimals(&self) -> Result<u8> {66 67 68 69 70 71 todo!()72 }7374 fn balance_of(&self, owner: Address) -> Result<U256> {75 76 77 78 79 todo!()80 }8182 83 fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {84 85 86 87 88 89 9091 92 93 todo!()94 }9596 97 fn transfer_from(98 &mut self,99 caller: Caller,100 from: Address,101 to: Address,102 amount: U256,103 ) -> Result<bool> {104 105 106 107 108 109 110 111112 113 114 115 todo!()116 }117118 119 fn approve(&mut self, caller: Caller, spender: Address, amount: U256) -> Result<bool> {120 121 122 123124 125 126 127 todo!()128 }129130 fn allowance(&self, owner: Address, spender: Address) -> Result<U256> {131 132 133 134135 136 todo!()137 }138}139140#[solidity_interface(141 name = UniqueNativeFungible,142 is(ERC20),143 enum(derive(PreDispatch))144)]145impl<T: Config> NativeFungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}146147generate_stubgen!(gen_impl, UniqueNativeFungibleCall<()>, true);148generate_stubgen!(gen_iface, UniqueNativeFungibleCall<()>, false);149150impl<T: Config> CommonEvmHandler for NativeFungibleHandle<T>151where152 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,153{154 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNativeFungible.raw");155156 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {157 call::<T, UniqueNativeFungibleCall<T>, _, _>(handle, self)158 }159}