creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "@openzeppelin/contracts/access/Ownable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.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. 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        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/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"
      },
      "contracts/PriceFeedStore.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.19;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\ncontract PriceFeedStore is Ownable {\n    address public xOracle;\n    string public name;\n    uint256 public tokenIndex;\n    uint256 public decimals;\n\n    // price store\n    struct PriceData {\n        uint256 price;\n        uint256 latestPrice;\n        uint256 timestamp;\n    }\n    mapping(uint256 => PriceData) public pricesData;\n    uint256 public latestRound;\n    uint256 public latestTimestamp;\n\n    event UpdatePrice(uint256 indexed tokenIndex, uint256 roundId, uint256 price, uint256 latestPrice, uint256 timestamp);\n    event SetXOracle(address xOracle);\n\n    modifier onlyXOracle() {\n        require(xOracle == msg.sender, \"xOracle: forbidden\");\n        _;\n    }\n\n    constructor(address _xOracle, string memory _name, uint256 _tokenIndex, uint256 _decimals) {\n        require(_xOracle != address(0), \"address invalid\");\n        xOracle = _xOracle;\n        name = _name;\n        tokenIndex = _tokenIndex;\n        decimals = _decimals;\n    }\n\n    // ------------------------------\n    // xOracle setPrice\n    // ------------------------------\n    function setPrice(uint256 _price, uint256 _timestamp) external onlyXOracle { \n        // Sometimes the fulfill request is not in order in a short time.\n        // So it's possible that the price is not the latest price.\n        // _price is the fulfilling price, but latestPrice is the newest price at the time.\n        uint256 latestPrice;\n        if (_timestamp > latestTimestamp) {\n            latestPrice = _price;\n            latestTimestamp = _timestamp;\n        } else {\n            latestPrice = pricesData[latestRound].latestPrice;\n        }\n\n        // next round\n        latestRound++;\n\n        // already checked correct tokenIndex in xOracle.setPriceFeedStore\n        pricesData[latestRound] = PriceData({\n            price: _price,\n            latestPrice: latestPrice,\n            timestamp: block.timestamp\n        });\n\n        emit UpdatePrice(tokenIndex, latestRound, _price, latestPrice, block.timestamp);\n    }\n\n    // ------------------------------\n    // onlyOwner\n    // ------------------------------\n    function setXOracle(address _xOracle) external onlyOwner {\n        require(_xOracle != address(0), \"address invalid\");\n        xOracle = _xOracle;\n        emit SetXOracle(_xOracle);\n    }\n\n    // ------------------------------\n    // view function\n    // ------------------------------\n    function getLastPrice() external view returns (uint256, uint256, uint256, uint256) {\n        PriceData memory priceData = pricesData[latestRound];\n        return (\n            latestRound, \n            priceData.price, \n            priceData.latestPrice, \n            priceData.timestamp\n        );\n    }\n\n    function getPrice(uint256 _roundId) external view returns (uint256, uint256, uint256, uint256) {\n        PriceData memory priceData = pricesData[_roundId];\n        return (\n            _roundId, \n            priceData.price, \n            priceData.latestPrice, \n            priceData.timestamp\n        );\n    }\n}"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "libraries": {}
    }
  }}