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