-
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.
Merge pull request #81 from MyriadFlow/AddedFanToken
Added Reward Token
- Loading branch information
Showing
11 changed files
with
1,995 additions
and
7 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
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,172 @@ | ||
// 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"; | ||
|
||
contract RewardToken is Context, ERC1155Supply { | ||
string public name; | ||
string public symbol; | ||
|
||
address public tradeHub; | ||
address public accessMasterAddress; | ||
|
||
uint256 public Counter; | ||
uint8 public constant version = 1; | ||
// Optional mapping for token URIs | ||
mapping(uint256 => string) private _tokenURIs; | ||
mapping(address => mapping(uint256 => uint256)) public phygitalToRewardId; | ||
|
||
//// 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 RewardTokenDestroyed(uint indexed tokenId, address ownerOrApproved); | ||
|
||
// tradeHub should be there | ||
/** | ||
* @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 tradeHubAddress, | ||
address flowContract | ||
) ERC1155(baseURI) { | ||
name = _name; | ||
symbol = _symbol; | ||
tradeHub = tradeHubAddress; | ||
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, | ||
uint256 tokenId, | ||
bytes memory data, | ||
string memory _uri | ||
) public returns (uint256) { | ||
uint256 currentTokenID; | ||
if (phygitalToRewardId[phygitalcontractAddr][tokenId] > 0) { | ||
currentTokenID = phygitalToRewardId[phygitalcontractAddr][tokenId]; | ||
} else { | ||
Counter++; | ||
currentTokenID = Counter; | ||
} | ||
_mint(_msgSender(), currentTokenID, amount, data); | ||
_tokenURIs[currentTokenID] = _uri; | ||
setApprovalForAll(tradeHub, true); | ||
emit RewardTokenCreated(currentTokenID, _msgSender(), amount, _uri); | ||
return currentTokenID; | ||
} | ||
|
||
/** | ||
* @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`. | ||
*/ | ||
function delegateAssetCreation( | ||
address phygitalcontractAddr, | ||
address creator, | ||
uint256 tokenId, | ||
uint256 amount, | ||
bytes memory data, | ||
string memory _uri | ||
) public onlyOperator returns (uint256) { | ||
uint256 currentTokenID; | ||
// We cannot just use balanceOf to create the new tokenId because tokens | ||
// can be burned (destroyed), so we need a separate counter. | ||
if (phygitalToRewardId[phygitalcontractAddr][tokenId] > 0) { | ||
currentTokenID = phygitalToRewardId[phygitalcontractAddr][tokenId]; | ||
} else { | ||
Counter++; | ||
currentTokenID = Counter; | ||
} | ||
_mint(creator, currentTokenID, amount, data); | ||
_tokenURIs[currentTokenID] = _uri; | ||
setApprovalForAll(tradeHub, true); | ||
emit RewardTokenCreated(currentTokenID, _msgSender(), amount, _uri); | ||
return currentTokenID; | ||
} | ||
|
||
/** | ||
* @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 **/ | ||
|
||
/// @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); | ||
} | ||
} |
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,55 @@ | ||
// imports | ||
const { ethers, run, network } = require("hardhat") | ||
// async main | ||
async function main() { | ||
const accounts = await ethers.getSigners() | ||
const deplpoyer = accounts[0].address | ||
const RewardTokenNftFactory = await ethers.getContractFactory("RewardToken") | ||
console.log("Deploying contract...") | ||
const RewardToken = await RewardTokenNftFactory.deploy( | ||
"ipfs://bafkreib7oqdtji6xhcsf3usbzt4mzefds7bs3ye2t3aedg2ssy6nyn36gq", | ||
"RewardToken", | ||
"RTS", | ||
"0xaf5793324C9de8e164E822652278AB8FC174C78e", | ||
"0xcA1DE631D9Cb2e64C863BF50b83D18249dFb7054" | ||
) | ||
await RewardToken.deployed() | ||
console.log(`Deployed contract to: ${RewardToken.address}`) | ||
|
||
if (hre.network.name != "hardhat") { | ||
console.log("Waiting for block confirmations...") | ||
await RewardToken.deployTransaction.wait(6) | ||
await verify(RewardToken.address, [ | ||
"ipfs://bafkreib7oqdtji6xhcsf3usbzt4mzefds7bs3ye2t3aedg2ssy6nyn36gq", | ||
"RewardToken", | ||
"RTS", | ||
"0xaf5793324C9de8e164E822652278AB8FC174C78e", | ||
"0xcA1DE631D9Cb2e64C863BF50b83D18249dFb7054", | ||
]) | ||
} | ||
} | ||
|
||
// async function verify(contractAddress, args) { | ||
const verify = async (contractAddress, args) => { | ||
console.log("Verifying contract...") | ||
try { | ||
await run("verify:verify", { | ||
address: contractAddress, | ||
constructorArguments: args, | ||
}) | ||
} catch (e) { | ||
if (e.message.toLowerCase().includes("already verified")) { | ||
console.log("Already Verified!") | ||
} else { | ||
console.log(e) | ||
} | ||
} | ||
} | ||
|
||
// main | ||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error) | ||
process.exit(1) | ||
}) |
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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
{ | ||
"contractName": "AccessMaster", | ||
"constructorParams": { | ||
"param1": "0x83AD8ddAdb013fbA80DE0d802FD4fB1a949AD79f" | ||
"contractName" : "PhygitalA", | ||
"constructorParams":{ | ||
"param1": "Alice Clothing", | ||
"param2" : "AC", | ||
"param3" : "0x3A29EA5Ee6AB0326D72b55837dD9fD45b7a867Dd", | ||
"param4" : "0xc3fE1c3bCCE02d7A115Df2d4737137A15ff830F9", | ||
"param5" : "0xe6b8a5CF854791412c1f6EFC7CAf629f5Df1c747", | ||
"param6" : "[10000000000000000,100,300,6]", | ||
"param7" : "www.xyz.com" | ||
} | ||
} |
Oops, something went wrong.