-
Notifications
You must be signed in to change notification settings - Fork 2
/
Minter.sol
108 lines (94 loc) · 4.45 KB
/
Minter.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import {UniqueNFT, CrossAddress} from "@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol";
import {Property, CollectionLimitValue, CollectionNestingAndPermission} from "@unique-nft/solidity-interfaces/contracts/CollectionHelpers.sol";
import {CollectionMinter, CollectionMode, TokenPropertyPermission} from "../CollectionMinter.sol";
import {TokenMinter, Attribute} from "../TokenMinter.sol";
/**
* @title Minter
* @notice ❗️DISCLAIMER: This contract is provided as an example and is not production-ready.
* It is intended for educational and testing purposes only. Use at your own risk.
*
* @dev Contract for minting collections and tokens in the Unique Schema V2.
* It sets sponsoring for each collection to create a gasless experience for end users.
* Inherits from CollectionMinter and TokenMinter.
* See the example in tests https://github.com/UniqueNetwork/unique-contracts/blob/main/test/minter.spec.ts
*/
contract Minter is CollectionMinter, TokenMinter {
/// @dev track collection owners to restrict minting
mapping(address collection => address owner) private s_collectionOwner;
/// @dev Event emitted when a new collection is created.
event CollectionCreated(address collectionAddress);
modifier onlyCollectionOwner(address _collectionAddress) {
require(msg.sender == s_collectionOwner[_collectionAddress]);
_;
}
/**
* @dev Constructor that sets default property permissions and allows the contract to receive UNQ.
* This contract sponsors every collection and token minting which is why it should have a balance of UNQ
* Sets properties as
* - mutable
* - collectionAdmin has permissions to change properties.
* - token owner has no permissions to change properties
*/
constructor() payable CollectionMinter(true, true, false) {}
receive() external payable {}
/**
* @dev Function to mint a new collection.
* @param _name Name of the collection.
* @param _description Description of the collection.
* @param _symbol Symbol prefix for the tokens in the collection.
* @param _collectionCover URL of the cover image for the collection.
* @param _owner Owner of the collection
* @return Address of the created collection.
*/
function mintCollection(
string memory _name,
string memory _description,
string memory _symbol,
string memory _collectionCover,
CollectionNestingAndPermission memory nesting_settings,
CrossAddress memory _owner
) external payable returns (address) {
address collectionAddress = _createCollection(
_name,
_description,
_symbol,
_collectionCover,
nesting_settings,
new CollectionLimitValue[](0),
new Property[](0),
new TokenPropertyPermission[](0)
);
UniqueNFT collection = UniqueNFT(collectionAddress);
// Set collection sponsorship to the contract address
collection.setCollectionSponsorCross(CrossAddress({eth: address(this), sub: 0}));
// Confirm the collection sponsorship
collection.confirmCollectionSponsorship();
// Sponsor every transaction
// Set this contract as an admin
// Because the minted collection will be owned by the user this contract
// has to be set as a collection admin in order to be able to mint NFTs
collection.addCollectionAdminCross(CrossAddress({eth: address(this), sub: 0}));
// Transfer ownership of the collection to the contract caller
collection.changeCollectionOwnerCross(_owner);
s_collectionOwner[collectionAddress] = msg.sender;
emit CollectionCreated(collectionAddress);
return collectionAddress;
}
/**
* @dev Function to mint a new token within a collection.
* @param _collectionAddress Address of the collection in which to mint the token. The contract should be an admin for the collection
* @param _image URL of the token image.
* @param _attributes Array of attributes for the token.
* @param _tokenOwner Owner of the token
*/
function mintToken(
address _collectionAddress,
string memory _image,
Attribute[] memory _attributes,
CrossAddress memory _tokenOwner
) external onlyCollectionOwner(_collectionAddress) {
_createToken(_collectionAddress, _image, _attributes, _tokenOwner);
}
}