git.delta.rocks / unique-network / refs/commits / 44992fca8f8c

difftreelog

feat burn_from

Yaroslav Bolyukin2021-11-02parent: #283713e.patch.diff
in: master

12 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -459,6 +459,7 @@
 	fn transfer() -> Weight;
 	fn approve() -> Weight;
 	fn transfer_from() -> Weight;
+	fn burn_from() -> Weight;
 	fn set_variable_metadata(bytes: u32) -> Weight;
 }
 
@@ -504,6 +505,13 @@
 		token: TokenId,
 		amount: u128,
 	) -> DispatchResultWithPostInfo;
+	fn burn_from(
+		&self,
+		sender: T::CrossAccountId,
+		from: T::CrossAccountId,
+		token: TokenId,
+		amount: u128,
+	) -> DispatchResultWithPostInfo;
 
 	fn set_variable_metadata(
 		&self,
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -38,6 +38,10 @@
 		<SelfWeightOf<T>>::transfer_from()
 	}
 
+	fn burn_from() -> Weight {
+		0
+	}
+
 	fn set_variable_metadata(_bytes: u32) -> Weight {
 		// Error
 		0
@@ -156,6 +160,24 @@
 		)
 	}
 
+	fn burn_from(
+		&self,
+		sender: T::CrossAccountId,
+		from: T::CrossAccountId,
+		token: TokenId,
+		amount: u128,
+	) -> DispatchResultWithPostInfo {
+		ensure!(
+			token == TokenId::default(),
+			<Error<T>>::FungibleItemsHaveNoId
+		);
+
+		with_weight(
+			<Pallet<T>>::burn_from(&self, &sender, &from, amount),
+			<CommonWeights<T>>::burn_from(),
+		)
+	}
+
 	fn set_variable_metadata(
 		&self,
 		_sender: T::CrossAccountId,
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -96,6 +96,18 @@
 	}
 }
 
+#[solidity_interface(name = "ERC20UniqueExtensions")]
+impl<T: Config> FungibleHandle<T> {
+	fn burn_from(&mut self, caller: caller, from: address, amount: uint256) -> Result<bool> {
+		let caller = T::CrossAccountId::from_eth(caller);
+		let from = T::CrossAccountId::from_eth(from);
+		let amount = amount.try_into().map_err(|_| "amount overflow")?;
+
+		<Pallet<T>>::burn_from(self, &caller, &from, amount).map_err(dispatch_to_evm::<T>)?;
+		Ok(true)
+	}
+}
+
 #[solidity_interface(name = "UniqueFungible", is(ERC20))]
 impl<T: Config> FungibleHandle<T> {}
 
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -356,6 +356,38 @@
 		Ok(())
 	}
 
+	pub fn burn_from(
+		collection: &FungibleHandle<T>,
+		spender: &T::CrossAccountId,
+		from: &T::CrossAccountId,
+		amount: u128,
+	) -> DispatchResult {
+		if spender == from {
+			return Self::burn(collection, from, amount);
+		}
+		if collection.access == AccessMode::WhiteList {
+			// `from` checked in [`burn`]
+			collection.check_allowlist(spender)?;
+		}
+
+		let allowance = <Allowance<T>>::get((collection.id, from.as_sub(), spender.as_sub()))
+			.checked_sub(amount);
+		if allowance.is_none() {
+			ensure!(
+				collection.ignores_allowance(spender)?,
+				<CommonError<T>>::TokenValueNotEnough
+			);
+		}
+
+		// =========
+
+		Self::burn(collection, from, amount)?;
+		if let Some(allowance) = allowance {
+			Self::set_allowance_unchecked(collection, from, spender, allowance);
+		}
+		Ok(())
+	}
+
 	/// Delegated to `create_multiple_items`
 	pub fn create_item(
 		collection: &FungibleHandle<T>,
modifiedpallets/nft/src/common.rsdiffbeforeafterboth
--- a/pallets/nft/src/common.rs
+++ b/pallets/nft/src/common.rs
@@ -45,4 +45,8 @@
 	fn set_variable_metadata(bytes: u32) -> nft_data_structs::Weight {
 		dispatch_weight::<T>() + max_weight_of!(set_variable_metadata(bytes))
 	}
+
+	fn burn_from() -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(burn_from())
+	}
 }
