Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sashadev-sky/acdfe781172138c507158ee7fb4899ce to your computer and use it in GitHub Desktop.
Save sashadev-sky/acdfe781172138c507158ee7fb4899ce to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155SupplyUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
/**
* @title OneV
* @dev pre-mint 3 tokens
*/
contract OneVU is Initializable, ERC1155Upgradeable, AccessControlUpgradeable, PausableUpgradeable, ERC1155BurnableUpgradeable, ERC1155SupplyUpgradeable {
// these state variables and their values
// will be preserved forever, regardless of upgrading
bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
uint256 public constant Rock = 1;
uint256 public constant Paper = 2;
uint256 public constant Scissors = 3;
/// @custom:oz-upgrades-unsafe-allow constructor
// constructor() initializer {
/**
* NOTE: putting these in initialize doesn't work, they just don't get minted. In the constructor, they
* are minted on the **implementation contract** address.
**/
// _mint(msg.sender, Rock, 1, "");
// _mint(msg.sender, Paper, 1, "");
// _mint(msg.sender, Scissors, 1, "");
// }
function initialize() initializer public {
__ERC1155_init("https://ipfs.io/ipfs/bafybeigo7inkcatifkwgydozhmz5ms4ebco7bq7ccu25w33smvr52dq6o4/{id}.json");
__AccessControl_init();
__Pausable_init();
__ERC1155Burnable_init();
__ERC1155Supply_init();
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(URI_SETTER_ROLE, msg.sender);
_grantRole(PAUSER_ROLE, msg.sender);
_grantRole(MINTER_ROLE, msg.sender);
_mint(msg.sender, Rock, 1, "");
_mint(msg.sender, Paper, 1, "");
_mint(msg.sender, Scissors, 1, "");
}
function setURI(string memory newuri) public onlyRole(URI_SETTER_ROLE) {
_setURI(newuri);
}
function pause() public onlyRole(PAUSER_ROLE) {
_pause();
}
function unpause() public onlyRole(PAUSER_ROLE) {
_unpause();
}
// anybody with a wallet address can mint
function mint(address account, uint256 id, uint256 amount, bytes memory data) public {
_mint(account, id, amount, data);
}
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
public
onlyRole(MINTER_ROLE)
{
_mintBatch(to, ids, amounts, data);
}
function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
internal
whenNotPaused
override(ERC1155Upgradeable, ERC1155SupplyUpgradeable)
{
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
}
// The following functions are overrides required by Solidity.
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC1155Upgradeable, AccessControlUpgradeable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
function uri(uint256 _tokenid) override public pure returns (string memory) {
return string(
abi.encodePacked(
"https://ipfs.io/ipfs/bafybeigo7inkcatifkwgydozhmz5ms4ebco7bq7ccu25w33smvr52dq6o4/",
Strings.toString(_tokenid),".json"
)
);
}
function contractURI() public pure returns (string memory) {
return "https://ipfs.io/ipfs/bafkreiddo6pmuztmwcnesdadyqwmioupfuwv7lli5bjzovy4ztn3yzvt54";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment