File size: 109,821 Bytes
f998fcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{
  "language": "Solidity",
  "sources": {
    "contracts/Airdrop.sol": {
      "content": "pragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/utils/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"./helpers/TransferHelper.sol\";\n\ncontract Airdrop is Ownable {\n  using Address for address;\n  using SafeMath for uint256;\n\n  struct AirdropItem {\n    address to;\n    uint256 amount;\n  }\n\n  uint256 public fee;\n\n  constructor(uint256 _fee) {\n    fee = _fee;\n  }\n\n  function setFee(uint256 _fee) external onlyOwner {\n    fee = _fee;\n  }\n\n  function drop(address token, AirdropItem[] memory airdropItems) external payable {\n    require(token.isContract(), \"must_be_contract_address\");\n    require(msg.value >= fee, \"fee\");\n\n    uint256 totalSent;\n\n    for (uint256 i = 0; i < airdropItems.length; i++) totalSent = totalSent.add(airdropItems[i].amount);\n\n    require(IERC20(token).allowance(_msgSender(), address(this)) >= totalSent, \"not_enough_allowance\");\n\n    for (uint256 i = 0; i < airdropItems.length; i++) {\n      TransferHelpers._safeTransferFromERC20(token, _msgSender(), airdropItems[i].to, airdropItems[i].amount);\n    }\n  }\n\n  function retrieveEther(address to) external onlyOwner {\n    TransferHelpers._safeTransferEther(to, address(this).balance);\n  }\n\n  function retrieveERC20(\n    address token,\n    address to,\n    uint256 amount\n  ) external onlyOwner {\n    TransferHelpers._safeTransferERC20(token, to, amount);\n  }\n\n  receive() external payable {}\n}\n"
    },
    "contracts/helpers/TransferHelper.sol": {
      "content": "pragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/utils/Address.sol\";\n\nlibrary TransferHelpers {\n  using Address for address;\n\n  function _safeTransferEther(address to, uint256 amount) internal returns (bool success) {\n    (success, ) = to.call{value: amount}(new bytes(0));\n    require(success, \"failed to transfer ether\");\n  }\n\n  function _safeTransferERC20(\n    address token,\n    address to,\n    uint256 amount\n  ) internal returns (bool success) {\n    require(token.isContract(), \"call_to_non_contract\");\n    (success, ) = token.call(abi.encodeWithSelector(bytes4(keccak256(bytes(\"transfer(address,uint256)\"))), to, amount));\n    require(success, \"low_level_contract_call_failed\");\n  }\n\n  function _safeTransferFromERC20(\n    address token,\n    address spender,\n    address recipient,\n    uint256 amount\n  ) internal returns (bool success) {\n    require(token.isContract(), \"call_to_non_contract\");\n    (success, ) = token.call(abi.encodeWithSelector(bytes4(keccak256(bytes(\"transferFrom(address,address,uint256)\"))), spender, recipient, amount));\n    require(success, \"low_level_contract_call_failed\");\n  }\n}\n"
    },
    "@openzeppelin/contracts/access/Ownable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../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 * By default, the owner account will be the one that deploys the contract. This\n * can 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    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    constructor() {\n        _transferOwnership(_msgSender());\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        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions anymore. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby removing 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        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\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/Address.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length > 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCall(target, data, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        require(isContract(target), \"Address: call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        require(isContract(target), \"Address: static call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(isContract(target), \"Address: delegate call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            // Look for revert reason and bubble it up if present\n            if (returndata.length > 0) {\n                // The easiest way to bubble the revert reason is using memory via assembly\n                /// @solidity memory-safe-assembly\n                assembly {\n                    let returndata_size := mload(returndata)\n                    revert(add(32, returndata), returndata_size)\n                }\n            } else {\n                revert(errorMessage);\n            }\n        }\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/math/SafeMath.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol)\n\npragma solidity ^0.8.0;\n\n// CAUTION\n// This version of SafeMath should only be used with Solidity 0.8 or later,\n// because it relies on the compiler's built in overflow checks.\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations.\n *\n * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler\n * now has built in overflow checking.\n */\nlibrary SafeMath {\n    /**\n     * @dev Returns the addition of two unsigned integers, with an overflow flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            uint256 c = a + b;\n            if (c < a) return (false, 0);\n            return (true, c);\n        }\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.\n     *\n     * _Available since v3.4._\n     */\n    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            if (b > a) return (false, 0);\n            return (true, a - b);\n        }\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n            // benefit is lost if 'b' is also tested.\n            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n            if (a == 0) return (true, 0);\n            uint256 c = a * b;\n            if (c / a != b) return (false, 0);\n            return (true, c);\n        }\n    }\n\n    /**\n     * @dev Returns the division of two unsigned integers, with a division by zero flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            if (b == 0) return (false, 0);\n            return (true, a / b);\n        }\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            if (b == 0) return (false, 0);\n            return (true, a % b);\n        }\n    }\n\n    /**\n     * @dev Returns the addition of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `+` operator.\n     *\n     * Requirements:\n     *\n     * - Addition cannot overflow.\n     */\n    function add(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a + b;\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting on\n     * overflow (when the result is negative).\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a - b;\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `*` operator.\n     *\n     * Requirements:\n     *\n     * - Multiplication cannot overflow.\n     */\n    function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a * b;\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers, reverting on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity's `/` operator.\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a / b;\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * reverting when dividing by zero.\n     *\n     * Counterpart to Solidity's `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a % b;\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n     * overflow (when the result is negative).\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {trySub}.\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(\n        uint256 a,\n        uint256 b,\n        string memory errorMessage\n    ) internal pure returns (uint256) {\n        unchecked {\n            require(b <= a, errorMessage);\n            return a - b;\n        }\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers, reverting with custom message on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity's `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(\n        uint256 a,\n        uint256 b,\n        string memory errorMessage\n    ) internal pure returns (uint256) {\n        unchecked {\n            require(b > 0, errorMessage);\n            return a / b;\n        }\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * reverting with custom message when dividing by zero.\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {tryMod}.\n     *\n     * Counterpart to Solidity's `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(\n        uint256 a,\n        uint256 b,\n        string memory errorMessage\n    ) internal pure returns (uint256) {\n        unchecked {\n            require(b > 0, errorMessage);\n            return a % b;\n        }\n    }\n}\n"
    },
    "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\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 amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` 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 amount) 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 `amount` as the allowance of `spender` over the 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 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `from` to `to` using the\n     * allowance mechanism. `amount` 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(\n        address from,\n        address to,\n        uint256 amount\n    ) external returns (bool);\n}\n"
    },
    "@openzeppelin/contracts/utils/Context.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\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"
    },
    "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the symbol of the token.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the decimals places of the token.\n     */\n    function decimals() external view returns (uint8);\n}\n"
    },
    "@openzeppelin/contracts/token/ERC20/ERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n    mapping(address => uint256) private _balances;\n\n    mapping(address => mapping(address => uint256)) private _allowances;\n\n    uint256 private _totalSupply;\n\n    string private _name;\n    string private _symbol;\n\n    /**\n     * @dev Sets the values for {name} and {symbol}.\n     *\n     * The default value of {decimals} is 18. To select a different value for\n     * {decimals} you should overload it.\n     *\n     * All two of these values are immutable: they can only be set once during\n     * construction.\n     */\n    constructor(string memory name_, string memory symbol_) {\n        _name = name_;\n        _symbol = symbol_;\n    }\n\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() public view virtual override returns (string memory) {\n        return _name;\n    }\n\n    /**\n     * @dev Returns the symbol of the token, usually a shorter version of the\n     * name.\n     */\n    function symbol() public view virtual override returns (string memory) {\n        return _symbol;\n    }\n\n    /**\n     * @dev Returns the number of decimals used to get its user representation.\n     * For example, if `decimals` equals `2`, a balance of `505` tokens should\n     * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n     *\n     * Tokens usually opt for a value of 18, imitating the relationship between\n     * Ether and Wei. This is the value {ERC20} uses, unless this function is\n     * overridden;\n     *\n     * NOTE: This information is only used for _display_ purposes: it in\n     * no way affects any of the arithmetic of the contract, including\n     * {IERC20-balanceOf} and {IERC20-transfer}.\n     */\n    function decimals() public view virtual override returns (uint8) {\n        return 18;\n    }\n\n    /**\n     * @dev See {IERC20-totalSupply}.\n     */\n    function totalSupply() public view virtual override returns (uint256) {\n        return _totalSupply;\n    }\n\n    /**\n     * @dev See {IERC20-balanceOf}.\n     */\n    function balanceOf(address account) public view virtual override returns (uint256) {\n        return _balances[account];\n    }\n\n    /**\n     * @dev See {IERC20-transfer}.\n     *\n     * Requirements:\n     *\n     * - `to` cannot be the zero address.\n     * - the caller must have a balance of at least `amount`.\n     */\n    function transfer(address to, uint256 amount) public virtual override returns (bool) {\n        address owner = _msgSender();\n        _transfer(owner, to, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-allowance}.\n     */\n    function allowance(address owner, address spender) public view virtual override returns (uint256) {\n        return _allowances[owner][spender];\n    }\n\n    /**\n     * @dev See {IERC20-approve}.\n     *\n     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n     * `transferFrom`. This is semantically equivalent to an infinite approval.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function approve(address spender, uint256 amount) public virtual override returns (bool) {\n        address owner = _msgSender();\n        _approve(owner, spender, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-transferFrom}.\n     *\n     * Emits an {Approval} event indicating the updated allowance. This is not\n     * required by the EIP. See the note at the beginning of {ERC20}.\n     *\n     * NOTE: Does not update the allowance if the current allowance\n     * is the maximum `uint256`.\n     *\n     * Requirements:\n     *\n     * - `from` and `to` cannot be the zero address.\n     * - `from` must have a balance of at least `amount`.\n     * - the caller must have allowance for ``from``'s tokens of at least\n     * `amount`.\n     */\n    function transferFrom(\n        address from,\n        address to,\n        uint256 amount\n    ) public virtual override returns (bool) {\n        address spender = _msgSender();\n        _spendAllowance(from, spender, amount);\n        _transfer(from, to, amount);\n        return true;\n    }\n\n    /**\n     * @dev Atomically increases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n        address owner = _msgSender();\n        _approve(owner, spender, allowance(owner, spender) + addedValue);\n        return true;\n    }\n\n    /**\n     * @dev Atomically decreases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `spender` must have allowance for the caller of at least\n     * `subtractedValue`.\n     */\n    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n        address owner = _msgSender();\n        uint256 currentAllowance = allowance(owner, spender);\n        require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n        unchecked {\n            _approve(owner, spender, currentAllowance - subtractedValue);\n        }\n\n        return true;\n    }\n\n    /**\n     * @dev Moves `amount` of tokens from `from` to `to`.\n     *\n     * This internal function is equivalent to {transfer}, and can be used to\n     * e.g. implement automatic token fees, slashing mechanisms, etc.\n     *\n     * Emits a {Transfer} event.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `from` must have a balance of at least `amount`.\n     */\n    function _transfer(\n        address from,\n        address to,\n        uint256 amount\n    ) internal virtual {\n        require(from != address(0), \"ERC20: transfer from the zero address\");\n        require(to != address(0), \"ERC20: transfer to the zero address\");\n\n        _beforeTokenTransfer(from, to, amount);\n\n        uint256 fromBalance = _balances[from];\n        require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n        unchecked {\n            _balances[from] = fromBalance - amount;\n        }\n        _balances[to] += amount;\n\n        emit Transfer(from, to, amount);\n\n        _afterTokenTransfer(from, to, amount);\n    }\n\n    /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n     * the total supply.\n     *\n     * Emits a {Transfer} event with `from` set to the zero address.\n     *\n     * Requirements:\n     *\n     * - `account` cannot be the zero address.\n     */\n    function _mint(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: mint to the zero address\");\n\n        _beforeTokenTransfer(address(0), account, amount);\n\n        _totalSupply += amount;\n        _balances[account] += amount;\n        emit Transfer(address(0), account, amount);\n\n        _afterTokenTransfer(address(0), account, amount);\n    }\n\n    /**\n     * @dev Destroys `amount` tokens from `account`, reducing the\n     * total supply.\n     *\n     * Emits a {Transfer} event with `to` set to the zero address.\n     *\n     * Requirements:\n     *\n     * - `account` cannot be the zero address.\n     * - `account` must have at least `amount` tokens.\n     */\n    function _burn(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: burn from the zero address\");\n\n        _beforeTokenTransfer(account, address(0), amount);\n\n        uint256 accountBalance = _balances[account];\n        require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n        unchecked {\n            _balances[account] = accountBalance - amount;\n        }\n        _totalSupply -= amount;\n\n        emit Transfer(account, address(0), amount);\n\n        _afterTokenTransfer(account, address(0), amount);\n    }\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n     *\n     * This internal function is equivalent to `approve`, and can be used to\n     * e.g. set automatic allowances for certain subsystems, etc.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `owner` cannot be the zero address.\n     * - `spender` cannot be the zero address.\n     */\n    function _approve(\n        address owner,\n        address spender,\n        uint256 amount\n    ) internal virtual {\n        require(owner != address(0), \"ERC20: approve from the zero address\");\n        require(spender != address(0), \"ERC20: approve to the zero address\");\n\n        _allowances[owner][spender] = amount;\n        emit Approval(owner, spender, amount);\n    }\n\n    /**\n     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n     *\n     * Does not update the allowance amount in case of infinite allowance.\n     * Revert if not enough allowance is available.\n     *\n     * Might emit an {Approval} event.\n     */\n    function _spendAllowance(\n        address owner,\n        address spender,\n        uint256 amount\n    ) internal virtual {\n        uint256 currentAllowance = allowance(owner, spender);\n        if (currentAllowance != type(uint256).max) {\n            require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n            unchecked {\n                _approve(owner, spender, currentAllowance - amount);\n            }\n        }\n    }\n\n    /**\n     * @dev Hook that is called before any transfer of tokens. This includes\n     * minting and burning.\n     *\n     * Calling conditions:\n     *\n     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n     * will be transferred to `to`.\n     * - when `from` is zero, `amount` tokens will be minted for `to`.\n     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n     * - `from` and `to` are never both zero.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _beforeTokenTransfer(\n        address from,\n        address to,\n        uint256 amount\n    ) internal virtual {}\n\n    /**\n     * @dev Hook that is called after any transfer of tokens. This includes\n     * minting and burning.\n     *\n     * Calling conditions:\n     *\n     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n     * has been transferred to `to`.\n     * - when `from` is zero, `amount` tokens have been minted for `to`.\n     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n     * - `from` and `to` are never both zero.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _afterTokenTransfer(\n        address from,\n        address to,\n        uint256 amount\n    ) internal virtual {}\n}\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"
    },
    "contracts/TokenSaleCreator.sol": {
      "content": "pragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/utils/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"./interfaces/ITokenSaleCreator.sol\";\nimport \"./helpers/TransferHelper.sol\";\n\ncontract TokenSaleCreator is ReentrancyGuard, Pausable, Ownable, AccessControl, ITokenSaleCreator {\n  using Address for address;\n  using SafeMath for uint256;\n\n  bytes32[] public allTokenSales;\n  bytes32 public pauserRole = keccak256(abi.encodePacked(\"PAUSER_ROLE\"));\n  bytes32 public withdrawerRole = keccak256(abi.encodePacked(\"WITHDRAWER_ROLE\"));\n  bytes32 public finalizerRole = keccak256(abi.encodePacked(\"FINALIZER_ROLE\"));\n  uint256 public withdrawable;\n\n  uint8 public feePercentage;\n  uint256 public saleCreationFee;\n\n  mapping(bytes32 => TokenSaleItem) private tokenSales;\n  mapping(bytes32 => uint256) private totalEtherRaised;\n  mapping(bytes32 => mapping(address => bool)) private isNotAllowedToContribute;\n  mapping(bytes32 => mapping(address => uint256)) public amountContributed;\n  mapping(bytes32 => mapping(address => uint256)) public balance;\n\n  modifier whenParamsSatisfied(bytes32 saleId) {\n    TokenSaleItem memory tokenSale = tokenSales[saleId];\n    require(!tokenSale.interrupted, \"token_sale_paused\");\n    require(block.timestamp >= tokenSale.saleStartTime, \"token_sale_not_started_yet\");\n    require(!tokenSale.ended, \"token_sale_has_ended\");\n    require(!isNotAllowedToContribute[saleId][_msgSender()], \"you_are_not_allowed_to_participate_in_this_sale\");\n    require(totalEtherRaised[saleId] < tokenSale.hardCap, \"hardcap_reached\");\n    _;\n  }\n\n  constructor(uint8 _feePercentage, uint256 _saleCreationFee) {\n    _grantRole(pauserRole, _msgSender());\n    _grantRole(withdrawerRole, _msgSender());\n    _grantRole(finalizerRole, _msgSender());\n    feePercentage = _feePercentage;\n    saleCreationFee = _saleCreationFee;\n  }\n\n  function initTokenSale(\n    address token,\n    uint256 tokensForSale,\n    uint256 hardCap,\n    uint256 softCap,\n    uint256 presaleRate,\n    uint256 minContributionEther,\n    uint256 maxContributionEther,\n    uint256 saleStartTime,\n    uint256 daysToLast,\n    address proceedsTo,\n    address admin\n  ) external payable whenNotPaused nonReentrant returns (bytes32 saleId) {\n    {\n      require(msg.value >= saleCreationFee, \"fee\");\n      require(token.isContract(), \"must_be_contract_address\");\n      require(saleStartTime > block.timestamp && saleStartTime.sub(block.timestamp) >= 24 hours, \"sale_must_begin_in_at_least_24_hours\");\n      require(IERC20(token).allowance(_msgSender(), address(this)) >= tokensForSale, \"not_enough_allowance_given\");\n      TransferHelpers._safeTransferFromERC20(token, _msgSender(), address(this), tokensForSale);\n    }\n    saleId = keccak256(\n      abi.encodePacked(\n        token,\n        _msgSender(),\n        block.timestamp,\n        tokensForSale,\n        hardCap,\n        softCap,\n        presaleRate,\n        minContributionEther,\n        maxContributionEther,\n        saleStartTime,\n        daysToLast,\n        proceedsTo\n      )\n    );\n    // Added to prevent 'stack too deep' error\n    uint256 endTime;\n    {\n      endTime = saleStartTime.add(daysToLast.mul(1 days));\n      tokenSales[saleId] = TokenSaleItem(\n        token,\n        tokensForSale,\n        hardCap,\n        softCap,\n        presaleRate,\n        saleId,\n        minContributionEther,\n        maxContributionEther,\n        saleStartTime,\n        endTime,\n        false,\n        proceedsTo,\n        admin,\n        tokensForSale,\n        false\n      );\n    }\n    allTokenSales.push(saleId);\n    withdrawable = msg.value;\n    emit TokenSaleItemCreated(\n      saleId,\n      token,\n      tokensForSale,\n      hardCap,\n      softCap,\n      presaleRate,\n      minContributionEther,\n      maxContributionEther,\n      saleStartTime,\n      endTime,\n      proceedsTo,\n      admin\n    );\n  }\n\n  function contribute(bytes32 saleId) external payable whenNotPaused nonReentrant whenParamsSatisfied(saleId) {\n    TokenSaleItem storage tokenSaleItem = tokenSales[saleId];\n    require(\n      msg.value >= tokenSaleItem.minContributionEther && msg.value <= tokenSaleItem.maxContributionEther,\n      \"contribution_must_be_within_min_and_max_range\"\n    );\n    uint256 val = tokenSaleItem.presaleRate.mul(msg.value).div(1 ether);\n    require(tokenSaleItem.availableTokens >= val, \"tokens_available_for_sale_is_less\");\n    balance[saleId][_msgSender()] = balance[saleId][_msgSender()].add(val);\n    amountContributed[saleId][_msgSender()] = amountContributed[saleId][_msgSender()].add(msg.value);\n    totalEtherRaised[saleId] = totalEtherRaised[saleId].add(msg.value);\n    tokenSaleItem.availableTokens = tokenSaleItem.availableTokens.sub(val);\n  }\n\n  function normalWithdrawal(bytes32 saleId) external whenNotPaused nonReentrant {\n    TokenSaleItem storage tokenSaleItem = tokenSales[saleId];\n    require(tokenSaleItem.ended || block.timestamp >= tokenSaleItem.saleEndTime, \"sale_has_not_ended\");\n    TransferHelpers._safeTransferERC20(tokenSaleItem.token, _msgSender(), balance[saleId][_msgSender()]);\n    delete balance[saleId][_msgSender()];\n  }\n\n  function emergencyWithdrawal(bytes32 saleId) external nonReentrant {\n    TokenSaleItem storage tokenSaleItem = tokenSales[saleId];\n    require(!tokenSaleItem.ended, \"sale_has_already_ended\");\n    TransferHelpers._safeTransferEther(_msgSender(), amountContributed[saleId][_msgSender()]);\n    tokenSaleItem.availableTokens = tokenSaleItem.availableTokens.add(balance[saleId][_msgSender()]);\n    totalEtherRaised[saleId] = totalEtherRaised[saleId].sub(amountContributed[saleId][_msgSender()]);\n    delete balance[saleId][_msgSender()];\n    delete amountContributed[saleId][_msgSender()];\n  }\n\n  function interruptTokenSale(bytes32 saleId) external whenNotPaused onlyOwner {\n    TokenSaleItem storage tokenSale = tokenSales[saleId];\n    require(!tokenSale.ended, \"token_sale_has_ended\");\n    tokenSale.interrupted = true;\n  }\n\n  function uninterruptTokenSale(bytes32 saleId) external whenNotPaused onlyOwner {\n    TokenSaleItem storage tokenSale = tokenSales[saleId];\n    tokenSale.interrupted = false;\n  }\n\n  function finalizeTokenSale(bytes32 saleId) external whenNotPaused {\n    TokenSaleItem storage tokenSale = tokenSales[saleId];\n    require(hasRole(finalizerRole, _msgSender()) || tokenSale.admin == _msgSender(), \"only_finalizer_or_admin\");\n    require(!tokenSale.ended, \"sale_has_ended\");\n    uint256 launchpadProfit = (totalEtherRaised[saleId] * uint256(feePercentage)).div(100);\n    TransferHelpers._safeTransferEther(tokenSale.proceedsTo, totalEtherRaised[saleId].sub(launchpadProfit));\n    withdrawable = withdrawable.add(launchpadProfit);\n\n    if (tokenSale.availableTokens > 0) {\n      TransferHelpers._safeTransferERC20(tokenSale.token, tokenSale.proceedsTo, tokenSale.availableTokens);\n    }\n\n    tokenSale.ended = true;\n  }\n\n  function barFromParticiption(bytes32 saleId, address account) external {\n    TokenSaleItem memory tokenSale = tokenSales[saleId];\n    require(tokenSale.admin == _msgSender(), \"only_admin\");\n    require(!tokenSale.ended, \"sale_has_ended\");\n    require(!isNotAllowedToContribute[saleId][account], \"already_barred\");\n    isNotAllowedToContribute[saleId][account] = true;\n  }\n\n  function rescindBar(bytes32 saleId, address account) external {\n    TokenSaleItem memory tokenSale = tokenSales[saleId];\n    require(tokenSale.admin == _msgSender(), \"only_admin\");\n    require(!tokenSale.ended, \"sale_has_ended\");\n    require(isNotAllowedToContribute[saleId][account], \"not_barred\");\n    isNotAllowedToContribute[saleId][account] = false;\n  }\n\n  function pause() external whenNotPaused {\n    require(hasRole(pauserRole, _msgSender()), \"must_have_pauser_role\");\n    _pause();\n  }\n\n  function unpause() external whenPaused {\n    require(hasRole(pauserRole, _msgSender()), \"must_have_pauser_role\");\n    _unpause();\n  }\n\n  function getTotalEtherRaisedForSale(bytes32 saleId) external view returns (uint256) {\n    return totalEtherRaised[saleId];\n  }\n\n  function getExpectedEtherRaiseForSale(bytes32 saleId) external view returns (uint256) {\n    TokenSaleItem memory tokenSaleItem = tokenSales[saleId];\n    return tokenSaleItem.hardCap;\n  }\n\n  function getSoftCap(bytes32 saleId) external view returns (uint256) {\n    TokenSaleItem memory tokenSaleItem = tokenSales[saleId];\n    return tokenSaleItem.softCap;\n  }\n\n  function withdrawProfit(address to) external {\n    require(hasRole(withdrawerRole, _msgSender()) || _msgSender() == owner(), \"only_withdrawer_or_owner\");\n    TransferHelpers._safeTransferEther(to, withdrawable);\n    withdrawable = 0;\n  }\n\n  function setFeePercentage(uint8 _feePercentage) external onlyOwner {\n    feePercentage = _feePercentage;\n  }\n\n  function setSaleCreationFee(uint256 _saleCreationFee) external onlyOwner {\n    saleCreationFee = _saleCreationFee;\n  }\n\n  receive() external payable {\n    withdrawable = withdrawable.add(msg.value);\n  }\n}\n"
    },
    "contracts/interfaces/ITokenSaleCreator.sol": {
      "content": "pragma solidity ^0.8.0;\n\ninterface ITokenSaleCreator {\n  struct TokenSaleItem {\n    address token;\n    uint256 tokensForSale;\n    uint256 hardCap;\n    uint256 softCap;\n    uint256 presaleRate;\n    bytes32 saleId;\n    uint256 minContributionEther;\n    uint256 maxContributionEther;\n    uint256 saleStartTime;\n    uint256 saleEndTime;\n    bool interrupted;\n    address proceedsTo;\n    address admin;\n    uint256 availableTokens;\n    bool ended;\n  }\n\n  event TokenSaleItemCreated(\n    bytes32 saleId,\n    address token,\n    uint256 tokensForSale,\n    uint256 hardCap,\n    uint256 softCap,\n    uint256 presaleRate,\n    uint256 minContributionEther,\n    uint256 maxContributionEther,\n    uint256 saleStartTime,\n    uint256 saleEndTime,\n    address proceedsTo,\n    address admin\n  );\n\n  function initTokenSale(\n    address token,\n    uint256 tokensForSale,\n    uint256 hardCap,\n    uint256 softCap,\n    uint256 presaleRate,\n    uint256 minContributionEther,\n    uint256 maxContributionEther,\n    uint256 saleStartTime,\n    uint256 daysToLast,\n    address proceedsTo,\n    address admin\n  ) external payable returns (bytes32 saleId);\n\n  function interruptTokenSale(bytes32 saleId) external;\n\n  function allTokenSales(uint256) external view returns (bytes32);\n\n  function feePercentage() external view returns (uint8);\n\n  function balance(bytes32 saleId, address account) external view returns (uint256);\n\n  function amountContributed(bytes32 saleId, address account) external view returns (uint256);\n}\n"
    },
    "@openzeppelin/contracts/security/ReentrancyGuard.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n    // Booleans are more expensive than uint256 or any type that takes up a full\n    // word because each write operation emits an extra SLOAD to first read the\n    // slot's contents, replace the bits taken up by the boolean, and then write\n    // back. This is the compiler's defense against contract upgrades and\n    // pointer aliasing, and it cannot be disabled.\n\n    // The values being non-zero value makes deployment a bit more expensive,\n    // but in exchange the refund on every call to nonReentrant will be lower in\n    // amount. Since refunds are capped to a percentage of the total\n    // transaction's gas, it is best to keep them low in cases like this one, to\n    // increase the likelihood of the full refund coming into effect.\n    uint256 private constant _NOT_ENTERED = 1;\n    uint256 private constant _ENTERED = 2;\n\n    uint256 private _status;\n\n    constructor() {\n        _status = _NOT_ENTERED;\n    }\n\n    /**\n     * @dev Prevents a contract from calling itself, directly or indirectly.\n     * Calling a `nonReentrant` function from another `nonReentrant`\n     * function is not supported. It is possible to prevent this from happening\n     * by making the `nonReentrant` function external, and making it call a\n     * `private` function that does the actual work.\n     */\n    modifier nonReentrant() {\n        // On the first call to nonReentrant, _notEntered will be true\n        require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n        // Any calls to nonReentrant after this point will fail\n        _status = _ENTERED;\n\n        _;\n\n        // By storing the original value once again, a refund is triggered (see\n        // https://eips.ethereum.org/EIPS/eip-2200)\n        _status = _NOT_ENTERED;\n    }\n}\n"
    },
    "@openzeppelin/contracts/access/AccessControl.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\nimport \"../utils/Context.sol\";\nimport \"../utils/Strings.sol\";\nimport \"../utils/introspection/ERC165.sol\";\n\n/**\n * @dev Contract module that allows children to implement role-based access\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\n * members except through off-chain means by accessing the contract event logs. Some\n * applications may benefit from on-chain enumerability, for those cases see\n * {AccessControlEnumerable}.\n *\n * Roles are referred to by their `bytes32` identifier. These should be exposed\n * in the external API and be unique. The best way to achieve this is by\n * using `public constant` hash digests:\n *\n * ```\n * bytes32 public constant MY_ROLE = keccak256(\"MY_ROLE\");\n * ```\n *\n * Roles can be used to represent a set of permissions. To restrict access to a\n * function call, use {hasRole}:\n *\n * ```\n * function foo() public {\n *     require(hasRole(MY_ROLE, msg.sender));\n *     ...\n * }\n * ```\n *\n * Roles can be granted and revoked dynamically via the {grantRole} and\n * {revokeRole} functions. Each role has an associated admin role, and only\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\n *\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\n * that only accounts with this role will be able to grant or revoke other\n * roles. More complex role relationships can be created by using\n * {_setRoleAdmin}.\n *\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\n * grant and revoke this role. Extra precautions should be taken to secure\n * accounts that have been granted it.\n */\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\n    struct RoleData {\n        mapping(address => bool) members;\n        bytes32 adminRole;\n    }\n\n    mapping(bytes32 => RoleData) private _roles;\n\n    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\n\n    /**\n     * @dev Modifier that checks that an account has a specific role. Reverts\n     * with a standardized message including the required role.\n     *\n     * The format of the revert reason is given by the following regular expression:\n     *\n     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n     *\n     * _Available since v4.1._\n     */\n    modifier onlyRole(bytes32 role) {\n        _checkRole(role);\n        _;\n    }\n\n    /**\n     * @dev See {IERC165-supportsInterface}.\n     */\n    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\n    }\n\n    /**\n     * @dev Returns `true` if `account` has been granted `role`.\n     */\n    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\n        return _roles[role].members[account];\n    }\n\n    /**\n     * @dev Revert with a standard message if `_msgSender()` is missing `role`.\n     * Overriding this function changes the behavior of the {onlyRole} modifier.\n     *\n     * Format of the revert message is described in {_checkRole}.\n     *\n     * _Available since v4.6._\n     */\n    function _checkRole(bytes32 role) internal view virtual {\n        _checkRole(role, _msgSender());\n    }\n\n    /**\n     * @dev Revert with a standard message if `account` is missing `role`.\n     *\n     * The format of the revert reason is given by the following regular expression:\n     *\n     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n     */\n    function _checkRole(bytes32 role, address account) internal view virtual {\n        if (!hasRole(role, account)) {\n            revert(\n                string(\n                    abi.encodePacked(\n                        \"AccessControl: account \",\n                        Strings.toHexString(uint160(account), 20),\n                        \" is missing role \",\n                        Strings.toHexString(uint256(role), 32)\n                    )\n                )\n            );\n        }\n    }\n\n    /**\n     * @dev Returns the admin role that controls `role`. See {grantRole} and\n     * {revokeRole}.\n     *\n     * To change a role's admin, use {_setRoleAdmin}.\n     */\n    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\n        return _roles[role].adminRole;\n    }\n\n    /**\n     * @dev Grants `role` to `account`.\n     *\n     * If `account` had not been already granted `role`, emits a {RoleGranted}\n     * event.\n     *\n     * Requirements:\n     *\n     * - the caller must have ``role``'s admin role.\n     *\n     * May emit a {RoleGranted} event.\n     */\n    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n        _grantRole(role, account);\n    }\n\n    /**\n     * @dev Revokes `role` from `account`.\n     *\n     * If `account` had been granted `role`, emits a {RoleRevoked} event.\n     *\n     * Requirements:\n     *\n     * - the caller must have ``role``'s admin role.\n     *\n     * May emit a {RoleRevoked} event.\n     */\n    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n        _revokeRole(role, account);\n    }\n\n    /**\n     * @dev Revokes `role` from the calling account.\n     *\n     * Roles are often managed via {grantRole} and {revokeRole}: this function's\n     * purpose is to provide a mechanism for accounts to lose their privileges\n     * if they are compromised (such as when a trusted device is misplaced).\n     *\n     * If the calling account had been revoked `role`, emits a {RoleRevoked}\n     * event.\n     *\n     * Requirements:\n     *\n     * - the caller must be `account`.\n     *\n     * May emit a {RoleRevoked} event.\n     */\n    function renounceRole(bytes32 role, address account) public virtual override {\n        require(account == _msgSender(), \"AccessControl: can only renounce roles for self\");\n\n        _revokeRole(role, account);\n    }\n\n    /**\n     * @dev Grants `role` to `account`.\n     *\n     * If `account` had not been already granted `role`, emits a {RoleGranted}\n     * event. Note that unlike {grantRole}, this function doesn't perform any\n     * checks on the calling account.\n     *\n     * May emit a {RoleGranted} event.\n     *\n     * [WARNING]\n     * ====\n     * This function should only be called from the constructor when setting\n     * up the initial roles for the system.\n     *\n     * Using this function in any other way is effectively circumventing the admin\n     * system imposed by {AccessControl}.\n     * ====\n     *\n     * NOTE: This function is deprecated in favor of {_grantRole}.\n     */\n    function _setupRole(bytes32 role, address account) internal virtual {\n        _grantRole(role, account);\n    }\n\n    /**\n     * @dev Sets `adminRole` as ``role``'s admin role.\n     *\n     * Emits a {RoleAdminChanged} event.\n     */\n    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\n        bytes32 previousAdminRole = getRoleAdmin(role);\n        _roles[role].adminRole = adminRole;\n        emit RoleAdminChanged(role, previousAdminRole, adminRole);\n    }\n\n    /**\n     * @dev Grants `role` to `account`.\n     *\n     * Internal function without access restriction.\n     *\n     * May emit a {RoleGranted} event.\n     */\n    function _grantRole(bytes32 role, address account) internal virtual {\n        if (!hasRole(role, account)) {\n            _roles[role].members[account] = true;\n            emit RoleGranted(role, account, _msgSender());\n        }\n    }\n\n    /**\n     * @dev Revokes `role` from `account`.\n     *\n     * Internal function without access restriction.\n     *\n     * May emit a {RoleRevoked} event.\n     */\n    function _revokeRole(bytes32 role, address account) internal virtual {\n        if (hasRole(role, account)) {\n            _roles[role].members[account] = false;\n            emit RoleRevoked(role, account, _msgSender());\n        }\n    }\n}\n"
    },
    "@openzeppelin/contracts/access/IAccessControl.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev External interface of AccessControl declared to support ERC165 detection.\n */\ninterface IAccessControl {\n    /**\n     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\n     *\n     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\n     * {RoleAdminChanged} not being emitted signaling this.\n     *\n     * _Available since v3.1._\n     */\n    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\n\n    /**\n     * @dev Emitted when `account` is granted `role`.\n     *\n     * `sender` is the account that originated the contract call, an admin role\n     * bearer except when using {AccessControl-_setupRole}.\n     */\n    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\n\n    /**\n     * @dev Emitted when `account` is revoked `role`.\n     *\n     * `sender` is the account that originated the contract call:\n     *   - if using `revokeRole`, it is the admin role bearer\n     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)\n     */\n    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\n\n    /**\n     * @dev Returns `true` if `account` has been granted `role`.\n     */\n    function hasRole(bytes32 role, address account) external view returns (bool);\n\n    /**\n     * @dev Returns the admin role that controls `role`. See {grantRole} and\n     * {revokeRole}.\n     *\n     * To change a role's admin, use {AccessControl-_setRoleAdmin}.\n     */\n    function getRoleAdmin(bytes32 role) external view returns (bytes32);\n\n    /**\n     * @dev Grants `role` to `account`.\n     *\n     * If `account` had not been already granted `role`, emits a {RoleGranted}\n     * event.\n     *\n     * Requirements:\n     *\n     * - the caller must have ``role``'s admin role.\n     */\n    function grantRole(bytes32 role, address account) external;\n\n    /**\n     * @dev Revokes `role` from `account`.\n     *\n     * If `account` had been granted `role`, emits a {RoleRevoked} event.\n     *\n     * Requirements:\n     *\n     * - the caller must have ``role``'s admin role.\n     */\n    function revokeRole(bytes32 role, address account) external;\n\n    /**\n     * @dev Revokes `role` from the calling account.\n     *\n     * Roles are often managed via {grantRole} and {revokeRole}: this function's\n     * purpose is to provide a mechanism for accounts to lose their privileges\n     * if they are compromised (such as when a trusted device is misplaced).\n     *\n     * If the calling account had been granted `role`, emits a {RoleRevoked}\n     * event.\n     *\n     * Requirements:\n     *\n     * - the caller must be `account`.\n     */\n    function renounceRole(bytes32 role, address account) external;\n}\n"
    },
    "@openzeppelin/contracts/utils/Strings.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n    bytes16 private constant _HEX_SYMBOLS = \"0123456789abcdef\";\n    uint8 private constant _ADDRESS_LENGTH = 20;\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n     */\n    function toString(uint256 value) internal pure returns (string memory) {\n        // Inspired by OraclizeAPI's implementation - MIT licence\n        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\n\n        if (value == 0) {\n            return \"0\";\n        }\n        uint256 temp = value;\n        uint256 digits;\n        while (temp != 0) {\n            digits++;\n            temp /= 10;\n        }\n        bytes memory buffer = new bytes(digits);\n        while (value != 0) {\n            digits -= 1;\n            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));\n            value /= 10;\n        }\n        return string(buffer);\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n     */\n    function toHexString(uint256 value) internal pure returns (string memory) {\n        if (value == 0) {\n            return \"0x00\";\n        }\n        uint256 temp = value;\n        uint256 length = 0;\n        while (temp != 0) {\n            length++;\n            temp >>= 8;\n        }\n        return toHexString(value, length);\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n     */\n    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n        bytes memory buffer = new bytes(2 * length + 2);\n        buffer[0] = \"0\";\n        buffer[1] = \"x\";\n        for (uint256 i = 2 * length + 1; i > 1; --i) {\n            buffer[i] = _HEX_SYMBOLS[value & 0xf];\n            value >>= 4;\n        }\n        require(value == 0, \"Strings: hex length insufficient\");\n        return string(buffer);\n    }\n\n    /**\n     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n     */\n    function toHexString(address addr) internal pure returns (string memory) {\n        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/introspection/ERC165.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n    /**\n     * @dev See {IERC165-supportsInterface}.\n     */\n    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n        return interfaceId == type(IERC165).interfaceId;\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/introspection/IERC165.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n    /**\n     * @dev Returns true if this contract implements the interface defined by\n     * `interfaceId`. See the corresponding\n     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n     * to learn more about how these ids are created.\n     *\n     * This function call must use less than 30 000 gas.\n     */\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
    },
    "contracts/USDB.sol": {
      "content": "pragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/utils/math/SafeMath.sol\";\nimport \"./helpers/TransferHelper.sol\";\nimport \"./interfaces/IvToken.sol\";\n\ncontract USDB is ERC20, AccessControl, Ownable, IvToken {\n  using SafeMath for uint256;\n\n  bytes32 public excludedFromTaxRole = keccak256(abi.encodePacked(\"EXCLUDED_FROM_TAX\"));\n  bytes32 public retrieverRole = keccak256(abi.encodePacked(\"RETRIEVER_ROLE\"));\n  bytes32 public minterRole = keccak256(abi.encodePacked(\"MINTER_ROLE\"));\n  address public taxCollector;\n  uint8 public taxPercentage;\n\n  constructor(\n    string memory name_,\n    string memory symbol_,\n    uint256 amount,\n    address tCollector,\n    uint8 tPercentage\n  ) ERC20(name_, symbol_) {\n    _grantRole(excludedFromTaxRole, _msgSender());\n    _grantRole(retrieverRole, _msgSender());\n    _mint(_msgSender(), amount);\n    {\n      taxCollector = tCollector;\n      taxPercentage = tPercentage;\n    }\n  }\n\n  function _transfer(\n    address sender,\n    address recipient,\n    uint256 amount\n  ) internal virtual override(ERC20) {\n    if (!hasRole(excludedFromTaxRole, sender) && sender != address(this)) {\n      uint256 tax = amount.mul(uint256(taxPercentage)).div(100);\n      super._transfer(sender, taxCollector, tax);\n      super._transfer(sender, recipient, amount.sub(tax));\n    } else {\n      super._transfer(sender, recipient, amount);\n    }\n  }\n\n  function mint(address to, uint256 amount) external {\n    require(hasRole(minterRole, _msgSender()), \"only_minter\");\n    _mint(to, amount);\n  }\n\n  function burn(address account, uint256 amount) external {\n    require(hasRole(minterRole, _msgSender()), \"only_minter\");\n    _burn(account, amount);\n  }\n\n  function retrieveEther(address to) external {\n    require(hasRole(retrieverRole, _msgSender()), \"only_retriever\");\n    TransferHelpers._safeTransferEther(to, address(this).balance);\n  }\n\n  function retrieveERC20(\n    address token,\n    address to,\n    uint256 amount\n  ) external {\n    require(hasRole(retrieverRole, _msgSender()), \"only_retriever\");\n    TransferHelpers._safeTransferERC20(token, to, amount);\n  }\n\n  function excludeFromPayingTax(address account) external onlyOwner {\n    require(!hasRole(excludedFromTaxRole, account), \"already_excluded_from_paying_tax\");\n    _grantRole(excludedFromTaxRole, account);\n  }\n\n  function includeInPayingTax(address account) external onlyOwner {\n    require(hasRole(excludedFromTaxRole, account), \"not_paying_tax\");\n    _revokeRole(excludedFromTaxRole, account);\n  }\n\n  function addRetriever(address account) external onlyOwner {\n    require(!hasRole(retrieverRole, account), \"already_retriever\");\n    _grantRole(retrieverRole, account);\n  }\n\n  function removeRetriever(address account) external onlyOwner {\n    require(hasRole(retrieverRole, account), \"not_retriever\");\n    _revokeRole(retrieverRole, account);\n  }\n\n  function setTaxPercentage(uint8 tPercentage) external onlyOwner {\n    require(tPercentage <= 10, \"tax_must_be_ten_percent_or_less\");\n    taxPercentage = tPercentage;\n  }\n\n  function setMinter(address account) external onlyOwner {\n    require(!hasRole(minterRole, account), \"already_minter\");\n    _grantRole(minterRole, account);\n  }\n\n  function removeMinter(address account) external onlyOwner {\n    require(hasRole(minterRole, account), \"not_a_minter\");\n    _revokeRole(minterRole, account);\n  }\n\n  function setTaxCollector(address tCollector) external onlyOwner {\n    taxCollector = tCollector;\n  }\n\n  receive() external payable {}\n}\n"
    },
    "contracts/interfaces/IvToken.sol": {
      "content": "pragma solidity ^0.8.0;\n\ninterface IvToken {\n  function mint(address to, uint256 amount) external;\n\n  function burn(address account, uint256 amount) external;\n}\n"
    },
    "contracts/StakingPoolActions.sol": {
      "content": "pragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"./StakingPool.sol\";\nimport \"./helpers/TransferHelper.sol\";\n\ncontract StakingPoolActions is Ownable, AccessControl {\n  uint256 public deploymentFee;\n\n  bytes32 public feeTakerRole = keccak256(abi.encodePacked(\"FEE_TAKER_ROLE\"));\n  bytes32 public feeSetterRole = keccak256(abi.encodePacked(\"FEE_SETTER_ROLE\"));\n\n  mapping(address => address[]) public stakingPools;\n\n  event StakingPoolDeployed(address poolId, address owner, address token0, address token1, uint256 apy1, uint256 apy2, uint256 tax);\n\n  constructor(uint256 _deploymentFee) {\n    deploymentFee = _deploymentFee;\n    _grantRole(feeTakerRole, _msgSender());\n    _grantRole(feeSetterRole, _msgSender());\n  }\n\n  function deployStakingPool(\n    address token0,\n    address token1,\n    uint16 apy1,\n    uint16 apy2,\n    uint8 taxPercentage,\n    uint256 withdrawalIntervals\n  ) external payable returns (address poolId) {\n    require(msg.value >= deploymentFee);\n    bytes memory bytecode = abi.encodePacked(\n      type(StakingPool).creationCode,\n      abi.encode(_msgSender(), token0, token1, apy1, apy2, taxPercentage, withdrawalIntervals)\n    );\n    bytes32 salt = keccak256(abi.encodePacked(token0, token1, apy1, apy2, _msgSender(), block.timestamp));\n\n    assembly {\n      poolId := create2(0, add(bytecode, 32), mload(bytecode), salt)\n      if iszero(extcodesize(poolId)) {\n        revert(0, 0)\n      }\n    }\n\n    address[] storage usersPools = stakingPools[_msgSender()];\n    usersPools.push(poolId);\n\n    emit StakingPoolDeployed(poolId, _msgSender(), token0, token1, apy1, apy2, taxPercentage);\n  }\n\n  function withdrawEther(address to) external {\n    require(hasRole(feeTakerRole, _msgSender()));\n    TransferHelpers._safeTransferEther(to, address(this).balance);\n  }\n\n  function withdrawToken(\n    address token,\n    address to,\n    uint256 amount\n  ) external {\n    require(hasRole(feeTakerRole, _msgSender()));\n    TransferHelpers._safeTransferERC20(token, to, amount);\n  }\n\n  function setFee(uint256 _fee) external {\n    require(hasRole(feeSetterRole, _msgSender()));\n    deploymentFee = _fee;\n  }\n\n  function setFeeSetter(address account) external onlyOwner {\n    require(!hasRole(feeSetterRole, account));\n    _grantRole(feeSetterRole, account);\n  }\n\n  function removeFeeSetter(address account) external onlyOwner {\n    require(hasRole(feeSetterRole, account));\n    _revokeRole(feeSetterRole, account);\n  }\n\n  function setFeeTaker(address account) external onlyOwner {\n    require(!hasRole(feeTakerRole, account));\n    _grantRole(feeTakerRole, account);\n  }\n\n  function removeFeeTaker(address account) external onlyOwner {\n    require(hasRole(feeTakerRole, account));\n    _revokeRole(feeTakerRole, account);\n  }\n\n  receive() external payable {}\n}\n"
    },
    "contracts/StakingPool.sol": {
      "content": "pragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport \"@openzeppelin/contracts/utils/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"./interfaces/IStakingPool.sol\";\nimport \"./helpers/TransferHelper.sol\";\n\ncontract StakingPool is Ownable, AccessControl, Pausable, ReentrancyGuard, IStakingPool {\n  using SafeMath for uint256;\n  using Address for address;\n\n  bytes32 public pauserRole = keccak256(abi.encodePacked(\"PAUSER_ROLE\"));\n  address public immutable tokenA;\n  address public immutable tokenB;\n  uint16 public tokenAAPY;\n  uint16 public tokenBAPY;\n  uint8 public stakingPoolTax;\n  uint256 public withdrawalIntervals;\n\n  mapping(bytes32 => Stake) public stakes;\n  mapping(address => bytes32[]) public poolsByAddresses;\n  mapping(address => bool) public blockedAddresses;\n  mapping(address => uint256) public nonWithdrawableERC20;\n\n  bytes32[] public stakeIDs;\n\n  constructor(\n    address newOwner,\n    address token0,\n    address token1,\n    uint16 apy1,\n    uint16 apy2,\n    uint8 poolTax,\n    uint256 intervals\n  ) {\n    require(token0.isContract());\n    require(token1.isContract());\n    tokenA = token0;\n    tokenB = token1;\n    tokenAAPY = apy1;\n    tokenBAPY = apy2;\n    stakingPoolTax = poolTax;\n    withdrawalIntervals = intervals;\n    _grantRole(pauserRole, _msgSender());\n    _grantRole(pauserRole, newOwner);\n    _transferOwnership(newOwner);\n  }\n\n  function calculateReward(bytes32 stakeId) public view returns (uint256 reward) {\n    Stake memory stake = stakes[stakeId];\n    uint256 percentage;\n    if (stake.tokenStaked == tokenA) {\n      // How much percentage reward does this staker yield?\n      percentage = uint256(tokenBAPY).mul(block.timestamp.sub(stake.since) / (60 * 60 * 24 * 7 * 4)).div(12);\n    } else {\n      percentage = uint256(tokenAAPY).mul(block.timestamp.sub(stake.since) / (60 * 60 * 24 * 7 * 4)).div(12);\n    }\n\n    reward = stake.amountStaked.mul(percentage) / 100;\n  }\n\n  function stakeAsset(address token, uint256 amount) external whenNotPaused nonReentrant {\n    require(token == tokenA || token == tokenB);\n    require(token.isContract());\n    require(!blockedAddresses[_msgSender()]);\n    require(amount > 0);\n    uint256 tax = amount.mul(stakingPoolTax) / 100;\n    require(IERC20(token).allowance(_msgSender(), address(this)) >= amount);\n    TransferHelpers._safeTransferFromERC20(token, _msgSender(), address(this), amount);\n    bytes32 stakeId = keccak256(abi.encodePacked(_msgSender(), address(this), token, block.timestamp));\n    Stake memory stake = Stake({\n      amountStaked: amount.sub(tax),\n      tokenStaked: token,\n      since: block.timestamp,\n      staker: _msgSender(),\n      stakeId: stakeId,\n      nextWithdrawalTime: block.timestamp.add(withdrawalIntervals)\n    });\n    stakes[stakeId] = stake;\n    bytes32[] storage stakez = poolsByAddresses[_msgSender()];\n    stakez.push(stakeId);\n    stakeIDs.push(stakeId);\n    nonWithdrawableERC20[token] = nonWithdrawableERC20[token].add(stake.amountStaked);\n    emit Staked(amount, token, stake.since, _msgSender(), stakeId);\n  }\n\n  function unstakeAmount(bytes32 stakeId, uint256 amount) external whenNotPaused nonReentrant {\n    Stake storage stake = stakes[stakeId];\n    require(_msgSender() == stake.staker);\n    TransferHelpers._safeTransferERC20(stake.tokenStaked, _msgSender(), amount);\n    stake.amountStaked = stake.amountStaked.sub(amount);\n    nonWithdrawableERC20[stake.tokenStaked] = nonWithdrawableERC20[stake.tokenStaked].sub(amount);\n    emit Unstaked(amount, stakeId);\n  }\n\n  function unstakeAll(bytes32 stakeId) external nonReentrant {\n    Stake memory stake = stakes[stakeId];\n    require(_msgSender() == stake.staker);\n    TransferHelpers._safeTransferERC20(stake.tokenStaked, _msgSender(), stake.amountStaked);\n    delete stakes[stakeId];\n\n    bytes32[] storage stakez = poolsByAddresses[_msgSender()];\n\n    for (uint256 i = 0; i < stakez.length; i++) {\n      if (stakez[i] == stakeId) {\n        stakez[i] = bytes32(0);\n      }\n    }\n    nonWithdrawableERC20[stake.tokenStaked] = nonWithdrawableERC20[stake.tokenStaked].sub(stake.amountStaked);\n    emit Unstaked(stake.amountStaked, stakeId);\n  }\n\n  function withdrawRewards(bytes32 stakeId) external whenNotPaused nonReentrant {\n    Stake storage stake = stakes[stakeId];\n    require(_msgSender() == stake.staker);\n    require(block.timestamp >= stake.nextWithdrawalTime, \"cannot_withdraw_now\");\n    uint256 reward = calculateReward(stakeId);\n    address token = stake.tokenStaked == tokenA ? tokenB : tokenA;\n    uint256 amount = stake.amountStaked.add(reward);\n    TransferHelpers._safeTransferERC20(token, stake.staker, amount);\n    stake.since = block.timestamp;\n    stake.nextWithdrawalTime = block.timestamp.add(withdrawalIntervals);\n    emit Withdrawn(amount, stakeId);\n  }\n\n  function retrieveEther(address to) external onlyOwner {\n    TransferHelpers._safeTransferEther(to, address(this).balance);\n  }\n\n  function setStakingPoolTax(uint8 poolTax) external onlyOwner {\n    stakingPoolTax = poolTax;\n  }\n\n  function retrieveERC20(\n    address token,\n    address to,\n    uint256 amount\n  ) external onlyOwner {\n    require(token.isContract(), \"must_be_contract_address\");\n    uint256 bal = IERC20(token).balanceOf(address(this));\n    require(bal > nonWithdrawableERC20[token], \"balance_lower_than_staked\");\n\n    if (nonWithdrawableERC20[token] > 0) {\n      require(bal.sub(amount) < nonWithdrawableERC20[token], \"amount_must_be_less_than_staked\");\n    }\n\n    TransferHelpers._safeTransferERC20(token, to, amount);\n  }\n\n  function pause() external {\n    require(hasRole(pauserRole, _msgSender()));\n    _pause();\n  }\n\n  function unpause() external {\n    require(hasRole(pauserRole, _msgSender()));\n    _unpause();\n  }\n\n  receive() external payable {}\n}\n"
    },
    "contracts/interfaces/IStakingPool.sol": {
      "content": "pragma solidity ^0.8.0;\n\ninterface IStakingPool {\n  struct Stake {\n    uint256 amountStaked;\n    address tokenStaked;\n    uint256 since;\n    address staker;\n    bytes32 stakeId;\n    uint256 nextWithdrawalTime;\n  }\n\n  event Staked(uint256 amount, address token, uint256 since, address staker, bytes32 stakeId);\n  event Unstaked(uint256 amount, bytes32 stakeId);\n  event Withdrawn(uint256 amount, bytes32 stakeId);\n\n  function stakes(bytes32)\n    external\n    view\n    returns (\n      uint256,\n      address,\n      uint256,\n      address,\n      bytes32,\n      uint256\n    );\n\n  // function poolsByAddresses(address) external view returns (bytes32[] memory);\n\n  function blockedAddresses(address) external view returns (bool);\n\n  function stakeIDs(uint256) external view returns (bytes32);\n\n  function stakingPoolTax() external view returns (uint8);\n\n  function tokenA() external view returns (address);\n\n  function tokenB() external view returns (address);\n\n  function stakeAsset(address, uint256) external;\n\n  function withdrawRewards(bytes32) external;\n\n  function tokenAAPY() external view returns (uint16);\n\n  function tokenBAPY() external view returns (uint16);\n\n  function withdrawalIntervals() external view returns (uint256);\n\n  function unstakeAmount(bytes32, uint256) external;\n\n  function unstakeAll(bytes32) external;\n}\n"
    },
    "contracts/SpecialStakingPool.sol": {
      "content": "pragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport \"@openzeppelin/contracts/utils/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"./helpers/TransferHelper.sol\";\nimport \"./interfaces/IStakingPool.sol\";\nimport \"./interfaces/IvToken.sol\";\n\ncontract SpecialStakingPool is Ownable, AccessControl, Pausable, ReentrancyGuard, IStakingPool {\n  using SafeMath for uint256;\n  using Address for address;\n\n  address public immutable tokenA;\n  address public immutable tokenB;\n\n  uint16 public tokenAAPY;\n  uint16 public tokenBAPY;\n  uint8 public stakingPoolTax;\n  uint256 public withdrawalIntervals;\n\n  bytes32 public pauserRole = keccak256(abi.encodePacked(\"PAUSER_ROLE\"));\n  bytes32 public apySetterRole = keccak256(abi.encodePacked(\"APY_SETTER_ROLE\"));\n\n  mapping(bytes32 => Stake) public stakes;\n  mapping(address => bytes32[]) public poolsByAddresses;\n  mapping(address => bool) public blockedAddresses;\n  mapping(address => uint256) public nonWithdrawableERC20;\n\n  bytes32[] public stakeIDs;\n\n  uint256 public withdrawable;\n\n  constructor(\n    address newOwner,\n    address A,\n    address B,\n    uint16 aAPY,\n    uint16 bAPY,\n    uint8 stakingTax,\n    uint256 intervals\n  ) {\n    require(A == address(0) || A.isContract(), \"A_must_be_zero_address_or_contract\");\n    require(B.isContract(), \"B_must_be_contract\");\n    tokenA = A;\n    tokenB = B;\n    tokenAAPY = aAPY;\n    tokenBAPY = bAPY;\n    stakingPoolTax = stakingTax;\n    withdrawalIntervals = intervals;\n    _transferOwnership(newOwner);\n    _grantRole(pauserRole, newOwner);\n    _grantRole(apySetterRole, newOwner);\n  }\n\n  function calculateReward(bytes32 stakeId) public view returns (uint256 reward) {\n    Stake memory stake = stakes[stakeId];\n    uint256 percentage;\n    if (stake.tokenStaked == tokenA) {\n      // How much percentage reward does this staker yield?\n      percentage = uint256(tokenBAPY).mul(block.timestamp.sub(stake.since) / (60 * 60 * 24 * 7 * 4)).div(12);\n    } else {\n      percentage = uint256(tokenAAPY).mul(block.timestamp.sub(stake.since) / (60 * 60 * 24 * 7 * 4)).div(12);\n    }\n\n    reward = stake.amountStaked.mul(percentage) / 100;\n  }\n\n  function stakeEther() external payable whenNotPaused nonReentrant {\n    require(!blockedAddresses[_msgSender()], \"blocked\");\n    require(msg.value > 0, \"must_stake_greater_than_0\");\n    uint256 tax = msg.value.mul(stakingPoolTax) / 100;\n    bytes32 stakeId = keccak256(abi.encodePacked(_msgSender(), address(this), address(0), block.timestamp));\n    Stake memory stake = Stake({\n      amountStaked: msg.value.sub(tax),\n      tokenStaked: address(0),\n      since: block.timestamp,\n      staker: _msgSender(),\n      stakeId: stakeId,\n      nextWithdrawalTime: block.timestamp.add(withdrawalIntervals)\n    });\n    stakes[stakeId] = stake;\n    bytes32[] storage stakez = poolsByAddresses[_msgSender()];\n    stakez.push(stakeId);\n    stakeIDs.push(stakeId);\n    withdrawable = withdrawable.add(tax);\n    emit Staked(msg.value, address(0), stake.since, _msgSender(), stakeId);\n  }\n\n  function stakeAsset(address token, uint256 amount) external whenNotPaused nonReentrant {\n    require(token.isContract(), \"must_be_contract_address\");\n    require(token == tokenA, \"cannot_stake_this_token\");\n    require(!blockedAddresses[_msgSender()], \"blocked\");\n    require(amount > 0, \"must_stake_greater_than_0\");\n    uint256 tax = amount.mul(stakingPoolTax) / 100;\n    require(IERC20(token).allowance(_msgSender(), address(this)) >= amount, \"not_enough_allowance\");\n    TransferHelpers._safeTransferFromERC20(token, _msgSender(), address(this), amount);\n    bytes32 stakeId = keccak256(abi.encodePacked(_msgSender(), address(this), token, block.timestamp));\n    Stake memory stake = Stake({\n      amountStaked: amount.sub(tax),\n      tokenStaked: token,\n      since: block.timestamp,\n      staker: _msgSender(),\n      stakeId: stakeId,\n      nextWithdrawalTime: block.timestamp.add(withdrawalIntervals)\n    });\n    stakes[stakeId] = stake;\n    bytes32[] storage stakez = poolsByAddresses[_msgSender()];\n    stakez.push(stakeId);\n    stakeIDs.push(stakeId);\n    nonWithdrawableERC20[token] = nonWithdrawableERC20[token].add(stake.amountStaked);\n    emit Staked(amount, token, stake.since, _msgSender(), stakeId);\n  }\n\n  function unstakeAmount(bytes32 stakeId, uint256 amount) external whenNotPaused nonReentrant {\n    Stake storage stake = stakes[stakeId];\n    require(_msgSender() == stake.staker, \"not_owner\");\n    if (stake.tokenStaked == address(0)) {\n      TransferHelpers._safeTransferEther(_msgSender(), amount);\n    } else {\n      TransferHelpers._safeTransferERC20(stake.tokenStaked, _msgSender(), amount);\n      nonWithdrawableERC20[stake.tokenStaked] = nonWithdrawableERC20[stake.tokenStaked].sub(amount);\n    }\n\n    stake.amountStaked = stake.amountStaked.sub(amount);\n    emit Unstaked(amount, stakeId);\n  }\n\n  function unstakeAll(bytes32 stakeId) external whenNotPaused nonReentrant {\n    Stake memory stake = stakes[stakeId];\n    require(_msgSender() == stake.staker, \"not_owner\");\n    if (stake.tokenStaked == address(0)) {\n      TransferHelpers._safeTransferEther(_msgSender(), stake.amountStaked);\n    } else {\n      TransferHelpers._safeTransferERC20(stake.tokenStaked, _msgSender(), stake.amountStaked);\n      nonWithdrawableERC20[stake.tokenStaked] = nonWithdrawableERC20[stake.tokenStaked].sub(stake.amountStaked);\n    }\n    delete stakes[stakeId];\n\n    bytes32[] storage stakez = poolsByAddresses[_msgSender()];\n\n    for (uint256 i = 0; i < stakez.length; i++) {\n      if (stakez[i] == stakeId) {\n        stakez[i] = bytes32(0);\n      }\n    }\n    emit Unstaked(stake.amountStaked, stakeId);\n  }\n\n  function withdrawRewards(bytes32 stakeId) external whenNotPaused nonReentrant {\n    Stake storage stake = stakes[stakeId];\n    require(_msgSender() == stake.staker, \"not_owner\");\n    require(block.timestamp >= stake.nextWithdrawalTime, \"cannot_withdraw_now\");\n    uint256 reward = calculateReward(stakeId);\n    address token = stake.tokenStaked == tokenA ? tokenB : tokenA;\n    uint256 amount = stake.amountStaked.add(reward);\n\n    if (token == tokenB) IvToken(token).mint(_msgSender(), amount);\n    else {\n      if (tokenA == address(0)) TransferHelpers._safeTransferEther(_msgSender(), amount);\n      else TransferHelpers._safeTransferERC20(token, _msgSender(), amount);\n    }\n\n    stake.since = block.timestamp;\n    stake.nextWithdrawalTime = block.timestamp.add(withdrawalIntervals);\n    emit Withdrawn(amount, stakeId);\n  }\n\n  function retrieveEther(address to) external onlyOwner {\n    TransferHelpers._safeTransferEther(to, withdrawable);\n    withdrawable = 0;\n  }\n\n  function setStakingPoolTax(uint8 poolTax) external onlyOwner {\n    stakingPoolTax = poolTax;\n  }\n\n  function retrieveERC20(\n    address token,\n    address to,\n    uint256 amount\n  ) external onlyOwner {\n    require(token.isContract(), \"must_be_contract_address\");\n    uint256 bal = IERC20(token).balanceOf(address(this));\n    require(bal > nonWithdrawableERC20[token], \"balance_lower_than_staked\");\n\n    if (nonWithdrawableERC20[token] > 0) require(bal.sub(amount) < nonWithdrawableERC20[token], \"amount_must_be_less_than_staked\");\n\n    TransferHelpers._safeTransferERC20(token, to, amount);\n  }\n\n  function pause() external {\n    require(hasRole(pauserRole, _msgSender()), \"only_pauser\");\n    _pause();\n  }\n\n  function unpause() external {\n    require(hasRole(pauserRole, _msgSender()), \"only_pauser\");\n    _unpause();\n  }\n\n  function setTokenAAPY(uint8 aAPY) external {\n    require(hasRole(apySetterRole, _msgSender()), \"only_apy_setter\");\n    tokenAAPY = aAPY;\n  }\n\n  function setTokenBAPY(uint8 bAPY) external {\n    require(hasRole(apySetterRole, _msgSender()), \"only_apy_setter\");\n    tokenBAPY = bAPY;\n  }\n\n  function setAPYSetter(address account) external onlyOwner {\n    require(!hasRole(apySetterRole, account), \"already_apy_setter\");\n    _grantRole(apySetterRole, account);\n  }\n\n  function removeAPYSetter(address account) external onlyOwner {\n    require(hasRole(apySetterRole, account), \"not_apy_setter\");\n    _revokeRole(apySetterRole, account);\n  }\n\n  function setWithdrawalIntervals(uint256 intervals) external onlyOwner {\n    withdrawalIntervals = intervals;\n  }\n\n  function setPauser(address account) external onlyOwner {\n    require(!hasRole(pauserRole, account), \"already_pauser\");\n    _grantRole(pauserRole, account);\n  }\n\n  function removePauser(address account) external onlyOwner {\n    require(hasRole(pauserRole, account), \"not_pauser\");\n    _revokeRole(pauserRole, account);\n  }\n\n  receive() external payable {\n    withdrawable = withdrawable.add(msg.value);\n  }\n}\n"
    },
    "contracts/PrivateTokenSaleCreator.sol": {
      "content": "pragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport \"@openzeppelin/contracts/security/Pausable.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/utils/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"./interfaces/IPrivateTokenSaleCreator.sol\";\nimport \"./helpers/TransferHelper.sol\";\n\ncontract PrivateTokenSaleCreator is ReentrancyGuard, Pausable, Ownable, AccessControl, IPrivateTokenSaleCreator {\n  using Address for address;\n  using SafeMath for uint256;\n\n  bytes32[] public allTokenSales;\n  bytes32 public pauserRole = keccak256(abi.encodePacked(\"PAUSER_ROLE\"));\n  bytes32 public withdrawerRole = keccak256(abi.encodePacked(\"WITHDRAWER_ROLE\"));\n  bytes32 public finalizerRole = keccak256(abi.encodePacked(\"FINALIZER_ROLE\"));\n  uint256 public withdrawable;\n\n  uint8 public feePercentage;\n  uint256 public saleCreationFee;\n\n  mapping(bytes32 => TokenSaleItem) private tokenSales;\n  mapping(bytes32 => uint256) private totalEtherRaised;\n  mapping(bytes32 => mapping(address => bool)) private isNotAllowedToContribute;\n  mapping(bytes32 => mapping(address => uint256)) public amountContributed;\n  mapping(bytes32 => mapping(address => uint256)) public balance;\n  mapping(bytes32 => address[]) public whitelists;\n\n  modifier whenParamsSatisfied(bytes32 saleId) {\n    TokenSaleItem memory tokenSale = tokenSales[saleId];\n    require(!tokenSale.interrupted, \"token_sale_paused\");\n    require(block.timestamp >= tokenSale.saleStartTime, \"token_sale_not_started_yet\");\n    require(!tokenSale.ended, \"token_sale_has_ended\");\n    require(!isNotAllowedToContribute[saleId][_msgSender()], \"you_are_not_allowed_to_participate_in_this_sale\");\n    require(indexOfList(whitelists[saleId], _msgSender()) > uint256(int256(-1)), \"only_whitelisted_addresses_can_partake_in_this_sale\");\n    require(totalEtherRaised[saleId] < tokenSale.hardCap, \"hardcap_reached\");\n    _;\n  }\n\n  constructor(uint8 _feePercentage, uint256 _saleCreationFee) {\n    _grantRole(pauserRole, _msgSender());\n    _grantRole(withdrawerRole, _msgSender());\n    _grantRole(finalizerRole, _msgSender());\n    feePercentage = _feePercentage;\n    saleCreationFee = _saleCreationFee;\n  }\n\n  function initTokenSale(\n    address token,\n    uint256 tokensForSale,\n    uint256 hardCap,\n    uint256 softCap,\n    uint256 presaleRate,\n    uint256 minContributionEther,\n    uint256 maxContributionEther,\n    uint256 saleStartTime,\n    uint256 daysToLast,\n    address proceedsTo,\n    address admin,\n    address[] memory whiteList\n  ) external payable whenNotPaused nonReentrant returns (bytes32 saleId) {\n    {\n      require(msg.value >= saleCreationFee, \"fee\");\n      require(token.isContract(), \"must_be_contract_address\");\n      require(saleStartTime > block.timestamp && saleStartTime.sub(block.timestamp) >= 24 hours, \"sale_must_begin_in_at_least_24_hours\");\n      require(IERC20(token).allowance(_msgSender(), address(this)) >= tokensForSale, \"not_enough_allowance_given\");\n      TransferHelpers._safeTransferFromERC20(token, _msgSender(), address(this), tokensForSale);\n    }\n    saleId = keccak256(\n      abi.encodePacked(\n        token,\n        _msgSender(),\n        block.timestamp,\n        tokensForSale,\n        hardCap,\n        softCap,\n        presaleRate,\n        minContributionEther,\n        maxContributionEther,\n        saleStartTime,\n        daysToLast,\n        proceedsTo\n      )\n    );\n    // Added to prevent 'stack too deep' error\n    uint256 endTime;\n    {\n      endTime = saleStartTime.add(daysToLast.mul(1 days));\n      tokenSales[saleId] = TokenSaleItem(\n        token,\n        tokensForSale,\n        hardCap,\n        softCap,\n        presaleRate,\n        saleId,\n        minContributionEther,\n        maxContributionEther,\n        saleStartTime,\n        endTime,\n        false,\n        proceedsTo,\n        admin,\n        tokensForSale,\n        false\n      );\n    }\n    allTokenSales.push(saleId);\n    whitelists[saleId] = whiteList;\n    withdrawable = msg.value;\n    emit TokenSaleItemCreated(\n      saleId,\n      token,\n      tokensForSale,\n      hardCap,\n      softCap,\n      presaleRate,\n      minContributionEther,\n      maxContributionEther,\n      saleStartTime,\n      endTime,\n      proceedsTo,\n      admin\n    );\n  }\n\n  function contribute(bytes32 saleId) external payable whenNotPaused nonReentrant whenParamsSatisfied(saleId) {\n    TokenSaleItem storage tokenSaleItem = tokenSales[saleId];\n    require(\n      msg.value >= tokenSaleItem.minContributionEther && msg.value <= tokenSaleItem.maxContributionEther,\n      \"contribution_must_be_within_min_and_max_range\"\n    );\n    uint256 val = tokenSaleItem.presaleRate.mul(msg.value).div(1 ether);\n    require(tokenSaleItem.availableTokens >= val, \"tokens_available_for_sale_is_less\");\n    balance[saleId][_msgSender()] = balance[saleId][_msgSender()].add(val);\n    amountContributed[saleId][_msgSender()] = amountContributed[saleId][_msgSender()].add(msg.value);\n    totalEtherRaised[saleId] = totalEtherRaised[saleId].add(msg.value);\n    tokenSaleItem.availableTokens = tokenSaleItem.availableTokens.sub(val);\n  }\n\n  function normalWithdrawal(bytes32 saleId) external whenNotPaused nonReentrant {\n    TokenSaleItem storage tokenSaleItem = tokenSales[saleId];\n    require(tokenSaleItem.ended || block.timestamp >= tokenSaleItem.saleEndTime, \"sale_has_not_ended\");\n    TransferHelpers._safeTransferERC20(tokenSaleItem.token, _msgSender(), balance[saleId][_msgSender()]);\n    delete balance[saleId][_msgSender()];\n  }\n\n  function emergencyWithdrawal(bytes32 saleId) external nonReentrant {\n    TokenSaleItem storage tokenSaleItem = tokenSales[saleId];\n    require(!tokenSaleItem.ended, \"sale_has_already_ended\");\n    TransferHelpers._safeTransferEther(_msgSender(), amountContributed[saleId][_msgSender()]);\n    tokenSaleItem.availableTokens = tokenSaleItem.availableTokens.add(balance[saleId][_msgSender()]);\n    totalEtherRaised[saleId] = totalEtherRaised[saleId].sub(amountContributed[saleId][_msgSender()]);\n    delete balance[saleId][_msgSender()];\n    delete amountContributed[saleId][_msgSender()];\n  }\n\n  function interruptTokenSale(bytes32 saleId) external whenNotPaused onlyOwner {\n    TokenSaleItem storage tokenSale = tokenSales[saleId];\n    require(!tokenSale.ended, \"token_sale_has_ended\");\n    tokenSale.interrupted = true;\n  }\n\n  function uninterruptTokenSale(bytes32 saleId) external whenNotPaused onlyOwner {\n    TokenSaleItem storage tokenSale = tokenSales[saleId];\n    tokenSale.interrupted = false;\n  }\n\n  function finalizeTokenSale(bytes32 saleId) external whenNotPaused {\n    TokenSaleItem storage tokenSale = tokenSales[saleId];\n    require(hasRole(finalizerRole, _msgSender()) || tokenSale.admin == _msgSender(), \"only_finalizer_or_admin\");\n    require(!tokenSale.ended, \"sale_has_ended\");\n    uint256 launchpadProfit = (totalEtherRaised[saleId] * feePercentage).div(100);\n    TransferHelpers._safeTransferEther(tokenSale.proceedsTo, totalEtherRaised[saleId].sub(launchpadProfit));\n    withdrawable = withdrawable.add(launchpadProfit);\n\n    if (tokenSale.availableTokens > 0) {\n      TransferHelpers._safeTransferERC20(tokenSale.token, tokenSale.proceedsTo, tokenSale.availableTokens);\n    }\n\n    tokenSale.ended = true;\n  }\n\n  function barFromParticiption(bytes32 saleId, address account) external {\n    TokenSaleItem memory tokenSale = tokenSales[saleId];\n    require(tokenSale.admin == _msgSender(), \"only_admin\");\n    require(!tokenSale.ended, \"sale_has_ended\");\n    require(!isNotAllowedToContribute[saleId][account], \"already_barred\");\n    isNotAllowedToContribute[saleId][account] = true;\n  }\n\n  function rescindBar(bytes32 saleId, address account) external {\n    TokenSaleItem memory tokenSale = tokenSales[saleId];\n    require(tokenSale.admin == _msgSender(), \"only_admin\");\n    require(!tokenSale.ended, \"sale_has_ended\");\n    require(isNotAllowedToContribute[saleId][account], \"not_barred\");\n    isNotAllowedToContribute[saleId][account] = false;\n  }\n\n  function whitelist(bytes32 saleId) public view returns (address[] memory list) {\n    list = whitelists[saleId];\n  }\n\n  function addToWhitelist(bytes32 saleId, address[] memory list) external {\n    TokenSaleItem memory tokenSale = tokenSales[saleId];\n    require(tokenSale.admin == _msgSender(), \"only_admin\");\n\n    address[] storage l = whitelists[saleId];\n\n    for (uint256 i = 0; i < list.length; i++) {\n      if (indexOfList(l, list[i]) == uint256(int256(-1))) {\n        l.push(list[i]);\n      }\n    }\n  }\n\n  function removeFromWhiteList(bytes32 saleId, address[] memory list) external {\n    TokenSaleItem memory tokenSale = tokenSales[saleId];\n    require(tokenSale.admin == _msgSender(), \"only_admin\");\n\n    address[] storage l = whitelists[saleId];\n\n    for (uint256 i = 0; i < list.length; i++) {\n      uint256 index = indexOfList(l, list[i]);\n      if (index > uint256(int256(-1))) {\n        delete l[index];\n      }\n    }\n  }\n\n  function indexOfList(address[] memory list, address item) internal pure returns (uint256 index) {\n    index = uint256(int256(-1));\n\n    for (uint256 i = 0; i < list.length; i++) {\n      if (list[i] == item) {\n        index = i;\n      }\n    }\n  }\n\n  function pause() external whenNotPaused {\n    require(hasRole(pauserRole, _msgSender()), \"must_have_pauser_role\");\n    _pause();\n  }\n\n  function unpause() external whenPaused {\n    require(hasRole(pauserRole, _msgSender()), \"must_have_pauser_role\");\n    _unpause();\n  }\n\n  function getTotalEtherRaisedForSale(bytes32 saleId) external view returns (uint256) {\n    return totalEtherRaised[saleId];\n  }\n\n  function getExpectedEtherRaiseForSale(bytes32 saleId) external view returns (uint256) {\n    TokenSaleItem memory tokenSaleItem = tokenSales[saleId];\n    return tokenSaleItem.hardCap;\n  }\n\n  function getSoftCap(bytes32 saleId) external view returns (uint256) {\n    TokenSaleItem memory tokenSaleItem = tokenSales[saleId];\n    return tokenSaleItem.softCap;\n  }\n\n  function withdrawProfit(address to) external {\n    require(hasRole(withdrawerRole, _msgSender()), \"only_withdrawer\");\n    TransferHelpers._safeTransferEther(to, withdrawable);\n    withdrawable = 0;\n  }\n\n  function setFeePercentage(uint8 _feePercentage) external onlyOwner {\n    feePercentage = _feePercentage;\n  }\n\n  function setSaleCreationFee(uint256 _saleCreationFee) external onlyOwner {\n    saleCreationFee = _saleCreationFee;\n  }\n\n  receive() external payable {\n    withdrawable = withdrawable.add(msg.value);\n  }\n}\n"
    },
    "contracts/interfaces/IPrivateTokenSaleCreator.sol": {
      "content": "pragma solidity ^0.8.0;\n\ninterface IPrivateTokenSaleCreator {\n  struct TokenSaleItem {\n    address token;\n    uint256 tokensForSale;\n    uint256 hardCap;\n    uint256 softCap;\n    uint256 presaleRate;\n    bytes32 saleId;\n    uint256 minContributionEther;\n    uint256 maxContributionEther;\n    uint256 saleStartTime;\n    uint256 saleEndTime;\n    bool interrupted;\n    address proceedsTo;\n    address admin;\n    uint256 availableTokens;\n    bool ended;\n  }\n\n  event TokenSaleItemCreated(\n    bytes32 saleId,\n    address token,\n    uint256 tokensForSale,\n    uint256 hardCap,\n    uint256 softCap,\n    uint256 presaleRate,\n    uint256 minContributionEther,\n    uint256 maxContributionEther,\n    uint256 saleStartTime,\n    uint256 saleEndTime,\n    address proceedsTo,\n    address admin\n  );\n\n  function initTokenSale(\n    address token,\n    uint256 tokensForSale,\n    uint256 hardCap,\n    uint256 softCap,\n    uint256 presaleRate,\n    uint256 minContributionEther,\n    uint256 maxContributionEther,\n    uint256 saleStartTime,\n    uint256 daysToLast,\n    address proceedsTo,\n    address admin,\n    address[] memory whitelist\n  ) external payable returns (bytes32 saleId);\n\n  function interruptTokenSale(bytes32 saleId) external;\n\n  function allTokenSales(uint256) external view returns (bytes32);\n\n  function feePercentage() external view returns (uint8);\n\n  function balance(bytes32 saleId, address account) external view returns (uint256);\n\n  function amountContributed(bytes32 saleId, address account) external view returns (uint256);\n\n  function whitelist(bytes32) external view returns (address[] memory);\n}\n"
    },
    "contracts/test/TestERC20.sol": {
      "content": "pragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n\ncontract TestERC20 is ERC20 {\n  constructor(uint256 _totalSupply) ERC20(\"Test Token\", \"TT\") {\n    _mint(_msgSender(), _totalSupply);\n  }\n}\n"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "abi"
        ]
      }
    }
  }
}