You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.8 KiB
Solidity
95 lines
3.8 KiB
Solidity
// SPDX-License-Identifier: UNLICENSED
|
|
pragma solidity ^0.8.13;
|
|
|
|
import {ERC1155} from "solmate/tokens/ERC1155.sol";
|
|
import {Owned} from "solmate/auth/Owned.sol";
|
|
import {Punkhunt} from "./Punkhunt.sol";
|
|
|
|
/**
|
|
@title Zapper
|
|
@author lzamenace.eth
|
|
@notice This contract contains ERC-1155 Zapper tokens (ZAPPER) which are used as
|
|
utility tokens for the Punkhunt NFT project and chain based game.
|
|
Zappers can be "shot" (burned) to "kill" (burn) ZAPPER tokens held by other players.
|
|
@dev All contract functions regarding token burning and minting are limited to
|
|
the Punkhunt interface where the logic and validation resides.
|
|
*/
|
|
contract Zapper is ERC1155, Owned {
|
|
|
|
/// Track the total number of zappers minted
|
|
uint256 public zappersMinted;
|
|
/// Track the number of zappers that have burned
|
|
uint256 public zappersBurned;
|
|
/// Base URI for the zapper image - all zappers use the same image
|
|
string public baseURI;
|
|
/// Contract address of the deployed Punkhunt contract interface to the game
|
|
Punkhunt public punkhunt;
|
|
|
|
constructor() ERC1155() Owned(msg.sender) {}
|
|
|
|
// =========================================================================
|
|
// Admin
|
|
// =========================================================================
|
|
|
|
/// Set metadata URI for all ZAPPER (token 1)
|
|
/// @param _baseURI IPFS hash or URL to retrieve JSON metadata
|
|
function setBaseURI(string calldata _baseURI) external onlyOwner {
|
|
baseURI = _baseURI;
|
|
}
|
|
|
|
/// Set punkhunt contract address for executing functions
|
|
/// @param _address Contract address of the deployed Punkhunt contract
|
|
function setPunkhuntContract(address _address) external onlyOwner {
|
|
punkhunt = Punkhunt(_address);
|
|
}
|
|
|
|
// =========================================================================
|
|
// Modifiers
|
|
// =========================================================================
|
|
|
|
/// Limit function execution to deployed Punkhunt contract
|
|
modifier onlyPunkhunt {
|
|
require(msg.sender == address(punkhunt), "invalid msg sender");
|
|
_;
|
|
}
|
|
|
|
// =========================================================================
|
|
// Tokens
|
|
// =========================================================================
|
|
|
|
/// Mint tokens from punkhunt contract
|
|
/// @param _to Address to mint ZAPPER tokens to
|
|
/// @param _amount Amount of ZAPPER tokens to mint
|
|
function mint(address _to, uint256 _amount) external onlyPunkhunt {
|
|
zappersMinted += _amount;
|
|
super._mint(_to, 1, _amount, "");
|
|
}
|
|
|
|
/// Burn spent tokens from punkhunt contract
|
|
/// @param _from Address to burn ZAPPER tokens from
|
|
/// @param _amount Amount of ZAPPER tokens to burn
|
|
function burn(address _from, uint256 _amount) external onlyPunkhunt {
|
|
zappersBurned += _amount;
|
|
super._burn(_from, 1, _amount);
|
|
}
|
|
|
|
/// Get the total amount of ZAPPER that has been minted
|
|
/// @return supply Amount of ZAPPER minted
|
|
function totalSupply() public view returns (uint256 supply) {
|
|
return zappersMinted;
|
|
}
|
|
|
|
/// Return URI to retrieve JSON metadata from - points to images and descriptions
|
|
/// @param _tokenId Unused as all zappers point to same metadata URI
|
|
/// @return string IPFS or HTTP URI to retrieve JSON metadata from
|
|
function uri(uint256 _tokenId) public view override returns (string memory) {
|
|
return baseURI;
|
|
}
|
|
|
|
/// Checks if contract supports a given interface
|
|
/// @param interfaceId The interface ID to check if contract supports
|
|
/// @return bool Boolean value if contract supports interface ID or not
|
|
function supportsInterface(bytes4 interfaceId) public view virtual override (ERC1155) returns (bool) {
|
|
return super.supportsInterface(interfaceId);
|
|
}
|
|
} |