--- a/pallets/balances-adapter/src/erc.rs +++ b/pallets/balances-adapter/src/erc.rs @@ -1,6 +1,7 @@ use crate::Config; use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*}; -use pallet_common::erc::{CommonEvmHandler, PrecompileHandle, PrecompileResult}; +use frame_support::traits::Currency; +use pallet_common::erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult}; use pallet_evm_coder_substrate::{ call, dispatch_to_evm, execution::{PreDispatch, Result}, @@ -45,37 +46,48 @@ #[solidity_interface(name = ERC20, events(ERC20Events), enum(derive(PreDispatch)), enum_attr(weight), expect_selector = 0x942e8b22)] impl NativeFungibleHandle { - fn name(&self) -> Result { - // Ok(decode_utf16(self.name.iter().copied()) - // .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER)) - // .collect::()) - todo!() + fn allowance(&self, owner: Address, spender: Address) -> Result { + Ok(U256::zero()) } - fn symbol(&self) -> Result { - // Ok(String::from_utf8_lossy(&self.token_prefix).into()) - todo!() + // #[weight(>::approve())] + fn approve(&mut self, caller: Caller, spender: Address, amount: U256) -> Result { + // self.consume_store_reads(1)?; + Err("Approve not supported now".into()) } - fn total_supply(&self) -> Result { + fn balance_of(&self, owner: Address) -> Result { // self.consume_store_reads(1)?; - // Ok(>::get(self.id).into()) - todo!() + let owner = T::CrossAccountId::from_eth(owner); + let a = ::Currency::free_balance(owner.as_sub()); + Ok(a.into()) } fn decimals(&self) -> Result { // Ok(if let CollectionMode::Fungible(decimals) = &self.mode { // *decimals // } else { - // unreachable!() + // unreachable! // }) + + // From config 18 todo!() } - fn balance_of(&self, owner: Address) -> Result { + fn name(&self) -> Result { + // Ok(decode_utf16(self.name.iter().copied()) + // .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER)) + // .collect::()) + todo!() + } + + fn symbol(&self) -> Result { + // Ok(String::from_utf8_lossy(&self.token_prefix).into()) + todo!() + } + + fn total_supply(&self) -> Result { // self.consume_store_reads(1)?; - // let owner = T::CrossAccountId::from_eth(owner); - // let balance = >::get((self.id, owner)); - // Ok(balance.into()) + // Ok(>::get(self.id).into()) todo!() } @@ -112,27 +124,6 @@ // >::transfer_from(self, &caller, &from, &to, amount, &budget) // .map_err(dispatch_to_evm::)?; // Ok(true) - todo!() - } - - // #[weight(>::approve())] - fn approve(&mut self, caller: Caller, spender: Address, amount: U256) -> Result { - // let caller = T::CrossAccountId::from_eth(caller); - // let spender = T::CrossAccountId::from_eth(spender); - // let amount = amount.try_into().map_err(|_| "amount overflow")?; - - // >::set_allowance(self, &caller, &spender, amount) - // .map_err(dispatch_to_evm::)?; - // Ok(true) - todo!() - } - - fn allowance(&self, owner: Address, spender: Address) -> Result { - // self.consume_store_reads(1)?; - // let owner = T::CrossAccountId::from_eth(owner); - // let spender = T::CrossAccountId::from_eth(spender); - - // Ok(>::get((self.id, owner, spender)).into()) todo!() } } --- a/pallets/balances-adapter/src/lib.rs +++ b/pallets/balances-adapter/src/lib.rs @@ -8,8 +8,16 @@ #[frame_support::pallet] pub mod pallet { + use sp_core::U256; + #[pallet::config] - pub trait Config: frame_system::Config + pallet_evm_coder_substrate::Config {} + pub trait Config: frame_system::Config + pallet_evm_coder_substrate::Config { + type Currency: frame_support::traits::Currency< + Self::AccountId, + Balance = Self::CurrencyBalance, + >; + type CurrencyBalance: Into; + } #[pallet::pallet] pub struct Pallet(_); --- a/runtime/common/config/pallets/mod.rs +++ b/runtime/common/config/pallets/mod.rs @@ -25,7 +25,7 @@ }, Runtime, RuntimeEvent, RuntimeCall, RuntimeOrigin, Balances, }; -use frame_support::traits::{ConstU32, ConstU64}; +use frame_support::traits::{ConstU32, ConstU64, Currency}; use up_common::{ types::{AccountId, Balance, BlockNumber}, constants::*, @@ -84,7 +84,8 @@ type WeightInfo = pallet_nonfungible::weights::SubstrateWeight; } impl pallet_balances_adapter::Config for Runtime { - // type WeightInfo = pallet_nonfungible::weights::SubstrateWeight; + type Currency = Balances; + type CurrencyBalance = >::Balance; } parameter_types! {