Contract 0x74A0EEA77e342323aA463098e959612d3Fe6E686 7

 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x0995e2e6864dd8065d3f9781ca3bc9ced008ce47d02f4805f78be0968b6fc44e0x500f528c201566982022-08-13 12:46:221 hr 45 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000107650066 ETH
0x4075790e4da2b13924e75b1ff6af5f393fb1b4992f84de2ba94ac758806ae702Batch Claim201494052022-08-13 10:47:103 hrs 44 mins ago0xe0276474243fff9aa11fbe7acb80f6bf04c142ab IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000114195195 ETH
0x9c43568d05ced5c0c8bc849723ddff93655c5c46fe35c2b9117be071ac8583fc0x3fc8ef10201492142022-08-13 10:44:293 hrs 47 mins ago0xc4b84ee1cf1765bf907ab59859b6a7d7a879d08f IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000163249826 ETH
0xac141af48d2d40d3a8685fe6b42f5264a6ddf514210a0a9e95f93895e2807f1cBatch Claim201434012022-08-13 9:05:115 hrs 26 mins ago0xe0276474243fff9aa11fbe7acb80f6bf04c142ab IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000127523471 ETH
0x1c64a7b80e45933e3d2ea9f14069e03b218f2ed1ef746592d682b346bc0fb1f00x3fc8ef10201432972022-08-13 9:03:465 hrs 28 mins ago0x21e2441035cdd3fdda3b2cec0ccd3c11cdae4725 IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000185815757 ETH
0x8ae040e44d684dd5c78ff25026cc7a2f99f99be730d64fecf0a42f0238c2b1f10x500f528c201372162022-08-13 7:18:217 hrs 13 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000227427093 ETH
0xd5405becc61b749d9e2d0c0fc659cd06aeec6d90e3e27b6d0e7c8ee4f0c570c80x500f528c201034012022-08-12 19:38:0318 hrs 53 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000183237361 ETH
0x0bb729085b70d3afb9fe2ea5c555ef0d0a95b8665172d31ab3d0aa710ac006300x500f528c200981072022-08-12 17:46:4220 hrs 45 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.00042586042 ETH
0x5533e37f6e6ea99c4ceda9b43dd5374b549bbbace676338f1bfb3b7f30174aed0x3fc8ef10200971112022-08-12 17:17:5121 hrs 13 mins ago0x2881a58796ec4ffcceb307f0c01ed7b760281e7d IN  0x74a0eea77e342323aa463098e959612d3fe6e6860.054425 ETH0.00042246837 ETH
0x070e1c8c03e2d12011d8352ccfdcaf460ba67401a4365d5a1ce4f840140f049b0x3fc8ef10200911402022-08-12 15:14:3023 hrs 17 mins ago0x4f321ad6ddc21ebcf9ee7213d2b41895196b6a9b IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000520921979 ETH
0x89190067e85d357c2a43b20e5f6ac28dcb6d0864bac6b33b670ef0bf5935e4c60x500f528c200859882022-08-12 13:37:511 day 53 mins ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000267325313 ETH
0x87b28eac9dc073ba5492f994f8e0feeca3cfca460b3fd03383dfd1a8104372350x3fc8ef10200850512022-08-12 13:23:571 day 1 hr ago0xe2a0addd20513c0ca19af2c5ee88eb232e9fef3d IN  0x74a0eea77e342323aa463098e959612d3fe6e6860.127501 ETH0.000352850587 ETH
0x04698fa102fe7ce5b8dfe8c1042f78a62f2e8cfd0a68a4ae63b7bcea893e5b460x3fc8ef10200819052022-08-12 12:28:351 day 2 hrs ago0x25083ce6575202c6941d18f2e3437b0fd2ab5856 IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000241125483 ETH
0xe6853e7603bf432d1a403080d6190ca6f566cc16dda4e4af865a1f32e13b49930x500f528c200692432022-08-12 8:50:301 day 5 hrs ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000269495445 ETH
0x561bcf028f8e3b3b34f581bf799631a7175c90c5fffc6e54afc84a27a03c55f00x3fc8ef10200583242022-08-12 5:21:521 day 9 hrs ago0x203e9fad55b68695cacd78ca683d6c5d526b892d IN  0x74a0eea77e342323aa463098e959612d3fe6e6860.053 ETH0.000382510364 ETH
0x24c7460f588be98a4c4443b892b09f9a417bb54dc3f5f6bb32828cdc6051f66b0x500f528c200437092022-08-11 23:56:401 day 14 hrs ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000192353204 ETH
0x48b57435f5d18161a61b0c6174087a3c244747af93d8fa002f1b8b27719772230x500f528c200162522022-08-11 14:49:141 day 23 hrs ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000171114885 ETH
0xcc92d00d6aa11f5f20cdda5986ac664b2ad284f63e4648e870d5944fe44eee8a0x3fc8ef10199894842022-08-11 8:51:022 days 5 hrs ago0xc54b67b43f4216d4073c1dac65361978e8e22a74 IN  0x74a0eea77e342323aa463098e959612d3fe6e6860.0035 ETH0.000424966113 ETH
0x0a604c53dd6338fdbf821fb80f366ae954686b619ad46ffce45f2b82d3be295f0x500f528c199888432022-08-11 8:42:032 days 5 hrs ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000324101526 ETH
0xc2ef25a0712c7304314eff4f8ae6bcbdbd4a014750947eaa55385c518b780fc7Batch Claim199794152022-08-11 6:39:382 days 7 hrs ago0xe0276474243fff9aa11fbe7acb80f6bf04c142ab IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000205525548 ETH
0xdf0a01f6551a76ce4a97468f2a88a03e772777e08248fe38a7f62b46c85089e30x3fc8ef10199793102022-08-11 6:38:432 days 7 hrs ago0xe66990d76abb350d21ff68b71b9ef2d29896543f IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000317928354 ETH
0x0ee1f8ef96b8902aefbec6bc375513d5aa5d5712910b9d2e87f68004ff7042d50x500f528c199789762022-08-11 6:34:342 days 7 hrs ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000218447455 ETH
0x2ab64fb018794e94fb4739391cff5d8d32febe9d47a03c60c2a059ab98cce3110x500f528c199753542022-08-11 5:40:102 days 8 hrs ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000204161955 ETH
0x414bc68e1a23338b268939d274ab8a432fec5b4dbc0e5a5e75c024ce1c81d1870x3fc8ef10199707822022-08-11 4:32:522 days 9 hrs ago0x75484d72e0ddcb858c1771a26704c13bbe37ccb4 IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000354064389 ETH
0x3dcd1a24fe2581fb78c6225ac06039e94f6ad859aff6268bafaa3ba69b5805da0x500f528c199693832022-08-11 4:07:142 days 10 hrs ago0xb35f9aac007666cacd0520b68d59d682262db7da IN  0x74a0eea77e342323aa463098e959612d3fe6e6860 ETH0.000394510018 ETH
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0x0995e2e6864dd8065d3f9781ca3bc9ced008ce47d02f4805f78be0968b6fc44e201566982022-08-13 12:46:221 hr 45 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xff970a61a04b1ca14834a43f5de4533ebddb5cc80 ETH
0x0995e2e6864dd8065d3f9781ca3bc9ced008ce47d02f4805f78be0968b6fc44e201566982022-08-13 12:46:221 hr 45 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xff970a61a04b1ca14834a43f5de4533ebddb5cc80 ETH
0x0995e2e6864dd8065d3f9781ca3bc9ced008ce47d02f4805f78be0968b6fc44e201566982022-08-13 12:46:221 hr 45 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0x680ab543acd0e52035e9d409014dd57861fa1edf0 ETH
0x0995e2e6864dd8065d3f9781ca3bc9ced008ce47d02f4805f78be0968b6fc44e201566982022-08-13 12:46:221 hr 45 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xff970a61a04b1ca14834a43f5de4533ebddb5cc80 ETH
0x0995e2e6864dd8065d3f9781ca3bc9ced008ce47d02f4805f78be0968b6fc44e201566982022-08-13 12:46:221 hr 45 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xff970a61a04b1ca14834a43f5de4533ebddb5cc80 ETH
0x4075790e4da2b13924e75b1ff6af5f393fb1b4992f84de2ba94ac758806ae702201494052022-08-13 10:47:103 hrs 44 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0x7a483730ad5a845ed2962c49de38be1661d473410 ETH
0x4075790e4da2b13924e75b1ff6af5f393fb1b4992f84de2ba94ac758806ae702201494052022-08-13 10:47:103 hrs 44 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb90 ETH
0x4075790e4da2b13924e75b1ff6af5f393fb1b4992f84de2ba94ac758806ae702201494052022-08-13 10:47:103 hrs 44 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb90 ETH
0x4075790e4da2b13924e75b1ff6af5f393fb1b4992f84de2ba94ac758806ae702201494052022-08-13 10:47:103 hrs 44 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0x73ce60416035b8d7019f6399778c14ccf5c9c7a10 ETH
0x4075790e4da2b13924e75b1ff6af5f393fb1b4992f84de2ba94ac758806ae702201494052022-08-13 10:47:103 hrs 44 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0x73ce60416035b8d7019f6399778c14ccf5c9c7a10 ETH
0x9c43568d05ced5c0c8bc849723ddff93655c5c46fe35c2b9117be071ac8583fc201492142022-08-13 10:44:293 hrs 47 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb90 ETH
0x9c43568d05ced5c0c8bc849723ddff93655c5c46fe35c2b9117be071ac8583fc201492142022-08-13 10:44:293 hrs 47 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb90 ETH
0x9c43568d05ced5c0c8bc849723ddff93655c5c46fe35c2b9117be071ac8583fc201492142022-08-13 10:44:293 hrs 47 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb90 ETH
0x9c43568d05ced5c0c8bc849723ddff93655c5c46fe35c2b9117be071ac8583fc201492142022-08-13 10:44:293 hrs 47 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb90 ETH
0x9c43568d05ced5c0c8bc849723ddff93655c5c46fe35c2b9117be071ac8583fc201492142022-08-13 10:44:293 hrs 47 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb90 ETH
0x9c43568d05ced5c0c8bc849723ddff93655c5c46fe35c2b9117be071ac8583fc201492142022-08-13 10:44:293 hrs 47 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb90 ETH
0xac141af48d2d40d3a8685fe6b42f5264a6ddf514210a0a9e95f93895e2807f1c201434012022-08-13 9:05:115 hrs 26 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0x680ab543acd0e52035e9d409014dd57861fa1edf0 ETH
0xac141af48d2d40d3a8685fe6b42f5264a6ddf514210a0a9e95f93895e2807f1c201434012022-08-13 9:05:115 hrs 26 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xff970a61a04b1ca14834a43f5de4533ebddb5cc80 ETH
0xac141af48d2d40d3a8685fe6b42f5264a6ddf514210a0a9e95f93895e2807f1c201434012022-08-13 9:05:115 hrs 26 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xff970a61a04b1ca14834a43f5de4533ebddb5cc80 ETH
0xac141af48d2d40d3a8685fe6b42f5264a6ddf514210a0a9e95f93895e2807f1c201434012022-08-13 9:05:115 hrs 26 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0x73ce60416035b8d7019f6399778c14ccf5c9c7a10 ETH
0xac141af48d2d40d3a8685fe6b42f5264a6ddf514210a0a9e95f93895e2807f1c201434012022-08-13 9:05:115 hrs 26 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0x73ce60416035b8d7019f6399778c14ccf5c9c7a10 ETH
0x1c64a7b80e45933e3d2ea9f14069e03b218f2ed1ef746592d682b346bc0fb1f0201432972022-08-13 9:03:465 hrs 28 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xff970a61a04b1ca14834a43f5de4533ebddb5cc80 ETH
0x1c64a7b80e45933e3d2ea9f14069e03b218f2ed1ef746592d682b346bc0fb1f0201432972022-08-13 9:03:465 hrs 28 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xff970a61a04b1ca14834a43f5de4533ebddb5cc80 ETH
0x1c64a7b80e45933e3d2ea9f14069e03b218f2ed1ef746592d682b346bc0fb1f0201432972022-08-13 9:03:465 hrs 28 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xff970a61a04b1ca14834a43f5de4533ebddb5cc80 ETH
0x1c64a7b80e45933e3d2ea9f14069e03b218f2ed1ef746592d682b346bc0fb1f0201432972022-08-13 9:03:465 hrs 28 mins ago 0x74a0eea77e342323aa463098e959612d3fe6e686 0xff970a61a04b1ca14834a43f5de4533ebddb5cc80 ETH
[ 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.2;

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 YPoolSupportedToken;
    // 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) {
        require(_swapId < swapId, "ERR_INVALID_SWAP_ID");
        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");
        YPoolSupportedToken[_supportedToken] = _isSet;
        YPoolVaults[_supportedToken] = _vault;
        emit YPoolVaultSet(_supportedToken, _vault, _isSet);
    }

    /// @notice Rescue fund accidentally sent to this contract. Can not rescue YPool token
    /// @param tokens List of token address to rescue
    function rescue(IERC20[] memory tokens) external onlyRole(ROLE_OWNER) {
        for (uint256 i; i < tokens.length; i++) {
            IERC20 token = tokens[i];
            require(!YPoolSupportedToken[address(token)], "ERR_CAN_NOT_RESCUE_YPOOL_TOKEN");
            uint256 _tokenBalance = token.balanceOf(address(this));
            token.safeTransfer(msg.sender, _tokenBalance);
        }
    }

    /* ========== 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(YPoolSupportedToken[_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(YPoolSupportedToken[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(YPoolSupportedToken[_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(YPoolSupportedToken[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.2;

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';
    bytes32 public constant VALIDATE_XY_CROSS_CHAIN_IDENTIFIER = 'VALIDATE_XY_XCHAIN_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.2;
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.2;

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
  },
  "libraries": {
    "XSwapper.sol": {}
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

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":"YPoolSupportedToken","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":"contract IERC20[]","name":"tokens","type":"address[]"}],"name":"rescue","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"}]

60a060405260006005553480156200001657600080fd5b5060405162004fc138038062004fc1833981016040819052620000399162000358565b6001805460ff191681556002556200005d826200023b602090811b62002f9a17901c565b620000af5760405162461bcd60e51b815260206004820152601b60248201527f4552525f53555045525649534f525f4e4f545f434f4e5452414354000000000060448201526064015b60405180910390fd5b600480546001600160a01b0319166001600160a01b03841617905560e081901b6001600160e01b0319166080524663ffffffff82168114620001295760405162461bcd60e51b815260206004820152601260248201527111549497d5d493d391d7d0d210525397d25160721b6044820152606401620000a6565b6200014460008051602062004fa18339815191528062000245565b6200016e60008051602062004f4183398151915260008051602062004fa183398151915262000245565b6200019860008051602062004f6183398151915260008051602062004fa183398151915262000245565b620001c260008051602062004f8183398151915260008051602062004fa183398151915262000245565b620001dd60008051602062004fa18339815191528862000290565b620001f860008051602062004f418339815191528762000290565b6200021360008051602062004f618339815191528662000290565b6200022e60008051602062004f818339815191528562000290565b50505050505050620003e3565b803b15155b919050565b600082815260208190526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b6200029c8282620002a0565b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff166200029c576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620002fc3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b03811681146200024057600080fd5b60008060008060008060c0878903121562000371578182fd5b6200037c8762000340565b95506200038c6020880162000340565b94506200039c6040880162000340565b9350620003ac6060880162000340565b9250620003bc6080880162000340565b915060a087015163ffffffff81168114620003d5578182fd5b809150509295509295509295565b60805160e01c614b1c62000425600039600081816105ca01528181610a8d015281816121d001528181612bd801528181612d9c01526134f90152614b1c6000f3fe60806040526004361061023e5760003560e01c80638ad682af1161012e578063d547741f116100ab578063f281de9e1161006f578063f281de9e14610814578063f54738ef14610834578063f5b944eb1461084a578063f9120af61461086c578063fde3f7dc1461088c57610245565b8063d547741f14610710578063d8331e7114610730578063e251975e14610750578063e53e016e14610770578063f13de4b3146107a657610245565b80639c61d7a4116100f25780639c61d7a414610601578063a217fddf14610636578063acb355321461064b578063b89bbce7146106ce578063cf1d21c0146106ee57610245565b80638ad682af146105245780638fc3ab8b1461055857806391d14854146105785780639968230b146105985780639a8a0592146105b857610245565b80633fc8ef10116101bc5780635c975abb116101805780635c975abb1461048357806364024b421461049b5780636aa4d6b5146104cf5780636c3f3917146104ef5780638456cb591461050f57610245565b80633fc8ef10146103f05780634a23656d14610403578063500f528c146104305780635136d5a21461044357806356e4b68b1461046357610245565b8063245a7bfc11610203578063245a7bfc14610333578063248a9ca31461036b5780632f2ff15d1461039b57806336568abe146103bb5780633f4ba83a146103db57610245565b8062501e281461024a57806301ffc9a71461026c57806312708c7b146102a157806322566122146102d157806322bf2e24146102f157610245565b3661024557005b600080fd5b34801561025657600080fd5b5061026a610265366004614106565b6108b9565b005b34801561027857600080fd5b5061028c610287366004613f66565b610d95565b60405190151581526020015b60405180910390f35b3480156102ad57600080fd5b5061028c6102bc366004613d1c565b60076020526000908152604090205460ff1681565b3480156102dd57600080fd5b5061026a6102ec366004613d82565b610dce565b3480156102fd57600080fd5b506103257f358933fb1b4f9e62c7cd3651025ad8825acb20ebbb23b09160e3867d71501ddd81565b604051908152602001610298565b34801561033f57600080fd5b50600954610353906001600160a01b031681565b6040516001600160a01b039091168152602001610298565b34801561037757600080fd5b50610325610386366004613f07565b60009081526020819052604090206001015490565b3480156103a757600080fd5b5061026a6103b6366004613f37565b610e3d565b3480156103c757600080fd5b5061026a6103d6366004613f37565b610e68565b3480156103e757600080fd5b5061026a610ee6565b61026a6103fe366004613ffa565b610f0a565b34801561040f57600080fd5b5061042361041e366004613f07565b6114d8565b60405161029891906146f3565b61026a61043e366004613f8e565b611669565b34801561044f57600080fd5b5061026a61045e366004613d38565b611bce565b34801561046f57600080fd5b50600454610353906001600160a01b031681565b34801561048f57600080fd5b5060015460ff1661028c565b3480156104a757600080fd5b506103257f43ccaf94e5a0ff213b32419bf56f27f93e4170af0c4867ff3412f6aa5a22daf081565b3480156104db57600080fd5b5061026a6104ea36600461420a565b611d3d565b3480156104fb57600080fd5b5061026a61050a366004613dad565b611f3e565b34801561051b57600080fd5b5061026a6120b5565b34801561053057600080fd5b506103257f9f4e1c871d5fdd0aee1cd182666698a4492b24c6832aac230d07b11046af5a8981565b34801561056457600080fd5b5061026a610573366004613e46565b6120d6565b34801561058457600080fd5b5061028c610593366004613f37565b61265c565b3480156105a457600080fd5b5061026a6105b3366004613d1c565b612687565b3480156105c457600080fd5b506105ec7f000000000000000000000000000000000000000000000000000000000000000081565b60405163ffffffff9091168152602001610298565b34801561060d57600080fd5b5061062161061c366004613f07565b612708565b604051610298999897969594939291906147ac565b34801561064257600080fd5b50610325600081565b34801561065757600080fd5b5061069f610666366004613f07565b600b6020526000908152604090208054600182015460028301546003840154600485015460059095015460ff9094169492939192909186565b6040805196151587526020870195909552938501929092526060840152608083015260a082015260c001610298565b3480156106da57600080fd5b5061026a6106e9366004614190565b612780565b3480156106fa57600080fd5b50610353600080516020614ac783398151915281565b34801561071c57600080fd5b5061026a61072b366004613f37565b6129cf565b34801561073c57600080fd5b50600a54610353906001600160a01b031681565b34801561075c57600080fd5b5061026a61076b3660046140af565b6129f5565b34801561077c57600080fd5b5061035361078b366004613d1c565b6008602052600090815260409020546001600160a01b031681565b3480156107b257600080fd5b506107c66107c1366004614165565b612e30565b6040516102989190600060c0820190508251151582526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015292915050565b34801561082057600080fd5b5061028c61082f3660046141ef565b612e9f565b34801561084057600080fd5b5061032560055481565b34801561085657600080fd5b50610325600080516020614aa783398151915281565b34801561087857600080fd5b5061026a610887366004613d1c565b612ee5565b34801561089857600080fd5b506103256108a7366004613d1c565b60036020526000908152604090205481565b60015460ff16156108e55760405162461bcd60e51b81526004016108dc9061457b565b60405180910390fd5b60055482106109065760405162461bcd60e51b81526004016108dc90614605565b6001600c838154811061092957634e487b7160e01b600052603260045260246000fd5b906000526020600020906008020160070160149054906101000a900460ff16600181111561096757634e487b7160e01b600052602160045260246000fd5b14156109855760405162461bcd60e51b81526004016108dc9061454f565b6001600c83815481106109a857634e487b7160e01b600052603260045260246000fd5b60009182526020909120600760089092020101805460ff60a01b1916600160a01b8360018111156109e957634e487b7160e01b600052602160045260246000fd5b02179055506000600460009054906101000a90046001600160a01b03166001600160a01b031663faf55b5c6040518163ffffffff1660e01b815260040160206040518083038186803b158015610a3e57600080fd5b505afa158015610a52573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a769190613f1f565b600a54604051610ab792916001600160a01b0316907f0000000000000000000000000000000000000000000000000000000000000000908790602001614374565b6040516020818303038152906040528051906020012090506000610ada82612fa0565b600480546040516305a0f88360e41b81529293506001600160a01b031691635a0f883091610b0c918591889101614481565b60006040518083038186803b158015610b2457600080fd5b505afa158015610b38573d6000803e3d6000fd5b505050506000600c8581548110610b5f57634e487b7160e01b600052603260045260246000fd5b600091825260209182902060408051610120810182526008909302909101805463ffffffff1683526001808201549484019490945260028101546001600160a01b039081169284019290925260038101548216606084015260048101546080840152600581015460a0840152600681015460c0840152600781015491821660e0840152919261010084019160ff600160a01b9091041690811115610c1357634e487b7160e01b600052602160045260246000fd5b6001811115610c3257634e487b7160e01b600052602160045260246000fd5b90525060e0810180516001600160a01b0390811660009081526008602052604081205492519394509181169216600080516020614ac783398151915214610c7a576000610c80565b82608001515b60e08401519091506001600160a01b0316600080516020614ac783398151915214610ccb57610ccb8284608001518560e001516001600160a01b0316612ff39092919063ffffffff16565b60e0830151608084015160a085015160c086015160405163496d674b60e11b81526001600160a01b039485166004820152602481019390935260448301919091526064820152908316906392dace969083906084016000604051808303818588803b158015610d3957600080fd5b505af1158015610d4d573d6000803e3d6000fd5b50505050507f7cf616e580913e39d7ffeeb739823ba0799bc2948b9b6043f5127cad95b655c8600084604051610d84929190614517565b60405180910390a150505050505050565b60006001600160e01b03198216637965db0b60e01b1480610dc657506301ffc9a760e01b6001600160e01b03198316145b90505b919050565b600080516020614aa7833981519152610de881335b61314a565b6001600160a01b03831660009081526007602052604090205460ff16610e205760405162461bcd60e51b81526004016108dc906145ce565b506001600160a01b03909116600090815260036020526040902055565b600082815260208190526040902060010154610e598133610de3565b610e6383836131ae565b505050565b6001600160a01b0381163314610ed85760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084016108dc565b610ee28282613232565b5050565b600080516020614aa7833981519152610eff8133610de3565b610f07613297565b50565b825160608401516001600160a01b038216600080516020614ac783398151915214610f4957600954610f49906001600160a01b03848116911683612ff3565b60015460ff1615610f6c5760405162461bcd60e51b81526004016108dc9061457b565b600280541415610fbe5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016108dc565b6002805560408086015186516020808901516001600160a01b03811660009081526007909252939020549192909160ff1661100b5760405162461bcd60e51b81526004016108dc906145ce565b6060880151600061101d84338461332a565b826001600160a01b0316846001600160a01b0316141561103e5750806110f1565b6110488330613413565b306040808d01919091526009549051638218b58f60e01b81529192506001600160a01b031690638218b58f903490611086908e908e906004016146a3565b6020604051808303818588803b15801561109f57600080fd5b505af11580156110b3573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906110d89190613f1f565b50806110e48430613413565b6110ee91906149cc565b90505b61110861110160208a018a61414b565b84836134c1565b6111545760405162461bcd60e51b815260206004820152601a60248201527f4552525f4e4f545f454e4f5547485f535741505f414d4f554e5400000000000060448201526064016108dc565b6001600160a01b0383166000908152600360205260409020548111156111bc5760405162461bcd60e51b815260206004820152601a60248201527f4552525f4558434545445f4d41585f535741505f414d4f554e5400000000000060448201526064016108dc565b6000806111d66111cf60208c018c61414b565b868561355c565b6040805161012081019091529193509150600090806111f860208e018e61414b565b63ffffffff16815260055460208201526001600160a01b03808b1660408301523360608301526080820187905260a0820186905260c08201859052881660e08201526101000160009052600c805460018181018355600092909252825160089091027fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c78101805463ffffffff90931663ffffffff1990931692909217825560208401517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c882015560408401517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c9820180546001600160a01b039283166001600160a01b03199182161790915560608601517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8ca8401805491841691831691909117905560808601517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8cb84015560a08601517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8cc84015560c08601517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8cd84015560e08601517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8ce9093018054939092169216919091178082556101008501519495508594929360ff60a01b1990911690600160a01b90849081111561142957634e487b7160e01b600052602160045260246000fd5b021790555050600580547f988e36bbb7fb7444e889f1367ca3ee06e9d8bec0d99f1ffec20c2697987a4a45925090600061146283614a26565b919050558c8989888d8989604051611481989796959493929190614702565b60405180910390a150506001600255505050506001600160a01b038416600080516020614ac78339815191521491506114d19050576009546114d1906001600160a01b0384811691166000612ff3565b5050505050565b6115256040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081018290529061010082015290565b600554821061156c5760405162461bcd60e51b815260206004820152601360248201527211549497d253959053125117d4d5d05417d251606a1b60448201526064016108dc565b600c828154811061158d57634e487b7160e01b600052603260045260246000fd5b600091825260209182902060408051610120810182526008909302909101805463ffffffff1683526001808201549484019490945260028101546001600160a01b039081169284019290925260038101548216606084015260048101546080840152600581015460a0840152600681015460c0840152600781015491821660e0840152919261010084019160ff600160a01b909104169081111561164157634e487b7160e01b600052602160045260246000fd5b600181111561166057634e487b7160e01b600052602160045260246000fd5b90525092915050565b60015460ff161561168c5760405162461bcd60e51b81526004016108dc9061457b565b7f43ccaf94e5a0ff213b32419bf56f27f93e4170af0c4867ff3412f6aa5a22daf06116b78133610de3565b6116c46020860186613d1c565b60608601356001600160a01b038216600080516020614ac78339815191521461170157600954611701906001600160a01b03848116911683612ff3565b6007600061171260208a018a613d1c565b6001600160a01b0316815260208101919091526040016000205460ff1661174b5760405162461bcd60e51b81526004016108dc906145ce565b60008585604051602001611760929190614464565b60408051601f1981840301815291815281516020928301206000818152600690935291205490915060ff16156117a85760405162461bcd60e51b81526004016108dc9061454f565b60008181526006602090815260408220805460ff1916600117905560608a0135916003916117d8908c018c613d1c565b6001600160a01b03166001600160a01b03168152602001908152602001600020548111156118485760405162461bcd60e51b815260206004820152601a60248201527f4552525f4558434545445f4d41585f535741505f414d4f554e5400000000000060448201526064016108dc565b6008600061185960208c018c613d1c565b6001600160a01b039081168252602080830193909352604090910160002054169063c2fc21109061188c908c018c613d1c565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401600060405180830381600087803b1580156118d457600080fd5b505af11580156118e8573d6000803e3d6000fd5b50600092508291506118ff905060208c018c613d1c565b6001600160a01b031661191860408d0160208e01613d1c565b6001600160a01b0316141561193257508190506000611a6f565b6000600080516020614ac783398151915261195060208e018e613d1c565b6001600160a01b031614611965576000611967565b835b905061199461197c60408e0160208f01613d1c565b8d604001602081019061198f9190613d1c565b613413565b9250600960009054906101000a90046001600160a01b03166001600160a01b0316638218b58f828e8e6040518463ffffffff1660e01b81526004016119da929190614631565b6020604051808303818588803b1580156119f357600080fd5b505af193505050508015611a24575060408051601f3d908101601f19168201909252611a2191810190613f1f565b60015b611a315760029150611a6d565b5082611a5c8d6020016020810190611a499190613d1c565b8e604001602081019061198f9190613d1c565b611a6691906149cc565b9250600191505b505b6001816003811115611a9157634e487b7160e01b600052602160045260246000fd5b14611abc57611abc611aa960608d0160408e01613d1c565b611ab660208e018e613d1c565b856135e4565b7fee823aedb9f54993693aeaca62918fd9eeaf9d0416276706739088c10ceaf2b8818a8a604051611aef939291906144e9565b60405180910390a17f4a1c72e2e3d1f37b0b083de3b7f8b54bebc3dd82fba56aa4e5f68b970b26ea67611b2560208d018d613d1c565b848d6020016020810190611b399190613d1c565b858f6040016020810190611b4d9190613d1c565b604080516001600160a01b0396871681526020810195909552928516928401929092526060830152909116608082015260a00160405180910390a1505050506001600160a01b038216600080516020614ac783398151915214611bc557600954611bc5906001600160a01b0384811691166000612ff3565b50505050505050565b7f9f4e1c871d5fdd0aee1cd182666698a4492b24c6832aac230d07b11046af5a89611bf98133610de3565b6001600160a01b038416600080516020614ac783398151915214611c6557833b611c655760405162461bcd60e51b815260206004820152601c60248201527f4552525f59504f4f4c5f544f4b454e5f4e4f545f434f4e54524143540000000060448201526064016108dc565b823b611cb35760405162461bcd60e51b815260206004820152601c60248201527f4552525f59504f4f4c5f5641554c545f4e4f545f434f4e54524143540000000060448201526064016108dc565b6001600160a01b038481166000818152600760209081526040808320805460ff1916881515908117909155600883529281902080546001600160a01b03191695891695861790558051938452908301939093528183015290517ff1e53a62d5935afca4762c943ac543a520fbf358eafaac6024bcb3f053f32071916060908290030190a150505050565b60015460ff1615611d605760405162461bcd60e51b81526004016108dc9061457b565b60008383604051602001611d75929190614464565b60408051601f1981840301815291815281516020928301206000818152600690935291205490915060ff1615611dbd5760405162461bcd60e51b81526004016108dc9061454f565b6000600460009054906101000a90046001600160a01b03166001600160a01b03166374892a726040518163ffffffff1660e01b815260040160206040518083038186803b158015611e0d57600080fd5b505afa158015611e21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e459190613f1f565b308686604051602001611e5b9493929190614374565b6040516020818303038152906040528051906020012090506000611e7e82612fa0565b600480546040516305a0f88360e41b81529293506001600160a01b031691635a0f883091611eb0918591899101614481565b60006040518083038186803b158015611ec857600080fd5b505afa158015611edc573d6000803e3d6000fd5b50505060008481526006602052604090819020805460ff19166001179055517fee823aedb9f54993693aeaca62918fd9eeaf9d0416276706739088c10ceaf2b89150611f2e90600390899089906144e9565b60405180910390a1505050505050565b7f9f4e1c871d5fdd0aee1cd182666698a4492b24c6832aac230d07b11046af5a89611f698133610de3565b60005b8251811015610e63576000838281518110611f9757634e487b7160e01b600052603260045260246000fd5b6020908102919091018101516001600160a01b0381166000908152600790925260409091205490915060ff16156120105760405162461bcd60e51b815260206004820152601e60248201527f4552525f43414e5f4e4f545f5245534355455f59504f4f4c5f544f4b454e000060448201526064016108dc565b6040516370a0823160e01b81523060048201526000906001600160a01b038316906370a082319060240160206040518083038186803b15801561205257600080fd5b505afa158015612066573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061208a9190613f1f565b90506120a06001600160a01b038316338361364f565b505080806120ad90614a26565b915050611f6c565b600080516020614aa78339815191526120ce8133610de3565b610f0761367f565b60015460ff16156120f95760405162461bcd60e51b81526004016108dc9061457b565b6001600160a01b03821660009081526007602052604090205460ff166121315760405162461bcd60e51b81526004016108dc906145ce565b6000600460009054906101000a90046001600160a01b03166001600160a01b031663f7ca80236040518163ffffffff1660e01b815260040160206040518083038186803b15801561218157600080fd5b505afa158015612195573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121b99190613f1f565b600a546040516121fc92916001600160a01b0316907f00000000000000000000000000000000000000000000000000000000000000009089908990602001614316565b604051602081830303815290604052805190602001209050600061221f82612fa0565b600480546040516305a0f88360e41b81529293506001600160a01b031691635a0f883091612251918591889101614481565b60006040518083038186803b15801561226957600080fd5b505afa15801561227d573d6000803e3d6000fd5b5050505060008490506000806000805b8981101561256b5760008b8b838181106122b757634e487b7160e01b600052603260045260246000fd5b90506020020135905060055481106122e15760405162461bcd60e51b81526004016108dc90614605565b6000600c828154811061230457634e487b7160e01b600052603260045260246000fd5b600091825260209182902060408051610120810182526008909302909101805463ffffffff1683526001808201549484019490945260028101546001600160a01b039081169284019290925260038101548216606084015260048101546080840152600581015460a0840152600681015460c0840152600781015491821660e0840152919261010084019160ff600160a01b90910416908111156123b857634e487b7160e01b600052602160045260246000fd5b60018111156123d757634e487b7160e01b600052602160045260246000fd5b90525090506001816101000151600181111561240357634e487b7160e01b600052602160045260246000fd5b14156124215760405162461bcd60e51b81526004016108dc9061454f565b866001600160a01b03168160e001516001600160a01b03161461247e5760405162461bcd60e51b815260206004820152601560248201527422a9292faba927a723afaca827a7a62faa27a5a2a760591b60448201526064016108dc565b608081015161248d9087614866565b95508060a001518561249f9190614866565b94508060c00151846124b19190614866565b93506001600c83815481106124d657634e487b7160e01b600052603260045260246000fd5b60009182526020909120600760089092020101805460ff60a01b1916600160a01b83600181111561251757634e487b7160e01b600052602160045260246000fd5b02179055507f7cf616e580913e39d7ffeeb739823ba0799bc2948b9b6043f5127cad95b655c860018260405161254e929190614517565b60405180910390a15050808061256390614a26565b91505061228d565b506001600160a01b038089166000818152600860205260408120549092169190600080516020614ac7833981519152146125a65760006125a8565b845b90506001600160a01b038a16600080516020614ac7833981519152146125dc576125dc6001600160a01b0387168387612ff3565b60405163496d674b60e11b81526001600160a01b0387811660048301526024820187905260448201869052606482018590528316906392dace969083906084016000604051808303818588803b15801561263557600080fd5b505af1158015612649573d6000803e3d6000fd5b5050505050505050505050505050505050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff165b92915050565b7f358933fb1b4f9e62c7cd3651025ad8825acb20ebbb23b09160e3867d71501ddd6126b28133610de3565b600a80546001600160a01b0319166001600160a01b0384169081179091556040519081527f3623260a18beeff6af38bff0981baf3571a6f16d5b4c8942e8d26c0a166669db906020015b60405180910390a15050565b600c818154811061271857600080fd5b60009182526020909120600890910201805460018201546002830154600384015460048501546005860154600687015460079097015463ffffffff909616975093956001600160a01b039384169592841694919391929091811690600160a01b900460ff1689565b7f358933fb1b4f9e62c7cd3651025ad8825acb20ebbb23b09160e3867d71501ddd6127ab8133610de3565b6001600160a01b038716600080516020614ac78339815191521461281757863b6128175760405162461bcd60e51b815260206004820152601c60248201527f4552525f59504f4f4c5f544f4b454e5f4e4f545f434f4e54524143540000000060448201526064016108dc565b84841161285c5760405162461bcd60e51b815260206004820152601360248201527222a9292fa4a72b20a624a22fa6a0ac2fa6a4a760691b60448201526064016108dc565b858510156128a25760405162461bcd60e51b81526020600482015260136024820152724552525f494e56414c49445f4d494e5f47415360681b60448201526064016108dc565b600088886040516020016128b792919061443a565b60408051601f19818403018152828252805160209182012060c08401835260018085528483018c81528585018c8152606087018c8152608088018c815260a089018c81526000878152600b909852968890208951815490151560ff199091161781559351948401949094559051600283015551600382015590516004820155915160059092019190915590519092507fcb4bb3001f7b245a106522f836b6aed77ba72ad177e278f9bb0b46d81d98356c906129bb908c908c908c908c908c908c908c9063ffffffff9790971687526001600160a01b0395909516602087015260408601939093526060850191909152608084015260a083015260c082015260e00190565b60405180910390a150505050505050505050565b6000828152602081905260409020600101546129eb8133610de3565b610e638383613232565b60015460ff1615612a185760405162461bcd60e51b81526004016108dc9061457b565b6005548310612a395760405162461bcd60e51b81526004016108dc90614605565b6001600c8481548110612a5c57634e487b7160e01b600052603260045260246000fd5b906000526020600020906008020160070160149054906101000a900460ff166001811115612a9a57634e487b7160e01b600052602160045260246000fd5b1415612ab85760405162461bcd60e51b81526004016108dc9061454f565b6001600c8481548110612adb57634e487b7160e01b600052603260045260246000fd5b60009182526020909120600760089092020101805460ff60a01b1916600160a01b836001811115612b1c57634e487b7160e01b600052602160045260246000fd5b02179055506000600460009054906101000a90046001600160a01b03166001600160a01b03166374892a726040518163ffffffff1660e01b815260040160206040518083038186803b158015612b7157600080fd5b505afa158015612b85573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ba99190613f1f565b6040805160208101929092526001600160601b031930606090811b8216928401929092526001600160e01b03197f000000000000000000000000000000000000000000000000000000000000000060e01b166054840152605883018790529085901b166078820152608c016040516020818303038152906040528051906020012090506000612c3782612fa0565b600480546040516305a0f88360e41b81529293506001600160a01b031691635a0f883091612c69918591889101614481565b60006040518083038186803b158015612c8157600080fd5b505afa158015612c95573d6000803e3d6000fd5b505050506000600c8681548110612cbc57634e487b7160e01b600052603260045260246000fd5b600091825260209182902060408051610120810182526008909302909101805463ffffffff1683526001808201549484019490945260028101546001600160a01b039081169284019290925260038101548216606084015260048101546080840152600581015460a0840152600681015460c0840152600781015491821660e0840152919261010084019160ff600160a01b9091041690811115612d7057634e487b7160e01b600052602160045260246000fd5b6001811115612d8f57634e487b7160e01b600052602160045260246000fd5b8152505090506000612dca7f00000000000000000000000000000000000000000000000000000000000000008360e00151846080015161355c565b915050612def82606001518360e00151838560800151612dea91906149cc565b6135e4565b612dfe868360e00151836135e4565b7f7cf616e580913e39d7ffeeb739823ba0799bc2948b9b6043f5127cad95b655c8600283604051610d84929190614517565b612e6b6040518060c0016040528060001515815260200160008152602001600081526020016000815260200160008152602001600081525090565b6000612e7784846136d5565b8051909150612e985760405162461bcd60e51b81526004016108dc906145a5565b9392505050565b6000808383604051602001612eb5929190614464565b60408051808303601f1901815291815281516020928301206000908152600690925290205460ff16949350505050565b600080516020614aa7833981519152612efe8133610de3565b813b612f4c5760405162461bcd60e51b815260206004820152601b60248201527f4552525f41474752454741544f525f4e4f545f434f4e5452414354000000000060448201526064016108dc565b600980546001600160a01b0319166001600160a01b0384169081179091556040519081527f94b241e14651a9658c51a45c82167e4f25ac3d3e7f8a2beae9d10b1ba07a94a0906020016126fc565b3b151590565b6040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b80158061307c5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e9060440160206040518083038186803b15801561304257600080fd5b505afa158015613056573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061307a9190613f1f565b155b6130e75760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b60648201526084016108dc565b6040516001600160a01b038316602482015260448101829052610e6390849063095ea7b360e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613795565b613154828261265c565b610ee25761316c816001600160a01b03166014613867565b613177836020613867565b6040516020016131889291906143c5565b60408051601f198184030181529082905262461bcd60e51b82526108dc9160040161453c565b6131b8828261265c565b610ee2576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556131ee3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b61323c828261265c565b15610ee2576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60015460ff166132e05760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b60448201526064016108dc565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6001600160a01b038316600080516020614ac783398151915214156133925780341461338d5760405162461bcd60e51b815260206004820152601260248201527111549497d253959053125117d05353d5539560721b60448201526064016108dc565b610e63565b600061339e8430613413565b90506133b56001600160a01b038516843085613a49565b81816133c18630613413565b6133cb91906149cc565b1461340d5760405162461bcd60e51b815260206004820152601260248201527111549497d253959053125117d05353d5539560721b60448201526064016108dc565b50505050565b60006001600160a01b038316600080516020614ac7833981519152146134b1576040516370a0823160e01b81526001600160a01b0383811660048301528416906370a082319060240160206040518083038186803b15801561347457600080fd5b505afa158015613488573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134ac9190613f1f565b612e98565b506001600160a01b031631919050565b6000806134ce85856136d5565b80519091506134ef5760405162461bcd60e51b81526004016108dc906145a5565b604081015161351e7f0000000000000000000000000000000000000000000000000000000000000000866136d5565b805190925061353f5760405162461bcd60e51b81526004016108dc906145a5565b604082015161354e8282613a81565b909410159695505050505050565b600080600061356b86866136d5565b805190915061358c5760405162461bcd60e51b81526004016108dc906145a5565b60a081015161359c90600a6148e4565b60808201516135ab90866149ad565b6135b5919061487e565b92506135d26135c8848360400151613a81565b8260600151613a98565b92508060200151915050935093915050565b6001600160a01b038216600080516020614ac7833981519152141561363f576040516001600160a01b0384169082156108fc029083906000818181858888f19350505050158015613639573d6000803e3d6000fd5b50610e63565b610e636001600160a01b03831684835b6040516001600160a01b038316602482015260448101829052610e6390849063a9059cbb60e01b90606401613113565b60015460ff16156136a25760405162461bcd60e51b81526004016108dc9061457b565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2583361330d565b6137106040518060c0016040528060001515815260200160008152602001600081526020016000815260200160008152602001600081525090565b6000838360405160200161372592919061443a565b60408051808303601f1901815282825280516020918201206000908152600b825282902060c084018352805460ff161515845260018101549184019190915260028101549183019190915260038101546060830152600481015460808301526005015460a0820152949350505050565b60006137ea826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316613aa79092919063ffffffff16565b805190915015610e6357808060200190518101906138089190613eeb565b610e635760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016108dc565b606060006138768360026149ad565b613881906002614866565b67ffffffffffffffff8111156138a757634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f1916602001820160405280156138d1576020820181803683370190505b509050600360fc1b816000815181106138fa57634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350600f60fb1b8160018151811061393757634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350600061395b8460026149ad565b613966906001614866565b90505b60018111156139fa576f181899199a1a9b1b9c1cb0b131b232b360811b85600f16601081106139a857634e487b7160e01b600052603260045260246000fd5b1a60f81b8282815181106139cc57634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a90535060049490941c936139f381614a0f565b9050613969565b508315612e985760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016108dc565b6040516001600160a01b038085166024830152831660448201526064810182905261340d9085906323b872dd60e01b90608401613113565b600081831015613a915781612e98565b5090919050565b6000818310613a915781612e98565b6060613ab68484600085613abe565b949350505050565b606082471015613b1f5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016108dc565b843b613b6d5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016108dc565b600080866001600160a01b03168587604051613b8991906143a9565b60006040518083038185875af1925050503d8060008114613bc6576040519150601f19603f3d011682016040523d82523d6000602084013e613bcb565b606091505b5091509150613bdb828286613be6565b979650505050505050565b60608315613bf5575081612e98565b825115613c055782518084602001fd5b8160405162461bcd60e51b81526004016108dc919061453c565b600082601f830112613c2f578081fd5b81356020613c44613c3f83614842565b614811565b82815281810190858301855b85811015613c7957613c67898684358b0101613c86565b84529284019290840190600101613c50565b5090979650505050505050565b600082601f830112613c96578081fd5b813567ffffffffffffffff811115613cb057613cb0614a6d565b613cc3601f8201601f1916602001614811565b818152846020838601011115613cd7578283fd5b816020850160208301379081016020019190915292915050565b600060808284031215613d02578081fd5b50919050565b803563ffffffff81168114610dc957600080fd5b600060208284031215613d2d578081fd5b8135612e9881614a83565b600080600060608486031215613d4c578182fd5b8335613d5781614a83565b92506020840135613d6781614a83565b91506040840135613d7781614a98565b809150509250925092565b60008060408385031215613d94578182fd5b8235613d9f81614a83565b946020939093013593505050565b60006020808385031215613dbf578182fd5b823567ffffffffffffffff811115613dd5578283fd5b8301601f81018513613de5578283fd5b8035613df3613c3f82614842565b8181528381019083850185840285018601891015613e0f578687fd5b8694505b83851015613e3a578035613e2681614a83565b835260019490940193918501918501613e13565b50979650505050505050565b60008060008060608587031215613e5b578081fd5b843567ffffffffffffffff80821115613e72578283fd5b818701915087601f830112613e85578283fd5b813581811115613e93578384fd5b8860208083028501011115613ea6578384fd5b6020928301965094509086013590613ebd82614a83565b90925060408601359080821115613ed2578283fd5b50613edf87828801613c1f565b91505092959194509250565b600060208284031215613efc578081fd5b8151612e9881614a98565b600060208284031215613f18578081fd5b5035919050565b600060208284031215613f30578081fd5b5051919050565b60008060408385031215613f49578182fd5b823591506020830135613f5b81614a83565b809150509250929050565b600060208284031215613f77578081fd5b81356001600160e01b031981168114612e98578182fd5b600080600080848603610100811215613fa5578283fd5b60a0811215613fb2578283fd5b5084935060a085013567ffffffffffffffff811115613fcf578283fd5b613fdb87828801613c86565b935050613fea60c08601613d08565b9396929550929360e00135925050565b6000806000838503610140811215614010578182fd5b60a081121561401d578182fd5b5061402860a0614811565b843561403381614a83565b8152602085013561404381614a83565b6020820152604085013561405681614a83565b60408201526060858101359082015260808086013590820152925060a084013567ffffffffffffffff81111561408a578182fd5b61409686828701613c86565b9250506140a68560c08601613cf1565b90509250925092565b6000806000606084860312156140c3578081fd5b8335925060208401356140d581614a83565b9150604084013567ffffffffffffffff8111156140f0578182fd5b6140fc86828701613c1f565b9150509250925092565b60008060408385031215614118578182fd5b82359150602083013567ffffffffffffffff811115614135578182fd5b61414185828601613c1f565b9150509250929050565b60006020828403121561415c578081fd5b612e9882613d08565b60008060408385031215614177578182fd5b61418083613d08565b91506020830135613f5b81614a83565b600080600080600080600060e0888a0312156141aa578485fd5b6141b388613d08565b965060208801356141c381614a83565b96999698505050506040850135946060810135946080820135945060a0820135935060c0909101359150565b60008060408385031215614201578182fd5b613d9f83613d08565b60008060006060848603121561421e578081fd5b61422784613d08565b925060208401359150604084013567ffffffffffffffff8111156140f0578182fd5b600081518084526142618160208601602086016149e3565b601f01601f19169290920160200192915050565b6002811061428557614285614a57565b9052565b63ffffffff81511682526020810151602083015260018060a01b03604082015116604083015260608101516142c960608401826001600160a01b03169052565b506080810151608083015260a081015160a083015260c081015160c083015260e081015161430260e08401826001600160a01b03169052565b506101008082015161340d82850182614275565b858152606085901b6001600160601b031916602082015260e084901b6001600160e01b031916603482015260006001600160fb1b03831115614356578081fd5b60208302808560388501379190910160380190815295945050505050565b93845260609290921b6001600160601b031916602084015260e01b6001600160e01b0319166034830152603882015260580190565b600082516143bb8184602087016149e3565b9190910192915050565b60007f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000825283516143fd8160178501602088016149e3565b7001034b99036b4b9b9b4b733903937b6329607d1b601791840191820152835161442e8160288401602088016149e3565b01602801949350505050565b60e09290921b6001600160e01b031916825260601b6001600160601b031916600482015260180190565b60e09290921b6001600160e01b0319168252600482015260240190565b600060408201848352602060408185015281855180845260608601915060608382028701019350828701855b828110156144db57605f198887030184526144c9868351614249565b955092840192908401906001016144ad565b509398975050505050505050565b60608101600485106144fd576144fd614a57565b93815263ffffffff92909216602083015260409091015290565b61014081016003841061452c5761452c614a57565b838252612e986020830184614289565b600060208252612e986020830184614249565b60208082526012908201527111549497d053149150511657d0d313d4d15160721b604082015260600190565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b6020808252600f908201526e11549497d1915157d393d517d4d155608a1b604082015260600190565b60208082526017908201527f4552525f494e56414c49445f59504f4f4c5f544f4b454e000000000000000000604082015260600190565b60208082526012908201527111549497d253959053125117d4d5d054125160721b604082015260600190565b6000833561463e81614a83565b6001600160a01b03908116835260208501359061465a82614a83565b908116602084015260408501359061467182614a83565b80821660408501525050606084013560608301526080840135608083015260c060a0830152613ab660c0830184614249565b600060018060a01b0380855116835280602086015116602084015280604086015116604084015250606084015160608301526080840151608083015260c060a0830152613ab660c0830184614249565b61012081016126818284614289565b888152610160810163ffffffff806147198b613d08565b16602084015260208a013561472d81614a83565b60018060a01b03811660408501525060408a013560608401528061475360608c01613d08565b166080840152506001600160a01b03881660a08301526001600160a01b03871660c08301528560e08301526147946101008301866001600160a01b03169052565b61012082019390935261014001529695505050505050565b63ffffffff8a168152602081018990526001600160a01b03888116604083015287811660608301526080820187905260a0820186905260c08201859052831660e08201526101208101614803610100830184614275565b9a9950505050505050505050565b604051601f8201601f1916810167ffffffffffffffff8111828210171561483a5761483a614a6d565b604052919050565b600067ffffffffffffffff82111561485c5761485c614a6d565b5060209081020190565b6000821982111561487957614879614a41565b500190565b60008261489957634e487b7160e01b81526012600452602481fd5b500490565b80825b60018086116148b057506148db565b8187048211156148c2576148c2614a41565b808616156148cf57918102915b9490941c9380026148a1565b94509492505050565b6000612e9860001984846000826148fd57506001612e98565b8161490a57506000612e98565b8160018114614920576002811461492a57614957565b6001915050612e98565b60ff84111561493b5761493b614a41565b6001841b91508482111561495157614951614a41565b50612e98565b5060208310610133831016604e8410600b8410161715614985575081810a838111156134ac576134ac614a41565b614992848484600161489e565b8086048211156149a4576149a4614a41565b02949350505050565b60008160001904831182151516156149c7576149c7614a41565b500290565b6000828210156149de576149de614a41565b500390565b60005b838110156149fe5781810151838201526020016149e6565b8381111561340d5750506000910152565b600081614a1e57614a1e614a41565b506000190190565b6000600019821415614a3a57614a3a614a41565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114610f0757600080fd5b8015158114610f0757600080fdfef206625bad3d9112d5609b8d356e6fbd514cd1f69980d4ce2b3e6e68e1789ace000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeea26469706673582212206f52a2a98de0a881bbf6b5103a30233fd98c89e14d9f16bfbc9435d9d6ca9de464736f6c63430008020033f206625bad3d9112d5609b8d356e6fbd514cd1f69980d4ce2b3e6e68e1789ace358933fb1b4f9e62c7cd3651025ad8825acb20ebbb23b09160e3867d71501ddd43ccaf94e5a0ff213b32419bf56f27f93e4170af0c4867ff3412f6aa5a22daf09f4e1c871d5fdd0aee1cd182666698a4492b24c6832aac230d07b11046af5a890000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b00000000000000000000000073ce60416035b8d7019f6399778c14ccf5c9c7a1000000000000000000000000000000000000000000000000000000000000a4b1

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

0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b00000000000000000000000073ce60416035b8d7019f6399778c14ccf5c9c7a1000000000000000000000000000000000000000000000000000000000000a4b1

-----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): 0x73ce60416035b8d7019f6399778c14ccf5c9c7a1
Arg [5] : _chainId (uint32): 42161

-----Encoded View---------------
6 Constructor Arguments found :
Arg [0] : 0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b
Arg [1] : 0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b
Arg [2] : 0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b
Arg [3] : 0000000000000000000000000132613b3a1061816f4661ad301612910e3cce0b
Arg [4] : 00000000000000000000000073ce60416035b8d7019f6399778c14ccf5c9c7a1
Arg [5] : 000000000000000000000000000000000000000000000000000000000000a4b1


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