Skip to content

Instantly share code, notes, and snippets.

@phinett
Last active August 22, 2022 19:40
Show Gist options
  • Save phinett/6678b371f16c3b5ffc53c9fa5a32b6be to your computer and use it in GitHub Desktop.
Save phinett/6678b371f16c3b5ffc53c9fa5a32b6be to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
//.
pragma solidity ^0.8.10;
// Import the IERC20 interface and and SafeMath library
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
contract GeminiToken is ERC20, Ownable {
using SafeMath for uint256;
address public constant deadAddress = address(0xdead);
bool public tradingActive = false;
uint256 public maxWallet;
uint256 public initialSupply;
mapping (address => bool) public automatedMarketMakerPairs;
event SetAutomatedMarketMakerPair(address indexed pair, bool indexed value);
constructor() ERC20("Gemini", "GEM")
{
initialSupply = 100000000*1e18;
maxWallet = initialSupply * 2 / 100; // 2% maxWallet
_mint(owner(), initialSupply);
}
receive() external payable {
}
// Launch
function init() external onlyOwner {
require(!tradingActive, "Trading is already active");
tradingActive = true;
}
function pauseTrading() external onlyOwner {
tradingActive = false;
}
function resumeTrading() external onlyOwner {
tradingActive = true;
}
function updateMaxWalletAmount(uint256 newNum) external onlyOwner {
require(newNum >= (totalSupply() * 5 / 1000)/1e18, "Cannot set maxWallet lower than 0.5%");
maxWallet = newNum * (10**18);
}
function setAutomatedMarketMakerPair(address pair, bool value) public onlyOwner {
//require(pair != uniswapV2Pair, "The pair cannot be removed from automatedMarketMakerPairs");
automatedMarketMakerPairs[pair] = value;
emit SetAutomatedMarketMakerPair(pair, value);
}
function _transfer(
address from,
address to,
uint256 amount
) internal override {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
if(amount == 0) {
super._transfer(from, to, 0);
return;
}
if (
from != owner() &&
to != owner() &&
to != address(0) &&
to != address(0xdead)
){
require(tradingActive, 'Trading is not active');
//when buy
if (automatedMarketMakerPairs[from]) {
require(amount + balanceOf(to) <= maxWallet, "Max wallet exceeded");
}
//when transfer
if (!(automatedMarketMakerPairs[to)] && !(automatedMarketMakerPairs[from])) {
require(amount + balanceOf(to) <= maxWallet, "Max wallet exceeded");
}
}
super._transfer(from, to, amount);
}
function withdrawEth() external onlyOwner {
bool success;
(success,) = address(msg.sender).call{value: address(this).balance}("");
}
function emergencyRescueToken(address token) public onlyOwner{
IERC20(token).transfer(owner(), IERC20(token).balanceOf(address(this)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment