Skip to content

Commit b9c9510

Browse files
committed
Implemented parity in the ERC1155Initializable contract
1 parent 630047f commit b9c9510

File tree

7 files changed

+106
-19
lines changed

7 files changed

+106
-19
lines changed

src/core/token/ERC1155Core.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {BeforeTransferCallbackERC1155} from "../../callback/BeforeTransferCallba
1919
import {UpdateMetadataCallbackERC1155} from "../../callback/UpdateMetadataCallbackERC1155.sol";
2020

2121
import {OnTokenURICallback} from "../../callback/OnTokenURICallback.sol";
22-
import {console} from "forge-std/console.sol";
2322

2423
contract ERC1155Core is ERC1155, Core, Multicallable, EIP712 {
2524

src/core/token/ERC1155CoreInitializable.sol

Lines changed: 106 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
// SPDX-License-Identifier: Apache-2.0
22
pragma solidity ^0.8.20;
33

4+
import {OwnableRoles} from "@solady/auth/OwnableRoles.sol";
45
import {ERC1155} from "@solady/tokens/ERC1155.sol";
6+
7+
import {ECDSA} from "@solady/utils/ECDSA.sol";
8+
import {EIP712} from "@solady/utils/EIP712.sol";
59
import {Initializable} from "@solady/utils/Initializable.sol";
610
import {Multicallable} from "@solady/utils/Multicallable.sol";
711

812
import {Core} from "../../Core.sol";
13+
import {Role} from "../../Role.sol";
914

1015
import {BeforeApproveForAllCallback} from "../../callback/BeforeApproveForAllCallback.sol";
1116
import {BeforeBatchTransferCallbackERC1155} from "../../callback/BeforeBatchTransferCallbackERC1155.sol";
1217
import {BeforeBurnCallbackERC1155} from "../../callback/BeforeBurnCallbackERC1155.sol";
1318
import {BeforeMintCallbackERC1155} from "../../callback/BeforeMintCallbackERC1155.sol";
19+
import {BeforeMintWithSignatureCallbackERC1155} from "../../callback/BeforeMintWithSignatureCallbackERC1155.sol";
1420
import {BeforeTransferCallbackERC1155} from "../../callback/BeforeTransferCallbackERC1155.sol";
21+
import {UpdateMetadataCallbackERC1155} from "../../callback/UpdateMetadataCallbackERC1155.sol";
1522

1623
import {OnTokenURICallback} from "../../callback/OnTokenURICallback.sol";
1724

18-
contract ERC1155CoreInitializable is ERC1155, Core, Multicallable, Initializable {
25+
contract ERC1155CoreInitializable is ERC1155, Core, Multicallable, Initializable, EIP712 {
26+
27+
using ECDSA for bytes32;
28+
29+
/*//////////////////////////////////////////////////////////////
30+
CONSTANTS
31+
//////////////////////////////////////////////////////////////*/
32+
33+
bytes32 private constant TYPEHASH_SIGNATURE_MINT_ERC1155 =
34+
keccak256("MintRequestERC1155(address to,uint256 tokenId,uint256 value,string baseURI,bytes data)");
1935

2036
/*//////////////////////////////////////////////////////////////
2137
STORAGE
@@ -40,6 +56,12 @@ contract ERC1155CoreInitializable is ERC1155, Core, Multicallable, Initializable
4056
/// @notice Emitted when the contract URI is updated.
4157
event ContractURIUpdated();
4258

59+
/*//////////////////////////////////////////////////////////////
60+
ERRORS
61+
//////////////////////////////////////////////////////////////*/
62+
63+
error SignatureMintUnauthorized();
64+
4365
/*//////////////////////////////////////////////////////////////
4466
CONSTRUCTOR & INITIALIZER
4567
//////////////////////////////////////////////////////////////*/
@@ -128,29 +150,37 @@ contract ERC1155CoreInitializable is ERC1155, Core, Multicallable, Initializable
128150
override
129151
returns (SupportedCallbackFunction[] memory supportedCallbackFunctions)
130152
{
131-
supportedCallbackFunctions = new SupportedCallbackFunction[](6);
153+
supportedCallbackFunctions = new SupportedCallbackFunction[](8);
132154
supportedCallbackFunctions[0] = SupportedCallbackFunction({
133155
selector: BeforeMintCallbackERC1155.beforeMintERC1155.selector,
134156
mode: CallbackMode.REQUIRED
135157
});
136158
supportedCallbackFunctions[1] = SupportedCallbackFunction({
159+
selector: BeforeMintWithSignatureCallbackERC1155.beforeMintWithSignatureERC1155.selector,
160+
mode: CallbackMode.REQUIRED
161+
});
162+
supportedCallbackFunctions[2] = SupportedCallbackFunction({
137163
selector: BeforeTransferCallbackERC1155.beforeTransferERC1155.selector,
138164
mode: CallbackMode.OPTIONAL
139165
});
140-
supportedCallbackFunctions[2] = SupportedCallbackFunction({
166+
supportedCallbackFunctions[3] = SupportedCallbackFunction({
141167
selector: BeforeBatchTransferCallbackERC1155.beforeBatchTransferERC1155.selector,
142168
mode: CallbackMode.OPTIONAL
143169
});
144-
supportedCallbackFunctions[3] = SupportedCallbackFunction({
170+
supportedCallbackFunctions[4] = SupportedCallbackFunction({
145171
selector: BeforeBurnCallbackERC1155.beforeBurnERC1155.selector,
146172
mode: CallbackMode.OPTIONAL
147173
});
148-
supportedCallbackFunctions[4] = SupportedCallbackFunction({
174+
supportedCallbackFunctions[5] = SupportedCallbackFunction({
149175
selector: BeforeApproveForAllCallback.beforeApproveForAll.selector,
150176
mode: CallbackMode.OPTIONAL
151177
});
152-
supportedCallbackFunctions[5] =
178+
supportedCallbackFunctions[6] =
153179
SupportedCallbackFunction({selector: OnTokenURICallback.onTokenURI.selector, mode: CallbackMode.REQUIRED});
180+
supportedCallbackFunctions[7] = SupportedCallbackFunction({
181+
selector: UpdateMetadataCallbackERC1155.updateMetadataERC1155.selector,
182+
mode: CallbackMode.REQUIRED
183+
});
154184
}
155185

156186
/*//////////////////////////////////////////////////////////////
@@ -172,15 +202,57 @@ contract ERC1155CoreInitializable is ERC1155, Core, Multicallable, Initializable
172202
* @param to The address to mint the token to.
173203
* @param tokenId The tokenId to mint.
174204
* @param value The amount of tokens to mint.
205+
* @param baseURI The base URI for the token metadata.
175206
* @param data ABI encoded data to pass to the beforeMint hook.
176207
*/
177-
function mint(address to, uint256 tokenId, uint256 value, bytes memory data) external payable {
208+
function mint(address to, uint256 tokenId, uint256 value, string calldata baseURI, bytes memory data)
209+
external
210+
payable
211+
{
212+
if (bytes(baseURI).length > 0) {
213+
_updateMetadata(to, tokenId, value, baseURI);
214+
}
178215
_beforeMint(to, tokenId, value, data);
179216

180217
_totalSupply[tokenId] += value;
181218
_mint(to, tokenId, value, "");
182219
}
183220

221+
/**
222+
* @notice Mints tokens with a signature. Calls the beforeMintWithSignature hook.
223+
* @dev Reverts if beforeMintWithSignature hook is absent or unsuccessful.
224+
* @param to The address to mint the token to.
225+
* @param tokenId The tokenId to mint.
226+
* @param value The amount of tokens to mint.
227+
* @param baseURI The base URI for the token metadata.
228+
* @param data ABI encoded data to pass to the beforeMintWithSignature hook.
229+
* @param signature The signature produced from signing the minting request.
230+
*/
231+
function mintWithSignature(
232+
address to,
233+
uint256 tokenId,
234+
uint256 value,
235+
string calldata baseURI,
236+
bytes calldata data,
237+
bytes memory signature
238+
) external payable {
239+
address signer = _hashTypedData(
240+
keccak256(abi.encode(TYPEHASH_SIGNATURE_MINT_ERC1155, to, tokenId, value, keccak256(bytes(baseURI)), data))
241+
).recover(signature);
242+
243+
if (!OwnableRoles(address(this)).hasAllRoles(signer, Role._MINTER_ROLE)) {
244+
revert SignatureMintUnauthorized();
245+
}
246+
247+
if (bytes(baseURI).length > 0) {
248+
_updateMetadata(to, tokenId, value, baseURI);
249+
}
250+
_beforeMintWithSignature(to, tokenId, value, data);
251+
252+
_totalSupply[tokenId] += value;
253+
_mint(to, tokenId, value, "");
254+
}
255+
184256
/**
185257
* @notice Burns given amount of tokens.
186258
* @dev Calls the beforeBurn hook. Skips calling the hook if it doesn't exist.
@@ -264,6 +336,19 @@ contract ERC1155CoreInitializable is ERC1155, Core, Multicallable, Initializable
264336
);
265337
}
266338

339+
/// @dev Calls the beforeMintWithSignature hook.
340+
function _beforeMintWithSignature(address to, uint256 tokenId, uint256 value, bytes calldata data)
341+
internal
342+
virtual
343+
{
344+
_executeCallbackFunction(
345+
BeforeMintWithSignatureCallbackERC1155.beforeMintWithSignatureERC1155.selector,
346+
abi.encodeCall(
347+
BeforeMintWithSignatureCallbackERC1155.beforeMintWithSignatureERC1155, (to, tokenId, value, data)
348+
)
349+
);
350+
}
351+
267352
/// @dev Calls the beforeTransfer hook, if installed.
268353
function _beforeTransfer(address from, address to, uint256 tokenId, uint256 value) internal virtual {
269354
_executeCallbackFunction(
@@ -307,4 +392,18 @@ contract ERC1155CoreInitializable is ERC1155, Core, Multicallable, Initializable
307392
tokenUri = abi.decode(returndata, (string));
308393
}
309394

395+
/// @dev Calls the updateMetadata hook, if installed.
396+
function _updateMetadata(address to, uint256 tokenId, uint256 value, string calldata baseURI) internal virtual {
397+
_executeCallbackFunction(
398+
UpdateMetadataCallbackERC1155.updateMetadataERC1155.selector,
399+
abi.encodeCall(UpdateMetadataCallbackERC1155.updateMetadataERC1155, (to, tokenId, value, baseURI))
400+
);
401+
}
402+
403+
/// @dev Returns the domain name and version for EIP712.
404+
function _domainNameAndVersion() internal pure override returns (string memory name, string memory version) {
405+
name = "ERC1155Core";
406+
version = "1";
407+
}
408+
310409
}

src/core/token/ERC721Core.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
pragma solidity ^0.8.20;
33

44
import {ERC721A, ERC721AQueryable, IERC721A} from "@erc721a/extensions/ERC721AQueryable.sol";
5-
import {console} from "forge-std/console.sol";
65

76
import {OwnableRoles} from "@solady/auth/OwnableRoles.sol";
87
import {ECDSA} from "@solady/utils/ECDSA.sol";

src/module/token/metadata/BatchMetadataERC721.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {Role} from "../../../Role.sol";
66

77
import {UpdateMetadataCallbackERC721} from "../../../callback/UpdateMetadataCallbackERC721.sol";
88
import {LibString} from "@solady/utils/LibString.sol";
9-
import {console} from "forge-std/console.sol";
109

1110
library BatchMetadataStorage {
1211

src/module/token/minting/MintableERC721.sol

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
pragma solidity ^0.8.20;
33

44
import {Module} from "../../../Module.sol";
5-
import {console} from "forge-std/console.sol";
65

76
import {Role} from "../../../Role.sol";
87
import {IInstallationCallback} from "../../../interface/IInstallationCallback.sol";
@@ -153,7 +152,6 @@ contract MintableERC721 is
153152
MintRequestERC721 memory _params = abi.decode(_data, (MintRequestERC721));
154153

155154
_mintWithSignatureERC721(_params);
156-
console.log("gets in here");
157155
_distributeMintPrice(msg.sender, _params.currency, _quantity * _params.pricePerUnit);
158156
}
159157

@@ -233,16 +231,13 @@ contract MintableERC721 is
233231
}
234232
return;
235233
}
236-
console.log("passes initial test");
237234

238235
SaleConfig memory saleConfig = _mintableStorage().saleConfig;
239236

240237
if (_currency == NATIVE_TOKEN_ADDRESS) {
241-
console.log("native token detected");
242238
if (msg.value != _price) {
243239
revert MintableIncorrectNativeTokenSent();
244240
}
245-
console.log("shouldn't get here");
246241
SafeTransferLib.safeTransferETH(saleConfig.primarySaleRecipient, _price);
247242
} else {
248243
if (msg.value > 0) {

test/module/minting/ClaimableERC1155.t.sol

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,6 @@ contract ClaimableERC1155Test is Test {
343343

344344
vm.prank(tokenRecipient);
345345
vm.expectRevert(abi.encodeWithSelector(ClaimableERC1155.ClaimableIncorrectNativeTokenSent.selector));
346-
// fails here
347-
console.log("permissionedActorAddress");
348-
console.logAddress(permissionedActor);
349346
core.mintWithSignature{value: (quantity * claimRequest.pricePerUnit)}(
350347
tokenRecipient, tokenId, quantity, baseURI, abi.encode(claimRequest), sig
351348
);

test/module/minting/MintableERC721.t.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import "lib/forge-std/src/console.sol";
66
import {OwnableRoles} from "@solady/auth/OwnableRoles.sol";
77
import {ERC20} from "@solady/tokens/ERC20.sol";
88
import {Test} from "forge-std/Test.sol";
9-
import {console} from "forge-std/console.sol";
109

1110
// Target contract
1211

0 commit comments

Comments
 (0)