creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "Simulationbot2.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\npragma solidity ^0.8.0;\r\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\r\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\r\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\r\n\r\ncontract Hello is Ownable, Pausable {\r\n    struct Wallet {\r\n        address _address;\r\n        uint256 _point;\r\n    }\r\n    mapping(address => uint256) private ids;\r\n    Wallet[] public wallets;\r\n    address public token;\r\n    uint256 public totalETH;\r\n    uint256 public gasFee;\r\n\r\n    event UpdatedToken(address prevToken, address newToken);\r\n    event AddedWallet(address _address, uint256 _point);\r\n    event RemovedWallet(address _address);\r\n    event Deposited(address from, uint256 amount);\r\n    event Withdrawn(address to, uint256 amount);\r\n    event Buy(address token, address[] wallets, uint256 slippage, uint256 amount);\r\n    event Sell(address token, address[] wallets, uint256 slippage, uint256 amount);\r\n\r\n    constructor() Ownable(msg.sender) {\r\n    }\r\n\r\n    function updateToken(address newToken) public onlyOwner {\r\n        address prevToken = token;\r\n        token = newToken;\r\n        emit UpdatedToken(prevToken, newToken);\r\n    }\r\n\r\n    function setGasFee(uint256 _gasFee) public onlyOwner {\r\n        gasFee = _gasFee;\r\n    }\r\n\r\n    function addWallet(address _address, uint256 _point) public onlyOwner {\r\n        require(_address != address(0), \"invalid wallet address\");\r\n        require(_point < 10000, \"point less than 10000\");\r\n        require(ids[_address] == 0, \"already registered address\");\r\n\r\n        wallets.push(Wallet(_address, _point));\r\n        ids[_address] = wallets.length;\r\n\r\n        emit AddedWallet(_address, _point);\r\n    }\r\n\r\n    function addWallets(address[] memory _addresses, uint256[] memory _points) public onlyOwner {\r\n        require(_addresses.length == _points.length, \"invalid length\");\r\n\r\n        for(uint256 i = 0 ; i < _addresses.length; i++) {\r\n            addWallet(_addresses[i], _points[i]);\r\n        }\r\n    }\r\n\r\n    function removeWallet(address _address) public onlyOwner {\r\n        require(_address != address(0), \"invalid wallet address\");\r\n        require(ids[_address] > 0, \"not registered address\");\r\n\r\n        uint256 id = ids[_address];\r\n        delete ids[_address];\r\n\r\n        if (wallets.length > 0) {\r\n            Wallet memory lastWallet = wallets[wallets.length - 1];\r\n            wallets[id - 1] = lastWallet;\r\n            ids[lastWallet._address] = id;\r\n        }\r\n\r\n        wallets.pop();\r\n        emit RemovedWallet(_address);\r\n    }\r\n\r\n    function _random(uint256 x) internal pure returns (uint256) {\r\n        return (16807 * x) % 2147483647;\r\n    }\r\n\r\n    function _randomSelectWallets(uint256 total, uint256 n) internal view returns (uint256[] memory) {\r\n        require(total >= n, \"invalid parameter\");\r\n\r\n        uint256 x = block.timestamp;\r\n        bool[] memory flag = new bool[](total);\r\n        uint256[] memory arr = new uint256[](n);\r\n\r\n        for(uint256 i = 0; i < n;) {\r\n            x = _random(x);\r\n            uint256 id = x % total;\r\n            if(!flag[id]) {\r\n                flag[id] = true;\r\n                arr[i] = id;\r\n                i++;\r\n            }\r\n        }\r\n\r\n        return arr;\r\n    } \r\n\r\n    function deposit() public payable {\r\n        uint256 amount = msg.value;\r\n        totalETH += amount;\r\n\r\n        emit Deposited(msg.sender, totalETH);\r\n    }\r\n\r\n    function withdraw(address to, uint256 amount) public onlyOwner {\r\n        require(totalETH >= amount, \"amount exceeds the contract balance\");\r\n        totalETH -= amount;\r\n        payable(to).transfer(amount);\r\n\r\n        emit Withdrawn(to, amount);\r\n    }\r\n\r\n    function buy(uint256 n, uint256 slippage, uint256 amount) public onlyOwner {\r\n        require(wallets.length > 0, \" wallets not registered\");\r\n        require(slippage >= 1 && slippage <= 100, \"slippage's range from 1 to 100\");\r\n        require(totalETH >= amount, \"amount exceeds the contract balance\");\r\n\r\n        totalETH -= amount;\r\n\r\n        uint256[] memory arr = _randomSelectWallets(wallets.length, n);\r\n        address[] memory selectedWallets = new address[](n);\r\n        uint256 totalPoint = 0;\r\n        for(uint256 i = 0; i < n; i ++) {\r\n            uint256 id = arr[i];\r\n            totalPoint += wallets[id]._point;\r\n        }\r\n\r\n        uint256 divideAmountPerPoint = amount * 1e12 / totalPoint;\r\n        uint256 restAmount = amount;\r\n\r\n        for(uint256 i = 0; i < n; i++) {\r\n            uint256 id = arr[i];\r\n\r\n            uint256 divideAmount;\r\n            if(i < n - 1) divideAmount = divideAmountPerPoint * wallets[id]._point / 1e12;\r\n            else divideAmount = restAmount;\r\n\r\n            restAmount -= divideAmount;\r\n            selectedWallets[i] = wallets[id]._address;\r\n\r\n            payable(selectedWallets[i]).transfer(divideAmount);\r\n        }\r\n\r\n        emit Buy(token, selectedWallets, slippage, amount);\r\n    }\r\n\r\n    function sell(uint256 slippage, uint256 amount) public onlyOwner {\r\n        require(wallets.length > 0, \" wallets not registered\");\r\n        require(slippage >= 1 && slippage <= 100, \"slippage's range from 1 to 100\");\r\n\r\n        uint256[] memory arr = _randomSelectWallets(wallets.length, wallets.length);\r\n        IERC20 _token = IERC20(token);\r\n        uint256 rest = amount;\r\n        uint256 n = 0;\r\n        for(uint256 i = 0; i < wallets.length && rest > 0; i++) {\r\n            uint256 id = arr[i];\r\n            uint256 balance = _token.balanceOf(wallets[id]._address);\r\n            if(balance > 0) {\r\n                if(rest > balance) rest -= balance;\r\n                else rest = 0;\r\n                n++;\r\n            }\r\n        }\r\n\r\n        address[] memory selectedWallets = new address[](n);\r\n        for(uint256 i = 0; i < n; i++) {\r\n            uint256 id = arr[i];\r\n            selectedWallets[i] = wallets[id]._address;\r\n            payable(wallets[id]._address).transfer(gasFee);\r\n        }\r\n\r\n        emit Sell(token, selectedWallets, slippage, amount - rest);\r\n    }\r\n\r\n    function getTotalBalance() public view returns(uint256) {\r\n        IERC20 _token = IERC20(token);\r\n\r\n        uint256 total = 0;\r\n        for(uint256 i = 0; i < wallets.length; i++) {\r\n            uint256 balance = _token.balanceOf(wallets[i]._address);\r\n            total += balance;\r\n        }\r\n\r\n        return total;\r\n    }\r\n\r\n    receive() external payable {\r\n        uint256 amount = msg.value;\r\n        totalETH += amount;\r\n\r\n        emit Deposited(msg.sender, totalETH);       \r\n    }\r\n}"
      },
      "@openzeppelin/contracts/security/Pausable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract Pausable is Context {\n    /**\n     * @dev Emitted when the pause is triggered by `account`.\n     */\n    event Paused(address account);\n\n    /**\n     * @dev Emitted when the pause is lifted by `account`.\n     */\n    event Unpaused(address account);\n\n    bool private _paused;\n\n    /**\n     * @dev Initializes the contract in unpaused state.\n     */\n    constructor() {\n        _paused = false;\n    }\n\n    /**\n     * @dev Modifier to make a function callable only when the contract is not paused.\n     *\n     * Requirements:\n     *\n     * - The contract must not be paused.\n     */\n    modifier whenNotPaused() {\n        _requireNotPaused();\n        _;\n    }\n\n    /**\n     * @dev Modifier to make a function callable only when the contract is paused.\n     *\n     * Requirements:\n     *\n     * - The contract must be paused.\n     */\n    modifier whenPaused() {\n        _requirePaused();\n        _;\n    }\n\n    /**\n     * @dev Returns true if the contract is paused, and false otherwise.\n     */\n    function paused() public view virtual returns (bool) {\n        return _paused;\n    }\n\n    /**\n     * @dev Throws if the contract is paused.\n     */\n    function _requireNotPaused() internal view virtual {\n        require(!paused(), \"Pausable: paused\");\n    }\n\n    /**\n     * @dev Throws if the contract is not paused.\n     */\n    function _requirePaused() internal view virtual {\n        require(paused(), \"Pausable: not paused\");\n    }\n\n    /**\n     * @dev Triggers stopped state.\n     *\n     * Requirements:\n     *\n     * - The contract must not be paused.\n     */\n    function _pause() internal virtual whenNotPaused {\n        _paused = true;\n        emit Paused(_msgSender());\n    }\n\n    /**\n     * @dev Returns to normal state.\n     *\n     * Requirements:\n     *\n     * - The contract must be paused.\n     */\n    function _unpause() internal virtual whenPaused {\n        _paused = false;\n        emit Unpaused(_msgSender());\n    }\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the value of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the value of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves a `value` amount of tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 value) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n     * caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 value) external returns (bool);\n\n    /**\n     * @dev Moves a `value` amount of tokens from `from` to `to` using the\n     * allowance mechanism. `value` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n"
      },
      "@openzeppelin/contracts/access/Ownable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * The initial owner is set to the address provided by the deployer. This can\n * later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    /**\n     * @dev The caller account is not authorized to perform an operation.\n     */\n    error OwnableUnauthorizedAccount(address account);\n\n    /**\n     * @dev The owner is not a valid owner account. (eg. `address(0)`)\n     */\n    error OwnableInvalidOwner(address owner);\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n     */\n    constructor(address initialOwner) {\n        if (initialOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\n        _transferOwnership(initialOwner);\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        if (owner() != _msgSender()) {\n            revert OwnableUnauthorizedAccount(_msgSender());\n        }\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        if (newOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/Context.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    function _contextSuffixLength() internal view virtual returns (uint256) {\n        return 0;\n    }\n}\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      }
    }
  }}