Sepolia Testnet

Contract

0xb0608C86A850e1C33c965272dF19ab686061Af28

Overview

ETH Balance

6.321020689682155817 ETH

Multichain Info

N/A
Transaction Hash
Method
Block
From
To
Set Gas Limit65485902024-08-22 9:04:12152 days ago1724317452IN
0xb0608C86...86061Af28
0 ETH0.0005394118.45239992
Set Gas Limit65166852024-08-17 8:59:24157 days ago1723885164IN
0xb0608C86...86061Af28
0 ETH0.000051.70995653
Set Gas Limit64850662024-08-12 9:32:24162 days ago1723455144IN
0xb0608C86...86061Af28
0 ETH0.0003798212.98756235
Set Gas Limit64035062024-07-30 12:10:12175 days ago1722341412IN
0xb0608C86...86061Af28
0 ETH0.0003915913.39016736
Set Gas Limit63973102024-07-29 11:49:12176 days ago1722253752IN
0xb0608C86...86061Af28
0 ETH0.000195737.40494983
Set Peer63973012024-07-29 11:47:00176 days ago1722253620IN
0xb0608C86...86061Af28
0 ETH0.00021437.71165019
Set Peer63973002024-07-29 11:46:36176 days ago1722253596IN
0xb0608C86...86061Af28
0 ETH0.000228397.46644783
Set Peer63853242024-07-27 13:22:00178 days ago1722086520IN
0xb0608C86...86061Af28
0 ETH0.000093233.04791185
Set Peer63853232024-07-27 13:21:48178 days ago1722086508IN
0xb0608C86...86061Af28
0 ETH0.000097333.18191133
Set Peer63853212024-07-27 13:21:24178 days ago1722086484IN
0xb0608C86...86061Af28
0 ETH0.000081192.65438307
Set Peer63853182024-07-27 13:20:36178 days ago1722086436IN
0xb0608C86...86061Af28
0 ETH0.000087422.85803863
Initialize63850942024-07-27 12:30:00178 days ago1722083400IN
0xb0608C86...86061Af28
0 ETH0.000095523.01870043
Set Gas Limit63838152024-07-27 7:29:48178 days ago1722065388IN
0xb0608C86...86061Af28
0 ETH0.000414688.95010057
Set Gas Limit63838132024-07-27 7:29:24178 days ago1722065364IN
0xb0608C86...86061Af28
0 ETH0.000414958.95588745
Set Gas Limit63838112024-07-27 7:29:00178 days ago1722065340IN
0xb0608C86...86061Af28
0 ETH0.000443259.56680385
Set Gas Limit63838102024-07-27 7:28:36178 days ago1722065316IN
0xb0608C86...86061Af28
0 ETH0.000430589.29321362
Set Peer63836782024-07-27 6:56:12178 days ago1722063372IN
0xb0608C86...86061Af28
0 ETH0.0005895112.36141836
Set Peer63836762024-07-27 6:55:48178 days ago1722063348IN
0xb0608C86...86061Af28
0 ETH0.0006385513.38973544
Set Peer63836742024-07-27 6:55:24178 days ago1722063324IN
0xb0608C86...86061Af28
0 ETH0.00064213.4620966
Set Peer63836722024-07-27 6:55:00178 days ago1722063300IN
0xb0608C86...86061Af28
0 ETH0.0006523713.67946945
Initialize63800512024-07-26 16:17:48179 days ago1722010668IN
0xb0608C86...86061Af28
0 ETH0.0014658328.43846161

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block
From
To
73373582024-12-23 9:07:1229 days ago1734944832
0xb0608C86...86061Af28
0.0004207 ETH
73373582024-12-23 9:07:1229 days ago1734944832
0xb0608C86...86061Af28
0.00084141 ETH
73373522024-12-23 9:06:0029 days ago1734944760
0xb0608C86...86061Af28
0.0004207 ETH
73373522024-12-23 9:06:0029 days ago1734944760
0xb0608C86...86061Af28
0.00084141 ETH
73373182024-12-23 8:59:1229 days ago1734944352
0xb0608C86...86061Af28
0.00042064 ETH
73373182024-12-23 8:59:1229 days ago1734944352
0xb0608C86...86061Af28
0.00042064 ETH
73373062024-12-23 8:56:4829 days ago1734944208
0xb0608C86...86061Af28
0.00042064 ETH
73373062024-12-23 8:56:4829 days ago1734944208
0xb0608C86...86061Af28
0.00042064 ETH
73372562024-12-23 8:46:0029 days ago1734943560
0xb0608C86...86061Af28
0.0004207 ETH
73372562024-12-23 8:46:0029 days ago1734943560
0xb0608C86...86061Af28
0.00084141 ETH
73372532024-12-23 8:45:2429 days ago1734943524
0xb0608C86...86061Af28
0.00042064 ETH
73372532024-12-23 8:45:2429 days ago1734943524
0xb0608C86...86061Af28
0.00042064 ETH
73372452024-12-23 8:43:3629 days ago1734943416
0xb0608C86...86061Af28
0.00042064 ETH
73372452024-12-23 8:43:3629 days ago1734943416
0xb0608C86...86061Af28
0.00042064 ETH
73372002024-12-23 8:34:1229 days ago1734942852
0xb0608C86...86061Af28
0.00042064 ETH
73372002024-12-23 8:34:1229 days ago1734942852
0xb0608C86...86061Af28
0.00042064 ETH
73371532024-12-23 8:23:4829 days ago1734942228
0xb0608C86...86061Af28
0.00042064 ETH
73371532024-12-23 8:23:4829 days ago1734942228
0xb0608C86...86061Af28
0.00042064 ETH
73371042024-12-23 8:13:3629 days ago1734941616
0xb0608C86...86061Af28
0.00042064 ETH
73371042024-12-23 8:13:3629 days ago1734941616
0xb0608C86...86061Af28
0.00042064 ETH
73370422024-12-23 8:00:2429 days ago1734940824
0xb0608C86...86061Af28
0.00042089 ETH
73370422024-12-23 8:00:2429 days ago1734940824
0xb0608C86...86061Af28
0.00084179 ETH
73370362024-12-23 7:59:1229 days ago1734940752
0xb0608C86...86061Af28
0.00042064 ETH
73370362024-12-23 7:59:1229 days ago1734940752
0xb0608C86...86061Af28
0.00042064 ETH
73370322024-12-23 7:58:2429 days ago1734940704
0xb0608C86...86061Af28
0.00042089 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
SynthrBridgeLightChainLz

Compiler Version
v0.8.24+commit.e11b9ed9

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 36 : SynthrBridgeLightChainLz.sol
// SPDX-License-Identifier: MIT

pragma solidity =0.8.24;

import "./BaseBridgeLZ.sol";
import "../../interfaces/ISynthrIssuer.sol";
import "../../interfaces/IExchanger.sol";
import "../../interfaces/IWrappedSynthr.sol";
import "../../libraries/BytesLib.sol";

/**
 * @title SynthrBridgeLightChainLz
 * @dev Bridge contract for cross-chain communication using LayerZero in the Synthr protocol
 */
contract SynthrBridgeLightChainLz is BaseBridgeLZ {
    using BytesLib for bytes;

    error Bridging_on_same_chain();
    error MarginDelta_should_be_greater_than_zero();
    error Unknown_packetType(uint16 packetType);

    /**
     * @notice Constructor to initialize the bridge contract
     * @param _lzEndpoint The LayerZero endpoint address
     * @param _owner The owner of the contract
     */
    constructor(address _lzEndpoint, address _owner) BaseBridgeLZ(_lzEndpoint, _owner) {
        lzFeePercentage = 100;
    }

    /**
     * @notice Get the main chain ID
     * @return The main chain ID
     */
    function mainChainId() external view returns (uint16) {
        return _mainChainId;
    }

    /**
     * @notice Initialize the contract with the given parameters
     * @param __synthrAddressResolver The address resolver for Synthr
     * @param __mainChainId The ID of the main chain
     * @param __selfLZChainId The ID of the current chain
     */
    function initialize(
        address __synthrAddressResolver,
        uint16 __mainChainId,
        uint16 __selfLZChainId
    ) external onlyOwner {
        _mainChainId = __mainChainId;
        _synthrAddressResolver = __synthrAddressResolver;
        _selfLZChainId = __selfLZChainId;
    }

    function _lzReceive(
        Origin calldata _origin,
        bytes32 _guid,
        bytes calldata _payload,
        address,
        bytes calldata
    ) internal override {
        uint16 packetType = _getPacketType(_payload);
        address account;
        if (packetType == PT_MINT_SYNTH) {
            // receive mint synth message
            // from only the main chain
            (, bytes memory accountBytes, bytes32 synthKey, uint amount) = abi.decode(_payload, (uint16, bytes, bytes32, uint));
            account = accountBytes.toAddress(0);
            ISynthrIssuer(getAddressFromResolver("Issuer")).destIssue(account, synthKey, amount);
        } else if (packetType == PT_WITHDRAW_COLLATERAL) {
            // withdraw collateral message
            // from only the main chain
            (, bytes memory accountBytes, bytes32 collateralKey, uint amount) = abi.decode(_payload, (uint16, bytes, bytes32, uint));
            account = accountBytes.toAddress(0);
            IWrappedSynthr(getAddressFromResolver("WrappedSynthr")).withdrawCollateral(account, account, collateralKey, amount);
        } else if (packetType == PT_EXCHANGE) {
            // exchange syTokens
            // from every chain
            (, bytes memory accountBytes, , , bytes32 destKey, uint destAmount, ) = abi.decode(_payload, (uint16, bytes, bytes32, uint, bytes32, uint, uint));
            account = accountBytes.toAddress(0);
            IExchanger(getAddressFromResolver("Exchanger")).updateDestinationForExchange(account, destKey, destAmount);
        } else if (packetType == PT_LIQUIDATE) {
            // liquidate collateral
            // message from only the main chain
            (, bytes memory accountBytes, bytes32 collateralKey, uint collateralAmount) = abi.decode(_payload, (uint16, bytes, bytes32, uint));
            account = accountBytes.toAddress(0);
            IWrappedSynthr(getAddressFromResolver("WrappedSynthr")).collateralTransfer(account, collateralKey, collateralAmount);
        } else if (packetType == PT_BRIDGE_SYNTH) {
            // bridge syToken
            // message from every chain
            (, bytes memory accountBytes, bytes32 synthKey, uint amount) = abi.decode(_payload, (uint16, bytes, bytes32, uint));
            account = accountBytes.toAddress(0);
            ISynthrIssuer(getAddressFromResolver("Issuer")).destIssue(account, synthKey, amount);
        } else if (packetType == PT_WITHDRAW_MARGIN) {
            (, bytes memory accountBytes, uint amount) = abi.decode(_payload, (uint16, bytes, uint));
            account = accountBytes.toAddress(0);
            // bytes32("sUSD") = 0x7355534400000000000000000000000000000000000000000000000000000000
            ISynthrIssuer(getAddressFromResolver("Issuer")).destIssue(account, 0x7355534400000000000000000000000000000000000000000000000000000000, amount);
        } else if (packetType == PT_CROSS_SWAP_CASE_1) {
            (
                ,
                bytes memory accountBytes,
                bytes32 srcKey,
                uint srcAmount,
                bytes32 dstKey,
                uint dstAmount, // uint16 dstChainId // uint fee
                ,
                ,
                bytes memory dexPayload,
                bytes memory dexAddressBytes
            ) = abi.decode(_payload, (uint16, bytes, bytes32, uint, bytes32, uint, uint16, uint, bytes, bytes));
            account = accountBytes.toAddress(0);
            address dexAddress = dexAddressBytes.toAddress(0);
            ISynthrSwap(getAddressFromResolver("SynthrSwap")).destSwapSynthToNative(account, srcKey, srcAmount, dstKey, dstAmount, dexAddress, dexPayload);
        } else if (packetType == PT_CROSS_SWAP_CASE_2) {
            (
                ,
                bytes memory accountBytes,
                bytes32 srcKey,
                uint srcAmount,
                bytes32 dstKey,
                uint dstAmount, // uint16 dstChainId // uint fee
                ,

            ) = abi.decode(_payload, (uint16, bytes, bytes32, uint, bytes32, uint, uint16, uint));
            account = accountBytes.toAddress(0);
            ISynthrSwap(getAddressFromResolver("SynthrSwap")).destSwapNativeToSynth(account, srcKey, srcAmount, dstKey, dstAmount);
        } else if (packetType == PT_CROSS_SWAP_CASE_3) {
            (
                ,
                bytes memory accountBytes,
                bytes32 srcKey,
                uint srcAmount,
                bytes32 dstKey,
                uint dstAmount, // uint16 dstChainId // uint fee,
                ,
                ,
                bytes memory dexPayload,
                bytes memory dexAddressBytes
            ) = abi.decode(_payload, (uint16, bytes, bytes32, uint, bytes32, uint, uint16, uint, bytes, bytes));
            account = accountBytes.toAddress(0);
            address dexAddress = dexAddressBytes.toAddress(0);
            ISynthrSwap(getAddressFromResolver("SynthrSwap")).destSwapNativeToNative(account, srcKey, srcAmount, dstKey, dstAmount, dexAddress, dexPayload);
        } else if (packetType == PT_CROSS_SWAP_DEX_CASE_1) {
            (
                ,
                bytes memory accountBytes,
                bytes32 srcKey,
                uint srcAmount,
                bytes32 dstKey,
                uint dstAmount, //uint16 dstChainId // uint fee
                ,

            ) = abi.decode(_payload, (uint16, bytes, bytes32, uint, bytes32, uint, uint16, uint));
            account = accountBytes.toAddress(0);
            ISynthrSwapDex(getAddressFromResolver("SynthrSwapWithDex")).destSwapSynthToNative(account, srcKey, srcAmount, dstKey, dstAmount);
        } else if (packetType == PT_CROSS_SWAP_DEX_CASE_3) {
            (
                ,
                bytes memory accountBytes,
                bytes32 srcKey,
                uint srcAmount,
                bytes32 dstKey,
                uint dstAmount, // uint16 dstChainId // uint fee
                ,

            ) = abi.decode(_payload, (uint16, bytes, bytes32, uint, bytes32, uint, uint16, uint));
            account = accountBytes.toAddress(0);
            ISynthrSwapDex(getAddressFromResolver("SynthrSwapWithDex")).destSwapNativeToNative(account, srcKey, srcAmount, dstKey, dstAmount);
        } else {
            revert Unknown_packetType(packetType);
        }
        {
            bytes32 path = _getPeerOrRevert(_origin.srcEid);
            emit ReceivePacket(account, path, _guid, packetType, uint16(_origin.srcEid), _origin.nonce);
        }
    }

    /**
     * @notice Send a deposit collateral message to the main chain
     * @param account The account depositing collateral
     * @param collateralKey The key representing the collateral
     * @param amount The amount of collateral to deposit
     * Boolean indicating if ZRO token payment is used for LayerZero fee
     */
    function sendDepositCollateral(
        address account,
        bytes32 collateralKey,
        uint amount,
        bool // the param to check ZRO token payment -  true: ZRO token payment for LZ fee, false: native token payment for LZ fee
    ) external payable onlySynthr {
        bytes memory lzPayload = abi.encode(PT_DEPOSIT_COLLATERAL, abi.encodePacked(account), collateralKey, amount);
        _broadcast(account, lzPayload, PT_DEPOSIT_COLLATERAL, _mainChainId, msg.value, false);
    }

    /**
     * @notice Send a burn synth message to the main chain
     * @param account The account burning synth tokens
     * @param synthKey The key representing the synth token
     * @param amount The amount of synth tokens to burn
     * Boolean indicating if ZRO token payment is used for LayerZero fee
     */
    function sendBurn(
        address account,
        bytes32 synthKey,
        uint amount,
        bool // the param to check ZRO token payment -  true: ZRO token payment for LZ fee, false: native token payment for LZ fee
    ) external payable onlySynthr {
        bytes memory lzPayload = abi.encode(PT_BURN_SYNTH, abi.encodePacked(account), synthKey, amount);
        _broadcast(account, lzPayload, PT_BURN_SYNTH, _mainChainId, msg.value, false);
    }

    /**
     * @notice Send an exchange message to the destination chain and main chain
     * @param account The account performing the exchange
     * @param srcSynthKey The key representing the source synth token
     * @param dstSynthKey The key representing the destination synth token
     * @param srcAmount The amount of source synth tokens
     * @param dstAmount The amount of destination synth tokens
     * @param reclaimed The amount of tokens reclaimed
     * @param refund The amount of tokens refunded
     * @param fee The fee for the exchange
     * @param dstChainId The destination chain ID
     * Boolean indicating if ZRO token payment is used for LayerZero fee
     */
    function sendExchange(
        address account,
        bytes32 srcSynthKey,
        bytes32 dstSynthKey,
        uint srcAmount,
        uint dstAmount,
        uint reclaimed,
        uint refund,
        uint fee,
        uint16 dstChainId,
        bool // the param to check ZRO token payment -  true: ZRO token payment for LZ fee, false: native token payment for LZ fee
    ) external payable onlySynthr {
        srcAmount += reclaimed - refund;
        if (dstChainId == 0) {
            dstChainId = _selfLZChainId;
        }

        bytes memory lzPayload = abi.encode(PT_EXCHANGE, abi.encodePacked(account), srcSynthKey, srcAmount, dstSynthKey, dstAmount, fee, dstChainId);
        uint value = msg.value;
        if (dstChainId != _selfLZChainId) {
            uint consumed = _broadcast(account, lzPayload, PT_EXCHANGE, dstChainId, value, false);
            value -= consumed;
        }

        if (dstChainId != _mainChainId) {
            _broadcast(account, lzPayload, PT_EXCHANGE, _mainChainId, value, false);
        }
    }

    /**
     * @notice Send a bridge synth token message to the destination chain
     * @param account The account bridging synth tokens
     * @param synthKey The key representing the synth token
     * @param amount The amount of synth tokens to bridge
     * @param dstChainId The destination chain ID
     * Boolean indicating if ZRO token payment is used for LayerZero fee
     */
    function sendBridgeSyToken(
        address account,
        bytes32 synthKey,
        uint amount,
        uint16 dstChainId,
        bool // the param to check ZRO token payment -  true: ZRO token payment for LZ fee, false: native token payment for LZ fee
    ) external payable onlySynthr {
        if (dstChainId == 0) {
            revert Bridging_on_same_chain();
        }

        bytes memory lzPayload = abi.encode(PT_BRIDGE_SYNTH, abi.encodePacked(account), synthKey, amount, dstChainId);
        uint value = msg.value;
        uint consumed = _broadcast(account, lzPayload, PT_BRIDGE_SYNTH, dstChainId, value, false);
        value -= consumed;

        if (dstChainId != _mainChainId) {
            _broadcast(account, lzPayload, PT_BRIDGE_SYNTH, _mainChainId, value, false);
        }
    }

    // This function is on only the light chain as we don't need to bridge `transfer margin` message to the other chain
    /**
     * @notice Send a transfer margin message to the main chain
     * @param account The account transferring margin
     * @param marginDelta The amount of margin to transfer
     * @param marketKey The key representing the market
     * Boolean indicating if ZRO token payment is used for LayerZero fee
     */
    function sendTransferMargin(
        address account,
        uint marginDelta,
        bytes32 marketKey,
        bool // the param to check ZRO token payment -  true: ZRO token payment for LZ fee, false: native token payment for LZ fee
    ) external payable onlySynthr {
        if (marginDelta <= 0) {
            revert MarginDelta_should_be_greater_than_zero();
        }
        bytes memory lzPayload = abi.encode(PT_TRANSFER_MARGIN, abi.encodePacked(account), marginDelta, marketKey);
        _broadcast(account, lzPayload, PT_TRANSFER_MARGIN, _mainChainId, msg.value, false);
    }

    // TODO
    // DO we need to check the hash of the dexPayload?
    /**
     * @notice Send a cross-chain swap from synth to native asset
     * @param account The account performing the swap
     * @param srcKey The key representing the source synth token
     * @param srcAmount The amount of source synth tokens
     * @param dstKey The key representing the destination native asset
     * @param dstAmount The amount of destination native asset
     * @param dstChainId The destination chain ID
     * @param fee The fee for the swap
     * @param dexPayload The payload data for the DEX
     * @param dexAddress The address of the DEX
     * Boolean indicating if ZRO token payment is used for LayerZero fee
     */
    function sendCrossSwapSyAssetToNative(
        address account,
        bytes32 srcKey,
        uint srcAmount,
        bytes32 dstKey,
        uint dstAmount,
        uint16 dstChainId,
        uint fee,
        bytes calldata dexPayload,
        address dexAddress,
        bool // the param to check ZRO token payment -  true: ZRO token payment for LZ fee, false: native token payment for LZ fee
    ) external payable onlySynthr {
        bytes memory lzPayload = abi.encode(
            PT_CROSS_SWAP_CASE_1,
            abi.encodePacked(account),
            srcKey,
            srcAmount,
            dstKey,
            dstAmount,
            dstChainId,
            fee,
            dexPayload,
            abi.encodePacked(dexAddress)
        );

        uint value = msg.value;
        uint consumed = _broadcast(account, lzPayload, PT_CROSS_SWAP_CASE_1, _mainChainId, msg.value, false);
        value -= consumed;

        // to the light chain
        if (dstChainId != _mainChainId) {
            _broadcast(account, lzPayload, PT_CROSS_SWAP_CASE_1, dstChainId, value, false);
        }
    }

    /**
     * @notice Send a cross-chain swap from native asset to synth
     * @param account The account performing the swap
     * @param srcKey The key representing the source native asset
     * @param srcAmount The amount of source native asset
     * @param dstKey The key representing the destination synth token
     * @param dstAmount The amount of destination synth tokens
     * @param dstChainId The destination chain ID
     * @param fee The fee for the swap
     * Boolean indicating if ZRO token payment is used for LayerZero fee
     */
    function sendCrossSwapNativeToSyAsset(
        address account,
        bytes32 srcKey,
        uint srcAmount,
        bytes32 dstKey,
        uint dstAmount,
        uint16 dstChainId,
        uint fee,
        bool // the param to check ZRO token payment -  true: ZRO token payment for LZ fee, false: native token payment for LZ fee
    ) external payable onlySynthr {
        bytes memory lzPayload = abi.encode(PT_CROSS_SWAP_CASE_2, abi.encodePacked(account), srcKey, srcAmount, dstKey, dstAmount, dstChainId, fee);
        uint value = msg.value;
        uint consumed = _broadcast(account, lzPayload, PT_CROSS_SWAP_CASE_2, _mainChainId, msg.value, false);
        value -= consumed;

        if (dstChainId != _mainChainId) {
            _broadcast(account, lzPayload, PT_CROSS_SWAP_CASE_2, dstChainId, value, false);
        }
    }

    /**
     * @notice Send a cross-chain swap from native asset to native asset
     * @param account The account performing the swap
     * @param srcKey The key representing the source native asset
     * @param srcAmount The amount of source native asset
     * @param dstKey The key representing the destination native asset
     * @param dstAmount The amount of destination native asset
     * @param dstChainId The destination chain ID
     * @param fee The fee for the swap
     * @param dexAddress The address of the DEX
     * @param dexPayload The payload data for the DEX
     * Boolean indicating if ZRO token payment is used for LayerZero fee
     */
    function sendCrossSwapNativeToNative(
        address account,
        bytes32 srcKey,
        uint srcAmount,
        bytes32 dstKey,
        uint dstAmount,
        uint16 dstChainId,
        uint fee,
        address dexAddress,
        bytes calldata dexPayload,
        bool // the param to check ZRO token payment -  true: ZRO token payment for LZ fee, false: native token payment for LZ fee
    ) external payable onlySynthr {
        bytes memory lzPayload = abi.encode(
            PT_CROSS_SWAP_CASE_3,
            abi.encodePacked(account),
            srcKey,
            srcAmount,
            dstKey,
            dstAmount,
            dstChainId,
            fee,
            dexPayload,
            abi.encodePacked(dexAddress)
        );

        uint value = msg.value;
        uint consumed = _broadcast(account, lzPayload, PT_CROSS_SWAP_CASE_3, _mainChainId, value, false);
        value -= consumed;

        if (dstChainId != _mainChainId) {
            _broadcast(account, lzPayload, PT_CROSS_SWAP_CASE_3, dstChainId, value, false);
        }
    }

    /**
     * @notice Send a cross-chain swap from synth to native asset using a DEX
     * @param account The account performing the swap
     * @param srcKey The key representing the source synth token
     * @param srcAmount The amount of source synth tokens
     * @param dstKey The key representing the destination native asset
     * @param dstAmount The amount of destination native asset
     * @param dstChainId The destination chain ID
     * @param fee The fee for the swap
     * Boolean indicating if ZRO token payment is used for LayerZero fee
     */
    function sendCrossSwapSyAssetToNativeWithDex(
        address account,
        bytes32 srcKey,
        uint srcAmount,
        bytes32 dstKey,
        uint dstAmount,
        uint16 dstChainId,
        uint fee,
        bool // the param to check ZRO token payment -  true: ZRO token payment for LZ fee, false: native token payment for LZ fee
    ) external payable onlySynthr {
        bytes memory lzPayload = abi.encode(PT_CROSS_SWAP_DEX_CASE_1, abi.encodePacked(account), srcKey, srcAmount, dstKey, dstAmount, dstChainId, fee);

        uint value = msg.value;
        uint consumed = _broadcast(account, lzPayload, PT_CROSS_SWAP_DEX_CASE_1, _mainChainId, msg.value, false);
        value -= consumed;

        if (dstChainId != _mainChainId) {
            _broadcast(account, lzPayload, PT_CROSS_SWAP_DEX_CASE_1, dstChainId, value, false);
        }
    }

    /**
     * @notice Send a cross-chain swap from native asset to native asset using a DEX
     * @param account The account performing the swap
     * @param srcKey The key representing the source native asset
     * @param srcAmount The amount of source native asset
     * @param dstKey The key representing the destination native asset
     * @param dstAmount The amount of destination native asset
     * @param dstChainId The destination chain ID
     * @param fee The fee for the swap
     * Boolean indicating if ZRO token payment is used for LayerZero fee
     */
    function sendCrossSwapNativeToNativeWithDex(
        address account,
        bytes32 srcKey,
        uint srcAmount,
        bytes32 dstKey,
        uint dstAmount,
        uint16 dstChainId,
        uint fee,
        bool // the param to check ZRO token payment -  true: ZRO token payment for LZ fee, false: native token payment for LZ fee
    ) external payable onlySynthr {
        bytes memory lzPayload = abi.encode(PT_CROSS_SWAP_DEX_CASE_3, abi.encodePacked(account), srcKey, srcAmount, dstKey, dstAmount, dstChainId, fee);

        uint value = msg.value;
        uint consumed = _broadcast(account, lzPayload, PT_CROSS_SWAP_DEX_CASE_3, _mainChainId, value, false);
        value -= consumed;

        if (dstChainId != _mainChainId) {
            _broadcast(account, lzPayload, PT_CROSS_SWAP_DEX_CASE_3, dstChainId, value, false);
        }
    }
}

