Skip to content

Commit

Permalink
merge two minting function into one
Browse files Browse the repository at this point in the history
  • Loading branch information
nour-karoui committed Oct 30, 2024
1 parent 5b91b43 commit fd7539c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 105 deletions.
52 changes: 13 additions & 39 deletions src/IPNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

/**
Expand Down
58 changes: 0 additions & 58 deletions subgraph/abis/IPNFT.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 3 additions & 8 deletions test/IPNFT.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit fd7539c

Please sign in to comment.