Skip to content

Commit

Permalink
Add royalty to deployment function
Browse files Browse the repository at this point in the history
  • Loading branch information
ScreamingHawk authored and acrylix committed Nov 9, 2023
1 parent 91e70f4 commit bbbc213
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 86 deletions.
21 changes: 4 additions & 17 deletions src/tokens/ERC1155/ERC1155Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,25 @@ 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.
* @param owner Owner address.
* @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;
}

//
Expand Down Expand Up @@ -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);
}
}
22 changes: 17 additions & 5 deletions src/tokens/ERC1155/presets/minter/ERC1155TokenMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
16 changes: 13 additions & 3 deletions src/tokens/ERC1155/presets/minter/ERC1155TokenMinterFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 12 additions & 2 deletions src/tokens/ERC1155/presets/minter/IERC1155TokenMinterFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
57 changes: 39 additions & 18 deletions src/tokens/ERC1155/presets/sale/ERC1155Sale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down
16 changes: 13 additions & 3 deletions src/tokens/ERC1155/presets/sale/ERC1155SaleFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 12 additions & 2 deletions src/tokens/ERC1155/presets/sale/IERC1155SaleFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
17 changes: 4 additions & 13 deletions src/tokens/ERC721/ERC721Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -36,20 +31,16 @@ 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;

_setupRole(DEFAULT_ADMIN_ROLE, owner);
_setupRole(METADATA_ADMIN_ROLE, owner);
_setupRole(ROYALTY_ADMIN_ROLE, owner);

_initialized = true;
}

//
Expand Down
20 changes: 16 additions & 4 deletions src/tokens/ERC721/presets/minter/ERC721TokenMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit bbbc213

Please sign in to comment.