RanchToken

0xcded2ae4ffba59177a0cea3ba296e49b4e957720

Verification
Verified
v0.8.34+commit.80d5c536
Type
Contract
10,530 bytes
ABI entries
41
20 read · 9 write
License
none

Contract information

Address
0xcded2ae4ffba59177a0cea3ba296e49b4e957720
Chain
Robinhood Chain (4663)
Compiler
v0.8.34+commit.80d5c536
Optimization
Disabled
Creation tx
0x9b53d9492e…1557e175d9

Token

Name
Ranch
Symbol
RANCH
Decimals
18
Holders
2,279

Read contract (20)

DEAD()address
ROUTER_ADDRESS()address
TENDIES_ADDRESS()address
allowance(address, address)uint256
autoLiquidityEnabled()bool
balanceOf(address)uint256
deadBlocks()uint256
decimals()uint8
isExcludedFromLimits(address)bool
maxTxAmount()uint256
maxWalletAmount()uint256
name()string
owner()address
pairAddress()address
router()address
swapThreshold()uint256
symbol()string
totalSupply()uint256
tradingActiveBlock()uint256
tradingEnabled()bool

Events (3)

ApprovalOwnershipTransferredTransfer

ABI

[
  {
    "inputs": [],
    "stateMutability": "nonpayable",
    "type": "constructor"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "spender",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "allowance",
        "type": "uint256"
      },
      {
        "internalType": "uint256",
        "name": "needed",
        "type": "uint256"
      }
    ],
    "name": "ERC20InsufficientAllowance",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "sender",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "balance",
        "type": "uint256"
      },
      {
        "internalType": "uint256",
        "name": "needed",
        "type": "uint256"
      }
    ],
    "name": "ERC20InsufficientBalance",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "approver",
        "type": "address"
      }
    ],
    "name": "ERC20InvalidApprover",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "receiver",
        "type": "address"
      }
    ],
    "name": "ERC20InvalidReceiver",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "sender",
        "type": "address"
      }
    ],
    "name": "ERC20InvalidSender",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "spender",
        "type": "address"
      }
    ],
    "name": "ERC20InvalidSpender",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      }
    ],
    "name": "OwnableInvalidOwner",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "OwnableUnauthorizedAccount",
    "type": "error"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "owner",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "spender",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "value",
        "type": "uint256"
      }
    ],
    "name": "Approval",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "previousOwner",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "newOwner",
        "type": "address"
      }
    ],
    "name": "OwnershipTransferred",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "from",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "to",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "value",
        "type": "uint256"
      }
    ],
    "name": "Transfer",
    "type": "event"
  },
  {
    "inputs": [],
    "name": "DEAD",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "ROUTER_ADDRESS",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "TENDIES_ADDRESS",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      },
      {
        "internalType": "address",
        "name": "spender",
        "type": "address"
      }
    ],
    "name": "allowance",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "spender",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "value",
        "type": "uint256"
      }
    ],
    "name": "approve",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "autoLiquidityEnabled",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "balanceOf",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "deadBlocks",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "decimals",
    "outputs": [
      {
        "internalType": "uint8",
        "name": "",
        "type": "uint8"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "uint256",
        "name": "_deadBlocks",
        "type": "uint256"
      }
    ],
    "name": "enableTrading",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      },
      {
        "internalType": "bool",
        "name": "excluded",
        "type": "bool"
      }
    ],
    "name": "excludeFromLimits",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "name": "isExcludedFromLimits",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "maxTxAmount",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "maxWalletAmount",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "name",
    "outputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "owner",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "pairAddress",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "renounceOwnership",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "router",
    "outputs": [
      {
        "internalType": "contract IUniswapV2Router",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "_pairAddress",
        "type": "address"
      }
    ],
    "name": "setPair",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "swapThreshold",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "symbol",
    "outputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "totalSupply",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "tradingActiveBlock",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "tradingEnabled",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "to",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "value",
        "type": "uint256"
      }
    ],
    "name": "transfer",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "from",
        "type": "address"
      },
      {
        "internalType": "address",
        "name": "to",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "value",
        "type": "uint256"
      }
    ],
    "name": "transferFrom",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "newOwner",
        "type": "address"
      }
    ],
    "name": "transferOwnership",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "uint256",
        "name": "newMaxTxTokens",
        "type": "uint256"
      },
      {
        "internalType": "uint256",
        "name": "newMaxWalletTokens",
        "type": "uint256"
      }
    ],
    "name": "updateLimits",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  }
]

Source code

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

interface IUniswapV2Router {
    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline
    ) external;
    
    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);
}

