Skip to content

Commit bbbc213

Browse files
ScreamingHawkacrylix
authored andcommitted
Add royalty to deployment function
1 parent 91e70f4 commit bbbc213

18 files changed

+183
-86
lines changed

src/tokens/ERC1155/ERC1155Token.sol

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,25 @@ error InvalidInitialization();
1414
abstract contract ERC1155Token is ERC1155MintBurn, ERC1155Meta, ERC1155Metadata, ERC2981Controlled {
1515
bytes32 public constant METADATA_ADMIN_ROLE = keccak256("METADATA_ADMIN_ROLE");
1616

17-
address private immutable _initializer;
18-
bool private _initialized;
19-
2017
/**
21-
* Initialize contract.
18+
* Deploy contract.
2219
*/
23-
constructor() ERC1155Metadata("", "") {
24-
_initializer = msg.sender;
25-
}
20+
constructor() ERC1155Metadata("", "") {}
2621

2722
/**
2823
* Initialize the contract.
2924
* @param owner Owner address.
3025
* @param tokenName Token name.
3126
* @param tokenBaseURI Base URI for token metadata.
3227
* @dev This should be called immediately after deployment.
33-
3428
*/
35-
function initialize(address owner, string memory tokenName, string memory tokenBaseURI) public virtual {
36-
if (msg.sender != _initializer || _initialized) {
37-
revert InvalidInitialization();
38-
}
39-
29+
function _initialize(address owner, string memory tokenName, string memory tokenBaseURI) internal {
4030
name = tokenName;
4131
baseURI = tokenBaseURI;
4232

4333
_setupRole(DEFAULT_ADMIN_ROLE, owner);
4434
_setupRole(ROYALTY_ADMIN_ROLE, owner);
4535
_setupRole(METADATA_ADMIN_ROLE, owner);
46-
47-
_initialized = true;
4836
}
4937

5038
//
@@ -84,7 +72,6 @@ abstract contract ERC1155Token is ERC1155MintBurn, ERC1155Meta, ERC1155Metadata,
8472
returns (bool)
8573
{
8674
return ERC1155.supportsInterface(interfaceId) || ERC1155Metadata.supportsInterface(interfaceId)
87-
|| ERC2981Controlled.supportsInterface(interfaceId)
88-
|| super.supportsInterface(interfaceId);
75+
|| ERC2981Controlled.supportsInterface(interfaceId) || super.supportsInterface(interfaceId);
8976
}
9077
}

src/tokens/ERC1155/presets/minter/ERC1155TokenMinter.sol

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,29 @@ contract ERC1155TokenMinter is ERC1155MintBurn, ERC1155Token, IERC1155TokenMinte
2121

2222
/**
2323
* Initialize the contract.
24-
* @param owner Owner address.
25-
* @param tokenName Token name.
26-
* @param tokenBaseURI Base URI for token metadata.
24+
* @param owner Owner address
25+
* @param tokenName Token name
26+
* @param tokenBaseURI Base URI for token metadata
27+
* @param royaltyReceiver Address of who should be sent the royalty payment
28+
* @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500)
2729
* @dev This should be called immediately after deployment.
2830
*/
29-
function initialize(address owner, string memory tokenName, string memory tokenBaseURI) public virtual override {
31+
function initialize(
32+
address owner,
33+
string memory tokenName,
34+
string memory tokenBaseURI,
35+
address royaltyReceiver,
36+
uint96 royaltyFeeNumerator
37+
)
38+
public
39+
virtual
40+
{
3041
if (msg.sender != initializer || initialized) {
3142
revert InvalidInitialization();
3243
}
3344

34-
ERC1155Token.initialize(owner, tokenName, tokenBaseURI);
45+
ERC1155Token._initialize(owner, tokenName, tokenBaseURI);
46+
_setDefaultRoyalty(royaltyReceiver, royaltyFeeNumerator);
3547

3648
_setupRole(MINTER_ROLE, owner);
3749

src/tokens/ERC1155/presets/minter/ERC1155TokenMinterFactory.sol

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,27 @@ contract ERC1155TokenMinterFactory is IERC1155TokenMinterFactory, SequenceProxyF
2525
* @param tokenOwner The owner of the ERC-1155 Token Minter implementation
2626
* @param name The name of the ERC-1155 Token Minter proxy
2727
* @param baseURI The base URI of the ERC-1155 Token Minter proxy
28+
* @param royaltyReceiver Address of who should be sent the royalty payment
29+
* @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500)
2830
* @param salt The deployment salt
2931
* @return proxyAddr The address of the ERC-1155 Token Minter Proxy
3032
* @dev The provided `salt` is hashed with the caller address for security.
31-
* @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-20 Token Minter functions.
33+
* @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-1155 Token Minter functions.
3234
*/
33-
function deploy(address proxyOwner, address tokenOwner, string memory name, string memory baseURI, bytes32 salt)
35+
function deploy(
36+
address proxyOwner,
37+
address tokenOwner,
38+
string memory name,
39+
string memory baseURI,
40+
address royaltyReceiver,
41+
uint96 royaltyFeeNumerator,
42+
bytes32 salt
43+
)
3444
external
3545
returns (address proxyAddr)
3646
{
3747
proxyAddr = _createProxy(salt, proxyOwner, "");
38-
ERC1155TokenMinter(proxyAddr).initialize(tokenOwner, name, baseURI);
48+
ERC1155TokenMinter(proxyAddr).initialize(tokenOwner, name, baseURI, royaltyReceiver, royaltyFeeNumerator);
3949
emit ERC1155TokenMinterDeployed(proxyAddr);
4050
return proxyAddr;
4151
}

src/tokens/ERC1155/presets/minter/IERC1155TokenMinterFactory.sol

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,22 @@ interface IERC1155TokenMinterFactoryFunctions {
88
* @param tokenOwner The owner of the ERC-1155 Token Minter implementation
99
* @param name The name of the ERC-1155 Token Minter proxy
1010
* @param baseURI The base URI of the ERC-1155 Token Minter proxy
11+
* @param royaltyReceiver Address of who should be sent the royalty payment
12+
* @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500)
1113
* @param salt The deployment salt
1214
* @return proxyAddr The address of the ERC-1155 Token Minter Proxy
1315
* @dev The provided `salt` is hashed with the caller address for security.
14-
* @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-20 Token Minter functions.
16+
* @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-1155 Token Minter functions.
1517
*/
16-
function deploy(address proxyOwner, address tokenOwner, string memory name, string memory baseURI, bytes32 salt)
18+
function deploy(
19+
address proxyOwner,
20+
address tokenOwner,
21+
string memory name,
22+
string memory baseURI,
23+
address royaltyReceiver,
24+
uint96 royaltyFeeNumerator,
25+
bytes32 salt
26+
)
1727
external
1828
returns (address proxyAddr);
1929
}

src/tokens/ERC1155/presets/sale/ERC1155Sale.sol

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
pragma solidity ^0.8.17;
33

44
import {IERC1155Sale} from "@0xsequence/contracts-library/tokens/ERC1155/presets/sale/IERC1155Sale.sol";
5-
import {ERC1155Supply, ERC1155Token} from "@0xsequence/contracts-library/tokens/ERC1155/extensions/supply/ERC1155Supply.sol";
6-
import {WithdrawControlled, AccessControl, SafeERC20, IERC20} from "@0xsequence/contracts-library/tokens/common/WithdrawControlled.sol";
7-
import {MerkleProofSingleUse} from "@0xsequence/contracts-library/tokens/common/MerkleProofSingleUse.sol";
8-
9-
contract ERC1155Sale is
10-
IERC1155Sale,
5+
import {
116
ERC1155Supply,
7+
ERC1155Token
8+
} from "@0xsequence/contracts-library/tokens/ERC1155/extensions/supply/ERC1155Supply.sol";
9+
import {
1210
WithdrawControlled,
13-
MerkleProofSingleUse
14-
{
11+
AccessControl,
12+
SafeERC20,
13+
IERC20
14+
} from "@0xsequence/contracts-library/tokens/common/WithdrawControlled.sol";
15+
import {MerkleProofSingleUse} from "@0xsequence/contracts-library/tokens/common/MerkleProofSingleUse.sol";
16+
17+
contract ERC1155Sale is IERC1155Sale, ERC1155Supply, WithdrawControlled, MerkleProofSingleUse {
1518
bytes32 public constant MINT_ADMIN_ROLE = keccak256("MINT_ADMIN_ROLE");
1619

1720
bytes4 private constant _ERC20_TRANSFERFROM_SELECTOR =
@@ -27,20 +30,30 @@ contract ERC1155Sale is
2730

2831
/**
2932
* Initialize the contract.
30-
* @param owner Owner address.
31-
* @param tokenName Token name.
32-
* @param tokenBaseURI Base URI for token metadata.
33+
* @param owner Owner address
34+
* @param tokenName Token name
35+
* @param tokenBaseURI Base URI for token metadata
36+
* @param royaltyReceiver Address of who should be sent the royalty payment
37+
* @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500)
3338
* @dev This should be called immediately after deployment.
3439
*/
35-
function initialize(address owner, string memory tokenName, string memory tokenBaseURI) public virtual override {
40+
function initialize(
41+
address owner,
42+
string memory tokenName,
43+
string memory tokenBaseURI,
44+
address royaltyReceiver,
45+
uint96 royaltyFeeNumerator
46+
)
47+
public
48+
virtual
49+
{
3650
if (_initialized) {
3751
revert InvalidInitialization();
3852
}
39-
ERC1155Token.initialize(owner, tokenName, tokenBaseURI);
4053

41-
name = tokenName;
42-
baseURI = tokenBaseURI;
43-
_setupRole(DEFAULT_ADMIN_ROLE, owner);
54+
ERC1155Token._initialize(owner, tokenName, tokenBaseURI);
55+
_setDefaultRoyalty(royaltyReceiver, royaltyFeeNumerator);
56+
4457
_setupRole(MINT_ADMIN_ROLE, owner);
4558
_setupRole(WITHDRAW_ROLE, owner);
4659

@@ -64,7 +77,9 @@ contract ERC1155Sale is
6477
* @param _amounts Amounts of tokens to mint.
6578
* @param _proof Merkle proof for allowlist minting.
6679
*/
67-
function _payForActiveMint(uint256[] memory _tokenIds, uint256[] memory _amounts, bytes32[] calldata _proof) private {
80+
function _payForActiveMint(uint256[] memory _tokenIds, uint256[] memory _amounts, bytes32[] calldata _proof)
81+
private
82+
{
6883
uint256 lastTokenId;
6984
uint256 totalCost;
7085
uint256 totalAmount;
@@ -127,7 +142,13 @@ contract ERC1155Sale is
127142
* @dev tokenIds must be sorted ascending without duplicates.
128143
* @dev An empty proof is supplied when no proof is required.
129144
*/
130-
function mint(address to, uint256[] memory tokenIds, uint256[] memory amounts, bytes memory data, bytes32[] calldata proof)
145+
function mint(
146+
address to,
147+
uint256[] memory tokenIds,
148+
uint256[] memory amounts,
149+
bytes memory data,
150+
bytes32[] calldata proof
151+
)
131152
public
132153
payable
133154
{

src/tokens/ERC1155/presets/sale/ERC1155SaleFactory.sol

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,26 @@ contract ERC1155SaleFactory is IERC1155SaleFactory, SequenceProxyFactory {
2424
* @param tokenOwner The owner of the ERC-1155 Sale implementation
2525
* @param name The name of the ERC-1155 Sale token
2626
* @param baseURI The base URI of the ERC-1155 Sale token
27+
* @param royaltyReceiver Address of who should be sent the royalty payment
28+
* @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500)
2729
* @param salt The deployment salt
2830
* @return proxyAddr The address of the ERC-1155 Sale Proxy
29-
* @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-20 Token Minter functions.
31+
* @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-1155 Sale Minter functions.
3032
*/
31-
function deploy(address proxyOwner, address tokenOwner, string memory name, string memory baseURI, bytes32 salt)
33+
function deploy(
34+
address proxyOwner,
35+
address tokenOwner,
36+
string memory name,
37+
string memory baseURI,
38+
address royaltyReceiver,
39+
uint96 royaltyFeeNumerator,
40+
bytes32 salt
41+
)
3242
external
3343
returns (address proxyAddr)
3444
{
3545
proxyAddr = _createProxy(salt, proxyOwner, "");
36-
ERC1155Sale(proxyAddr).initialize(tokenOwner, name, baseURI);
46+
ERC1155Sale(proxyAddr).initialize(tokenOwner, name, baseURI, royaltyReceiver, royaltyFeeNumerator);
3747
emit ERC1155SaleDeployed(proxyAddr);
3848
return proxyAddr;
3949
}

src/tokens/ERC1155/presets/sale/IERC1155SaleFactory.sol

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@ interface IERC1155SaleFactoryFunctions {
88
* @param tokenOwner The owner of the ERC-1155 Sale implementation
99
* @param name The name of the ERC-1155 Sale token
1010
* @param baseURI The base URI of the ERC-1155 Sale token
11+
* @param royaltyReceiver Address of who should be sent the royalty payment
12+
* @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500)
1113
* @param salt The deployment salt
1214
* @return proxyAddr The address of the ERC-1155 Sale Proxy
13-
* @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-20 Token Minter functions.
15+
* @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-1155 Token Sale functions.
1416
*/
15-
function deploy(address proxyOwner, address tokenOwner, string memory name, string memory baseURI, bytes32 salt)
17+
function deploy(
18+
address proxyOwner,
19+
address tokenOwner,
20+
string memory name,
21+
string memory baseURI,
22+
address royaltyReceiver,
23+
uint96 royaltyFeeNumerator,
24+
bytes32 salt
25+
)
1626
external
1727
returns (address proxyAddr);
1828
}

src/tokens/ERC721/ERC721Token.sol

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,10 @@ abstract contract ERC721Token is ERC721AQueryable, ERC2981Controlled {
1818
string internal _tokenName;
1919
string internal _tokenSymbol;
2020

21-
address private immutable _initializer;
22-
bool private _initialized;
23-
2421
/**
2522
* Deploy contract.
2623
*/
27-
constructor() ERC721A("", "") {
28-
_initializer = msg.sender;
29-
}
24+
constructor() ERC721A("", "") {}
3025

3126
/**
3227
* Initialize contract.
@@ -36,20 +31,16 @@ abstract contract ERC721Token is ERC721AQueryable, ERC2981Controlled {
3631
* @param tokenBaseURI Base URI of the token
3732
* @dev This should be called immediately after deployment.
3833
*/
39-
function initialize(address owner, string memory tokenName, string memory tokenSymbol, string memory tokenBaseURI) public virtual {
40-
if (msg.sender != _initializer || _initialized) {
41-
revert InvalidInitialization();
42-
}
43-
34+
function _initialize(address owner, string memory tokenName, string memory tokenSymbol, string memory tokenBaseURI)
35+
internal
36+
{
4437
_tokenName = tokenName;
4538
_tokenSymbol = tokenSymbol;
4639
_tokenBaseURI = tokenBaseURI;
4740

4841
_setupRole(DEFAULT_ADMIN_ROLE, owner);
4942
_setupRole(METADATA_ADMIN_ROLE, owner);
5043
_setupRole(ROYALTY_ADMIN_ROLE, owner);
51-
52-
_initialized = true;
5344
}
5445

5546
//

src/tokens/ERC721/presets/minter/ERC721TokenMinter.sol

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,27 @@ contract ERC721TokenMinter is ERC721Token, IERC721TokenMinter {
2626
* @param tokenName Name of the token
2727
* @param tokenSymbol Symbol of the token
2828
* @param tokenBaseURI Base URI of the token
29+
* @param royaltyReceiver Address of who should be sent the royalty payment
30+
* @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500)
2931
* @dev This should be called immediately after deployment.
3032
*/
31-
function initialize(address owner, string memory tokenName, string memory tokenSymbol, string memory tokenBaseURI)
33+
function initialize(
34+
address owner,
35+
string memory tokenName,
36+
string memory tokenSymbol,
37+
string memory tokenBaseURI,
38+
address royaltyReceiver,
39+
uint96 royaltyFeeNumerator
40+
)
3241
public
3342
virtual
34-
override
3543
{
3644
if (msg.sender != _initializer || _initialized) {
3745
revert InvalidInitialization();
3846
}
3947

40-
ERC721Token.initialize(owner, tokenName, tokenSymbol, tokenBaseURI);
48+
ERC721Token._initialize(owner, tokenName, tokenSymbol, tokenBaseURI);
49+
_setDefaultRoyalty(royaltyReceiver, royaltyFeeNumerator);
4150

4251
_setupRole(MINTER_ROLE, owner);
4352

@@ -66,7 +75,10 @@ contract ERC721TokenMinter is ERC721Token, IERC721TokenMinter {
6675
* @param tokenName Name of token.
6776
* @param tokenSymbol Symbol of token.
6877
*/
69-
function setNameAndSymbol(string memory tokenName, string memory tokenSymbol) external onlyRole(METADATA_ADMIN_ROLE) {
78+
function setNameAndSymbol(string memory tokenName, string memory tokenSymbol)
79+
external
80+
onlyRole(METADATA_ADMIN_ROLE)
81+
{
7082
_tokenName = tokenName;
7183
_tokenSymbol = tokenSymbol;
7284
}

0 commit comments

Comments
 (0)