-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c0a77a
commit ff2a156
Showing
3 changed files
with
192 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.17; | ||
|
||
import "@openzeppelin/contracts/utils/Context.sol"; | ||
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol"; | ||
import "../accessmaster/interfaces/IAccessMaster.sol"; | ||
|
||
//// tokenID -> 1 -> 0 | ||
|
||
/// mapping[contractAddress] -> tokenId | ||
|
||
/// CreateFanToken -- arguments -- | ||
/// 1. MetadataURI (must be unique) | ||
/// 2. ContractAddress(must be unique) | ||
|
||
/// delegate mint function which allow users to mint more balance on that particular. DelegateMintFanToken() -- OnlyOperator | ||
|
||
contract RewardToken is Context, ERC1155Supply { | ||
string public name; | ||
string public symbol; | ||
|
||
address public accessMasterAddress; | ||
|
||
string[] public strArr; | ||
|
||
uint256 private _nextTokenId; | ||
uint8 public constant version = 1; | ||
// Optional mapping for token URIs | ||
mapping(uint256 => string) private _tokenURIs; | ||
mapping(address => mapping(uint256 => uint256)) public phygitalToRewardId; | ||
mapping(address => uint) public phygitalcontractAddrToToken; | ||
|
||
//// phygitalTokenID => RewardToken -- >if it exists +++ | ||
|
||
IACCESSMASTER flowRoles; | ||
|
||
modifier onlyOperator() { | ||
require( | ||
flowRoles.isOperator(_msgSender()), | ||
"RewardToken: Unauthorized!" | ||
); | ||
_; | ||
} | ||
|
||
modifier onlyCreator() { | ||
require( | ||
flowRoles.isCreator(_msgSender()), | ||
"RewardToken: Unauthorized!" | ||
); | ||
_; | ||
} | ||
|
||
event RewardTokenCreated( | ||
uint256 indexed tokenID, | ||
address indexed creator, | ||
uint256 indexed amount, | ||
string metadatauri | ||
); | ||
|
||
event RewardTokenMinted( | ||
uint256 indexed tokenID, | ||
address indexed creator, | ||
uint256 indexed amount | ||
); | ||
event RewardTokenDestroyed(uint indexed tokenId, address ownerOrApproved); | ||
|
||
/** | ||
* @dev Grants `FLOW_ADMIN_ROLE`, `FLOW_CREATOR_ROLE` and `FLOW_OPERATOR_ROLE` to the | ||
* account that deploys the contract. | ||
* | ||
*/ | ||
constructor( | ||
string memory baseURI, | ||
string memory _name, | ||
string memory _symbol, | ||
address flowContract | ||
) ERC1155(baseURI) { | ||
name = _name; | ||
symbol = _symbol; | ||
flowRoles = IACCESSMASTER(flowContract); | ||
accessMasterAddress = flowContract; | ||
} | ||
|
||
/** | ||
* @dev Creates a new token for `to`. Its token ID will be automatically | ||
* assigned (and available on the emitted {IERC1155-Transfer} event), and the token | ||
* URI autogenerated based on the base URI passed at construction. | ||
* | ||
* | ||
* Requirements: | ||
* | ||
* - the caller must have the `FLOW_CREATOR_ROLE`. | ||
*/ | ||
|
||
///IssueRewardToken | ||
function createFanToken( | ||
address phygitalcontractAddr, | ||
uint256 amount, | ||
bytes memory data, | ||
string memory _uri | ||
) public returns (uint256) { | ||
require( | ||
phygitalcontractAddrToToken[phygitalcontractAddr] == 0, | ||
"RewrdToken: Token is already minted!" | ||
); | ||
require( | ||
elementExists(_uri) == false, | ||
"RewardToken: Metadata already exists" | ||
); | ||
|
||
_nextTokenId++; | ||
uint256 currentTokenID = _nextTokenId; | ||
phygitalcontractAddrToToken[phygitalcontractAddr] = currentTokenID; | ||
|
||
_mint(_msgSender(), currentTokenID, amount, data); | ||
strArr.push(_uri); | ||
_tokenURIs[currentTokenID] = _uri; | ||
emit RewardTokenCreated(currentTokenID, _msgSender(), amount, _uri); | ||
return currentTokenID; | ||
} | ||
|
||
function delegateAssetCreation( | ||
address creator, | ||
uint256 tokenId, | ||
uint256 amount, | ||
bytes memory data | ||
) public onlyOperator returns (uint256) { | ||
_mint(creator, tokenId, amount, data); | ||
emit RewardTokenMinted(tokenId, creator, amount); | ||
return tokenId; | ||
} | ||
|
||
/** | ||
* @notice Burns `tokenId`. See {ERC721-_burn}. | ||
* | ||
* @dev Requirements: | ||
* | ||
* - The caller must own `tokenId` or be an approved operator. | ||
*/ | ||
function destroyAsset(uint256 tokenId, uint256 amount) public { | ||
require( | ||
balanceOf(_msgSender(), tokenId) == amount, | ||
"RewardToken: Caller is not token owner or approved" | ||
); | ||
_burn(_msgSender(), tokenId, amount); | ||
emit RewardTokenDestroyed(tokenId, _msgSender()); | ||
} | ||
|
||
/// @dev ONLY Operator can set the Base URI | ||
function setURI(string memory newuri) external onlyOperator { | ||
_setURI(newuri); | ||
} | ||
|
||
/** Getter Functions **/ | ||
|
||
// New function to check if a string element exists in the array | ||
function elementExists(string memory element) public view returns (bool) { | ||
for (uint i = 0; i < strArr.length; i++) { | ||
if ( | ||
keccak256(abi.encodePacked(strArr[i])) == | ||
keccak256(abi.encodePacked(element)) | ||
) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/// @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. | ||
function uri( | ||
uint256 tokenId | ||
) public view virtual override returns (string memory) { | ||
return _tokenURIs[tokenId]; | ||
} | ||
|
||
/** | ||
* @dev See {IERC165-supportsInterface}. | ||
*/ | ||
function supportsInterface( | ||
bytes4 interfaceId | ||
) public view virtual override(ERC1155) returns (bool) { | ||
return super.supportsInterface(interfaceId); | ||
} | ||
} |
Oops, something went wrong.