-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
RankToken.sol
126 lines (106 loc) · 4.49 KB
/
RankToken.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {IRankToken} from "../interfaces/IRankToken.sol";
import "../abstracts/LockableERC1155.sol";
import "@peeramid-labs/eds/src/abstracts/ERC7746Middleware.sol";
import "@peeramid-labs/eds/src/libraries/LibMiddleware.sol";
import {IERC1155} from "@openzeppelin/contracts/interfaces/IERC1155.sol";
//ToDo: it was planned to make it track for highest token users hold (their rank), right now it's not implemented. Yet.
/**
* @title RankToken
* @author Peersky
* @notice RankToken is a composite ERC1155 token that is used to track user ranks
*/
contract RankToken is LockableERC1155, IRankToken, ERC7746Middleware {
struct Storage {
string _contractURI;
}
bytes32 constant RANK_TOKEN_STORAGE_POSITION = keccak256("rank.token.storage.position");
function getStorage() private pure returns (Storage storage s) {
bytes32 position = LOCKABLE_TOKEN_STORAGE_POSITION;
assembly {
s.slot := position
}
}
constructor(string memory uri_, string memory cURI, address accessLayer) {
initialize(uri_, cURI, accessLayer);
}
function initialize(string memory uri_, string memory cURI, address accessLayer) public initializer {
// __Ownable_init(owner_);
_setURI(uri_);
getStorage()._contractURI = cURI;
LibMiddleware.LayerStruct[] memory layers = new LibMiddleware.LayerStruct[](1);
// Set the layer for the sender
layers[0] = LibMiddleware.LayerStruct({layerAddess: accessLayer, layerConfigData: ""});
LibMiddleware.setLayers(layers);
}
// function getRankingInstance() public view returns (address) {
// return getStorage().rankingInstance;
// }
function contractURI() public view returns (string memory) {
return getStorage()._contractURI;
}
function setURI(string memory uri_) public ERC7746C(msg.sig, msg.sender, msg.data, 0) {
_setURI(uri_);
}
function setContractURI(string memory uri_) public ERC7746C(msg.sig, msg.sender, msg.data, 0) {
getStorage()._contractURI = uri_;
}
function _mintRank(address to, uint256 amount, uint256 level, bytes memory data) private {
require(to != address(0), "RankToken->mint: Address not specified");
require(amount != 0, "RankToken->mint: amount not specified");
require(level != 0, "RankToken->mint: pool id not specified");
// if (level > topRank) {
// topRank = level;
// emit Leader(to, level);
// }
_mint(to, level, amount, data);
}
function mint(
address to,
uint256 amount,
uint256 level,
bytes memory data
) public ERC7746C(msg.sig, msg.sender, msg.data, 0) {
_mintRank(to, amount, level, data);
}
// function updateRankingInstance(address newRankingInstance) public onlyOwner {
// require(newRankingInstance != address(0), "must specify ranking instance");
// getStorage()._rankingInstance = newRankingInstance;
// emit RankingInstanceUpdated(newRankingInstance);
// }
function lock(
address account,
uint256 id,
uint256 amount
) public override(LockableERC1155, ILockableERC1155) ERC7746C(msg.sig, msg.sender, msg.data, 0) {
super.lock(account, id, amount);
}
function unlock(
address account,
uint256 id,
uint256 amount
) public override(LockableERC1155, ILockableERC1155) ERC7746C(msg.sig, msg.sender, msg.data, 0) {
super.unlock(account, id, amount);
}
function batchMint(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public ERC7746C(msg.sig, msg.sender, msg.data, 0) {
require(to != address(0), "RankToken->mint: Address not specified");
require(amounts.length != 0, "RankToken->mint: amount not specified");
require(ids.length != 0, "RankToken->mint: pool id not specified");
_mintBatch(to, ids, amounts, data);
}
function _update(address from, address to, uint256[] memory ids, uint256[] memory values) internal override {
super._update(from, to, ids, values);
}
function supportsInterface(
bytes4 interfaceId
) public view virtual override(IERC165, ERC1155Upgradeable) returns (bool) {
return interfaceId == type(IRankToken).interfaceId || super.supportsInterface(interfaceId);
}
}