modifiedpallets/nft/src/eth/sponsoring.rsdiffbeforeafterboth
--- a/pallets/nft/src/eth/sponsoring.rs
+++ b/pallets/nft/src/eth/sponsoring.rs
@@ -35,9 +35,10 @@
 				.map_err(|_| AnyError)?
 				.ok_or(AnyError)?;
 			match call {
-				UniqueNFTCall::ERC721UniqueExtensions(
-					ERC721UniqueExtensionsCall::TransferNft { token_id, .. },
-				)
+				UniqueNFTCall::ERC721UniqueExtensions(ERC721UniqueExtensionsCall::Transfer {
+					token_id,
+					..
+				})
 				| UniqueNFTCall::ERC721(ERC721Call::TransferFrom { token_id, .. }) => {
 					let token_id: u32 = token_id.try_into().map_err(|_| AnyError)?;
 					let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -623,14 +623,13 @@
 		/// * item_id: ID of NFT to burn.
 		///
 		/// * from: owner of item
-		// #[weight = 0]
-		// #[transactional]
-		// pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> PostDispatchInfo {
-		// 	let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+		#[weight = <CommonWeights<T>>::burn_from()]
+		#[transactional]
+		pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {
+			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 
-		// 	// dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value))
-		// 	todo!()
-		// }
+			dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value))
+		}
 
 		/// Change ownership of the token.
 		///
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -39,6 +39,10 @@
 		<SelfWeightOf<T>>::transfer_from()
 	}
 
+	fn burn_from() -> Weight {
+		0
+	}
+
 	fn set_variable_metadata(bytes: u32) -> Weight {
 		<SelfWeightOf<T>>::set_variable_metadata(bytes)
 	}
@@ -163,6 +167,25 @@
 		}
 	}
 