File 2 of 36 : DVNOptions.sol
// SPDX-License-Identifier: LZBL-1.2

pragma solidity ^0.8.20;

import { BytesLib } from "solidity-bytes-utils/contracts/BytesLib.sol";

import { BitMap256 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/BitMaps.sol";
import { CalldataBytesLib } from "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/CalldataBytesLib.sol";

library DVNOptions {
    using CalldataBytesLib for bytes;
    using BytesLib for bytes;

    uint8 internal constant WORKER_ID = 2;
    uint8 internal constant OPTION_TYPE_PRECRIME = 1;

    error DVN_InvalidDVNIdx();
    error DVN_InvalidDVNOptions(uint256 cursor);

    /// @dev group dvn options by its idx
    /// @param _options [dvn_id][dvn_option][dvn_id][dvn_option]...
    ///        dvn_option = [option_size][dvn_idx][option_type][option]
    ///        option_size = len(dvn_idx) + len(option_type) + len(option)
    ///        dvn_id: uint8, dvn_idx: uint8, option_size: uint16, option_type: uint8, option: bytes
    /// @return dvnOptions the grouped options, still share the same format of _options
    /// @return dvnIndices the dvn indices
    function groupDVNOptionsByIdx(
        bytes memory _options
    ) internal pure returns (bytes[] memory dvnOptions, uint8[] memory dvnIndices) {
        if (_options.length == 0) return (dvnOptions, dvnIndices);

        uint8 numDVNs = getNumDVNs(_options);

        // if there is only 1 dvn, we can just return the whole options
        if (numDVNs == 1) {
            dvnOptions = new bytes[](1);
            dvnOptions[0] = _options;

            dvnIndices = new uint8[](1);
            dvnIndices[0] = _options.toUint8(3); // dvn idx
            return (dvnOptions, dvnIndices);
        }

        // otherwise, we need to group the options by dvn_idx
        dvnIndices = new uint8[](numDVNs);
        dvnOptions = new bytes[](numDVNs);
        unchecked {
            uint256 cursor = 0;
            uint256 start = 0;
            uint8 lastDVNIdx = 255; // 255 is an invalid dvn_idx

            while (cursor < _options.length) {
                ++cursor; // skip worker_id

                // optionLength asserted in getNumDVNs (skip check)
                uint16 optionLength = _options.toUint16(cursor);
                cursor += 2;

                // dvnIdx asserted in getNumDVNs (skip check)
                uint8 dvnIdx = _options.toUint8(cursor);

                // dvnIdx must equal to the lastDVNIdx for the first option
                // so it is always skipped in the first option
                // this operation slices out options whenever the scan finds a different lastDVNIdx
                if (lastDVNIdx == 255) {
                    lastDVNIdx = dvnIdx;
                } else if (dvnIdx != lastDVNIdx) {
                    uint256 len = cursor - start - 3; // 3 is for worker_id and option_length
                    bytes memory opt = _options.slice(start, len);
                    _insertDVNOptions(dvnOptions, dvnIndices, lastDVNIdx, opt);

                    // reset the start and lastDVNIdx
                    start += len;
                    lastDVNIdx = dvnIdx;
                }

                cursor += optionLength;
            }

            // skip check the cursor here because the cursor is asserted in getNumDVNs
            // if we have reached the end of the options, we need to process the last dvn
            uint256 size = cursor - start;
            bytes memory op = _options.slice(start, size);
            _insertDVNOptions(dvnOptions, dvnIndices, lastDVNIdx, op);

            // revert dvnIndices to start from 0
            for (uint8 i = 0; i < numDVNs; ++i) {
                --dvnIndices[i];
            }
        }
    }

    function _insertDVNOptions(
        bytes[] memory _dvnOptions,
        uint8[] memory _dvnIndices,
        uint8 _dvnIdx,
        bytes memory _newOptions
    ) internal pure {
        // dvnIdx starts from 0 but default value of dvnIndices is 0,
        // so we tell if the slot is empty by adding 1 to dvnIdx
        if (_dvnIdx == 255) revert DVN_InvalidDVNIdx();
        uint8 dvnIdxAdj = _dvnIdx + 1;

        for (uint256 j = 0; j < _dvnIndices.length; ++j) {
            uint8 index = _dvnIndices[j];
            if (dvnIdxAdj == index) {
                _dvnOptions[j] = abi.encodePacked(_dvnOptions[j], _newOptions);
                break;
            } else if (index == 0) {
                // empty slot, that means it is the first time we see this dvn
                _dvnIndices[j] = dvnIdxAdj;
                _dvnOptions[j] = _newOptions;
                break;
            }
        }
    }

    /// @dev get the number of unique dvns
    /// @param _options the format is the same as groupDVNOptionsByIdx
    function getNumDVNs(bytes memory _options) internal pure returns (uint8 numDVNs) {
        uint256 cursor = 0;
        BitMap256 bitmap;

        // find number of unique dvn_idx
        unchecked {
            while (cursor < _options.length) {
                ++cursor; // skip worker_id

                uint16 optionLength = _options.toUint16(cursor);
                cursor += 2;
                if (optionLength < 2) revert DVN_InvalidDVNOptions(cursor); // at least 1 byte for dvn_idx and 1 byte for option_type

                uint8 dvnIdx = _options.toUint8(cursor);

                // if dvnIdx is not set, increment numDVNs
                // max num of dvns is 255, 255 is an invalid dvn_idx
                // The order of the dvnIdx is not required to be sequential, as enforcing the order may weaken
                // the composability of the options. e.g. if we refrain from enforcing the order, an OApp that has
                // already enforced certain options can append additional options to the end of the enforced
                // ones without restrictions.
                if (dvnIdx == 255) revert DVN_InvalidDVNIdx();
                if (!bitmap.get(dvnIdx)) {
                    ++numDVNs;
                    bitmap = bitmap.set(dvnIdx);
                }

                cursor += optionLength;
            }
        }
        if (cursor != _options.length) revert DVN_InvalidDVNOptions(cursor);
    }

    /// @dev decode the next dvn option from _options starting from the specified cursor
    /// @param _options the format is the same as groupDVNOptionsByIdx
    /// @param _cursor the cursor to start decoding
    /// @return optionType the type of the option
    /// @return option the option
    /// @return cursor the cursor to start decoding the next option
    function nextDVNOption(
        bytes calldata _options,
        uint256 _cursor
    ) internal pure returns (uint8 optionType, bytes calldata option, uint256 cursor) {
        unchecked {
            // skip worker id
            cursor = _cursor + 1;

            // read option size
            uint16 size = _options.toU16(cursor);
            cursor += 2;

            // read option type
            optionType = _options.toU8(cursor + 1); // skip dvn_idx

            // startCursor and endCursor are used to slice the option from _options
            uint256 startCursor = cursor + 2; // skip option type and dvn_idx
            uint256 endCursor = cursor + size;
            option = _options[startCursor:endCursor];
            cursor += size;
        }
    }
}

File 3 of 36 : IOAppCore.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { ILayerZeroEndpointV2 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";

/**
 * @title IOAppCore
 */
interface IOAppCore {
    // Custom error messages
    error OnlyPeer(uint32 eid, bytes32 sender);
    error NoPeer(uint32 eid);
    error InvalidEndpointCall();
    error InvalidDelegate();

    // Event emitted when a peer (OApp) is set for a corresponding endpoint
    event PeerSet(uint32 eid, bytes32 peer);

    /**
     * @notice Retrieves the OApp version information.
     * @return senderVersion The version of the OAppSender.sol contract.
     * @return receiverVersion The version of the OAppReceiver.sol contract.
     */
    function oAppVersion() external view returns (uint64 senderVersion, uint64 receiverVersion);

    /**
     * @notice Retrieves the LayerZero endpoint associated with the OApp.
     * @return iEndpoint The LayerZero endpoint as an interface.
     */
    function endpoint() external view returns (ILayerZeroEndpointV2 iEndpoint);

    /**
     * @notice Retrieves the peer (OApp) associated with a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @return peer The peer address (OApp instance) associated with the corresponding endpoint.
     */
    function peers(uint32 _eid) external view returns (bytes32 peer);

    /**
     * @notice Sets the peer address (OApp instance) for a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @param _peer The address of the peer to be associated with the corresponding endpoint.
     */
    function setPeer(uint32 _eid, bytes32 _peer) external;

    /**
     * @notice Sets the delegate address for the OApp Core.
     * @param _delegate The address of the delegate to be set.
     */
    function setDelegate(address _delegate) external;
}

File 4 of 36 : IOAppReceiver.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import { ILayerZeroReceiver, Origin } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroReceiver.sol";

interface IOAppReceiver is ILayerZeroReceiver {
    /**
     * @notice Indicates whether an address is an approved composeMsg sender to the Endpoint.
     * @param _origin The origin information containing the source endpoint and sender address.
     *  - srcEid: The source chain endpoint ID.
     *  - sender: The sender address on the src chain.
     *  - nonce: The nonce of the message.
     * @param _message The lzReceive payload.
     * @param _sender The sender address.
     * @return isSender Is a valid sender.
     *
     * @dev Applications can optionally choose to implement a separate composeMsg sender that is NOT the bridging layer.
     * @dev The default sender IS the OAppReceiver implementer.
     */
    function isComposeMsgSender(
        Origin calldata _origin,
        bytes calldata _message,
        address _sender
    ) external view returns (bool isSender);
}

File 5 of 36 : OptionsBuilder.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { BytesLib } from "solidity-bytes-utils/contracts/BytesLib.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";

import { ExecutorOptions } from "@layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/ExecutorOptions.sol";
import { DVNOptions } from "@layerzerolabs/lz-evm-messagelib-v2/contracts/uln/libs/DVNOptions.sol";

/**
 * @title OptionsBuilder
 * @dev Library for building and encoding various message options.
 */
library OptionsBuilder {
    using SafeCast for uint256;
    using BytesLib for bytes;

    // Constants for options types
    uint16 internal constant TYPE_1 = 1; // legacy options type 1
    uint16 internal constant TYPE_2 = 2; // legacy options type 2
    uint16 internal constant TYPE_3 = 3;

    // Custom error message
    error InvalidSize(uint256 max, uint256 actual);
    error InvalidOptionType(uint16 optionType);

    // Modifier to ensure only options of type 3 are used
    modifier onlyType3(bytes memory _options) {
        if (_options.toUint16(0) != TYPE_3) revert InvalidOptionType(_options.toUint16(0));
        _;
    }

    /**
     * @dev Creates a new options container with type 3.
     * @return options The newly created options container.
     */
    function newOptions() internal pure returns (bytes memory) {
        return abi.encodePacked(TYPE_3);
    }

    /**
     * @dev Adds an executor LZ receive option to the existing options.
     * @param _options The existing options container.
     * @param _gas The gasLimit used on the lzReceive() function in the OApp.
     * @param _value The msg.value passed to the lzReceive() function in the OApp.
     * @return options The updated options container.
     *
     * @dev When multiples of this option are added, they are summed by the executor
     * eg. if (_gas: 200k, and _value: 1 ether) AND (_gas: 100k, _value: 0.5 ether) are sent in an option to the LayerZeroEndpoint,
     * that becomes (300k, 1.5 ether) when the message is executed on the remote lzReceive() function.
     */
    function addExecutorLzReceiveOption(
        bytes memory _options,
        uint128 _gas,
        uint128 _value
    ) internal pure onlyType3(_options) returns (bytes memory) {
        bytes memory option = ExecutorOptions.encodeLzReceiveOption(_gas, _value);
        return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_LZRECEIVE, option);
    }

    /**
     * @dev Adds an executor native drop option to the existing options.
     * @param _options The existing options container.
     * @param _amount The amount for the native value that is airdropped to the 'receiver'.
     * @param _receiver The receiver address for the native drop option.
     * @return options The updated options container.
     *
     * @dev When multiples of this option are added, they are summed by the executor on the remote chain.
     */
    function addExecutorNativeDropOption(
        bytes memory _options,
        uint128 _amount,
        bytes32 _receiver
    ) internal pure onlyType3(_options) returns (bytes memory) {
        bytes memory option = ExecutorOptions.encodeNativeDropOption(_amount, _receiver);
        return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_NATIVE_DROP, option);
    }

    /**
     * @dev Adds an executor LZ compose option to the existing options.
     * @param _options The existing options container.
     * @param _index The index for the lzCompose() function call.
     * @param _gas The gasLimit for the lzCompose() function call.
     * @param _value The msg.value for the lzCompose() function call.
     * @return options The updated options container.
     *
     * @dev When multiples of this option are added, they are summed PER index by the executor on the remote chain.
     * @dev If the OApp sends N lzCompose calls on the remote, you must provide N incremented indexes starting with 0.
     * ie. When your remote OApp composes (N = 3) messages, you must set this option for index 0,1,2
     */
    function addExecutorLzComposeOption(
        bytes memory _options,
        uint16 _index,
        uint128 _gas,
        uint128 _value
    ) internal pure onlyType3(_options) returns (bytes memory) {
        bytes memory option = ExecutorOptions.encodeLzComposeOption(_index, _gas, _value);
        return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_LZCOMPOSE, option);
    }

    /**
     * @dev Adds an executor ordered execution option to the existing options.
     * @param _options The existing options container.
     * @return options The updated options container.
     */
    function addExecutorOrderedExecutionOption(
        bytes memory _options
    ) internal pure onlyType3(_options) returns (bytes memory) {
        return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_ORDERED_EXECUTION, bytes(""));
    }

    /**
     * @dev Adds a DVN pre-crime option to the existing options.
     * @param _options The existing options container.
     * @param _dvnIdx The DVN index for the pre-crime option.
     * @return options The updated options container.
     */
    function addDVNPreCrimeOption(
        bytes memory _options,
        uint8 _dvnIdx
    ) internal pure onlyType3(_options) returns (bytes memory) {
        return addDVNOption(_options, _dvnIdx, DVNOptions.OPTION_TYPE_PRECRIME, bytes(""));
    }

    /**
     * @dev Adds an executor option to the existing options.
     * @param _options The existing options container.
     * @param _optionType The type of the executor option.
     * @param _option The encoded data for the executor option.
     * @return options The updated options container.
     */
    function addExecutorOption(
        bytes memory _options,
        uint8 _optionType,
        bytes memory _option
    ) internal pure onlyType3(_options) returns (bytes memory) {
        return
            abi.encodePacked(
                _options,
                ExecutorOptions.WORKER_ID,
                _option.length.toUint16() + 1, // +1 for optionType
                _optionType,
                _option
            );
    }

    /**
     * @dev Adds a DVN option to the existing options.
     * @param _options The existing options container.
     * @param _dvnIdx The DVN index for the DVN option.
     * @param _optionType The type of the DVN option.
     * @param _option The encoded data for the DVN option.
     * @return options The updated options container.
     */
    function addDVNOption(
        bytes memory _options,
        uint8 _dvnIdx,
        uint8 _optionType,
        bytes memory _option
    ) internal pure onlyType3(_options) returns (bytes memory) {
        return
            abi.encodePacked(
                _options,
                DVNOptions.WORKER_ID,
                _option.length.toUint16() + 2, // +2 for optionType and dvnIdx
                _dvnIdx,
                _optionType,
                _option
            );
    }

    /**
     * @dev Encodes legacy options of type 1.
     * @param _executionGas The gasLimit value passed to lzReceive().
     * @return legacyOptions The encoded legacy options.
     */
    function encodeLegacyOptionsType1(uint256 _executionGas) internal pure returns (bytes memory) {
        if (_executionGas > type(uint128).max) revert InvalidSize(type(uint128).max, _executionGas);
        return abi.encodePacked(TYPE_1, _executionGas);
    }

    /**
     * @dev Encodes legacy options of type 2.
     * @param _executionGas The gasLimit value passed to lzReceive().
     * @param _nativeForDst The amount of native air dropped to the receiver.
     * @param _receiver The _nativeForDst receiver address.
     * @return legacyOptions The encoded legacy options of type 2.
     */
    function encodeLegacyOptionsType2(
        uint256 _executionGas,
        uint256 _nativeForDst,
        bytes memory _receiver // @dev Use bytes instead of bytes32 in legacy type 2 for _receiver.
    ) internal pure returns (bytes memory) {
        if (_executionGas > type(uint128).max) revert InvalidSize(type(uint128).max, _executionGas);
        if (_nativeForDst > type(uint128).max) revert InvalidSize(type(uint128).max, _nativeForDst);
        if (_receiver.length > 32) revert InvalidSize(32, _receiver.length);
        return abi.encodePacked(TYPE_2, _executionGas, _nativeForDst, _receiver);
    }
}

