Skip to content

Commit fd7539c

Browse files
committed
merge two minting function into one
1 parent 5b91b43 commit fd7539c

File tree

3 files changed

+16
-105
lines changed

3 files changed

+16
-105
lines changed

src/IPNFT.sol

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -103,37 +103,17 @@ contract IPNFT is ERC721URIStorageUpgradeable, ERC721BurnableUpgradeable, IReser
103103
}
104104

105105
/**
106-
* @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.
106+
* @notice mints an IPNFT with `tokenURI` as source of metadata.
107+
* Minting the IPNFT can happen either with a reservation id or poi hash (Proof of Idea).
108+
* if the tokenId is a reservationId then it invalidates the reservation.
107109
* @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.
108110
*
109111
* @param to the recipient of the NFT
110-
* @param poi the hash of the poi that will be computed to the tokenId
111-
* @param _tokenURI a location that resolves to a valid IP-NFT metadata structure
112-
* @param _symbol a symbol that represents the IPNFT's derivatives. Can be changed by the owner
113-
* @param authorization a bytes encoded parameter that ensures that the poi is owned by the owner (to param)
114-
* @return computedTokenId
115-
*/
116-
function mintWithPOI(address to, bytes32 poi, string calldata _tokenURI, string calldata _symbol, bytes calldata authorization)
117-
external
118-
payable
119-
whenNotPaused
120-
returns (uint256)
121-
{
122-
uint256 computedTokenId = uint256(poi);
123-
_handleMint(to, computedTokenId, _tokenURI, _symbol, authorization);
124-
return computedTokenId;
125-
}
126-
127-
/**
128-
* @notice mints an IPNFT with `tokenURI` as source of metadata. Invalidates the reservation. Redeems `mintpassId` on the authorizer contract
129-
* @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.
130-
*
131-
* @param to the recipient of the NFT
132-
* @param reservationId the reserved token id that has been reserved with `reserve()`
112+
* @param reservationId the reserved token id that has been reserved with `reserve()` / or the poi hash
133113
* @param _tokenURI a location that resolves to a valid IP-NFT metadata structure
134114
* @param _symbol a symbol that represents the IPNFT's derivatives. Can be changed by the owner
135115
* @param authorization a bytes encoded parameter that's handed to the current authorizer
136-
* @return the `reservationId`
116+
* @return the `tokenId`
137117
*/
138118
function mintReservation(address to, uint256 reservationId, string calldata _tokenURI, string calldata _symbol, bytes calldata authorization)
139119
external
@@ -142,31 +122,25 @@ contract IPNFT is ERC721URIStorageUpgradeable, ERC721BurnableUpgradeable, IReser
142122
whenNotPaused
143123
returns (uint256)
144124
{
145-
if (reservations[reservationId] != _msgSender()) {
125+
bool isPoi = reservationId > type(uint128).max;
126+
if (!isPoi && reservations[reservationId] != _msgSender()) {
146127
revert NotOwningReservation(reservationId);
147128
}
148129

149-
150-
_handleMint(to, reservationId, _tokenURI, _symbol, authorization);
151-
delete reservations[reservationId];
152-
return reservationId;
153-
}
154-
155-
function _handleMint(address to, uint256 tokenId, string calldata _tokenURI, string calldata _symbol, bytes calldata authorization) internal {
156130
if (msg.value < SYMBOLIC_MINT_FEE) {
157131
revert MintingFeeTooLow();
158132
}
159133

160-
if (!mintAuthorizer.authorizeMint(_msgSender(), to, abi.encode(SignedMintAuthorization(tokenId, _tokenURI, authorization)))) {
134+
if (!mintAuthorizer.authorizeMint(_msgSender(), to, abi.encode(SignedMintAuthorization(reservationId, _tokenURI, authorization)))) {
161135
revert Unauthorized();
162136
}
163-
164-
symbol[tokenId] = _symbol;
137+
symbol[reservationId] = _symbol;
165138
mintAuthorizer.redeem(authorization);
166139

167-
_mint(to, tokenId);
168-
_setTokenURI(tokenId, _tokenURI);
169-
emit IPNFTMinted(to, tokenId, _tokenURI, _symbol);
140+
_mint(to, reservationId);
141+
_setTokenURI(reservationId, _tokenURI);
142+
emit IPNFTMinted(to, reservationId, _tokenURI, _symbol);
143+
return reservationId;
170144
}
171145

172146
/**

subgraph/abis/IPNFT.json

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -226,45 +226,6 @@
226226
],
227227
"stateMutability": "payable"
228228
},
229-
{
230-
"type": "function",
231-
"name": "mintWithPOI",
232-
"inputs": [
233-
{
234-
"name": "to",
235-
"type": "address",
236-
"internalType": "address"
237-
},
238-
{
239-
"name": "poi",
240-
"type": "bytes",
241-
"internalType": "bytes"
242-
},
243-
{
244-
"name": "_tokenURI",
245-
"type": "string",
246-
"internalType": "string"
247-
},
248-
{
249-
"name": "_symbol",
250-
"type": "string",
251-
"internalType": "string"
252-
},
253-
{
254-
"name": "authorization",
255-
"type": "bytes",
256-
"internalType": "bytes"
257-
}
258-
],
259-
"outputs": [
260-
{
261-
"name": "",
262-
"type": "uint256",
263-
"internalType": "uint256"
264-
}
265-
],
266-
"stateMutability": "payable"
267-
},
268229
{
269230
"type": "function",
270231
"name": "name",
@@ -760,25 +721,6 @@
760721
],
761722
"anonymous": false
762723
},
763-
{
764-
"type": "event",
765-
"name": "IPNFTPOI",
766-
"inputs": [
767-
{
768-
"name": "tokenId",
769-
"type": "uint256",
770-
"indexed": true,
771-
"internalType": "uint256"
772-
},
773-
{
774-
"name": "poi",
775-
"type": "bytes",
776-
"indexed": false,
777-
"internalType": "bytes"
778-
}
779-
],
780-
"anonymous": false
781-
},
782724
{
783725
"type": "event",
784726
"name": "Initialized",

test/IPNFT.t.sol

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,19 @@ contract IPNFTTest is IPNFTMintHelper {
8686

8787
vm.startPrank(alice);
8888
vm.expectRevert(IPNFT.MintingFeeTooLow.selector);
89-
ipnft.mintWithPOI(alice, poiHash, ipfsUri, DEFAULT_SYMBOL, maliciousAuthorization);
89+
ipnft.mintReservation(alice, tokenId, ipfsUri, DEFAULT_SYMBOL, maliciousAuthorization);
9090

9191
vm.expectRevert(IPNFT.Unauthorized.selector);
92-
ipnft.mintWithPOI{ value: MINTING_FEE }(alice, poiHash, ipfsUri, DEFAULT_SYMBOL, maliciousAuthorization);
92+
ipnft.mintReservation{ value: MINTING_FEE }(alice, tokenId, ipfsUri, DEFAULT_SYMBOL, maliciousAuthorization);
9393

9494
(v, r, s) = vm.sign(deployerPk, authMessageHash);
9595
bytes memory authorization = abi.encodePacked(r, s, v);
9696
vm.expectEmit(true, true, false, true);
9797
emit IPNFTMinted(alice, tokenId, ipfsUri, DEFAULT_SYMBOL);
98-
ipnft.mintWithPOI{ value: MINTING_FEE }(
99-
alice, poiHash, ipfsUri, DEFAULT_SYMBOL, authorization
100-
);
98+
ipnft.mintReservation{ value: MINTING_FEE }(alice, tokenId, ipfsUri, DEFAULT_SYMBOL, authorization);
10199
assertEq(ipnft.ownerOf(tokenId), alice);
102100
assertEq(ipnft.tokenURI(tokenId), ipfsUri);
103101
assertEq(ipnft.symbol(tokenId), DEFAULT_SYMBOL);
104-
assertEq(tokenId, 3273451770044532981553402679345217193568252544895634663440128735015952812626);
105102
vm.stopPrank();
106103
}
107104

@@ -134,8 +131,6 @@ contract IPNFTTest is IPNFTMintHelper {
134131
assertEq(ipnft.tokenURI(1), ipfsUri);
135132
assertEq(ipnft.symbol(reservationId), DEFAULT_SYMBOL);
136133

137-
assertEq(ipnft.reservations(1), address(0));
138-
139134
vm.stopPrank();
140135
}
141136

0 commit comments

Comments
 (0)