Contract 0x50a64d05bB8618D8d96A83CbBb12b3044ec3489A 7

 
 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0xd07013a8f0bdafcb4a792eb3e06935ebafde2b57dc94692ad2516399a35be27b0x500f528c317669872022-08-11 11:39:3311 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00863586000330.000000013
0x669b2d91e3f5c49a6197efbb2b179d6d2b5406e7ccb694617bbf913682c5c2320x3fc8ef10317646242022-08-11 10:11:551 hr 39 mins ago0xb1cc45dab6818f1e6b948621016d188f0e4bed5f IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a13 MATIC0.013072169817 30.555231786
0x77e051c69b7cabcc0bc54b0490acf675e183019102f43c106ae1afe9391471d3Batch Claim317642512022-08-11 9:59:051 hr 52 mins ago0xe0276474243fff9aa11fbe7acb80f6bf04c142ab IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00455816075530.019894596
0xcb7d550abacf89974dee95ac8f3a95f9c1a63a63349b368f87f2403bbbe413290x3fc8ef10317641512022-08-11 9:55:371 hr 55 mins ago0x37d6da103946ad22c18e75356f9ea9616b96fc2a IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.01153534411 35.554629855
0x2f8aa6a2b7e26fe052175edbb9cf7e10bfc347649e4884ae51b8214ee394e48e0x500f528c317632222022-08-11 9:19:272 hrs 32 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.01220599041431.961137609
0xefea0d8bf835c2017d7c3dd09e4466926ed07be58f40ee5a4073735b4d97f2a10x500f528c317630992022-08-11 9:15:132 hrs 36 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.0124365951132.332993911
0x1f36060bbe949cdcc683b07c551afd4946247b3f0df05870f250e0dc14f5a3810x500f528c317625142022-08-11 8:52:592 hrs 58 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00990347842832.091738561
0xa848c9007722cf656117729550f7520bd2ca6fed8acc9251fedf0dfd2f3a136c0x500f528c317620942022-08-11 8:38:313 hrs 12 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.0056748588238.25472429
0xd410e523ba0a92d646de643e90cb3a7f6ddb25aa50797676df38553ce93c29270x500f528c317617752022-08-11 8:27:333 hrs 23 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.01996225589752.270761001
0x5370794accb4b0cfbca3417412ca1dae4a370c7933363109b14bbb36a48c7ba90x500f528c317614812022-08-11 8:17:263 hrs 34 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.01302490404434.105446293
0x6777cb1ff4301cf657c6e2ad6462b8d75b82f889a9468add5753187bd709cf810x3fc8ef10317614422022-08-11 8:16:043 hrs 35 mins ago0x2bb74f34019509d8c8cf2bcd7f1692ba32f9e8cd IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a25.558978686357303 MATIC0.015209661985 34.105669348
0xfdc2d3403d19700f9c212dfdd16ce4af836ce1ee35d1801d151b78cf2345e2b70x500f528c317594332022-08-11 6:56:154 hrs 55 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00430182002130.000000153
0xceffd19258a0e4b206f6444dbcec10dcdadadc922855a98f3d4069a4a8a75277Batch Claim317576432022-08-11 5:50:206 hrs 1 min ago0xe0276474243fff9aa11fbe7acb80f6bf04c142ab IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00556674000330.000000017
0xa36231093902f712461b736bcb24e41c6dbd4d0c54ea880eec3b04029a7fd22d0x500f528c317576292022-08-11 5:49:486 hrs 1 min ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00418326000230.000000016
0xfdccbddec46c39438b88a8eb6d2f00d365e2b73f899cf4c5a4a47303f9430eab0x500f528c317576172022-08-11 5:49:246 hrs 2 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00418290000230.000000021
0x82f539cb436a864880818f07de9d7335987a53572aa8729f768b92fabca3661c0x500f528c317576032022-08-11 5:48:566 hrs 2 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00418398000430.000000029
0xe15ca6bddba850dbea18657ed821736817cb14d9528c497c341b2154a0deaca20x3fc8ef10317575512022-08-11 5:47:086 hrs 4 mins ago0x9d90793344ed2dab8879a0ea2acf6ff33900fdc3 IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00994760551131.500000036
0x88416ad0511ea39d52f4f10a6495939e9dfcb7da2e5eb5eaf01ce9c7259a1e3bBatch Claim317575482022-08-11 5:47:026 hrs 4 mins ago0xe0276474243fff9aa11fbe7acb80f6bf04c142ab IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00494973000530.000000036
0x6c0c05caf84c57034c3f0a61aa6278da1acd04ac2359f5f06eda21a02c959f1c0x3fc8ef10317575422022-08-11 5:46:506 hrs 4 mins ago0xbcf78e4cf9b595366d758b53a954fa62152b0c85 IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00994836151531.50000005
0x8adcbb54422ccab6e545a0033eade8ff446767a5f7ba1d59d492f7a0a3aadaad0x500f528c317575252022-08-11 5:46:166 hrs 5 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00418290000530.000000042
0x95041ad01e7cb3934c885d5f7d780c41389dd2c9385c86c62200d390c027c298Batch Claim317575152022-08-11 5:45:566 hrs 5 mins ago0xe0276474243fff9aa11fbe7acb80f6bf04c142ab IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00494937000630.000000037
0x3b610202668d17060d27d5346b1f4235a0e6ffe552e2c9e3e34253813c5861790x500f528c317574992022-08-11 5:45:206 hrs 6 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00418326000430.00000003
0xe09b924c76f3bd11f7f402c5cc157d509579c2db4730959aac2f90e0b06e06f8Batch Claim317574492022-08-11 5:43:406 hrs 7 mins ago0xe0276474243fff9aa11fbe7acb80f6bf04c142ab IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00495033000930.000000056
0x4ef829406ef21d67c5d689a361bbeb6d097b2cb04c9802cf613ddd8effda48790x3fc8ef10317574392022-08-11 5:43:166 hrs 8 mins ago0xe4b80a7f1fb7ac3c9900c5842bae4b988adbedbe IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00994873951931.500000063
0x71b2d99134af3e1a9073aa871debfda874dc93d9bb1cf6dd7c584efde617e51e0x500f528c317574102022-08-11 5:42:186 hrs 9 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a0 MATIC0.00418290001430.000000102
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0x669b2d91e3f5c49a6197efbb2b179d6d2b5406e7ccb694617bbf913682c5c232317646242022-08-11 10:11:551 hr 39 mins ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d13 MATIC
0x6777cb1ff4301cf657c6e2ad6462b8d75b82f889a9468add5753187bd709cf81317614422022-08-11 8:16:043 hrs 35 mins ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d25.558978686357303772 MATIC
0x5c01d6024ac3ae75b71b6a6238841e1d6a089d9808e9a8e99243c4418865701d317483922022-08-11 0:08:5111 hrs 42 mins ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d2 MATIC
0x63de4c51cde2b07a5cd66899382b34e2f3df7b06cfb7c2780fdf8afa391aa0af317305072022-08-10 11:40:361 day 10 mins ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d2 MATIC
0xe247367ab0ec9be770abda144fa24559c2e67bda9076d65397ade7d39ea85a6a317301512022-08-10 11:26:121 day 25 mins ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d1.7 MATIC
0xddcd3d3bdd6315bd5fd9ceca67b9e4733c4dd35e9fd612cc589d3737ded6d819316976632022-08-09 14:11:151 day 21 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d1.5 MATIC
0xcac8b9708080828f26b6e681f418d042ae541485c1e393f954c700878e87ed50316946002022-08-09 12:04:591 day 23 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d48.5 MATIC
0x495b4848a1513dc98247e77fa0367baba632e25657e94d267b110b015ba711bc316769872022-08-09 0:27:052 days 11 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d10 MATIC
0x5675a6d0f82992ce0aeacb6e0d8b32f3d5f85347a8d3680b9582500b3fcf2f3a316767922022-08-09 0:20:232 days 11 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d13 MATIC
0x74ae4c11ee4ddbba0ef8b64ba46f397f10e774dbc3fc80a370cb41542a70ed5e316684802022-08-08 19:10:312 days 16 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d12.5 MATIC
0x3c003eca9cac3dfb8d9672425bd38b3ce3ea3e5416b58138a0a40a83e5ef3f79316650952022-08-08 16:52:482 days 18 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d10.7 MATIC
0x5339e3711a18a675f53bf628d654201c91dc2652b50a7d9a8ef7f88bf9ef1e5a316594612022-08-08 13:09:082 days 22 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d88 MATIC
0x18e2c8e39a71c244228c49e704e5fe7d0fe382f6e8ee62691af71d5ccbac17ee316586722022-08-08 12:41:572 days 23 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d17.5 MATIC
0x36e2839e43f30b57eaccead04aa2f971751db45a5f77c919ea085cb16b474639316551632022-08-08 10:34:523 days 1 hr ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d29.75 MATIC
0x35dbbad5d2e21d0d9654a52f905907d02b31bf736beeca3d94d3c6880d9a1800316548122022-08-08 10:20:423 days 1 hr ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d10.35 MATIC
0xdf4948f0cc230c7a3287fe6dac26e439a7d3138c1ad555d763b6a5efdc00ab41316530192022-08-08 9:14:443 days 2 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d20 MATIC
0x13ae7ca1c7a59f8b968f178136c271f98aaed7c94307371038a0519945a555be316528512022-08-08 9:04:403 days 2 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d15 MATIC
0xe9bc0331ed053d156c33ae1fcb797eeda5a3b23cb6a131973b612167f7775b3b316527152022-08-08 9:00:003 days 2 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d6 MATIC
0x372563e1e46564bc21c898a0966d424f3724d143583fc27fd10dd22d5e4ef8e7316455862022-08-08 4:30:213 days 7 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d47.7 MATIC
0x7cd67d10a20142ff04d89bf95d5565503eabc49f95983b97c08207996a9e186d316414822022-08-08 1:50:003 days 10 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d36 MATIC
0x4c1783b4db05ce7b02b4368a15d18c3a23644149be480ebcb96a12fc748cc4d1316370492022-08-07 22:13:203 days 13 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d82.8618 MATIC
0xa8d6c07e2091109a62caf049fec2d19920f94f7c9f244344cc87a2fc5ba3e656316304402022-08-07 17:23:573 days 18 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d6.3 MATIC
0x4c2b2050cb229ca423ef91b6ec607ec9b84c275b3f5665bdaae88c40691e5fb5316193172022-08-07 9:55:584 days 1 hr ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d2 MATIC
0x999caf74d384cfd544c0d09b70b61916bd531e7d7813a797eafd46acbf17cf40316130772022-08-07 5:51:314 days 5 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d13 MATIC
0x4123ef5dceeaaee0c76483c620653a4da8b6c17507650ee3cbd5540a1d329685315928772022-08-06 16:06:344 days 19 hrs ago 0x50a64d05bb8618d8d96a83cbbb12b3044ec3489a 0xfdf54f6f232dd5a6daf067628ba045a1b5a6724d120 MATIC
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
XSwapper

Compiler Version
v0.8.2+commit.661d1103

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, None license

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 18 : XSwapper.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import { Address } from "Address.sol";
import "ERC20.sol";
import "ECDSA.sol";
import "SafeERC20.sol";
import "Pausable.sol";
import "ReentrancyGuard.sol";
import "AccessControl.sol";

import "Supervisor.sol";
import "IAggregator.sol";
import "IYPoolVault.sol";