contract RanchToken is ERC20, Ownable {
    // Limits are now fully adjustable
    uint256 public maxTxAmount = 5_000_000 * 10**18;       // 0.5% starting max tx
    uint256 public maxWalletAmount = 10_000_000 * 10**18;  // 1.0% starting max wallet
    uint256 public swapThreshold = 500_000 * 10**18;       // 0.05%
    
    bool public tradingEnabled = false;
    bool private inSwap;
    bool public autoLiquidityEnabled = true;
    
    // Anti-bot variables
    uint256 public tradingActiveBlock;
    uint256 public deadBlocks;
    
    address public constant DEAD = 0x000000000000000000000000000000000000dEaD;
    address public constant TENDIES_ADDRESS = 0x45242320DBB855EeA8Fd36804C6487E10E97FCF9; 
    address public constant ROUTER_ADDRESS = 0x89e5DB8B5aA49aA85AC63f691524311AEB649eba; 
    
    address public pairAddress; 
    IUniswapV2Router public router;
    mapping(address => bool) public isExcludedFromLimits;

    constructor() ERC20("Ranch", "RANCH") Ownable(msg.sender) {
        router = IUniswapV2Router(ROUTER_ADDRESS);
        
        isExcludedFromLimits[msg.sender] = true;
        isExcludedFromLimits[address(this)] = true;
        isExcludedFromLimits[DEAD] = true;
        isExcludedFromLimits[ROUTER_ADDRESS] = true;

        // Mint 1 Billion tokens
        _mint(msg.sender, 1_000_000_000 * 10**18);
    }

    function setPair(address _pairAddress) external onlyOwner {
        require(pairAddress == address(0), "Pair already set"); // Prevent accidental resets
        pairAddress = _pairAddress;
        isExcludedFromLimits[_pairAddress] = true; 
    }

    // Function to whitelist airdrop tools or other addresses
    function excludeFromLimits(address account, bool excluded) external onlyOwner {
        isExcludedFromLimits[account] = excluded;
    }

    // Function to update limits incrementally using raw numbers of tokens.
    // Example: To raise the max wallet limit to 20 million tokens (2%), type 20000000.
    // To completely remove limits, type 1000000000 (1 Billion - your total supply).
    function updateLimits(uint256 newMaxTxTokens, uint256 newMaxWalletTokens) external onlyOwner {
        maxTxAmount = newMaxTxTokens * 10**18;
        maxWalletAmount = newMaxWalletTokens * 10**18;
    }

    // Pass in the number of blocks you want snipers heavily restricted (e.g., 2)
    function enableTrading(uint256 _deadBlocks) external onlyOwner { 
        require(!tradingEnabled, "Already enabled");
        tradingEnabled = true; 
        tradingActiveBlock = block.number;
        deadBlocks = _deadBlocks;
    }

    function _update(address from, address to, uint256 amount) internal override {
        // 1. Enforce Max Limits & Anti-Bot
        if (!isExcludedFromLimits[from] && !isExcludedFromLimits[to]) {
            require(tradingEnabled, "Trading not active");
            require(amount <= maxTxAmount, "Exceeds max transaction");
            
            if (to != pairAddress) {
                require(balanceOf(to) + amount <= maxWalletAmount, "Exceeds max wallet");
            }

            // Anti-Sniper Block Protection
            if (block.number <= tradingActiveBlock + deadBlocks) {
                // Prevent smart contract snipers in the first few blocks
                require(tx.origin == msg.sender, "No bot contracts during launch");
            }
        }

        uint256 taxAmount = 0;
        
        // 2. Tax Logic (Taxes BOTH Buys and Sells)
        if (tradingEnabled && !inSwap && !isExcludedFromLimits[from] && !isExcludedFromLimits[to]) {
            
            // If tokens are going TO the pair (Sell) or FROM the pair (Buy)
            if (to == pairAddress || from == pairAddress) {
                taxAmount = (amount * 2) / 100; // 2% Tax
            }
            
            // Trigger automation on SALES only to prevent gas issues on buys
            if (to == pairAddress && balanceOf(address(this)) >= swapThreshold) {
                swapAndLiquify();
            }
        }

        // 3. Process Tax and Transfer
        if (taxAmount > 0) {
            super._update(from, address(this), taxAmount);
            amount -= taxAmount;
        }
        
        super._update(from, to, amount);
    }

    function swapAndLiquify() private {
        inSwap = true;
        uint256 totalTax = balanceOf(address(this));
        
        // 1. Burn 0.5% RANCH (25% of total tax)
        uint256 forBurnRanch = totalTax / 4; 
        _transfer(address(this), DEAD, forBurnRanch);

        // 2. Prepare 50% of the tax for Swap to TENDIES (for TENDIES Burn + LP)
        uint256 forSwap = totalTax / 2;
        
        // 3. The remaining 25% stays as RANCH to pair for Auto-LP
        uint256 ranchForLP = totalTax - forBurnRanch - forSwap; 

        _approve(address(this), address(router), forSwap);

        address[] memory path = new address[](2);
        path[0] = address(this);
        path[1] = TENDIES_ADDRESS;
        
        uint256 initialTendies = IERC20(TENDIES_ADDRESS).balanceOf(address(this));

        try router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
            forSwap, 0, path, address(this), block.timestamp
        ) {
            uint256 newTendies = IERC20(TENDIES_ADDRESS).balanceOf(address(this)) - initialTendies;

            // 4. Burn TENDIES (50% of what was just swapped)
            uint256 tendiesForBurn = newTendies / 2; 
            IERC20(TENDIES_ADDRESS).transfer(DEAD, tendiesForBurn);

            // 5. Add Auto-LP
            if (autoLiquidityEnabled && pairAddress != address(0)) {
                uint256 tendiesForLP = newTendies - tendiesForBurn;

                IERC20(TENDIES_ADDRESS).approve(address(router), tendiesForLP);
                _approve(address(this), address(router), ranchForLP);

                try router.addLiquidity(
                    address(this), TENDIES_ADDRESS, ranchForLP, tendiesForLP, 0, 0, DEAD, block.timestamp
                ) {} catch {} 
            }
        } catch {}

        inSwap = false;
    }
}
Chain explorer3382msChain node80ms