1// SPDX-License-Identifier: Apache License2pragma solidity >=0.8.0;3import {CollectionHelpers} from "../../eth/api/CollectionHelpers.sol";4import {ContractHelpers} from "../../eth/api/ContractHelpers.sol";5import {UniqueRefungibleToken} from "../../eth/api/UniqueRefungibleToken.sol";6import {UniqueRefungible, Collection, EthCrossAccount as RftCrossAccountId, Tuple20 as RftProperties} from "../../eth/api/UniqueRefungible.sol";7import {UniqueNFT, EthCrossAccount as NftCrossAccountId, Tuple21 as NftProperty, TokenProperties} from "../../eth/api/UniqueNFT.sol";89struct Property {10 string key;11 bytes value;12}1314contract ProxyMint {15 bytes32 constant REFUNGIBLE_COLLECTION_TYPE = keccak256(bytes("ReFungible"));16 bytes32 constant NONFUNGIBLE_COLLECTION_TYPE = keccak256(bytes("NFT"));1718 modifier checkRestrictions(address _collection) {19 Collection commonContract = Collection(_collection);20 require(commonContract.isOwnerOrAdmin(msg.sender), "Only collection admin/owner can call this method");21 _;22 }2324 /// @dev This emits when a mint to a substrate address has been made.25 event MintToSub(address _toEth, uint256 _toSub, address _collection, uint256 _tokenId);2627 function mintToSubstrate(address _collection, uint256 _substrateReceiver) external checkRestrictions(_collection) {28 Collection commonContract = Collection(_collection);29 bytes32 collectionType = keccak256(bytes(commonContract.uniqueCollectionType()));30 uint256 tokenId;3132 if (collectionType == REFUNGIBLE_COLLECTION_TYPE) {33 UniqueRefungible rftCollection = UniqueRefungible(_collection);3435 tokenId = rftCollection.mint(address(this));3637 rftCollection.transferFromCross(38 RftCrossAccountId(address(this), 0),39 RftCrossAccountId(address(0), _substrateReceiver),40 tokenId41 );42 } else if (collectionType == NONFUNGIBLE_COLLECTION_TYPE) {43 UniqueNFT nftCollection = UniqueNFT(_collection);44 tokenId = nftCollection.mint(address(this));4546 nftCollection.transferFromCross(47 NftCrossAccountId(address(this), 0),48 NftCrossAccountId(address(0), _substrateReceiver),49 tokenId50 );51 } else {52 revert("Wrong collection type. Works only with NFT or RFT");53 }5455 emit MintToSub(address(0), _substrateReceiver, _collection, tokenId);56 }5758 function mintToSubstrateWithProperty(59 address _collection,60 uint256 _substrateReceiver,61 Property[] calldata properties62 ) external checkRestrictions(_collection) {63 uint256 propertiesLength = properties.length;64 require(propertiesLength > 0, "Properies is empty");6566 Collection commonContract = Collection(_collection);67 bytes32 collectionType = keccak256(bytes(commonContract.uniqueCollectionType()));68 uint256 tokenId;6970 if (collectionType == REFUNGIBLE_COLLECTION_TYPE) {71 UniqueRefungible rftCollection = UniqueRefungible(_collection);72 tokenId = rftCollection.nextTokenId();73 rftCollection.mint(address(this));74 for (uint256 i = 0; i < propertiesLength; ++i) {75 rftCollection.setProperty(tokenId, properties[i].key, properties[i].value);76 }77 rftCollection.transferFromCross(78 RftCrossAccountId(address(this), 0),79 RftCrossAccountId(address(0), _substrateReceiver),80 tokenId81 );82 } else if (collectionType == NONFUNGIBLE_COLLECTION_TYPE) {83 UniqueNFT nftCollection = UniqueNFT(_collection);84 tokenId = nftCollection.mint(address(this));85 for (uint256 i = 0; i < propertiesLength; ++i) {86 nftCollection.setProperty(tokenId, properties[i].key, properties[i].value);87 }88 nftCollection.transferFromCross(89 NftCrossAccountId(address(this), 0),90 NftCrossAccountId(address(0), _substrateReceiver),91 tokenId92 );93 } else {94 revert("Wrong collection type. Works only with NFT or RFT");95 }9697 emit MintToSub(address(0), _substrateReceiver, _collection, tokenId);98 }99100 function mintToSubstrateBulkProperty(101 address _collection,102 uint256 _substrateReceiver,103 NftProperty[] calldata _properties104 ) external checkRestrictions(_collection) {105 uint256 propertiesLength = _properties.length;106 require(propertiesLength > 0, "Properies is empty");107108 Collection commonContract = Collection(_collection);109 bytes32 collectionType = keccak256(bytes(commonContract.uniqueCollectionType()));110 uint256 tokenId;111112 if (collectionType == REFUNGIBLE_COLLECTION_TYPE) {} else if (collectionType == NONFUNGIBLE_COLLECTION_TYPE) {113 UniqueNFT nftCollection = UniqueNFT(_collection);114 tokenId = nftCollection.mint(address(this));115116 nftCollection.setProperties(tokenId, _properties);117118 nftCollection.transferFromCross(119 NftCrossAccountId(address(this), 0),120 NftCrossAccountId(address(0), _substrateReceiver),121 tokenId122 );123 } else {124 revert("Wrong collection type. Works only with NFT or RFT");125 }126127 emit MintToSub(address(0), _substrateReceiver, _collection, tokenId);128 }129}