Created
February 8, 2023 07:13
-
-
Save puneetkaura/b7a33c4f6d3dfb9a6b7d26e6eb7dc400 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=
This file contains hidden or 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
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
import "hardhat/console.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC20Capped.sol"; | |
// Check this USDC contract - https://gist.github.com/chappjc/350aafb9031f7a66986967bf8ab67d38 | |
// ERC20 with sanctions. Create an ERC20 token that allows an admin to ban specified addresses from sending and receiving tokens. | |
// Block transfer, Block Allowance, Block minting | |
contract SanctionedERC20 is ERC20, ERC20Capped { | |
uint private constant CAP_AMOUNT = 100_000_000; | |
address public immutable ADMIN; | |
mapping(address => bool) public sanctionList; | |
constructor(address _adminAddress) ERC20("GOD", "GOD") ERC20Capped(CAP_AMOUNT) { | |
ADMIN=_adminAddress; | |
} | |
modifier onlyADMIN() { | |
require (msg.sender == ADMIN, "Only Admin"); | |
_; | |
} | |
modifier blacklistCheck(address add){ | |
require(!sanctionList[add], "Blacklisted address"); | |
_; | |
} | |
event BlackListed(address _address); | |
event UnBlackListed(address _address); | |
// event BlackListTxferAttempted(address from, address to, uint amount); | |
function _mint(address to, uint256 amount) internal override(ERC20, ERC20Capped){ | |
super._mint(to, amount); | |
} | |
// Anyone can mint any number of tokens till cap is reached | |
function mint(uint _amount) external returns(bool){ | |
_mint(msg.sender, _amount); | |
return true; | |
} | |
// Admin can sanction an address | |
function addToBlackList(address _sanctionedAddress) external onlyADMIN returns(bool){ | |
sanctionList[_sanctionedAddress] = true; | |
emit BlackListed(_sanctionedAddress); | |
return true; | |
} | |
function removeFromBlackList(address _sanctionedAddress) external onlyADMIN returns(bool){ | |
sanctionList[_sanctionedAddress] = false; | |
emit UnBlackListed(_sanctionedAddress); | |
return true; | |
} | |
function transfer(address to, uint256 amount) public blacklistCheck(to) blacklistCheck(msg.sender) virtual override returns (bool) { | |
address owner = _msgSender(); | |
_transfer(owner, to, amount); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment