Skip to content

Commit

Permalink
Merge pull request #81 from MyriadFlow/AddedFanToken
Browse files Browse the repository at this point in the history
Added Reward Token
  • Loading branch information
soumalya340 authored Jun 26, 2024
2 parents 5f71029 + ad3ea20 commit 9f583f8
Show file tree
Hide file tree
Showing 11 changed files with 1,995 additions and 7 deletions.
4 changes: 4 additions & 0 deletions contracts/fusionseries/FusionSeries.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ contract FusionSeries is Context, ERC1155Supply {
// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;

//// phygitalTokenID => FusionSeries -- >if it exists +++

IACCESSMASTER flowRoles;

modifier onlyOperator() {
Expand Down Expand Up @@ -94,6 +96,8 @@ contract FusionSeries is Context, ERC1155Supply {
* - the caller must have the `FLOW_CREATOR_ROLE`.
*/
function createAsset(
//contractAddr
//tokenID -> phygitalTokenID = FusionSeries tokenId
uint256 amount,
bytes memory data,
string memory _uri
Expand Down
11 changes: 9 additions & 2 deletions contracts/phygital/PhygitalA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ contract PhygitalA is Context, ERC2981, ERC721A, ERC721ABurnable {
IACCESSMASTER flowRoles;
IERC20 token;

modifier onlyAdnin() {
require(
flowRoles.isAdmin(_msgSender()),
"PhygitalA: User is not authorized"
);
_;
}

modifier onlyOperator() {
require(
flowRoles.isOperator(_msgSender()),
Expand Down Expand Up @@ -143,7 +151,6 @@ contract PhygitalA is Context, ERC2981, ERC721A, ERC721ABurnable {
// SET DEFAULT ROYALTY
_setDefaultRoyalty(_msgSender(), uint96(contractDetails[2]));
maxMint = uint16(contractDetails[3]);

baseURL = _baseUri;
accessMasterAddress = accessControlAddress;
}
Expand Down Expand Up @@ -287,7 +294,7 @@ contract PhygitalA is Context, ERC2981, ERC721A, ERC721ABurnable {
);
}

function reveal(string memory uri) external {
function reveal(string memory uri) external onlyAdnin {
require(isRevealed == false, "Collection is already revealed!");
isRevealed = true;
baseURL = uri;
Expand Down
172 changes: 172 additions & 0 deletions contracts/phygital/Reward.sol
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);
}
}
55 changes: 55 additions & 0 deletions scripts/RewardDeploy.js
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)
})
12 changes: 9 additions & 3 deletions scripts/launch/launch.json
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"
}
}
Loading

0 comments on commit 9f583f8

Please sign in to comment.