Skip to content

Instantly share code, notes, and snippets.

@ArslanKathia
Created February 23, 2023 16:57
Show Gist options
  • Save ArslanKathia/e8cf62dabaf0d1ba31554fa1b0b43b6d to your computer and use it in GitHub Desktop.
Save ArslanKathia/e8cf62dabaf0d1ba31554fa1b0b43b6d 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.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20FlashMint.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Snapshot.sol";
/// @custom:security contact [email protected]
contract ShaniToken is ERC20,Pausable,AccessControl,ERC20Permit,ERC20Snapshot,ERC20FlashMint{
bytes32 public constant SNAPSHOT_ROLE = keccak256("SNAPSHOT_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
/**
Fixed Supply
**/
constructor() ERC20("SCoin","SCO") ERC20Permit("SCoin"){
//_mint(msg.sender,1000*10**18);
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(SNAPSHOT_ROLE,msg.sender);
_grantRole(PAUSER_ROLE,msg.sender);
_grantRole(MINTER_ROLE, msg.sender);
}
function mint(address to,uint256 amount) public onlyRole(MINTER_ROLE){
_mint(to,amount); //create new token
}
function snapshot() public onlyRole(SNAPSHOT_ROLE){
_snapshot();
}
function pause() public onlyRole(PAUSER_ROLE){
_pause(); //pause the token transaction
}
function unpause() public onlyRole(PAUSER_ROLE){
_unpause(); //unpause the token transaction
}
function _beforeTokenTransfer(address from,address to,uint256 amount)
internal
whenNotPaused
override(ERC20,ERC20Snapshot)
{
super._beforeTokenTransfer(from,to,amount);
}
/**
Uncapped lazy supply
**/
// constructor() ERC20("SCoin","SCO"){}
// function issueToken() public onlyOwner{
// _mint(msg.sender,1000*10**18);
// }
// function issueToken(address receiver,uint256 amount) public onlyOwner{
// _mint(receiver,amount*10**decimals());
// }
}
/**
capped modular supply
**/
contract ShaniToken1 is ERC20Capped,AccessControl{
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
constructor(uint256 cap) ERC20("SCoin","SCO") ERC20Capped(cap){
_grantRole(MINTER_ROLE,msg.sender);
}
function issueToken() public onlyRole(MINTER_ROLE){
_mint(msg.sender,100*10**decimals());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment