creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "@openzeppelin/contracts/access/Ownable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * The initial owner is set to the address provided by the deployer. This can\n * later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    /**\n     * @dev The caller account is not authorized to perform an operation.\n     */\n    error OwnableUnauthorizedAccount(address account);\n\n    /**\n     * @dev The owner is not a valid owner account. (eg. `address(0)`)\n     */\n    error OwnableInvalidOwner(address owner);\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n     */\n    constructor(address initialOwner) {\n        if (initialOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\n        _transferOwnership(initialOwner);\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        if (owner() != _msgSender()) {\n            revert OwnableUnauthorizedAccount(_msgSender());\n        }\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        if (newOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the value of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the value of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves a `value` amount of tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 value) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n     * caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 value) external returns (bool);\n\n    /**\n     * @dev Moves a `value` amount of tokens from `from` to `to` using the\n     * allowance mechanism. `value` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n"
      },
      "@openzeppelin/contracts/utils/Context.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    function _contextSuffixLength() internal view virtual returns (uint256) {\n        return 0;\n    }\n}\n"
      },
      "contracts/Cloudwork.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\npragma solidity ^0.8.20;\r\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\r\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\r\n\r\ncontract Cloudwork is Ownable {\r\n    mapping(address => bool) public allowedCoins;\r\n\r\n    uint256 public totalPaid;\r\n    uint256 public totalWithdrawn;\r\n\r\n    address public tokenAddressForDiscount;\r\n\r\n    uint256 public discountPercentage = 10; // 1%\r\n    uint256 public constant PERCENTAGE_DIVIDER = 1000; // 100%\r\n\r\n    uint256 public tokenHoldingForDiscount = 5000; // 5000 tokens\r\n\r\n    uint256 public currentPaymentId;\r\n\r\n    mapping(address => uint256) public totalPaidPerCoin;\r\n\r\n    struct Payment {\r\n        uint256 id;\r\n        address sender;\r\n        address coin;\r\n        uint256 amount;\r\n        uint256 dicount;\r\n        uint256 amountAfterDiscount;\r\n        string message;\r\n    }\r\n\r\n    mapping(uint256 => Payment) public payments;\r\n\r\n    event PaymentReceived(\r\n        uint256 id,\r\n        address sender,\r\n        address coin,\r\n        uint256 amount,\r\n        string message\r\n    );\r\n\r\n    constructor(\r\n        address[] memory coins,\r\n        address _discountToken\r\n    ) Ownable(msg.sender) {\r\n        allowedCoins[address(0)] = true;\r\n        for (uint256 i = 0; i < coins.length; i++) {\r\n            allowedCoins[coins[i]] = true;\r\n        }\r\n        tokenAddressForDiscount = _discountToken;\r\n    }\r\n\r\n    function setDiscountToken(address tokenAddress) external onlyOwner {\r\n        tokenAddressForDiscount = tokenAddress;\r\n    }\r\n\r\n    function setDiscountPercentage(uint256 percentage) external onlyOwner {\r\n        discountPercentage = percentage;\r\n    }\r\n\r\n    function setTokenHoldingForDiscount(uint256 amount) external onlyOwner {\r\n        tokenHoldingForDiscount = amount;\r\n    }\r\n\r\n    function addAllowedCoin(address coin) external onlyOwner {\r\n        allowedCoins[coin] = true;\r\n    }\r\n\r\n    function removeAllowedCoin(address coin) external onlyOwner {\r\n        allowedCoins[coin] = false;\r\n    }\r\n\r\n    function pay(\r\n        address coin,\r\n        uint256 amount,\r\n        string calldata message\r\n    ) external payable {\r\n        require(allowedCoins[coin], \"Coin not allowed\");\r\n\r\n        uint256 finalAmount = amount;\r\n        uint256 discount = 0;\r\n        if (tokenAddressForDiscount != address(0)) {\r\n            uint256 tokenBalance = IERC20(tokenAddressForDiscount).balanceOf(\r\n                msg.sender\r\n            );\r\n            if (tokenBalance >= tokenHoldingForDiscount) {\r\n                discount = (amount * discountPercentage) / PERCENTAGE_DIVIDER;\r\n                finalAmount -= discount;\r\n            }\r\n        }\r\n\r\n        if (coin == address(0)) {\r\n            require(msg.value == finalAmount, \"Invalid amount\");\r\n        } else {\r\n            IERC20(coin).transferFrom(msg.sender, address(this), finalAmount);\r\n        }\r\n\r\n        totalPaid += finalAmount;\r\n\r\n        totalPaidPerCoin[coin] += finalAmount;\r\n\r\n        currentPaymentId++;\r\n\r\n        uint256 id = currentPaymentId;\r\n\r\n        payments[id] = Payment(\r\n            id,\r\n            msg.sender,\r\n            coin,\r\n            amount,\r\n            discount,\r\n            finalAmount,\r\n            message\r\n        );\r\n\r\n        emit PaymentReceived(id, msg.sender, coin, amount, message);\r\n    }\r\n\r\n    fallback() external payable {}\r\n\r\n    receive() external payable {}\r\n\r\n    function withdraw(address coin, uint256 amount) external onlyOwner {\r\n        if (coin == address(0)) {\r\n            payable(owner()).transfer(amount);\r\n        } else {\r\n            IERC20(coin).transfer(owner(), amount);\r\n        }\r\n    }\r\n}\r\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": false,
        "runs": 200
      },
      "evmVersion": "paris",
      "remappings": [],
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      }
    }
  }}