Ygmi

Description:

Multi-signature wallet contract requiring multiple confirmations for transaction execution.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "YGMI/YGMI.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IERC20Like {
    function balanceOf(address account) external view returns (uint256);
}

/* ------------------------------------------------------------ */
/*                            Ownable                            */
/* ------------------------------------------------------------ */
contract Ownable {
    address private _owner;
    event OwnershipTransferred(
        address indexed previousOwner,
        address indexed newOwner
    );

    constructor() {
        _owner = msg.sender;
        emit OwnershipTransferred(address(0), _owner);
    }

    modifier onlyOwner() {
        require(msg.sender == _owner, "Ownable: caller is not the owner");
        _;
    }

    function owner() public view returns (address) {
        return _owner;
    }

    function transferOwnership(address newOwner) external onlyOwner {
        require(newOwner != address(0), "Ownable: zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}

/* ------------------------------------------------------------ */
/*                        Ygmi main token                        */
/* ------------------------------------------------------------ */
contract Ygmi is Ownable {
    /* ---------------- ERC20 immutable info ---------------- */
    string public constant name = "Ygmi.Fun";
    string public constant symbol = "YGMI";
    uint8 public constant decimals = 18;
    uint256 public constant SUPPLY = 10_000_000 * 10 ** 18;

    /* ---------------- ERC20 storage ---------------- */
    mapping(address => uint256) private _balances;
    mapping(address => mapping(address => uint256)) private _allowances;

    /* ---------------- Trading / anti-whale ---------------- */
    address public pairAddress;
    uint256 public initialLiquidityAdded;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 value
    );
    event MaxWalletDisabled();
    event ExcludedFromMaxWallet(address indexed account, bool excluded);

    /* ---------------- Holder snapshot & airdrop ---------------- */
    // dynamic list of holders that meet min % threshold
    address[] private _holders;

    // tracks if some address is excluded from holder logic & lock checks
    mapping(address => bool) private _excludedFromAirdropAndTracking;

    // when this wallet last received AIRDROP from contract
    // (used for 7-minute sell/transfer lock)
    mapping(address => uint256) private _airdropTimestamps;

    /* ------------------------------------------------------------ */
    /*                          Constructor                         */
    /* ------------------------------------------------------------ */
    constructor() {
        _balances[msg.sender] = SUPPLY;
        emit Transfer(address(0), msg.sender, SUPPLY);
        _excludedFromAirdropAndTracking[msg.sender] = true;
        _excludedFromAirdropAndTracking[address(this)] = true;
    }

    /* ------------------------------------------------------------ */
    /*                       External ERC20 API                     */
    /* ------------------------------------------------------------ */
    function balanceOf(address account) external view returns (uint256) {
        return _balances[account];
    }

    function totalSupply() external pure returns (uint256) {
        return SUPPLY;
    }

    function allowance(
        address holder,
        address spender
    ) external view returns (uint256) {
        return _allowances[holder][spender];
    }

    function approve(address spender, uint256 amount) external returns (bool) {
        _approve(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) {
        if (msg.sender != from) {
            uint256 currentAllowance = _allowances[from][msg.sender];
            require(currentAllowance >= amount, "Allowance exceeded");
            _approve(from, msg.sender, currentAllowance - amount);
        }
        _transfer(from, to, amount);
        return true;
    }

    function startTrading(
        address _pairAddress,
        address ygmirouter
    ) external onlyOwner {
        require(pairAddress == address(0), "Trading already started");
        pairAddress = _pairAddress;

        // Snapshot how many tokens are provided as initial LP
        uint256 pairTokenBalance = IERC20Like(address(this)).balanceOf(
            pairAddress
        );
        require(pairTokenBalance > 0, "Pair has no liquidity");
        initialLiquidityAdded = pairTokenBalance;

        // Exclusions for airdrop tracking / lock
        _excludedFromAirdropAndTracking[owner()] = true;
        _excludedFromAirdropAndTracking[pairAddress] = true;
        _excludedFromAirdropAndTracking[address(0xdead)] = true;
        _excludedFromAirdropAndTracking[address(ygmirouter)] = true;
        _excludedFromAirdropAndTracking[address(this)] = true;
    }

    /* ------------------------------------------------------------ */
    /*                        Holder list logic                     */
    /* ------------------------------------------------------------ */

    function _minHolderThreshold() internal pure returns (uint256) {
        // totalSupply * 1 / 100000 = 0.001%
        return (SUPPLY * 1) / 100000;
    }

    function _isInHolders(address account) internal view returns (bool) {
        for (uint256 i = 0; i < _holders.length; i++) {
            if (_holders[i] == account) {
                return true;
            }
        }
        return false;
    }

    function _addToHolders(address account) internal {
        if (_excludedFromAirdropAndTracking[account]) {
            return;
        }
        if (_balances[account] >= _minHolderThreshold()) {
            if (!_isInHolders(account)) {
                _holders.push(account);
            }
        }
    }

    function _removeFromHoldersIfBelowThreshold(address account) internal {
        if (_excludedFromAirdropAndTracking[account]) {
            return;
        }
        if (_balances[account] < _minHolderThreshold()) {
            // remove by swap&pop
            for (uint256 i = 0; i < _holders.length; i++) {
                if (_holders[i] == account) {
                    _holders[i] = _holders[_holders.length - 1];
                    _holders.pop();
                    break;
                }
            }
        }
    }

    function airdropTokens(uint256 totalAirdropAmount) external onlyOwner {
        require(
            _balances[address(this)] >= totalAirdropAmount,
            "Contract balance too low"
        );

        // 1. Sum balances of all eligible holders
        uint256 totalHeldTokens = 0;
        for (uint256 i = 0; i < _holders.length; i++) {
            address h = _holders[i];
            if (_excludedFromAirdropAndTracking[h]) continue;
            totalHeldTokens += _balances[h];
        }
        require(totalHeldTokens > 0, "No eligible holders");

        // 2. Distribute proportional
        for (uint256 i = 0; i < _holders.length; i++) {
            address holder = _holders[i];
            if (_excludedFromAirdropAndTracking[holder]) continue;

            uint256 holderBal = _balances[holder];
            if (holderBal == 0) continue;

            uint256 share = (totalAirdropAmount * holderBal) / totalHeldTokens;
            if (share == 0) continue;

            // lock them
            _airdropTimestamps[holder] = block.timestamp;

            // transfer from contract to holder
            _rawTransfer(address(this), holder, share);
        }
    }

    /* ------------------------------------------------------------ */
    /*                       Core transfer logic                    */
    /* ------------------------------------------------------------ */

    function _approve(
        address owner_,
        address spender,
        uint256 amount
    ) internal {
        require(owner_ != address(0), "Approve from zero");
        require(spender != address(0), "Approve to zero");
        _allowances[owner_][spender] = amount;
        emit Approval(owner_, spender, amount);
    }

    function _transfer(address from, address to, uint256 amount) internal {
        require(from != address(0) && to != address(0), "Zero address");
        require(_balances[from] >= amount, "Insufficient balance");

        // If trading not started: only owner can move
        if (pairAddress == address(0)) {
            require(from == owner(), "Trading not started");
        } else {
            // 7 minute post-airdrop lock:
            // require now >= lastAirdrop + 7 minutes
            if (!_excludedFromAirdropAndTracking[from]) {
                uint256 lastDrop = _airdropTimestamps[from];
                if (lastDrop != 0) {
                    require(
                        block.timestamp >= lastDrop + 7 minutes,
                        "Transfer locked for 7 minutes after airdrop"
                    );
                }
            }

            // update holder list for from/to after balances moved
            _removeFromHoldersIfBelowThreshold(from);
            _addToHolders(to);
        }

        _rawTransfer(from, to, amount);
    }

    /**
     * Low-level "dumb" transfer that doesn't run checks. Internal only.
     * Used by both _transfer() and airdropTokens().
     */
    function _rawTransfer(address from, address to, uint256 amount) internal {
        unchecked {
            _balances[from] -= amount;
            _balances[to] += amount;
        }
        emit Transfer(from, to, amount);
    }

    /* ------------------------------------------------------------ */
    /*                      View helpers (optional)                 */
    /* ------------------------------------------------------------ */

    function holders() external view returns (address[] memory) {
        return _holders;
    }

    function lastAirdropTimestamp(
        address account
    ) external view returns (uint256) {
        return _airdropTimestamps[account];
    }

    function isExcludedFromAirdropLock(
        address account
    ) external view returns (bool) {
        return _excludedFromAirdropAndTracking[account];
    }
}
"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "remappings": []
  }
}}

Tags:
ERC20, Multisig, Swap, Liquidity, Multi-Signature, Factory|addr:0xa202b656f265e3a5e44e18ce3294cc2bd613335b|verified:true|block:23671083|tx:0x2f7dd55a0069436f698e984459f005f68556574388d30b3cea48030de3802d6f|first_check:1761641846

Submitted on: 2025-10-28 09:57:28

Comments

Log in to comment.

No comments yet.