Skip to content

Commit 9f583f8

Browse files
authored
Merge pull request #81 from MyriadFlow/AddedFanToken
Added Reward Token
2 parents 5f71029 + ad3ea20 commit 9f583f8

11 files changed

+1995
-7
lines changed

contracts/fusionseries/FusionSeries.sol

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ contract FusionSeries is Context, ERC1155Supply {
3434
// Optional mapping for token URIs
3535
mapping(uint256 => string) private _tokenURIs;
3636

37+
//// phygitalTokenID => FusionSeries -- >if it exists +++
38+
3739
IACCESSMASTER flowRoles;
3840

3941
modifier onlyOperator() {
@@ -94,6 +96,8 @@ contract FusionSeries is Context, ERC1155Supply {
9496
* - the caller must have the `FLOW_CREATOR_ROLE`.
9597
*/
9698
function createAsset(
99+
//contractAddr
100+
//tokenID -> phygitalTokenID = FusionSeries tokenId
97101
uint256 amount,
98102
bytes memory data,
99103
string memory _uri

contracts/phygital/PhygitalA.sol

+9-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ contract PhygitalA is Context, ERC2981, ERC721A, ERC721ABurnable {
6868
IACCESSMASTER flowRoles;
6969
IERC20 token;
7070

71+
modifier onlyAdnin() {
72+
require(
73+
flowRoles.isAdmin(_msgSender()),
74+
"PhygitalA: User is not authorized"
75+
);
76+
_;
77+
}
78+
7179
modifier onlyOperator() {
7280
require(
7381
flowRoles.isOperator(_msgSender()),
@@ -143,7 +151,6 @@ contract PhygitalA is Context, ERC2981, ERC721A, ERC721ABurnable {
143151
// SET DEFAULT ROYALTY
144152
_setDefaultRoyalty(_msgSender(), uint96(contractDetails[2]));
145153
maxMint = uint16(contractDetails[3]);
146-
147154
baseURL = _baseUri;
148155
accessMasterAddress = accessControlAddress;
149156
}
@@ -287,7 +294,7 @@ contract PhygitalA is Context, ERC2981, ERC721A, ERC721ABurnable {
287294
);
288295
}
289296

290-
function reveal(string memory uri) external {
297+
function reveal(string memory uri) external onlyAdnin {
291298
require(isRevealed == false, "Collection is already revealed!");
292299
isRevealed = true;
293300
baseURL = uri;

contracts/phygital/Reward.sol

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.17;
3+
4+
import "@openzeppelin/contracts/utils/Context.sol";
5+
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
6+
import "../accessmaster/interfaces/IAccessMaster.sol";
7+
8+
contract RewardToken is Context, ERC1155Supply {
9+
string public name;
10+
string public symbol;
11+
12+
address public tradeHub;
13+
address public accessMasterAddress;
14+
15+
uint256 public Counter;
16+
uint8 public constant version = 1;
17+
// Optional mapping for token URIs
18+
mapping(uint256 => string) private _tokenURIs;
19+
mapping(address => mapping(uint256 => uint256)) public phygitalToRewardId;
20+
21+
//// phygitalTokenID => RewardToken -- >if it exists +++
22+
23+
IACCESSMASTER flowRoles;
24+
25+
modifier onlyOperator() {
26+
require(
27+
flowRoles.isOperator(_msgSender()),
28+
"RewardToken: Unauthorized!"
29+
);
30+
_;
31+
}
32+
33+
modifier onlyCreator() {
34+
require(
35+
flowRoles.isCreator(_msgSender()),
36+
"RewardToken: Unauthorized!"
37+
);
38+
_;
39+
}
40+
41+
event RewardTokenCreated(
42+
uint256 indexed tokenID,
43+
address indexed creator,
44+
uint256 indexed amount,
45+
string metadataUri
46+
);
47+
event RewardTokenDestroyed(uint indexed tokenId, address ownerOrApproved);
48+
49+
// tradeHub should be there
50+
/**
51+
* @dev Grants `FLOW_ADMIN_ROLE`, `FLOW_CREATOR_ROLE` and `FLOW_OPERATOR_ROLE` to the
52+
* account that deploys the contract.
53+
*
54+
*/
55+
constructor(
56+
string memory baseURI,
57+
string memory _name,
58+
string memory _symbol,
59+
address tradeHubAddress,
60+
address flowContract
61+
) ERC1155(baseURI) {
62+
name = _name;
63+
symbol = _symbol;
64+
tradeHub = tradeHubAddress;
65+
flowRoles = IACCESSMASTER(flowContract);
66+
accessMasterAddress = flowContract;
67+
}
68+
69+
/**
70+
* @dev Creates a new token for `to`. Its token ID will be automatically
71+
* assigned (and available on the emitted {IERC1155-Transfer} event), and the token
72+
* URI autogenerated based on the base URI passed at construction.
73+
*
74+
*
75+
* Requirements:
76+
*
77+
* - the caller must have the `FLOW_CREATOR_ROLE`.
78+
*/
79+
///IssueRewardToken
80+
function createFanToken(
81+
address phygitalcontractAddr,
82+
uint256 amount,
83+
uint256 tokenId,
84+
bytes memory data,
85+
string memory _uri
86+
) public returns (uint256) {
87+
uint256 currentTokenID;
88+
if (phygitalToRewardId[phygitalcontractAddr][tokenId] > 0) {
89+
currentTokenID = phygitalToRewardId[phygitalcontractAddr][tokenId];
90+
} else {
91+
Counter++;
92+
currentTokenID = Counter;
93+
}
94+
_mint(_msgSender(), currentTokenID, amount, data);
95+
_tokenURIs[currentTokenID] = _uri;
96+
setApprovalForAll(tradeHub, true);
97+
emit RewardTokenCreated(currentTokenID, _msgSender(), amount, _uri);
98+
return currentTokenID;
99+
}
100+
101+
/**
102+
* @dev Creates a new token for `to`. Its token ID will be automatically
103+
* assigned (and available on the emitted {IERC1155-Transfer} event), and the token
104+
* URI autogenerated based on the base URI passed at construction.
105+
*
106+
* Requirements:
107+
*
108+
* - the caller must have the `FLOW_CREATOR_ROLE`.
109+
*/
110+
function delegateAssetCreation(
111+
address phygitalcontractAddr,
112+
address creator,
113+
uint256 tokenId,
114+
uint256 amount,
115+
bytes memory data,
116+
string memory _uri
117+
) public onlyOperator returns (uint256) {
118+
uint256 currentTokenID;
119+
// We cannot just use balanceOf to create the new tokenId because tokens
120+
// can be burned (destroyed), so we need a separate counter.
121+
if (phygitalToRewardId[phygitalcontractAddr][tokenId] > 0) {
122+
currentTokenID = phygitalToRewardId[phygitalcontractAddr][tokenId];
123+
} else {
124+
Counter++;
125+
currentTokenID = Counter;
126+
}
127+
_mint(creator, currentTokenID, amount, data);
128+
_tokenURIs[currentTokenID] = _uri;
129+
setApprovalForAll(tradeHub, true);
130+
emit RewardTokenCreated(currentTokenID, _msgSender(), amount, _uri);
131+
return currentTokenID;
132+
}
133+
134+
/**
135+
* @notice Burns `tokenId`. See {ERC721-_burn}.
136+
*
137+
* @dev Requirements:
138+
*
139+
* - The caller must own `tokenId` or be an approved operator.
140+
*/
141+
function destroyAsset(uint256 tokenId, uint256 amount) public {
142+
require(
143+
balanceOf(_msgSender(), tokenId) == amount,
144+
"RewardToken: Caller is not token owner or approved"
145+
);
146+
_burn(_msgSender(), tokenId, amount);
147+
emit RewardTokenDestroyed(tokenId, _msgSender());
148+
}
149+
150+
/// @dev ONLY Operator can set the Base URI
151+
function setURI(string memory newuri) external onlyOperator {
152+
_setURI(newuri);
153+
}
154+
155+
/** Getter Functions **/
156+
157+
/// @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
158+
function uri(
159+
uint256 tokenId
160+
) public view virtual override returns (string memory) {
161+
return _tokenURIs[tokenId];
162+
}
163+
164+
/**
165+
* @dev See {IERC165-supportsInterface}.
166+
*/
167+
function supportsInterface(
168+
bytes4 interfaceId
169+
) public view virtual override(ERC1155) returns (bool) {
170+
return super.supportsInterface(interfaceId);
171+
}
172+
}

scripts/RewardDeploy.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// imports
2+
const { ethers, run, network } = require("hardhat")
3+
// async main
4+
async function main() {
5+
const accounts = await ethers.getSigners()
6+
const deplpoyer = accounts[0].address
7+
const RewardTokenNftFactory = await ethers.getContractFactory("RewardToken")
8+
console.log("Deploying contract...")
9+
const RewardToken = await RewardTokenNftFactory.deploy(
10+
"ipfs://bafkreib7oqdtji6xhcsf3usbzt4mzefds7bs3ye2t3aedg2ssy6nyn36gq",
11+
"RewardToken",
12+
"RTS",
13+
"0xaf5793324C9de8e164E822652278AB8FC174C78e",
14+
"0xcA1DE631D9Cb2e64C863BF50b83D18249dFb7054"
15+
)
16+
await RewardToken.deployed()
17+
console.log(`Deployed contract to: ${RewardToken.address}`)
18+
19+
if (hre.network.name != "hardhat") {
20+
console.log("Waiting for block confirmations...")
21+
await RewardToken.deployTransaction.wait(6)
22+
await verify(RewardToken.address, [
23+
"ipfs://bafkreib7oqdtji6xhcsf3usbzt4mzefds7bs3ye2t3aedg2ssy6nyn36gq",
24+
"RewardToken",
25+
"RTS",
26+
"0xaf5793324C9de8e164E822652278AB8FC174C78e",
27+
"0xcA1DE631D9Cb2e64C863BF50b83D18249dFb7054",
28+
])
29+
}
30+
}
31+
32+
// async function verify(contractAddress, args) {
33+
const verify = async (contractAddress, args) => {
34+
console.log("Verifying contract...")
35+
try {
36+
await run("verify:verify", {
37+
address: contractAddress,
38+
constructorArguments: args,
39+
})
40+
} catch (e) {
41+
if (e.message.toLowerCase().includes("already verified")) {
42+
console.log("Already Verified!")
43+
} else {
44+
console.log(e)
45+
}
46+
}
47+
}
48+
49+
// main
50+
main()
51+
.then(() => process.exit(0))
52+
.catch((error) => {
53+
console.error(error)
54+
process.exit(1)
55+
})

scripts/launch/launch.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
2-
"contractName": "AccessMaster",
3-
"constructorParams": {
4-
"param1": "0x83AD8ddAdb013fbA80DE0d802FD4fB1a949AD79f"
2+
"contractName" : "PhygitalA",
3+
"constructorParams":{
4+
"param1": "Alice Clothing",
5+
"param2" : "AC",
6+
"param3" : "0x3A29EA5Ee6AB0326D72b55837dD9fD45b7a867Dd",
7+
"param4" : "0xc3fE1c3bCCE02d7A115Df2d4737137A15ff830F9",
8+
"param5" : "0xe6b8a5CF854791412c1f6EFC7CAf629f5Df1c747",
9+
"param6" : "[10000000000000000,100,300,6]",
10+
"param7" : "www.xyz.com"
511
}
612
}

0 commit comments

Comments
 (0)