SherwoodTreasureChest

0xa7ded605ac34021a754d2e9c54f1ee47a79e1ede

Verification
Verified
v0.8.24+commit.e11b9ed9
Type
Contract
14,485 bytes
ABI entries
69
33 read · 21 write
License
none

Contract information

Address
0xa7ded605ac34021a754d2e9c54f1ee47a79e1ede
Chain
Robinhood Chain (4663)
Compiler
v0.8.24+commit.e11b9ed9
Optimization
Enabled
Creation tx
0x6e7ed6aef0…47c50175dd

Token

Name
Sherwood Treasure Chest
Symbol
TREASURE
Decimals
18
Holders
177

Read contract (33)

DEAD()address
MAX_SWAP_SLIPPAGE_BPS()uint256
PROCESSOR_SHARE_BPS()uint256
accumulativeStockOf(address, address)uint256
activeRewardTokenAt(uint256)address
activeRewardTokenCount()uint256
allowance(address, address)uint256
automatedMarketMakerPairs(address)bool
balanceOf(address)uint256
currentTaxFeeBps()uint256
decimals()uint8
devWallet()address
isExcludedFromFee(address)bool
isExcludedFromRewards(address)bool
isStockToken(address)bool
name()string
owner()address
pendingStockRewards(address, address)uint256
poolManager()address
rewardHolderCount()uint256
router()address
stockTokenAt(uint256)address
stockTokenCount()uint256
swapEnabled()bool
swapSlippageBps()uint256
swapThreshold()uint256
symbol()string
totalRewardsEligibleSupply()uint256
totalStockDistributed(address)uint256
totalSupply()uint256
totalTransactions()uint256
uniswapV2Pair()address
weth()address

Events (13)

ApprovalDevWalletAllocatedExcludedFromRewardsOwnershipTransferredRewardClaimedRewardPayoutFailedSetAutomatedMarketMakerPairStockRewardDistributedStockTokenUpdatedSwapSlippageUpdatedSwapThresholdUpdatedTransferV2Configured

ABI

