Skip to content

Instantly share code, notes, and snippets.

@mwaqasaslam
Created September 13, 2021 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwaqasaslam/384438f39beccc443be171948bb2b37b to your computer and use it in GitHub Desktop.
Save mwaqasaslam/384438f39beccc443be171948bb2b37b 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=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Pausable.sol";
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract DinisiumToken is ERC1155Pausable, Ownable {
using SafeMath for uint256;
struct ITO {
uint256 serialNumForITO;
address ownerOfITO;
uint256 totalSupply;
}
mapping(uint256 => ITO) private ito;
ITO[] private itos;
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)
external
onlyOwner
returns (bool status)
{
bytes memory data = "0x00";
ITO memory i = ITO ({
serialNumForITO : _serialNumForITO,
totalSupply : _totalSupply,
ownerOfITO : msg.sender
});
itos.push(i);
ito[_serialNumForITO] = i;
_mint(msg.sender, _serialNumForITO, _totalSupply, data);
emit ITOCreated(msg.sender, _serialNumForITO, _totalSupply);
return true ;
}
function getBalanceOfITO(uint256 _serialNumForITO)
public
view
onlyOwner
returns (uint256)
{
uint256 balanceOfITO = balanceOf(msg.sender, _serialNumForITO);
return balanceOfITO;
}
function getBalanceBatch (address _ownerOfITO) public view returns(uint256[] memory){
uint256[] memory _serialNumber = getSerial();
uint256[] memory batchBalances = new uint256[](_serialNumber.length);
uint256 i;
for (i= 0; i < _serialNumber.length; ++i) {
batchBalances[i] = balanceOf(_ownerOfITO, _serialNumber[i]);
}
return batchBalances;
}
function getAllITO() public view returns (ITO[] memory) {
return itos;
}
function ItoCreatedByAdmin(address _ownerOfITO) public returns (ITO[] memory) {
for(uint256 i = 0; i <itos.length; i++){
itos[i].ownerOfITO = _ownerOfITO;
}
return itos;
}
function getSerial() internal view returns (uint256[] memory) {
uint256[] memory createdITOs = new uint256[](itos.length);
for(uint256 i = 0; i < itos.length;i++){
createdITOs[i] = itos[i].serialNumForITO;
}
return createdITOs;
}
function increaseSupply(
uint256 _serialNumForITO,
uint256 amount
) external whenNotPaused onlyOwner returns (bool status) {
require(msg.sender != address(0), "Address is zero");
require(
ito[_serialNumForITO].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 amount
) external whenNotPaused onlyOwner returns (bool status) {
require(msg.sender != address(0), "Address is zero");
require(
ito[_serialNumForITO].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
) public whenNotPaused {
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
) external whenNotPaused {
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 rate
) public onlyOwner whenNotPaused {
require(
ito[_serialNumForITO].serialNumForITO == _serialNumForITO,
"Serial number does not exist!!"
);
for (uint256 i = 0; i < _addresses.length; i++) {
uint256 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