File size: 60,728 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
{
  "language": "Solidity",
  "sources": {
    "contracts/Escrow.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/utils/math/SafeMath.sol\";\nimport \"./IEscrow.sol\";\nimport \"./IModerator.sol\";\nimport \"./IProduct.sol\";\n\ncontract Escrow is IEscrow, Ownable {\n    using SafeMath for uint256;\n    //moderator contract\n    address private moderatorAddress;\n\n    IModerator moderatorContract;\n\n    // product contract\n    address private productAddress;\n    IProduct productContract;\n\n\n    // total app num\n    uint256 private maxAppNum;\n\n    // app owner\n    // appId => address\n    mapping(uint256 => address) private appOwner;\n\n    //how many seconds after order paid, can buyer make dispute\n    // appId => interval\n    mapping(uint256 => uint256) private appIntervalDispute;\n\n    //how many seconds after order paid, can seller claim order\n    // appId => interval\n    mapping(uint256 => uint256) private appIntervalClaim;\n\n    //how many seconds after dispute made, if seller does not response, buyer can claim the refund\n    // appId => interval\n    mapping(uint256 => uint256) private appIntervalRefuse;\n\n    // app uri\n    // appId => string\n    mapping(uint256 => string) private appURI;\n\n    // app name\n    // appId => string\n    mapping(uint256 => string) private appName;\n\n    // app mod commission (For each mod and app owner if possible)\n    mapping(uint256 => uint8) private appModCommission;\n\n    // app owner commission\n    mapping(uint256 => uint8) private appOwnerCommission;\n\n    // modA resolution for order.\n    // orderId => modA resolution : 0 not resolved, 1 agree refund, 2 disagree refund.\n    mapping(uint256 => uint8) private orderModAResolution;\n\n    // modB resolution for order.\n    // orderId => modB resolution : 0 not resolved, 1 agree refund, 2 disagree refund.\n    mapping(uint256 => uint8) private orderModBResolution;\n\n    // total order num\n    uint256 public maxOrderId;\n\n    //Struct Order\n    struct Order {\n        uint256 appId; //app id\n        uint256 amount; //order amount\n        address coinAddress; //coin contract address\n        address buyer; //buyer address\n        uint256 productId; // product id\n        address seller; //seller address\n        uint256 createdTime; //order created timestamp\n        uint256 claimTime; //timestamp after when seller can claim if there is no dispute\n        uint8 status; //order status, 1 paid, 2 buyer ask refund, 3 completed, 4 seller refuse dispute, 5 buyer or seller escalate, so voters can vote\n        \n    }\n\n    // orderId => Order\n    mapping(uint256 => Order) public orderBook;\n    //Struct Dispute\n    struct Dispute {\n        uint256 refund; // refund amount\n        uint256 modAId; //the mod that chosen by buyer\n        uint256 modBId; // the mod that chosen by seller\n        uint256 refuseExpired; // after it, if seller does not refuse refund, buyer can claim the refund\n    }\n\n    // orderId => Dispute\n    mapping(uint256 => Dispute) public disputeBook;\n\n    // user balance (userAddress => mapping(coinAddress => balance))\n    mapping(address => mapping(address => uint256)) private userBalance;\n\n    //Withdraw event\n    event Withdraw(\n        address indexed user, //user wallet address\n        uint256 indexed amount, //withdraw amount\n        address indexed coinContract //withdraw coin contract\n    );\n\n    //Create new APP event\n    event NewApp(uint256 indexed appId); //appId\n\n    //Create order event\n    event PayOrder(\n        uint256 indexed orderId,\n        uint256 indexed appOrderId,\n        address indexed coinAddress,\n        uint256 amount,\n        uint256 productId,\n        address buyer,\n        address seller,\n        uint256 appId\n    );\n\n    //Confirm Done event\n    event ConfirmDone(uint256 indexed appId, uint256 indexed orderId);\n\n    //Ask refund event\n    event AskRefund(\n        uint256 indexed appId,\n        uint256 indexed orderId,\n        uint256 indexed refund,\n        uint256 modAId\n    );\n\n    //Cancel refund event\n    event CancelRefund(uint256 indexed appId, uint256 indexed orderId);\n\n    //Refuse refund event\n    event RefuseRefund(\n        uint256 indexed appId, \n        uint256 indexed orderId,\n        uint256 indexed modBId\n        );\n\n    //Escalate dispute event\n    event Escalate(uint256 indexed appId, uint256 indexed orderId);\n\n    //Resolve to Agree or Disagree refund\n    event Resolve(\n        address indexed user,\n        bool indexed isAgree,\n        uint256 indexed orderId,\n        uint256 appId,\n        uint8 modType // 0 both modA&modB, 1 modA, 2 modB, 3 app Owner \n    );\n\n    //Resolved now event\n    event ResolvedFinally(\n        uint256 indexed appId,\n        uint256 indexed orderId,\n        uint8 indexed refundType //0 disagree win, 1 agree win, 2 seller refund\n    );\n\n    //Cash out event\n    event Claim(\n        address indexed user,\n        uint256 indexed appId,\n        uint256 indexed orderId\n    );\n\n    //User Balance Changed event\n    event UserBalanceChanged(\n        address indexed user,\n        bool indexed isIn,\n        uint256 indexed amount,\n        address coinAddress,\n        uint256 appId,\n        uint256 orderId\n    );\n\n    constructor(address _modAddress, address _prodAddress) payable {\n            moderatorAddress    =   _modAddress;\n            moderatorContract   =  IModerator(_modAddress);\n\n            productAddress      =   _prodAddress;\n            productContract     =   IProduct(_prodAddress);\n\n    }\n\n    // Function to deposit Ether into this contract.\n    // Call this function along with some Ether.\n    // The balance of this contract will be automatically updated.\n    receive() external payable {}\n\n    // get Moderator contract address\n    function getModAddress() external view override returns (address)\n    {\n        return moderatorAddress;\n    }\n\n    // get Product contract address\n    function getProductAddress() external view override returns (address)\n    {\n        return productAddress;\n    }\n\n    // get app owner address\n    function getAppOwner(uint256 appId) public view returns (address) {\n        return appOwner[appId];\n    }\n\n    // get app Interval Dispute timestamp\n    function getAppIntervalDispute(uint256 appId) public view returns(uint256) {\n        return appIntervalDispute[appId];\n    }\n\n    // get app Interval Claim timestamp\n    function getAppIntervalClaim(uint256 appId) public view returns(uint256) {\n        return appIntervalClaim[appId];\n    }\n\n    // get app Interval Refuse timestamp\n    function getAppIntervalRefuse(uint256 appId) public view returns(uint256) {\n        return appIntervalRefuse[appId];\n    }\n\n    // get app URI\n    function getAppURI(uint256 appId) public view returns(string memory) {\n        return appURI[appId];\n    }\n\n    // get app Name\n    function getAppName(uint256 appId) public view returns(string memory) {\n        return appName[appId];\n    }\n\n    // get app Mod Commission\n    function getAppModCommission(uint256 appId) public view returns(uint8) {\n        return appModCommission[appId];\n    }\n\n    // get app Owner Commission\n    function getAppOwnerCommission(uint256 appId) public view returns(uint8) {\n        return appOwnerCommission[appId];\n    }\n\n    // get order ModA Resolution\n    function getModAResolution(uint256 orderId) public view returns(uint8) {\n        return orderModAResolution[orderId];\n    }\n\n    // get order ModB Resolution\n    function getModBResolution(uint256 orderId) public view returns(uint8) {\n        return orderModBResolution[orderId];\n    }\n\n    // get user balance\n    function getUserBalance(address userAddress, address coinAddress) public view returns(uint256) {\n        return userBalance[userAddress][coinAddress];\n    }\n\n    // get order detail\n    function getOrderDetail(uint256 orderId) public view returns(Order memory) {\n        return orderBook[orderId];\n    }\n\n    // get dispute detail\n    function getDisputeDetail(uint256 orderId) public view returns(Dispute memory) {\n        return disputeBook[orderId];\n    }\n\n    //Create new APP\n    function newApp(\n        address _appOwner,\n        string memory _appName,\n        string memory websiteURI\n    ) public onlyOwner returns (uint256) {\n        uint256 appId = maxAppNum.add(1);\n        appOwner[appId] = _appOwner;\n        appURI[appId] = websiteURI;\n        appName[appId] = _appName;\n        appIntervalDispute[appId] = uint256(3000000);// buyer can only dispute in 1 month after order paid.\n        appIntervalClaim[appId] = uint256(3000000);  // seller can claim if buyer does not dispute over 1 month after order paid.\n        appIntervalRefuse[appId] = uint256(259200); // buyer can claim if seller does not refuse dispute over 3 days after dispute .\n        appModCommission[appId] = uint8(1);\n        appOwnerCommission[appId] = uint8(0);\n        maxAppNum = appId;\n        emit NewApp(appId);\n\n        return appId;\n    }\n\n    //Transfer app owner to a new address\n    function setAppOwner(uint256 appId, address _newOwner)\n        public\n        returns (bool)\n    {\n        // Only app owner\n        require(\n            _msgSender() == appOwner[appId],\n            \"Escrow: only app owner can set app owner\"\n        );\n        require(_newOwner != address(0), \"Escrow: new owner is the zero address\");\n        appOwner[appId] = _newOwner;\n\n        return true;\n    }\n\n    //Set mod commission\n    //Only app owner\n    function setModCommission(uint256 appId, uint8 _commission)\n        public\n        returns (bool)\n    {\n        // Only app owner\n        require(\n            _msgSender() == appOwner[appId],\n            \"Escrow: only app owner can set mod commission\"\n        );\n        require(_commission < 15, \"Escrow: commission must be less than 15\");\n        appModCommission[appId] = _commission;\n        return true;\n    }\n\n    //Set app owner commission\n    function setAppOwnerCommission(uint256 appId, uint8 _commission)\n        public\n        returns (bool)\n    {\n        // Only app owner\n        require(\n            _msgSender() == appOwner[appId],\n            \"Escrow: only app owner can set app owner commission\"\n        );\n        require(_commission < 45, \"Escrow: commission must be less than 45\");\n        appOwnerCommission[appId] = _commission;\n        return true;\n    }\n\n    //Set dispute interval\n    function setIntervalDispute(uint256 appId, uint256 _seconds)\n        public\n        returns (bool)\n    {\n        // Only app owner\n        require(\n            _msgSender() == appOwner[appId],\n            \"Escrow: only app owner can set dispute interval\"\n        );\n        require(_seconds > 10, \"Escrow: interval time too small!\");\n        require(_seconds < 10000000, \"Escrow: interval time too big!\");\n        appIntervalDispute[appId] = _seconds;\n        return true;\n    }\n\n    //Set refuse interval\n    function setIntervalRefuse(uint256 appId, uint256 _seconds)\n        public\n        returns (bool)\n    {\n        // Only app owner\n        require(\n            _msgSender() == appOwner[appId],\n            \"Escrow: only app owner can set refuse interval\"\n        );\n        require(_seconds > 10, \"Escrow: interval time too small!\");\n        require(_seconds < 10000000, \"Escrow: interval time too big!\");\n        appIntervalRefuse[appId] = _seconds;\n        return true;\n    }\n\n    //Set claim interval\n    function setIntervalClaim(uint256 appId, uint256 _seconds)\n        public\n        returns (bool)\n    {\n        // Only app owner\n        require(\n            _msgSender() == appOwner[appId],\n            \"Escrow: only app owner can set claim interval\"\n        );\n        require(_seconds > 20, \"Escrow: interval time too small!\");\n        require(_seconds < 10000000, \"Escrow: interval time too big!\");\n        appIntervalClaim[appId] = _seconds;\n        return true;\n    }\n\n    function getMaxModId() public view returns (uint256) {\n       return moderatorContract.getMaxModId();\n    }\n\n    function getModOwner(uint256 modId) public view returns (address) {\n        return moderatorContract.getModOwner(modId);\n    }\n\n    //Pay Order\n    function payOrder(\n        uint256 appId,\n        uint256 amount,\n        address coinAddress,\n        uint256 productId,\n        uint256 appOrderId\n    ) public payable returns (uint256) {\n        require(\n            appId > 0 &&\n                appId <= maxAppNum &&\n                appOrderId > 0 &&\n                amount > 0,\n                \"Escrow: all the ids should be bigger than 0\"\n        );\n        // Product should not be blocked\n        require(!productContract.isProductBlocked(productId),\"product should not be blocked\");\n        \n        //Native Currency\n        if (coinAddress == address(0)) {\n            require(msg.value == amount, \"Escrow: Wrong amount or wrong value sent\");\n            //send native currency to this contract\n            payable(this).transfer(amount);\n        } else {\n            IERC20 buyCoinContract = IERC20(coinAddress);\n            //send ERC20 to this contract\n            buyCoinContract.transferFrom(_msgSender(), address(this), amount);\n        }\n        maxOrderId = maxOrderId.add(1);\n        // store order information\n        Order memory _order;\n        _order.appId = appId;\n        _order.coinAddress = coinAddress;\n        _order.amount = amount;\n        _order.buyer = _msgSender();\n        _order.seller = productContract.getProdOwner(productId);\n        _order.productId = productId;\n        _order.createdTime = block.timestamp;\n        _order.claimTime = block.timestamp.add(appIntervalClaim[appId]);\n        _order.status = uint8(1);\n        \n        orderBook[maxOrderId] = _order;\n\n        // emit event\n        emit PayOrder(\n            maxOrderId,\n            appOrderId,\n            coinAddress,\n            amount,\n            productId,\n            _msgSender(),\n            productContract.getProdOwner(productId),\n            appId\n        );\n\n        return maxOrderId;\n    }\n\n    //confirm order received, and money will be sent to seller's balance\n    //triggled by buyer\n    function confirmDone(uint256 orderId) public {\n        require(\n            _msgSender() == orderBook[orderId].buyer,\n            \"Escrow: only buyer can confirm done\"\n        );\n\n        require(\n            orderBook[orderId].status == uint8(1) ||\n                orderBook[orderId].status == uint8(2) ||\n                orderBook[orderId].status == uint8(4),\n            \"Escrow: order status must be equal to just paid or refund asked or dispute refused\"\n        );\n\n        // send money to seller's balance\n        userBalance[orderBook[orderId].seller][\n            orderBook[orderId].coinAddress\n        ] = userBalance[orderBook[orderId].seller][\n            orderBook[orderId].coinAddress\n        ].add(orderBook[orderId].amount);\n        emit UserBalanceChanged(\n            orderBook[orderId].seller,\n            true,\n            orderBook[orderId].amount,\n            orderBook[orderId].coinAddress,\n            orderBook[orderId].appId,\n            orderId\n        );\n\n        // set order status to completed\n        orderBook[orderId].status = uint8(3);\n\n        // update product sold\n        productContract.updateProdScore(orderBook[orderId].productId, true);\n\n        //emit event\n        emit ConfirmDone(orderBook[orderId].appId, orderId);\n    }\n\n    //ask refund\n    //triggled by buyer\n    function askRefund(uint256 orderId, uint256 refund, uint256 modAId) public {\n        require(\n            _msgSender() == orderBook[orderId].buyer,\n            \"Escrow: only buyer can make dispute\"\n        );\n\n        require(\n            orderBook[orderId].status == uint8(1) ||\n                orderBook[orderId].status == uint8(2),\n            \"Escrow: order status must be equal to just paid or refund asked\"\n        );\n\n        require(\n            block.timestamp < orderBook[orderId].createdTime.add(appIntervalDispute[orderBook[orderId].appId]),\n            \"Escrow: it is too late to make dispute\"\n        );\n\n        require(refund > 0 && refund <= orderBook[orderId].amount, \n                \"Escrow: refund amount must be bigger than 0 and not bigger than paid amount\");\n\n        //Mod Id should be validated\n        require(modAId <= moderatorContract.getMaxModId(), \"Escrow: mod id is too big\");\n\n        // update order status \n        if (orderBook[orderId].status == uint8(1)) {\n            orderBook[orderId].status = uint8(2);\n        }\n        // update dispute modAId\n        disputeBook[orderId].modAId = modAId;\n        // update refund of dispute\n        disputeBook[orderId].refund = refund;\n        \n        // update refuse expired\n        disputeBook[orderId].refuseExpired = block.timestamp.add(appIntervalRefuse[orderBook[orderId].appId]);\n        //emit event\n        emit AskRefund(orderBook[orderId].appId, orderId, refund, modAId);\n    }\n\n    //cancel refund\n    //triggled by buyer\n    function cancelRefund(uint256 orderId) public {\n        require(\n            _msgSender() == orderBook[orderId].buyer,\n            \"Escrow: only buyer can cancel refund\"\n        );\n\n        require(\n            orderBook[orderId].status == uint8(2) ||\n                orderBook[orderId].status == uint8(4),\n            \"Escrow: order status must be equal to refund asked or refund refused\"\n        );\n\n        //update order status to paid\n        orderBook[orderId].status = uint8(1);\n\n        emit CancelRefund(orderBook[orderId].appId, orderId);\n    }\n\n    //refuse refund\n    //triggled by seller\n    function refuseRefund(uint256 orderId, uint256 modBId) public {\n        require(\n            _msgSender() == orderBook[orderId].seller,\n            \"Escrow: only seller can refuse dispute\"\n        );\n\n        require(\n            orderBook[orderId].status == uint8(2),\n            \"Escrow: order status must be equal to refund asked\"\n        );\n\n        require(\n            modBId > 0 && modBId <= moderatorContract.getMaxModId(),\n            \"Escrow: modB id does not exists\"\n        );\n\n        // update modBId of dispute\n        disputeBook[orderId].modBId = modBId;\n\n        //update order status to refund refused\n        orderBook[orderId].status = uint8(4);\n\n        emit RefuseRefund(orderBook[orderId].appId, orderId, modBId);\n    }\n\n    //escalate, so mods can vote\n    //triggled by seller or buyer\n    function escalate(uint256 orderId) public {\n        require(\n            _msgSender() == orderBook[orderId].seller ||\n                _msgSender() == orderBook[orderId].buyer,\n            \"Escrow: only seller or buyer can escalate\"\n        );\n\n        require(\n            orderBook[orderId].status == uint8(4),\n            \"Escrow: order status must be equal to refund refused by seller\"\n        );\n\n        //update order status to escalated dispute, ready for mods to vote\n        orderBook[orderId].status = uint8(5);\n\n        emit Escalate(orderBook[orderId].appId, orderId);\n    }\n\n    // if seller agreed refund, then refund immediately\n    // otherwise let mods or appOwner(if need) to judge\n    \n    function agreeRefund(uint256 orderId) public {\n        //if seller agreed refund, then refund immediately\n        if (_msgSender() == orderBook[orderId].seller) {\n            require(\n                orderBook[orderId].status == uint8(2) ||\n                    orderBook[orderId].status == uint8(4) ||\n                    orderBook[orderId].status == uint8(5),\n                \"Escrow: order status must be at refund asked or refund refused or dispute esclated\"\n            );\n            sellerAgree(orderId);\n        } else {\n            require(\n                orderBook[orderId].status == uint8(5),\n                \"Escrow: mod can only vote on dispute escalated status\"\n            );\n            // get the mod's owner wallet address\n            address modAWallet = moderatorContract.getModOwner(disputeBook[orderId].modAId);\n            address modBWallet = moderatorContract.getModOwner(disputeBook[orderId].modBId);\n            // if modA's owner equal to modB's owner and they are msg sender\n            if (\n                modAWallet == modBWallet &&\n                modAWallet == _msgSender()\n            ) {\n                // set modAResolution/modBResolution to voted\n                orderModAResolution[orderId] = uint8(1);\n                orderModBResolution[orderId] = uint8(1);\n                resolvedFinally(orderId, true);\n                emit Resolve(\n                    _msgSender(),\n                    true,\n                    orderId,\n                    orderBook[orderId].appId,\n                    uint8(0)\n                );\n            }\n            // if voter is app owner , and modA/modB not agree with each other.\n            else if (\n                appOwner[orderBook[orderId].appId] == _msgSender() &&\n                ((orderModAResolution[orderId] == uint8(1) &&\n                    orderModBResolution[orderId] == uint8(2)) ||\n                    (orderModAResolution[orderId] == uint8(2) &&\n                        orderModBResolution[orderId] == uint8(1)))\n            ) {\n                resolvedFinally(orderId, true);\n                emit Resolve(\n                    _msgSender(),\n                    true,\n                    orderId,\n                    orderBook[orderId].appId,\n                    uint8(3)\n                );\n            }\n            // if voter is modA, and modA not vote yet, and modB not vote or vote disagree\n            else if (\n                modAWallet ==  _msgSender() &&\n                orderModAResolution[orderId] == uint8(0) &&\n                (orderModBResolution[orderId] == uint8(0) ||\n                    orderModBResolution[orderId] == uint8(2))\n            ) {\n                // set modAResolution to voted\n                orderModAResolution[orderId] = uint8(1);\n                emit Resolve(\n                    _msgSender(),\n                    true,\n                    orderId,\n                    orderBook[orderId].appId,\n                    uint8(1)\n                );\n            }\n            // if voter is modA, and modA not vote yet, and modB vote agree\n            else if (\n                modAWallet == _msgSender() &&\n                orderModAResolution[orderId] == uint8(0) &&\n                orderModBResolution[orderId] == uint8(1)\n            ) {\n                // set modAResolution to voted\n                orderModAResolution[orderId] = uint8(1);\n                resolvedFinally(orderId, true);\n                emit Resolve(\n                    _msgSender(),\n                    true,\n                    orderId,\n                    orderBook[orderId].appId,\n                    uint8(1)\n                );\n            }\n            // if voter is modB, and modB not vote yet, and modA not vote or vote disagree\n            else if (\n                modBWallet == _msgSender() &&\n                orderModBResolution[orderId] == uint8(0) &&\n                (orderModAResolution[orderId] == uint8(0) ||\n                    orderModAResolution[orderId] == uint8(2))\n            ) {\n                // set modBResolution to voted\n                orderModBResolution[orderId] = uint8(1);\n                emit Resolve(\n                    _msgSender(),\n                    true,\n                    orderId,\n                    orderBook[orderId].appId,\n                    uint8(2)\n                );\n            }\n            // if voter is modB, and modB not vote yet, and modA vote agree\n            else if (\n                modBWallet == _msgSender() &&\n                orderModBResolution[orderId] == uint8(0) &&\n                orderModAResolution[orderId] == uint8(1)\n            ) {\n                // set modBResolution to voted\n                orderModBResolution[orderId] = uint8(1);\n                resolvedFinally(orderId, true);\n                emit Resolve(\n                    _msgSender(),\n                    true,\n                    orderId,\n                    orderBook[orderId].appId,\n                    uint8(2)\n                );\n            }\n            // in other case , revert\n            else {\n                revert(\"Escrow: sender can not vote!\");\n            }\n        }\n    } \n\n    // the _msgSender() does not agree the refund\n    \n    function disagreeRefund(uint256 orderId) public {\n        require(\n            orderBook[orderId].status == uint8(5),\n            \"Escrow: mod can only vote on dispute escalated status\"\n        );\n        // get the mod's owner wallet address\n        address modAWallet = moderatorContract.getModOwner(disputeBook[orderId].modAId);\n        address modBWallet = moderatorContract.getModOwner(disputeBook[orderId].modBId);\n        // if modA's owner equal to modB's owner and they are msg sender\n        if (\n            modAWallet == modBWallet && \n            modAWallet == _msgSender()\n        ) {\n            // set modAResolution/modBResolution to voted\n            orderModAResolution[orderId] = uint8(2);\n            orderModBResolution[orderId] = uint8(2);\n            resolvedFinally(orderId, false);\n            emit Resolve(\n                _msgSender(), \n                false, \n                orderId, \n                orderBook[orderId].appId,\n                uint8(0)\n                );\n        }\n        // if voter is app owner , and modA/modB not agree with each other.\n        else if (\n            appOwner[orderBook[orderId].appId] == _msgSender() &&\n            ((orderModAResolution[orderId] == uint8(2) &&\n                orderModBResolution[orderId] == uint8(1)) ||\n                (orderModAResolution[orderId] == uint8(1) &&\n                    orderModBResolution[orderId] == uint8(2)))\n        ) {\n            resolvedFinally(orderId, false);\n            emit Resolve(\n                _msgSender(), \n                false, \n                orderId, \n                orderBook[orderId].appId,\n                uint8(3)\n                );\n        }\n        // if voter is modA, and modA not vote yet, and modB not vote or vote agree\n        else if (\n            modAWallet == _msgSender() &&\n            orderModAResolution[orderId] == uint8(0) &&\n            (orderModBResolution[orderId] == uint8(0) ||\n                orderModBResolution[orderId] == uint8(1))\n        ) {\n            // set modAResolution to voted\n            orderModAResolution[orderId] = uint8(2);\n            emit Resolve(\n                _msgSender(), \n                false, \n                orderId, \n                orderBook[orderId].appId,\n                uint8(1)\n                );\n        }\n        // if voter is modA, and modA not vote yet, and modB vote disagree\n        else if (\n            modAWallet == _msgSender() &&\n            orderModAResolution[orderId] == uint8(0) &&\n            orderModBResolution[orderId] == uint8(2)\n        ) {\n            // set modAResolution to voted\n            orderModAResolution[orderId] = uint8(2);\n            resolvedFinally(orderId, false);\n            emit Resolve(\n                _msgSender(), \n                false, \n                orderId, \n                orderBook[orderId].appId,\n                uint8(1)\n                );\n        }\n        // if voter is modB, and modB not vote yet, and modA not vote or vote agree\n        else if (\n            modBWallet == _msgSender() &&\n            orderModBResolution[orderId] == uint8(0) &&\n            (orderModAResolution[orderId] == uint8(0) ||\n                orderModAResolution[orderId] == uint8(1))\n        ) {\n            // set modBResolution to voted\n            orderModBResolution[orderId] = uint8(2);\n            emit Resolve(\n                _msgSender(), \n                false, \n                orderId, \n                orderBook[orderId].appId,\n                uint8(2)\n                );\n        }\n        // if voter is modB, and modB not vote yet, and modA vote disagree\n        else if (\n            modBWallet == _msgSender() &&\n            orderModBResolution[orderId] == uint8(0) &&\n            orderModAResolution[orderId] == uint8(2)\n        ) {\n            // set modBResolution to voted\n            orderModBResolution[orderId] = uint8(2);\n            resolvedFinally(orderId, false);\n            emit Resolve(\n                _msgSender(), \n                false, \n                orderId, \n                orderBook[orderId].appId,\n                uint8(2)\n                );\n        }\n        // in other case , revert\n        else {\n            revert(\"Escrow: sender can not vote!\");\n        }\n    } \n\n    // if seller agreed refund, then refund immediately\n    \n    function sellerAgree(uint256 orderId) internal {\n        require(_msgSender() == orderBook[orderId].seller);\n        // update order status to finish\n        orderBook[orderId].status = uint8(3);\n        // final commission is the app owner commission\n        uint8 finalCommission = appOwnerCommission[orderBook[orderId].appId];\n        // add app ownner commission fee\n        userBalance[appOwner[orderBook[orderId].appId]][orderBook[orderId].coinAddress] =\n        userBalance[appOwner[orderBook[orderId].appId]][orderBook[orderId].coinAddress].add(\n            orderBook[orderId].amount.mul(finalCommission).div(100));\n        emit UserBalanceChanged(\n                appOwner[orderBook[orderId].appId],\n                true,\n                orderBook[orderId].amount.mul(finalCommission).div(100),\n                orderBook[orderId].coinAddress,\n                orderBook[orderId].appId,\n                orderId\n            );\n        // as the refund is approved, refund to buyer\n        userBalance[orderBook[orderId].buyer][\n            orderBook[orderId].coinAddress\n        ] = userBalance[orderBook[orderId].buyer][\n            orderBook[orderId].coinAddress\n        ].add(disputeBook[orderId].refund.mul(100 - finalCommission).div(100));\n        emit UserBalanceChanged(\n            orderBook[orderId].buyer,\n            true,\n            disputeBook[orderId].refund.mul(100 - finalCommission).div(100),\n            orderBook[orderId].coinAddress,\n            orderBook[orderId].appId,\n            orderId\n        );\n        // if there is amount left, then send left amount to seller\n        if (orderBook[orderId].amount > disputeBook[orderId].refund) {\n            userBalance[orderBook[orderId].seller][\n                orderBook[orderId].coinAddress\n            ] = userBalance[orderBook[orderId].seller][\n                orderBook[orderId].coinAddress\n            ].add(\n                    (orderBook[orderId].amount.sub(disputeBook[orderId].refund))\n                        .mul(100 - finalCommission)\n                        .div(100)\n                );\n            emit UserBalanceChanged(\n                orderBook[orderId].seller,\n                true,\n                (orderBook[orderId].amount.sub(disputeBook[orderId].refund))\n                    .mul(100 - finalCommission)\n                    .div(100),\n                orderBook[orderId].coinAddress,\n                orderBook[orderId].appId,\n                orderId\n            );\n        }\n        emit ResolvedFinally(orderBook[orderId].appId, orderId, uint8(1));\n    } \n    \n    function resolvedFinally(uint256 orderId, bool result) internal {\n        // update order status to finish\n        orderBook[orderId].status = uint8(3);\n\n        // the mod who judge right decision will increase 1 score, as well as adding the mod commission\n        uint8 modNum = 1;\n        uint8 winResolve = result ? 1 : 2;\n        // get the mod's owner wallet address\n        address modAWallet = moderatorContract.getModOwner(disputeBook[orderId].modAId);\n        address modBWallet = moderatorContract.getModOwner(disputeBook[orderId].modBId);\n        // if modA's owner equal to modB's owner, then just increase 1 success score for the owner\n        // and add the mod commission\n        if (\n            modAWallet == modBWallet\n        ) {\n            rewardMod(\n                orderId,\n                disputeBook[orderId].modAId,\n                modAWallet\n            );\n        }\n        // else if modA does not agree with modB\n        else if (orderModAResolution[orderId] != orderModBResolution[orderId]) {\n            modNum = 2;\n            // anyway app owner will get the mod commission\n            userBalance[appOwner[orderBook[orderId].appId]][\n                orderBook[orderId].coinAddress\n            ] = userBalance[appOwner[orderBook[orderId].appId]][\n                orderBook[orderId].coinAddress\n            ].add(\n                    orderBook[orderId]\n                        .amount\n                        .mul(appModCommission[orderBook[orderId].appId])\n                        .div(100)\n                );\n            // the mod who vote the same as final result will give award\n            if (orderModAResolution[orderId] == winResolve) {\n                rewardMod(\n                    orderId,\n                    disputeBook[orderId].modAId,\n                    modAWallet\n                );\n                moderatorContract.updateModScore(disputeBook[orderId].modBId,false);\n            } else {\n                rewardMod(\n                    orderId,\n                    disputeBook[orderId].modBId,\n                    modBWallet\n                );\n                moderatorContract.updateModScore(disputeBook[orderId].modAId,false);\n            }\n        }\n        // else if modA agree with modB\n        else {\n            // give both mods reward\n            modNum = 2;\n            rewardMod(\n                orderId,\n                disputeBook[orderId].modAId,\n                modAWallet\n            );\n            rewardMod(\n                orderId,\n                disputeBook[orderId].modBId,\n                modBWallet\n            );\n        }\n        // caculate the commission fee\n        uint8 finalCommission = appOwnerCommission[orderBook[orderId].appId] +\n            (modNum * appModCommission[orderBook[orderId].appId]);\n        // send app owner commission fee\n        userBalance[appOwner[orderBook[orderId].appId]][orderBook[orderId].coinAddress] =\n        userBalance[appOwner[orderBook[orderId].appId]][orderBook[orderId].coinAddress].add(\n            orderBook[orderId].amount.mul(appOwnerCommission[orderBook[orderId].appId]).div(100));\n        emit UserBalanceChanged(\n                appOwner[orderBook[orderId].appId],\n                true,\n                orderBook[orderId].amount.mul(appOwnerCommission[orderBook[orderId].appId]).div(100),\n                orderBook[orderId].coinAddress,\n                orderBook[orderId].appId,\n                orderId\n            );\n        //if result is to refund, then refund to buyer, the left will be sent to seller\n        //else all paid to the seller\n\n        if (result == true) {\n            // as the refund is approved, refund to buyer\n            userBalance[orderBook[orderId].buyer][orderBook[orderId].coinAddress] = \n            userBalance[orderBook[orderId].buyer][orderBook[orderId].coinAddress].add(\n                    disputeBook[orderId].refund.mul(100 - finalCommission).div(100));\n            emit UserBalanceChanged(\n                orderBook[orderId].buyer,\n                true,\n                disputeBook[orderId].refund.mul(100 - finalCommission).div(100),\n                orderBook[orderId].coinAddress,\n                orderBook[orderId].appId,\n                orderId\n            );\n            // if there is amount left, then send left amount to seller\n            if (orderBook[orderId].amount > disputeBook[orderId].refund) {\n                userBalance[orderBook[orderId].seller][\n                    orderBook[orderId].coinAddress\n                ] = userBalance[orderBook[orderId].seller][\n                    orderBook[orderId].coinAddress\n                ].add(\n                        (\n                            orderBook[orderId].amount.sub(\n                                disputeBook[orderId].refund\n                            )\n                        ).mul(100 - finalCommission).div(100)\n                    );\n                emit UserBalanceChanged(\n                    orderBook[orderId].seller,\n                    true,\n                    (orderBook[orderId].amount.sub(disputeBook[orderId].refund))\n                        .mul(100 - finalCommission)\n                        .div(100),\n                    orderBook[orderId].coinAddress,\n                    orderBook[orderId].appId,\n                    orderId\n                );\n            }\n            // update product sold\n            productContract.updateProdScore(orderBook[orderId].productId, false);\n            emit ResolvedFinally(orderBook[orderId].appId, orderId, uint8(1));\n        } else {\n            // send all the amount to the seller\n            userBalance[orderBook[orderId].seller][\n                orderBook[orderId].coinAddress\n            ] = userBalance[orderBook[orderId].seller][\n                orderBook[orderId].coinAddress\n            ].add(\n                    orderBook[orderId].amount.mul(100 - finalCommission).div(\n                        100\n                    )\n                );\n            emit UserBalanceChanged(\n                orderBook[orderId].seller,\n                true,\n                orderBook[orderId].amount.mul(100 - finalCommission).div(100),\n                orderBook[orderId].coinAddress,\n                orderBook[orderId].appId,\n                orderId\n            );\n            // update product sold\n            productContract.updateProdScore(orderBook[orderId].productId, true);\n            emit ResolvedFinally(orderBook[orderId].appId, orderId, uint8(0));\n        }\n    }\n\n    // reward mod\n    // adding mod commission as well as increasing mod score\n    \n    function rewardMod(uint256 orderId, uint256 modId, address mod) private {\n        moderatorContract.updateModScore(modId, true);\n        userBalance[mod][orderBook[orderId].coinAddress] = \n        userBalance[mod][orderBook[orderId].coinAddress].add(\n            orderBook[orderId].amount.mul(appModCommission[orderBook[orderId].appId]).div(100));\n        emit UserBalanceChanged(\n                mod,\n                true,\n                orderBook[orderId].amount.mul(appModCommission[orderBook[orderId].appId]).div(100),\n                orderBook[orderId].coinAddress,\n                orderBook[orderId].appId,\n                orderId\n            );\n    } \n\n    //seller want to claim money from order to balance\n    //or\n    //buyer want to claim money after seller either not to refuse dispute or agree dispute\n    \n    function claim(uint256 orderId) public {\n        // final commission is the app owner commission\n        uint8 finalCommission = appOwnerCommission[orderBook[orderId].appId];\n        // add app ownner commission fee\n        userBalance[appOwner[orderBook[orderId].appId]][orderBook[orderId].coinAddress] =\n        userBalance[appOwner[orderBook[orderId].appId]][orderBook[orderId].coinAddress].add(\n            orderBook[orderId].amount.mul(finalCommission).div(100));\n        emit UserBalanceChanged(\n                appOwner[orderBook[orderId].appId],\n                true,\n                orderBook[orderId].amount.mul(finalCommission).div(100),\n                orderBook[orderId].coinAddress,\n                orderBook[orderId].appId,\n                orderId\n            );\n        //seller claim\n        if (_msgSender() == orderBook[orderId].seller) {\n            require(\n                orderBook[orderId].status == uint8(1),\n                \"Escrow: order status must be equal to 1 \"\n            );\n\n            require(\n                block.timestamp > orderBook[orderId].claimTime,\n                \"Escrow: currently seller can not claim, need to wait\"\n            );\n            // send all the amount to the seller\n            userBalance[orderBook[orderId].seller][\n                orderBook[orderId].coinAddress\n            ] = userBalance[orderBook[orderId].seller][\n                orderBook[orderId].coinAddress\n            ].add(\n                    orderBook[orderId].amount.mul(100 - finalCommission).div(\n                        100\n                    )\n                );\n            // update product sold record\n            productContract.updateProdScore(orderBook[orderId].productId, true);\n            emit UserBalanceChanged(\n                orderBook[orderId].seller,\n                true,\n                orderBook[orderId].amount.mul(100 - finalCommission).div(100),\n                orderBook[orderId].coinAddress,\n                orderBook[orderId].appId,\n                orderId\n            );\n            \n        } else if (_msgSender() == orderBook[orderId].buyer) {\n            // buyer claim\n\n            require(\n                orderBook[orderId].status == uint8(2),\n                \"Escrow: order status must be equal to 2 \"\n            );\n\n            require(\n                block.timestamp > disputeBook[orderId].refuseExpired,\n                \"Escrow: currently buyer can not claim, need to wait\"\n            );\n            // refund to buyer\n            userBalance[orderBook[orderId].buyer][orderBook[orderId].coinAddress] = \n            userBalance[orderBook[orderId].buyer][orderBook[orderId].coinAddress].add(\n                    disputeBook[orderId].refund.mul(100 - finalCommission).div(100));\n            // update product sold record\n            productContract.updateProdScore(orderBook[orderId].productId, false);\n            emit UserBalanceChanged(\n                orderBook[orderId].buyer,\n                true,\n                disputeBook[orderId].refund.mul(100 - finalCommission).div(100),\n                orderBook[orderId].coinAddress,\n                orderBook[orderId].appId,\n                orderId\n            );\n            // if there is amount left, then send left amount to seller\n            if (orderBook[orderId].amount > disputeBook[orderId].refund) {\n                userBalance[orderBook[orderId].seller][\n                    orderBook[orderId].coinAddress\n                ] = userBalance[orderBook[orderId].seller][\n                    orderBook[orderId].coinAddress\n                ].add(\n                        (\n                            orderBook[orderId].amount.sub(\n                                disputeBook[orderId].refund\n                            )\n                        ).mul(100 - finalCommission).div(100)\n                    );\n                    \n                emit UserBalanceChanged(\n                    orderBook[orderId].seller,\n                    true,\n                    (orderBook[orderId].amount.sub(disputeBook[orderId].refund))\n                        .mul(100 - finalCommission)\n                        .div(100),\n                    orderBook[orderId].coinAddress,\n                    orderBook[orderId].appId,\n                    orderId\n                );\n            }\n            \n        } else {\n            revert(\"Escrow: only seller or buyer can claim\");\n        }\n\n        orderBook[orderId].status = 3;\n        emit Claim(_msgSender(), orderBook[orderId].appId, orderId);\n    } \n\n    //withdraw from user balance\n    function withdraw(uint256 _amount, address _coinAddress) public {\n        //get user balance\n        uint256 _balance = userBalance[_msgSender()][_coinAddress];\n\n        require(_balance >= _amount, \"Escrow: insufficient balance!\");\n\n        //descrease user balance\n        userBalance[_msgSender()][_coinAddress] = _balance.sub(_amount);\n\n        //if the coin type is ETH\n        if (_coinAddress == address(0)) {\n            //check balance is enough\n            require(address(this).balance > _amount, \"Escrow: insufficient balance\");\n\n            payable(_msgSender()).transfer(_amount);\n        } else {\n            //if the coin type is ERC20\n\n            IERC20 _token = IERC20(_coinAddress);\n\n            _token.transfer(_msgSender(), _amount);\n        }\n\n        //emit withdraw event\n        emit Withdraw(_msgSender(), _amount, _coinAddress);\n    }\n}\n"
    },
    "contracts/IProduct.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface IProduct {\n    \n    // get product's owner\n    function getProdOwner(uint256 prodId) external view returns(address);\n\n    // get product's total supply\n    function getMaxProdId() external view returns(uint256);\n\n    // update product's score\n    function updateProdScore(uint256 prodId, bool ifSuccess) external returns(bool);\n\n    // get product's block status\n    function isProductBlocked(uint256 prodId) external view returns(bool);\n}"
    },
    "contracts/IModerator.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface IModerator {\n    \n    // get mod's owner\n    function getModOwner(uint256 modId) external view returns(address);\n\n    // get mod's total supply\n    function getMaxModId() external view returns(uint256);\n\n    // update mod's score\n    function updateModScore(uint256 modId, bool ifSuccess) external returns(bool);\n}"
    },
    "contracts/IEscrow.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface IEscrow {\n    function getModAddress() external view returns (address);\n\n    function getProductAddress() external view returns (address);\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/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/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"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    }
  }
}