File 6 of 36 : OApp.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

// @dev Import the 'MessagingFee' and 'MessagingReceipt' so it's exposed to OApp implementers
// solhint-disable-next-line no-unused-import
import { OAppSender, MessagingFee, MessagingReceipt } from "./OAppSender.sol";
// @dev Import the 'Origin' so it's exposed to OApp implementers
// solhint-disable-next-line no-unused-import
import { OAppReceiver, Origin } from "./OAppReceiver.sol";
import { OAppCore } from "./OAppCore.sol";

/**
 * @title OApp
 * @dev Abstract contract serving as the base for OApp implementation, combining OAppSender and OAppReceiver functionality.
 */
abstract contract OApp is OAppSender, OAppReceiver {
    /**
     * @dev Constructor to initialize the OApp with the provided endpoint and owner.
     * @param _endpoint The address of the LOCAL LayerZero endpoint.
     * @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
     */
    constructor(address _endpoint, address _delegate) OAppCore(_endpoint, _delegate) {}

    /**
     * @notice Retrieves the OApp version information.
     * @return senderVersion The version of the OAppSender.sol implementation.
     * @return receiverVersion The version of the OAppReceiver.sol implementation.
     */
    function oAppVersion()
        public
        pure
        virtual
        override(OAppSender, OAppReceiver)
        returns (uint64 senderVersion, uint64 receiverVersion)
    {
        return (SENDER_VERSION, RECEIVER_VERSION);
    }
}

File 7 of 36 : OAppCore.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IOAppCore, ILayerZeroEndpointV2 } from "./interfaces/IOAppCore.sol";

/**
 * @title OAppCore
 * @dev Abstract contract implementing the IOAppCore interface with basic OApp configurations.
 */
abstract contract OAppCore is IOAppCore, Ownable {
    // The LayerZero endpoint associated with the given OApp
    ILayerZeroEndpointV2 public immutable endpoint;

    // Mapping to store peers associated with corresponding endpoints
    mapping(uint32 eid => bytes32 peer) public peers;

    /**
     * @dev Constructor to initialize the OAppCore with the provided endpoint and delegate.
     * @param _endpoint The address of the LOCAL Layer Zero endpoint.
     * @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
     *
     * @dev The delegate typically should be set as the owner of the contract.
     */
    constructor(address _endpoint, address _delegate) {
        endpoint = ILayerZeroEndpointV2(_endpoint);

        if (_delegate == address(0)) revert InvalidDelegate();
        endpoint.setDelegate(_delegate);
    }

    /**
     * @notice Sets the peer address (OApp instance) for a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @param _peer The address of the peer to be associated with the corresponding endpoint.
     *
     * @dev Only the owner/admin of the OApp can call this function.
     * @dev Indicates that the peer is trusted to send LayerZero messages to this OApp.
     * @dev Set this to bytes32(0) to remove the peer address.
     * @dev Peer is a bytes32 to accommodate non-evm chains.
     */
    function setPeer(uint32 _eid, bytes32 _peer) public virtual onlyOwner {
        _setPeer(_eid, _peer);
    }

    /**
     * @notice Sets the peer address (OApp instance) for a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @param _peer The address of the peer to be associated with the corresponding endpoint.
     *
     * @dev Indicates that the peer is trusted to send LayerZero messages to this OApp.
     * @dev Set this to bytes32(0) to remove the peer address.
     * @dev Peer is a bytes32 to accommodate non-evm chains.
     */
    function _setPeer(uint32 _eid, bytes32 _peer) internal virtual {
        peers[_eid] = _peer;
        emit PeerSet(_eid, _peer);
    }

    /**
     * @notice Internal function to get the peer address associated with a specific endpoint; reverts if NOT set.
     * ie. the peer is set to bytes32(0).
     * @param _eid The endpoint ID.
     * @return peer The address of the peer associated with the specified endpoint.
     */
    function _getPeerOrRevert(uint32 _eid) internal view virtual returns (bytes32) {
        bytes32 peer = peers[_eid];
        if (peer == bytes32(0)) revert NoPeer(_eid);
        return peer;
    }

    /**
     * @notice Sets the delegate address for the OApp.
     * @param _delegate The address of the delegate to be set.
     *
     * @dev Only the owner/admin of the OApp can call this function.
     * @dev Provides the ability for a delegate to set configs, on behalf of the OApp, directly on the Endpoint contract.
     */
    function setDelegate(address _delegate) public onlyOwner {
        endpoint.setDelegate(_delegate);
    }
}

File 8 of 36 : OAppReceiver.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { IOAppReceiver, Origin } from "./interfaces/IOAppReceiver.sol";
import { OAppCore } from "./OAppCore.sol";

/**
 * @title OAppReceiver
 * @dev Abstract contract implementing the ILayerZeroReceiver interface and extending OAppCore for OApp receivers.
 */
abstract contract OAppReceiver is IOAppReceiver, OAppCore {
    // Custom error message for when the caller is not the registered endpoint/
    error OnlyEndpoint(address addr);

    // @dev The version of the OAppReceiver implementation.
    // @dev Version is bumped when changes are made to this contract.
    uint64 internal constant RECEIVER_VERSION = 2;

    /**
     * @notice Retrieves the OApp version information.
     * @return senderVersion The version of the OAppSender.sol contract.
     * @return receiverVersion The version of the OAppReceiver.sol contract.
     *
     * @dev Providing 0 as the default for OAppSender version. Indicates that the OAppSender is not implemented.
     * ie. this is a RECEIVE only OApp.
     * @dev If the OApp uses both OAppSender and OAppReceiver, then this needs to be override returning the correct versions.
     */
    function oAppVersion() public view virtual returns (uint64 senderVersion, uint64 receiverVersion) {
        return (0, RECEIVER_VERSION);
    }

    /**
     * @notice Indicates whether an address is an approved composeMsg sender to the Endpoint.
     * @dev _origin The origin information containing the source endpoint and sender address.
     *  - srcEid: The source chain endpoint ID.
     *  - sender: The sender address on the src chain.
     *  - nonce: The nonce of the message.
     * @dev _message The lzReceive payload.
     * @param _sender The sender address.
     * @return isSender Is a valid sender.
     *
     * @dev Applications can optionally choose to implement separate composeMsg senders that are NOT the bridging layer.
     * @dev The default sender IS the OAppReceiver implementer.
     */
    function isComposeMsgSender(
        Origin calldata /*_origin*/,
        bytes calldata /*_message*/,
        address _sender
    ) public view virtual returns (bool) {
        return _sender == address(this);
    }

    /**
     * @notice Checks if the path initialization is allowed based on the provided origin.
     * @param origin The origin information containing the source endpoint and sender address.
     * @return Whether the path has been initialized.
     *
     * @dev This indicates to the endpoint that the OApp has enabled msgs for this particular path to be received.
     * @dev This defaults to assuming if a peer has been set, its initialized.
     * Can be overridden by the OApp if there is other logic to determine this.
     */
    function allowInitializePath(Origin calldata origin) public view virtual returns (bool) {
        return peers[origin.srcEid] == origin.sender;
    }

    /**
     * @notice Retrieves the next nonce for a given source endpoint and sender address.
     * @dev _srcEid The source endpoint ID.
     * @dev _sender The sender address.
     * @return nonce The next nonce.
     *
     * @dev The path nonce starts from 1. If 0 is returned it means that there is NO nonce ordered enforcement.
     * @dev Is required by the off-chain executor to determine the OApp expects msg execution is ordered.
     * @dev This is also enforced by the OApp.
     * @dev By default this is NOT enabled. ie. nextNonce is hardcoded to return 0.
     */
    function nextNonce(uint32 /*_srcEid*/, bytes32 /*_sender*/) public view virtual returns (uint64 nonce) {
        return 0;
    }

    /**
     * @dev Entry point for receiving messages or packets from the endpoint.
     * @param _origin The origin information containing the source endpoint and sender address.
     *  - srcEid: The source chain endpoint ID.
     *  - sender: The sender address on the src chain.
     *  - nonce: The nonce of the message.
     * @param _guid The unique identifier for the received LayerZero message.
     * @param _message The payload of the received message.
     * @param _executor The address of the executor for the received message.
     * @param _extraData Additional arbitrary data provided by the corresponding executor.
     *
     * @dev Entry point for receiving msg/packet from the LayerZero endpoint.
     */
    function lzReceive(
        Origin calldata _origin,
        bytes32 _guid,
        bytes calldata _message,
        address _executor,
        bytes calldata _extraData
    ) public payable virtual {
        // Ensures that only the endpoint can attempt to lzReceive() messages to this OApp.
        if (address(endpoint) != msg.sender) revert OnlyEndpoint(msg.sender);

        // Ensure that the sender matches the expected peer for the source endpoint.
        if (_getPeerOrRevert(_origin.srcEid) != _origin.sender) revert OnlyPeer(_origin.srcEid, _origin.sender);

        // Call the internal OApp implementation of lzReceive.
        _lzReceive(_origin, _guid, _message, _executor, _extraData);
    }

    /**
     * @dev Internal function to implement lzReceive logic without needing to copy the basic parameter validation.
     */
    function _lzReceive(
        Origin calldata _origin,
        bytes32 _guid,
        bytes calldata _message,
        address _executor,
        bytes calldata _extraData
    ) internal virtual;
}

File 9 of 36 : OAppSender.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { MessagingParams, MessagingFee, MessagingReceipt } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import { OAppCore } from "./OAppCore.sol";

/**
 * @title OAppSender
 * @dev Abstract contract implementing the OAppSender functionality for sending messages to a LayerZero endpoint.
 */
abstract contract OAppSender is OAppCore {
    using SafeERC20 for IERC20;

    // Custom error messages
    error NotEnoughNative(uint256 msgValue);
    error LzTokenUnavailable();

    // @dev The version of the OAppSender implementation.
    // @dev Version is bumped when changes are made to this contract.
    uint64 internal constant SENDER_VERSION = 1;

    /**
     * @notice Retrieves the OApp version information.
     * @return senderVersion The version of the OAppSender.sol contract.
     * @return receiverVersion The version of the OAppReceiver.sol contract.
     *
     * @dev Providing 0 as the default for OAppReceiver version. Indicates that the OAppReceiver is not implemented.
     * ie. this is a SEND only OApp.
     * @dev If the OApp uses both OAppSender and OAppReceiver, then this needs to be override returning the correct versions
     */
    function oAppVersion() public view virtual returns (uint64 senderVersion, uint64 receiverVersion) {
        return (SENDER_VERSION, 0);
    }

    /**
     * @dev Internal function to interact with the LayerZero EndpointV2.quote() for fee calculation.
     * @param _dstEid The destination endpoint ID.
     * @param _message The message payload.
     * @param _options Additional options for the message.
     * @param _payInLzToken Flag indicating whether to pay the fee in LZ tokens.
     * @return fee The calculated MessagingFee for the message.
     *      - nativeFee: The native fee for the message.
     *      - lzTokenFee: The LZ token fee for the message.
     */
    function _quote(
        uint32 _dstEid,
        bytes memory _message,
        bytes memory _options,
        bool _payInLzToken
    ) internal view virtual returns (MessagingFee memory fee) {
        return
            endpoint.quote(
                MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _payInLzToken),
                address(this)
            );
    }

    /**
     * @dev Internal function to interact with the LayerZero EndpointV2.send() for sending a message.
     * @param _dstEid The destination endpoint ID.
     * @param _message The message payload.
     * @param _options Additional options for the message.
     * @param _fee The calculated LayerZero fee for the message.
     *      - nativeFee: The native fee.
     *      - lzTokenFee: The lzToken fee.
     * @param _refundAddress The address to receive any excess fee values sent to the endpoint.
     * @return receipt The receipt for the sent message.
     *      - guid: The unique identifier for the sent message.
     *      - nonce: The nonce of the sent message.
     *      - fee: The LayerZero fee incurred for the message.
     */
    function _lzSend(
        uint32 _dstEid,
        bytes memory _message,
        bytes memory _options,
        MessagingFee memory _fee,
        address _refundAddress
    ) internal virtual returns (MessagingReceipt memory receipt) {
        // @dev Push corresponding fees to the endpoint, any excess is sent back to the _refundAddress from the endpoint.
        uint256 messageValue = _payNative(_fee.nativeFee);
        if (_fee.lzTokenFee > 0) _payLzToken(_fee.lzTokenFee);

        return
            // solhint-disable-next-line check-send-result
            endpoint.send{ value: messageValue }(
                MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _fee.lzTokenFee > 0),
                _refundAddress
            );
    }

    /**
     * @dev Internal function to pay the native fee associated with the message.
     * @param _nativeFee The native fee to be paid.
     * @return nativeFee The amount of native currency paid.
     *
     * @dev If the OApp needs to initiate MULTIPLE LayerZero messages in a single transaction,
     * this will need to be overridden because msg.value would contain multiple lzFees.
     * @dev Should be overridden in the event the LayerZero endpoint requires a different native currency.
     * @dev Some EVMs use an ERC20 as a method for paying transactions/gasFees.
     * @dev The endpoint is EITHER/OR, ie. it will NOT support both types of native payment at a time.
     */
    function _payNative(uint256 _nativeFee) internal virtual returns (uint256 nativeFee) {
        if (msg.value != _nativeFee) revert NotEnoughNative(msg.value);
        return _nativeFee;
    }

    /**
     * @dev Internal function to pay the LZ token fee associated with the message.
     * @param _lzTokenFee The LZ token fee to be paid.
     *
     * @dev If the caller is trying to pay in the specified lzToken, then the lzTokenFee is passed to the endpoint.
     * @dev Any excess sent, is passed back to the specified _refundAddress in the _lzSend().
     */
    function _payLzToken(uint256 _lzTokenFee) internal virtual {
        // @dev Cannot cache the token because it is not immutable in the endpoint.
        address lzToken = endpoint.lzToken();
        if (lzToken == address(0)) revert LzTokenUnavailable();

        // Pay LZ token fee by sending tokens to the endpoint.
        IERC20(lzToken).safeTransferFrom(msg.sender, address(endpoint), _lzTokenFee);
    }
}

File 10 of 36 : ILayerZeroEndpointV2.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

import { IMessageLibManager } from "./IMessageLibManager.sol";
import { IMessagingComposer } from "./IMessagingComposer.sol";
import { IMessagingChannel } from "./IMessagingChannel.sol";
import { IMessagingContext } from "./IMessagingContext.sol";

struct MessagingParams {
    uint32 dstEid;
    bytes32 receiver;
    bytes message;
    bytes options;
    bool payInLzToken;
}

struct MessagingReceipt {
    bytes32 guid;
    uint64 nonce;
    MessagingFee fee;
}

struct MessagingFee {
    uint256 nativeFee;
    uint256 lzTokenFee;
}

struct Origin {
    uint32 srcEid;
    bytes32 sender;
    uint64 nonce;
}

interface ILayerZeroEndpointV2 is IMessageLibManager, IMessagingComposer, IMessagingChannel, IMessagingContext {
    event PacketSent(bytes encodedPayload, bytes options, address sendLibrary);

    event PacketVerified(Origin origin, address receiver, bytes32 payloadHash);

    event PacketDelivered(Origin origin, address receiver);

    event LzReceiveAlert(
        address indexed receiver,
        address indexed executor,
        Origin origin,
        bytes32 guid,
        uint256 gas,
        uint256 value,
        bytes message,
        bytes extraData,
        bytes reason
    );

    event LzTokenSet(address token);

    event DelegateSet(address sender, address delegate);

    function quote(MessagingParams calldata _params, address _sender) external view returns (MessagingFee memory);

    function send(
        MessagingParams calldata _params,
        address _refundAddress
    ) external payable returns (MessagingReceipt memory);

    function verify(Origin calldata _origin, address _receiver, bytes32 _payloadHash) external;

    function verifiable(Origin calldata _origin, address _receiver) external view returns (bool);

    function initializable(Origin calldata _origin, address _receiver) external view returns (bool);

    function lzReceive(
        Origin calldata _origin,
        address _receiver,
        bytes32 _guid,
        bytes calldata _message,
        bytes calldata _extraData
    ) external payable;

    // oapp can burn messages partially by calling this function with its own business logic if messages are verified in order
    function clear(address _oapp, Origin calldata _origin, bytes32 _guid, bytes calldata _message) external;

    function setLzToken(address _lzToken) external;

    function lzToken() external view returns (address);

    function nativeToken() external view returns (address);

    function setDelegate(address _delegate) external;
}

File 11 of 36 : ILayerZeroReceiver.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

import { Origin } from "./ILayerZeroEndpointV2.sol";

interface ILayerZeroReceiver {
    function allowInitializePath(Origin calldata _origin) external view returns (bool);

    function nextNonce(uint32 _eid, bytes32 _sender) external view returns (uint64);

    function lzReceive(
        Origin calldata _origin,
        bytes32 _guid,
        bytes calldata _message,
        address _executor,
        bytes calldata _extraData
    ) external payable;
}

File 12 of 36 : IMessageLibManager.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

struct SetConfigParam {
    uint32 eid;
    uint32 configType;
    bytes config;
}

interface IMessageLibManager {
    struct Timeout {
        address lib;
        uint256 expiry;
    }

    event LibraryRegistered(address newLib);
    event DefaultSendLibrarySet(uint32 eid, address newLib);
    event DefaultReceiveLibrarySet(uint32 eid, address newLib);
    event DefaultReceiveLibraryTimeoutSet(uint32 eid, address oldLib, uint256 expiry);
    event SendLibrarySet(address sender, uint32 eid, address newLib);
    event ReceiveLibrarySet(address receiver, uint32 eid, address newLib);
    event ReceiveLibraryTimeoutSet(address receiver, uint32 eid, address oldLib, uint256 timeout);

    function registerLibrary(address _lib) external;

    function isRegisteredLibrary(address _lib) external view returns (bool);

    function getRegisteredLibraries() external view returns (address[] memory);

    function setDefaultSendLibrary(uint32 _eid, address _newLib) external;

    function defaultSendLibrary(uint32 _eid) external view returns (address);

    function setDefaultReceiveLibrary(uint32 _eid, address _newLib, uint256 _gracePeriod) external;

    function defaultReceiveLibrary(uint32 _eid) external view returns (address);

    function setDefaultReceiveLibraryTimeout(uint32 _eid, address _lib, uint256 _expiry) external;

