From fd7539cac26a826d81797b594df2a4a1248915e2 Mon Sep 17 00:00:00 2001 From: nour-karoui Date: Wed, 30 Oct 2024 16:19:15 +0100 Subject: [PATCH] merge two minting function into one --- src/IPNFT.sol | 52 +++++++++-------------------------- subgraph/abis/IPNFT.json | 58 ---------------------------------------- test/IPNFT.t.sol | 11 +++----- 3 files changed, 16 insertions(+), 105 deletions(-) diff --git a/src/IPNFT.sol b/src/IPNFT.sol index 2f4e4eb3..44845d27 100644 --- a/src/IPNFT.sol +++ b/src/IPNFT.sol @@ -103,37 +103,17 @@ contract IPNFT is ERC721URIStorageUpgradeable, ERC721BurnableUpgradeable, IReser } /** - * @notice mints an IPNFT with `tokenURI` as source of metadata. This IPNFT is linked a proof of idea (POI) which is a hash of any collection of files that represents an idea, anchored on any chain. + * @notice mints an IPNFT with `tokenURI` as source of metadata. + * Minting the IPNFT can happen either with a reservation id or poi hash (Proof of Idea). + * if the tokenId is a reservationId then it invalidates the reservation. * @notice We are charging a nominal fee to symbolically represent the transfer of ownership rights, for a price of .001 ETH (<$2USD at current prices). This helps ensure the protocol is affordable to almost all projects, but discourages frivolous IP-NFT minting. * * @param to the recipient of the NFT - * @param poi the hash of the poi that will be computed to the tokenId - * @param _tokenURI a location that resolves to a valid IP-NFT metadata structure - * @param _symbol a symbol that represents the IPNFT's derivatives. Can be changed by the owner - * @param authorization a bytes encoded parameter that ensures that the poi is owned by the owner (to param) - * @return computedTokenId - */ - function mintWithPOI(address to, bytes32 poi, string calldata _tokenURI, string calldata _symbol, bytes calldata authorization) - external - payable - whenNotPaused - returns (uint256) - { - uint256 computedTokenId = uint256(poi); - _handleMint(to, computedTokenId, _tokenURI, _symbol, authorization); - return computedTokenId; - } - - /** - * @notice mints an IPNFT with `tokenURI` as source of metadata. Invalidates the reservation. Redeems `mintpassId` on the authorizer contract - * @notice We are charging a nominal fee to symbolically represent the transfer of ownership rights, for a price of .001 ETH (<$2USD at current prices). This helps ensure the protocol is affordable to almost all projects, but discourages frivolous IP-NFT minting. - * - * @param to the recipient of the NFT - * @param reservationId the reserved token id that has been reserved with `reserve()` + * @param reservationId the reserved token id that has been reserved with `reserve()` / or the poi hash * @param _tokenURI a location that resolves to a valid IP-NFT metadata structure * @param _symbol a symbol that represents the IPNFT's derivatives. Can be changed by the owner * @param authorization a bytes encoded parameter that's handed to the current authorizer - * @return the `reservationId` + * @return the `tokenId` */ function mintReservation(address to, uint256 reservationId, string calldata _tokenURI, string calldata _symbol, bytes calldata authorization) external @@ -142,31 +122,25 @@ contract IPNFT is ERC721URIStorageUpgradeable, ERC721BurnableUpgradeable, IReser whenNotPaused returns (uint256) { - if (reservations[reservationId] != _msgSender()) { + bool isPoi = reservationId > type(uint128).max; + if (!isPoi && reservations[reservationId] != _msgSender()) { revert NotOwningReservation(reservationId); } - - _handleMint(to, reservationId, _tokenURI, _symbol, authorization); - delete reservations[reservationId]; - return reservationId; - } - - function _handleMint(address to, uint256 tokenId, string calldata _tokenURI, string calldata _symbol, bytes calldata authorization) internal { if (msg.value < SYMBOLIC_MINT_FEE) { revert MintingFeeTooLow(); } - if (!mintAuthorizer.authorizeMint(_msgSender(), to, abi.encode(SignedMintAuthorization(tokenId, _tokenURI, authorization)))) { + if (!mintAuthorizer.authorizeMint(_msgSender(), to, abi.encode(SignedMintAuthorization(reservationId, _tokenURI, authorization)))) { revert Unauthorized(); } - - symbol[tokenId] = _symbol; + symbol[reservationId] = _symbol; mintAuthorizer.redeem(authorization); - _mint(to, tokenId); - _setTokenURI(tokenId, _tokenURI); - emit IPNFTMinted(to, tokenId, _tokenURI, _symbol); + _mint(to, reservationId); + _setTokenURI(reservationId, _tokenURI); + emit IPNFTMinted(to, reservationId, _tokenURI, _symbol); + return reservationId; } /** diff --git a/subgraph/abis/IPNFT.json b/subgraph/abis/IPNFT.json index 2055ed4d..b03fe6f6 100644 --- a/subgraph/abis/IPNFT.json +++ b/subgraph/abis/IPNFT.json @@ -226,45 +226,6 @@ ], "stateMutability": "payable" }, - { - "type": "function", - "name": "mintWithPOI", - "inputs": [ - { - "name": "to", - "type": "address", - "internalType": "address" - }, - { - "name": "poi", - "type": "bytes", - "internalType": "bytes" - }, - { - "name": "_tokenURI", - "type": "string", - "internalType": "string" - }, - { - "name": "_symbol", - "type": "string", - "internalType": "string" - }, - { - "name": "authorization", - "type": "bytes", - "internalType": "bytes" - } - ], - "outputs": [ - { - "name": "", - "type": "uint256", - "internalType": "uint256" - } - ], - "stateMutability": "payable" - }, { "type": "function", "name": "name", @@ -760,25 +721,6 @@ ], "anonymous": false }, - { - "type": "event", - "name": "IPNFTPOI", - "inputs": [ - { - "name": "tokenId", - "type": "uint256", - "indexed": true, - "internalType": "uint256" - }, - { - "name": "poi", - "type": "bytes", - "indexed": false, - "internalType": "bytes" - } - ], - "anonymous": false - }, { "type": "event", "name": "Initialized", diff --git a/test/IPNFT.t.sol b/test/IPNFT.t.sol index d8ee576f..407b9f9f 100644 --- a/test/IPNFT.t.sol +++ b/test/IPNFT.t.sol @@ -86,22 +86,19 @@ contract IPNFTTest is IPNFTMintHelper { vm.startPrank(alice); vm.expectRevert(IPNFT.MintingFeeTooLow.selector); - ipnft.mintWithPOI(alice, poiHash, ipfsUri, DEFAULT_SYMBOL, maliciousAuthorization); + ipnft.mintReservation(alice, tokenId, ipfsUri, DEFAULT_SYMBOL, maliciousAuthorization); vm.expectRevert(IPNFT.Unauthorized.selector); - ipnft.mintWithPOI{ value: MINTING_FEE }(alice, poiHash, ipfsUri, DEFAULT_SYMBOL, maliciousAuthorization); + ipnft.mintReservation{ value: MINTING_FEE }(alice, tokenId, ipfsUri, DEFAULT_SYMBOL, maliciousAuthorization); (v, r, s) = vm.sign(deployerPk, authMessageHash); bytes memory authorization = abi.encodePacked(r, s, v); vm.expectEmit(true, true, false, true); emit IPNFTMinted(alice, tokenId, ipfsUri, DEFAULT_SYMBOL); - ipnft.mintWithPOI{ value: MINTING_FEE }( - alice, poiHash, ipfsUri, DEFAULT_SYMBOL, authorization - ); + ipnft.mintReservation{ value: MINTING_FEE }(alice, tokenId, ipfsUri, DEFAULT_SYMBOL, authorization); assertEq(ipnft.ownerOf(tokenId), alice); assertEq(ipnft.tokenURI(tokenId), ipfsUri); assertEq(ipnft.symbol(tokenId), DEFAULT_SYMBOL); - assertEq(tokenId, 3273451770044532981553402679345217193568252544895634663440128735015952812626); vm.stopPrank(); } @@ -134,8 +131,6 @@ contract IPNFTTest is IPNFTMintHelper { assertEq(ipnft.tokenURI(1), ipfsUri); assertEq(ipnft.symbol(reservationId), DEFAULT_SYMBOL); - assertEq(ipnft.reservations(1), address(0)); - vm.stopPrank(); }