difftreelog
Merge pull request #986 from UniqueNetwork/feature/add_mint_bulk_cross
in: master
Add mintBulkCross to NFT and RFT collections
20 files changed
node/cli/src/command.rsdiffbeforeafterboth--- a/node/cli/src/command.rs
+++ b/node/cli/src/command.rs
@@ -425,7 +425,7 @@
.map(|cfg| &cfg.registry);
let task_manager =
sc_service::TaskManager::new(runner.config().tokio_handle.clone(), *registry)
- .map_err(|e| format!("Error: {:?}", e))?;
+ .map_err(|e| format!("Error: {e:?}"))?;
let info_provider = Some(timestamp_with_aura_info(12000));
runner.async_run(|config| -> Result<(Pin<Box<dyn Future<Output = _>>>, _)> {
pallets/common/src/eth.rsdiffbeforeafterboth--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -119,7 +119,7 @@
} else if self.sub == Default::default() {
Ok(Some(T::CrossAccountId::from_eth(self.eth)))
} else {
- Err(format!("All fields of cross account is non zeroed {:?}", self).into())
+ Err(format!("All fields of cross account is non zeroed {self:?}").into())
}
}
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -26,7 +26,7 @@
char::{REPLACEMENT_CHARACTER, decode_utf16},
convert::TryInto,
};
-use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};
+use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*};
use frame_support::BoundedVec;
use up_data_structs::{
TokenId, PropertyPermission, PropertyKeyPermission, Property, CollectionId, PropertyKey,
@@ -64,6 +64,15 @@
},
}
+/// Token minting parameters
+#[derive(AbiCoder, Default, Debug)]
+pub struct MintTokenData {
+ /// Minted token owner
+ pub owner: eth::CrossAddress,
+ /// Minted token properties
+ pub properties: Vec<eth::Property>,
+}
+
frontier_contract! {
macro_rules! NonfungibleHandle_result {...}
impl<T: Config> Contract for NonfungibleHandle<T> {...}
@@ -981,13 +990,41 @@
Ok(true)
}
+ /// @notice Function to mint a token.
+ /// @param data Array of pairs of token owner and token's properties for minted token
+ #[weight(<SelfWeightOf<T>>::create_multiple_items(data.len() as u32) + <SelfWeightOf<T>>::set_token_properties(data.len() as u32))]
+ fn mint_bulk_cross(&mut self, caller: Caller, data: Vec<MintTokenData>) -> Result<bool> {
+ let caller = T::CrossAccountId::from_eth(caller);
+ let budget = self
+ .recorder
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
+
+ let mut create_nft_data = Vec::with_capacity(data.len());
+ for MintTokenData { owner, properties } in data {
+ let owner = owner.into_sub_cross_account::<T>()?;
+ create_nft_data.push(CreateItemData::<T> {
+ properties: properties
+ .into_iter()
+ .map(|property| property.try_into())
+ .collect::<Result<Vec<_>>>()?
+ .try_into()
+ .map_err(|_| "too many properties")?,
+ owner,
+ });
+ }
+
+ <Pallet<T>>::create_multiple_items(self, &caller, create_nft_data, &budget)
+ .map_err(dispatch_to_evm::<T>)?;
+ Ok(true)
+ }
+
/// @notice Function to mint multiple tokens with the given tokenUris.
/// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
/// numbers and first number should be obtained with `nextTokenId` method
/// @param to The new owner
/// @param tokens array of pairs of token ID and token URI for minted tokens
#[solidity(hide, rename_selector = "mintBulkWithTokenURI")]
- #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32) + <SelfWeightOf<T>>::set_token_properties(tokens.len() as u32))]
+ #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32) + <SelfWeightOf<T>>::set_token_properties(tokens.len() as u32))]
fn mint_bulk_with_token_uri(
&mut self,
caller: Caller,
pallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -800,7 +800,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x307b061a
+/// @dev the ERC-165 identifier for this interface is 0x9b397d16
contract ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -997,6 +997,17 @@
// return false;
// }
+ /// @notice Function to mint a token.
+ /// @param data Array of pairs of token owner and token's properties for minted token
+ /// @dev EVM selector for this function is: 0xab427b0c,
+ /// or in textual repr: mintBulkCross(((address,uint256),(string,bytes)[])[])
+ function mintBulkCross(MintTokenData[] memory data) public returns (bool) {
+ require(false, stub_error);
+ data;
+ dummy = 0;
+ return false;
+ }
+
// /// @notice Function to mint multiple tokens with the given tokenUris.
// /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
// /// numbers and first number should be obtained with `nextTokenId` method
@@ -1044,6 +1055,14 @@
string uri;
}
+/// Token minting parameters
+struct MintTokenData {
+ /// Minted token owner
+ CrossAddress owner;
+ /// Minted token properties
+ Property[] properties;
+}
+
/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// @dev the ERC-165 identifier for this interface is 0x780e9d63
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -26,7 +26,7 @@
char::{REPLACEMENT_CHARACTER, decode_utf16},
convert::TryInto,
};
-use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};
+use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*};
use frame_support::{BoundedBTreeMap, BoundedVec};
use pallet_common::{
CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
@@ -71,6 +71,24 @@
},
}
+/// Token minting parameters
+#[derive(AbiCoder, Default, Debug)]
+pub struct OwnerPieces {
+ /// Minted token owner
+ pub owner: eth::CrossAddress,
+ /// Number of token pieces
+ pub pieces: u128,
+}
+
+/// Token minting parameters
+#[derive(AbiCoder, Default, Debug)]
+pub struct MintTokenData {
+ /// Minted token owner and number of pieces
+ pub owners: Vec<OwnerPieces>,
+ /// Minted token properties
+ pub properties: Vec<eth::Property>,
+}
+
/// @title A contract that allows to set and delete token properties and change token property permissions.
#[solidity_interface(name = TokenProperties, events(ERC721TokenEvent), enum(derive(PreDispatch)), enum_attr(weight))]
impl<T: Config> RefungibleHandle<T> {
@@ -1021,6 +1039,55 @@
Ok(true)
}
+ /// @notice Function to mint a token.
+ /// @param tokenProperties Properties of minted token
+ #[weight(if token_properties.len() == 1 {
+ <SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(token_properties.iter().next().unwrap().owners.len() as u32)
+ } else {
+ <SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(token_properties.len() as u32)
+ } + <SelfWeightOf<T>>::set_token_properties(token_properties.len() as u32))]
+ fn mint_bulk_cross(
+ &mut self,
+ caller: Caller,
+ token_properties: Vec<MintTokenData>,
+ ) -> Result<bool> {
+ let caller = T::CrossAccountId::from_eth(caller);
+ let budget = self
+ .recorder
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
+ let has_multiple_tokens = token_properties.len() > 1;
+
+ let mut create_rft_data = Vec::with_capacity(token_properties.len());
+ for MintTokenData { owners, properties } in token_properties {
+ let has_multiple_owners = owners.len() > 1;
+ if has_multiple_tokens & has_multiple_owners {
+ return Err(
+ "creation of multiple tokens supported only if they have single owner each"
+ .into(),
+ );
+ }
+ let users: BoundedBTreeMap<_, _, _> = owners
+ .into_iter()
+ .map(|data| Ok((data.owner.into_sub_cross_account::<T>()?, data.pieces)))
+ .collect::<Result<BTreeMap<_, _>>>()?
+ .try_into()
+ .map_err(|_| "too many users")?;
+ create_rft_data.push(CreateItemData::<T> {
+ properties: properties
+ .into_iter()
+ .map(|property| property.try_into())
+ .collect::<Result<Vec<_>>>()?
+ .try_into()
+ .map_err(|_| "too many properties")?,
+ users,
+ });
+ }
+
+ <Pallet<T>>::create_multiple_items(self, &caller, create_rft_data, &budget)
+ .map_err(dispatch_to_evm::<T>)?;
+ Ok(true)
+ }
+
/// @notice Function to mint multiple tokens with the given tokenUris.
/// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
/// numbers and first number should be obtained with `nextTokenId` method
pallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth--- a/pallets/refungible/src/stubs/UniqueRefungible.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -800,7 +800,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x95c0f66c
+/// @dev the ERC-165 identifier for this interface is 0x4abaabdb
contract ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -986,6 +986,17 @@
// return false;
// }
+ /// @notice Function to mint a token.
+ /// @param tokenProperties Properties of minted token
+ /// @dev EVM selector for this function is: 0xdf7a5db7,
+ /// or in textual repr: mintBulkCross((((address,uint256),uint128)[],(string,bytes)[])[])
+ function mintBulkCross(MintTokenData[] memory tokenProperties) public returns (bool) {
+ require(false, stub_error);
+ tokenProperties;
+ dummy = 0;
+ return false;
+ }
+
// /// @notice Function to mint multiple tokens with the given tokenUris.
// /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
// /// numbers and first number should be obtained with `nextTokenId` method
@@ -1045,6 +1056,22 @@
string uri;
}
+/// Token minting parameters
+struct MintTokenData {
+ /// Minted token owner and number of pieces
+ OwnerPieces[] owners;
+ /// Minted token properties
+ Property[] properties;
+}
+
+/// Token minting parameters
+struct OwnerPieces {
+ /// Minted token owner
+ CrossAddress owner;
+ /// Number of token pieces
+ uint128 pieces;
+}
+
/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// @dev the ERC-165 identifier for this interface is 0x780e9d63
pallets/scheduler-v2/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/scheduler-v2/src/benchmarking.rs
+++ b/pallets/scheduler-v2/src/benchmarking.rs
@@ -136,8 +136,10 @@
let bound = EncodedCall::bound() as u32;
let mut len = match maybe_lookup_len {
Some(len) => {
- len.min(<T::Preimages as PreimageRecipient<T::Hash>>::MaxSize::get() - 2)
- .max(bound) - 3
+ len.clamp(
+ bound,
+ <T::Preimages as PreimageRecipient<T::Hash>>::MaxSize::get() - 2,
+ ) - 3
}
None => bound.saturating_sub(4),
};
pallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth--- a/pallets/unique/src/eth/stubs/CollectionHelpers.sol
+++ b/pallets/unique/src/eth/stubs/CollectionHelpers.sol
@@ -25,12 +25,12 @@
}
/// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0x4135fff1
+/// @dev the ERC-165 identifier for this interface is 0x94e5af0d
contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
/// Create a collection
/// @return address Address of the newly created collection
- /// @dev EVM selector for this function is: 0xa765ee5b,
- /// or in textual repr: createCollection(((address,uint256),string,string,string,uint8,uint8,(string,bytes)[],(string,(uint8,bool)[])[],(address,uint256)[],(bool,bool,address[]),(uint8,uint256)[],uint8))
+ /// @dev EVM selector for this function is: 0x72b5bea7,
+ /// or in textual repr: createCollection((string,string,string,uint8,uint8,(string,bytes)[],(string,(uint8,bool)[])[],(address,uint256)[],(bool,bool,address[]),(uint8,uint256)[],(address,uint256),uint8))
function createCollection(CreateCollectionData memory data) public payable returns (address) {
require(false, stub_error);
data;
@@ -170,8 +170,6 @@
/// Collection properties
struct CreateCollectionData {
- /// Collection sponsor
- CrossAddress pending_sponsor;
/// Collection name
string name;
/// Collection description
@@ -192,11 +190,12 @@
CollectionNestingAndPermission nesting_settings;
/// Collection limits
CollectionLimitValue[] limits;
+ /// Collection sponsor
+ CrossAddress pending_sponsor;
/// Extra collection flags
CollectionFlags flags;
}
-/// Cross account struct
type CollectionFlags is uint8;
library CollectionFlagsLib {
@@ -207,13 +206,19 @@
/// External collections can't be managed using `unique` api
CollectionFlags constant externalField = CollectionFlags.wrap(1);
- /// Reserved bits
+ /// Reserved flags
function reservedField(uint8 value) public pure returns (CollectionFlags) {
require(value < 1 << 5, "out of bound value");
return CollectionFlags.wrap(value << 1);
}
}
+/// Cross account struct
+struct CrossAddress {
+ address eth;
+ uint256 sub;
+}
+
/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
struct CollectionLimitValue {
CollectionLimitField field;
@@ -250,12 +255,6 @@
bool collection_admin;
/// If set - only tokens from specified collections can be nested.
address[] restricted;
-}
-
-/// Cross account struct
-struct CrossAddress {
- address eth;
- uint256 sub;
}
/// Ethereum representation of Token Property Permissions.
@@ -292,10 +291,10 @@
/// Type of tokens in collection
enum CollectionMode {
- /// Fungible
- Fungible,
/// Nonfungible
Nonfungible,
+ /// Fungible
+ Fungible,
/// Refungible
Refungible
}
runtime/common/ethereum/sponsoring/refungible.rsdiffbeforeafterboth1// 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/>.1617//! Implements EVM sponsoring logic via TransactionValidityHack1819use pallet_common::CollectionHandle;20use pallet_evm::account::CrossAccountId;21use pallet_fungible::Config as FungibleConfig;22use pallet_refungible::Config as RefungibleConfig;23use pallet_nonfungible::Config as NonfungibleConfig;24use pallet_unique::Config as UniqueConfig;25use up_data_structs::{CreateItemData, CreateNftData, TokenId};2627use super::common;28use crate::runtime_common::sponsoring::*;2930use pallet_refungible::{31 erc::{32 ERC721BurnableCall, ERC721Call, ERC721EnumerableCall, ERC721MetadataCall,33 ERC721UniqueExtensionsCall, ERC721UniqueMintableCall, TokenPropertiesCall,34 UniqueRefungibleCall,35 },36 erc_token::{37 ERC1633Call, ERC20Call, ERC20UniqueExtensionsCall, RefungibleTokenHandle,38 UniqueRefungibleTokenCall,39 },40};4142pub fn call_sponsor<T>(43 call: UniqueRefungibleCall<T>,44 collection: CollectionHandle<T>,45 who: &T::CrossAccountId,46) -> Option<()>47where48 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,49{50 use UniqueRefungibleCall::*;5152 match call {53 // Readonly54 ERC165Call(_, _) => None,5556 ERC721Enumerable(call) => erc721::enumerable_call_sponsor(call, collection, who),57 ERC721Burnable(call) => erc721::burnable_call_sponsor(call, collection, who),58 ERC721Metadata(call) => erc721::metadata_call_sponsor(call, collection, who),59 Collection(call) => common::collection_call_sponsor(call, collection, who),60 ERC721(call) => erc721::call_sponsor(call, collection, who),61 ERC721UniqueExtensions(call) => {62 erc721::unique_extensions_call_sponsor(call, collection, who)63 }64 ERC721UniqueMintable(call) => erc721::unique_mintable_call_sponsor(call, collection, who),65 TokenProperties(call) => token_properties_call_sponsor(call, collection, who),66 }67}6869pub fn token_properties_call_sponsor<T>(70 call: TokenPropertiesCall<T>,71 collection: CollectionHandle<T>,72 who: &T::CrossAccountId,73) -> Option<()>74where75 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,76{77 use TokenPropertiesCall::*;7879 match call {80 // Readonly81 ERC165Call(_, _) | Property { .. } | TokenPropertyPermissions => None,8283 // Not sponsored84 SetTokenPropertyPermission { .. }85 | SetTokenPropertyPermissions { .. }86 | SetProperties { .. }87 | DeleteProperty { .. }88 | DeleteProperties { .. } => None,8990 SetProperty {91 token_id,92 key,93 value,94 ..95 } => {96 let token_id = TokenId::try_from(token_id).ok()?;97 withdraw_set_existing_token_property::<T>(98 &collection,99 who,100 &token_id,101 key.len() + value.len(),102 )103 }104 }105}106107pub fn token_call_sponsor<T>(108 call: UniqueRefungibleTokenCall<T>,109 token: RefungibleTokenHandle<T>,110 who: &T::CrossAccountId,111) -> Option<()>112where113 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,114{115 use UniqueRefungibleTokenCall::*;116117 match call {118 // Readonly119 ERC165Call(_, _) => None,120121 ERC20(call) => erc20::call_sponsor(call, token, who),122 ERC20UniqueExtensions(call) => erc20::unique_extensions_call_sponsor(call, token, who),123 ERC1633(call) => erc1633::call_sponsor(call, token, who),124 }125}126127mod erc721 {128 use super::*;129130 pub fn call_sponsor<T>(131 call: ERC721Call<T>,132 collection: CollectionHandle<T>,133 _who: &T::CrossAccountId,134 ) -> Option<()>135 where136 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,137 {138 use ERC721Call::*;139140 match call {141 // Readonly142 ERC165Call(_, _)143 | BalanceOf { .. }144 | OwnerOf { .. }145 | GetApproved { .. }146 | IsApprovedForAll { .. } => None,147148 // Not sponsored149 SafeTransferFromWithData { .. }150 | SafeTransferFrom { .. }151 | SetApprovalForAll { .. } => None,152153 TransferFrom { token_id, from, .. } => {154 let token_id = TokenId::try_from(token_id).ok()?;155 let from = T::CrossAccountId::from_eth(from);156 withdraw_transfer::<T>(&collection, &from, &token_id)157 }158159 // Not supported160 Approve { .. } => None,161 }162 }163164 pub fn enumerable_call_sponsor<T>(165 call: ERC721EnumerableCall<T>,166 _collection: CollectionHandle<T>,167 _who: &T::CrossAccountId,168 ) -> Option<()>169 where170 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,171 {172 use ERC721EnumerableCall::*;173174 match call {175 // Readonly176 ERC165Call(_, _) | TokenByIndex { .. } | TokenOfOwnerByIndex { .. } | TotalSupply => {177 None178 }179 }180 }181182 pub fn burnable_call_sponsor<T>(183 call: ERC721BurnableCall<T>,184 _collection: CollectionHandle<T>,185 _who: &T::CrossAccountId,186 ) -> Option<()>187 where188 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,189 {190 use ERC721BurnableCall::*;191192 match call {193 // Readonly194 ERC165Call(_, _) => None,195196 // Not sponsored197 Burn { .. } => None,198 }199 }200201 pub fn metadata_call_sponsor<T>(202 call: ERC721MetadataCall<T>,203 _collection: CollectionHandle<T>,204 _who: &T::CrossAccountId,205 ) -> Option<()>206 where207 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,208 {209 use ERC721MetadataCall::*;210211 match call {212 // Readonly213 ERC165Call(_, _) | NameProxy | SymbolProxy | TokenUri { .. } => None,214 }215 }216217 pub fn unique_extensions_call_sponsor<T>(218 call: ERC721UniqueExtensionsCall<T>,219 collection: CollectionHandle<T>,220 who: &T::CrossAccountId,221 ) -> Option<()>222 where223 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,224 {225 use ERC721UniqueExtensionsCall::*;226227 match call {228 // Readonly229 ERC165Call(_, _)230 | Name231 | Symbol232 | Description233 | CrossOwnerOf { .. }234 | OwnerOfCross { .. }235 | BalanceOfCross { .. }236 | Properties { .. }237 | NextTokenId238 | TokenContractAddress { .. }239 | CollectionHelperAddress => None,240241 // Not sponsored242 BurnFrom { .. }243 | BurnFromCross { .. }244 | MintBulk { .. }245 | MintBulkWithTokenUri { .. } => None,246247 MintCross { .. } => withdraw_create_item::<T>(248 &collection,249 who,250 &CreateItemData::NFT(CreateNftData::default()),251 ),252253 TransferCross { token_id, .. }254 | TransferFromCross { token_id, .. }255 | Transfer { token_id, .. } => {256 let token_id = TokenId::try_from(token_id).ok()?;257 withdraw_transfer::<T>(&collection, who, &token_id)258 }259 }260 }261262 pub fn unique_mintable_call_sponsor<T>(263 call: ERC721UniqueMintableCall<T>,264 collection: CollectionHandle<T>,265 who: &T::CrossAccountId,266 ) -> Option<()>267 where268 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,269 {270 use ERC721UniqueMintableCall::*;271272 match call {273 // Readonly274 ERC165Call(_, _) => None,275276 // Sponsored277 Mint { .. }278 | MintCheckId { .. }279 | MintWithTokenUri { .. }280 | MintWithTokenUriCheckId { .. } => withdraw_create_item::<T>(281 &collection,282 who,283 &CreateItemData::NFT(CreateNftData::default()),284 ),285 }286 }287}288289/// Module for methods of refungible token290///291/// Existance of token should be checked before searching for sponsor292/// because RefungibleTokenHandle doesn't check token's existence upon creation293mod erc20 {294 use super::*;295296 pub fn call_sponsor<T>(297 call: ERC20Call<T>,298 token: RefungibleTokenHandle<T>,299 who: &T::CrossAccountId,300 ) -> Option<()>301 where302 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,303 {304 use ERC20Call::*;305306 match call {307 // Readonly308 ERC165Call(_, _)309 | Name310 | Symbol311 | TotalSupply312 | Decimals313 | BalanceOf { .. }314 | Allowance { .. } => None,315316 Transfer { .. } => {317 let RefungibleTokenHandle(handle, token_id) = token;318 withdraw_transfer::<T>(&handle, who, &token_id)319 }320 TransferFrom { from, .. } => {321 let RefungibleTokenHandle(handle, token_id) = token;322 let from = T::CrossAccountId::from_eth(from);323 withdraw_transfer::<T>(&handle, &from, &token_id)324 }325 Approve { .. } => {326 let RefungibleTokenHandle(handle, token_id) = token;327 withdraw_approve::<T>(&handle, who.as_sub(), &token_id)328 }329 }330 }331332 pub fn unique_extensions_call_sponsor<T>(333 call: ERC20UniqueExtensionsCall<T>,334 token: RefungibleTokenHandle<T>,335 who: &T::CrossAccountId,336 ) -> Option<()>337 where338 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,339 {340 use ERC20UniqueExtensionsCall::*;341342 match call {343 // Readonly344 ERC165Call(_, _) => None,345346 // Not sponsored347 AllowanceCross { .. }348 | BalanceOfCross { .. }349 | BurnFrom { .. }350 | BurnFromCross { .. }351 | Repartition { .. } => None,352353 TransferCross { .. } | TransferFromCross { .. } => {354 let RefungibleTokenHandle(handle, token_id) = token;355 withdraw_transfer::<T>(&handle, who, &token_id)356 }357358 ApproveCross { .. } => {359 let RefungibleTokenHandle(handle, token_id) = token;360 withdraw_approve::<T>(&handle, who.as_sub(), &token_id)361 }362 }363 }364}365366mod erc1633 {367 use super::*;368369 pub fn call_sponsor<T>(370 call: ERC1633Call<T>,371 _token: RefungibleTokenHandle<T>,372 _who: &T::CrossAccountId,373 ) -> Option<()>374 where375 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,376 {377 use ERC1633Call::*;378379 match call {380 // Readonly381 ERC165Call(_, _) | ParentToken | ParentTokenId => None,382 }383 }384}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/>.1617//! Implements EVM sponsoring logic via TransactionValidityHack1819use pallet_common::CollectionHandle;20use pallet_evm::account::CrossAccountId;21use pallet_fungible::Config as FungibleConfig;22use pallet_refungible::Config as RefungibleConfig;23use pallet_nonfungible::Config as NonfungibleConfig;24use pallet_unique::Config as UniqueConfig;25use up_data_structs::{CreateItemData, CreateNftData, TokenId};2627use super::common;28use crate::runtime_common::sponsoring::*;2930use pallet_refungible::{31 erc::{32 ERC721BurnableCall, ERC721Call, ERC721EnumerableCall, ERC721MetadataCall,33 ERC721UniqueExtensionsCall, ERC721UniqueMintableCall, TokenPropertiesCall,34 UniqueRefungibleCall,35 },36 erc_token::{37 ERC1633Call, ERC20Call, ERC20UniqueExtensionsCall, RefungibleTokenHandle,38 UniqueRefungibleTokenCall,39 },40};4142pub fn call_sponsor<T>(43 call: UniqueRefungibleCall<T>,44 collection: CollectionHandle<T>,45 who: &T::CrossAccountId,46) -> Option<()>47where48 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,49{50 use UniqueRefungibleCall::*;5152 match call {53 // Readonly54 ERC165Call(_, _) => None,5556 ERC721Enumerable(call) => erc721::enumerable_call_sponsor(call, collection, who),57 ERC721Burnable(call) => erc721::burnable_call_sponsor(call, collection, who),58 ERC721Metadata(call) => erc721::metadata_call_sponsor(call, collection, who),59 Collection(call) => common::collection_call_sponsor(call, collection, who),60 ERC721(call) => erc721::call_sponsor(call, collection, who),61 ERC721UniqueExtensions(call) => {62 erc721::unique_extensions_call_sponsor(call, collection, who)63 }64 ERC721UniqueMintable(call) => erc721::unique_mintable_call_sponsor(call, collection, who),65 TokenProperties(call) => token_properties_call_sponsor(call, collection, who),66 }67}6869pub fn token_properties_call_sponsor<T>(70 call: TokenPropertiesCall<T>,71 collection: CollectionHandle<T>,72 who: &T::CrossAccountId,73) -> Option<()>74where75 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,76{77 use TokenPropertiesCall::*;7879 match call {80 // Readonly81 ERC165Call(_, _) | Property { .. } | TokenPropertyPermissions => None,8283 // Not sponsored84 SetTokenPropertyPermission { .. }85 | SetTokenPropertyPermissions { .. }86 | SetProperties { .. }87 | DeleteProperty { .. }88 | DeleteProperties { .. } => None,8990 SetProperty {91 token_id,92 key,93 value,94 ..95 } => {96 let token_id = TokenId::try_from(token_id).ok()?;97 withdraw_set_existing_token_property::<T>(98 &collection,99 who,100 &token_id,101 key.len() + value.len(),102 )103 }104 }105}106107pub fn token_call_sponsor<T>(108 call: UniqueRefungibleTokenCall<T>,109 token: RefungibleTokenHandle<T>,110 who: &T::CrossAccountId,111) -> Option<()>112where113 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,114{115 use UniqueRefungibleTokenCall::*;116117 match call {118 // Readonly119 ERC165Call(_, _) => None,120121 ERC20(call) => erc20::call_sponsor(call, token, who),122 ERC20UniqueExtensions(call) => erc20::unique_extensions_call_sponsor(call, token, who),123 ERC1633(call) => erc1633::call_sponsor(call, token, who),124 }125}126127mod erc721 {128 use super::*;129130 pub fn call_sponsor<T>(131 call: ERC721Call<T>,132 collection: CollectionHandle<T>,133 _who: &T::CrossAccountId,134 ) -> Option<()>135 where136 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,137 {138 use ERC721Call::*;139140 match call {141 // Readonly142 ERC165Call(_, _)143 | BalanceOf { .. }144 | OwnerOf { .. }145 | GetApproved { .. }146 | IsApprovedForAll { .. } => None,147148 // Not sponsored149 SafeTransferFromWithData { .. }150 | SafeTransferFrom { .. }151 | SetApprovalForAll { .. } => None,152153 TransferFrom { token_id, from, .. } => {154 let token_id = TokenId::try_from(token_id).ok()?;155 let from = T::CrossAccountId::from_eth(from);156 withdraw_transfer::<T>(&collection, &from, &token_id)157 }158159 // Not supported160 Approve { .. } => None,161 }162 }163164 pub fn enumerable_call_sponsor<T>(165 call: ERC721EnumerableCall<T>,166 _collection: CollectionHandle<T>,167 _who: &T::CrossAccountId,168 ) -> Option<()>169 where170 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,171 {172 use ERC721EnumerableCall::*;173174 match call {175 // Readonly176 ERC165Call(_, _) | TokenByIndex { .. } | TokenOfOwnerByIndex { .. } | TotalSupply => {177 None178 }179 }180 }181182 pub fn burnable_call_sponsor<T>(183 call: ERC721BurnableCall<T>,184 _collection: CollectionHandle<T>,185 _who: &T::CrossAccountId,186 ) -> Option<()>187 where188 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,189 {190 use ERC721BurnableCall::*;191192 match call {193 // Readonly194 ERC165Call(_, _) => None,195196 // Not sponsored197 Burn { .. } => None,198 }199 }200201 pub fn metadata_call_sponsor<T>(202 call: ERC721MetadataCall<T>,203 _collection: CollectionHandle<T>,204 _who: &T::CrossAccountId,205 ) -> Option<()>206 where207 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,208 {209 use ERC721MetadataCall::*;210211 match call {212 // Readonly213 ERC165Call(_, _) | NameProxy | SymbolProxy | TokenUri { .. } => None,214 }215 }216217 pub fn unique_extensions_call_sponsor<T>(218 call: ERC721UniqueExtensionsCall<T>,219 collection: CollectionHandle<T>,220 who: &T::CrossAccountId,221 ) -> Option<()>222 where223 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,224 {225 use ERC721UniqueExtensionsCall::*;226227 match call {228 // Readonly229 ERC165Call(_, _)230 | Name231 | Symbol232 | Description233 | CrossOwnerOf { .. }234 | OwnerOfCross { .. }235 | BalanceOfCross { .. }236 | Properties { .. }237 | NextTokenId238 | TokenContractAddress { .. }239 | CollectionHelperAddress => None,240241 // Not sponsored242 BurnFrom { .. }243 | BurnFromCross { .. }244 | MintBulk { .. }245 | MintBulkCross { .. }246 | MintBulkWithTokenUri { .. } => None,247248 MintCross { .. } => withdraw_create_item::<T>(249 &collection,250 who,251 &CreateItemData::NFT(CreateNftData::default()),252 ),253254 TransferCross { token_id, .. }255 | TransferFromCross { token_id, .. }256 | Transfer { token_id, .. } => {257 let token_id = TokenId::try_from(token_id).ok()?;258 withdraw_transfer::<T>(&collection, who, &token_id)259 }260 }261 }262263 pub fn unique_mintable_call_sponsor<T>(264 call: ERC721UniqueMintableCall<T>,265 collection: CollectionHandle<T>,266 who: &T::CrossAccountId,267 ) -> Option<()>268 where269 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,270 {271 use ERC721UniqueMintableCall::*;272273 match call {274 // Readonly275 ERC165Call(_, _) => None,276277 // Sponsored278 Mint { .. }279 | MintCheckId { .. }280 | MintWithTokenUri { .. }281 | MintWithTokenUriCheckId { .. } => withdraw_create_item::<T>(282 &collection,283 who,284 &CreateItemData::NFT(CreateNftData::default()),285 ),286 }287 }288}289290/// Module for methods of refungible token291///292/// Existance of token should be checked before searching for sponsor293/// because RefungibleTokenHandle doesn't check token's existence upon creation294mod erc20 {295 use super::*;296297 pub fn call_sponsor<T>(298 call: ERC20Call<T>,299 token: RefungibleTokenHandle<T>,300 who: &T::CrossAccountId,301 ) -> Option<()>302 where303 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,304 {305 use ERC20Call::*;306307 match call {308 // Readonly309 ERC165Call(_, _)310 | Name311 | Symbol312 | TotalSupply313 | Decimals314 | BalanceOf { .. }315 | Allowance { .. } => None,316317 Transfer { .. } => {318 let RefungibleTokenHandle(handle, token_id) = token;319 withdraw_transfer::<T>(&handle, who, &token_id)320 }321 TransferFrom { from, .. } => {322 let RefungibleTokenHandle(handle, token_id) = token;323 let from = T::CrossAccountId::from_eth(from);324 withdraw_transfer::<T>(&handle, &from, &token_id)325 }326 Approve { .. } => {327 let RefungibleTokenHandle(handle, token_id) = token;328 withdraw_approve::<T>(&handle, who.as_sub(), &token_id)329 }330 }331 }332333 pub fn unique_extensions_call_sponsor<T>(334 call: ERC20UniqueExtensionsCall<T>,335 token: RefungibleTokenHandle<T>,336 who: &T::CrossAccountId,337 ) -> Option<()>338 where339 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,340 {341 use ERC20UniqueExtensionsCall::*;342343 match call {344 // Readonly345 ERC165Call(_, _) => None,346347 // Not sponsored348 AllowanceCross { .. }349 | BalanceOfCross { .. }350 | BurnFrom { .. }351 | BurnFromCross { .. }352 | Repartition { .. } => None,353354 TransferCross { .. } | TransferFromCross { .. } => {355 let RefungibleTokenHandle(handle, token_id) = token;356 withdraw_transfer::<T>(&handle, who, &token_id)357 }358359 ApproveCross { .. } => {360 let RefungibleTokenHandle(handle, token_id) = token;361 withdraw_approve::<T>(&handle, who.as_sub(), &token_id)362 }363 }364 }365}366367mod erc1633 {368 use super::*;369370 pub fn call_sponsor<T>(371 call: ERC1633Call<T>,372 _token: RefungibleTokenHandle<T>,373 _who: &T::CrossAccountId,374 ) -> Option<()>375 where376 T: UniqueConfig + FungibleConfig + NonfungibleConfig + RefungibleConfig,377 {378 use ERC1633Call::*;379380 match call {381 // Readonly382 ERC165Call(_, _) | ParentToken | ParentTokenId => None,383 }384 }385}runtime/common/tests/mod.rsdiffbeforeafterboth--- a/runtime/common/tests/mod.rs
+++ b/runtime/common/tests/mod.rs
@@ -33,7 +33,7 @@
const PARA_ID: u32 = 2037;
fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
- TPublic::Pair::from_string(&format!("//{}", seed), None)
+ TPublic::Pair::from_string(&format!("//{seed}"), None)
.expect("static values are valid; qed")
.public()
}
tests/src/eth/abi/nonFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/nonFungible.json
+++ b/tests/src/eth/abi/nonFungible.json
@@ -469,6 +469,39 @@
"inputs": [
{
"components": [
+ {
+ "components": [
+ { "internalType": "address", "name": "eth", "type": "address" },
+ { "internalType": "uint256", "name": "sub", "type": "uint256" }
+ ],
+ "internalType": "struct CrossAddress",
+ "name": "owner",
+ "type": "tuple"
+ },
+ {
+ "components": [
+ { "internalType": "string", "name": "key", "type": "string" },
+ { "internalType": "bytes", "name": "value", "type": "bytes" }
+ ],
+ "internalType": "struct Property[]",
+ "name": "properties",
+ "type": "tuple[]"
+ }
+ ],
+ "internalType": "struct MintTokenData[]",
+ "name": "data",
+ "type": "tuple[]"
+ }
+ ],
+ "name": "mintBulkCross",
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "components": [
{ "internalType": "address", "name": "eth", "type": "address" },
{ "internalType": "uint256", "name": "sub", "type": "uint256" }
],
tests/src/eth/abi/reFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/reFungible.json
+++ b/tests/src/eth/abi/reFungible.json
@@ -451,6 +451,55 @@
"inputs": [
{
"components": [
+ {
+ "components": [
+ {
+ "components": [
+ {
+ "internalType": "address",
+ "name": "eth",
+ "type": "address"
+ },
+ {
+ "internalType": "uint256",
+ "name": "sub",
+ "type": "uint256"
+ }
+ ],
+ "internalType": "struct CrossAddress",
+ "name": "owner",
+ "type": "tuple"
+ },
+ { "internalType": "uint128", "name": "pieces", "type": "uint128" }
+ ],
+ "internalType": "struct OwnerPieces[]",
+ "name": "owners",
+ "type": "tuple[]"
+ },
+ {
+ "components": [
+ { "internalType": "string", "name": "key", "type": "string" },
+ { "internalType": "bytes", "name": "value", "type": "bytes" }
+ ],
+ "internalType": "struct Property[]",
+ "name": "properties",
+ "type": "tuple[]"
+ }
+ ],
+ "internalType": "struct MintTokenData[]",
+ "name": "tokenProperties",
+ "type": "tuple[]"
+ }
+ ],
+ "name": "mintBulkCross",
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "components": [
{ "internalType": "address", "name": "eth", "type": "address" },
{ "internalType": "uint256", "name": "sub", "type": "uint256" }
],
tests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth--- a/tests/src/eth/api/CollectionHelpers.sol
+++ b/tests/src/eth/api/CollectionHelpers.sol
@@ -20,12 +20,12 @@
}
/// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0x4135fff1
+/// @dev the ERC-165 identifier for this interface is 0x94e5af0d
interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
/// Create a collection
/// @return address Address of the newly created collection
- /// @dev EVM selector for this function is: 0xa765ee5b,
- /// or in textual repr: createCollection(((address,uint256),string,string,string,uint8,uint8,(string,bytes)[],(string,(uint8,bool)[])[],(address,uint256)[],(bool,bool,address[]),(uint8,uint256)[],uint8))
+ /// @dev EVM selector for this function is: 0x72b5bea7,
+ /// or in textual repr: createCollection((string,string,string,uint8,uint8,(string,bytes)[],(string,(uint8,bool)[])[],(address,uint256)[],(bool,bool,address[]),(uint8,uint256)[],(address,uint256),uint8))
function createCollection(CreateCollectionData memory data) external payable returns (address);
/// Create an NFT collection
@@ -103,8 +103,6 @@
/// Collection properties
struct CreateCollectionData {
- /// Collection sponsor
- CrossAddress pending_sponsor;
/// Collection name
string name;
/// Collection description
@@ -125,11 +123,12 @@
CollectionNestingAndPermission nesting_settings;
/// Collection limits
CollectionLimitValue[] limits;
+ /// Collection sponsor
+ CrossAddress pending_sponsor;
/// Extra collection flags
CollectionFlags flags;
}
-/// Cross account struct
type CollectionFlags is uint8;
library CollectionFlagsLib {
@@ -140,13 +139,19 @@
/// External collections can't be managed using `unique` api
CollectionFlags constant externalField = CollectionFlags.wrap(1);
- /// Reserved bits
+ /// Reserved flags
function reservedField(uint8 value) public pure returns (CollectionFlags) {
require(value < 1 << 5, "out of bound value");
return CollectionFlags.wrap(value << 1);
}
}
+/// Cross account struct
+struct CrossAddress {
+ address eth;
+ uint256 sub;
+}
+
/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
struct CollectionLimitValue {
CollectionLimitField field;
@@ -183,12 +188,6 @@
bool collection_admin;
/// If set - only tokens from specified collections can be nested.
address[] restricted;
-}
-
-/// Cross account struct
-struct CrossAddress {
- address eth;
- uint256 sub;
}
/// Ethereum representation of Token Property Permissions.
@@ -225,10 +224,10 @@
/// Type of tokens in collection
enum CollectionMode {
- /// Fungible
- Fungible,
/// Nonfungible
Nonfungible,
+ /// Fungible
+ Fungible,
/// Refungible
Refungible
}
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -551,7 +551,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x307b061a
+/// @dev the ERC-165 identifier for this interface is 0x9b397d16
interface ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -674,6 +674,12 @@
// /// or in textual repr: mintBulk(address,uint256[])
// function mintBulk(address to, uint256[] memory tokenIds) external returns (bool);
+ /// @notice Function to mint a token.
+ /// @param data Array of pairs of token owner and token's properties for minted token
+ /// @dev EVM selector for this function is: 0xab427b0c,
+ /// or in textual repr: mintBulkCross(((address,uint256),(string,bytes)[])[])
+ function mintBulkCross(MintTokenData[] memory data) external returns (bool);
+
// /// @notice Function to mint multiple tokens with the given tokenUris.
// /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
// /// numbers and first number should be obtained with `nextTokenId` method
@@ -705,6 +711,14 @@
string uri;
}
+/// Token minting parameters
+struct MintTokenData {
+ /// Minted token owner
+ CrossAddress owner;
+ /// Minted token properties
+ Property[] properties;
+}
+
/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// @dev the ERC-165 identifier for this interface is 0x780e9d63
tests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -551,7 +551,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x95c0f66c
+/// @dev the ERC-165 identifier for this interface is 0x4abaabdb
interface ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -668,6 +668,12 @@
// /// or in textual repr: mintBulk(address,uint256[])
// function mintBulk(address to, uint256[] memory tokenIds) external returns (bool);
+ /// @notice Function to mint a token.
+ /// @param tokenProperties Properties of minted token
+ /// @dev EVM selector for this function is: 0xdf7a5db7,
+ /// or in textual repr: mintBulkCross((((address,uint256),uint128)[],(string,bytes)[])[])
+ function mintBulkCross(MintTokenData[] memory tokenProperties) external returns (bool);
+
// /// @notice Function to mint multiple tokens with the given tokenUris.
// /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
// /// numbers and first number should be obtained with `nextTokenId` method
@@ -706,6 +712,22 @@
string uri;
}
+/// Token minting parameters
+struct MintTokenData {
+ /// Minted token owner and number of pieces
+ OwnerPieces[] owners;
+ /// Minted token properties
+ Property[] properties;
+}
+
+/// Token minting parameters
+struct OwnerPieces {
+ /// Minted token owner
+ CrossAddress owner;
+ /// Number of token pieces
+ uint128 pieces;
+}
+
/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// @dev the ERC-165 identifier for this interface is 0x780e9d63
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -18,6 +18,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
import {ITokenPropertyPermission} from '../util/playgrounds/types';
+import {CREATE_COLLECTION_DATA_DEFAULTS, CollectionMode, CreateCollectionData, TokenPermissionField} from './util/playgrounds/types';
describe('Check ERC721 token URI for NFT', () => {
let donor: IKeyringPair;
@@ -197,6 +198,96 @@
}
});
+ itEth('Can perform mintBulkCross()', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const callerCross = helper.ethCrossAccount.fromAddress(caller);
+ const receiver = helper.eth.createAccount();
+ const receiverCross = helper.ethCrossAccount.fromAddress(receiver);
+
+ const permissions = [
+ {code: TokenPermissionField.Mutable, value: true},
+ {code: TokenPermissionField.TokenOwner, value: true},
+ {code: TokenPermissionField.CollectionAdmin, value: true},
+ ];
+ const {collectionAddress} = await helper.eth.createCollection(
+ caller,
+ {
+ ...CREATE_COLLECTION_DATA_DEFAULTS,
+ name: 'A',
+ description: 'B',
+ tokenPrefix: 'C',
+ collectionMode: 'nft',
+ adminList: [callerCross],
+ tokenPropertyPermissions: [
+ {key: 'key_0_0', permissions},
+ {key: 'key_1_0', permissions},
+ {key: 'key_1_1', permissions},
+ {key: 'key_2_0', permissions},
+ {key: 'key_2_1', permissions},
+ {key: 'key_2_2', permissions},
+ ],
+ },
+ ).send();
+
+ const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);
+ {
+ const nextTokenId = await contract.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ const result = await contract.methods.mintBulkCross([
+ {
+ owner: receiverCross,
+ properties: [
+ {key: 'key_0_0', value: Buffer.from('value_0_0')},
+ ],
+ },
+ {
+ owner: receiverCross,
+ properties: [
+ {key: 'key_1_0', value: Buffer.from('value_1_0')},
+ {key: 'key_1_1', value: Buffer.from('value_1_1')},
+ ],
+ },
+ {
+ owner: receiverCross,
+ properties: [
+ {key: 'key_2_0', value: Buffer.from('value_2_0')},
+ {key: 'key_2_1', value: Buffer.from('value_2_1')},
+ {key: 'key_2_2', value: Buffer.from('value_2_2')},
+ ],
+ },
+ ]).send({from: caller});
+ const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);
+ const bulkSize = 3;
+ for(let i = 0; i < bulkSize; i++) {
+ const event = events[i];
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receiver);
+ expect(event.returnValues.tokenId).to.equal(`${+nextTokenId + i}`);
+ }
+
+ const properties = [
+ await contract.methods.properties(+nextTokenId, []).call(),
+ await contract.methods.properties(+nextTokenId + 1, []).call(),
+ await contract.methods.properties(+nextTokenId + 2, []).call(),
+ ];
+ expect(properties).to.be.deep.equal([
+ [
+ ['key_0_0', helper.getWeb3().utils.toHex('value_0_0')],
+ ],
+ [
+ ['key_1_0', helper.getWeb3().utils.toHex('value_1_0')],
+ ['key_1_1', helper.getWeb3().utils.toHex('value_1_1')],
+ ],
+ [
+ ['key_2_0', helper.getWeb3().utils.toHex('value_2_0')],
+ ['key_2_1', helper.getWeb3().utils.toHex('value_2_1')],
+ ['key_2_2', helper.getWeb3().utils.toHex('value_2_2')],
+ ],
+ ]);
+ }
+ });
+
itEth('Can perform burn()', async ({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -18,6 +18,7 @@
import {expect, itEth, usingEthPlaygrounds} from './util';
import {IKeyringPair} from '@polkadot/types/types';
import {ITokenPropertyPermission} from '../util/playgrounds/types';
+import {CREATE_COLLECTION_DATA_DEFAULTS, TokenPermissionField} from './util/playgrounds/types';
describe('Refungible: Plain calls', () => {
let donor: IKeyringPair;
@@ -125,6 +126,169 @@
}
});
+ itEth('Can perform mintBulkCross() with multiple tokens', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const callerCross = helper.ethCrossAccount.fromAddress(caller);
+ const receiver = helper.eth.createAccount();
+ const receiverCross = helper.ethCrossAccount.fromAddress(receiver);
+
+ const permissions = [
+ {code: TokenPermissionField.Mutable, value: true},
+ {code: TokenPermissionField.TokenOwner, value: true},
+ {code: TokenPermissionField.CollectionAdmin, value: true},
+ ];
+ const {collectionAddress} = await helper.eth.createCollection(
+ caller,
+ {
+ ...CREATE_COLLECTION_DATA_DEFAULTS,
+ name: 'A',
+ description: 'B',
+ tokenPrefix: 'C',
+ collectionMode: 'rft',
+ adminList: [callerCross],
+ tokenPropertyPermissions: [
+ {key: 'key_0_0', permissions},
+ {key: 'key_1_0', permissions},
+ {key: 'key_1_1', permissions},
+ {key: 'key_2_0', permissions},
+ {key: 'key_2_1', permissions},
+ {key: 'key_2_2', permissions},
+ ],
+ },
+ ).send();
+
+ const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
+ const nextTokenId = await contract.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ const result = await contract.methods.mintBulkCross([
+ {
+ owners: [{
+ owner: receiverCross,
+ pieces: 1,
+ }],
+ properties: [
+ {key: 'key_0_0', value: Buffer.from('value_0_0')},
+ ],
+ },
+ {
+ owners: [{
+ owner: receiverCross,
+ pieces: 2,
+ }],
+ properties: [
+ {key: 'key_1_0', value: Buffer.from('value_1_0')},
+ {key: 'key_1_1', value: Buffer.from('value_1_1')},
+ ],
+ },
+ {
+ owners: [{
+ owner: receiverCross,
+ pieces: 1,
+ }],
+ properties: [
+ {key: 'key_2_0', value: Buffer.from('value_2_0')},
+ {key: 'key_2_1', value: Buffer.from('value_2_1')},
+ {key: 'key_2_2', value: Buffer.from('value_2_2')},
+ ],
+ },
+ ]).send({from: caller});
+ const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);
+ const bulkSize = 3;
+ for(let i = 0; i < bulkSize; i++) {
+ const event = events[i];
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receiver);
+ expect(event.returnValues.tokenId).to.equal(`${+nextTokenId + i}`);
+ }
+
+ const properties = [
+ await contract.methods.properties(+nextTokenId, []).call(),
+ await contract.methods.properties(+nextTokenId + 1, []).call(),
+ await contract.methods.properties(+nextTokenId + 2, []).call(),
+ ];
+ expect(properties).to.be.deep.equal([
+ [
+ ['key_0_0', helper.getWeb3().utils.toHex('value_0_0')],
+ ],
+ [
+ ['key_1_0', helper.getWeb3().utils.toHex('value_1_0')],
+ ['key_1_1', helper.getWeb3().utils.toHex('value_1_1')],
+ ],
+ [
+ ['key_2_0', helper.getWeb3().utils.toHex('value_2_0')],
+ ['key_2_1', helper.getWeb3().utils.toHex('value_2_1')],
+ ['key_2_2', helper.getWeb3().utils.toHex('value_2_2')],
+ ],
+ ]);
+ });
+
+ itEth('Can perform mintBulkCross() with multiple owners', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const callerCross = helper.ethCrossAccount.fromAddress(caller);
+ const receiver = helper.eth.createAccount();
+ const receiverCross = helper.ethCrossAccount.fromAddress(receiver);
+ const receiver2 = helper.eth.createAccount();
+ const receiver2Cross = helper.ethCrossAccount.fromAddress(receiver2);
+
+ const permissions = [
+ {code: TokenPermissionField.Mutable, value: true},
+ {code: TokenPermissionField.TokenOwner, value: true},
+ {code: TokenPermissionField.CollectionAdmin, value: true},
+ ];
+ const {collectionAddress} = await helper.eth.createCollection(
+ caller,
+ {
+ ...CREATE_COLLECTION_DATA_DEFAULTS,
+ name: 'A',
+ description: 'B',
+ tokenPrefix: 'C',
+ collectionMode: 'rft',
+ adminList: [callerCross],
+ tokenPropertyPermissions: [
+ {key: 'key_2_0', permissions},
+ {key: 'key_2_1', permissions},
+ {key: 'key_2_2', permissions},
+ ],
+ },
+ ).send();
+
+ const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
+ const nextTokenId = await contract.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ const result = await contract.methods.mintBulkCross([{
+ owners: [
+ {
+ owner: receiverCross,
+ pieces: 1,
+ },
+ {
+ owner: receiver2Cross,
+ pieces: 2,
+ },
+ ],
+ properties: [
+ {key: 'key_2_0', value: Buffer.from('value_2_0')},
+ {key: 'key_2_1', value: Buffer.from('value_2_1')},
+ {key: 'key_2_2', value: Buffer.from('value_2_2')},
+ ],
+ }]).send({from: caller});
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
+ expect(event.returnValues.tokenId).to.equal(`${+nextTokenId}`);
+
+ const properties = [
+ await contract.methods.properties(+nextTokenId, []).call(),
+ ];
+ expect(properties).to.be.deep.equal([[
+ ['key_2_0', helper.getWeb3().utils.toHex('value_2_0')],
+ ['key_2_1', helper.getWeb3().utils.toHex('value_2_1')],
+ ['key_2_2', helper.getWeb3().utils.toHex('value_2_2')],
+ ]]);
+ });
+
itEth('Can perform setApprovalForAll()', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const operator = helper.eth.createAccount();
@@ -786,4 +950,70 @@
await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;
});
+
+ itEth('[negative] Can perform mintBulkCross() with multiple owners and multiple tokens', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const callerCross = helper.ethCrossAccount.fromAddress(caller);
+ const receiver = helper.eth.createAccount();
+ const receiverCross = helper.ethCrossAccount.fromAddress(receiver);
+ const receiver2 = helper.eth.createAccount();
+ const receiver2Cross = helper.ethCrossAccount.fromAddress(receiver2);
+
+ const permissions = [
+ {code: TokenPermissionField.Mutable, value: true},
+ {code: TokenPermissionField.TokenOwner, value: true},
+ {code: TokenPermissionField.CollectionAdmin, value: true},
+ ];
+ const {collectionAddress} = await helper.eth.createCollection(
+ caller,
+ {
+ ...CREATE_COLLECTION_DATA_DEFAULTS,
+ name: 'A',
+ description: 'B',
+ tokenPrefix: 'C',
+ collectionMode: 'rft',
+ adminList: [callerCross],
+ tokenPropertyPermissions: [
+ {key: 'key_0_0', permissions},
+ {key: 'key_2_0', permissions},
+ {key: 'key_2_1', permissions},
+ {key: 'key_2_2', permissions},
+ ],
+ },
+ ).send();
+
+ const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
+ const nextTokenId = await contract.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ const createData = [
+ {
+ owners: [{
+ owner: receiverCross,
+ pieces: 1,
+ }],
+ properties: [
+ {key: 'key_0_0', value: Buffer.from('value_0_0')},
+ ],
+ },
+ {
+ owners: [
+ {
+ owner: receiverCross,
+ pieces: 1,
+ },
+ {
+ owner: receiver2Cross,
+ pieces: 2,
+ },
+ ],
+ properties: [
+ {key: 'key_2_0', value: Buffer.from('value_2_0')},
+ {key: 'key_2_1', value: Buffer.from('value_2_1')},
+ {key: 'key_2_2', value: Buffer.from('value_2_2')},
+ ],
+ },
+ ];
+
+ await expect(contract.methods.mintBulkCross(createData).call({from: caller})).to.be.rejectedWith('creation of multiple tokens supported only if they have single owner each');
+ });
});