    function defaultReceiveLibraryTimeout(uint32 _eid) external view returns (address lib, uint256 expiry);

    function isSupportedEid(uint32 _eid) external view returns (bool);

    function isValidReceiveLibrary(address _receiver, uint32 _eid, address _lib) external view returns (bool);

    /// ------------------- OApp interfaces -------------------
    function setSendLibrary(address _oapp, uint32 _eid, address _newLib) external;

    function getSendLibrary(address _sender, uint32 _eid) external view returns (address lib);

    function isDefaultSendLibrary(address _sender, uint32 _eid) external view returns (bool);

    function setReceiveLibrary(address _oapp, uint32 _eid, address _newLib, uint256 _gracePeriod) external;

    function getReceiveLibrary(address _receiver, uint32 _eid) external view returns (address lib, bool isDefault);

    function setReceiveLibraryTimeout(address _oapp, uint32 _eid, address _lib, uint256 _expiry) external;

    function receiveLibraryTimeout(address _receiver, uint32 _eid) external view returns (address lib, uint256 expiry);

    function setConfig(address _oapp, address _lib, SetConfigParam[] calldata _params) external;

    function getConfig(
        address _oapp,
        address _lib,
        uint32 _eid,
        uint32 _configType
    ) external view returns (bytes memory config);
}

File 13 of 36 : IMessagingChannel.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

interface IMessagingChannel {
    event InboundNonceSkipped(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce);
    event PacketNilified(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);
    event PacketBurnt(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);

    function eid() external view returns (uint32);

    // this is an emergency function if a message cannot be verified for some reasons
    // required to provide _nextNonce to avoid race condition
    function skip(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce) external;

    function nilify(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;

    function burn(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;

    function nextGuid(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (bytes32);

    function inboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);

    function outboundNonce(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (uint64);

    function inboundPayloadHash(
        address _receiver,
        uint32 _srcEid,
        bytes32 _sender,
        uint64 _nonce
    ) external view returns (bytes32);

    function lazyInboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);
}

File 14 of 36 : IMessagingComposer.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

interface IMessagingComposer {
    event ComposeSent(address from, address to, bytes32 guid, uint16 index, bytes message);
    event ComposeDelivered(address from, address to, bytes32 guid, uint16 index);
    event LzComposeAlert(
        address indexed from,
        address indexed to,
        address indexed executor,
        bytes32 guid,
        uint16 index,
        uint256 gas,
        uint256 value,
        bytes message,
        bytes extraData,
        bytes reason
    );

    function composeQueue(
        address _from,
        address _to,
        bytes32 _guid,
        uint16 _index
    ) external view returns (bytes32 messageHash);

    function sendCompose(address _to, bytes32 _guid, uint16 _index, bytes calldata _message) external;

    function lzCompose(
        address _from,
        address _to,
        bytes32 _guid,
        uint16 _index,
        bytes calldata _message,
        bytes calldata _extraData
    ) external payable;
}

File 15 of 36 : IMessagingContext.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

interface IMessagingContext {
    function isSendingMessage() external view returns (bool);

    function getSendContext() external view returns (uint32 dstEid, address sender);
}

File 16 of 36 : CalldataBytesLib.sol
// SPDX-License-Identifier: LZBL-1.2

pragma solidity ^0.8.20;

library CalldataBytesLib {
    function toU8(bytes calldata _bytes, uint256 _start) internal pure returns (uint8) {
        return uint8(_bytes[_start]);
    }

    function toU16(bytes calldata _bytes, uint256 _start) internal pure returns (uint16) {
        unchecked {
            uint256 end = _start + 2;
            return uint16(bytes2(_bytes[_start:end]));
        }
    }

    function toU32(bytes calldata _bytes, uint256 _start) internal pure returns (uint32) {
        unchecked {
            uint256 end = _start + 4;
            return uint32(bytes4(_bytes[_start:end]));
        }
    }

    function toU64(bytes calldata _bytes, uint256 _start) internal pure returns (uint64) {
        unchecked {
            uint256 end = _start + 8;
            return uint64(bytes8(_bytes[_start:end]));
        }
    }

    function toU128(bytes calldata _bytes, uint256 _start) internal pure returns (uint128) {
        unchecked {
            uint256 end = _start + 16;
            return uint128(bytes16(_bytes[_start:end]));
        }
    }

    function toU256(bytes calldata _bytes, uint256 _start) internal pure returns (uint256) {
        unchecked {
            uint256 end = _start + 32;
            return uint256(bytes32(_bytes[_start:end]));
        }
    }

    function toAddr(bytes calldata _bytes, uint256 _start) internal pure returns (address) {
        unchecked {
            uint256 end = _start + 20;
            return address(bytes20(_bytes[_start:end]));
        }
    }

    function toB32(bytes calldata _bytes, uint256 _start) internal pure returns (bytes32) {
        unchecked {
            uint256 end = _start + 32;
            return bytes32(_bytes[_start:end]);
        }
    }
}

File 17 of 36 : BitMaps.sol
// SPDX-License-Identifier: MIT

// modified from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/structs/BitMaps.sol
pragma solidity ^0.8.20;

type BitMap256 is uint256;

using BitMaps for BitMap256 global;

library BitMaps {
    /**
     * @dev Returns whether the bit at `index` is set.
     */
    function get(BitMap256 bitmap, uint8 index) internal pure returns (bool) {
        uint256 mask = 1 << index;
        return BitMap256.unwrap(bitmap) & mask != 0;
    }

    /**
     * @dev Sets the bit at `index`.
     */
    function set(BitMap256 bitmap, uint8 index) internal pure returns (BitMap256) {
        uint256 mask = 1 << index;
        return BitMap256.wrap(BitMap256.unwrap(bitmap) | mask);
    }
}

File 18 of 36 : ExecutorOptions.sol
// SPDX-License-Identifier: LZBL-1.2

pragma solidity ^0.8.20;

import { CalldataBytesLib } from "../../libs/CalldataBytesLib.sol";

library ExecutorOptions {
    using CalldataBytesLib for bytes;

    uint8 internal constant WORKER_ID = 1;

    uint8 internal constant OPTION_TYPE_LZRECEIVE = 1;
    uint8 internal constant OPTION_TYPE_NATIVE_DROP = 2;
    uint8 internal constant OPTION_TYPE_LZCOMPOSE = 3;
    uint8 internal constant OPTION_TYPE_ORDERED_EXECUTION = 4;

    error Executor_InvalidLzReceiveOption();
    error Executor_InvalidNativeDropOption();
    error Executor_InvalidLzComposeOption();

    /// @dev decode the next executor option from the options starting from the specified cursor
    /// @param _options [executor_id][executor_option][executor_id][executor_option]...
    ///        executor_option = [option_size][option_type][option]
    ///        option_size = len(option_type) + len(option)
    ///        executor_id: uint8, option_size: uint16, option_type: uint8, option: bytes
    /// @param _cursor the cursor to start decoding from
    /// @return optionType the type of the option
    /// @return option the option of the executor
    /// @return cursor the cursor to start decoding the next executor option
    function nextExecutorOption(
        bytes calldata _options,
        uint256 _cursor
    ) internal pure returns (uint8 optionType, bytes calldata option, uint256 cursor) {
        unchecked {
            // skip worker id
            cursor = _cursor + 1;

            // read option size
            uint16 size = _options.toU16(cursor);
            cursor += 2;

            // read option type
            optionType = _options.toU8(cursor);

            // startCursor and endCursor are used to slice the option from _options
            uint256 startCursor = cursor + 1; // skip option type
            uint256 endCursor = cursor + size;
            option = _options[startCursor:endCursor];
            cursor += size;
        }
    }

    function decodeLzReceiveOption(bytes calldata _option) internal pure returns (uint128 gas, uint128 value) {
        if (_option.length != 16 && _option.length != 32) revert Executor_InvalidLzReceiveOption();
        gas = _option.toU128(0);
        value = _option.length == 32 ? _option.toU128(16) : 0;
    }

    function decodeNativeDropOption(bytes calldata _option) internal pure returns (uint128 amount, bytes32 receiver) {
        if (_option.length != 48) revert Executor_InvalidNativeDropOption();
        amount = _option.toU128(0);
        receiver = _option.toB32(16);
    }

    function decodeLzComposeOption(
        bytes calldata _option
    ) internal pure returns (uint16 index, uint128 gas, uint128 value) {
        if (_option.length != 18 && _option.length != 34) revert Executor_InvalidLzComposeOption();
        index = _option.toU16(0);
        gas = _option.toU128(2);
        value = _option.length == 34 ? _option.toU128(18) : 0;
    }

    function encodeLzReceiveOption(uint128 _gas, uint128 _value) internal pure returns (bytes memory) {
        return _value == 0 ? abi.encodePacked(_gas) : abi.encodePacked(_gas, _value);
    }

    function encodeNativeDropOption(uint128 _amount, bytes32 _receiver) internal pure returns (bytes memory) {
        return abi.encodePacked(_amount, _receiver);
    }

    function encodeLzComposeOption(uint16 _index, uint128 _gas, uint128 _value) internal pure returns (bytes memory) {
        return _value == 0 ? abi.encodePacked(_index, _gas) : abi.encodePacked(_index, _gas, _value);
    }
}

File 19 of 36 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 20 of 36 : IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 21 of 36 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

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

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

File 22 of 36 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";

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

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

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

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

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

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

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}

File 23 of 36 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

File 24 of 36 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

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

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

File 25 of 36 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.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
     *
     * _Available since v4.7._
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.2._
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
        return uint136(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
     *
     * _Available since v2.5._
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
        return uint104(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
     *
     * _Available since v4.2._
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
        return uint72(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
     *
     * _Available since v2.5._
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
        return uint40(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
     *
     * _Available since v2.5._
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
        return uint24(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
     *
     * _Available since v2.5._
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value <= type(uint16).max, "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
     *
     * _Available since v2.5._
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value <= type(uint8).max, "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.
     *
     * _Available since v3.0._
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.7._
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int128(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.7._
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int64(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int32(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int16(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
    }

    /**
     * @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 downcasted) {
        downcasted = int8(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     *
     * _Available since v3.0._
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

File 26 of 36 : BaseBridge.sol
// SPDX-License-Identifier: MIT

pragma solidity =0.8.24;

import "@openzeppelin/contracts/access/Ownable.sol";
import "../libraries/TransferHelper.sol";
import "../interfaces/ISynthrSwap.sol";
import "../interfaces/ISynthrSwapDex.sol";
import "../interfaces/IFuturesMarketManager.sol";

interface IAddressResolver {
    function getAddress(bytes32 name) external view returns (address);
}

abstract contract BaseBridge is Ownable {
    error Invalid_caller();

    address public _synthrAddressResolver;

    uint16 internal constant PT_DEPOSIT_COLLATERAL = 1;
    uint16 internal constant PT_MINT_SYNTH = 2;
    uint16 internal constant PT_WITHDRAW_COLLATERAL = 3;
    uint16 internal constant PT_BURN_SYNTH = 4;
    uint16 internal constant PT_EXCHANGE = 5;
    uint16 internal constant PT_LIQUIDATE = 6;
    uint16 internal constant PT_BRIDGE_SYNTH = 7;
    uint16 internal constant PT_TRANSFER_MARGIN = 9;
    uint16 internal constant PT_WITHDRAW_MARGIN = 10;
    uint16 internal constant PT_CROSS_SWAP_CASE_1 = 11;
    uint16 internal constant PT_CROSS_SWAP_CASE_2 = 12;
    uint16 internal constant PT_CROSS_SWAP_CASE_3 = 13;
    uint16 internal constant PT_CROSS_SWAP_DEX_CASE_1 = 14;
    uint16 internal constant PT_CROSS_SWAP_DEX_CASE_3 = 15;

    constructor() {}

    modifier onlySynthr() {
        if (isAllowedCaller(msg.sender)) {
            _;
        } else {
            revert Invalid_caller();
        }
    }

    receive() external payable {}

    function isAllowedCaller(address caller) private view returns (bool) {
        return
            caller == getAddressFromResolver("WrappedSynthr") ||
            caller == getAddressFromResolver("Issuer") ||
            caller == getAddressFromResolver("Exchanger") ||
            caller == getAddressFromResolver("SynthrSwap") ||
            caller == getAddressFromResolver("SynthrSwapWithDex") ||
            caller == getAddressFromResolver("OffChainExchanger") ||
            caller == getAddressFromResolver("FuturesMarketManager") ||
            IFuturesMarketManager(getAddressFromResolver("FuturesMarketManager")).isMarketImplementation(caller);
    }

    function getAddressFromResolver(bytes32 name) internal view returns (address) {
        return IAddressResolver(_synthrAddressResolver).getAddress(name);
    }

    /**
     * @notice Calculate the fee for a given payload and packet type
     * @param payload The payload to calculate the fee for
     * @param packetType The packet type
     * @param dstChainId The destination chain ID
     * @return The calculated fee
     */
    function calcFee(
        bytes memory payload,
        uint16 packetType,
        uint16 dstChainId
    ) public view virtual returns (uint);

    /**
     * @notice Withdraw a specified amount of a given token
     * @param token The address of the token to withdraw
     * @param amount The amount to withdraw
     */
    function withdrawAsset(address token, uint amount) public onlyOwner {
        if (token == address(0)) {
            TransferHelper.safeTransferETH(msg.sender, amount);
        } else {
            TransferHelper.safeTransfer(token, msg.sender, amount);
        }
    }
}

File 27 of 36 : BaseBridgeLZ.sol
// SPDX-License-Identifier: MIT

pragma solidity =0.8.24;

// import "@layerzerolabs/solidity-examples/contracts/lzApp/NonblockingLzApp.sol";
import {OApp, MessagingFee, Origin} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OApp.sol";
import {MessagingReceipt} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OAppSender.sol";
import {OptionsBuilder} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/libs/OptionsBuilder.sol";
import "../BaseBridge.sol";

/**
 * @title BaseBridgeLZ
 * @dev Base Bridge contract for cross-chain communication using LayerZero
 */
abstract contract BaseBridgeLZ is BaseBridge, OApp {
    using OptionsBuilder for bytes;

    error Bridge_limit_not_set_for_endpoint(uint32 endPoint);
    error Fee_Percentage_should_be_more_than_hundred();
    error Invalid_gasLimit_to_set();
    error Invalid_crossChainFee_attached(uint256 attached, uint256 expected);

    uint16 internal _selfLZChainId;
    uint16 public lzFeePercentage;
    uint16 internal _mainChainId;
    mapping(uint32 destinationEps => uint128 gasLimit) gasLimits;

    event SendPacket(
        address indexed account,
        bytes32 path,
        bytes32 guid,
        uint16 indexed packetType,
        uint16 indexed dstEid,
        uint64 nonce
    );
    event ReceivePacket(
        address indexed account,
        bytes32 path,
        bytes32 guid,
        uint16 indexed packetType,
        uint16 indexed srcChainId,
        uint64 nonce
    );

    constructor(address _lzEndpoint, address _owner) OApp(_lzEndpoint, _owner) {}

    /**
     * @notice Get the LayerZero chain ID of the current chain
     * @return The LayerZero chain ID
     */
    function selfLZChainId() external view returns (uint16) {
        return _selfLZChainId;
    }

    /**
     * @notice Get the options for a given destination endpoint
     * @param _destinationEP The destination endpoint
     * @return options The options for the destination endpoint
     */
    function getOptions(uint32 _destinationEP) public view returns (bytes memory options) {
        uint128 gasLimit = gasLimits[_destinationEP];
        if (gasLimit == 0) {
            revert Bridge_limit_not_set_for_endpoint(_destinationEP);
        }
        options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(gasLimit, 0);
    }

    /**
     * @notice Set the LayerZero fee percentage
     * @param _percentage The fee percentage (must be at least 100)
     */
    function setLZFeePercentage(uint16 _percentage) public {
        if (_percentage < 100) {
            revert Fee_Percentage_should_be_more_than_hundred();
        }
        lzFeePercentage = _percentage;
    }

    /**
     * @notice Set the gas limit for a given destination endpoint
     * @param _destinationEP The destination endpoint
     * @param _gasLimit The gas limit to set
     */
    function setGasLimit(uint32 _destinationEP, uint128 _gasLimit) external onlyOwner {
        if (_gasLimit <= 0) {
            revert Invalid_gasLimit_to_set();
        }
        gasLimits[_destinationEP] = _gasLimit;
    }

    /**
     * @notice Calculate the LayerZero fee for a given payload
     * @param lzPayload The LayerZero payload
     * @param packetType The packet type
     * @param dstEid The destination endpoint ID
     * @return lzFee The calculated LayerZero fee
     */
    function calcFee(bytes memory lzPayload, uint16 packetType, uint16 dstEid) public view override returns (uint256 lzFee) {
        bytes memory _options = getOptions(dstEid);

        MessagingFee memory fee = _quote(dstEid, lzPayload, _options, false);
        if (_checkMultiBroadcast(packetType)) {
            fee.nativeFee += (_quote(_mainChainId, lzPayload, getOptions(_mainChainId), false)).nativeFee;
        }
        lzFee = fee.nativeFee * lzFeePercentage / 100;
    }

    // check for different packetTypes to invoke 2-way cross transaction in case of lightchain <> lightchain
    function _checkMultiBroadcast(uint16 _packetType) private view returns (bool isAllowed) {
        if (
            (
                _packetType == PT_EXCHANGE || _packetType == PT_BRIDGE_SYNTH || _packetType == PT_CROSS_SWAP_CASE_1
                    || _packetType == PT_CROSS_SWAP_CASE_2 || _packetType == PT_CROSS_SWAP_CASE_3
                    || _packetType == PT_CROSS_SWAP_DEX_CASE_1 || _packetType == PT_CROSS_SWAP_DEX_CASE_3
            ) && (_selfLZChainId != _mainChainId)
        ) {
            isAllowed = true;
        }
    }
    /**
     * @return Consumed native gas in crosschain transaction
     */
    function _broadcast(
        address account,
        bytes memory lzPayload,
        uint16 packetType,
        uint16 dstEid,
        uint256 value,
        bool // the param to check ZRO token payment
    ) internal returns (uint256) {
        bytes memory _options = getOptions(dstEid);
        MessagingFee memory fee = _quote(dstEid, lzPayload, _options, false);
        if (value < fee.nativeFee) {
            revert Invalid_crossChainFee_attached(value, fee.nativeFee);
        }
        MessagingReceipt memory receipt =
            _lzSend(dstEid, lzPayload, _options, MessagingFee(fee.nativeFee, 0), payable(address(this)));

        {
            bytes32 path = _getPeerOrRevert(dstEid);
            emit SendPacket(account, path, receipt.guid, packetType, dstEid, receipt.nonce);
        }

        return receipt.fee.nativeFee;
    }

    function _getPacketType(bytes memory _payload) internal pure returns (uint16 _packetType) {
        assembly {
            _packetType := mload(add(_payload, 32))
        }
    }

    // overrided _payNative for multiple cross chain transactions {bridge, exchange in lightchain}
    function _payNative(uint256 _nativeFee) internal override returns (uint256 nativeFee) {
        if (msg.value < _nativeFee) revert NotEnoughNative(msg.value);
        return _nativeFee;
    }
}

File 28 of 36 : IExchanger.sol
// SPDX-License-Identifier: MIT

pragma solidity =0.8.24;

interface IExchanger {
    function updateDestinationForExchange(
        address recipient,
        bytes32 destinationKey,
        uint destinationAmount
    ) external;
}

File 29 of 36 : IFuturesMarketManager.sol
// SPDX-License-Identifier: MIT

pragma solidity =0.8.24;

interface IFuturesMarketManager {
    function marketForKey(bytes32 marketKey) external view returns (address);

    function isMarketImplementation(address _account) external view returns (bool);
}

File 30 of 36 : ISynthrIssuer.sol
// SPDX-License-Identifier: MIT

pragma solidity =0.8.24;

interface ISynthrIssuer {
    function synthsByAddress(address synthAddress) external view returns (bytes32);

    function destIssue(
        address account,
        bytes32 synthKey,
        uint synthAmount
    ) external;
}

File 31 of 36 : ISynthrSwap.sol
// SPDX-License-Identifier: MIT

pragma solidity =0.8.24;

interface ISynthrSwap {
    function destSwapSynthToNative(
        address account,
        bytes32 sourceKey,
        uint sourceAmount,
        bytes32 destKey,
        uint destAmount,
        address target,
        bytes memory data
    ) external returns (bool);

    function destSwapNativeToSynth(
        address account,
        bytes32 sourceKey,
        uint sourceAmount,
        bytes32 destKey,
        uint destAmount
    ) external;

    function destSwapNativeToNative(
        address account,
        bytes32 sourceKey,
        uint sourceAmount,
        bytes32 destKey,
        uint destAmount,
        address target,
        bytes memory data
    ) external returns (bool);
}

File 32 of 36 : ISynthrSwapDex.sol
// SPDX-License-Identifier: MIT

pragma solidity =0.8.24;

interface ISynthrSwapDex {
    function destSwapSynthToNative(
        address account,
        bytes32 sourceKey,
        uint sourceAmount,
        bytes32 destKey,
        uint destAmount
    ) external returns (bool);

    function destSwapNativeToNative(
        address account,
        bytes32 sourceKey,
        uint sourceAmount,
        bytes32 destKey,
        uint destAmount
    ) external returns (bool);
}

File 33 of 36 : IWrappedSynthr.sol
// SPDX-License-Identifier: MIT

pragma solidity =0.8.24;

interface IWrappedSynthr {
    function getAvailableCollaterals() external view returns (bytes32[] memory);

    function withdrawCollateral(
        address from,
        address to,
        bytes32 collateralKey,
        uint collateralAmount
    ) external;

    function collateralTransfer(
        address _from,
        bytes32 _collateralKey,
        uint _collateralAmount
    ) external;

    function destBurn(
        address account,
        bytes32 synthKey,
        uint amount
    ) external returns (bool);

    function destTransferMargin(
        address account,
        uint marginDelta,
        bytes32 marketKey
    ) external returns (bool);
}

File 34 of 36 : BytesLib.sol
// SPDX-License-Identifier: Unlicense
/*
 * @title Solidity Bytes Arrays Utils
 * @author Gonçalo Sá <[email protected]>
 *
 * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.
 *      The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
 */
pragma solidity =0.8.24;

library BytesLib {
    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 concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal {
        assembly {
            // Read the first 32 bytes of _preBytes storage, which is the length
            // of the array. (We don't need to use the offset into the slot
            // because arrays use the entire slot.)
            let fslot := sload(_preBytes.slot)
            // Arrays of 31 bytes or less have an even value in their slot,
            // while longer arrays have an odd value. The actual length is
            // the slot divided by two for odd values, and the lowest order
            // byte divided by two for even values.
            // If the slot is even, bitwise and the slot with 255 and divide by
            // two to get the length. If the slot is odd, bitwise and the slot
            // with -1 and divide by two.
            let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
            let mlength := mload(_postBytes)
            let newlength := add(slength, mlength)
            // slength can contain both the length and contents of the array
            // if length < 32 bytes so let's prepare for that
            // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
            switch add(lt(slength, 32), lt(newlength, 32))
            case 2 {
                // Since the new array still fits in the slot, we just need to
                // update the contents of the slot.
                // uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length
                sstore(
                    _preBytes.slot,
                    // all the modifications to the slot are inside this
                    // next block
                    add(
                        // we can just add to the slot contents because the
                        // bytes we want to change are the LSBs
                        fslot,
                        add(
                            mul(
                                div(
                                    // load the bytes from memory
                                    mload(add(_postBytes, 0x20)),
                                    // zero all bytes to the right
                                    exp(0x100, sub(32, mlength))
                                ),
                                // and now shift left the number of bytes to
                                // leave space for the length in the slot
                                exp(0x100, sub(32, newlength))
                            ),
                            // increase length by the double of the memory
                            // bytes length
                            mul(mlength, 2)
                        )
                    )
                )
            }
            case 1 {
                // The stored value fits in the slot, but the combined value
                // will exceed it.
                // get the keccak hash to get the contents of the array
                mstore(0x0, _preBytes.slot)
                let sc := add(keccak256(0x0, 0x20), div(slength, 32))

                // save new length
                sstore(_preBytes.slot, add(mul(newlength, 2), 1))

                // The contents of the _postBytes array start 32 bytes into
                // the structure. Our first read should obtain the `submod`
                // bytes that can fit into the unused space in the last word
                // of the stored array. To get this, we read 32 bytes starting
                // from `submod`, so the data we read overlaps with the array
                // contents by `submod` bytes. Masking the lowest-order
                // `submod` bytes allows us to add that value directly to the
                // stored value.

                let submod := sub(32, slength)
                let mc := add(_postBytes, submod)
                let end := add(_postBytes, mlength)
                let mask := sub(exp(0x100, submod), 1)

                sstore(
                    sc,
                    add(
                        and(fslot, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00),
                        and(mload(mc), mask)
                    )
                )

                for {
                    mc := add(mc, 0x20)
                    sc := add(sc, 1)
                } lt(mc, end) {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } { sstore(sc, mload(mc)) }

                mask := exp(0x100, sub(mc, end))

                sstore(sc, mul(div(mload(mc), mask), mask))
            }
            default {
                // get the keccak hash to get the contents of the array
                mstore(0x0, _preBytes.slot)
                // Start copying to the last used word of the stored array.
                let sc := add(keccak256(0x0, 0x20), div(slength, 32))

                // save new length
                sstore(_preBytes.slot, add(mul(newlength, 2), 1))

                // Copy over the first `submod` bytes of the new data as in
                // case 1 above.
                let slengthmod := mod(slength, 32)
                let mlengthmod := mod(mlength, 32)
                let submod := sub(32, slengthmod)
                let mc := add(_postBytes, submod)
                let end := add(_postBytes, mlength)
                let mask := sub(exp(0x100, submod), 1)

                sstore(sc, add(sload(sc), and(mload(mc), mask)))

                for {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } lt(mc, end) {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } { sstore(sc, mload(mc)) }

                mask := exp(0x100, sub(mc, end))

                sstore(sc, mul(div(mload(mc), mask), mask))
            }
        }
    }

    function slice(bytes memory _bytes, uint256 _start, uint256 _length) internal pure returns (bytes memory) {
        require(_length + 31 >= _length, "slice_overflow");
        require(_bytes.length >= _start + _length, "slice_outOfBounds");

        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)
                //zero out the 32 bytes slice we are about to return
                //we need to do it because Solidity does not garbage collect
                mstore(tempBytes, 0)

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

        return tempBytes;
    }

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

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

        return tempAddress;
    }

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

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

        return tempUint;
    }

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

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

        return tempUint;
    }

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

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

        return tempUint;
    }

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

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

        return tempUint;
    }

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

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

        return tempUint;
    }

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

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

        return tempUint;
    }

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

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

