{
    "Function": "slitherConstructorVariables",
    "File": "contracts/mocks/LZEndpointMock.sol",
    "Parent Contracts": [
        "contracts/OFT/interfaces/ILayerZeroEndpoint.sol",
        "contracts/OFT/interfaces/ILayerZeroUserApplicationConfig.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract LZEndpointMock is ILayerZeroEndpoint {\n    uint8 internal constant _NOT_ENTERED = 1;\n    uint8 internal constant _ENTERED = 2;\n\n    mapping(address => address) public lzEndpointLookup;\n\n    uint16 public mockChainId;\n    bool public nextMsgBlocked;\n\n    // fee config\n    RelayerFeeConfig public relayerFeeConfig;\n    ProtocolFeeConfig public protocolFeeConfig;\n    uint public oracleFee;\n    bytes public defaultAdapterParams;\n\n    // path = remote addrss + local address\n    // inboundNonce = [srcChainId][path].\n    mapping(uint16 => mapping(bytes => uint64)) public inboundNonce;\n    //todo: this is a hack\n    // outboundNonce = [dstChainId][srcAddress]\n    mapping(uint16 => mapping(address => uint64)) public outboundNonce;\n    //    // outboundNonce = [dstChainId][path].\n    //    mapping(uint16 => mapping(bytes => uint64)) public outboundNonce;\n    // storedPayload = [srcChainId][path]\n    mapping(uint16 => mapping(bytes => StoredPayload)) public storedPayload;\n    // msgToDeliver = [srcChainId][path]\n    mapping(uint16 => mapping(bytes => QueuedPayload[])) public msgsToDeliver;\n\n    // reentrancy guard\n    uint8 internal _send_entered_state = 1;\n    uint8 internal _receive_entered_state = 1;\n    bytes public storedMessage;\n\n    struct ProtocolFeeConfig {\n        uint zroFee;\n        uint nativeBP;\n    }\n\n    struct RelayerFeeConfig {\n        uint128 dstPriceRatio; // 10^10\n        uint128 dstGasPriceInWei;\n        uint128 dstNativeAmtCap;\n        uint64 baseGas;\n        uint64 gasPerByte;\n    }\n\n    struct StoredPayload {\n        uint64 payloadLength;\n        address dstAddress;\n        bytes32 payloadHash;\n    }\n\n    struct QueuedPayload {\n        address dstAddress;\n        uint64 nonce;\n        bytes payload;\n    }\n\n    modifier sendNonReentrant() {\n        require(_send_entered_state == _NOT_ENTERED, \"LayerZeroMock: no send reentrancy\");\n        _send_entered_state = _ENTERED;\n        _;\n        _send_entered_state = _NOT_ENTERED;\n    }\n\n    modifier receiveNonReentrant() {\n        require(_receive_entered_state == _NOT_ENTERED, \"LayerZeroMock: no receive reentrancy\");\n        _receive_entered_state = _ENTERED;\n        _;\n        _receive_entered_state = _NOT_ENTERED;\n    }\n\n    event UaForceResumeReceive(uint16 chainId, bytes srcAddress);\n    event PayloadCleared(uint16 srcChainId, bytes srcAddress, uint64 nonce, address dstAddress);\n    event PayloadStored(uint16 srcChainId, bytes srcAddress, address dstAddress, uint64 nonce, bytes payload, bytes reason);\n    event ValueTransferFailed(address indexed to, uint indexed quantity);\n\n    constructor(uint16 _chainId) {\n        mockChainId = _chainId;\n\n        // init config\n        relayerFeeConfig = RelayerFeeConfig({\n            dstPriceRatio: 1e10, // 1:1, same chain, same native coin\n            dstGasPriceInWei: 1e10,\n            dstNativeAmtCap: 1e19,\n            baseGas: 100,\n            gasPerByte: 1\n        });\n        protocolFeeConfig = ProtocolFeeConfig({zroFee: 1e18, nativeBP: 1000}); // BP 0.1\n        oracleFee = 1e16;\n        defaultAdapterParams = LzLib.buildDefaultAdapterParams(200000);\n    }\n\n    // ------------------------------ ILayerZeroEndpoint Functions ------------------------------\n    function send(uint16 _chainId, bytes memory _path, bytes calldata _payload, address payable _refundAddress, address _zroPaymentAddress, bytes memory _adapterParams) external payable override sendNonReentrant {\n        require(_path.length == 40, \"LayerZeroMock: incorrect remote address size\"); // only support evm chains\n\n        address dstAddr;\n        assembly {\n            dstAddr := mload(add(_path, 20))\n        }\n\n        address lzEndpoint = lzEndpointLookup[dstAddr];\n        require(lzEndpoint != address(0), \"LayerZeroMock: destination LayerZero Endpoint not found\");\n\n        // not handle zro token\n        bytes memory adapterParams = _adapterParams.length > 0 ? _adapterParams : defaultAdapterParams;\n        (uint nativeFee, ) = estimateFees(_chainId, msg.sender, _payload, _zroPaymentAddress != address(0x0), adapterParams);\n        require(msg.value >= nativeFee, \"LayerZeroMock: not enough native for fees\");\n\n        uint64 nonce = ++outboundNonce[_chainId][msg.sender];\n\n        // refund if they send too much\n        uint amount = msg.value - nativeFee;\n        if (amount > 0) {\n            (bool success, ) = _refundAddress.call{value: amount}(\"\");\n            require(success, \"LayerZeroMock: failed to refund\");\n        }\n\n        // Mock the process of receiving msg on dst chain\n        // Mock the relayer paying the dstNativeAddr the amount of extra native token\n        (, uint extraGas, uint dstNativeAmt, address payable dstNativeAddr) = LzLib.decodeAdapterParams(adapterParams);\n        if (dstNativeAmt > 0) {\n            (bool success, ) = dstNativeAddr.call{value: dstNativeAmt}(\"\");\n            if (!success) {\n                emit ValueTransferFailed(dstNativeAddr, dstNativeAmt);\n            }\n        }\n\n        bytes memory srcUaAddress = abi.encodePacked(msg.sender, dstAddr); // cast this address to bytes\n        bytes memory payload = _payload;\n        LZEndpointMock(lzEndpoint).receivePayload(mockChainId, srcUaAddress, dstAddr, nonce, extraGas, payload);\n    }\n\n    function receivePayload(uint16 _srcChainId, bytes calldata _path, address _dstAddress, uint64 _nonce, uint _gasLimit, bytes calldata _payload) external override receiveNonReentrant {\n        StoredPayload storage sp = storedPayload[_srcChainId][_path];\n\n        // assert and increment the nonce. no message shuffling\n        require(_nonce == ++inboundNonce[_srcChainId][_path], \"LayerZeroMock: wrong nonce\");\n\n        // queue the following msgs inside of a stack to simulate a successful send on src, but not fully delivered on dst\n        if (sp.payloadHash != bytes32(0)) {\n            QueuedPayload[] storage msgs = msgsToDeliver[_srcChainId][_path];\n            QueuedPayload memory newMsg = QueuedPayload(_dstAddress, _nonce, _payload);\n\n            // warning, might run into gas issues trying to forward through a bunch of queued msgs\n            // shift all the msgs over so we can treat this like a fifo via array.pop()\n            if (msgs.length > 0) {\n                // extend the array\n                msgs.push(newMsg);\n\n                // shift all the indexes up for pop()\n                for (uint i = 0; i < msgs.length - 1; i++) {\n                    msgs[i + 1] = msgs[i];\n                }\n\n                // put the newMsg at the bottom of the stack\n                msgs[0] = newMsg;\n            } else {\n                msgs.push(newMsg);\n            }\n        } else if (nextMsgBlocked) {\n            storedPayload[_srcChainId][_path] = StoredPayload(uint64(_payload.length), _dstAddress, keccak256(_payload));\n            emit PayloadStored(_srcChainId, _path, _dstAddress, _nonce, _payload, bytes(\"\"));\n            // ensure the next msgs that go through are no longer blocked\n            nextMsgBlocked = false;\n        } else {\n            storedMessage = _payload;\n            try ILayerZeroReceiver(_dstAddress).lzReceive{gas: _gasLimit}(_srcChainId, _path, _nonce, _payload) {} catch (bytes memory reason) {\n                storedPayload[_srcChainId][_path] = StoredPayload(uint64(_payload.length), _dstAddress, keccak256(_payload));\n                emit PayloadStored(_srcChainId, _path, _dstAddress, _nonce, _payload, reason);\n                // ensure the next msgs that go through are no longer blocked\n                nextMsgBlocked = false;\n            }\n        }\n    }\n\n    function getInboundNonce(uint16 _chainID, bytes calldata _path) external view override returns (uint64) {\n        return inboundNonce[_chainID][_path];\n    }\n\n    function getOutboundNonce(uint16 _chainID, address _srcAddress) external view override returns (uint64) {\n        return outboundNonce[_chainID][_srcAddress];\n    }\n\n    function estimateFees(uint16 _dstChainId, address _userApplication, bytes memory _payload, bool _payInZRO, bytes memory _adapterParams) public view override returns (uint nativeFee, uint zroFee) {\n        bytes memory adapterParams = _adapterParams.length > 0 ? _adapterParams : defaultAdapterParams;\n\n        // Relayer Fee\n        uint relayerFee = _getRelayerFee(_dstChainId, 1, _userApplication, _payload.length, adapterParams);\n\n        // LayerZero Fee\n        uint protocolFee = _getProtocolFees(_payInZRO, relayerFee, oracleFee);\n        _payInZRO ? zroFee = protocolFee : nativeFee = protocolFee;\n\n        // return the sum of fees\n        nativeFee = nativeFee + relayerFee + oracleFee;\n    }\n\n    function getChainId() external view override returns (uint16) {\n        return mockChainId;\n    }\n\n    function retryPayload(uint16 _srcChainId, bytes calldata _path, bytes calldata _payload) external override {\n        StoredPayload storage sp = storedPayload[_srcChainId][_path];\n        require(sp.payloadHash != bytes32(0), \"LayerZeroMock: no stored payload\");\n        require(_payload.length == sp.payloadLength && keccak256(_payload) == sp.payloadHash, \"LayerZeroMock: invalid payload\");\n\n        address dstAddress = sp.dstAddress;\n        // empty the storedPayload\n        sp.payloadLength = 0;\n        sp.dstAddress = address(0);\n        sp.payloadHash = bytes32(0);\n\n        uint64 nonce = inboundNonce[_srcChainId][_path];\n\n        ILayerZeroReceiver(dstAddress).lzReceive(_srcChainId, _path, nonce, _payload);\n        emit PayloadCleared(_srcChainId, _path, nonce, dstAddress);\n    }\n\n    function hasStoredPayload(uint16 _srcChainId, bytes calldata _path) external view override returns (bool) {\n        StoredPayload storage sp = storedPayload[_srcChainId][_path];\n        return sp.payloadHash != bytes32(0);\n    }\n\n    function getSendLibraryAddress(address) external view override returns (address) {\n        return address(this);\n    }\n\n    function getReceiveLibraryAddress(address) external view override returns (address) {\n        return address(this);\n    }\n\n    function isSendingPayload() external view override returns (bool) {\n        return _send_entered_state == _ENTERED;\n    }\n\n    function isReceivingPayload() external view override returns (bool) {\n        return _receive_entered_state == _ENTERED;\n    }\n\n    function getConfig(\n        uint16, /*_version*/\n        uint16, /*_chainId*/\n        address, /*_ua*/\n        uint /*_configType*/\n    ) external pure override returns (bytes memory) {\n        return \"\";\n    }\n\n    function getSendVersion(\n        address /*_userApplication*/\n    ) external pure override returns (uint16) {\n        return 1;\n    }\n\n    function getReceiveVersion(\n        address /*_userApplication*/\n    ) external pure override returns (uint16) {\n        return 1;\n    }\n\n    function setConfig(\n        uint16, /*_version*/\n        uint16, /*_chainId*/\n        uint, /*_configType*/\n        bytes memory /*_config*/\n    ) external override {}\n\n    function setSendVersion(\n        uint16 /*version*/\n    ) external override {}\n\n    function setReceiveVersion(\n        uint16 /*version*/\n    ) external override {}\n\n    function forceResumeReceive(uint16 _srcChainId, bytes calldata _path) external override {\n        StoredPayload storage sp = storedPayload[_srcChainId][_path];\n        // revert if no messages are cached. safeguard malicious UA behaviour\n        require(sp.payloadHash != bytes32(0), \"LayerZeroMock: no stored payload\");\n        require(sp.dstAddress == msg.sender, \"LayerZeroMock: invalid caller\");\n\n        // empty the storedPayload\n        sp.payloadLength = 0;\n        sp.dstAddress = address(0);\n        sp.payloadHash = bytes32(0);\n\n        emit UaForceResumeReceive(_srcChainId, _path);\n\n        // resume the receiving of msgs after we force clear the \"stuck\" msg\n        _clearMsgQue(_srcChainId, _path);\n    }\n\n    // ------------------------------ Other Public/External Functions --------------------------------------------------\n\n    function getLengthOfQueue(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (uint) {\n        return msgsToDeliver[_srcChainId][_srcAddress].length;\n    }\n\n    // used to simulate messages received get stored as a payload\n    function blockNextMsg() external {\n        nextMsgBlocked = true;\n    }\n\n    function setDestLzEndpoint(address destAddr, address lzEndpointAddr) external {\n        lzEndpointLookup[destAddr] = lzEndpointAddr;\n    }\n\n    function setRelayerPrice(uint128 _dstPriceRatio, uint128 _dstGasPriceInWei, uint128 _dstNativeAmtCap, uint64 _baseGas, uint64 _gasPerByte) external {\n        relayerFeeConfig.dstPriceRatio = _dstPriceRatio;\n        relayerFeeConfig.dstGasPriceInWei = _dstGasPriceInWei;\n        relayerFeeConfig.dstNativeAmtCap = _dstNativeAmtCap;\n        relayerFeeConfig.baseGas = _baseGas;\n        relayerFeeConfig.gasPerByte = _gasPerByte;\n    }\n\n    function setProtocolFee(uint _zroFee, uint _nativeBP) external {\n        protocolFeeConfig.zroFee = _zroFee;\n        protocolFeeConfig.nativeBP = _nativeBP;\n    }\n\n    function setOracleFee(uint _oracleFee) external {\n        oracleFee = _oracleFee;\n    }\n\n    function setDefaultAdapterParams(bytes memory _adapterParams) external {\n        defaultAdapterParams = _adapterParams;\n    }\n\n    // --------------------- Internal Functions ---------------------\n    // simulates the relayer pushing through the rest of the msgs that got delayed due to the stored payload\n    function _clearMsgQue(uint16 _srcChainId, bytes calldata _path) internal {\n        QueuedPayload[] storage msgs = msgsToDeliver[_srcChainId][_path];\n\n        // warning, might run into gas issues trying to forward through a bunch of queued msgs\n        while (msgs.length > 0) {\n            QueuedPayload memory payload = msgs[msgs.length - 1];\n            ILayerZeroReceiver(payload.dstAddress).lzReceive(_srcChainId, _path, payload.nonce, payload.payload);\n            msgs.pop();\n        }\n    }\n\n    function _getProtocolFees(bool _payInZro, uint _relayerFee, uint _oracleFee) internal view returns (uint) {\n        if (_payInZro) {\n            return protocolFeeConfig.zroFee;\n        } else {\n            return ((_relayerFee + _oracleFee) * protocolFeeConfig.nativeBP) / 10000;\n        }\n    }\n\n    function _getRelayerFee(\n        uint16, /* _dstChainId */\n        uint16, /* _outboundProofType */\n        address, /* _userApplication */\n        uint _payloadSize,\n        bytes memory _adapterParams\n    ) internal view returns (uint) {\n        (uint16 txType, uint extraGas, uint dstNativeAmt, ) = LzLib.decodeAdapterParams(_adapterParams);\n        uint totalRemoteToken; // = baseGas + extraGas + requiredNativeAmount\n        if (txType == 2) {\n            require(relayerFeeConfig.dstNativeAmtCap >= dstNativeAmt, \"LayerZeroMock: dstNativeAmt too large \");\n            totalRemoteToken += dstNativeAmt;\n        }\n        // remoteGasTotal = dstGasPriceInWei * (baseGas + extraGas)\n        uint remoteGasTotal = relayerFeeConfig.dstGasPriceInWei * (relayerFeeConfig.baseGas + extraGas);\n        totalRemoteToken += remoteGasTotal;\n\n        // tokenConversionRatio = dstPrice / localPrice\n        // basePrice = totalRemoteToken * tokenConversionRatio\n        uint basePrice = (totalRemoteToken * relayerFeeConfig.dstPriceRatio) / 10**10;\n\n        // pricePerByte = (dstGasPriceInWei * gasPerBytes) * tokenConversionRatio\n        uint pricePerByte = (relayerFeeConfig.dstGasPriceInWei * relayerFeeConfig.gasPerByte * relayerFeeConfig.dstPriceRatio) / 10**10;\n\n        return basePrice + _payloadSize * pricePerByte;\n    }\n}"
}