Skip to content

Instantly share code, notes, and snippets.

@mwaqasaslam
Created September 8, 2021 12:18
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/34bdfb4dfde0d61973b5b3cddf9ba20e to your computer and use it in GitHub Desktop.
Save mwaqasaslam/34bdfb4dfde0d61973b5b3cddf9ba20e 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=
// 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;
uint256 private idForITO;
struct ITO {
uint256 serialNumForITO;
uint256 id;
uint256 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)
external
onlyOwner
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)
public
view
onlyOwner
returns (uint256)
{
uint256 balanceOfITO = balanceOf(msg.sender, _serialNumForITO);
return balanceOfITO;
}
function getBalanceBatch (address account, uint256[] memory _serialNumber) public view onlyOwner returns(uint256[] memory){
uint256[] memory batchBalances = new uint256[](_serialNumber.length);
for (uint256 i = 0; i < _serialNumber.length; ++i) {
batchBalances[i] = balanceOf(account, _serialNumber[i]);
}
return batchBalances;
}
function getAllITO() public view returns (ITO[] memory) {
return ito;
}
function increaseSupply(
uint256 _serialNumForITO,
uint256 _idForITO,
uint256 amount
) external whenNotPaused onlyOwner 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
) external whenNotPaused onlyOwner 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
) 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 _idForITO,
uint256 rate
) public onlyOwner whenNotPaused {
require(
itos[_idForITO].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