From 4bfcaa9c6cd16cbb547f2688ffeb375f26eb4c2a Mon Sep 17 00:00:00 2001 From: cebgcontract <99630598+cebgcontract@users.noreply.github.com> Date: Mon, 15 Aug 2022 14:43:37 +0800 Subject: [PATCH] =?UTF-8?q?1155=20mint=E6=97=B6=E5=88=A4=E6=96=AD=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contracts/logic/MinterFactory.sol | 20 ++++++++++++++++++++ contracts/tokens/erc1155/BEBase1155.sol | 16 ++++++++++++---- contracts/tokens/erc1155/BEChip1155.sol | 4 ++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/contracts/logic/MinterFactory.sol b/contracts/logic/MinterFactory.sol index 7a40637..f6dddbe 100644 --- a/contracts/logic/MinterFactory.sol +++ b/contracts/logic/MinterFactory.sol @@ -15,6 +15,7 @@ contract MinterFactory is Ownable, Initializable, HasSignature { IBEERC1155 public chip; IBEERC1155 public shard; uint256 private _duration; + mapping(address => bool) public approvalLists; event TokenMinted( address contractAddress, @@ -41,6 +42,21 @@ contract MinterFactory is Ownable, Initializable, HasSignature { shard = IBEERC1155(_erc721s[3]); _duration = 1 days; } + + /** + * @dev Allow operation to reverse signature. + */ + function addApprovalList(address user) external onlyOwner { + require(!approvalLists[user], "MinterFactory: Invalid user address"); + approvalLists[user] = true; + } + + /** + * @dev Remove operation from approval list. + */ + function removeApprovalList(address user) external onlyOwner { + approvalLists[user] = false; + } /** * @dev update executor @@ -229,6 +245,10 @@ contract MinterFactory is Ownable, Initializable, HasSignature { function ignoreSignature( bytes calldata signature ) external { + require( + approvalLists[_msgSender()], + "Must be valid approval list" + ); if (!usedSignatures[signature]) { usedSignatures[signature] = true; } diff --git a/contracts/tokens/erc1155/BEBase1155.sol b/contracts/tokens/erc1155/BEBase1155.sol index dd3d420..5676106 100644 --- a/contracts/tokens/erc1155/BEBase1155.sol +++ b/contracts/tokens/erc1155/BEBase1155.sol @@ -17,10 +17,13 @@ abstract contract BEBase1155 is ERC1155, AccessControl { mapping(uint256 => bool) public lockedTokens; mapping(address => uint256[]) private _ownedTokens; + // for 0 means not exists, value stored = index + 1; mapping(address => mapping(uint256 => uint256)) private _ownedTokensIndex; mapping(uint256 => uint256) private _totalSupply; + uint256 public maxSupply = 0; + struct TokenStruct { uint256 tokenId; uint256 amount; @@ -213,6 +216,12 @@ abstract contract BEBase1155 is ERC1155, AccessControl { // mint nft for (uint256 i = 0; i < len; ++i) { _totalSupply[ids[i]] += amounts[i]; + if (maxSupply > 0) { + require( + _totalSupply[ids[i]] <= maxSupply, + "Can not mint for exceeds max supply" + ); + } } } else if (from != to) { // transfer from -> to @@ -233,12 +242,11 @@ abstract contract BEBase1155 is ERC1155, AccessControl { } } } - function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { if ( _ownedTokensIndex[to][tokenId] == 0 && balanceOf(to, tokenId) == 0 ) { - _ownedTokensIndex[to][tokenId] = _ownedTokens[to].length; + _ownedTokensIndex[to][tokenId] = _ownedTokens[to].length + 1; _ownedTokens[to].push(tokenId); } } @@ -251,12 +259,12 @@ abstract contract BEBase1155 is ERC1155, AccessControl { uint256 balance = balanceOf(from, tokenId); if (balance == amount) { uint256 lastTokenIndex = _ownedTokens[from].length - 1; - uint256 tokenIndex = _ownedTokensIndex[from][tokenId]; + uint256 tokenIndex = _ownedTokensIndex[from][tokenId] - 1; uint256 lastTokenId = _ownedTokens[from][lastTokenIndex]; _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token - _ownedTokensIndex[from][lastTokenId] = tokenIndex; // Update the moved token's index + _ownedTokensIndex[from][lastTokenId] = tokenIndex + 1; // Update the moved token's index // This also deletes the contents at the last position of the array delete _ownedTokensIndex[from][tokenId]; diff --git a/contracts/tokens/erc1155/BEChip1155.sol b/contracts/tokens/erc1155/BEChip1155.sol index dcb9d28..e0c0c67 100644 --- a/contracts/tokens/erc1155/BEChip1155.sol +++ b/contracts/tokens/erc1155/BEChip1155.sol @@ -9,6 +9,10 @@ import "./BEBase1155.sol"; contract BEChip1155 is BEBase1155 { mapping(uint256 => uint256) public tokenLevels; + constructor() { + maxSupply = 1; + } + function canMint(uint256 id) external view override returns (bool) { return !exists(id); }