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

difftreelog

refactor split fungible into its own pallet

Yaroslav Bolyukin2021-10-12parent: #ae3e881.patch.diff
in: master

8 files changed

addedpallets/fungible/Cargo.tomldiffbeforeafterboth
--- /dev/null
+++ b/pallets/fungible/Cargo.toml
@@ -0,0 +1,36 @@
+[package]
+name = "pallet-fungible"
+version = "0.1.0"
+edition = "2018"
+
+[dependencies.codec]
+default-features = false
+features = ['derive']
+package = 'parity-scale-codec'
+version = '2.0.0'
+
+[dependencies]
+frame-support = { default-features = false, version = '4.0.0-dev', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.10' }
+frame-system = { default-features = false, version = '4.0.0-dev', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.10' }
+sp-runtime = { default-features = false, version = '4.0.0-dev', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.10' }
+sp-std = { default-features = false, version = '4.0.0-dev', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.10' }
+sp-core = { default-features = false, version = '4.0.0-dev', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.10' }
+pallet-common = { default-features = false, path = '../common' }
+nft-data-structs = { default-features = false, path = '../../primitives/nft' }
+evm-coder = { default-features = false, path = '../../crates/evm-coder' }
+ethereum = { default-features = false, version = "0.9.0" }
+pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }
+
+[features]
+default = ["std"]
+std = [
+    "frame-support/std",
+    "frame-system/std",
+    "sp-runtime/std",
+    "sp-std/std",
+    "nft-data-structs/std",
+    "pallet-common/std",
+    "evm-coder/std",
+    "ethereum/std",
+]
+runtime-benchmarks = []
addedpallets/fungible/src/benchmarking.rsdiffbeforeafterboth
--- /dev/null
+++ b/pallets/fungible/src/benchmarking.rs
@@ -0,0 +1 @@
+#![cfg(feature = "runtime-benchmarking")]
addedpallets/fungible/src/common.rsdiffbeforeafterboth
--- /dev/null
+++ b/pallets/fungible/src/common.rs
@@ -0,0 +1,220 @@
+use core::marker::PhantomData;
+
+use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight};
+use nft_data_structs::TokenId;
+use pallet_common::{
+	CommonCollectionOperations, CommonWeightInfo, account::CrossAccountId, with_weight,
+};
+use sp_runtime::ArithmeticError;
+use sp_std::{vec::Vec, vec};
+
+use crate::{
+	Allowance, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf, weights::WeightInfo,
+};
+
+pub struct CommonWeights<T: Config>(PhantomData<T>);
+impl<T: Config> CommonWeightInfo for CommonWeights<T> {
+	fn create_item() -> Weight {
+		<SelfWeightOf<T>>::create_item()
+	}
+
+	fn create_multiple_items(_amount: u32) -> Weight {
+		Self::create_item()
+	}
+
+	fn burn_item() -> Weight {
+		<SelfWeightOf<T>>::burn_item()
+	}
+
+	fn transfer() -> Weight {
+		<SelfWeightOf<T>>::transfer()
+	}
+
+	fn approve() -> Weight {
+		<SelfWeightOf<T>>::approve()
+	}
+
+	fn transfer_from() -> Weight {
+		<SelfWeightOf<T>>::transfer_from()
+	}
+
+	fn set_variable_metadata(_bytes: u32) -> Weight {
+		// Error
+		0
+	}
+}
+
+impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {
+	fn create_item(
+		&self,
+		sender: T::CrossAccountId,
+		to: T::CrossAccountId,
+		data: nft_data_structs::CreateItemData,
+	) -> DispatchResultWithPostInfo {
+		match data {
+			nft_data_structs::CreateItemData::Fungible(data) => with_weight(
+				<Pallet<T>>::create_item(self, &sender, (to, data.value)),
+				<SelfWeightOf<T>>::create_item(),
+			),
+			_ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),
+		}
+	}
+
+	fn create_multiple_items(
+		&self,
+		sender: T::CrossAccountId,
+		to: T::CrossAccountId,
+		data: Vec<nft_data_structs::CreateItemData>,
+	) -> DispatchResultWithPostInfo {
+		let mut sum: u128 = 0;
+		for data in data {
+			match data {
+				nft_data_structs::CreateItemData::Fungible(data) => {
+					sum = sum
+						.checked_add(data.value)
+						.ok_or(ArithmeticError::Overflow)?;
+				}
+				_ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),
+			}
+		}
+
+		with_weight(
+			<Pallet<T>>::create_item(self, &sender, (to, sum)),
+			<SelfWeightOf<T>>::create_item(),
+		)
+	}
+
+	fn burn_item(
+		&self,
+		sender: T::CrossAccountId,
+		token: TokenId,
+		amount: u128,
+	) -> DispatchResultWithPostInfo {
+		ensure!(
+			token == TokenId::default(),
+			<Error<T>>::FungibleItemsHaveNoId
+		);
+
+		with_weight(
+			<Pallet<T>>::burn(self, &sender, amount),
+			<SelfWeightOf<T>>::burn_item(),
+		)
+	}
+
+	fn transfer(
+		&self,
+		from: T::CrossAccountId,
+		to: T::CrossAccountId,
+		token: TokenId,
+		amount: u128,
+	) -> DispatchResultWithPostInfo {
+		ensure!(
+			token == TokenId::default(),
+			<Error<T>>::FungibleItemsHaveNoId
+		);
+
+		with_weight(
+			<Pallet<T>>::transfer(&self, &from, &to, amount),
+			<SelfWeightOf<T>>::transfer(),
+		)
+	}
+
+	fn approve(
+		&self,
+		sender: T::CrossAccountId,
+		spender: T::CrossAccountId,
+		token: TokenId,
+		amount: u128,
+	) -> DispatchResultWithPostInfo {
+		ensure!(
+			token == TokenId::default(),
+			<Error<T>>::FungibleItemsHaveNoId
+		);
+
+		with_weight(
+			<Pallet<T>>::set_allowance(&self, &sender, &spender, amount),
+			<SelfWeightOf<T>>::approve(),
+		)
+	}
+
+	fn transfer_from(
+		&self,
+		sender: T::CrossAccountId,
+		from: T::CrossAccountId,
+		to: T::CrossAccountId,
+		token: TokenId,
+		amount: u128,
+	) -> DispatchResultWithPostInfo {
+		ensure!(
+			token == TokenId::default(),
+			<Error<T>>::FungibleItemsHaveNoId
+		);
+
+		with_weight(
+			<Pallet<T>>::transfer_from(&self, &sender, &from, &to, amount),
+			<SelfWeightOf<T>>::transfer_from(),
+		)
+	}
+
+	fn set_variable_metadata(
+		&self,
+		_sender: T::CrossAccountId,
+		_token: TokenId,
+		_data: Vec<u8>,
+	) -> DispatchResultWithPostInfo {
+		fail!(<Error<T>>::FungibleItemsHaveData)
+	}
+
+	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {
+		if <Balance<T>>::get((self.id, account.as_sub())) != 0 {
+			vec![TokenId::default()]
+		} else {
+			vec![]
+		}
+	}
+
+	fn token_exists(&self, token: TokenId) -> bool {
+		token == TokenId::default()
+	}
+
+	fn token_owner(&self, _token: TokenId) -> T::CrossAccountId {
+		T::CrossAccountId::default()
+	}
+	fn const_metadata(&self, _token: TokenId) -> Vec<u8> {
+		Vec::new()
+	}
+	fn variable_metadata(&self, _token: TokenId) -> Vec<u8> {
+		Vec::new()
+	}
+
+	fn collection_tokens(&self) -> u32 {
+		1
+	}
+
+	fn account_balance(&self, account: T::CrossAccountId) -> u32 {
+		if <Balance<T>>::get((self.id, account.as_sub())) != 0 {
+			1
+		} else {
+			0
+		}
+	}
+
+	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {
+		if token != TokenId::default() {
+			return 0;
+		}
+		<Balance<T>>::get((self.id, account.as_sub()))
+	}
+
+	fn allowance(
+		&self,
+		sender: T::CrossAccountId,
+		spender: T::CrossAccountId,
+		token: TokenId,
+	) -> u128 {
+		if token != TokenId::default() {
+			return 0;
+		}
+		<Allowance<T>>::get((self.id, sender.as_sub(), spender.as_sub()))
+	}
+}
addedpallets/fungible/src/erc.rsdiffbeforeafterboth
--- /dev/null
+++ b/pallets/fungible/src/erc.rs
@@ -0,0 +1,112 @@
+use core::char::{REPLACEMENT_CHARACTER, decode_utf16};
+use core::convert::TryInto;
+use evm_coder::{ToLog, execution::*, generate_stubgen, solidity_interface, types::*};
+use nft_data_structs::CollectionMode;
+use pallet_common::erc::CommonEvmHandler;
+use sp_core::{H160, U256};
+use sp_std::vec::Vec;
+use pallet_common::account::CrossAccountId;
+use pallet_common::erc::PrecompileOutput;
+use pallet_evm_coder_substrate::{call_internal, dispatch_to_evm};
+
+use crate::{Allowance, Balance, Config, FungibleHandle, Pallet, TotalSupply};
+
+#[derive(ToLog)]
+pub enum ERC20Events {
+	Transfer {
+		#[indexed]
+		from: address,
+		#[indexed]
+		to: address,
+		value: uint256,
+	},
+	Approval {
+		#[indexed]
+		owner: address,
+		#[indexed]
+		spender: address,
+		value: uint256,
+	},
+}
+
+#[solidity_interface(name = "ERC20", events(ERC20Events))]
+impl<T: Config> FungibleHandle<T> {
+	fn name(&self) -> Result<string> {
+		Ok(decode_utf16(self.name.iter().copied())
+			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
+			.collect::<string>())
+	}
+	fn symbol(&self) -> Result<string> {
+		Ok(string::from_utf8_lossy(&self.token_prefix).into())
+	}
+	fn total_supply(&self) -> Result<uint256> {
+		Ok(<TotalSupply<T>>::get(self.id).into())
+	}
+
+	fn decimals(&self) -> Result<uint8> {
+		Ok(if let CollectionMode::Fungible(decimals) = &self.mode {
+			*decimals
+		} else {
+			unreachable!()
+		})
+	}
+	fn balance_of(&self, owner: address) -> Result<uint256> {
+		let owner = T::CrossAccountId::from_eth(owner);
+		let balance = <Balance<T>>::get((self.id, owner.as_sub()));
+		Ok(balance.into())
+	}
+	fn transfer(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {
+		let caller = T::CrossAccountId::from_eth(caller);
+		let to = T::CrossAccountId::from_eth(to);
+		let amount = amount.try_into().map_err(|_| "amount overflow")?;
+
+		<Pallet<T>>::transfer(self, &caller, &to, amount).map_err(|_| "transfer error")?;
+		Ok(true)
+	}
+	fn transfer_from(
+		&mut self,
+		caller: caller,
+		from: address,
+		to: address,
+		amount: uint256,
+	) -> Result<bool> {
+		let caller = T::CrossAccountId::from_eth(caller);
+		let from = T::CrossAccountId::from_eth(from);
+		let to = T::CrossAccountId::from_eth(to);
+		let amount = amount.try_into().map_err(|_| "amount overflow")?;
+
+		<Pallet<T>>::transfer_from(self, &caller, &from, &to, amount)
+			.map_err(dispatch_to_evm::<T>)?;
+		Ok(true)
+	}
+	fn approve(&mut self, caller: caller, spender: address, amount: uint256) -> Result<bool> {
+		let caller = T::CrossAccountId::from_eth(caller);
+		let spender = T::CrossAccountId::from_eth(spender);
+		let amount = amount.try_into().map_err(|_| "amount overflow")?;
+
+		<Pallet<T>>::set_allowance(self, &caller, &spender, amount)
+			.map_err(dispatch_to_evm::<T>)?;
+		Ok(true)
+	}
+	fn allowance(&self, owner: address, spender: address) -> Result<uint256> {
+		let owner = T::CrossAccountId::from_eth(owner);
+		let spender = T::CrossAccountId::from_eth(spender);
+
+		Ok(<Allowance<T>>::get((self.id, owner.as_sub(), spender.as_sub())).into())
+	}
+}
+
+#[solidity_interface(name = "UniqueFungible", is(ERC20))]
+impl<T: Config> FungibleHandle<T> {}
+
+generate_stubgen!(get_impl, UniqueFungibleCall, true);
+generate_stubgen!(gen_iface, UniqueFungibleCall, false);
+
+impl<T: Config> CommonEvmHandler for FungibleHandle<T> {
+	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueFungible.raw");
+
+	fn call(mut self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput> {
+		let result = call_internal::<UniqueFungibleCall, _>(*source, &mut self, value, input);
+		self.0.recorder.evm_to_precompile_output(result)
+	}
+}
addedpallets/fungible/src/lib.rsdiffbeforeafterboth
after · pallets/fungible/src/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]23use core::ops::Deref;4use frame_support::{ensure};5use nft_data_structs::{AccessMode, Collection, CollectionId, TokenId};6use pallet_common::{7	Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, account::CrossAccountId,8};9use sp_core::H160;10use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};11use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};1213pub use pallet::*;1415use crate::erc::ERC20Events;16pub mod benchmarking;17pub mod common;18pub mod erc;19pub mod weights;2021pub type CreateItemData<T> = (<T as pallet_common::Config>::CrossAccountId, u128);22pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;2324#[frame_support::pallet]25pub mod pallet {26	use frame_support::{Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key};27	use nft_data_structs::CollectionId;28	use super::weights::WeightInfo;2930	#[pallet::error]31	pub enum Error<T> {32		/// Not Fungible item data used to mint in Fungible collection.33		NotFungibleDataUsedToMintFungibleCollectionToken,34		/// Not default id passed as TokenId argument35		FungibleItemsHaveNoId,36		/// Tried to set data for fungible item37		FungibleItemsHaveData,38	}3940	#[pallet::config]41	pub trait Config: frame_system::Config + pallet_common::Config {42		type WeightInfo: WeightInfo;43	}4445	#[pallet::pallet]46	#[pallet::generate_store(pub(super) trait Store)]47	pub struct Pallet<T>(_);4849	#[pallet::storage]50	pub(super) type TotalSupply<T: Config> =51		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;5253	#[pallet::storage]54	pub(super) type Balance<T: Config> = StorageNMap<55		Key = (56			Key<Twox64Concat, CollectionId>,57			Key<Blake2_128Concat, T::AccountId>,58		),59		Value = u128,60		QueryKind = ValueQuery,61	>;6263	#[pallet::storage]64	pub(super) type Allowance<T: Config> = StorageNMap<65		Key = (66			Key<Twox64Concat, CollectionId>,67			Key<Blake2_128, T::AccountId>,68			Key<Blake2_128Concat, T::AccountId>,69		),70		Value = u128,71		QueryKind = ValueQuery,72	>;73}7475pub struct FungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);76impl<T: Config> FungibleHandle<T> {77	pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {78		Self(inner)79	}80	pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {81		self.082	}83}84impl<T: Config> Deref for FungibleHandle<T> {85	type Target = pallet_common::CollectionHandle<T>;8687	fn deref(&self) -> &Self::Target {88		&self.089	}90}9192impl<T: Config> Pallet<T> {93	pub fn init_collection(data: Collection<T>) -> Result<CollectionId, DispatchError> {94		PalletCommon::init_collection(data)95	}96	pub fn destroy_collection(97		collection: FungibleHandle<T>,98		sender: &T::CrossAccountId,99	) -> DispatchResult {100		let id = collection.id;101102		// =========103104		PalletCommon::destroy_collection(collection.0, sender)?;105106		<TotalSupply<T>>::remove(id);107		<Balance<T>>::remove_prefix((id,), None);108		<Allowance<T>>::remove_prefix((id,), None);109		Ok(())110	}111112	pub fn burn(113		collection: &FungibleHandle<T>,114		owner: &T::CrossAccountId,115		amount: u128,116	) -> DispatchResult {117		let total_supply = <TotalSupply<T>>::get(collection.id)118			.checked_sub(amount)119			.ok_or(<CommonError<T>>::TokenValueTooLow)?;120121		let balance = <Balance<T>>::get((collection.id, owner.as_sub()))122			.checked_sub(amount)123			.ok_or(<CommonError<T>>::TokenValueTooLow)?;124125		if collection.access == AccessMode::WhiteList {126			collection.check_whitelist(owner)?;127		}128129		// =========130131		if balance == 0 {132			<Balance<T>>::remove((collection.id, owner.as_sub()));133		} else {134			<Balance<T>>::insert((collection.id, owner.as_sub()), balance);135		}136		<TotalSupply<T>>::insert(collection.id, total_supply);137138		collection.log_infallible(ERC20Events::Transfer {139			from: *owner.as_eth(),140			to: H160::default(),141			value: amount.into(),142		});143		<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(144			collection.id,145			TokenId::default(),146			owner.clone(),147			amount,148		));149		Ok(())150	}151152	pub fn transfer(153		collection: &FungibleHandle<T>,154		from: &T::CrossAccountId,155		to: &T::CrossAccountId,156		amount: u128,157	) -> DispatchResult {158		ensure!(159			collection.transfers_enabled,160			<CommonError<T>>::TransferNotAllowed161		);162163		if collection.access == AccessMode::WhiteList {164			collection.check_whitelist(from)?;165			collection.check_whitelist(to)?;166		}167		<PalletCommon<T>>::ensure_correct_receiver(to)?;168169		let balance_from = <Balance<T>>::get((collection.id, from.as_sub()))170			.checked_sub(amount)171			.ok_or(<CommonError<T>>::TokenValueTooLow)?;172		let balance_to = if from != to {173			Some(174				<Balance<T>>::get((collection.id, to.as_sub()))175					.checked_add(amount)176					.ok_or(ArithmeticError::Overflow)?,177			)178		} else {179			None180		};181182		collection.consume_sstore()?;183		collection.consume_sstore()?;184		collection.consume_log(2, 32)?;185		collection.consume_sstore()?;186187		// =========188189		if let Some(balance_to) = balance_to {190			// from != to191			if balance_from == 0 {192				<Balance<T>>::remove((collection.id, from.as_sub()));193			} else {194				<Balance<T>>::insert((collection.id, from.as_sub()), balance_from);195			}196			<Balance<T>>::insert((collection.id, to.as_sub()), balance_to);197		}198199		collection.log_infallible(ERC20Events::Transfer {200			from: *from.as_eth(),201			to: *to.as_eth(),202			value: amount.into(),203		});204		<PalletCommon<T>>::deposit_event(CommonEvent::Transfer(205			collection.id,206			TokenId::default(),207			from.clone(),208			to.clone(),209			amount,210		));211		Ok(())212	}213214	pub fn create_multiple_items(215		collection: &FungibleHandle<T>,216		sender: &T::CrossAccountId,217		data: Vec<CreateItemData<T>>,218	) -> DispatchResult {219		let unrestricted_minting = collection.is_owner_or_admin(sender)?;220		if !unrestricted_minting {221			ensure!(222				collection.mint_mode,223				<CommonError<T>>::PublicMintingNotAllowed224			);225			collection.check_whitelist(sender)?;226227			for (owner, _) in data.iter() {228				collection.check_whitelist(owner)?;229			}230		}231232		let mut balances = BTreeMap::new();233234		let total_supply = data235			.iter()236			.map(|u| u.1)237			.try_fold(0u128, |acc, v| acc.checked_add(v))238			.ok_or(ArithmeticError::Overflow)?;239240		for (user, amount) in data.into_iter() {241			collection.consume_sload()?;242			let balance = balances243				.entry(user.clone())244				.or_insert_with(|| <Balance<T>>::get((collection.id, user.as_sub())));245			*balance = (*balance)246				.checked_add(amount)247				.ok_or(ArithmeticError::Overflow)?;248		}249250		collection.consume_sstore()?;251		for _ in &balances {252			collection.consume_sstore()?;253			collection.consume_log(2, 32)?;254			collection.consume_sstore()?;255		}256257		// =========258259		<TotalSupply<T>>::insert(collection.id, total_supply);260		for (user, amount) in balances {261			<Balance<T>>::insert((collection.id, user.as_sub()), amount);262263			collection.log_infallible(ERC20Events::Transfer {264				from: H160::default(),265				to: *user.as_eth(),266				value: amount.into(),267			});268			<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(269				collection.id,270				TokenId::default(),271				user.clone(),272				amount,273			));274		}275276		Ok(())277	}278279	fn set_allowance_unchecked(280		collection: &FungibleHandle<T>,281		owner: &T::CrossAccountId,282		spender: &T::CrossAccountId,283		amount: u128,284	) {285		<Allowance<T>>::insert((collection.id, owner.as_sub(), spender.as_sub()), amount);286287		collection.log_infallible(ERC20Events::Approval {288			owner: *owner.as_eth(),289			spender: *spender.as_eth(),290			value: amount.into(),291		});292		<PalletCommon<T>>::deposit_event(CommonEvent::Approved(293			collection.id,294			TokenId(0),295			owner.clone(),296			spender.clone(),297			amount,298		));299	}300301	pub fn set_allowance(302		collection: &FungibleHandle<T>,303		owner: &T::CrossAccountId,304		spender: &T::CrossAccountId,305		amount: u128,306	) -> DispatchResult {307		if collection.access == AccessMode::WhiteList {308			collection.check_whitelist(&owner)?;309			collection.check_whitelist(&spender)?;310		}311312		if <Balance<T>>::get((collection.id, owner.as_sub())) < amount {313			ensure!(314				collection.ignores_owned_amount(owner)?,315				<CommonError<T>>::CantApproveMoreThanOwned316			);317		}318319		// =========320321		Self::set_allowance_unchecked(collection, owner, spender, amount);322		Ok(())323	}324325	pub fn transfer_from(326		collection: &FungibleHandle<T>,327		spender: &T::CrossAccountId,328		from: &T::CrossAccountId,329		to: &T::CrossAccountId,330		amount: u128,331	) -> DispatchResult {332		if spender == from {333			return Self::transfer(collection, from, to, amount);334		}335		if collection.access == AccessMode::WhiteList {336			// `from`, `to` checked in [`transfer`]337			collection.check_whitelist(spender)?;338		}339340		let allowance = <Allowance<T>>::get((collection.id, from.as_sub(), spender.as_sub()))341			.checked_sub(amount);342		if allowance.is_none() {343			ensure!(344				collection.ignores_allowance(spender)?,345				<CommonError<T>>::TokenValueNotEnough346			);347		}348349		// =========350351		Self::transfer(collection, from, to, amount)?;352		if let Some(allowance) = allowance {353			Self::set_allowance_unchecked(collection, from, spender, allowance);354		}355		Ok(())356	}357358	/// Delegated to `create_multiple_items`359	pub fn create_item(360		collection: &FungibleHandle<T>,361		sender: &T::CrossAccountId,362		data: CreateItemData<T>,363	) -> DispatchResult {364		Self::create_multiple_items(collection, sender, vec![data])365	}366}
addedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

addedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
--- /dev/null
+++ b/pallets/fungible/src/stubs/UniqueFungible.sol
@@ -0,0 +1,121 @@
+// SPDX-License-Identifier: OTHER
+// This code is automatically generated
+
+pragma solidity >=0.8.0 <0.9.0;
+
+// Common stubs holder
+contract Dummy {
+	uint8 dummy;
+	string stub_error = "this contract is implemented in native";
+}
+
+// Inline
+contract ERC20Events {
+	event Transfer(address indexed from, address indexed to, uint256 value);
+	event Approval(
+		address indexed owner,
+		address indexed spender,
+		uint256 value
+	);
+}
+
+// Inline
+contract InlineNameSymbol is Dummy {
+	// Selector: name() 06fdde03
+	function name() public view returns (string memory) {
+		require(false, stub_error);
+		dummy;
+		return "";
+	}
+
+	// Selector: symbol() 95d89b41
+	function symbol() public view returns (string memory) {
+		require(false, stub_error);
+		dummy;
+		return "";
+	}
+}
+
+// Inline
+contract InlineTotalSupply is Dummy {
+	// Selector: totalSupply() 18160ddd
+	function totalSupply() public view returns (uint256) {
+		require(false, stub_error);
+		dummy;
+		return 0;
+	}
+}
+
+contract ERC165 is Dummy {
+	// Selector: supportsInterface(bytes4) 01ffc9a7
+	function supportsInterface(uint32 interfaceId) public view returns (bool) {
+		require(false, stub_error);
+		interfaceId;
+		dummy;
+		return false;
+	}
+}
+
+contract ERC20 is Dummy, InlineNameSymbol, InlineTotalSupply, ERC20Events {
+	// Selector: decimals() 313ce567
+	function decimals() public view returns (uint8) {
+		require(false, stub_error);
+		dummy;
+		return 0;
+	}
+
+	// Selector: balanceOf(address) 70a08231
+	function balanceOf(address owner) public view returns (uint256) {
+		require(false, stub_error);
+		owner;
+		dummy;
+		return 0;
+	}
+
+	// Selector: transfer(address,uint256) a9059cbb
+	function transfer(address to, uint256 amount) public returns (bool) {
+		require(false, stub_error);
+		to;
+		amount;
+		dummy = 0;
+		return false;
+	}
+
+	// Selector: transferFrom(address,address,uint256) 23b872dd
+	function transferFrom(
+		address from,
+		address to,
+		uint256 amount
+	) public returns (bool) {
+		require(false, stub_error);
+		from;
+		to;
+		amount;
+		dummy = 0;
+		return false;
+	}
+
+	// Selector: approve(address,uint256) 095ea7b3
+	function approve(address spender, uint256 amount) public returns (bool) {
+		require(false, stub_error);
+		spender;
+		amount;
+		dummy = 0;
+		return false;
+	}
+
+	// Selector: allowance(address,address) dd62ed3e
+	function allowance(address owner, address spender)
+		public
+		view
+		returns (uint256)
+	{
+		require(false, stub_error);
+		owner;
+		spender;
+		dummy;
+		return 0;
+	}
+}
+
+contract UniqueFungible is Dummy, ERC165, ERC20 {}
addedpallets/fungible/src/weights.rsdiffbeforeafterboth
--- /dev/null
+++ b/pallets/fungible/src/weights.rs
@@ -0,0 +1,31 @@
+#![cfg_attr(rustfmt, rustfmt_skip)]
+#![allow(unused_parens)]
+#![allow(unused_imports)]
+
+use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
+use sp_std::marker::PhantomData;
+
+pub trait WeightInfo {
+	fn create_item() -> Weight;
+	fn burn_item() -> Weight;
+	fn transfer() -> Weight;
+	fn approve() -> Weight;
+	fn transfer_from() -> Weight;
+}
+
+pub struct SubstrateWeight<T>(PhantomData<T>);
+impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
+    fn create_item() -> Weight {0}
+	fn burn_item() -> Weight {0}
+	fn transfer() -> Weight {0}
+	fn approve() -> Weight {0}
+	fn transfer_from() -> Weight {0}
+}
+
+impl WeightInfo for () {
+    fn create_item() -> Weight {0}
+	fn burn_item() -> Weight {0}
+	fn transfer() -> Weight {0}
+	fn approve() -> Weight {0}
+	fn transfer_from() -> Weight {0}
+}