        return tempUint;
    }

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

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

        return tempBytes32;
    }

    function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) {
        bool success = true;

        assembly {
            let length := mload(_preBytes)

            // if lengths don't match the arrays are not equal
            switch eq(length, mload(_postBytes))
            case 1 {
                // cb is a circuit breaker in the for loop since there's
                //  no said feature for inline assembly loops
                // cb = 1 - don't breaker
                // cb = 0 - break
                let cb := 1

                let mc := add(_preBytes, 0x20)
                let end := add(mc, length)

                for { let cc := add(_postBytes, 0x20) }
                // the next line is the loop condition:
                // while(uint256(mc < end) + cb == 2)
                eq(add(lt(mc, end), cb), 2) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    // if any of these checks fails then arrays are not equal
                    if iszero(eq(mload(mc), mload(cc))) {
                        // unsuccess:
                        success := 0
                        cb := 0
                    }
                }
            }
            default {
                // unsuccess:
                success := 0
            }
        }

        return success;
    }

    function equal_nonAligned(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) {
        bool success = true;

        assembly {
            let length := mload(_preBytes)

            // if lengths don't match the arrays are not equal
            switch eq(length, mload(_postBytes))
            case 1 {
                // cb is a circuit breaker in the for loop since there's
                //  no said feature for inline assembly loops
                // cb = 1 - don't breaker
                // cb = 0 - break
                let cb := 1

                let endMinusWord := add(_preBytes, length)
                let mc := add(_preBytes, 0x20)
                let cc := add(_postBytes, 0x20)

                for {
                    // the next line is the loop condition:
                    // while(uint256(mc < endWord) + cb == 2)
                } eq(add(lt(mc, endMinusWord), cb), 2) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    // if any of these checks fails then arrays are not equal
                    if iszero(eq(mload(mc), mload(cc))) {
                        // unsuccess:
                        success := 0
                        cb := 0
                    }
                }

                // Only if still successful
                // For <1 word tail bytes
                if gt(success, 0) {
                    // Get the remainder of length/32
                    // length % 32 = AND(length, 32 - 1)
                    let numTailBytes := and(length, 0x1f)
                    let mcRem := mload(mc)
                    let ccRem := mload(cc)
                    for { let i := 0 }
                    // the next line is the loop condition:
                    // while(uint256(i < numTailBytes) + cb == 2)
                    eq(add(lt(i, numTailBytes), cb), 2) { i := add(i, 1) } {
                        if iszero(eq(byte(i, mcRem), byte(i, ccRem))) {
                            // unsuccess:
                            success := 0
                            cb := 0
                        }
                    }
                }
            }
            default {
                // unsuccess:
                success := 0
            }
        }

        return success;
    }

    function equalStorage(bytes storage _preBytes, bytes memory _postBytes) internal view returns (bool) {
        bool success = true;

        assembly {
            // we know _preBytes_offset is 0
            let fslot := sload(_preBytes.slot)
            // Decode the length of the stored array like in concatStorage().
            let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
            let mlength := mload(_postBytes)

            // if lengths don't match the arrays are not equal
            switch eq(slength, mlength)
            case 1 {
                // slength can contain both the length and contents of the array
                // if length < 32 bytes so let's prepare for that
                // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
                if iszero(iszero(slength)) {
                    switch lt(slength, 32)
                    case 1 {
                        // blank the last byte which is the length
                        fslot := mul(div(fslot, 0x100), 0x100)

                        if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) {
                            // unsuccess:
                            success := 0
                        }
                    }
                    default {
                        // cb is a circuit breaker in the for loop since there's
                        //  no said feature for inline assembly loops
                        // cb = 1 - don't breaker
                        // cb = 0 - break
                        let cb := 1

                        // get the keccak hash to get the contents of the array
                        mstore(0x0, _preBytes.slot)
                        let sc := keccak256(0x0, 0x20)

                        let mc := add(_postBytes, 0x20)
                        let end := add(mc, mlength)

                        // the next line is the loop condition:
                        // while(uint256(mc < end) + cb == 2)
                        for {} eq(add(lt(mc, end), cb), 2) {
                            sc := add(sc, 1)
                            mc := add(mc, 0x20)
                        } {
                            if iszero(eq(sload(sc), mload(mc))) {
                                // unsuccess:
                                success := 0
                                cb := 0
                            }
                        }
                    }
                }
            }
            default {
                // unsuccess:
                success := 0
            }
        }

        return success;
    }
}

File 35 of 36 : TransferHelper.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity =0.8.24;

library TransferHelper {
    function safeTransfer(
        address token,
        address to,
        uint value
    ) internal {
        // bytes4(keccak256(bytes('transfer(address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), "TransferHelper::safeTransfer: transfer failed");
    }

    function safeTransferETH(address to, uint value) internal {
        (bool success, ) = to.call{value: value}(new bytes(0));
        require(success, "TransferHelper::safeTransferETH: ETH transfer failed");
    }
}

File 36 of 36 : BytesLib.sol
// SPDX-License-Identifier: Unlicense
/*
 * @title Solidity Bytes Arrays Utils
 * @author Gonçalo Sá <[email protected]>
 *
 * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.
 *      The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
 */
pragma solidity >=0.8.0 <0.9.0;


library BytesLib {
    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 concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal {
        assembly {
            // Read the first 32 bytes of _preBytes storage, which is the length
            // of the array. (We don't need to use the offset into the slot
            // because arrays use the entire slot.)
            let fslot := sload(_preBytes.slot)
            // Arrays of 31 bytes or less have an even value in their slot,
            // while longer arrays have an odd value. The actual length is
            // the slot divided by two for odd values, and the lowest order
            // byte divided by two for even values.
            // If the slot is even, bitwise and the slot with 255 and divide by
            // two to get the length. If the slot is odd, bitwise and the slot
            // with -1 and divide by two.
            let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
            let mlength := mload(_postBytes)
            let newlength := add(slength, mlength)
            // slength can contain both the length and contents of the array
            // if length < 32 bytes so let's prepare for that
            // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
            switch add(lt(slength, 32), lt(newlength, 32))
            case 2 {
                // Since the new array still fits in the slot, we just need to
                // update the contents of the slot.
                // uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length
                sstore(
                    _preBytes.slot,
                    // all the modifications to the slot are inside this
                    // next block
                    add(
                        // we can just add to the slot contents because the
                        // bytes we want to change are the LSBs
                        fslot,
                        add(
                            mul(
                                div(
                                    // load the bytes from memory
                                    mload(add(_postBytes, 0x20)),
                                    // zero all bytes to the right
                                    exp(0x100, sub(32, mlength))
                                ),
                                // and now shift left the number of bytes to
                                // leave space for the length in the slot
                                exp(0x100, sub(32, newlength))
                            ),
                            // increase length by the double of the memory
                            // bytes length
                            mul(mlength, 2)
                        )
                    )
                )
            }
            case 1 {
                // The stored value fits in the slot, but the combined value
                // will exceed it.
                // get the keccak hash to get the contents of the array
                mstore(0x0, _preBytes.slot)
                let sc := add(keccak256(0x0, 0x20), div(slength, 32))

                // save new length
                sstore(_preBytes.slot, add(mul(newlength, 2), 1))

                // The contents of the _postBytes array start 32 bytes into
                // the structure. Our first read should obtain the `submod`
                // bytes that can fit into the unused space in the last word
                // of the stored array. To get this, we read 32 bytes starting
                // from `submod`, so the data we read overlaps with the array
                // contents by `submod` bytes. Masking the lowest-order
                // `submod` bytes allows us to add that value directly to the
                // stored value.

                let submod := sub(32, slength)
                let mc := add(_postBytes, submod)
                let end := add(_postBytes, mlength)
                let mask := sub(exp(0x100, submod), 1)

                sstore(
                    sc,
                    add(
                        and(
                            fslot,
                            0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00
                        ),
                        and(mload(mc), mask)
                    )
                )

                for {
                    mc := add(mc, 0x20)
                    sc := add(sc, 1)
                } lt(mc, end) {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } {
                    sstore(sc, mload(mc))
                }

                mask := exp(0x100, sub(mc, end))

                sstore(sc, mul(div(mload(mc), mask), mask))
            }
            default {
                // get the keccak hash to get the contents of the array
                mstore(0x0, _preBytes.slot)
                // Start copying to the last used word of the stored array.
                let sc := add(keccak256(0x0, 0x20), div(slength, 32))

                // save new length
                sstore(_preBytes.slot, add(mul(newlength, 2), 1))

                // Copy over the first `submod` bytes of the new data as in
                // case 1 above.
                let slengthmod := mod(slength, 32)
                let mlengthmod := mod(mlength, 32)
                let submod := sub(32, slengthmod)
                let mc := add(_postBytes, submod)
                let end := add(_postBytes, mlength)
                let mask := sub(exp(0x100, submod), 1)

                sstore(sc, add(sload(sc), and(mload(mc), mask)))

                for {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } lt(mc, end) {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } {
                    sstore(sc, mload(mc))
                }

                mask := exp(0x100, sub(mc, end))

                sstore(sc, mul(div(mload(mc), mask), mask))
            }
        }
    }

    function slice(
        bytes memory _bytes,
        uint256 _start,
        uint256 _length
    )
        internal
        pure
        returns (bytes memory)
    {
        require(_length + 31 >= _length, "slice_overflow");
        require(_bytes.length >= _start + _length, "slice_outOfBounds");

        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)
                //zero out the 32 bytes slice we are about to return
                //we need to do it because Solidity does not garbage collect
                mstore(tempBytes, 0)

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

        return tempBytes;
    }

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

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

        return tempAddress;
    }

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

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

        return tempUint;
    }

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

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

        return tempUint;
    }

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

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

        return tempUint;
    }

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

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

        return tempUint;
    }

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

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

        return tempUint;
    }

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

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

        return tempUint;
    }

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

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

        return tempUint;
    }

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

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

        return tempBytes32;
    }

    function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) {
        bool success = true;

        assembly {
            let length := mload(_preBytes)

            // if lengths don't match the arrays are not equal
            switch eq(length, mload(_postBytes))
            case 1 {
                // cb is a circuit breaker in the for loop since there's
                //  no said feature for inline assembly loops
                // cb = 1 - don't breaker
                // cb = 0 - break
                let cb := 1

                let mc := add(_preBytes, 0x20)
                let end := add(mc, length)

                for {
                    let cc := add(_postBytes, 0x20)
                // the next line is the loop condition:
                // while(uint256(mc < end) + cb == 2)
                } eq(add(lt(mc, end), cb), 2) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    // if any of these checks fails then arrays are not equal
                    if iszero(eq(mload(mc), mload(cc))) {
                        // unsuccess:
                        success := 0
                        cb := 0
                    }
                }
            }
            default {
                // unsuccess:
                success := 0
            }
        }

        return success;
    }

    function equal_nonAligned(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) {
        bool success = true;

        assembly {
            let length := mload(_preBytes)

            // if lengths don't match the arrays are not equal
            switch eq(length, mload(_postBytes))
            case 1 {
                // cb is a circuit breaker in the for loop since there's
                //  no said feature for inline assembly loops
                // cb = 1 - don't breaker
                // cb = 0 - break
                let cb := 1

                let endMinusWord := add(_preBytes, length)
                let mc := add(_preBytes, 0x20)
                let cc := add(_postBytes, 0x20)

                for {
                // the next line is the loop condition:
                // while(uint256(mc < endWord) + cb == 2)
                } eq(add(lt(mc, endMinusWord), cb), 2) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    // if any of these checks fails then arrays are not equal
                    if iszero(eq(mload(mc), mload(cc))) {
                        // unsuccess:
                        success := 0
                        cb := 0
                    }
                }

                // Only if still successful
                // For <1 word tail bytes
                if gt(success, 0) {
                    // Get the remainder of length/32
                    // length % 32 = AND(length, 32 - 1)
                    let numTailBytes := and(length, 0x1f)
                    let mcRem := mload(mc)
                    let ccRem := mload(cc)
                    for {
                        let i := 0
                    // the next line is the loop condition:
                    // while(uint256(i < numTailBytes) + cb == 2)
                    } eq(add(lt(i, numTailBytes), cb), 2) {
                        i := add(i, 1)
                    } {
                        if iszero(eq(byte(i, mcRem), byte(i, ccRem))) {
                            // unsuccess:
                            success := 0
                            cb := 0
                        }
                    }
                }
            }
            default {
                // unsuccess:
                success := 0
            }
        }

        return success;
    }

    function equalStorage(
        bytes storage _preBytes,
        bytes memory _postBytes
    )
        internal
        view
        returns (bool)
    {
        bool success = true;

        assembly {
            // we know _preBytes_offset is 0
            let fslot := sload(_preBytes.slot)
            // Decode the length of the stored array like in concatStorage().
            let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
            let mlength := mload(_postBytes)

            // if lengths don't match the arrays are not equal
            switch eq(slength, mlength)
            case 1 {
                // slength can contain both the length and contents of the array
                // if length < 32 bytes so let's prepare for that
                // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
                if iszero(iszero(slength)) {
                    switch lt(slength, 32)
                    case 1 {
                        // blank the last byte which is the length
                        fslot := mul(div(fslot, 0x100), 0x100)

                        if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) {
                            // unsuccess:
                            success := 0
                        }
                    }
                    default {
                        // cb is a circuit breaker in the for loop since there's
                        //  no said feature for inline assembly loops
                        // cb = 1 - don't breaker
                        // cb = 0 - break
                        let cb := 1

                        // get the keccak hash to get the contents of the array
                        mstore(0x0, _preBytes.slot)
                        let sc := keccak256(0x0, 0x20)

                        let mc := add(_postBytes, 0x20)
                        let end := add(mc, mlength)

                        // the next line is the loop condition:
                        // while(uint256(mc < end) + cb == 2)
                        for {} eq(add(lt(mc, end), cb), 2) {
                            sc := add(sc, 1)
                            mc := add(mc, 0x20)
                        } {
                            if iszero(eq(sload(sc), mload(mc))) {
                                // unsuccess:
                                success := 0
                                cb := 0
                            }
                        }
                    }
                }
            }
            default {
                // unsuccess:
                success := 0
            }
        }

        return success;
    }
}

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

Contract ABI

