creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "/contracts/AllowanceCrowdsale.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\npragma solidity ^0.8.0;\r\n\r\nimport \"./Crowdsale.sol\";\r\n\r\n/**\r\n * @title AllowanceCrowdsale\r\n * @dev Extension of Crowdsale where tokens are held by a wallet, which approves an allowance to the crowdsale.\r\n */\r\ncontract AllowanceCrowdsale is Crowdsale {\r\n\r\n    address public tokenWallet;\r\n\r\n    /**\r\n     * @dev Constructor, takes token wallet address.\r\n   * @param _tokenWallet Address holding the tokens, which has approved allowance to the crowdsale\r\n   */\r\n    constructor(uint256 _rate, address payable _wallet, IERC20 _token, address _tokenWallet) Crowdsale(_rate, _wallet, _token) {\r\n        require(_tokenWallet != address(0));\r\n        tokenWallet = _tokenWallet;\r\n    }\r\n\r\n    /**\r\n     * @dev Checks the amount of tokens left in the allowance.\r\n   * @return Amount of tokens left in the allowance\r\n   */\r\n    function remainingTokens() public view returns (uint256) {\r\n        return token.allowance(tokenWallet, address(this));\r\n    }\r\n\r\n    /**\r\n     * @dev Overrides parent behavior by transferring tokens from wallet.\r\n   * @param _beneficiary Token purchaser\r\n   * @param _tokenAmount Amount of tokens purchased\r\n   */\r\n    function _deliverTokens(\r\n        address _beneficiary,\r\n        uint256 _tokenAmount\r\n    )\r\n    internal override\r\n    {\r\n        token.transferFrom(tokenWallet, _beneficiary, _tokenAmount);\r\n    }\r\n}"
      },
      "/contracts/Crowdsale.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\npragma solidity ^0.8.0;\r\n\r\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\r\n\r\n/**\r\n * @title Crowdsale\r\n * @dev Crowdsale is a base contract for managing a token crowdsale,\r\n * allowing investors to purchase tokens with ether. This contract implements\r\n * such functionality in its most fundamental form and can be extended to provide additional\r\n * functionality and/or custom behavior.\r\n * The external interface represents the basic interface for purchasing tokens, and conform\r\n * the base architecture for crowdsales. They are *not* intended to be modified / overriden.\r\n * The internal interface conforms the extensible and modifiable surface of crowdsales. Override\r\n * the methods to add functionality. Consider using 'super' where appropiate to concatenate\r\n * behavior.\r\n */\r\nabstract contract Crowdsale {\r\n\r\n    // The token being sold\r\n    IERC20 public token;\r\n\r\n    // Address where funds are collected\r\n    address payable public wallet;\r\n\r\n    // How many token units a buyer gets per wei\r\n    uint256 public rate;\r\n\r\n    // Amount of wei raised\r\n    uint256 public weiRaised;\r\n\r\n    /**\r\n     * Event for token purchase logging\r\n     * @param purchaser who paid for the tokens\r\n   * @param beneficiary who got the tokens\r\n   * @param value weis paid for purchase\r\n   * @param amount amount of tokens purchased\r\n   */\r\n    event TokenPurchase(\r\n        address indexed purchaser,\r\n        address indexed beneficiary,\r\n        uint256 value,\r\n        uint256 amount\r\n    );\r\n\r\n    /**\r\n     * @param _rate Number of token units a buyer gets per wei\r\n   * @param _wallet Address where collected funds will be forwarded to\r\n   * @param _token Address of the token being sold\r\n   */\r\n    constructor(uint256 _rate, address payable _wallet, IERC20 _token) {\r\n        require(_rate > 0);\r\n        require(_wallet != address(0));\r\n        require(address(_token) != address(0));\r\n\r\n        rate = _rate;\r\n        wallet = _wallet;\r\n        token = _token;\r\n    }\r\n\r\n    // -----------------------------------------\r\n    // Crowdsale external interface\r\n    // -----------------------------------------\r\n\r\n    receive() external payable {\r\n        buyTokens(msg.sender);\r\n    }\r\n\r\n    /**\r\n     * @dev low level token purchase ***DO NOT OVERRIDE***\r\n   * @param _beneficiary Address performing the token purchase\r\n   */\r\n    function buyTokens(address _beneficiary) public virtual payable {\r\n\r\n        uint256 weiAmount = msg.value;\r\n        _preValidatePurchase(_beneficiary, weiAmount);\r\n\r\n        // calculate token amount to be created\r\n        uint256 tokens = _getTokenAmount(weiAmount);\r\n\r\n        // update state\r\n        weiRaised = weiRaised + weiAmount;\r\n\r\n        _processPurchase(_beneficiary, tokens);\r\n        emit TokenPurchase(\r\n            msg.sender,\r\n            _beneficiary,\r\n            weiAmount,\r\n            tokens\r\n        );\r\n\r\n        _updatePurchasingState(_beneficiary, weiAmount);\r\n\r\n        _forwardFunds();\r\n        _postValidatePurchase(_beneficiary, weiAmount);\r\n    }\r\n\r\n    // -----------------------------------------\r\n    // Internal interface (extensible)\r\n    // -----------------------------------------\r\n\r\n    /**\r\n     * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use super to concatenate validations.\r\n   * @param _beneficiary Address performing the token purchase\r\n   * @param _weiAmount Value in wei involved in the purchase\r\n   */\r\n    function _preValidatePurchase(\r\n        address _beneficiary,\r\n        uint256 _weiAmount\r\n    )\r\n    internal virtual\r\n    {\r\n        require(_beneficiary != address(0));\r\n        require(_weiAmount != 0);\r\n    }\r\n\r\n    /**\r\n     * @dev Validation of an executed purchase. Observe state and use revert statements to undo rollback when valid conditions are not met.\r\n   * @param _beneficiary Address performing the token purchase\r\n   * @param _weiAmount Value in wei involved in the purchase\r\n   */\r\n    function _postValidatePurchase(\r\n        address _beneficiary,\r\n        uint256 _weiAmount\r\n    )\r\n    internal virtual\r\n    {\r\n        // optional override\r\n    }\r\n\r\n    /**\r\n     * @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends its tokens.\r\n   * @param _beneficiary Address performing the token purchase\r\n   * @param _tokenAmount Number of tokens to be emitted\r\n   */\r\n    function _deliverTokens(\r\n        address _beneficiary,\r\n        uint256 _tokenAmount\r\n    )\r\n    internal virtual\r\n    {\r\n        token.transfer(_beneficiary, _tokenAmount);\r\n    }\r\n\r\n    /**\r\n     * @dev Executed when a purchase has been validated and is ready to be executed. Not necessarily emits/sends tokens.\r\n   * @param _beneficiary Address receiving the tokens\r\n   * @param _tokenAmount Number of tokens to be purchased\r\n   */\r\n    function _processPurchase(\r\n        address _beneficiary,\r\n        uint256 _tokenAmount\r\n    )\r\n    internal virtual\r\n    {\r\n        _deliverTokens(_beneficiary, _tokenAmount);\r\n    }\r\n\r\n    /**\r\n     * @dev Override for extensions that require an internal state to check for validity (current user contributions, etc.)\r\n   * @param _beneficiary Address receiving the tokens\r\n   * @param _weiAmount Value in wei involved in the purchase\r\n   */\r\n    function _updatePurchasingState(\r\n        address _beneficiary,\r\n        uint256 _weiAmount\r\n    )\r\n    internal virtual\r\n    {\r\n        // optional override\r\n    }\r\n\r\n    /**\r\n     * @dev Override to extend the way in which ether is converted to tokens.\r\n   * @param _weiAmount Value in wei to be converted into tokens\r\n   * @return Number of tokens that can be purchased with the specified _weiAmount\r\n   */\r\n    function _getTokenAmount(uint256 _weiAmount)\r\n    internal virtual view returns (uint256)\r\n    {\r\n        return _weiAmount * rate;\r\n    }\r\n\r\n    /**\r\n     * @dev Determines how ETH is stored/forwarded on purchases.\r\n   */\r\n    function _forwardFunds() internal {\r\n        wallet.transfer(msg.value);\r\n    }\r\n}\r\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"
      }
    },
    "settings": {
      "remappings": [],
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "evmVersion": "cancun",
      "libraries": {},
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      }
    }
  }}