+	fn burn_from(
+		&self,
+		sender: T::CrossAccountId,
+		from: T::CrossAccountId,
+		token: TokenId,
+		amount: u128,
+	) -> DispatchResultWithPostInfo {
+		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);
+
+		if amount == 1 {
+			with_weight(
+				<Pallet<T>>::burn_from(&self, &sender, &from, token),
+				<CommonWeights<T>>::burn_from(),
+			)
+		} else {
+			Ok(().into())
+		}
+	}
+
 	fn set_variable_metadata(
 		&self,
 		sender: T::CrossAccountId,
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
before · pallets/nonfungible/src/erc.rs
1use core::{2	char::{REPLACEMENT_CHARACTER, decode_utf16},3	convert::TryInto,4};5use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*};6use frame_support::BoundedVec;7use nft_data_structs::TokenId;8use pallet_evm_coder_substrate::dispatch_to_evm;9use sp_core::{H160, U256};10use sp_std::{vec::Vec, vec};11use pallet_common::{account::CrossAccountId, erc::CommonEvmHandler};12use pallet_evm_coder_substrate::call_internal;13use pallet_common::erc::PrecompileOutput;1415use crate::{16	AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,17};1819#[derive(ToLog)]20pub enum ERC721Events {21	Transfer {22		#[indexed]23		from: address,24		#[indexed]25		to: address,26		#[indexed]27		token_id: uint256,28	},29	Approval {30		#[indexed]31		owner: address,32		#[indexed]33		approved: address,34		#[indexed]35		token_id: uint256,36	},37	#[allow(dead_code)]38	ApprovalForAll {39		#[indexed]40		owner: address,41		#[indexed]42		operator: address,43		approved: bool,44	},45}4647#[derive(ToLog)]48pub enum ERC721MintableEvents {49	#[allow(dead_code)]50	MintingFinished {},51}5253#[solidity_interface(name = "ERC721Metadata")]54impl<T: Config> NonfungibleHandle<T> {55	fn name(&self) -> Result<string> {56		Ok(decode_utf16(self.name.iter().copied())57			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))58			.collect::<string>())59	}60	fn symbol(&self) -> Result<string> {61		Ok(string::from_utf8_lossy(&self.token_prefix).into())62	}6364	#[solidity(rename_selector = "tokenURI")]65	fn token_uri(&self, token_id: uint256) -> Result<string> {66		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;67		Ok(string::from_utf8_lossy(68			&<TokenData<T>>::get((self.id, token_id))69				.ok_or("token not found")?70				.const_data,71		)72		.into())73	}74}7576#[solidity_interface(name = "ERC721Enumerable")]77impl<T: Config> NonfungibleHandle<T> {78	fn token_by_index(&self, index: uint256) -> Result<uint256> {79		Ok(index)80	}8182	fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {83		// TODO: Not implemetable84		Err("not implemented".into())85	}8687	fn total_supply(&self) -> Result<uint256> {88		Ok(<Pallet<T>>::total_supply(self).into())89	}90}9192#[solidity_interface(name = "ERC721", events(ERC721Events))]93impl<T: Config> NonfungibleHandle<T> {94	fn balance_of(&self, owner: address) -> Result<uint256> {95		let owner = T::CrossAccountId::from_eth(owner);96		let balance = <AccountBalance<T>>::get((self.id, owner.as_sub()));97		Ok(balance.into())98	}99	fn owner_of(&self, token_id: uint256) -> Result<address> {100		let token: TokenId = token_id.try_into()?;101		Ok(*<TokenData<T>>::get((self.id, token))102			.ok_or("token not found")?103			.owner104			.as_eth())105	}106	fn safe_transfer_from_with_data(107		&mut self,108		_from: address,109		_to: address,110		_token_id: uint256,111		_data: bytes,112		_value: value,113	) -> Result<void> {114		// TODO: Not implemetable115		Err("not implemented".into())116	}117	fn safe_transfer_from(118		&mut self,119		_from: address,120		_to: address,121		_token_id: uint256,122		_value: value,123	) -> Result<void> {124		// TODO: Not implemetable125		Err("not implemented".into())126	}127128	fn transfer_from(129		&mut self,130		caller: caller,131		from: address,132		to: address,133		token_id: uint256,134		_value: value,135	) -> Result<void> {136		let caller = T::CrossAccountId::from_eth(caller);137		let from = T::CrossAccountId::from_eth(from);138		let to = T::CrossAccountId::from_eth(to);139		let token = token_id.try_into()?;140141		<Pallet<T>>::transfer_from(self, &caller, &from, &to, token)142			.map_err(dispatch_to_evm::<T>)?;143		Ok(())144	}145146	fn approve(147		&mut self,148		caller: caller,149		approved: address,150		token_id: uint256,151		_value: value,152	) -> Result<void> {153		let caller = T::CrossAccountId::from_eth(caller);154		let approved = T::CrossAccountId::from_eth(approved);155		let token = token_id.try_into()?;156157		<Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))158			.map_err(dispatch_to_evm::<T>)?;159		Ok(())160	}161162	fn set_approval_for_all(163		&mut self,164		_caller: caller,165		_operator: address,166		_approved: bool,167	) -> Result<void> {168		// TODO: Not implemetable169		Err("not implemented".into())170	}171172	fn get_approved(&self, _token_id: uint256) -> Result<address> {173		// TODO: Not implemetable174		Err("not implemented".into())175	}176177	fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {178		// TODO: Not implemetable179		Err("not implemented".into())180	}181}182183#[solidity_interface(name = "ERC721Burnable")]184impl<T: Config> NonfungibleHandle<T> {185	fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {186		let caller = T::CrossAccountId::from_eth(caller);187		let token = token_id.try_into()?;188189		<Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;190		Ok(())191	}192}193194#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]195impl<T: Config> NonfungibleHandle<T> {196	fn minting_finished(&self) -> Result<bool> {197		Ok(false)198	}199200	fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {201		let caller = T::CrossAccountId::from_eth(caller);202		let to = T::CrossAccountId::from_eth(to);203		let token_id: u32 = token_id.try_into()?;204		if <TokensMinted<T>>::get(self.id)205			.checked_add(1)206			.ok_or("item id overflow")?207			!= token_id208		{209			return Err("item id should be next".into());210		}211212		<Pallet<T>>::create_item(213			self,214			&caller,215			CreateItemData {216				const_data: BoundedVec::default(),217				variable_data: BoundedVec::default(),218				owner: to,219			},220		)221		.map_err(dispatch_to_evm::<T>)?;222223		Ok(true)224	}225226	#[solidity(rename_selector = "mintWithTokenURI")]227	fn mint_with_token_uri(228		&mut self,229		caller: caller,230		to: address,231		token_id: uint256,232		token_uri: string,233	) -> Result<bool> {234		let caller = T::CrossAccountId::from_eth(caller);235		let to = T::CrossAccountId::from_eth(to);236		let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;237		if <TokensMinted<T>>::get(self.id)238			.checked_add(1)239			.ok_or("item id overflow")?240			!= token_id241		{242			return Err("item id should be next".into());243		}244245		<Pallet<T>>::create_item(246			self,247			&caller,248			CreateItemData {249				const_data: Vec::<u8>::from(token_uri)250					.try_into()251					.map_err(|_| "token uri is too long")?,252				variable_data: BoundedVec::default(),253				owner: to,254			},255		)256		.map_err(dispatch_to_evm::<T>)?;257		Ok(true)258	}259260	fn finish_minting(&mut self, _caller: caller) -> Result<bool> {261		Err("not implementable".into())262	}263}264265#[solidity_interface(name = "ERC721UniqueExtensions")]266impl<T: Config> NonfungibleHandle<T> {267	#[solidity(rename_selector = "transfer")]268	fn transfer_nft(269		&mut self,270		caller: caller,271		to: address,272		token_id: uint256,273		_value: value,274	) -> Result<void> {275		let caller = T::CrossAccountId::from_eth(caller);276		let to = T::CrossAccountId::from_eth(to);277		let token = token_id.try_into()?;278279		<Pallet<T>>::transfer(self, &caller, &to, token).map_err(dispatch_to_evm::<T>)?;280		Ok(())281	}282283	fn next_token_id(&self) -> Result<uint256> {284		Ok(<TokensMinted<T>>::get(self.id)285			.checked_add(1)286			.ok_or("item id overflow")?287			.into())288	}289290	fn set_variable_metadata(291		&mut self,292		caller: caller,293		token_id: uint256,294		data: bytes,295	) -> Result<void> {296		let caller = T::CrossAccountId::from_eth(caller);297		let token = token_id.try_into()?;298299		<Pallet<T>>::set_variable_metadata(self, &caller, token, data)300			.map_err(dispatch_to_evm::<T>)?;301		Ok(())302	}303304	fn get_variable_metadata(&self, token_id: uint256) -> Result<bytes> {305		let token: TokenId = token_id.try_into()?;306307		Ok(<TokenData<T>>::get((self.id, token))308			.ok_or("token not found")?309			.variable_data)310	}311312	fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {313		let caller = T::CrossAccountId::from_eth(caller);314		let to = T::CrossAccountId::from_eth(to);315		let mut expected_index = <TokensMinted<T>>::get(self.id)316			.checked_add(1)317			.ok_or("item id overflow")?;318319		let total_tokens = token_ids.len();320		for id in token_ids.into_iter() {321			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;322			if id != expected_index {323				return Err("item id should be next".into());324			}325			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;326		}327		let data = (0..total_tokens)328			.map(|_| CreateItemData {329				const_data: BoundedVec::default(),330				variable_data: BoundedVec::default(),331				owner: to.clone(),332			})333			.collect();334335		<Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;336		Ok(true)337	}338339	#[solidity(rename_selector = "mintBulkWithTokenURI")]340	fn mint_bulk_with_token_uri(341		&mut self,342		caller: caller,343		to: address,344		tokens: Vec<(uint256, string)>,345	) -> Result<bool> {346		let caller = T::CrossAccountId::from_eth(caller);347		let to = T::CrossAccountId::from_eth(to);348		let mut expected_index = <TokensMinted<T>>::get(self.id)349			.checked_add(1)350			.ok_or("item id overflow")?;351352		let mut data = Vec::with_capacity(tokens.len());353		for (id, token_uri) in tokens {354			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;355			if id != expected_index {356				panic!("item id should be next ({}) but got {}", expected_index, id);357			}358			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;359360			data.push(CreateItemData {361				const_data: Vec::<u8>::from(token_uri)362					.try_into()363					.map_err(|_| "token uri is too long")?,364				variable_data: vec![].try_into().unwrap(),365				owner: to.clone(),366			});367		}368369		<Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;370		Ok(true)371	}372}373374#[solidity_interface(375	name = "UniqueNFT",376	is(377		ERC721,378		ERC721Metadata,379		ERC721Enumerable,380		ERC721UniqueExtensions,381		ERC721Mintable,382		ERC721Burnable,383	)384)]385impl<T: Config> NonfungibleHandle<T> {}386387// Not a tests, but code generators388generate_stubgen!(gen_impl, UniqueNFTCall, true);389generate_stubgen!(gen_iface, UniqueNFTCall, false);390391pub const CODE: &[u8] = include_bytes!("./stubs/UniqueNFT.raw");392393impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {394	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");395396	fn call(mut self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput> {397		let result = call_internal::<UniqueNFTCall, _>(*source, &mut self, value, input);398		self.0.recorder.evm_to_precompile_output(result)399	}400}
after · pallets/nonfungible/src/erc.rs
1use core::{2	char::{REPLACEMENT_CHARACTER, decode_utf16},3	convert::TryInto,4};5use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*};6use frame_support::BoundedVec;7use nft_data_structs::TokenId;8use pallet_evm_coder_substrate::dispatch_to_evm;9use sp_core::{H160, U256};10use sp_std::{vec::Vec, vec};11use pallet_common::{account::CrossAccountId, erc::CommonEvmHandler};12use pallet_evm_coder_substrate::call_internal;13use pallet_common::erc::PrecompileOutput;1415use crate::{16	AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,17};1819#[derive(ToLog)]20pub enum ERC721Events {21	Transfer {22		#[indexed]23		from: address,24		#[indexed]25		to: address,26		#[indexed]27		token_id: uint256,28	},29	Approval {30		#[indexed]31		owner: address,32		#[indexed]33		approved: address,34		#[indexed]35		token_id: uint256,36	},37	#[allow(dead_code)]38	ApprovalForAll {39		#[indexed]40		owner: address,41		#[indexed]42		operator: address,43		approved: bool,44	},45}4647#[derive(ToLog)]48pub enum ERC721MintableEvents {49	#[allow(dead_code)]50	MintingFinished {},51}5253#[solidity_interface(name = "ERC721Metadata")]54impl<T: Config> NonfungibleHandle<T> {55	fn name(&self) -> Result<string> {56		Ok(decode_utf16(self.name.iter().copied())57			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))58			.collect::<string>())59	}60	fn symbol(&self) -> Result<string> {61		Ok(string::from_utf8_lossy(&self.token_prefix).into())62	}6364	#[solidity(rename_selector = "tokenURI")]65	fn token_uri(&self, token_id: uint256) -> Result<string> {66		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;67		Ok(string::from_utf8_lossy(68			&<TokenData<T>>::get((self.id, token_id))69				.ok_or("token not found")?70				.const_data,71		)72		.into())73	}74}7576#[solidity_interface(name = "ERC721Enumerable")]77impl<T: Config> NonfungibleHandle<T> {78	fn token_by_index(&self, index: uint256) -> Result<uint256> {79		Ok(index)80	}8182	fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {83		// TODO: Not implemetable84		Err("not implemented".into())85	}8687	fn total_supply(&self) -> Result<uint256> {88		Ok(<Pallet<T>>::total_supply(self).into())89	}90}9192#[solidity_interface(name = "ERC721", events(ERC721Events))]93impl<T: Config> NonfungibleHandle<T> {94	fn balance_of(&self, owner: address) -> Result<uint256> {95		let owner = T::CrossAccountId::from_eth(owner);96		let balance = <AccountBalance<T>>::get((self.id, owner.as_sub()));97		Ok(balance.into())98	}99	fn owner_of(&self, token_id: uint256) -> Result<address> {100		let token: TokenId = token_id.try_into()?;101		Ok(*<TokenData<T>>::get((self.id, token))102			.ok_or("token not found")?103			.owner104			.as_eth())105	}106	fn safe_transfer_from_with_data(107		&mut self,108		_from: address,109		_to: address,110		_token_id: uint256,111		_data: bytes,112		_value: value,113	) -> Result<void> {114		// TODO: Not implemetable115		Err("not implemented".into())116	}117	fn safe_transfer_from(118		&mut self,119		_from: address,120		_to: address,121		_token_id: uint256,122		_value: value,123	) -> Result<void> {124		// TODO: Not implemetable125		Err("not implemented".into())126	}127128	fn transfer_from(129		&mut self,130		caller: caller,131		from: address,132		to: address,133		token_id: uint256,134		_value: value,135	) -> Result<void> {136		let caller = T::CrossAccountId::from_eth(caller);137		let from = T::CrossAccountId::from_eth(from);138		let to = T::CrossAccountId::from_eth(to);139		let token = token_id.try_into()?;140141		<Pallet<T>>::transfer_from(self, &caller, &from, &to, token)142			.map_err(dispatch_to_evm::<T>)?;143		Ok(())144	}145146	fn approve(147		&mut self,148		caller: caller,149		approved: address,150		token_id: uint256,151		_value: value,152	) -> Result<void> {153		let caller = T::CrossAccountId::from_eth(caller);154		let approved = T::CrossAccountId::from_eth(approved);155		let token = token_id.try_into()?;156157		<Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))158			.map_err(dispatch_to_evm::<T>)?;159		Ok(())160	}161162	fn set_approval_for_all(163		&mut self,164		_caller: caller,165		_operator: address,166		_approved: bool,167	) -> Result<void> {168		// TODO: Not implemetable169		Err("not implemented".into())170	}171172	fn get_approved(&self, _token_id: uint256) -> Result<address> {173		// TODO: Not implemetable174		Err("not implemented".into())175	}176177	fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {178		// TODO: Not implemetable179		Err("not implemented".into())180	}181}182183#[solidity_interface(name = "ERC721Burnable")]184impl<T: Config> NonfungibleHandle<T> {185	fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {186		let caller = T::CrossAccountId::from_eth(caller);187		let token = token_id.try_into()?;188189		<Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;190		Ok(())191	}192}193194#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]195impl<T: Config> NonfungibleHandle<T> {196	fn minting_finished(&self) -> Result<bool> {197		Ok(false)198	}199200	fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {201		let caller = T::CrossAccountId::from_eth(caller);202		let to = T::CrossAccountId::from_eth(to);203		let token_id: u32 = token_id.try_into()?;204		if <TokensMinted<T>>::get(self.id)205			.checked_add(1)206			.ok_or("item id overflow")?207			!= token_id208		{209			return Err("item id should be next".into());210		}211212		<Pallet<T>>::create_item(213			self,214			&caller,215			CreateItemData {216				const_data: BoundedVec::default(),217				variable_data: BoundedVec::default(),218				owner: to,219			},220		)221		.map_err(dispatch_to_evm::<T>)?;222223		Ok(true)224	}225226	#[solidity(rename_selector = "mintWithTokenURI")]227	fn mint_with_token_uri(228		&mut self,229		caller: caller,230		to: address,231		token_id: uint256,232		token_uri: string,233	) -> Result<bool> {234		let caller = T::CrossAccountId::from_eth(caller);235		let to = T::CrossAccountId::from_eth(to);236		let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;237		if <TokensMinted<T>>::get(self.id)238			.checked_add(1)239			.ok_or("item id overflow")?240			!= token_id241		{242			return Err("item id should be next".into());243		}244245		<Pallet<T>>::create_item(246			self,247			&caller,248			CreateItemData {249				const_data: Vec::<u8>::from(token_uri)250					.try_into()251					.map_err(|_| "token uri is too long")?,252				variable_data: BoundedVec::default(),253				owner: to,254			},255		)256		.map_err(dispatch_to_evm::<T>)?;257		Ok(true)258	}259260	fn finish_minting(&mut self, _caller: caller) -> Result<bool> {261		Err("not implementable".into())262	}263}264265#[solidity_interface(name = "ERC721UniqueExtensions")]266impl<T: Config> NonfungibleHandle<T> {267	fn transfer(268		&mut self,269		caller: caller,270		to: address,271		token_id: uint256,272		_value: value,273	) -> Result<void> {274		let caller = T::CrossAccountId::from_eth(caller);275		let to = T::CrossAccountId::from_eth(to);276		let token = token_id.try_into()?;277278		<Pallet<T>>::transfer(self, &caller, &to, token).map_err(dispatch_to_evm::<T>)?;279		Ok(())280	}281282	fn burn_from(283		&mut self,284		caller: caller,285		from: address,286		token_id: uint256,287		_value: value,288	) -> Result<void> {289		let caller = T::CrossAccountId::from_eth(caller);290		let from = T::CrossAccountId::from_eth(from);291		let token = token_id.try_into()?;292293		<Pallet<T>>::burn_from(self, &caller, &from, token).map_err(dispatch_to_evm::<T>)?;294		Ok(())295	}296297	fn next_token_id(&self) -> Result<uint256> {298		Ok(<TokensMinted<T>>::get(self.id)299			.checked_add(1)300			.ok_or("item id overflow")?301			.into())302	}303304	fn set_variable_metadata(305		&mut self,306		caller: caller,307		token_id: uint256,308		data: bytes,309	) -> Result<void> {310		let caller = T::CrossAccountId::from_eth(caller);311		let token = token_id.try_into()?;312313		<Pallet<T>>::set_variable_metadata(self, &caller, token, data)314			.map_err(dispatch_to_evm::<T>)?;315		Ok(())316	}317318	fn get_variable_metadata(&self, token_id: uint256) -> Result<bytes> {319		let token: TokenId = token_id.try_into()?;320321		Ok(<TokenData<T>>::get((self.id, token))322			.ok_or("token not found")?323			.variable_data)324	}325326	fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {327		let caller = T::CrossAccountId::from_eth(caller);328		let to = T::CrossAccountId::from_eth(to);329		let mut expected_index = <TokensMinted<T>>::get(self.id)330			.checked_add(1)331			.ok_or("item id overflow")?;332333		let total_tokens = token_ids.len();334		for id in token_ids.into_iter() {335			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;336			if id != expected_index {337				return Err("item id should be next".into());338			}339			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;340		}341		let data = (0..total_tokens)342			.map(|_| CreateItemData {343				const_data: BoundedVec::default(),344				variable_data: BoundedVec::default(),345				owner: to.clone(),346			})347			.collect();348349		<Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;350		Ok(true)351	}352353	#[solidity(rename_selector = "mintBulkWithTokenURI")]354	fn mint_bulk_with_token_uri(355		&mut self,356		caller: caller,357		to: address,358		tokens: Vec<(uint256, string)>,359	) -> Result<bool> {360		let caller = T::CrossAccountId::from_eth(caller);361		let to = T::CrossAccountId::from_eth(to);362		let mut expected_index = <TokensMinted<T>>::get(self.id)363			.checked_add(1)364			.ok_or("item id overflow")?;365366		let mut data = Vec::with_capacity(tokens.len());367		for (id, token_uri) in tokens {368			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;369			if id != expected_index {370				panic!("item id should be next ({}) but got {}", expected_index, id);371			}372			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;373374			data.push(CreateItemData {375				const_data: Vec::<u8>::from(token_uri)376					.try_into()377					.map_err(|_| "token uri is too long")?,378				variable_data: vec![].try_into().unwrap(),379				owner: to.clone(),380			});381		}382383		<Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;384		Ok(true)385	}386}387388#[solidity_interface(389	name = "UniqueNFT",390	is(391		ERC721,392		ERC721Metadata,393		ERC721Enumerable,394		ERC721UniqueExtensions,395		ERC721Mintable,396		ERC721Burnable,397	)398)]399impl<T: Config> NonfungibleHandle<T> {}400401// Not a tests, but code generators402generate_stubgen!(gen_impl, UniqueNFTCall, true);403generate_stubgen!(gen_iface, UniqueNFTCall, false);404405pub const CODE: &[u8] = include_bytes!("./stubs/UniqueNFT.raw");406407impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {408	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");409410	fn call(mut self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput> {411		let result = call_internal::<UniqueNFTCall, _>(*source, &mut self, value, input);412		self.0.recorder.evm_to_precompile_output(result)413	}414}
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -499,6 +499,32 @@
 		Ok(())
 	}
 