[{"inputs":[{"internalType":"address","name":"_lzEndpoint","type":"address"},{"internalType":"address","name":"_owner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint32","name":"endPoint","type":"uint32"}],"name":"Bridge_limit_not_set_for_endpoint","type":"error"},{"inputs":[],"name":"Bridging_on_same_chain","type":"error"},{"inputs":[],"name":"Fee_Percentage_should_be_more_than_hundred","type":"error"},{"inputs":[],"name":"InvalidDelegate","type":"error"},{"inputs":[],"name":"InvalidEndpointCall","type":"error"},{"inputs":[{"internalType":"uint16","name":"optionType","type":"uint16"}],"name":"InvalidOptionType","type":"error"},{"inputs":[],"name":"Invalid_caller","type":"error"},{"inputs":[{"internalType":"uint256","name":"attached","type":"uint256"},{"internalType":"uint256","name":"expected","type":"uint256"}],"name":"Invalid_crossChainFee_attached","type":"error"},{"inputs":[],"name":"Invalid_gasLimit_to_set","type":"error"},{"inputs":[],"name":"LzTokenUnavailable","type":"error"},{"inputs":[],"name":"MarginDelta_should_be_greater_than_zero","type":"error"},{"inputs":[{"internalType":"uint32","name":"eid","type":"uint32"}],"name":"NoPeer","type":"error"},{"inputs":[{"internalType":"uint256","name":"msgValue","type":"uint256"}],"name":"NotEnoughNative","type":"error"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"OnlyEndpoint","type":"error"},{"inputs":[{"internalType":"uint32","name":"eid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"}],"name":"OnlyPeer","type":"error"},{"inputs":[{"internalType":"uint16","name":"packetType","type":"uint16"}],"name":"Unknown_packetType","type":"error"},{"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":"uint32","name":"eid","type":"uint32"},{"indexed":false,"internalType":"bytes32","name":"peer","type":"bytes32"}],"name":"PeerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bytes32","name":"path","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"guid","type":"bytes32"},{"indexed":true,"internalType":"uint16","name":"packetType","type":"uint16"},{"indexed":true,"internalType":"uint16","name":"srcChainId","type":"uint16"},{"indexed":false,"internalType":"uint64","name":"nonce","type":"uint64"}],"name":"ReceivePacket","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bytes32","name":"path","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"guid","type":"bytes32"},{"indexed":true,"internalType":"uint16","name":"packetType","type":"uint16"},{"indexed":true,"internalType":"uint16","name":"dstEid","type":"uint16"},{"indexed":false,"internalType":"uint64","name":"nonce","type":"uint64"}],"name":"SendPacket","type":"event"},{"inputs":[],"name":"_synthrAddressResolver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"srcEid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"}],"internalType":"struct Origin","name":"origin","type":"tuple"}],"name":"allowInitializePath","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"lzPayload","type":"bytes"},{"internalType":"uint16","name":"packetType","type":"uint16"},{"internalType":"uint16","name":"dstEid","type":"uint16"}],"name":"calcFee","outputs":[{"internalType":"uint256","name":"lzFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"endpoint","outputs":[{"internalType":"contract ILayerZeroEndpointV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_destinationEP","type":"uint32"}],"name":"getOptions","outputs":[{"internalType":"bytes","name":"options","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"__synthrAddressResolver","type":"address"},{"internalType":"uint16","name":"__mainChainId","type":"uint16"},{"internalType":"uint16","name":"__selfLZChainId","type":"uint16"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"srcEid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"}],"internalType":"struct Origin","name":"","type":"tuple"},{"internalType":"bytes","name":"","type":"bytes"},{"internalType":"address","name":"_sender","type":"address"}],"name":"isComposeMsgSender","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lzFeePercentage","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"srcEid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"}],"internalType":"struct Origin","name":"_origin","type":"tuple"},{"internalType":"bytes32","name":"_guid","type":"bytes32"},{"internalType":"bytes","name":"_message","type":"bytes"},{"internalType":"address","name":"_executor","type":"address"},{"internalType":"bytes","name":"_extraData","type":"bytes"}],"name":"lzReceive","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"mainChainId","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"nextNonce","outputs":[{"internalType":"uint64","name":"nonce","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oAppVersion","outputs":[{"internalType":"uint64","name":"senderVersion","type":"uint64"},{"internalType":"uint64","name":"receiverVersion","type":"uint64"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"eid","type":"uint32"}],"name":"peers","outputs":[{"internalType":"bytes32","name":"peer","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"selfLZChainId","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"synthKey","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint16","name":"dstChainId","type":"uint16"},{"internalType":"bool","name":"","type":"bool"}],"name":"sendBridgeSyToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"synthKey","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"","type":"bool"}],"name":"sendBurn","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"srcKey","type":"bytes32"},{"internalType":"uint256","name":"srcAmount","type":"uint256"},{"internalType":"bytes32","name":"dstKey","type":"bytes32"},{"internalType":"uint256","name":"dstAmount","type":"uint256"},{"internalType":"uint16","name":"dstChainId","type":"uint16"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"address","name":"dexAddress","type":"address"},{"internalType":"bytes","name":"dexPayload","type":"bytes"},{"internalType":"bool","name":"","type":"bool"}],"name":"sendCrossSwapNativeToNative","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"srcKey","type":"bytes32"},{"internalType":"uint256","name":"srcAmount","type":"uint256"},{"internalType":"bytes32","name":"dstKey","type":"bytes32"},{"internalType":"uint256","name":"dstAmount","type":"uint256"},{"internalType":"uint16","name":"dstChainId","type":"uint16"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"bool","name":"","type":"bool"}],"name":"sendCrossSwapNativeToNativeWithDex","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"srcKey","type":"bytes32"},{"internalType":"uint256","name":"srcAmount","type":"uint256"},{"internalType":"bytes32","name":"dstKey","type":"bytes32"},{"internalType":"uint256","name":"dstAmount","type":"uint256"},{"internalType":"uint16","name":"dstChainId","type":"uint16"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"bool","name":"","type":"bool"}],"name":"sendCrossSwapNativeToSyAsset","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"srcKey","type":"bytes32"},{"internalType":"uint256","name":"srcAmount","type":"uint256"},{"internalType":"bytes32","name":"dstKey","type":"bytes32"},{"internalType":"uint256","name":"dstAmount","type":"uint256"},{"internalType":"uint16","name":"dstChainId","type":"uint16"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"bytes","name":"dexPayload","type":"bytes"},{"internalType":"address","name":"dexAddress","type":"address"},{"internalType":"bool","name":"","type":"bool"}],"name":"sendCrossSwapSyAssetToNative","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"srcKey","type":"bytes32"},{"internalType":"uint256","name":"srcAmount","type":"uint256"},{"internalType":"bytes32","name":"dstKey","type":"bytes32"},{"internalType":"uint256","name":"dstAmount","type":"uint256"},{"internalType":"uint16","name":"dstChainId","type":"uint16"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"bool","name":"","type":"bool"}],"name":"sendCrossSwapSyAssetToNativeWithDex","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"collateralKey","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"","type":"bool"}],"name":"sendDepositCollateral","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"srcSynthKey","type":"bytes32"},{"internalType":"bytes32","name":"dstSynthKey","type":"bytes32"},{"internalType":"uint256","name":"srcAmount","type":"uint256"},{"internalType":"uint256","name":"dstAmount","type":"uint256"},{"internalType":"uint256","name":"reclaimed","type":"uint256"},{"internalType":"uint256","name":"refund","type":"uint256"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"uint16","name":"dstChainId","type":"uint16"},{"internalType":"bool","name":"","type":"bool"}],"name":"sendExchange","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"marginDelta","type":"uint256"},{"internalType":"bytes32","name":"marketKey","type":"bytes32"},{"internalType":"bool","name":"","type":"bool"}],"name":"sendTransferMargin","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_delegate","type":"address"}],"name":"setDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_destinationEP","type":"uint32"},{"internalType":"uint128","name":"_gasLimit","type":"uint128"}],"name":"setGasLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_percentage","type":"uint16"}],"name":"setLZFeePercentage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_eid","type":"uint32"},{"internalType":"bytes32","name":"_peer","type":"bytes32"}],"name":"setPeer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60a03462000185576200345c906001600160401b03601f38849003908101601f1916830190828211848310176200018a578084916040968794855283398101031262000185576200005e60206200005684620001a0565b9301620001a0565b60008054336001600160a01b03198216811783558651929592936001600160a01b039384939192849283167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08a80a316608052169182156200017657506080511690813b156200017257839291602484928751968793849263ca5eb5e160e01b845260048401525af18015620001685762000141575b836264000063ffff0000196003541617600355516132a69081620001b682396080518181816105a201528181610e4e0152818161143301528181612a0801528181612e8c01526130400152f35b82116200015457508152388080620000f4565b634e487b7160e01b81526041600452602490fd5b84513d84823e3d90fd5b8380fd5b632d618d8160e21b8152600490fd5b600080fd5b634e487b7160e01b600052604160045260246000fd5b51906001600160a01b0382168203620001855756fe6080604052600436101561001b575b361561001957600080fd5b005b60003560e01c806302de00921461021b5780630cf2abc6146102165780630f45ad431461021157806313137d651461020c57806317442b70146102075780631c4b995a1461020257806323f78bf3146101fd5780632abe893f146101f85780632bb821bd146101f35780632c957005146101ee5780633400288b146101e957806338e4f064146101e4578063397b2b3a146101df5780634fa34310146101da5780635e280f11146101d557806365b9bacb146101d05780636fcdef87146101cb578063715018a6146101c65780637d25a05e146101c157806380a2eb14146101bc57806382413eac146101b7578063863c576f146101b25780638da5cb5b146101ad578063af02b429146101a8578063bb0b6a53146101a3578063bcc44cb11461019e578063ca5eb5e114610199578063e289c24a14610194578063f2fde38b1461018f578063f7736f3d1461018a578063fa594daf146101855763ff7bd03d0361000e576116ae565b61168c565b61158c565b6114c5565b6114a0565b611402565b611315565b6112da565b611283565b61125a565b6111af565b611151565b611027565b611000565b610fa2565b610ef7565b610e7d565b610e38565b610d60565b610cdd565b610bc8565b610b41565b610b18565b6109aa565b6107c3565b61073a565b61066b565b610649565b610544565b61050f565b61046a565b6102d2565b6001600160a01b0381160361023157565b600080fd5b60a4359061ffff8216820361023157565b6024359061ffff8216820361023157565b6044359061ffff8216820361023157565b610104359061ffff8216820361023157565b6064359061ffff8216820361023157565b359061ffff8216820361023157565b9181601f84011215610231578235916001600160401b038311610231576020838186019501011161023157565b8015150361023157565b610140366003190112610231576004356102eb81610220565b6102f3610236565b60e4359061030082610220565b610104356001600160401b0381116102315761032090369060040161029b565b909261032e610124356102c8565b61033733611a68565b1561042857604051606086901b6001600160601b03191660208201526103d9926103cd9061039d906103a984603481015b039561037c601f199788810188528761090d565b604051938491602083016014916001600160601b03199060601b1681520190565b0386810184528361090d565b6040519788948860c435916084359060643590604435906024359060208c016116f4565b0390810184528361090d565b61ffff916103f96103f3348560035460201c168488611eea565b346117b5565b9261041561040e60035461ffff9060201c1690565b61ffff1690565b9083160361041f57005b61001993611eea565b604051632e79a65160e01b8152600490fd5b60809060031901126102315760043561045281610220565b906024359060443590606435610467816102c8565b90565b6104733661043a565b5061048092919233611a68565b15610428576040516001600160601b0319606084901b16602082015260148152610019936104db926104f292601f199290916104bd60348461090d565b604051958693600160208601526080604086015260a0850190610715565b91606084015260808301520390810183528261090d565b61ffff60035460201c16903492611bc4565b600091031261023157565b3461023157600036600319011261023157602060035461ffff60405191831c168152f35b606090600319011261023157600490565b60e03660031901126102315761055936610533565b6001600160401b036084358181116102315761057990369060040161029b565b9161058560a435610220565b60c4359081116102315761059d90369060040161029b565b5050337f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031603610631576105e06105db846117c2565b611f74565b9260208101358094036105fb576100199350606435906121cf565b61060584916117c2565b60405163309afaf360e21b815263ffffffff9190911660048201526024810191909152604490fd5b0390fd5b6040516391ac5e4f60e01b8152336004820152602490fd5b3461023157600036600319011261023157604080516001815260026020820152f35b346102315760603660031901126102315760043561068881610220565b610690610247565b9065ffff0000000061ffff6106a3610258565b6106ab612882565b6003549360018060a01b03166001600160601b0360a01b6001541617600155169260201b169065ffff0000ffff19161717600355600080f35b63ffffffff81160361023157565b60005b8381106107055750506000910152565b81810151838201526020016106f5565b9060209161072e815180928185528580860191016106f2565b601f01601f1916010190565b346102315760203660031901126102315761077661076260043561075d816106e4565b6117cc565b604051918291602083526020830190610715565b0390f35b6101009060031901126102315760043561079381610220565b906024359060443590606435906084359060a43561ffff81168103610231579060c4359060e435610467816102c8565b6107cc3661077a565b50929093916107da33611a68565b15610428576040516001600160601b0319606089901b1660208201526014815261082894601f199491936103cd9391928892919061081960348861090d565b6040519a8b976020890161191c565b61ffff9161083f348460035460201c168387611ca4565b34039234841161086e5761085b8160035460201c1661ffff1690565b9083160361086557005b61001993611ca4565b61179f565b634e487b7160e01b600052604160045260246000fd5b6001600160401b03811161089c57604052565b610873565b604081019081106001600160401b0382111761089c57604052565b606081019081106001600160401b0382111761089c57604052565b60a081019081106001600160401b0382111761089c57604052565b608081019081106001600160401b0382111761089c57604052565b90601f801991011681019081106001600160401b0382111761089c57604052565b6040519061093b826108d7565b565b6001600160401b03811161089c57601f01601f191660200190565b9291926109648261093d565b91610972604051938461090d565b829481845281830111610231578281602093846000960137010152565b9080601f830112156102315781602061046793359101610958565b34610231576060366003190112610231576004356001600160401b03811161023157610a75610a6e6109e361077693369060040161098f565b6109eb610247565b9061ffff610a0c816109fb610258565b1683610a06826117cc565b9161299d565b92816000911660058114908115610b0d575b8115610b02575b8115610af7575b8115610aec575b8115610ae1575b8115610ad6575b5080610ac2575b610aba575b610a85575b505051600354610a689060101c61ffff1661040e565b906119ba565b6064900490565b6040519081529081906020820190565b610ab191610aa991610a9e60035461ffff9060201c1690565b1690610a06826117cc565b5182516119ad565b81523880610a52565b506001610a4d565b5060035482808260201c1691161415610a48565b600f91501438610a41565b600e81149150610a3a565b600d81149150610a33565b600c81149150610a2c565b600b81149150610a25565b600781149150610a1e565b34610231576000366003190112610231576001546040516001600160a01b039091168152602090f35b34610231576040366003190112610231577f238399d427b947898edb290f5ff0f9109849b1c3ba196a42e35f00c50a54b98b600435610b7f816106e4565b60243590610b8b612882565b63ffffffff8116600052600260205281604060002055610bc3604051928392836020909392919363ffffffff60408201951681520152565b0390a1005b3461023157604036600319011261023157600435610be581610220565b602435610bf0612882565b6001600160a01b038216610c0957610019915033612a9b565b600091829182604051602081019263a9059cbb60e01b8452336024830152604482015260448152610c39816108f2565b51925af1610c45612a6b565b81610cae575b5015610c5357005b60405162461bcd60e51b815260206004820152602d60248201527f5472616e7366657248656c7065723a3a736166655472616e736665723a20747260448201526c185b9cd9995c8819985a5b1959609a1b6064820152608490fd5b8051801592508215610cc3575b505038610c4b565b610cd69250602080918301019101611a53565b3880610cbb565b610ce63661043a565b50610cf392919233611a68565b15610428576040516001600160601b0319606084901b16602082015260148152610019936104db92610d4e92601f19929091610d3060348461090d565b604051958693600460208601526080604086015260a0850190610715565b61ffff60035460201c16903492611d4c565b608036600319011261023157600435610d7881610220565b60243590610d876064356102c8565b610d9033611a68565b15610428578115610e2657610dfa610e146100199360405180610dc886602083016014916001600160601b03199060601b1681520190565b0391610ddc601f199384810184528361090d565b604051948592600960208501526080604085015260a0840190610715565b90606083015260443560808301520390810183528261090d565b60035460201c61ffff16903492611d91565b6040516305a81ae160e21b8152600490fd5b34610231576000366003190112610231576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b3461023157604036600319011261023157600435610e9a816106e4565b602435906001600160801b03821680920361023157610eb7612882565b8115610ee55763ffffffff1660005260046020526040600020906001600160801b0319825416179055600080f35b6040516309c227e960e31b8152600490fd5b610f003661077a565b5092909391610f0e33611a68565b15610428576040516001600160601b0319606089901b16602082015260148152610f5c94601f199491936103cd93919288929190610f4d60348861090d565b6040519a8b9760208901611961565b61ffff91610f73348460035460201c168387611dd6565b34039234841161086e57610f8f8160035460201c1661ffff1690565b90831603610f9957005b61001993611dd6565b3461023157600080600319360112610ffd57610fbc612882565b80546001600160a01b03198116825581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b80fd5b346102315760403660031901126102315761101c6004356106e4565b602060405160008152f35b6101403660031901126102315760043561104081610220565b611048610269565b611054610124356102c8565b61105d33611a68565b15610428578061107c61107460c43560a4356117b5565b6064356119ad565b61ffff8092161561113c575b6040516001600160601b0319606086901b16602082015260148152906110e690601f19906110b760348561090d565b6110da8660405195869360e43591608435916044359160243590602089016119cd565b0390810183528261090d565b34926110f861040e60035461ffff1690565b90838116918203611122575b5060035460201c61ffff169283160361111957005b61001993611e1b565b6111359194506103f39034908488611e1b565b9238611104565b915061114b60035461ffff1690565b91611088565b346102315760a03660031901126102315761116b36610533565b506064356001600160401b0381116102315761118b90369060040161029b565b5050602060843561119b81610220565b6040516001600160a01b0390911630148152f35b6111b83661077a565b50929093916111c633611a68565b15610428576040516001600160601b0319606089901b1660208201526014815261121494601f199491936103cd9391928892919061120560348861090d565b6040519a8b9760208901611987565b61ffff9161122b348460035460201c168387611e60565b34039234841161086e576112478160035460201c1661ffff1690565b9083160361125157005b61001993611e60565b34610231576000366003190112610231576000546040516001600160a01b039091168152602090f35b346102315760203660031901126102315760043561ffff8116808203610231576064116112c85763ffff00006003549160101b169063ffff0000191617600355600080f35b6040516302b763b760e01b8152600490fd5b346102315760203660031901126102315763ffffffff6004356112fc816106e4565b1660005260026020526020604060002054604051908152f35b60a03660031901126102315760043561132d81610220565b61133561027b565b6113406084356102c8565b61134933611a68565b156104285761ffff8082169182156113f0576113cb6103f3826113c2604051806113888a602083016014916001600160601b03199060601b1681520190565b039061139c601f199283810183528261090d565b6113b6604051978892604435906024359060208601611a13565b0390810186528561090d565b34908488611ea5565b926113dd60035461ffff9060201c1690565b928316036113e757005b61001993611ea5565b604051636794524760e01b8152600490fd5b346102315760006020366003190112610ffd5760043561142181610220565b611429612882565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811691839190833b1561149c5760249083604051958694859363ca5eb5e160e01b85521660048401525af180156114975761148b575080f35b61149490610889565b80f35b611a47565b8280fd5b3461023157600036600319011261023157602061ffff60035460101c16604051908152f35b34610231576020366003190112610231576004356114e281610220565b6114ea612882565b6001600160a01b03908116801561153857600080546001600160a01b03198116831782559092167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b610140366003190112610231576004356115a581610220565b6115ad610236565b60e4356001600160401b038111610231576115cc90369060040161029b565b610104929192356115dc81610220565b6115e8610124356102c8565b6115f133611a68565b1561042857604051606086901b6001600160601b031916602082015261164a926103cd9061039d906116268460348101610368565b6040519788948860c435916084359060643590604435906024359060208c01611773565b61ffff916116646103f3348560035460201c168488611f2f565b9261167961040e60035461ffff9060201c1690565b9083160361168357005b61001993611f2f565b3461023157600036600319011261023157602061ffff60035416604051908152f35b346102315760603660031901126102315760206116ca36610533565b63ffffffff81356116da816106e4565b166000526002825260406000205482604051920135148152f35b96919589956104679b9a9560209a9561172061ffff958d8d6101409181600d84935201528d0190610715565b9960408c015260608b015260808a015260a08901521660c087015260e0860152848403610100860152818452858401376000848284010152601f8019910116019061012083828403019101520190610715565b96919589956104679b9a9560209a9561172061ffff958d8d6101409181600b84935201528d0190610715565b634e487b7160e01b600052601160045260246000fd5b9190820391821161086e57565b35610467816106e4565b63ffffffff168060005260046020526040908160002054906001600160801b0382161561190557508151600360f01b6020820152600281529061180e826108a1565b61ffff60038161181d85612f50565b16036118e3578351916001600160801b03199060801b16602083015260108252611846826108a1565b60038161185285612f50565b16036118e3578151818111611890579161187461188292610467959416612f9c565b945194859360208501612faf565b03601f19810183528261090d565b845162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201526536206269747360d01b6064820152608490fd5b836024916118f085612f50565b9151633a51740d60e01b815291166004820152fd5b60249083519063466a9c3160e01b82526004820152fd5b9361ffff9361194260e097939a9998949a610100600c89528060208a0152880190610715565b9960408701526060860152608085015260a08401521660c08201520152565b9361ffff9361194260e097939a9998949a610100600f89528060208a0152880190610715565b9361ffff9361194260e097939a9998949a610100600e89528060208a0152880190610715565b9190820180921161086e57565b8181029291811591840414171561086e57565b95919796929361ffff946119f360e0979361010060058b528060208c01528a0190610715565b9960408901526060880152608087015260a086015260c085015216910152565b92936080929594611a3661ffff936007875260a0602088015260a0870190610715565b966040860152606085015216910152565b6040513d6000823e3d90fd5b908160209103126102315751610467816102c8565b611a7f611a73612b4d565b6001600160a01b031690565b6001600160a01b03821690811491908215611baf575b8215611b9a575b8215611b85575b8215611b70575b8215611b5b575b8215611b45575b508115611ac3575090565b611b069150602090611ad9611a73611a73612d44565b6040516308651a8360e31b81526001600160a01b0390921660048301529092839190829081906024820190565b03915afa90811561149757600091611b1c575090565b610467915060203d602011611b3e575b611b36818361090d565b810190611a53565b503d611b2c565b909150611b53611a73612d44565b149038611ab8565b9150611b68611a73612cf2565b821491611ab1565b9150611b7d611a73612ca0565b821491611aaa565b9150611b92611a73612c55565b821491611aa3565b9150611ba7611a73612c0b565b821491611a9c565b9150611bbc611a73612bc4565b821491611a95565b909392909161ffff1690611bd7826117cc565b90611be382878561299d565b90815190818110611c8257505060409495600192611c1a925190875191611c09836108a1565b825260006020830152309286612e03565b927f6aa69f7f20316a9c2f58092cd0c92195c168922f7f281bb9c7ab4b9f3eafb43d611c4584611f74565b85516020808801518951938452908301919091526001600160401b0316604082015260a084901b8490039092169180606081015b0390a401515190565b60405163ee72231d60e01b815260048101919091526024810191909152604490fd5b909392909161ffff1690611cb7826117cc565b90611cc382878561299d565b90815190818110611c8257505060409495600c92611ce9925190875191611c09836108a1565b927f6aa69f7f20316a9c2f58092cd0c92195c168922f7f281bb9c7ab4b9f3eafb43d611d1484611f74565b85516020808801518951938452908301919091526001600160401b031660408201526001600160a01b03909216918060608101611c79565b909392909161ffff1690611d5f826117cc565b90611d6b82878561299d565b90815190818110611c8257505060409495600492611ce9925190875191611c09836108a1565b909392909161ffff1690611da4826117cc565b90611db082878561299d565b90815190818110611c8257505060409495600992611ce9925190875191611c09836108a1565b909392909161ffff1690611de9826117cc565b90611df582878561299d565b90815190818110611c8257505060409495600f92611ce9925190875191611c09836108a1565b909392909161ffff1690611e2e826117cc565b90611e3a82878561299d565b90815190818110611c8257505060409495600592611ce9925190875191611c09836108a1565b909392909161ffff1690611e73826117cc565b90611e7f82878561299d565b90815190818110611c8257505060409495600e92611ce9925190875191611c09836108a1565b909392909161ffff1690611eb8826117cc565b90611ec482878561299d565b90815190818110611c8257505060409495600792611ce9925190875191611c09836108a1565b909392909161ffff1690611efd826117cc565b90611f0982878561299d565b90815190818110611c8257505060409495600d92611ce9925190875191611c09836108a1565b909392909161ffff1690611f42826117cc565b90611f4e82878561299d565b90815190818110611c8257505060409495600b92611ce9925190875191611c09836108a1565b63ffffffff16806000526002602052604060002054908115611f94575090565b6024906040519063f6ff4fb760e01b82526004820152fd5b9190916101008184031261023157611fc38161028c565b926020820135906001600160401b03821161023157611fe391830161098f565b9160408201359160608101359160808201359160a08101359160e061200a60c0840161028c565b92013590565b91909161014081840312610231576120278161028c565b926001600160401b036020830135818111610231578261204891850161098f565b9360408401359360608101359360808201359360a08301359361206d60c0850161028c565b9360e081013593610100820135848111610231578161208d91840161098f565b9361012083013590811161023157610467920161098f565b9360e095919361046798979360018060a01b03809616875260208701526040860152606085015260808401521660a08201528160c08201520190610715565b9091606082840312610231576120f98261028c565b9260208301356001600160401b0381116102315760409161200a91850161098f565b919091608081840312610231576121318161028c565b926020820135906001600160401b0382116102315761215191830161098f565b916060604083013592013590565b909160e082840312610231576121748261028c565b926020830135906001600160401b0382116102315761219491840161098f565b9160408101359160608201359160808101359160c060a083013592013590565b6001600160401b0381160361023157565b35610467816121b4565b926121e56121de368386610958565b6020015190565b9261ffff9182851694600286146000146122fc57508161220c91612216979493019061211b565b9492509690612f00565b95612225611a73611a73612bc4565b93843b1561023157604051631a4ac9bf60e21b81526001600160a01b038916600482015260248101929092526044820152926000908490606490829084905af192831561149757600080516020613251833981519152936122e3575b505b6122de6122926105db836117c2565b946122ab60406122a461040e866117c2565b94016121c5565b6040805197885260208801929092526001600160401b0316908601529116946001600160a01b0316929081906060820190565b0390a4565b806122f06122f692610889565b80610504565b38612281565b600386036123a557508161220c91612317979493019061211b565b95612326611a73611a73612b4d565b93843b15610231576040516358ff317f60e11b81526001600160a01b03891660048201819052602482015260448101929092526064820152926000908490818381608481015b03925af19283156114975760008051602061325183398151915293612392575b50612283565b806122f061239f92610889565b3861238c565b600586036124205750816123c0916123ce979493019061215f565b509694509892915050612f00565b956123dd611a73611a73612c0b565b93843b1561023157604051630a77839d60e11b81526001600160a01b0389166004820152602481019290925260448201529260009084908183816064810161236c565b600686036124ab57508161220c9161243b979493019061211b565b9561244a611a73611a73612b4d565b93843b1561023157604051630533242960e31b81526001600160a01b038916600482015260248101929092526044820152926000908490606490829084905af192831561149757600080516020613251833981519152936123925750612283565b6007860361251857508161220c916124c6979493019061211b565b956124d5611a73611a73612bc4565b93843b1561023157604051631a4ac9bf60e21b81526001600160a01b0389166004820152602481019290925260448201529260009084908183816064810161236c565b600a86036125b05750816125329161253a949301906120e4565b939150612f00565b94612549611a73611a73612bc4565b803b1561023157604051631a4ac9bf60e21b81526001600160a01b0388166004820152631cd554d160e21b602482015260448101949094526000908490606490829084905af192831561149757600080516020613251833981519152936123925750612283565b92969592600b860361266657509160206126226125ee6125da856000976125f69b9c970190612010565b969850939d96915050979297969096612f00565b9d8e93612f00565b612604611a73611a73612c55565b966040519c8d998a9889976314cf934360e11b8952600489016120a5565b03925af192831561149757600080516020613251833981519152936126475750612283565b61265f9060203d602011611b3e57611b36818361090d565b503861238c565b600c8603612714575081612681916126919798930190611fac565b5050939096945098909198612f00565b976126a0611a73611a73612c55565b90813b15610231576040516315491d7d60e21b81526001600160a01b038b166004820152602481019190915260448101929092526064820195909552608481019190915292600090849060a490829084905af192831561149757600080516020613251833981519152936123925750612283565b600d860361276657509160206126226125ee6125da8560009761273a9b9c970190612010565b612748611a73611a73612c55565b966040519c8d998a988997631077bc3b60e01b8952600489016120a5565b600e86036127ec575091612784826127929460209899940190611fac565b5050929a9450969092612f00565b9860008a6126226127a7611a73611a73612ca0565b946040519a8b978896879563b4c4dff960e01b8752600487019192608093969594919660a084019760018060a01b031684526020840152604083015260608201520152565b600f86036128645750916127848261280a9460209899940190611fac565b9860008a61262261281f611a73611a73612ca0565b946040519a8b978896879563b9eacb7560e01b8752600487019192608093969594919660a084019760018060a01b031684526020840152604083015260608201520152565b604051634f18ccbb60e11b815261ffff919091166004820152602490fd5b6000546001600160a01b0316330361289657565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b604051906128e7826108a1565b60006020838281520152565b91908260409103126102315760405161290b816108a1565b6020808294805184520151910152565b9060408282031261023157610467916128f3565b906020909392936040835263ffffffff8151166040840152818101516060840152608061298361296d604084015160a08488015260e0870190610715565b6060840151868203603f190160a0880152610715565b910151151560c08401526001600160a01b03909416910152565b91612a0491926129ab6128da565b506129b581611f74565b9160409485936129d48551946129ca866108d7565b63ffffffff168552565b602084015283830152606082015260006080820152815180938192631bb8518b60e31b835230906004840161292f565b03817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa91821561149757600092612a4557505090565b6104679250803d10612a64575b612a5c818361090d565b81019061291b565b503d612a52565b3d15612a96573d90612a7c8261093d565b91612a8a604051938461090d565b82523d6000602084013e565b606090565b60405160208101908082106001600160401b0383111761089c576000938493848094938194604052525af1612ace612a6b565b5015612ad657565b60405162461bcd60e51b815260206004820152603460248201527f5472616e7366657248656c7065723a3a736166655472616e736665724554483a60448201527308115512081d1c985b9cd9995c8819985a5b195960621b6064820152608490fd5b90816020910312610231575161046781610220565b6001546040516321f8a72160e01b81526c2bb930b83832b229bcb73a343960991b600482015290602090829060249082906001600160a01b03165afa90811561149757600091612b9b575090565b610467915060203d602011612bbd575b612bb5818361090d565b810190612b38565b503d612bab565b6001546040516321f8a72160e01b81526524b9b9bab2b960d11b600482015290602090829060249082906001600160a01b03165afa90811561149757600091612b9b575090565b6001546040516321f8a72160e01b81526822bc31b430b733b2b960b91b600482015290602090829060249082906001600160a01b03165afa90811561149757600091612b9b575090565b6001546040516321f8a72160e01b815269053796e746872537761760b41b600482015290602090829060249082906001600160a01b03165afa90811561149757600091612b9b575090565b6001546040516321f8a72160e01b8152700a6f2dce8d0e4a6eec2e0aed2e8d088caf607b1b600482015290602090829060249082906001600160a01b03165afa90811561149757600091612b9b575090565b6001546040516321f8a72160e01b81527027b33321b430b4b722bc31b430b733b2b960791b600482015290602090829060249082906001600160a01b03165afa90811561149757600091612b9b575090565b6001546040516321f8a72160e01b815273233aba3ab932b9a6b0b935b2ba26b0b730b3b2b960611b600482015290602090829060249082906001600160a01b03165afa90811561149757600091612b9b575090565b60405190612da6826108bc565b8160008152600060208201526040612dbc6128da565b910152565b9060808282031261023157612dfb906040805193612dde856108bc565b805185526020810151612df0816121b4565b6020860152016128f3565b604082015290565b612e6c60809492612e889694612e17612d99565b506020612e248651613004565b950191825180612ef1575b50612e3985611f74565b9251151592612e55612e4961092e565b63ffffffff9097168752565b602086015260408501526060840152151585830152565b6040518095819482936302637a4560e41b84526004840161292f565b03917f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165af190811561149757600091612ec8575090565b610467915060803d608011612eea575b612ee2818361090d565b810190612dc1565b503d612ed8565b612efa90613026565b38612e2f565b6014815110612f13576020015160601c90565b60405162461bcd60e51b8152602060048201526015602482015274746f416464726573735f6f75744f66426f756e647360581b6044820152606490fd5b6002815110612f60576002015190565b60405162461bcd60e51b8152602060048201526014602482015273746f55696e7431365f6f75744f66426f756e647360601b6044820152606490fd5b90600161ffff8093160191821161086e57565b602090612fc66004959493828151948592016106f2565b600160f81b910181815260f09290921b6001600160f01b03191660018301526003820152815191612fff908390858401906020016106f2565b010190565b80341061300e5790565b6040516304fb820960e51b8152346004820152602490fd5b60405163393f876560e21b81526020916001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116928481600481875afa9081156114975760009161319a575b50168015613188576000806131009460405194878601916323b872dd60e01b835233602488015260448701526064860152606485526130b7856108d7565b604051946130c4866108a1565b8786527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656488870152519082855af16130fa612a6b565b916131b7565b805190828215928315613170575b505050156131195750565b6084906040519062461bcd60e51b82526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152fd5b6131809350820181019101611a53565b38828161310e565b6040516329b99a9560e11b8152600490fd5b6131b19150853d8711612bbd57612bb5818361090d565b38613079565b9192901561321957508151156131cb575090565b3b156131d45790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b82519091501561322c5750805190602001fd5b60405162461bcd60e51b81526020600482015290819061062d90602483019061071556fea76ad68a16ace0986b691a89b6b634c00c444d89c522f8ec8b70dcf24d999590a26469706673582212204506629f0db5a22aeb2160a6f0ae48b0540796a7bd017fc45f101c43c20c1b3364736f6c634300081800330000000000000000000000006edce65403992e310a62460808c4b910d972f10f0000000000000000000000006f808ae3445a711ecaa4da5c8330b051541a4de0

