pragmasolidity^0.6.0;import"@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";import"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";import"@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol";import"@openzeppelin/contracts/token/ERC20/IERC20.sol";import"@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";import"../interfaces/INFT20Pair.sol";import"@openzeppelin/contracts/proxy/BeaconProxy.sol";contractNFT20FactoryV3isInitializable,OwnableUpgradeable{usingSafeMathUpgradeableforuint256;// keep track of nft address to pair address
mapping(address=>address)publicnftToToken;mapping(uint256=>address)publicindexToNft;uint256publiccounter;uint256publicfee;eventpairCreated(addressindexedoriginalNFT,addressnewPair,uint256_type);usingAddressUpgradeableforaddress;addresspubliclogic;constructor()public{}functionnft20Pair(stringmemoryname,address_nftOrigin,uint256_nftType)publicpayable{require(nftToToken[_nftOrigin]==address(0));bytesmemoryinitData=abi.encodeWithSignature("init(string,string,address,uint256)",string(abi.encodePacked("NFT20 ",name)),string(abi.encodePacked(name,"20")),_nftOrigin,_nftType);addressinstance=address(newBeaconProxy(logic,""));instance.functionCallWithValue(initData,msg.value);nftToToken[_nftOrigin]=instance;indexToNft[counter]=_nftOrigin;counter=counter+1;emitpairCreated(_nftOrigin,instance,_nftType);}functiongetPairByNftAddress(uint256index)publicviewreturns(address_nft20pair,address_originalNft,uint256_type,stringmemory_name,stringmemory_symbol,uint256_supply){_originalNft=indexToNft[index];_nft20pair=nftToToken[_originalNft];(_type,_name,_symbol,_supply)=INFT20Pair(_nft20pair).getInfos();}// this is to sset value in case we decided to change tokens given to a tokenizing project.
functionsetValue(address_pair,uint256_nftType,stringcalldata_name,stringcalldata_symbol,uint256_value)externalonlyOwner{INFT20Pair(_pair).setParams(_nftType,_name,_symbol,_value);}functionsetFee(uint256_fee)externalonlyOwner{fee=_fee;}functionrecoverERC20(addresstokenAddress,uint256tokenAmount)publiconlyOwner{IERC20(tokenAddress).transfer(owner(),tokenAmount);}functionchangeLogic(address_newLogic)externalonlyOwner{logic=_newLogic;}functionfix()externalonlyOwner{nftToToken[address(0xC2C747E0F7004F9E8817Db2ca4997657a7746928)]=address(0xc2BdE1A2fA26890c8E6AcB10C91CC6D9c11F4a73);counter=counter-1;}}