creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "FeeDistri.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n// ethereum\r\n// impl: 0x309c656a95c04A9a7b7E055Cce16A733cf40D40b\r\n// proxy: 0x07a844f086E33eE8fef9Bea54dEaf329880F13f7\r\n// arbitrum\r\n// impl: 0x3c86Fd44a3713383037f60ed9a4494Be093b3EE5\r\n// proxy: 0x00DD2Caa56fAfbab7529147Ab5d2763978f50e8D\r\n// bsc\r\n// impl: 0x3c86Fd44a3713383037f60ed9a4494Be093b3EE5\r\n// proxy: 0x00DD2Caa56fAfbab7529147Ab5d2763978f50e8D\r\n// base\r\n// impl: 0x3c86Fd44a3713383037f60ed9a4494Be093b3EE5\r\n// proxy: 0x00DD2Caa56fAfbab7529147Ab5d2763978f50e8D\r\n\r\npragma solidity ^0.8.0;\r\n\r\ncontract AlphaXBotsFeeDist {\r\n    struct FeeItem {\r\n        address user;\r\n        uint256 share;\r\n    }\r\n\r\n    uint256 constant RESOLUTION = 10000;\r\n\r\n    bool initialized;\r\n    bool isEntering;\r\n    address public owner;\r\n\r\n    uint256 public totalAmount;\r\n\r\n    FeeItem[] feeItems;\r\n\r\n    address public defaultFeeReceiver;\r\n\r\n    event TransferOwnership(address indexed oldOwner, address indexed newOwner);\r\n\r\n    modifier nonReentrant() {\r\n        require(!isEntering, \"Already Entered\");\r\n        isEntering = true;\r\n        _;\r\n        isEntering = false;\r\n    }\r\n\r\n    modifier onlyOwner() {\r\n        require(msg.sender == owner, \"Not Owner\");\r\n        _;\r\n    }\r\n\r\n    function initialize() external {\r\n        require(!initialized, \"Already Initialized\");\r\n        initialized = true;\r\n\r\n        emit TransferOwnership(address(0), msg.sender);\r\n        owner = msg.sender;\r\n        defaultFeeReceiver = msg.sender;\r\n    }\r\n\r\n    function transferOwnership(address newOwner) external onlyOwner {\r\n        require(newOwner != address(0), \"Null Address\");\r\n        emit TransferOwnership(owner, newOwner);\r\n        owner = newOwner;\r\n    }\r\n\r\n    function renounceOwnership() external onlyOwner {\r\n        emit TransferOwnership(owner, address(0));\r\n        owner = address(0);\r\n    }\r\n\r\n    function setFeeItems(FeeItem[] calldata items) external onlyOwner {\r\n        delete feeItems;\r\n        uint256 i;\r\n        for (i = 0; i < items.length; i ++) {\r\n            feeItems.push(items[i]);\r\n        }\r\n    }\r\n\r\n    function setDefaultFeeReceiver(address newReceiver) external onlyOwner {\r\n        require(defaultFeeReceiver != newReceiver, \"Already Set\");\r\n        defaultFeeReceiver = newReceiver;\r\n    }\r\n\r\n    function getFeeItems() external view returns (FeeItem[] memory) {\r\n        return feeItems;\r\n    }\r\n\r\n    function deposit(address[] calldata referees) external nonReentrant payable {\r\n        uint256 totalValue = msg.value;\r\n\r\n        totalAmount += totalValue;\r\n        uint256 spent = 0;\r\n        uint256 i = 0;\r\n        for (i = 0; i < feeItems.length; i ++) {\r\n            FeeItem storage fi = feeItems[i];\r\n            uint256 amount = totalValue * fi.share / RESOLUTION;\r\n            spent += pay(fi.user, amount);\r\n        }\r\n\r\n        if (spent < totalValue) {\r\n            totalValue = (totalValue - spent);\r\n            spent = 0;\r\n            for (i = 0; i < referees.length; i ++) {\r\n                uint256 amount = totalValue / referees.length;\r\n                spent += pay(referees[i], amount);\r\n            }\r\n        }\r\n\r\n        if (spent < totalValue) {\r\n            pay(defaultFeeReceiver, totalValue - spent);\r\n        }\r\n    }\r\n\r\n    receive() external payable {\r\n    }\r\n\r\n    function pay(address user, uint256 amount) internal returns (uint256) {\r\n        (bool success, ) = payable(user).call{value: amount}(\"\");\r\n        if (!success) {\r\n            return 0;\r\n        }\r\n        return amount;\r\n    }\r\n}\r\n\r\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      }
    }
  }}