Deployed Bytecode

0x6080604052600436101561001b575b361561001957600080fd5b005b60003560e01c806302de00921461021b5780630cf2abc6146102165780630f45ad431461021157806313137d651461020c57806317442b70146102075780631c4b995a1461020257806323f78bf3146101fd5780632abe893f146101f85780632bb821bd146101f35780632c957005146101ee5780633400288b146101e957806338e4f064146101e4578063397b2b3a146101df5780634fa34310146101da5780635e280f11146101d557806365b9bacb146101d05780636fcdef87146101cb578063715018a6146101c65780637d25a05e146101c157806380a2eb14146101bc57806382413eac146101b7578063863c576f146101b25780638da5cb5b146101ad578063af02b429146101a8578063bb0b6a53146101a3578063bcc44cb11461019e578063ca5eb5e114610199578063e289c24a14610194578063f2fde38b1461018f578063f7736f3d1461018a578063fa594daf146101855763ff7bd03d0361000e576116ae565b61168c565b61158c565b6114c5565b6114a0565b611402565b611315565b6112da565b611283565b61125a565b6111af565b611151565b611027565b611000565b610fa2565b610ef7565b610e7d565b610e38565b610d60565b610cdd565b610bc8565b610b41565b610b18565b6109aa565b6107c3565b61073a565b61066b565b610649565b610544565b61050f565b61046a565b6102d2565b6001600160a01b0381160361023157565b600080fd5b60a4359061ffff8216820361023157565b6024359061ffff8216820361023157565b6044359061ffff8216820361023157565b610104359061ffff8216820361023157565b6064359061ffff8216820361023157565b359061ffff8216820361023157565b9181601f84011215610231578235916001600160401b038311610231576020838186019501011161023157565b8015150361023157565b610140366003190112610231576004356102eb81610220565b6102f3610236565b60e4359061030082610220565b610104356001600160401b0381116102315761032090369060040161029b565b909261032e610124356102c8565b61033733611a68565b1561042857604051606086901b6001600160601b03191660208201526103d9926103cd9061039d906103a984603481015b039561037c601f199788810188528761090d565b604051938491602083016014916001600160601b03199060601b1681520190565b0386810184528361090d565b6040519788948860c435916084359060643590604435906024359060208c016116f4565b0390810184528361090d565b61ffff916103f96103f3348560035460201c168488611eea565b346117b5565b9261041561040e60035461ffff9060201c1690565b61ffff1690565b9083160361041f57005b61001993611eea565b604051632e79a65160e01b8152600490fd5b60809060031901126102315760043561045281610220565b906024359060443590606435610467816102c8565b90565b6104733661043a565b5061048092919233611a68565b15610428576040516001600160601b0319606084901b16602082015260148152610019936104db926104f292601f199290916104bd60348461090d565b604051958693600160208601526080604086015260a0850190610715565b91606084015260808301520390810183528261090d565b61ffff60035460201c16903492611bc4565b600091031261023157565b3461023157600036600319011261023157602060035461ffff60405191831c168152f35b606090600319011261023157600490565b60e03660031901126102315761055936610533565b6001600160401b036084358181116102315761057990369060040161029b565b9161058560a435610220565b60c4359081116102315761059d90369060040161029b565b5050337f0000000000000000000000006edce65403992e310a62460808c4b910d972f10f6001600160a01b031603610631576105e06105db846117c2565b611f74565b9260208101358094036105fb576100199350606435906121cf565b61060584916117c2565b60405163309afaf360e21b815263ffffffff9190911660048201526024810191909152604490fd5b0390fd5b6040516391ac5e4f60e01b8152336004820152602490fd5b3461023157600036600319011261023157604080516001815260026020820152f35b346102315760603660031901126102315760043561068881610220565b610690610247565b9065ffff0000000061ffff6106a3610258565b6106ab612882565b6003549360018060a01b03166001600160601b0360a01b6001541617600155169260201b169065ffff0000ffff19161717600355600080f35b63ffffffff81160361023157565b60005b8381106107055750506000910152565b81810151838201526020016106f5565b9060209161072e815180928185528580860191016106f2565b601f01601f1916010190565b346102315760203660031901126102315761077661076260043561075d816106e4565b6117cc565b604051918291602083526020830190610715565b0390f35b6101009060031901126102315760043561079381610220565b906024359060443590606435906084359060a43561ffff81168103610231579060c4359060e435610467816102c8565b6107cc3661077a565b50929093916107da33611a68565b15610428576040516001600160601b0319606089901b1660208201526014815261082894601f199491936103cd9391928892919061081960348861090d565b6040519a8b976020890161191c565b61ffff9161083f348460035460201c168387611ca4565b34039234841161086e5761085b8160035460201c1661ffff1690565b9083160361086557005b61001993611ca4565b61179f565b634e487b7160e01b600052604160045260246000fd5b6001600160401b03811161089c57604052565b610873565b604081019081106001600160401b0382111761089c57604052565b606081019081106001600160401b0382111761089c57604052565b60a081019081106001600160401b0382111761089c57604052565b608081019081106001600160401b0382111761089c57604052565b90601f801991011681019081106001600160401b0382111761089c57604052565b6040519061093b826108d7565b565b6001600160401b03811161089c57601f01601f191660200190565b9291926109648261093d565b91610972604051938461090d565b829481845281830111610231578281602093846000960137010152565b9080601f830112156102315781602061046793359101610958565b34610231576060366003190112610231576004356001600160401b03811161023157610a75610a6e6109e361077693369060040161098f565b6109eb610247565b9061ffff610a0c816109fb610258565b1683610a06826117cc565b9161299d565b92816000911660058114908115610b0d575b8115610b02575b8115610af7575b8115610aec575b8115610ae1575b8115610ad6575b5080610ac2575b610aba575b610a85575b505051600354610a689060101c61ffff1661040e565b906119ba565b6064900490565b6040519081529081906020820190565b610ab191610aa991610a9e60035461ffff9060201c1690565b1690610a06826117cc565b5182516119ad565b81523880610a52565b506001610a4d565b5060035482808260201c1691161415610a48565b600f91501438610a41565b600e81149150610a3a565b600d81149150610a33565b600c81149150610a2c565b600b81149150610a25565b600781149150610a1e565b34610231576000366003190112610231576001546040516001600160a01b039091168152602090f35b34610231576040366003190112610231577f238399d427b947898edb290f5ff0f9109849b1c3ba196a42e35f00c50a54b98b600435610b7f816106e4565b60243590610b8b612882565b63ffffffff8116600052600260205281604060002055610bc3604051928392836020909392919363ffffffff60408201951681520152565b0390a1005b3461023157604036600319011261023157600435610be581610220565b602435610bf0612882565b6001600160a01b038216610c0957610019915033612a9b565b600091829182604051602081019263a9059cbb60e01b8452336024830152604482015260448152610c39816108f2565b51925af1610c45612a6b565b81610cae575b5015610c5357005b60405162461bcd60e51b815260206004820152602d60248201527f5472616e7366657248656c7065723a3a736166655472616e736665723a20747260448201526c185b9cd9995c8819985a5b1959609a1b6064820152608490fd5b8051801592508215610cc3575b505038610c4b565b610cd69250602080918301019101611a53565b3880610cbb565b610ce63661043a565b50610cf392919233611a68565b15610428576040516001600160601b0319606084901b16602082015260148152610019936104db92610d4e92601f19929091610d3060348461090d565b604051958693600460208601526080604086015260a0850190610715565b61ffff60035460201c16903492611d4c565b608036600319011261023157600435610d7881610220565b60243590610d876064356102c8565b610d9033611a68565b15610428578115610e2657610dfa610e146100199360405180610dc886602083016014916001600160601b03199060601b1681520190565b0391610ddc601f199384810184528361090d565b604051948592600960208501526080604085015260a0840190610715565b90606083015260443560808301520390810183528261090d565b60035460201c61ffff16903492611d91565b6040516305a81ae160e21b8152600490fd5b34610231576000366003190112610231576040517f0000000000000000000000006edce65403992e310a62460808c4b910d972f10f6001600160a01b03168152602090f35b3461023157604036600319011261023157600435610e9a816106e4565b602435906001600160801b03821680920361023157610eb7612882565b8115610ee55763ffffffff1660005260046020526040600020906001600160801b0319825416179055600080f35b6040516309c227e960e31b8152600490fd5b610f003661077a565b5092909391610f0e33611a68565b15610428576040516001600160601b0319606089901b16602082015260148152610f5c94601f199491936103cd93919288929190610f4d60348861090d565b6040519a8b9760208901611961565b61ffff91610f73348460035460201c168387611dd6565b34039234841161086e57610f8f8160035460201c1661ffff1690565b90831603610f9957005b61001993611dd6565b3461023157600080600319360112610ffd57610fbc612882565b80546001600160a01b03198116825581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b80fd5b346102315760403660031901126102315761101c6004356106e4565b602060405160008152f35b6101403660031901126102315760043561104081610220565b611048610269565b611054610124356102c8565b61105d33611a68565b15610428578061107c61107460c43560a4356117b5565b6064356119ad565b61ffff8092161561113c575b6040516001600160601b0319606086901b16602082015260148152906110e690601f19906110b760348561090d565b6110da8660405195869360e43591608435916044359160243590602089016119cd565b0390810183528261090d565b34926110f861040e60035461ffff1690565b90838116918203611122575b5060035460201c61ffff169283160361111957005b61001993611e1b565b6111359194506103f39034908488611e1b565b9238611104565b915061114b60035461ffff1690565b91611088565b346102315760a03660031901126102315761116b36610533565b506064356001600160401b0381116102315761118b90369060040161029b565b5050602060843561119b81610220565b6040516001600160a01b0390911630148152f35b6111b83661077a565b50929093916111c633611a68565b15610428576040516001600160601b0319606089901b1660208201526014815261121494601f199491936103cd9391928892919061120560348861090d565b6040519a8b9760208901611987565b61ffff9161122b348460035460201c168387611e60565b34039234841161086e576112478160035460201c1661ffff1690565b9083160361125157005b61001993611e60565b34610231576000366003190112610231576000546040516001600160a01b039091168152602090f35b346102315760203660031901126102315760043561ffff8116808203610231576064116112c85763ffff00006003549160101b169063ffff0000191617600355600080f35b6040516302b763b760e01b8152600490fd5b346102315760203660031901126102315763ffffffff6004356112fc816106e4565b1660005260026020526020604060002054604051908152f35b60a03660031901126102315760043561132d81610220565b61133561027b565b6113406084356102c8565b61134933611a68565b156104285761ffff8082169182156113f0576113cb6103f3826113c2604051806113888a602083016014916001600160601b03199060601b1681520190565b039061139c601f199283810183528261090d565b6113b6604051978892604435906024359060208601611a13565b0390810186528561090d565b34908488611ea5565b926113dd60035461ffff9060201c1690565b928316036113e757005b61001993611ea5565b604051636794524760e01b8152600490fd5b346102315760006020366003190112610ffd5760043561142181610220565b611429612882565b6001600160a01b037f0000000000000000000000006edce65403992e310a62460808c4b910d972f10f811691839190833b1561149c5760249083604051958694859363ca5eb5e160e01b85521660048401525af180156114975761148b575080f35b61149490610889565b80f35b611a47565b8280fd5b3461023157600036600319011261023157602061ffff60035460101c16604051908152f35b34610231576020366003190112610231576004356114e281610220565b6114ea612882565b6001600160a01b03908116801561153857600080546001600160a01b03198116831782559092167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b610140366003190112610231576004356115a581610220565b6115ad610236565b60e4356001600160401b038111610231576115cc90369060040161029b565b610104929192356115dc81610220565b6115e8610124356102c8565b6115f133611a68565b1561042857604051606086901b6001600160601b031916602082015261164a926103cd9061039d906116268460348101610368565b6040519788948860c435916084359060643590604435906024359060208c01611773565b61ffff916116646103f3348560035460201c168488611f2f565b9261167961040e60035461ffff9060201c1690565b9083160361168357005b61001993611f2f565b3461023157600036600319011261023157602061ffff60035416604051908152f35b346102315760603660031901126102315760206116ca36610533565b63ffffffff81356116da816106e4565b166000526002825260406000205482604051920135148152f35b96919589956104679b9a9560209a9561172061ffff958d8d6101409181600d84935201528d0190610715565b9960408c015260608b015260808a015260a08901521660c087015260e0860152848403610100860152818452858401376000848284010152601f8019910116019061012083828403019101520190610715565b96919589956104679b9a9560209a9561172061ffff958d8d6101409181600b84935201528d0190610715565b634e487b7160e01b600052601160045260246000fd5b9190820391821161086e57565b35610467816106e4565b63ffffffff168060005260046020526040908160002054906001600160801b0382161561190557508151600360f01b6020820152600281529061180e826108a1565b61ffff60038161181d85612f50565b16036118e3578351916001600160801b03199060801b16602083015260108252611846826108a1565b60038161185285612f50565b16036118e3578151818111611890579161187461188292610467959416612f9c565b945194859360208501612faf565b03601f19810183528261090d565b845162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201526536206269747360d01b6064820152608490fd5b836024916118f085612f50565b9151633a51740d60e01b815291166004820152fd5b60249083519063466a9c3160e01b82526004820152fd5b9361ffff9361194260e097939a9998949a610100600c89528060208a0152880190610715565b9960408701526060860152608085015260a08401521660c08201520152565b9361ffff9361194260e097939a9998949a610100600f89528060208a0152880190610715565b9361ffff9361194260e097939a9998949a610100600e89528060208a0152880190610715565b9190820180921161086e57565b8181029291811591840414171561086e57565b95919796929361ffff946119f360e0979361010060058b528060208c01528a0190610715565b9960408901526060880152608087015260a086015260c085015216910152565b92936080929594611a3661ffff936007875260a0602088015260a0870190610715565b966040860152606085015216910152565b6040513d6000823e3d90fd5b908160209103126102315751610467816102c8565b611a7f611a73612b4d565b6001600160a01b031690565b6001600160a01b03821690811491908215611baf575b8215611b9a575b8215611b85575b8215611b70575b8215611b5b575b8215611b45575b508115611ac3575090565b611b069150602090611ad9611a73611a73612d44565b6040516308651a8360e31b81526001600160a01b0390921660048301529092839190829081906024820190565b03915afa90811561149757600091611b1c575090565b610467915060203d602011611b3e575b611b36818361090d565b810190611a53565b503d611b2c565b909150611b53611a73612d44565b149038611ab8565b9150611b68611a73612cf2565b821491611ab1565b9150611b7d611a73612ca0565b821491611aaa565b9150611b92611a73612c55565b821491611aa3565b9150611ba7611a73612c0b565b821491611a9c565b9150611bbc611a73612bc4565b821491611a95565b909392909161ffff1690611bd7826117cc565b90611be382878561299d565b90815190818110611c8257505060409495600192611c1a925190875191611c09836108a1565b825260006020830152309286612e03565b927f6aa69f7f20316a9c2f58092cd0c92195c168922f7f281bb9c7ab4b9f3eafb43d611c4584611f74565b85516020808801518951938452908301919091526001600160401b0316604082015260a084901b8490039092169180606081015b0390a401515190565b60405163ee72231d60e01b815260048101919091526024810191909152604490fd5b909392909161ffff1690611cb7826117cc565b90611cc382878561299d565b90815190818110611c8257505060409495600c92611ce9925190875191611c09836108a1565b927f6aa69f7f20316a9c2f58092cd0c92195c168922f7f281bb9c7ab4b9f3eafb43d611d1484611f74565b85516020808801518951938452908301919091526001600160401b031660408201526001600160a01b03909216918060608101611c79565b909392909161ffff1690611d5f826117cc565b90611d6b82878561299d565b90815190818110611c8257505060409495600492611ce9925190875191611c09836108a1565b909392909161ffff1690611da4826117cc565b90611db082878561299d565b90815190818110611c8257505060409495600992611ce9925190875191611c09836108a1565b909392909161ffff1690611de9826117cc565b90611df582878561299d565b90815190818110611c8257505060409495600f92611ce9925190875191611c09836108a1565b909392909161ffff1690611e2e826117cc565b90611e3a82878561299d565b90815190818110611c8257505060409495600592611ce9925190875191611c09836108a1565b909392909161ffff1690611e73826117cc565b90611e7f82878561299d565b90815190818110611c8257505060409495600e92611ce9925190875191611c09836108a1565b909392909161ffff1690611eb8826117cc565b90611ec482878561299d565b90815190818110611c8257505060409495600792611ce9925190875191611c09836108a1565b909392909161ffff1690611efd826117cc565b90611f0982878561299d565b90815190818110611c8257505060409495600d92611ce9925190875191611c09836108a1565b909392909161ffff1690611f42826117cc565b90611f4e82878561299d565b90815190818110611c8257505060409495600b92611ce9925190875191611c09836108a1565b63ffffffff16806000526002602052604060002054908115611f94575090565b6024906040519063f6ff4fb760e01b82526004820152fd5b9190916101008184031261023157611fc38161028c565b926020820135906001600160401b03821161023157611fe391830161098f565b9160408201359160608101359160808201359160a08101359160e061200a60c0840161028c565b92013590565b91909161014081840312610231576120278161028c565b926001600160401b036020830135818111610231578261204891850161098f565b9360408401359360608101359360808201359360a08301359361206d60c0850161028c565b9360e081013593610100820135848111610231578161208d91840161098f565b9361012083013590811161023157610467920161098f565b9360e095919361046798979360018060a01b03809616875260208701526040860152606085015260808401521660a08201528160c08201520190610715565b9091606082840312610231576120f98261028c565b9260208301356001600160401b0381116102315760409161200a91850161098f565b919091608081840312610231576121318161028c565b926020820135906001600160401b0382116102315761215191830161098f565b916060604083013592013590565b909160e082840312610231576121748261028c565b926020830135906001600160401b0382116102315761219491840161098f565b9160408101359160608201359160808101359160c060a083013592013590565b6001600160401b0381160361023157565b35610467816121b4565b926121e56121de368386610958565b6020015190565b9261ffff9182851694600286146000146122fc57508161220c91612216979493019061211b565b9492509690612f00565b95612225611a73611a73612bc4565b93843b1561023157604051631a4ac9bf60e21b81526001600160a01b038916600482015260248101929092526044820152926000908490606490829084905af192831561149757600080516020613251833981519152936122e3575b505b6122de6122926105db836117c2565b946122ab60406122a461040e866117c2565b94016121c5565b6040805197885260208801929092526001600160401b0316908601529116946001600160a01b0316929081906060820190565b0390a4565b806122f06122f692610889565b80610504565b38612281565b600386036123a557508161220c91612317979493019061211b565b95612326611a73611a73612b4d565b93843b15610231576040516358ff317f60e11b81526001600160a01b03891660048201819052602482015260448101929092526064820152926000908490818381608481015b03925af19283156114975760008051602061325183398151915293612392575b50612283565b806122f061239f92610889565b3861238c565b600586036124205750816123c0916123ce979493019061215f565b509694509892915050612f00565b956123dd611a73611a73612c0b565b93843b1561023157604051630a77839d60e11b81526001600160a01b0389166004820152602481019290925260448201529260009084908183816064810161236c565b600686036124ab57508161220c9161243b979493019061211b565b9561244a611a73611a73612b4d565b93843b1561023157604051630533242960e31b81526001600160a01b038916600482015260248101929092526044820152926000908490606490829084905af192831561149757600080516020613251833981519152936123925750612283565b6007860361251857508161220c916124c6979493019061211b565b956124d5611a73611a73612bc4565b93843b1561023157604051631a4ac9bf60e21b81526001600160a01b0389166004820152602481019290925260448201529260009084908183816064810161236c565b600a86036125b05750816125329161253a949301906120e4565b939150612f00565b94612549611a73611a73612bc4565b803b1561023157604051631a4ac9bf60e21b81526001600160a01b0388166004820152631cd554d160e21b602482015260448101949094526000908490606490829084905af192831561149757600080516020613251833981519152936123925750612283565b92969592600b860361266657509160206126226125ee6125da856000976125f69b9c970190612010565b969850939d96915050979297969096612f00565b9d8e93612f00565b612604611a73611a73612c55565b966040519c8d998a9889976314cf934360e11b8952600489016120a5565b03925af192831561149757600080516020613251833981519152936126475750612283565b61265f9060203d602011611b3e57611b36818361090d565b503861238c565b600c8603612714575081612681916126919798930190611fac565b5050939096945098909198612f00565b976126a0611a73611a73612c55565b90813b15610231576040516315491d7d60e21b81526001600160a01b038b166004820152602481019190915260448101929092526064820195909552608481019190915292600090849060a490829084905af192831561149757600080516020613251833981519152936123925750612283565b600d860361276657509160206126226125ee6125da8560009761273a9b9c970190612010565b612748611a73611a73612c55565b966040519c8d998a988997631077bc3b60e01b8952600489016120a5565b600e86036127ec575091612784826127929460209899940190611fac565b5050929a9450969092612f00565b9860008a6126226127a7611a73611a73612ca0565b946040519a8b978896879563b4c4dff960e01b8752600487019192608093969594919660a084019760018060a01b031684526020840152604083015260608201520152565b600f86036128645750916127848261280a9460209899940190611fac565b9860008a61262261281f611a73611a73612ca0565b946040519a8b978896879563b9eacb7560e01b8752600487019192608093969594919660a084019760018060a01b031684526020840152604083015260608201520152565b604051634f18ccbb60e11b815261ffff919091166004820152602490fd5b6000546001600160a01b0316330361289657565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b604051906128e7826108a1565b60006020838281520152565b91908260409103126102315760405161290b816108a1565b6020808294805184520151910152565b9060408282031261023157610467916128f3565b906020909392936040835263ffffffff8151166040840152818101516060840152608061298361296d604084015160a08488015260e0870190610715565b6060840151868203603f190160a0880152610715565b910151151560c08401526001600160a01b03909416910152565b91612a0491926129ab6128da565b506129b581611f74565b9160409485936129d48551946129ca866108d7565b63ffffffff168552565b602084015283830152606082015260006080820152815180938192631bb8518b60e31b835230906004840161292f565b03817f0000000000000000000000006edce65403992e310a62460808c4b910d972f10f6001600160a01b03165afa91821561149757600092612a4557505090565b6104679250803d10612a64575b612a5c818361090d565b81019061291b565b503d612a52565b3d15612a96573d90612a7c8261093d565b91612a8a604051938461090d565b82523d6000602084013e565b606090565b60405160208101908082106001600160401b0383111761089c576000938493848094938194604052525af1612ace612a6b565b5015612ad657565b60405162461bcd60e51b815260206004820152603460248201527f5472616e7366657248656c7065723a3a736166655472616e736665724554483a60448201527308115512081d1c985b9cd9995c8819985a5b195960621b6064820152608490fd5b90816020910312610231575161046781610220565b6001546040516321f8a72160e01b81526c2bb930b83832b229bcb73a343960991b600482015290602090829060249082906001600160a01b03165afa90811561149757600091612b9b575090565b610467915060203d602011612bbd575b612bb5818361090d565b810190612b38565b503d612bab565b6001546040516321f8a72160e01b81526524b9b9bab2b960d11b600482015290602090829060249082906001600160a01b03165afa90811561149757600091612b9b575090565b6001546040516321f8a72160e01b81526822bc31b430b733b2b960b91b600482015290602090829060249082906001600160a01b03165afa90811561149757600091612b9b575090565b6001546040516321f8a72160e01b815269053796e746872537761760b41b600482015290602090829060249082906001600160a01b03165afa90811561149757600091612b9b575090565b6001546040516321f8a72160e01b8152700a6f2dce8d0e4a6eec2e0aed2e8d088caf607b1b600482015290602090829060249082906001600160a01b03165afa90811561149757600091612b9b575090565b6001546040516321f8a72160e01b81527027b33321b430b4b722bc31b430b733b2b960791b600482015290602090829060249082906001600160a01b03165afa90811561149757600091612b9b575090565b6001546040516321f8a72160e01b815273233aba3ab932b9a6b0b935b2ba26b0b730b3b2b960611b600482015290602090829060249082906001600160a01b03165afa90811561149757600091612b9b575090565b60405190612da6826108bc565b8160008152600060208201526040612dbc6128da565b910152565b9060808282031261023157612dfb906040805193612dde856108bc565b805185526020810151612df0816121b4565b6020860152016128f3565b604082015290565b612e6c60809492612e889694612e17612d99565b506020612e248651613004565b950191825180612ef1575b50612e3985611f74565b9251151592612e55612e4961092e565b63ffffffff9097168752565b602086015260408501526060840152151585830152565b6040518095819482936302637a4560e41b84526004840161292f565b03917f0000000000000000000000006edce65403992e310a62460808c4b910d972f10f6001600160a01b03165af190811561149757600091612ec8575090565b610467915060803d608011612eea575b612ee2818361090d565b810190612dc1565b503d612ed8565b612efa90613026565b38612e2f565b6014815110612f13576020015160601c90565b60405162461bcd60e51b8152602060048201526015602482015274746f416464726573735f6f75744f66426f756e647360581b6044820152606490fd5b6002815110612f60576002015190565b60405162461bcd60e51b8152602060048201526014602482015273746f55696e7431365f6f75744f66426f756e647360601b6044820152606490fd5b90600161ffff8093160191821161086e57565b602090612fc66004959493828151948592016106f2565b600160f81b910181815260f09290921b6001600160f01b03191660018301526003820152815191612fff908390858401906020016106f2565b010190565b80341061300e5790565b6040516304fb820960e51b8152346004820152602490fd5b60405163393f876560e21b81526020916001600160a01b037f0000000000000000000000006edce65403992e310a62460808c4b910d972f10f8116928481600481875afa9081156114975760009161319a575b50168015613188576000806131009460405194878601916323b872dd60e01b835233602488015260448701526064860152606485526130b7856108d7565b604051946130c4866108a1565b8786527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656488870152519082855af16130fa612a6b565b916131b7565b805190828215928315613170575b505050156131195750565b6084906040519062461bcd60e51b82526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152fd5b6131809350820181019101611a53565b38828161310e565b6040516329b99a9560e11b8152600490fd5b6131b19150853d8711612bbd57612bb5818361090d565b38613079565b9192901561321957508151156131cb575090565b3b156131d45790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b82519091501561322c5750805190602001fd5b60405162461bcd60e51b81526020600482015290819061062d90602483019061071556fea76ad68a16ace0986b691a89b6b634c00c444d89c522f8ec8b70dcf24d999590a26469706673582212204506629f0db5a22aeb2160a6f0ae48b0540796a7bd017fc45f101c43c20c1b3364736f6c63430008180033

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

0000000000000000000000006edce65403992e310a62460808c4b910d972f10f0000000000000000000000006f808ae3445a711ecaa4da5c8330b051541a4de0

-----Decoded View---------------
Arg [0] : _lzEndpoint (address): 0x6EDCE65403992e310A62460808c4b910D972f10f
Arg [1] : _owner (address): 0x6F808aE3445A711ecAa4DA5c8330B051541A4dE0

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 0000000000000000000000006edce65403992e310a62460808c4b910d972f10f
Arg [1] : 0000000000000000000000006f808ae3445a711ecaa4da5c8330b051541a4de0


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ 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.