[
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "initialOwner",
        "type": "address"
      },
      {
        "internalType": "address",
        "name": "devWallet_",
        "type": "address"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "constructor"
  },
  {
    "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": "devWallet",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "DevWalletAllocated",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "account",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "bool",
        "name": "excluded",
        "type": "bool"
      }
    ],
    "name": "ExcludedFromRewards",
    "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": "account",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "stock",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "RewardClaimed",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "account",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "stock",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "RewardPayoutFailed",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "pair",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "bool",
        "name": "value",
        "type": "bool"
      }
    ],
    "name": "SetAutomatedMarketMakerPair",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "stock",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      },
      {
        "indexed": true,
        "internalType": "uint256",
        "name": "stockIndex",
        "type": "uint256"
      }
    ],
    "name": "StockRewardDistributed",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "stock",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "bool",
        "name": "added",
        "type": "bool"
      }
    ],
    "name": "StockTokenUpdated",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "slippageBps",
        "type": "uint256"
      }
    ],
    "name": "SwapSlippageUpdated",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "threshold",
        "type": "uint256"
      }
    ],
    "name": "SwapThresholdUpdated",
    "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"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "router",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "pair",
        "type": "address"
      }
    ],
    "name": "V2Configured",
    "type": "event"
  },
  {
    "inputs": [],
    "name": "DEAD",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "MAX_SWAP_SLIPPAGE_BPS",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "PROCESSOR_SHARE_BPS",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      },
      {
        "internalType": "address",
        "name": "stock",
        "type": "address"
      }
    ],
    "name": "accumulativeStockOf",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "uint256",
        "name": "index",
        "type": "uint256"
      }
    ],
    "name": "activeRewardTokenAt",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "activeRewardTokenCount",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "stock",
        "type": "address"
      }
    ],
    "name": "addStockToken",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "tokenOwner",
        "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": "amount",
        "type": "uint256"
      }
    ],
    "name": "approve",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "name": "automatedMarketMakerPairs",
    "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": [
      {
        "internalType": "address",
        "name": "stock",
        "type": "address"
      }
    ],
    "name": "claimReward",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "claimRewards",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "configureV2",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "processor",
        "type": "address"
      }
    ],
    "name": "convertTaxToStock",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "currentTaxFeeBps",
    "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": "address",
        "name": "spender",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "subtractedValue",
        "type": "uint256"
      }
    ],
    "name": "decreaseAllowance",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "devWallet",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "stock",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "amount",
        "type": "uint256"
      }
    ],
    "name": "distributeStockRewards",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      },
      {
        "internalType": "bool",
        "name": "excluded",
        "type": "bool"
      }
    ],
    "name": "excludeFromRewards",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "spender",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "addedValue",
        "type": "uint256"
      }
    ],
    "name": "increaseAllowance",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "name": "isExcludedFromFee",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "name": "isExcludedFromRewards",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "name": "isStockToken",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "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": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      },
      {
        "internalType": "address",
        "name": "stock",
        "type": "address"
      }
    ],
    "name": "pendingStockRewards",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "poolManager",
    "outputs": [
      {
        "internalType": "contract IPoolManager",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "processFees",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address[]",
        "name": "accounts",
        "type": "address[]"
      }
    ],
    "name": "pushRewards",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "renounceOwnership",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "rewardHolderCount",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "router",
    "outputs": [
      {
        "internalType": "contract IUniswapV2Router02",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "pair",
        "type": "address"
      },
      {
        "internalType": "bool",
        "name": "value",
        "type": "bool"
      }
    ],
    "name": "setAutomatedMarketMakerPair",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "uint256",
        "name": "slippageBps",
        "type": "uint256"
      }
    ],
    "name": "setSwapSlippageBps",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "uint256",
        "name": "threshold",
        "type": "uint256"
      }
    ],
    "name": "setSwapThreshold",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "uint256",
        "name": "index",
        "type": "uint256"
      }
    ],
    "name": "stockTokenAt",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "stockTokenCount",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "swapEnabled",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "swapSlippageBps",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "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": "totalRewardsEligibleSupply",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "name": "totalStockDistributed",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "totalSupply",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "pure",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "totalTransactions",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "to",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "amount",
        "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": "amount",
        "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": [],
    "name": "uniswapV2Pair",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "bytes",
        "name": "data",
        "type": "bytes"
      }
    ],
    "name": "unlockCallback",
    "outputs": [
      {
        "internalType": "bytes",
        "name": "",
        "type": "bytes"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "stock",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "ethAmount",
        "type": "uint256"
      }
    ],
    "name": "v4BuyStock",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "stockOut",
        "type": "uint256"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "weth",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "stateMutability": "payable",
    "type": "receive"
  }
]

Source code

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

/*

    Sherwood Treasure Chest — Crypto's first dynamic rewards token that gives YOU
    an investment in top performing stocks.

    X: https://x.com/TreasureChestRH

    regards, schizophrenia onchain

*/

interface IERC20 {
    function balanceOf(address account) external view returns (uint256);
    function transfer(address to, uint256 amount) external returns (bool);
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
    function approve(address spender, uint256 amount) external returns (bool);
}

interface IUniswapV2Factory {
    function getPair(address tokenA, address tokenB) external view returns (address pair);
    function createPair(address tokenA, address tokenB) external returns (address pair);
}

interface IUniswapV2Router02 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);
    function getAmountsOut(uint256 amountIn, address[] calldata path)
        external
        view
        returns (uint256[] memory amounts);

    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external;
}

struct PoolKey {
    address currency0;
    address currency1;
    uint24 fee;
    int24 tickSpacing;
    address hooks;
}

struct V4SwapParams {
    bool zeroForOne;
    int256 amountSpecified;
    uint160 sqrtPriceLimitX96;
}

interface IPoolManager {
    function unlock(bytes calldata data) external returns (bytes memory);
    function swap(PoolKey calldata key, V4SwapParams calldata params, bytes calldata hookData)
        external
        returns (int256 swapDelta);
    function settle() external payable returns (uint256 paid);
    function take(address currency, address to, uint256 amount) external;
    function extsload(bytes32 slot) external view returns (bytes32);
}

