Verified contractExactMIT
LaunchToken
Address0xdd943bacc4df4e7b9cbf9f4d6da6e39993e2def5
- Balance
0 ETH
- Transactions
7
- Compiler
solc 0.8.38
- Same code
3 more contracts
Details
- Compiler
- solc 0.8.38+commit.1835d247
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- paris
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,357,022
- Creation transaction
- 0xfcdce01ef6…7b98406024
LaunchToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/// @title LaunchKit LaunchToken
/// @notice 参数化 ERC-20 代币,所有功能开关在部署时一次写死,之后不可增删:
/// - 买入/卖出税费:上限部署时固定(硬顶 25%),之后只能降、不能升
/// - 冻结(黑名单):Owner 可冻结/解冻任意地址,被冻结地址无法转出或接收
/// - 增发:可附带部署时写死的总量上限
/// - 所有权:Owner 可随时放弃(renounce),放弃后合约彻底不可管理
/// Owner 由部署参数指定(支持经 CREATE2 工厂部署靓号地址),Owner 与税费收款地址默认免税,方便加池/撤池不触发税费。
contract LaunchToken {
// ---------- 元数据 ----------
string public name;
string public symbol;
uint8 public immutable decimals;
// ---------- ERC-20 ----------
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
// ---------- 所有权 ----------
address public owner;
// ---------- 部署时固定的功能开关与上限 ----------
bool public immutable taxEnabled;
bool public immutable freezeEnabled;
bool public immutable mintEnabled;
uint16 public immutable feeBuyCapBps;
uint16 public immutable feeSellCapBps;
/// @notice 增发后的最大总供应量;0 = 不限
uint256 public immutable mintCap;
// ---------- 可变状态(Owner 管理) ----------
uint16 public feeBuyBps;
uint16 public feeSellBps;
address public feeWallet;
address public pair;
mapping(address => bool) public isFrozen;
mapping(address => bool) public isFeeExempt;
uint16 public constant MAX_FEE_CAP_BPS = 2500; // 税费上限的硬顶 25%,写死在合约里
/// @notice 所有部署参数打包成一个结构体,功能开关部署后不可增删
struct Init {
string name;
string symbol;
uint8 decimals;
address supplyTo;
uint256 initialSupply;
bool taxEnabled;
uint16 feeBuyBps;
uint16 feeSellBps;
uint16 feeBuyCapBps;
uint16 feeSellCapBps;
address feeWallet;
bool freezeEnabled;
bool mintEnabled;
uint256 mintCap; // 增发后的最大总供应量;0 = 不限
address owner;
}
// ---------- 事件 ----------
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed holder, address indexed spender, uint256 value);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event FeesSet(uint16 buyBps, uint16 sellBps);
event FeeWalletSet(address indexed previousWallet, address indexed newWallet);
event PairSet(address indexed pair);
event FreezeSet(address indexed account, bool frozen);
event FeeExemptSet(address indexed account, bool exempt);
event Minted(address indexed to, uint256 amount);
event Burned(address indexed account, uint256 amount);
// ---------- 错误 ----------
error NotOwner();
error ZeroAddress();
error ZeroAmount();
error InsufficientBalance();
error InsufficientAllowance();
error AccountFrozen();
error TaxDisabled();
error FreezeDisabled();
error MintDisabled();
error CapTooHigh();
error FeeAboveCap();
error FeeNotLower();
error MintCapBelowSupply();
error MintCapExceeded();
error InvalidPair();
modifier onlyOwner() {
if (msg.sender != owner) revert NotOwner();
_;
}
constructor(Init memory init) {
address supplyTo = init.supplyTo;
address owner_ = init.owner;
uint256 initialSupply = init.initialSupply;
if (supplyTo == address(0) || owner_ == address(0)) revert ZeroAddress();
if (init.taxEnabled) {
if (init.feeWallet == address(0)) revert ZeroAddress();
if (init.feeBuyCapBps > MAX_FEE_CAP_BPS || init.feeSellCapBps > MAX_FEE_CAP_BPS) revert CapTooHigh();
if (init.feeBuyBps > init.feeBuyCapBps || init.feeSellBps > init.feeSellCapBps) revert FeeAboveCap();
}
if (init.mintEnabled && init.mintCap != 0 && init.mintCap < initialSupply) revert MintCapBelowSupply();
name = init.name;
symbol = init.symbol;
decimals = init.decimals;
taxEnabled = init.taxEnabled;
freezeEnabled = init.freezeEnabled;
mintEnabled = init.mintEnabled;
feeBuyCapBps = init.feeBuyCapBps;
feeSellCapBps = init.feeSellCapBps;
mintCap = init.mintCap;
if (init.taxEnabled) {
feeWallet = init.feeWallet;
feeBuyBps = init.feeBuyBps;
feeSellBps = init.feeSellBps;
isFeeExempt[owner_] = true;
isFeeExempt[init.feeWallet] = true;
}
owner = owner_;
totalSupply = initialSupply;
balanceOf[supplyTo] = initialSupply;
emit Transfer(address(0), supplyTo, initialSupply);
emit OwnershipTransferred(address(0), owner_);
}
// ---------- ERC-20 ----------
function approve(address spender, uint256 amount) external returns (bool) {
if (spender == address(0)) revert ZeroAddress();
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) external returns (bool) {
_transfer(msg.sender, to, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) external returns (bool) {
uint256 allowed = allowance[from][msg.sender];
if (allowed < amount) revert InsufficientAllowance();
if (allowed != type(uint256).max) {
allowance[from][msg.sender] = allowed - amount;
emit Approval(from, msg.sender, allowed - amount);
}
_transfer(from, to, amount);
return true;
}
function _transfer(address from, address to, uint256 amount) internal {
if (from == address(0) || to == address(0)) revert ZeroAddress();
uint256 fromBalance = balanceOf[from];
if (fromBalance < amount) revert InsufficientBalance();
if (freezeEnabled && (isFrozen[from] || isFrozen[to])) revert AccountFrozen();
uint16 feeBps = 0;
if (taxEnabled && pair != address(0) && !isFeeExempt[from] && !isFeeExempt[to]) {
if (from == pair) {
feeBps = feeBuyBps;
} else if (to == pair) {
feeBps = feeSellBps;
}
}
balanceOf[from] = fromBalance - amount;
uint256 netAmount = amount;
if (feeBps != 0) {
uint256 fee = (amount * feeBps) / 10000;
if (fee != 0) {
netAmount = amount - fee;
balanceOf[feeWallet] += fee;
emit Transfer(from, feeWallet, fee);
}
}
balanceOf[to] += netAmount;
emit Transfer(from, to, netAmount);
}
// ---------- Owner:税费 ----------
function setPair(address pair_) external onlyOwner {
if (!taxEnabled) revert TaxDisabled();
if (pair_ == address(0)) revert ZeroAddress();
// 用显式 staticcall 校验:目标必须是本代币的 V2 类交易对(token0/token1 之一 == 本合约)。
// 不用 try/catch:无代码地址会以空数据裸回退,错误名丢失;staticcall + 长度检查保证 InvalidPair 一定带选择器。
(bool ok0, bytes memory ret0) = pair_.staticcall(abi.encodeWithSignature("token0()"));
if (!ok0 || ret0.length != 32) revert InvalidPair();
(bool ok1, bytes memory ret1) = pair_.staticcall(abi.encodeWithSignature("token1()"));
if (!ok1 || ret1.length != 32) revert InvalidPair();
address token0_ = abi.decode(ret0, (address));
address token1_ = abi.decode(ret1, (address));
if (token0_ != address(this) && token1_ != address(this)) revert InvalidPair();
pair = pair_;
emit PairSet(pair_);
}
function setFees(uint16 buyBps_, uint16 sellBps_) external onlyOwner {
if (!taxEnabled) revert TaxDisabled();
if (buyBps_ > feeBuyBps || sellBps_ > feeSellBps) revert FeeNotLower();
if (buyBps_ > feeBuyCapBps || sellBps_ > feeSellCapBps) revert FeeAboveCap();
feeBuyBps = buyBps_;
feeSellBps = sellBps_;
emit FeesSet(buyBps_, sellBps_);
}
function setFeeWallet(address feeWallet_) external onlyOwner {
if (!taxEnabled) revert TaxDisabled();
if (feeWallet_ == address(0)) revert ZeroAddress();
address previous = feeWallet;
feeWallet = feeWallet_;
isFeeExempt[feeWallet_] = true;
emit FeeWalletSet(previous, feeWallet_);
}
function setFeeExempt(address[] calldata accounts, bool exempt) external onlyOwner {
if (!taxEnabled) revert TaxDisabled();
for (uint256 i = 0; i < accounts.length; ++i) {
isFeeExempt[accounts[i]] = exempt;
emit FeeExemptSet(accounts[i], exempt);
}
}
// ---------- Owner:冻结 ----------
function setFrozen(address[] calldata accounts, bool frozen) external onlyOwner {
if (!freezeEnabled) revert FreezeDisabled();
for (uint256 i = 0; i < accounts.length; ++i) {
isFrozen[accounts[i]] = frozen;
emit FreezeSet(accounts[i], frozen);
}
}
// ---------- Owner:增发 ----------
function mint(address to, uint256 amount) external onlyOwner {
if (!mintEnabled) revert MintDisabled();
if (to == address(0)) revert ZeroAddress();
if (amount == 0) revert ZeroAmount();
if (mintCap != 0 && totalSupply + amount > mintCap) revert MintCapExceeded();
totalSupply += amount;
balanceOf[to] += amount;
emit Transfer(address(0), to, amount);
emit Minted(to, amount);
}
// ---------- 销毁 ----------
function burn(uint256 amount) external {
if (amount == 0) revert ZeroAmount();
uint256 balance = balanceOf[msg.sender];
if (balance < amount) revert InsufficientBalance();
balanceOf[msg.sender] = balance - amount;
totalSupply -= amount;
emit Transfer(msg.sender, address(0), amount);
emit Burned(msg.sender, amount);
}
function burnFrom(address from, uint256 amount) external {
if (amount == 0) revert ZeroAmount();
uint256 allowed = allowance[from][msg.sender];
if (allowed < amount) revert InsufficientAllowance();
if (allowed != type(uint256).max) {
allowance[from][msg.sender] = allowed - amount;
emit Approval(from, msg.sender, allowed - amount);
}
uint256 balance = balanceOf[from];
if (balance < amount) revert InsufficientBalance();
balanceOf[from] = balance - amount;
totalSupply -= amount;
emit Transfer(from, address(0), amount);
emit Burned(from, amount);
}
// ---------- 所有权 ----------
function renounceOwnership() external onlyOwner {
_setOwner(address(0));
}
function transferOwnership(address newOwner) external onlyOwner {
if (newOwner == address(0)) revert ZeroAddress();
_setOwner(newOwner);
}
function _setOwner(address newOwner) internal {
address previous = owner;
owner = newOwner;
emit OwnershipTransferred(previous, newOwner);
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "paris"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.