From 0cccc7bdbc8824f94185f1f456f8c67fec6f0c67 Mon Sep 17 00:00:00 2001 From: harshit-bitpack Date: Tue, 27 Feb 2024 15:33:45 +0530 Subject: [PATCH] bulk mint and updateURI added --- contracts/AppNFTUpgradeable.sol | 12 +++++------ contracts/AppStoreNFTUpgradeable.sol | 31 ++++++++++++++++++++++++++++ contracts/DevNFTUpgradeable.sol | 31 ++++++++++++++++++++++++++++ scripts/upgradeDevProxy.js | 1 + 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/contracts/AppNFTUpgradeable.sol b/contracts/AppNFTUpgradeable.sol index e24eb96..dc9a7e5 100644 --- a/contracts/AppNFTUpgradeable.sol +++ b/contracts/AppNFTUpgradeable.sol @@ -433,15 +433,15 @@ contract AppNFTUpgradeable is Initializable, ERC721Upgradeable, ERC721Enumerable /** * @dev Mint multiple NFTs and assign them to a specified address. * @param to The address to assign the minted NFTs to. - * @param appNames An array of app names to use for the NFTs. + * @param names An array of names to use for the NFTs. * @param uris An array of URIs to use for the NFTs. */ - function bulkMintAndURIupdate(address[] calldata to, uint256[] calldata tokenIds, string[] calldata appNames, string[] calldata uris) external onlyOwner { - uint256 quantity = appNames.length; - require(quantity == uris.length, "appNames and uris length mismatch"); - for (uint256 i = 0; i < appNames.length; i++) { + function bulkMintAndURIupdate(address[] calldata to, uint256[] calldata tokenIds, string[] calldata names, string[] calldata uris) external onlyOwner { + uint256 quantity = tokenIds.length; + require(quantity == uris.length, "tokenIds and uris length mismatch"); + for (uint256 i = 0; i < tokenIds.length; i++) { if(tokenIds[i] == 0){ - mint(to[i], uris[i], appNames[i]); + mint(to[i], uris[i], names[i]); } else { _setTokenURI(tokenIds[i], uris[i]); } diff --git a/contracts/AppStoreNFTUpgradeable.sol b/contracts/AppStoreNFTUpgradeable.sol index 94ce8c9..00bc4db 100644 --- a/contracts/AppStoreNFTUpgradeable.sol +++ b/contracts/AppStoreNFTUpgradeable.sol @@ -428,6 +428,37 @@ contract AppStoreNFTUpgradeable is Initializable, ERC721Upgradeable, ERC721Enume require(_to.send(amount), 'Fee Transfer to Owner failed.'); } + /** + * @dev Mint multiple NFTs and assign them to a specified address. + * @param to The address to assign the minted NFTs to. + * @param names An array of names to use for the NFTs. + * @param uris An array of URIs to use for the NFTs. + */ + function bulkMintAndURIupdate(address[] calldata to, uint256[] calldata tokenIds, string[] calldata names, string[] calldata uris) external onlyOwner { + uint256 quantity = tokenIds.length; + require(quantity == uris.length, "tokenIds and uris length mismatch"); + for (uint256 i = 0; i < tokenIds.length; i++) { + if(tokenIds[i] == 0){ + mint(to[i], uris[i], names[i]); + } else { + _setTokenURI(tokenIds[i], uris[i]); + } + } + } + + /** + * @dev Transfer multiple NFTs from one address to another. + * @param to The address to transfer the NFTs to. + * @param tokenIds An array of token IDs to transfer. + */ + function bulkTransfer(address to, uint256[] calldata tokenIds) external { + for (uint256 i = 0; i < tokenIds.length; i++) { + uint256 tokenId = tokenIds[i]; + require(_isApprovedOrOwner(_msgSender(), tokenId), "Caller is not owner nor approved"); + _transfer(_msgSender(), to, tokenId); + } + } + /** * @notice function to set trusted forwarder * @dev only owner can call this function diff --git a/contracts/DevNFTUpgradeable.sol b/contracts/DevNFTUpgradeable.sol index 38d17e8..00a0374 100644 --- a/contracts/DevNFTUpgradeable.sol +++ b/contracts/DevNFTUpgradeable.sol @@ -268,6 +268,37 @@ contract DevNFTUpgradeable is Initializable, ERC721Upgradeable, ERC721Enumerable require(_to.send(amount), 'Fee Transfer to Owner failed.'); } + /** + * @dev Mint multiple NFTs and assign them to a specified address. + * @param to The address to assign the minted NFTs to. + * @param names An array of names to use for the NFTs. + * @param uris An array of URIs to use for the NFTs. + */ + function bulkMintAndURIupdate(address[] calldata to, uint256[] calldata tokenIds, string[] calldata names, string[] calldata uris) external onlyOwner { + uint256 quantity = tokenIds.length; + require(quantity == uris.length, "tokenIds and uris length mismatch"); + for (uint256 i = 0; i < tokenIds.length; i++) { + if(tokenIds[i] == 0){ + mint(to[i], uris[i], names[i]); + } else { + _setTokenURI(tokenIds[i], uris[i]); + } + } + } + + /** + * @dev Transfer multiple NFTs from one address to another. + * @param to The address to transfer the NFTs to. + * @param tokenIds An array of token IDs to transfer. + */ + function bulkTransfer(address to, uint256[] calldata tokenIds) external { + for (uint256 i = 0; i < tokenIds.length; i++) { + uint256 tokenId = tokenIds[i]; + require(_isApprovedOrOwner(_msgSender(), tokenId), "Caller is not owner nor approved"); + _transfer(_msgSender(), to, tokenId); + } + } + /** * @notice function to set trusted forwarder * @dev only owner can call this function diff --git a/scripts/upgradeDevProxy.js b/scripts/upgradeDevProxy.js index 169db63..c33d9cc 100644 --- a/scripts/upgradeDevProxy.js +++ b/scripts/upgradeDevProxy.js @@ -4,6 +4,7 @@ var file = require("./config.json"); async function main() { const DevNFT = await ethers.getContractFactory("DevNFTUpgradeable"); const devNFT = await upgrades.upgradeProxy(file.DevNFTUpgradeable, DevNFT, [ + file.DappNameList, process.env.TRUSTED_FORWARDER_ADDRESS, ]); console.log("DevNFT upgraded", devNFT);