/// @title XSwapper contract
/// @notice Users call `swap` to swap asset to specified bridgeable asset and then initiate a cross-chain swap request.
/// YPool workers call `closeSwap` to complete a cross-chain swap, `claim` & `batchClaim` to claim the credit back.
/// YPool validators call `lockCloseSwap` & `refund` to lock the swap and refund asset back to user if no applicable
/// liquidity or a YPool worker sent an invalidated closeSwap tx.
/// - "User" and "Account" refer to the same thing
/// - "fromChain" and "source chain" refer to the same thing
/// - "toChain" and "target chain" refer to the same thing
/// - "XYChain" and "Settlement chain" refer to the same thing
contract XSwapper is AccessControl, Pausable, ReentrancyGuard {

    using SafeERC20 for IERC20;
    using ECDSA for bytes32;

    /* ========== STRUCTURE ========== */

    // Status of a swap request (on source chain)
    enum RequestStatus { Open, Closed }
    // Result of a swap when it's closed (on target chain)
    enum CloseSwapResult { NonSwapped, Success, Failed, Locked }
    // Type of how the asset is transferred when the swap is completed
    enum CompleteSwapType { Claimed, FreeClaimed, Refunded }

    // Fees settings on each chain
    // Fee is calculated as `inputAmount * FeeStructure.rate / (10 ** FeeStructure.decimals)`
    struct FeeStructure {
        bool isSet;
        uint256 gas;
        uint256 min;
        uint256 max;
        uint256 rate;
        uint256 decimals;
    }

    // Info of a swap request
    struct SwapRequest {
        uint32 toChainId;
        uint256 swapId;
        address receiver;
        address sender;
        uint256 YPoolTokenAmount;
        uint256 xyFee;
        uint256 gasFee;
        IERC20 YPoolToken;
        RequestStatus status;
    }

    // Info of an expecting swap on target chain of a swap request
    struct ToChainDescription {
        uint32 toChainId;
        IERC20 toChainToken;
        uint256 expectedToChainTokenAmount;
        uint32 slippage;
    }

    /* ========== STATE VARIABLES ========== */

    // Roles
    bytes32 public constant ROLE_OWNER = keccak256("ROLE_OWNER");
    bytes32 public constant ROLE_MANAGER = keccak256("ROLE_MANAGER");
    bytes32 public constant ROLE_STAFF = keccak256("ROLE_STAFF");
    bytes32 public constant ROLE_YPOOL_WORKER = keccak256("ROLE_YPOOL_WORKER");

    // Mapping of YPool token to its max amount in a single swap
    mapping (address => uint256) public maxYPoolTokenSwapAmount;

    // A contract that supervises each refund and claim by providing signatures
    Supervisor public supervisor;
    // A referenced address of native currency
    address public constant ETHER_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
    // Id of the current chain
    uint32 public immutable chainId;
    // Next available id of a swap request
    // Note: the value is monotonically increasing as there MUST NOT exist swap requests with same Id
    uint256 public swapId = 0;
    // Close status of each swap
    mapping (bytes32 => bool) everClosed;

    // Supported YPool tokens
    mapping (address => bool) public YPoolSupoortedToken;
    // YPoolVault of a YPoolSupportedToken
    mapping (address => address) public YPoolVaults;
    // DEX aggregator used by `swap` and `closeSwap`
    address public aggregator;
    // SwapValidator contract on XYChain that validates a `closeSwap` transaction
    // Note: this contract does not exist on periphery chains so its address is used only for signature verification purpose in `claim` and `batchClaim`
    address public swapValidatorXYChain;

    // Fees setting of a supported token on each chain
    mapping (bytes32 => FeeStructure) public feeStructures;
    // All swap requests initiated by users
    SwapRequest[] public swapRequests;

    constructor(address owner, address manager, address staff, address worker, address _supervisor, uint32 _chainId) {
        require(Address.isContract(_supervisor), "ERR_SUPERVISOR_NOT_CONTRACT");
        supervisor = Supervisor(_supervisor);
        chainId = _chainId;

        // Validate chainId
        uint256 _realChainId;
        assembly {
            _realChainId := chainid()
        }
        require(_chainId == _realChainId, "ERR_WRONG_CHAIN_ID");

        _setRoleAdmin(ROLE_OWNER, ROLE_OWNER);
        _setRoleAdmin(ROLE_MANAGER, ROLE_OWNER);
        _setRoleAdmin(ROLE_STAFF, ROLE_OWNER);
        _setRoleAdmin(ROLE_YPOOL_WORKER, ROLE_OWNER);
        _setupRole(ROLE_OWNER, owner);
        _setupRole(ROLE_MANAGER, manager);
        _setupRole(ROLE_STAFF, staff);
        _setupRole(ROLE_YPOOL_WORKER, worker);
    }

    receive() external payable {}

    /* ========== MODIFIERS ========== */

    modifier approveAggregator(IERC20 token, uint256 amount) {
        if (address(token) != ETHER_ADDRESS) token.safeApprove(aggregator, amount);
        _;
        if (address(token) != ETHER_ADDRESS) token.safeApprove(aggregator, 0);
    }

    /* ========== PRIVATE FUNCTIONS ========== */

    function max(uint256 a, uint256 b) private pure returns (uint256) {
        return a >= b ? a : b;
    }

    function min(uint256 a, uint256 b) private pure returns (uint256) {
        return a < b ? a : b;
    }

    /// @notice Get the XY protocol fee setting of `_token` on chain `_toChainId`
    /// @param _toChainId Chain Id of the periphery chain
    /// @param _token YPool token
    function _getFeeStructure(uint32 _toChainId, address _token) private view returns (FeeStructure memory) {
        bytes32 universalTokenId = keccak256(abi.encodePacked(_toChainId, _token));
        return feeStructures[universalTokenId];
    }

    function _getTokenBalance(IERC20 token, address account) private view returns (uint256 balance) {
        balance = address(token) == ETHER_ADDRESS ? account.balance : token.balanceOf(account);
    }

    function _safeTransferAsset(address receiver, IERC20 token, uint256 amount) private {
        if (address(token) == ETHER_ADDRESS) {
            payable(receiver).transfer(amount);
        } else {
            token.safeTransfer(receiver, amount);
        }
    }

    function _safeTransferFromAsset(IERC20 fromToken, address from, uint256 amount) private {
        if (address(fromToken) == ETHER_ADDRESS)
            require(msg.value == amount, "ERR_INVALID_AMOUNT");
        else {
            uint256 _fromTokenBalance = _getTokenBalance(fromToken, address(this));
            fromToken.safeTransferFrom(from, address(this), amount);
            require(_getTokenBalance(fromToken, address(this)) - _fromTokenBalance == amount, "ERR_INVALID_AMOUNT");
        }
    }

    /// @notice Check whether the swap amount reaches the threshold or not
    /// @param _toChainId Chain Id of the target chain
    /// @param token YPool token
    /// @param amount Swap amount
    /// @dev A swap could be closed by YPool worker on target chain or get refunded on source chain, i.e., this chain,
    /// therefore, we require the `amount` not only be GTE the fee on target chain but also on source chain
    function _checkMinimumSwapAmount(uint32 _toChainId, IERC20 token, uint256 amount) private view returns (bool) {
        FeeStructure memory feeStructure = _getFeeStructure(_toChainId, address(token));
        require(feeStructure.isSet, "ERR_FEE_NOT_SET");
        uint256 minToChainFee = feeStructure.min;  // closeSwap

        feeStructure = _getFeeStructure(chainId, address(token));
        require(feeStructure.isSet, "ERR_FEE_NOT_SET");
        uint256 minFromChainFee = feeStructure.min;  // refund

        return amount >= max(minToChainFee, minFromChainFee);
    }

    /// @notice Calculate the XY protocol fee and gas fee
    /// @param _chainId Chain Id of the periphery chain
    /// @param token YPool token
    /// @param amount YPool token amount
    function _calculateFee(uint32 _chainId, IERC20 token, uint256 amount) private view returns (uint256 xyFee, uint256 gasFee) {
        FeeStructure memory feeStructure = _getFeeStructure(_chainId, address(token));
        require(feeStructure.isSet, "ERR_FEE_NOT_SET");

        xyFee = amount * feeStructure.rate / (10 ** feeStructure.decimals);
        xyFee = min(max(xyFee, feeStructure.min), feeStructure.max);
        gasFee = feeStructure.gas;
    }

    /* ========== VIEW FUNCTIONS ========== */

    /// @notice Get a certain swap request
    /// @param _swapId Swap Id of a swap request
    function getSwapRequest(uint256 _swapId) external view returns (SwapRequest memory) {
        if (_swapId >= swapId) revert();
        return swapRequests[_swapId];
    }

    /// @notice Get the XY protocol fee setting of `_token` on chain `_toChainId`
    /// @param _chainId Chain Id of the periphery chain
    /// @param _token YPool token
    function getFeeStructure(uint32 _chainId, address _token) external view returns (FeeStructure memory) {
        FeeStructure memory feeStructure = _getFeeStructure(_chainId, _token);
        require(feeStructure.isSet, "ERR_FEE_NOT_SET");
        return feeStructure;
    }

    /// @notice Check whether a swap is closed or not on this chain, assuming this chain is the target chain
    /// @param _chainId Chain Id of the source chain
    /// @param _swapId Swap Id of a swap request
    function getEverClosed(uint32 _chainId, uint256 _swapId) external view returns (bool) {
        bytes32 universalSwapId = keccak256(abi.encodePacked(_chainId, _swapId));
        return everClosed[universalSwapId];
    }

    /* ========== RESTRICTED FUNCTIONS (OWNER) ========== */

    /// @notice Set YPoolVault and its token
    /// @param _supportedToken YPool token
    /// @param _vault Address of the YPoolVault
    /// @param _isSet To Add or to remove
    function setYPoolVault(address _supportedToken, address _vault, bool _isSet) external onlyRole(ROLE_OWNER) {
        if (_supportedToken != ETHER_ADDRESS) {
            require(Address.isContract(_supportedToken), "ERR_YPOOL_TOKEN_NOT_CONTRACT");
        }
        require(Address.isContract(_vault), "ERR_YPOOL_VAULT_NOT_CONTRACT");
        YPoolSupoortedToken[_supportedToken] = _isSet;
        YPoolVaults[_supportedToken] = _vault;
        emit YPoolVaultSet(_supportedToken, _vault, _isSet);
    }

    /* ========== RESTRICTED FUNCTIONS (MANAGER) ========== */

    /// @notice Set the maximum swap amount of a YPool token
    /// @param _supportedToken YPool token
    /// @param amount Maximum swap amount
    function setMaxYPoolTokenSwapAmount(address _supportedToken, uint256 amount) external onlyRole(ROLE_MANAGER) {
        require(YPoolSupoortedToken[_supportedToken], "ERR_INVALID_YPOOL_TOKEN");
        maxYPoolTokenSwapAmount[_supportedToken] = amount;
    }

    /// @notice Set the dex aggregator
    /// @param _aggregator Address of the aggregator
    function setAggregator(address _aggregator) external onlyRole(ROLE_MANAGER) {
        require(Address.isContract(_aggregator), "ERR_AGGREGATOR_NOT_CONTRACT");
        aggregator = _aggregator;
        emit AggregatorSet(_aggregator);
    }

    /// @notice Pause the major functions
    function pause() external onlyRole(ROLE_MANAGER) {
        _pause();
    }

    /// @notice Unpause the major functions
    function unpause() external onlyRole(ROLE_MANAGER) {
        _unpause();
    }

    /* ========== RESTRICTED FUNCTIONS (STAFF) ========== */

    /// @notice Set the XY protocol fee setting of `_token` on chain `_toChainId`
    /// @param _toChainId Chain Id of the periphery chain
    /// @param _supportedToken YPool token
    /// @param _gas Estimated gas fee of closeSwap/refund in form of YPool Token
    /// @param _min Minimum amount of the XY protocol fee of `_supportedToken`
    /// @param _max Maximum amount of the XY protocol fee of `_supportedToken`
    /// @param rate Fee rate of the XY protocol fee of `_supportedToken`
    /// @param decimals Decimals of `_rate`
    function setFeeStructure(uint32 _toChainId, address _supportedToken, uint256 _gas, uint256 _min, uint256 _max, uint256 rate, uint256 decimals) external onlyRole(ROLE_STAFF) {
        if (_supportedToken != ETHER_ADDRESS) {
            require(Address.isContract(_supportedToken), "ERR_YPOOL_TOKEN_NOT_CONTRACT");
        }
        require(_max > _min, "ERR_INVALID_MAX_MIN");
        require(_min >= _gas, "ERR_INVALID_MIN_GAS");
        bytes32 universalTokenId = keccak256(abi.encodePacked(_toChainId, _supportedToken));
        FeeStructure memory feeStructure = FeeStructure(true, _gas, _min, _max, rate, decimals);
        feeStructures[universalTokenId] = feeStructure;
        emit FeeStructureSet(_toChainId, _supportedToken, _gas, _min, _max, rate, decimals);
    }

    /// @notice Set the SwapValidator
    /// @param _swapValidatorXYChain Address of the SwapValidator on XY chain
    function setSwapValidatorXYChain(address _swapValidatorXYChain) external onlyRole(ROLE_STAFF) {
        swapValidatorXYChain = _swapValidatorXYChain;
        emit SwapValidatorXYChainSet(_swapValidatorXYChain);
    }

    /* ========== RESTRICTED FUNCTIONS (YPOOL_WORKER) ========== */

    /// @notice Fulfill a swap request for a user by YPool worker
    /// Closing a swap MUST be performed on target chain and only by YPool worker
    /// @dev swapDesc is the swap info for swapping on DEX on target chain, not the info of the swap request user initiated on source chain
    /// @param swapDesc Description of the swap on DEX, see IAggregator.SwapDescription
    /// @param aggregatorData Raw data consists of instructions to swap user's token for YPool token
    /// @param fromChainId Source chain id of the swap request
    /// @param fromSwapId Swap id of the swap request
    function closeSwap(
        IAggregator.SwapDescription calldata swapDesc,
        bytes memory aggregatorData,
        uint32 fromChainId,
        uint256 fromSwapId
    ) external payable whenNotPaused onlyRole(ROLE_YPOOL_WORKER) approveAggregator(swapDesc.fromToken, swapDesc.amount) {
        require(YPoolSupoortedToken[address(swapDesc.fromToken)], "ERR_INVALID_YPOOL_TOKEN");

        bytes32 universalSwapId = keccak256(abi.encodePacked(fromChainId, fromSwapId));
        require(!everClosed[universalSwapId], "ERR_ALREADY_CLOSED");
        everClosed[universalSwapId] = true;

        uint256 fromTokenAmount = swapDesc.amount;
        require(fromTokenAmount <= maxYPoolTokenSwapAmount[address(swapDesc.fromToken)], "ERR_EXCEED_MAX_SWAP_AMOUNT");
        IYPoolVault(YPoolVaults[address(swapDesc.fromToken)]).transferToSwapper(swapDesc.fromToken, fromTokenAmount);

        uint256 toTokenAmountOut;
        CloseSwapResult swapResult;
        if (swapDesc.toToken == swapDesc.fromToken) {
            toTokenAmountOut = fromTokenAmount;
            swapResult = CloseSwapResult.NonSwapped;
        } else {
            uint256 value = (address(swapDesc.fromToken) == ETHER_ADDRESS) ? fromTokenAmount : 0;
            toTokenAmountOut = _getTokenBalance(swapDesc.toToken, swapDesc.receiver);
            try IAggregator(aggregator).swap{value: value}(swapDesc, aggregatorData) {
                toTokenAmountOut = _getTokenBalance(swapDesc.toToken, swapDesc.receiver) - toTokenAmountOut;
                swapResult = CloseSwapResult.Success;
            } catch {
                swapResult = CloseSwapResult.Failed;
            }
        }
        if (swapResult != CloseSwapResult.Success) {
            _safeTransferAsset(swapDesc.receiver, swapDesc.fromToken, fromTokenAmount);
        }
        emit CloseSwapCompleted(swapResult, fromChainId, fromSwapId);
        emit SwappedForUser(swapDesc.fromToken, fromTokenAmount, swapDesc.toToken, toTokenAmountOut, swapDesc.receiver);
    }

    /* ========== RESTRICTED FUNCTIONS (SIGNATURE REQUIRED) ========== */

    /// @notice Claim the asset of a swap request on source chain after YPool worker `closeSwap` on target chain, by providing signatures of validators
    /// Claiming MUST be performed on source chain
    /// @dev Signatures from validators are first sent to SwapValidator contract on Settlement chain to validate a swap request. Then the signatures can be reused here to approve the claim
    /// @param _swapId Swap id of the swap request
    /// @param signatures Signatures of validators
    function claim(uint256 _swapId, bytes[] memory signatures) external whenNotPaused {
        require(_swapId < swapId, "ERR_INVALID_SWAPID");
        require(swapRequests[_swapId].status != RequestStatus.Closed, "ERR_ALREADY_CLOSED");
        swapRequests[_swapId].status = RequestStatus.Closed;

        bytes32 sigId = keccak256(abi.encodePacked(supervisor.VALIDATE_SWAP_IDENTIFIER(), address(swapValidatorXYChain), chainId, _swapId));
        bytes32 sigIdHash = sigId.toEthSignedMessageHash();
        supervisor.checkSignatures(sigIdHash, signatures);

        SwapRequest memory request = swapRequests[_swapId];
        IYPoolVault yPoolVault = IYPoolVault(YPoolVaults[address(request.YPoolToken)]);
        uint256 value = (address(request.YPoolToken) == ETHER_ADDRESS) ? request.YPoolTokenAmount : 0;
        if (address(request.YPoolToken) != ETHER_ADDRESS) {
            request.YPoolToken.safeApprove(address(yPoolVault), request.YPoolTokenAmount);
        }
        yPoolVault.receiveAssetFromSwapper{value: value}(request.YPoolToken, request.YPoolTokenAmount, request.xyFee, request.gasFee);

        emit SwapCompleted(CompleteSwapType.Claimed, request);
    }

    /// @notice Claim the asset of multiple swap requests on source chain after YPool worker `closeSwap` on eacg target chain, by providing signatures of validators
    /// Claiming MUST be performed on source chain
    /// @dev YPool token of the swap request MUST be the same
    /// @dev Validators sign to the array of swap ids, which is different from signing for `claim`
    /// @param _swapIds Swap ids of the swap requests
    /// @param _YPoolToken Y Pool token
    /// @param signatures Signatures of validators
    function batchClaim(uint256[] calldata _swapIds, address _YPoolToken, bytes[] memory signatures) external whenNotPaused {
        require(YPoolSupoortedToken[_YPoolToken], "ERR_INVALID_YPOOL_TOKEN");
        bytes32 sigId = keccak256(abi.encodePacked(supervisor.BATCH_CLAIM_IDENTIFIER(), address(swapValidatorXYChain), chainId, _swapIds));
        bytes32 sigIdHash = sigId.toEthSignedMessageHash();
        supervisor.checkSignatures(sigIdHash, signatures);

        IERC20 YPoolToken = IERC20(_YPoolToken);
        uint256 totalClaimedAmount;
        uint256 totalXYFee;
        uint256 totalGasFee;
        for (uint256 i; i < _swapIds.length; i++) {
            uint256 _swapId = _swapIds[i];
            require(_swapId < swapId, "ERR_INVALID_SWAPID");
            SwapRequest memory request = swapRequests[_swapId];
            require(request.status != RequestStatus.Closed, "ERR_ALREADY_CLOSED");
            require(request.YPoolToken == YPoolToken, "ERR_WRONG_YPOOL_TOKEN");
            totalClaimedAmount += request.YPoolTokenAmount;
            totalXYFee += request.xyFee;
            totalGasFee += request.gasFee;
            swapRequests[_swapId].status = RequestStatus.Closed;
            emit SwapCompleted(CompleteSwapType.FreeClaimed, request);
        }

        IYPoolVault yPoolVault = IYPoolVault(YPoolVaults[_YPoolToken]);
        uint256 value = (_YPoolToken == ETHER_ADDRESS) ? totalClaimedAmount : 0;
        if (_YPoolToken != ETHER_ADDRESS) {
            YPoolToken.safeApprove(address(yPoolVault), totalClaimedAmount);
        }
        yPoolVault.receiveAssetFromSwapper{value: value}(YPoolToken, totalClaimedAmount, totalXYFee, totalGasFee);
    }

    /// @notice Lock an expired swap request by providing signatures of validators
    /// Locking a swap MUST be performed on target chain to prevent YPool worker from closing an expired swap request
    /// @dev Signature collector collects signature from different validators off-chain and call this function
    /// @param fromChainId Source chain id of the swap request
    /// @param fromSwapId Swap id of the swap request
    /// @param signatures Signatures of validators
    function lockCloseSwap(uint32 fromChainId, uint256 fromSwapId, bytes[] memory signatures) external whenNotPaused {
        bytes32 universalSwapId = keccak256(abi.encodePacked(fromChainId, fromSwapId));
        require(!everClosed[universalSwapId], "ERR_ALREADY_CLOSED");
        bytes32 sigId = keccak256(abi.encodePacked(supervisor.LOCK_CLOSE_SWAP_AND_REFUND_IDENTIFIER(), address(this), fromChainId, fromSwapId));
        bytes32 sigIdHash = sigId.toEthSignedMessageHash();
        supervisor.checkSignatures(sigIdHash, signatures);

        everClosed[universalSwapId] = true;
        emit CloseSwapCompleted(CloseSwapResult.Locked, fromChainId, fromSwapId);
    }

    /// @notice Refund user if a swap request is expired or invalidated by providing signatures of validators
    /// A portion of refund will be taken away as gas fee compensation to execute the refund
    /// Refund MUST be performed on source chain
    /// @param _swapId Swap id of the swap request
    /// @param gasFeeReceiver Address that receives gas fees
    /// @param signatures Signatures of validators
    function refund(uint256 _swapId, address gasFeeReceiver, bytes[] memory signatures) external whenNotPaused {
        require(_swapId < swapId, "ERR_INVALID_SWAPID");
        require(swapRequests[_swapId].status != RequestStatus.Closed, "ERR_ALREADY_CLOSED");
        swapRequests[_swapId].status = RequestStatus.Closed;

        bytes32 sigId = keccak256(abi.encodePacked(supervisor.LOCK_CLOSE_SWAP_AND_REFUND_IDENTIFIER(), address(this), chainId, _swapId, gasFeeReceiver));
        bytes32 sigIdHash = sigId.toEthSignedMessageHash();
        supervisor.checkSignatures(sigIdHash, signatures);

        SwapRequest memory request = swapRequests[_swapId];
        (, uint256 refundGasFee) = _calculateFee(chainId, request.YPoolToken, request.YPoolTokenAmount);
        _safeTransferAsset(request.sender, request.YPoolToken, request.YPoolTokenAmount - refundGasFee);
        _safeTransferAsset(gasFeeReceiver, request.YPoolToken, refundGasFee);

        emit SwapCompleted(CompleteSwapType.Refunded, request);
    }

    /* ========== WRITE FUNCTIONS ========== */

    /// @notice This functions is called by user to initiate a swap. User swaps his/her token for YPool token on this chain and provide info for the swap on target chain. A swap request will be created for each swap.
    /// @dev swapDesc is the swap info for swapping on DEX on this chain, not the swap request
    /// @param swapDesc Description of the swap on DEX, see IAggregator.SwapDescription
    /// @param aggregatorData Raw data consists of instructions to swap user's token for YPool token
    /// @param toChainDesc Description of the swap on target chain, see ToChainDescription
    function swap(
        IAggregator.SwapDescription memory swapDesc,
        bytes memory aggregatorData,
        ToChainDescription calldata toChainDesc
    ) external payable approveAggregator(swapDesc.fromToken, swapDesc.amount) whenNotPaused nonReentrant {
        address receiver = swapDesc.receiver;
        IERC20 fromToken = swapDesc.fromToken;
        IERC20 YPoolToken = swapDesc.toToken;
        require(YPoolSupoortedToken[address(YPoolToken)], "ERR_INVALID_YPOOL_TOKEN");

        uint256 fromTokenAmount = swapDesc.amount;
        uint256 yBalance;
        _safeTransferFromAsset(fromToken, msg.sender, fromTokenAmount);
        if (fromToken == YPoolToken) {
            yBalance = fromTokenAmount;
        } else {
            yBalance = _getTokenBalance(YPoolToken, address(this));
            swapDesc.receiver = address(this);
            IAggregator(aggregator).swap{value: msg.value}(swapDesc, aggregatorData);
            yBalance = _getTokenBalance(YPoolToken, address(this)) - yBalance;
        }
        require(_checkMinimumSwapAmount(toChainDesc.toChainId, YPoolToken, yBalance), "ERR_NOT_ENOUGH_SWAP_AMOUNT");
        require(yBalance <= maxYPoolTokenSwapAmount[address(YPoolToken)], "ERR_EXCEED_MAX_SWAP_AMOUNT");

        // Calculate XY fee and gas fee for closeSwap on toChain
        // NOTE: XY fee already includes gas fee and gas fee is computed here only for bookkeeping purpose
        (uint256 xyFee, uint256 closeSwapGasFee) = _calculateFee(toChainDesc.toChainId, YPoolToken, yBalance);
        SwapRequest memory request = SwapRequest(toChainDesc.toChainId, swapId, receiver, msg.sender, yBalance, xyFee, closeSwapGasFee, YPoolToken, RequestStatus.Open);
        swapRequests.push(request);
        emit SwapRequested(swapId++, toChainDesc, fromToken, YPoolToken, yBalance, receiver, xyFee, closeSwapGasFee);
    }

    /* ========== EVENTS ========== */

    // Owner events
    event FeeStructureSet(uint32 _toChainId, address _YPoolToken, uint256 _gas, uint256 _min, uint256 _max, uint256 _rate, uint256 _decimals);
    event YPoolVaultSet(address _supportedToken, address _vault, bool _isSet);
    event AggregatorSet(address _aggregator);
    event SwapValidatorXYChainSet(address _swapValidatorXYChain);
    // Swap events
    event SwapRequested(uint256 _swapId, ToChainDescription _toChainDesc, IERC20 _fromToken, IERC20 _YPoolToken, uint256 _YPoolTokenAmount, address _receiver, uint256 _xyFee, uint256 _gasFee);
    event SwapCompleted(CompleteSwapType _closeType, SwapRequest _swapRequest);
    event CloseSwapCompleted(CloseSwapResult _swapResult, uint32 _fromChainId, uint256 _fromSwapId);
    event SwappedForUser(IERC20 _fromToken, uint256 _fromTokenAmount, IERC20 _toToken, uint256 _toTokenAmountOut, address _receiver);
}

