From 91e70f4047af3c0ede3e67ab5ca53de3f77bfb90 Mon Sep 17 00:00:00 2001 From: Michael Standen Date: Tue, 31 Oct 2023 11:01:34 +1300 Subject: [PATCH] Add ability to change contract name symbol for erc20 721 --- src/tokens/ERC20/ERC20Token.sol | 4 ++-- .../ERC20/presets/minter/ERC20TokenMinter.sol | 14 ++++++++++++++ .../ERC20/presets/minter/IERC20TokenMinter.sol | 7 +++++++ src/tokens/ERC721/ERC721Token.sol | 4 ++-- .../ERC721/presets/minter/ERC721TokenMinter.sol | 14 ++++++++++++++ .../ERC721/presets/minter/IERC721TokenMinter.sol | 9 +++++++-- src/tokens/ERC721/presets/sale/ERC721Sale.sol | 14 ++++++++++++++ src/tokens/ERC721/presets/sale/IERC721Sale.sol | 7 +++++++ 8 files changed, 67 insertions(+), 6 deletions(-) diff --git a/src/tokens/ERC20/ERC20Token.sol b/src/tokens/ERC20/ERC20Token.sol index 11aa363..d17ff66 100644 --- a/src/tokens/ERC20/ERC20Token.sol +++ b/src/tokens/ERC20/ERC20Token.sol @@ -13,8 +13,8 @@ error InvalidInitialization(); */ abstract contract ERC20Token is ERC20, AccessControl { - string private _tokenName; - string private _tokenSymbol; + string internal _tokenName; + string internal _tokenSymbol; uint8 private _tokenDecimals; address private immutable _initializer; diff --git a/src/tokens/ERC20/presets/minter/ERC20TokenMinter.sol b/src/tokens/ERC20/presets/minter/ERC20TokenMinter.sol index 0d08679..746a8e2 100644 --- a/src/tokens/ERC20/presets/minter/ERC20TokenMinter.sol +++ b/src/tokens/ERC20/presets/minter/ERC20TokenMinter.sol @@ -51,6 +51,20 @@ contract ERC20TokenMinter is ERC20Token, IERC20TokenMinter { _mint(to, amount); } + // + // Admin + // + + /** + * Set name and symbol of token. + * @param tokenName Name of token. + * @param tokenSymbol Symbol of token. + */ + function setNameAndSymbol(string memory tokenName, string memory tokenSymbol) external onlyRole(DEFAULT_ADMIN_ROLE) { + _tokenName = tokenName; + _tokenSymbol = tokenSymbol; + } + // // Views // diff --git a/src/tokens/ERC20/presets/minter/IERC20TokenMinter.sol b/src/tokens/ERC20/presets/minter/IERC20TokenMinter.sol index aabbab9..f9e92d9 100644 --- a/src/tokens/ERC20/presets/minter/IERC20TokenMinter.sol +++ b/src/tokens/ERC20/presets/minter/IERC20TokenMinter.sol @@ -9,6 +9,13 @@ interface IERC20TokenMinterFunctions { * @param amount Amount of tokens to mint. */ function mint(address to, uint256 amount) external; + + /** + * Set name and symbol of token. + * @param tokenName Name of token. + * @param tokenSymbol Symbol of token. + */ + function setNameAndSymbol(string memory tokenName, string memory tokenSymbol) external; } interface IERC20TokenMinterSignals { diff --git a/src/tokens/ERC721/ERC721Token.sol b/src/tokens/ERC721/ERC721Token.sol index 0b16c51..2ffe604 100644 --- a/src/tokens/ERC721/ERC721Token.sol +++ b/src/tokens/ERC721/ERC721Token.sol @@ -15,8 +15,8 @@ abstract contract ERC721Token is ERC721AQueryable, ERC2981Controlled { bytes32 public constant METADATA_ADMIN_ROLE = keccak256("METADATA_ADMIN_ROLE"); string private _tokenBaseURI; - string private _tokenName; - string private _tokenSymbol; + string internal _tokenName; + string internal _tokenSymbol; address private immutable _initializer; bool private _initialized; diff --git a/src/tokens/ERC721/presets/minter/ERC721TokenMinter.sol b/src/tokens/ERC721/presets/minter/ERC721TokenMinter.sol index 416f467..e57f8d0 100644 --- a/src/tokens/ERC721/presets/minter/ERC721TokenMinter.sol +++ b/src/tokens/ERC721/presets/minter/ERC721TokenMinter.sol @@ -56,4 +56,18 @@ contract ERC721TokenMinter is ERC721Token, IERC721TokenMinter { function mint(address to, uint256 amount) external onlyRole(MINTER_ROLE) { _mint(to, amount); } + + // + // Admin + // + + /** + * Set name and symbol of token. + * @param tokenName Name of token. + * @param tokenSymbol Symbol of token. + */ + 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/IERC721TokenMinter.sol b/src/tokens/ERC721/presets/minter/IERC721TokenMinter.sol index 3a2364f..053168e 100644 --- a/src/tokens/ERC721/presets/minter/IERC721TokenMinter.sol +++ b/src/tokens/ERC721/presets/minter/IERC721TokenMinter.sol @@ -2,17 +2,22 @@ pragma solidity ^0.8.17; interface IERC721TokenMinterFunctions { - /** * Mint tokens. * @param to Address to mint tokens to. * @param amount Amount of tokens to mint. */ function mint(address to, uint256 amount) external; + + /** + * Set name and symbol of token. + * @param tokenName Name of token. + * @param tokenSymbol Symbol of token. + */ + function setNameAndSymbol(string memory tokenName, string memory tokenSymbol) external; } interface IERC721TokenMinterSignals { - /** * Invalid initialization error. */ diff --git a/src/tokens/ERC721/presets/sale/ERC721Sale.sol b/src/tokens/ERC721/presets/sale/ERC721Sale.sol index ead97a8..e054445 100644 --- a/src/tokens/ERC721/presets/sale/ERC721Sale.sol +++ b/src/tokens/ERC721/presets/sale/ERC721Sale.sol @@ -136,6 +136,20 @@ contract ERC721Sale is IERC721Sale, ERC721Token, WithdrawControlled, MerkleProof emit SaleDetailsUpdated(supplyCap, cost, paymentToken, startTime, endTime, merkleRoot); } + // + // Admin + // + + /** + * Set name and symbol of token. + * @param tokenName Name of token. + * @param tokenSymbol Symbol of token. + */ + function setNameAndSymbol(string memory tokenName, string memory tokenSymbol) external onlyRole(METADATA_ADMIN_ROLE) { + _tokenName = tokenName; + _tokenSymbol = tokenSymbol; + } + // // Views // diff --git a/src/tokens/ERC721/presets/sale/IERC721Sale.sol b/src/tokens/ERC721/presets/sale/IERC721Sale.sol index 949d4bd..f538283 100644 --- a/src/tokens/ERC721/presets/sale/IERC721Sale.sol +++ b/src/tokens/ERC721/presets/sale/IERC721Sale.sol @@ -45,6 +45,13 @@ interface IERC721SaleFunctions { * @return Sale details. */ function saleDetails() external view returns (SaleDetails memory); + + /** + * Set name and symbol of token. + * @param tokenName Name of token. + * @param tokenSymbol Symbol of token. + */ + function setNameAndSymbol(string memory tokenName, string memory tokenSymbol) external; } interface IERC721SaleSignals {