contract SherwoodTreasureChest {
    string public constant name = "Sherwood Treasure Chest";
    string public constant symbol = "TREASURE";
    uint8 public constant decimals = 18;

    address public constant DEAD = 0x000000000000000000000000000000000000dEaD;

    uint256 private constant TOTAL_SUPPLY = 1_000_000_000 * 10 ** 18;
    uint256 private constant MAGNITUDE = 2 ** 128;

    uint256 public constant PROCESSOR_SHARE_BPS = 200;

    IUniswapV2Router02 public constant router =
        IUniswapV2Router02(0x89e5DB8B5aA49aA85AC63f691524311AEB649eba);
    IPoolManager public constant poolManager =
        IPoolManager(0x8366a39CC670B4001A1121B8F6A443A643e40951);

    uint24 private constant V4_FEE = 50000;
    int24 private constant V4_TICK_SPACING = 1000;
    uint256 private constant V4_FEE_BPS = 500;
    uint160 private constant MIN_SQRT_PRICE_PLUS_ONE = 4295128740;
    uint256 private constant POOLS_SLOT = 6;

    uint256 public totalTransactions;
    uint256 public swapThreshold;

    uint256 public swapSlippageBps = 300;
    uint256 public constant MAX_SWAP_SLIPPAGE_BPS = 2000;

    address public owner;
    address public devWallet;
    address public uniswapV2Pair;
    address public weth;

    bool public constant swapEnabled = true;
    bool private _inSwap;

    address[] private _stockTokens;
    address[] private _activeRewardTokens;

    uint256 private _totalRewardsSupply;
    uint256 private _activeHolderCount;

    mapping(address => uint256) private _balances;
    mapping(address => mapping(address => uint256)) private _allowances;

    mapping(address => bool) public isExcludedFromFee;
    mapping(address => bool) public isExcludedFromRewards;
    mapping(address => bool) public automatedMarketMakerPairs;
    mapping(address => bool) public isStockToken;
    mapping(address => bool) private _isActiveRewardToken;

    mapping(address => uint256) private _magnifiedDividendPerShare;

    mapping(address => mapping(address => int256)) private _magnifiedDividendCorrections;

    mapping(address => mapping(address => uint256)) private _withdrawnDividends;

    mapping(address => uint256) public totalStockDistributed;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    event DevWalletAllocated(address indexed devWallet, uint256 amount);
    event ExcludedFromRewards(address indexed account, bool excluded);
    event SetAutomatedMarketMakerPair(address indexed pair, bool indexed value);
    event SwapThresholdUpdated(uint256 threshold);
    event V2Configured(address indexed router, address indexed pair);
    event SwapSlippageUpdated(uint256 slippageBps);
    event StockRewardDistributed(address indexed stock, uint256 amount, uint256 indexed stockIndex);
    event RewardClaimed(address indexed account, address indexed stock, uint256 amount);
    event RewardPayoutFailed(address indexed account, address indexed stock, uint256 amount);
    event StockTokenUpdated(address indexed stock, bool added);

    modifier onlyOwner() {
        require(msg.sender == owner, "Not owner");
        _;
    }

    modifier lockTheSwap() {
        _inSwap = true;
        _;
        _inSwap = false;
    }

    constructor(address initialOwner, address devWallet_) {
        require(initialOwner != address(0), "Zero owner");
        require(devWallet_ != address(0), "Zero dev wallet");
        owner = initialOwner;
        devWallet = devWallet_;
        weth = router.WETH();

        uint256 devAmount = (TOTAL_SUPPLY * 5) / 100;
        uint256 ownerAmount = TOTAL_SUPPLY - devAmount;

        if (initialOwner == devWallet_) {

            _balances[initialOwner] = TOTAL_SUPPLY;
            _activeHolderCount = 1;
            emit Transfer(address(0), initialOwner, TOTAL_SUPPLY);
            emit DevWalletAllocated(devWallet_, TOTAL_SUPPLY);
        } else {
            _balances[initialOwner] = ownerAmount;
            _balances[devWallet_] = devAmount;
            _activeHolderCount = 2;
            emit Transfer(address(0), initialOwner, ownerAmount);
            emit Transfer(address(0), devWallet_, devAmount);
            emit DevWalletAllocated(devWallet_, devAmount);
        }
        _totalRewardsSupply = TOTAL_SUPPLY;

        isExcludedFromFee[initialOwner] = true;
        isExcludedFromFee[address(this)] = true;
        isExcludedFromRewards[address(this)] = true;

        isExcludedFromRewards[DEAD] = true;

        swapThreshold = TOTAL_SUPPLY / 400;

        _initStockTokens();

        emit OwnershipTransferred(address(0), initialOwner);
    }

    function _initStockTokens() private {
        _addStock(0xaF3D76f1834A1d425780943C99Ea8A608f8a93f9);
        _addStock(0x86923f96303D656E4aa86D9d42D1e57ad2023fdC);
        _addStock(0x2e0847E8910a9732eB3fb1bb4b70a580ADAD4FE3);
        _addStock(0xd0601CE157Db5bdC3162BbaC2a2C8aF5320D9EEC);
        _addStock(0x4a0E65A3EcceC6dBe60AE065F2e7bb85Fae35eEa);
        _addStock(0x322F0929c4625eD5bAd873c95208D54E1c003b2d);
    }

    function _addStock(address stock) private {
        require(stock != address(0), "Zero stock");
        require(!isStockToken[stock], "Duplicate");
        isStockToken[stock] = true;
        _stockTokens.push(stock);
        emit StockTokenUpdated(stock, true);
    }

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

    function balanceOf(address account) public view returns (uint256) {
        return _balances[account];
    }

    function transfer(address to, uint256 amount) external returns (bool) {
        _transfer(msg.sender, to, amount);
        return true;
    }

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

    function approve(address spender, uint256 amount) external returns (bool) {
        _approve(msg.sender, spender, amount);
        return true;
    }

    function transferFrom(address from, address to, uint256 amount) external returns (bool) {
        uint256 currentAllowance = _allowances[from][msg.sender];
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "Allowance exceeded");
            unchecked {
                _approve(from, msg.sender, currentAllowance - amount);
            }
        }
        _transfer(from, to, amount);
        return true;
    }

    function increaseAllowance(address spender, uint256 addedValue) external returns (bool) {
        _approve(msg.sender, spender, _allowances[msg.sender][spender] + addedValue);
        return true;
    }

    function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool) {
        uint256 currentAllowance = _allowances[msg.sender][spender];
        require(currentAllowance >= subtractedValue, "Decreased below zero");
        unchecked {
            _approve(msg.sender, spender, currentAllowance - subtractedValue);
        }
        return true;
    }

    function currentTaxFeeBps() public view returns (uint256) {
        uint256 r = uint256(
            keccak256(abi.encodePacked(block.prevrandao, block.timestamp, block.number, totalTransactions))
        ) % 3;
        if (r == 0) return 100;
        if (r == 1) return 500;
        return 1000;
    }

    function stockTokenCount() external view returns (uint256) {
        return _stockTokens.length;
    }

    function stockTokenAt(uint256 index) external view returns (address) {
        return _stockTokens[index];
    }

    function activeRewardTokenCount() external view returns (uint256) {
        return _activeRewardTokens.length;
    }

    function activeRewardTokenAt(uint256 index) external view returns (address) {
        return _activeRewardTokens[index];
    }

    function rewardHolderCount() external view returns (uint256) {
        return _activeHolderCount;
    }

    function totalRewardsEligibleSupply() external view returns (uint256) {
        return _totalRewardsSupply;
    }

    function pendingStockRewards(address account, address stock) public view returns (uint256) {
        if (isExcludedFromRewards[account] || !_isActiveRewardToken[stock]) return 0;
        return accumulativeStockOf(account, stock) - _withdrawnDividends[stock][account];
    }

    function accumulativeStockOf(address account, address stock) public view returns (uint256) {
        return uint256(
            int256(_magnifiedDividendPerShare[stock] * _balances[account])
                + _magnifiedDividendCorrections[stock][account]
        ) / MAGNITUDE;
    }

    function claimRewards() external {
        _claimAll(msg.sender);
    }

    function claimReward(address stock) external returns (uint256) {
        return _claim(msg.sender, stock);
    }

    function pushRewards(address[] calldata accounts) external {
        uint256 len = accounts.length;
        for (uint256 i = 0; i < len; i++) {
            _claimAll(accounts[i]);
        }
    }

    function processFees() external {
        require(!_inSwap, "Busy");
        require(_balances[address(this)] >= swapThreshold, "Below threshold");
        this.convertTaxToStock(msg.sender);
    }

    function distributeStockRewards(address stock, uint256 amount) external onlyOwner {
        require(isStockToken[stock], "Not a reward stock");
        require(amount > 0, "Zero amount");
        require(IERC20(stock).transferFrom(msg.sender, address(this), amount), "Transfer failed");
        _distributeStock(stock, amount, type(uint256).max);
    }

    function configureV2() external onlyOwner {
        require(uniswapV2Pair == address(0), "Already configured");
        address factory = router.factory();
        address pair_ = IUniswapV2Factory(factory).getPair(address(this), weth);
        if (pair_ == address(0)) {
            pair_ = IUniswapV2Factory(factory).createPair(address(this), weth);
        }
        uniswapV2Pair = pair_;

        isExcludedFromFee[address(router)] = true;
        _setAutomatedMarketMakerPair(pair_, true);

        emit V2Configured(address(router), pair_);
    }

    function setSwapSlippageBps(uint256 slippageBps) external onlyOwner {
        require(slippageBps <= MAX_SWAP_SLIPPAGE_BPS, "Slippage too high");
        swapSlippageBps = slippageBps;
        emit SwapSlippageUpdated(slippageBps);
    }

    function setSwapThreshold(uint256 threshold) external onlyOwner {
        require(threshold > 0, "Zero threshold");
        swapThreshold = threshold;
        emit SwapThresholdUpdated(threshold);
    }

    function addStockToken(address stock) external onlyOwner {
        _addStock(stock);
    }

    function excludeFromRewards(address account, bool excluded) external onlyOwner {
        require(isExcludedFromRewards[account] != excluded, "Already set");
        if (excluded) {
            _setExcludedFromRewards(account);
        } else {
            _setIncludedInRewards(account);
        }
        emit ExcludedFromRewards(account, excluded);
    }

    function setAutomatedMarketMakerPair(address pair, bool value) external onlyOwner {
        require(pair != uniswapV2Pair || value, "Cannot unset primary pair");
        _setAutomatedMarketMakerPair(pair, value);
    }

    function transferOwnership(address newOwner) external onlyOwner {
        require(newOwner != address(0), "Zero address");
        emit OwnershipTransferred(owner, newOwner);
        owner = newOwner;
    }

    function renounceOwnership() external onlyOwner {
        emit OwnershipTransferred(owner, address(0));
        owner = address(0);
    }

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

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

        if (from == to) {
            if (!_inSwap) _claimAll(from);
            emit Transfer(from, to, amount);
            _bumpTransactionCount();
            return;
        }

        bool isSell = automatedMarketMakerPairs[to];
        bool isBuy = automatedMarketMakerPairs[from];

        if (
            isSell
                && !_inSwap
                && swapEnabled
                && uniswapV2Pair != address(0)
                && _balances[address(this)] >= swapThreshold
        ) {

            try this.convertTaxToStock(address(0)) {} catch {}
        }

        uint256 taxBps = currentTaxFeeBps();
        bool excluded = isExcludedFromFee[from] || isExcludedFromFee[to];
        bool wantFee = (isBuy || isSell) && !excluded && taxBps > 0 && !_inSwap;

        if (wantFee) {

            uint256 feeAmount = (amount * taxBps) / 10_000;
            _moveBalance(from, to, amount - feeAmount);
            _moveBalance(from, address(this), feeAmount);
        } else {
            _moveBalance(from, to, amount);
        }

        if (!_inSwap) {
            _claimAll(from);
            _claimAll(to);
        }

        _bumpTransactionCount();
    }

    function _moveBalance(address from, address to, uint256 amount) private {
        if (amount == 0) return;

        uint256 fromBalanceBefore = _balances[from];
        uint256 toBalanceBefore = _balances[to];

        _balances[from] = fromBalanceBefore - amount;
        _balances[to] += amount;

        _updateDividendCorrections(from, to, amount, fromBalanceBefore, toBalanceBefore);
        emit Transfer(from, to, amount);
    }

    function _updateDividendCorrections(
        address from,
        address to,
        uint256 amount,
        uint256 fromBalanceBefore,
        uint256 toBalanceBefore
    ) private {
        uint256 activeLen = _activeRewardTokens.length;

        if (!isExcludedFromRewards[from]) {
            for (uint256 i = 0; i < activeLen; i++) {
                address stock = _activeRewardTokens[i];
                _magnifiedDividendCorrections[stock][from] +=
                    int256(_magnifiedDividendPerShare[stock] * amount);
            }
            if (fromBalanceBefore == amount) {
                unchecked {
                    _activeHolderCount -= 1;
                }
            }
        }

        if (!isExcludedFromRewards[to]) {
            for (uint256 i = 0; i < activeLen; i++) {
                address stock = _activeRewardTokens[i];
                _magnifiedDividendCorrections[stock][to] -=
                    int256(_magnifiedDividendPerShare[stock] * amount);
            }
            if (toBalanceBefore == 0) {
                unchecked {
                    _activeHolderCount += 1;
                }
            }
        }

        if (isExcludedFromRewards[from] && !isExcludedFromRewards[to]) {
            _totalRewardsSupply += amount;
        } else if (!isExcludedFromRewards[from] && isExcludedFromRewards[to]) {
            _totalRewardsSupply -= amount;
        }
    }

    function _bumpTransactionCount() private {
        unchecked {
            totalTransactions += 1;
        }
    }

    function _setAutomatedMarketMakerPair(address pair, bool value) private {
        automatedMarketMakerPairs[pair] = value;
        if (value && !isExcludedFromRewards[pair]) {
            _setExcludedFromRewards(pair);
        }
        emit SetAutomatedMarketMakerPair(pair, value);
    }

    function _setExcludedFromRewards(address account) private {
        require(!isExcludedFromRewards[account], "Already excluded");

        uint256 balance = _balances[account];
        if (balance > 0) {
            uint256 len = _activeRewardTokens.length;
            for (uint256 i = 0; i < len; i++) {
                _claim(account, _activeRewardTokens[i]);
                _magnifiedDividendCorrections[_activeRewardTokens[i]][account] = 0;
            }
            _totalRewardsSupply -= balance;
            unchecked {
                _activeHolderCount -= 1;
            }
        }
        isExcludedFromRewards[account] = true;
    }

    function _setIncludedInRewards(address account) private {
        require(isExcludedFromRewards[account], "Not excluded");
        isExcludedFromRewards[account] = false;

        uint256 balance = _balances[account];
        uint256 len = _activeRewardTokens.length;
        if (balance > 0) {
            for (uint256 i = 0; i < len; i++) {
                address stock = _activeRewardTokens[i];
                _magnifiedDividendCorrections[stock][account] =
                    -int256(_magnifiedDividendPerShare[stock] * balance);
                _withdrawnDividends[stock][account] = 0;
            }
            _totalRewardsSupply += balance;
            unchecked {
                _activeHolderCount += 1;
            }
        } else {
            for (uint256 i = 0; i < len; i++) {
                _magnifiedDividendCorrections[_activeRewardTokens[i]][account] = 0;
                _withdrawnDividends[_activeRewardTokens[i]][account] = 0;
            }
        }
    }

    function _randomStockIndex(uint256 salt) private view returns (uint256) {
        return uint256(
            keccak256(abi.encodePacked(block.prevrandao, block.timestamp, totalTransactions, salt))
        ) % _stockTokens.length;
    }

    function convertTaxToStock(address processor) external lockTheSwap {
        require(msg.sender == address(this), "Self only");
        if (_totalRewardsSupply == 0 || _stockTokens.length == 0) return;

        uint256 taxAmount = _balances[address(this)];
        if (taxAmount > 0 && uniswapV2Pair != address(0)) {
            _approve(address(this), address(router), taxAmount);
            address[] memory path = new address[](2);
            path[0] = address(this);
            path[1] = weth;
            uint256 minEth;
            try router.getAmountsOut(taxAmount, path) returns (uint256[] memory amounts) {
                minEth = (amounts[1] * (10_000 - swapSlippageBps)) / 10_000;
            } catch {
                return;
            }
            try router.swapExactTokensForETHSupportingFeeOnTransferTokens(
                taxAmount, minEth, path, address(this), block.timestamp
            ) {} catch {
                return;
            }
        }

        uint256 ethAmount = address(this).balance;
        if (ethAmount == 0) return;

        uint256 start = _randomStockIndex(0);
        uint256 len = _stockTokens.length;
        for (uint256 i = 0; i < len; i++) {
            uint256 index = (start + i) % len;
            address stock = _stockTokens[index];
            try this.v4BuyStock(stock, ethAmount) returns (uint256 stockOut) {
                if (stockOut > 0) {
                    uint256 tip;
                    if (processor != address(0) && PROCESSOR_SHARE_BPS > 0) {
                        tip = (stockOut * PROCESSOR_SHARE_BPS) / 10_000;
                        if (tip > 0 && !_safeStockTransfer(stock, processor, tip)) {
                            tip = 0;
                        }
                    }
                    _distributeStock(stock, stockOut - tip, index);
                    return;
                }
            } catch {}
        }

        revert("Conversion failed");
    }

    function v4BuyStock(address stock, uint256 ethAmount) external returns (uint256 stockOut) {
        require(msg.sender == address(this), "Self only");
        uint160 sqrtP = _poolSqrtPrice(stock);
        require(sqrtP > 0, "No V4 pool");

        uint256 s1 = (ethAmount * uint256(sqrtP)) >> 96;
        uint256 expected = (s1 * uint256(sqrtP)) >> 96;
        uint256 minOut = (expected * (10_000 - V4_FEE_BPS - swapSlippageBps)) / 10_000;

        bytes memory res = poolManager.unlock(abi.encode(stock, ethAmount, minOut));
        stockOut = abi.decode(res, (uint256));
    }

    function unlockCallback(bytes calldata data) external returns (bytes memory) {
        require(msg.sender == address(poolManager), "Not PoolManager");
        (address stock, uint256 ethAmount, uint256 minOut) =
            abi.decode(data, (address, uint256, uint256));

        int256 delta = poolManager.swap(
            _poolKey(stock),
            V4SwapParams({
                zeroForOne: true,
                amountSpecified: -int256(ethAmount),
                sqrtPriceLimitX96: MIN_SQRT_PRICE_PLUS_ONE
            }),
            ""
        );

        int128 ethDelta = int128(delta >> 128);
        int128 stockDelta = int128(delta);
        uint256 ethSpent = uint256(uint128(-ethDelta));
        uint256 stockGained = uint256(uint128(stockDelta));

        require(stockGained >= minOut, "V4 slippage");

        poolManager.settle{value: ethSpent}();
        poolManager.take(stock, address(this), stockGained);

        return abi.encode(stockGained);
    }

    function _poolKey(address stock) private pure returns (PoolKey memory) {
        return PoolKey({
            currency0: address(0),
            currency1: stock,
            fee: V4_FEE,
            tickSpacing: V4_TICK_SPACING,
            hooks: address(0)
        });
    }

    function _poolSqrtPrice(address stock) private view returns (uint160) {
        bytes32 poolId = keccak256(abi.encode(_poolKey(stock)));
        bytes32 stateSlot = keccak256(abi.encode(poolId, POOLS_SLOT));
        return uint160(uint256(poolManager.extsload(stateSlot)));
    }

    function _distributeStock(address stock, uint256 amount, uint256 stockIndex) private {
        if (amount == 0 || _totalRewardsSupply == 0) return;

        if (!_isActiveRewardToken[stock]) {
            _isActiveRewardToken[stock] = true;
            _activeRewardTokens.push(stock);
        }

        _magnifiedDividendPerShare[stock] += (amount * MAGNITUDE) / _totalRewardsSupply;
        totalStockDistributed[stock] += amount;

        emit StockRewardDistributed(stock, amount, stockIndex);
    }

    function _claimAll(address account) private {
        if (isExcludedFromRewards[account] || _activeRewardTokens.length == 0) return;
        uint256 len = _activeRewardTokens.length;
        for (uint256 i = 0; i < len; i++) {
            _claim(account, _activeRewardTokens[i]);
        }
    }

    function _claim(address account, address stock) private returns (uint256) {
        uint256 amount = pendingStockRewards(account, stock);
        if (amount == 0) return 0;

        _withdrawnDividends[stock][account] += amount;

        if (!_safeStockTransfer(stock, account, amount)) {
            _withdrawnDividends[stock][account] -= amount;
            emit RewardPayoutFailed(account, stock, amount);
            return 0;
        }

        emit RewardClaimed(account, stock, amount);
        return amount;
    }

    function _safeStockTransfer(address stock, address to, uint256 amount) private returns (bool) {
        (bool success, bytes memory data) =
            stock.call(abi.encodeWithSelector(IERC20.transfer.selector, to, amount));
        return success && (data.length == 0 || abi.decode(data, (bool)));
    }

    receive() external payable {}
}
Chain explorer3253msChain node155ms