+	pub fn burn_from(
+		collection: &NonfungibleHandle<T>,
+		spender: &T::CrossAccountId,
+		from: &T::CrossAccountId,
+		token: TokenId,
+	) -> DispatchResult {
+		if spender == from {
+			return Self::burn(collection, from, token);
+		}
+		if collection.access == AccessMode::WhiteList {
+			// `from` checked in [`burn`]
+			collection.check_allowlist(spender)?;
+		}
+
+		if <Allowance<T>>::get((collection.id, token)).as_ref() != Some(spender) {
+			ensure!(
+				collection.ignores_allowance(spender)?,
+				<CommonError<T>>::TokenValueNotEnough
+			);
+		}
+
+		// =========
+
+		Self::burn(collection, &from, token)
+	}
+
 	pub fn set_variable_metadata(
 		collection: &NonfungibleHandle<T>,
 		sender: &T::CrossAccountId,
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -59,6 +59,10 @@
 		)
 	}
 
+	fn burn_from() -> Weight {
+		0
+	}
+
 	fn set_variable_metadata(bytes: u32) -> Weight {
 		<SelfWeightOf<T>>::set_variable_metadata(bytes)
 	}
@@ -161,7 +165,20 @@
 	) -> DispatchResultWithPostInfo {
 		with_weight(
 			<Pallet<T>>::transfer_from(&self, &sender, &from, &to, token, amount),
-			<CommonWeights<T>>::approve(),
+			<CommonWeights<T>>::transfer_from(),
+		)
+	}
+
+	fn burn_from(
+		&self,
+		sender: T::CrossAccountId,
+		from: T::CrossAccountId,
+		token: TokenId,
+		amount: u128,
+	) -> DispatchResultWithPostInfo {
+		with_weight(
+			<Pallet<T>>::burn_from(&self, &sender, &from, token, amount),
+			<CommonWeights<T>>::burn_from(),
 		)
 	}
 
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -537,6 +537,39 @@
 		Ok(())
 	}
 
+	pub fn burn_from(
+		collection: &RefungibleHandle<T>,
+		spender: &T::CrossAccountId,
+		from: &T::CrossAccountId,
+		token: TokenId,
+		amount: u128,
+	) -> DispatchResult {
+		if spender == from {
+			return Self::burn(collection, from, token, amount);
+		}
+		if collection.access == AccessMode::WhiteList {
+			// `from` checked in [`burn`]
+			collection.check_allowlist(spender)?;
+		}
+
+		let allowance = <Allowance<T>>::get((collection.id, token, from.as_sub(), &spender))
+			.checked_sub(amount);
+		if allowance.is_none() {
+			ensure!(
+				collection.ignores_allowance(spender)?,
+				<CommonError<T>>::TokenValueNotEnough
+			);
+		}
+
+		// =========
+
+		Self::burn(collection, from, token, amount)?;
+		if let Some(allowance) = allowance {
+			Self::set_allowance_unchecked(collection, from, spender, token, allowance);
+		}
+		Ok(())
+	}
+
 	pub fn set_variable_metadata(
 		collection: &RefungibleHandle<T>,
 		sender: &T::CrossAccountId,