ETH Price: $3,700.70 (+4.38%)

Contract

0xe63602a9B3DFE983187525AC985Fec4F57B24eD5
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Deposit180415752023-09-01 12:02:47455 days ago1693569767IN
0xe63602a9...F57B24eD5
0 ETH0.0031639622.43228451
Register Token180277782023-08-30 13:41:59457 days ago1693402919IN
0xe63602a9...F57B24eD5
0 ETH0.0034940230.71269689
Deposit179773912023-08-23 12:24:59464 days ago1692793499IN
0xe63602a9...F57B24eD5
0 ETH0.0018129215.27677468
Register Token179342782023-08-17 11:35:47470 days ago1692272147IN
0xe63602a9...F57B24eD5
0 ETH0.0021323418.74343259
Register Token179286072023-08-16 16:33:23471 days ago1692203603IN
0xe63602a9...F57B24eD5
0 ETH0.0037395332.87073788
Register Token179220522023-08-15 18:33:35472 days ago1692124415IN
0xe63602a9...F57B24eD5
0 ETH0.0039777534.96467133
Register Token179208702023-08-15 14:35:11472 days ago1692110111IN
0xe63602a9...F57B24eD5
0 ETH0.0039767834.95614229
Deposit178609572023-08-07 5:24:59481 days ago1691385899IN
0xe63602a9...F57B24eD5
0 ETH0.0017375411
Register Token178554142023-08-06 10:47:23481 days ago1691318843IN
0xe63602a9...F57B24eD5
0 ETH0.0012514111
Register Token177923692023-07-28 15:13:11490 days ago1690557191IN
0xe63602a9...F57B24eD5
0 ETH0.0057717950.73438919
Deposit177776422023-07-26 13:46:47492 days ago1690379207IN
0xe63602a9...F57B24eD5
0 ETH0.0052601741.00317281
Register Token177683812023-07-25 6:39:11494 days ago1690267151IN
0xe63602a9...F57B24eD5
0 ETH0.0019121816.80817607
Deposit177126342023-07-17 11:18:35501 days ago1689592715IN
0xe63602a9...F57B24eD5
0 ETH0.0023170718.06336493
Register Token176921762023-07-14 14:04:59504 days ago1689343499IN
0xe63602a9...F57B24eD5
0 ETH0.0059343352.16306743
Deposit176398372023-07-07 5:25:11512 days ago1688707511IN
0xe63602a9...F57B24eD5
0 ETH0.0033090220.2916688
Register Token176397912023-07-07 5:15:59512 days ago1688706959IN
0xe63602a9...F57B24eD5
0 ETH0.0022723719.97428267
Deposit176386672023-07-07 1:29:23512 days ago1688693363IN
0xe63602a9...F57B24eD5
0 ETH0.003194324.89969975
Deposit176259882023-07-05 6:45:35514 days ago1688539535IN
0xe63602a9...F57B24eD5
0 ETH0.0068458244.70422109
Register Token176256482023-07-05 5:37:11514 days ago1688535431IN
0xe63602a9...F57B24eD5
0 ETH0.0046916541.2398783
Deposit175747542023-06-28 2:09:35521 days ago1687918175IN
0xe63602a9...F57B24eD5
0 ETH0.0019701215.88196243
Deposit175697622023-06-27 9:16:35521 days ago1687857395IN
0xe63602a9...F57B24eD5
0 ETH0.0016191312.37059268
Deposit175329882023-06-22 5:08:23527 days ago1687410503IN
0xe63602a9...F57B24eD5
0 ETH0.0023867315.07040571
Deposit175149262023-06-19 16:17:23529 days ago1687191443IN
0xe63602a9...F57B24eD5
0 ETH0.0047170229.48142378
Deposit174824172023-06-15 2:47:11534 days ago1686797231IN
0xe63602a9...F57B24eD5
0 ETH0.0021781416.36926487
Deposit174645612023-06-12 14:27:11536 days ago1686580031IN
0xe63602a9...F57B24eD5
0 ETH0.0030356824.47421357
View all transactions

Latest 3 internal transactions

Advanced mode:
Parent Transaction Hash Block From To
172288092023-05-10 8:26:11569 days ago1683707171
0xe63602a9...F57B24eD5
0.01 ETH
171721132023-05-02 9:10:47577 days ago1683018647
0xe63602a9...F57B24eD5
0.01 ETH
171655472023-05-01 11:01:11578 days ago1682938871
0xe63602a9...F57B24eD5
0.01 ETH
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ExchangeV3

Compiler Version
v0.7.0+commit.9e61f92b

Optimization Enabled:
Yes with 1000000 runs

Other Settings:
default evmVersion, Apache-2.0 license
File 1 of 95 : ExchangeV3.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../lib/AddressUtil.sol";
import "../../lib/EIP712.sol";
import "../../lib/ERC20SafeTransfer.sol";
import "../../lib/MathUint.sol";
import "../../lib/ReentrancyGuard.sol";
import "../../thirdparty/proxies/OwnedUpgradabilityProxy.sol";
import "../iface/IAgentRegistry.sol";
import "../iface/IExchangeV3.sol";
import "../iface/IBlockVerifier.sol";
import "./libexchange/ExchangeAdmins.sol";
import "./libexchange/ExchangeBalances.sol";
import "./libexchange/ExchangeBlocks.sol";
import "./libexchange/ExchangeDeposits.sol";
import "./libexchange/ExchangeGenesis.sol";
import "./libexchange/ExchangeMode.sol";
import "./libexchange/ExchangeTokens.sol";
import "./libexchange/ExchangeWithdrawals.sol";

/// @title An Implementation of IExchangeV3.
/// @dev This contract supports upgradability proxy, therefore its constructor
///      must do NOTHING.
/// @author Brecht Devos - <[email protected]>
/// @author Daniel Wang  - <[email protected]>
contract ExchangeV3 is IExchangeV3, ReentrancyGuard
{
    using AddressUtil           for address;
    using ERC20SafeTransfer     for address;
    using MathUint              for uint;
    using ExchangeAdmins        for ExchangeData.State;
    using ExchangeBalances      for ExchangeData.State;
    using ExchangeBlocks        for ExchangeData.State;
    using ExchangeDeposits      for ExchangeData.State;
    using ExchangeGenesis       for ExchangeData.State;
    using ExchangeMode          for ExchangeData.State;
    using ExchangeTokens        for ExchangeData.State;
    using ExchangeWithdrawals   for ExchangeData.State;

    ExchangeData.State public state;
    bool public allowOnchainTransferFrom = false;

    modifier onlyWhenUninitialized()
    {
        require(
            address(state.loopring) == address(0) && state.merkleRoot == bytes32(0),
            "INITIALIZED"
        );
        _;
    }

    modifier onlyFromUserOrAgent(address from)
    {
        require(isUserOrAgent(from), "UNAUTHORIZED");
        _;
    }

    /// @dev The constructor must do NOTHING to support proxy.
    constructor() {}

    function version()
        public
        pure
        returns (string memory)
    {
        return "0.1.0";
    }

    function domainSeparator()
        external
        view
        returns (bytes32)
    {
        return state.DOMAIN_SEPARATOR;
    }

    // -- Initialization --
    function initialize(
        address _loopring,
        address _owner,
        bytes32 _genesisMerkleRoot,
        bytes32 _genesisMerkleAssetRoot
        )
        external
        override
        nonReentrant
        onlyWhenUninitialized
    {
        require(address(0) != _owner, "ZERO_ADDRESS");
        owner = _owner;

        state.initializeGenesisBlock(
            _loopring,
            _genesisMerkleRoot,
            _genesisMerkleAssetRoot,
            EIP712.hash(EIP712.Domain("DeGate Protocol", version(), address(this)))
        );
    }

    function setDepositContract(address _depositContract)
        external
        override
        nonReentrant
        onlyOwner
    {
        require(_depositContract != address(0), "ZERO_ADDRESS");
        // Only used for initialization
        require(state.depositContract == IDepositContract(0), "ALREADY_SET");
        state.depositContract = IDepositContract(_depositContract);

        emit DepositContractUpdate(_depositContract);
    }

    function getDepositContract()
        external
        override
        view
        returns (IDepositContract)
    {
        return state.depositContract;
    }

    function withdrawExchangeFees(
        address token,
        address recipient
        )
        external
        override
        nonReentrant
        onlyOwner
    {
        require(recipient != address(0), "INVALID_ADDRESS");

        if (token == address(0)) {
            uint amount = address(this).balance;
            recipient.sendETHAndVerify(amount, gasleft());
        } else {
            uint amount = ERC20(token).balanceOf(address(this));
            token.safeTransferAndVerify(recipient, amount);
        }

        emit WithdrawExchangeFees(token, recipient);
    }

    function setDepositParams(
        uint256 freeDepositMax,
        uint256 freeDepositRemained,
        uint256 freeSlotPerBlock,
        uint256 depositFee
        )
        external
        override
        nonReentrant
        onlyOwner
    {
        state.setDepositParams(
            freeDepositMax,
            freeDepositRemained,
            freeSlotPerBlock,
            depositFee
        );

        emit DepositParamsUpdate(freeDepositMax, freeDepositRemained, freeSlotPerBlock, depositFee);
    }

    function isUserOrAgent(address from)
        public
        view
        returns (bool)
    {
         return from == msg.sender ||
            state.agentRegistry != IAgentRegistry(address(0)) &&
            state.agentRegistry.isAgent(from, msg.sender);
    }

    // -- Constants --
    function getConstants()
        external
        override
        pure
        returns(ExchangeData.Constants memory)
    {
        return ExchangeData.Constants(
            uint(ExchangeData.SNARK_SCALAR_FIELD),
            uint(ExchangeData.MAX_OPEN_FORCED_REQUESTS),
            uint(ExchangeData.MAX_AGE_FORCED_REQUEST_UNTIL_WITHDRAW_MODE),
            uint(ExchangeData.TIMESTAMP_HALF_WINDOW_SIZE_IN_SECONDS),
            uint(ExchangeData.MAX_NUM_ACCOUNTS),
            uint(ExchangeData.MAX_NUM_TOKENS),
            uint(ExchangeData.MIN_AGE_PROTOCOL_FEES_UNTIL_UPDATED),
            uint(ExchangeData.MIN_TIME_IN_SHUTDOWN),
            uint(ExchangeData.TX_DATA_AVAILABILITY_SIZE),
            uint(ExchangeData.MAX_AGE_DEPOSIT_UNTIL_WITHDRAWABLE_UPPERBOUND),
            uint(ExchangeData.MAX_FORCED_WITHDRAWAL_FEE),
            uint(ExchangeData.DEFAULT_PROTOCOL_FEE_BIPS)
        );
    }

    // -- Mode --
    function isInWithdrawalMode()
        external
        override
        view
        returns (bool)
    {
        return state.isInWithdrawalMode();
    }

    function isShutdown()
        external
        override
        view
        returns (bool)
    {
        return state.isShutdown();
    }

    // -- Tokens --

    function registerToken(
        address tokenAddress
        )
        external
        override
        nonReentrant
        returns (uint32)
    {
        return state.registerToken(tokenAddress, msg.sender == owner);
    }

    function getTokenID(
        address tokenAddress
        )
        external
        override
        view
        returns (uint32)
    {
        return state.getTokenID(tokenAddress);
    }

    function getTokenAddress(
        uint32 tokenID
        )
        external
        override
        view
        returns (address)
    {
        return state.getTokenAddress(tokenID);
    }

    // -- Stakes --
    function getExchangeStake()
        external
        override
        view
        returns (uint)
    {
        return state.loopring.getExchangeStake(address(this));
    }

    function withdrawExchangeStake(
        address recipient
        )
        external
        override
        nonReentrant
        onlyOwner
        returns (uint)
    {
        return state.withdrawExchangeStake(recipient);
    }

    function getProtocolFeeLastWithdrawnTime(
        address tokenAddress
        )
        external
        override
        view
        returns (uint)
    {
        return state.protocolFeeLastWithdrawnTime[tokenAddress];
    }

    function burnExchangeStake()
        external
        override
        nonReentrant
    {
        // Allow burning the complete exchange stake when the exchange gets into withdrawal mode
        if (state.isInWithdrawalMode()) {
            // Burn the complete stake of the exchange
            uint stake = state.loopring.getExchangeStake(address(this));
            state.loopring.burnExchangeStake(stake);
        }
    }

    // -- Blocks --
    function getMerkleRoot()
        external
        override
        view
        returns (bytes32)
    {
        return state.merkleRoot;
    }

    // -- Blocks --
    function getMerkleAssetRoot()
        external
        override
        view
        returns (bytes32)
    {
        return state.merkleAssetRoot;
    }

    function getBlockHeight()
        external
        override
        view
        returns (uint)
    {
        return state.numBlocks;
    }

    function getBlockInfo(uint blockIdx)
        external
        override
        view
        returns (ExchangeData.BlockInfo memory)
    {
        return state.blocks[blockIdx];
    }

    function submitBlocks(ExchangeData.Block[] calldata blocks)
        external
        override
        nonReentrant
        onlyOwner
    {
        state.submitBlocks(blocks);
    }

    function getNumAvailableForcedSlots()
        external
        override
        view
        returns (uint)
    {
        return state.getNumAvailableForcedSlots();
    }

    // -- Deposits --

    function deposit(
        address from,
        address to,
        address tokenAddress,
        uint248  amount,
        bytes   calldata extraData
        )
        external
        payable
        override
        nonReentrant
        onlyFromUserOrAgent(from)
    {
        state.deposit(from, to, tokenAddress, amount, extraData);
    }

    function getPendingDepositAmount(
        address from,
        address tokenAddress
        )
        external
        override
        view
        returns (uint248)
    {
        uint32 tokenID = state.getTokenID(tokenAddress);
        return state.pendingDeposits[from][tokenID].amount;
    }

    // -- Withdrawals --

    function forceWithdraw(
        address from,
        address token,
        uint32  accountID
        )
        external
        override
        nonReentrant
        payable
        onlyFromUserOrAgent(from)
    {
        state.forceWithdraw(from, token, accountID);
    }

    function isForcedWithdrawalPending(
        uint32  accountID,
        address token
        )
        external
        override
        view
        returns (bool)
    {
        uint32 tokenID = state.getTokenID(token);
        return state.pendingForcedWithdrawals[accountID][tokenID].timestamp != 0;
    }

    // We still alow anyone to withdraw these funds for the account owner
    function withdrawFromMerkleTree(
        ExchangeData.MerkleProof calldata merkleProof
        )
        external
        override
        nonReentrant
    {
        state.withdrawFromMerkleTree(merkleProof);
    }

    function isWithdrawnInWithdrawalMode(
        uint32  accountID,
        address token
        )
        external
        override
        view
        returns (bool)
    {
        uint32 tokenID = state.getTokenID(token);
        return state.withdrawnInWithdrawMode[accountID][tokenID];
    }

    function withdrawFromDepositRequest(
        address from,
        address token
        )
        external
        override
        nonReentrant
    {
        state.withdrawFromDepositRequest(
            from,
            token
        );
    }

    function withdrawFromApprovedWithdrawals(
        address[] calldata owners,
        address[] calldata tokens
        )
        external
        override
        nonReentrant
    {
        state.withdrawFromApprovedWithdrawals(
            owners,
            tokens
        );
    }

    function getAmountWithdrawable(
        address from,
        address token
        )
        external
        override
        view
        returns (uint)
    {
        uint32 tokenID = state.getTokenID(token);
        return state.amountWithdrawable[from][tokenID];
    }

    function notifyForcedRequestTooOld(
        uint32  accountID,
        address token
        )
        external
        override
        nonReentrant
    {
        uint32 tokenID = state.getTokenID(token);
        ExchangeData.ForcedWithdrawal storage withdrawal = state.pendingForcedWithdrawals[accountID][tokenID];
        require(withdrawal.timestamp != 0, "WITHDRAWAL_NOT_TOO_OLD");

        // Check if the withdrawal has indeed exceeded the time limit
        require(block.timestamp >= withdrawal.timestamp + ExchangeData.MAX_AGE_FORCED_REQUEST_UNTIL_WITHDRAW_MODE, "WITHDRAWAL_NOT_TOO_OLD");

        // Enter withdrawal mode
        state.modeTime.withdrawalModeStartTime = block.timestamp;

        emit WithdrawalModeActivated(state.modeTime.withdrawalModeStartTime);
    }

    function setWithdrawalRecipient(
        address from,
        address to,
        address token,
        uint248  amount,
        uint32  storageID,
        address newRecipient
        )
        external
        override
        nonReentrant
        onlyFromUserOrAgent(from)
    {
        require(newRecipient != address(0), "INVALID_DATA");
        uint32 tokenID = state.getTokenID(token);
        require(state.withdrawalRecipient[from][to][tokenID][amount][storageID] == address(0), "CANNOT_OVERRIDE_RECIPIENT_ADDRESS");
        state.withdrawalRecipient[from][to][tokenID][amount][storageID] = newRecipient;

        emit WithdrawalRecipientUpdate(from, to, token, amount, storageID, newRecipient);
    }

    function getWithdrawalRecipient(
        address from,
        address to,
        address token,
        uint248  amount,
        uint32  storageID
        )
        external
        override
        view
        returns (address)
    {
        uint32 tokenID = state.getTokenID(token);
        return state.withdrawalRecipient[from][to][tokenID][amount][storageID];
    }

    function onchainTransferFrom(
        address from,
        address to,
        address token,
        uint    amount
        )
        external
        override
        nonReentrant
        onlyFromUserOrAgent(from)
    {
        require(allowOnchainTransferFrom, "NOT_ALLOWED");
        state.depositContract.transfer(from, to, token, amount);
    }

    function approveTransaction(
        address from,
        bytes32 transactionHash
        )
        external
        override
        nonReentrant
        onlyFromUserOrAgent(from)
    {
        state.approvedTx[from][transactionHash] = true;
        emit TransactionApproved(from, transactionHash);
    }

    function approveTransactions(
        address[] calldata owners,
        bytes32[] calldata transactionHashes
        )
        external
        override
        nonReentrant
    {
        require(owners.length == transactionHashes.length, "INVALID_DATA");
        require(state.agentRegistry.isAgent(owners, msg.sender), "UNAUTHORIZED");
        for (uint i = 0; i < owners.length; i++) {
            state.approvedTx[owners[i]][transactionHashes[i]] = true;
        }
        emit TransactionsApproved(owners, transactionHashes);
    }

    function isTransactionApproved(
        address from,
        bytes32 transactionHash
        )
        external
        override
        view
        returns (bool)
    {
        return state.approvedTx[from][transactionHash];
    }

    function getDomainSeparator()
        external
        override
        view
        returns (bytes32)
    {
        return state.DOMAIN_SEPARATOR;
    }

    // -- Admins --
    function setMaxAgeDepositUntilWithdrawable(
        uint32 newValue
        )
        external
        override
        nonReentrant
        onlyOwner
        returns (uint32)
    {
        return state.setMaxAgeDepositUntilWithdrawable(newValue);
    }

    function getMaxAgeDepositUntilWithdrawable()
        external
        override
        view
        returns (uint32)
    {
        return state.maxAgeDepositUntilWithdrawable;
    }

    function shutdown()
        external
        override
        nonReentrant
        onlyOwner
        returns (bool success)
    {
        require(!state.isInWithdrawalMode(), "INVALID_MODE");
        require(!state.isShutdown(), "ALREADY_SHUTDOWN");
        state.modeTime.shutdownModeStartTime = block.timestamp;
        emit Shutdown(state.modeTime.shutdownModeStartTime);
        return true;
    }

    function getProtocolFeeValues()
        external
        override
        view
        returns (
            uint32 syncedAt,
            uint16 protocolFeeBips,
            uint16 previousProtocolFeeBips,
            uint32 executeTimeOfNextProtocolFeeBips,
            uint16 nextProtocolFeeBips
        )
    {
        syncedAt = state.protocolFeeData.syncedAt;
        protocolFeeBips = state.protocolFeeData.protocolFeeBips;
        previousProtocolFeeBips = state.protocolFeeData.previousProtocolFeeBips;
        executeTimeOfNextProtocolFeeBips = state.protocolFeeData.executeTimeOfNextProtocolFeeBips;
        nextProtocolFeeBips = state.protocolFeeData.nextProtocolFeeBips;
    }

    function setAllowOnchainTransferFrom(bool value)
        external
        nonReentrant
        onlyOwner
    {
        require(allowOnchainTransferFrom != value, "SAME_VALUE");
        allowOnchainTransferFrom = value;

        emit AllowOnchainTransferFrom(value);
    }

    function getUnconfirmedBalance(address token)
        external
        override
        view
        returns(uint256)
    {
        uint32 tokenId = state.getTokenID(token);

        uint256 unconfirmedBalance = 0;

        if (tokenId == 0) {
            unconfirmedBalance = address(state.depositContract).balance.sub(state.tokenIdToDepositBalance[tokenId]);
        } else {
            unconfirmedBalance = ERC20(token).balanceOf(address(state.depositContract)).sub(state.tokenIdToDepositBalance[tokenId]);
        }
        return unconfirmedBalance;
    }

    function getFreeDepositRemained()
        external
        override
        view
        returns(uint256)
    {
        return state.depositState.freeDepositRemained;
    }

    function getDepositBalance(address token)
        external
        override
        view
        returns(uint248)
    {
        uint32 tokenId = state.getTokenID(token);

        return state.tokenIdToDepositBalance[tokenId];
    }

}

File 2 of 95 : AddressUtil.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;


/// @title Utility Functions for addresses
/// @author Daniel Wang - <[email protected]>
/// @author Brecht Devos - <[email protected]>
library AddressUtil
{
    using AddressUtil for *;

    function isContract(
        address addr
        )
        internal
        view
        returns (bool)
    {
        // According to EIP-1052, 0x0 is the value returned for not-yet created accounts
        // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
        // for accounts without code, i.e. `keccak256('')`
        bytes32 codehash;
        // solhint-disable-next-line no-inline-assembly
        assembly { codehash := extcodehash(addr) }
        return (codehash != 0x0 &&
                codehash != 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470);
    }

    function toPayable(
        address addr
        )
        internal
        pure
        returns (address payable)
    {
        return payable(addr);
    }

    // Works like address.send but with a customizable gas limit
    // Make sure your code is safe for reentrancy when using this function!
    function sendETH(
        address to,
        uint    amount,
        uint    gasLimit
        )
        internal
        returns (bool success)
    {
        if (amount == 0) {
            return true;
        }
        address payable recipient = to.toPayable();
        /* solium-disable-next-line */
        (success, ) = recipient.call{value: amount, gas: gasLimit}("");
    }

    // Works like address.transfer but with a customizable gas limit
    // Make sure your code is safe for reentrancy when using this function!
    function sendETHAndVerify(
        address to,
        uint    amount,
        uint    gasLimit
        )
        internal
        returns (bool success)
    {
        success = to.sendETH(amount, gasLimit);
        require(success, "TRANSFER_FAILURE");
    }

    // Works like call but is slightly more efficient when data
    // needs to be copied from memory to do the call.
    function fastCall(
        address to,
        uint    gasLimit,
        uint    value,
        bytes   memory data
        )
        internal
        returns (bool success, bytes memory returnData)
    {
        if (to != address(0)) {
            assembly {
                // Do the call
                success := call(gasLimit, to, value, add(data, 32), mload(data), 0, 0)
                // Copy the return data
                let size := returndatasize()
                returnData := mload(0x40)
                mstore(returnData, size)
                returndatacopy(add(returnData, 32), 0, size)
                // Update free memory pointer
                mstore(0x40, add(returnData, add(32, size)))
            }
        }
    }

    // Like fastCall, but throws when the call is unsuccessful.
    function fastCallAndVerify(
        address to,
        uint    gasLimit,
        uint    value,
        bytes   memory data
        )
        internal
        returns (bytes memory returnData)
    {
        bool success;
        (success, returnData) = fastCall(to, gasLimit, value, data);
        if (!success) {
            assembly {
                revert(add(returnData, 32), mload(returnData))
            }
        }
    }
}

File 3 of 95 : EIP712.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;


library EIP712
{
    struct Domain {
        string  name;
        string  version;
        address verifyingContract;
    }

    bytes32 constant internal EIP712_DOMAIN_TYPEHASH = keccak256(
        "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
    );

    string constant internal EIP191_HEADER = "\x19\x01";

    function hash(Domain memory domain)
        internal
        pure
        returns (bytes32)
    {
        uint _chainid;
        assembly { _chainid := chainid() }

        return keccak256(
            abi.encode(
                EIP712_DOMAIN_TYPEHASH,
                keccak256(bytes(domain.name)),
                keccak256(bytes(domain.version)),
                _chainid,
                domain.verifyingContract
            )
        );
    }

    function hashPacked(
        bytes32 domainHash,
        bytes32 dataHash
        )
        internal
        pure
        returns (bytes32)
    {
        return keccak256(
            abi.encodePacked(
                EIP191_HEADER,
                domainHash,
                dataHash
            )
        );
    }
}

File 4 of 95 : ERC20SafeTransfer.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;


/// @title ERC20 safe transfer
/// @dev see https://github.com/sec-bit/badERC20Fix
/// @author Brecht Devos - <[email protected]>
library ERC20SafeTransfer
{
    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;
    }

    function safeTransferAndVerify(
        address token,
        address to,
        uint    value
        )
        internal
    {
        safeTransferWithGasLimitAndVerify(
            token,
            to,
            value,
            gasleft()
        );
    }

    function safeTransfer(
        address token,
        address to,
        uint    value
        )
        internal
        returns (bool)
    {
        return safeTransferWithGasLimit(
            token,
            to,
            value,
            gasleft()
        );
    }

    function safeTransferWithGasLimitAndVerify(
        address token,
        address to,
        uint    value,
        uint    gasLimit
        )
        internal
    {
        require(
            safeTransferWithGasLimit(token, to, value, gasLimit),
            "TRANSFER_FAILURE"
        );
    }

    function safeTransferWithGasLimit(
        address token,
        address to,
        uint    value,
        uint    gasLimit
        )
        internal
        returns (bool)
    {
        // A transfer is successful when 'call' is successful and depending on the token:
        // - No value is returned: we assume a revert when the transfer failed (i.e. 'call' returns false)
        // - A single boolean is returned: this boolean needs to be true (non-zero)

        require(isContract(token), "ERC20SafeTransfer: call to non-contract");

        // bytes4(keccak256("transfer(address,uint256)")) = 0xa9059cbb
        bytes memory callData = abi.encodeWithSelector(
            bytes4(0xa9059cbb),
            to,
            value
        );
        (bool success, ) = token.call{gas: gasLimit}(callData);
        return checkReturnValue(success);
    }

    function safeTransferFromAndVerify(
        address token,
        address from,
        address to,
        uint    value
        )
        internal
    {
        safeTransferFromWithGasLimitAndVerify(
            token,
            from,
            to,
            value,
            gasleft()
        );
    }

    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint    value
        )
        internal
        returns (bool)
    {
        return safeTransferFromWithGasLimit(
            token,
            from,
            to,
            value,
            gasleft()
        );
    }

    function safeTransferFromWithGasLimitAndVerify(
        address token,
        address from,
        address to,
        uint    value,
        uint    gasLimit
        )
        internal
    {
        bool result = safeTransferFromWithGasLimit(
            token,
            from,
            to,
            value,
            gasLimit
        );
        require(result, "TRANSFER_FAILURE");
    }

    function safeTransferFromWithGasLimit(
        address token,
        address from,
        address to,
        uint    value,
        uint    gasLimit
        )
        internal
        returns (bool)
    {
        // A transferFrom is successful when 'call' is successful and depending on the token:
        // - No value is returned: we assume a revert when the transfer failed (i.e. 'call' returns false)
        // - A single boolean is returned: this boolean needs to be true (non-zero)

        require(isContract(token), "ERC20SafeTransfer: call to non-contract");

        // bytes4(keccak256("transferFrom(address,address,uint256)")) = 0x23b872dd
        bytes memory callData = abi.encodeWithSelector(
            bytes4(0x23b872dd),
            from,
            to,
            value
        );
        (bool success, ) = token.call{gas: gasLimit}(callData);
        return checkReturnValue(success);
    }

    function checkReturnValue(
        bool success
        )
        internal
        pure
        returns (bool)
    {
        // A transfer/transferFrom is successful when 'call' is successful and depending on the token:
        // - No value is returned: we assume a revert when the transfer failed (i.e. 'call' returns false)
        // - A single boolean is returned: this boolean needs to be true (non-zero)
        if (success) {
            assembly {
                switch returndatasize()
                // Non-standard ERC20: nothing is returned so if 'call' was successful we assume the transfer succeeded
                case 0 {
                    success := 1
                }
                // Standard ERC20: a single boolean value is returned which needs to be true
                case 32 {
                    returndatacopy(0, 0, 32)
                    success := mload(0)
                }
                // None of the above: not successful
                default {
                    success := 0
                }
            }
        }
        return success;
    }
}

File 5 of 95 : MathUint.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;


/// @title Utility Functions for uint
/// @author Daniel Wang - <[email protected]>
library MathUint
{
    using MathUint for uint;

    function mul(
        uint a,
        uint b
        )
        internal
        pure
        returns (uint c)
    {
        c = a * b;
        require(a == 0 || c / a == b, "MUL_OVERFLOW");
    }

    function sub(
        uint a,
        uint b
        )
        internal
        pure
        returns (uint)
    {
        require(b <= a, "SUB_UNDERFLOW");
        return a - b;
    }

    function add(
        uint a,
        uint b
        )
        internal
        pure
        returns (uint c)
    {
        c = a + b;
        require(c >= a, "ADD_OVERFLOW");
    }

    function add64(
        uint64 a,
        uint64 b
        )
        internal
        pure
        returns (uint64 c)
    {
        c = a + b;
        require(c >= a, "ADD_OVERFLOW");
    }
}

File 6 of 95 : ReentrancyGuard.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;


/// @title ReentrancyGuard
/// @author Brecht Devos - <[email protected]>
/// @dev Exposes a modifier that guards a function against reentrancy
///      Changing the value of the same storage value multiple times in a transaction
///      is cheap (starting from Istanbul) so there is no need to minimize
///      the number of times the value is changed
contract ReentrancyGuard
{
    //The default value must be 0 in order to work behind a proxy.
    uint private _guardValue;

    // Use this modifier on a function to prevent reentrancy
    modifier nonReentrant()
    {
        // Check if the guard value has its original value
        require(_guardValue == 0, "REENTRANCY");

        // Set the value to something else
        _guardValue = 1;

        // Function body
        _;

        // Set the value back
        _guardValue = 0;
    }
}

File 7 of 95 : OwnedUpgradabilityProxy.sol
// SPDX-License-Identifier: UNLICENSED
// This code is taken from https://github.com/OpenZeppelin/openzeppelin-labs
// with minor modifications.
pragma solidity ^0.7.0;

import './UpgradabilityProxy.sol';


/**
 * @title OwnedUpgradabilityProxy
 * @dev This contract combines an upgradeability proxy with basic authorization control functionalities
 */
contract OwnedUpgradabilityProxy is UpgradeabilityProxy {
  /**
  * @dev Event to show ownership has been transferred
  * @param previousOwner representing the address of the previous owner
  * @param newOwner representing the address of the new owner
  */
  event ProxyOwnershipTransferred(address previousOwner, address newOwner);

  // Storage position of the owner of the contract
  bytes32 private constant proxyOwnerPosition = keccak256("org.zeppelinos.proxy.owner");

  /**
  * @dev the constructor sets the original owner of the contract to the sender account.
  */
  constructor() {
    setUpgradabilityOwner(msg.sender);
  }

  /**
  * @dev Throws if called by any account other than the owner.
  */
  modifier onlyProxyOwner() {
    require(msg.sender == proxyOwner());
    _;
  }

  /**
   * @dev Tells the address of the owner
   * @return owner the address of the owner
   */
  function proxyOwner() public view returns (address owner) {
    bytes32 position = proxyOwnerPosition;
    assembly {
      owner := sload(position)
    }
  }

  /**
   * @dev Sets the address of the owner
   */
  function setUpgradabilityOwner(address newProxyOwner) internal {
    bytes32 position = proxyOwnerPosition;
    assembly {
      sstore(position, newProxyOwner)
    }
  }

  /**
   * @dev Allows the current owner to transfer control of the contract to a newOwner.
   * @param newOwner The address to transfer ownership to.
   */
  function transferProxyOwnership(address newOwner) public onlyProxyOwner {
    require(newOwner != address(0));
    emit ProxyOwnershipTransferred(proxyOwner(), newOwner);
    setUpgradabilityOwner(newOwner);
  }

  /**
   * @dev Allows the proxy owner to upgrade the current version of the proxy.
   * @param implementation representing the address of the new implementation to be set.
   */
  function upgradeTo(address implementation) public onlyProxyOwner {
    _upgradeTo(implementation);
  }

  /**
   * @dev Allows the proxy owner to upgrade the current version of the proxy and call the new implementation
   * to initialize whatever is needed through a low level call.
   * @param implementation representing the address of the new implementation to be set.
   * @param data represents the msg.data to bet sent in the low level call. This parameter may include the function
   * signature of the implementation to be called with the needed payload
   */
  function upgradeToAndCall(address implementation, bytes memory data) payable public onlyProxyOwner {
    upgradeTo(implementation);
    (bool success, ) = address(this).call{value: msg.value}(data);
    require(success);
  }
}

File 8 of 95 : UpgradabilityProxy.sol
// SPDX-License-Identifier: UNLICENSED
// This code is taken from https://github.com/OpenZeppelin/openzeppelin-labs
// with minor modifications.
pragma solidity ^0.7.0;

import './Proxy.sol';


/**
 * @title UpgradeabilityProxy
 * @dev This contract represents a proxy where the implementation address to which it will delegate can be upgraded
 */
contract UpgradeabilityProxy is Proxy {
  /**
   * @dev This event will be emitted every time the implementation gets upgraded
   * @param implementation representing the address of the upgraded implementation
   */
  event Upgraded(address indexed implementation);

  // Storage position of the address of the current implementation
  bytes32 private constant implementationPosition = keccak256("org.zeppelinos.proxy.implementation");

  /**
   * @dev Constructor function
   */
  constructor() {}

  /**
   * @dev Tells the address of the current implementation
   * @return impl address of the current implementation
   */
  function implementation() public view override returns (address impl) {
    bytes32 position = implementationPosition;
    assembly {
      impl := sload(position)
    }
  }

  /**
   * @dev Sets the address of the current implementation
   * @param newImplementation address representing the new implementation to be set
   */
  function setImplementation(address newImplementation) internal {
    bytes32 position = implementationPosition;
    assembly {
      sstore(position, newImplementation)
    }
  }

  /**
   * @dev Upgrades the implementation address
   * @param newImplementation representing the address of the new implementation to be set
   */
  function _upgradeTo(address newImplementation) internal {
    address currentImplementation = implementation();
    require(currentImplementation != newImplementation);
    setImplementation(newImplementation);
    emit Upgraded(newImplementation);
  }
}

File 9 of 95 : Proxy.sol
// SPDX-License-Identifier: UNLICENSED
// This code is taken from https://github.com/OpenZeppelin/openzeppelin-labs
// with minor modifications.
pragma solidity ^0.7.0;

/**
 * @title Proxy
 * @dev Gives the possibility to delegate any call to a foreign implementation.
 */
abstract contract Proxy {
  /**
  * @dev Tells the address of the implementation where every call will be delegated.
  * @return impl address of the implementation to which it will be delegated
  */
  function implementation() public view virtual returns (address impl);

  receive() payable external {
    _fallback();
  }

  fallback() payable external {
    _fallback();
  }

  function _fallback() private {
    address _impl = implementation();
    require(_impl != address(0));

    assembly {
      let ptr := mload(0x40)
      calldatacopy(ptr, 0, calldatasize())
      let result := delegatecall(gas(), _impl, ptr, calldatasize(), 0, 0)
      let size := returndatasize()
      returndatacopy(ptr, 0, size)

      switch result
      case 0 { revert(ptr, size) }
      default { return(ptr, size) }
    }
  }
}

File 10 of 95 : IAgentRegistry.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

interface IAgent{}

abstract contract IAgentRegistry
{
    /// @dev Returns whether an agent address is an agent of an account owner
    /// @param owner The account owner.
    /// @param agent The agent address
    /// @return True if the agent address is an agent for the account owner, else false
    function isAgent(
        address owner,
        address agent
        )
        external
        virtual
        view
        returns (bool);

    /// @dev Returns whether an agent address is an agent of all account owners
    /// @param owners The account owners.
    /// @param agent The agent address
    /// @return True if the agent address is an agent for the account owner, else false
    function isAgent(
        address[] calldata owners,
        address            agent
        )
        external
        virtual
        view
        returns (bool);

    /// @dev Returns whether an agent address is a universal agent.
    /// @param agent The agent address
    /// @return True if the agent address is a universal agent, else false
    function isUniversalAgent(address agent)
        public
        virtual
        view
        returns (bool);
}

File 11 of 95 : IExchangeV3.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../lib/Claimable.sol";
import "./ExchangeData.sol";

/// @title IExchangeV3
/// @dev Note that Claimable and RentrancyGuard are inherited here to
///      ensure all data members are declared on IExchangeV3 to make it
///      easy to support upgradability through proxies.
///
///      Subclasses of this contract must NOT define constructor to
///      initialize data.
///
/// @author Brecht Devos - <[email protected]>
/// @author Daniel Wang  - <[email protected]>
abstract contract IExchangeV3 is Claimable
{
    // -- Events --

    event ExchangeCloned(
        address exchangeAddress,
        address owner,
        bytes32 genesisMerkleRoot
    );

    event TokenRegistered(
        address token,
        uint32  tokenId
    );

    event Shutdown(
        uint timestamp
    );

    event WithdrawalModeActivated(
        uint timestamp
    );

    event BlockSubmitted(
        uint    indexed blockIdx,
        bytes32         merkleRoot,
        bytes32         publicDataHash
    );

    event DepositRequested(
        address from,
        address to,
        address token,
        uint32  tokenId,
        uint248  amount
    );

    event ForcedWithdrawalRequested(
        address owner,
        address token,
        uint32  accountID
    );

    event WithdrawalCompleted(
        uint8   category,
        address from,
        address to,
        address token,
        uint    amount
    );

    event WithdrawalFailed(
        uint8   category,
        address from,
        address to,
        address token,
        uint    amount
    );

    event ProtocolFeesUpdated(
        uint16 protocolFeeBips,
        uint16 previousProtocolFeeBips
    );

    event TransactionApproved(
        address owner,
        bytes32 transactionHash
    );

    event TransactionsApproved(
        address[] owners,
        bytes32[] transactionHashes
    );

    event BlockVerifierRefreshed(address blockVerifier);
    event DepositContractUpdate(address depositContract);
    event WithdrawExchangeFees(address token, address recipient);

    event WithdrawalRecipientUpdate(
        address from,
        address to,
        address token,
        uint248 amount,
        uint32 storageID,
        address newRecipient
    );

    event DepositParamsUpdate(
        uint256 freeDepositMax,
        uint256 freeDepositRemained,
        uint256 freeSlotPerBlock,
        uint256 depositFee
    );

    event AllowOnchainTransferFrom(bool value);

    // -- Initialization --
    /// @dev Initializes this exchange. This method can only be called once.
    /// @param  loopring The LoopringV3 contract address.
    /// @param  owner The owner of this exchange.
    /// @param  genesisMerkleRoot The initial Merkle tree state.
    /// @param  genesisMerkleAssetRoot The initial Asset Merkle tree state.
    function initialize(
        address loopring,
        address owner,
        bytes32 genesisMerkleRoot,
        bytes32 genesisMerkleAssetRoot
        )
        virtual
        external;

    ///      Can only be called by the exchange owner once.
    /// @param depositContract The deposit contract to be used
    function setDepositContract(address depositContract)
        external
        virtual;

    /// @dev Gets the deposit contract used by the exchange.
    /// @return the deposit contract
    function getDepositContract()
        external
        virtual
        view
        returns (IDepositContract);

    // @dev Exchange owner set params for deposit.
    // @param freeDepositMax Max slots for free deposit
    // @param freeDepositRemained Remained free deposit
    // @param freeSlotPerBlock Free slot for every block
    // @param depositFee Deposit fee in ETH
    function setDepositParams(
        uint256 freeDepositMax,
        uint256 freeDepositRemained,
        uint256 freeSlotPerBlock,
        uint256 depositFee
    ) external virtual;

    // @dev Exchange owner withdraws fees from the exchange.
    // @param token Fee token address
    // @param feeRecipient Fee recipient address
    function withdrawExchangeFees(
        address token,
        address feeRecipient
        )
        external
        virtual;

    // -- Constants --
    /// @dev Returns a list of constants used by the exchange.
    /// @return constants The list of constants.
    function getConstants()
        external
        virtual
        pure
        returns(ExchangeData.Constants memory);

    // -- Mode --
    /// @dev Returns hether the exchange is in withdrawal mode.
    /// @return Returns true if the exchange is in withdrawal mode, else false.
    function isInWithdrawalMode()
        external
        virtual
        view
        returns (bool);

    /// @dev Returns whether the exchange is shutdown.
    /// @return Returns true if the exchange is shutdown, else false.
    function isShutdown()
        external
        virtual
        view
        returns (bool);

    // -- Tokens --
    /// @dev Registers an ERC20 token for a token id. Note that different exchanges may have
    ///      different ids for the same ERC20 token.
    ///
    ///      Please note that 1 is reserved for Ether (ETH), 2 is reserved for Wrapped Ether (ETH),
    ///      and 3 is reserved for Loopring Token (LRC).
    ///
    ///      This function is only callable by the exchange owner.
    ///
    /// @param  tokenAddress The token's address
    /// @return tokenID The token's ID in this exchanges.
    function registerToken(
        address tokenAddress
        )
        external
        virtual
        returns (uint32 tokenID);

    /// @dev Returns the id of a registered token.
    /// @param  tokenAddress The token's address
    /// @return tokenID The token's ID in this exchanges.
    function getTokenID(
        address tokenAddress
        )
        external
        virtual
        view
        returns (uint32 tokenID);

    /// @dev Returns the address of a registered token.
    /// @param  tokenID The token's ID in this exchanges.
    /// @return tokenAddress The token's address
    function getTokenAddress(
        uint32 tokenID
        )
        external
        virtual
        view
        returns (address tokenAddress);

    // -- Stakes --
    /// @dev Gets the amount of LRC the owner has staked onchain for this exchange.
    ///      The stake will be burned if the exchange does not fulfill its duty by
    ///      processing user requests in time. Please note that order matching may potentially
    ///      performed by another party and is not part of the exchange's duty.
    ///
    /// @return The amount of LRC staked
    function getExchangeStake()
        external
        virtual
        view
        returns (uint);

    /// @dev Withdraws the amount staked for this exchange.
    ///      This can only be done if the exchange has been correctly shutdown:
    ///      - The exchange owner has shutdown the exchange
    ///      - All deposit requests are processed
    ///      - All funds are returned to the users (merkle root is reset to initial state)
    ///
    ///      Can only be called by the exchange owner.
    ///
    /// @return amountLRC The amount of LRC withdrawn
    function withdrawExchangeStake(
        address recipient
        )
        external
        virtual
        returns (uint amountLRC);

    /// @dev Can by called by anyone to burn the stake of the exchange when certain
    ///      conditions are fulfilled.
    ///
    ///      Currently this will only burn the stake of the exchange if
    ///      the exchange is in withdrawal mode.
    function burnExchangeStake()
        external
        virtual;

    // -- Blocks --

    /// @dev Gets the current Merkle root of this exchange's virtual blockchain.
    /// @return The current Merkle root.
    function getMerkleRoot()
        external
        virtual
        view
        returns (bytes32);

    /// @dev Gets the current Asset Merkle root of this exchange's virtual blockchain.
    /// @return The current Asset Merkle root.
    function getMerkleAssetRoot()
        external
        virtual
        view
        returns (bytes32);

    /// @dev Gets the height of this exchange's virtual blockchain. The block height for a
    ///      new exchange is 1.
    /// @return The virtual blockchain height which is the index of the last block.
    function getBlockHeight()
        external
        virtual
        view
        returns (uint);

    /// @dev Gets some minimal info of a previously submitted block that's kept onchain.
    ///      A DEX can use this function to implement a payment receipt verification
    ///      contract with a challange-response scheme.
    /// @param blockIdx The block index.
    function getBlockInfo(uint blockIdx)
        external
        virtual
        view
        returns (ExchangeData.BlockInfo memory);

    /// @dev Sumbits new blocks to the rollup blockchain.
    ///
    ///      This function can only be called by the exchange operator.
    ///
    /// @param blocks The blocks being submitted
    ///      - blockType: The type of the new block
    ///      - blockSize: The number of onchain or offchain requests/settlements
    ///        that have been processed in this block
    ///      - blockVersion: The circuit version to use for verifying the block
    ///      - storeBlockInfoOnchain: If the block info for this block needs to be stored on-chain
    ///      - data: The data for this block
    ///      - offchainData: Arbitrary data, mainly for off-chain data-availability, i.e.,
    ///        the multihash of the IPFS file that contains the block data.
    function submitBlocks(ExchangeData.Block[] calldata blocks)
        external
        virtual;

    /// @dev Gets the number of available forced request slots.
    /// @return The number of available slots.
    function getNumAvailableForcedSlots()
        external
        virtual
        view
        returns (uint);

    // -- Deposits --

    /// @dev Deposits Ether or ERC20 tokens to the specified account.
    ///
    ///      This function is only callable by an agent of 'from'.
    ///
    ///      A fee to the owner is paid in ETH to process the deposit.
    ///      The operator is not forced to do the deposit and the user can send
    ///      any fee amount.
    ///
    /// @param from The address that deposits the funds to the exchange
    /// @param to The account owner's address receiving the funds
    /// @param tokenAddress The address of the token, use `0x0` for Ether.
    /// @param amount The amount of tokens to deposit
    /// @param auxiliaryData Optional extra data used by the deposit contract
    function deposit(
        address from,
        address to,
        address tokenAddress,
        uint248  amount,
        bytes   calldata auxiliaryData
        )
        external
        virtual
        payable;

    /// @dev Gets the amount of tokens that may be added to the owner's account.
    /// @param owner The destination address for the amount deposited.
    /// @param tokenAddress The address of the token, use `0x0` for Ether.
    /// @return The amount of tokens pending.
    function getPendingDepositAmount(
        address owner,
        address tokenAddress
        )
        external
        virtual
        view
        returns (uint248);

    // -- Withdrawals --
    /// @dev Submits an onchain request to force withdraw Ether or ERC20 tokens.
    ///      This request always withdraws the full balance.
    ///
    ///      This function is only callable by an agent of the account.
    ///
    ///      The total fee in ETH that the user needs to pay is 'withdrawalFee'.
    ///      If the user sends too much ETH the surplus is sent back immediately.
    ///
    ///      Note that after such an operation, it will take the owner some
    ///      time (no more than MAX_AGE_FORCED_REQUEST_UNTIL_WITHDRAW_MODE) to process the request
    ///      and create the deposit to the offchain account.
    ///
    /// @param owner The expected owner of the account
    /// @param tokenAddress The address of the token, use `0x0` for Ether.
    /// @param accountID The address the account in the Merkle tree.
    function forceWithdraw(
        address owner,
        address tokenAddress,
        uint32  accountID
        )
        external
        virtual
        payable;

    /// @dev Checks if a forced withdrawal is pending for an account balance.
    /// @param  accountID The accountID of the account to check.
    /// @param  token The token address
    /// @return True if a request is pending, false otherwise
    function isForcedWithdrawalPending(
        uint32  accountID,
        address token
        )
        external
        virtual
        view
        returns (bool);

    /// @dev Gets the time the protocol fee for a token was last withdrawn.
    /// @param tokenAddress The address of the token, use `0x0` for Ether.
    /// @return The time the protocol fee was last withdrawn.
    function getProtocolFeeLastWithdrawnTime(
        address tokenAddress
        )
        external
        virtual
        view
        returns (uint);

    /// @dev Allows anyone to withdraw funds for a specified user using the balances stored
    ///      in the Merkle tree. The funds will be sent to the owner of the acount.
    ///
    ///      Can only be used in withdrawal mode (i.e. when the owner has stopped
    ///      committing blocks and is not able to commit any more blocks).
    ///
    ///      This will NOT modify the onchain merkle root! The merkle root stored
    ///      onchain will remain the same after the withdrawal. We store if the user
    ///      has withdrawn the balance in State.withdrawnInWithdrawMode.
    ///
    /// @param  merkleProof The Merkle inclusion proof
    function withdrawFromMerkleTree(
        ExchangeData.MerkleProof calldata merkleProof
        )
        external
        virtual;

    /// @dev Checks if the balance for the account was withdrawn with `withdrawFromMerkleTree`.
    /// @param  accountID The accountID of the balance to check.
    /// @param  token The token address
    /// @return True if it was already withdrawn, false otherwise
    function isWithdrawnInWithdrawalMode(
        uint32  accountID,
        address token
        )
        external
        virtual
        view
        returns (bool);

    /// @dev Allows withdrawing funds deposited to the contract in a deposit request when
    ///      it was never processed by the owner within the maximum time allowed.
    ///
    ///      Can be called by anyone. The deposited tokens will be sent back to
    ///      the owner of the account they were deposited in.
    ///
    /// @param  owner The address of the account the withdrawal was done for.
    /// @param  token The token address
    function withdrawFromDepositRequest(
        address owner,
        address token
        )
        external
        virtual;

    /// @dev Allows withdrawing funds after a withdrawal request (either onchain
    ///      or offchain) was submitted in a block by the operator.
    ///
    ///      Can be called by anyone. The withdrawn tokens will be sent to
    ///      the owner of the account they were withdrawn out.
    ///
    ///      Normally it is should not be needed for users to call this manually.
    ///      Funds from withdrawal requests will be sent to the account owner
    ///      immediately by the owner when the block is submitted.
    ///      The user will however need to call this manually if the transfer failed.
    ///
    ///      Tokens and owners must have the same size.
    ///
    /// @param  owners The addresses of the account the withdrawal was done for.
    /// @param  tokens The token addresses
    function withdrawFromApprovedWithdrawals(
        address[] calldata owners,
        address[] calldata tokens
        )
        external
        virtual;

    /// @dev Gets the amount that can be withdrawn immediately with `withdrawFromApprovedWithdrawals`.
    /// @param  owner The address of the account the withdrawal was done for.
    /// @param  token The token address
    /// @return The amount withdrawable
    function getAmountWithdrawable(
        address owner,
        address token
        )
        external
        virtual
        view
        returns (uint);

    /// @dev Notifies the exchange that the owner did not process a forced request.
    ///      If this is indeed the case, the exchange will enter withdrawal mode.
    ///
    ///      Can be called by anyone.
    ///
    /// @param  accountID The accountID the forced request was made for
    /// @param  token The token address of the the forced request
    function notifyForcedRequestTooOld(
        uint32  accountID,
        address token
        )
        external
        virtual;

    /// @dev Allows a withdrawal to be done to an adddresss that is different
    ///      than initialy specified in the withdrawal request. This can be used to
    ///      implement functionality like fast withdrawals.
    ///
    ///      This function can only be called by an agent.
    ///
    /// @param from The address of the account that does the withdrawal.
    /// @param to The address to which 'amount' tokens were going to be withdrawn.
    /// @param token The address of the token that is withdrawn ('0x0' for ETH).
    /// @param amount The amount of tokens that are going to be withdrawn.
    /// @param storageID The storageID of the withdrawal request.
    /// @param newRecipient The new recipient address of the withdrawal.
    function setWithdrawalRecipient(
        address from,
        address to,
        address token,
        uint248  amount,
        uint32  storageID,
        address newRecipient
        )
        external
        virtual;

    /// @dev Gets the withdrawal recipient.
    ///
    /// @param from The address of the account that does the withdrawal.
    /// @param to The address to which 'amount' tokens were going to be withdrawn.
    /// @param token The address of the token that is withdrawn ('0x0' for ETH).
    /// @param amount The amount of tokens that are going to be withdrawn.
    /// @param storageID The storageID of the withdrawal request.
    function getWithdrawalRecipient(
        address from,
        address to,
        address token,
        uint248  amount,
        uint32  storageID
        )
        external
        virtual
        view
        returns (address);

    /// @dev Allows an agent to transfer ERC-20 tokens for a user using the allowance
    ///      the user has set for the exchange. This way the user only needs to approve a single exchange contract
    ///      for all exchange/agent features, which allows for a more seamless user experience.
    ///
    ///      This function can only be called by an agent.
    ///
    /// @param from The address of the account that sends the tokens.
    /// @param to The address to which 'amount' tokens are transferred.
    /// @param token The address of the token to transfer (ETH is and cannot be suppported).
    /// @param amount The amount of tokens transferred.
    function onchainTransferFrom(
        address from,
        address to,
        address token,
        uint    amount
        )
        external
        virtual;

    /// @dev Allows an agent to approve a rollup tx.
    ///
    ///      This function can only be called by an agent.
    ///
    /// @param owner The owner of the account
    /// @param txHash The hash of the transaction
    function approveTransaction(
        address owner,
        bytes32 txHash
        )
        external
        virtual;

    /// @dev Allows an agent to approve multiple rollup txs.
    ///
    ///      This function can only be called by an agent.
    ///
    /// @param owners The account owners
    /// @param txHashes The hashes of the transactions
    function approveTransactions(
        address[] calldata owners,
        bytes32[] calldata txHashes
        )
        external
        virtual;

    /// @dev Checks if a rollup tx is approved using the tx's hash.
    ///
    /// @param owner The owner of the account that needs to authorize the tx
    /// @param txHash The hash of the transaction
    /// @return True if the tx is approved, else false
    function isTransactionApproved(
        address owner,
        bytes32 txHash
        )
        external
        virtual
        view
        returns (bool);

    // -- Admins --
    /// @dev Sets the max time deposits have to wait before becoming withdrawable.
    /// @param newValue The new value.
    /// @return  The old value.
    function setMaxAgeDepositUntilWithdrawable(
        uint32 newValue
        )
        external
        virtual
        returns (uint32);

    /// @dev Returns the max time deposits have to wait before becoming withdrawable.
    /// @return The value.
    function getMaxAgeDepositUntilWithdrawable()
        external
        virtual
        view
        returns (uint32);

    /// @dev Shuts down the exchange.
    ///      Once the exchange is shutdown all onchain requests are permanently disabled.
    ///      When all requirements are fulfilled the exchange owner can withdraw
    ///      the exchange stake with withdrawStake.
    ///
    ///      Note that the exchange can still enter the withdrawal mode after this function
    ///      has been invoked successfully. To prevent entering the withdrawal mode before the
    ///      the echange stake can be withdrawn, all withdrawal requests still need to be handled
    ///      for at least MIN_TIME_IN_SHUTDOWN seconds.
    ///
    ///      Can only be called by the exchange owner.
    ///
    /// @return success True if the exchange is shutdown, else False
    function shutdown()
        external
        virtual
        returns (bool success);

    /// @dev Gets the protocol fees for this exchange.
    /// @return syncedAt The timestamp the protocol fees were last updated
    /// @return protocolFeeBips The protocol fee
    /// @return previousProtocolFeeBips The previous protocol fee
    /// @return executeTimeOfNextProtocolFeeBips The timestamp the next protocol fees will be updated
    /// @return nextProtocolFeeBips The next protocol fee
    function getProtocolFeeValues()
        external
        virtual
        view
        returns (
            uint32 syncedAt,
            uint16 protocolFeeBips,
            uint16 previousProtocolFeeBips,
            uint32 executeTimeOfNextProtocolFeeBips,
            uint16 nextProtocolFeeBips
        );

    /// @dev Gets the domain separator used in this exchange.
    function getDomainSeparator()
        external
        virtual
        view
        returns (bytes32);

    /// @dev Gets the uncomfirmed balance in DepositContract, which can be used for DepositTransaction.
    /// @param tokenAddress The address of the token, use `0x0` for Ether.
    /// @return Unconfirmed balance of the token
    function getUnconfirmedBalance(
        address tokenAddress
        )
        external
        virtual
        view
        returns (uint256);

    /// @dev Gets free deposit slots
    function getFreeDepositRemained()
        external
        virtual
        view
        returns (uint256);

    /// @dev Gets token deposit balance
    /// @param tokenAddress The address of the token, use `0x0` for Ether.
    /// @return deposit balance of the token
    function getDepositBalance(
        address tokenAddress
        )
        external
        virtual
        view
        returns (uint248);
}

File 12 of 95 : Claimable.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "./Ownable.sol";


/// @title Claimable
/// @author Brecht Devos - <[email protected]>
/// @dev Extension for the Ownable contract, where the ownership needs
///      to be claimed. This allows the new owner to accept the transfer.
contract Claimable is Ownable
{
    address public pendingOwner;

    /// @dev Modifier throws if called by any account other than the pendingOwner.
    modifier onlyPendingOwner() {
        require(msg.sender == pendingOwner, "UNAUTHORIZED");
        _;
    }

    /// @dev Allows the current owner to set the pendingOwner address.
    /// @param newOwner The address to transfer ownership to.
    function transferOwnership(
        address newOwner
        )
        public
        override
        onlyOwner
    {
        require(newOwner != address(0) && newOwner != owner, "INVALID_ADDRESS");
        pendingOwner = newOwner;
    }

    /// @dev Allows the pendingOwner address to finalize the transfer.
    function claimOwnership()
        public
        onlyPendingOwner
    {
        emit OwnershipTransferred(owner, pendingOwner);
        owner = pendingOwner;
        pendingOwner = address(0);
    }
}

File 13 of 95 : Ownable.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;


/// @title Ownable
/// @author Brecht Devos - <[email protected]>
/// @dev The Ownable contract has an owner address, and provides basic
///      authorization control functions, this simplifies the implementation of
///      "user permissions".
contract Ownable
{
    address public owner;

    event OwnershipTransferred(
        address indexed previousOwner,
        address indexed newOwner
    );

    /// @dev The Ownable constructor sets the original `owner` of the contract
    ///      to the sender.
    constructor()
    {
        owner = msg.sender;
    }

    /// @dev Throws if called by any account other than the owner.
    modifier onlyOwner()
    {
        require(msg.sender == owner, "UNAUTHORIZED");
        _;
    }

    /// @dev Allows the current owner to transfer control of the contract to a
    ///      new owner.
    /// @param newOwner The address to transfer ownership to.
    function transferOwnership(
        address newOwner
        )
        public
        virtual
        onlyOwner
    {
        require(newOwner != address(0), "ZERO_ADDRESS");
        emit OwnershipTransferred(owner, newOwner);
        owner = newOwner;
    }

    function renounceOwnership()
        public
        onlyOwner
    {
        emit OwnershipTransferred(owner, address(0));
        owner = address(0);
    }
}

File 14 of 95 : ExchangeData.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "./IAgentRegistry.sol";
import "./IBlockVerifier.sol";
import "./IDepositContract.sol";
import "./ILoopringV3.sol";

/// @title ExchangeData
/// @dev All methods in this lib are internal, therefore, there is no need
///      to deploy this library independently.
/// @author Daniel Wang  - <[email protected]>
/// @author Brecht Devos - <[email protected]>
library ExchangeData
{
    // -- Enums --
    enum TransactionType
    {
        NOOP,
        DEPOSIT,
        WITHDRAWAL,
        TRANSFER,
        SPOT_TRADE,
        ACCOUNT_UPDATE,
        ORDER_CANCEL,
        BATCH_SPOT_TRADE,
        APPKEY_UPDATE
    }

    // -- Structs --
    struct Token
    {
        address token;
    }

    struct ProtocolFeeData
    {
        uint32 syncedAt; // only valid before 2105 (85 years to go)
        uint16 protocolFeeBips;
        uint16 previousProtocolFeeBips;

        uint32 executeTimeOfNextProtocolFeeBips;
        uint16 nextProtocolFeeBips;
    }

    // General auxiliary data for each conditional transaction
    struct AuxiliaryData
    {
        bytes data;
    }

    // This is the (virtual) block the owner  needs to submit onchain to maintain the
    // per-exchange (virtual) blockchain.
    struct Block
    {
        uint8      blockType;
        uint16     blockSize;
        uint8      blockVersion;
        bytes      data;
        uint256[8] proof;

        // Whether we should store the @BlockInfo for this block on-chain.
        bool storeBlockInfoOnchain;

        // Block specific data that is only used to help process the block on-chain.
        // It is not used as input for the circuits and it is not necessary for data-availability.
        // This bytes array contains the abi encoded AuxiliaryData[] data.
        bytes auxiliaryData;

        // Arbitrary data, mainly for off-chain data-availability, i.e.,
        // the multihash of the IPFS file that contains the block data.
        bytes offchainData;
    }

    struct BlockInfo
    {
        // The time the block was submitted on-chain.
        uint32  timestamp;
        // The public data hash of the block (the 28 most significant bytes).
        bytes28 blockDataHash;
    }

    // Represents an onchain deposit request.
    struct Deposit
    {
        uint248 amount;
        uint64 timestamp;
    }

    // A forced withdrawal request.
    // If the actual owner of the account initiated the request (we don't know who the owner is
    // at the time the request is being made) the full balance will be withdrawn.
    struct ForcedWithdrawal
    {
        address owner;
        uint64  timestamp;
    }

    struct Constants
    {
        uint SNARK_SCALAR_FIELD;
        uint MAX_OPEN_FORCED_REQUESTS;
        uint MAX_AGE_FORCED_REQUEST_UNTIL_WITHDRAW_MODE;
        uint TIMESTAMP_HALF_WINDOW_SIZE_IN_SECONDS;
        uint MAX_NUM_ACCOUNTS;
        uint MAX_NUM_TOKENS;
        uint MIN_AGE_PROTOCOL_FEES_UNTIL_UPDATED;
        uint MIN_TIME_IN_SHUTDOWN;
        uint TX_DATA_AVAILABILITY_SIZE;
        uint MAX_AGE_DEPOSIT_UNTIL_WITHDRAWABLE_UPPERBOUND;
        uint MAX_FORCED_WITHDRAWAL_FEE;
        uint DEFAULT_PROTOCOL_FEE_BIPS;
    }

    // This is the prime number that is used for the alt_bn128 elliptic curve, see EIP-196.
    uint public constant SNARK_SCALAR_FIELD = 21888242871839275222246405745257275088548364400416034343698204186575808495617;

    uint public constant MAX_OPEN_FORCED_REQUESTS = 1000000;
    uint public constant MAX_AGE_FORCED_REQUEST_UNTIL_WITHDRAW_MODE = 15 days;
    uint public constant TIMESTAMP_HALF_WINDOW_SIZE_IN_SECONDS = 7 days;
    uint public constant BINARY_TREE_DEPTH_ACCOUNTS = 32;
    uint public constant MAX_NUM_ACCOUNTS = 2 ** BINARY_TREE_DEPTH_ACCOUNTS;
    uint public constant BINARY_TREE_DEPTH_TOKENS = 32;
    uint public constant MAX_NUM_TOKENS = 2 ** BINARY_TREE_DEPTH_TOKENS;
    uint public constant MAX_NUM_RESERVED_TOKENS = 32;
    uint public constant MAX_NUM_NORMAL_TOKENS = 2 ** BINARY_TREE_DEPTH_TOKENS - 32;

    uint public constant MIN_AGE_PROTOCOL_FEES_UNTIL_UPDATED = 7 days;
    uint public constant MIN_TIME_IN_SHUTDOWN = 30 days;

    uint32 public constant MAX_AGE_DEPOSIT_UNTIL_WITHDRAWABLE_UPPERBOUND = 15 days;
    uint32 public constant ACCOUNTID_PROTOCOLFEE = 0;

    // The amount of bytes each rollup transaction uses in the block data for data-availability.
    // This is the maximum amount of bytes of all different transaction types.
    uint public constant TX_DATA_AVAILABILITY_SIZE = 83;
    uint public constant TX_DATA_AVAILABILITY_SIZE_PART_1 = 80;
    uint public constant TX_DATA_AVAILABILITY_SIZE_PART_2 = 3;

    uint public constant MAX_FORCED_WITHDRAWAL_FEE = 0.25 ether;

    uint16 public constant DEFAULT_PROTOCOL_FEE_BIPS = 18;

    struct AccountLeaf
    {
        uint32   accountID;
        address  owner;
        uint     pubKeyX;
        uint     pubKeyY;
        uint32   nonce;
    }

    struct BalanceLeaf
    {
        uint32  tokenID;
        uint248 balance;
    }

    struct MerkleProof
    {
        ExchangeData.AccountLeaf accountLeaf;
        ExchangeData.BalanceLeaf balanceLeaf;
        uint[48]                 accountMerkleProof;
        uint[48]                 balanceMerkleProof;
    }

    struct BlockContext
    {
        bytes32 DOMAIN_SEPARATOR;
        uint32  timestamp;
    }

   struct DepositState {
        uint256 freeDepositMax;
        uint256 freeDepositRemained;
        uint256 lastDepositBlockNum;
        uint256 freeSlotPerBlock;
        uint256 depositFee;
    }

    struct ModeTime {
        // Time when the exchange was shutdown
        uint shutdownModeStartTime;

        // Time when the exchange has entered withdrawal mode
        uint withdrawalModeStartTime;
    }

    // Represents the entire exchange state except the owner of the exchange.
    struct State
    {
        uint32  maxAgeDepositUntilWithdrawable;
        bytes32 DOMAIN_SEPARATOR;

        ILoopringV3      loopring;
        IBlockVerifier   blockVerifier;
        IAgentRegistry   agentRegistry;
        IDepositContract depositContract;
        DepositState depositState;
        // The merkle root of the offchain data stored in a Merkle tree. The Merkle tree
        // stores balances for users using an account model.
        bytes32 merkleRoot;
        bytes32 merkleAssetRoot;

        // List of all blocks
        mapping(uint => BlockInfo) blocks;
        uint  numBlocks;

        // List of all tokens
        Token[] reservedTokens;
        Token[] normalTokens;

        // A map from a tokenID to deposit balance
        mapping(uint32 => uint248) tokenIdToDepositBalance;

        // A map from a token to its tokenID + 1
        mapping (address => uint32) tokenToTokenId;
        mapping (uint32 => address) tokenIdToToken;

        // A map from an accountID to a tokenID to if the balance is withdrawn
        mapping (uint32 => mapping (uint32 => bool)) withdrawnInWithdrawMode;

        // A map from an account to a token to the amount withdrawable for that account.
        // This is only used when the automatic distribution of the withdrawal failed.
        mapping (address => mapping (uint32 => uint248)) amountWithdrawable;

        // A map from an account to a token to the forced withdrawal (always full balance)
        mapping (uint32 => mapping (uint32 => ForcedWithdrawal)) pendingForcedWithdrawals;

        // A map from an address to a token to a deposit
        mapping (address => mapping (uint32 => Deposit)) pendingDeposits;

        // A map from an account owner to an approved transaction hash to if the transaction is approved or not
        mapping (address => mapping (bytes32 => bool)) approvedTx;

        // A map from an account owner to a destination address to a tokenID to an amount to a storageID to a new recipient address
        mapping (address => mapping (address => mapping (uint32 => mapping (uint => mapping (uint32 => address))))) withdrawalRecipient;

        // Counter to keep track of how many of forced requests are open so we can limit the work that needs to be done by the owner
        uint32 numPendingForcedTransactions;

        // Cached data for the protocol fee
        ProtocolFeeData protocolFeeData;

        ModeTime modeTime;

        // Last time the protocol fee was withdrawn for a specific token
        mapping (address => uint) protocolFeeLastWithdrawnTime;
    }
}

File 15 of 95 : IBlockVerifier.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../lib/Claimable.sol";


/// @title IBlockVerifier
/// @author Brecht Devos - <[email protected]>
abstract contract IBlockVerifier is Claimable
{
    // -- Events --

    event CircuitRegistered(
        uint8  indexed blockType,
        uint16         blockSize,
        uint8          blockVersion
    );

    event CircuitDisabled(
        uint8  indexed blockType,
        uint16         blockSize,
        uint8          blockVersion
    );

    // -- Public functions --

    /// @dev Verifies blocks with the given public data and proofs.
    ///      Verifying a block makes sure all requests handled in the block
    ///      are correctly handled by the operator.
    /// @param blockType The type of block
    /// @param blockSize The number of requests handled in the block
    /// @param blockVersion The block version (i.e. which circuit version needs to be used)
    /// @param publicInputs The hash of all the public data of the blocks
    /// @param proofs The ZK proofs proving that the blocks are correct
    /// @return True if the block is valid, false otherwise
    function verifyProofs(
        uint8  blockType,
        uint16 blockSize,
        uint8  blockVersion,
        uint[] calldata publicInputs,
        uint[] calldata proofs
        )
        external
        virtual
        view
        returns (bool);

    /// @dev Checks if a circuit with the specified parameters is registered.
    /// @param blockType The type of the block
    /// @param blockSize The number of requests handled in the block
    /// @param blockVersion The block version (i.e. which circuit version needs to be used)
    /// @return True if the circuit is registered, false otherwise
    function isCircuitRegistered(
        uint8  blockType,
        uint16 blockSize,
        uint8  blockVersion
        )
        external
        virtual
        view
        returns (bool);

    /// @dev Checks if a circuit can still be used to commit new blocks.
    /// @param blockType The type of the block
    /// @param blockSize The number of requests handled in the block
    /// @param blockVersion The block version (i.e. which circuit version needs to be used)
    /// @return True if the circuit is enabled, false otherwise
    function isCircuitEnabled(
        uint8  blockType,
        uint16 blockSize,
        uint8  blockVersion
        )
        external
        virtual
        view
        returns (bool);
}

File 16 of 95 : IDepositContract.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;


/// @title IDepositContract.
/// @dev   Contract storing and transferring funds for an exchange.
///
///        ERC1155 tokens can be supported by registering pseudo token addresses calculated
///        as `address(keccak256(real_token_address, token_params))`. Then the custom
///        deposit contract can look up the real token address and paramsters with the
///        pseudo token address before doing the transfers.
/// @author Brecht Devos - <[email protected]>
interface IDepositContract
{
    /// @dev Returns if a token is suppoprted by this contract.
    function isTokenSupported(address token)
        external
        view
        returns (bool);

    /// @dev Transfers tokens from a user to the exchange. This function will
    ///      be called when a user deposits funds to the exchange.
    ///      In a simple implementation the funds are simply stored inside the
    ///      deposit contract directly. More advanced implementations may store the funds
    ///      in some DeFi application to earn interest, so this function could directly
    ///      call the necessary functions to store the funds there.
    ///
    ///      This function needs to throw when an error occurred!
    ///
    ///      This function can only be called by the exchange.
    ///
    /// @param from The address of the account that sends the tokens.
    /// @param token The address of the token to transfer (`0x0` for ETH).
    /// @param amount The amount of tokens to transfer.
    /// @param extraData Opaque data that can be used by the contract to handle the deposit
    /// @return amountReceived The amount to deposit to the user's account in the Merkle tree
    function deposit(
        address from,
        address token,
        uint248  amount,
        bytes   calldata extraData
        )
        external
        payable
        returns (uint248 amountReceived);

    /// @dev Transfers tokens from the exchange to a user. This function will
    ///      be called when a withdrawal is done for a user on the exchange.
    ///      In the simplest implementation the funds are simply stored inside the
    ///      deposit contract directly so this simply transfers the requested tokens back
    ///      to the user. More advanced implementations may store the funds
    ///      in some DeFi application to earn interest so the function would
    ///      need to get those tokens back from the DeFi application first before they
    ///      can be transferred to the user.
    ///
    ///      This function needs to throw when an error occurred!
    ///
    ///      This function can only be called by the exchange.
    ///
    /// @param from The address from which 'amount' tokens are transferred.
    /// @param to The address to which 'amount' tokens are transferred.
    /// @param token The address of the token to transfer (`0x0` for ETH).
    /// @param amount The amount of tokens transferred.
    function withdraw(
        address from,
        address to,
        address token,
        uint    amount
        )
        external
        payable;

    /// @dev Transfers tokens (ETH not supported) for a user using the allowance set
    ///      for the exchange. This way the approval can be used for all functionality (and
    ///      extended functionality) of the exchange.
    ///      Should NOT be used to deposit/withdraw user funds, `deposit`/`withdraw`
    ///      should be used for that as they will contain specialised logic for those operations.
    ///      This function can be called by the exchange to transfer onchain funds of users
    ///      necessary for Agent functionality.
    ///
    ///      This function needs to throw when an error occurred!
    ///
    ///      This function can only be called by the exchange.
    ///
    /// @param from The address of the account that sends the tokens.
    /// @param to The address to which 'amount' tokens are transferred.
    /// @param token The address of the token to transfer (ETH is and cannot be suppported).
    /// @param amount The amount of tokens transferred.
    function transfer(
        address from,
        address to,
        address token,
        uint    amount
        )
        external
        payable;

    /// @dev Checks if the given address is used for depositing ETH or not.
    ///      Is used while depositing to send the correct ETH amount to the deposit contract.
    ///
    ///      Note that 0x0 is always registered for deposting ETH when the exchange is created!
    ///      This function allows additional addresses to be used for depositing ETH, the deposit
    ///      contract can implement different behaviour based on the address value.
    ///
    /// @param addr The address to check
    /// @return True if the address is used for depositing ETH, else false.
    function isETH(address addr)
        external
        view
        returns (bool);
}

File 17 of 95 : ILoopringV3.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;

import "../../lib/Claimable.sol";


/// @title ILoopringV3
/// @author Brecht Devos - <[email protected]>
/// @author Daniel Wang  - <[email protected]>
abstract contract ILoopringV3 is Claimable
{
    // == Events ==
    event ExchangeStakeDeposited(address exchangeAddr, uint amount);
    event ExchangeStakeWithdrawn(address exchangeAddr, uint amount);
    event ExchangeStakeBurned(address exchangeAddr, uint amount);
    event SettingsUpdated(uint time);

    // == Public Variables ==
    mapping (address => uint) internal exchangeStake;

    uint    public totalStake;
    address public blockVerifierAddress;
    uint    public forcedWithdrawalFee;
    uint16  public protocolFeeBips;
    

    address payable public protocolFeeVault;

    // == Public Functions ==

    /// @dev Returns the LRC token address
    /// @return the LRC token address
    function lrcAddress()
        external
        view
        virtual
        returns (address);

    /// @dev Updates the global exchange settings.
    ///      This function can only be called by the owner of this contract.
    ///
    ///      Warning: these new values will be used by existing and
    ///      new Loopring exchanges.
    function updateSettings(
        address payable _protocolFeeVault,   // address(0) not allowed
        uint    _forcedWithdrawalFee
        )
        external
        virtual;

    /// @dev Updates the global protocol fee settings.
    ///      This function can only be called by the owner of this contract.
    ///
    ///      Warning: these new values will be used by existing and
    ///      new Loopring exchanges.
    function updateProtocolFeeSettings(
        uint16 _protocolFeeBips
        )
        external
        virtual;

    /// @dev Gets the amount of staked LRC for an exchange.
    /// @param exchangeAddr The address of the exchange
    /// @return stakedLRC The amount of LRC
    function getExchangeStake(
        address exchangeAddr
        )
        external
        virtual
        view
        returns (uint stakedLRC);

    /// @dev Burns a certain amount of staked LRC for a specific exchange.
    ///      This function is meant to be called only from exchange contracts.
    /// @return burnedLRC The amount of LRC burned. If the amount is greater than
    ///         the staked amount, all staked LRC will be burned.
    function burnExchangeStake(
        uint amount
        )
        external
        virtual
        returns (uint burnedLRC);

    /// @dev Stakes more LRC for an exchange.
    /// @param  exchangeAddr The address of the exchange
    /// @param  amountLRC The amount of LRC to stake
    /// @return stakedLRC The total amount of LRC staked for the exchange
    function depositExchangeStake(
        address exchangeAddr,
        uint    amountLRC
        )
        external
        virtual
        returns (uint stakedLRC);

    /// @dev Withdraws a certain amount of staked LRC for an exchange to the given address.
    ///      This function is meant to be called only from within exchange contracts.
    /// @param  recipient The address to receive LRC
    /// @param  requestedAmount The amount of LRC to withdraw
    /// @return amountLRC The amount of LRC withdrawn
    function withdrawExchangeStake(
        address recipient,
        uint    requestedAmount
        )
        external
        virtual
        returns (uint amountLRC);

    /// @dev Gets the protocol fee values for an exchange.
    /// @return feeBips The protocol fee
    function getProtocolFeeValues(
        )
        external
        virtual
        view
        returns (
            uint16 feeBips
        );
}

File 18 of 95 : ExchangeAdmins.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../../lib/ERC20.sol";
import "../../../lib/ERC20SafeTransfer.sol";
import "../../../lib/MathUint.sol";
import "../../iface/ExchangeData.sol";
import "./ExchangeMode.sol";


/// @title ExchangeAdmins.
/// @author Daniel Wang  - <[email protected]>
/// @author Brecht Devos - <[email protected]>
library ExchangeAdmins
{
    using ERC20SafeTransfer for address;
    using ExchangeMode      for ExchangeData.State;
    using MathUint          for uint;

    event MaxAgeDepositUntilWithdrawableChanged(
        address indexed exchangeAddr,
        uint32          oldValue,
        uint32          newValue
    );

    function setMaxAgeDepositUntilWithdrawable(
        ExchangeData.State storage S,
        uint32 newValue
        )
        public
        returns (uint32 oldValue)
    {
        require(!S.isInWithdrawalMode(), "INVALID_MODE");
        require(
            newValue > 0 &&
            newValue <= ExchangeData.MAX_AGE_DEPOSIT_UNTIL_WITHDRAWABLE_UPPERBOUND,
            "INVALID_VALUE"
        );
        oldValue = S.maxAgeDepositUntilWithdrawable;
        S.maxAgeDepositUntilWithdrawable = newValue;

        emit MaxAgeDepositUntilWithdrawableChanged(
            address(this),
            oldValue,
            newValue
        );
    }

    function withdrawExchangeStake(
        ExchangeData.State storage S,
        address recipient
        )
        public
        returns (uint)
    {
        // Exchange needs to be shutdown
        require(S.isShutdown(), "EXCHANGE_NOT_SHUTDOWN");
        require(!S.isInWithdrawalMode(), "CANNOT_BE_IN_WITHDRAWAL_MODE");

        // Need to remain in shutdown for some time
        require(block.timestamp >= S.modeTime.shutdownModeStartTime + ExchangeData.MIN_TIME_IN_SHUTDOWN, "TOO_EARLY");

        // Withdraw the complete stake
        uint amount = S.loopring.getExchangeStake(address(this));
        return S.loopring.withdrawExchangeStake(recipient, amount);
    }
}

File 19 of 95 : ERC20.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;


/// @title ERC20 Token Interface
/// @dev see https://github.com/ethereum/EIPs/issues/20
/// @author Daniel Wang - <[email protected]>
abstract contract ERC20
{
    function totalSupply()
        public
        virtual
        view
        returns (uint);

    function balanceOf(
        address who
        )
        public
        virtual
        view
        returns (uint);

    function allowance(
        address owner,
        address spender
        )
        public
        virtual
        view
        returns (uint);

    function transfer(
        address to,
        uint value
        )
        public
        virtual
        returns (bool);

    function transferFrom(
        address from,
        address to,
        uint    value
        )
        public
        virtual
        returns (bool);

    function approve(
        address spender,
        uint    value
        )
        public
        virtual
        returns (bool);
}

File 20 of 95 : ExchangeMode.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../../lib/MathUint.sol";
import "../../iface/ExchangeData.sol";


/// @title ExchangeMode.
/// @dev All methods in this lib are internal, therefore, there is no need
///      to deploy this library independently.
/// @author Brecht Devos - <[email protected]>
/// @author Daniel Wang  - <[email protected]>
library ExchangeMode
{
    using MathUint  for uint;

    function isInWithdrawalMode(
        ExchangeData.State storage S
        )
        internal // inline call
        view
        returns (bool result)
    {
        result = S.modeTime.withdrawalModeStartTime > 0;
    }

    function isShutdown(
        ExchangeData.State storage S
        )
        internal // inline call
        view
        returns (bool)
    {
        return S.modeTime.shutdownModeStartTime > 0;
    }

    function getNumAvailableForcedSlots(
        ExchangeData.State storage S
        )
        internal
        view
        returns (uint)
    {
        return ExchangeData.MAX_OPEN_FORCED_REQUESTS - S.numPendingForcedTransactions;
    }
}

File 21 of 95 : ExchangeBalances.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../../lib/MathUint.sol";
import "../../../lib/Poseidon.sol";
import "../../iface/ExchangeData.sol";


/// @title ExchangeBalances.
/// @author Daniel Wang  - <[email protected]>
/// @author Brecht Devos - <[email protected]>
library ExchangeBalances
{
    using MathUint  for uint;

    function verifyAccountBalance(
        uint                              merkleRoot,
        ExchangeData.MerkleProof calldata merkleProof
        )
        public
        pure
    {
        require(
            isAccountBalanceCorrect(merkleRoot, merkleProof),
            "INVALID_MERKLE_TREE_DATA"
        );
    }

    function isAccountBalanceCorrect(
        uint                            merkleRoot,
        ExchangeData.MerkleProof memory merkleProof
        )
        public
        pure
        returns (bool)
    {
        // Calculate the Merkle root using the Merkle paths provided
        uint calculatedRoot = getBalancesRoot(
            merkleProof.balanceLeaf.tokenID,
            merkleProof.balanceLeaf.balance,
            merkleProof.balanceMerkleProof
        );
        calculatedRoot = getAccountInternalsRoot(
            merkleProof.accountLeaf.accountID,
            merkleProof.accountLeaf.owner,
            merkleProof.accountLeaf.pubKeyX,
            merkleProof.accountLeaf.pubKeyY,
            merkleProof.accountLeaf.nonce,
            calculatedRoot,
            merkleProof.accountMerkleProof
        );
        // Check against the expected Merkle root
        return (calculatedRoot == merkleRoot);
    }

    function getBalancesRoot(
        uint32   tokenID,
        uint     balance,
        uint[48] memory balanceMerkleProof
        )
        private
        pure
        returns (uint)
    {
        // Hash the balance leaf
        uint balanceItem = hashImpl(balance, 0, 0, 0);
        // Calculate the Merkle root of the balance quad Merkle tree
        uint _id = tokenID;
        for (uint depth = 0; depth < ExchangeData.BINARY_TREE_DEPTH_TOKENS/2; depth++) { // quad tree depth 
            uint base = depth * 3;
            if (_id & 3 == 0) {
                balanceItem = hashImpl(
                    balanceItem,
                    balanceMerkleProof[base],
                    balanceMerkleProof[base + 1],
                    balanceMerkleProof[base + 2]
                );
            } else if (_id & 3 == 1) {
                balanceItem = hashImpl(
                    balanceMerkleProof[base],
                    balanceItem,
                    balanceMerkleProof[base + 1],
                    balanceMerkleProof[base + 2]
                );
            } else if (_id & 3 == 2) {
                balanceItem = hashImpl(
                    balanceMerkleProof[base],
                    balanceMerkleProof[base + 1],
                    balanceItem,
                    balanceMerkleProof[base + 2]
                );
            } else if (_id & 3 == 3) {
                balanceItem = hashImpl(
                    balanceMerkleProof[base],
                    balanceMerkleProof[base + 1],
                    balanceMerkleProof[base + 2],
                    balanceItem
                );
            }
            _id = _id >> 2;
        }
        return balanceItem;
    }

    function getAccountInternalsRoot(
        uint32   accountID,
        address  owner,
        uint     pubKeyX,
        uint     pubKeyY,
        uint     nonce,
        uint     balancesRoot,
        uint[48] memory accountMerkleProof
        )
        private
        pure
        returns (uint)
    {
        // Hash the account leaf
        uint accountItem = hashAccountLeaf(uint(owner), pubKeyX, pubKeyY, nonce, balancesRoot);
        // Calculate the Merkle root of the account quad Merkle tree
        uint _id = accountID;
        for (uint depth = 0; depth < ExchangeData.BINARY_TREE_DEPTH_ACCOUNTS/2; depth++) { // quad tree depth 
            uint base = depth * 3;
            if (_id & 3 == 0) {
                accountItem = hashImpl(
                    accountItem,
                    accountMerkleProof[base],
                    accountMerkleProof[base + 1],
                    accountMerkleProof[base + 2]
                );
            } else if (_id & 3 == 1) {
                accountItem = hashImpl(
                    accountMerkleProof[base],
                    accountItem,
                    accountMerkleProof[base + 1],
                    accountMerkleProof[base + 2]
                );
            } else if (_id & 3 == 2) {
                accountItem = hashImpl(
                    accountMerkleProof[base],
                    accountMerkleProof[base + 1],
                    accountItem,
                    accountMerkleProof[base + 2]
                );
            } else if (_id & 3 == 3) {
                accountItem = hashImpl(
                    accountMerkleProof[base],
                    accountMerkleProof[base + 1],
                    accountMerkleProof[base + 2],
                    accountItem
                );
            }
            _id = _id >> 2;
        }
        return accountItem;
    }

    function hashAccountLeaf(
        uint t0,
        uint t1,
        uint t2,
        uint t3,
        uint t4
        )
        public
        pure
        returns (uint)
    {
        Poseidon.HashInputs6 memory inputs = Poseidon.HashInputs6(t0, t1, t2, t3, t4, 0);
        return Poseidon.hash_t6f6p52(inputs, ExchangeData.SNARK_SCALAR_FIELD);
    }

    function hashImpl(
        uint t0,
        uint t1,
        uint t2,
        uint t3
        )
        private
        pure
        returns (uint)
    {
        Poseidon.HashInputs5 memory inputs = Poseidon.HashInputs5(t0, t1, t2, t3, 0);
        return Poseidon.hash_t5f6p52(inputs, ExchangeData.SNARK_SCALAR_FIELD);
    }
}

File 22 of 95 : Poseidon.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;


/// @title Poseidon hash function
///        See: https://eprint.iacr.org/2019/458.pdf
///        Code auto-generated by generate_poseidon_EVM_code.py
/// @author Brecht Devos - <[email protected]>
library Poseidon
{
    //
    // hash_t5f6p52
    //

    struct HashInputs5
    {
        uint t0;
        uint t1;
        uint t2;
        uint t3;
        uint t4;
    }

    function hash_t5f6p52_internal(
        uint t0,
        uint t1,
        uint t2,
        uint t3,
        uint t4,
        uint q
        )
        internal
        pure
        returns (uint)
    {
        assembly {
            function mix(_t0, _t1, _t2, _t3, _t4, _q) -> nt0, nt1, nt2, nt3, nt4 {
                nt0 := mulmod(_t0, 4977258759536702998522229302103997878600602264560359702680165243908162277980, _q)
                nt0 := addmod(nt0, mulmod(_t1, 19167410339349846567561662441069598364702008768579734801591448511131028229281, _q), _q)
                nt0 := addmod(nt0, mulmod(_t2, 14183033936038168803360723133013092560869148726790180682363054735190196956789, _q), _q)
                nt0 := addmod(nt0, mulmod(_t3, 9067734253445064890734144122526450279189023719890032859456830213166173619761, _q), _q)
                nt0 := addmod(nt0, mulmod(_t4, 16378664841697311562845443097199265623838619398287411428110917414833007677155, _q), _q)
                nt1 := mulmod(_t0, 107933704346764130067829474107909495889716688591997879426350582457782826785, _q)
                nt1 := addmod(nt1, mulmod(_t1, 17034139127218860091985397764514160131253018178110701196935786874261236172431, _q), _q)
                nt1 := addmod(nt1, mulmod(_t2, 2799255644797227968811798608332314218966179365168250111693473252876996230317, _q), _q)
                nt1 := addmod(nt1, mulmod(_t3, 2482058150180648511543788012634934806465808146786082148795902594096349483974, _q), _q)
                nt1 := addmod(nt1, mulmod(_t4, 16563522740626180338295201738437974404892092704059676533096069531044355099628, _q), _q)
                nt2 := mulmod(_t0, 13596762909635538739079656925495736900379091964739248298531655823337482778123, _q)
                nt2 := addmod(nt2, mulmod(_t1, 18985203040268814769637347880759846911264240088034262814847924884273017355969, _q), _q)
                nt2 := addmod(nt2, mulmod(_t2, 8652975463545710606098548415650457376967119951977109072274595329619335974180, _q), _q)
                nt2 := addmod(nt2, mulmod(_t3, 970943815872417895015626519859542525373809485973005165410533315057253476903, _q), _q)
                nt2 := addmod(nt2, mulmod(_t4, 19406667490568134101658669326517700199745817783746545889094238643063688871948, _q), _q)
                nt3 := mulmod(_t0, 2953507793609469112222895633455544691298656192015062835263784675891831794974, _q)
                nt3 := addmod(nt3, mulmod(_t1, 19025623051770008118343718096455821045904242602531062247152770448380880817517, _q), _q)
                nt3 := addmod(nt3, mulmod(_t2, 9077319817220936628089890431129759976815127354480867310384708941479362824016, _q), _q)
                nt3 := addmod(nt3, mulmod(_t3, 4770370314098695913091200576539533727214143013236894216582648993741910829490, _q), _q)
                nt3 := addmod(nt3, mulmod(_t4, 4298564056297802123194408918029088169104276109138370115401819933600955259473, _q), _q)
                nt4 := mulmod(_t0, 8336710468787894148066071988103915091676109272951895469087957569358494947747, _q)
                nt4 := addmod(nt4, mulmod(_t1, 16205238342129310687768799056463408647672389183328001070715567975181364448609, _q), _q)
                nt4 := addmod(nt4, mulmod(_t2, 8303849270045876854140023508764676765932043944545416856530551331270859502246, _q), _q)
                nt4 := addmod(nt4, mulmod(_t3, 20218246699596954048529384569730026273241102596326201163062133863539137060414, _q), _q)
                nt4 := addmod(nt4, mulmod(_t4, 1712845821388089905746651754894206522004527237615042226559791118162382909269, _q), _q)
            }

            function ark(_t0, _t1, _t2, _t3, _t4, _q, c) -> nt0, nt1, nt2, nt3, nt4 {
                nt0 := addmod(_t0, c, _q)
                nt1 := addmod(_t1, c, _q)
                nt2 := addmod(_t2, c, _q)
                nt3 := addmod(_t3, c, _q)
                nt4 := addmod(_t4, c, _q)
            }

            function sbox_full(_t0, _t1, _t2, _t3, _t4, _q) -> nt0, nt1, nt2, nt3, nt4 {
                nt0 := mulmod(_t0, _t0, _q)
                nt0 := mulmod(nt0, nt0, _q)
                nt0 := mulmod(_t0, nt0, _q)
                nt1 := mulmod(_t1, _t1, _q)
                nt1 := mulmod(nt1, nt1, _q)
                nt1 := mulmod(_t1, nt1, _q)
                nt2 := mulmod(_t2, _t2, _q)
                nt2 := mulmod(nt2, nt2, _q)
                nt2 := mulmod(_t2, nt2, _q)
                nt3 := mulmod(_t3, _t3, _q)
                nt3 := mulmod(nt3, nt3, _q)
                nt3 := mulmod(_t3, nt3, _q)
                nt4 := mulmod(_t4, _t4, _q)
                nt4 := mulmod(nt4, nt4, _q)
                nt4 := mulmod(_t4, nt4, _q)
            }

            function sbox_partial(_t, _q) -> nt {
                nt := mulmod(_t, _t, _q)
                nt := mulmod(nt, nt, _q)
                nt := mulmod(_t, nt, _q)
            }

            // round 0
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 14397397413755236225575615486459253198602422701513067526754101844196324375522)
            t0, t1, t2, t3, t4 := sbox_full(t0, t1, t2, t3, t4, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 1
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 10405129301473404666785234951972711717481302463898292859783056520670200613128)
            t0, t1, t2, t3, t4 := sbox_full(t0, t1, t2, t3, t4, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 2
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 5179144822360023508491245509308555580251733042407187134628755730783052214509)
            t0, t1, t2, t3, t4 := sbox_full(t0, t1, t2, t3, t4, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 3
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 9132640374240188374542843306219594180154739721841249568925550236430986592615)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 4
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 20360807315276763881209958738450444293273549928693737723235350358403012458514)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 5
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 17933600965499023212689924809448543050840131883187652471064418452962948061619)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 6
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 3636213416533737411392076250708419981662897009810345015164671602334517041153)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 7
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 2008540005368330234524962342006691994500273283000229509835662097352946198608)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 8
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 16018407964853379535338740313053768402596521780991140819786560130595652651567)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 9
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 20653139667070586705378398435856186172195806027708437373983929336015162186471)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 10
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 17887713874711369695406927657694993484804203950786446055999405564652412116765)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 11
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 4852706232225925756777361208698488277369799648067343227630786518486608711772)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 12
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 8969172011633935669771678412400911310465619639756845342775631896478908389850)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 13
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 20570199545627577691240476121888846460936245025392381957866134167601058684375)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 14
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 16442329894745639881165035015179028112772410105963688121820543219662832524136)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 15
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 20060625627350485876280451423010593928172611031611836167979515653463693899374)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 16
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 16637282689940520290130302519163090147511023430395200895953984829546679599107)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 17
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 15599196921909732993082127725908821049411366914683565306060493533569088698214)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 18
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 16894591341213863947423904025624185991098788054337051624251730868231322135455)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 19
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 1197934381747032348421303489683932612752526046745577259575778515005162320212)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 20
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 6172482022646932735745595886795230725225293469762393889050804649558459236626)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 21
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 21004037394166516054140386756510609698837211370585899203851827276330669555417)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 22
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 15262034989144652068456967541137853724140836132717012646544737680069032573006)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 23
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 15017690682054366744270630371095785995296470601172793770224691982518041139766)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 24
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 15159744167842240513848638419303545693472533086570469712794583342699782519832)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 25
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 11178069035565459212220861899558526502477231302924961773582350246646450941231)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 26
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 21154888769130549957415912997229564077486639529994598560737238811887296922114)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 27
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 20162517328110570500010831422938033120419484532231241180224283481905744633719)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 28
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 2777362604871784250419758188173029886707024739806641263170345377816177052018)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 29
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 15732290486829619144634131656503993123618032247178179298922551820261215487562)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 30
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 6024433414579583476444635447152826813568595303270846875177844482142230009826)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 31
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 17677827682004946431939402157761289497221048154630238117709539216286149983245)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 32
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 10716307389353583413755237303156291454109852751296156900963208377067748518748)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 33
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 14925386988604173087143546225719076187055229908444910452781922028996524347508)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 34
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 8940878636401797005293482068100797531020505636124892198091491586778667442523)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 35
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 18911747154199663060505302806894425160044925686870165583944475880789706164410)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 36
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 8821532432394939099312235292271438180996556457308429936910969094255825456935)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 37
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 20632576502437623790366878538516326728436616723089049415538037018093616927643)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 38
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 71447649211767888770311304010816315780740050029903404046389165015534756512)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 39
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 2781996465394730190470582631099299305677291329609718650018200531245670229393)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 40
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 12441376330954323535872906380510501637773629931719508864016287320488688345525)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 41
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 2558302139544901035700544058046419714227464650146159803703499681139469546006)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 42
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 10087036781939179132584550273563255199577525914374285705149349445480649057058)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 43
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 4267692623754666261749551533667592242661271409704769363166965280715887854739)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 44
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 4945579503584457514844595640661884835097077318604083061152997449742124905548)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 45
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 17742335354489274412669987990603079185096280484072783973732137326144230832311)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 46
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 6266270088302506215402996795500854910256503071464802875821837403486057988208)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 47
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 2716062168542520412498610856550519519760063668165561277991771577403400784706)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 48
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 19118392018538203167410421493487769944462015419023083813301166096764262134232)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 49
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 9386595745626044000666050847309903206827901310677406022353307960932745699524)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 50
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 9121640807890366356465620448383131419933298563527245687958865317869840082266)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 51
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 3078975275808111706229899605611544294904276390490742680006005661017864583210)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 52
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 7157404299437167354719786626667769956233708887934477609633504801472827442743)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 53
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 14056248655941725362944552761799461694550787028230120190862133165195793034373)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 54
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 14124396743304355958915937804966111851843703158171757752158388556919187839849)
            t0 := sbox_partial(t0, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 55
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 11851254356749068692552943732920045260402277343008629727465773766468466181076)
            t0, t1, t2, t3, t4 := sbox_full(t0, t1, t2, t3, t4, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 56
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 9799099446406796696742256539758943483211846559715874347178722060519817626047)
            t0, t1, t2, t3, t4 := sbox_full(t0, t1, t2, t3, t4, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
            // round 57
            t0, t1, t2, t3, t4 := ark(t0, t1, t2, t3, t4, q, 10156146186214948683880719664738535455146137901666656566575307300522957959544)
            t0, t1, t2, t3, t4 := sbox_full(t0, t1, t2, t3, t4, q)
            t0, t1, t2, t3, t4 := mix(t0, t1, t2, t3, t4, q)
        }
        return t0;
    }

    function hash_t5f6p52(HashInputs5 memory i, uint q) internal pure returns (uint)
    {
        // validate inputs
        require(i.t0 < q, "INVALID_INPUT");
        require(i.t1 < q, "INVALID_INPUT");
        require(i.t2 < q, "INVALID_INPUT");
        require(i.t3 < q, "INVALID_INPUT");
        require(i.t4 < q, "INVALID_INPUT");

        return hash_t5f6p52_internal(i.t0, i.t1, i.t2, i.t3, i.t4, q);
    }

    //
    // hash_t6f6p52
    //

    struct HashInputs6
    {
        uint t0;
        uint t1;
        uint t2;
        uint t3;
        uint t4;
        uint t5;
    }


    function mix(HashInputs6 memory i, uint q) internal pure 
    {
        HashInputs6 memory o;
        o.t0 = mulmod(i.t0, 19167410339349846567561662441069598364702008768579734801591448511131028229281, q);
        o.t0 = addmod(o.t0, mulmod(i.t1, 14183033936038168803360723133013092560869148726790180682363054735190196956789, q), q);
        o.t0 = addmod(o.t0, mulmod(i.t2, 9067734253445064890734144122526450279189023719890032859456830213166173619761, q), q);
        o.t0 = addmod(o.t0, mulmod(i.t3, 16378664841697311562845443097199265623838619398287411428110917414833007677155, q), q);
        o.t0 = addmod(o.t0, mulmod(i.t4, 12968540216479938138647596899147650021419273189336843725176422194136033835172, q), q);
        o.t0 = addmod(o.t0, mulmod(i.t5, 3636162562566338420490575570584278737093584021456168183289112789616069756675, q), q);
        o.t1 = mulmod(i.t0, 17034139127218860091985397764514160131253018178110701196935786874261236172431, q);
        o.t1 = addmod(o.t1, mulmod(i.t1, 2799255644797227968811798608332314218966179365168250111693473252876996230317, q), q);
        o.t1 = addmod(o.t1, mulmod(i.t2, 2482058150180648511543788012634934806465808146786082148795902594096349483974, q), q);
        o.t1 = addmod(o.t1, mulmod(i.t3, 16563522740626180338295201738437974404892092704059676533096069531044355099628, q), q);
        o.t1 = addmod(o.t1, mulmod(i.t4, 10468644849657689537028565510142839489302836569811003546969773105463051947124, q), q);
        o.t1 = addmod(o.t1, mulmod(i.t5, 3328913364598498171733622353010907641674136720305714432354138807013088636408, q), q);
        o.t2 = mulmod(i.t0, 18985203040268814769637347880759846911264240088034262814847924884273017355969, q);
        o.t2 = addmod(o.t2, mulmod(i.t1, 8652975463545710606098548415650457376967119951977109072274595329619335974180, q), q);
        o.t2 = addmod(o.t2, mulmod(i.t2, 970943815872417895015626519859542525373809485973005165410533315057253476903, q), q);
        o.t2 = addmod(o.t2, mulmod(i.t3, 19406667490568134101658669326517700199745817783746545889094238643063688871948, q), q);
        o.t2 = addmod(o.t2, mulmod(i.t4, 17049854690034965250221386317058877242629221002521630573756355118745574274967, q), q);
        o.t2 = addmod(o.t2, mulmod(i.t5, 4964394613021008685803675656098849539153699842663541444414978877928878266244, q), q);
        o.t3 = mulmod(i.t0, 19025623051770008118343718096455821045904242602531062247152770448380880817517, q);
        o.t3 = addmod(o.t3, mulmod(i.t1, 9077319817220936628089890431129759976815127354480867310384708941479362824016, q), q);
        o.t3 = addmod(o.t3, mulmod(i.t2, 4770370314098695913091200576539533727214143013236894216582648993741910829490, q), q);
        o.t3 = addmod(o.t3, mulmod(i.t3, 4298564056297802123194408918029088169104276109138370115401819933600955259473, q), q);
        o.t3 = addmod(o.t3, mulmod(i.t4, 6905514380186323693285869145872115273350947784558995755916362330070690839131, q), q);
        o.t3 = addmod(o.t3, mulmod(i.t5, 4783343257810358393326889022942241108539824540285247795235499223017138301952, q), q);
        o.t4 = mulmod(i.t0, 16205238342129310687768799056463408647672389183328001070715567975181364448609, q);
        o.t4 = addmod(o.t4, mulmod(i.t1, 8303849270045876854140023508764676765932043944545416856530551331270859502246, q), q);
        o.t4 = addmod(o.t4, mulmod(i.t2, 20218246699596954048529384569730026273241102596326201163062133863539137060414, q), q);
        o.t4 = addmod(o.t4, mulmod(i.t3, 1712845821388089905746651754894206522004527237615042226559791118162382909269, q), q);
        o.t4 = addmod(o.t4, mulmod(i.t4, 13001155522144542028910638547179410124467185319212645031214919884423841839406, q), q);
        o.t4 = addmod(o.t4, mulmod(i.t5, 16037892369576300958623292723740289861626299352695838577330319504984091062115, q), q);
        o.t5 = mulmod(i.t0, 15162889384227198851506890526431746552868519326873025085114621698588781611738, q);
        o.t5 = addmod(o.t5, mulmod(i.t1, 13272957914179340594010910867091459756043436017766464331915862093201960540910, q), q);
        o.t5 = addmod(o.t5, mulmod(i.t2, 9416416589114508529880440146952102328470363729880726115521103179442988482948, q), q);
        o.t5 = addmod(o.t5, mulmod(i.t3, 8035240799672199706102747147502951589635001418759394863664434079699838251138, q), q);
        o.t5 = addmod(o.t5, mulmod(i.t4, 21642389080762222565487157652540372010968704000567605990102641816691459811717, q), q);
        o.t5 = addmod(o.t5, mulmod(i.t5, 20261355950827657195644012399234591122288573679402601053407151083849785332516, q), q);
        i.t0 = o.t0;
        i.t1 = o.t1;
        i.t2 = o.t2;
        i.t3 = o.t3;
        i.t4 = o.t4;
        i.t5 = o.t5;
    }

    function ark(HashInputs6 memory i, uint q, uint c) internal pure 
    {
        HashInputs6 memory o;
        o.t0 = addmod(i.t0, c, q);
        o.t1 = addmod(i.t1, c, q);
        o.t2 = addmod(i.t2, c, q);
        o.t3 = addmod(i.t3, c, q);
        o.t4 = addmod(i.t4, c, q);
        o.t5 = addmod(i.t5, c, q);
        i.t0 = o.t0;
        i.t1 = o.t1;
        i.t2 = o.t2;
        i.t3 = o.t3;
        i.t4 = o.t4;
        i.t5 = o.t5;
    }

    function sbox_full(HashInputs6 memory i, uint q) internal pure 
    {
        HashInputs6 memory o;
        o.t0 = mulmod(i.t0, i.t0, q);
        o.t0 = mulmod(o.t0, o.t0, q);
        o.t0 = mulmod(i.t0, o.t0, q);
        o.t1 = mulmod(i.t1, i.t1, q);
        o.t1 = mulmod(o.t1, o.t1, q);
        o.t1 = mulmod(i.t1, o.t1, q);
        o.t2 = mulmod(i.t2, i.t2, q);
        o.t2 = mulmod(o.t2, o.t2, q);
        o.t2 = mulmod(i.t2, o.t2, q);
        o.t3 = mulmod(i.t3, i.t3, q);
        o.t3 = mulmod(o.t3, o.t3, q);
        o.t3 = mulmod(i.t3, o.t3, q);
        o.t4 = mulmod(i.t4, i.t4, q);
        o.t4 = mulmod(o.t4, o.t4, q);
        o.t4 = mulmod(i.t4, o.t4, q);
        o.t5 = mulmod(i.t5, i.t5, q);
        o.t5 = mulmod(o.t5, o.t5, q);
        o.t5 = mulmod(i.t5, o.t5, q);
        i.t0 = o.t0;
        i.t1 = o.t1;
        i.t2 = o.t2;
        i.t3 = o.t3;
        i.t4 = o.t4;
        i.t5 = o.t5;
    }

    function sbox_partial(HashInputs6 memory i, uint q) internal pure 
    {
        HashInputs6 memory o;
        o.t0 = mulmod(i.t0, i.t0, q);
        o.t0 = mulmod(o.t0, o.t0, q);
        o.t0 = mulmod(i.t0, o.t0, q);
        i.t0 = o.t0;
    }

    function hash_t6f6p52(HashInputs6 memory i, uint q) internal pure returns (uint)
    {
        // validate inputs
        require(i.t0 < q, "INVALID_INPUT");
        require(i.t1 < q, "INVALID_INPUT");
        require(i.t2 < q, "INVALID_INPUT");
        require(i.t3 < q, "INVALID_INPUT");
        require(i.t4 < q, "INVALID_INPUT");
        require(i.t5 < q, "INVALID_INPUT");

        // round 0
        ark(i, q, 14397397413755236225575615486459253198602422701513067526754101844196324375522);
        sbox_full(i, q);
        mix(i, q);
        // round 1
        ark(i, q, 10405129301473404666785234951972711717481302463898292859783056520670200613128);
        sbox_full(i, q);
        mix(i, q);
        // round 2
        ark(i, q, 5179144822360023508491245509308555580251733042407187134628755730783052214509);
        sbox_full(i, q);
        mix(i, q);
        // round 3
        ark(i, q, 9132640374240188374542843306219594180154739721841249568925550236430986592615);
        sbox_partial(i, q);
        mix(i, q);
        // round 4
        ark(i, q, 20360807315276763881209958738450444293273549928693737723235350358403012458514);
        sbox_partial(i, q);
        mix(i, q);
        // round 5
        ark(i, q, 17933600965499023212689924809448543050840131883187652471064418452962948061619);
        sbox_partial(i, q);
        mix(i, q);
        // round 6
        ark(i, q, 3636213416533737411392076250708419981662897009810345015164671602334517041153);
        sbox_partial(i, q);
        mix(i, q);
        // round 7
        ark(i, q, 2008540005368330234524962342006691994500273283000229509835662097352946198608);
        sbox_partial(i, q);
        mix(i, q);
        // round 8
        ark(i, q, 16018407964853379535338740313053768402596521780991140819786560130595652651567);
        sbox_partial(i, q);
        mix(i, q);
        // round 9
        ark(i, q, 20653139667070586705378398435856186172195806027708437373983929336015162186471);
        sbox_partial(i, q);
        mix(i, q);
        // round 10
        ark(i, q, 17887713874711369695406927657694993484804203950786446055999405564652412116765);
        sbox_partial(i, q);
        mix(i, q);
        // round 11
        ark(i, q, 4852706232225925756777361208698488277369799648067343227630786518486608711772);
        sbox_partial(i, q);
        mix(i, q);
        // round 12
        ark(i, q, 8969172011633935669771678412400911310465619639756845342775631896478908389850);
        sbox_partial(i, q);
        mix(i, q);
        // round 13
        ark(i, q, 20570199545627577691240476121888846460936245025392381957866134167601058684375);
        sbox_partial(i, q);
        mix(i, q);
        // round 14
        ark(i, q, 16442329894745639881165035015179028112772410105963688121820543219662832524136);
        sbox_partial(i, q);
        mix(i, q);
        // round 15
        ark(i, q, 20060625627350485876280451423010593928172611031611836167979515653463693899374);
        sbox_partial(i, q);
        mix(i, q);
        // round 16
        ark(i, q, 16637282689940520290130302519163090147511023430395200895953984829546679599107);
        sbox_partial(i, q);
        mix(i, q);
        // round 17
        ark(i, q, 15599196921909732993082127725908821049411366914683565306060493533569088698214);
        sbox_partial(i, q);
        mix(i, q);
        // round 18
        ark(i, q, 16894591341213863947423904025624185991098788054337051624251730868231322135455);
        sbox_partial(i, q);
        mix(i, q);
        // round 19
        ark(i, q, 1197934381747032348421303489683932612752526046745577259575778515005162320212);
        sbox_partial(i, q);
        mix(i, q);
        // round 20
        ark(i, q, 6172482022646932735745595886795230725225293469762393889050804649558459236626);
        sbox_partial(i, q);
        mix(i, q);
        // round 21
        ark(i, q, 21004037394166516054140386756510609698837211370585899203851827276330669555417);
        sbox_partial(i, q);
        mix(i, q);
        // round 22
        ark(i, q, 15262034989144652068456967541137853724140836132717012646544737680069032573006);
        sbox_partial(i, q);
        mix(i, q);
        // round 23
        ark(i, q, 15017690682054366744270630371095785995296470601172793770224691982518041139766);
        sbox_partial(i, q);
        mix(i, q);
        // round 24
        ark(i, q, 15159744167842240513848638419303545693472533086570469712794583342699782519832);
        sbox_partial(i, q);
        mix(i, q);
        // round 25
        ark(i, q, 11178069035565459212220861899558526502477231302924961773582350246646450941231);
        sbox_partial(i, q);
        mix(i, q);
        // round 26
        ark(i, q, 21154888769130549957415912997229564077486639529994598560737238811887296922114);
        sbox_partial(i, q);
        mix(i, q);
        // round 27
        ark(i, q, 20162517328110570500010831422938033120419484532231241180224283481905744633719);
        sbox_partial(i, q);
        mix(i, q);
        // round 28
        ark(i, q, 2777362604871784250419758188173029886707024739806641263170345377816177052018);
        sbox_partial(i, q);
        mix(i, q);
        // round 29
        ark(i, q, 15732290486829619144634131656503993123618032247178179298922551820261215487562);
        sbox_partial(i, q);
        mix(i, q);
        // round 30
        ark(i, q, 6024433414579583476444635447152826813568595303270846875177844482142230009826);
        sbox_partial(i, q);
        mix(i, q);
        // round 31
        ark(i, q, 17677827682004946431939402157761289497221048154630238117709539216286149983245);
        sbox_partial(i, q);
        mix(i, q);
        // round 32
        ark(i, q, 10716307389353583413755237303156291454109852751296156900963208377067748518748);
        sbox_partial(i, q);
        mix(i, q);
        // round 33
        ark(i, q, 14925386988604173087143546225719076187055229908444910452781922028996524347508);
        sbox_partial(i, q);
        mix(i, q);
        // round 34
        ark(i, q, 8940878636401797005293482068100797531020505636124892198091491586778667442523);
        sbox_partial(i, q);
        mix(i, q);
        // round 35
        ark(i, q, 18911747154199663060505302806894425160044925686870165583944475880789706164410);
        sbox_partial(i, q);
        mix(i, q);
        // round 36
        ark(i, q, 8821532432394939099312235292271438180996556457308429936910969094255825456935);
        sbox_partial(i, q);
        mix(i, q);
        // round 37
        ark(i, q, 20632576502437623790366878538516326728436616723089049415538037018093616927643);
        sbox_partial(i, q);
        mix(i, q);
        // round 38
        ark(i, q, 71447649211767888770311304010816315780740050029903404046389165015534756512);
        sbox_partial(i, q);
        mix(i, q);
        // round 39
        ark(i, q, 2781996465394730190470582631099299305677291329609718650018200531245670229393);
        sbox_partial(i, q);
        mix(i, q);
        // round 40
        ark(i, q, 12441376330954323535872906380510501637773629931719508864016287320488688345525);
        sbox_partial(i, q);
        mix(i, q);
        // round 41
        ark(i, q, 2558302139544901035700544058046419714227464650146159803703499681139469546006);
        sbox_partial(i, q);
        mix(i, q);
        // round 42
        ark(i, q, 10087036781939179132584550273563255199577525914374285705149349445480649057058);
        sbox_partial(i, q);
        mix(i, q);
        // round 43
        ark(i, q, 4267692623754666261749551533667592242661271409704769363166965280715887854739);
        sbox_partial(i, q);
        mix(i, q);
        // round 44
        ark(i, q, 4945579503584457514844595640661884835097077318604083061152997449742124905548);
        sbox_partial(i, q);
        mix(i, q);
        // round 45
        ark(i, q, 17742335354489274412669987990603079185096280484072783973732137326144230832311);
        sbox_partial(i, q);
        mix(i, q);
        // round 46
        ark(i, q, 6266270088302506215402996795500854910256503071464802875821837403486057988208);
        sbox_partial(i, q);
        mix(i, q);
        // round 47
        ark(i, q, 2716062168542520412498610856550519519760063668165561277991771577403400784706);
        sbox_partial(i, q);
        mix(i, q);
        // round 48
        ark(i, q, 19118392018538203167410421493487769944462015419023083813301166096764262134232);
        sbox_partial(i, q);
        mix(i, q);
        // round 49
        ark(i, q, 9386595745626044000666050847309903206827901310677406022353307960932745699524);
        sbox_partial(i, q);
        mix(i, q);
        // round 50
        ark(i, q, 9121640807890366356465620448383131419933298563527245687958865317869840082266);
        sbox_partial(i, q);
        mix(i, q);
        // round 51
        ark(i, q, 3078975275808111706229899605611544294904276390490742680006005661017864583210);
        sbox_partial(i, q);
        mix(i, q);
        // round 52
        ark(i, q, 7157404299437167354719786626667769956233708887934477609633504801472827442743);
        sbox_partial(i, q);
        mix(i, q);
        // round 53
        ark(i, q, 14056248655941725362944552761799461694550787028230120190862133165195793034373);
        sbox_partial(i, q);
        mix(i, q);
        // round 54
        ark(i, q, 14124396743304355958915937804966111851843703158171757752158388556919187839849);
        sbox_partial(i, q);
        mix(i, q);
        // round 55
        ark(i, q, 11851254356749068692552943732920045260402277343008629727465773766468466181076);
        sbox_full(i, q);
        mix(i, q);
        // round 56
        ark(i, q, 9799099446406796696742256539758943483211846559715874347178722060519817626047);
        sbox_full(i, q);
        mix(i, q);
        // round 57
        ark(i, q, 10156146186214948683880719664738535455146137901666656566575307300522957959544);
        sbox_full(i, q);
        mix(i, q);

        return i.t0;
    }
}

File 23 of 95 : ExchangeBlocks.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../../lib/AddressUtil.sol";
import "../../../lib/MathUint.sol";
import "../../../thirdparty/BytesUtil.sol";
import "../../iface/ExchangeData.sol";
import "../../iface/IBlockVerifier.sol";
import "../libtransactions/BlockReader.sol";
import "../libtransactions/AccountUpdateTransaction.sol";
import "../libtransactions/DepositTransaction.sol";
import "../libtransactions/WithdrawTransaction.sol";
import "./ExchangeMode.sol";
import "./ExchangeWithdrawals.sol";


/// @title ExchangeBlocks.
/// @author Brecht Devos - <[email protected]>
/// @author Daniel Wang  - <[email protected]>
library ExchangeBlocks
{
    using AddressUtil          for address;
    using AddressUtil          for address payable;
    using BlockReader          for bytes;
    using BytesUtil            for bytes;
    using MathUint             for uint;
    using ExchangeMode         for ExchangeData.State;
    using ExchangeWithdrawals  for ExchangeData.State;
    using SignatureUtil        for bytes32;

    event BlockSubmitted(
        uint    indexed blockIdx,
        bytes32         merkleRoot,
        bytes32         publicDataHash
    );

    event ProtocolFeesUpdated(
        uint16 protocolFeeBips,
        uint16 previousProtocolFeeBips
    );

    function submitBlocks(
        ExchangeData.State   storage S,
        ExchangeData.Block[] memory  blocks
        )
        public
    {
        // Exchange cannot be in withdrawal mode
        require(!S.isInWithdrawalMode(), "INVALID_MODE");

        // Commit the blocks
        bytes32[] memory publicDataHashes = new bytes32[](blocks.length);
        for (uint i = 0; i < blocks.length; i++) {
            // Hash all the public data to a single value which is used as the input for the circuit
            publicDataHashes[i] = blocks[i].data.fastSHA256();
            // Commit the block
            commitBlock(S, blocks[i], publicDataHashes[i]);
        }

        // Verify the blocks - blocks are verified in a batch to save gas.
        verifyBlocks(S, blocks, publicDataHashes);
    }

    // == Internal Functions ==

    function commitBlock(
        ExchangeData.State storage S,
        ExchangeData.Block memory  _block,
        bytes32                    _publicDataHash
        )
        private
    {
        // Read the block header
        BlockReader.BlockHeader memory header = _block.data.readHeader();

        // Validate the exchange
        require(header.exchange == address(this), "INVALID_EXCHANGE");
        // Validate the Merkle roots
        require(header.merkleRootBefore == S.merkleRoot, "INVALID_MERKLE_ROOT");
        require(header.merkleRootAfter != header.merkleRootBefore, "EMPTY_BLOCK_DISABLED");
        require(header.merkleAssetRootBefore == S.merkleAssetRoot, "INVALID_MERKLE_ASSET_ROOT");
        require(header.merkleAssetRootAfter != header.merkleAssetRootBefore, "EMPTY_BLOCK_DISABLED");

        require(uint(header.merkleRootAfter) < ExchangeData.SNARK_SCALAR_FIELD, "INVALID_MERKLE_ROOT");
        require(uint(header.merkleAssetRootAfter) < ExchangeData.SNARK_SCALAR_FIELD, "INVALID_ASSERT_MERKLE_ROOT");
        // Validate the timestamp
        require(
            header.timestamp > block.timestamp - ExchangeData.TIMESTAMP_HALF_WINDOW_SIZE_IN_SECONDS &&
            header.timestamp < block.timestamp + ExchangeData.TIMESTAMP_HALF_WINDOW_SIZE_IN_SECONDS,
            "INVALID_TIMESTAMP"
        );
        // Validate the protocol fee values
        require(
            validateAndSyncProtocolFees(S, header.protocolFeeBips),
            "INVALID_PROTOCOL_FEES"
        );

        // Process conditional transactions
        processConditionalTransactions(
            S,
            _block,
            header
        );

        // Emit an event
        uint numBlocks = S.numBlocks;
        emit BlockSubmitted(numBlocks, header.merkleRootAfter, _publicDataHash);

        S.merkleRoot = header.merkleRootAfter;
        S.merkleAssetRoot = header.merkleAssetRootAfter;

        if (_block.storeBlockInfoOnchain) {
            S.blocks[numBlocks] = ExchangeData.BlockInfo(
                uint32(block.timestamp),
                bytes28(_publicDataHash)
            );
        }

        S.numBlocks = numBlocks + 1;
    }

    function verifyBlocks(
        ExchangeData.State   storage S,
        ExchangeData.Block[] memory  blocks,
        bytes32[]            memory  publicDataHashes
        )
        private
        view
    {
        IBlockVerifier blockVerifier = S.blockVerifier;
        uint numBlocksVerified = 0;
        bool[] memory blockVerified = new bool[](blocks.length);
        ExchangeData.Block memory firstBlock;
        uint[] memory batch = new uint[](blocks.length);

        while (numBlocksVerified < blocks.length) {
            // Find all blocks of the same type
            uint batchLength = 0;
            for (uint i = 0; i < blocks.length; i++) {
                if (blockVerified[i] == false) {
                    if (batchLength == 0) {
                        firstBlock = blocks[i];
                        batch[batchLength++] = i;
                    } else {
                        ExchangeData.Block memory _block = blocks[i];
                        if (_block.blockType == firstBlock.blockType &&
                            _block.blockSize == firstBlock.blockSize &&
                            _block.blockVersion == firstBlock.blockVersion) {
                            batch[batchLength++] = i;
                        }
                    }
                }
            }

            // Prepare the data for batch verification
            uint[] memory publicInputs = new uint[](batchLength);
            uint[] memory proofs = new uint[](batchLength * 8);

            for (uint i = 0; i < batchLength; i++) {
                uint blockIdx = batch[i];
                // Mark the block as verified
                blockVerified[blockIdx] = true;
                // Strip the 3 least significant bits of the public data hash
                // so we don't have any overflow in the snark field
                publicInputs[i] = uint(publicDataHashes[blockIdx]) >> 3;
                // Copy proof
                ExchangeData.Block memory _block = blocks[blockIdx];
                for (uint j = 0; j < 8; j++) {
                    proofs[i*8 + j] = _block.proof[j];
                }
            }

            // Verify the proofs
            require(
                blockVerifier.verifyProofs(
                    uint8(firstBlock.blockType),
                    firstBlock.blockSize,
                    firstBlock.blockVersion,
                    publicInputs,
                    proofs
                ),
                "INVALID_PROOF"
            );

            numBlocksVerified += batchLength;
        }
    }

    function processConditionalTransactions(
        ExchangeData.State      storage S,
        ExchangeData.Block      memory _block,
        BlockReader.BlockHeader memory header
        )
        private
    {
        if (header.numConditionalTransactions > 0) {
            // Cache the domain seperator to save on SLOADs each time it is accessed.
            ExchangeData.BlockContext memory ctx = ExchangeData.BlockContext({
                DOMAIN_SEPARATOR: S.DOMAIN_SEPARATOR,
                timestamp: header.timestamp
            });

            ExchangeData.AuxiliaryData[] memory block_auxiliaryData;
            bytes memory blockAuxData = _block.auxiliaryData;
            assembly {
                block_auxiliaryData := add(blockAuxData, 64)
            }

            require(
                block_auxiliaryData.length == header.numConditionalTransactions,
                "AUXILIARYDATA_INVALID_LENGTH"
            );

            require(
                header.numConditionalTransactions == (header.depositSize + header.accountUpdateSize + header.withdrawSize),
                "invalid number of conditional transactions"
            );

            // Run over all conditional transactions
            uint minTxIndex = 0;
            bytes memory txData = new bytes(ExchangeData.TX_DATA_AVAILABILITY_SIZE);
            for (uint i = 0; i < block_auxiliaryData.length; i++) {
                uint txIndex;
                ExchangeData.TransactionType txType;
                if (i < header.depositSize) {
                    txType = ExchangeData.TransactionType.DEPOSIT;
                    txIndex = i; 
                }else if(i < header.depositSize + header.accountUpdateSize) {
                    txType = ExchangeData.TransactionType.ACCOUNT_UPDATE;
                    txIndex = i;
                }else {
                    txType = ExchangeData.TransactionType.WITHDRAWAL;
                    txIndex = i + _block.blockSize - header.depositSize - header.accountUpdateSize - header.withdrawSize; 
                }

                // Load the data from auxiliaryData, which is still encoded as calldata



                bytes memory auxData;
                assembly {
                    // Offset to block_auxiliaryData[i]
                    let auxOffset := mload(add(block_auxiliaryData, add(32, mul(32, i))))

                    // Load `data` (pos 0)
                    let auxDataOffset := mload(add(add(32, block_auxiliaryData), auxOffset))
                    auxData := add(add(32, block_auxiliaryData), add(auxOffset, auxDataOffset))
                }

                // Each conditional transaction needs to be processed from left to right
                require(txIndex >= minTxIndex, "AUXILIARYDATA_INVALID_ORDER");

                minTxIndex = txIndex + 1;


                // Get the transaction data
                _block.data.readTransactionData(txIndex, _block.blockSize, txData);

                // Process the transaction
                uint txDataOffset = 0;

                if (txType == ExchangeData.TransactionType.DEPOSIT) {
                    DepositTransaction.process(
                        S,
                        ctx,
                        txData,
                        txDataOffset,
                        auxData
                    );
                } else if (txType == ExchangeData.TransactionType.WITHDRAWAL) {
                    WithdrawTransaction.process(
                        S,
                        ctx,
                        txData,
                        txDataOffset,
                        auxData
                    );
                } else if (txType == ExchangeData.TransactionType.ACCOUNT_UPDATE) {
                    AccountUpdateTransaction.process(
                        S,
                        ctx,
                        txData,
                        txDataOffset,
                        auxData
                    );
                } else {
                    // ExchangeData.TransactionType.NOOP,
                    // ExchangeData.TransactionType.TRANSFER and
                    // ExchangeData.TransactionType.SPOT_TRADE and
                    // ExchangeData.TransactionType.ORDER_CANCEL and
                    // ExchangeData.TransactionType.BATCH_SPOT_TRADE 
                    // ExchangeData.TransactionType.APPKEY_UPDATE 
                    // are not supported
                    revert("UNSUPPORTED_TX_TYPE");
                }
            }
        }
    }

    function validateAndSyncProtocolFees(
        ExchangeData.State storage S,
        uint16 protocolFeeBips
        )
        private
        returns (bool)
    {
        ExchangeData.ProtocolFeeData memory data = S.protocolFeeData;

        uint16 protocolFeeBipsInLoopring = S.loopring.getProtocolFeeValues();
        if (data.nextProtocolFeeBips != protocolFeeBipsInLoopring ) {
            data.executeTimeOfNextProtocolFeeBips = uint32(block.timestamp + ExchangeData.MIN_AGE_PROTOCOL_FEES_UNTIL_UPDATED);
            data.nextProtocolFeeBips = protocolFeeBipsInLoopring;

            // Update the data in storage
            S.protocolFeeData = data;
        }

        if ((data.executeTimeOfNextProtocolFeeBips !=0) && (block.timestamp > data.executeTimeOfNextProtocolFeeBips)) {
            // Store the current protocol fees in the previous protocol fees
            data.previousProtocolFeeBips = data.protocolFeeBips;
            // Get the latest protocol fees for this exchange
            data.protocolFeeBips = data.nextProtocolFeeBips;
            data.syncedAt = uint32(block.timestamp);

            data.executeTimeOfNextProtocolFeeBips = 0;

            if (data.protocolFeeBips != data.previousProtocolFeeBips ) {
                emit ProtocolFeesUpdated(
                    data.protocolFeeBips,
                    data.previousProtocolFeeBips
                );
            }

            // Update the data in storage
            S.protocolFeeData = data;
        }

        // The given fee values are valid if they are the current or previous protocol fee values
        return (protocolFeeBips == data.protocolFeeBips) ||
            (protocolFeeBips == data.previousProtocolFeeBips );
    }
}

File 24 of 95 : BytesUtil.sol
// SPDX-License-Identifier: UNLICENSED
//Mainly taken from https://github.com/GNSPS/solidity-bytes-utils/blob/master/contracts/BytesLib.sol
pragma solidity ^0.7.0;

library BytesUtil {

    function concat(
        bytes memory _preBytes,
        bytes memory _postBytes
    )
        internal
        pure
        returns (bytes memory)
    {
        bytes memory tempBytes;

        assembly {
            // Get a location of some free memory and store it in tempBytes as
            // Solidity does for memory variables.
            tempBytes := mload(0x40)

            // Store the length of the first bytes array at the beginning of
            // the memory for tempBytes.
            let length := mload(_preBytes)
            mstore(tempBytes, length)

            // Maintain a memory counter for the current write location in the
            // temp bytes array by adding the 32 bytes for the array length to
            // the starting location.
            let mc := add(tempBytes, 0x20)
            // Stop copying when the memory counter reaches the length of the
            // first bytes array.
            let end := add(mc, length)

            for {
                // Initialize a copy counter to the start of the _preBytes data,
                // 32 bytes into its memory.
                let cc := add(_preBytes, 0x20)
            } lt(mc, end) {
                // Increase both counters by 32 bytes each iteration.
                mc := add(mc, 0x20)
                cc := add(cc, 0x20)
            } {
                // Write the _preBytes data into the tempBytes memory 32 bytes
                // at a time.
                mstore(mc, mload(cc))
            }

            // Add the length of _postBytes to the current length of tempBytes
            // and store it as the new length in the first 32 bytes of the
            // tempBytes memory.
            length := mload(_postBytes)
            mstore(tempBytes, add(length, mload(tempBytes)))

            // Move the memory counter back from a multiple of 0x20 to the
            // actual end of the _preBytes data.
            mc := end
            // Stop copying when the memory counter reaches the new combined
            // length of the arrays.
            end := add(mc, length)

            for {
                let cc := add(_postBytes, 0x20)
            } lt(mc, end) {
                mc := add(mc, 0x20)
                cc := add(cc, 0x20)
            } {
                mstore(mc, mload(cc))
            }

            // Update the free-memory pointer by padding our last write location
            // to 32 bytes: add 31 bytes to the end of tempBytes to move to the
            // next 32 byte block, then round down to the nearest multiple of
            // 32. If the sum of the length of the two arrays is zero then add
            // one before rounding down to leave a blank 32 bytes (the length block with 0).
            mstore(0x40, and(
              add(add(end, iszero(add(length, mload(_preBytes)))), 31),
              not(31) // Round down to the nearest 32 bytes.
            ))
        }

        return tempBytes;
    }

    function slice(
        bytes memory _bytes,
        uint _start,
        uint _length
    )
        internal
        pure
        returns (bytes memory)
    {
        require(_bytes.length >= (_start + _length));

        bytes memory tempBytes;

        assembly {
            switch iszero(_length)
            case 0 {
                // Get a location of some free memory and store it in tempBytes as
                // Solidity does for memory variables.
                tempBytes := mload(0x40)

                // The first word of the slice result is potentially a partial
                // word read from the original array. To read it, we calculate
                // the length of that partial word and start copying that many
                // bytes into the array. The first word we copy will start with
                // data we don't care about, but the last `lengthmod` bytes will
                // land at the beginning of the contents of the new array. When
                // we're done copying, we overwrite the full first word with
                // the actual length of the slice.
                let lengthmod := and(_length, 31)

                // The multiplication in the next line is necessary
                // because when slicing multiples of 32 bytes (lengthmod == 0)
                // the following copy loop was copying the origin's length
                // and then ending prematurely not copying everything it should.
                let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
                let end := add(mc, _length)

                for {
                    // The multiplication in the next line has the same exact purpose
                    // as the one above.
                    let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
                } lt(mc, end) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    mstore(mc, mload(cc))
                }

                mstore(tempBytes, _length)

                //update free-memory pointer
                //allocating the array padded to 32 bytes like the compiler does now
                mstore(0x40, and(add(mc, 31), not(31)))
            }
            //if we want a zero-length slice let's just return a zero-length array
            default {
                tempBytes := mload(0x40)

                mstore(0x40, add(tempBytes, 0x20))
            }
        }

        return tempBytes;
    }

    function toAddress(bytes memory _bytes, uint _start) internal  pure returns (address) {
        require(_bytes.length >= (_start + 20));
        address tempAddress;

        assembly {
            tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)
        }

        return tempAddress;
    }

    function toUint8(bytes memory _bytes, uint _start) internal  pure returns (uint8) {
        require(_bytes.length >= (_start + 1));
        uint8 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x1), _start))
        }

        return tempUint;
    }

    function toUint16(bytes memory _bytes, uint _start) internal  pure returns (uint16) {
        require(_bytes.length >= (_start + 2));
        uint16 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x2), _start))
        }

        return tempUint;
    }

    function toUint24(bytes memory _bytes, uint _start) internal  pure returns (uint24) {
        require(_bytes.length >= (_start + 3));
        uint24 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x3), _start))
        }

        return tempUint;
    }

    function toUint32(bytes memory _bytes, uint _start) internal  pure returns (uint32) {
        require(_bytes.length >= (_start + 4));
        uint32 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x4), _start))
        }

        return tempUint;
    }

    function toUint64(bytes memory _bytes, uint _start) internal  pure returns (uint64) {
        require(_bytes.length >= (_start + 8));
        uint64 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x8), _start))
        }

        return tempUint;
    }

    function toUint96(bytes memory _bytes, uint _start) internal  pure returns (uint96) {
        require(_bytes.length >= (_start + 12));
        uint96 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0xc), _start))
        }

        return tempUint;
    }

    function toUint128(bytes memory _bytes, uint _start) internal  pure returns (uint128) {
        require(_bytes.length >= (_start + 16));
        uint128 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x10), _start))
        }

        return tempUint;
    }

    function toUint(bytes memory _bytes, uint _start) internal  pure returns (uint256) {
        require(_bytes.length >= (_start + 32));
        uint256 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x20), _start))
        }

        return tempUint;
    }

    function toBytes4(bytes memory _bytes, uint _start) internal  pure returns (bytes4) {
        require(_bytes.length >= (_start + 4));
        bytes4 tempBytes4;

        assembly {
            tempBytes4 := mload(add(add(_bytes, 0x20), _start))
        }

        return tempBytes4;
    }

    function toBytes20(bytes memory _bytes, uint _start) internal  pure returns (bytes20) {
        require(_bytes.length >= (_start + 20));
        bytes20 tempBytes20;

        assembly {
            tempBytes20 := mload(add(add(_bytes, 0x20), _start))
        }

        return tempBytes20;
    }

    function toBytes32(bytes memory _bytes, uint _start) internal  pure returns (bytes32) {
        require(_bytes.length >= (_start + 32));
        bytes32 tempBytes32;

        assembly {
            tempBytes32 := mload(add(add(_bytes, 0x20), _start))
        }

        return tempBytes32;
    }


    function toAddressUnsafe(bytes memory _bytes, uint _start) internal  pure returns (address) {
        address tempAddress;

        assembly {
            tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)
        }

        return tempAddress;
    }

    function toUint8Unsafe(bytes memory _bytes, uint _start) internal  pure returns (uint8) {
        uint8 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x1), _start))
        }

        return tempUint;
    }

    function toUint16Unsafe(bytes memory _bytes, uint _start) internal  pure returns (uint16) {
        uint16 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x2), _start))
        }

        return tempUint;
    }

    function toUint24Unsafe(bytes memory _bytes, uint _start) internal  pure returns (uint24) {
        uint24 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x3), _start))
        }

        return tempUint;
    }

    function toUint32Unsafe(bytes memory _bytes, uint _start) internal  pure returns (uint32) {
        uint32 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x4), _start))
        }

        return tempUint;
    }

    function toUint64Unsafe(bytes memory _bytes, uint _start) internal  pure returns (uint64) {
        uint64 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x8), _start))
        }

        return tempUint;
    }

    function toUint96Unsafe(bytes memory _bytes, uint _start) internal  pure returns (uint96) {
        uint96 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0xc), _start))
        }

        return tempUint;
    }

    function toUint128Unsafe(bytes memory _bytes, uint _start) internal  pure returns (uint128) {
        uint128 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x10), _start))
        }

        return tempUint;
    }


    function toUint248Unsafe(bytes memory _bytes, uint _start) internal  pure returns (uint248) {
        uint248 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x1f), _start))
        }

        return tempUint;
    }

    function toUintUnsafe(bytes memory _bytes, uint _start) internal  pure returns (uint256) {
        uint256 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x20), _start))
        }

        return tempUint;
    }

    function toBytes4Unsafe(bytes memory _bytes, uint _start) internal  pure returns (bytes4) {
        bytes4 tempBytes4;

        assembly {
            tempBytes4 := mload(add(add(_bytes, 0x20), _start))
        }

        return tempBytes4;
    }

    function toBytes20Unsafe(bytes memory _bytes, uint _start) internal  pure returns (bytes20) {
        bytes20 tempBytes20;

        assembly {
            tempBytes20 := mload(add(add(_bytes, 0x20), _start))
        }

        return tempBytes20;
    }

    function toBytes32Unsafe(bytes memory _bytes, uint _start) internal  pure returns (bytes32) {
        bytes32 tempBytes32;

        assembly {
            tempBytes32 := mload(add(add(_bytes, 0x20), _start))
        }

        return tempBytes32;
    }


    function fastSHA256(
        bytes memory data
        )
        internal
        view
        returns (bytes32)
    {
        bytes32[] memory result = new bytes32[](1);
        bool success;
        assembly {
             let ptr := add(data, 32)
             success := staticcall(sub(gas(), 2000), 2, ptr, mload(data), add(result, 32), 32)
        }
        require(success, "SHA256_FAILED");
        return result[0];
    }
}

File 25 of 95 : BlockReader.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../../thirdparty/BytesUtil.sol";
import "../../iface/ExchangeData.sol";

/// @title BlockReader
/// @author Brecht Devos - <[email protected]>
/// @dev Utility library to read block data.
library BlockReader {
    using BlockReader       for ExchangeData.Block;
    using BytesUtil         for bytes;

    uint public constant OFFSET_TO_TRANSACTIONS = 20 + 32 + 32 + 32 + 32 + 4 + 2 + 4 + 4 + 2 + 2 + 2;


    struct BlockHeader
    {
        address exchange;
        bytes32 merkleRootBefore;
        bytes32 merkleRootAfter;
        bytes32 merkleAssetRootBefore;
        bytes32 merkleAssetRootAfter;
        uint32  timestamp;
        uint16  protocolFeeBips;

        uint32  numConditionalTransactions;
        uint32  operatorAccountID;

        uint16  depositSize;
        uint16  accountUpdateSize;
        uint16  withdrawSize;
    }

    function readHeader(
        bytes memory _blockData
        )
        internal
        pure
        returns (BlockHeader memory header)
    {
        uint offset = 0;
        header.exchange = _blockData.toAddress(offset);
        offset += 20;
        header.merkleRootBefore = _blockData.toBytes32(offset);
        offset += 32;
        header.merkleRootAfter = _blockData.toBytes32(offset);
        offset += 32;
        
        header.merkleAssetRootBefore = _blockData.toBytes32(offset);
        offset += 32;
        header.merkleAssetRootAfter = _blockData.toBytes32(offset);
        offset += 32;

        header.timestamp = _blockData.toUint32(offset);
        offset += 4;

        header.protocolFeeBips = _blockData.toUint16(offset);
        offset += 2;

        header.numConditionalTransactions = _blockData.toUint32(offset);
        offset += 4;
        header.operatorAccountID = _blockData.toUint32(offset);
        offset += 4;

        header.depositSize = _blockData.toUint16(offset);
        offset += 2;
        header.accountUpdateSize = _blockData.toUint16(offset);
        offset += 2;
        header.withdrawSize = _blockData.toUint16(offset);
        offset += 2;


        assert(offset == OFFSET_TO_TRANSACTIONS);
    }

    function readTransactionData(
        bytes memory data,
        uint txIdx,
        uint blockSize,
        bytes memory txData
        )
        internal
        pure
    {
        require(txIdx < blockSize, "INVALID_TX_IDX");

        // The transaction was transformed to make it easier to compress.
        // Transform it back here.
        // Part 1
        uint txDataOffset = OFFSET_TO_TRANSACTIONS +
            txIdx * ExchangeData.TX_DATA_AVAILABILITY_SIZE_PART_1;
        assembly {
            //  first 32 bytes of an Array stores the length of that array.

            // part_1 is 80 bytes, longer than 32 bytes,  80 = 32 + 32 + 16
            mstore(add(txData, 32), mload(add(data, add(txDataOffset, 32))))
            mstore(add(txData, 64), mload(add(data, add(txDataOffset, 64))))
            mstore(add(txData, 80), mload(add(data, add(txDataOffset, 80))))
        }
        // Part 2
        txDataOffset = OFFSET_TO_TRANSACTIONS +
            blockSize * ExchangeData.TX_DATA_AVAILABILITY_SIZE_PART_1 +
            txIdx * ExchangeData.TX_DATA_AVAILABILITY_SIZE_PART_2;
        assembly {
            // part_2 is 3 bytes
            // 112 = 32 + 80(part_1)
            mstore(add(txData, 112 ), mload(add(data, add(txDataOffset, 32))))
        }
    }
}

File 26 of 95 : AccountUpdateTransaction.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../../lib/EIP712.sol";
import "../../../lib/FloatUtil.sol";
import "../../../thirdparty/BytesUtil.sol";
import "../../iface/ExchangeData.sol";
import "../libexchange/ExchangeSignatures.sol";


/// @title AccountUpdateTransaction
/// @author Brecht Devos - <[email protected]>
library AccountUpdateTransaction
{
    using BytesUtil            for bytes;
    using FloatUtil            for uint16;
    using ExchangeSignatures   for ExchangeData.State;

    bytes32 constant public ACCOUNTUPDATE_TYPEHASH = keccak256(
        "AccountUpdate(address owner,uint32 accountID,uint32 feeTokenID,uint96 maxFee,uint256 publicKey,uint32 validUntil,uint32 nonce)"
    );

    struct AccountUpdate
    {
        address owner;
        uint32  accountID;
        uint32  feeTokenID;
        uint96  maxFee;
        uint96  fee;
        uint    publicKey;
        uint32  validUntil;
        uint32  nonce;
    }

    // Auxiliary data for each account update
    struct AccountUpdateAuxiliaryData
    {
        bytes  signature;
        uint96 maxFee;
        uint32 validUntil;
    }

    function process(
        ExchangeData.State        storage S,
        ExchangeData.BlockContext memory  ctx,
        bytes                     memory  data,
        uint                              offset,
        bytes                     memory  auxiliaryData
        )
        internal
    {
        // Read the account update
        AccountUpdate memory accountUpdate;
        readTx(data, offset, accountUpdate);
        AccountUpdateAuxiliaryData memory auxData = abi.decode(auxiliaryData, (AccountUpdateAuxiliaryData));

        // Fill in withdrawal data missing from DA
        accountUpdate.validUntil = auxData.validUntil;
        accountUpdate.maxFee = auxData.maxFee;
        // Validate
        require(ctx.timestamp < accountUpdate.validUntil, "ACCOUNT_UPDATE_EXPIRED");
        require(accountUpdate.fee <= accountUpdate.maxFee, "ACCOUNT_UPDATE_FEE_TOO_HIGH");

        // Calculate the tx hash
        bytes32 txHash = hashTx(ctx.DOMAIN_SEPARATOR, accountUpdate);

        // Check onchain authorization
        S.requireAuthorizedTx(accountUpdate.owner, auxData.signature, txHash);

    }

    function readTx(
        bytes memory data,
        uint         offset,
        AccountUpdate memory accountUpdate
        )
        private
        pure
    {
        uint _offset = offset;

        // Check that this is a conditional offset
        require(data.toUint8Unsafe(_offset) == 1, "INVALID_AUXILIARYDATA_DATA");
        _offset += 1;

        // Extract the data from the tx data
        // We don't use abi.decode for this because of the large amount of zero-padding
        // bytes the circuit would also have to hash.
        accountUpdate.owner = data.toAddressUnsafe(_offset);
        _offset += 20;
        accountUpdate.accountID = data.toUint32Unsafe(_offset);
        _offset += 4;
        accountUpdate.feeTokenID = data.toUint32Unsafe(_offset);
        _offset += 4;
        accountUpdate.fee = data.toUint16Unsafe(_offset).decodeFloat16();
        _offset += 2;
        accountUpdate.publicKey = data.toUintUnsafe(_offset);
        _offset += 32;
        accountUpdate.nonce = data.toUint32Unsafe(_offset);
        _offset += 4;
    }

    function hashTx(
        bytes32 DOMAIN_SEPARATOR,
        AccountUpdate memory accountUpdate
        )
        private
        pure
        returns (bytes32)
    {
        return EIP712.hashPacked(
            DOMAIN_SEPARATOR,
            keccak256(
                abi.encode(
                    ACCOUNTUPDATE_TYPEHASH,
                    accountUpdate.owner,
                    accountUpdate.accountID,
                    accountUpdate.feeTokenID,
                    accountUpdate.maxFee,
                    accountUpdate.publicKey,
                    accountUpdate.validUntil,
                    accountUpdate.nonce
                )
            )
        );
    }
}

File 27 of 95 : FloatUtil.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "./MathUint.sol";
import "../thirdparty/SafeCast.sol";


/// @title Utility Functions for floats
/// @author Brecht Devos - <[email protected]>
library FloatUtil
{
    using MathUint for uint;
    using SafeCast for uint;

    // Decodes a decimal float value that is encoded like `exponent | mantissa`.
    // Both exponent and mantissa are in base 10.
    // Decoding to an integer is as simple as `mantissa * (10 ** exponent)`
    // Will throw when the decoded value overflows an uint96
    /// @param f The float value with 5 bits for the exponent
    /// @param numBits The total number of bits (numBitsMantissa := numBits - numBitsExponent)
    /// @return value The decoded integer value.
    function decodeFloat(
        uint f,
        uint numBits
        )
        internal
        pure
        returns (uint96 value)
    {
        if (f == 0) {
            return 0;
        }
        uint numBitsMantissa = numBits.sub(5);
        uint exponent = f >> numBitsMantissa;
        // log2(10**77) = 255.79 < 256
        require(exponent <= 77, "EXPONENT_TOO_LARGE");
        uint mantissa = f & ((1 << numBitsMantissa) - 1);
        value = mantissa.mul(10 ** exponent).toUint96();
    }

    // Decodes a decimal float value that is encoded like `exponent | mantissa`.
    // Both exponent and mantissa are in base 10.
    // Decoding to an integer is as simple as `mantissa * (10 ** exponent)`
    // Will throw when the decoded value overflows an uint96
    /// @param f The float value with 5 bits exponent, 11 bits mantissa
    /// @return value The decoded integer value.
    function decodeFloat16(
        uint16 f
        )
        internal
        pure
        returns (uint96)
    {
        uint value = ((uint(f) & 2047) * (10 ** (uint(f) >> 11)));
        require(value < 2**96, "SafeCast: value doesn\'t fit in 96 bits");
        return uint96(value);
    }

    // Decodes a decimal float value that is encoded like `exponent | mantissa`.
    // Both exponent and mantissa are in base 10.
    // Decoding to an integer is as simple as `mantissa * (10 ** exponent)`
    // Will throw when the decoded value overflows an uint96
    /// @param f The float value with 5 bits exponent, 19 bits mantissa
    /// @return value The decoded integer value.
    function decodeFloat24(
        uint24 f
        )
        internal
        pure
        returns (uint96)
    {
        uint value = ((uint(f) & 524287) * (10 ** (uint(f) >> 19)));
        require(value < 2**96, "SafeCast: value doesn\'t fit in 96 bits");
        return uint96(value);
    }
}

File 28 of 95 : SafeCast.sol
// SPDX-License-Identifier: MIT
// Taken from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/SafeCast.sol

pragma solidity ^0.7.0;


/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {

    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        require(value < 2**248, "SafeCast: value doesn\'t fit in 248 bits");
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value < 2**128, "SafeCast: value doesn\'t fit in 128 bits");
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        require(value < 2**96, "SafeCast: value doesn\'t fit in 96 bits");
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value < 2**64, "SafeCast: value doesn\'t fit in 64 bits");
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value < 2**32, "SafeCast: value doesn\'t fit in 32 bits");
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        require(value < 2**40, "SafeCast: value doesn\'t fit in 40 bits");
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value < 2**16, "SafeCast: value doesn\'t fit in 16 bits");
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits.
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value < 2**8, "SafeCast: value doesn\'t fit in 8 bits");
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128) {
        require(value >= -2**127 && value < 2**127, "SafeCast: value doesn\'t fit in 128 bits");
        return int128(value);
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64) {
        require(value >= -2**63 && value < 2**63, "SafeCast: value doesn\'t fit in 64 bits");
        return int64(value);
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32) {
        require(value >= -2**31 && value < 2**31, "SafeCast: value doesn\'t fit in 32 bits");
        return int32(value);
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16) {
        require(value >= -2**15 && value < 2**15, "SafeCast: value doesn\'t fit in 16 bits");
        return int16(value);
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits.
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8) {
        require(value >= -2**7 && value < 2**7, "SafeCast: value doesn\'t fit in 8 bits");
        return int8(value);
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        require(value < 2**255, "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

File 29 of 95 : ExchangeSignatures.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../../lib/SignatureUtil.sol";
import "../../iface/ExchangeData.sol";


/// @title ExchangeSignatures.
/// @dev All methods in this lib are internal, therefore, there is no need
///      to deploy this library independently.
/// @author Brecht Devos - <[email protected]>
/// @author Daniel Wang  - <[email protected]>
library ExchangeSignatures
{
    using SignatureUtil for bytes32;

    function requireAuthorizedTx(
        ExchangeData.State storage S,
        address signer,
        bytes memory signature,
        bytes32 txHash
        )
        internal // inline call
    {
        require(signer != address(0), "INVALID_SIGNER");
        // Verify the signature if one is provided, otherwise fall back to an approved tx
        if (signature.length > 0) {
            require(txHash.verifySignature(signer, signature), "INVALID_SIGNATURE");
        } else {
            require(S.approvedTx[signer][txHash], "TX_NOT_APPROVED");
            delete S.approvedTx[signer][txHash];
        }
    }
}

File 30 of 95 : SignatureUtil.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../thirdparty/BytesUtil.sol";
import "./AddressUtil.sol";
import "./MathUint.sol";
import "./ERC1271.sol";


/// @title SignatureUtil
/// @author Daniel Wang - <[email protected]>
/// @dev This method supports multihash standard. Each signature's last byte indicates
///      the signature's type.
library SignatureUtil
{
    using BytesUtil     for bytes;
    using MathUint      for uint;
    using AddressUtil   for address;

    enum SignatureType {
        ILLEGAL,
        INVALID,
        EIP_712,
        ETH_SIGN,
        WALLET   // deprecated
    }

    bytes4 constant internal ERC1271_MAGICVALUE = 0x1626ba7e;

    function verifySignatures(
        bytes32          signHash,
        address[] memory signers,
        bytes[]   memory signatures
        )
        internal
        view
        returns (bool)
    {
        require(signers.length == signatures.length, "BAD_SIGNATURE_DATA");
        address lastSigner;
        for (uint i = 0; i < signers.length; i++) {
            require(signers[i] > lastSigner, "INVALID_SIGNERS_ORDER");
            lastSigner = signers[i];
            if (!verifySignature(signHash, signers[i], signatures[i])) {
                return false;
            }
        }
        return true;
    }

    function verifySignature(
        bytes32        signHash,
        address        signer,
        bytes   memory signature
        )
        internal
        view
        returns (bool)
    {
        if (signer == address(0)) {
            return false;
        }

        return signer.isContract()?
            verifyERC1271Signature(signHash, signer, signature):
            verifyEOASignature(signHash, signer, signature);
    }

    function recoverECDSASigner(
        bytes32      signHash,
        bytes memory signature
        )
        internal
        pure
        returns (address)
    {
        if (signature.length != 65) {
            return address(0);
        }

        bytes32 r;
        bytes32 s;
        uint8   v;
        // we jump 32 (0x20) as the first slot of bytes contains the length
        // we jump 65 (0x41) per signature
        // for v we load 32 bytes ending with v (the first 31 come from s) then apply a mask
        assembly {
            r := mload(add(signature, 0x20))
            s := mload(add(signature, 0x40))
            v := and(mload(add(signature, 0x41)), 0xff)
        }
        // See https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/cryptography/ECDSA.sol
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return address(0);
        }
        if (v == 27 || v == 28) {
            return ecrecover(signHash, v, r, s);
        } else {
            return address(0);
        }
    }

    function verifyEOASignature(
        bytes32        signHash,
        address        signer,
        bytes   memory signature
        )
        private
        pure
        returns (bool success)
    {
        if (signer == address(0)) {
            return false;
        }

        uint signatureTypeOffset = signature.length.sub(1);
        SignatureType signatureType = SignatureType(signature.toUint8(signatureTypeOffset));

        // Strip off the last byte of the signature by updating the length
        assembly {
            mstore(signature, signatureTypeOffset)
        }

        if (signatureType == SignatureType.EIP_712) {
            success = (signer == recoverECDSASigner(signHash, signature));
        } else if (signatureType == SignatureType.ETH_SIGN) {
            bytes32 hash = keccak256(
                abi.encodePacked("\x19Ethereum Signed Message:\n32", signHash)
            );
            success = (signer == recoverECDSASigner(hash, signature));
        } else {
            success = false;
        }

        // Restore the signature length
        assembly {
            mstore(signature, add(signatureTypeOffset, 1))
        }

        return success;
    }

    function verifyERC1271Signature(
        bytes32 signHash,
        address signer,
        bytes   memory signature
        )
        private
        view
        returns (bool)
    {
        bytes memory callData = abi.encodeWithSelector(
            ERC1271.isValidSignature.selector,
            signHash,
            signature
        );
        (bool success, bytes memory result) = signer.staticcall(callData);
        return (
            success &&
            result.length == 32 &&
            result.toBytes4(0) == ERC1271_MAGICVALUE
        );
    }
}

File 31 of 95 : ERC1271.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;

abstract contract ERC1271 {
    // bytes4(keccak256("isValidSignature(bytes32,bytes)")
    bytes4 constant internal ERC1271_MAGICVALUE = 0x1626ba7e;

    function isValidSignature(
        bytes32      _hash,
        bytes memory _signature)
        external
        view
        virtual
        returns (bytes4 magicValueB32);

}

File 32 of 95 : DepositTransaction.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../../lib/EIP712.sol";
import "../../../lib/ERC20.sol";
import "../../../lib/MathUint248.sol";
import "../../../lib/SignatureUtil.sol";
import "../../../thirdparty/BytesUtil.sol";
import "../../iface/ExchangeData.sol";

/// @title DepositTransaction
/// @author Brecht Devos - <[email protected]>
library DepositTransaction
{
    using BytesUtil for bytes;
    using MathUint248 for uint248;
    using MathUint for uint256;

    struct Deposit
    {
        uint depositType;
        address to;
        uint32 toAccountID;
        uint32 tokenID;
        uint248 amount;
    }

    function process(
        ExchangeData.State        storage S,
        ExchangeData.BlockContext memory  /*ctx*/,
        bytes                     memory  data,
        uint                              offset,
        bytes                     memory  /*auxiliaryData*/
        )
        internal
    {
        // Read in the deposit
        Deposit memory deposit;
        readTx(data, offset, deposit);
        if (deposit.amount == 0) {
            return;
        }

        // depositType 0: deposit by exchange::deposit()
        // depositType 1: deposit by transfer tokens to DepositContract directly 
        if(deposit.depositType == 0) { 
            // Process the deposit
            ExchangeData.Deposit memory pendingDeposit = S.pendingDeposits[deposit.to][deposit.tokenID];
            // Make sure the deposit was actually done
            require(pendingDeposit.timestamp > 0, "DEPOSIT_DOESNT_EXIST");

            // Processing partial amounts of the deposited amount is allowed.
            // This is done to ensure the user can do multiple deposits after each other
            // without invalidating work done by the exchange owner for previous deposit amounts.

            require(pendingDeposit.amount >= deposit.amount, "INVALID_AMOUNT");
            pendingDeposit.amount = pendingDeposit.amount.sub(deposit.amount);

            // If the deposit was fully consumed, reset it so the storage is freed up
            // and the owner receives a gas refund.
            if (pendingDeposit.amount == 0) {
                delete S.pendingDeposits[deposit.to][deposit.tokenID];
            } else {
                S.pendingDeposits[deposit.to][deposit.tokenID] = pendingDeposit;
            }

        }else if(deposit.depositType == 1) {
            uint32 tokenId = deposit.tokenID;
            uint256 unconfirmedBalance;

            if (tokenId == 0) {
                unconfirmedBalance = address(S.depositContract).balance.sub(S.tokenIdToDepositBalance[tokenId]);
            } else {
                address token = S.tokenIdToToken[tokenId];
                unconfirmedBalance = ERC20(token).balanceOf(address(S.depositContract)).sub(S.tokenIdToDepositBalance[tokenId]);
            }

            require(unconfirmedBalance >= deposit.amount, "INVALID_DIRECT_DEPOSIT_AMOUNT");

            S.tokenIdToDepositBalance[deposit.tokenID] = S.tokenIdToDepositBalance[deposit.tokenID].add(deposit.amount);
        }else{
            revert("INVALID_DEPOSIT_TYPE");
        }
    }

    function readTx(
        bytes   memory data,
        uint           offset,
        Deposit memory deposit
        )
        internal
        pure
    {
        uint _offset = offset;

        // We don't use abi.decode for this because of the large amount of zero-padding
        // bytes the circuit would also have to hash.

        deposit.depositType = data.toUint8Unsafe(_offset);
        _offset += 1;
        deposit.to = data.toAddressUnsafe(_offset);
        _offset += 20;
        deposit.toAccountID = data.toUint32Unsafe(_offset);
        _offset += 4;
        deposit.tokenID = data.toUint32Unsafe(_offset);
        _offset += 4;
        deposit.amount = data.toUint248Unsafe(_offset);
        _offset += 31;
    }
}

File 33 of 95 : MathUint248.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2022 DeGate DAO
pragma solidity ^0.7.0;


/// @title Utility Functions for uint
/// @author Daniel Wang - <[email protected]>
library MathUint248
{
    function add(
        uint248 a,
        uint248 b
        )
        internal
        pure
        returns (uint248 c)
    {
        c = a + b;
        require(c >= a, "ADD_OVERFLOW");
    }

    function sub(
        uint248 a,
        uint248 b
        )
        internal
        pure
        returns (uint248 c)
    {
        require(b <= a, "SUB_UNDERFLOW");
        return a - b;
    }
}

File 34 of 95 : WithdrawTransaction.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../../lib/EIP712.sol";
import "../../../lib/FloatUtil.sol";
import "../../../lib/MathUint.sol";
import "../../../lib/SignatureUtil.sol";
import "../../../thirdparty/BytesUtil.sol";
import "../../iface/ExchangeData.sol";
import "../libexchange/ExchangeMode.sol";
import "../libexchange/ExchangeSignatures.sol";
import "../libexchange/ExchangeWithdrawals.sol";


/// @title WithdrawTransaction
/// @author Brecht Devos - <[email protected]>
/// @dev The following 4 types of withdrawals are supported:
///      - withdrawType = 0: offchain withdrawals with EdDSA signatures
///      - withdrawType = 1: offchain withdrawals with ECDSA signatures or onchain appprovals
///      - withdrawType = 2: onchain valid forced withdrawals (owner and accountID match), or
///                          offchain operator-initiated withdrawals for protocol fees or for
///                          users in shutdown mode
///      - withdrawType = 3: onchain invalid forced withdrawals (owner and accountID mismatch)
library WithdrawTransaction
{
    using BytesUtil            for bytes;
    using FloatUtil            for uint16;
    using MathUint             for uint;
    using SafeCast             for uint;
    using ExchangeMode         for ExchangeData.State;
    using ExchangeSignatures   for ExchangeData.State;
    using ExchangeWithdrawals  for ExchangeData.State;
    using SignatureUtil        for bytes32;

    bytes32 constant public WITHDRAWAL_TYPEHASH = keccak256(
        "Withdrawal(address owner,uint32 accountID,uint32 tokenID,uint248 amount,uint32 feeTokenID,uint96 maxFee,address to,uint248 minGas,uint32 validUntil,uint32 storageID)"
    );

    struct Withdrawal
    {
        uint    withdrawalType;
        address from;
        uint32  fromAccountID;
        uint32  tokenID;
        uint248 amount;
        uint32  feeTokenID;
        uint96  maxFee;
        uint96  fee;
        address to;
        uint248 minGas;
        uint32  validUntil;
        uint32  storageID;
        bytes20 onchainDataHash;
    }

    // Auxiliary data for each withdrawal
    struct WithdrawalAuxiliaryData
    {
        bool  storeRecipient;
        uint  gasLimit;
        bytes signature;

        uint248 minGas;
        address to;
        uint96  maxFee;
        uint32  validUntil;
        uint248 amount;
    }

    function process(
        ExchangeData.State        storage S,
        ExchangeData.BlockContext memory  ctx,
        bytes                     memory  data,
        uint                              offset,
        bytes                     memory  auxiliaryData
        )
        internal
    {
        Withdrawal memory withdrawal;
        readTx(data, offset, withdrawal);
        WithdrawalAuxiliaryData memory auxData = abi.decode(auxiliaryData, (WithdrawalAuxiliaryData));

        // Validate the withdrawal data not directly part of the DA
        bytes20 onchainDataHash = hashOnchainData(
            auxData.minGas,
            auxData.to,
            auxData.amount
        );

        // Only the 20 MSB are used, which is still 80-bit of security, which is more
        // than enough, especially when combined with validUntil.
        require(withdrawal.onchainDataHash == onchainDataHash, "INVALID_WITHDRAWAL_DATA");

        // Fill in withdrawal data missing from DA
        withdrawal.to = auxData.to;
        withdrawal.minGas = auxData.minGas;
        withdrawal.maxFee = auxData.maxFee;
        withdrawal.validUntil = auxData.validUntil;
        withdrawal.amount = auxData.amount;

        // If the account has an owner, don't allow withdrawing to the zero address
        // (which will be the protocol fee vault contract).
        require(withdrawal.from == address(0) || withdrawal.to != address(0), "INVALID_WITHDRAWAL_RECIPIENT");

        if (withdrawal.withdrawalType == 0) {
            // Signature checked offchain, nothing to do
        } else if (withdrawal.withdrawalType == 1) {
            // Validate
            require(ctx.timestamp < withdrawal.validUntil, "WITHDRAWAL_EXPIRED");
            require(withdrawal.fee <= withdrawal.maxFee, "WITHDRAWAL_FEE_TOO_HIGH");

            // Check appproval onchain
            // Calculate the tx hash
            bytes32 txHash = hashTx(ctx.DOMAIN_SEPARATOR, withdrawal);
            // Check onchain authorization
            S.requireAuthorizedTx(withdrawal.from, auxData.signature, txHash);
        } else if (withdrawal.withdrawalType == 2 || withdrawal.withdrawalType == 3) {
            // Forced withdrawals cannot make use of certain features because the
            // necessary data is not authorized by the account owner.
            // For protocol fee withdrawals, `owner` and `to` are both address(0).
            require(withdrawal.from == withdrawal.to, "INVALID_WITHDRAWAL_ADDRESS");

            // Forced withdrawal fees are charged when the request is submitted.
            require(withdrawal.fee == 0, "FEE_NOT_ZERO");

            ExchangeData.ForcedWithdrawal memory forcedWithdrawal =
                S.pendingForcedWithdrawals[withdrawal.fromAccountID][withdrawal.tokenID];

            if (forcedWithdrawal.timestamp != 0) {
                if (withdrawal.withdrawalType == 2) {
                    require(withdrawal.from == forcedWithdrawal.owner, "INCONSISENT_OWNER");
                } else { //withdrawal.withdrawalType == 3
                    require(withdrawal.from != forcedWithdrawal.owner, "INCONSISENT_OWNER");
                    require(withdrawal.amount == 0, "UNAUTHORIZED_WITHDRAWAL");
                }

                // delete the withdrawal request and free a slot
                delete S.pendingForcedWithdrawals[withdrawal.fromAccountID][withdrawal.tokenID];
                S.numPendingForcedTransactions--;
            } else {
                // Allow the owner to submit full withdrawals without authorization
                // - when in shutdown mode
                // - to withdraw protocol fees
                require(
                    withdrawal.fromAccountID == ExchangeData.ACCOUNTID_PROTOCOLFEE ||
                    S.isShutdown(),
                    "FULL_WITHDRAWAL_UNAUTHORIZED"
                );
            }
        } else {
            revert("INVALID_WITHDRAWAL_TYPE");
        }

        // Check if there is a withdrawal recipient
        address recipient = S.withdrawalRecipient[withdrawal.from][withdrawal.to][withdrawal.tokenID][withdrawal.amount][withdrawal.storageID];
        if (recipient != address(0)) {
            // Set the new recipient address
            withdrawal.to = recipient;
            // Allow any amount of gas to be used on this withdrawal (which allows the transfer to be skipped)
            withdrawal.minGas = 0;

            // Do NOT delete the recipient to prevent replay attack
            // delete S.withdrawalRecipient[withdrawal.owner][withdrawal.to][withdrawal.tokenID][withdrawal.amount][withdrawal.storageID];
        } else if (auxData.storeRecipient) {
            // Store the destination address to mark the withdrawal as done
            require(withdrawal.to != address(0), "INVALID_DESTINATION_ADDRESS");
            S.withdrawalRecipient[withdrawal.from][withdrawal.to][withdrawal.tokenID][withdrawal.amount][withdrawal.storageID] = withdrawal.to;
        }

        // Validate gas provided
        require(auxData.gasLimit >= withdrawal.minGas, "OUT_OF_GAS_FOR_WITHDRAWAL");

        // Try to transfer the tokens with the provided gas limit
        S.distributeWithdrawal(
            withdrawal.from,
            withdrawal.to,
            withdrawal.tokenID,
            withdrawal.amount,
            auxData.gasLimit
        );
    }

    function readTx(
        bytes      memory data,
        uint              offset,
        Withdrawal memory withdrawal
        )
        internal
        pure
    {
        uint _offset = offset;

        // Extract the transfer data
        // We don't use abi.decode for this because of the large amount of zero-padding
        // bytes the circuit would also have to hash.
        withdrawal.withdrawalType = data.toUint8Unsafe(_offset);
        _offset += 1;
        withdrawal.from = data.toAddressUnsafe(_offset);
        _offset += 20;
        withdrawal.fromAccountID = data.toUint32Unsafe(_offset);
        _offset += 4;
        withdrawal.tokenID = data.toUint32Unsafe(_offset);
        _offset += 4;
        withdrawal.feeTokenID = data.toUint32Unsafe(_offset);
        _offset += 4;
        withdrawal.fee = data.toUint16Unsafe(_offset).decodeFloat16();
        _offset += 2;
        withdrawal.storageID = data.toUint32Unsafe(_offset);
        _offset += 4;
        withdrawal.onchainDataHash = data.toBytes20Unsafe(_offset);
        _offset += 20;
    }

    function hashTx(
        bytes32 DOMAIN_SEPARATOR,
        Withdrawal memory withdrawal
        )
        private
        pure
        returns (bytes32)
    {
        return EIP712.hashPacked(
            DOMAIN_SEPARATOR,
            keccak256(
                abi.encode(
                    WITHDRAWAL_TYPEHASH,
                    withdrawal.from,
                    withdrawal.fromAccountID,
                    withdrawal.tokenID,
                    withdrawal.amount,
                    withdrawal.feeTokenID,
                    withdrawal.maxFee,
                    withdrawal.to,
                    withdrawal.minGas,
                    withdrawal.validUntil,
                    withdrawal.storageID
                )
            )
        );
    }

    function hashOnchainData(
        uint248 minGas,
        address to,
        uint248 amount
        )
        private
        view
        returns (bytes20)
    {
        // Only the 20 MSB are used, which is still 80-bit of security, which is more
        // than enough, especially when combined with validUntil.
        return bytes20(
            abi.encodePacked(
                minGas,
                to,
                amount
            ).fastSHA256()
        );
    }
}

File 35 of 95 : ExchangeWithdrawals.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../../lib/AddressUtil.sol";
import "../../../lib/MathUint248.sol";
import "../../../thirdparty/BytesUtil.sol";
import "../../iface/ExchangeData.sol";
import "./ExchangeBalances.sol";
import "./ExchangeMode.sol";
import "./ExchangeTokens.sol";


/// @title ExchangeWithdrawals.
/// @author Brecht Devos - <[email protected]>
/// @author Daniel Wang  - <[email protected]>
library ExchangeWithdrawals
{
    enum WithdrawalCategory
    {
        DISTRIBUTION,
        FROM_MERKLE_TREE,
        FROM_DEPOSIT_REQUEST,
        FROM_APPROVED_WITHDRAWAL
    }

    using AddressUtil       for address;
    using AddressUtil       for address payable;
    using BytesUtil         for bytes;
    using MathUint          for uint;
    using MathUint248       for uint248;
    using ExchangeBalances  for ExchangeData.State;
    using ExchangeMode      for ExchangeData.State;
    using ExchangeTokens    for ExchangeData.State;

    event ForcedWithdrawalRequested(
        address owner,
        address token,
        uint32  accountID
    );

    event WithdrawalCompleted(
        uint8   category,
        address from,
        address to,
        address token,
        uint    amount
    );

    event WithdrawalFailed(
        uint8   category,
        address from,
        address to,
        address token,
        uint    amount
    );

    function forceWithdraw(
        ExchangeData.State storage S,
        address owner,
        address token,
        uint32  accountID
        )
        public
    {
        require(!S.isInWithdrawalMode(), "INVALID_MODE");
        // Limit the amount of pending forced withdrawals so that the owner cannot be overwhelmed.
        require(S.getNumAvailableForcedSlots() > 0, "TOO_MANY_REQUESTS_OPEN");
        require(accountID < ExchangeData.MAX_NUM_ACCOUNTS, "INVALID_ACCOUNTID");
        require(accountID != 0, "INVALID_ACCOUNTID");

        uint32 tokenID = S.getTokenID(token);

        // A user needs to pay a fixed ETH withdrawal fee, set by the protocol.
        uint withdrawalFeeETH = S.loopring.forcedWithdrawalFee();

        // Check ETH value sent, can be larger than the expected withdraw fee
        require(msg.value >= withdrawalFeeETH, "INSUFFICIENT_WITHDRAW_FEE");

        // Send surplus of ETH back to the sender
        uint feeSurplus = msg.value.sub(withdrawalFeeETH);
        if (feeSurplus > 0) {
            msg.sender.sendETHAndVerify(feeSurplus, gasleft());
        }

        // There can only be a single forced withdrawal per (account, token) pair.
        require(
            S.pendingForcedWithdrawals[accountID][tokenID].timestamp == 0,
            "WITHDRAWAL_ALREADY_PENDING"
        );

        // Store the forced withdrawal request data
        S.pendingForcedWithdrawals[accountID][tokenID] = ExchangeData.ForcedWithdrawal({
            owner: owner,
            timestamp: uint64(block.timestamp)
        });

        // Increment the number of pending forced transactions so we can keep count.
        S.numPendingForcedTransactions++;

        emit ForcedWithdrawalRequested(
            owner,
            token,
            accountID
        );
    }

    // We alow anyone to withdraw these funds for the account owner
    function withdrawFromMerkleTree(
        ExchangeData.State       storage S,
        ExchangeData.MerkleProof calldata merkleProof
        )
        public
    {
        require(S.isInWithdrawalMode(), "NOT_IN_WITHDRAW_MODE");

        address owner = merkleProof.accountLeaf.owner;
        uint32 accountID = merkleProof.accountLeaf.accountID;
        uint32 tokenID = merkleProof.balanceLeaf.tokenID;
        uint248 balance = merkleProof.balanceLeaf.balance;

        // Make sure the funds aren't withdrawn already.
        require(S.withdrawnInWithdrawMode[accountID][tokenID] == false, "WITHDRAWN_ALREADY");

        // Verify that the provided Merkle tree data is valid by using the Merkle proof.
        ExchangeBalances.verifyAccountBalance(
            uint(S.merkleAssetRoot),
            merkleProof
        );

        // Make sure the balance can only be withdrawn once
        S.withdrawnInWithdrawMode[accountID][tokenID] = true;

        // Transfer the tokens to the account owner
        transferTokens(
            S,
            uint8(WithdrawalCategory.FROM_MERKLE_TREE),
            owner,
            owner,
            tokenID,
            balance,
            gasleft(),
            false
        );
    }

    function withdrawFromDepositRequest(
        ExchangeData.State storage S,
        address owner,
        address token
        )
        public
    {
        uint32 tokenID = S.getTokenID(token);
        ExchangeData.Deposit storage deposit = S.pendingDeposits[owner][tokenID];
        require(deposit.timestamp != 0, "DEPOSIT_NOT_WITHDRAWABLE_YET");

        // Check if the deposit has indeed exceeded the time limit of if the exchange is in withdrawal mode
        require(
            block.timestamp >= deposit.timestamp + S.maxAgeDepositUntilWithdrawable ||
            S.isInWithdrawalMode(),
            "DEPOSIT_NOT_WITHDRAWABLE_YET"
        );

        uint248 amount = deposit.amount;

        // Reset the deposit request
        delete S.pendingDeposits[owner][tokenID];

        // Transfer the tokens
        transferTokens(
            S,
            uint8(WithdrawalCategory.FROM_DEPOSIT_REQUEST),
            owner,
            owner,
            tokenID,
            amount,
            gasleft(),
            false
        );
    }

    function withdrawFromApprovedWithdrawals(
        ExchangeData.State storage S,
        address[] memory owners,
        address[] memory tokens
        )
        public
    {
        require(owners.length == tokens.length, "INVALID_INPUT_DATA");
        for (uint i = 0; i < owners.length; i++) {
            address owner = owners[i];
            uint32 tokenID = S.getTokenID(tokens[i]);
            uint248 amount = S.amountWithdrawable[owner][tokenID];

            // Make sure this amount can't be withdrawn again
            delete S.amountWithdrawable[owner][tokenID];

            // Transfer the tokens to the owner
            transferTokens(
                S,
                uint8(WithdrawalCategory.FROM_APPROVED_WITHDRAWAL),
                owner,
                owner,
                tokenID,
                amount,
                gasleft(),
                false
            );
        }
    }

    function distributeWithdrawal(
        ExchangeData.State storage S,
        address from,
        address to,
        uint32  tokenID,
        uint248    amount,
        uint    gasLimit
        )
        public
    {
        // Try to transfer the tokens
        bool success = transferTokens(
            S,
            uint8(WithdrawalCategory.DISTRIBUTION),
            from,
            to,
            tokenID,
            amount,
            gasLimit,
            true
        );
        // If the transfer was successful there's nothing left to do.
        // However, if the transfer failed the tokens are still in the contract and can be
        // withdrawn later to `to` by anyone by using `withdrawFromApprovedWithdrawal.
        if (!success) {
            S.amountWithdrawable[to][tokenID] = S.amountWithdrawable[to][tokenID].add(amount);
        }
    }

    // == Internal and Private Functions ==

    // If allowFailure is true the transfer can fail because of a transfer error or
    // because the transfer uses more than `gasLimit` gas. The function
    // will return true when successful, false otherwise.
    // If allowFailure is false the transfer is guaranteed to succeed using
    // as much gas as needed, otherwise it throws. The function always returns true.
    function transferTokens(
        ExchangeData.State storage S,
        uint8   category,
        address from,
        address to,
        uint32  tokenID,
        uint248 amount,
        uint    gasLimit,
        bool    allowFailure
        )
        private
        returns (bool success)
    {
        // Redirect withdrawals to address(0) to the protocol fee vault
        if (to == address(0)) {
            to = S.loopring.protocolFeeVault();
        }
        address token = S.getTokenAddress(tokenID);

        // Transfer the tokens from the deposit contract to the owner
        if (gasLimit > 0) {
            try S.depositContract.withdraw{gas: gasLimit}(from, to, token, amount) {
                success = true;
            } catch {
                success = false;
            }
        } else {
            success = false;
        }

        require(allowFailure || success, "TRANSFER_FAILURE");

        if (success) {
            emit WithdrawalCompleted(category, from, to, token, amount);

            // Keep track of when the protocol fees were last withdrawn
            // (only done to make this data easier available).
            if (from == address(0)) {
                S.protocolFeeLastWithdrawnTime[token] = block.timestamp;
            }

            S.tokenIdToDepositBalance[tokenID] = S.tokenIdToDepositBalance[tokenID].sub(amount);

        } else {
            emit WithdrawalFailed(category, from, to, token, amount);
        }
    }
}

File 36 of 95 : ExchangeTokens.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../../lib/ERC20SafeTransfer.sol";
import "../../../lib/MathUint.sol";
import "../../iface/ExchangeData.sol";
import "./ExchangeMode.sol";

/// @title ExchangeTokens.
/// @author Daniel Wang  - <[email protected]>
/// @author Brecht Devos - <[email protected]>
library ExchangeTokens
{
    using MathUint          for uint;
    using ERC20SafeTransfer for address;
    using ExchangeMode      for ExchangeData.State;

    event TokenRegistered(
        address token,
        uint32  tokenId
    );

    function getTokenAddress(
        ExchangeData.State storage S,
        uint32 tokenID
        )
        public
        view
        returns (address)
    {
        require(tokenID < S.normalTokens.length.add(ExchangeData.MAX_NUM_RESERVED_TOKENS), "INVALID_TOKEN_ID");

        if (tokenID < ExchangeData.MAX_NUM_RESERVED_TOKENS) {
            return S.reservedTokens[tokenID].token;
        }

        return S.normalTokens[tokenID - ExchangeData.MAX_NUM_RESERVED_TOKENS].token;
    }

    function registerToken(
        ExchangeData.State storage S,
        address tokenAddress,
        bool isOwnerRegister
        )
        public
        returns (uint32 tokenID)
    {
        require(!S.isInWithdrawalMode(), "INVALID_MODE");
        require(S.tokenToTokenId[tokenAddress] == 0, "TOKEN_ALREADY_EXIST");

        if (isOwnerRegister) {
            require(S.reservedTokens.length < ExchangeData.MAX_NUM_RESERVED_TOKENS, "TOKEN_REGISTRY_FULL");
        } else {
            require(S.normalTokens.length < ExchangeData.MAX_NUM_NORMAL_TOKENS, "TOKEN_REGISTRY_FULL");
        }

        // Check if the deposit contract supports the new token
        if (S.depositContract != IDepositContract(0)) {
            require(S.depositContract.isTokenSupported(tokenAddress), "UNSUPPORTED_TOKEN");
        }

        // Assign a tokenID and store the token
        ExchangeData.Token memory token = ExchangeData.Token(tokenAddress);

        if (isOwnerRegister) {
            tokenID = uint32(S.reservedTokens.length);
            S.reservedTokens.push(token);
        } else {
            tokenID = uint32(S.normalTokens.length.add(ExchangeData.MAX_NUM_RESERVED_TOKENS));
            S.normalTokens.push(token);
        }
        S.tokenToTokenId[tokenAddress] = tokenID + 1;
        S.tokenIdToToken[tokenID] = tokenAddress;

        S.tokenIdToDepositBalance[tokenID] = 0;

        emit TokenRegistered(tokenAddress, tokenID);
    }

    function getTokenID(
        ExchangeData.State storage S,
        address tokenAddress
        )
        internal  // inline call
        view
        returns (uint32 tokenID)
    {
        tokenID = S.tokenToTokenId[tokenAddress];
        require(tokenID != 0, "TOKEN_NOT_FOUND");
        tokenID = tokenID - 1;
    }

    function findTokenID(
        ExchangeData.State storage S,
        address tokenAddress
        )
        internal  // inline call
        view
        returns (uint32 tokenID, bool found)
    {
        tokenID = S.tokenToTokenId[tokenAddress];
        if(tokenID == 0) {
            return (0, false);
        }
        tokenID = tokenID - 1;
        found = true;
    }

}

File 37 of 95 : ExchangeDeposits.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../../lib/AddressUtil.sol";
import "../../../lib/MathUint248.sol";
import "../../../lib/MathUint.sol";
import "../../iface/ExchangeData.sol";
import "./ExchangeMode.sol";
import "./ExchangeTokens.sol";


/// @title ExchangeDeposits.
/// @author Daniel Wang  - <[email protected]>
/// @author Brecht Devos - <[email protected]>
library ExchangeDeposits
{
    using AddressUtil       for address payable;
    using MathUint248       for uint248;
    using MathUint          for uint;
    using ExchangeMode      for ExchangeData.State;
    using ExchangeTokens    for ExchangeData.State;

    event DepositRequested(
        address from,
        address to,
        address token,
        uint32  tokenId,
        uint248  amount
    );

    event DepositFee(
        uint256  amount
    );

    function deposit(
        ExchangeData.State storage S,
        address from,
        address to,
        address tokenAddress,
        uint248  amount,                 // can be zero
        bytes   memory extraData
        )
        internal  // inline call
    {
        require(to != address(0), "ZERO_ADDRESS");

        // Deposits are still possible when the exchange is being shutdown, or even in withdrawal mode.
        // This is fine because the user can easily withdraw the deposited amounts again.
        // We don't want to make all deposits more expensive just to stop that from happening.

        (uint32 tokenID, bool tokenFound) = S.findTokenID(tokenAddress);
        if(!tokenFound) {
            tokenID = S.registerToken(tokenAddress, false);
        }

        if (tokenID == 0 && amount == 0) {
            require(msg.value == 0, "INVALID_ETH_DEPOSIT");
        }

        // A user may need to pay a fixed ETH deposit fee, set by the protocol.
        uint256 depositFeeETH = 0;
        if (needChargeDepositFee(S)) {
            depositFeeETH = S.depositState.depositFee;
            emit DepositFee(depositFeeETH);
        }

        // Check ETH value sent
        require(msg.value >= depositFeeETH, "INSUFFICIENT_DEPOSIT_FEE");

        uint256 ethAmountToDeposit = msg.value - depositFeeETH;

        // Transfer the tokens to this contract
        uint248 amountDeposited = S.depositContract.deposit{value: ethAmountToDeposit}(
            from,
            tokenAddress,
            amount,
            extraData
        );

        // Add the amount to the deposit request and reset the time the operator has to process it
        ExchangeData.Deposit memory _deposit = S.pendingDeposits[to][tokenID];
        _deposit.timestamp = uint64(block.timestamp);
        _deposit.amount = _deposit.amount.add(amountDeposited);
        S.pendingDeposits[to][tokenID] = _deposit;


        S.tokenIdToDepositBalance[tokenID] = S.tokenIdToDepositBalance[tokenID].add(amountDeposited);

        emit DepositRequested(
            from,
            to,
            tokenAddress,
            tokenID,
            amountDeposited
        );
    }

    function setDepositParams(
        ExchangeData.State storage S,
        uint256 freeDepositMax,
        uint256 freeDepositRemained,
        uint256 freeSlotPerBlock,
        uint256 depositFee
    ) internal {
        S.depositState.freeDepositMax = freeDepositMax;
        S.depositState.freeDepositRemained = freeDepositRemained;
        S.depositState.freeSlotPerBlock = freeSlotPerBlock;
        S.depositState.depositFee = depositFee;
    }

    function needChargeDepositFee(ExchangeData.State storage S)
        private
        returns (bool)
    {
        bool needCharge = false;

        // S.depositState.freeDepositRemained + (block.number - S.depositState.lastDepositBlockNum) * S.depositState.freeSlotPerBlock;
        uint256 freeDepositRemained = S.depositState.freeDepositRemained.add(
            (block.number.sub(S.depositState.lastDepositBlockNum)).mul(S.depositState.freeSlotPerBlock)
        );
        
        if (freeDepositRemained > S.depositState.freeDepositMax) {
            freeDepositRemained = S.depositState.freeDepositMax;
        }

        if (freeDepositRemained > 0) {
            freeDepositRemained -= 1;
        } else {
            needCharge = true;
        }

        S.depositState.freeDepositRemained = freeDepositRemained;
        S.depositState.lastDepositBlockNum = block.number;

        return needCharge;
    }
}

File 38 of 95 : ExchangeGenesis.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../../lib/MathUint.sol";
import "../../iface/ExchangeData.sol";
import "../../iface/IAgentRegistry.sol";
import "../../iface/IBlockVerifier.sol";
import "../../iface/ILoopringV3.sol";
import "./ExchangeTokens.sol";


/// @title ExchangeGenesis.
/// @author Daniel Wang  - <[email protected]>
/// @author Brecht Devos - <[email protected]>
library ExchangeGenesis
{
    using ExchangeTokens    for ExchangeData.State;

    event ExchangeGenesisBlockInitialized(
        address loopringAddr,
        bytes32 genesisMerkleRoot,
        bytes32 genesisMerkleAssetRoot,
        bytes32 domainSeparator
    );

    function initializeGenesisBlock(
        ExchangeData.State storage S,
        address _loopringAddr,
        bytes32 _genesisMerkleRoot,
        bytes32 _genesisMerkleAssetRoot,
        bytes32 _domainSeparator
        )
        public
    {
        require(address(0) != _loopringAddr, "INVALID_LOOPRING_ADDRESS");
        require(_genesisMerkleRoot != 0, "INVALID_GENESIS_MERKLE_ROOT");
        require(_genesisMerkleAssetRoot != 0, "INVALID_GENESIS_MERKLE_ASSET_ROOT");

        S.maxAgeDepositUntilWithdrawable = ExchangeData.MAX_AGE_DEPOSIT_UNTIL_WITHDRAWABLE_UPPERBOUND;
        S.DOMAIN_SEPARATOR = _domainSeparator;

        ILoopringV3 loopring = ILoopringV3(_loopringAddr);
        S.loopring = loopring;

        S.blockVerifier = IBlockVerifier(loopring.blockVerifierAddress());

        S.merkleRoot = _genesisMerkleRoot;
        S.merkleAssetRoot = _genesisMerkleAssetRoot;
        S.blocks[0] = ExchangeData.BlockInfo(uint32(block.timestamp), bytes28(0));
        S.numBlocks = 1;

        // Get the protocol fees for this exchange
        S.protocolFeeData.syncedAt = uint32(0);

        S.protocolFeeData.protocolFeeBips = S.loopring.protocolFeeBips();
        S.protocolFeeData.previousProtocolFeeBips = S.protocolFeeData.protocolFeeBips;

        S.protocolFeeData.nextProtocolFeeBips = S.protocolFeeData.protocolFeeBips;
        S.protocolFeeData.executeTimeOfNextProtocolFeeBips = uint32(0);

        // Call these after the main state has been set up
        S.registerToken(address(0), true);
        S.registerToken(loopring.lrcAddress(), true);

        emit ExchangeGenesisBlockInitialized(_loopringAddr, _genesisMerkleRoot, _genesisMerkleAssetRoot, _domainSeparator);
    }
}

File 39 of 95 : VerificationKeys.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2023
pragma solidity ^0.7.0;


/// @title Hard coded verification keys
/// @dev Generated on 11-Apr-2023 11:44:54, +07
/// @author Berg Jefferson - <[email protected]>
library VerificationKeys
{
    function getKey(
        uint blockType,
        uint blockSize,
        uint blockVersion
        )
        internal
        pure
        returns (uint[14] memory vk, uint[4] memory vk_gammaABC, bool found)
    {
        if (blockType == 0 && blockSize == 355 && blockVersion == 0) {
            vk = [
              5352502781177947990917130463223399859512438492630961972971092263507416941516,
              15740437711478785114349806024529911308972872013948538929238342659340522712126,
              857813897181731197783915787862562304226029941350914163907371544319541895260,
              7957246859073493699836222386708957497839125015489338533609373877535608740778,
              15248382147802000479459044690531195440846921222336500821300479761117402252465,
              1793540727469341929692272133594052943856871084761890962840372296656862838809,
              11559732032986387107991004021392285783925812861821192530917403151452391805634,
              10857046999023057135944570762232829481370756359578518086990519993285655852781,
              4082367875863433681332203403145435568316851327593401208105741076214120093531,
              8495653923123431417604973247489272438418190587263600148770280649306958101930,
              8784538352103544680544878569619633069286083932582545941496458603046818302532,
              21648363849698280106394784764113647897280169853712601216492738905134979055640,
              12113343877939370604059730323953748020167123825465139942787941544590851447603,
              17860672404560553406804732120373414225886864244229187254216976620688017704505
            ];
            vk_gammaABC = [
              6154759800727527048208100447065751592039902387097803200029822832426260239363,
              5986117161970146962752513955722959425732161191503024685217801208634710577786,
              937097291856302928916368018648858823309397389879989126199717335871410920053,
              16307402130624676642736973369304182775582201206433672350640385611090747375090
            ];
            found = true;
        } else if (blockType == 0 && blockSize == 300 && blockVersion == 0) {
            vk = [
              5352502781177947990917130463223399859512438492630961972971092263507416941516,
              15740437711478785114349806024529911308972872013948538929238342659340522712126,
              857813897181731197783915787862562304226029941350914163907371544319541895260,
              7957246859073493699836222386708957497839125015489338533609373877535608740778,
              15248382147802000479459044690531195440846921222336500821300479761117402252465,
              1793540727469341929692272133594052943856871084761890962840372296656862838809,
              11559732032986387107991004021392285783925812861821192530917403151452391805634,
              10857046999023057135944570762232829481370756359578518086990519993285655852781,
              4082367875863433681332203403145435568316851327593401208105741076214120093531,
              8495653923123431417604973247489272438418190587263600148770280649306958101930,
              4747955692483067772308318587415967610398454018379630612596851644675920255036,
              11329897094260727327989813350572608280108302990743237539876046612299431907740,
              8873499132820766915470814753978217112280162662109894032108656387332727222877,
              10158388304642048469951914864855923192463021881832527027409260053219943275285
            ];
            vk_gammaABC = [
              16651548375569746195656570840235550700994288882729305649570659623515860877628,
              9879702970394785959210782688871209903010998686060193834464015713002640780276,
              5723418409241761603969411966858769820691042460369773749661312245649964854992,
              20434570015310898647089678774679180797767479764974323812963795733452220803009
            ];
            found = true;
        } else if (blockType == 0 && blockSize == 250 && blockVersion == 0) {
            vk = [
              5352502781177947990917130463223399859512438492630961972971092263507416941516,
              15740437711478785114349806024529911308972872013948538929238342659340522712126,
              857813897181731197783915787862562304226029941350914163907371544319541895260,
              7957246859073493699836222386708957497839125015489338533609373877535608740778,
              15248382147802000479459044690531195440846921222336500821300479761117402252465,
              1793540727469341929692272133594052943856871084761890962840372296656862838809,
              11559732032986387107991004021392285783925812861821192530917403151452391805634,
              10857046999023057135944570762232829481370756359578518086990519993285655852781,
              4082367875863433681332203403145435568316851327593401208105741076214120093531,
              8495653923123431417604973247489272438418190587263600148770280649306958101930,
              11182755481462438379213191509479644532470435293054770461631826731735665851050,
              8292557992667277657300707643166138761668301086182391879359976315208518976405,
              18366964884508028540025036467126890803699601355786835455993811595786957939096,
              900537295133976455087300759962616225871458336754595738167622191250109222823
            ];
            vk_gammaABC = [
              6333771999757102163655577055317945725296972892098736206172425341645142683948,
              9234199208605299653041173125980318687080675601043588370022137401901679268243,
              17600556694764736291937390668944170001780557836403483455115490089342180788268,
              14281744364110609092505621317540557374203701786165940889320091243810935656604
            ];
            found = true;
        } else if (blockType == 0 && blockSize == 200 && blockVersion == 0) {
            vk = [
              5352502781177947990917130463223399859512438492630961972971092263507416941516,
              15740437711478785114349806024529911308972872013948538929238342659340522712126,
              857813897181731197783915787862562304226029941350914163907371544319541895260,
              7957246859073493699836222386708957497839125015489338533609373877535608740778,
              15248382147802000479459044690531195440846921222336500821300479761117402252465,
              1793540727469341929692272133594052943856871084761890962840372296656862838809,
              11559732032986387107991004021392285783925812861821192530917403151452391805634,
              10857046999023057135944570762232829481370756359578518086990519993285655852781,
              4082367875863433681332203403145435568316851327593401208105741076214120093531,
              8495653923123431417604973247489272438418190587263600148770280649306958101930,
              15507132891597317446931861219663948078022814774145513599214864331939470213687,
              5685868260410174253262076419938782319407108084610909286587299710205571511605,
              4729285692597119610072501966805527354106942546121296710784508184103975326063,
              7008896191941032825821162846554940812502651290486410736060678529920663036638
            ];
            vk_gammaABC = [
              19359239074840306948693123635362867701942968777660082989917288096102083411108,
              12852377488837155535558791084592321901778396457139261275108963319769039981987,
              10247430062824978040611756094885979035087178762323810333116161989956619404045,
              889058745861907269701500854512221096371575738310536283949460569077774161413
            ];
            found = true;
        } else if (blockType == 0 && blockSize == 150 && blockVersion == 0) {
            vk = [
              5352502781177947990917130463223399859512438492630961972971092263507416941516,
              15740437711478785114349806024529911308972872013948538929238342659340522712126,
              857813897181731197783915787862562304226029941350914163907371544319541895260,
              7957246859073493699836222386708957497839125015489338533609373877535608740778,
              15248382147802000479459044690531195440846921222336500821300479761117402252465,
              1793540727469341929692272133594052943856871084761890962840372296656862838809,
              11559732032986387107991004021392285783925812861821192530917403151452391805634,
              10857046999023057135944570762232829481370756359578518086990519993285655852781,
              4082367875863433681332203403145435568316851327593401208105741076214120093531,
              8495653923123431417604973247489272438418190587263600148770280649306958101930,
              12046915847436427808797215864795211538985988200404944304088362311587752679461,
              2836535876448322966272274299623480677569948946646379415475491880908465894094,
              20564321642567480757016126470556472176992830195880274967059869784683670284131,
              18254067943493611050107576491657850633635936383905959736502132154689274760404
            ];
            vk_gammaABC = [
              784898175304000497939645325114184529556206078622719988757338927517196491105,
              11719495144678724556381220356525131382173591030323769752386787242343398558589,
              2261001650755314303247646610805020428628138223315727480727317315040426475785,
              2647338121854271434391407366219284534447544635403619449227969706203185252979
            ];
            found = true;
        } else if (blockType == 0 && blockSize == 100 && blockVersion == 0) {
            vk = [
              5352502781177947990917130463223399859512438492630961972971092263507416941516,
              15740437711478785114349806024529911308972872013948538929238342659340522712126,
              857813897181731197783915787862562304226029941350914163907371544319541895260,
              7957246859073493699836222386708957497839125015489338533609373877535608740778,
              15248382147802000479459044690531195440846921222336500821300479761117402252465,
              1793540727469341929692272133594052943856871084761890962840372296656862838809,
              11559732032986387107991004021392285783925812861821192530917403151452391805634,
              10857046999023057135944570762232829481370756359578518086990519993285655852781,
              4082367875863433681332203403145435568316851327593401208105741076214120093531,
              8495653923123431417604973247489272438418190587263600148770280649306958101930,
              2605866266672960200467142668466082624748113684622104884896922575956497526754,
              609455949401253732196053612226022194372470911160436084844854167927088461257,
              3980570836161694190032467012904542479676945193790662191193755381525938533717,
              14084656950434588371070294070151917111349595382494097623998171042670111234987
            ];
            vk_gammaABC = [
              12600696019503419743569076041481290871534632240786743989885961529819029195075,
              18337338474776158492240498787610045195222023382110359691697636703643611198111,
              8690954427690606460223990064278965215405764848150797565633191279158039043921,
              18253003144666534577122704550119274008118866518518375747615157145757761935304
            ];
            found = true;
        } else if (blockType == 0 && blockSize == 50 && blockVersion == 0) {
            vk = [
              5352502781177947990917130463223399859512438492630961972971092263507416941516,
              15740437711478785114349806024529911308972872013948538929238342659340522712126,
              857813897181731197783915787862562304226029941350914163907371544319541895260,
              7957246859073493699836222386708957497839125015489338533609373877535608740778,
              15248382147802000479459044690531195440846921222336500821300479761117402252465,
              1793540727469341929692272133594052943856871084761890962840372296656862838809,
              11559732032986387107991004021392285783925812861821192530917403151452391805634,
              10857046999023057135944570762232829481370756359578518086990519993285655852781,
              4082367875863433681332203403145435568316851327593401208105741076214120093531,
              8495653923123431417604973247489272438418190587263600148770280649306958101930,
              9462989441952398475049803740288403081280558335403094538350299925745497676701,
              2960176382516232001818500473181134712339286795386066402876934958003133412219,
              16438384370689427037987401102792504750542910351966618258654778320567433848435,
              3401688728570393693379387779284613900749166337460165896399055099543910428150
            ];
            vk_gammaABC = [
              10480014149692890646930705497621060728595138655330314889705093419542311015998,
              4679269646022302528248348817927381280014823292153947070975104636680966863005,
              19190325509017272094108783001308988031170872461349384133937622397591944878744,
              19142598844650906162779561473585908239898492961632422619734253204589859038776
            ];
            found = true;
        } else if (blockType == 0 && blockSize == 25 && blockVersion == 0) {
            vk = [
              5352502781177947990917130463223399859512438492630961972971092263507416941516,
              15740437711478785114349806024529911308972872013948538929238342659340522712126,
              857813897181731197783915787862562304226029941350914163907371544319541895260,
              7957246859073493699836222386708957497839125015489338533609373877535608740778,
              15248382147802000479459044690531195440846921222336500821300479761117402252465,
              1793540727469341929692272133594052943856871084761890962840372296656862838809,
              11559732032986387107991004021392285783925812861821192530917403151452391805634,
              10857046999023057135944570762232829481370756359578518086990519993285655852781,
              4082367875863433681332203403145435568316851327593401208105741076214120093531,
              8495653923123431417604973247489272438418190587263600148770280649306958101930,
              448149886349620760576175214516173742326657822735137905922313116464173504103,
              4929075781575170759971924837499033608454405873493501083551961673165144790309,
              18558261575517349648467561870559244983019358532372422861349906403233212367622,
              15824129899911016862422865499180607941870299625776971354825182803154223497955
            ];
            vk_gammaABC = [
              12654105164742611145874596631045701775460489635361003220760146341475988478997,
              15479498270635111435624945116639076100818802093753267084043714331168954584642,
              21001468645325530302380094268191927423206548414291825260561093702708374072222,
              13673310815289060788777642550823650515774831138594135912456465824383460106163
            ];
            found = true;
        } else if (blockType == 0 && blockSize == 10 && blockVersion == 0) {
            vk = [
              5352502781177947990917130463223399859512438492630961972971092263507416941516,
              15740437711478785114349806024529911308972872013948538929238342659340522712126,
              857813897181731197783915787862562304226029941350914163907371544319541895260,
              7957246859073493699836222386708957497839125015489338533609373877535608740778,
              15248382147802000479459044690531195440846921222336500821300479761117402252465,
              1793540727469341929692272133594052943856871084761890962840372296656862838809,
              11559732032986387107991004021392285783925812861821192530917403151452391805634,
              10857046999023057135944570762232829481370756359578518086990519993285655852781,
              4082367875863433681332203403145435568316851327593401208105741076214120093531,
              8495653923123431417604973247489272438418190587263600148770280649306958101930,
              15868364611863585087175494820824776881600040882160436994910805995558642515398,
              9196443539467153624334088201520074819906562754537442404835244438199142837078,
              9578105535232751231439753379774199230917782465775995229361624374317450163776,
              6637813986356313109463759776683907894602496572516123953655275535229112224877
            ];
            vk_gammaABC = [
              1541628895787759189288185605888350030828411023426491785221415993167385722160,
              11592373080133128775774724371446859248381871207618673406351326349827677624840,
              5747029919253340747421366752416647676535937020883132819591349266848369937991,
              15424434633948383200877610552749524693502371096312710412344425727169935560277
            ];
            found = true;
        } else if (blockType == 0 && blockSize == 5 && blockVersion == 0) {
            vk = [
              5352502781177947990917130463223399859512438492630961972971092263507416941516,
              15740437711478785114349806024529911308972872013948538929238342659340522712126,
              857813897181731197783915787862562304226029941350914163907371544319541895260,
              7957246859073493699836222386708957497839125015489338533609373877535608740778,
              15248382147802000479459044690531195440846921222336500821300479761117402252465,
              1793540727469341929692272133594052943856871084761890962840372296656862838809,
              11559732032986387107991004021392285783925812861821192530917403151452391805634,
              10857046999023057135944570762232829481370756359578518086990519993285655852781,
              4082367875863433681332203403145435568316851327593401208105741076214120093531,
              8495653923123431417604973247489272438418190587263600148770280649306958101930,
              5247777729988598287106995776749297875785027826696934352128795156086624450194,
              5908241076113038557991606167471356299841167658696245541116430806675911147204,
              12696835005594814759424641929482009800802834730358602423220255021859048777192,
              12061905920204481582130412492899952626011128681660782227171339091582457380150
            ];
            vk_gammaABC = [
              16993593899733644870336397849091495493452059897613484913307748430166933382414,
              10029328427974761716247230971922731503862911711448944576103532688683695145460,
              13295603287437356399029521023390521175121750267486223753939941915842148692862,
              12536631341558385456008588428384822500419310393332622864437662191693700120667
            ];
            found = true;
        } else {
            found = false;
        }
    }
}

File 40 of 95 : DefaultDepositContract.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;

import "../../lib/AddressUtil.sol";
import "../../lib/Claimable.sol";
import "../../lib/ERC20.sol";
import "../../lib/ERC20SafeTransfer.sol";
import "../../lib/MathUint.sol";
import "../../thirdparty/SafeCast.sol";
import "../iface/IDepositContract.sol";


/// @title DefaultDepositContract
/// @dev   Default implementation of IDepositContract that just stores
///        all funds without doing anything with them.
///
///        Should be able to work with proxy contracts so the contract
///        can be updated easily (but with great caution and transparency!)
///        when necessary.
///
/// @author Brecht Devos - <[email protected]>
contract DefaultDepositContract is IDepositContract, Claimable
{
    using AddressUtil       for address;
    using ERC20SafeTransfer for address;
    using MathUint          for uint;
    using SafeCast          for uint;

    address public exchange;

    mapping (address => bool) private needCheckBalance;

    modifier onlyExchange()
    {
        require(msg.sender == exchange, "UNAUTHORIZED");
        _;
    }

    modifier ifNotZero(uint amount)
    {
        if (amount == 0) return;
        else  _;
    }

    event CheckBalance(
        address indexed token,
        bool            checkBalance
    );

    receive() external payable { }

    function initialize(
        address _exchange
        )
        external
    {
        require(
            exchange == address(0) && _exchange != address(0),
            "INVALID_EXCHANGE"
        );
        owner = msg.sender;
        exchange = _exchange;
    }

    function setCheckBalance(
        address token,
        bool    checkBalance
        )
        external
        onlyOwner
    {
        require(needCheckBalance[token] != checkBalance, "INVALID_VALUE");

        needCheckBalance[token] = checkBalance;
        emit CheckBalance(token, checkBalance);
    }

    function isTokenSupported(address /*token*/)
        external
        override
        pure
        returns (bool)
    {
        return true;
    }

    function deposit(
        address from,
        address token,
        uint248  amount, // 0-value supported
        bytes   calldata /*extraData*/
        )
        external
        override
        payable
        onlyExchange
        returns (uint248 amountReceived)
    {
        uint ethToReturn = 0;

        if (isETHInternal(token)) {
            require(msg.value >= amount, "INVALID_ETH_DEPOSIT");
            amountReceived = amount;
            ethToReturn = msg.value - amount;
        } else {
            // When checkBalance is enabled for a token we check the balance change
            // on the contract instead of counting on transferFrom to transfer exactly
            // the amount of tokens that is specified in the transferFrom call.
            // This is to support non-standard tokens which do custom transfer logic.
            bool checkBalance = needCheckBalance[token];
            uint balanceBefore = checkBalance ? ERC20(token).balanceOf(address(this)) : 0;

            token.safeTransferFromAndVerify(from, address(this), uint(amount));

            uint balanceAfter = checkBalance ? ERC20(token).balanceOf(address(this)) : amount;
            uint diff = balanceAfter.sub(balanceBefore);
            amountReceived = diff.toUint248();

            ethToReturn = msg.value;
        }

        if (ethToReturn > 0) {
            from.sendETHAndVerify(ethToReturn, gasleft());
        }
    }

    function withdraw(
        address /*from*/,
        address to,
        address token,
        uint    amount
        )
        external
        override
        payable
        onlyExchange
        ifNotZero(amount)
    {
        if (isETHInternal(token)) {
            to.sendETHAndVerify(amount, gasleft());
        } else {
            // Try to transfer the amount requested.
            // If this fails try to transfer the remaining balance in this contract.
            // This is to guard against non-standard token behavior where total supply
            // has changed in unexpected ways.
            if (!token.safeTransfer(to, amount)){
                uint amountPaid = ERC20(token).balanceOf(address(this));
                require(amountPaid < amount, "UNEXPECTED");
                token.safeTransferAndVerify(to, amountPaid);
            }
        }
    }

    function transfer(
        address from,
        address to,
        address token,
        uint    amount
        )
        external
        override
        payable
        onlyExchange
        ifNotZero(amount)
    {
        token.safeTransferFromAndVerify(from, to, amount);
    }

    function isETH(address addr)
        external
        override
        pure
        returns (bool)
    {
        return isETHInternal(addr);
    }

    // -- private --

    function isETHInternal(address addr)
        private
        pure
        returns (bool)
    {
        return addr == address(0);
    }
}

File 41 of 95 : BlockVerifier.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;

import "../../lib/ReentrancyGuard.sol";
import "../../thirdparty/verifiers/BatchVerifier.sol";
import "../../thirdparty/verifiers/Verifier.sol";
import "../iface/ExchangeData.sol";
import "../iface/IBlockVerifier.sol";
import "./VerificationKeys.sol";

/// @title An Implementation of IBlockVerifier.
/// @author Brecht Devos - <[email protected]>
contract BlockVerifier is ReentrancyGuard, IBlockVerifier
{
    struct Circuit
    {
        bool registered;
        bool enabled;
        uint[18] verificationKey;
    }

    mapping (uint8 => mapping (uint16 => mapping (uint8 => Circuit))) public circuits;

    constructor() Claimable() {}

    function verifyProofs(
        uint8  blockType,
        uint16 blockSize,
        uint8  blockVersion,
        uint[] calldata publicInputs,
        uint[] calldata proofs
        )
        external
        override
        view
        returns (bool)
    {
        // First try to find the verification key in the hard coded list
        (uint[14] memory _vk, uint[4] memory _vk_gammaABC, bool found) = VerificationKeys.getKey(
            blockType,
            blockSize,
            blockVersion
        );
        if (!found) {
            Circuit storage circuit = circuits[blockType][blockSize][blockVersion];
            require(circuit.registered == true, "NOT_REGISTERED");
            require(circuit.enabled == true, "NOT_ENABLED");

            // Load the verification key from storage.
            uint[18] storage vk = circuit.verificationKey;
            _vk = [
                vk[0], vk[1], vk[2], vk[3], vk[4], vk[5], vk[6],
                vk[7], vk[8], vk[9], vk[10], vk[11], vk[12], vk[13]
            ];
            _vk_gammaABC = [vk[14], vk[15], vk[16], vk[17]];
        }

        // Verify the proof.
        // Batched proof verification has a fixed overhead which makes it more
        // expensive to verify a single proof compared to the non-batched code
        // This is why we don't use the batched verification code here when only
        // a single proof needs to be verified.
        if (publicInputs.length == 1) {
            return Verifier.Verify(_vk, _vk_gammaABC, proofs, publicInputs);
        } else {
            return BatchVerifier.BatchVerify(
                _vk,
                _vk_gammaABC,
                proofs,
                publicInputs,
                publicInputs.length
            );
        }
    }

    function isCircuitRegistered(
        uint8  blockType,
        uint16 blockSize,
        uint8  blockVersion
        )
        external
        override
        view
        returns (bool)
    {
        return circuits[blockType][blockSize][blockVersion].registered;
    }

    function isCircuitEnabled(
        uint8  blockType,
        uint16 blockSize,
        uint8  blockVersion
        )
        external
        override
        view
        returns (bool)
    {
        return circuits[blockType][blockSize][blockVersion].enabled;
    }

    function getVerificationKey(
        uint8  blockType,
        uint16 blockSize,
        uint8  blockVersion
        )
        public
        view
        returns (uint[18] memory)
    {
        return circuits[blockType][blockSize][blockVersion].verificationKey;
    }
}

File 42 of 95 : BatchVerifier.sol
// SPDX-License-Identifier: UNLICENSED
// This code is taken from https://github.com/matter-labs/Groth16BatchVerifier/blob/master/BatchedSnarkVerifier/contracts/BatchVerifier.sol
// Thanks Harry from ETHSNARKS for base code
pragma solidity ^0.7.0;

library BatchVerifier {
    function GroupOrder ()
        public pure returns (uint256)
    {
        return 21888242871839275222246405745257275088548364400416034343698204186575808495617;
    }

    function NegateY( uint256 Y )
        internal pure returns (uint256)
    {
        uint q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
        return q - (Y % q);
    }

    function getProofEntropy(
        uint256[] memory in_proof,
        uint256[] memory proof_inputs,
        uint proofNumber
    )
        internal pure returns (uint256)
    {
        // Truncate the least significant 3 bits from the 256bit entropy so it fits the scalar field
        return uint(
            keccak256(
                abi.encodePacked(
                    in_proof[proofNumber*8 + 0], in_proof[proofNumber*8 + 1], in_proof[proofNumber*8 + 2], in_proof[proofNumber*8 + 3],
                    in_proof[proofNumber*8 + 4], in_proof[proofNumber*8 + 5], in_proof[proofNumber*8 + 6], in_proof[proofNumber*8 + 7],
                    proof_inputs[proofNumber]
                )
            )
        ) >> 3;
    }

    function accumulate(
        uint256[] memory in_proof,
        uint256[] memory proof_inputs, // public inputs, length is num_inputs * num_proofs
        uint256 num_proofs
    ) internal view returns (
        bool success,
        uint256[] memory proofsAandC,
        uint256[] memory inputAccumulators
    ) {
        uint256 q = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
        uint256 numPublicInputs = proof_inputs.length / num_proofs;
        uint256[] memory entropy = new uint256[](num_proofs);
        inputAccumulators = new uint256[](numPublicInputs + 1);

        for (uint256 proofNumber = 0; proofNumber < num_proofs; proofNumber++) {
            if (proofNumber == 0) {
                entropy[proofNumber] = 1;
            } else {
                // entropy[proofNumber] = uint(blockhash(block.number - proofNumber)) % q;
                // Safer entropy:
                entropy[proofNumber] = getProofEntropy(in_proof, proof_inputs, proofNumber);
            }
            require(entropy[proofNumber] != 0, "Entropy should not be zero");
            // here multiplication by 1 is implied
            inputAccumulators[0] = addmod(inputAccumulators[0], entropy[proofNumber], q);
            for (uint256 i = 0; i < numPublicInputs; i++) {
                require(proof_inputs[proofNumber * numPublicInputs + i] < q, "INVALID_INPUT");
                // accumulate the exponent with extra entropy mod q
                inputAccumulators[i+1] = addmod(inputAccumulators[i+1], mulmod(entropy[proofNumber], proof_inputs[proofNumber * numPublicInputs + i], q), q);
            }
            // coefficient for +vk.alpha (mind +) is the same as inputAccumulator[0]
        }

        // inputs for scalar multiplication
        uint256[3] memory mul_input;

        // use scalar multiplications to get proof.A[i] * entropy[i]

        proofsAandC = new uint256[](num_proofs*2 + 2);

        proofsAandC[0] = in_proof[0];
        proofsAandC[1] = in_proof[1];

        for (uint256 proofNumber = 1; proofNumber < num_proofs; proofNumber++) {
            require(entropy[proofNumber] < q, "INVALID_INPUT");
            mul_input[0] = in_proof[proofNumber*8];
            mul_input[1] = in_proof[proofNumber*8 + 1];
            mul_input[2] = entropy[proofNumber];
            assembly {
                // ECMUL, output proofsA[i]
                // success := staticcall(sub(gas, 2000), 7, mul_input, 0x60, add(add(proofsAandC, 0x20), mul(proofNumber, 0x40)), 0x40)
                success := staticcall(sub(gas(), 2000), 7, mul_input, 0x60, mul_input, 0x40)
            }
            if (!success) {
                return (false, proofsAandC, inputAccumulators);
            }
            proofsAandC[proofNumber*2] = mul_input[0];
            proofsAandC[proofNumber*2 + 1] = mul_input[1];
        }

        // use scalar multiplication and addition to get sum(proof.C[i] * entropy[i])

        uint256[4] memory add_input;

        add_input[0] = in_proof[6];
        add_input[1] = in_proof[7];

        for (uint256 proofNumber = 1; proofNumber < num_proofs; proofNumber++) {
            mul_input[0] = in_proof[proofNumber*8 + 6];
            mul_input[1] = in_proof[proofNumber*8 + 7];
            mul_input[2] = entropy[proofNumber];
            assembly {
                // ECMUL, output proofsA
                success := staticcall(sub(gas(), 2000), 7, mul_input, 0x60, add(add_input, 0x40), 0x40)
            }
            if (!success) {
                return (false, proofsAandC, inputAccumulators);
            }

            assembly {
                // ECADD from two elements that are in add_input and output into first two elements of add_input
                success := staticcall(sub(gas(), 2000), 6, add_input, 0x80, add_input, 0x40)
            }
            if (!success) {
                return (false, proofsAandC, inputAccumulators);
            }
        }

        proofsAandC[num_proofs*2] = add_input[0];
        proofsAandC[num_proofs*2 + 1] = add_input[1];
    }

    function prepareBatches(
        uint256[14] memory in_vk,
        uint256[4] memory vk_gammaABC,
        uint256[] memory inputAccumulators
    ) internal view returns (
        bool success,
        uint256[4] memory finalVksAlphaX
    ) {
        // Compute the linear combination vk_x using accumulator
        // First two fields are used as the sum and are initially zero
        uint256[4] memory add_input;
        uint256[3] memory mul_input;

        // Performs a sum(gammaABC[i] * inputAccumulator[i])
        for (uint256 i = 0; i < inputAccumulators.length; i++) {
            mul_input[0] = vk_gammaABC[2*i];
            mul_input[1] = vk_gammaABC[2*i + 1];
            mul_input[2] = inputAccumulators[i];

            assembly {
                // ECMUL, output to the last 2 elements of `add_input`
                success := staticcall(sub(gas(), 2000), 7, mul_input, 0x60, add(add_input, 0x40), 0x40)
            }
            if (!success) {
                return (false, finalVksAlphaX);
            }

            assembly {
                // ECADD from four elements that are in add_input and output into first two elements of add_input
                success := staticcall(sub(gas(), 2000), 6, add_input, 0x80, add_input, 0x40)
            }
            if (!success) {
                return (false, finalVksAlphaX);
            }
        }

        finalVksAlphaX[2] = add_input[0];
        finalVksAlphaX[3] = add_input[1];

        // add one extra memory slot for scalar for multiplication usage
        uint256[3] memory finalVKalpha;
        finalVKalpha[0] = in_vk[0];
        finalVKalpha[1] = in_vk[1];
        finalVKalpha[2] = inputAccumulators[0];

        assembly {
            // ECMUL, output to first 2 elements of finalVKalpha
            success := staticcall(sub(gas(), 2000), 7, finalVKalpha, 0x60, finalVKalpha, 0x40)
        }
        if (!success) {
            return (false, finalVksAlphaX);
        }

        finalVksAlphaX[0] = finalVKalpha[0];
        finalVksAlphaX[1] = finalVKalpha[1];
    }

    // original equation
    // e(proof.A, proof.B)*e(-vk.alpha, vk.beta)*e(-vk_x, vk.gamma)*e(-proof.C, vk.delta) == 1
    // accumulation of inputs
    // gammaABC[0] + sum[ gammaABC[i+1]^proof_inputs[i] ]

    function BatchVerify (
        uint256[14] memory in_vk, // verifying key is always constant number of elements
        uint256[4] memory vk_gammaABC, // variable length, depends on number of inputs
        uint256[] memory in_proof, // proof itself, length is 8 * num_proofs
        uint256[] memory proof_inputs, // public inputs, length is num_inputs * num_proofs
        uint256 num_proofs
    )
    internal
    view
    returns (bool success)
    {
        require(in_proof.length == num_proofs * 8, "Invalid proofs length for a batch");
        require(proof_inputs.length % num_proofs == 0, "Invalid inputs length for a batch");
        require(((vk_gammaABC.length / 2) - 1) == proof_inputs.length / num_proofs, "Invalid verification key");

        // strategy is to accumulate entropy separately for some proof elements
        // (accumulate only for G1, can't in G2) of the pairing equation, as well as input verification key,
        // postpone scalar multiplication as much as possible and check only one equation
        // by using 3 + num_proofs pairings only plus 2*num_proofs + (num_inputs+1) + 1 scalar multiplications compared to naive
        // 4*num_proofs pairings and num_proofs*(num_inputs+1) scalar multiplications

        bool valid;
        uint256[] memory proofsAandC;
        uint256[] memory inputAccumulators;
        (valid, proofsAandC, inputAccumulators) = accumulate(in_proof, proof_inputs, num_proofs);
        if (!valid) {
            return false;
        }

        uint256[4] memory finalVksAlphaX;
        (valid, finalVksAlphaX) = prepareBatches(in_vk, vk_gammaABC, inputAccumulators);
        if (!valid) {
            return false;
        }

        uint256[] memory inputs = new uint256[](6*num_proofs + 18);
        // first num_proofs pairings e(ProofA, ProofB)
        for (uint256 proofNumber = 0; proofNumber < num_proofs; proofNumber++) {
            inputs[proofNumber*6] = proofsAandC[proofNumber*2];
            inputs[proofNumber*6 + 1] = proofsAandC[proofNumber*2 + 1];
            inputs[proofNumber*6 + 2] = in_proof[proofNumber*8 + 2];
            inputs[proofNumber*6 + 3] = in_proof[proofNumber*8 + 3];
            inputs[proofNumber*6 + 4] = in_proof[proofNumber*8 + 4];
            inputs[proofNumber*6 + 5] = in_proof[proofNumber*8 + 5];
        }

        // second pairing e(-finalVKaplha, vk.beta)
        inputs[num_proofs*6] = finalVksAlphaX[0];
        inputs[num_proofs*6 + 1] = NegateY(finalVksAlphaX[1]);
        inputs[num_proofs*6 + 2] = in_vk[2];
        inputs[num_proofs*6 + 3] = in_vk[3];
        inputs[num_proofs*6 + 4] = in_vk[4];
        inputs[num_proofs*6 + 5] = in_vk[5];

        // third pairing e(-finalVKx, vk.gamma)
        inputs[num_proofs*6 + 6] = finalVksAlphaX[2];
        inputs[num_proofs*6 + 7] = NegateY(finalVksAlphaX[3]);
        inputs[num_proofs*6 + 8] = in_vk[6];
        inputs[num_proofs*6 + 9] = in_vk[7];
        inputs[num_proofs*6 + 10] = in_vk[8];
        inputs[num_proofs*6 + 11] = in_vk[9];

        // fourth pairing e(-proof.C, finalVKdelta)
        inputs[num_proofs*6 + 12] = proofsAandC[num_proofs*2];
        inputs[num_proofs*6 + 13] = NegateY(proofsAandC[num_proofs*2 + 1]);
        inputs[num_proofs*6 + 14] = in_vk[10];
        inputs[num_proofs*6 + 15] = in_vk[11];
        inputs[num_proofs*6 + 16] = in_vk[12];
        inputs[num_proofs*6 + 17] = in_vk[13];

        uint256 inputsLength = inputs.length * 32;
        uint[1] memory out;
        require(inputsLength % 192 == 0, "Inputs length should be multiple of 192 bytes");

        assembly {
            success := staticcall(sub(gas(), 2000), 8, add(inputs, 0x20), inputsLength, out, 0x20)
        }
        return success && out[0] == 1;
    }
}

File 43 of 95 : Verifier.sol
// SPDX-License-Identifier: UNLICENSED
// This code is taken from https://github.com/HarryR/ethsnarks/blob/master/contracts/Verifier.sol
// this code is taken from https://github.com/JacobEberhardt/ZoKrates
pragma solidity ^0.7.0;

library Verifier
{
    function ScalarField ()
        internal
        pure
        returns (uint256)
    {
        return 21888242871839275222246405745257275088548364400416034343698204186575808495617;
    }

    function NegateY( uint256 Y )
        internal pure returns (uint256)
    {
        uint q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
        return q - (Y % q);
    }


    /*
    * This implements the Solidity equivalent of the following Python code:

        from py_ecc.bn128 import *

        data = # ... arguments to function [in_vk, vk_gammaABC, in_proof, proof_inputs]

        vk = [int(_, 16) for _ in data[0]]
        ic = [FQ(int(_, 16)) for _ in data[1]]
        proof = [int(_, 16) for _ in data[2]]
        inputs = [int(_, 16) for _ in data[3]]

        it = iter(ic)
        ic = [(_, next(it)) for _ in it]
        vk_alpha = [FQ(_) for _ in vk[:2]]
        vk_beta = (FQ2(vk[2:4][::-1]), FQ2(vk[4:6][::-1]))
        vk_gamma = (FQ2(vk[6:8][::-1]), FQ2(vk[8:10][::-1]))
        vk_delta = (FQ2(vk[10:12][::-1]), FQ2(vk[12:14][::-1]))

        assert is_on_curve(vk_alpha, b)
        assert is_on_curve(vk_beta, b2)
        assert is_on_curve(vk_gamma, b2)
        assert is_on_curve(vk_delta, b2)

        proof_A = [FQ(_) for _ in proof[:2]]
        proof_B = (FQ2(proof[2:4][::-1]), FQ2(proof[4:-2][::-1]))
        proof_C = [FQ(_) for _ in proof[-2:]]

        assert is_on_curve(proof_A, b)
        assert is_on_curve(proof_B, b2)
        assert is_on_curve(proof_C, b)

        vk_x = ic[0]
        for i, s in enumerate(inputs):
            vk_x = add(vk_x, multiply(ic[i + 1], s))

        check_1 = pairing(proof_B, proof_A)
        check_2 = pairing(vk_beta, neg(vk_alpha))
        check_3 = pairing(vk_gamma, neg(vk_x))
        check_4 = pairing(vk_delta, neg(proof_C))

        ok = check_1 * check_2 * check_3 * check_4
        assert ok == FQ12.one()
    */
    function Verify(
        uint256[14] memory in_vk,
        uint256[4] memory vk_gammaABC,
        uint256[] memory in_proof,
        uint256[] memory proof_inputs
        )
        internal
        view
        returns (bool)
    {
        uint256 snark_scalar_field = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
        require(((vk_gammaABC.length / 2) - 1) == proof_inputs.length, "INVALID_VALUE");

        // Compute the linear combination vk_x
        uint256[3] memory mul_input;
        uint256[4] memory add_input;
        bool success;
        uint m = 2;

        // First two fields are used as the sum
        add_input[0] = vk_gammaABC[0];
        add_input[1] = vk_gammaABC[1];

        // Performs a sum of gammaABC[0] + sum[ gammaABC[i+1]^proof_inputs[i] ]
        for (uint i = 0; i < proof_inputs.length; i++) {
            require(proof_inputs[i] < snark_scalar_field, "INVALID_INPUT");
            mul_input[0] = vk_gammaABC[m++];
            mul_input[1] = vk_gammaABC[m++];
            mul_input[2] = proof_inputs[i];

            assembly {
                // ECMUL, output to last 2 elements of `add_input`
                success := staticcall(sub(gas(), 2000), 7, mul_input, 0x80, add(add_input, 0x40), 0x60)
            }
            if (!success) {
                return false;
            }

            assembly {
                // ECADD
                success := staticcall(sub(gas(), 2000), 6, add_input, 0xc0, add_input, 0x60)
            }
            if (!success) {
                return false;
            }
        }

        uint[24] memory input = [
            // (proof.A, proof.B)
            in_proof[0], in_proof[1],                           // proof.A   (G1)
            in_proof[2], in_proof[3], in_proof[4], in_proof[5], // proof.B   (G2)

            // (-vk.alpha, vk.beta)
            in_vk[0], NegateY(in_vk[1]),                        // -vk.alpha (G1)
            in_vk[2], in_vk[3], in_vk[4], in_vk[5],             // vk.beta   (G2)

            // (-vk_x, vk.gamma)
            add_input[0], NegateY(add_input[1]),                // -vk_x     (G1)
            in_vk[6], in_vk[7], in_vk[8], in_vk[9],             // vk.gamma  (G2)

            // (-proof.C, vk.delta)
            in_proof[6], NegateY(in_proof[7]),                  // -proof.C  (G1)
            in_vk[10], in_vk[11], in_vk[12], in_vk[13]          // vk.delta  (G2)
        ];

        uint[1] memory out;
        assembly {
            success := staticcall(sub(gas(), 2000), 8, input, 768, out, 0x20)
        }
        return success && out[0] != 0;
    }
}

File 44 of 95 : LoopringV3.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;

import "../../lib/AddressUtil.sol";
import "../../lib/ERC20SafeTransfer.sol";
import "../../lib/MathUint.sol";
import "../../lib/ReentrancyGuard.sol";
import "../iface/IExchangeV3.sol";
import "../iface/ILoopringV3.sol";


/// @title LoopringV3
/// @dev This contract does NOT support proxy.
/// @author Brecht Devos - <[email protected]>
/// @author Daniel Wang  - <[email protected]>
contract LoopringV3 is ILoopringV3, ReentrancyGuard
{
    using AddressUtil       for address payable;
    using MathUint          for uint;
    using ERC20SafeTransfer for address;

    address public immutable override lrcAddress;

    // -- Constructor --
    constructor(
        address _lrcAddress,
        address payable _protocolFeeVault,
        address _blockVerifierAddress
        )
        Claimable()
    {
        require(address(0) != _lrcAddress, "ZERO_ADDRESS");

        lrcAddress = _lrcAddress;
        blockVerifierAddress = _blockVerifierAddress;

        protocolFeeBips = ExchangeData.DEFAULT_PROTOCOL_FEE_BIPS;

        updateSettingsInternal(_protocolFeeVault, 0);
    }

    // == Public Functions ==
    function updateSettings(
        address payable _protocolFeeVault,
        uint    _forcedWithdrawalFee
        )
        external
        override
        nonReentrant
        onlyOwner
    {
        updateSettingsInternal(
            _protocolFeeVault,
            _forcedWithdrawalFee
        );
    }

    function updateProtocolFeeSettings(
        uint16 _protocolFeeBips
        )
        external
        override
        nonReentrant
        onlyOwner
    {
        protocolFeeBips = _protocolFeeBips;

        emit SettingsUpdated(block.timestamp);
    }

    function getExchangeStake(
        address exchangeAddr
        )
        external
        override
        view
        returns (uint)
    {
        return exchangeStake[exchangeAddr];
    }

    function burnExchangeStake(
        uint amount
        )
        external
        override
        nonReentrant
        returns (uint burnedLRC)
    {
        require(amount > 0, "ZERO_VALUE");

        burnedLRC = exchangeStake[msg.sender];

        if (amount < burnedLRC) {
            burnedLRC = amount;
        }
        if (burnedLRC > 0) {
            lrcAddress.safeTransferAndVerify(protocolFeeVault, burnedLRC);
            exchangeStake[msg.sender] = exchangeStake[msg.sender].sub(burnedLRC);
            totalStake = totalStake.sub(burnedLRC);
        }
        emit ExchangeStakeBurned(msg.sender, burnedLRC);
    }

    function depositExchangeStake(
        address exchangeAddr,
        uint    amountLRC
        )
        external
        override
        nonReentrant
        returns (uint stakedLRC)
    {
        require(amountLRC > 0, "ZERO_VALUE");

        lrcAddress.safeTransferFromAndVerify(msg.sender, address(this), amountLRC);

        stakedLRC = exchangeStake[exchangeAddr].add(amountLRC);
        exchangeStake[exchangeAddr] = stakedLRC;
        totalStake = totalStake.add(amountLRC);

        emit ExchangeStakeDeposited(exchangeAddr, amountLRC);
    }

    function withdrawExchangeStake(
        address recipient,
        uint    requestedAmount
        )
        external
        override
        nonReentrant
        returns (uint amountLRC)
    {
        require(requestedAmount > 0, "ZERO_VALUE");

        uint stake = exchangeStake[msg.sender];
        amountLRC = (stake > requestedAmount) ? requestedAmount : stake;

        if (amountLRC > 0) {
            lrcAddress.safeTransferAndVerify(recipient, amountLRC);
            exchangeStake[msg.sender] = exchangeStake[msg.sender].sub(amountLRC);
            totalStake = totalStake.sub(amountLRC);
        }

        emit ExchangeStakeWithdrawn(msg.sender, amountLRC);
    }

    function getProtocolFeeValues()
        external
        override
        view
        returns (
            uint16 feeBips
        )
    {
        return protocolFeeBips;
    }

    // == Internal Functions ==
    function updateSettingsInternal(
        address payable  _protocolFeeVault,
        uint    _forcedWithdrawalFee
        )
        private
    {
        require(address(0) != _protocolFeeVault, "ZERO_ADDRESS");
        require(_forcedWithdrawalFee <= ExchangeData.MAX_FORCED_WITHDRAWAL_FEE, "INVALID_FORCED_WITHDRAWAL_FEE");

        protocolFeeVault = _protocolFeeVault;
        forcedWithdrawalFee = _forcedWithdrawalFee;

        emit SettingsUpdated(block.timestamp);
    }
}

File 45 of 95 : LzDecompressorContract.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;

import "../aux/compression/LzDecompressor.sol";

contract LzDecompressorContract {
    function decompress(
        bytes calldata data
        )
        external
        pure
        returns (bytes memory)
    {
        return LzDecompressor.decompress(data);
    }

    function benchmark(
        bytes calldata data
        )
        external
        pure
        returns (bytes memory)
    {
        return LzDecompressor.decompress(data);
    }
}

File 46 of 95 : LzDecompressor.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;


/// @title LzDecompressor
/// @author Brecht Devos - <[email protected]>
/// @dev Decompresses data compressed with a LZ77/Snappy like compressor optimized for EVM
///      Currently supports 3 modes:
///      - Copy directly from calldata (needs length)
///      - Fill memory with zeros (needs length)
///      - Copy from previously decompressed memory (needs offset, length)
///      TODO:
///      - better packing of (mode, offset, length)
///      - add mode copying from random location in calldata (faster than memory copies)
///      - add support to copy data from memory using the identity pre-compile
///        (large initital cost but cheaper copying, does not support overlapping memory ranges)
library LzDecompressor
{
    function decompress(
        bytes calldata /*data*/
        )
        internal
        pure
        returns (bytes memory)
    {
        bytes memory uncompressed;
        assembly {
            uncompressed := mload(0x40)
            let ptr := add(uncompressed, 32)
            let dataLength := calldataload(36)
            for { let pos := 0 } lt(pos, dataLength) {} {
                // Read the mode
                pos := add(pos, 1)
                let mode := and(calldataload(add(36, pos)), 0xFF)

                switch mode
                case 0 {
                    // Copy from calldata at the current position
                    pos := add(pos, 2)
                    let length := and(calldataload(add(36, pos)), 0xFFFF)

                    calldatacopy(ptr, add(68, pos), length)
                    pos := add(pos, length)

                    ptr := add(ptr, length)
                }
                case 1 {
                    // Write out zeros
                    pos := add(pos, 2)
                    let length := and(calldataload(add(36, pos)), 0xFFFF)

                    codecopy(ptr, codesize(), length)

                    ptr := add(ptr, length)
                }
                case 2 {
                    // Copy from previously decompressed bytes in memory
                    pos := add(pos, 2)
                    let offset := and(calldataload(add(36, pos)), 0xFFFF)
                    pos := add(pos, 2)
                    let length := and(calldataload(add(36, pos)), 0xFFFF)

                    let src := sub(ptr, offset)
                    let i := 0
                    if lt(offset, 32) {
                        // If the offset is less than 32 we can't begin copying 32 bytes at a time.
                        // We first do some copies to fix this
                        mstore(add(src, offset), mload(src))
                        mstore(add(src, mul(offset, 2)), mload(src))
                        mstore(add(src, mul(offset, 4)), mload(src))
                        mstore(add(src, mul(offset, 8)), mload(src))
                        mstore(add(src, mul(offset, 16)), mload(src))
                        mstore(add(src, mul(offset, 32)), mload(src))

                        // No matter the offset, the first 32 bytes can now be copied
                        // Fix the starting data so we can copy like normal afterwards
                        i := 32
                        src := add(sub(src, 32), mod(32, offset))
                    }
                    // This can copy too many bytes, but that's okay
                    // Needs unrolling for the best performance
                    for { } lt(i, length) { } {
                        mstore(add(ptr, i), mload(add(src, i)))
                        i := add(i, 32)
                        mstore(add(ptr, i), mload(add(src, i)))
                        i := add(i, 32)
                        mstore(add(ptr, i), mload(add(src, i)))
                        i := add(i, 32)
                        mstore(add(ptr, i), mload(add(src, i)))
                        i := add(i, 32)
                    }
                    ptr := add(ptr, length)
                }
                default {
                    revert(0, 0)
                }
            }
            // Store data length
            mstore(uncompressed, sub(sub(ptr, uncompressed), 32))

            // Update free memory pointer
            mstore(0x40, add(ptr, 0x20))
        }
        return uncompressed;
    }
}

File 47 of 95 : DelayedOwnerContract.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "../aux/access/DelayedOwner.sol";
import "./DelayedTargetContract.sol";


/// @title DelayedOwnerContract
/// @author Brecht Devos - <[email protected]>
contract DelayedOwnerContract is DelayedOwner
{
    constructor(
        address delayedTargetAddress,
        bool setDefaultFunctionDelays
        )
        DelayedOwner(delayedTargetAddress, 3 days)
    {
        if (setDefaultFunctionDelays) {
            DelayedTargetContract delayedTarget = DelayedTargetContract(delayedTargetAddress);
            setFunctionDelay(delayedTarget.delayedFunctionPayable.selector, 1 days);
            setFunctionDelay(delayedTarget.delayedFunctionRevert.selector, 2 days);
            setFunctionDelay(delayedTarget.transferOwnership.selector, 3 days);
        }
    }

    function setFunctionDelayExternal(
        address to,
        bytes4  functionSelector,
        uint    delay
        )
        external
    {
        setFunctionDelay(to, functionSelector, delay);
    }
}

File 48 of 95 : DelayedOwner.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;

import "../../lib/Claimable.sol";
import "./DelayedTransaction.sol";


/// @title  DelayedOwner
/// @author Brecht Devos - <[email protected]>
contract DelayedOwner is DelayedTransaction, Claimable
{
    address public defaultContract;

    event FunctionDelayUpdate(
        bytes4  functionSelector,
        uint    delay
    );

    constructor(
        address _defaultContract,
        uint    _timeToLive
        )
        DelayedTransaction(_timeToLive)
    {
        require(_defaultContract != address(0), "INVALID_ADDRESS");

        defaultContract = _defaultContract;
    }

    receive()
        external
        // nonReentrant
        payable
    {
        // Don't do anything when receiving ETH
    }

    fallback()
        external
        nonReentrant
        payable
    {
        // Don't do anything if msg.sender isn't the owner
        if (msg.sender != owner) {
            return;
        }
        transactInternal(defaultContract, msg.value, msg.data);
    }

    function isAuthorizedForTransactions(address sender)
        internal
        override
        view
        returns (bool)
    {
        return sender == owner;
    }

    function setFunctionDelay(
        bytes4  functionSelector,
        uint    delay
        )
        internal
    {
        setFunctionDelay(defaultContract, functionSelector, delay);

        emit FunctionDelayUpdate(functionSelector, delay);
    }
}

File 49 of 95 : DelayedTransaction.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "../../lib/AddressUtil.sol";
import "../../lib/MathUint.sol";
import "../../lib/ReentrancyGuard.sol";
import "../../thirdparty/BytesUtil.sol";
import "./IDelayedTransaction.sol";


/// @title DelayedOwner
/// @author Brecht Devos - <[email protected]>
/// @dev Base class for an Owner contract where certain functions have
///      a mandatory delay for security purposes.
abstract contract DelayedTransaction is IDelayedTransaction, ReentrancyGuard
{
    using AddressUtil for address payable;
    using BytesUtil   for bytes;
    using MathUint    for uint;

    // Map from address and function to the functions's location+1 in the `delayedFunctions` array.
    mapping (address => mapping (bytes4 => uint)) private delayedFunctionMap;

    // Map from transaction ID to the transaction's location+1 in the `pendingTransactions` array.
    mapping (uint => uint) private pendingTransactionMap;

    // Used to generate a unique identifier for a delayed transaction
    uint private totalNumDelayedTransactions = 0;

    modifier onlyAuthorized
    {
        require(isAuthorizedForTransactions(msg.sender), "UNAUTHORIZED");
        _;
    }

    constructor(
        uint    _timeToLive
        )
    {
        timeToLive = _timeToLive;
    }

    // If the function that is called has no delay the function is called immediately,
    // otherwise the function call is stored on-chain and can be executed later using
    // `executeTransaction` when the necessary time has passed.
    function transact(
        address to,
        bytes   calldata data
        )
        external
        override
        nonReentrant
        payable
        onlyAuthorized
    {
        transactInternal(to, msg.value, data);
    }

    function executeTransaction(
        uint transactionId
        )
        external
        override
        nonReentrant
        onlyAuthorized
    {
        Transaction memory transaction = getTransaction(transactionId);

        // Make sure the delay is respected
        bytes4 functionSelector = transaction.data.toBytes4(0);
        uint delay = getFunctionDelay(transaction.to, functionSelector);
        require(block.timestamp >= transaction.timestamp.add(delay), "TOO_EARLY");
        require(block.timestamp <= transaction.timestamp.add(delay).add(timeToLive), "TOO_LATE");

        // Remove the transaction
        removeTransaction(transaction.id);

        // Exectute the transaction
        (bool success, bytes memory returnData) = exectuteTransaction(transaction);
        if (!success) {
            assembly { revert(add(returnData, 32), mload(returnData)) }
        }

        emit PendingTransactionExecuted(
            transaction.id,
            transaction.timestamp,
            transaction.to,
            transaction.value,
            transaction.data
        );
    }

    function cancelTransaction(
        uint transactionId
        )
        external
        override
        nonReentrant
        onlyAuthorized
    {
        cancelTransactionInternal(transactionId);
    }

    function cancelAllTransactions()
        external
        override
        nonReentrant
        onlyAuthorized
    {
        // First cache all transactions ids of the transactions we will remove
        uint[] memory transactionIds = new uint[](pendingTransactions.length);
        for(uint i = 0; i < pendingTransactions.length; i++) {
            transactionIds[i] = pendingTransactions[i].id;
        }
        // Now remove all delayed transactions
        for(uint i = 0; i < transactionIds.length; i++) {
            cancelTransactionInternal(transactionIds[i]);
        }
    }

    function getFunctionDelay(
        address to,
        bytes4  functionSelector
        )
        public
        override
        view
        returns (uint)
    {
        uint pos = delayedFunctionMap[to][functionSelector];
        if (pos == 0) {
            return 0;
        } else {
            return delayedFunctions[pos - 1].delay;
        }
    }

    function getNumPendingTransactions()
        external
        override
        view
        returns (uint)
    {
        return pendingTransactions.length;
    }

    function getNumDelayedFunctions()
        external
        override
        view
        returns (uint)
    {
        return delayedFunctions.length;
    }

    // == Internal Functions ==

    function transactInternal(
        address to,
        uint    value,
        bytes   memory data
        )
        internal
    {
        Transaction memory transaction = Transaction(
            totalNumDelayedTransactions,
            block.timestamp,
            to,
            value,
            data
        );

        bytes4 functionSelector = transaction.data.toBytes4(0);
        uint delay = getFunctionDelay(transaction.to, functionSelector);
        if (delay == 0) {
            (bool success, bytes memory returnData) = exectuteTransaction(transaction);
            if (!success) {
                assembly { revert(add(returnData, 32), mload(returnData)) }
            }
            emit TransactionExecuted(
                transaction.timestamp,
                transaction.to,
                transaction.value,
                transaction.data
            );
        } else {
            pendingTransactions.push(transaction);
            pendingTransactionMap[transaction.id] = pendingTransactions.length;
            emit TransactionDelayed(
                transaction.id,
                transaction.timestamp,
                transaction.to,
                transaction.value,
                transaction.data,
                delay
            );
            totalNumDelayedTransactions++;
        }
    }

    function setFunctionDelay(
        address to,
        bytes4  functionSelector,
        uint    delay
        )
        internal
    {
        // Check if the function already has a delay
        uint pos = delayedFunctionMap[to][functionSelector];
        if (pos > 0) {
            if (delay > 0) {
                // Just update the delay
                delayedFunctions[pos - 1].delay = delay;
            } else {
                // Remove the delayed function
                uint size = delayedFunctions.length;
                if (pos != size) {
                    DelayedFunction memory lastOne = delayedFunctions[size - 1];
                    delayedFunctions[pos - 1] = lastOne;
                    delayedFunctionMap[lastOne.to][lastOne.functionSelector] = pos;
                }
                delayedFunctions.pop();
                delete delayedFunctionMap[to][functionSelector];
            }
        } else if (delay > 0) {
            // Add the new delayed function
            DelayedFunction memory delayedFunction = DelayedFunction(
                to,
                functionSelector,
                delay
            );
            delayedFunctions.push(delayedFunction);
            delayedFunctionMap[to][functionSelector] = delayedFunctions.length;
        }
    }

    function exectuteTransaction(
        Transaction memory transaction
        )
        internal
        returns (bool success, bytes memory returnData)
    {
        // solium-disable-next-line security/no-call-value
        (success, returnData) = transaction.to.call{value: transaction.value}(transaction.data);
    }

    function cancelTransactionInternal(
        uint transactionId
        )
        internal
    {
        Transaction memory transaction = getTransaction(transactionId);

        // Remove the transaction
        removeTransaction(transaction.id);

        emit TransactionCancelled(
            transaction.id,
            transaction.timestamp,
            transaction.to,
            transaction.value,
            transaction.data
        );

        // Return the transaction value (if there is any)
        uint value = transaction.value;
        if (value > 0) {
            msg.sender.sendETHAndVerify(value, gasleft());
        }
    }

    function getTransaction(
        uint transactionId
        )
        internal
        view
        returns (Transaction storage transaction)
    {
        uint pos = pendingTransactionMap[transactionId];
        require(pos != 0, "TRANSACTION_NOT_FOUND");
        transaction = pendingTransactions[pos - 1];
    }

    function removeTransaction(
        uint transactionId
        )
        internal
    {
        uint pos = pendingTransactionMap[transactionId];
        require(pos != 0, "TRANSACTION_NOT_FOUND");

        uint size = pendingTransactions.length;
        if (pos != size) {
            Transaction memory lastOne = pendingTransactions[size - 1];
            pendingTransactions[pos - 1] = lastOne;
            pendingTransactionMap[lastOne.id] = pos;
        }

        pendingTransactions.pop();
        delete pendingTransactionMap[transactionId];
    }

    function isAuthorizedForTransactions(address sender)
        internal
        virtual
        view
        returns (bool);
}

File 50 of 95 : IDelayedTransaction.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;


/// @title IDelayedTransaction
/// @author Brecht Devos - <[email protected]>
abstract contract IDelayedTransaction
{
    event TransactionDelayed(
        uint    id,
        uint    timestamp,
        address to,
        uint    value,
        bytes   data,
        uint    delay
    );

    event TransactionCancelled(
        uint    id,
        uint    timestamp,
        address to,
        uint    value,
        bytes   data
    );

    event TransactionExecuted(
        uint    timestamp,
        address to,
        uint    value,
        bytes   data
    );

    event PendingTransactionExecuted(
        uint    id,
        uint    timestamp,
        address to,
        uint    value,
        bytes   data
    );

    struct Transaction
    {
        uint    id;
        uint    timestamp;
        address to;
        uint    value;
        bytes   data;
    }

    struct DelayedFunction
    {
        address to;
        bytes4  functionSelector;
        uint    delay;
    }

    // The maximum amount of time (in seconds) a pending transaction can be executed
    // (so the amount of time than can pass after the mandatory function specific delay).
    // If the transaction hasn't been executed before then it can be cancelled so it is removed
    // from the pending transaction list.
    uint public timeToLive;

    // Active list of delayed functions (delay > 0)
    DelayedFunction[] public delayedFunctions;

    // Active list of pending transactions
    Transaction[] public pendingTransactions;

    /// @dev Executes a pending transaction.
    /// @param to The contract address to call
    /// @param data The call data
    function transact(
        address to,
        bytes   calldata data
        )
        external
        virtual
        payable;

    /// @dev Executes a pending transaction.
    /// @param transactionId The id of the pending transaction.
    function executeTransaction(
        uint transactionId
        )
        external
        virtual;

    /// @dev Cancels a pending transaction.
    /// @param transactionId The id of the pending transaction.
    function cancelTransaction(
        uint transactionId
        )
        external
        virtual;

    /// @dev Cancels all pending transactions.
    function cancelAllTransactions()
        external
        virtual;

    /// @dev Gets the delay for the given function
    /// @param functionSelector The function selector.
    /// @return The delay of the function.
    function getFunctionDelay(
        address to,
        bytes4  functionSelector
        )
        public
        virtual
        view
        returns (uint);

    /// @dev Gets the number of pending transactions.
    /// @return The number of pending transactions.
    function getNumPendingTransactions()
        external
        virtual
        view
        returns (uint);

    /// @dev Gets the number of functions that have a delay.
    /// @return The number of delayed functions.
    function getNumDelayedFunctions()
        external
        virtual
        view
        returns (uint);
}

File 51 of 95 : DelayedTargetContract.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "../lib/Claimable.sol";


/// @title DelayedTargetContract
/// @author Brecht Devos - <[email protected]>
contract DelayedTargetContract is Claimable
{
    uint public constant MAGIC_VALUE = 0xFEDCBA987654321;
    uint public value = 7;

    function delayedFunctionPayable(
        uint _value
        )
        external
        payable
        returns (uint)
    {
        value = _value;
        return _value;
    }

    function delayedFunctionRevert(
        uint _value
        )
        external
    {
        require(false, "DELAYED_REVERT");
        value = _value;
    }

    function immediateFunctionPayable(
        uint _value
        )
        external
        payable
    {
        value = _value;
    }

    function immediateFunctionView()
        external
        pure
        returns (uint)
    {
        return MAGIC_VALUE;
    }

    function immediateFunctionRevert(
        uint _value
        )
        external
        payable
    {
        require(false, "IMMEDIATE_REVERT");
        value = _value;
    }
}

File 52 of 95 : DummyToken.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "./LRCToken.sol";


/// @author Kongliang Zhong - <[email protected]>
contract DummyToken is LRCToken {
    using SafeMath for uint;

    constructor(
        string memory _name,
        string memory _symbol,
        uint8         _decimals,
        uint          _totalSupply
    ) LRCToken(
        _name,
        _symbol,
        _decimals,
        _totalSupply,
        msg.sender
        )
    {
    }

    function setBalance(
        address _target,
        uint _value
        )
        public
    {
        uint currBalance = balanceOf(_target);
        if (_value < currBalance) {
            totalSupply_ = totalSupply_.sub(currBalance.sub(_value));
        } else {
            totalSupply_ = totalSupply_.add(_value.sub(currBalance));
        }
        balances[_target] = _value;
    }

    function addBalance(
        address _target,
        uint _value
        )
        public
    {
        uint currBalance = balanceOf(_target);
        require(_value + currBalance >= currBalance, "INVALID_VALUE");
        totalSupply_ = totalSupply_.add(_value);
        balances[_target] = currBalance.add(_value);
    }

}

File 53 of 95 : LRCToken.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

/**
 * @title ERC20Basic
 * @dev Simpler version of ERC20 interface
 * @dev see https://github.com/ethereum/EIPs/issues/179
 */
abstract contract ERC20Basic {
    function totalSupply() public view virtual returns (uint);
    function balanceOf(address who) public view virtual returns (uint);
    function transfer(address to, uint value) public virtual returns (bool);
    event Transfer(address indexed from, address indexed to, uint value);
}
/**
 * @title SafeMath
 * @dev Math operations with safety checks that throw on error
 */
library SafeMath {
    /**
     * @dev Multiplies two numbers, throws on overflow.
     */
    function mul(uint a, uint b) internal pure returns (uint) {
        if (a == 0) {
            return 0;
        }
        uint c = a * b;
        assert(c / a == b);
        return c;
    }
    /**
     * @dev Integer division of two numbers, truncating the quotient.
     */
    function div(uint a, uint b) internal pure returns (uint) {
        // assert(b > 0); // Solidity automatically throws when dividing by 0
        uint c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold
        return c;
    }
    /**
     * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
     */
    function sub(uint a, uint b) internal pure returns (uint) {
        assert(b <= a);
        return a - b;
    }
    /**
     * @dev Adds two numbers, throws on overflow.
     */
    function add(uint a, uint b) internal pure returns (uint) {
        uint c = a + b;
        assert(c >= a);
        return c;
    }
}
/**
 * @title Basic token
 * @dev Basic version of StandardToken, with no allowances.
 */
contract BasicToken is ERC20Basic {
    using SafeMath for uint;
    mapping(address => uint) balances;
    uint totalSupply_;
    /**
     * @dev total number of tokens in existence
     */
    function totalSupply() public view override virtual returns (uint) {
        return totalSupply_;
    }
    /**
     * @dev transfer token for a specified address
     * @param _to The address to transfer to.
     * @param _value The amount to be transferred.
     */
    function transfer(address _to, uint _value) public override virtual returns (bool) {
        // require(_to != address(0), "ZERO_ADDRESS");
        require(_value <= balances[msg.sender], "TRANSFER_INSUFFICIENT_BALANCE");
        // SafeMath.sub will throw if there is not enough balance.
        balances[msg.sender] = balances[msg.sender].sub(_value);
        balances[_to] = balances[_to].add(_value);
        emit Transfer(msg.sender, _to, _value);
        return true;
    }
    /**
     * @dev Gets the balance of the specified address.
     * @param _owner The address to query the the balance of.
     * @return balance An uint representing the amount owned by the passed address.
     */
    function balanceOf(address _owner) public view override virtual returns (uint balance) {
        return balances[_owner];
    }
}
/**
 * @title ERC20 interface
 * @dev see https://github.com/ethereum/EIPs/issues/20
 */
abstract contract ERC20 is ERC20Basic {
    function allowance(address owner, address spender) public view virtual returns (uint);
    function transferFrom(address from, address to, uint value) public virtual returns (bool);
    function approve(address spender, uint value) public virtual returns (bool);
    event Approval(address indexed owner, address indexed spender, uint value);
}
/**
 * @title Standard ERC20 token
 *
 * @dev Implementation of the basic standard token.
 * @dev https://github.com/ethereum/EIPs/issues/20
 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
 */
contract StandardToken is ERC20, BasicToken {
    using SafeMath for uint;
    mapping (address => mapping (address => uint)) internal allowed;
    /**
     * @dev Transfer tokens from one address to another
     * @param _from address The address which you want to send tokens from
     * @param _to address The address which you want to transfer to
     * @param _value uint the amount of tokens to be transferred
     */
    function transferFrom(address _from, address _to, uint _value) public override virtual returns (bool) {
        // require(_to != address(0), "ZERO_ADDRESS");
        require(_value <= balances[_from], "TRANSFERFROM_INSUFFICIENT_BALANCE");
        require(_value <= allowed[_from][msg.sender], "TRANSFERFROM_INSUFFICIENT_ALLOWANCE");
        balances[_from] = balances[_from].sub(_value);
        balances[_to] = balances[_to].add(_value);
        allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
        emit Transfer(_from, _to, _value);
        return true;
    }
    /**
     * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
     *
     * 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
     * @param _spender The address which will spend the funds.
     * @param _value The amount of tokens to be spent.
     */
    function approve(address _spender, uint _value) public override returns (bool) {
        allowed[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }
    /**
     * @dev Function to check the amount of tokens that an owner allowed to a spender.
     * @param _owner address The address which owns the funds.
     * @param _spender address The address which will spend the funds.
     * @return A uint specifying the amount of tokens still available for the spender.
     */
    function allowance(address _owner, address _spender) public view override returns (uint) {
        return allowed[_owner][_spender];
    }
    /**
     * @dev Increase the amount of tokens that an owner allowed to a spender.
     *
     * approve should be called when allowed[_spender] == 0. To increment
     * allowed value is better to use this function to avoid 2 calls (and wait until
     * the first transaction is mined)
     * From MonolithDAO Token.sol
     * @param _spender The address which will spend the funds.
     * @param _addedValue The amount of tokens to increase the allowance by.
     */
    function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
        allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
        emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
        return true;
    }
    /**
     * @dev Decrease the amount of tokens that an owner allowed to a spender.
     *
     * approve should be called when allowed[_spender] == 0. To decrement
     * allowed value is better to use this function to avoid 2 calls (and wait until
     * the first transaction is mined)
     * From MonolithDAO Token.sol
     * @param _spender The address which will spend the funds.
     * @param _subtractedValue The amount of tokens to decrease the allowance by.
     */
    function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
        uint oldValue = allowed[msg.sender][_spender];
        if (_subtractedValue > oldValue) {
            allowed[msg.sender][_spender] = 0;
        } else {
            allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
        }
        emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
        return true;
    }
}

contract LRCToken is StandardToken {
    using SafeMath for uint;

    string     public name = "New Loopring token on ethereum";
    string     public symbol = "LRC";
    uint8      public decimals = 18;

    event Burn(address indexed burner, uint value);

    function burn(uint _value) public returns (bool) {
        require(_value <= balances[msg.sender], "BURN_INSUFFICIENT_BALANCE");

        address burner = msg.sender;
        balances[burner] = balances[burner].sub(_value);
        totalSupply_ = totalSupply_.sub(_value);
        emit Burn(burner, _value);
        emit Transfer(burner, address(0), _value);
        return true;
    }

    function burnFrom(address _owner, uint _value) public returns (bool) {
        require(_owner != address(0), "ZERO_ADDRESS");
        require(_value <= balances[_owner], "BURNFROM_INSUFFICIENT_BALANCE");
        require(_value <= allowed[_owner][msg.sender], "BURNFROM_INSUFFICIENT_ALLOWANCE");

        balances[_owner] = balances[_owner].sub(_value);
        allowed[_owner][msg.sender] = allowed[_owner][msg.sender].sub(_value);
        totalSupply_ = totalSupply_.sub(_value);

        emit Burn(_owner, _value);
        emit Transfer(_owner, address(0), _value);
        return true;
    }

    constructor(
        string memory _name,
        string memory _symbol,
        uint8         _decimals,
        uint          _totalSupply,
        address       _firstHolder
        )
    {
        require(_totalSupply > 0, "INVALID_VALUE");
        require(_firstHolder != address(0), "ZERO_ADDRESS");
        checkSymbolAndName(_symbol,_name);

        name = _name;
        symbol = _symbol;
        decimals = _decimals;
        totalSupply_ = _totalSupply;

        balances[_firstHolder] = totalSupply_;
    }

    // Make sure symbol has 3-8 chars in [A-Za-z._] and name has up to 128 chars.
    function checkSymbolAndName(
        string memory _symbol,
        string memory _name
        )
        internal
        pure
    {
        bytes memory s = bytes(_symbol);
        require(s.length >= 3 && s.length <= 8, "INVALID_SIZE");
        for (uint i = 0; i < s.length; i++) {
            // make sure symbol contains only [A-Za-z._]
            require(
                s[i] == 0x2E || (
                s[i] == 0x5F) || (
                s[i] >= 0x41 && s[i] <= 0x5A) || (
                s[i] >= 0x61 && s[i] <= 0x7A), "INVALID_VALUE");
        }
        bytes memory n = bytes(_name);
        require(n.length >= s.length && n.length <= 128, "INVALID_SIZE");
        for (uint i = 0; i < n.length; i++) {
            require(n[i] >= 0x20 && n[i] <= 0x7E, "INVALID_VALUE");
        }
    }
}

File 54 of 95 : TransferContract.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "../lib/AddressUtil.sol";
import "../lib/ERC20SafeTransfer.sol";


contract TransferContract {

    using AddressUtil       for address;
    using AddressUtil       for address payable;
    using ERC20SafeTransfer for address;

    uint8 public constant TEST_NOTHING = 0;
    uint8 public constant TEST_REQUIRE_FAIL = 1;
    uint8 public constant TEST_EXPENSIVE_TRANSFER = 2;

    uint public testCase = TEST_NOTHING;

    uint[16] private dummyStorageVariables;

    function safeTransferWithGasLimit(
        address token,
        address to,
        uint    value,
        uint    gasLimit
        )
        external
    {
        token.safeTransferWithGasLimitAndVerify(to, value, gasLimit);
    }

    function safeTransferFromWithGasLimit(
        address token,
        address from,
        address to,
        uint    value,
        uint    gasLimit
        )
        external
    {
        token.safeTransferFromWithGasLimitAndVerify(from, to, value, gasLimit);
    }

    function sendETH(
        address to,
        uint    amount,
        uint    gasLimit
        )
        external
    {
        to.sendETHAndVerify(amount, gasLimit);
    }

    function setTestCase(
        uint8 _testCase
        )
        external
    {
        testCase = _testCase;
    }

    receive()
        external
        payable
    {
        if (testCase == TEST_NOTHING) {
            return;
        } else if (testCase == TEST_REQUIRE_FAIL) {
            revert("ETH_FAILURE");
        } else if (testCase == TEST_EXPENSIVE_TRANSFER) {
            // Some expensive operation
            for (uint i = 0; i < 16; i++) {
                dummyStorageVariables[i] = block.number;
            }
        }
    }
}

File 55 of 95 : PoseidonContract.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;

import "../lib/Poseidon.sol";
import "../core/iface/ExchangeData.sol";


contract PoseidonContract {
    function hash_t5f6p52(
        uint t0,
        uint t1,
        uint t2,
        uint t3,
        uint t4
        )
        external
        pure
        returns (uint)
    {
        Poseidon.HashInputs5 memory inputs = Poseidon.HashInputs5(t0, t1, t2, t3, t4);
        return Poseidon.hash_t5f6p52(inputs, ExchangeData.SNARK_SCALAR_FIELD);
    }

    function hash_t6f6p52(
        uint t0,
        uint t1,
        uint t2,
        uint t3,
        uint t4,
        uint t5
        )
        external
        pure
        returns (uint)
    {
        Poseidon.HashInputs6 memory inputs = Poseidon.HashInputs6(t0, t1, t2, t3, t4, t5);
        return Poseidon.hash_t6f6p52(inputs, ExchangeData.SNARK_SCALAR_FIELD);
    }
}

File 56 of 95 : LPERC20.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import '../lib/ERC20.sol';
import '../lib/MathUint.sol';

contract LPERC20 is ERC20 {
    using MathUint for uint;

    string public constant name = 'Loopring AMM';
    string public constant symbol = 'LLT';
    uint8 public constant decimals = 18;
    uint  public _totalSupply;
    mapping(address => uint) public _balanceOf;
    mapping(address => mapping(address => uint)) public _allowance;

    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function totalSupply() public virtual view override returns (uint) {
        return _totalSupply;
    }

    function balanceOf(address owner) public view override virtual returns (uint balance) {
        return _balanceOf[owner];
    }

    function allowance(address owner, address spender) public view override returns (uint) {
        return _allowance[owner][spender];
    }

    function approve(address spender, uint value) public override returns (bool) {
        _approve(msg.sender, spender, value);
        return true;
    }

    function transfer(address to, uint value) public override returns (bool) {
        _transfer(msg.sender, to, value);
        return true;
    }

    function transferFrom(address from, address to, uint value) public override returns (bool) {
        if (_allowance[from][msg.sender] != uint(-1)) {
            _allowance[from][msg.sender] = _allowance[from][msg.sender].sub(value);
        }
        _transfer(from, to, value);
        return true;
    }

    function _mint(address to, uint value) internal {
        _totalSupply = _totalSupply.add(value);
        _balanceOf[to] = _balanceOf[to].add(value);
        emit Transfer(address(0), to, value);
    }

    function _burn(address from, uint value) internal {
        _balanceOf[from] = _balanceOf[from].sub(value);
        _totalSupply = _totalSupply.sub(value);
        emit Transfer(from, address(0), value);
    }

    function _approve(address owner, address spender, uint value) private {
        _allowance[owner][spender] = value;
        emit Approval(owner, spender, value);
    }

    function _transfer(address from, address to, uint value) private {
        _balanceOf[from] = _balanceOf[from].sub(value);
        _balanceOf[to] = _balanceOf[to].add(value);
        emit Transfer(from, to, value);
    }
}

File 57 of 95 : ZeroDecompressorContract.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;

import "../aux/compression/ZeroDecompressor.sol";

contract ZeroDecompressorContract {
    function decompress(
        bytes calldata data
        )
        external
        pure
        returns (bytes memory)
    {
        return ZeroDecompressor.decompress(data, 0);
    }

    function benchmark(
        bytes calldata data
        )
        external
        pure
        returns (bytes memory)
    {
        return ZeroDecompressor.decompress(data, 0);
    }
}

File 58 of 95 : ZeroDecompressor.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;


/// @title ZeroDecompressor
/// @author Brecht Devos - <[email protected]>
/// @dev Easy decompressor that compresses runs of zeros.
/// The format is very simple. Each entry consists of
/// (uint16 numDataBytes, uint16 numZeroBytes) which will
/// copy `numDataBytes` data bytes from `data` and will
/// add an additional `numZeroBytes` after it.
library ZeroDecompressor
{
    function decompress(
        bytes calldata /*data*/,
        uint  parameterIdx
        )
        internal
        pure
        returns (bytes memory)
    {
        bytes memory uncompressed;
        uint offsetPos = 4 + 32 * parameterIdx;
        assembly {
            uncompressed := mload(0x40)
            let ptr := add(uncompressed, 32)
            let offset := add(4, calldataload(offsetPos))
            let pos := add(offset, 4)
            let dataLength := add(calldataload(offset), pos)
            let tupple := 0
            let numDataBytes := 0
            let numZeroBytes := 0

            for {} lt(pos, dataLength) {} {
                tupple := and(calldataload(pos), 0xFFFFFFFF)
                numDataBytes := shr(16, tupple)
                numZeroBytes := and(tupple, 0xFFFF)
                calldatacopy(ptr, add(32, pos), numDataBytes)
                pos := add(pos, add(4, numDataBytes))
                ptr := add(ptr, add(numDataBytes, numZeroBytes))
            }

            // Store data length
            mstore(uncompressed, sub(sub(ptr, uncompressed), 32))

            // Update free memory pointer
            mstore(0x40, add(ptr, 0x20))
        }
        return uncompressed;
    }
}

File 59 of 95 : TestAccountContract.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "../core/iface/IExchangeV3.sol";

import "../lib/AddressUtil.sol";
import "../lib/MathUint.sol";


contract TestAccountContract {

    using AddressUtil       for address payable;
    using MathUint          for uint;

    IExchangeV3 exchange;

    uint[16] private dummyStorageVariables;

    modifier refund()
    {
        // Send surplus to msg.sender
        uint balanceBefore = address(this).balance.sub(msg.value);
        _;
        uint balanceAfter = address(this).balance;
        msg.sender.sendETHAndVerify(balanceAfter.sub(balanceBefore), gasleft());
    }

    constructor(
        address _exchangeAddress
        )
    {
        exchange = IExchangeV3(_exchangeAddress);
    }

    function withdraw(
        address token,
        uint96 amount,
        uint32 accountID
        )
        external
        payable
        refund
    {
        //exchange.withdraw{value: msg.value}(address(this), token, amount, accountID);
    }

    receive()
        external
        payable
    {
        // Some expensive operation
        for (uint i = 0; i < 16; i++) {
            dummyStorageVariables[i] = block.number;
        }
    }
}

File 60 of 95 : INDA.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "../DummyToken.sol";

contract INDA is DummyToken {

    constructor() DummyToken(
        "INDIVISIBLE_A",
        "INDA",
        0,
        10 ** 27
    )
    {
    }

}

File 61 of 95 : INDB.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "../DummyToken.sol";

contract INDB is DummyToken {

    constructor() DummyToken(
        "INDIVISIBLE_B",
        "INDB",
        0,
        10 ** 27
    )
    {
    }

}

File 62 of 95 : RDN.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "../DummyToken.sol";

contract RDN is DummyToken {

    constructor() DummyToken(
        "RDN_TEST",
        "RDN",
        18,
        10 ** 27
    )
    {
    }

}

File 63 of 95 : LRC.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "../DummyToken.sol";

contract LRC is DummyToken {

    constructor() DummyToken(
        "LRC_TEST",
        "LRC",
        18,
        10 ** 27
    )
    {
    }

}

File 64 of 95 : GTO.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "../DummyToken.sol";

contract GTO is DummyToken {

    constructor() DummyToken(
        "GTO_TEST",
        "GTO",
        18,
        10 ** 27
    )
    {
    }

}

File 65 of 95 : TEST.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "../DummyToken.sol";
import "../../core/iface/IExchangeV3.sol";

/// @author Brecht Devos - <[email protected]>
contract TEST is DummyToken {
    using SafeMath for uint;

    // Test cases
    uint8 public constant TEST_NOTHING = 0;
    uint8 public constant TEST_REENTRANCY = 1;
    uint8 public constant TEST_REQUIRE_FAIL = 2;
    uint8 public constant TEST_RETURN_FALSE = 3;
    uint8 public constant TEST_NO_RETURN_VALUE = 4;
    uint8 public constant TEST_INVALID_RETURN_SIZE = 5;
    uint8 public constant TEST_EXPENSIVE_TRANSFER = 6;
    uint8 public constant TEST_DIFFERENT_TRANSFER_AMOUNT = 7;

    uint public testCase = TEST_NOTHING;

    address public exchangeAddress = address(0);

    bytes public reentrancyCalldata;

    uint[16] private dummyStorageVariables;

    constructor() DummyToken(
        "TEST_TEST",
        "TEST",
        18,
        2 ** 128
    )
    {
    }

    function transfer(
        address _to,
        uint _value
        )
        public
        override
        returns (bool)
    {
        if (testCase == TEST_DIFFERENT_TRANSFER_AMOUNT) {
            _value = _value.mul(99) / 100;
        }
        // require(_to != address(0), "ZERO_ADDRESS");
        require(_value <= balances[msg.sender], "INVALID_VALUE");
        // SafeMath.sub will throw if there is not enough balance.
        balances[msg.sender] = balances[msg.sender].sub(_value);
        balances[_to] = balances[_to].add(_value);
        emit Transfer(msg.sender, _to, _value);
        return doTestCase();
    }

    function transferFrom(
        address _from,
        address _to,
        uint _value
        )
        public
        override
        returns (bool)
    {
        if (testCase == TEST_DIFFERENT_TRANSFER_AMOUNT) {
            _value = _value.mul(99) / 100;
        }
        // require(_to != address(0), "ZERO_ADDRESS");
        require(_value <= balances[_from], "INVALID_VALUE");
        require(_value <= allowed[_from][msg.sender], "INVALID_VALUE");
        balances[_from] = balances[_from].sub(_value);
        balances[_to] = balances[_to].add(_value);
        allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
        emit Transfer(_from, _to, _value);
        return doTestCase();
    }

    function doTestCase()
        internal
        returns (bool)
    {
        if (testCase == TEST_NOTHING) {
            return true;
        } else if (testCase == TEST_REENTRANCY) {
            // Call the exchange function without ever throwing
            (bool success, ) = exchangeAddress.call(reentrancyCalldata);
            success; // to disable unused local variable warning

            // Copy the 100 bytes containing the revert message
            bytes memory returnData = new bytes(100);
            assembly {
                if eq(returndatasize(), 100) {
                    returndatacopy(add(returnData, 32), 0, 100)
                }
            }

            // Revert reason should match REENTRANCY
            bytes memory reentryMessageData = abi.encodeWithSelector(
                bytes4(keccak256("Error(string)")),
                "REENTRANCY"
            );

            // Throw here when the results are as expected. This way we know the test was correctly executed.
            require(keccak256(reentryMessageData) != keccak256(returnData), "REVERT_MESSAGE_OK");
            return true;
        } else if (testCase == TEST_REQUIRE_FAIL) {
            require(false, "REQUIRE_FAILED");
            return true;
        } else if (testCase == TEST_RETURN_FALSE) {
            return false;
        } else if (testCase == TEST_NO_RETURN_VALUE) {
            assembly {
                return(0, 0)
            }
        } else if (testCase == TEST_INVALID_RETURN_SIZE) {
            assembly {
                return(0, 64)
            }
        } else if (testCase == TEST_EXPENSIVE_TRANSFER) {
            // Some expensive operation
            for (uint i = 0; i < 16; i++) {
                dummyStorageVariables[i] = block.number;
            }
        }
        return true;
    }

    function setTestCase(
        uint8 _testCase
        )
        external
    {
        testCase = _testCase;
    }

    function setExchangeAddress(
        address _exchangeAddress
        )
        external
    {
        exchangeAddress = _exchangeAddress;
    }

    function setCalldata(
        bytes calldata _reentrancyCalldata
        )
        external
    {
        reentrancyCalldata = _reentrancyCalldata;
    }
}

File 66 of 95 : WETH.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "../DummyToken.sol";

contract WETH is DummyToken {

    constructor() DummyToken(
        "WETH_TEST",
        "WETH",
        18,
        10 ** 27
    )
    {
    }

}

File 67 of 95 : REP.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "../DummyToken.sol";

contract REP is DummyToken {

    constructor() DummyToken(
        "REP_TEST",
        "REP",
        18,
        10 ** 27
    )
    {
    }

}

File 68 of 95 : Migrations.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

contract Migrations
{
    address public owner;
    uint public last_completed_migration;

    modifier restricted()
    {
        if (msg.sender == owner) {
            _;
        }
    }

    constructor()
    {
        owner = msg.sender;
    }

    function setCompleted(uint completed)
        public
        restricted
    {
        last_completed_migration = completed;
    }

    function upgrade(address newAddress)
        public
        restricted
    {
        Migrations upgraded = Migrations(newAddress);
        upgraded.setCompleted(last_completed_migration);
    }
}

File 69 of 95 : AddressSet.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;


/// @title AddressSet
/// @author Daniel Wang - <[email protected]>
contract AddressSet
{
    struct Set
    {
        address[] addresses;
        mapping (address => uint) positions;
        uint count;
    }
    mapping (bytes32 => Set) private sets;

    function addAddressToSet(
        bytes32 key,
        address addr,
        bool maintainList
        ) internal
    {
        Set storage set = sets[key];
        require(set.positions[addr] == 0, "ALREADY_IN_SET");

        if (maintainList) {
            require(set.addresses.length == set.count, "PREVIOUSLY_NOT_MAINTAILED");
            set.addresses.push(addr);
        } else {
            require(set.addresses.length == 0, "MUST_MAINTAIN");
        }

        set.count += 1;
        set.positions[addr] = set.count;
    }

    function removeAddressFromSet(
        bytes32 key,
        address addr
        )
        internal
    {
        Set storage set = sets[key];
        uint pos = set.positions[addr];
        require(pos != 0, "NOT_IN_SET");

        delete set.positions[addr];
        set.count -= 1;

        if (set.addresses.length > 0) {
            address lastAddr = set.addresses[set.count];
            if (lastAddr != addr) {
                set.addresses[pos - 1] = lastAddr;
                set.positions[lastAddr] = pos;
            }
            set.addresses.pop();
        }
    }

    function removeSet(bytes32 key)
        internal
    {
        delete sets[key];
    }

    function isAddressInSet(
        bytes32 key,
        address addr
        )
        internal
        view
        returns (bool)
    {
        return sets[key].positions[addr] != 0;
    }

    function numAddressesInSet(bytes32 key)
        internal
        view
        returns (uint)
    {
        Set storage set = sets[key];
        return set.count;
    }

    function addressesInSet(bytes32 key)
        internal
        view
        returns (address[] memory)
    {
        Set storage set = sets[key];
        require(set.count == set.addresses.length, "NOT_MAINTAINED");
        return sets[key].addresses;
    }
}

File 70 of 95 : OwnerManagable.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "./AddressSet.sol";
import "./Claimable.sol";


contract OwnerManagable is Claimable, AddressSet
{
    bytes32 internal constant MANAGER = keccak256("__MANAGED__");

    event ManagerAdded  (address indexed manager);
    event ManagerRemoved(address indexed manager);

    modifier onlyManager
    {
        require(isManager(msg.sender), "NOT_MANAGER");
        _;
    }

    modifier onlyOwnerOrManager
    {
        require(msg.sender == owner || isManager(msg.sender), "NOT_OWNER_OR_MANAGER");
        _;
    }

    constructor() Claimable() {}

    /// @dev Gets the managers.
    /// @return The list of managers.
    function managers()
        public
        view
        returns (address[] memory)
    {
        return addressesInSet(MANAGER);
    }

    /// @dev Gets the number of managers.
    /// @return The numer of managers.
    function numManagers()
        public
        view
        returns (uint)
    {
        return numAddressesInSet(MANAGER);
    }

    /// @dev Checks if an address is a manger.
    /// @param addr The address to check.
    /// @return True if the address is a manager, False otherwise.
    function isManager(address addr)
        public
        view
        returns (bool)
    {
        return isAddressInSet(MANAGER, addr);
    }

    /// @dev Adds a new manager.
    /// @param manager The new address to add.
    function addManager(address manager)
        public
        onlyOwner
    {
        addManagerInternal(manager);
    }

    /// @dev Removes a manager.
    /// @param manager The manager to remove.
    function removeManager(address manager)
        public
        onlyOwner
    {
        removeAddressFromSet(MANAGER, manager);
        emit ManagerRemoved(manager);
    }

    function addManagerInternal(address manager)
        internal
    {
        addAddressToSet(MANAGER, manager, true);
        emit ManagerAdded(manager);
    }
}

File 71 of 95 : ERC20Token.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "./ERC20.sol";
import "./MathUint.sol";


/// @title ERC20 Token Implementation
/// @dev see https://github.com/ethereum/EIPs/issues/20
/// @author Daniel Wang - <[email protected]>
contract ERC20Token is ERC20
{
    using MathUint for uint;

    string  public name;
    string  public symbol;
    uint8   public decimals;
    uint    public totalSupply_;

    mapping (address => uint) balances;
    mapping (address => mapping (address => uint)) internal allowed;

    event Transfer(
        address indexed from,
        address indexed to,
        uint            value
    );

    event Approval(
        address indexed owner,
        address indexed spender,
        uint            value
    );

    constructor(
        string memory _name,
        string memory _symbol,
        uint8         _decimals,
        uint          _totalSupply,
        address       _firstHolder
        )
    {
        require(_totalSupply > 0, "INVALID_VALUE");
        require(_firstHolder != address(0), "ZERO_ADDRESS");
        checkSymbolAndName(_symbol,_name);

        name = _name;
        symbol = _symbol;
        decimals = _decimals;
        totalSupply_ = _totalSupply;

        balances[_firstHolder] = totalSupply_;
    }

    /**
    * @dev total number of tokens in existence
    */
    function totalSupply()
        public
        override
        view
        returns (uint)
    {
        return totalSupply_;
    }

    /**
    * @dev transfer token for a specified address
    * @param _to The address to transfer to.
    * @param _value The amount to be transferred.
    */
    function transfer(
        address _to,
        uint    _value
        )
        public
        override
        returns (bool)
    {
        require(_to != address(0), "ZERO_ADDRESS");
        require(_value <= balances[msg.sender], "INVALID_VALUE");

        // SafeMath.sub will throw if there is not enough balance.
        balances[msg.sender] = balances[msg.sender].sub(_value);
        balances[_to] = balances[_to].add(_value);
        emit Transfer(msg.sender, _to, _value);
        return true;
    }

    /**
    * @dev Gets the balance of the specified address.
    * @param _owner The address to query the the balance of.
    * @return balance An uint representing the amount owned by the passed address.
    */
    function balanceOf(
        address _owner
        )
        public
        override
        view
        returns (uint balance)
    {
        return balances[_owner];
    }

    /**
     * @dev Transfer tokens from one address to another
     * @param _from address The address which you want to send tokens from
     * @param _to address The address which you want to transfer to
     * @param _value uint the amount of tokens to be transferred
     */
    function transferFrom(
        address _from,
        address _to,
        uint    _value
        )
        public
        override
        returns (bool)
    {
        require(_to != address(0), "ZERO_ADDRESS");
        require(_value <= balances[_from], "INVALID_VALUE");
        require(_value <= allowed[_from][msg.sender], "INVALID_VALUE");

        balances[_from] = balances[_from].sub(_value);
        balances[_to] = balances[_to].add(_value);
        allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
        emit Transfer(_from, _to, _value);
        return true;
    }

    /**
     * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
     *
     * 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
     * @param _spender The address which will spend the funds.
     * @param _value The amount of tokens to be spent.
     */
    function approve(
        address _spender,
        uint    _value
        )
        public
        override
        returns (bool)
    {
        allowed[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }

    /**
     * @dev Function to check the amount of tokens that an owner allowed to a spender.
     * @param _owner address The address which owns the funds.
     * @param _spender address The address which will spend the funds.
     * @return A uint specifying the amount of tokens still available for the spender.
     */
    function allowance(
        address _owner,
        address _spender
        )
        public
        override
        view
        returns (uint)
    {
        return allowed[_owner][_spender];
    }

    /**
     * @dev Increase the amount of tokens that an owner allowed to a spender.
     *
     * approve should be called when allowed[_spender] == 0. To increment
     * allowed value is better to use this function to avoid 2 calls (and wait until
     * the first transaction is mined)
     * From MonolithDAO Token.sol
     * @param _spender The address which will spend the funds.
     * @param _addedValue The amount of tokens to increase the allowance by.
     */
    function increaseApproval(
        address _spender,
        uint    _addedValue
        )
        public
        returns (bool)
    {
        allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
        emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
        return true;
    }

    /**
     * @dev Decrease the amount of tokens that an owner allowed to a spender.
     *
     * approve should be called when allowed[_spender] == 0. To decrement
     * allowed value is better to use this function to avoid 2 calls (and wait until
     * the first transaction is mined)
     * From MonolithDAO Token.sol
     * @param _spender The address which will spend the funds.
     * @param _subtractedValue The amount of tokens to decrease the allowance by.
     */
    function decreaseApproval(
        address _spender,
        uint    _subtractedValue
        )
        public
        returns (bool)
    {
        uint oldValue = allowed[msg.sender][_spender];
        if (_subtractedValue > oldValue) {
            allowed[msg.sender][_spender] = 0;
        } else {
            allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
        }
        emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
        return true;
    }

    // Make sure symbol has 3-8 chars in [A-Za-z._] and name has up to 128 chars.
    function checkSymbolAndName(
        string memory _symbol,
        string memory _name
        )
        internal
        pure
    {
        bytes memory s = bytes(_symbol);
        require(s.length >= 3 && s.length <= 8, "INVALID_SIZE");
        for (uint i = 0; i < s.length; i++) {
            // make sure symbol contains only [A-Za-z._]
            require(
                s[i] == 0x2E || (
                s[i] == 0x5F) || (
                s[i] >= 0x41 && s[i] <= 0x5A) || (
                s[i] >= 0x61 && s[i] <= 0x7A), "INVALID_VALUE");
        }
        bytes memory n = bytes(_name);
        require(n.length >= s.length && n.length <= 128, "INVALID_SIZE");
        for (uint i = 0; i < n.length; i++) {
            require(n[i] >= 0x20 && n[i] <= 0x7E, "INVALID_VALUE");
        }
    }
}

File 72 of 95 : SimpleProxy.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "../thirdparty/proxies/Proxy.sol";


/// @title SimpleProxy
/// @author Daniel Wang  - <[email protected]>
contract SimpleProxy is Proxy
{
    bytes32 private constant implementationPosition = keccak256(
        "org.loopring.protocol.simple.proxy"
    );

    constructor(address _implementation) {
        if (_implementation != address(0)) {
            setImplementation(_implementation);
        }
    }

    function setImplementation(address _implementation)
        public
    {
        address _impl = implementation();
        require(_impl == address(0), "INITIALIZED_ALREADY");

        bytes32 position = implementationPosition;
        assembly {sstore(position, _implementation) }
    }

    function implementation()
        public
        override
        view
        returns (address)
    {
        address impl;
        bytes32 position = implementationPosition;
        assembly { impl := sload(position) }
        return impl;
    }
}

File 73 of 95 : ERC2612.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "./ERC20.sol";


/// @title ERC2612 Token with permit – 712-signed approvals but with
///        bytes as signature
/// @dev see https://eips.ethereum.org/EIPS/eip-2612
/// @author Daniel Wang - <[email protected]>
abstract contract ERC2612 is ERC20
{
    function nonces(address owner)
        public
        view
        virtual
        returns (uint);

    function permit(
        address        owner,
        address        spender,
        uint256        value,
        uint256        deadline,
        bytes calldata signature
        )
        external
        virtual;
}

File 74 of 95 : BurnableERC20.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "./ERC20.sol";


/// @title Burnable ERC20 Token Interface
/// @author Brecht Devos - <[email protected]>
abstract contract BurnableERC20 is ERC20
{
    function burn(
        uint value
        )
        public
        virtual
        returns (bool);

    function burnFrom(
        address from,
        uint value
        )
        public
        virtual
        returns (bool);
}

File 75 of 95 : MathUint96.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;


/// @title Utility Functions for uint
/// @author Daniel Wang - <[email protected]>
library MathUint96
{
    function add(
        uint96 a,
        uint96 b
        )
        internal
        pure
        returns (uint96 c)
    {
        c = a + b;
        require(c >= a, "ADD_OVERFLOW");
    }

    function sub(
        uint96 a,
        uint96 b
        )
        internal
        pure
        returns (uint96 c)
    {
        require(b <= a, "SUB_UNDERFLOW");
        return a - b;
    }
}

File 76 of 95 : Create2.sol
// SPDX-License-Identifier: UNLICENSED
// Taken from: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/970f687f04d20e01138a3e8ccf9278b1d4b3997b/contracts/utils/Create2.sol

pragma solidity ^0.7.0;

/**
 * @dev Helper to make usage of the `CREATE2` EVM opcode easier and safer.
 * `CREATE2` can be used to compute in advance the address where a smart
 * contract will be deployed, which allows for interesting new mechanisms known
 * as 'counterfactual interactions'.
 *
 * See the https://eips.ethereum.org/EIPS/eip-1014#motivation[EIP] for more
 * information.
 */
library Create2 {
    /**
     * @dev Deploys a contract using `CREATE2`. The address where the contract
     * will be deployed can be known in advance via {computeAddress}. Note that
     * a contract cannot be deployed twice using the same salt.
     */
    function deploy(bytes32 salt, bytes memory bytecode) internal returns (address payable) {
        address payable addr;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            addr := create2(0, add(bytecode, 0x20), mload(bytecode), salt)
        }
        require(addr != address(0), "CREATE2_FAILED");
        return addr;
    }

    /**
     * @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the `bytecode`
     * or `salt` will result in a new destination address.
     */
    function computeAddress(bytes32 salt, bytes memory bytecode) internal view returns (address) {
        return computeAddress(salt, bytecode, address(this));
    }

    /**
     * @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at
     * `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.
     */
    function computeAddress(bytes32 salt, bytes memory bytecodeHash, address deployer) internal pure returns (address) {
        bytes32 bytecodeHashHash = keccak256(bytecodeHash);
        bytes32 _data = keccak256(
            abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHashHash)
        );
        return address(bytes20(_data << 96));
    }
}

File 77 of 95 : Drainable.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "./AddressUtil.sol";
import "./ERC20.sol";
import "./ERC20SafeTransfer.sol";


/// @title Drainable
/// @author Brecht Devos - <[email protected]>
/// @dev Standard functionality to allow draining funds from a contract.
abstract contract Drainable
{
    using AddressUtil       for address;
    using ERC20SafeTransfer for address;

    event Drained(
        address to,
        address token,
        uint    amount
    );

    function drain(
        address to,
        address token
        )
        public
        returns (uint amount)
    {
        require(canDrain(msg.sender, token), "UNAUTHORIZED");

        if (token == address(0)) {
            amount = address(this).balance;
            to.sendETHAndVerify(amount, gasleft());   // ETH
        } else {
            amount = ERC20(token).balanceOf(address(this));
            token.safeTransferAndVerify(to, amount);  // ERC20 token
        }

        emit Drained(to, token, amount);
    }

    // Needs to return if the address is authorized to call drain.
    function canDrain(address drainer, address token)
        public
        virtual
        view
        returns (bool);
}

File 78 of 95 : LoopringIOExchangeOwner.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../aux/compression/ZeroDecompressor.sol";
import "../../core/iface/IExchangeV3.sol";
import "../../thirdparty/BytesUtil.sol";
import "../../lib/AddressUtil.sol";
import "../../lib/Drainable.sol";
import "../../lib/ERC1271.sol";
import "../../lib/MathUint.sol";
import "../../lib/SignatureUtil.sol";
import "./SelectorBasedAccessManager.sol";
import "./IBlockReceiver.sol";


contract LoopringIOExchangeOwner is SelectorBasedAccessManager, ERC1271, Drainable
{
    using AddressUtil       for address;
    using AddressUtil       for address payable;
    using BytesUtil         for bytes;
    using MathUint          for uint;
    using SignatureUtil     for bytes32;

    bytes4    private constant SUBMITBLOCKS_SELECTOR = IExchangeV3.submitBlocks.selector;
    bool      public  open;

    event SubmitBlocksAccessOpened(bool open);

    struct TxCallback
    {
        uint16 txIdx;
        uint16 numTxs;
        uint16 receiverIdx;
        bytes  data;
    }

    struct BlockCallback
    {
        uint16        blockIdx;
        TxCallback[]  txCallbacks;
    }

    struct CallbackConfig
    {
        BlockCallback[] blockCallbacks;
        address[]       receivers;
    }

    constructor(
        address _exchange
        )
        SelectorBasedAccessManager(_exchange)
    {
    }

    function openAccessToSubmitBlocks(bool _open)
        external
        onlyOwner
    {
        open = _open;
        emit SubmitBlocksAccessOpened(_open);
    }

    function isValidSignature(
        bytes32        signHash,
        bytes   memory signature
        )
        external
        view
        override
        returns (bytes4)
    {
        // Role system used a bit differently here.
        return hasAccessTo(
            signHash.recoverECDSASigner(signature),
            this.isValidSignature.selector
        ) ? ERC1271_MAGICVALUE : bytes4(0);
    }

    function canDrain(address drainer, address /* token */)
        public
        override
        view
        returns (bool)
    {
        return hasAccessTo(drainer, this.drain.selector);
    }

    function submitBlocks(
        bool                     isDataCompressed,
        bytes           calldata data
        )
        external
    {
        require(
            hasAccessTo(msg.sender, SUBMITBLOCKS_SELECTOR) || open,
            "PERMISSION_DENIED"
        );
        bytes memory decompressed = isDataCompressed ?
            ZeroDecompressor.decompress(data, 1):
            data;

        require(
            decompressed.toBytes4(0) == SUBMITBLOCKS_SELECTOR,
            "INVALID_DATA"
        );

        target.fastCallAndVerify(gasleft(), 0, decompressed);
    }
}

File 79 of 95 : SelectorBasedAccessManager.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;

import "../../core/iface/IExchangeV3.sol";
import "../../lib/Claimable.sol";
import "../../thirdparty/BytesUtil.sol";


/// @title  SelectorBasedAccessManager
/// @author Daniel Wang - <[email protected]>
contract SelectorBasedAccessManager is Claimable
{
    using BytesUtil for bytes;

    event PermissionUpdate(
        address indexed user,
        bytes4  indexed selector,
        bool            allowed
    );

    event TargetCalled(
        address target,
        bytes data
    );

    address public immutable target;
    mapping(address => mapping(bytes4 => bool)) public permissions;

    modifier withAccess(bytes4 selector)
    {
        require(hasAccessTo(msg.sender, selector), "PERMISSION_DENIED");
        _;
    }

    constructor(address _target)
    {
        require(_target != address(0), "ZERO_ADDRESS");
        target = _target;
    }

    function grantAccess(
        address user,
        bytes4  selector,
        bool    granted
        )
        external
        onlyOwner
    {
        require(permissions[user][selector] != granted, "INVALID_VALUE");
        permissions[user][selector] = granted;
        emit PermissionUpdate(user, selector, granted);
    }

    receive() payable external {}

    fallback()
        payable
        external
    {
        transact(msg.data);
    }

    function transact(bytes memory data)
        payable
        public
        withAccess(data.toBytes4(0))
    {
        (bool success, bytes memory returnData) = target
            .call{value: msg.value}(data);

        if (!success) {
            assembly { revert(add(returnData, 32), mload(returnData)) }
        }

        emit TargetCalled(target, data);
    }

    function hasAccessTo(address user, bytes4 selector)
        public
        view
        returns (bool)
    {
        return user == owner || permissions[user][selector];
    }
}

File 80 of 95 : IBlockReceiver.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../core/iface/ExchangeData.sol";

/// @title IBlockReceiver
/// @author Brecht Devos - <[email protected]>
abstract contract IBlockReceiver
{
    function beforeBlockSubmission(
        bytes              calldata txsData,
        bytes              calldata callbackData
        )
        external
        virtual;
}

File 81 of 95 : ITokenSeller.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;


/// @title ITokenSeller
/// @dev Use this contract to sell tokenS for as many tokenB.
/// @author Daniel Wang  - <[email protected]>
interface ITokenSeller
{
    /// @dev Sells all tokenS for tokenB
    /// @param tokenS The token or Ether (0x0) to sell.
    /// @param tokenB The token to buy.
    /// @return success True if success, false otherwise.
    function sellToken(
        address tokenS,
        address tokenB
        )
        external
        payable
        returns (bool success);
}

File 82 of 95 : AgentRegistry.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../core/iface/IAgentRegistry.sol";
import "../../lib/AddressSet.sol";
import "../../lib/Claimable.sol";


contract AgentRegistry is IAgentRegistry, AddressSet, Claimable
{
    bytes32 internal constant UNIVERSAL_AGENTS = keccak256("__UNVERSAL_AGENTS__");

    event AgentRegistered(
        address indexed user,
        address indexed agent,
        bool            registered
    );

    event TrustUniversalAgents(
        address indexed user,
        bool            trust
    );

    constructor() Claimable() {}

    function isAgent(
        address user,
        address agent
        )
        external
        override
        view
        returns (bool)
    {
        return isUniversalAgent(agent) || isUserAgent(user, agent);
    }

    function isAgent(
        address[] calldata users,
        address            agent
        )
        external
        override
        view
        returns (bool)
    {
        if (isUniversalAgent(agent)) {
            return true;
        }
        for (uint i = 0; i < users.length; i++) {
            if (!isUserAgent(users[i], agent)) {
                return false;
            }
        }
        return true;
    }

    function registerUniversalAgent(
        address agent,
        bool    toRegister
        )
        external
        onlyOwner
    {
        registerInternal(UNIVERSAL_AGENTS, agent, toRegister);
        emit AgentRegistered(address(0), agent, toRegister);
    }

    function isUniversalAgent(address agent)
        public
        override
        view
        returns (bool)
    {
        return isAddressInSet(UNIVERSAL_AGENTS, agent);
    }

    function registerUserAgent(
        address agent,
        bool    toRegister
        )
        external
    {
        registerInternal(userKey(msg.sender), agent, toRegister);
        emit AgentRegistered(msg.sender, agent, toRegister);
    }

    function isUserAgent(
        address user,
        address agent
        )
        public
        view
        returns (bool)
    {
        return isAddressInSet(userKey(user), agent);
    }

    function registerInternal(
        bytes32 key,
        address agent,
        bool    toRegister
        )
        private
    {
        require(agent != address(0), "ZERO_ADDRESS");
        if (toRegister) {
            addAddressToSet(key, agent, false /* maintanList */);
        } else {
            removeAddressFromSet(key, agent);
        }
    }

    function userKey(address addr)
        private
        pure
        returns (bytes32)
    {
        return keccak256(abi.encodePacked("__AGENT__", addr));
    }
}

File 83 of 95 : ForcedWithdrawalAgent.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../core/iface/IExchangeV3.sol";
import "../../lib/ReentrancyGuard.sol";
import "../../lib/OwnerManagable.sol";
import "../../lib/AddressUtil.sol";
import "../../lib/Drainable.sol";

/// @author Kongliang Zhong - <[email protected]>
contract ForcedWithdrawalAgent is ReentrancyGuard, OwnerManagable, Drainable
{
    using AddressUtil for address;

    function canDrain(address /*drainer*/, address /*token*/)
        public
        override
        view
        returns (bool) {
        return msg.sender == owner || isManager(msg.sender);
    }

    function doForcedWithdrawalFor(
        address exchangeAddress,
        address from,
        address token,
        uint32 accountID
        )
        external
        payable
        nonReentrant
        onlyOwnerOrManager
    {
        IExchangeV3(exchangeAddress).forceWithdraw{value: msg.value}(from, token, accountID);

        if (address(this).balance > 0) {
            drain(msg.sender, address(0));
        }
    }

    receive() external payable { }
}

File 84 of 95 : FastWithdrawalAgent.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../../core/iface/IAgentRegistry.sol";
import "../../core/iface/IExchangeV3.sol";
import "../../lib/Claimable.sol";
import "../../lib/EIP712.sol";
import "../../lib/ERC20SafeTransfer.sol";
import "../../lib/MathUint.sol";
import "../../lib/ReentrancyGuard.sol";
import "../../lib/SignatureUtil.sol";

/// @title Fast withdrawal agent implementation. With the help of liquidity providers (LPs),
///        exchange operators can convert any normal withdrawals into fast withdrawals.
///
///        Fast withdrawals are a way for the owner to provide instant withdrawals for
///        users with the help of a liquidity provider and conditional transfers.
///
///        A fast withdrawal requires the non-trustless cooperation of 2 parties:
///        - A liquidity provider which provides funds to users immediately onchain
///        - The operator which will make sure the user has sufficient funds offchain
///          so that the liquidity provider can be paid back.
///          The operator also needs to process those withdrawals so that the
///          liquidity provider receives its funds back.
///
///        We require the fast withdrawals to be executed by the liquidity provider (as msg.sender)
///        so that the liquidity provider can impose its own rules on how its funds are spent. This will
///        inevitably need to be done in close cooperation with the operator, or by the operator
///        itself using a smart contract where the liquidity provider enforces who, how
///        and even if their funds can be used to facilitate the fast withdrawals.
///
///        The liquidity provider can call `executeFastWithdrawals` to provide users
///        immediately with funds onchain. This allows the security of the funds to be handled
///        by any EOA or smart contract.
///
///        Users that want to make use of this functionality have to
///        authorize this contract as their agent.
///
/// @author Brecht Devos - <[email protected]>
/// @author Kongliang Zhong - <[email protected]>
/// @author Daniel Wang - <[email protected]>
contract FastWithdrawalAgent is ReentrancyGuard, IAgent
{
    using AddressUtil       for address;
    using AddressUtil       for address payable;
    using ERC20SafeTransfer for address;
    using MathUint          for uint;

    event Processed(
        address exchange,
        address from,
        address to,
        address token,
        uint248  amount,
        address provider,
        bool    success
    );

    struct Withdrawal
    {
        address exchange;
        address from;                   // The owner of the account
        address to;                     // The `to` address of the withdrawal
        address token;
        uint248  amount;
        uint32  storageID;
    }

    // This method needs to be called by any liquidity provider
    function executeFastWithdrawals(Withdrawal[] calldata withdrawals)
        external
        nonReentrant
        payable
    {
        // Do all fast withdrawals
        for (uint i = 0; i < withdrawals.length; i++) {
            executeInternal(withdrawals[i]);
        }
        // Return any ETH left into this contract
        // (can happen when more ETH is sent than needed for the fast withdrawals)
        msg.sender.sendETHAndVerify(address(this).balance, gasleft());
    }

    // -- Internal --

    function executeInternal(Withdrawal calldata withdrawal)
        internal
    {
        require(
            withdrawal.exchange != address(0) &&
            withdrawal.from != address(0) &&
            withdrawal.to != address(0) &&
            withdrawal.amount != 0,
            "INVALID_WITHDRAWAL"
        );

        // The liquidity provider always authorizes the fast withdrawal by being the direct caller
        address payable liquidityProvider = msg.sender;

        bool success;
        // Override the destination address of a withdrawal to the address of the liquidity provider
        try IExchangeV3(withdrawal.exchange).setWithdrawalRecipient(
            withdrawal.from,
            withdrawal.to,
            withdrawal.token,
            withdrawal.amount,
            withdrawal.storageID,
            liquidityProvider
        ) {
            // Transfer the tokens immediately to the requested address
            // using funds from the liquidity provider (`msg.sender`).
            transfer(
                liquidityProvider,
                withdrawal.to,
                withdrawal.token,
                withdrawal.amount
            );
            success = true;
        } catch {
            success = false;
        }

        emit Processed(
            withdrawal.exchange,
            withdrawal.from,
            withdrawal.to,
            withdrawal.token,
            withdrawal.amount,
            liquidityProvider,
            success
        );
    }

    function transfer(
        address from,
        address to,
        address token,
        uint    amount
        )
        internal
    {
        if (amount > 0) {
            if (token == address(0)) {
                to.sendETHAndVerify(amount, gasleft()); // ETH
            } else {
                token.safeTransferFromAndVerify(from, to, amount);  // ERC20 token
            }
        }
    }
}

File 85 of 95 : IProtocolFeeVault.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;


/// @title IProtocolFeeVault
/// @dev This smart contract manages the distribution of protocol fees.
///     Tokens other than LRC will be sold by TokenSeller,
///     If no TokenSeller is set, the tokens or Ether will be sent to the owner
///     to sell them for LRC by other means such as using a centralized exchange.
///     For LRC token, 70% of them can be withdrawn to the UserStakingPool contract
///     to reward LRC stakers; 20% of them can be withdrawn to the Loopring DAO,
///     and the remaining 10% can be burned to reduce LRC's total supply.
abstract contract IProtocolFeeVault
{
    uint public constant REWARD_PERCENTAGE      = 70;
    uint public constant DAO_PERDENTAGE         = 20;

    address public userStakingPoolAddress;
    address public tokenSellerAddress;
    address public daoAddress;

    uint claimedReward;
    uint claimedDAOFund;
    uint claimedBurn;

    event LRCClaimed(uint amount);
    event DAOFunded(uint amountDAO, uint amountBurn);
    event TokenSold(address token, uint amount);
    event SettingsUpdated(uint time);

    /// @dev Returns the LRC token address
    /// @return the LRC token address
    function lrcAddress()
        external
        view
        virtual
        returns (address);

    /// @dev Sets depending contract addresses. All these addresses can be zero.
    /// @param _userStakingPoolAddress The address of the user staking pool.
    /// @param _tokenSellerAddress The address of the token seller.
    /// @param _daoAddress The address of the DAO contract.
    function updateSettings(
        address _userStakingPoolAddress,
        address _tokenSellerAddress,
        address _daoAddress
        )
        external
        virtual;

    /// @dev Claims LRC as staking reward to the IUserStakingPool contract.
    ///      Note that this function can only be called by
    ///      the IUserStakingPool contract.
    ///
    /// @param amount The amount of LRC to be claimed.
    function claimStakingReward(uint amount)
        external
        virtual;

    /// @dev Withdraws LRC to DAO and in the meanwhile burn some LRC according to
    ///      the predefined percentages.
    function fundDAO()
        external
        virtual;

    /// @dev Sells a non-LRC token or Ether to LRC. If no TokenSeller is set,
    ///      the tokens or Ether will be sent to the owner.
    /// @param token The token or ether (0x0) to sell.
    /// @param amount THe amout of token/ether to sell.
    function sellTokenForLRC(
        address token,
        uint    amount
        )
        external
        virtual;

    /// @dev Returns some global stats regarding fees.
    /// @return accumulatedFees The accumulated amount of LRC protocol fees.
    /// @return accumulatedBurn The accumulated amount of LRC to burn.
    /// @return accumulatedDAOFund The accumulated amount of LRC as developer pool.
    /// @return accumulatedReward The accumulated amount of LRC as staking reward.
    /// @return remainingFees The remaining amount of LRC protocol fees.
    /// @return remainingBurn The remaining amount of LRC to burn.
    /// @return remainingDAOFund The remaining amount of LRC as developer pool.
    /// @return remainingReward The remaining amount of LRC as staking reward.
    function getProtocolFeeStats()
        external
        virtual
        view
        returns (
            uint accumulatedFees,
            uint accumulatedBurn,
            uint accumulatedDAOFund,
            uint accumulatedReward,
            uint remainingFees,
            uint remainingBurn,
            uint remainingDAOFund,
            uint remainingReward
        );
}

File 86 of 95 : ProtocolFeeVault.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;

import "../../lib/AddressUtil.sol";
import "../../lib/BurnableERC20.sol";
import "../../lib/Claimable.sol";
import "../../lib/ERC20.sol";
import "../../lib/ERC20SafeTransfer.sol";
import "../../lib/MathUint.sol";
import "../../lib/ReentrancyGuard.sol";
import "../token-sellers/ITokenSeller.sol";
import "./IProtocolFeeVault.sol";


/// @title An Implementation of IProtocolFeeVault.
/// @author Daniel Wang - <[email protected]>
contract ProtocolFeeVault is Claimable, ReentrancyGuard, IProtocolFeeVault
{
    using AddressUtil       for address;
    using AddressUtil       for address payable;
    using ERC20SafeTransfer for address;
    using MathUint          for uint;

    address public immutable override lrcAddress;

    constructor(address _lrcAddress)
        Claimable()
    {
        require(_lrcAddress != address(0), "ZERO_ADDRESS");
        lrcAddress = _lrcAddress;
    }

    receive() external payable { }

    function updateSettings(
        address _userStakingPoolAddress,
        address _tokenSellerAddress,
        address _daoAddress
        )
        external
        override
        nonReentrant
        onlyOwner
    {
        require(
            userStakingPoolAddress != _userStakingPoolAddress ||
            tokenSellerAddress != _tokenSellerAddress ||
            daoAddress != _daoAddress,
            "SAME_ADDRESSES"
        );
        userStakingPoolAddress = _userStakingPoolAddress;
        tokenSellerAddress = _tokenSellerAddress;
        daoAddress = _daoAddress;

        emit SettingsUpdated(block.timestamp);
    }

    function claimStakingReward(
        uint amount
        )
        external
        override
        nonReentrant
    {
        require(amount > 0, "ZERO_VALUE");
        require(msg.sender == userStakingPoolAddress, "UNAUTHORIZED");
        lrcAddress.safeTransferAndVerify(userStakingPoolAddress, amount);
        claimedReward = claimedReward.add(amount);
        emit LRCClaimed(amount);
    }

    function fundDAO()
        external
        override
        nonReentrant
    {
        uint amountDAO;
        uint amountBurn;
        (, , , , , amountBurn, amountDAO, ) = getProtocolFeeStats();

        address recipient = daoAddress == address(0) ? owner : daoAddress;

        if (amountDAO > 0) {
            lrcAddress.safeTransferAndVerify(recipient, amountDAO);
        }

        if (amountBurn > 0) {
            require(BurnableERC20(lrcAddress).burn(amountBurn), "BURN_FAILURE");
        }

        claimedBurn = claimedBurn.add(amountBurn);
        claimedDAOFund = claimedDAOFund.add(amountDAO);

        emit DAOFunded(amountDAO, amountBurn);
    }

    function sellTokenForLRC(
        address token,
        uint    amount
        )
        external
        override
        nonReentrant
    {
        require(amount > 0, "ZERO_AMOUNT");
        require(token != lrcAddress, "PROHIBITED");

        address recipient = tokenSellerAddress == address(0) ? owner : tokenSellerAddress;

        if (token == address(0)) {
            recipient.sendETHAndVerify(amount, gasleft());
        } else {
            token.safeTransferAndVerify(recipient, amount);
        }

        require(
            tokenSellerAddress == address(0) ||
            ITokenSeller(tokenSellerAddress).sellToken(token, lrcAddress),
            "SELL_FAILURE"
        );

        emit TokenSold(token, amount);
    }

    function getProtocolFeeStats()
        public
        override
        view
        returns (
            uint accumulatedFees,
            uint accumulatedBurn,
            uint accumulatedDAOFund,
            uint accumulatedReward,
            uint remainingFees,
            uint remainingBurn,
            uint remainingDAOFund,
            uint remainingReward
        )
    {
        remainingFees = ERC20(lrcAddress).balanceOf(address(this));
        accumulatedFees = remainingFees.add(claimedReward).add(claimedDAOFund).add(claimedBurn);

        accumulatedReward = accumulatedFees.mul(REWARD_PERCENTAGE) / 100;
        accumulatedDAOFund = accumulatedFees.mul(DAO_PERDENTAGE) / 100;
        accumulatedBurn = accumulatedFees.sub(accumulatedReward).sub(accumulatedDAOFund);

        remainingReward = accumulatedReward.sub(claimedReward);
        remainingDAOFund = accumulatedDAOFund.sub(claimedDAOFund);
        remainingBurn = accumulatedBurn.sub(claimedBurn);
    }
}

File 87 of 95 : FastWithdrawalLiquidityProvider.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
// Modified by DeGate DAO, 2022
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "../agents/FastWithdrawalAgent.sol";
import "../../lib/OwnerManagable.sol";
import "../../lib/EIP712.sol";
import "../../lib/ERC20.sol";
import "../../lib/ERC20SafeTransfer.sol";
import "../../lib/MathUint.sol";
import "../../lib/ReentrancyGuard.sol";
import "../../lib/SignatureUtil.sol";


/// @title Basic contract storing funds for a liquidity provider.
/// @author Brecht Devos - <[email protected]>
contract FastWithdrawalLiquidityProvider is ReentrancyGuard, OwnerManagable
{
    using AddressUtil       for address;
    using AddressUtil       for address payable;
    using ERC20SafeTransfer for address;
    using MathUint          for uint;
    using SignatureUtil     for bytes32;

    struct FastWithdrawalApproval
    {
        address exchange;
        address from;
        address to;
        address token;
        uint248  amount;
        uint32  storageID;
        uint64  validUntil; // most significant 32 bits as block height, least significant 32 bits as block time
        address signer;
        bytes   signature;  // signer's signature
    }

    bytes32 constant public FASTWITHDRAWAL_APPROVAL_TYPEHASH = keccak256(
        "FastWithdrawalApproval(address exchange,address from,address to,address token,uint248 amount,uint32 storageID,uint64 validUntil)"
    );

    bytes32 public immutable DOMAIN_SEPARATOR;

    FastWithdrawalAgent public immutable agent;

    constructor(FastWithdrawalAgent _agent)
    {
        agent = _agent;
        DOMAIN_SEPARATOR = EIP712.hash(EIP712.Domain("FastWithdrawalLiquidityProvider", "1.0", address(this)));
    }

    // Execute the fast withdrawals.
    // Full approvals are posted onchain so they can be used by anyone to speed up the
    // withdrawal by calling , but the approvals are not validated when done by the
    // owner or one of the managers.
    function execute(FastWithdrawalApproval[] calldata approvals)
        external
        nonReentrant
    {
        // Prepare the data and validate the approvals when necessary
        FastWithdrawalAgent.Withdrawal[] memory withdrawals =
            new FastWithdrawalAgent.Withdrawal[](approvals.length);

        bool skipApprovalCheck = isManager(msg.sender);
        for (uint i = 0; i < approvals.length; i++) {
            require(skipApprovalCheck || isApprovalValid(approvals[i]), "PROHIBITED");
            withdrawals[i] = translate(approvals[i]);
        }

        // Calculate how much ETH we need to send to the agent contract.
        // We could also send the full ETH balance each time, but that'll need
        // an additional transfer to send funds back, which may actually be more efficient.
        uint value = 0;
        for (uint i = 0; i < withdrawals.length; i++) {
            if (withdrawals[i].token == address(0)) {
                value = value.add(withdrawals[i].amount);
            }
        }
        // Execute all the fast withdrawals
        agent.executeFastWithdrawals{value: value}(withdrawals);
    }

    // Allows the LP to transfer funds back out of this contract.
    function drain(
        address to,
        address token,
        uint    amount
        )
        external
        nonReentrant
        onlyOwner
    {
        if (token == address(0)) {
            to.sendETHAndVerify(amount, gasleft()); // ETH
        } else {
            token.safeTransferAndVerify(to, amount);  // ERC20 token
        }
    }

    // Allows the LP to enable the necessary ERC20 approvals
    function approve(
        address token,
        address spender,
        uint    amount
        )
        external
        nonReentrant
        onlyOwner
    {
        require(ERC20(token).approve(spender, amount), "APPROVAL_FAILED");
    }

    function isApprovalValid(
        FastWithdrawalApproval calldata approval
        )
        internal
        view
        returns (bool)
    {
        // Compute the hash
        bytes32 hash = EIP712.hashPacked(
            DOMAIN_SEPARATOR,
            keccak256(
                abi.encodePacked(
                    FASTWITHDRAWAL_APPROVAL_TYPEHASH,
                    approval.exchange,
                    approval.from,
                    approval.to,
                    approval.token,
                    approval.amount,
                    approval.storageID,
                    approval.validUntil
                )
            )
        );

        return hash.verifySignature(approval.signer, approval.signature) &&
            checkValidUntil(approval.validUntil) &&
            isManager(approval.signer);
    }

    receive() payable external {}

    // -- Internal --

    function checkValidUntil(uint64 validUntil)
        internal
        view
        returns (bool)
    {
        return (validUntil & 0xFFFFFFFF) >= block.timestamp ||
            (validUntil >> 32) >= block.number;
    }

    function translate(FastWithdrawalApproval calldata approval)
        internal
        pure
        returns (FastWithdrawalAgent.Withdrawal memory)
    {
        return FastWithdrawalAgent.Withdrawal({
            exchange: approval.exchange,
            from: approval.from,
            to: approval.to,
            token: approval.token,
            amount: approval.amount,
            storageID: approval.storageID
        });
    }
}

File 88 of 95 : MigrationToLoopringExchangeV2.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;


import "../../lib/ReentrancyGuard.sol";
import "../../lib/Drainable.sol";

abstract contract ILoopringV3Partial
{
    function withdrawExchangeStake(
        uint    exchangeId,
        address recipient,
        uint    requestedAmount
        )
        external
        virtual
        returns (uint amount);
}

/// @author Kongliang Zhong - <[email protected]>
/// @dev This contract enables an alternative approach of getting back assets from Loopring Exchange v1.
/// Now you don't have to withdraw using merkle proofs (very expensive);
/// instead, all assets will be distributed on Loopring Exchange v2 - Loopring's new zkRollup implementation.
/// Please activate and unlock your address on https://exchange.loopring.io to claim your assets.
contract MigrationToLoopringExchangeV2 is Drainable
{
    function canDrain(address /*drainer*/, address /*token*/)
        public
        override
        view
        returns (bool) {
        return isMigrationOperator();
    }

    function withdrawExchangeStake(
        address loopringV3,
        uint exchangeId,
        uint amount,
        address recipient
        )
        external
    {
        require(isMigrationOperator(), "INVALID_SENDER");
        ILoopringV3Partial(loopringV3).withdrawExchangeStake(exchangeId, recipient, amount);
    }

    function isMigrationOperator() internal view returns (bool) {
        return msg.sender == 0x4374D3d032B3c96785094ec9f384f07077792768;
    }

}

File 89 of 95 : IChiToken.sol
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.7.0;

import "../../lib/ERC20.sol";


abstract contract IChiToken is ERC20
{
    function free(uint256 value)
    external
    virtual
    returns (uint256);

    function freeUpTo(uint256 value)
    external
    virtual
    returns (uint256);

    function freeFrom(address from, uint256 value)
    external
    virtual
    returns (uint256);

    function freeFromUpTo(address from, uint256 value)
    external
    virtual
    returns (uint256 freed);
}

File 90 of 95 : AggregatorInterface.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.0;

interface AggregatorInterface {
  function latestAnswer() external view returns (int256);
  function latestTimestamp() external view returns (uint256);
  function latestRound() external view returns (uint256);
  function getAnswer(uint256 roundId) external view returns (int256);
  function getTimestamp(uint256 roundId) external view returns (uint256);

  event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 timestamp);
  event NewRound(uint256 indexed roundId, address indexed startedBy);
}

File 91 of 95 : Cloneable.sol
// SPDX-License-Identifier: UNLICENSED
// This code is taken from https://gist.github.com/holiman/069de8d056a531575d2b786df3345665
pragma solidity ^0.7.0;

library Cloneable {
    function clone(address a)
        external
        returns (address)
    {

    /*
    Assembly of the code that we want to use as init-code in the new contract,
    along with stack values:
                    # bottom [ STACK ] top
     PUSH1 00       # [ 0 ]
     DUP1           # [ 0, 0 ]
     PUSH20
     <address>      # [0,0, address]
     DUP1           # [0,0, address ,address]
     EXTCODESIZE    # [0,0, address, size ]
     DUP1           # [0,0, address, size, size]
     SWAP4          # [ size, 0, address, size, 0]
     DUP1           # [ size, 0, address ,size, 0,0]
     SWAP2          # [ size, 0, address, 0, 0, size]
     SWAP3          # [ size, 0, size, 0, 0, address]
     EXTCODECOPY    # [ size, 0]
     RETURN

    The code above weighs in at 33 bytes, which is _just_ above fitting into a uint.
    So a modified version is used, where the initial PUSH1 00 is replaced by `PC`.
    This is one byte smaller, and also a bit cheaper Wbase instead of Wverylow. It only costs 2 gas.

     PC             # [ 0 ]
     DUP1           # [ 0, 0 ]
     PUSH20
     <address>      # [0,0, address]
     DUP1           # [0,0, address ,address]
     EXTCODESIZE    # [0,0, address, size ]
     DUP1           # [0,0, address, size, size]
     SWAP4          # [ size, 0, address, size, 0]
     DUP1           # [ size, 0, address ,size, 0,0]
     SWAP2          # [ size, 0, address, 0, 0, size]
     SWAP3          # [ size, 0, size, 0, 0, address]
     EXTCODECOPY    # [ size, 0]
     RETURN

    The opcodes are:
    58 80 73 <address> 80 3b 80 93 80 91 92 3c F3
    We get <address> in there by OR:ing the upshifted address into the 0-filled space.
      5880730000000000000000000000000000000000000000803b80938091923cF3
     +000000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx000000000000000000
     -----------------------------------------------------------------
      588073xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx00000803b80938091923cF3

    This is simply stored at memory position 0, and create is invoked.
    */
        address retval;
        assembly{
            mstore(0x0, or (0x5880730000000000000000000000000000000000000000803b80938091923cF3 ,mul(a,0x1000000000000000000)))
            retval := create(0,0, 32)
        }
        return retval;
    }
}

File 92 of 95 : IKnowForwarderAddress.sol
// SPDX-License-Identifier:MIT
pragma solidity ^0.7.0;

interface IKnowForwarderAddress {

    /**
     * return the forwarder we trust to forward relayed transactions to us.
     * the forwarder is required to verify the sender's signature, and verify
     * the call is not a replay.
     */
    function getTrustedForwarder() external view returns(address);
}

File 93 of 95 : IRelayRecipient.sol
// SPDX-License-Identifier:MIT
pragma solidity ^0.7.0;

/**
 * a contract must implement this interface in order to support relayed transaction.
 * It is better to inherit the BaseRelayRecipient as its implementation.
 */
abstract contract IRelayRecipient {

    /**
     * return if the forwarder is trusted to forward relayed transactions to us.
     * the forwarder is required to verify the sender's signature, and verify
     * the call is not a replay.
     */
    function isTrustedForwarder(address forwarder) public virtual view returns(bool);

    /**
     * return the sender of this call.
     * if the call came through our trusted forwarder, then the real sender is appended as the last 20 bytes
     * of the msg.data.
     * otherwise, return `msg.sender`
     * should be used in the contract anywhere instead of msg.sender
     */
    function _msgSender() internal virtual view returns (address payable);

    function versionRecipient() external virtual view returns (string memory);
}

File 94 of 95 : BaseRelayRecipient.sol
// SPDX-License-Identifier:MIT
pragma solidity ^0.7.0;

import "./IRelayRecipient.sol";

/**
 * A base contract to be inherited by any contract that want to receive relayed transactions
 * A subclass must use "_msgSender()" instead of "msg.sender"
 */
abstract contract BaseRelayRecipient is IRelayRecipient {

    /*
     * Forwarder singleton we accept calls from
     */
    address public immutable trustedForwarder;

    constructor(address _forwarder)
    {
        trustedForwarder = _forwarder;
    }

    /*
     * require a function to be called through GSN only
     */
    modifier trustedForwarderOnly() {
        require(msg.sender == address(trustedForwarder), "Function can only be called through the trusted Forwarder");
        _;
    }

    function isTrustedForwarder(address forwarder) public override view returns(bool) {
        return forwarder == trustedForwarder;
    }

    /**
     * return the sender of this call.
     * if the call came through our trusted forwarder, return the original sender.
     * otherwise, return `msg.sender`.
     * should be used in the contract anywhere instead of msg.sender
     */
    function _msgSender() internal override virtual view returns (address payable ret) {
        if (msg.data.length >= 24 && isTrustedForwarder(msg.sender)) {
            // At this point we know that the sender is a trusted forwarder,
            // so we trust that the last bytes of msg.data are the verified sender address.
            // extract sender address from the end of msg.data
            assembly {
                ret := shr(96,calldataload(sub(calldatasize(),20)))
            }
        } else {
            return msg.sender;
        }
    }
}

File 95 of 95 : MockContract.sol
// SPDX-License-Identifier: UNLICENSED
/// Borrowed from https://github.com/gnosis/mock-contract
pragma solidity ^0.7.0;

interface MockInterface {
	/**
	 * @dev After calling this method, the mock will return `response` when it is called
	 * with any calldata that is not mocked more specifically below
	 * (e.g. using givenMethodReturn).
	 * @param response ABI encoded response that will be returned if method is invoked
	 */
	function givenAnyReturn(bytes calldata response) external;
	function givenAnyReturnBool(bool response) external;
	function givenAnyReturnUint(uint response) external;
	function givenAnyReturnAddress(address response) external;

	function givenAnyRevert() external;
	function givenAnyRevertWithMessage(string calldata message) external;
	function givenAnyRunOutOfGas() external;

	/**
	 * @dev After calling this method, the mock will return `response` when the given
	 * methodId is called regardless of arguments. If the methodId and arguments
	 * are mocked more specifically (using `givenMethodAndArguments`) the latter
	 * will take precedence.
	 * @param method ABI encoded methodId. It is valid to pass full calldata (including arguments). The mock will extract the methodId from it
	 * @param response ABI encoded response that will be returned if method is invoked
	 */
	function givenMethodReturn(bytes calldata method, bytes calldata response) external;
	function givenMethodReturnBool(bytes calldata method, bool response) external;
	function givenMethodReturnUint(bytes calldata method, uint response) external;
	function givenMethodReturnAddress(bytes calldata method, address response) external;

	function givenMethodRevert(bytes calldata method) external;
	function givenMethodRevertWithMessage(bytes calldata method, string calldata message) external;
	function givenMethodRunOutOfGas(bytes calldata method) external;

	/**
	 * @dev After calling this method, the mock will return `response` when the given
	 * methodId is called with matching arguments. These exact calldataMocks will take
	 * precedence over all other calldataMocks.
	 * @param call ABI encoded calldata (methodId and arguments)
	 * @param response ABI encoded response that will be returned if contract is invoked with calldata
	 */
	function givenCalldataReturn(bytes calldata call, bytes calldata response) external;
	function givenCalldataReturnBool(bytes calldata call, bool response) external;
	function givenCalldataReturnUint(bytes calldata call, uint response) external;
	function givenCalldataReturnAddress(bytes calldata call, address response) external;

	function givenCalldataRevert(bytes calldata call) external;
	function givenCalldataRevertWithMessage(bytes calldata call, string calldata message) external;
	function givenCalldataRunOutOfGas(bytes calldata call) external;

	/**
	 * @dev Returns the number of times anything has been called on this mock since last reset
	 */
	function invocationCount() external returns (uint);

	/**
	 * @dev Returns the number of times the given method has been called on this mock since last reset
	 * @param method ABI encoded methodId. It is valid to pass full calldata (including arguments). The mock will extract the methodId from it
	 */
	function invocationCountForMethod(bytes calldata method) external returns (uint);

	/**
	 * @dev Returns the number of times this mock has been called with the exact calldata since last reset.
	 * @param call ABI encoded calldata (methodId and arguments)
	 */
	function invocationCountForCalldata(bytes calldata call) external returns (uint);

	/**
	 * @dev Resets all mocked methods and invocation counts.
	 */
	 function reset() external;
}

/**
 * Implementation of the MockInterface.
 */
contract MockContract is MockInterface {
	enum MockType { Return, Revert, OutOfGas }

	bytes32 public constant MOCKS_LIST_START = hex"01";
	bytes public constant MOCKS_LIST_END = "0xff";
	bytes32 public constant MOCKS_LIST_END_HASH = keccak256(MOCKS_LIST_END);
	bytes4 public constant SENTINEL_ANY_MOCKS = hex"01";

	// A linked list allows easy iteration and inclusion checks
	mapping(bytes32 => bytes) calldataMocks;
	mapping(bytes => MockType) calldataMockTypes;
	mapping(bytes => bytes) calldataExpectations;
	mapping(bytes => string) calldataRevertMessage;
	mapping(bytes32 => uint) calldataInvocations;

	mapping(bytes4 => bytes4) methodIdMocks;
	mapping(bytes4 => MockType) methodIdMockTypes;
	mapping(bytes4 => bytes) methodIdExpectations;
	mapping(bytes4 => string) methodIdRevertMessages;
	mapping(bytes32 => uint) methodIdInvocations;

	MockType fallbackMockType;
	bytes fallbackExpectation;
	string fallbackRevertMessage;
	uint invocations;
	uint resetCount;

	constructor() {
		calldataMocks[MOCKS_LIST_START] = MOCKS_LIST_END;
		methodIdMocks[SENTINEL_ANY_MOCKS] = SENTINEL_ANY_MOCKS;
	}

	function trackCalldataMock(bytes memory call) private {
		bytes32 callHash = keccak256(call);
		if (calldataMocks[callHash].length == 0) {
			calldataMocks[callHash] = calldataMocks[MOCKS_LIST_START];
			calldataMocks[MOCKS_LIST_START] = call;
		}
	}

	function trackMethodIdMock(bytes4 methodId) private {
		if (methodIdMocks[methodId] == 0x0) {
			methodIdMocks[methodId] = methodIdMocks[SENTINEL_ANY_MOCKS];
			methodIdMocks[SENTINEL_ANY_MOCKS] = methodId;
		}
	}

	function _givenAnyReturn(bytes memory response) internal {
		fallbackMockType = MockType.Return;
		fallbackExpectation = response;
	}

	function givenAnyReturn(bytes calldata response) external override {
		_givenAnyReturn(response);
	}

	function givenAnyReturnBool(bool response) external override {
		uint flag = response ? 1 : 0;
		_givenAnyReturn(uintToBytes(flag));
	}

	function givenAnyReturnUint(uint response) external override {
		_givenAnyReturn(uintToBytes(response));
	}

	function givenAnyReturnAddress(address response) external override {
		_givenAnyReturn(uintToBytes(uint(response)));
	}

	function givenAnyRevert() external override {
		fallbackMockType = MockType.Revert;
		fallbackRevertMessage = "";
	}

	function givenAnyRevertWithMessage(string calldata message) external override {
		fallbackMockType = MockType.Revert;
		fallbackRevertMessage = message;
	}

	function givenAnyRunOutOfGas() external override {
		fallbackMockType = MockType.OutOfGas;
	}

	function _givenCalldataReturn(bytes memory call, bytes memory response) private  {
		calldataMockTypes[call] = MockType.Return;
		calldataExpectations[call] = response;
		trackCalldataMock(call);
	}

	function givenCalldataReturn(bytes calldata call, bytes calldata response) external override {
		_givenCalldataReturn(call, response);
	}

	function givenCalldataReturnBool(bytes calldata call, bool response) external override {
		uint flag = response ? 1 : 0;
		_givenCalldataReturn(call, uintToBytes(flag));
	}

	function givenCalldataReturnUint(bytes calldata call, uint response) external override {
		_givenCalldataReturn(call, uintToBytes(response));
	}

	function givenCalldataReturnAddress(bytes calldata call, address response) external override {
		_givenCalldataReturn(call, uintToBytes(uint(response)));
	}

	function _givenMethodReturn(bytes memory call, bytes memory response) private {
		bytes4 method = bytesToBytes4(call);
		methodIdMockTypes[method] = MockType.Return;
		methodIdExpectations[method] = response;
		trackMethodIdMock(method);
	}

	function givenMethodReturn(bytes calldata call, bytes calldata response) external override {
		_givenMethodReturn(call, response);
	}

	function givenMethodReturnBool(bytes calldata call, bool response) external override {
		uint flag = response ? 1 : 0;
		_givenMethodReturn(call, uintToBytes(flag));
	}

	function givenMethodReturnUint(bytes calldata call, uint response) external override {
		_givenMethodReturn(call, uintToBytes(response));
	}

	function givenMethodReturnAddress(bytes calldata call, address response) external override {
		_givenMethodReturn(call, uintToBytes(uint(response)));
	}

	function givenCalldataRevert(bytes calldata call) external override {
		calldataMockTypes[call] = MockType.Revert;
		calldataRevertMessage[call] = "";
		trackCalldataMock(call);
	}

	function givenMethodRevert(bytes calldata call) external override {
		bytes4 method = bytesToBytes4(call);
		methodIdMockTypes[method] = MockType.Revert;
		trackMethodIdMock(method);
	}

	function givenCalldataRevertWithMessage(bytes calldata call, string calldata message) external override {
		calldataMockTypes[call] = MockType.Revert;
		calldataRevertMessage[call] = message;
		trackCalldataMock(call);
	}

	function givenMethodRevertWithMessage(bytes calldata call, string calldata message) external override {
		bytes4 method = bytesToBytes4(call);
		methodIdMockTypes[method] = MockType.Revert;
		methodIdRevertMessages[method] = message;
		trackMethodIdMock(method);
	}

	function givenCalldataRunOutOfGas(bytes calldata call) external override {
		calldataMockTypes[call] = MockType.OutOfGas;
		trackCalldataMock(call);
	}

	function givenMethodRunOutOfGas(bytes calldata call) external override {
		bytes4 method = bytesToBytes4(call);
		methodIdMockTypes[method] = MockType.OutOfGas;
		trackMethodIdMock(method);
	}

	function invocationCount() external override view returns (uint) {
		return invocations;
	}

	function invocationCountForMethod(bytes calldata call) external view override returns (uint) {
		bytes4 method = bytesToBytes4(call);
		return methodIdInvocations[keccak256(abi.encodePacked(resetCount, method))];
	}

	function invocationCountForCalldata(bytes calldata call) external view override returns (uint) {
		return calldataInvocations[keccak256(abi.encodePacked(resetCount, call))];
	}

	function reset() external override {
		// Reset all exact calldataMocks
		bytes memory nextMock = calldataMocks[MOCKS_LIST_START];
		bytes32 mockHash = keccak256(nextMock);
		// We cannot compary bytes
		while(mockHash != MOCKS_LIST_END_HASH) {
			// Reset all mock maps
			calldataMockTypes[nextMock] = MockType.Return;
			calldataExpectations[nextMock] = hex"";
			calldataRevertMessage[nextMock] = "";
			// Set next mock to remove
			nextMock = calldataMocks[mockHash];
			// Remove from linked list
			calldataMocks[mockHash] = "";
			// Update mock hash
			mockHash = keccak256(nextMock);
		}
		// Clear list
		calldataMocks[MOCKS_LIST_START] = MOCKS_LIST_END;

		// Reset all any calldataMocks
		bytes4 nextAnyMock = methodIdMocks[SENTINEL_ANY_MOCKS];
		while(nextAnyMock != SENTINEL_ANY_MOCKS) {
			bytes4 currentAnyMock = nextAnyMock;
			methodIdMockTypes[currentAnyMock] = MockType.Return;
			methodIdExpectations[currentAnyMock] = hex"";
			methodIdRevertMessages[currentAnyMock] = "";
			nextAnyMock = methodIdMocks[currentAnyMock];
			// Remove from linked list
			methodIdMocks[currentAnyMock] = 0x0;
		}
		// Clear list
		methodIdMocks[SENTINEL_ANY_MOCKS] = SENTINEL_ANY_MOCKS;

		fallbackExpectation = "";
		fallbackMockType = MockType.Return;
		invocations = 0;
		resetCount += 1;
	}

	function useAllGas() private {
		while(true) {
			bool s;
			assembly {
				//expensive call to EC multiply contract
				s := call(sub(gas(), 2000), 6, 0, 0x0, 0xc0, 0x0, 0x60)
			}
		}
	}

	function bytesToBytes4(bytes memory b) private pure returns (bytes4) {
		bytes4 out;
		for (uint i = 0; i < 4; i++) {
			out |= bytes4(b[i] & 0xFF) >> (i * 8);
		}
		return out;
	}

	function uintToBytes(uint256 x) private pure returns (bytes memory b) {
		b = new bytes(32);
		assembly { mstore(add(b, 32), x) }
	}

	function updateInvocationCount(bytes4 methodId, bytes memory originalMsgData) public {
		require(msg.sender == address(this), "Can only be called from the contract itself");
		invocations += 1;
		methodIdInvocations[keccak256(abi.encodePacked(resetCount, methodId))] += 1;
		calldataInvocations[keccak256(abi.encodePacked(resetCount, originalMsgData))] += 1;
	}

	receive()
        external
        payable
    {
        // Don't do anything
    }

	fallback() payable external {
		bytes4 methodId;
		assembly {
			methodId := calldataload(0)
		}

		// First, check exact matching overrides
		if (calldataMockTypes[msg.data] == MockType.Revert) {
			revert(calldataRevertMessage[msg.data]);
		}
		if (calldataMockTypes[msg.data] == MockType.OutOfGas) {
			useAllGas();
		}
		bytes memory result = calldataExpectations[msg.data];

		// Then check method Id overrides
		if (result.length == 0) {
			if (methodIdMockTypes[methodId] == MockType.Revert) {
				revert(methodIdRevertMessages[methodId]);
			}
			if (methodIdMockTypes[methodId] == MockType.OutOfGas) {
				useAllGas();
			}
			result = methodIdExpectations[methodId];
		}

		// Last, use the fallback override
		if (result.length == 0) {
			if (fallbackMockType == MockType.Revert) {
				revert(fallbackRevertMessage);
			}
			if (fallbackMockType == MockType.OutOfGas) {
				useAllGas();
			}
			result = fallbackExpectation;
		}

		// Record invocation as separate call so we don't rollback in case we are called with STATICCALL
		(, bytes memory r) = address(this).call{gas: 100000}(abi.encodeWithSignature("updateInvocationCount(bytes4,bytes)", methodId, msg.data));
		assert(r.length == 0);

		assembly {
			return(add(0x20, result), mload(result))
		}
	}
}

Settings
{
  "metadata": {
    "useLiteralContent": true
  },
  "optimizer": {
    "enabled": true,
    "runs": 1000000
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  },
  "libraries": {
    "./contracts/core/impl/libexchange/ExchangeAdmins.sol": {
      "ExchangeAdmins": "0x2375BBB012C378a0df56da7B947067a76372Ec0A"
    },
    "./contracts/core/impl/libexchange/ExchangeBalances.sol": {
      "ExchangeBalances": "0x3F93f7CD35E715476bba0DbAA99c9c5D1cb10736"
    },
    "./contracts/core/impl/libexchange/ExchangeTokens.sol": {
      "ExchangeTokens": "0x52C0Bc9fa4481CA8d43a74B4Add792B2E15367C8"
    },
    "./contracts/core/impl/libexchange/ExchangeBlocks.sol": {
      "ExchangeBlocks": "0x615B953baD4Cc5E1232976Cd0205Fa53D279b3De"
    },
    "./contracts/core/impl/libexchange/ExchangeGenesis.sol": {
      "ExchangeGenesis": "0xF9c1F624B13ffd90aF9Da0f83d233808cAcab937"
    },
    "./contracts/core/impl/libexchange/ExchangeWithdrawals.sol": {
      "ExchangeWithdrawals": "0x6a4690aE65D020A61c99449a11bc02934f081b97"
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"value","type":"bool"}],"name":"AllowOnchainTransferFrom","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"blockIdx","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"merkleRoot","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"publicDataHash","type":"bytes32"}],"name":"BlockSubmitted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"blockVerifier","type":"address"}],"name":"BlockVerifierRefreshed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"depositContract","type":"address"}],"name":"DepositContractUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"freeDepositMax","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"freeDepositRemained","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"freeSlotPerBlock","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"depositFee","type":"uint256"}],"name":"DepositParamsUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint32","name":"tokenId","type":"uint32"},{"indexed":false,"internalType":"uint248","name":"amount","type":"uint248"}],"name":"DepositRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"exchangeAddress","type":"address"},{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"bytes32","name":"genesisMerkleRoot","type":"bytes32"}],"name":"ExchangeCloned","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint32","name":"accountID","type":"uint32"}],"name":"ForcedWithdrawalRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"protocolFeeBips","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"previousProtocolFeeBips","type":"uint16"}],"name":"ProtocolFeesUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"Shutdown","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint32","name":"tokenId","type":"uint32"}],"name":"TokenRegistered","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"bytes32","name":"transactionHash","type":"bytes32"}],"name":"TransactionApproved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"owners","type":"address[]"},{"indexed":false,"internalType":"bytes32[]","name":"transactionHashes","type":"bytes32[]"}],"name":"TransactionsApproved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"recipient","type":"address"}],"name":"WithdrawExchangeFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"category","type":"uint8"},{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawalCompleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"category","type":"uint8"},{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawalFailed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"WithdrawalModeActivated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint248","name":"amount","type":"uint248"},{"indexed":false,"internalType":"uint32","name":"storageID","type":"uint32"},{"indexed":false,"internalType":"address","name":"newRecipient","type":"address"}],"name":"WithdrawalRecipientUpdate","type":"event"},{"inputs":[],"name":"allowOnchainTransferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"bytes32","name":"transactionHash","type":"bytes32"}],"name":"approveTransaction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"owners","type":"address[]"},{"internalType":"bytes32[]","name":"transactionHashes","type":"bytes32[]"}],"name":"approveTransactions","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"burnExchangeStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint248","name":"amount","type":"uint248"},{"internalType":"bytes","name":"extraData","type":"bytes"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"domainSeparator","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint32","name":"accountID","type":"uint32"}],"name":"forceWithdraw","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"getAmountWithdrawable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBlockHeight","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"blockIdx","type":"uint256"}],"name":"getBlockInfo","outputs":[{"components":[{"internalType":"uint32","name":"timestamp","type":"uint32"},{"internalType":"bytes28","name":"blockDataHash","type":"bytes28"}],"internalType":"struct ExchangeData.BlockInfo","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getConstants","outputs":[{"components":[{"internalType":"uint256","name":"SNARK_SCALAR_FIELD","type":"uint256"},{"internalType":"uint256","name":"MAX_OPEN_FORCED_REQUESTS","type":"uint256"},{"internalType":"uint256","name":"MAX_AGE_FORCED_REQUEST_UNTIL_WITHDRAW_MODE","type":"uint256"},{"internalType":"uint256","name":"TIMESTAMP_HALF_WINDOW_SIZE_IN_SECONDS","type":"uint256"},{"internalType":"uint256","name":"MAX_NUM_ACCOUNTS","type":"uint256"},{"internalType":"uint256","name":"MAX_NUM_TOKENS","type":"uint256"},{"internalType":"uint256","name":"MIN_AGE_PROTOCOL_FEES_UNTIL_UPDATED","type":"uint256"},{"internalType":"uint256","name":"MIN_TIME_IN_SHUTDOWN","type":"uint256"},{"internalType":"uint256","name":"TX_DATA_AVAILABILITY_SIZE","type":"uint256"},{"internalType":"uint256","name":"MAX_AGE_DEPOSIT_UNTIL_WITHDRAWABLE_UPPERBOUND","type":"uint256"},{"internalType":"uint256","name":"MAX_FORCED_WITHDRAWAL_FEE","type":"uint256"},{"internalType":"uint256","name":"DEFAULT_PROTOCOL_FEE_BIPS","type":"uint256"}],"internalType":"struct ExchangeData.Constants","name":"","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getDepositBalance","outputs":[{"internalType":"uint248","name":"","type":"uint248"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDepositContract","outputs":[{"internalType":"contract IDepositContract","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDomainSeparator","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getExchangeStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFreeDepositRemained","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMaxAgeDepositUntilWithdrawable","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMerkleAssetRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMerkleRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNumAvailableForcedSlots","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"getPendingDepositAmount","outputs":[{"internalType":"uint248","name":"","type":"uint248"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"getProtocolFeeLastWithdrawnTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getProtocolFeeValues","outputs":[{"internalType":"uint32","name":"syncedAt","type":"uint32"},{"internalType":"uint16","name":"protocolFeeBips","type":"uint16"},{"internalType":"uint16","name":"previousProtocolFeeBips","type":"uint16"},{"internalType":"uint32","name":"executeTimeOfNextProtocolFeeBips","type":"uint32"},{"internalType":"uint16","name":"nextProtocolFeeBips","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"tokenID","type":"uint32"}],"name":"getTokenAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"getTokenID","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getUnconfirmedBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint248","name":"amount","type":"uint248"},{"internalType":"uint32","name":"storageID","type":"uint32"}],"name":"getWithdrawalRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_loopring","type":"address"},{"internalType":"address","name":"_owner","type":"address"},{"internalType":"bytes32","name":"_genesisMerkleRoot","type":"bytes32"},{"internalType":"bytes32","name":"_genesisMerkleAssetRoot","type":"bytes32"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"accountID","type":"uint32"},{"internalType":"address","name":"token","type":"address"}],"name":"isForcedWithdrawalPending","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isInWithdrawalMode","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isShutdown","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"bytes32","name":"transactionHash","type":"bytes32"}],"name":"isTransactionApproved","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"}],"name":"isUserOrAgent","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"accountID","type":"uint32"},{"internalType":"address","name":"token","type":"address"}],"name":"isWithdrawnInWithdrawalMode","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"accountID","type":"uint32"},{"internalType":"address","name":"token","type":"address"}],"name":"notifyForcedRequestTooOld","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"onchainTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"registerToken","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"value","type":"bool"}],"name":"setAllowOnchainTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_depositContract","type":"address"}],"name":"setDepositContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"freeDepositMax","type":"uint256"},{"internalType":"uint256","name":"freeDepositRemained","type":"uint256"},{"internalType":"uint256","name":"freeSlotPerBlock","type":"uint256"},{"internalType":"uint256","name":"depositFee","type":"uint256"}],"name":"setDepositParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"newValue","type":"uint32"}],"name":"setMaxAgeDepositUntilWithdrawable","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint248","name":"amount","type":"uint248"},{"internalType":"uint32","name":"storageID","type":"uint32"},{"internalType":"address","name":"newRecipient","type":"address"}],"name":"setWithdrawalRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"shutdown","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"state","outputs":[{"internalType":"uint32","name":"maxAgeDepositUntilWithdrawable","type":"uint32"},{"internalType":"bytes32","name":"DOMAIN_SEPARATOR","type":"bytes32"},{"internalType":"contract ILoopringV3","name":"loopring","type":"address"},{"internalType":"contract IBlockVerifier","name":"blockVerifier","type":"address"},{"internalType":"contract IAgentRegistry","name":"agentRegistry","type":"address"},{"internalType":"contract IDepositContract","name":"depositContract","type":"address"},{"components":[{"internalType":"uint256","name":"freeDepositMax","type":"uint256"},{"internalType":"uint256","name":"freeDepositRemained","type":"uint256"},{"internalType":"uint256","name":"lastDepositBlockNum","type":"uint256"},{"internalType":"uint256","name":"freeSlotPerBlock","type":"uint256"},{"internalType":"uint256","name":"depositFee","type":"uint256"}],"internalType":"struct ExchangeData.DepositState","name":"depositState","type":"tuple"},{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"},{"internalType":"bytes32","name":"merkleAssetRoot","type":"bytes32"},{"internalType":"uint256","name":"numBlocks","type":"uint256"},{"internalType":"uint32","name":"numPendingForcedTransactions","type":"uint32"},{"components":[{"internalType":"uint32","name":"syncedAt","type":"uint32"},{"internalType":"uint16","name":"protocolFeeBips","type":"uint16"},{"internalType":"uint16","name":"previousProtocolFeeBips","type":"uint16"},{"internalType":"uint32","name":"executeTimeOfNextProtocolFeeBips","type":"uint32"},{"internalType":"uint16","name":"nextProtocolFeeBips","type":"uint16"}],"internalType":"struct ExchangeData.ProtocolFeeData","name":"protocolFeeData","type":"tuple"},{"components":[{"internalType":"uint256","name":"shutdownModeStartTime","type":"uint256"},{"internalType":"uint256","name":"withdrawalModeStartTime","type":"uint256"}],"internalType":"struct ExchangeData.ModeTime","name":"modeTime","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint8","name":"blockType","type":"uint8"},{"internalType":"uint16","name":"blockSize","type":"uint16"},{"internalType":"uint8","name":"blockVersion","type":"uint8"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256[8]","name":"proof","type":"uint256[8]"},{"internalType":"bool","name":"storeBlockInfoOnchain","type":"bool"},{"internalType":"bytes","name":"auxiliaryData","type":"bytes"},{"internalType":"bytes","name":"offchainData","type":"bytes"}],"internalType":"struct ExchangeData.Block[]","name":"blocks","type":"tuple[]"}],"name":"submitBlocks","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"recipient","type":"address"}],"name":"withdrawExchangeFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"}],"name":"withdrawExchangeStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"owners","type":"address[]"},{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"withdrawFromApprovedWithdrawals","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"withdrawFromDepositRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"uint32","name":"accountID","type":"uint32"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"pubKeyX","type":"uint256"},{"internalType":"uint256","name":"pubKeyY","type":"uint256"},{"internalType":"uint32","name":"nonce","type":"uint32"}],"internalType":"struct ExchangeData.AccountLeaf","name":"accountLeaf","type":"tuple"},{"components":[{"internalType":"uint32","name":"tokenID","type":"uint32"},{"internalType":"uint248","name":"balance","type":"uint248"}],"internalType":"struct ExchangeData.BalanceLeaf","name":"balanceLeaf","type":"tuple"},{"internalType":"uint256[48]","name":"accountMerkleProof","type":"uint256[48]"},{"internalType":"uint256[48]","name":"balanceMerkleProof","type":"uint256[48]"}],"internalType":"struct ExchangeData.MerkleProof","name":"merkleProof","type":"tuple"}],"name":"withdrawFromMerkleTree","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60806040526022805460ff1916905534801561001a57600080fd5b50600080546001600160a01b031916331790556154a48061003c6000396000f3fe60806040526004361061036b5760003560e01c80638a554abe116101c6578063c8e26cae116100f7578063e795799211610095578063f2fde38b1161006f578063f2fde38b14610997578063f698da2514610982578063f732e021146109b7578063fc0e74d1146109cc5761036b565b8063e795799214610942578063ed05ae7814610962578063ed24911d146109825761036b565b8063ce2ec5de116100d1578063ce2ec5de146108cd578063cea69b86146108ed578063d59acd251461090d578063e30c39781461092d5761036b565b8063c8e26cae1461086d578063cd097b4f1461088d578063cdb1b44b146108ad5761036b565b80639a295e7311610164578063ab94276a1161013e578063ab94276a146107e8578063bb141cf4146107fd578063bf86d6901461082a578063c19d93fb1461083f5761036b565b80639a295e7314610791578063a75f8a4e146107b3578063a7bff050146107d35761036b565b806391b11ad4116101a057806391b11ad41461072757806392f54afc1461073c578063960af2d91461075c578063972f75651461077c5761036b565b80638a554abe146106d25780638d2a8888146106f25780638da5cb5b146107125761036b565b80634e71e0c8116102a057806370f30de31161023e5780637907140e116102185780637907140e146106755780637bb96acb146106955780637beefcd4146106aa5780638070f2ca146106bf5761036b565b806370f30de314610620578063715018a61461064057806376cfcff6146106555761036b565b806354fd4d501161027a57806354fd4d50146105a95780636008cd1f146105cb57806363f8071c146105eb57806369b914321461060b5761036b565b80634e71e0c814610547578063532284301461055c578063543d7a191461057c5761036b565b80632c3d356b1161030d5780634597d3ce116102e75780634597d3ce146104e457806347b67d051461050a578063495906571461051d5780634a14cd84146105325761036b565b80632c3d356b146104775780632fa5825f14610497578063438c2a42146104b75761036b565b80630ec2e821116103495780630ec2e821146103f55780631280f724146104155780631de679661461043557806328068da3146104575761036b565b806301b1eb071461037057806309824a80146103925780630c6dd8c9146103c8575b600080fd5b34801561037c57600080fd5b5061039061038b3660046142a2565b6109e1565b005b34801561039e57600080fd5b506103b26103ad366004613ed7565b610b29565b6040516103bf9190615255565b60405180910390f35b3480156103d457600080fd5b506103e86103e3366004613ed7565b610c36565b6040516103bf91906148b2565b34801561040157600080fd5b50610390610410366004613ed7565b610daf565b34801561042157600080fd5b506103906104303660046142da565b610f4c565b34801561044157600080fd5b5061044a611016565b6040516103bf91906148a7565b34801561046357600080fd5b506103906104723660046140ef565b61101f565b34801561048357600080fd5b5061044a6104923660046143a7565b611174565b3480156104a357600080fd5b506103e86104b2366004613f0f565b6111b4565b3480156104c357600080fd5b506104d76104d2366004613f0f565b611223565b6040516103bf919061520e565b3480156104f057600080fd5b506104f9611292565b6040516103bf95949392919061530d565b610390610518366004614184565b6112de565b34801561052957600080fd5b506103e86113ef565b34801561053e57600080fd5b506103b26113f5565b34801561055357600080fd5b50610390611401565b34801561056857600080fd5b50610390610577366004614262565b6114e8565b34801561058857600080fd5b5061059c61059736600461436f565b611606565b6040516103bf9190614626565b3480156105b557600080fd5b506105be6116ac565b6040516103bf91906148f4565b3480156105d757600080fd5b5061044a6105e63660046141ce565b6116e3565b3480156105f757600080fd5b506103b2610606366004613ed7565b61171b565b34801561061757600080fd5b506103e8611728565b34801561062c57600080fd5b5061039061063b3660046143a7565b611739565b34801561064c57600080fd5b506103906118af565b34801561066157600080fd5b5061039061067036600461413f565b61196f565b34801561068157600080fd5b5061039061069036600461406e565b611b36565b3480156106a157600080fd5b506103e8611db6565b3480156106b657600080fd5b506103e8611dbc565b6103906106cd366004613f47565b611dc2565b3480156106de57600080fd5b5061044a6106ed366004613ed7565b611e9a565b3480156106fe57600080fd5b5061039061070d366004613f0f565b611f85565b34801561071e57600080fd5b5061059c612019565b34801561073357600080fd5b5061044a612035565b34801561074857600080fd5b5061044a6107573660046143a7565b612041565b34801561076857600080fd5b506103b261077736600461436f565b6120a2565b34801561078857600080fd5b50610390612189565b34801561079d57600080fd5b506107a6612331565b6040516103bf9190614e15565b3480156107bf57600080fd5b506103906107ce366004613f0f565b6123d1565b3480156107df57600080fd5b506103e8612600565b3480156107f457600080fd5b5061059c612606565b34801561080957600080fd5b5061081d61081836600461430e565b612622565b6040516103bf9190614dd6565b34801561083657600080fd5b5061044a612682565b34801561084b57600080fd5b5061085461268e565b6040516103bf9d9c9b9a99989796959493929190615266565b34801561087957600080fd5b506103e8610888366004613ed7565b612799565b34801561089957600080fd5b506103906108a83660046141f9565b6127c1565b3480156108b957600080fd5b506103906108c83660046141f9565b612859565b3480156108d957600080fd5b506103e86108e8366004613ed7565b612aaf565b3480156108f957600080fd5b5061059c610908366004613ffe565b612be6565b34801561091957600080fd5b506103906109283660046141ce565b612c79565b34801561093957600080fd5b5061059c612d95565b34801561094e57600080fd5b5061039061095d36600461433e565b612db1565b34801561096e57600080fd5b506104d761097d366004613ed7565b612e84565b34801561098e57600080fd5b506103e8612ecf565b3480156109a357600080fd5b506103906109b2366004613ed7565b612ed5565b3480156109c357600080fd5b506103e8612fe3565b3480156109d857600080fd5b5061044a61308a565b60025415610a24576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60405180910390fd5b600160025560005473ffffffffffffffffffffffffffffffffffffffff163314610a7a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b60225460ff1615158115151415610abd576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614a51565b602280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168215151790556040517f17d24aa44406852bec8b62a0f7e5aa1becf54dc52cfe7d6976325584cb51fc5b90610b199083906148a7565b60405180910390a1506000600255565b6000600254600014610b67576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002556000546040517f5ac783340000000000000000000000000000000000000000000000000000000081527352c0bc9fa4481ca8d43a74b4add792b2e15367c891635ac7833491610bdb91600391879173ffffffffffffffffffffffffffffffffffffffff16331490600401614f1d565b60206040518083038186803b158015610bf357600080fd5b505af4158015610c07573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2b919061438b565b600060025592915050565b600080610c446003846131e7565b9050600063ffffffff8216610cba5763ffffffff808316600090815260146020526040902054600854610cb39273ffffffffffffffffffffffffffffffffffffffff90911631917effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff169061327416565b9050610da8565b63ffffffff8216600090815260146020526040908190205460085491517f70a08231000000000000000000000000000000000000000000000000000000008152610da5927effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9092169173ffffffffffffffffffffffffffffffffffffffff808916926370a0823192610d4f921690600401614626565b60206040518083038186803b158015610d6757600080fd5b505afa158015610d7b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d9f9190614326565b90613274565b90505b9392505050565b60025415610de9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560005473ffffffffffffffffffffffffffffffffffffffff163314610e3f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b73ffffffffffffffffffffffffffffffffffffffff8116610e8c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614b2d565b60085473ffffffffffffffffffffffffffffffffffffffff1615610edc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614a1a565b600880547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83161790556040517f88d7f6699f4edd4606a19dfeb74ff4531bd8941e1a059fd431ddff444f7b035f90610b19908390614626565b60025415610f86576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002556040517fcae3c781000000000000000000000000000000000000000000000000000000008152736a4690ae65d020a61c99449a11bc02934f081b979063cae3c78190610fde90600390859060040161514c565b60006040518083038186803b158015610ff657600080fd5b505af415801561100a573d6000803e3d6000fd5b50506000600255505050565b60225460ff1681565b60025415611059576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002558361106881611e9a565b61109e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b60225460ff166110da576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614abf565b6008546040517ff18d03cc00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9091169063f18d03cc906111369088908890889088906004016146da565b600060405180830381600087803b15801561115057600080fd5b505af1158015611164573d6000803e3d6000fd5b5050600060025550505050505050565b6000806111826003846131e7565b63ffffffff808616600090815260176020908152604080832093909416825291909152205460ff169150505b92915050565b6000806111c26003846131e7565b73ffffffffffffffffffffffffffffffffffffffff8516600090815260186020908152604080832063ffffffff909416835292905220547effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1691505092915050565b6000806112316003846131e7565b73ffffffffffffffffffffffffffffffffffffffff85166000908152601a6020908152604080832063ffffffff909416835292905220547effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1691505092915050565b601e5463ffffffff8082169261ffff64010000000084048116936601000000000000810482169368010000000000000000820416926c0100000000000000000000000090910490911690565b60025415611318576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002558261132781611e9a565b61135d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b6040517f997f0d5f000000000000000000000000000000000000000000000000000000008152736a4690ae65d020a61c99449a11bc02934f081b979063997f0d5f906113b490600390889088908890600401614ee5565b60006040518083038186803b1580156113cc57600080fd5b505af41580156113e0573d6000803e3d6000fd5b50506000600255505050505050565b600e5490565b60035463ffffffff1690565b60015473ffffffffffffffffffffffffffffffffffffffff163314611452576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b6001546000805460405173ffffffffffffffffffffffffffffffffffffffff93841693909116917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a360018054600080547fffffffffffffffffffffffff000000000000000000000000000000000000000090811673ffffffffffffffffffffffffffffffffffffffff841617909155169055565b60025415611522576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560005473ffffffffffffffffffffffffffffffffffffffff163314611578576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b6040517f5ee5495b00000000000000000000000000000000000000000000000000000000815273615b953bad4cc5e1232976cd0205fa53d279b3de90635ee5495b906115cd9060039086908690600401614fbd565b60006040518083038186803b1580156115e557600080fd5b505af41580156115f9573d6000803e3d6000fd5b5050600060025550505050565b6040517fcb25fdbe0000000000000000000000000000000000000000000000000000000081526000907352c0bc9fa4481ca8d43a74b4add792b2e15367c89063cb25fdbe9061165c9060039086906004016151fa565b60206040518083038186803b15801561167457600080fd5b505af4158015611688573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111ae9190613ef3565b60408051808201909152600581527f302e312e30000000000000000000000000000000000000000000000000000000602082015290565b73ffffffffffffffffffffffffffffffffffffffff919091166000908152601b60209081526040808320938352929052205460ff1690565b60006111ae6003836131e7565b600061173460036132b6565b905090565b60025415611773576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560006117856003836131e7565b63ffffffff848116600090815260196020908152604080832093851683529290522080549192509074010000000000000000000000000000000000000000900467ffffffffffffffff16611805576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614c77565b805467ffffffffffffffff74010000000000000000000000000000000000000000909104166213c68001421015611868576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614c77565b4260208190556040517f5b8f5ce93a49fc6eab534327f9c77fd2966e16278d6135cc0d99e6b6450c79639161189c916148b2565b60405180910390a1505060006002555050565b60005473ffffffffffffffffffffffffffffffffffffffff163314611900576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b6000805460405173ffffffffffffffffffffffffffffffffffffffff909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b600254156119a9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560055473ffffffffffffffffffffffffffffffffffffffff161580156119d45750600e54155b611a0a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614907565b73ffffffffffffffffffffffffffffffffffffffff8316611a57576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614b2d565b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff85161790556040805160a08101909152600f606082019081527f4465476174652050726f746f636f6c00000000000000000000000000000000006080830152815273f9c1f624b13ffd90af9da0f83d233808cacab93790630f903da490600390879086908690611b169060208101611b086116ac565b8152306020909101526132c8565b6040518663ffffffff1660e01b81526004016113b4959493929190614f4b565b60025415611b70576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025585611b7f81611e9a565b611bb5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b73ffffffffffffffffffffffffffffffffffffffff8216611c02576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614d42565b6000611c0f6003876131e7565b73ffffffffffffffffffffffffffffffffffffffff8981166000908152601c602090815260408083208c85168452825280832063ffffffff80871685529083528184207effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8c1685528352818420908a1684529091529020549192501615611cc1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614cae565b73ffffffffffffffffffffffffffffffffffffffff8881166000908152601c602090815260408083208b85168452825280832063ffffffff86811685529083528184207effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8b168552835281842090891684529091529081902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001692861692909217909155517fbf71661a97663230b12613d9e77a7d73cd25efa46a80a34836ee240f02c5641390611d9f908a908a908a908a908a908a9061466e565b60405180910390a150506000600255505050505050565b60115490565b600a5490565b60025415611dfc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025585611e0b81611e9a565b611e41576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b611e8c8787878787878080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506003979695949392505061333f9050565b505060006002555050505050565b600073ffffffffffffffffffffffffffffffffffffffff82163314806111ae575060075473ffffffffffffffffffffffffffffffffffffffff16158015906111ae57506007546040517f4ebf59d200000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff90911690634ebf59d290611f359085903390600401614647565b60206040518083038186803b158015611f4d57600080fd5b505afa158015611f61573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111ae91906142be565b60025415611fbf576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002556040517f95d75555000000000000000000000000000000000000000000000000000000008152736a4690ae65d020a61c99449a11bc02934f081b97906395d75555906115cd9060039086908690600401614eb9565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b600061173460036138ff565b60008061204f6003846131e7565b63ffffffff808616600090815260196020908152604080832093909416825291909152205467ffffffffffffffff7401000000000000000000000000000000000000000090910416151591505092915050565b60006002546000146120e0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560005473ffffffffffffffffffffffffffffffffffffffff163314612136576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b6040517f1854b85c000000000000000000000000000000000000000000000000000000008152732375bbb012c378a0df56da7b947067a76372ec0a90631854b85c90610bdb9060039086906004016151fa565b600254156121c3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002556121d260036138ff565b1561232a576005546040517f883515c100000000000000000000000000000000000000000000000000000000815260009173ffffffffffffffffffffffffffffffffffffffff169063883515c19061222e903090600401614626565b60206040518083038186803b15801561224657600080fd5b505afa15801561225a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061227e9190614326565b6005546040517fc51c820800000000000000000000000000000000000000000000000000000000815291925073ffffffffffffffffffffffffffffffffffffffff169063c51c8208906122d59084906004016148b2565b602060405180830381600087803b1580156122ef57600080fd5b505af1158015612303573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123279190614326565b50505b6000600255565b612339613df6565b5060408051610180810182527f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f00000018152620f424060208201526213c68091810182905262093a80606082018190526401000000006080830181905260a083015260c082015262278d0060e082015260536101008201526101208101919091526703782dace9d90000610140820152601261016082015290565b6002541561240b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560005473ffffffffffffffffffffffffffffffffffffffff163314612461576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b73ffffffffffffffffffffffffffffffffffffffff81166124ae576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b9061493e565b73ffffffffffffffffffffffffffffffffffffffff82166124f457476124ed815a73ffffffffffffffffffffffffffffffffffffffff85169190613908565b50506125be565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815260009073ffffffffffffffffffffffffffffffffffffffff8416906370a0823190612549903090600401614626565b60206040518083038186803b15801561256157600080fd5b505afa158015612575573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125999190614326565b90506125bc73ffffffffffffffffffffffffffffffffffffffff84168383613964565b505b7faa34b6f2263f4f4931586178b8e2d225effbfae46a95b5c56c6c641a8a21f62982826040516125ef929190614647565b60405180910390a150506000600255565b600f5490565b60085473ffffffffffffffffffffffffffffffffffffffff1690565b61262a613e57565b5060009081526010602090815260409182902082518084019093525463ffffffff811683526401000000009004811b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000169082015290565b60006117346003613975565b6003546004546005546006546007546008546040805160a080820183526009548252600a54602080840191909152600b5483850152600c54606080850191909152600d54608080860191909152600e54600f54601154601d5489519788018a52601e5463ffffffff8181168a5261ffff640100000000830481168b8b01526601000000000000830481168b8e01526801000000000000000083048216988b01989098526c01000000000000000000000000909104909616948801949094528851808a01909952601f5489528554958901959095529c83169c73ffffffffffffffffffffffffffffffffffffffff9b8c169b9a8b169a998a16999890981697959690959491909216918d565b73ffffffffffffffffffffffffffffffffffffffff1660009081526021602052604090205490565b600254156127fb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002556040517ff460cca9000000000000000000000000000000000000000000000000000000008152736a4690ae65d020a61c99449a11bc02934f081b979063f460cca9906113b4906003908890889088908890600401614f84565b60025415612893576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002558281146128d1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614d42565b6007546040517f2eac95f100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff90911690632eac95f19061292b90879087903390600401614807565b60206040518083038186803b15801561294357600080fd5b505afa158015612957573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061297b91906142be565b6129b1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b60005b83811015612a79576001601b60008787858181106129ce57fe5b90506020020160208101906129e39190613ed7565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000858585818110612a2b57fe5b6020908102929092013583525081019190915260400160002080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169115159190911790556001016129b4565b507fe548a963a45d48f7887098ee1903d1291c4bef5b33e4fa75fced37e24b3a20da8484848460405161189c9493929190614841565b6000600254600014612aed576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560005473ffffffffffffffffffffffffffffffffffffffff163314612b43576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b6040517ff93234a2000000000000000000000000000000000000000000000000000000008152732375bbb012c378a0df56da7b947067a76372ec0a9063f93234a290612b96906003908690600401614e95565b60206040518083038186803b158015612bae57600080fd5b505af4158015612bc2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2b9190614326565b600080612bf46003866131e7565b73ffffffffffffffffffffffffffffffffffffffff8089166000908152601c602090815260408083208b85168452825280832063ffffffff958616845282528083207effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8a1684528252808320948816835293905291909120541691505095945050505050565b60025415612cb3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025581612cc281611e9a565b612cf8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b73ffffffffffffffffffffffffffffffffffffffff83166000908152601b602090815260408083208584529091529081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055517f7115b98931e7aca6d0aa11d10fe28877316a661a44c4bfc93c76b19dbbf5b10790612d8390859085906147e1565b60405180910390a15050600060025550565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b60025415612deb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560005473ffffffffffffffffffffffffffffffffffffffff163314612e41576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b612e4f60038585858561397e565b7fd5ed9d44b4e70b483ebc5cb0f4b40468805a9cb2f9249d0201d77ef64d6368828484848460405161189c949392919061523a565b600080612e926003846131e7565b63ffffffff166000908152601460205260409020547effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff169392505050565b60045490565b60005473ffffffffffffffffffffffffffffffffffffffff163314612f26576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b73ffffffffffffffffffffffffffffffffffffffff811615801590612f66575060005473ffffffffffffffffffffffffffffffffffffffff828116911614155b612f9c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b9061493e565b600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b6005546040517f883515c100000000000000000000000000000000000000000000000000000000815260009173ffffffffffffffffffffffffffffffffffffffff169063883515c19061303a903090600401614626565b60206040518083038186803b15801561305257600080fd5b505afa158015613066573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117349190614326565b60006002546000146130c8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560005473ffffffffffffffffffffffffffffffffffffffff16331461311e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b61312860036138ff565b1561315f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614b64565b6131696003613975565b156131a0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614b9b565b42601f8190556040517f574214b195bf5273a95bb4498e35cf1fde0ce327c727a95ec2ab359f7ba4e11a916131d4916148b2565b60405180910390a1506001600060025590565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260128301602052604090205463ffffffff168061324c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614bd2565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0192915050565b6000828211156132b0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614af6565b50900390565b601a015463ffffffff16620f42400390565b6000804690507f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8360000151805190602001208460200151805190602001208386604001516040516020016133219594939291906148bb565b60405160208183030381529060405280519060200120915050919050565b73ffffffffffffffffffffffffffffffffffffffff841661338c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614b2d565b600080613399888661399b565b915091508061344a576040517f5ac783340000000000000000000000000000000000000000000000000000000081527352c0bc9fa4481ca8d43a74b4add792b2e15367c890635ac78334906133f7908b908990600090600401614f1d565b60206040518083038186803b15801561340f57600080fd5b505af4158015613423573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613447919061438b565b91505b63ffffffff821615801561347d57507effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8416155b156134ba5734156134ba576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149e3565b60006134c589613a07565b156135095750600a8801546040517f12197207b0a54de931fdf21dc8066c293dc29b9dd4875c6b64a36c6a36ff9040906135009083906148b2565b60405180910390a15b80341015613543576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614c40565b60058901546040517f5e1da861000000000000000000000000000000000000000000000000000000008152348390039160009173ffffffffffffffffffffffffffffffffffffffff90911690635e1da8619084906135ab908e908d908d908d90600401614777565b6020604051808303818588803b1580156135c457600080fd5b505af11580156135d8573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906135fd91906142f2565b9050613607613e57565b5073ffffffffffffffffffffffffffffffffffffffff8916600090815260178c016020908152604080832063ffffffff808a168552908352928190208151808301909252547effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff168082524267ffffffffffffffff16928201929092529161369091908490613a9716565b81600001907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1690817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1681525050808c60170160008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008863ffffffff1663ffffffff16815260200190815260200160002060008201518160000160006101000a8154817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff02191690837effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff16021790555060208201518160010160006101000a81548167ffffffffffffffff021916908367ffffffffffffffff16021790555090505061384b828d60110160008963ffffffff1663ffffffff16815260200190815260200160002060009054906101000a90047effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff16613a9790919063ffffffff16565b63ffffffff8716600090815260118e0160205260409081902080547fff00000000000000000000000000000000000000000000000000000000000000167effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9390931692909217909155517f5cc43c6b47c350258362c540eb61d09c2060eaa8b760707b2892d08a01f6e9c3906138e9908d908d908d908b908890614711565b60405180910390a1505050505050505050505050565b601d0154151590565b600061392b73ffffffffffffffffffffffffffffffffffffffff85168484613af8565b905080610da8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614a88565b6139708383835a613b9f565b505050565b601c0154151590565b600685019390935560078401919091556009830155600a90910155565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260128301602052604081205463ffffffff1690816139da57506000905080613a00565b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0160015b9250929050565b6009810154600882015460009182918291613a3d91613a329190613a2c904390613274565b90613be7565b600786015490613c35565b6006850154909150811115613a53575060068301545b8015613a80577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01613a85565b600191505b60078401554360088401559050919050565b8181017effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80841690821610156111ae576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614c09565b600082613b0757506001610da8565b6000613b288573ffffffffffffffffffffffffffffffffffffffff16613c72565b90508073ffffffffffffffffffffffffffffffffffffffff16848490604051613b5090613c72565b600060405180830381858888f193505050503d8060008114613b8e576040519150601f19603f3d011682016040523d82523d6000602084013e613b93565b606091505b50909695505050505050565b613bab84848484613c75565b613be1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614a88565b50505050565b818102821580613bff575081838281613bfc57fe5b04145b6111ae576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614d0b565b818101828110156111ae576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614c09565b90565b6000613c8085613db5565b613cb6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614d79565b606063a9059cbb60e01b8585604051602401613cd39291906147e1565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050905060008673ffffffffffffffffffffffffffffffffffffffff168483604051613d5a919061460a565b60006040518083038160008787f1925050503d8060008114613d98576040519150601f19603f3d011682016040523d82523d6000602084013e613d9d565b606091505b50509050613daa81613dbb565b979650505050505050565b3b151590565b60008115613df2573d8015613ddb5760208114613de45760009250613df0565b60019250613df0565b60206000803e60005192505b505b5090565b6040518061018001604052806000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b604080518082019091526000808252602082015290565b80356111ae816153fc565b60008083601f840112613e8a578182fd5b50813567ffffffffffffffff811115613ea1578182fd5b6020830191508360208083028501011115613a0057600080fd5b80356111ae8161545c565b803560ff811681146111ae57600080fd5b600060208284031215613ee8578081fd5b8135610da8816153fc565b600060208284031215613f04578081fd5b8151610da8816153fc565b60008060408385031215613f21578081fd5b8235613f2c816153fc565b91506020830135613f3c816153fc565b809150509250929050565b60008060008060008060a08789031215613f5f578182fd5b8635613f6a816153fc565b95506020870135613f7a816153fc565b94506040870135613f8a816153fc565b93506060870135613f9a8161542f565b9250608087013567ffffffffffffffff80821115613fb6578384fd5b818901915089601f830112613fc9578384fd5b813581811115613fd7578485fd5b8a6020828501011115613fe8578485fd5b6020830194508093505050509295509295509295565b600080600080600060a08688031215614015578081fd5b8535614020816153fc565b94506020860135614030816153fc565b93506040860135614040816153fc565b925060608601356140508161542f565b915060808601356140608161545c565b809150509295509295909350565b60008060008060008060c08789031215614086578182fd5b8635614091816153fc565b955060208701356140a1816153fc565b945060408701356140b1816153fc565b935060608701356140c18161542f565b925060808701356140d18161545c565b915060a08701356140e1816153fc565b809150509295509295509295565b60008060008060808587031215614104578182fd5b843561410f816153fc565b9350602085013561411f816153fc565b9250604085013561412f816153fc565b9396929550929360600135925050565b60008060008060808587031215614154578182fd5b843561415f816153fc565b9350602085013561416f816153fc565b93969395505050506040820135916060013590565b600080600060608486031215614198578081fd5b83356141a3816153fc565b925060208401356141b3816153fc565b915060408401356141c38161545c565b809150509250925092565b600080604083850312156141e0578182fd5b82356141eb816153fc565b946020939093013593505050565b6000806000806040858703121561420e578182fd5b843567ffffffffffffffff80821115614225578384fd5b61423188838901613e79565b90965094506020870135915080821115614249578384fd5b5061425687828801613e79565b95989497509550505050565b60008060208385031215614274578182fd5b823567ffffffffffffffff81111561428a578283fd5b61429685828601613e79565b90969095509350505050565b6000602082840312156142b3578081fd5b8135610da881615421565b6000602082840312156142cf578081fd5b8151610da881615421565b6000610ce082840312156142ec578081fd5b50919050565b600060208284031215614303578081fd5b8151610da88161542f565b60006020828403121561431f578081fd5b5035919050565b600060208284031215614337578081fd5b5051919050565b60008060008060808587031215614353578182fd5b5050823594602084013594506040840135936060013592509050565b600060208284031215614380578081fd5b8135610da88161545c565b60006020828403121561439c578081fd5b8151610da88161545c565b600080604083850312156143b9578182fd5b8235613f2c8161545c565b60008284526020808501945082825b8581101561440e5781356143e6816153fc565b73ffffffffffffffffffffffffffffffffffffffff16875295820195908201906001016143d3565b509495945050505050565b60008284526020808501945082825b8581101561440e57813561443b816153fc565b73ffffffffffffffffffffffffffffffffffffffff1687529582019590820190600101614428565b61060080828437600081840152505050565b61010080828437600081840152505050565b15159052565b600082845282826020860137806020848601015260207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f85011685010190509392505050565b600081518084526144ed8160208601602086016153d0565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b803561452a8161545c565b63ffffffff16825260208101356145408161542f565b7effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81166020840152505050565b80518252602081015160208301526040810151604083015260608101516060830152608081015160808301525050565b80518252602090810151910152565b63ffffffff808251168352602082015161ffff80821660208601528060408501511660408601528260608501511660608601528060808501511660808601525050505050565b61ffff169052565b63ffffffff169052565b60ff169052565b6000825161461c8184602087016153d0565b9190910192915050565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff9687168152948616602086015292851660408501527effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff91909116606084015263ffffffff16608083015290911660a082015260c00190565b73ffffffffffffffffffffffffffffffffffffffff9485168152928416602084015292166040820152606081019190915260800190565b73ffffffffffffffffffffffffffffffffffffffff9586168152938516602085015291909316604083015263ffffffff90921660608201527effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff909116608082015260a00190565b600073ffffffffffffffffffffffffffffffffffffffff80871683528086166020840152507effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff84166040830152608060608301526147d760808301846144d5565b9695505050505050565b73ffffffffffffffffffffffffffffffffffffffff929092168252602082015260400190565b60006040825261481b6040830185876143c4565b905073ffffffffffffffffffffffffffffffffffffffff83166020830152949350505050565b6000604082526148556040830186886143c4565b82810360208401528381527f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff84111561488c578182fd5b60208402808660208401370160200190815295945050505050565b901515815260200190565b90815260200190565b94855260208501939093526040840191909152606083015273ffffffffffffffffffffffffffffffffffffffff16608082015260a00190565b600060208252610da860208301846144d5565b6020808252600b908201527f494e495449414c495a4544000000000000000000000000000000000000000000604082015260600190565b6020808252600f908201527f494e56414c49445f414444524553530000000000000000000000000000000000604082015260600190565b6020808252600a908201527f5245454e5452414e435900000000000000000000000000000000000000000000604082015260600190565b6020808252600c908201527f554e415554484f52495a45440000000000000000000000000000000000000000604082015260600190565b60208082526013908201527f494e56414c49445f4554485f4445504f53495400000000000000000000000000604082015260600190565b6020808252600b908201527f414c52454144595f534554000000000000000000000000000000000000000000604082015260600190565b6020808252600a908201527f53414d455f56414c554500000000000000000000000000000000000000000000604082015260600190565b60208082526010908201527f5452414e534645525f4641494c55524500000000000000000000000000000000604082015260600190565b6020808252600b908201527f4e4f545f414c4c4f574544000000000000000000000000000000000000000000604082015260600190565b6020808252600d908201527f5355425f554e444552464c4f5700000000000000000000000000000000000000604082015260600190565b6020808252600c908201527f5a45524f5f414444524553530000000000000000000000000000000000000000604082015260600190565b6020808252600c908201527f494e56414c49445f4d4f44450000000000000000000000000000000000000000604082015260600190565b60208082526010908201527f414c52454144595f53485554444f574e00000000000000000000000000000000604082015260600190565b6020808252600f908201527f544f4b454e5f4e4f545f464f554e440000000000000000000000000000000000604082015260600190565b6020808252600c908201527f4144445f4f564552464c4f570000000000000000000000000000000000000000604082015260600190565b60208082526018908201527f494e53554646494349454e545f4445504f5349545f4645450000000000000000604082015260600190565b60208082526016908201527f5749544844524157414c5f4e4f545f544f4f5f4f4c4400000000000000000000604082015260600190565b60208082526021908201527f43414e4e4f545f4f564552524944455f524543495049454e545f41444452455360408201527f5300000000000000000000000000000000000000000000000000000000000000606082015260800190565b6020808252600c908201527f4d554c5f4f564552464c4f570000000000000000000000000000000000000000604082015260600190565b6020808252600c908201527f494e56414c49445f444154410000000000000000000000000000000000000000604082015260600190565b60208082526027908201527f4552433230536166655472616e736665723a2063616c6c20746f206e6f6e2d6360408201527f6f6e747261637400000000000000000000000000000000000000000000000000606082015260800190565b815163ffffffff1681526020918201517fffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000169181019190915260400190565b815181526020808301519082015260408083015190820152606080830151908201526080808301519082015260a0808301519082015260c0808301519082015260e0808301519082015261010080830151908201526101208083015190820152610140808301519082015261016091820151918101919091526101800190565b91825273ffffffffffffffffffffffffffffffffffffffff16602082015260400190565b92835273ffffffffffffffffffffffffffffffffffffffff918216602084015216604082015260600190565b93845273ffffffffffffffffffffffffffffffffffffffff92831660208501529116604083015263ffffffff16606082015260800190565b92835273ffffffffffffffffffffffffffffffffffffffff9190911660208301521515604082015260600190565b94855273ffffffffffffffffffffffffffffffffffffffff93909316602085015260408401919091526060830152608082015260a00190565b600086825260606020830152614f9e606083018688614419565b8281036040840152614fb1818587614419565b98975050505050505050565b83815260406020808301829052828201849052600091906060908185018682028601830188865b8981101561513c577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa089840301845281357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe218c3603018112615044578889fd5b8b016101e086820160ff6150588285613ec6565b16865261506581846153ae565b9050615073888701826145f1565b50615080898301836153c1565b61508c8a870182614603565b506150998883018361534b565b828a8801526150ab838801828461448d565b9250505060806150bf818701828501614475565b506101806150cf8184018461533e565b6150db82880182614487565b50506101a06150ec8184018461534b565b878403838901526150fe84828461448d565b93505050506101c06151128184018461534b565b93508683038288015261512683858361448d565b9789019796505050928601925050600101614fe4565b50909a9950505050505050505050565b828152610d008101823561515f8161545c565b63ffffffff81166020840152506040830173ffffffffffffffffffffffffffffffffffffffff6151928260208701613e6e565b16604084015280356060840152506060830135608083015260a083016151bb8160808601613ebb565b6151c860a08501826145f9565b506151d660c084018261451f565b506151e8610100830160e08501614463565b610da861070083016106e08501614463565b91825263ffffffff16602082015260400190565b7effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff91909116815260200190565b93845260208401929092526040830152606082015260800190565b63ffffffff91909116815260200190565b63ffffffff8e168152602081018d905273ffffffffffffffffffffffffffffffffffffffff8c811660408301528b811660608301528a81166080830152891660a08201526102c081016152bc60c083018a61456c565b8761016083015286610180830152856101a08301526152df6101c08301866145f9565b6152ed6101e08301856145ab565b6152fb61028083018461459c565b9e9d5050505050505050505050505050565b63ffffffff958616815261ffff94851660208201529284166040840152931660608201529116608082015260a00190565b60008235610da881615421565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261537f578283fd5b830160208101925035905067ffffffffffffffff81111561539f57600080fd5b803603831315613a0057600080fd5b6000823561ffff81168114610da8578182fd5b6000610da86020840184613ec6565b60005b838110156153eb5781810151838201526020016153d3565b83811115613be15750506000910152565b73ffffffffffffffffffffffffffffffffffffffff8116811461541e57600080fd5b50565b801515811461541e57600080fd5b7effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8116811461541e57600080fd5b63ffffffff8116811461541e57600080fdfea264697066735822122095271289a8b1b9ad9caf850e53e6d44c615b95e6063944cc48f80d250a8489a564736f6c63430007000033

Deployed Bytecode

0x60806040526004361061036b5760003560e01c80638a554abe116101c6578063c8e26cae116100f7578063e795799211610095578063f2fde38b1161006f578063f2fde38b14610997578063f698da2514610982578063f732e021146109b7578063fc0e74d1146109cc5761036b565b8063e795799214610942578063ed05ae7814610962578063ed24911d146109825761036b565b8063ce2ec5de116100d1578063ce2ec5de146108cd578063cea69b86146108ed578063d59acd251461090d578063e30c39781461092d5761036b565b8063c8e26cae1461086d578063cd097b4f1461088d578063cdb1b44b146108ad5761036b565b80639a295e7311610164578063ab94276a1161013e578063ab94276a146107e8578063bb141cf4146107fd578063bf86d6901461082a578063c19d93fb1461083f5761036b565b80639a295e7314610791578063a75f8a4e146107b3578063a7bff050146107d35761036b565b806391b11ad4116101a057806391b11ad41461072757806392f54afc1461073c578063960af2d91461075c578063972f75651461077c5761036b565b80638a554abe146106d25780638d2a8888146106f25780638da5cb5b146107125761036b565b80634e71e0c8116102a057806370f30de31161023e5780637907140e116102185780637907140e146106755780637bb96acb146106955780637beefcd4146106aa5780638070f2ca146106bf5761036b565b806370f30de314610620578063715018a61461064057806376cfcff6146106555761036b565b806354fd4d501161027a57806354fd4d50146105a95780636008cd1f146105cb57806363f8071c146105eb57806369b914321461060b5761036b565b80634e71e0c814610547578063532284301461055c578063543d7a191461057c5761036b565b80632c3d356b1161030d5780634597d3ce116102e75780634597d3ce146104e457806347b67d051461050a578063495906571461051d5780634a14cd84146105325761036b565b80632c3d356b146104775780632fa5825f14610497578063438c2a42146104b75761036b565b80630ec2e821116103495780630ec2e821146103f55780631280f724146104155780631de679661461043557806328068da3146104575761036b565b806301b1eb071461037057806309824a80146103925780630c6dd8c9146103c8575b600080fd5b34801561037c57600080fd5b5061039061038b3660046142a2565b6109e1565b005b34801561039e57600080fd5b506103b26103ad366004613ed7565b610b29565b6040516103bf9190615255565b60405180910390f35b3480156103d457600080fd5b506103e86103e3366004613ed7565b610c36565b6040516103bf91906148b2565b34801561040157600080fd5b50610390610410366004613ed7565b610daf565b34801561042157600080fd5b506103906104303660046142da565b610f4c565b34801561044157600080fd5b5061044a611016565b6040516103bf91906148a7565b34801561046357600080fd5b506103906104723660046140ef565b61101f565b34801561048357600080fd5b5061044a6104923660046143a7565b611174565b3480156104a357600080fd5b506103e86104b2366004613f0f565b6111b4565b3480156104c357600080fd5b506104d76104d2366004613f0f565b611223565b6040516103bf919061520e565b3480156104f057600080fd5b506104f9611292565b6040516103bf95949392919061530d565b610390610518366004614184565b6112de565b34801561052957600080fd5b506103e86113ef565b34801561053e57600080fd5b506103b26113f5565b34801561055357600080fd5b50610390611401565b34801561056857600080fd5b50610390610577366004614262565b6114e8565b34801561058857600080fd5b5061059c61059736600461436f565b611606565b6040516103bf9190614626565b3480156105b557600080fd5b506105be6116ac565b6040516103bf91906148f4565b3480156105d757600080fd5b5061044a6105e63660046141ce565b6116e3565b3480156105f757600080fd5b506103b2610606366004613ed7565b61171b565b34801561061757600080fd5b506103e8611728565b34801561062c57600080fd5b5061039061063b3660046143a7565b611739565b34801561064c57600080fd5b506103906118af565b34801561066157600080fd5b5061039061067036600461413f565b61196f565b34801561068157600080fd5b5061039061069036600461406e565b611b36565b3480156106a157600080fd5b506103e8611db6565b3480156106b657600080fd5b506103e8611dbc565b6103906106cd366004613f47565b611dc2565b3480156106de57600080fd5b5061044a6106ed366004613ed7565b611e9a565b3480156106fe57600080fd5b5061039061070d366004613f0f565b611f85565b34801561071e57600080fd5b5061059c612019565b34801561073357600080fd5b5061044a612035565b34801561074857600080fd5b5061044a6107573660046143a7565b612041565b34801561076857600080fd5b506103b261077736600461436f565b6120a2565b34801561078857600080fd5b50610390612189565b34801561079d57600080fd5b506107a6612331565b6040516103bf9190614e15565b3480156107bf57600080fd5b506103906107ce366004613f0f565b6123d1565b3480156107df57600080fd5b506103e8612600565b3480156107f457600080fd5b5061059c612606565b34801561080957600080fd5b5061081d61081836600461430e565b612622565b6040516103bf9190614dd6565b34801561083657600080fd5b5061044a612682565b34801561084b57600080fd5b5061085461268e565b6040516103bf9d9c9b9a99989796959493929190615266565b34801561087957600080fd5b506103e8610888366004613ed7565b612799565b34801561089957600080fd5b506103906108a83660046141f9565b6127c1565b3480156108b957600080fd5b506103906108c83660046141f9565b612859565b3480156108d957600080fd5b506103e86108e8366004613ed7565b612aaf565b3480156108f957600080fd5b5061059c610908366004613ffe565b612be6565b34801561091957600080fd5b506103906109283660046141ce565b612c79565b34801561093957600080fd5b5061059c612d95565b34801561094e57600080fd5b5061039061095d36600461433e565b612db1565b34801561096e57600080fd5b506104d761097d366004613ed7565b612e84565b34801561098e57600080fd5b506103e8612ecf565b3480156109a357600080fd5b506103906109b2366004613ed7565b612ed5565b3480156109c357600080fd5b506103e8612fe3565b3480156109d857600080fd5b5061044a61308a565b60025415610a24576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60405180910390fd5b600160025560005473ffffffffffffffffffffffffffffffffffffffff163314610a7a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b60225460ff1615158115151415610abd576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614a51565b602280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168215151790556040517f17d24aa44406852bec8b62a0f7e5aa1becf54dc52cfe7d6976325584cb51fc5b90610b199083906148a7565b60405180910390a1506000600255565b6000600254600014610b67576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002556000546040517f5ac783340000000000000000000000000000000000000000000000000000000081527352c0bc9fa4481ca8d43a74b4add792b2e15367c891635ac7833491610bdb91600391879173ffffffffffffffffffffffffffffffffffffffff16331490600401614f1d565b60206040518083038186803b158015610bf357600080fd5b505af4158015610c07573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2b919061438b565b600060025592915050565b600080610c446003846131e7565b9050600063ffffffff8216610cba5763ffffffff808316600090815260146020526040902054600854610cb39273ffffffffffffffffffffffffffffffffffffffff90911631917effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff169061327416565b9050610da8565b63ffffffff8216600090815260146020526040908190205460085491517f70a08231000000000000000000000000000000000000000000000000000000008152610da5927effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9092169173ffffffffffffffffffffffffffffffffffffffff808916926370a0823192610d4f921690600401614626565b60206040518083038186803b158015610d6757600080fd5b505afa158015610d7b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d9f9190614326565b90613274565b90505b9392505050565b60025415610de9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560005473ffffffffffffffffffffffffffffffffffffffff163314610e3f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b73ffffffffffffffffffffffffffffffffffffffff8116610e8c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614b2d565b60085473ffffffffffffffffffffffffffffffffffffffff1615610edc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614a1a565b600880547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83161790556040517f88d7f6699f4edd4606a19dfeb74ff4531bd8941e1a059fd431ddff444f7b035f90610b19908390614626565b60025415610f86576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002556040517fcae3c781000000000000000000000000000000000000000000000000000000008152736a4690ae65d020a61c99449a11bc02934f081b979063cae3c78190610fde90600390859060040161514c565b60006040518083038186803b158015610ff657600080fd5b505af415801561100a573d6000803e3d6000fd5b50506000600255505050565b60225460ff1681565b60025415611059576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002558361106881611e9a565b61109e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b60225460ff166110da576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614abf565b6008546040517ff18d03cc00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9091169063f18d03cc906111369088908890889088906004016146da565b600060405180830381600087803b15801561115057600080fd5b505af1158015611164573d6000803e3d6000fd5b5050600060025550505050505050565b6000806111826003846131e7565b63ffffffff808616600090815260176020908152604080832093909416825291909152205460ff169150505b92915050565b6000806111c26003846131e7565b73ffffffffffffffffffffffffffffffffffffffff8516600090815260186020908152604080832063ffffffff909416835292905220547effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1691505092915050565b6000806112316003846131e7565b73ffffffffffffffffffffffffffffffffffffffff85166000908152601a6020908152604080832063ffffffff909416835292905220547effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1691505092915050565b601e5463ffffffff8082169261ffff64010000000084048116936601000000000000810482169368010000000000000000820416926c0100000000000000000000000090910490911690565b60025415611318576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002558261132781611e9a565b61135d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b6040517f997f0d5f000000000000000000000000000000000000000000000000000000008152736a4690ae65d020a61c99449a11bc02934f081b979063997f0d5f906113b490600390889088908890600401614ee5565b60006040518083038186803b1580156113cc57600080fd5b505af41580156113e0573d6000803e3d6000fd5b50506000600255505050505050565b600e5490565b60035463ffffffff1690565b60015473ffffffffffffffffffffffffffffffffffffffff163314611452576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b6001546000805460405173ffffffffffffffffffffffffffffffffffffffff93841693909116917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a360018054600080547fffffffffffffffffffffffff000000000000000000000000000000000000000090811673ffffffffffffffffffffffffffffffffffffffff841617909155169055565b60025415611522576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560005473ffffffffffffffffffffffffffffffffffffffff163314611578576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b6040517f5ee5495b00000000000000000000000000000000000000000000000000000000815273615b953bad4cc5e1232976cd0205fa53d279b3de90635ee5495b906115cd9060039086908690600401614fbd565b60006040518083038186803b1580156115e557600080fd5b505af41580156115f9573d6000803e3d6000fd5b5050600060025550505050565b6040517fcb25fdbe0000000000000000000000000000000000000000000000000000000081526000907352c0bc9fa4481ca8d43a74b4add792b2e15367c89063cb25fdbe9061165c9060039086906004016151fa565b60206040518083038186803b15801561167457600080fd5b505af4158015611688573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111ae9190613ef3565b60408051808201909152600581527f302e312e30000000000000000000000000000000000000000000000000000000602082015290565b73ffffffffffffffffffffffffffffffffffffffff919091166000908152601b60209081526040808320938352929052205460ff1690565b60006111ae6003836131e7565b600061173460036132b6565b905090565b60025415611773576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560006117856003836131e7565b63ffffffff848116600090815260196020908152604080832093851683529290522080549192509074010000000000000000000000000000000000000000900467ffffffffffffffff16611805576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614c77565b805467ffffffffffffffff74010000000000000000000000000000000000000000909104166213c68001421015611868576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614c77565b4260208190556040517f5b8f5ce93a49fc6eab534327f9c77fd2966e16278d6135cc0d99e6b6450c79639161189c916148b2565b60405180910390a1505060006002555050565b60005473ffffffffffffffffffffffffffffffffffffffff163314611900576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b6000805460405173ffffffffffffffffffffffffffffffffffffffff909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b600254156119a9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560055473ffffffffffffffffffffffffffffffffffffffff161580156119d45750600e54155b611a0a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614907565b73ffffffffffffffffffffffffffffffffffffffff8316611a57576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614b2d565b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff85161790556040805160a08101909152600f606082019081527f4465476174652050726f746f636f6c00000000000000000000000000000000006080830152815273f9c1f624b13ffd90af9da0f83d233808cacab93790630f903da490600390879086908690611b169060208101611b086116ac565b8152306020909101526132c8565b6040518663ffffffff1660e01b81526004016113b4959493929190614f4b565b60025415611b70576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025585611b7f81611e9a565b611bb5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b73ffffffffffffffffffffffffffffffffffffffff8216611c02576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614d42565b6000611c0f6003876131e7565b73ffffffffffffffffffffffffffffffffffffffff8981166000908152601c602090815260408083208c85168452825280832063ffffffff80871685529083528184207effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8c1685528352818420908a1684529091529020549192501615611cc1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614cae565b73ffffffffffffffffffffffffffffffffffffffff8881166000908152601c602090815260408083208b85168452825280832063ffffffff86811685529083528184207effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8b168552835281842090891684529091529081902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001692861692909217909155517fbf71661a97663230b12613d9e77a7d73cd25efa46a80a34836ee240f02c5641390611d9f908a908a908a908a908a908a9061466e565b60405180910390a150506000600255505050505050565b60115490565b600a5490565b60025415611dfc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025585611e0b81611e9a565b611e41576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b611e8c8787878787878080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506003979695949392505061333f9050565b505060006002555050505050565b600073ffffffffffffffffffffffffffffffffffffffff82163314806111ae575060075473ffffffffffffffffffffffffffffffffffffffff16158015906111ae57506007546040517f4ebf59d200000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff90911690634ebf59d290611f359085903390600401614647565b60206040518083038186803b158015611f4d57600080fd5b505afa158015611f61573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111ae91906142be565b60025415611fbf576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002556040517f95d75555000000000000000000000000000000000000000000000000000000008152736a4690ae65d020a61c99449a11bc02934f081b97906395d75555906115cd9060039086908690600401614eb9565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b600061173460036138ff565b60008061204f6003846131e7565b63ffffffff808616600090815260196020908152604080832093909416825291909152205467ffffffffffffffff7401000000000000000000000000000000000000000090910416151591505092915050565b60006002546000146120e0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560005473ffffffffffffffffffffffffffffffffffffffff163314612136576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b6040517f1854b85c000000000000000000000000000000000000000000000000000000008152732375bbb012c378a0df56da7b947067a76372ec0a90631854b85c90610bdb9060039086906004016151fa565b600254156121c3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002556121d260036138ff565b1561232a576005546040517f883515c100000000000000000000000000000000000000000000000000000000815260009173ffffffffffffffffffffffffffffffffffffffff169063883515c19061222e903090600401614626565b60206040518083038186803b15801561224657600080fd5b505afa15801561225a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061227e9190614326565b6005546040517fc51c820800000000000000000000000000000000000000000000000000000000815291925073ffffffffffffffffffffffffffffffffffffffff169063c51c8208906122d59084906004016148b2565b602060405180830381600087803b1580156122ef57600080fd5b505af1158015612303573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123279190614326565b50505b6000600255565b612339613df6565b5060408051610180810182527f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f00000018152620f424060208201526213c68091810182905262093a80606082018190526401000000006080830181905260a083015260c082015262278d0060e082015260536101008201526101208101919091526703782dace9d90000610140820152601261016082015290565b6002541561240b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560005473ffffffffffffffffffffffffffffffffffffffff163314612461576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b73ffffffffffffffffffffffffffffffffffffffff81166124ae576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b9061493e565b73ffffffffffffffffffffffffffffffffffffffff82166124f457476124ed815a73ffffffffffffffffffffffffffffffffffffffff85169190613908565b50506125be565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815260009073ffffffffffffffffffffffffffffffffffffffff8416906370a0823190612549903090600401614626565b60206040518083038186803b15801561256157600080fd5b505afa158015612575573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125999190614326565b90506125bc73ffffffffffffffffffffffffffffffffffffffff84168383613964565b505b7faa34b6f2263f4f4931586178b8e2d225effbfae46a95b5c56c6c641a8a21f62982826040516125ef929190614647565b60405180910390a150506000600255565b600f5490565b60085473ffffffffffffffffffffffffffffffffffffffff1690565b61262a613e57565b5060009081526010602090815260409182902082518084019093525463ffffffff811683526401000000009004811b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000169082015290565b60006117346003613975565b6003546004546005546006546007546008546040805160a080820183526009548252600a54602080840191909152600b5483850152600c54606080850191909152600d54608080860191909152600e54600f54601154601d5489519788018a52601e5463ffffffff8181168a5261ffff640100000000830481168b8b01526601000000000000830481168b8e01526801000000000000000083048216988b01989098526c01000000000000000000000000909104909616948801949094528851808a01909952601f5489528554958901959095529c83169c73ffffffffffffffffffffffffffffffffffffffff9b8c169b9a8b169a998a16999890981697959690959491909216918d565b73ffffffffffffffffffffffffffffffffffffffff1660009081526021602052604090205490565b600254156127fb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002556040517ff460cca9000000000000000000000000000000000000000000000000000000008152736a4690ae65d020a61c99449a11bc02934f081b979063f460cca9906113b4906003908890889088908890600401614f84565b60025415612893576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b60016002558281146128d1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614d42565b6007546040517f2eac95f100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff90911690632eac95f19061292b90879087903390600401614807565b60206040518083038186803b15801561294357600080fd5b505afa158015612957573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061297b91906142be565b6129b1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b60005b83811015612a79576001601b60008787858181106129ce57fe5b90506020020160208101906129e39190613ed7565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000858585818110612a2b57fe5b6020908102929092013583525081019190915260400160002080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169115159190911790556001016129b4565b507fe548a963a45d48f7887098ee1903d1291c4bef5b33e4fa75fced37e24b3a20da8484848460405161189c9493929190614841565b6000600254600014612aed576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560005473ffffffffffffffffffffffffffffffffffffffff163314612b43576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b6040517ff93234a2000000000000000000000000000000000000000000000000000000008152732375bbb012c378a0df56da7b947067a76372ec0a9063f93234a290612b96906003908690600401614e95565b60206040518083038186803b158015612bae57600080fd5b505af4158015612bc2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2b9190614326565b600080612bf46003866131e7565b73ffffffffffffffffffffffffffffffffffffffff8089166000908152601c602090815260408083208b85168452825280832063ffffffff958616845282528083207effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8a1684528252808320948816835293905291909120541691505095945050505050565b60025415612cb3576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025581612cc281611e9a565b612cf8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b73ffffffffffffffffffffffffffffffffffffffff83166000908152601b602090815260408083208584529091529081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055517f7115b98931e7aca6d0aa11d10fe28877316a661a44c4bfc93c76b19dbbf5b10790612d8390859085906147e1565b60405180910390a15050600060025550565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b60025415612deb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560005473ffffffffffffffffffffffffffffffffffffffff163314612e41576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b612e4f60038585858561397e565b7fd5ed9d44b4e70b483ebc5cb0f4b40468805a9cb2f9249d0201d77ef64d6368828484848460405161189c949392919061523a565b600080612e926003846131e7565b63ffffffff166000908152601460205260409020547effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff169392505050565b60045490565b60005473ffffffffffffffffffffffffffffffffffffffff163314612f26576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b73ffffffffffffffffffffffffffffffffffffffff811615801590612f66575060005473ffffffffffffffffffffffffffffffffffffffff828116911614155b612f9c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b9061493e565b600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b6005546040517f883515c100000000000000000000000000000000000000000000000000000000815260009173ffffffffffffffffffffffffffffffffffffffff169063883515c19061303a903090600401614626565b60206040518083038186803b15801561305257600080fd5b505afa158015613066573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117349190614326565b60006002546000146130c8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614975565b600160025560005473ffffffffffffffffffffffffffffffffffffffff16331461311e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149ac565b61312860036138ff565b1561315f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614b64565b6131696003613975565b156131a0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614b9b565b42601f8190556040517f574214b195bf5273a95bb4498e35cf1fde0ce327c727a95ec2ab359f7ba4e11a916131d4916148b2565b60405180910390a1506001600060025590565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260128301602052604090205463ffffffff168061324c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614bd2565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0192915050565b6000828211156132b0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614af6565b50900390565b601a015463ffffffff16620f42400390565b6000804690507f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8360000151805190602001208460200151805190602001208386604001516040516020016133219594939291906148bb565b60405160208183030381529060405280519060200120915050919050565b73ffffffffffffffffffffffffffffffffffffffff841661338c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614b2d565b600080613399888661399b565b915091508061344a576040517f5ac783340000000000000000000000000000000000000000000000000000000081527352c0bc9fa4481ca8d43a74b4add792b2e15367c890635ac78334906133f7908b908990600090600401614f1d565b60206040518083038186803b15801561340f57600080fd5b505af4158015613423573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613447919061438b565b91505b63ffffffff821615801561347d57507effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8416155b156134ba5734156134ba576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b906149e3565b60006134c589613a07565b156135095750600a8801546040517f12197207b0a54de931fdf21dc8066c293dc29b9dd4875c6b64a36c6a36ff9040906135009083906148b2565b60405180910390a15b80341015613543576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614c40565b60058901546040517f5e1da861000000000000000000000000000000000000000000000000000000008152348390039160009173ffffffffffffffffffffffffffffffffffffffff90911690635e1da8619084906135ab908e908d908d908d90600401614777565b6020604051808303818588803b1580156135c457600080fd5b505af11580156135d8573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906135fd91906142f2565b9050613607613e57565b5073ffffffffffffffffffffffffffffffffffffffff8916600090815260178c016020908152604080832063ffffffff808a168552908352928190208151808301909252547effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff168082524267ffffffffffffffff16928201929092529161369091908490613a9716565b81600001907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1690817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1681525050808c60170160008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008863ffffffff1663ffffffff16815260200190815260200160002060008201518160000160006101000a8154817effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff02191690837effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff16021790555060208201518160010160006101000a81548167ffffffffffffffff021916908367ffffffffffffffff16021790555090505061384b828d60110160008963ffffffff1663ffffffff16815260200190815260200160002060009054906101000a90047effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff16613a9790919063ffffffff16565b63ffffffff8716600090815260118e0160205260409081902080547fff00000000000000000000000000000000000000000000000000000000000000167effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9390931692909217909155517f5cc43c6b47c350258362c540eb61d09c2060eaa8b760707b2892d08a01f6e9c3906138e9908d908d908d908b908890614711565b60405180910390a1505050505050505050505050565b601d0154151590565b600061392b73ffffffffffffffffffffffffffffffffffffffff85168484613af8565b905080610da8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614a88565b6139708383835a613b9f565b505050565b601c0154151590565b600685019390935560078401919091556009830155600a90910155565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260128301602052604081205463ffffffff1690816139da57506000905080613a00565b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0160015b9250929050565b6009810154600882015460009182918291613a3d91613a329190613a2c904390613274565b90613be7565b600786015490613c35565b6006850154909150811115613a53575060068301545b8015613a80577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01613a85565b600191505b60078401554360088401559050919050565b8181017effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80841690821610156111ae576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614c09565b600082613b0757506001610da8565b6000613b288573ffffffffffffffffffffffffffffffffffffffff16613c72565b90508073ffffffffffffffffffffffffffffffffffffffff16848490604051613b5090613c72565b600060405180830381858888f193505050503d8060008114613b8e576040519150601f19603f3d011682016040523d82523d6000602084013e613b93565b606091505b50909695505050505050565b613bab84848484613c75565b613be1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614a88565b50505050565b818102821580613bff575081838281613bfc57fe5b04145b6111ae576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614d0b565b818101828110156111ae576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614c09565b90565b6000613c8085613db5565b613cb6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a1b90614d79565b606063a9059cbb60e01b8585604051602401613cd39291906147e1565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050905060008673ffffffffffffffffffffffffffffffffffffffff168483604051613d5a919061460a565b60006040518083038160008787f1925050503d8060008114613d98576040519150601f19603f3d011682016040523d82523d6000602084013e613d9d565b606091505b50509050613daa81613dbb565b979650505050505050565b3b151590565b60008115613df2573d8015613ddb5760208114613de45760009250613df0565b60019250613df0565b60206000803e60005192505b505b5090565b6040518061018001604052806000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b604080518082019091526000808252602082015290565b80356111ae816153fc565b60008083601f840112613e8a578182fd5b50813567ffffffffffffffff811115613ea1578182fd5b6020830191508360208083028501011115613a0057600080fd5b80356111ae8161545c565b803560ff811681146111ae57600080fd5b600060208284031215613ee8578081fd5b8135610da8816153fc565b600060208284031215613f04578081fd5b8151610da8816153fc565b60008060408385031215613f21578081fd5b8235613f2c816153fc565b91506020830135613f3c816153fc565b809150509250929050565b60008060008060008060a08789031215613f5f578182fd5b8635613f6a816153fc565b95506020870135613f7a816153fc565b94506040870135613f8a816153fc565b93506060870135613f9a8161542f565b9250608087013567ffffffffffffffff80821115613fb6578384fd5b818901915089601f830112613fc9578384fd5b813581811115613fd7578485fd5b8a6020828501011115613fe8578485fd5b6020830194508093505050509295509295509295565b600080600080600060a08688031215614015578081fd5b8535614020816153fc565b94506020860135614030816153fc565b93506040860135614040816153fc565b925060608601356140508161542f565b915060808601356140608161545c565b809150509295509295909350565b60008060008060008060c08789031215614086578182fd5b8635614091816153fc565b955060208701356140a1816153fc565b945060408701356140b1816153fc565b935060608701356140c18161542f565b925060808701356140d18161545c565b915060a08701356140e1816153fc565b809150509295509295509295565b60008060008060808587031215614104578182fd5b843561410f816153fc565b9350602085013561411f816153fc565b9250604085013561412f816153fc565b9396929550929360600135925050565b60008060008060808587031215614154578182fd5b843561415f816153fc565b9350602085013561416f816153fc565b93969395505050506040820135916060013590565b600080600060608486031215614198578081fd5b83356141a3816153fc565b925060208401356141b3816153fc565b915060408401356141c38161545c565b809150509250925092565b600080604083850312156141e0578182fd5b82356141eb816153fc565b946020939093013593505050565b6000806000806040858703121561420e578182fd5b843567ffffffffffffffff80821115614225578384fd5b61423188838901613e79565b90965094506020870135915080821115614249578384fd5b5061425687828801613e79565b95989497509550505050565b60008060208385031215614274578182fd5b823567ffffffffffffffff81111561428a578283fd5b61429685828601613e79565b90969095509350505050565b6000602082840312156142b3578081fd5b8135610da881615421565b6000602082840312156142cf578081fd5b8151610da881615421565b6000610ce082840312156142ec578081fd5b50919050565b600060208284031215614303578081fd5b8151610da88161542f565b60006020828403121561431f578081fd5b5035919050565b600060208284031215614337578081fd5b5051919050565b60008060008060808587031215614353578182fd5b5050823594602084013594506040840135936060013592509050565b600060208284031215614380578081fd5b8135610da88161545c565b60006020828403121561439c578081fd5b8151610da88161545c565b600080604083850312156143b9578182fd5b8235613f2c8161545c565b60008284526020808501945082825b8581101561440e5781356143e6816153fc565b73ffffffffffffffffffffffffffffffffffffffff16875295820195908201906001016143d3565b509495945050505050565b60008284526020808501945082825b8581101561440e57813561443b816153fc565b73ffffffffffffffffffffffffffffffffffffffff1687529582019590820190600101614428565b61060080828437600081840152505050565b61010080828437600081840152505050565b15159052565b600082845282826020860137806020848601015260207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f85011685010190509392505050565b600081518084526144ed8160208601602086016153d0565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b803561452a8161545c565b63ffffffff16825260208101356145408161542f565b7effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81166020840152505050565b80518252602081015160208301526040810151604083015260608101516060830152608081015160808301525050565b80518252602090810151910152565b63ffffffff808251168352602082015161ffff80821660208601528060408501511660408601528260608501511660608601528060808501511660808601525050505050565b61ffff169052565b63ffffffff169052565b60ff169052565b6000825161461c8184602087016153d0565b9190910192915050565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff9687168152948616602086015292851660408501527effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff91909116606084015263ffffffff16608083015290911660a082015260c00190565b73ffffffffffffffffffffffffffffffffffffffff9485168152928416602084015292166040820152606081019190915260800190565b73ffffffffffffffffffffffffffffffffffffffff9586168152938516602085015291909316604083015263ffffffff90921660608201527effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff909116608082015260a00190565b600073ffffffffffffffffffffffffffffffffffffffff80871683528086166020840152507effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff84166040830152608060608301526147d760808301846144d5565b9695505050505050565b73ffffffffffffffffffffffffffffffffffffffff929092168252602082015260400190565b60006040825261481b6040830185876143c4565b905073ffffffffffffffffffffffffffffffffffffffff83166020830152949350505050565b6000604082526148556040830186886143c4565b82810360208401528381527f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff84111561488c578182fd5b60208402808660208401370160200190815295945050505050565b901515815260200190565b90815260200190565b94855260208501939093526040840191909152606083015273ffffffffffffffffffffffffffffffffffffffff16608082015260a00190565b600060208252610da860208301846144d5565b6020808252600b908201527f494e495449414c495a4544000000000000000000000000000000000000000000604082015260600190565b6020808252600f908201527f494e56414c49445f414444524553530000000000000000000000000000000000604082015260600190565b6020808252600a908201527f5245454e5452414e435900000000000000000000000000000000000000000000604082015260600190565b6020808252600c908201527f554e415554484f52495a45440000000000000000000000000000000000000000604082015260600190565b60208082526013908201527f494e56414c49445f4554485f4445504f53495400000000000000000000000000604082015260600190565b6020808252600b908201527f414c52454144595f534554000000000000000000000000000000000000000000604082015260600190565b6020808252600a908201527f53414d455f56414c554500000000000000000000000000000000000000000000604082015260600190565b60208082526010908201527f5452414e534645525f4641494c55524500000000000000000000000000000000604082015260600190565b6020808252600b908201527f4e4f545f414c4c4f574544000000000000000000000000000000000000000000604082015260600190565b6020808252600d908201527f5355425f554e444552464c4f5700000000000000000000000000000000000000604082015260600190565b6020808252600c908201527f5a45524f5f414444524553530000000000000000000000000000000000000000604082015260600190565b6020808252600c908201527f494e56414c49445f4d4f44450000000000000000000000000000000000000000604082015260600190565b60208082526010908201527f414c52454144595f53485554444f574e00000000000000000000000000000000604082015260600190565b6020808252600f908201527f544f4b454e5f4e4f545f464f554e440000000000000000000000000000000000604082015260600190565b6020808252600c908201527f4144445f4f564552464c4f570000000000000000000000000000000000000000604082015260600190565b60208082526018908201527f494e53554646494349454e545f4445504f5349545f4645450000000000000000604082015260600190565b60208082526016908201527f5749544844524157414c5f4e4f545f544f4f5f4f4c4400000000000000000000604082015260600190565b60208082526021908201527f43414e4e4f545f4f564552524944455f524543495049454e545f41444452455360408201527f5300000000000000000000000000000000000000000000000000000000000000606082015260800190565b6020808252600c908201527f4d554c5f4f564552464c4f570000000000000000000000000000000000000000604082015260600190565b6020808252600c908201527f494e56414c49445f444154410000000000000000000000000000000000000000604082015260600190565b60208082526027908201527f4552433230536166655472616e736665723a2063616c6c20746f206e6f6e2d6360408201527f6f6e747261637400000000000000000000000000000000000000000000000000606082015260800190565b815163ffffffff1681526020918201517fffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000169181019190915260400190565b815181526020808301519082015260408083015190820152606080830151908201526080808301519082015260a0808301519082015260c0808301519082015260e0808301519082015261010080830151908201526101208083015190820152610140808301519082015261016091820151918101919091526101800190565b91825273ffffffffffffffffffffffffffffffffffffffff16602082015260400190565b92835273ffffffffffffffffffffffffffffffffffffffff918216602084015216604082015260600190565b93845273ffffffffffffffffffffffffffffffffffffffff92831660208501529116604083015263ffffffff16606082015260800190565b92835273ffffffffffffffffffffffffffffffffffffffff9190911660208301521515604082015260600190565b94855273ffffffffffffffffffffffffffffffffffffffff93909316602085015260408401919091526060830152608082015260a00190565b600086825260606020830152614f9e606083018688614419565b8281036040840152614fb1818587614419565b98975050505050505050565b83815260406020808301829052828201849052600091906060908185018682028601830188865b8981101561513c577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa089840301845281357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe218c3603018112615044578889fd5b8b016101e086820160ff6150588285613ec6565b16865261506581846153ae565b9050615073888701826145f1565b50615080898301836153c1565b61508c8a870182614603565b506150998883018361534b565b828a8801526150ab838801828461448d565b9250505060806150bf818701828501614475565b506101806150cf8184018461533e565b6150db82880182614487565b50506101a06150ec8184018461534b565b878403838901526150fe84828461448d565b93505050506101c06151128184018461534b565b93508683038288015261512683858361448d565b9789019796505050928601925050600101614fe4565b50909a9950505050505050505050565b828152610d008101823561515f8161545c565b63ffffffff81166020840152506040830173ffffffffffffffffffffffffffffffffffffffff6151928260208701613e6e565b16604084015280356060840152506060830135608083015260a083016151bb8160808601613ebb565b6151c860a08501826145f9565b506151d660c084018261451f565b506151e8610100830160e08501614463565b610da861070083016106e08501614463565b91825263ffffffff16602082015260400190565b7effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff91909116815260200190565b93845260208401929092526040830152606082015260800190565b63ffffffff91909116815260200190565b63ffffffff8e168152602081018d905273ffffffffffffffffffffffffffffffffffffffff8c811660408301528b811660608301528a81166080830152891660a08201526102c081016152bc60c083018a61456c565b8761016083015286610180830152856101a08301526152df6101c08301866145f9565b6152ed6101e08301856145ab565b6152fb61028083018461459c565b9e9d5050505050505050505050505050565b63ffffffff958616815261ffff94851660208201529284166040840152931660608201529116608082015260a00190565b60008235610da881615421565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261537f578283fd5b830160208101925035905067ffffffffffffffff81111561539f57600080fd5b803603831315613a0057600080fd5b6000823561ffff81168114610da8578182fd5b6000610da86020840184613ec6565b60005b838110156153eb5781810151838201526020016153d3565b83811115613be15750506000910152565b73ffffffffffffffffffffffffffffffffffffffff8116811461541e57600080fd5b50565b801515811461541e57600080fd5b7effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8116811461541e57600080fd5b63ffffffff8116811461541e57600080fdfea264697066735822122095271289a8b1b9ad9caf850e53e6d44c615b95e6063944cc48f80d250a8489a564736f6c63430007000033

Deployed Bytecode Sourcemap

1134:17042:25:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;16920:271;;;;;;;;;;-1:-1:-1;16920:271:25;;;;;:::i;:::-;;:::i;:::-;;6386:225;;;;;;;;;;-1:-1:-1;6386:225:25;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;;17197:561;;;;;;;;;;-1:-1:-1;17197:561:25;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;3123:444::-;;;;;;;;;;-1:-1:-1;3123:444:25;;;;;:::i;:::-;;:::i;10515:214::-;;;;;;;;;;-1:-1:-1;10515:214:25;;;;;:::i;:::-;;:::i;1810:44::-;;;;;;;;;;;;;:::i;:::-;;;;;;;:::i;13743:351::-;;;;;;;;;;-1:-1:-1;13743:351:25;;;;;:::i;:::-;;:::i;10735:294::-;;;;;;;;;;-1:-1:-1;10735:294:25;;;;;:::i;:::-;;:::i;11577:273::-;;;;;;;;;;-1:-1:-1;11577:273:25;;;;;:::i;:::-;;:::i;9519:296::-;;;;;;;;;;-1:-1:-1;9519:296:25;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;16226:688::-;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;:::i;9847:274::-;;;;;;:::i;:::-;;:::i;8127:142::-;;;;;;;;;;;;;:::i;15632:181::-;;;;;;;;;;;;;:::i;1066:198:44:-;;;;;;;;;;;;;:::i;8786:180:25:-;;;;;;;;;;-1:-1:-1;8786:180:25;;;;;:::i;:::-;;:::i;6813:190::-;;;;;;;;;;-1:-1:-1;6813:190:25;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;2271:114::-;;;;;;;;;;;;;:::i;:::-;;;;;;;:::i;14955:233::-;;;;;;;;;;-1:-1:-1;14955:233:25;;;;;:::i;:::-;;:::i;6617:190::-;;;;;;;;;;-1:-1:-1;6617:190:25;;;;;:::i;:::-;;:::i;8972:170::-;;;;;;;;;;;;;:::i;11856:784::-;;;;;;;;;;-1:-1:-1;11856:784:25;;;;;:::i;:::-;;:::i;1287:155:57:-;;;;;;;;;;;;;:::i;2558:559:25:-;;;;;;;;;;-1:-1:-1;2558:559:25;;;;;:::i;:::-;;:::i;12646:712::-;;;;;;;;;;-1:-1:-1;12646:712:25;;;;;:::i;:::-;;:::i;8453:139::-;;;;;;;;;;;;;:::i;17764:172::-;;;;;;;;;;;;;:::i;9171:342::-;;;;;;:::i;:::-;;:::i;4847:261::-;;;;;;;;;;-1:-1:-1;4847:261:25;;;;;:::i;:::-;;:::i;11035:246::-;;;;;;;;;;-1:-1:-1;11035:246:25;;;;;:::i;:::-;;:::i;383:20:57:-;;;;;;;;;;;;;:::i;6061:154:25:-;;;;;;;;;;;;;:::i;10127:308::-;;;;;;;;;;-1:-1:-1;10127:308:25;;;;;:::i;:::-;;:::i;15373:253::-;;;;;;;;;;-1:-1:-1;15373:253:25;;;;;:::i;:::-;;:::i;7676:425::-;;;;;;;;;;;;;:::i;5137:900::-;;;;;;;;;;;;;:::i;:::-;;;;;;;:::i;3740:585::-;;;;;;;;;;-1:-1:-1;3740:585:25;;;;;:::i;:::-;;:::i;8295:152::-;;;;;;;;;;;;;:::i;3573:161::-;;;;;;;;;;;;;:::i;8598:182::-;;;;;;;;;;-1:-1:-1;8598:182:25;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;6221:138::-;;;;;;;;;;;;;:::i;1773:31::-;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;:::i;7443:227::-;;;;;;;;;;-1:-1:-1;7443:227:25;;;;;:::i;:::-;;:::i;11287:284::-;;;;;;;;;;-1:-1:-1;11287:284:25;;;;;:::i;:::-;;:::i;14412:537::-;;;;;;;;;;-1:-1:-1;14412:537:25;;;;;:::i;:::-;;:::i;7207:230::-;;;;;;;;;;-1:-1:-1;7207:230:25;;;;;:::i;:::-;;:::i;13364:373::-;;;;;;;;;;-1:-1:-1;13364:373:25;;;;;:::i;:::-;;:::i;14100:306::-;;;;;;;;;;-1:-1:-1;14100:306:25;;;;;:::i;:::-;;:::i;388:27:44:-;;;;;;;;;;;;;:::i;4331:510:25:-;;;;;;;;;;-1:-1:-1;4331:510:25;;;;;:::i;:::-;;:::i;17942:231::-;;;;;;;;;;-1:-1:-1;17942:231:25;;;;;:::i;:::-;;:::i;15194:153::-;;;;;;;;;;;;;:::i;751:238:44:-;;;;;;;;;;-1:-1:-1;751:238:44;;;;;:::i;:::-;;:::i;7029:172:25:-;;;;;;;;;;;;;:::i;15819:401::-;;;;;;;;;;;;;:::i;16920:271::-;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;;;;;;;;;863:1;849:11;:15;812:5:57::1;::::0;::::1;;798:10;:19;790:44;;;;;;;;;;;;:::i;:::-;17047:24:25::2;::::0;::::2;;:33;;::::0;::::2;;;;17039:56;;;;;;;;;;;;:::i;:::-;17105:24;:32:::0;;;::::2;::::0;::::2;;;::::0;;17153:31:::2;::::0;::::2;::::0;::::2;::::0;17105:32;;17153:31:::2;:::i;:::-;;;;;;;;-1:-1:-1::0;956:1:60;942:11;:15;16920:271:25:o;6386:225::-;6521:6;764:11:60;;779:1;764:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;6598:5:25::1;::::0;6550:54:::1;::::0;;;;:19:::1;::::0;::::1;::::0;:54:::1;::::0;:5:::1;::::0;6570:12;;6598:5:::1;;6584:10;:19;::::0;6550:54:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;956:1:60::0;942:11;:15;6543:61:25;6386:225;-1:-1:-1;;6386:225:25:o;17197:561::-;17306:7;;17346:23;:5;17363;17346:16;:23::i;:::-;17329:40;-1:-1:-1;17380:26:25;17425:12;;;17421:296;;17517:38;;;;;;;;:29;:38;;;;;;17482:21;;17474:82;;17482:21;;;;17474:38;;17517;;;17474:42;:82;:::i;:::-;17453:103;;17421:296;;;17667:38;;;;;;;:29;:38;;;;;;;;17639:21;;17608:54;;;;;:98;;17667:38;;;;;17608:22;;;;;;;:54;;17639:21;;17608:54;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;:58;;:98::i;:::-;17587:119;;17421:296;17733:18;17197:561;-1:-1:-1;;;17197:561:25:o;3123:444::-;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;812:5:57::1;::::0;::::1;;798:10;:19;790:44;;;;;;;;;;;;:::i;:::-;3272:30:25::2;::::0;::::2;3264:55;;;;;;;;;;;;:::i;:::-;3377:21:::0;;:44:::2;:21;:44:::0;3369:68:::2;;;;;;;;;;;;:::i;:::-;3447:21:::0;:58;;;::::2;;::::0;::::2;;::::0;;3521:39:::2;::::0;::::2;::::0;::::2;::::0;3447:58;;3521:39:::2;:::i;10515:214::-:0;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;10681:41:25::1;::::0;;;;:28:::1;::::0;::::1;::::0;:41:::1;::::0;:5:::1;::::0;10710:11;;10681:41:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;-1:-1:-1::0;;956:1:60;942:11;:15;-1:-1:-1;;;10515:214:25:o;1810:44::-;;;;;;:::o;13743:351::-;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;13954:4:25;2126:19:::1;13954:4:::0;2126:13:::1;:19::i;:::-;2118:44;;;;;;;;;;;;:::i;:::-;13982:24:::2;::::0;::::2;;13974:48;;;;;;;;;;;;:::i;:::-;14032:21:::0;;:55:::2;::::0;;;;:21:::2;::::0;;::::2;::::0;:30:::2;::::0;:55:::2;::::0;14063:4;;14069:2;;14073:5;;14080:6;;14032:55:::2;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::2;;;;;;;;;;;;::::0;::::2;;;;;-1:-1:-1::0;;956:1:60;942:11;:15;-1:-1:-1;;;;;;;13743:351:25:o;10735:294::-;10896:4;;10933:23;:5;10950;10933:16;:23::i;:::-;10973:40;;;;;;;;:29;:40;;;;;;;;:49;;;;;;;;;;;;;;;-1:-1:-1;;10735:294:25;;;;;:::o;11577:273::-;11727:4;;11764:23;:5;11781;11764:16;:23::i;:::-;11804:30;;;;;;;:24;:30;;;;;;;;:39;;;;;;;;;;;;;;-1:-1:-1;;11577:273:25;;;;:::o;9519:296::-;9678:7;;9718:30;:5;9735:12;9718:16;:30::i;:::-;9765:27;;;;;;;:21;:27;;;;;;;;:36;;;;;;;;;;:43;;;;-1:-1:-1;;9519:296:25;;;;:::o;16226:688::-;16559:21;:30;;;;;;16617:37;;;;;;;16690:45;;;;;;16780:54;;;;;16866:41;;;;;;;;16226:688::o;9847:274::-;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;10051:4:25;2126:19:::1;10051:4:::0;2126:13:::1;:19::i;:::-;2118:44;;;;;;;;;;;;:::i;:::-;10071:43:::2;::::0;;;;:19:::2;::::0;::::2;::::0;:43:::2;::::0;:5:::2;::::0;10091:4;;10097:5;;10104:9;;10071:43:::2;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::2;;;;;;;;;;;;::::0;::::2;;;;;-1:-1:-1::0;;956:1:60;942:11;:15;-1:-1:-1;;;;;;9847:274:25:o;8127:142::-;8246:16;;8127:142;:::o;15632:181::-;15770:5;:36;;;15632:181;:::o;1066:198:44:-;565:12;;;;551:10;:26;543:51;;;;;;;;;;;;:::i;:::-;1179:12:::1;::::0;::::1;1172:5:::0;;1151:41:::1;::::0;1179:12:::1;::::0;;::::1;::::0;1172:5;;::::1;::::0;1151:41:::1;::::0;::::1;1210:12;::::0;;::::1;1202:20:::0;;;;;::::1;1210:12;::::0;::::1;1202:20;::::0;;;1232:25:::1;::::0;;1066:198::o;8786:180:25:-;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;812:5:57::1;::::0;::::1;;798:10;:19;790:44;;;;;;;;;;;;:::i;:::-;8933:26:25::2;::::0;;;;:18:::2;::::0;::::2;::::0;:26:::2;::::0;:5:::2;::::0;8952:6;;;;8933:26:::2;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::2;;;;;;;;;;;;::::0;::::2;;;;;-1:-1:-1::0;;956:1:60;942:11;:15;-1:-1:-1;;;;8786:180:25:o;6813:190::-;6966:30;;;;;6936:7;;6966:21;;;;:30;;:5;;6988:7;;6966:30;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;2271:114::-;2364:14;;;;;;;;;;;;;;;;;2271:114;:::o;14955:233::-;15142:22;;;;;15115:4;15142:22;;;:16;:22;;;;;;;;:39;;;;;;;;;;;14955:233::o;6617:190::-;6741:6;6770:30;:5;6787:12;6770:16;:30::i;8972:170::-;9074:4;9101:34;:5;:32;:34::i;:::-;9094:41;;8972:170;:::o;11856:784::-;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;12020:14:25::1;12037:23;:5;12054::::0;12037:16:::1;:23::i;:::-;12121:41;::::0;;::::1;12070:48;12121:41:::0;;;:30;:41:::1;::::0;;;;;;;:50;;::::1;::::0;;;;;;12189:20;;12121:50;;-1:-1:-1;12121:50:25;12189:20;;::::1;;;12181:60;;;;;;;;;;;;:::i;:::-;12349:20:::0;;::::1;::::0;;;::::1;;3692:7:17;12349:78:25;12330:15;:97;;12322:132;;;;;;;;;;;;:::i;:::-;12539:15;12498:38:::0;:56;;;12570:63:::1;::::0;::::1;::::0;::::1;::::0;::::1;:::i;:::-;;;;;;;;-1:-1:-1::0;;956:1:60;942:11;:15;-1:-1:-1;;11856:784:25:o;1287:155:57:-;812:5;;;;798:10;:19;790:44;;;;;;;;;;;;:::i;:::-;1404:1:::1;1389:5:::0;;1368:39:::1;::::0;::::1;1389:5:::0;;::::1;::::0;1368:39:::1;::::0;1404:1;;1368:39:::1;1433:1;1417:18:::0;;;::::1;::::0;;1287:155::o;2558:559:25:-;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;1937:14:25;;1929:37:::1;1937:14;1929:37:::0;:71;::::1;;;-1:-1:-1::0;1970:16:25;;:30;1929:71:::1;1908:129;;;;;;;;;;;;:::i;:::-;2823:20:::2;::::0;::::2;2815:45;;;;;;;;;;;;:::i;:::-;2870:5;:14:::0;;;::::2;;::::0;::::2;;::::0;;3041:58:::2;::::0;;;;;;;;::::2;;::::0;::::2;::::0;;;::::2;::::0;;;;;;2895:28:::2;::::0;::::2;::::0;:5:::2;::::0;2937:9;;2960:18;;2992:23;;3029:71:::2;::::0;3041:58:::2;::::0;::::2;3074:9;:7;:9::i;:::-;3041:58:::0;;3093:4:::2;3041:58;::::0;;::::2;::::0;3029:11:::2;:71::i;:::-;2895:215;;;;;;;;;;;;;;;;;;;:::i;12646:712::-:0;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;12918:4:25;2126:19:::1;12918:4:::0;2126:13:::1;:19::i;:::-;2118:44;;;;;;;;;;;;:::i;:::-;12946:26:::2;::::0;::::2;12938:51;;;;;;;;;;;;:::i;:::-;12999:14;13016:23;:5;13033::::0;13016:16:::2;:23::i;:::-;13057:77;:31:::0;;::::2;13132:1;13057:31:::0;;;:25;:31:::2;::::0;;;;;;;:35;;::::2;::::0;;;;;;;:44:::2;::::0;;::::2;::::0;;;;;;;;:52:::2;::::0;::::2;::::0;;;;;;;:63;;::::2;::::0;;;;;;;;12999:40;;-1:-1:-1;13057:63:25::2;:77:::0;13049:123:::2;;;;;;;;;;;;:::i;:::-;13182:31;::::0;;::::2;;::::0;;;:25;:31:::2;::::0;;;;;;;:35;;::::2;::::0;;;;;;;:44:::2;::::0;;::::2;::::0;;;;;;;;:52:::2;::::0;::::2;::::0;;;;;;;:63;;::::2;::::0;;;;;;;;;:78;;;::::2;::::0;;::::2;::::0;;;::::2;::::0;;;13276:75;::::2;::::0;::::2;::::0;13182:31;;:35;;13312:5;;13182:52;;:63;;:78;;13276:75:::2;:::i;:::-;;;;;;;;-1:-1:-1::0;;956:1:60;942:11;:15;-1:-1:-1;;;;;;12646:712:25:o;8453:139::-;8570:15;;8453:139;:::o;17764:172::-;17891:38;;17764:172;:::o;9171:342::-;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;9430:4:25;2126:19:::1;9430:4:::0;2126:13:::1;:19::i;:::-;2118:44;;;;;;;;;;;;:::i;:::-;9450:56:::2;9464:4;9470:2;9474:12;9488:6;9496:9;;9450:56;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::2;::::0;;;;-1:-1:-1;9450:5:25::2;::::0;:56;;;;;-1:-1:-1;;9450:13:25::2;:56:::0;-1:-1:-1;9450:56:25:i:2;:::-;-1:-1:-1::0;;956:1:60;942:11;:15;-1:-1:-1;;;;;9171:342:25:o;4847:261::-;4929:4;4957:18;;;4965:10;4957:18;;:144;;-1:-1:-1;4991:19:25;;:49;:19;:49;;;;:110;;-1:-1:-1;5056:19:25;;:45;;;;;:19;;;;;:27;;:45;;5084:4;;5090:10;;5056:19;:45;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;11035:246::-;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;11195:79:25::1;::::0;;;;:32:::1;::::0;::::1;::::0;:79:::1;::::0;:5:::1;::::0;11241:4;;11259:5;;11195:79:::1;;;:::i;383:20:57:-:0;;;;;;:::o;6061:154:25:-;6155:4;6182:26;:5;:24;:26::i;10127:308::-;10286:4;;10323:23;:5;10340;10323:16;:23::i;:::-;10363:41;;;;;;;;:30;:41;;;;;;;;:50;;;;;;;;;;;:60;;;;;;;:65;;;-1:-1:-1;;10127:308:25;;;;:::o;15373:253::-;15541:6;764:11:60;;779:1;764:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;812:5:57::1;::::0;::::1;;798:10;:19;790:44;;;;;;;;;;;;:::i;:::-;15570:49:25::2;::::0;;;;:39:::2;::::0;::::2;::::0;:49:::2;::::0;:5:::2;::::0;15610:8;;15570:49:::2;;;:::i;7676:425::-:0;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;7875:26:25::1;:5;:24;:26::i;:::-;7871:224;;;7985:14:::0;;:46:::1;::::0;;;;7972:10:::1;::::0;7985:14:::1;;::::0;:31:::1;::::0;:46:::1;::::0;8025:4:::1;::::0;7985:46:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;8045:14:::0;;:39:::1;::::0;;;;7972:59;;-1:-1:-1;8045:14:25::1;;::::0;:32:::1;::::0;:39:::1;::::0;7972:59;;8045:39:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;7871:224;;956:1:60::0;942:11;:15;7676:425:25:o;5137:900::-;5224:29;;:::i;:::-;-1:-1:-1;5276:754:25;;;;;;;;3481:77:17;5276:754:25;;3613:7:17;5276:754:25;;;;3692:7:17;5276:754:25;;;;;;3766:6:17;5276:754:25;;;;;;3876:31:17;5276:754:25;;;;;;;;;;;;;;4298:7:17;5276:754:25;;;;4676:2:17;5276:754:25;;;;;;;;;;;4861:10:17;5276:754:25;;;;4929:2:17;5276:754:25;;;;5137:900;:::o;3740:585::-;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;812:5:57::1;::::0;::::1;;798:10;:19;790:44;;;;;;;;;;;;:::i;:::-;3925:23:25::2;::::0;::::2;3917:51;;;;;;;;;;;;:::i;:::-;3983:19;::::0;::::2;3979:286;;4032:21;4067:45;4032:21:::0;4102:9:::2;4067:26;::::0;::::2;::::0;:45;:26:::2;:45::i;:::-;;3979:286;;;;4157:37;::::0;;;;4143:11:::2;::::0;4157:22:::2;::::0;::::2;::::0;::::2;::::0;:37:::2;::::0;4188:4:::2;::::0;4157:37:::2;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::2;;;;;;;;;;;;::::0;::::2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;4143:51:::0;-1:-1:-1;4208:46:25::2;:27;::::0;::::2;4236:9:::0;4143:51;4208:27:::2;:46::i;:::-;3979:286;;4280:38;4301:5;4308:9;4280:38;;;;;;;:::i;:::-;;;;;;;;-1:-1:-1::0;;956:1:60;942:11;:15;3740:585:25:o;8295:152::-;8419:21;;8295:152;:::o;3573:161::-;3706:21;;;;3573:161;:::o;8598:182::-;8699:29;;:::i;:::-;-1:-1:-1;8751:22:25;;;;:12;:22;;;;;;;;;8744:29;;;;;;;;;;;;;;;;;;;;;;;;;;8598:182::o;6221:138::-;6307:4;6334:18;:5;:16;:18::i;1773:31::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;7443:227::-;7615:48;;7588:4;7615:48;;;:34;:48;;;;;;;7443:227::o;11287:284::-;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;11477:87:25::1;::::0;;;;:37:::1;::::0;::::1;::::0;:87:::1;::::0;:5:::1;::::0;11528:6;;;;11548;;;;11477:87:::1;;;:::i;14412:537::-:0;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;14609:41:25;;::::1;14601:66;;;;;;;;;;;;:::i;:::-;14685:19:::0;;:47:::1;::::0;;;;:19:::1;::::0;;::::1;::::0;:27:::1;::::0;:47:::1;::::0;14713:6;;;;14721:10:::1;::::0;14685:19:::1;:47;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;14677:72;;;;;;;;;;;;:::i;:::-;14764:6;14759:122;14776:17:::0;;::::1;14759:122;;;14866:4;14814:16:::0;:27:::1;14831:6:::0;;14838:1;14831:9;;::::1;;;;;;;;;;;;;;;;;;:::i;:::-;14814:27;;;;;;;;;;;;;;;:49;14842:17;;14860:1;14842:20;;;;;;;;::::0;;::::1;::::0;;;::::1;;14814:49:::0;;-1:-1:-1;14814:49:25;::::1;::::0;;;;;;-1:-1:-1;14814:49:25;:56;;;::::1;::::0;::::1;;::::0;;;::::1;::::0;;-1:-1:-1;14795:3:25::1;14759:122;;;;14895:47;14916:6;;14924:17;;14895:47;;;;;;;;;:::i;7207:230::-:0;7365:4;764:11:60;;779:1;764:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;812:5:57::1;::::0;::::1;;798:10;:19;790:44;;;;;;;;;;;;:::i;:::-;7392:38:25::2;::::0;;;;:27:::2;::::0;::::2;::::0;:38:::2;::::0;:5:::2;::::0;7420:9;;7392:38:::2;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::2;;;;;;;;;;;;::::0;::::2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;13364:373::-:0;13587:7;;13627:23;:5;13644;13627:16;:23::i;:::-;13667:31;;;;;;;;:25;:31;;;;;;;;:35;;;;;;;;;;:44;;;;;;;;;;;:52;;;;;;;;;;:63;;;;;;;;;;;;;;;-1:-1:-1;;13364:373:25;;;;;;;:::o;14100:306::-;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;14276:4:25;2126:19:::1;14276:4:::0;2126:13:::1;:19::i;:::-;2118:44;;;;;;;;;;;;:::i;:::-;14296:22:::2;::::0;::::2;;::::0;;;:16;:22:::2;::::0;;;;;;;:39;;;;;;;;;;:46;;;::::2;14338:4;14296:46;::::0;;14357:42;::::2;::::0;::::2;::::0;14313:4;;14319:15;;14357:42:::2;:::i;:::-;;;;;;;;-1:-1:-1::0;;956:1:60;942:11;:15;-1:-1:-1;14100:306:25:o;388:27:44:-;;;;;;:::o;4331:510:25:-;764:11:60;;:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;812:5:57::1;::::0;::::1;;798:10;:19;790:44;;;;;;;;;;;;:::i;:::-;4585:147:25::2;:5;4621:14:::0;4649:19;4682:16;4712:10;4585:22:::2;:147::i;:::-;4748:86;4768:14;4784:19;4805:16;4823:10;4748:86;;;;;;;;;:::i;17942:231::-:0;18047:7;;18087:23;:5;18104;18087:16;:23::i;:::-;18128:38;;;;;;:29;:38;;;;;;;;;17942:231;-1:-1:-1;;;17942:231:25:o;15194:153::-;15318:22;;15194:153;:::o;751:238:44:-;812:5:57;;;;798:10;:19;790:44;;;;;;;;;;;;:::i;:::-;886:22:44::1;::::0;::::1;::::0;;::::1;::::0;:43:::1;;-1:-1:-1::0;924:5:44::1;::::0;::::1;912:17:::0;;::::1;924:5:::0;::::1;912:17;;886:43;878:71;;;;;;;;;;;;:::i;:::-;959:12;:23:::0;;;::::1;;::::0;;;::::1;::::0;;;::::1;::::0;;751:238::o;7029:172:25:-;7148:14;;:46;;;;;7121:4;;7148:14;;;:31;;:46;;7188:4;;7148:46;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;15819:401::-;15929:12;764:11:60;;779:1;764:16;756:39;;;;;;;;;;;;:::i;:::-;863:1;849:11;:15;812:5:57::1;::::0;::::1;;798:10;:19;790:44;;;;;;;;;;;;:::i;:::-;15966:26:25::2;:5;:24;:26::i;:::-;15965:27;15957:52;;;;;;;;;;;;:::i;:::-;16028:18;:5;:16;:18::i;:::-;16027:19;16019:48;;;;;;;;;;;;:::i;:::-;16116:15;16077:14:::0;:54;;;16146:46:::2;::::0;::::2;::::0;::::2;::::0;::::2;:::i;:::-;;;;;;;;-1:-1:-1::0;16209:4:25::2;956:1:60::0;942:11;:15;15819:401:25;:::o;2634:319:35:-;2835:30;;;2795:14;2835:30;;;:16;;;:30;;;;;;;;2883:12;2875:40;;;;;;;;;;;;:::i;:::-;2935:11;;;2634:319;-1:-1:-1;;2634:319:35:o;452:183:54:-;554:4;587:1;582;:6;;574:32;;;;;;;;;;;;:::i;:::-;-1:-1:-1;623:5:54;;;452:183::o;988:235:33:-;1186:30;;;;;3613:7:17;1146:70:33;;988:235::o;501:449:47:-;584:7;607:13;653:9;641:21;;327:109;788:6;:11;;;772:29;;;;;;835:6;:14;;;819:32;;;;;;869:8;895:6;:24;;;704:229;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;681:262;;;;;;674:269;;;501:449;;;:::o;987:2169:31:-;1269:16;;;1261:41;;;;;;;;;;;;:::i;:::-;1604:14;;1639:27;:1;1653:12;1639:13;:27::i;:::-;1603:63;;;;1680:10;1676:87;;1716:36;;;;;:15;;;;:36;;:1;;1732:12;;1746:5;;1716:36;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;1706:46;;1676:87;1777:12;;;;:27;;;;-1:-1:-1;1793:11:31;;;;1777:27;1773:104;;;1828:9;:14;1820:46;;;;;;;;;;;;:::i;:::-;1967:21;2006:23;2027:1;2006:20;:23::i;:::-;2002:139;;;-1:-1:-1;2061:25:31;;;;2105;;;;;;2061;;2105;:::i;:::-;;;;;;;;2002:139;2204:13;2191:9;:26;;2183:63;;;;;;;;;;;;:::i;:::-;2396:17;;;;:149;;;;;2286:9;:25;;;;2257:26;;2396:17;;;;;:25;;2286;;2396:149;;2462:4;;2480:12;;2506:6;;2526:9;;2396:149;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;2370:175;;2655:36;;:::i;:::-;-1:-1:-1;2694:21:31;;;;;;;:17;;;:21;;;;;;;;:30;;;;;;;;;;;;;2655:69;;;;;;;;;;;;;;2762:15;2655:69;2734:44;2655:69;;;2734:44;;;;2655:69;2806:36;;2655:69;2826:15;;2806:19;:36;:::i;:::-;2788:8;:15;;:54;;;;;;;;;;;2885:8;2852:1;:17;;:21;2870:2;2852:21;;;;;;;;;;;;;;;:30;2874:7;2852:30;;;;;;;;;;;;;;;:41;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2942:55;2981:15;2942:1;:25;;:34;2968:7;2942:34;;;;;;;;;;;;;;;;;;;;;;;;;:38;;;;:55;;;;:::i;:::-;2905:34;;;;;;;:25;;;:34;;;;;;;:92;;;;;;;;;;;;;;;;3013:136;;;;;3043:4;;3061:2;;3077:12;;2905:34;;3124:15;;3013:136;:::i;:::-;;;;;;;;987:2169;;;;;;;;;;;;:::o;557:219:33:-;731:34;;;:38;;;557:219::o;1772:259:42:-;1912:12;1950:28;:10;;;1961:6;1969:8;1950:10;:28::i;:::-;1940:38;;1996:7;1988:36;;;;;;;;;;;;:::i;691:265:50:-;829:120;876:5;895:2;911:5;930:9;829:33;:120::i;:::-;691:265;;;:::o;782:200:33:-;939:10;;:32;:36;;;782:200::o;3162:447:31:-;3382:14;;;:46;;;;3438:34;;;:56;;;;3504:31;;;:50;3564:25;;;;:38;3162:447::o;2959:372:35:-;3173:30;;;3121:14;3173:30;;;:16;;;:30;;;;;;;;;3216:12;3213:59;;-1:-1:-1;3252:1:35;;-1:-1:-1;3252:1:35;3244:17;;3213:59;-1:-1:-1;3291:11:35;;3301:1;2959:372;;;;;;:::o;3615:913:31:-;4038:31;;;;3997:34;;;;3708:4;;;;;;3927:153;;3979:91;;4038:31;3980:52;;:12;;:16;:52::i;:::-;3979:58;;:91::i;:::-;3927:34;;;;;:38;:153::i;:::-;4125:14;;;:29;3897:183;;-1:-1:-1;4103:51:31;;4099:133;;;-1:-1:-1;4192:14:31;;;:29;4099:133;4246:23;;4242:126;;4285:24;;4242:126;;;4353:4;4340:17;;4242:126;4378:34;;;:56;4481:12;4444:34;;;:49;4511:10;-1:-1:-1;3615:913:31;;;:::o;206:190:55:-;343:5;;;366:6;;;;;;;;;358:31;;;;;;;;;;;;:::i;1240:381:42:-;1371:12;1403:11;1399:53;;-1:-1:-1;1437:4:42;1430:11;;1399:53;1461:25;1489:14;:2;:12;;;:14::i;:::-;1461:42;;1566:9;:14;;1588:6;1601:8;1566:48;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1552:62:42;;1240:381;-1:-1:-1;;;;;;1240:381:42:o;1245:298:50:-;1442:52;1467:5;1474:2;1478:5;1485:8;1442:24;:52::i;:::-;1421:115;;;;;;;;;;;;:::i;:::-;1245:298;;;;:::o;251:195:54:-;379:5;;;402:6;;;:20;;;421:1;416;412;:5;;;;;;:10;402:20;394:45;;;;;;;;;;;;:::i;641:181::-;769:5;;;792:6;;;;784:31;;;;;;;;;;;;:::i;937:156:42:-;1081:4;937:156::o;1549:859:50:-;1719:4;2029:17;2040:5;2029:10;:17::i;:::-;2021:69;;;;;;;;;;;;:::i;:::-;2172:21;2239:10;2232:18;;2264:2;2280:5;2196:99;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2172:123;;2306:12;2324:5;:10;;2340:8;2350;2324:35;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2305:54;;;2376:25;2393:7;2376:16;:25::i;:::-;2369:32;1549:859;-1:-1:-1;;;;;;;1549:859:50:o;308:377::-;624:20;670:8;;;308:377::o;4395:1098::-;4500:4;4818:7;4814:649;;;4875:16;5028:59;;;;5202:2;5197:112;;;;5420:1;5409:12;;4868:571;;5028:59;5068:1;5057:12;;5028:59;;5197:112;5248:2;5245:1;5242;5227:24;5289:1;5283:8;5272:19;;4868:571;;4850:603;-1:-1:-1;5479:7:50;4395:1098::o;-1:-1:-1:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;:::o;5:130::-;72:20;;97:33;72:20;97:33;:::i;301:352::-;;;431:3;424:4;416:6;412:17;408:27;398:2;;-1:-1;;439:12;398:2;-1:-1;469:20;;509:18;498:30;;495:2;;;-1:-1;;531:12;495:2;575:4;567:6;563:17;551:29;;626:3;575:4;;610:6;606:17;567:6;592:32;;589:41;586:2;;;643:1;;633:12;3123:128;3189:20;;3214:32;3189:20;3214:32;:::i;3397:126::-;3462:20;;73829:4;73818:16;;76921:33;;76911:2;;76968:1;;76958:12;3530:241;;3634:2;3622:9;3613:7;3609:23;3605:32;3602:2;;;-1:-1;;3640:12;3602:2;85:6;72:20;97:33;124:5;97:33;:::i;3778:263::-;;3893:2;3881:9;3872:7;3868:23;3864:32;3861:2;;;-1:-1;;3899:12;3861:2;226:6;220:13;238:33;265:5;238:33;:::i;4048:366::-;;;4169:2;4157:9;4148:7;4144:23;4140:32;4137:2;;;-1:-1;;4175:12;4137:2;85:6;72:20;97:33;124:5;97:33;:::i;:::-;4227:63;-1:-1;4327:2;4366:22;;72:20;97:33;72:20;97:33;:::i;:::-;4335:63;;;;4131:283;;;;;:::o;4421:867::-;;;;;;;4612:3;4600:9;4591:7;4587:23;4583:33;4580:2;;;-1:-1;;4619:12;4580:2;85:6;72:20;97:33;124:5;97:33;:::i;:::-;4671:63;-1:-1;4771:2;4810:22;;72:20;97:33;72:20;97:33;:::i;:::-;4779:63;-1:-1;4879:2;4918:22;;72:20;97:33;72:20;97:33;:::i;:::-;4887:63;-1:-1;4987:2;5026:22;;2634:20;2659:33;2634:20;2659:33;:::i;:::-;4995:63;-1:-1;5123:3;5108:19;;5095:33;5148:18;5137:30;;;5134:2;;;-1:-1;;5170:12;5134:2;5255:6;5244:9;5240:22;;;1991:3;1984:4;1976:6;1972:17;1968:27;1958:2;;-1:-1;;1999:12;1958:2;2042:6;2029:20;5148:18;2061:6;2058:30;2055:2;;;-1:-1;;2091:12;2055:2;2186:3;4771:2;2166:17;2127:6;2152:32;;2149:41;2146:2;;;-1:-1;;2193:12;2146:2;4771;2127:6;2123:17;5190:82;;;;;;;;4574:714;;;;;;;;:::o;5295:741::-;;;;;;5466:3;5454:9;5445:7;5441:23;5437:33;5434:2;;;-1:-1;;5473:12;5434:2;85:6;72:20;97:33;124:5;97:33;:::i;:::-;5525:63;-1:-1;5625:2;5664:22;;72:20;97:33;72:20;97:33;:::i;:::-;5633:63;-1:-1;5733:2;5772:22;;72:20;97:33;72:20;97:33;:::i;:::-;5741:63;-1:-1;5841:2;5880:22;;2634:20;2659:33;2634:20;2659:33;:::i;:::-;5849:63;-1:-1;5949:3;5988:22;;3189:20;3214:32;3189:20;3214:32;:::i;:::-;5958:62;;;;5428:608;;;;;;;;:::o;6043:867::-;;;;;;;6231:3;6219:9;6210:7;6206:23;6202:33;6199:2;;;-1:-1;;6238:12;6199:2;85:6;72:20;97:33;124:5;97:33;:::i;:::-;6290:63;-1:-1;6390:2;6429:22;;72:20;97:33;72:20;97:33;:::i;:::-;6398:63;-1:-1;6498:2;6537:22;;72:20;97:33;72:20;97:33;:::i;:::-;6506:63;-1:-1;6606:2;6645:22;;2634:20;2659:33;2634:20;2659:33;:::i;:::-;6614:63;-1:-1;6714:3;6753:22;;3189:20;3214:32;3189:20;3214:32;:::i;:::-;6723:62;-1:-1;6822:3;6862:22;;72:20;97:33;72:20;97:33;:::i;:::-;6831:63;;;;6193:717;;;;;;;;:::o;6917:617::-;;;;;7072:3;7060:9;7051:7;7047:23;7043:33;7040:2;;;-1:-1;;7079:12;7040:2;85:6;72:20;97:33;124:5;97:33;:::i;:::-;7131:63;-1:-1;7231:2;7270:22;;72:20;97:33;72:20;97:33;:::i;:::-;7239:63;-1:-1;7339:2;7378:22;;72:20;97:33;72:20;97:33;:::i;:::-;7034:500;;;;-1:-1;7347:63;;7447:2;7486:22;2912:20;;-1:-1;;7034:500::o;7541:617::-;;;;;7696:3;7684:9;7675:7;7671:23;7667:33;7664:2;;;-1:-1;;7703:12;7664:2;85:6;72:20;97:33;124:5;97:33;:::i;:::-;7755:63;-1:-1;7855:2;7894:22;;72:20;97:33;72:20;97:33;:::i;:::-;7658:500;;7863:63;;-1:-1;;;;7963:2;8002:22;;1793:20;;8071:2;8110:22;1793:20;;7658:500::o;8165:489::-;;;;8302:2;8290:9;8281:7;8277:23;8273:32;8270:2;;;-1:-1;;8308:12;8270:2;85:6;72:20;97:33;124:5;97:33;:::i;:::-;8360:63;-1:-1;8460:2;8499:22;;72:20;97:33;72:20;97:33;:::i;:::-;8468:63;-1:-1;8568:2;8606:22;;3189:20;3214:32;3189:20;3214:32;:::i;:::-;8576:62;;;;8264:390;;;;;:::o;8661:366::-;;;8782:2;8770:9;8761:7;8757:23;8753:32;8750:2;;;-1:-1;;8788:12;8750:2;85:6;72:20;97:33;124:5;97:33;:::i;:::-;8840:63;8940:2;8979:22;;;;1793:20;;-1:-1;;;8744:283::o;9034:678::-;;;;;9225:2;9213:9;9204:7;9200:23;9196:32;9193:2;;;-1:-1;;9231:12;9193:2;9289:17;9276:31;9327:18;;9319:6;9316:30;9313:2;;;-1:-1;;9349:12;9313:2;9387:80;9459:7;9450:6;9439:9;9435:22;9387:80;:::i;:::-;9369:98;;-1:-1;9369:98;-1:-1;9532:2;9517:18;;9504:32;;-1:-1;9545:30;;;9542:2;;;-1:-1;;9578:12;9542:2;;9616:80;9688:7;9679:6;9668:9;9664:22;9616:80;:::i;:::-;9187:525;;;;-1:-1;9598:98;-1:-1;;;;9187:525::o;10404:447::-;;;10568:2;10556:9;10547:7;10543:23;10539:32;10536:2;;;-1:-1;;10574:12;10536:2;10632:17;10619:31;10670:18;10662:6;10659:30;10656:2;;;-1:-1;;10692:12;10656:2;10730:105;10827:7;10818:6;10807:9;10803:22;10730:105;:::i;:::-;10712:123;;;;-1:-1;10530:321;-1:-1;;;;10530:321::o;10858:235::-;;10959:2;10947:9;10938:7;10934:23;10930:32;10927:2;;;-1:-1;;10965:12;10927:2;1537:6;1524:20;1549:30;1573:5;1549:30;:::i;11100:257::-;;11212:2;11200:9;11191:7;11187:23;11183:32;11180:2;;;-1:-1;;11218:12;11180:2;1672:6;1666:13;1684:30;1708:5;1684:30;:::i;11364:305::-;;11499:4;11487:9;11478:7;11474:23;11470:34;11467:2;;;-1:-1;;11507:12;11467:2;-1:-1;11559:94;11461:208;-1:-1;11461:208::o;11676:263::-;;11791:2;11779:9;11770:7;11766:23;11762:32;11759:2;;;-1:-1;;11797:12;11759:2;2788:6;2782:13;2800:33;2827:5;2800:33;:::i;11946:241::-;;12050:2;12038:9;12029:7;12025:23;12021:32;12018:2;;;-1:-1;;12056:12;12018:2;-1:-1;2912:20;;12012:175;-1:-1;12012:175::o;12194:263::-;;12309:2;12297:9;12288:7;12284:23;12280:32;12277:2;;;-1:-1;;12315:12;12277:2;-1:-1;3060:13;;12271:186;-1:-1;12271:186::o;12464:617::-;;;;;12619:3;12607:9;12598:7;12594:23;12590:33;12587:2;;;-1:-1;;12626:12;12587:2;-1:-1;;2912:20;;;12778:2;12817:22;;2912:20;;-1:-1;12886:2;12925:22;;2912:20;;12994:2;13033:22;2912:20;;-1:-1;12581:500;-1:-1;12581:500::o;13088:239::-;;13191:2;13179:9;13170:7;13166:23;13162:32;13159:2;;;-1:-1;;13197:12;13159:2;3202:6;3189:20;3214:32;3240:5;3214:32;:::i;13334:261::-;;13448:2;13436:9;13427:7;13423:23;13419:32;13416:2;;;-1:-1;;13454:12;13416:2;3341:6;3335:13;3353:32;3379:5;3353:32;:::i;13602:364::-;;;13722:2;13710:9;13701:7;13697:23;13693:32;13690:2;;;-1:-1;;13728:12;13690:2;3202:6;3189:20;3214:32;3240:5;3214:32;:::i;15283:665::-;;69288:6;69283:3;69276:19;69325:4;;69320:3;69316:14;15430:93;;15608:21;-1:-1;15635:291;15660:6;15657:1;15654:13;15635:291;;;85:6;72:20;97:33;124:5;97:33;:::i;:::-;73379:42;73368:54;14837:37;;14127:14;;;;70710:12;;;;15682:1;15675:9;15635:291;;;-1:-1;15932:10;;15417:531;-1:-1;;;;;15417:531::o;15987:689::-;;69288:6;69283:3;69276:19;69325:4;;69320:3;69316:14;16142:101;;16328:21;-1:-1;16355:299;16380:6;16377:1;16374:13;16355:299;;;85:6;72:20;97:33;124:5;97:33;:::i;:::-;73379:42;73368:54;14837:37;;14127:14;;;;70710:12;;;;16402:1;16395:9;16355:299;;18341:169;18497:6;;75547:3;75542;75529:30;75608:1;18497:6;75594:3;75590:16;75583:27;;18454:56;;:::o;18551:167::-;18705:6;;75547:3;75542;75529:30;75608:1;18705:6;75594:3;75590:16;75583:27;;18662:56;;:::o;18726:104::-;72958:13;72951:21;18791:34;;18785:45::o;19446:293::-;;69288:6;69283:3;69276:19;75552:6;75547:3;69325:4;69320:3;69316:14;75529:30;-1:-1;69325:4;75599:6;69320:3;75590:16;;75583:27;69325:4;75985:7;75989:2;19725:6;75969:14;75965:28;69320:3;19694:39;;19687:46;;19544:195;;;;;:::o;19747:343::-;;19889:5;68728:12;69288:6;69283:3;69276:19;19982:52;20027:6;69325:4;69320:3;69316:14;69325:4;20008:5;20004:16;19982:52;:::i;:::-;75989:2;75969:14;75985:7;75965:28;20046:39;;;;69325:4;20046:39;;19837:253;-1:-1;;19837:253::o;30014:557::-;3202:6;3189:20;3214:32;3240:5;3214:32;:::i;:::-;73735:10;73724:22;41068:36;;72652:2;72643:12;;2634:20;2659:33;2634:20;2659:33;:::i;:::-;73507:64;40524:5;73496:76;72652:2;30539:3;30535:14;40494:37;;30138:433;;:::o;35837:1006::-;36072:16;36066:23;19253:3;19246:37;36252:4;36245:5;36241:16;36235:23;36252:4;36316:3;36312:14;19246:37;36421:4;36414:5;36410:16;36404:23;36421:4;36485:3;36481:14;19246:37;36587:4;36580:5;36576:16;36570:23;36587:4;36651:3;36647:14;19246:37;36747:4;36740:5;36736:16;36730:23;36747:4;36811:3;36807:14;19246:37;35963:880;;:::o;38321:514::-;38549:23;;19246:37;;38739:4;38728:16;;;38722:23;38799:14;;19246:37;38439:396::o;38923:1021::-;73735:10;;39158:16;39152:23;73724:22;41075:3;41068:36;39332:4;39325:5;39321:16;39315:23;73287:6;;40172:5;73276:18;39332:4;39394:3;39390:14;40143:36;73287:6;39503:4;39496:5;39492:16;39486:23;73276:18;39503:4;39565:3;39561:14;40143:36;73735:10;39683:4;39676:5;39672:16;39666:23;73724:22;39683:4;39745:3;39741:14;41068:36;73287:6;39850:4;39843:5;39839:16;39833:23;73276:18;39850:4;39912:3;39908:14;40143:36;;;;39055:889;;:::o;40084:100::-;73287:6;73276:18;40143:36;;40137:47::o;41009:100::-;73735:10;73724:22;41068:36;;41062:47::o;41473:105::-;73829:4;73818:16;41538:35;;41532:46::o;41585:271::-;;20257:5;68728:12;20368:52;20413:6;20408:3;20401:4;20394:5;20390:16;20368:52;:::i;:::-;20432:16;;;;;41719:137;-1:-1;;41719:137::o;42249:222::-;73379:42;73368:54;;;;14837:37;;42376:2;42361:18;;42347:124::o;42478:333::-;73379:42;73368:54;;;14837:37;;73368:54;;42797:2;42782:18;;14837:37;42633:2;42618:18;;42604:207::o;43174:776::-;73379:42;73368:54;;;14837:37;;73368:54;;;43604:2;43589:18;;14837:37;73368:54;;;43687:2;43672:18;;14837:37;73507:64;73496:76;;;;43770:2;43755:18;;40494:37;73735:10;73724:22;43851:3;43836:19;;41068:36;73368:54;;;43935:3;43920:19;;14837:37;43439:3;43424:19;;43410:540::o;43957:556::-;73379:42;73368:54;;;14837:37;;73368:54;;;44333:2;44318:18;;14837:37;73368:54;;44416:2;44401:18;;14837:37;44499:2;44484:18;;19246:37;;;;44168:3;44153:19;;44139:374::o;44520:664::-;73379:42;73368:54;;;14837:37;;73368:54;;;44922:2;44907:18;;14837:37;73368:54;;;;45005:2;44990:18;;14837:37;73735:10;73724:22;;;45086:2;45071:18;;41068:36;73507:64;73496:76;;;45169:3;45154:19;;40494:37;44757:3;44742:19;;44728:456::o;45191:640::-;;73379:42;;72874:5;73368:54;14844:3;14837:37;73379:42;72874:5;73368:54;45585:2;45574:9;45570:18;14837:37;;73507:64;40524:5;73496:76;45668:2;45657:9;45653:18;40494:37;45420:3;45705:2;45694:9;45690:18;45683:48;45745:76;45420:3;45409:9;45405:19;45807:6;45745:76;:::i;:::-;45737:84;45391:440;-1:-1;;;;;;45391:440::o;45838:333::-;73379:42;73368:54;;;;14837:37;;46157:2;46142:18;;19246:37;45993:2;45978:18;;45964:207::o;46518:517::-;;46741:2;46762:17;46755:47;46816:118;46741:2;46730:9;46726:18;46920:6;46912;46816:118;:::i;:::-;46808:126;;73379:42;72874:5;73368:54;47021:2;47010:9;47006:18;14706:58;46712:323;;;;;;:::o;47042:669::-;;47317:2;47338:17;47331:47;47392:118;47317:2;47306:9;47302:18;47496:6;47488;47392:118;:::i;:::-;47558:9;47552:4;47548:20;47543:2;47532:9;47528:18;47521:48;69288:6;69283:3;69276:19;16974:66;16966:6;16963:78;16960:2;;;-1:-1;;17044:12;16960:2;47543;17079:6;17075:17;75552:6;75547:3;47543:2;69320:3;69316:14;75529:30;75590:16;47543:2;75590:16;75583:27;;;75590:16;47288:423;-1:-1;;;;;47288:423::o;47718:210::-;72958:13;;72951:21;18791:34;;47839:2;47824:18;;47810:118::o;47935:222::-;19246:37;;;48062:2;48047:18;;48033:124::o;48164:668::-;19246:37;;;48568:2;48553:18;;19246:37;;;;48651:2;48636:18;;19246:37;;;;48734:2;48719:18;;19246:37;73379:42;73368:54;48817:3;48802:19;;14837:37;48403:3;48388:19;;48374:458::o;49118:310::-;;49265:2;49286:17;49279:47;49340:78;49265:2;49254:9;49250:18;49404:6;49340:78;:::i;49435:416::-;49635:2;49649:47;;;21753:2;49620:18;;;69276:19;21789:13;69316:14;;;21769:34;21822:12;;;49606:245::o;49858:416::-;50058:2;50072:47;;;22073:2;50043:18;;;69276:19;22109:17;69316:14;;;22089:38;22146:12;;;50029:245::o;50281:416::-;50481:2;50495:47;;;22397:2;50466:18;;;69276:19;22433:12;69316:14;;;22413:33;22465:12;;;50452:245::o;50704:416::-;50904:2;50918:47;;;22716:2;50889:18;;;69276:19;22752:14;69316;;;22732:35;22786:12;;;50875:245::o;51127:416::-;51327:2;51341:47;;;23037:2;51312:18;;;69276:19;23073:21;69316:14;;;23053:42;23114:12;;;51298:245::o;51550:416::-;51750:2;51764:47;;;23365:2;51735:18;;;69276:19;23401:13;69316:14;;;23381:34;23434:12;;;51721:245::o;51973:416::-;52173:2;52187:47;;;23685:2;52158:18;;;69276:19;23721:12;69316:14;;;23701:33;23753:12;;;52144:245::o;52396:416::-;52596:2;52610:47;;;24004:2;52581:18;;;69276:19;24040:18;69316:14;;;24020:39;24078:12;;;52567:245::o;52819:416::-;53019:2;53033:47;;;24329:2;53004:18;;;69276:19;24365:13;69316:14;;;24345:34;24398:12;;;52990:245::o;53242:416::-;53442:2;53456:47;;;24649:2;53427:18;;;69276:19;24685:15;69316:14;;;24665:36;24720:12;;;53413:245::o;53665:416::-;53865:2;53879:47;;;24971:2;53850:18;;;69276:19;25007:14;69316;;;24987:35;25041:12;;;53836:245::o;54088:416::-;54288:2;54302:47;;;25292:2;54273:18;;;69276:19;25328:14;69316;;;25308:35;25362:12;;;54259:245::o;54511:416::-;54711:2;54725:47;;;25613:2;54696:18;;;69276:19;25649:18;69316:14;;;25629:39;25687:12;;;54682:245::o;54934:416::-;55134:2;55148:47;;;25938:2;55119:18;;;69276:19;25974:17;69316:14;;;25954:38;26011:12;;;55105:245::o;55357:416::-;55557:2;55571:47;;;26262:2;55542:18;;;69276:19;26298:14;69316;;;26278:35;26332:12;;;55528:245::o;55780:416::-;55980:2;55994:47;;;26583:2;55965:18;;;69276:19;26619:26;69316:14;;;26599:47;26665:12;;;55951:245::o;56203:416::-;56403:2;56417:47;;;26916:2;56388:18;;;69276:19;26952:24;69316:14;;;26932:45;26996:12;;;56374:245::o;56626:416::-;56826:2;56840:47;;;27552:2;56811:18;;;69276:19;27588:34;69316:14;;;27568:55;27657:3;27643:12;;;27636:25;27680:12;;;56797:245::o;57049:416::-;57249:2;57263:47;;;27931:2;57234:18;;;69276:19;27967:14;69316;;;27947:35;28001:12;;;57220:245::o;57472:416::-;57672:2;57686:47;;;28252:2;57657:18;;;69276:19;28288:14;69316;;;28268:35;28322:12;;;57643:245::o;57895:416::-;58095:2;58109:47;;;28573:2;58080:18;;;69276:19;28609:34;69316:14;;;28589:55;28678:9;28664:12;;;28657:31;28707:12;;;58066:245::o;58318:330::-;30865:23;;73735:10;73724:22;41068:36;;31043:4;31032:16;;;31026:23;73057:66;73046:78;31103:14;;;19126:37;;;;58499:2;58484:18;;58470:178::o;58655:331::-;33668:23;;19246:37;;33859:4;33848:16;;;33842:23;33919:14;;;19246:37;34051:4;34040:16;;;34034:23;34111:14;;;19246:37;34238:4;34227:16;;;34221:23;34298:14;;;19246:37;34404:4;34393:16;;;34387:23;34464:14;;;19246:37;34568:4;34557:16;;;34551:23;34628:14;;;19246:37;34753:4;34742:16;;;34736:23;34813:14;;;19246:37;34923:4;34912:16;;;34906:23;34983:14;;;19246:37;35098:6;35087:18;;;35081:25;35160:16;;;19246:37;35297:6;35286:18;;;35280:25;35359:16;;;19246:37;35476:6;35465:18;;;35459:25;35538:16;;;19246:37;35655:6;35644:18;;;35638:25;35717:16;;;19246:37;;;;58836:3;58821:19;;58807:179::o;58993:405::-;19246:37;;;73379:42;73368:54;59384:2;59369:18;;14837:37;59180:2;59165:18;;59151:247::o;59405:524::-;19246:37;;;73379:42;73368:54;;;59824:2;59809:18;;14837:37;73368:54;59915:2;59900:18;;14837:37;59620:2;59605:18;;59591:338::o;59936:640::-;19246:37;;;73379:42;73368:54;;;60382:2;60367:18;;14837:37;73368:54;;60473:2;60458:18;;14837:37;73735:10;73724:22;60562:2;60547:18;;41068:36;60177:3;60162:19;;60148:428::o;60583:512::-;19246:37;;;73379:42;73368:54;;;;60996:2;60981:18;;14837:37;72958:13;72951:21;61081:2;61066:18;;18791:34;60792:2;60777:18;;60763:332::o;61102:764::-;19246:37;;;73379:42;73368:54;;;;61578:2;61563:18;;14837:37;61669:2;61654:18;;19246:37;;;;61760:2;61745:18;;19246:37;61851:3;61836:19;;19246:37;61373:3;61358:19;;61344:522::o;61873:860::-;;19276:5;19253:3;19246:37;62208:2;62358;62347:9;62343:18;62336:48;62398:126;62208:2;62197:9;62193:18;62510:6;62502;62398:126;:::i;:::-;62572:9;62566:4;62562:20;62557:2;62546:9;62542:18;62535:48;62597:126;62718:4;62709:6;62701;62597:126;:::i;:::-;62589:134;62179:554;-1:-1;;;;;;;;62179:554::o;62740:669::-;19246:37;;;63035:2;63185;63170:18;;;63163:48;;;63020:18;;;69276:19;;;62740:669;;63035:2;69316:14;;;;;17637:17;;;17628:27;;;;17765:21;62740:669;17792:467;17817:6;17814:1;17811:13;17792:467;;;17869:20;63024:9;17873:4;17869:20;;17864:3;17857:33;71981:3;71968:17;72025:50;72049:8;72033:14;72029:29;72025:50;72005:18;72001:75;71991:2;;-1:-1;;72080:12;71991:2;72109:33;;31354:6;72767:12;;;73829:4;72743:37;72767:12;72109:33;72743:37;:::i;:::-;73818:16;41545:3;41538:35;31615:49;31647:16;31640:5;31615:49;:::i;:::-;31595:69;;31670;63185:2;31728:3;31724:14;31710:12;31670:69;:::i;:::-;;31809:48;63035:2;31844:5;31840:16;31833:5;31809:48;:::i;:::-;31863:67;63035:2;31919:3;31915:14;31901:12;31863:67;:::i;:::-;;32006:61;69316:14;32054:5;32050:16;32043:5;32006:61;:::i;:::-;31354:6;69316:14;32091:3;32087:14;32080:38;32133:95;31354:6;31349:3;31345:16;32209:12;32195;32133:95;:::i;:::-;32125:103;;;;32366:4;32378:119;32366:4;32486:3;32482:14;32366:4;32359:5;32355:16;32378:119;:::i;:::-;;32617:6;32576:49;32617:6;32610:5;32606:18;32599:5;32576:49;:::i;:::-;32631:67;32617:6;32685:3;32681:16;32667:12;32631:67;:::i;:::-;;;32838:6;32783:63;32838:6;32831:5;32827:18;32820:5;32783:63;:::i;:::-;32894:3;32888:4;32884:14;32838:6;32870:3;32866:16;32859:40;32914:95;33004:4;32990:12;32976;32914:95;:::i;:::-;32906:103;;;;;33154:6;33099:63;33154:6;33147:5;33143:18;33136:5;33099:63;:::i;:::-;33065:97;;33210:3;33204:4;33200:14;33154:6;33186:3;33182:16;33175:40;33230:95;33320:4;33306:12;33292;33230:95;:::i;:::-;18238:14;;;;17992:128;-1:-1;;;68989:14;;;;-1:-1;;17839:1;17832:9;17792:467;;;-1:-1;63217:182;;63006:403;-1:-1;;;;;;;;;;63006:403::o;63416:527::-;19246:37;;;63663:4;63648:20;;3189;;3214:32;3189:20;3214:32;:::i;:::-;73735:10;41097:5;73724:22;63929:2;63918:9;63914:18;41068:36;;70710:12;29060:16;70710:12;73379:42;70684:39;70710:12;63929:2;29060:16;72643:12;70684:39;:::i;:::-;73368:54;70710:12;63918:9;29327:14;14837:37;2925:6;2912:20;29519:14;63918:9;29519:14;19246:37;;29519:14;29636:5;29632:16;2912:20;29711:14;63918:9;29711:14;19246:37;72643:12;29825:5;72643:12;72618:38;72643:12;29711:14;29825:5;29821:16;72618:38;:::i;:::-;29844:69;72643:12;63918:9;29898:14;29884:12;29844:69;:::i;:::-;;37533:131;37649:14;63918:9;37649:14;37635:12;37533:131;:::i;:::-;;37822:121;37928:14;63918:9;37928:14;37810:4;37803:5;37799:16;37822:121;:::i;:::-;38103:123;38209:16;63918:9;38209:16;38089:6;38082:5;38078:18;38103:123;:::i;63950:401::-;19246:37;;;73735:10;73724:22;64337:2;64322:18;;41068:36;64135:2;64120:18;;64106:245::o;64358:222::-;73507:64;73496:76;;;;40494:37;;64485:2;64470:18;;64456:124::o;64816:556::-;19246:37;;;65192:2;65177:18;;19246:37;;;;65275:2;65260:18;;19246:37;65358:2;65343:18;;19246:37;65027:3;65012:19;;64998:374::o;65379:218::-;73735:10;73724:22;;;;41068:36;;65504:2;65489:18;;65475:122::o;65604:2100::-;73735:10;73724:22;;41068:36;;66498:2;66483:18;;19246:37;;;73379:42;73368:54;;;66601:2;66586:18;;20554:73;73368:54;;;66707:2;66692:18;;14837:37;73368:54;;;66813:3;66798:19;;14837:37;73368:54;;66922:3;66907:19;;14837:37;66335:3;66320:19;;66938:133;67066:3;67051:19;;67042:6;66938:133;:::i;:::-;19276:5;67150:3;67139:9;67135:19;19246:37;19276:5;67234:3;67223:9;67219:19;19246:37;19276:5;67318:3;67307:9;67303:19;19246:37;67334:72;67401:3;67390:9;67386:19;67376:7;67334:72;:::i;:::-;67417:140;67552:3;67541:9;67537:19;67527:7;67417:140;:::i;:::-;67568:126;67689:3;67678:9;67674:19;67664:7;67568:126;:::i;:::-;66306:1398;;;;;;;;;;;;;;;;:::o;67711:648::-;73735:10;73724:22;;;41068:36;;73287:6;73276:18;;;68101:2;68086:18;;40143:36;73276:18;;;68182:2;68167:18;;40143:36;73724:22;;68263:2;68248:18;;41068:36;73276:18;;68344:3;68329:19;;40143:36;67940:3;67925:19;;67911:448::o;70973:113::-;;1537:6;1524:20;1549:30;1573:5;1549:30;:::i;71095:501::-;;;71219:3;71206:17;71263:48;71287:8;71271:14;71267:29;71263:48;71243:18;71239:73;71229:2;;-1:-1;;71316:12;71229:2;71345:33;;71302:4;71434:16;;;-1:-1;71400:19;;-1:-1;71470:18;71459:30;;71456:2;;;71502:1;;71492:12;71456:2;71549:17;71271:14;71529:38;71519:8;71515:53;71512:2;;;71581:1;;71571:12;72163:117;;2511:6;2498:20;73287:6;76457:5;73276:18;76433:5;76430:34;76420:2;;-1:-1;;76468:12;72671:115;;72743:37;72776:2;72771:3;72767:12;72762:3;72743:37;:::i;75625:268::-;75690:1;75697:101;75711:6;75708:1;75705:13;75697:101;;;75778:11;;;75772:18;75759:11;;;75752:39;75733:2;75726:10;75697:101;;;75813:6;75810:1;75807:13;75804:2;;;-1:-1;;75690:1;75860:16;;75853:27;75674:219::o;76006:117::-;73379:42;76093:5;73368:54;76068:5;76065:35;76055:2;;76114:1;;76104:12;76055:2;76049:74;:::o;76130:111::-;76211:5;72958:13;72951:21;76189:5;76186:32;76176:2;;76232:1;;76222:12;76494:117;73507:64;76581:5;73496:76;76556:5;76553:35;76543:2;;76602:1;;76592:12;76742:115;73735:10;76827:5;73724:22;76803:5;76800:34;76790:2;;76848:1;;76838:12

Swarm Source

ipfs://95271289a8b1b9ad9caf850e53e6d44c615b95e6063944cc48f80d250a8489a5

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

OVERVIEW

Responsible for processing zkBlocks and deposit/withdrawal requests.

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.