Created
August 16, 2021 13:57
-
-
Save mwaqasaslam/3d910c2aa506272d19affd199b79612d to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.0+commit.c7dfd78e.js&optimize=true&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// contracts/GameItems.sol | |
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
// import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/extensions/ERC1155Pausable.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol"; | |
import "github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeMath.sol"; | |
contract DinisiumToken is ERC1155Pausable, Ownable { | |
using SafeMath for uint256; | |
uint256 private idForITO; | |
struct ITO { | |
uint serialNumForITO; | |
uint id; | |
uint totalSupply; | |
} | |
mapping (uint256 => ITO) private itos; | |
ITO [] private ito; | |
event ITOCreated(address mintedOn, uint256 id, uint256 mintedTokens); | |
event SupplyIncreased(address mintedOn, uint256 id, uint256 mintedTokens); | |
event Supplydecreased(address burnedBy,uint256 id, uint256 burnedTokens); | |
event PausedContract(address pauseddBy); | |
event UnpausedContract(address unpausedBy); | |
event SingleTokenTransfer(address from, address to, uint256 id, uint256 amount); | |
event BatchTokensTransfer(address from, address to, uint256[] ids, uint256[] amounts); | |
constructor() ERC1155("DinisiumToken") { | |
} | |
function createITO(uint256 _serialNumForITO, uint256 _totalSupply) onlyOwner external returns(uint256) { | |
bytes memory data = "0x00"; | |
ITO memory i; | |
idForITO = idForITO + 1; | |
i.serialNumForITO = _serialNumForITO; | |
i.totalSupply = _totalSupply; | |
i.id = idForITO; | |
ito.push(i); | |
itos[idForITO] = i; | |
_mint(msg.sender, _serialNumForITO, _totalSupply, data); | |
emit ITOCreated(msg.sender, _serialNumForITO, _totalSupply); | |
return idForITO; | |
} | |
function getBalanceOfITO(uint256 _serialNumForITO) onlyOwner public view returns (uint256){ | |
uint256 balanceOfITO = balanceOf(msg.sender, _serialNumForITO); | |
return balanceOfITO; | |
} | |
function getAllITO() public view returns(ITO [] memory) { | |
return ito; | |
} | |
function increaseSupply (uint256 _serialNumForITO,uint256 _idForITO, uint256 amount) whenNotPaused onlyOwner external returns (bool status) { | |
require (msg.sender != address(0), "Address is zero"); | |
require(itos[_idForITO].serialNumForITO == _serialNumForITO, "Serial number does not exist!!"); | |
_mint (msg.sender, _serialNumForITO, amount, ""); | |
emit SupplyIncreased(msg.sender, _serialNumForITO, amount); | |
return true; | |
} | |
function decreaseSupply (uint256 _serialNumForITO,uint256 _idForITO, uint256 amount) whenNotPaused onlyOwner external returns (bool status) { | |
require (msg.sender != address(0), "Address is zero"); | |
require(itos[_idForITO].serialNumForITO == _serialNumForITO, "Serial number does not exist!!"); | |
_burn(msg.sender, _serialNumForITO, amount); | |
emit Supplydecreased(msg.sender, _serialNumForITO, amount); | |
return true; | |
} | |
function transferSingle (address from, address to, uint256 _serialNumForITO, uint256 amount) whenNotPaused public { | |
bytes memory data = '0x00'; | |
safeTransferFrom(from, to, _serialNumForITO, amount, data); | |
emit SingleTokenTransfer(from, to, _serialNumForITO, amount); | |
} | |
function transferBatch ( address from, address to, uint256[] memory _serialNumForITO, uint256[] memory amounts) whenNotPaused external { | |
bytes memory data = '0x00'; | |
safeBatchTransferFrom(from, to, _serialNumForITO, amounts, data); | |
emit BatchTokensTransfer(from, to, _serialNumForITO, amounts); | |
} | |
function pauseContract () public onlyOwner returns (bool status) { | |
_pause(); | |
emit PausedContract(msg.sender); | |
return true; | |
} | |
function unpauseContract () public onlyOwner returns (bool status) { | |
_unpause(); | |
emit UnpausedContract(msg.sender); | |
return true; | |
} | |
function airDrop(address from, address[] memory addresses, uint256 _serialNumForITO,uint256 _idForITO, uint256 rate) public onlyOwner whenNotPaused { | |
require(itos[_idForITO].serialNumForITO == _serialNumForITO, "Serial number does not exist!!"); | |
for(uint i=0;i<addresses.length;i++){ | |
uint value = balanceOf(addresses[i],_serialNumForITO); | |
if(value !=0){ | |
transferSingle(from,addresses[i], _serialNumForITO, value.mul(rate)); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment