// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
/**
* @title ERC1155 SBT
* @author 0xSumo @PBADAO
*/
pragma solidity ^0.8.0;
abstract contract OwnControll {
address public owner;
mapping(address => bool) public admin;
modifier onlyOwner { require(owner == msg.sender, "Not Owner"); _; }
modifier onlyAdmin { require(admin[msg.sender], "Not Admin"); _; }
constructor() { owner = msg.sender; }
function transferOwnership(address new_) external onlyOwner { owner = new_; }
function setAdmin(address address_, bool bool_) external onlyOwner { admin[address_] = bool_; }
}
abstract contract ERC1155URI {
mapping(uint256 => string) public tokenToURI;
function _setTokenToURI(uint256 tokenId_, string memory uri_) internal virtual {
tokenToURI[tokenId_] = uri_;
}
}
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);
}
contract SUNINSTALLATIONCOLLECTION is OwnControll, ERC1155URI {
string public name = "SUN INSTALLATION COLLECTION";
string public symbol = "SIC";
mapping(address => mapping(uint256 => uint256)) public balanceOf;
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_);
constructor() {}
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 _mintInternal(address to_, uint256 id_, uint256 amount_) internal {
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_;
}
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 _isSameLength(uint256 a, uint256 b) internal pure returns (bool) {
return a == b;
}
function mintToken(address to_, uint256 id_, uint256 amount_, bytes memory data_) external onlyAdmin {
_mint(to_, id_, amount_, data_);
}
function mintBatch(address[] calldata to_, uint256 id_, uint256[] memory amount_, bytes memory data_) external onlyOwner {
require(_isSameLength(to_.length, amount_.length));
for (uint256 i = 0; i < to_.length;) {
_mint(to_[i], id_, amount_[i], data_);
unchecked { ++i; }
}
}
function mintTokenBatch(address to_, uint256[] memory ids_, uint256[] memory amounts_, bytes memory data_) external onlyAdmin {
_batchMint(to_, ids_, amounts_, data_);
}
function burnToken(address from_, uint256 id_, uint256 amount_) external onlyAdmin {
_burn(from_, id_, amount_);
}
function burnTokenBatch(address from_, uint256[] memory ids_, uint256[] memory amounts_) external onlyAdmin {
_batchBurn(from_, ids_, amounts_);
}
function supportsInterface(bytes4 interfaceId_) public pure virtual returns (bool) {
return interfaceId_ == 0x01ffc9a7 || interfaceId_ == 0xd9b67a26 || interfaceId_ == 0x0e89341c;
}
function setURI(uint256 tokenId_, string memory uri_) external onlyAdmin {
_setTokenToURI(tokenId_, uri_);
}
function uri(uint256 id_) public virtual view returns (string memory) {
return tokenToURI[id_];
}
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;
}
}
{
"compilationTarget": {
"SUNINSTALLATIONCOLLECTION.sol": "SUNINSTALLATIONCOLLECTION"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator_","type":"address"},{"indexed":true,"internalType":"address","name":"from_","type":"address"},{"indexed":true,"internalType":"address","name":"to_","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"ids_","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"amounts_","type":"uint256[]"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator_","type":"address"},{"indexed":true,"internalType":"address","name":"from_","type":"address"},{"indexed":true,"internalType":"address","name":"to_","type":"address"},{"indexed":false,"internalType":"uint256","name":"id_","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"TransferSingle","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"admin","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"owners_","type":"address[]"},{"internalType":"uint256[]","name":"ids_","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from_","type":"address"},{"internalType":"uint256","name":"id_","type":"uint256"},{"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"burnToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from_","type":"address"},{"internalType":"uint256[]","name":"ids_","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts_","type":"uint256[]"}],"name":"burnTokenBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"to_","type":"address[]"},{"internalType":"uint256","name":"id_","type":"uint256"},{"internalType":"uint256[]","name":"amount_","type":"uint256[]"},{"internalType":"bytes","name":"data_","type":"bytes"}],"name":"mintBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to_","type":"address"},{"internalType":"uint256","name":"id_","type":"uint256"},{"internalType":"uint256","name":"amount_","type":"uint256"},{"internalType":"bytes","name":"data_","type":"bytes"}],"name":"mintToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to_","type":"address"},{"internalType":"uint256[]","name":"ids_","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts_","type":"uint256[]"},{"internalType":"bytes","name":"data_","type":"bytes"}],"name":"mintTokenBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"address_","type":"address"},{"internalType":"bool","name":"bool_","type":"bool"}],"name":"setAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId_","type":"uint256"},{"internalType":"string","name":"uri_","type":"string"}],"name":"setURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId_","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokenToURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"new_","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id_","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]