Skip to content

Instantly share code, notes, and snippets.

@Turupawn
Created August 9, 2021 18:18
Show Gist options
  • Save Turupawn/60d91fb8e4e1d333916f55ec5ae126ae to your computer and use it in GitHub Desktop.
Save Turupawn/60d91fb8e4e1d333916f55ec5ae126ae to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
contract Router {
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns(uint amountA, uint amountB, uint liquidity) {}
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts) {}
}
contract Factory {
mapping(address => mapping(address => address)) public getPair;
}
contract MyERC20 is ERC20 {
string TOKEN_NAME = "Token";
string TOKEN_SYMBOL = "TKN";
uint256 TOTAL_SUPPLY = 21000000 ether;
address MARKETING_ADDRESS = 0x730bF3B67090511A64ABA060FbD2F7903536321E;
uint256 LIQUIDITY_TX_PERCENTAGE_FEE = 700; // 700 = 7,00%
uint256 MARKETING_TX_PERCENTAGE_FEE = 500; // 500 = 5,00%
//Change this during TESTNET and LIVE
Router router = Router(0xD99D1c33F9fC3444f8101754aBC46c52416550D1); //Testnet: 0xD99D1c33F9fC3444f8101754aBC46c52416550D1 Live: 0x10ED43C718714eb63d5aA57B78B54704E256024E
ERC20 LIQUIDITY_SECOND_PAIR_TOKEN = ERC20(0x07bc1BEee6559D4f0900c08525Ca4F2F53Ce9bbC); // Testnet: 0x07bc1BEee6559D4f0900c08525Ca4F2F53Ce9bbC Live WBNB: 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c
Factory factory = Factory(0x6725F303b657a9451d8BA641348b6761A6CC7a17); // Testnet: 0x6725F303b657a9451d8BA641348b6761A6CC7a17 Live: 0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73
constructor () ERC20(TOKEN_NAME, TOKEN_SYMBOL) {
_mint(msg.sender, TOTAL_SUPPLY);
}
function getPercentage(uint256 number, uint256 percentage) internal pure returns(uint256 result)
{
return number * percentage / 10000;
}
function _afterTokenTransfer(address from, address to, uint256 amount) internal override
{
if(from != address(0) && to != address(0) && from == factory.getPair(address(this),address(LIQUIDITY_SECOND_PAIR_TOKEN)))
{
uint256 liquidity_amount = getPercentage(amount, LIQUIDITY_TX_PERCENTAGE_FEE);
uint256 marketing_amount = getPercentage(amount, MARKETING_TX_PERCENTAGE_FEE);
_burn(to, marketing_amount + liquidity_amount);
_mint(MARKETING_ADDRESS, marketing_amount);
_mint(address(this), liquidity_amount);
swapAndLiquify(liquidity_amount);
}
}
function swapAndLiquify(
uint amount
) internal
{
uint256 first_half = amount/2;
uint256 other_half = amount - first_half;
_approve(address(this),address(router), 99999999999999999999999999999);
LIQUIDITY_SECOND_PAIR_TOKEN.approve(address(router), 99999999999999999999999999999);
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = address(LIQUIDITY_SECOND_PAIR_TOKEN);
router.swapExactTokensForTokens(
other_half,
0,
path,
0x730bF3B67090511A64ABA060FbD2F7903536321E,//address(this),
block.timestamp
);
_mint(address(this), first_half);
router.addLiquidity(
address(this),
address(LIQUIDITY_SECOND_PAIR_TOKEN),
first_half,
LIQUIDITY_SECOND_PAIR_TOKEN.balanceOf(address(this)),
0,
0,
msg.sender,
block.timestamp
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment