Address Contract Verified
Address
0x9a67F5E015f838b911f2d13566e4BE05C5BA777F
Balance
2.1723 ETH
Nonce
154
Code Size
8102 bytes
Creator
0xa8c6524f...81f5 at tx 0x6f1095a7...1177ea
Indexed Transactions
0
Contract Bytecode
8102 bytes
0x6080604052600436106101395760003560e01c80637e051867116100ab578063ca4419331161006f578063ca441933146104f0578063d771775014610510578063dbdcf0c514610544578063ee99205c14610564578063f0685ef414610584578063f2fde38b146105a457600080fd5b80637e0518671461043d5780638da5cb5b1461047d5780638ddb0a3c1461049b5780639d67ac37146104bb578063aed5c7b2146104db57600080fd5b806365436cd8116100fd57806365436cd81461035357806368930637146103885780636dca7e7b146103a8578063715018a6146103db5780637a72f06f146103f05780637df326471461041057600080fd5b80631d12b9381461024a578063200952b11461027a5780632b67d122146102d457806352c3e349146102f6578063629c52a91461033d57600080fd5b366102455733737a250d5630b4cf539739df2c5dacb4c659f2488c19810161015d57005b6001600160a01b03811660009081526005602052604090205460ff1661019e5760405162461bcd60e51b8152600401610195906117be565b60405180910390fd5b6001600160a01b038116600090815260056020526040812060030180543492906101c99084906117fb565b90915550600090506101da826105c4565b90508015801561021957506001600160a01b038216600090815260056020526040812060029081015460ff16908111156102165761021661180e565b14155b1561024357600061022b600534611824565b90506102418361023b8334611846565b836108a1565b505b005b600080fd5b61025d6102583660046118fc565b610b31565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561028657600080fd5b506102c4610295366004611975565b600560205260009081526040902080546001820154600283015460039093015460ff9283169391929091169084565b6040516102719493929190611992565b3480156102e057600080fd5b506102e9610d33565b6040516102719190611a22565b34801561030257600080fd5b5061032f610311366004611975565b6001600160a01b031660009081526005602052604090206001015490565b604051908152602001610271565b34801561034957600080fd5b5061032f60025481565b34801561035f57600080fd5b5061037361036e366004611975565b610d52565b60408051928352602083019190915201610271565b34801561039457600080fd5b5060035461025d906001600160a01b031681565b3480156103b457600080fd5b506003546103c990600160a01b900460ff1681565b60405160ff9091168152602001610271565b3480156103e757600080fd5b50610243610d90565b3480156103fc57600080fd5b5061024361040b366004611975565b610da4565b34801561041c57600080fd5b5061043061042b366004611975565b610ddd565b6040516102719190611a35565b34801561044957600080fd5b5061046d610458366004611975565b60076020526000908152604090205460ff1681565b6040519015158152602001610271565b34801561048957600080fd5b506000546001600160a01b031661025d565b3480156104a757600080fd5b506102436104b6366004611a90565b610e53565b3480156104c757600080fd5b506102436104d6366004611975565b610e86565b3480156104e757600080fd5b506102e961147e565b3480156104fc57600080fd5b5061025d61050b366004611ac9565b61150c565b34801561051c57600080fd5b5061025d7f0000000000000000000000007af9ac1fdb60caf6510af1944f8b4b21f0fe924481565b34801561055057600080fd5b5061024361055f366004611af5565b611544565b34801561057057600080fd5b5060045461025d906001600160a01b031681565b34801561059057600080fd5b5061024361059f366004611975565b6115d0565b3480156105b057600080fd5b506102436105bf366004611975565b61161a565b6000806001600160a01b038316600090815260056020526040902060029081015460ff16908111156105f8576105f861180e565b1461060557506000919050565b60008061061184610d52565b91509150670de0b6b3a76400008210610897576001600160a01b038416600090815260056020526040902060020180546001919060ff19168280021790555060007f0000000000000000000000005c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f6001600160a01b031663e6a4390586737a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f89190611b29565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401602060405180830381865afa158015610743573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107679190611b29565b6040516370a0823160e01b81523060048201529091506001600160a01b0382169063a9059cbb9060009083906370a0823190602401602060405180830381865afa1580156107b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107dd9190611b46565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af1158015610828573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061084c9190611b5f565b506108588584846108a1565b6040516001600160a01b038616907fd4e33cc44d62fd42ca319b12d301e987973512f0467fbb68713dddaa52fc127890600090a2506001949350505050565b5060009392505050565b81156109ad576000836001600160a01b031663d5f394886040518163ffffffff1660e01b8152600401602060405180830381865afa1580156108e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061090b9190611b29565b6001600160a01b03168360405160006040518083038185875af1925050503d8060008114610955576040519150601f19603f3d011682016040523d82523d6000602084013e61095a565b606091505b50509050806109ab5760405162461bcd60e51b815260206004820152601960248201527f4661696c656420746f20726566756e64206465706c6f796572000000000000006044820152606401610195565b505b8015610b2c576003546000906064906109d1908490600160a01b900460ff16611b7c565b6109db9190611824565b905060006109e98284611846565b90508015610a8a576003546040516000916001600160a01b03169083908381818185875af1925050503d8060008114610a3e576040519150601f19603f3d011682016040523d82523d6000602084013e610a43565b606091505b5050905080610a885760405162461bcd60e51b815260206004820152601160248201527011985a5b1959081d1bc8199bdc9dd85c99607a1b6044820152606401610195565b505b8115610b29576004546040516000916001600160a01b03169084908381818185875af1925050503d8060008114610add576040519150601f19603f3d011682016040523d82523d6000602084013e610ae2565b606091505b5050905080610b275760405162461bcd60e51b815260206004820152601160248201527011985a5b1959081d1bc8199bdc9dd85c99607a1b6044820152606401610195565b505b50505b505050565b6000323314610b6c5760405162461bcd60e51b81526020600482015260076024820152664e6f7420454f4160c81b6044820152606401610195565b336000610b77611658565b90506000816001600160a01b0316346390657147858989604051602401610ba093929190611b93565b6040516020818303038152906040529060e01b6020820180516001600160e01b038381831617835250505050604051610bd99190611bd3565b60006040518083038185875af1925050503d8060008114610c16576040519150601f19603f3d011682016040523d82523d6000602084013e610c1b565b606091505b5050905080610c6c5760405162461bcd60e51b815260206004820152601860248201527f4572726f7220696e697469616c697a696e6720746f6b656e00000000000000006044820152606401610195565b6001600160a01b0382166000908152600560205260409020805460ff19166001908117909155600254610c9f9190611846565b6001600160a01b03808416600081815260056020908152604080832060019081019690965593881680835260068252848320805496870181558352912090930180546001600160a01b0319168217905590517fd5d05a8421149c74fd223cfc823befb883babf9bf0b0e4d6bf9c8fdb70e59bb490610d20908a908a90611bef565b60405180910390a3509150505b92915050565b6040518061030001604052806102dc8152602001611c956102dc913981565b6001600160a01b03811660009081526005602081905260408220600301548291610d7c9082611824565b9150610d888282611846565b925050915091565b610d98611729565b610da26000611756565b565b6003546001600160a01b03163314610dbb57600080fd5b600380546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b038116600090815260066020908152604091829020805483518184028101840190945280845260609392830182828015610e4757602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610e29575b50505050509050919050565b610e5b611729565b6001600160a01b03919091166000908152600760205260409020805460ff1916911515919091179055565b6001600160a01b03811660009081526005602052604090205460ff161515600114610ec35760405162461bcd60e51b8152600401610195906117be565b806001600160a01b031663d5f394886040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f259190611b29565b6001600160a01b0316336001600160a01b03161480610f5357503360009081526007602052604090205460ff165b610f8e5760405162461bcd60e51b815260206004820152600c60248201526b155b985d5d1a1bdc9a5e995960a21b6044820152606401610195565b6001600160a01b038116600090815260056020526040812060029081015460ff1690811115610fbf57610fbf61180e565b14610fc75750565b610fd0816105c4565b15610fd85750565b62015180816001600160a01b03166365cf7c9b6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561101a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061103e9190611b46565b6110489042611846565b116110955760405162461bcd60e51b815260206004820152601960248201527f546f6b656e206e6f7420726561647920746f20726566756e64000000000000006044820152606401610195565b6001600160a01b03811660009081526005602052604090206002908101805460ff1916600183021790555060007f0000000000000000000000005c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f6001600160a01b031663e6a4390583737a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015611144573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111689190611b29565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401602060405180830381865afa1580156111b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111d79190611b29565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038316906370a0823190602401602060405180830381865afa158015611221573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112459190611b46565b60405163095ea7b360e01b8152737a250d5630b4cf539739df2c5dacb4c659f2488d6004820152602481018290529091506001600160a01b0383169063095ea7b3906044016020604051808303816000875af11580156112a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112cd9190611b5f565b50604051629d473b60e21b81526001600160a01b038416600482015260248101829052600060448201819052606482018190523060848301524260a4830152908190737a250d5630b4cf539739df2c5dacb4c659f2488d906302751cec9060c40160408051808303816000875af115801561134c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113709190611c1d565b604051630852cd8d60e31b81526004810183905291935091506001600160a01b038616906342966c6890602401600060405180830381600087803b1580156113b757600080fd5b505af11580156113cb573d6000803e3d6000fd5b5050505060006113e382670de0b6b3a76400006117a6565b90506000670de0b6b3a764000083116113fd57600061140f565b61140f670de0b6b3a764000084611846565b905060008061141d89610d52565b909250905061143f8961143084876117fb565b61143a84876117fb565b6108a1565b6040516001600160a01b038a16907f02977011f209407fe8af1ffe4b4a45b806f4db3c525595f0a55c1e7fe17f3f5590600090a2505050505050505050565b6001805461148b90611c41565b80601f01602080910402602001604051908101604052809291908181526020018280546114b790611c41565b80156115045780601f106114d957610100808354040283529160200191611504565b820191906000526020600020905b8154815290600101906020018083116114e757829003601f168201915b505050505081565b6006602052816000526040600020818154811061152857600080fd5b6000918252602090912001546001600160a01b03169150829050565b61154c611729565b60648160ff16111561158f5760405162461bcd60e51b815260206004820152600c60248201526b496e76616c6964206665657360a01b6044820152606401610195565b6003805460ff909216600160a01b0260ff60a01b19909216919091179055600480546001600160a01b039092166001600160a01b0319909216919091179055565b6001600160a01b03811660009081526005602052604090205460ff16151560011461160d5760405162461bcd60e51b8152600401610195906117be565b611616816105c4565b5050565b611622611729565b6001600160a01b03811661164c57604051631e4fbdf760e01b815260006004820152602401610195565b61165581611756565b50565b6000806001805461166890611c41565b80601f016020809104026020016040519081016040528092919081815260200182805461169490611c41565b80156116e15780601f106116b6576101008083540402835291602001916116e1565b820191906000526020600020905b8154815290600101906020018083116116c457829003601f168201915b50505050509050600060025460001b9050806101f78301528151602083016000f09250823b61170f57600080fd5b6002805490600061171f83611c7b565b9190505550505090565b6000546001600160a01b03163314610da25760405163118cdaa760e01b8152336004820152602401610195565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60008183106117b557816117b7565b825b9392505050565b6020808252600d908201526c2ab735b737bbb7103a37b5b2b760991b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b80820180821115610d2d57610d2d6117e5565b634e487b7160e01b600052602160045260246000fd5b60008261184157634e487b7160e01b600052601260045260246000fd5b500490565b81810381811115610d2d57610d2d6117e5565b634e487b7160e01b600052604160045260246000fd5b600082601f83011261188057600080fd5b813567ffffffffffffffff8082111561189b5761189b611859565b604051601f8301601f19908116603f011681019082821181831017156118c3576118c3611859565b816040528381528660208588010111156118dc57600080fd5b836020870160208301376000602085830101528094505050505092915050565b6000806040838503121561190f57600080fd5b823567ffffffffffffffff8082111561192757600080fd5b6119338683870161186f565b9350602085013591508082111561194957600080fd5b506119568582860161186f565b9150509250929050565b6001600160a01b038116811461165557600080fd5b60006020828403121561198757600080fd5b81356117b781611960565b84151581526020810184905260808101600384106119c057634e487b7160e01b600052602160045260246000fd5b60408201939093526060015292915050565b60005b838110156119ed5781810151838201526020016119d5565b50506000910152565b60008151808452611a0e8160208601602086016119d2565b601f01601f19169290920160200192915050565b6020815260006117b760208301846119f6565b6020808252825182820181905260009190848201906040850190845b81811015611a765783516001600160a01b031683529284019291840191600101611a51565b50909695505050505050565b801515811461165557600080fd5b60008060408385031215611aa357600080fd5b8235611aae81611960565b91506020830135611abe81611a82565b809150509250929050565b60008060408385031215611adc57600080fd5b8235611ae781611960565b946020939093013593505050565b60008060408385031215611b0857600080fd5b8235611b1381611960565b9150602083013560ff81168114611abe57600080fd5b600060208284031215611b3b57600080fd5b81516117b781611960565b600060208284031215611b5857600080fd5b5051919050565b600060208284031215611b7157600080fd5b81516117b781611a82565b8082028115828204841417610d2d57610d2d6117e5565b6001600160a01b0384168152606060208201819052600090611bb7908301856119f6565b8281036040840152611bc981856119f6565b9695505050505050565b60008251611be58184602087016119d2565b9190910192915050565b604081526000611c0260408301856119f6565b8281036020840152611c1481856119f6565b95945050505050565b60008060408385031215611c3057600080fd5b505080516020909101519092909150565b600181811c90821680611c5557607f821691505b602082108103611c7557634e487b7160e01b600052602260045260246000fd5b50919050565b600060018201611c8d57611c8d6117e5565b506001019056fe60a060405234801561000f575f80fd5b506040516102dc3803806102dc833981810160405281019061003191906100c9565b8073ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff1681525050506100f4565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6100988261006f565b9050919050565b6100a88161008e565b81146100b2575f80fd5b50565b5f815190506100c38161009f565b92915050565b5f602082840312156100de576100dd61006b565b5b5f6100eb848285016100b5565b91505092915050565b6080516101cb6101115f395f81816030015260ea01526101cb5ff3fe60806040526004361061002c575f3560e01c8063629c52a914610070578063d77177501461009a5761002d565b5b5f7f00000000000000000000000000000000000000000000000000000000000000009050365f80375f80365f845af43d5f803e805f811461006c573d5ff35b3d5ffd5b34801561007b575f80fd5b506100846100c4565b6040516100919190610124565b60405180910390f35b3480156100a5575f80fd5b506100ae6100e8565b6040516100bb919061017c565b60405180910390f35b7f10eeeeffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81565b7f000000000000000000000000000000000000000000000000000000000000000081565b5f819050919050565b61011e8161010c565b82525050565b5f6020820190506101375f830184610115565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6101668261013d565b9050919050565b6101768161015c565b82525050565b5f60208201905061018f5f83018461016d565b9291505056fea26469706673582212208caaf51ee3f849b605f6e63e26072b5c076726d07d40423546787cda62f1dc5b64736f6c63430008140033a264697066735822122068299090ac3274951cdd2efd4e6d776c68ef2d728eaf6c2310a8e38938ea1ade64736f6c63430008140033
Verified Source Code Full Match
Compiler: v0.8.20+commit.a1b79de6
EVM: paris
Optimization: Yes (200 runs)
TokenLogic.sol 189 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/*
┌─────────────────────────────────────────────────────────────────────────┐
│ │
│ _______ ______ _ │
│ |__ __| | ____| (_) │
│ | | __ ___ _| |__ __ _ _ __ _ __ ___ _ _ __ __ _ │
│ | |/ _` \ \/ / __/ _` | '__| '_ ` _ \ | | '_ \ / _` | │
│ | | (_| |> <| | | (_| | | | | | | | | | | | | | (_| | │
│ |_|\__,_/_/\_\_| \__,_|_| |_| |_| |_|(_)_|_| |_|\__, | │
│ __/ | │
│ |___/ │
│ │
│ taxfarm.ing │
│ │
└─────────────────────────────────────────────────────────────────────────┘
*/
// utils
import {ERC20Logic} from "./utils/ERC20Logic.sol";
import {IUniswapV2Router02} from "./utils/IUniswapV2Router02.sol";
import {IUniswapV2Factory} from "./utils/IUniswapV2Factory.sol";
import {IUniswapV2Pair} from "./utils/IUniswapV2Pair.sol";
import {IWETH} from "./utils/IWETH.sol";
interface ITokenLogic {
function initialize(address _deployer, string memory _name, string memory _symbol) external payable;
function launchTimestamp() external view returns(uint);
function deployer() external view returns(address payable);
}
// token logic (code used by token proxies contracts)
contract TokenLogic is ERC20Logic, ITokenLogic {
enum FeesTier {
HIGH_FEES, // 20/20 fees the first 5 minutes
MEDIUM_FEES, // 5/5 fees until contract has less than 1% of the supply to sell
LOW_FEES // 1/1 then
}
// - token logic constants (not colliding proxies storages)
uint private constant HIGH_FEES_DURATION = 300; // duration of the high fees stage (20% during 5 minutes)
uint private constant LIMITS_DURATION = 300; // duration of max tx and max wallet limits in seconds
uint private constant BASE_TOTAL_SUPPLY = 1_000_000_000 * 10**18;
uint public constant MAX_TX_AMOUNT = (1 * BASE_TOTAL_SUPPLY) / 100; // max tx 10M (1%)
uint public constant MAX_WALLET_AMOUNT = (3 * BASE_TOTAL_SUPPLY) / 100; // max wallet 30M (3%)
uint private constant LIQUIDITY_AMOUNT = (80 * BASE_TOTAL_SUPPLY) / 100; // uniswap liquidity (80%)
address public immutable tokenFactory;
address public immutable WETH;
IUniswapV2Factory public immutable uniswapFactory;
IUniswapV2Router02 constant uniswapRouter = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
// - instance token storage (stored in each token proxies)
bool _swapping;
uint public launchTimestamp; // token launch timestamp
address payable public deployer;
address public uniswapPair;
FeesTier public feesTier; // current token fees tier (could be outdated and updated during the transaction)
constructor (address _tokenFactory) {
tokenFactory = _tokenFactory;
uniswapFactory = IUniswapV2Factory(uniswapRouter.factory());
WETH = uniswapRouter.WETH();
}
modifier lockSwap {
_swapping = true;
_;
_swapping = false;
}
// initialize new token datas (called from the factory to the token proxy delegating the call here)
function initialize(address _deployer, string memory _name, string memory _symbol) external payable {
require(msg.sender == tokenFactory, "Unauthorized"); // initialized only on the same deployment transaction from token factory
require(msg.value == 1 ether, "Wrong initial liquidity");
name = _name;
symbol = _symbol;
deployer = payable(_deployer);
launchTimestamp = block.timestamp;
_mint(address(this), BASE_TOTAL_SUPPLY - LIQUIDITY_AMOUNT); // mint clogged amount to the contract
uniswapPair = uniswapFactory.createPair(address(this), WETH);
_mint(uniswapPair, LIQUIDITY_AMOUNT); // mint liquidity amount to the pair
IWETH(WETH).deposit{value: 1 ether}();
assert(IWETH(WETH).transfer(uniswapPair, 1 ether)); // transfer weth to the pair
IUniswapV2Pair(uniswapPair).mint(tokenFactory); // call low level mint function on pair
}
function _transfer(address sender, address recipient, uint256 amount) internal override {
if (_swapping) return super._transfer(sender, recipient, amount);
uint fees = _takeFees(sender, recipient, amount);
if (fees != 0) {
super._transfer(sender, address(this), fees);
amount -= fees;
}
if (recipient == uniswapPair) _swapFees(amount);
super._transfer(sender, recipient, amount);
_forwardFees();
}
// return fees amount taken from the transfer (and check for tx and wallet limits)
function _takeFees(address sender, address recipient, uint amount) private returns (uint) {
if ((sender != uniswapPair && recipient != uniswapPair) || recipient == tokenFactory || sender == address(this) || recipient == address(uniswapRouter)) return 0;
// ensure max tx and max wallet
if (limitsActive() && sender == uniswapPair) {
require(amount <= MAX_TX_AMOUNT, "Max tx amount reached");
require(balanceOf(recipient) + amount <= MAX_WALLET_AMOUNT, "Max wallet amount reached");
}
// if token has low fees tier, fees are immutable at 1%
if (feesTier == FeesTier.LOW_FEES) return amount / 100; // 1% fees
// else, if token has medium fees, check if we can change tier and return correct fees
else if (feesTier == FeesTier.MEDIUM_FEES) {
if (balanceOf(address(this)) <= totalSupply / 100) {
feesTier = FeesTier.LOW_FEES;
return amount / 100; // 1% fees
}
return amount / 20; // 5% fees
}
// else, token is at high fees tier and we check if we can change tier and return correct fees
else {
if (block.timestamp - launchTimestamp > HIGH_FEES_DURATION) {
feesTier = FeesTier.MEDIUM_FEES;
return amount / 20; // 5% fees
}
return amount / 5; // 20% fees
}
}
// swap some fees tokens to eth
function _swapFees(uint maxAmount) private lockSwap {
uint tokenAmount = min(min(maxAmount, balanceOf(address(this))), totalSupply / 100);
if (tokenAmount < 1e18) return; // prevent too small swaps
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = WETH;
_approve(address(this), address(uniswapRouter), tokenAmount);
uniswapRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
}
// return true if max wallet and max tx limitations are still active
function limitsActive() public view returns (bool) {
return block.timestamp - launchTimestamp <= LIMITS_DURATION;
}
// forward contract fees to token factory (also try to burn liquidity)
function _forwardFees() private {
uint balance = address(this).balance;
if (balance == 0) return;
(bool result, ) = tokenFactory.call{value: balance}("");
require(result, "Failed to forward fees");
}
function min(uint a, uint b) private pure returns (uint) {
return a < b ? a : b;
}
receive() external payable {}
}
IWETH.sol 8 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IWETH {
function deposit() external payable;
function transfer(address to, uint value) external returns (bool);
function withdraw(uint) external;
}
TokenFactory.sol 261 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
/*
┌─────────────────────────────────────────────────────────────────────────┐
│ │
│ _______ ______ _ │
│ |__ __| | ____| (_) │
│ | | __ ___ _| |__ __ _ _ __ _ __ ___ _ _ __ __ _ │
│ | |/ _` \ \/ / __/ _` | '__| '_ ` _ \ | | '_ \ / _` | │
│ | | (_| |> <| | | (_| | | | | | | | | | | | | | (_| | │
│ |_|\__,_/_/\_\_| \__,_|_| |_| |_| |_|(_)_|_| |_|\__, | │
│ __/ | │
│ |___/ │
│ │
│ taxfarm.ing │
│ │
└─────────────────────────────────────────────────────────────────────────┘
*/
import {ITokenLogic, TokenLogic} from "./TokenLogic.sol";
// utils
import {IERC20} from "./utils/IERC20.sol";
import {IUniswapV2Router02} from "./utils/IUniswapV2Router02.sol";
import {IUniswapV2Factory} from "./utils/IUniswapV2Factory.sol";
import {Ownable} from "./utils/Ownable.sol";
interface ITokenFactory {
function externalTryBurn(address token) external;
}
// factory contract for deploying and managing child tokens
contract TokenFactory is Ownable {
bytes public constant TOKEN_PROXY_BYTECODE = hex"60a060405234801561000f575f80fd5b506040516102dc3803806102dc833981810160405281019061003191906100c9565b8073ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff1681525050506100f4565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6100988261006f565b9050919050565b6100a88161008e565b81146100b2575f80fd5b50565b5f815190506100c38161009f565b92915050565b5f602082840312156100de576100dd61006b565b5b5f6100eb848285016100b5565b91505092915050565b6080516101cb6101115f395f81816030015260ea01526101cb5ff3fe60806040526004361061002c575f3560e01c8063629c52a914610070578063d77177501461009a5761002d565b5b5f7f00000000000000000000000000000000000000000000000000000000000000009050365f80375f80365f845af43d5f803e805f811461006c573d5ff35b3d5ffd5b34801561007b575f80fd5b506100846100c4565b6040516100919190610124565b60405180910390f35b3480156100a5575f80fd5b506100ae6100e8565b6040516100bb919061017c565b60405180910390f35b7f10eeeeffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81565b7f000000000000000000000000000000000000000000000000000000000000000081565b5f819050919050565b61011e8161010c565b82525050565b5f6020820190506101375f830184610115565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6101668261013d565b9050919050565b6101768161015c565b82525050565b5f60208201905061018f5f83018461016d565b9291505056fea26469706673582212208caaf51ee3f849b605f6e63e26072b5c076726d07d40423546787cda62f1dc5b64736f6c63430008140033";
bytes public TOKEN_PROXY_DEPLOY_BYTECODE; // deployment bytecode got from TOKEN_PROXY_BYTECODE and constructor argument (token logic)
uint public uniqueId = 0x1000100000000000000000000000000000000000000000000000000000000000; // first child token unique id (used to keep track of token bytecode uniqueness)
address payable public protocolFeesRecipient;
address public immutable tokenLogic; // token logic passed to the newly created tokens
IUniswapV2Router02 constant uniswapRouter = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
IUniswapV2Factory immutable uniswapFactory;
uint8 public stakingFees = 0; // percentage of protocol fees forwarded to staking (initialized at 0 to avoid forwarding to zero address)
address payable public stakingContract;
enum LaunchStatus {
LAUNCH_ACTIVE,
LIQUIDITY_BURNED,
LIQUIDITY_REFUNDED
}
struct TokenInfo {
bool isChildToken;
uint uniqueId;
LaunchStatus launchStatus;
uint feesReceived; // eth amount received so far from the token
}
mapping (address => TokenInfo) public childTokens;
mapping (address => address[]) public tokensDeployed;
mapping (address => bool) public withdrawalAddresses;
event TokenCreated(address indexed token, address indexed deployer, string name, string symbol);
event LiquidityBurned(address indexed token);
event LiquidityRefunded(address indexed token);
constructor(address _protocolFeesRecipient) Ownable(msg.sender) {
protocolFeesRecipient = payable(_protocolFeesRecipient);
tokenLogic = address(new TokenLogic(address(this)));
// concatenate base creation bytecode of token proxy with token logic (token proxy constructor parameter)
TOKEN_PROXY_DEPLOY_BYTECODE = abi.encodePacked(
TOKEN_PROXY_BYTECODE,
abi.encode(tokenLogic)
);
uniswapFactory = IUniswapV2Factory(uniswapRouter.factory());
}
modifier onlyEoa() {
require(tx.origin == msg.sender, "Not EOA");
_;
}
function setStaking(address _stakingContract, uint8 _stakingFees) external onlyOwner {
require(_stakingFees <= 100, "Invalid fees");
stakingFees = _stakingFees;
stakingContract = payable(_stakingContract);
}
// set addresses able to call withdraw on behalf of deployers (could be used to build automatic bots ...)
function setWithdrawalAddresses(address account, bool isWithdrawalAddr) external onlyOwner {
withdrawalAddresses[account] = isWithdrawalAddr;
}
function setProtocolFeesRecipient(address payable _protocolFeesRecipient) external {
require(msg.sender == protocolFeesRecipient);
protocolFeesRecipient = _protocolFeesRecipient;
}
// deploy a child token with its name and symbol and return its address
function deployToken(string memory _name, string memory _symbol) onlyEoa external payable returns (address) {
address deployer = msg.sender;
address token = deployNewBytecode();
(bool success, ) = token.call{
value: msg.value
}(abi.encodeWithSelector(0x90657147, deployer, _name, _symbol));
require(success, "Error initializing token");
childTokens[token].isChildToken = true;
childTokens[token].uniqueId = uniqueId - 1;
tokensDeployed[deployer].push(token);
emit TokenCreated(token, deployer, _name, _symbol);
return token;
}
// deploy a new token proxy bytecode with the current uniqueId
function deployNewBytecode() private returns (address token) {
bytes memory bytecode = TOKEN_PROXY_DEPLOY_BYTECODE;
bytes32 _id = bytes32(uniqueId);
assembly {
mstore(add(bytecode, 503), _id) // dynamically replace the current unique id in the bytecode to deploy
token := create(0, add(bytecode, 0x20), mload(bytecode))
if iszero(extcodesize(token)) {
revert(0, 0)
}
}
uniqueId++;
}
// receive function, used by the child tokens to forward fees from tokens swaps
receive() external payable {
address token = msg.sender;
if (token == address(uniswapRouter)) return;
require(childTokens[token].isChildToken, "Unknown token");
childTokens[token].feesReceived += msg.value;
bool result = _tryBurn(token);
// stop acumulating fees and distribute if launch is active
if (!result && childTokens[token].launchStatus != LaunchStatus.LAUNCH_ACTIVE) {
uint protocolFees = msg.value / 5;
_distributeFees(token, msg.value - protocolFees, protocolFees);
}
}
// allow to externally withdraw liquidity (in case there is no tx for a while)
function withdrawLiquidity(address token) external {
require(childTokens[token].isChildToken == true, "Unknown token");
require(msg.sender == ITokenLogic(token).deployer() || withdrawalAddresses[msg.sender], "Unauthorized");
// if liquidity is already burned or refunded, then checking for burn is useless
if (childTokens[token].launchStatus != LaunchStatus.LAUNCH_ACTIVE) return;
// if we could burn lp, just return
if (_tryBurn(token)) return;
require(block.timestamp - ITokenLogic(token).launchTimestamp() > 24 hours, "Token not ready to refund");
childTokens[token].launchStatus = LaunchStatus.LIQUIDITY_REFUNDED;
// remove liquidity
IERC20 lpToken = IERC20(uniswapFactory.getPair(token, uniswapRouter.WETH()));
uint amount = lpToken.balanceOf(address(this));
lpToken.approve(address(uniswapRouter), amount);
(uint amountToken, uint amountETH) = uniswapRouter.removeLiquidityETH(token, amount, 0, 0, address(this), block.timestamp);
IERC20(token).burn(amountToken);
// refund eth from liquidity back to deployer up to 1 ether and tip the protocol with the remainder
uint deployerRefund = min(amountETH, 1 ether);
uint protocolTip = amountETH > 1 ether ? amountETH - 1 ether : 0;
(uint deployerFees, uint protocolFees) = getTokenFees(token);
_distributeFees(token, deployerRefund + deployerFees, protocolTip + protocolFees);
emit LiquidityRefunded(token);
}
function externalTryBurn(address token) external {
require(childTokens[token].isChildToken == true, "Unknown token");
_tryBurn(token);
}
function _tryBurn(address token) private returns (bool) {
// if liquidity is already burned or refunded, then checking for burn is useless
if (childTokens[token].launchStatus != LaunchStatus.LAUNCH_ACTIVE) return false;
(uint deployerFees, uint protocolFees) = getTokenFees(token);
// check if we can burn the liquidity
if (deployerFees >= 1 ether) {
childTokens[token].launchStatus = LaunchStatus.LIQUIDITY_BURNED;
IERC20 lpToken = IERC20(uniswapFactory.getPair(token, uniswapRouter.WETH()));
// burn lp token
lpToken.transfer(address(0), lpToken.balanceOf(address(this)));
_distributeFees(token, deployerFees, protocolFees);
emit LiquidityBurned(token);
return true;
}
return false;
}
function getTokenFees(address token) public view returns (uint deployerFees, uint protocolFees) {
uint totalFees = childTokens[token].feesReceived;
protocolFees = totalFees / 5;
deployerFees = totalFees - protocolFees;
}
// distribute fees to token deployer and protocol fees recipient
function _distributeFees(address token, uint deployerFees, uint protocolFees) private {
// refund deployer
if (deployerFees != 0) {
(bool result, ) = ITokenLogic(token).deployer().call{value: deployerFees}("");
require(result, "Failed to refund deployer");
}
// distribute protocol fees
if (protocolFees != 0) {
uint feesToStaking = (stakingFees * protocolFees) / 100;
uint feesToDev = protocolFees - feesToStaking;
if (feesToDev != 0) {
(bool result, ) = protocolFeesRecipient.call{value: feesToDev}("");
require(result, "Failed to forward");
}
if (feesToStaking != 0) {
(bool result, ) = stakingContract.call{value: feesToStaking}("");
require(result, "Failed to forward");
}
}
}
// return token unique id in bytes32
function getTokenUniqueId(address token) external view returns (bytes32) {
return bytes32(childTokens[token].uniqueId);
}
function getTokensDeployed(address deployer) external view returns (address[] memory) {
return tokensDeployed[deployer];
}
function min(uint a, uint b) private pure returns (uint) {
return a < b ? a : b;
}
}
IERC20.sol 19 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
function burn(uint256 value) external;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
Context.sol 12 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
Ownable.sol 99 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Context} from "./Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
ERC20Logic.sol 130 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {Context} from "./Context.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
// contract implementing the logic of ERC20 standard (thus usable from proxies)
contract ERC20Logic is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 public totalSupply;
string public name;
string public symbol;
function decimals() public view virtual override returns (uint8) {
return 18;
}
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
unchecked {
_approve(sender, _msgSender(), currentAllowance - amount);
}
return true;
}
function burn(uint256 value) public virtual {
_burn(_msgSender(), value);
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
}
return true;
}
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[sender] = senderBalance - amount;
}
_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
}
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
}
IUniswapV2Pair.sol 6 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IUniswapV2Pair {
function mint(address to) external returns (uint liquidity);
}
IUniswapV2Factory.sol 7 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IUniswapV2Factory {
function getPair(address tokenA, address tokenB) external view returns (address pair);
function createPair(address tokenA, address tokenB) external returns (address pair);
}
IUniswapV2Router02.sol 34 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IUniswapV2Router02 {
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
}
Read Contract
TOKEN_PROXY_BYTECODE 0x2b67d122 → bytes
TOKEN_PROXY_DEPLOY_BYTECODE 0xaed5c7b2 → bytes
childTokens 0x200952b1 → bool, uint256, uint8, uint256
getTokenFees 0x65436cd8 → uint256, uint256
getTokenUniqueId 0x52c3e349 → bytes32
getTokensDeployed 0x7df32647 → address[]
owner 0x8da5cb5b → address
protocolFeesRecipient 0x68930637 → address
stakingContract 0xee99205c → address
stakingFees 0x6dca7e7b → uint8
tokenLogic 0xd7717750 → address
tokensDeployed 0xca441933 → address
uniqueId 0x629c52a9 → uint256
withdrawalAddresses 0x7e051867 → bool
Write Contract 8 functions
These functions modify contract state and require a wallet transaction to execute.
deployToken 0x1d12b938
string _name
string _symbol
returns: address
externalTryBurn 0xf0685ef4
address token
renounceOwnership 0x715018a6
No parameters
setProtocolFeesRecipient 0x7a72f06f
address _protocolFeesRecipient
setStaking 0xdbdcf0c5
address _stakingContract
uint8 _stakingFees
setWithdrawalAddresses 0x8ddb0a3c
address account
bool isWithdrawalAddr
transferOwnership 0xf2fde38b
address newOwner
withdrawLiquidity 0x9d67ac37
address token
Token Balances (1)
View Transfers →Recent Transactions
No transactions found for this address