File size: 15,119 Bytes
f998fcd |
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
// This contract is part of Zellic’s smart contract dataset, which is a collection of publicly available contract code gathered as of March 2023.
// SPDX-License-Identifier: MIT
/**
* @title ERC1155 Token
* @author 0xSumo
* @sponsored by PBADAO
*/
pragma solidity ^0.8.0;
interface ERC1155TokenReceiver {
function onERC1155Received(address operator_, address from_, uint256 id_, uint256 amount_, bytes calldata data_) external returns (bytes4);
function onERC1155BatchReceived(address operator_, address from_, uint256[] calldata ids_, uint256[] calldata amounts_, bytes calldata data_) external returns (bytes4);
}
abstract contract ERC1155Enumerable {
string public name;
string public symbol;
constructor(string memory name_, string memory symbol_) {
name = name_;
symbol = symbol_;
}
event TransferSingle(address indexed operator_, address indexed from_, address indexed to_, uint256 id_, uint256 amount_);
event TransferBatch(address indexed operator_, address indexed from_, address indexed to_, uint256[] ids_, uint256[] amounts_);
event ApprovalForAll(address indexed owner_, address indexed operator_, bool approved_);
event URI(string value_, uint256 indexed id_);
mapping(address => mapping(uint256 => uint256)) public balanceOf;
mapping(address => mapping(address => bool)) public isApprovedForAll;
mapping(uint256 => address[]) public tokenToOwners;
mapping(uint256 => mapping(address => uint256)) public tokenToOwnersToIndex;
struct TokenBalances {
address owner;
uint256 balance;
}
function _addEnumerableData(address address_, uint256 id_) internal {
if (balanceOf[address_][id_] == 0) {
uint256 _nextIndex = tokenToOwners[id_].length;
tokenToOwners[id_].push(address_);
tokenToOwnersToIndex[id_][address_] = _nextIndex;
}
}
function _removeEnumerableData(address address_, uint256 id_) internal {
if (balanceOf[address_][id_] == 0) {
uint256 _userIndex = tokenToOwnersToIndex[id_][address_];
uint256 _lastIndex = tokenToOwners[id_].length - 1;
if (_userIndex != _lastIndex) {
address _userAtLastIndex = tokenToOwners[id_][_lastIndex];
tokenToOwners[id_][_userIndex] = _userAtLastIndex;
tokenToOwnersToIndex[id_][_userAtLastIndex] = _userIndex;
}
tokenToOwners[id_].pop();
delete tokenToOwnersToIndex[id_][address_];
}
}
function getOwnersOfTokenId(uint256 id_) public view returns (address[] memory) {
return tokenToOwners[id_];
}
function getOwnersOfTokenIdAndBalance(uint256 id_) public view returns (TokenBalances[] memory) {
address[] memory _owners = getOwnersOfTokenId(id_);
uint256 _ownersLength = _owners.length;
TokenBalances[] memory _TokenBalancesAll = new TokenBalances[] (_ownersLength);
for (uint256 i = 0; i < _ownersLength; i++) {
address _currentOwner = _owners[i];
_TokenBalancesAll[i] = TokenBalances(
_currentOwner,
balanceOf[_currentOwner][id_]
);
}
return _TokenBalancesAll;
}
function getTotalSupplyOfIds(uint256[] calldata ids_) public view returns (uint256) {
uint256 _tokens;
for (uint256 i = 0; i < ids_.length; i++) {
_tokens += getOwnersOfTokenId(ids_[i]).length;
}
return _tokens;
}
function uri(uint256 id) public view virtual returns (string memory);
function _isSameLength(uint256 a, uint256 b) internal pure returns (bool) {
return a == b;
}
function _isApprovedOrOwner(address from_) internal view returns (bool) {
return msg.sender == from_ || isApprovedForAll[from_][msg.sender];
}
function _ERC1155Supported(address from_, address to_, uint256 id_, uint256 amount_, bytes memory data_) internal {
require(to_.code.length == 0 ? to_ != address(0) :
ERC1155TokenReceiver(to_).onERC1155Received(
msg.sender, from_, id_, amount_, data_) ==
ERC1155TokenReceiver.onERC1155Received.selector,
"_ERC1155Supported(): Unsupported Recipient!"
);
}
function _ERC1155BatchSupported(address from_, address to_, uint256[] memory ids_, uint256[] memory amounts_, bytes memory data_) internal {
require(to_.code.length == 0 ? to_ != address(0) :
ERC1155TokenReceiver(to_).onERC1155BatchReceived(
msg.sender, from_, ids_, amounts_, data_) ==
ERC1155TokenReceiver.onERC1155BatchReceived.selector,
"_ERC1155BatchSupported(): Unsupported Recipient!"
);
}
function setApprovalForAll(address operator_, bool approved_) public virtual {
isApprovedForAll[msg.sender][operator_] = approved_;
emit ApprovalForAll(msg.sender, operator_, approved_);
}
function _transfer(address from_, address to_, uint256 id_, uint256 amount_) internal {
_addEnumerableData(to_, id_);
balanceOf[to_][id_] += amount_;
balanceOf[from_][id_] -= amount_;
_removeEnumerableData(from_, id_);
}
function safeTransferFrom(address from_, address to_, uint256 id_, uint256 amount_, bytes memory data_) public virtual {
require(_isApprovedOrOwner(from_));
_transfer(from_, to_, id_, amount_);
emit TransferSingle(msg.sender, from_, to_, id_, amount_);
_ERC1155Supported(from_, to_, id_, amount_, data_);
}
function safeBatchTransferFrom(address from_, address to_, uint256[] memory ids_, uint256[] memory amounts_, bytes memory data_) public virtual {
require(_isSameLength(ids_.length, amounts_.length));
require(_isApprovedOrOwner(from_));
for (uint256 i = 0; i < ids_.length; i++) {
_transfer(from_, to_, ids_[i], amounts_[i]);
}
emit TransferBatch(msg.sender, from_, to_, ids_, amounts_);
_ERC1155BatchSupported(from_, to_, ids_, amounts_, data_);
}
function _mintInternal(address to_, uint256 id_, uint256 amount_) internal {
_addEnumerableData(to_, id_);
balanceOf[to_][id_] += amount_;
}
function _mint(address to_, uint256 id_, uint256 amount_, bytes memory data_) internal {
_mintInternal(to_, id_, amount_);
emit TransferSingle(msg.sender, address(0), to_, id_, amount_);
_ERC1155Supported(address(0), to_, id_, amount_, data_);
}
function _batchMint(address to_, uint256[] memory ids_, uint256[] memory amounts_, bytes memory data_) internal {
require(_isSameLength(ids_.length, amounts_.length));
for (uint256 i = 0; i < ids_.length; i++) {
_mintInternal(to_, ids_[i], amounts_[i]);
}
emit TransferBatch(msg.sender, address(0), to_, ids_, amounts_);
_ERC1155BatchSupported(address(0), to_, ids_, amounts_, data_);
}
function _burnInternal(address from_, uint256 id_, uint256 amount_) internal {
balanceOf[from_][id_] -= amount_;
_removeEnumerableData(from_, id_);
}
function _burn(address from_, uint256 id_, uint256 amount_) internal {
_burnInternal(from_, id_, amount_);
emit TransferSingle(msg.sender, from_, address(0), id_, amount_);
}
function _batchBurn(address from_, uint256[] memory ids_, uint256[] memory amounts_) internal {
require(_isSameLength(ids_.length, amounts_.length));
for (uint256 i = 0; i < ids_.length; i++) {
_burnInternal(from_, ids_[i], amounts_[i]);
}
emit TransferBatch(msg.sender, from_, address(0), ids_, amounts_);
}
function supportsInterface(bytes4 interfaceId_) public pure virtual returns (bool) {
return interfaceId_ == 0x01ffc9a7 || interfaceId_ == 0xd9b67a26 || interfaceId_ == 0x0e89341c;
}
function balanceOfBatch(address[] memory owners_, uint256[] memory ids_) public view virtual returns (uint256[] memory) {
require(_isSameLength(owners_.length, ids_.length));
uint256[] memory _balances = new uint256[](owners_.length);
for (uint256 i = 0; i < owners_.length; i++) {
_balances[i] = balanceOf[owners_[i]][ids_[i]];
}
return _balances;
}
}
interface IOperatorFilterRegistry {
function isOperatorAllowed(address registrant, address operator) external view returns (bool);
function register(address registrant) external;
function registerAndSubscribe(address registrant, address subscription) external;
function registerAndCopyEntries(address registrant, address registrantToCopy) external;
function unregister(address addr) external;
function updateOperator(address registrant, address operator, bool filtered) external;
function updateOperators(address registrant, address[] calldata operators, bool filtered) external;
function updateCodeHash(address registrant, bytes32 codehash, bool filtered) external;
function updateCodeHashes(address registrant, bytes32[] calldata codeHashes, bool filtered) external;
function subscribe(address registrant, address registrantToSubscribe) external;
function unsubscribe(address registrant, bool copyExistingEntries) external;
function subscriptionOf(address addr) external returns (address registrant);
function subscribers(address registrant) external returns (address[] memory);
function subscriberAt(address registrant, uint256 index) external returns (address);
function copyEntriesOf(address registrant, address registrantToCopy) external;
function isOperatorFiltered(address registrant, address operator) external returns (bool);
function isCodeHashOfFiltered(address registrant, address operatorWithCode) external returns (bool);
function isCodeHashFiltered(address registrant, bytes32 codeHash) external returns (bool);
function filteredOperators(address addr) external returns (address[] memory);
function filteredCodeHashes(address addr) external returns (bytes32[] memory);
function filteredOperatorAt(address registrant, uint256 index) external returns (address);
function filteredCodeHashAt(address registrant, uint256 index) external returns (bytes32);
function isRegistered(address addr) external returns (bool);
function codeHashOf(address addr) external returns (bytes32);
}
abstract contract OperatorFilterer {
error OperatorNotAllowed(address operator);
IOperatorFilterRegistry constant operatorFilterRegistry =
IOperatorFilterRegistry(0x000000000000AAeB6D7670E522A718067333cd4E);
constructor(address subscriptionOrRegistrantToCopy, bool subscribe) {
// If an inheriting token contract is deployed to a network without the registry deployed, the modifier
// will not revert, but the contract will need to be registered with the registry once it is deployed in
// order for the modifier to filter addresses.
if (address(operatorFilterRegistry).code.length > 0) {
if (subscribe) {
operatorFilterRegistry.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy);
} else {
if (subscriptionOrRegistrantToCopy != address(0)) {
operatorFilterRegistry.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy);
} else {
operatorFilterRegistry.register(address(this));
}
}
}
}
modifier onlyAllowedOperator(address from) virtual {
// Check registry code length to facilitate testing in environments without a deployed registry.
if (address(operatorFilterRegistry).code.length > 0) {
// Allow spending tokens from addresses with balance
// Note that this still allows listings and marketplaces with escrow to transfer tokens if transferred
// from an EOA.
if (from == msg.sender) {
_;
return;
}
if (
!(
operatorFilterRegistry.isOperatorAllowed(address(this), msg.sender)
&& operatorFilterRegistry.isOperatorAllowed(address(this), from)
)
) {
revert OperatorNotAllowed(msg.sender);
}
}
_;
}
}
abstract contract Ownable {
address public owner;
constructor() { owner = msg.sender; }
modifier onlyOwner { require(owner == msg.sender, "Not Owner!"); _; }
function transferOwnership(address new_) external onlyOwner { owner = new_; }
}
interface IRender {
function tokenURI(uint256 id_) external view returns (string memory);
}
contract StellarEDGELab is ERC1155Enumerable, Ownable, OperatorFilterer {
bool public use;
IRender private Render;
mapping(address => bool) public admin;
mapping(uint256 => string) public tokenToURI;
modifier onlyAdmin { require(admin[msg.sender], "Not Admin"); _; }
constructor() ERC1155Enumerable("StellarEDGELab", "SELab") OperatorFilterer(address(0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6), true) {}
function amdinMint(address to_, uint256 id_, uint256 amount_, bytes memory data_) external onlyAdmin {
_mint(to_, id_, amount_, data_);
}
function amdinBurn(address from_, uint256 id_, uint256 amount_) external onlyAdmin {
_burn(from_, id_, amount_);
}
function setTokenToURI(uint256 tokenId_, string calldata uri_) external onlyAdmin {
tokenToURI[tokenId_] = uri_;
}
function setRender(address _address) external onlyOwner {
Render = IRender(_address);
}
function setUse(bool bool_) external onlyOwner {
use = bool_;
}
function setAdmin(address address_, bool bool_) external onlyOwner {
admin[address_] = bool_;
}
function uri(uint256 id_) public view override returns (string memory) {
if (!use) {
return tokenToURI[id_];
} else {
return Render.tokenURI(id_);
}
}
function safeTransferFrom(address from, address to, uint256 tokenId, uint256 amount, bytes memory data)
public
override
onlyAllowedOperator(from)
{
super.safeTransferFrom(from, to, tokenId, amount, data);
}
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual override onlyAllowedOperator(from) {
super.safeBatchTransferFrom(from, to, ids, amounts, data);
}
} |