git.delta.rocks / unique-network / refs/commits / dfdf99444c40

difftreelog

feat add dispatching

Trubnikov Sergey2023-04-21parent: #60662cc.patch.diff
in: master

6 files changed

addedpallets/balances-adapter/src/common.rsdiffbeforeafterboth
--- /dev/null
+++ b/pallets/balances-adapter/src/common.rs
@@ -0,0 +1,352 @@
+use alloc::vec::Vec;
+use core::marker::PhantomData;
+use crate::{Config, NativeFungibleHandle};
+use pallet_common::{CommonCollectionOperations, CommonWeightInfo};
+
+pub struct CommonWeights<T: Config>(PhantomData<T>);
+impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
+	fn create_multiple_items(
+		amount: &[up_data_structs::CreateItemData],
+	) -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn create_multiple_items_ex(
+		cost: &up_data_structs::CreateItemExData<T::CrossAccountId>,
+	) -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn burn_item() -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn set_collection_properties(amount: u32) -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn delete_collection_properties(amount: u32) -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn set_token_properties(amount: u32) -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn delete_token_properties(amount: u32) -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn set_token_property_permissions(amount: u32) -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn transfer() -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn approve() -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn approve_from() -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn transfer_from() -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn burn_from() -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn burn_recursively_self_raw() -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn burn_recursively_breadth_raw(amount: u32) -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn token_owner() -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn set_allowance_for_all() -> frame_support::weights::Weight {
+		todo!()
+	}
+
+	fn force_repair_item() -> frame_support::weights::Weight {
+		todo!()
+	}
+}
+
+/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallete
+/// methods and adds weight info.
+impl<T: Config> CommonCollectionOperations<T> for NativeFungibleHandle<T> {
+	fn create_item(
+		&self,
+		sender: <T>::CrossAccountId,
+		to: <T>::CrossAccountId,
+		data: up_data_structs::CreateItemData,
+		nesting_budget: &dyn up_data_structs::budget::Budget,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn create_multiple_items(
+		&self,
+		sender: <T>::CrossAccountId,
+		to: <T>::CrossAccountId,
+		data: Vec<up_data_structs::CreateItemData>,
+		nesting_budget: &dyn up_data_structs::budget::Budget,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn create_multiple_items_ex(
+		&self,
+		sender: <T>::CrossAccountId,
+		data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,
+		nesting_budget: &dyn up_data_structs::budget::Budget,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn burn_item(
+		&self,
+		sender: <T>::CrossAccountId,
+		token: up_data_structs::TokenId,
+		amount: u128,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn burn_item_recursively(
+		&self,
+		sender: <T>::CrossAccountId,
+		token: up_data_structs::TokenId,
+		self_budget: &dyn up_data_structs::budget::Budget,
+		breadth_budget: &dyn up_data_structs::budget::Budget,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn set_collection_properties(
+		&self,
+		sender: <T>::CrossAccountId,
+		properties: Vec<up_data_structs::Property>,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn delete_collection_properties(
+		&self,
+		sender: &<T>::CrossAccountId,
+		property_keys: Vec<up_data_structs::PropertyKey>,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn set_token_properties(
+		&self,
+		sender: <T>::CrossAccountId,
+		token_id: up_data_structs::TokenId,
+		properties: Vec<up_data_structs::Property>,
+		budget: &dyn up_data_structs::budget::Budget,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn delete_token_properties(
+		&self,
+		sender: <T>::CrossAccountId,
+		token_id: up_data_structs::TokenId,
+		property_keys: Vec<up_data_structs::PropertyKey>,
+		budget: &dyn up_data_structs::budget::Budget,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn set_token_property_permissions(
+		&self,
+		sender: &<T>::CrossAccountId,
+		property_permissions: Vec<up_data_structs::PropertyKeyPermission>,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn transfer(
+		&self,
+		sender: <T>::CrossAccountId,
+		to: <T>::CrossAccountId,
+		token: up_data_structs::TokenId,
+		amount: u128,
+		budget: &dyn up_data_structs::budget::Budget,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn approve(
+		&self,
+		sender: <T>::CrossAccountId,
+		spender: <T>::CrossAccountId,
+		token: up_data_structs::TokenId,
+		amount: u128,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn approve_from(
+		&self,
+		sender: <T>::CrossAccountId,
+		from: <T>::CrossAccountId,
+		to: <T>::CrossAccountId,
+		token: up_data_structs::TokenId,
+		amount: u128,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn transfer_from(
+		&self,
+		sender: <T>::CrossAccountId,
+		from: <T>::CrossAccountId,
+		to: <T>::CrossAccountId,
+		token: up_data_structs::TokenId,
+		amount: u128,
+		budget: &dyn up_data_structs::budget::Budget,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn burn_from(
+		&self,
+		sender: <T>::CrossAccountId,
+		from: <T>::CrossAccountId,
+		token: up_data_structs::TokenId,
+		amount: u128,
+		budget: &dyn up_data_structs::budget::Budget,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn check_nesting(
+		&self,
+		sender: <T>::CrossAccountId,
+		from: (up_data_structs::CollectionId, up_data_structs::TokenId),
+		under: up_data_structs::TokenId,
+		budget: &dyn up_data_structs::budget::Budget,
+	) -> frame_support::sp_runtime::DispatchResult {
+		todo!()
+	}
+
+	fn nest(
+		&self,
+		under: up_data_structs::TokenId,
+		to_nest: (up_data_structs::CollectionId, up_data_structs::TokenId),
+	) {
+		todo!()
+	}
+
+	fn unnest(
+		&self,
+		under: up_data_structs::TokenId,
+		to_nest: (up_data_structs::CollectionId, up_data_structs::TokenId),
+	) {
+		todo!()
+	}
+
+	fn account_tokens(&self, account: <T>::CrossAccountId) -> Vec<up_data_structs::TokenId> {
+		todo!()
+	}
+
+	fn collection_tokens(&self) -> Vec<up_data_structs::TokenId> {
+		todo!()
+	}
+
+	fn token_exists(&self, token: up_data_structs::TokenId) -> bool {
+		todo!()
+	}
+
+	fn last_token_id(&self) -> up_data_structs::TokenId {
+		todo!()
+	}
+
+	fn token_owner(
+		&self,
+		token: up_data_structs::TokenId,
+	) -> Result<<T>::CrossAccountId, up_data_structs::TokenOwnerError> {
+		todo!()
+	}
+
+	fn token_owners(&self, token: up_data_structs::TokenId) -> Vec<<T>::CrossAccountId> {
+		todo!()
+	}
+
+	fn token_property(
+		&self,
+		token_id: up_data_structs::TokenId,
+		key: &up_data_structs::PropertyKey,
+	) -> Option<up_data_structs::PropertyValue> {
+		todo!()
+	}
+
+	fn token_properties(
+		&self,
+		token: up_data_structs::TokenId,
+		keys: Option<Vec<up_data_structs::PropertyKey>>,
+	) -> Vec<up_data_structs::Property> {
+		todo!()
+	}
+
+	fn total_supply(&self) -> u32 {
+		todo!()
+	}
+
+	fn account_balance(&self, account: <T>::CrossAccountId) -> u32 {
+		todo!()
+	}
+
+	fn balance(&self, account: <T>::CrossAccountId, token: up_data_structs::TokenId) -> u128 {
+		todo!()
+	}
+
+	fn total_pieces(&self, token: up_data_structs::TokenId) -> Option<u128> {
+		todo!()
+	}
+
+	fn allowance(
+		&self,
+		sender: <T>::CrossAccountId,
+		spender: <T>::CrossAccountId,
+		token: up_data_structs::TokenId,
+	) -> u128 {
+		todo!()
+	}
+
+	fn refungible_extensions(&self) -> Option<&dyn pallet_common::RefungibleExtensions<T>> {
+		todo!()
+	}
+
+	fn set_allowance_for_all(
+		&self,
+		owner: <T>::CrossAccountId,
+		operator: <T>::CrossAccountId,
+		approve: bool,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+
+	fn allowance_for_all(&self, owner: <T>::CrossAccountId, operator: <T>::CrossAccountId) -> bool {
+		todo!()
+	}
+
+	fn repair_item(
+		&self,
+		token: up_data_structs::TokenId,
+	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+		todo!()
+	}
+}
modifiedpallets/balances-adapter/src/erc.rsdiffbeforeafterboth
--- a/pallets/balances-adapter/src/erc.rs
+++ b/pallets/balances-adapter/src/erc.rs
@@ -1,5 +1,5 @@
-use crate::Config;
-use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*};
+use crate::{Config, NativeFungibleHandle};
+use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};
 use frame_support::traits::{Currency, ExistenceRequirement};
 use pallet_common::{
 	erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult},
@@ -34,17 +34,6 @@
 		spender: Address,
 		value: U256,
 	},
-}
-
-pub struct NativeFungibleHandle<T: Config>(SubstrateRecorder<T>);
-
-impl<T: Config> WithRecorder<T> for NativeFungibleHandle<T> {
-	fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {
-		&self.0
-	}
-	fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {
-		self.0
-	}
 }
 
 #[solidity_interface(name = ERC20, events(ERC20Events), enum(derive(PreDispatch)), enum_attr(weight), expect_selector = 0x942e8b22)]
modifiedpallets/balances-adapter/src/lib.rsdiffbeforeafterboth
--- a/pallets/balances-adapter/src/lib.rs
+++ b/pallets/balances-adapter/src/lib.rs
@@ -4,17 +4,42 @@
 
 extern crate alloc;
 pub use pallet::*;
+use pallet_common::CollectionHandle;
+use pallet_evm_coder_substrate::{WithRecorder, SubstrateRecorder};
 
+pub mod common;
 pub mod erc;
 
+pub struct NativeFungibleHandle<T: Config>(CollectionHandle<T>);
+impl<T: Config> NativeFungibleHandle<T> {
+	pub fn cast(inner: CollectionHandle<T>) -> Self {
+		Self(inner)
+	}
+
+	/// Casts [`NativeFungibleHandle`] into [`CollectionHandle`][`pallet_common::CollectionHandle`].
+	pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {
+		self.0
+	}
+}
+
+impl<T: Config> WithRecorder<T> for NativeFungibleHandle<T> {
+	fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {
+		&self.0.recorder
+	}
+	fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {
+		self.0.recorder
+	}
+}
 #[frame_support::pallet]
 pub mod pallet {
 	use alloc::string::String;
-	use frame_support::traits::Get;
+	use frame_support::{traits::Get, sp_runtime::DispatchResult};
 	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 + pallet_common::Config
+	{
 		type Currency: frame_support::traits::Currency<
 			Self::AccountId,
 			Balance = Self::CurrencyBalance,
@@ -28,6 +53,10 @@
 	#[pallet::pallet]
 	pub struct Pallet<T>(_);
 
-	#[pallet::call]
-	impl<T: Config> Pallet<T> {}
+	// #[pallet::call]
+	impl<T: Config> Pallet<T> {
+		pub fn dummy() -> DispatchResult {
+			Ok(())
+		}
+	}
 }
modifiedruntime/common/dispatch.rsdiffbeforeafterboth
before · runtime/common/dispatch.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{dispatch::DispatchResult, ensure};18use pallet_evm::{PrecompileHandle, PrecompileResult};19use sp_core::H160;20use sp_runtime::DispatchError;21use sp_std::{borrow::ToOwned, vec::Vec};22use pallet_common::{23	CollectionById, CollectionHandle, CommonCollectionOperations, erc::CommonEvmHandler,24	eth::map_eth_to_id,25};26pub use pallet_common::dispatch::CollectionDispatch;27use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};28use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};29use pallet_refungible::{30	Pallet as PalletRefungible, RefungibleHandle, erc_token::RefungibleTokenHandle,31};32use up_data_structs::{33	CollectionMode, CreateCollectionData, MAX_DECIMAL_POINTS, mapping::TokenAddressMapping,34	CollectionId, CollectionFlags,35};3637#[cfg(not(feature = "refungible"))]38use pallet_common::unsupported;3940pub enum CollectionDispatchT<T>41where42	T: pallet_fungible::Config + pallet_nonfungible::Config + pallet_refungible::Config,43{44	Fungible(FungibleHandle<T>),45	Nonfungible(NonfungibleHandle<T>),46	Refungible(RefungibleHandle<T>),47}48impl<T> CollectionDispatch<T> for CollectionDispatchT<T>49where50	T: pallet_common::Config51		+ pallet_unique::Config52		+ pallet_fungible::Config53		+ pallet_nonfungible::Config54		+ pallet_refungible::Config,55{56	fn create(57		sender: T::CrossAccountId,58		payer: T::CrossAccountId,59		data: CreateCollectionData<T::AccountId>,60		flags: CollectionFlags,61	) -> Result<CollectionId, DispatchError> {62		let id = match data.mode {63			CollectionMode::NFT => {64				<PalletNonfungible<T>>::init_collection(sender, payer, data, flags)?65			}66			CollectionMode::Fungible(decimal_points) => {67				// check params68				ensure!(69					decimal_points <= MAX_DECIMAL_POINTS,70					pallet_unique::Error::<T>::CollectionDecimalPointLimitExceeded71				);72				<PalletFungible<T>>::init_collection(sender, payer, data, flags)?73			}7475			#[cfg(feature = "refungible")]76			CollectionMode::ReFungible => {77				<PalletRefungible<T>>::init_collection(sender, payer, data, flags)?78			}7980			#[cfg(not(feature = "refungible"))]81			CollectionMode::ReFungible => return unsupported!(T),82		};83		Ok(id)84	}8586	fn destroy(sender: T::CrossAccountId, collection: CollectionHandle<T>) -> DispatchResult {87		match collection.mode {88			CollectionMode::ReFungible => {89				PalletRefungible::destroy_collection(RefungibleHandle::cast(collection), &sender)?90			}91			CollectionMode::Fungible(_) => {92				PalletFungible::destroy_collection(FungibleHandle::cast(collection), &sender)?93			}94			CollectionMode::NFT => {95				PalletNonfungible::destroy_collection(NonfungibleHandle::cast(collection), &sender)?96			}97		}98		Ok(())99	}100101	fn dispatch(handle: CollectionHandle<T>) -> Self {102		match handle.mode {103			CollectionMode::Fungible(_) => Self::Fungible(FungibleHandle::cast(handle)),104			CollectionMode::NFT => Self::Nonfungible(NonfungibleHandle::cast(handle)),105			CollectionMode::ReFungible => Self::Refungible(RefungibleHandle::cast(handle)),106		}107	}108109	fn into_inner(self) -> CollectionHandle<T> {110		match self {111			Self::Fungible(f) => f.into_inner(),112			Self::Nonfungible(f) => f.into_inner(),113			Self::Refungible(f) => f.into_inner(),114		}115	}116117	fn as_dyn(&self) -> &dyn CommonCollectionOperations<T> {118		match self {119			Self::Fungible(h) => h,120			Self::Nonfungible(h) => h,121			Self::Refungible(h) => h,122		}123	}124}125126impl<T> pallet_evm::OnMethodCall<T> for CollectionDispatchT<T>127where128	T: pallet_common::Config129		+ pallet_unique::Config130		+ pallet_fungible::Config131		+ pallet_nonfungible::Config132		+ pallet_refungible::Config,133	T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,134{135	fn is_reserved(target: &H160) -> bool {136		map_eth_to_id(target).is_some()137	}138	fn is_used(target: &H160) -> bool {139		map_eth_to_id(target)140			.map(<CollectionById<T>>::contains_key)141			.unwrap_or(false)142	}143	fn get_code(target: &H160) -> Option<Vec<u8>> {144		if let Some(collection_id) = map_eth_to_id(target) {145			let collection = <CollectionById<T>>::get(collection_id)?;146			Some(147				match collection.mode {148					CollectionMode::NFT => <NonfungibleHandle<T>>::CODE,149					CollectionMode::Fungible(_) => <FungibleHandle<T>>::CODE,150					CollectionMode::ReFungible => <RefungibleHandle<T>>::CODE,151				}152				.to_owned(),153			)154		} else if let Some((collection_id, _token_id)) =155			<T as pallet_common::Config>::EvmTokenAddressMapping::address_to_token(target)156		{157			let collection = <CollectionById<T>>::get(collection_id)?;158			if collection.mode != CollectionMode::ReFungible {159				return None;160			}161			// TODO: check token existence162			Some(<RefungibleTokenHandle<T>>::CODE.to_owned())163		} else {164			None165		}166	}167	fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {168		if let Some(collection_id) = map_eth_to_id(&handle.code_address()) {169			let collection =170				<CollectionHandle<T>>::new_with_gas_limit(collection_id, handle.remaining_gas())?;171			let dispatched = Self::dispatch(collection);172173			match dispatched {174				Self::Fungible(h) => h.call(handle),175				Self::Nonfungible(h) => h.call(handle),176				Self::Refungible(h) => h.call(handle),177			}178		} else if let Some((collection_id, token_id)) =179			<T as pallet_common::Config>::EvmTokenAddressMapping::address_to_token(180				&handle.code_address(),181			) {182			let collection =183				<CollectionHandle<T>>::new_with_gas_limit(collection_id, handle.remaining_gas())?;184			if collection.mode != CollectionMode::ReFungible {185				return None;186			}187188			let h = RefungibleHandle::cast(collection);189			// TODO: check token existence190			RefungibleTokenHandle(h, token_id).call(handle)191		} else {192			None193		}194	}195}
after · runtime/common/dispatch.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{dispatch::DispatchResult, ensure};18use pallet_evm::{PrecompileHandle, PrecompileResult};19use sp_core::H160;20use sp_runtime::DispatchError;21use sp_std::{borrow::ToOwned, vec::Vec};22use pallet_common::{23	CollectionById, CollectionHandle, CommonCollectionOperations, erc::CommonEvmHandler,24	eth::map_eth_to_id,25};26pub use pallet_common::dispatch::CollectionDispatch;27use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};28use pallet_balances_adapter::{Pallet as PalletNativeFungible, NativeFungibleHandle};29use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};30use pallet_refungible::{31	Pallet as PalletRefungible, RefungibleHandle, erc_token::RefungibleTokenHandle,32};33use up_data_structs::{34	CollectionMode, CreateCollectionData, MAX_DECIMAL_POINTS, mapping::TokenAddressMapping,35	CollectionId, CollectionFlags,36};3738#[cfg(not(feature = "refungible"))]39use pallet_common::unsupported;4041pub enum CollectionDispatchT<T>42where43	T: pallet_fungible::Config44		+ pallet_nonfungible::Config45		+ pallet_refungible::Config46		+ pallet_balances_adapter::Config,47{48	Fungible(FungibleHandle<T>),49	Nonfungible(NonfungibleHandle<T>),50	Refungible(RefungibleHandle<T>),51	NativeFungible(NativeFungibleHandle<T>),52}53impl<T> CollectionDispatch<T> for CollectionDispatchT<T>54where55	T: pallet_common::Config56		+ pallet_unique::Config57		+ pallet_fungible::Config58		+ pallet_nonfungible::Config59		+ pallet_refungible::Config60		+ pallet_balances_adapter::Config,61{62	fn create(63		sender: T::CrossAccountId,64		payer: T::CrossAccountId,65		data: CreateCollectionData<T::AccountId>,66		flags: CollectionFlags,67	) -> Result<CollectionId, DispatchError> {68		let id = match data.mode {69			CollectionMode::NFT => {70				<PalletNonfungible<T>>::init_collection(sender, payer, data, flags)?71			}72			CollectionMode::Fungible(decimal_points) => {73				// check params74				ensure!(75					decimal_points <= MAX_DECIMAL_POINTS,76					pallet_unique::Error::<T>::CollectionDecimalPointLimitExceeded77				);78				<PalletFungible<T>>::init_collection(sender, payer, data, flags)?79			}8081			#[cfg(feature = "refungible")]82			CollectionMode::ReFungible => {83				<PalletRefungible<T>>::init_collection(sender, payer, data, flags)?84			}8586			#[cfg(not(feature = "refungible"))]87			CollectionMode::ReFungible => return unsupported!(T),88		};89		Ok(id)90	}9192	fn destroy(sender: T::CrossAccountId, collection: CollectionHandle<T>) -> DispatchResult {93		match collection.mode {94			CollectionMode::ReFungible => {95				PalletRefungible::destroy_collection(RefungibleHandle::cast(collection), &sender)?96			}97			CollectionMode::Fungible(_) => {98				PalletFungible::destroy_collection(FungibleHandle::cast(collection), &sender)?99			}100			CollectionMode::NFT => {101				PalletNonfungible::destroy_collection(NonfungibleHandle::cast(collection), &sender)?102			}103		}104		Ok(())105	}106107	fn dispatch(handle: CollectionHandle<T>) -> Self {108		match handle.mode {109			CollectionMode::Fungible(_) => {110				if handle.id != up_data_structs::CollectionId(0) {111					Self::Fungible(FungibleHandle::cast(handle))112				} else {113					Self::NativeFungible(NativeFungibleHandle::cast(handle))114				}115			}116			CollectionMode::NFT => Self::Nonfungible(NonfungibleHandle::cast(handle)),117			CollectionMode::ReFungible => Self::Refungible(RefungibleHandle::cast(handle)),118		}119	}120121	fn into_inner(self) -> CollectionHandle<T> {122		match self {123			Self::Fungible(f) => f.into_inner(),124			Self::Nonfungible(f) => f.into_inner(),125			Self::Refungible(f) => f.into_inner(),126			Self::NativeFungible(f) => f.into_inner(),127		}128	}129130	fn as_dyn(&self) -> &dyn CommonCollectionOperations<T> {131		match self {132			Self::Fungible(h) => h,133			Self::Nonfungible(h) => h,134			Self::Refungible(h) => h,135			Self::NativeFungible(h) => h,136		}137	}138}139140impl<T> pallet_evm::OnMethodCall<T> for CollectionDispatchT<T>141where142	T: pallet_common::Config143		+ pallet_unique::Config144		+ pallet_fungible::Config145		+ pallet_nonfungible::Config146		+ pallet_refungible::Config147		+ pallet_balances_adapter::Config,148	T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,149{150	fn is_reserved(target: &H160) -> bool {151		map_eth_to_id(target).is_some()152	}153	fn is_used(target: &H160) -> bool {154		map_eth_to_id(target)155			.map(<CollectionById<T>>::contains_key)156			.unwrap_or(false)157	}158	fn get_code(target: &H160) -> Option<Vec<u8>> {159		if let Some(collection_id) = map_eth_to_id(target) {160			let collection = <CollectionById<T>>::get(collection_id)?;161			Some(162				match collection.mode {163					CollectionMode::NFT => <NonfungibleHandle<T>>::CODE,164					CollectionMode::Fungible(_) => <FungibleHandle<T>>::CODE,165					CollectionMode::ReFungible => <RefungibleHandle<T>>::CODE,166				}167				.to_owned(),168			)169		} else if let Some((collection_id, _token_id)) =170			<T as pallet_common::Config>::EvmTokenAddressMapping::address_to_token(target)171		{172			let collection = <CollectionById<T>>::get(collection_id)?;173			if collection.mode != CollectionMode::ReFungible {174				return None;175			}176			// TODO: check token existence177			Some(<RefungibleTokenHandle<T>>::CODE.to_owned())178		} else {179			None180		}181	}182	fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {183		if let Some(collection_id) = map_eth_to_id(&handle.code_address()) {184			let collection =185				<CollectionHandle<T>>::new_with_gas_limit(collection_id, handle.remaining_gas())?;186			let dispatched = Self::dispatch(collection);187188			match dispatched {189				Self::Fungible(h) => h.call(handle),190				Self::Nonfungible(h) => h.call(handle),191				Self::Refungible(h) => h.call(handle),192				Self::NativeFungible(f) => todo!(),193			}194		} else if let Some((collection_id, token_id)) =195			<T as pallet_common::Config>::EvmTokenAddressMapping::address_to_token(196				&handle.code_address(),197			) {198			let collection =199				<CollectionHandle<T>>::new_with_gas_limit(collection_id, handle.remaining_gas())?;200			if collection.mode != CollectionMode::ReFungible {201				return None;202			}203204			let h = RefungibleHandle::cast(collection);205			// TODO: check token existence206			RefungibleTokenHandle(h, token_id).call(handle)207		} else {208			None209		}210	}211}
addedtests/src/eth/nativeFungible.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/eth/nativeFungible.test.ts
@@ -0,0 +1,44 @@
+// Copyright 2019-2023 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itEth, usingEthPlaygrounds} from './util';
+
+describe('NativeFungible: Plain calls', () => {
+  let donor: IKeyringPair;
+  let alice: IKeyringPair;
+  let owner: IKeyringPair;
+
+  before(async function() {
+    await usingEthPlaygrounds(async (helper, privateKey) => {
+      donor = await privateKey({url: import.meta.url});
+      [alice, owner] = await helper.arrange.createAccounts([30n, 20n], donor);
+    });
+  });
+
+  itEth.only('Can perform approve()', async ({helper}) => {
+    const owner = await helper.eth.createAccountWithBalance(donor);
+    const spender = helper.eth.createAccount();
+    const collection = await helper.ft.mintCollection(alice);
+    await collection.mint(alice, 200n, {Ethereum: owner});
+
+    const collectionAddress = helper.ethAddress.fromCollectionId(0);
+    const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
+
+
+    await contract.methods.approve(spender, 100).send({from: owner});
+  });
+});
\ No newline at end of file
modifiedtests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -141,11 +141,16 @@
   }
 
   async collection(address: string, mode: TCollectionMode, caller?: string, mergeDeprecated = false) {
-    let abi = {
-      'nft': nonFungibleAbi,
-      'rft': refungibleAbi,
-      'ft': fungibleAbi,
-    }[mode];
+    let abi;
+    if (address === '0' && mode === 'ft') {
+      abi = nativeFungibleAbi;
+    } else {
+      abi ={
+        'nft': nonFungibleAbi,
+        'rft': refungibleAbi,
+        'ft': fungibleAbi,
+      }[mode];
+    }
     if (mergeDeprecated) {
       const deprecated = {
         'nft': nonFungibleDeprecatedAbi,