File 2 of 18 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 3 of 18 : ERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "IERC20.sol";
import "IERC20Metadata.sol";
import "Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless this function is
     * overridden;
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);

        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        unchecked {
            _approve(sender, _msgSender(), currentAllowance - amount);
        }

        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        uint256 currentAllowance = _allowances[_msgSender()][spender];
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(_msgSender(), spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `sender` to `recipient`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `sender` cannot be the zero address.
     * - `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     */
    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        uint256 senderBalance = _balances[sender];
        require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[sender] = senderBalance - amount;
        }
        _balances[recipient] += amount;

        emit Transfer(sender, recipient, amount);

        _afterTokenTransfer(sender, recipient, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}

File 4 of 18 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

File 5 of 18 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 6 of 18 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

File 7 of 18 : ECDSA.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS,
        InvalidSignatureV
    }

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        } else if (error == RecoverError.InvalidSignatureV) {
            revert("ECDSA: invalid signature 'v' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        // Check the signature length
        // - case 65: r,s,v signature (standard)
        // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else if (signature.length == 64) {
            bytes32 r;
            bytes32 vs;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            assembly {
                r := mload(add(signature, 0x20))
                vs := mload(add(signature, 0x40))
            }
            return tryRecover(hash, r, vs);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, signature);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address, RecoverError) {
        bytes32 s;
        uint8 v;
        assembly {
            s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
            v := add(shr(255, vs), 27)
        }
        return tryRecover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     *
     * _Available since v4.2._
     */
    function recover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, r, vs);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS);
        }
        if (v != 27 && v != 28) {
            return (address(0), RecoverError.InvalidSignatureV);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature);
        }

        return (signer, RecoverError.NoError);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
    }
}

File 8 of 18 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "IERC20.sol";
import "Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 9 of 18 : Pausable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        require(!paused(), "Pausable: paused");
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        require(paused(), "Pausable: not paused");
        _;
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}

File 10 of 18 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and make it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

File 11 of 18 : AccessControl.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "IAccessControl.sol";
import "Context.sol";
import "Strings.sol";
import "ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role, _msgSender());
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(uint160(account), 20),
                        " is missing role ",
                        Strings.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view override returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    function _grantRole(bytes32 role, address account) private {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    function _revokeRole(bytes32 role, address account) private {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}

File 12 of 18 : IAccessControl.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}

File 13 of 18 : Strings.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }
}

File 14 of 18 : ERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 15 of 18 : IERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 16 of 18 : Supervisor.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import "ECDSA.sol";

/// @title Supervisor is the guardian of YPool. It requires multiple validators to valid
/// the requests from users and workers and sign on them if valid.
contract Supervisor {
    using ECDSA for bytes32;

    /* ========== STATE VARIABLES ========== */

    bytes32 public constant CLAIM_IDENTIFIER = 'SWAPPER_CLAIM';
    bytes32 public constant SET_THRESHOLD_IDENTIFIER = 'SET_THRESHOLD';
    bytes32 public constant SET_VALIDATOR_IDENTIFIER = 'SET_VALIDATOR';
    bytes32 public constant LOCK_CLOSE_SWAP_AND_REFUND_IDENTIFIER = 'LOCK_CLOSE_SWAP_AND_REFUND';
    bytes32 public constant BATCH_CLAIM_IDENTIFIER = 'BATCH_CLAIM';
    bytes32 public constant VALIDATE_SWAP_IDENTIFIER = 'VALIDATE_SWAP_IDENTIFIER';

    // the chain ID contract located at
    uint32 public chainId;
    // check if the address is one of the validators
    mapping (address => bool) public validators;
    // number of validators
    uint256 private validatorsNum;
    // threshold to pass the signature validation
    uint256 public threshold;
    // current nonce for write functions
    uint256 public nonce;

    /// @dev Constuctor with chainId / validators / threshold
    /// @param _chainId The chain ID located with
    /// @param _validators Initial validator addresses
    /// @param _threshold Initial threshold to pass the request validation
    constructor(uint32 _chainId, address [] memory _validators, uint256 _threshold) {
        chainId = _chainId;

        for (uint256 i; i < _validators.length; i++) {
            validators[_validators[i]] = true;
        }
        validatorsNum = _validators.length;
        require(_threshold <= validatorsNum, "ERR_INVALID_THRESHOLD");
        threshold = _threshold;
    }

    /* ========== VIEW FUNCTIONS ========== */

    /// @notice Check if there are enough signed signatures to the signature hash
    /// @param sigIdHash The signature hash to be signed
    /// @param signatures Signed signatures by different validators
    function checkSignatures(bytes32 sigIdHash, bytes[] memory signatures) public view {
        require(signatures.length >= threshold, "ERR_NOT_ENOUGH_SIGNATURES");
        address prevAddress = address(0);
        for (uint i; i < threshold; i++) {
            address recovered = sigIdHash.recover(signatures[i]);
            require(validators[recovered], "ERR_NOT_VALIDATOR");
            require(recovered > prevAddress, "ERR_WRONG_SIGNER_ORDER");
            prevAddress = recovered;
        }
    }

    /* ========== WRITE FUNCTIONS ========== */

    /// @notice Change `threshold` by providing a correct nonce and enough signatures from validators
    /// @param _threshold New `threshold`
    /// @param _nonce The nonce to be processed
    /// @param signatures Signed signatures by validators
    function setThreshold(uint256 _threshold, uint256 _nonce, bytes[] memory signatures) external {
        require(signatures.length >= threshold, "ERR_NOT_ENOUGH_SIGNATURES");
        require(_nonce == nonce, "ERR_INVALID_NONCE");
        require(_threshold > 0, "ERR_INVALID_THRESHOLD");
        require(_threshold <= validatorsNum, "ERR_INVALID_THRESHOLD");

        bytes32 sigId = keccak256(abi.encodePacked(SET_THRESHOLD_IDENTIFIER, address(this), chainId, _threshold, _nonce));
        bytes32 sigIdHash = sigId.toEthSignedMessageHash();
        checkSignatures(sigIdHash, signatures);

        threshold = _threshold;
        nonce++;
    }

    /// @notice Set / remove the validator address to be part of signatures committee
    /// @param _validator The address to add or remove
    /// @param flag `true` to add, `false` to remove
    /// @param _nonce The nonce to be processed
    /// @param signatures Signed signatures by validators
    function setValidator(address _validator, bool flag, uint256 _nonce, bytes[] memory signatures) external {
        require(_validator != address(0), "ERR_INVALID_VALIDATOR");
        require(signatures.length >= threshold, "ERR_NOT_ENOUGH_SIGNATURES");
        require(_nonce == nonce, "ERR_INVALID_NONCE");
        require(flag != validators[_validator], "ERR_OPERATION_TO_VALIDATOR");

        bytes32 sigId = keccak256(abi.encodePacked(SET_VALIDATOR_IDENTIFIER, address(this), chainId, _validator, flag, _nonce));
        bytes32 sigIdHash = sigId.toEthSignedMessageHash();
        checkSignatures(sigIdHash, signatures);

        if (validators[_validator]) {
            validatorsNum--;
            validators[_validator] = false;
            if (validatorsNum < threshold) threshold--;
        } else {
            validatorsNum++;
            validators[_validator] = true;
        }
        nonce++;
    }
}

File 17 of 18 : IAggregator.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
pragma experimental ABIEncoderV2;

import { IERC20 } from "ERC20.sol";


interface IAggregator {
    struct SwapDescription {
        IERC20 fromToken;
        IERC20 toToken;
        address receiver;
        uint256 amount;
        uint256 minReturnAmount;
    }
    function swap(SwapDescription calldata desc, bytes calldata data) external payable returns (uint256 returnAmount);
}

File 18 of 18 : IYPoolVault.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import { IERC20 } from "ERC20.sol";

interface IYPoolVault {
    function transferToSwapper(IERC20 token, uint256 amount) external;
    function receiveAssetFromSwapper(IERC20 token, uint256 amount, uint256 xyFeeAmount, uint256 gasFeeAmount) external payable;
}

Settings
{
  "evmVersion": "istanbul",
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"manager","type":"address"},{"internalType":"address","name":"staff","type":"address"},{"internalType":"address","name":"worker","type":"address"},{"internalType":"address","name":"_supervisor","type":"address"},{"internalType":"uint32","name":"_chainId","type":"uint32"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_aggregator","type":"address"}],"name":"AggregatorSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum XSwapper.CloseSwapResult","name":"_swapResult","type":"uint8"},{"indexed":false,"internalType":"uint32","name":"_fromChainId","type":"uint32"},{"indexed":false,"internalType":"uint256","name":"_fromSwapId","type":"uint256"}],"name":"CloseSwapCompleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"_toChainId","type":"uint32"},{"indexed":false,"internalType":"address","name":"_YPoolToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"_gas","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_min","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_max","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_rate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_decimals","type":"uint256"}],"name":"FeeStructureSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum XSwapper.CompleteSwapType","name":"_closeType","type":"uint8"},{"components":[{"internalType":"uint32","name":"toChainId","type":"uint32"},{"internalType":"uint256","name":"swapId","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"YPoolTokenAmount","type":"uint256"},{"internalType":"uint256","name":"xyFee","type":"uint256"},{"internalType":"uint256","name":"gasFee","type":"uint256"},{"internalType":"contract IERC20","name":"YPoolToken","type":"address"},{"internalType":"enum XSwapper.RequestStatus","name":"status","type":"uint8"}],"indexed":false,"internalType":"struct XSwapper.SwapRequest","name":"_swapRequest","type":"tuple"}],"name":"SwapCompleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_swapId","type":"uint256"},{"components":[{"internalType":"uint32","name":"toChainId","type":"uint32"},{"internalType":"contract IERC20","name":"toChainToken","type":"address"},{"internalType":"uint256","name":"expectedToChainTokenAmount","type":"uint256"},{"internalType":"uint32","name":"slippage","type":"uint32"}],"indexed":false,"internalType":"struct XSwapper.ToChainDescription","name":"_toChainDesc","type":"tuple"},{"indexed":false,"internalType":"contract IERC20","name":"_fromToken","type":"address"},{"indexed":false,"internalType":"contract IERC20","name":"_YPoolToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"_YPoolTokenAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"_receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"_xyFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_gasFee","type":"uint256"}],"name":"SwapRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_swapValidatorXYChain","type":"address"}],"name":"SwapValidatorXYChainSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IERC20","name":"_fromToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"_fromTokenAmount","type":"uint256"},{"indexed":false,"internalType":"contract IERC20","name":"_toToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"_toTokenAmountOut","type":"uint256"},{"indexed":false,"internalType":"address","name":"_receiver","type":"address"}],"name":"SwappedForUser","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_supportedToken","type":"address"},{"indexed":false,"internalType":"address","name":"_vault","type":"address"},{"indexed":false,"internalType":"bool","name":"_isSet","type":"bool"}],"name":"YPoolVaultSet","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ETHER_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ROLE_MANAGER","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ROLE_OWNER","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ROLE_STAFF","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ROLE_YPOOL_WORKER","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"YPoolSupoortedToken","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"YPoolVaults","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"aggregator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_swapIds","type":"uint256[]"},{"internalType":"address","name":"_YPoolToken","type":"address"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"}],"name":"batchClaim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"chainId","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_swapId","type":"uint256"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20","name":"fromToken","type":"address"},{"internalType":"contract IERC20","name":"toToken","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturnAmount","type":"uint256"}],"internalType":"struct IAggregator.SwapDescription","name":"swapDesc","type":"tuple"},{"internalType":"bytes","name":"aggregatorData","type":"bytes"},{"internalType":"uint32","name":"fromChainId","type":"uint32"},{"internalType":"uint256","name":"fromSwapId","type":"uint256"}],"name":"closeSwap","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"feeStructures","outputs":[{"internalType":"bool","name":"isSet","type":"bool"},{"internalType":"uint256","name":"gas","type":"uint256"},{"internalType":"uint256","name":"min","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"},{"internalType":"uint256","name":"rate","type":"uint256"},{"internalType":"uint256","name":"decimals","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_chainId","type":"uint32"},{"internalType":"uint256","name":"_swapId","type":"uint256"}],"name":"getEverClosed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_chainId","type":"uint32"},{"internalType":"address","name":"_token","type":"address"}],"name":"getFeeStructure","outputs":[{"components":[{"internalType":"bool","name":"isSet","type":"bool"},{"internalType":"uint256","name":"gas","type":"uint256"},{"internalType":"uint256","name":"min","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"},{"internalType":"uint256","name":"rate","type":"uint256"},{"internalType":"uint256","name":"decimals","type":"uint256"}],"internalType":"struct XSwapper.FeeStructure","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_swapId","type":"uint256"}],"name":"getSwapRequest","outputs":[{"components":[{"internalType":"uint32","name":"toChainId","type":"uint32"},{"internalType":"uint256","name":"swapId","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"YPoolTokenAmount","type":"uint256"},{"internalType":"uint256","name":"xyFee","type":"uint256"},{"internalType":"uint256","name":"gasFee","type":"uint256"},{"internalType":"contract IERC20","name":"YPoolToken","type":"address"},{"internalType":"enum XSwapper.RequestStatus","name":"status","type":"uint8"}],"internalType":"struct XSwapper.SwapRequest","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"fromChainId","type":"uint32"},{"internalType":"uint256","name":"fromSwapId","type":"uint256"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"}],"name":"lockCloseSwap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxYPoolTokenSwapAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_swapId","type":"uint256"},{"internalType":"address","name":"gasFeeReceiver","type":"address"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"}],"name":"refund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_aggregator","type":"address"}],"name":"setAggregator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_toChainId","type":"uint32"},{"internalType":"address","name":"_supportedToken","type":"address"},{"internalType":"uint256","name":"_gas","type":"uint256"},{"internalType":"uint256","name":"_min","type":"uint256"},{"internalType":"uint256","name":"_max","type":"uint256"},{"internalType":"uint256","name":"rate","type":"uint256"},{"internalType":"uint256","name":"decimals","type":"uint256"}],"name":"setFeeStructure","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_supportedToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"setMaxYPoolTokenSwapAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_swapValidatorXYChain","type":"address"}],"name":"setSwapValidatorXYChain","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_supportedToken","type":"address"},{"internalType":"address","name":"_vault","type":"address"},{"internalType":"bool","name":"_isSet","type":"bool"}],"name":"setYPoolVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"supervisor","outputs":[{"internalType":"contract Supervisor","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20","name":"fromToken","type":"address"},{"internalType":"contract IERC20","name":"toToken","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturnAmount","type":"uint256"}],"internalType":"struct IAggregator.SwapDescription","name":"swapDesc","type":"tuple"},{"internalType":"bytes","name":"aggregatorData","type":"bytes"},{"components":[{"internalType":"uint32","name":"toChainId","type":"uint32"},{"internalType":"contract IERC20","name":"toChainToken","type":"address"},{"internalType":"uint256","name":"expectedToChainTokenAmount","type":"uint256"},{"internalType":"uint32","name":"slippage","type":"uint32"}],"internalType":"struct XSwapper.ToChainDescription","name":"toChainDesc","type":"tuple"}],"name":"swap","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"swapId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"swapRequests","outputs":[{"internalType":"uint32","name":"toChainId","type":"uint32"},{"internalType":"uint256","name":"swapId","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"YPoolTokenAmount","type":"uint256"},{"internalType":"uint256","name":"xyFee","type":"uint256"},{"internalType":"uint256","name":"gasFee","type":"uint256"},{"internalType":"contract IERC20","name":"YPoolToken","type":"address"},{"internalType":"enum XSwapper.RequestStatus","name":"status","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapValidatorXYChain","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60a060405260006005553480156200001657600080fd5b5060405162004d4138038062004d41833981016040819052620000399162000358565b6001805460ff191681556002556200005d826200023b602090811b62002dbf17901c565b620000af5760405162461bcd60e51b815260206004820152601b60248201527f4552525f53555045525649534f525f4e4f545f434f4e5452414354000000000060448201526064015b60405180910390fd5b600480546001600160a01b0319166001600160a01b03841617905560e081901b6001600160e01b0319166080524663ffffffff82168114620001295760405162461bcd60e51b815260206004820152601260248201527111549497d5d493d391d7d0d210525397d25160721b6044820152606401620000a6565b6200014460008051602062004d218339815191528062000245565b6200016e60008051602062004cc183398151915260008051602062004d2183398151915262000245565b6200019860008051602062004ce183398151915260008051602062004d2183398151915262000245565b620001c260008051602062004d0183398151915260008051602062004d2183398151915262000245565b620001dd60008051602062004d218339815191528862000290565b620001f860008051602062004cc18339815191528762000290565b6200021360008051602062004ce18339815191528662000290565b6200022e60008051602062004d018339815191528562000290565b50505050505050620003e3565b803b15155b919050565b600082815260208190526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b6200029c8282620002a0565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff166200029c576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620002fc3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b03811681146200024057600080fd5b60008060008060008060c0878903121562000371578182fd5b6200037c8762000340565b95506200038c6020880162000340565b94506200039c6040880162000340565b9350620003ac6060880162000340565b9250620003bc6080880162000340565b915060a087015163ffffffff81168114620003d5578182fd5b809150509295509295509295565b60805160e01c61489c620004256000396000818161059f01528181610a6201528181611ff5015281816129fd01528181612bc1015261331e015261489c6000f3fe6080604052600436106102335760003560e01c80638ad682af1161012e578063d547741f116100ab578063f281de9e1161006f578063f281de9e146107e9578063f54738ef14610809578063f5b944eb1461081f578063f9120af614610841578063fde3f7dc146108615761023a565b8063d547741f146106e5578063d8331e7114610705578063e251975e14610725578063e53e016e14610745578063f13de4b31461077b5761023a565b80639c61d7a4116100f25780639c61d7a4146105d6578063a217fddf1461060b578063acb3553214610620578063b89bbce7146106a3578063cf1d21c0146106c35761023a565b80638ad682af146104f95780638fc3ab8b1461052d57806391d148541461054d5780639968230b1461056d5780639a8a05921461058d5761023a565b80633f4ba83a116101bc57806356e4b68b1161018057806356e4b68b146104585780635c975abb1461047857806364024b42146104905780636aa4d6b5146104c45780638456cb59146104e45761023a565b80633f4ba83a146103d05780633fc8ef10146103e55780634a23656d146103f8578063500f528c146104255780635136d5a2146104385761023a565b8063245a7bfc11610203578063245a7bfc146102f8578063248a9ca3146103305780632680a138146103605780632f2ff15d1461039057806336568abe146103b05761023a565b8062501e281461023f57806301ffc9a714610261578063225661221461029657806322bf2e24146102b65761023a565b3661023a57005b600080fd5b34801561024b57600080fd5b5061025f61025a366004613eaa565b61088e565b005b34801561026d57600080fd5b5061028161027c366004613d0a565b610d6a565b60405190151581526020015b60405180910390f35b3480156102a257600080fd5b5061025f6102b1366004613bbf565b610da3565b3480156102c257600080fd5b506102ea7f358933fb1b4f9e62c7cd3651025ad8825acb20ebbb23b09160e3867d71501ddd81565b60405190815260200161028d565b34801561030457600080fd5b50600954610318906001600160a01b031681565b6040516001600160a01b03909116815260200161028d565b34801561033c57600080fd5b506102ea61034b366004613cab565b60009081526020819052604090206001015490565b34801561036c57600080fd5b5061028161037b366004613b59565b60076020526000908152604090205460ff1681565b34801561039c57600080fd5b5061025f6103ab366004613cdb565b610e12565b3480156103bc57600080fd5b5061025f6103cb366004613cdb565b610e3d565b3480156103dc57600080fd5b5061025f610ebb565b61025f6103f3366004613d9e565b610edf565b34801561040457600080fd5b50610418610413366004613cab565b6114ad565b60405161028d9190614497565b61025f610433366004613d32565b611605565b34801561044457600080fd5b5061025f610453366004613b75565b611b6a565b34801561046457600080fd5b50600454610318906001600160a01b031681565b34801561048457600080fd5b5060015460ff16610281565b34801561049c57600080fd5b506102ea7f43ccaf94e5a0ff213b32419bf56f27f93e4170af0c4867ff3412f6aa5a22daf081565b3480156104d057600080fd5b5061025f6104df366004613fae565b611cd9565b3480156104f057600080fd5b5061025f611eda565b34801561050557600080fd5b506102ea7f9f4e1c871d5fdd0aee1cd182666698a4492b24c6832aac230d07b11046af5a8981565b34801561053957600080fd5b5061025f610548366004613bea565b611efb565b34801561055957600080fd5b50610281610568366004613cdb565b612481565b34801561057957600080fd5b5061025f610588366004613b59565b6124ac565b34801561059957600080fd5b506105c17f000000000000000000000000000000000000000000000000000000000000000081565b60405163ffffffff909116815260200161028d565b3480156105e257600080fd5b506105f66105f1366004613cab565b61252d565b60405161028d99989796959493929190614550565b34801561061757600080fd5b506102ea600081565b34801561062c57600080fd5b5061067461063b366004613cab565b600b6020526000908152604090208054600182015460028301546003840154600485015460059095015460ff9094169492939192909186565b6040805196151587526020870195909552938501929092526060840152608083015260a082015260c00161028d565b3480156106af57600080fd5b5061025f6106be366004613f34565b6125a5565b3480156106cf57600080fd5b5061031860008051602061484783398151915281565b3480156106f157600080fd5b5061025f610700366004613cdb565b6127f4565b34801561071157600080fd5b50600a54610318906001600160a01b031681565b34801561073157600080fd5b5061025f610740366004613e53565b61281a565b34801561075157600080fd5b50610318610760366004613b59565b6008602052600090815260409020546001600160a01b031681565b34801561078757600080fd5b5061079b610796366004613f09565b612c55565b60405161028d9190600060c0820190508251151582526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015292915050565b3480156107f557600080fd5b50610281610804366004613f93565b612cc4565b34801561081557600080fd5b506102ea60055481565b34801561082b57600080fd5b506102ea60008051602061482783398151915281565b34801561084d57600080fd5b5061025f61085c366004613b59565b612d0a565b34801561086d57600080fd5b506102ea61087c366004613b59565b60036020526000908152604090205481565b60015460ff16156108ba5760405162461bcd60e51b81526004016108b19061431f565b60405180910390fd5b60055482106108db5760405162461bcd60e51b81526004016108b1906143a9565b6001600c83815481106108fe57634e487b7160e01b600052603260045260246000fd5b906000526020600020906008020160070160149054906101000a900460ff16600181111561093c57634e487b7160e01b600052602160045260246000fd5b141561095a5760405162461bcd60e51b81526004016108b1906142f3565b6001600c838154811061097d57634e487b7160e01b600052603260045260246000fd5b60009182526020909120600760089092020101805460ff60a01b1916600160a01b8360018111156109be57634e487b7160e01b600052602160045260246000fd5b02179055506000600460009054906101000a90046001600160a01b03166001600160a01b031663faf55b5c6040518163ffffffff1660e01b815260040160206040518083038186803b158015610a1357600080fd5b505afa158015610a27573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a4b9190613cc3565b600a54604051610a8c92916001600160a01b0316907f0000000000000000000000000000000000000000000000000000000000000000908790602001614118565b6040516020818303038152906040528051906020012090506000610aaf82612dc5565b600480546040516305a0f88360e41b81529293506001600160a01b031691635a0f883091610ae1918591889101614225565b60006040518083038186803b158015610af957600080fd5b505afa158015610b0d573d6000803e3d6000fd5b505050506000600c8581548110610b3457634e487b7160e01b600052603260045260246000fd5b600091825260209182902060408051610120810182526008909302909101805463ffffffff1683526001808201549484019490945260028101546001600160a01b039081169284019290925260038101548216606084015260048101546080840152600581015460a0840152600681015460c0840152600781015491821660e0840152919261010084019160ff600160a01b9091041690811115610be857634e487b7160e01b600052602160045260246000fd5b6001811115610c0757634e487b7160e01b600052602160045260246000fd5b90525060e0810180516001600160a01b039081166000908152600860205260408120549251939450918116921660008051602061484783398151915214610c4f576000610c55565b82608001515b60e08401519091506001600160a01b031660008051602061484783398151915214610ca057610ca08284608001518560e001516001600160a01b0316612e189092919063ffffffff16565b60e0830151608084015160a085015160c086015160405163496d674b60e11b81526001600160a01b039485166004820152602481019390935260448301919091526064820152908316906392dace969083906084016000604051808303818588803b158015610d0e57600080fd5b505af1158015610d22573d6000803e3d6000fd5b50505050507f7cf616e580913e39d7ffeeb739823ba0799bc2948b9b6043f5127cad95b655c8600084604051610d599291906142bb565b60405180910390a150505050505050565b60006001600160e01b03198216637965db0b60e01b1480610d9b57506301ffc9a760e01b6001600160e01b03198316145b90505b919050565b600080516020614827833981519152610dbd81335b612f6f565b6001600160a01b03831660009081526007602052604090205460ff16610df55760405162461bcd60e51b81526004016108b190614372565b506001600160a01b03909116600090815260036020526040902055565b600082815260208190526040902060010154610e2e8133610db8565b610e388383612fd3565b505050565b6001600160a01b0381163314610ead5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084016108b1565b610eb78282613057565b5050565b600080516020614827833981519152610ed48133610db8565b610edc6130bc565b50565b825160608401516001600160a01b03821660008051602061484783398151915214610f1e57600954610f1e906001600160a01b03848116911683612e18565b60015460ff1615610f415760405162461bcd60e51b81526004016108b19061431f565b600280541415610f935760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016108b1565b6002805560408086015186516020808901516001600160a01b03811660009081526007909252939020549192909160ff16610fe05760405162461bcd60e51b81526004016108b190614372565b60608801516000610ff284338461314f565b826001600160a01b0316846001600160a01b031614156110135750806110c6565b61101d8330613238565b306040808d01919091526009549051638218b58f60e01b81529192506001600160a01b031690638218b58f90349061105b908e908e90600401614447565b6020604051808303818588803b15801561107457600080fd5b505af1158015611088573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906110ad9190613cc3565b50806110b98430613238565b6110c3919061474c565b90505b6110dd6110d660208a018a613eef565b84836132e6565b6111295760405162461bcd60e51b815260206004820152601a60248201527f4552525f4e4f545f454e4f5547485f535741505f414d4f554e5400000000000060448201526064016108b1565b6001600160a01b0383166000908152600360205260409020548111156111915760405162461bcd60e51b815260206004820152601a60248201527f4552525f4558434545445f4d41585f535741505f414d4f554e5400000000000060448201526064016108b1565b6000806111ab6111a460208c018c613eef565b8685613381565b6040805161012081019091529193509150600090806111cd60208e018e613eef565b63ffffffff16815260055460208201526001600160a01b03808b1660408301523360608301526080820187905260a0820186905260c08201859052881660e08201526101000160009052600c805460018181018355600092909252825160089091027fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c78101805463ffffffff90931663ffffffff1990931692909217825560208401517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c882015560408401517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c9820180546001600160a01b039283166001600160a01b03199182161790915560608601517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8ca8401805491841691831691909117905560808601517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8cb84015560a08601517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8cc84015560c08601517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8cd84015560e08601517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8ce9093018054939092169216919091178082556101008501519495508594929360ff60a01b1990911690600160a01b9084908111156113fe57634e487b7160e01b600052602160045260246000fd5b021790555050600580547f988e36bbb7fb7444e889f1367ca3ee06e9d8bec0d99f1ffec20c2697987a4a459250906000611437836147a6565b919050558c8989888d89896040516114569897969594939291906144a6565b60405180910390a150506001600255505050506001600160a01b0384166000805160206148478339815191521491506114a69050576009546114a6906001600160a01b0384811691166000612e18565b5050505050565b6114fa6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081018290529061010082015290565b600554821061150857600080fd5b600c828154811061152957634e487b7160e01b600052603260045260246000fd5b600091825260209182902060408051610120810182526008909302909101805463ffffffff1683526001808201549484019490945260028101546001600160a01b039081169284019290925260038101548216606084015260048101546080840152600581015460a0840152600681015460c0840152600781015491821660e0840152919261010084019160ff600160a01b90910416908111156115dd57634e487b7160e01b600052602160045260246000fd5b60018111156115fc57634e487b7160e01b600052602160045260246000fd5b90525092915050565b60015460ff16156116285760405162461bcd60e51b81526004016108b19061431f565b7f43ccaf94e5a0ff213b32419bf56f27f93e4170af0c4867ff3412f6aa5a22daf06116538133610db8565b6116606020860186613b59565b60608601356001600160a01b0382166000805160206148478339815191521461169d5760095461169d906001600160a01b03848116911683612e18565b600760006116ae60208a018a613b59565b6001600160a01b0316815260208101919091526040016000205460ff166116e75760405162461bcd60e51b81526004016108b190614372565b600085856040516020016116fc929190614208565b60408051601f1981840301815291815281516020928301206000818152600690935291205490915060ff16156117445760405162461bcd60e51b81526004016108b1906142f3565b60008181526006602090815260408220805460ff1916600117905560608a013591600391611774908c018c613b59565b6001600160a01b03166001600160a01b03168152602001908152602001600020548111156117e45760405162461bcd60e51b815260206004820152601a60248201527f4552525f4558434545445f4d41585f535741505f414d4f554e5400000000000060448201526064016108b1565b600860006117f560208c018c613b59565b6001600160a01b039081168252602080830193909352604090910160002054169063c2fc211090611828908c018c613b59565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401600060405180830381600087803b15801561187057600080fd5b505af1158015611884573d6000803e3d6000fd5b506000925082915061189b905060208c018c613b59565b6001600160a01b03166118b460408d0160208e01613b59565b6001600160a01b031614156118ce57508190506000611a0b565b60006000805160206148478339815191526118ec60208e018e613b59565b6001600160a01b031614611901576000611903565b835b905061193061191860408e0160208f01613b59565b8d604001602081019061192b9190613b59565b613238565b9250600960009054906101000a90046001600160a01b03166001600160a01b0316638218b58f828e8e6040518463ffffffff1660e01b81526004016119769291906143d5565b6020604051808303818588803b15801561198f57600080fd5b505af1935050505080156119c0575060408051601f3d908101601f191682019092526119bd91810190613cc3565b60015b6119cd5760029150611a09565b50826119f88d60200160208101906119e59190613b59565b8e604001602081019061192b9190613b59565b611a02919061474c565b9250600191505b505b6001816003811115611a2d57634e487b7160e01b600052602160045260246000fd5b14611a5857611a58611a4560608d0160408e01613b59565b611a5260208e018e613b59565b85613409565b7fee823aedb9f54993693aeaca62918fd9eeaf9d0416276706739088c10ceaf2b8818a8a604051611a8b9392919061428d565b60405180910390a17f4a1c72e2e3d1f37b0b083de3b7f8b54bebc3dd82fba56aa4e5f68b970b26ea67611ac160208d018d613b59565b848d6020016020810190611ad59190613b59565b858f6040016020810190611ae99190613b59565b604080516001600160a01b0396871681526020810195909552928516928401929092526060830152909116608082015260a00160405180910390a1505050506001600160a01b03821660008051602061484783398151915214611b6157600954611b61906001600160a01b0384811691166000612e18565b50505050505050565b7f9f4e1c871d5fdd0aee1cd182666698a4492b24c6832aac230d07b11046af5a89611b958133610db8565b6001600160a01b03841660008051602061484783398151915214611c0157833b611c015760405162461bcd60e51b815260206004820152601c60248201527f4552525f59504f4f4c5f544f4b454e5f4e4f545f434f4e54524143540000000060448201526064016108b1565b823b611c4f5760405162461bcd60e51b815260206004820152601c60248201527f4552525f59504f4f4c5f5641554c545f4e4f545f434f4e54524143540000000060448201526064016108b1565b6001600160a01b038481166000818152600760209081526040808320805460ff1916881515908117909155600883529281902080546001600160a01b03191695891695861790558051938452908301939093528183015290517ff1e53a62d5935afca4762c943ac543a520fbf358eafaac6024bcb3f053f32071916060908290030190a150505050565b60015460ff1615611cfc5760405162461bcd60e51b81526004016108b19061431f565b60008383604051602001611d11929190614208565b60408051601f1981840301815291815281516020928301206000818152600690935291205490915060ff1615611d595760405162461bcd60e51b81526004016108b1906142f3565b6000600460009054906101000a90046001600160a01b03166001600160a01b03166374892a726040518163ffffffff1660e01b815260040160206040518083038186803b158015611da957600080fd5b505afa158015611dbd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611de19190613cc3565b308686604051602001611df79493929190614118565b6040516020818303038152906040528051906020012090506000611e1a82612dc5565b600480546040516305a0f88360e41b81529293506001600160a01b031691635a0f883091611e4c918591899101614225565b60006040518083038186803b158015611e6457600080fd5b505afa158015611e78573d6000803e3d6000fd5b50505060008481526006602052604090819020805460ff19166001179055517fee823aedb9f54993693aeaca62918fd9eeaf9d0416276706739088c10ceaf2b89150611eca906003908990899061428d565b60405180910390a1505050505050565b600080516020614827833981519152611ef38133610db8565b610edc613478565b60015460ff1615611f1e5760405162461bcd60e51b81526004016108b19061431f565b6001600160a01b03821660009081526007602052604090205460ff16611f565760405162461bcd60e51b81526004016108b190614372565b6000600460009054906101000a90046001600160a01b03166001600160a01b031663f7ca80236040518163ffffffff1660e01b815260040160206040518083038186803b158015611fa657600080fd5b505afa158015611fba573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fde9190613cc3565b600a5460405161202192916001600160a01b0316907f000000000000000000000000000000000000000000000000000000000000000090899089906020016140ba565b604051602081830303815290604052805190602001209050600061204482612dc5565b600480546040516305a0f88360e41b81529293506001600160a01b031691635a0f883091612076918591889101614225565b60006040518083038186803b15801561208e57600080fd5b505afa1580156120a2573d6000803e3d6000fd5b5050505060008490506000806000805b898110156123905760008b8b838181106120dc57634e487b7160e01b600052603260045260246000fd5b90506020020135905060055481106121065760405162461bcd60e51b81526004016108b1906143a9565b6000600c828154811061212957634e487b7160e01b600052603260045260246000fd5b600091825260209182902060408051610120810182526008909302909101805463ffffffff1683526001808201549484019490945260028101546001600160a01b039081169284019290925260038101548216606084015260048101546080840152600581015460a0840152600681015460c0840152600781015491821660e0840152919261010084019160ff600160a01b90910416908111156121dd57634e487b7160e01b600052602160045260246000fd5b60018111156121fc57634e487b7160e01b600052602160045260246000fd5b90525090506001816101000151600181111561222857634e487b7160e01b600052602160045260246000fd5b14156122465760405162461bcd60e51b81526004016108b1906142f3565b866001600160a01b03168160e001516001600160a01b0316146122a35760405162461bcd60e51b815260206004820152601560248201527422a9292faba927a723afaca827a7a62faa27a5a2a760591b60448201526064016108b1565b60808101516122b290876145e6565b95508060a00151856122c491906145e6565b94508060c00151846122d691906145e6565b93506001600c83815481106122fb57634e487b7160e01b600052603260045260246000fd5b60009182526020909120600760089092020101805460ff60a01b1916600160a01b83600181111561233c57634e487b7160e01b600052602160045260246000fd5b02179055507f7cf616e580913e39d7ffeeb739823ba0799bc2948b9b6043f5127cad95b655c86001826040516123739291906142bb565b60405180910390a150508080612388906147a6565b9150506120b2565b506001600160a01b038089166000818152600860205260408120549092169190600080516020614847833981519152146123cb5760006123cd565b845b90506001600160a01b038a1660008051602061484783398151915214612401576124016001600160a01b0387168387612e18565b60405163496d674b60e11b81526001600160a01b0387811660048301526024820187905260448201869052606482018590528316906392dace969083906084016000604051808303818588803b15801561245a57600080fd5b505af115801561246e573d6000803e3d6000fd5b5050505050505050505050505050505050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff165b92915050565b7f358933fb1b4f9e62c7cd3651025ad8825acb20ebbb23b09160e3867d71501ddd6124d78133610db8565b600a80546001600160a01b0319166001600160a01b0384169081179091556040519081527f3623260a18beeff6af38bff0981baf3571a6f16d5b4c8942e8d26c0a166669db906020015b60405180910390a15050565b600c818154811061253d57600080fd5b60009182526020909120600890910201805460018201546002830154600384015460048501546005860154600687015460079097015463ffffffff909616975093956001600160a01b039384169592841694919391929091811690600160a01b900460ff1689565b7f358933fb1b4f9e62c7cd3651025ad8825acb20ebbb23b09160e3867d71501ddd6125d08133610db8565b6001600160a01b0387166000805160206148478339815191521461263c57863b61263c5760405162461bcd60e51b815260206004820152601c60248201527f4552525f59504f4f4c5f544f4b454e5f4e4f545f434f4e54524143540000000060448201526064016108b1565b8484116126815760405162461bcd60e51b815260206004820152601360248201527222a9292fa4a72b20a624a22fa6a0ac2fa6a4a760691b60448201526064016108b1565b858510156126c75760405162461bcd60e51b81526020600482015260136024820152724552525f494e56414c49445f4d494e5f47415360681b60448201526064016108b1565b600088886040516020016126dc9291906141de565b60408051601f19818403018152828252805160209182012060c08401835260018085528483018c81528585018c8152606087018c8152608088018c815260a089018c81526000878152600b909852968890208951815490151560ff199091161781559351948401949094559051600283015551600382015590516004820155915160059092019190915590519092507fcb4bb3001f7b245a106522f836b6aed77ba72ad177e278f9bb0b46d81d98356c906127e0908c908c908c908c908c908c908c9063ffffffff9790971687526001600160a01b0395909516602087015260408601939093526060850191909152608084015260a083015260c082015260e00190565b60405180910390a150505050505050505050565b6000828152602081905260409020600101546128108133610db8565b610e388383613057565b60015460ff161561283d5760405162461bcd60e51b81526004016108b19061431f565b600554831061285e5760405162461bcd60e51b81526004016108b1906143a9565b6001600c848154811061288157634e487b7160e01b600052603260045260246000fd5b906000526020600020906008020160070160149054906101000a900460ff1660018111156128bf57634e487b7160e01b600052602160045260246000fd5b14156128dd5760405162461bcd60e51b81526004016108b1906142f3565b6001600c848154811061290057634e487b7160e01b600052603260045260246000fd5b60009182526020909120600760089092020101805460ff60a01b1916600160a01b83600181111561294157634e487b7160e01b600052602160045260246000fd5b02179055506000600460009054906101000a90046001600160a01b03166001600160a01b03166374892a726040518163ffffffff1660e01b815260040160206040518083038186803b15801561299657600080fd5b505afa1580156129aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129ce9190613cc3565b6040805160208101929092526001600160601b031930606090811b8216928401929092526001600160e01b03197f000000000000000000000000000000000000000000000000000000000000000060e01b166054840152605883018790529085901b166078820152608c016040516020818303038152906040528051906020012090506000612a5c82612dc5565b600480546040516305a0f88360e41b81529293506001600160a01b031691635a0f883091612a8e918591889101614225565b60006040518083038186803b158015612aa657600080fd5b505afa158015612aba573d6000803e3d6000fd5b505050506000600c8681548110612ae157634e487b7160e01b600052603260045260246000fd5b600091825260209182902060408051610120810182526008909302909101805463ffffffff1683526001808201549484019490945260028101546001600160a01b039081169284019290925260038101548216606084015260048101546080840152600581015460a0840152600681015460c0840152600781015491821660e0840152919261010084019160ff600160a01b9091041690811115612b9557634e487b7160e01b600052602160045260246000fd5b6001811115612bb457634e487b7160e01b600052602160045260246000fd5b8152505090506000612bef7f00000000000000000000000000000000000000000000000000000000000000008360e001518460800151613381565b915050612c1482606001518360e00151838560800151612c0f919061474c565b613409565b612c23868360e0015183613409565b7f7cf616e580913e39d7ffeeb739823ba0799bc2948b9b6043f5127cad95b655c8600283604051610d599291906142bb565b612c906040518060c0016040528060001515815260200160008152602001600081526020016000815260200160008152602001600081525090565b6000612c9c84846134ce565b8051909150612cbd5760405162461bcd60e51b81526004016108b190614349565b9392505050565b6000808383604051602001612cda929190614208565b60408051808303601f1901815291815281516020928301206000908152600690925290205460ff16949350505050565b600080516020614827833981519152612d238133610db8565b813b612d715760405162461bcd60e51b815260206004820152601b60248201527f4552525f41474752454741544f525f4e4f545f434f4e5452414354000000000060448201526064016108b1565b600980546001600160a01b0319166001600160a01b0384169081179091556040519081527f94b241e14651a9658c51a45c82167e4f25ac3d3e7f8a2beae9d10b1ba07a94a090602001612521565b3b151590565b6040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b801580612ea15750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e9060440160206040518083038186803b158015612e6757600080fd5b505afa158015612e7b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e9f9190613cc3565b155b612f0c5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b60648201526084016108b1565b6040516001600160a01b038316602482015260448101829052610e3890849063095ea7b360e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261358e565b612f798282612481565b610eb757612f91816001600160a01b03166014613660565b612f9c836020613660565b604051602001612fad929190614169565b60408051601f198184030181529082905262461bcd60e51b82526108b1916004016142e0565b612fdd8282612481565b610eb7576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556130133390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6130618282612481565b15610eb7576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff166131055760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016108b1565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6001600160a01b03831660008051602061484783398151915214156131b7578034146131b25760405162461bcd60e51b815260206004820152601260248201527111549497d253959053125117d05353d5539560721b60448201526064016108b1565b610e38565b60006131c38430613238565b90506131da6001600160a01b038516843085613842565b81816131e68630613238565b6131f0919061474c565b146132325760405162461bcd60e51b815260206004820152601260248201527111549497d253959053125117d05353d5539560721b60448201526064016108b1565b50505050565b60006001600160a01b038316600080516020614847833981519152146132d6576040516370a0823160e01b81526001600160a01b0383811660048301528416906370a082319060240160206040518083038186803b15801561329957600080fd5b505afa1580156132ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132d19190613cc3565b612cbd565b506001600160a01b031631919050565b6000806132f385856134ce565b80519091506133145760405162461bcd60e51b81526004016108b190614349565b60408101516133437f0000000000000000000000000000000000000000000000000000000000000000866134ce565b80519092506133645760405162461bcd60e51b81526004016108b190614349565b6040820151613373828261387a565b909410159695505050505050565b600080600061339086866134ce565b80519091506133b15760405162461bcd60e51b81526004016108b190614349565b60a08101516133c190600a614664565b60808201516133d0908661472d565b6133da91906145fe565b92506133f76133ed84836040015161387a565b8260600151613891565b92508060200151915050935093915050565b6001600160a01b0382166000805160206148478339815191521415613464576040516001600160a01b0384169082156108fc029083906000818181858888f1935050505015801561345e573d6000803e3d6000fd5b50610e38565b610e386001600160a01b03831684836138a0565b60015460ff161561349b5760405162461bcd60e51b81526004016108b19061431f565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833613132565b6135096040518060c0016040528060001515815260200160008152602001600081526020016000815260200160008152602001600081525090565b6000838360405160200161351e9291906141de565b60408051808303601f1901815282825280516020918201206000908152600b825282902060c084018352805460ff161515845260018101549184019190915260028101549183019190915260038101546060830152600481015460808301526005015460a0820152949350505050565b60006135e3826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166138d09092919063ffffffff16565b805190915015610e3857808060200190518101906136019190613c8f565b610e385760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016108b1565b6060600061366f83600261472d565b61367a9060026145e6565b67ffffffffffffffff8111156136a057634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f1916602001820160405280156136ca576020820181803683370190505b509050600360fc1b816000815181106136f357634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350600f60fb1b8160018151811061373057634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350600061375484600261472d565b61375f9060016145e6565b90505b60018111156137f3576f181899199a1a9b1b9c1cb0b131b232b360811b85600f16601081106137a157634e487b7160e01b600052603260045260246000fd5b1a60f81b8282815181106137c557634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a90535060049490941c936137ec8161478f565b9050613762565b508315612cbd5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016108b1565b6040516001600160a01b03808516602483015283166044820152606481018290526132329085906323b872dd60e01b90608401612f38565b60008183101561388a5781612cbd565b5090919050565b600081831061388a5781612cbd565b6040516001600160a01b038316602482015260448101829052610e3890849063a9059cbb60e01b90606401612f38565b60606138df84846000856138e7565b949350505050565b6060824710156139485760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016108b1565b843b6139965760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016108b1565b600080866001600160a01b031685876040516139b2919061414d565b60006040518083038185875af1925050503d80600081146139ef576040519150601f19603f3d011682016040523d82523d6000602084013e6139f4565b606091505b5091509150613a04828286613a0f565b979650505050505050565b60608315613a1e575081612cbd565b825115613a2e5782518084602001fd5b8160405162461bcd60e51b81526004016108b191906142e0565b600082601f830112613a58578081fd5b8135602067ffffffffffffffff821115613a7457613a746147ed565b613a8181828402016145b5565b82815281810190858301855b85811015613ab657613aa4898684358b0101613ac3565b84529284019290840190600101613a8d565b5090979650505050505050565b600082601f830112613ad3578081fd5b813567ffffffffffffffff811115613aed57613aed6147ed565b613b00601f8201601f19166020016145b5565b818152846020838601011115613b14578283fd5b816020850160208301379081016020019190915292915050565b600060808284031215613b3f578081fd5b50919050565b803563ffffffff81168114610d9e57600080fd5b600060208284031215613b6a578081fd5b8135612cbd81614803565b600080600060608486031215613b89578182fd5b8335613b9481614803565b92506020840135613ba481614803565b91506040840135613bb481614818565b809150509250925092565b60008060408385031215613bd1578182fd5b8235613bdc81614803565b946020939093013593505050565b60008060008060608587031215613bff578081fd5b843567ffffffffffffffff80821115613c16578283fd5b818701915087601f830112613c29578283fd5b813581811115613c37578384fd5b8860208083028501011115613c4a578384fd5b6020928301965094509086013590613c6182614803565b90925060408601359080821115613c76578283fd5b50613c8387828801613a48565b91505092959194509250565b600060208284031215613ca0578081fd5b8151612cbd81614818565b600060208284031215613cbc578081fd5b5035919050565b600060208284031215613cd4578081fd5b5051919050565b60008060408385031215613ced578182fd5b823591506020830135613cff81614803565b809150509250929050565b600060208284031215613d1b578081fd5b81356001600160e01b031981168114612cbd578182fd5b600080600080848603610100811215613d49578283fd5b60a0811215613d56578283fd5b5084935060a085013567ffffffffffffffff811115613d73578283fd5b613d7f87828801613ac3565b935050613d8e60c08601613b45565b9396929550929360e00135925050565b6000806000838503610140811215613db4578182fd5b60a0811215613dc1578182fd5b50613dcc60a06145b5565b8435613dd781614803565b81526020850135613de781614803565b60208201526040850135613dfa81614803565b60408201526060858101359082015260808086013590820152925060a084013567ffffffffffffffff811115613e2e578182fd5b613e3a86828701613ac3565b925050613e4a8560c08601613b2e565b90509250925092565b600080600060608486031215613e67578081fd5b833592506020840135613e7981614803565b9150604084013567ffffffffffffffff811115613e94578182fd5b613ea086828701613a48565b9150509250925092565b60008060408385031215613ebc578182fd5b82359150602083013567ffffffffffffffff811115613ed9578182fd5b613ee585828601613a48565b9150509250929050565b600060208284031215613f00578081fd5b612cbd82613b45565b60008060408385031215613f1b578182fd5b613f2483613b45565b91506020830135613cff81614803565b600080600080600080600060e0888a031215613f4e578485fd5b613f5788613b45565b96506020880135613f6781614803565b96999698505050506040850135946060810135946080820135945060a0820135935060c0909101359150565b60008060408385031215613fa5578182fd5b613bdc83613b45565b600080600060608486031215613fc2578081fd5b613fcb84613b45565b925060208401359150604084013567ffffffffffffffff811115613e94578182fd5b60008151808452614005816020860160208601614763565b601f01601f19169290920160200192915050565b60028110614029576140296147d7565b9052565b63ffffffff81511682526020810151602083015260018060a01b036040820151166040830152606081015161406d60608401826001600160a01b03169052565b506080810151608083015260a081015160a083015260c081015160c083015260e08101516140a660e08401826001600160a01b03169052565b506101008082015161323282850182614019565b858152606085901b6001600160601b031916602082015260e084901b6001600160e01b031916603482015260006001600160fb1b038311156140fa578081fd5b60208302808560388501379190910160380190815295945050505050565b93845260609290921b6001600160601b031916602084015260e01b6001600160e01b0319166034830152603882015260580190565b6000825161415f818460208701614763565b9190910192915050565b60007f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000825283516141a1816017850160208801614763565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516141d2816028840160208801614763565b01602801949350505050565b60e09290921b6001600160e01b031916825260601b6001600160601b031916600482015260180190565b60e09290921b6001600160e01b0319168252600482015260240190565b600060408201848352602060408185015281855180845260608601915060608382028701019350828701855b8281101561427f57605f1988870301845261426d868351613fed565b95509284019290840190600101614251565b509398975050505050505050565b60608101600485106142a1576142a16147d7565b93815263ffffffff92909216602083015260409091015290565b6101408101600384106142d0576142d06147d7565b838252612cbd602083018461402d565b600060208252612cbd6020830184613fed565b60208082526012908201527111549497d053149150511657d0d313d4d15160721b604082015260600190565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b6020808252600f908201526e11549497d1915157d393d517d4d155608a1b604082015260600190565b60208082526017908201527f4552525f494e56414c49445f59504f4f4c5f544f4b454e000000000000000000604082015260600190565b60208082526012908201527111549497d253959053125117d4d5d054125160721b604082015260600190565b600083356143e281614803565b6001600160a01b0390811683526020850135906143fe82614803565b908116602084015260408501359061441582614803565b80821660408501525050606084013560608301526080840135608083015260c060a08301526138df60c0830184613fed565b600060018060a01b0380855116835280602086015116602084015280604086015116604084015250606084015160608301526080840151608083015260c060a08301526138df60c0830184613fed565b61012081016124a6828461402d565b888152610160810163ffffffff806144bd8b613b45565b16602084015260208a01356144d181614803565b60018060a01b03811660408501525060408a01356060840152806144f760608c01613b45565b166080840152506001600160a01b03881660a08301526001600160a01b03871660c08301528560e08301526145386101008301866001600160a01b03169052565b61012082019390935261014001529695505050505050565b63ffffffff8a168152602081018990526001600160a01b03888116604083015287811660608301526080820187905260a0820186905260c08201859052831660e082015261012081016145a7610100830184614019565b9a9950505050505050505050565b604051601f8201601f1916810167ffffffffffffffff811182821017156145de576145de6147ed565b604052919050565b600082198211156145f9576145f96147c1565b500190565b60008261461957634e487b7160e01b81526012600452602481fd5b500490565b80825b6001808611614630575061465b565b818704821115614642576146426147c1565b8086161561464f57918102915b9490941c938002614621565b94509492505050565b6000612cbd600019848460008261467d57506001612cbd565b8161468a57506000612cbd565b81600181146146a057600281146146aa576146d7565b6001915050612cbd565b60ff8411156146bb576146bb6147c1565b6001841b9150848211156146d1576146d16147c1565b50612cbd565b5060208310610133831016604e8410600b8410161715614705575081810a838111156132d1576132d16147c1565b614712848484600161461e565b808604821115614724576147246147c1565b02949350505050565b6000816000190483118215151615614747576147476147c1565b500290565b60008282101561475e5761475e6147c1565b500390565b60005b8381101561477e578181015183820152602001614766565b838111156132325750506000910152565b60008161479e5761479e6147c1565b506000190190565b60006000198214156147ba576147ba6147c1565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114610edc57600080fd5b8015158114610edc57600080fdfef206625bad3d9112d5609b8d356e6fbd514cd1f69980d4ce2b3e6e68e1789ace000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeea2646970667358221220cc51c530154668d0d3dd0b5567e70699700484c77a98127d1d0274310751672d64736f6c63430008020033f206625bad3d9112d5609b8d356e6fbd514cd1f69980d4ce2b3e6e68e1789ace358933fb1b4f9e62c7cd3651025ad8825acb20ebbb23b09160e3867d71501ddd43ccaf94e5a0ff213b32419bf56f27f93e4170af0c4867ff3412f6aa5a22daf09f4e1c871d5fdd0aee1cd182666698a4492b24c6832aac230d07b11046af5a890000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b0000000000000000000000001b0789910027c3cc58af2391de7228d973c5c46e0000000000000000000000000000000000000000000000000000000000000089

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b0000000000000000000000001b0789910027c3cc58af2391de7228d973c5c46e0000000000000000000000000000000000000000000000000000000000000089

-----Decoded View---------------
Arg [0] : owner (address): 0x0132613b3a1061816f4661ad301612910e3cce0b
Arg [1] : manager (address): 0x0132613b3a1061816f4661ad301612910e3cce0b
Arg [2] : staff (address): 0x0132613b3a1061816f4661ad301612910e3cce0b
Arg [3] : worker (address): 0x0132613b3a1061816f4661ad301612910e3cce0b
Arg [4] : _supervisor (address): 0x1b0789910027c3cc58af2391de7228d973c5c46e
Arg [5] : _chainId (uint32): 137

-----Encoded View---------------
6 Constructor Arguments found :
Arg [0] : 0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b
Arg [1] : 0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b
Arg [2] : 0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b
Arg [3] : 0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b
Arg [4] : 0000000000000000000000001b0789910027c3cc58af2391de7228d973c5c46e
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000089


Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.