From bbbc2134c67b13fdb1006cd017dd2891a948a001 Mon Sep 17 00:00:00 2001 From: Michael Standen Date: Tue, 31 Oct 2023 13:53:03 +1300 Subject: [PATCH] Add royalty to deployment function --- src/tokens/ERC1155/ERC1155Token.sol | 21 ++----- .../presets/minter/ERC1155TokenMinter.sol | 22 +++++-- .../minter/ERC1155TokenMinterFactory.sol | 16 +++++- .../minter/IERC1155TokenMinterFactory.sol | 14 ++++- .../ERC1155/presets/sale/ERC1155Sale.sol | 57 +++++++++++++------ .../presets/sale/ERC1155SaleFactory.sol | 16 +++++- .../presets/sale/IERC1155SaleFactory.sol | 14 ++++- src/tokens/ERC721/ERC721Token.sol | 17 ++---- .../presets/minter/ERC721TokenMinter.sol | 20 +++++-- .../minter/ERC721TokenMinterFactory.sol | 8 ++- .../minter/IERC721TokenMinterFactory.sol | 6 +- src/tokens/ERC721/presets/sale/ERC721Sale.sol | 28 +++++++-- .../ERC721/presets/sale/ERC721SaleFactory.sol | 6 +- .../presets/sale/IERC721SaleFactory.sol | 4 ++ test/tokens/ERC1155/presets/ERC1155Sale.t.sol | 4 +- .../ERC1155/presets/ERC1155TokenMinter.t.sol | 6 +- test/tokens/ERC721/presets/ERC721Sale.t.sol | 4 +- .../ERC721/presets/ERC721TokenMinter.t.sol | 6 +- 18 files changed, 183 insertions(+), 86 deletions(-) diff --git a/src/tokens/ERC1155/ERC1155Token.sol b/src/tokens/ERC1155/ERC1155Token.sol index e409bff..29594a8 100644 --- a/src/tokens/ERC1155/ERC1155Token.sol +++ b/src/tokens/ERC1155/ERC1155Token.sol @@ -14,15 +14,10 @@ error InvalidInitialization(); abstract contract ERC1155Token is ERC1155MintBurn, ERC1155Meta, ERC1155Metadata, ERC2981Controlled { bytes32 public constant METADATA_ADMIN_ROLE = keccak256("METADATA_ADMIN_ROLE"); - address private immutable _initializer; - bool private _initialized; - /** - * Initialize contract. + * Deploy contract. */ - constructor() ERC1155Metadata("", "") { - _initializer = msg.sender; - } + constructor() ERC1155Metadata("", "") {} /** * Initialize the contract. @@ -30,21 +25,14 @@ abstract contract ERC1155Token is ERC1155MintBurn, ERC1155Meta, ERC1155Metadata, * @param tokenName Token name. * @param tokenBaseURI Base URI for token metadata. * @dev This should be called immediately after deployment. - */ - function initialize(address owner, string memory tokenName, string memory tokenBaseURI) public virtual { - if (msg.sender != _initializer || _initialized) { - revert InvalidInitialization(); - } - + function _initialize(address owner, string memory tokenName, string memory tokenBaseURI) internal { name = tokenName; baseURI = tokenBaseURI; _setupRole(DEFAULT_ADMIN_ROLE, owner); _setupRole(ROYALTY_ADMIN_ROLE, owner); _setupRole(METADATA_ADMIN_ROLE, owner); - - _initialized = true; } // @@ -84,7 +72,6 @@ abstract contract ERC1155Token is ERC1155MintBurn, ERC1155Meta, ERC1155Metadata, returns (bool) { return ERC1155.supportsInterface(interfaceId) || ERC1155Metadata.supportsInterface(interfaceId) - || ERC2981Controlled.supportsInterface(interfaceId) - || super.supportsInterface(interfaceId); + || ERC2981Controlled.supportsInterface(interfaceId) || super.supportsInterface(interfaceId); } } diff --git a/src/tokens/ERC1155/presets/minter/ERC1155TokenMinter.sol b/src/tokens/ERC1155/presets/minter/ERC1155TokenMinter.sol index 29a0bb8..4c828d5 100644 --- a/src/tokens/ERC1155/presets/minter/ERC1155TokenMinter.sol +++ b/src/tokens/ERC1155/presets/minter/ERC1155TokenMinter.sol @@ -21,17 +21,29 @@ contract ERC1155TokenMinter is ERC1155MintBurn, ERC1155Token, IERC1155TokenMinte /** * Initialize the contract. - * @param owner Owner address. - * @param tokenName Token name. - * @param tokenBaseURI Base URI for token metadata. + * @param owner Owner address + * @param tokenName Token name + * @param tokenBaseURI Base URI for token metadata + * @param royaltyReceiver Address of who should be sent the royalty payment + * @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500) * @dev This should be called immediately after deployment. */ - function initialize(address owner, string memory tokenName, string memory tokenBaseURI) public virtual override { + function initialize( + address owner, + string memory tokenName, + string memory tokenBaseURI, + address royaltyReceiver, + uint96 royaltyFeeNumerator + ) + public + virtual + { if (msg.sender != initializer || initialized) { revert InvalidInitialization(); } - ERC1155Token.initialize(owner, tokenName, tokenBaseURI); + ERC1155Token._initialize(owner, tokenName, tokenBaseURI); + _setDefaultRoyalty(royaltyReceiver, royaltyFeeNumerator); _setupRole(MINTER_ROLE, owner); diff --git a/src/tokens/ERC1155/presets/minter/ERC1155TokenMinterFactory.sol b/src/tokens/ERC1155/presets/minter/ERC1155TokenMinterFactory.sol index 281e908..ff0b13e 100644 --- a/src/tokens/ERC1155/presets/minter/ERC1155TokenMinterFactory.sol +++ b/src/tokens/ERC1155/presets/minter/ERC1155TokenMinterFactory.sol @@ -25,17 +25,27 @@ contract ERC1155TokenMinterFactory is IERC1155TokenMinterFactory, SequenceProxyF * @param tokenOwner The owner of the ERC-1155 Token Minter implementation * @param name The name of the ERC-1155 Token Minter proxy * @param baseURI The base URI of the ERC-1155 Token Minter proxy + * @param royaltyReceiver Address of who should be sent the royalty payment + * @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500) * @param salt The deployment salt * @return proxyAddr The address of the ERC-1155 Token Minter Proxy * @dev The provided `salt` is hashed with the caller address for security. - * @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-20 Token Minter functions. + * @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-1155 Token Minter functions. */ - function deploy(address proxyOwner, address tokenOwner, string memory name, string memory baseURI, bytes32 salt) + function deploy( + address proxyOwner, + address tokenOwner, + string memory name, + string memory baseURI, + address royaltyReceiver, + uint96 royaltyFeeNumerator, + bytes32 salt + ) external returns (address proxyAddr) { proxyAddr = _createProxy(salt, proxyOwner, ""); - ERC1155TokenMinter(proxyAddr).initialize(tokenOwner, name, baseURI); + ERC1155TokenMinter(proxyAddr).initialize(tokenOwner, name, baseURI, royaltyReceiver, royaltyFeeNumerator); emit ERC1155TokenMinterDeployed(proxyAddr); return proxyAddr; } diff --git a/src/tokens/ERC1155/presets/minter/IERC1155TokenMinterFactory.sol b/src/tokens/ERC1155/presets/minter/IERC1155TokenMinterFactory.sol index 9dc0ff8..4ba1e3d 100644 --- a/src/tokens/ERC1155/presets/minter/IERC1155TokenMinterFactory.sol +++ b/src/tokens/ERC1155/presets/minter/IERC1155TokenMinterFactory.sol @@ -8,12 +8,22 @@ interface IERC1155TokenMinterFactoryFunctions { * @param tokenOwner The owner of the ERC-1155 Token Minter implementation * @param name The name of the ERC-1155 Token Minter proxy * @param baseURI The base URI of the ERC-1155 Token Minter proxy + * @param royaltyReceiver Address of who should be sent the royalty payment + * @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500) * @param salt The deployment salt * @return proxyAddr The address of the ERC-1155 Token Minter Proxy * @dev The provided `salt` is hashed with the caller address for security. - * @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-20 Token Minter functions. + * @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-1155 Token Minter functions. */ - function deploy(address proxyOwner, address tokenOwner, string memory name, string memory baseURI, bytes32 salt) + function deploy( + address proxyOwner, + address tokenOwner, + string memory name, + string memory baseURI, + address royaltyReceiver, + uint96 royaltyFeeNumerator, + bytes32 salt + ) external returns (address proxyAddr); } diff --git a/src/tokens/ERC1155/presets/sale/ERC1155Sale.sol b/src/tokens/ERC1155/presets/sale/ERC1155Sale.sol index 60db8f3..baac0a8 100644 --- a/src/tokens/ERC1155/presets/sale/ERC1155Sale.sol +++ b/src/tokens/ERC1155/presets/sale/ERC1155Sale.sol @@ -2,16 +2,19 @@ pragma solidity ^0.8.17; import {IERC1155Sale} from "@0xsequence/contracts-library/tokens/ERC1155/presets/sale/IERC1155Sale.sol"; -import {ERC1155Supply, ERC1155Token} from "@0xsequence/contracts-library/tokens/ERC1155/extensions/supply/ERC1155Supply.sol"; -import {WithdrawControlled, AccessControl, SafeERC20, IERC20} from "@0xsequence/contracts-library/tokens/common/WithdrawControlled.sol"; -import {MerkleProofSingleUse} from "@0xsequence/contracts-library/tokens/common/MerkleProofSingleUse.sol"; - -contract ERC1155Sale is - IERC1155Sale, +import { ERC1155Supply, + ERC1155Token +} from "@0xsequence/contracts-library/tokens/ERC1155/extensions/supply/ERC1155Supply.sol"; +import { WithdrawControlled, - MerkleProofSingleUse -{ + AccessControl, + SafeERC20, + IERC20 +} from "@0xsequence/contracts-library/tokens/common/WithdrawControlled.sol"; +import {MerkleProofSingleUse} from "@0xsequence/contracts-library/tokens/common/MerkleProofSingleUse.sol"; + +contract ERC1155Sale is IERC1155Sale, ERC1155Supply, WithdrawControlled, MerkleProofSingleUse { bytes32 public constant MINT_ADMIN_ROLE = keccak256("MINT_ADMIN_ROLE"); bytes4 private constant _ERC20_TRANSFERFROM_SELECTOR = @@ -27,20 +30,30 @@ contract ERC1155Sale is /** * Initialize the contract. - * @param owner Owner address. - * @param tokenName Token name. - * @param tokenBaseURI Base URI for token metadata. + * @param owner Owner address + * @param tokenName Token name + * @param tokenBaseURI Base URI for token metadata + * @param royaltyReceiver Address of who should be sent the royalty payment + * @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500) * @dev This should be called immediately after deployment. */ - function initialize(address owner, string memory tokenName, string memory tokenBaseURI) public virtual override { + function initialize( + address owner, + string memory tokenName, + string memory tokenBaseURI, + address royaltyReceiver, + uint96 royaltyFeeNumerator + ) + public + virtual + { if (_initialized) { revert InvalidInitialization(); } - ERC1155Token.initialize(owner, tokenName, tokenBaseURI); - name = tokenName; - baseURI = tokenBaseURI; - _setupRole(DEFAULT_ADMIN_ROLE, owner); + ERC1155Token._initialize(owner, tokenName, tokenBaseURI); + _setDefaultRoyalty(royaltyReceiver, royaltyFeeNumerator); + _setupRole(MINT_ADMIN_ROLE, owner); _setupRole(WITHDRAW_ROLE, owner); @@ -64,7 +77,9 @@ contract ERC1155Sale is * @param _amounts Amounts of tokens to mint. * @param _proof Merkle proof for allowlist minting. */ - function _payForActiveMint(uint256[] memory _tokenIds, uint256[] memory _amounts, bytes32[] calldata _proof) private { + function _payForActiveMint(uint256[] memory _tokenIds, uint256[] memory _amounts, bytes32[] calldata _proof) + private + { uint256 lastTokenId; uint256 totalCost; uint256 totalAmount; @@ -127,7 +142,13 @@ contract ERC1155Sale is * @dev tokenIds must be sorted ascending without duplicates. * @dev An empty proof is supplied when no proof is required. */ - function mint(address to, uint256[] memory tokenIds, uint256[] memory amounts, bytes memory data, bytes32[] calldata proof) + function mint( + address to, + uint256[] memory tokenIds, + uint256[] memory amounts, + bytes memory data, + bytes32[] calldata proof + ) public payable { diff --git a/src/tokens/ERC1155/presets/sale/ERC1155SaleFactory.sol b/src/tokens/ERC1155/presets/sale/ERC1155SaleFactory.sol index 80134b4..f8a99a5 100644 --- a/src/tokens/ERC1155/presets/sale/ERC1155SaleFactory.sol +++ b/src/tokens/ERC1155/presets/sale/ERC1155SaleFactory.sol @@ -24,16 +24,26 @@ contract ERC1155SaleFactory is IERC1155SaleFactory, SequenceProxyFactory { * @param tokenOwner The owner of the ERC-1155 Sale implementation * @param name The name of the ERC-1155 Sale token * @param baseURI The base URI of the ERC-1155 Sale token + * @param royaltyReceiver Address of who should be sent the royalty payment + * @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500) * @param salt The deployment salt * @return proxyAddr The address of the ERC-1155 Sale Proxy - * @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-20 Token Minter functions. + * @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-1155 Sale Minter functions. */ - function deploy(address proxyOwner, address tokenOwner, string memory name, string memory baseURI, bytes32 salt) + function deploy( + address proxyOwner, + address tokenOwner, + string memory name, + string memory baseURI, + address royaltyReceiver, + uint96 royaltyFeeNumerator, + bytes32 salt + ) external returns (address proxyAddr) { proxyAddr = _createProxy(salt, proxyOwner, ""); - ERC1155Sale(proxyAddr).initialize(tokenOwner, name, baseURI); + ERC1155Sale(proxyAddr).initialize(tokenOwner, name, baseURI, royaltyReceiver, royaltyFeeNumerator); emit ERC1155SaleDeployed(proxyAddr); return proxyAddr; } diff --git a/src/tokens/ERC1155/presets/sale/IERC1155SaleFactory.sol b/src/tokens/ERC1155/presets/sale/IERC1155SaleFactory.sol index d5b393d..b7e8d93 100644 --- a/src/tokens/ERC1155/presets/sale/IERC1155SaleFactory.sol +++ b/src/tokens/ERC1155/presets/sale/IERC1155SaleFactory.sol @@ -8,11 +8,21 @@ interface IERC1155SaleFactoryFunctions { * @param tokenOwner The owner of the ERC-1155 Sale implementation * @param name The name of the ERC-1155 Sale token * @param baseURI The base URI of the ERC-1155 Sale token + * @param royaltyReceiver Address of who should be sent the royalty payment + * @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500) * @param salt The deployment salt * @return proxyAddr The address of the ERC-1155 Sale Proxy - * @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-20 Token Minter functions. + * @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-1155 Token Sale functions. */ - function deploy(address proxyOwner, address tokenOwner, string memory name, string memory baseURI, bytes32 salt) + function deploy( + address proxyOwner, + address tokenOwner, + string memory name, + string memory baseURI, + address royaltyReceiver, + uint96 royaltyFeeNumerator, + bytes32 salt + ) external returns (address proxyAddr); } diff --git a/src/tokens/ERC721/ERC721Token.sol b/src/tokens/ERC721/ERC721Token.sol index 2ffe604..1812acb 100644 --- a/src/tokens/ERC721/ERC721Token.sol +++ b/src/tokens/ERC721/ERC721Token.sol @@ -18,15 +18,10 @@ abstract contract ERC721Token is ERC721AQueryable, ERC2981Controlled { string internal _tokenName; string internal _tokenSymbol; - address private immutable _initializer; - bool private _initialized; - /** * Deploy contract. */ - constructor() ERC721A("", "") { - _initializer = msg.sender; - } + constructor() ERC721A("", "") {} /** * Initialize contract. @@ -36,11 +31,9 @@ abstract contract ERC721Token is ERC721AQueryable, ERC2981Controlled { * @param tokenBaseURI Base URI of the token * @dev This should be called immediately after deployment. */ - function initialize(address owner, string memory tokenName, string memory tokenSymbol, string memory tokenBaseURI) public virtual { - if (msg.sender != _initializer || _initialized) { - revert InvalidInitialization(); - } - + function _initialize(address owner, string memory tokenName, string memory tokenSymbol, string memory tokenBaseURI) + internal + { _tokenName = tokenName; _tokenSymbol = tokenSymbol; _tokenBaseURI = tokenBaseURI; @@ -48,8 +41,6 @@ abstract contract ERC721Token is ERC721AQueryable, ERC2981Controlled { _setupRole(DEFAULT_ADMIN_ROLE, owner); _setupRole(METADATA_ADMIN_ROLE, owner); _setupRole(ROYALTY_ADMIN_ROLE, owner); - - _initialized = true; } // diff --git a/src/tokens/ERC721/presets/minter/ERC721TokenMinter.sol b/src/tokens/ERC721/presets/minter/ERC721TokenMinter.sol index e57f8d0..eac51de 100644 --- a/src/tokens/ERC721/presets/minter/ERC721TokenMinter.sol +++ b/src/tokens/ERC721/presets/minter/ERC721TokenMinter.sol @@ -26,18 +26,27 @@ contract ERC721TokenMinter is ERC721Token, IERC721TokenMinter { * @param tokenName Name of the token * @param tokenSymbol Symbol of the token * @param tokenBaseURI Base URI of the token + * @param royaltyReceiver Address of who should be sent the royalty payment + * @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500) * @dev This should be called immediately after deployment. */ - function initialize(address owner, string memory tokenName, string memory tokenSymbol, string memory tokenBaseURI) + function initialize( + address owner, + string memory tokenName, + string memory tokenSymbol, + string memory tokenBaseURI, + address royaltyReceiver, + uint96 royaltyFeeNumerator + ) public virtual - override { if (msg.sender != _initializer || _initialized) { revert InvalidInitialization(); } - ERC721Token.initialize(owner, tokenName, tokenSymbol, tokenBaseURI); + ERC721Token._initialize(owner, tokenName, tokenSymbol, tokenBaseURI); + _setDefaultRoyalty(royaltyReceiver, royaltyFeeNumerator); _setupRole(MINTER_ROLE, owner); @@ -66,7 +75,10 @@ contract ERC721TokenMinter is ERC721Token, IERC721TokenMinter { * @param tokenName Name of token. * @param tokenSymbol Symbol of token. */ - function setNameAndSymbol(string memory tokenName, string memory tokenSymbol) external onlyRole(METADATA_ADMIN_ROLE) { + function setNameAndSymbol(string memory tokenName, string memory tokenSymbol) + external + onlyRole(METADATA_ADMIN_ROLE) + { _tokenName = tokenName; _tokenSymbol = tokenSymbol; } diff --git a/src/tokens/ERC721/presets/minter/ERC721TokenMinterFactory.sol b/src/tokens/ERC721/presets/minter/ERC721TokenMinterFactory.sol index 822ac62..029bc58 100644 --- a/src/tokens/ERC721/presets/minter/ERC721TokenMinterFactory.sol +++ b/src/tokens/ERC721/presets/minter/ERC721TokenMinterFactory.sol @@ -27,10 +27,12 @@ contract ERC721TokenMinterFactory is IERC721TokenMinterFactory, SequenceProxyFac * @param name The name of the ERC-721 Token Minter proxy * @param symbol The symbol of the ERC-721 Token Minter proxy * @param baseURI The base URI of the ERC-721 Token Minter proxy + * @param royaltyReceiver Address of who should be sent the royalty payment + * @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500) * @param salt The deployment salt * @return proxyAddr The address of the ERC-721 Token Minter Proxy * @dev The provided `salt` is hashed with the caller address for security. - * @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-20 Token Minter functions. + * @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-721 Token Minter functions. */ function deploy( address proxyOwner, @@ -38,13 +40,15 @@ contract ERC721TokenMinterFactory is IERC721TokenMinterFactory, SequenceProxyFac string memory name, string memory symbol, string memory baseURI, + address royaltyReceiver, + uint96 royaltyFeeNumerator, bytes32 salt ) external returns (address proxyAddr) { proxyAddr = _createProxy(salt, proxyOwner, ""); - ERC721TokenMinter(proxyAddr).initialize(tokenOwner, name, symbol, baseURI); + ERC721TokenMinter(proxyAddr).initialize(tokenOwner, name, symbol, baseURI, royaltyReceiver, royaltyFeeNumerator); emit ERC721TokenMinterDeployed(proxyAddr); return proxyAddr; } diff --git a/src/tokens/ERC721/presets/minter/IERC721TokenMinterFactory.sol b/src/tokens/ERC721/presets/minter/IERC721TokenMinterFactory.sol index 8a3da54..41c782b 100644 --- a/src/tokens/ERC721/presets/minter/IERC721TokenMinterFactory.sol +++ b/src/tokens/ERC721/presets/minter/IERC721TokenMinterFactory.sol @@ -10,10 +10,12 @@ interface IERC721TokenMinterFactoryFunctions { * @param name The name of the ERC-721 Token Minter proxy * @param symbol The symbol of the ERC-721 Token Minter proxy * @param baseURI The base URI of the ERC-721 Token Minter proxy + * @param royaltyReceiver Address of who should be sent the royalty payment + * @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500) * @param salt The deployment salt * @return proxyAddr The address of the ERC-721 Token Minter Proxy * @dev The provided `salt` is hashed with the caller address for security. - * @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-20 Token Minter functions. + * @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-721 Token Minter functions. */ function deploy( address proxyOwner, @@ -21,6 +23,8 @@ interface IERC721TokenMinterFactoryFunctions { string memory name, string memory symbol, string memory baseURI, + address royaltyReceiver, + uint96 royaltyFeeNumerator, bytes32 salt ) external diff --git a/src/tokens/ERC721/presets/sale/ERC721Sale.sol b/src/tokens/ERC721/presets/sale/ERC721Sale.sol index e054445..65d7ba4 100644 --- a/src/tokens/ERC721/presets/sale/ERC721Sale.sol +++ b/src/tokens/ERC721/presets/sale/ERC721Sale.sol @@ -3,7 +3,12 @@ pragma solidity ^0.8.17; import {IERC721Sale} from "@0xsequence/contracts-library/tokens/ERC721/presets/sale/IERC721Sale.sol"; import {ERC721Token} from "@0xsequence/contracts-library/tokens/ERC721/ERC721Token.sol"; -import {WithdrawControlled, AccessControl, SafeERC20, IERC20} from "@0xsequence/contracts-library/tokens/common/WithdrawControlled.sol"; +import { + WithdrawControlled, + AccessControl, + SafeERC20, + IERC20 +} from "@0xsequence/contracts-library/tokens/common/WithdrawControlled.sol"; import {MerkleProofSingleUse} from "@0xsequence/contracts-library/tokens/common/MerkleProofSingleUse.sol"; /** @@ -25,18 +30,28 @@ contract ERC721Sale is IERC721Sale, ERC721Token, WithdrawControlled, MerkleProof * @param tokenName Name of the token * @param tokenSymbol Symbol of the token * @param tokenBaseURI Base URI of the token + * @param royaltyReceiver Address of who should be sent the royalty payment + * @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500) * @dev This should be called immediately after deployment. */ - function initialize(address owner, string memory tokenName, string memory tokenSymbol, string memory tokenBaseURI) + function initialize( + address owner, + string memory tokenName, + string memory tokenSymbol, + string memory tokenBaseURI, + address royaltyReceiver, + uint96 royaltyFeeNumerator + ) public virtual - override { if (_initialized) { revert InvalidInitialization(); } - ERC721Token.initialize(owner, tokenName, tokenSymbol, tokenBaseURI); + ERC721Token._initialize(owner, tokenName, tokenSymbol, tokenBaseURI); + _setDefaultRoyalty(royaltyReceiver, royaltyFeeNumerator); + _setupRole(MINT_ADMIN_ROLE, owner); _setupRole(WITHDRAW_ROLE, owner); @@ -145,7 +160,10 @@ contract ERC721Sale is IERC721Sale, ERC721Token, WithdrawControlled, MerkleProof * @param tokenName Name of token. * @param tokenSymbol Symbol of token. */ - function setNameAndSymbol(string memory tokenName, string memory tokenSymbol) external onlyRole(METADATA_ADMIN_ROLE) { + function setNameAndSymbol(string memory tokenName, string memory tokenSymbol) + external + onlyRole(METADATA_ADMIN_ROLE) + { _tokenName = tokenName; _tokenSymbol = tokenSymbol; } diff --git a/src/tokens/ERC721/presets/sale/ERC721SaleFactory.sol b/src/tokens/ERC721/presets/sale/ERC721SaleFactory.sol index 494b19b..989274d 100644 --- a/src/tokens/ERC721/presets/sale/ERC721SaleFactory.sol +++ b/src/tokens/ERC721/presets/sale/ERC721SaleFactory.sol @@ -26,6 +26,8 @@ contract ERC721SaleFactory is IERC721SaleFactory, SequenceProxyFactory { * @param name The name of the ERC-721 Sale token * @param symbol The symbol of the ERC-721 Sale token * @param baseURI The base URI of the ERC-721 Sale token + * @param royaltyReceiver Address of who should be sent the royalty payment + * @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500) * @param salt The deployment salt * @return proxyAddr The address of the ERC-721 Sale Proxy * @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-721 Sale functions. @@ -36,13 +38,15 @@ contract ERC721SaleFactory is IERC721SaleFactory, SequenceProxyFactory { string memory name, string memory symbol, string memory baseURI, + address royaltyReceiver, + uint96 royaltyFeeNumerator, bytes32 salt ) external returns (address proxyAddr) { proxyAddr = _createProxy(salt, proxyOwner, ""); - ERC721Sale(proxyAddr).initialize(tokenOwner, name, symbol, baseURI); + ERC721Sale(proxyAddr).initialize(tokenOwner, name, symbol, baseURI, royaltyReceiver, royaltyFeeNumerator); emit ERC721SaleDeployed(proxyAddr); return proxyAddr; } diff --git a/src/tokens/ERC721/presets/sale/IERC721SaleFactory.sol b/src/tokens/ERC721/presets/sale/IERC721SaleFactory.sol index 8a14e46..aa8a687 100644 --- a/src/tokens/ERC721/presets/sale/IERC721SaleFactory.sol +++ b/src/tokens/ERC721/presets/sale/IERC721SaleFactory.sol @@ -10,6 +10,8 @@ interface IERC721SaleFactoryFunctions { * @param name The name of the ERC-721 Sale token * @param symbol The symbol of the ERC-721 Sale token * @param baseURI The base URI of the ERC-721 Sale token + * @param royaltyReceiver Address of who should be sent the royalty payment + * @param royaltyFeeNumerator The royalty fee numerator in basis points (e.g. 15% would be 1500) * @param salt The deployment salt * @return proxyAddr The address of the ERC-721 Sale Proxy * @dev As `proxyOwner` owns the proxy, it will be unable to call the ERC-721 Sale functions. @@ -20,6 +22,8 @@ interface IERC721SaleFactoryFunctions { string memory name, string memory symbol, string memory baseURI, + address royaltyReceiver, + uint96 royaltyFeeNumerator, bytes32 salt ) external diff --git a/test/tokens/ERC1155/presets/ERC1155Sale.t.sol b/test/tokens/ERC1155/presets/ERC1155Sale.t.sol index 2ea249c..3016e90 100644 --- a/test/tokens/ERC1155/presets/ERC1155Sale.t.sol +++ b/test/tokens/ERC1155/presets/ERC1155Sale.t.sol @@ -39,14 +39,14 @@ contract ERC1155SaleTest is Test, Merkle, IERC1155SaleSignals, IERC1155SupplySig proxyOwner = makeAddr("proxyOwner"); token = new ERC1155Sale(); - token.initialize(address(this), "test", "ipfs://"); + token.initialize(address(this), "test", "ipfs://", address(this), 0); vm.deal(address(this), 1e6 ether); } function setUpFromFactory() public { ERC1155SaleFactory factory = new ERC1155SaleFactory(address(this)); - token = ERC1155Sale(factory.deploy(proxyOwner, address(this), "test", "ipfs://", "")); + token = ERC1155Sale(factory.deploy(proxyOwner, address(this), "test", "ipfs://", address(this), 0, "")); } function testSupportsInterface() public { diff --git a/test/tokens/ERC1155/presets/ERC1155TokenMinter.t.sol b/test/tokens/ERC1155/presets/ERC1155TokenMinter.t.sol index 80e0831..f096ba5 100644 --- a/test/tokens/ERC1155/presets/ERC1155TokenMinter.t.sol +++ b/test/tokens/ERC1155/presets/ERC1155TokenMinter.t.sol @@ -35,12 +35,12 @@ contract ERC1155TokenMinterTest is Test, IERC1155TokenMinterSignals { vm.deal(owner, 100 ether); ERC1155TokenMinterFactory factory = new ERC1155TokenMinterFactory(address(this)); - token = ERC1155TokenMinter(factory.deploy(proxyOwner, owner, "name", "baseURI", 0x0)); + token = ERC1155TokenMinter(factory.deploy(proxyOwner, owner, "name", "baseURI", address(this), 0, 0x0)); } function testReinitializeFails() public { vm.expectRevert(InvalidInitialization.selector); - token.initialize(owner, "name", "baseURI"); + token.initialize(owner, "name", "baseURI", address(this), 0); } function testSupportsInterface() public { @@ -240,7 +240,7 @@ contract ERC1155TokenMinterTest is Test, IERC1155TokenMinterSignals { assertEq(amount, salePrice * feeNumerator / 10000); (receiver_, amount) = token.royaltyInfo(69, salePrice); - assertEq(receiver_, address(0)); + assertEq(receiver_, address(this)); assertEq(amount, 0); } diff --git a/test/tokens/ERC721/presets/ERC721Sale.t.sol b/test/tokens/ERC721/presets/ERC721Sale.t.sol index 91cf73d..815651f 100644 --- a/test/tokens/ERC721/presets/ERC721Sale.t.sol +++ b/test/tokens/ERC721/presets/ERC721Sale.t.sol @@ -35,14 +35,14 @@ contract ERC721SaleTest is Test, Merkle, IERC721SaleSignals, IMerkleProofSingleU proxyOwner = makeAddr("proxyOwner"); token = new ERC721Sale(); - token.initialize(address(this), "test", "test", "ipfs://"); + token.initialize(address(this), "test", "test", "ipfs://", address(this), 0); vm.deal(address(this), 100 ether); } function setUpFromFactory() public { ERC721SaleFactory factory = new ERC721SaleFactory(address(this)); - token = ERC721Sale(factory.deploy(proxyOwner, address(this), "test", "test", "ipfs://", "")); + token = ERC721Sale(factory.deploy(proxyOwner, address(this), "test", "test", "ipfs://", address(this), 0, "")); } function testSupportsInterface() public { diff --git a/test/tokens/ERC721/presets/ERC721TokenMinter.t.sol b/test/tokens/ERC721/presets/ERC721TokenMinter.t.sol index cacbcd2..9ccf231 100644 --- a/test/tokens/ERC721/presets/ERC721TokenMinter.t.sol +++ b/test/tokens/ERC721/presets/ERC721TokenMinter.t.sol @@ -30,12 +30,12 @@ contract ERC721TokenMinterTest is Test, IERC721TokenMinterSignals { vm.deal(owner, 100 ether); ERC721TokenMinterFactory factory = new ERC721TokenMinterFactory(address(this)); - token = ERC721TokenMinter(factory.deploy(proxyOwner, owner, "name", "symbol", "baseURI", 0x0)); + token = ERC721TokenMinter(factory.deploy(proxyOwner, owner, "name", "symbol", "baseURI", address(this), 0, 0x0)); } function testReinitializeFails() public { vm.expectRevert(InvalidInitialization.selector); - token.initialize(owner, "name", "symbol", "baseURI"); + token.initialize(owner, "name", "symbol", "baseURI", address(this), 0); } function testSupportsInterface() public { @@ -196,7 +196,7 @@ contract ERC721TokenMinterTest is Test, IERC721TokenMinterSignals { assertEq(amount, salePrice * feeNumerator / 10000); (receiver_, amount) = token.royaltyInfo(69, salePrice); - assertEq(receiver_, address(0)); + assertEq(receiver_, address(this)); assertEq(amount, 0); }