1+ // SPDX-License-Identifier: SEE LICENSE IN LICENSE
2+ pragma solidity ^ 0.8.28 ;
3+
4+ import {Script, console2} from "forge-std/Script.sol " ;
5+ import {EIP712} from "lib/openzeppelin-contracts/contracts/utils/cryptography/EIP712.sol " ;
6+ import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol " ;
7+
8+ abstract contract CodeConstants is Script {
9+ string constant DOMAIN = "moshpit " ;
10+ string constant VERSION = "1 " ;
11+
12+ struct NFTVoucher {
13+ uint256 tokenId;
14+ uint256 price;
15+ uint256 quantity;
16+ uint256 buyerQty;
17+ uint256 start;
18+ uint256 end;
19+ uint96 royalty;
20+ bool isStealth;
21+ bool isSbt;
22+ bytes creator; // signature 1
23+ bytes validator; // signature 2
24+ }
25+
26+ address user1 = makeAddr ("user1 " );
27+ address user2 = makeAddr ("user2 " );
28+ address user3 = makeAddr ("user3 " );
29+ }
30+
31+ contract creationsVoucher is Script , CodeConstants {
32+
33+ function generateVoucher (uint256 collectionIndex ,uint256 tokenIndex ,uint256 price ,uint256 quantity ,uint256 buyerQty ,uint256 start ,uint256 end ,uint96 royalty ,bool isStealth ,bool isSbt ,address creator ) public pure returns (NFTVoucher memory nftVoucher ){
34+ uint256 tkID = generateTokenId (creator,collectionIndex,tokenIndex,quantity);
35+ nftVoucher = NFTVoucher ({
36+ tokenId:tkID,
37+ price:price,
38+ quantity:quantity,
39+ buyerQty:buyerQty,
40+ start:start,
41+ end:end,
42+ royalty:royalty,
43+ isStealth:isStealth,
44+ isSbt:isSbt,
45+ creator: hex "" ,
46+ validator:hex ""
47+ });
48+ }
49+
50+ function generateTokenId (address creator ,uint256 collectionIndex ,uint256 tokenIndex ,uint256 tokenQty ) internal pure returns (uint256 ){
51+
52+ // uint256 collectionIndexSize = 10; // in hex
53+ // uint256 tokenIndexSize = 10;
54+ // uint256 tokenQtySize = 4;
55+
56+ // one hex = 4 bits
57+ // total bits = 10*4 + 10*4 + 4*4 = 40+40+16 = 80+16 = 96 bits
58+ // with address = 160 + 96 = 256
59+
60+ uint256 tokenId = uint256 (uint160 (creator));
61+ tokenId = (tokenId << 40 ) + collectionIndex;
62+ tokenId = (tokenId << 40 ) + tokenIndex;
63+ tokenId = (tokenId << 16 ) + tokenQty;
64+
65+ return tokenId;
66+
67+ }
68+
69+ function generateEIP712SignedVoucher (NFTVoucher memory voucher ) public returns (NFTVoucher memory ,bytes32 voucherHash ) {
70+ // STEP 1 : Generate a EIP712 compliant voucher hash.
71+ // STEP 2 : Generate a Signature from the creator.
72+ // STEP 3 : Generate a Signature from the Admin
73+
74+ // For step on Import the EIP712 sol
75+
76+ }
77+ }
0 commit comments