MNT Price: $0.86 (+1.12%)

Contract

0x50154e11eDf5D7d528cBc7Ec0D507dDB70B8B1c6
 

Overview

MNT Balance

Mantle Mainnet Network LogoMantle Mainnet Network LogoMantle Mainnet Network Logo0 MNT

MNT Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Age:24H
Reset Filter

Transaction Hash
Block
From
To

There are no matching entries

Update your filters to view other transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
LiquidationFacet

Compiler Version
v0.8.18+commit.87f61d96

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "../../utils/Pausable.sol";
import "../../utils/Accessibility.sol";
import "./ILiquidationFacet.sol";
import "./LiquidationFacetImpl.sol";
import "./DeferredLiquidationFacetImpl.sol";
import "../../storages/AccountStorage.sol";

contract LiquidationFacet is Pausable, Accessibility, ILiquidationFacet {
	/**
	 * @notice Liquidates Party A based on the provided signature.
	 * @param partyA The address of Party A to be liquidated.
	 * @param liquidationSig The Muon signature.
	 */
	function liquidatePartyA(
		address partyA,
		LiquidationSig memory liquidationSig
	) external whenNotLiquidationPaused notLiquidatedPartyA(partyA) onlyRole(LibAccessibility.LIQUIDATOR_ROLE) {
		LiquidationFacetImpl.liquidatePartyA(partyA, liquidationSig);
		emit LiquidatePartyA(
			msg.sender,
			partyA,
			AccountStorage.layout().allocatedBalances[partyA],
			liquidationSig.upnl,
			liquidationSig.totalUnrealizedLoss,
			liquidationSig.liquidationId
		);
		emit LiquidatePartyA(
			msg.sender,
			partyA,
			AccountStorage.layout().allocatedBalances[partyA],
			liquidationSig.upnl,
			liquidationSig.totalUnrealizedLoss
		); // For backward compatibility, will be removed in future
	}

	/**
	 * @notice Sets the prices of symbols at the time of liquidation.
	 * @dev The Muon signature here should be the same as the one that got partyA liquidated.
	 * @param partyA The address of Party A associated with the liquidation.
	 * @param liquidationSig The Muon signature containing symbol IDs and their corresponding prices.
	 */
	function setSymbolsPrice(
		address partyA,
		LiquidationSig memory liquidationSig
	) external whenNotLiquidationPaused onlyRole(LibAccessibility.LIQUIDATOR_ROLE) {
		LiquidationFacetImpl.setSymbolsPrice(partyA, liquidationSig);
		emit SetSymbolsPrices(msg.sender, partyA, liquidationSig.symbolIds, liquidationSig.prices, liquidationSig.liquidationId);
		emit SetSymbolsPrices(msg.sender, partyA, liquidationSig.symbolIds, liquidationSig.prices); // For backward compatibility, will be removed in future
	}

	/**
	 * @notice Deferred liquidates Party A based on the provided signature.
	 * @param partyA The address of Party A to be liquidated.
	 * @param liquidationSig The Muon signature.
	 */
	function deferredLiquidatePartyA(
		address partyA,
		DeferredLiquidationSig memory liquidationSig
	) external whenNotLiquidationPaused notLiquidatedPartyA(partyA) onlyRole(LibAccessibility.LIQUIDATOR_ROLE) {
		DeferredLiquidationFacetImpl.deferredLiquidatePartyA(partyA, liquidationSig);
		emit DeferredLiquidatePartyA(
			msg.sender,
			partyA,
			AccountStorage.layout().allocatedBalances[partyA],
			liquidationSig.upnl,
			liquidationSig.totalUnrealizedLoss,
			liquidationSig.liquidationId,
			liquidationSig.liquidationBlockNumber,
			liquidationSig.liquidationTimestamp,
			liquidationSig.liquidationAllocatedBalance
		);
	}

	/**
	 * @notice Deferred sets the prices of symbols at the time of liquidation.
	 * @dev The Muon signature here should be the same as the one that got partyA liquidated.
	 * @param partyA The address of Party A associated with the liquidation.
	 * @param liquidationSig The Muon signature containing symbol IDs and their corresponding prices.
	 */
	function deferredSetSymbolsPrice(
		address partyA,
		DeferredLiquidationSig memory liquidationSig
	) external whenNotLiquidationPaused onlyRole(LibAccessibility.LIQUIDATOR_ROLE) {
		DeferredLiquidationFacetImpl.deferredSetSymbolsPrice(partyA, liquidationSig);
		emit SetSymbolsPrices(msg.sender, partyA, liquidationSig.symbolIds, liquidationSig.prices, liquidationSig.liquidationId);
		emit SetSymbolsPrices(msg.sender, partyA, liquidationSig.symbolIds, liquidationSig.prices); // For backward compatibility, will be removed in future
	}

	/**
	 * @notice Liquidates pending positions of Party A.
	 * @param partyA The address of Party A whose pending positions will be liquidated.
	 */
	function liquidatePendingPositionsPartyA(address partyA) external whenNotLiquidationPaused onlyRole(LibAccessibility.LIQUIDATOR_ROLE) {
		QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
		uint256[] memory pendingQuotes = quoteLayout.partyAPendingQuotes[partyA];
		(uint256[] memory liquidatedAmounts, bytes memory liquidationId) = LiquidationFacetImpl.liquidatePendingPositionsPartyA(partyA);
		emit LiquidatePendingPositionsPartyA(msg.sender, partyA, pendingQuotes, liquidatedAmounts, liquidationId);
		emit LiquidatePendingPositionsPartyA(msg.sender, partyA); // For backward compatibility, will be removed in future
	}

	/**
	 * @notice Liquidates other positions of Party A.
	 * @param partyA The address of Party A whose positions will be liquidated.
	 * @param quoteIds An array of quote IDs representing the positions to be liquidated.
	 */
	function liquidatePositionsPartyA(
		address partyA,
		uint256[] memory quoteIds
	) external whenNotLiquidationPaused onlyRole(LibAccessibility.LIQUIDATOR_ROLE) {
		(bool disputed, uint256[] memory liquidatedAmounts, uint256[] memory closeIds, bytes memory liquidationId) = LiquidationFacetImpl
			.liquidatePositionsPartyA(partyA, quoteIds);
		emit LiquidatePositionsPartyA(msg.sender, partyA, quoteIds, liquidatedAmounts, closeIds, liquidationId);
		emit LiquidatePositionsPartyA(msg.sender, partyA, quoteIds); // For backward compatibility, will be removed in future
		if (disputed) {
			emit LiquidationDisputed(partyA, liquidationId);
			emit LiquidationDisputed(partyA); // For backward compatibility, will be removed in future
		}
	}

	/**
	 * @notice Settles liquidation for Party A with specified Party Bs.
	 * @param partyA The address of Party A to settle liquidation for.
	 * @param partyBs An array of addresses representing Party Bs involved in the settlement.
	 */
	function settlePartyALiquidation(address partyA, address[] memory partyBs) external whenNotLiquidationPaused {
		(int256[] memory settleAmounts, bytes memory liquidationId) = LiquidationFacetImpl.settlePartyALiquidation(partyA, partyBs);
		emit SettlePartyALiquidation(partyA, partyBs, settleAmounts, liquidationId);
		emit SettlePartyALiquidation(partyA, partyBs, settleAmounts); // For backward compatibility, will be removed in future
		if (MAStorage.layout().liquidationStatus[partyA] == false) {
			emit FullyLiquidatedPartyA(partyA, liquidationId);
			emit FullyLiquidatedPartyA(partyA); // For backward compatibility, will be removed in future
		}
	}

	/**
	 * @notice Resolves a liquidation dispute for Party A with specified Party Bs and settlement amounts.
	 * @param partyA The address of Party A involved in the dispute.
	 * @param partyBs An array of addresses representing Party Bs involved in the dispute.
	 * @param amounts An array of settlement amounts corresponding to Party Bs.
	 * @param disputed A boolean indicating whether the liquidation was disputed.
	 */
	function resolveLiquidationDispute(
		address partyA,
		address[] memory partyBs,
		int256[] memory amounts,
		bool disputed
	) external onlyRole(LibAccessibility.DISPUTE_ROLE) {
		bytes memory liquidationId = LiquidationFacetImpl.resolveLiquidationDispute(partyA, partyBs, amounts, disputed);
		emit ResolveLiquidationDispute(partyA, partyBs, amounts, disputed, liquidationId);
		emit ResolveLiquidationDispute(partyA, partyBs, amounts, disputed); // For backward compatibility, will be removed in future
	}

	/**
	 * @notice Liquidates Party B with respect to a Party A.
	 * @param partyB The address of Party B to be liquidated.
	 * @param partyA The address of Party A related to the liquidation.
	 * @param upnlSig The Muon signature containing the unrealized profit and loss data.
	 */
	function liquidatePartyB(
		address partyB,
		address partyA,
		SingleUpnlSig memory upnlSig
	) external whenNotLiquidationPaused notLiquidatedPartyB(partyB, partyA) notLiquidatedPartyA(partyA) onlyRole(LibAccessibility.LIQUIDATOR_ROLE) {
		emit LiquidatePartyB(msg.sender, partyB, partyA, AccountStorage.layout().partyBAllocatedBalances[partyB][partyA], upnlSig.upnl);
		LiquidationFacetImpl.liquidatePartyB(partyB, partyA, upnlSig);
	}

	/**
	 * @notice Liquidates positions of Party B the Party A.
	 * @param partyB The address of Party B whose positions are being liquidated.
	 * @param partyA The address of Party A related to the liquidation.
	 * @param priceSig The Muon signature containing the quote price data.
	 */
	function liquidatePositionsPartyB(
		address partyB,
		address partyA,
		QuotePriceSig memory priceSig
	) external whenNotLiquidationPaused onlyRole(LibAccessibility.LIQUIDATOR_ROLE) {
		(uint256[] memory liquidatedAmounts, uint256[] memory closeIds) = LiquidationFacetImpl.liquidatePositionsPartyB(partyB, partyA, priceSig);
		emit LiquidatePositionsPartyB(msg.sender, partyB, partyA, priceSig.quoteIds, liquidatedAmounts, closeIds);
		emit LiquidatePositionsPartyB(msg.sender, partyB, partyA, priceSig.quoteIds); // For backward compatibility, will be removed in future
		if (QuoteStorage.layout().partyBPositionsCount[partyB][partyA] == 0) {
			emit FullyLiquidatedPartyB(partyB, partyA);
		}
	}
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../Strings.sol";

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

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

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

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

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

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

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

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

        return (signer, RecoverError.NoError);
    }

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

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

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

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, "\x19\x01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            data := keccak256(ptr, 0x42)
        }
    }

    /**
     * @dev Returns an Ethereum Signed Data with intended validator, created from a
     * `validator` and `data` according to the version 0 of EIP-191.
     *
     * See {recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x00", validator, data));
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv overflow");

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";
import "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toString(int256 value) internal pure returns (string memory) {
        return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

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

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "../../libraries/LibLockedValues.sol";
import "../../libraries/LibMuon.sol";
import "../../libraries/LibAccount.sol";
import "../../libraries/LibQuote.sol";
import "../../libraries/LibLiquidation.sol";
import "../../libraries/SharedEvents.sol";
import "../../storages/MAStorage.sol";
import "../../storages/QuoteStorage.sol";
import "../../storages/MuonStorage.sol";
import "../../storages/AccountStorage.sol";
import "../../storages/SymbolStorage.sol";

library DeferredLiquidationFacetImpl {
    using LockedValuesOps for LockedValues;

    function deferredLiquidatePartyA(address partyA, DeferredLiquidationSig memory liquidationSig) internal {
        MAStorage.Layout storage maLayout = MAStorage.layout();
        AccountStorage.Layout storage accountLayout = AccountStorage.layout();

        LibMuon.verifyDeferredLiquidationSig(liquidationSig, partyA);

        int256 liquidationAvailableBalance = LibAccount.partyAAvailableBalanceForLiquidation(
            liquidationSig.upnl,
            liquidationSig.liquidationAllocatedBalance,
            partyA
        );
        require(liquidationAvailableBalance < 0, "LiquidationFacet: PartyA is solvent");

        int256 availableBalance = LibAccount.partyAAvailableBalanceForLiquidation(
            liquidationSig.upnl,
            accountLayout.allocatedBalances[partyA],
            partyA
        );
        if (availableBalance > 0) {
            accountLayout.allocatedBalances[partyA] -= uint256(availableBalance);
            accountLayout.partyAReimbursement[partyA] += uint256(availableBalance);
        }

        maLayout.liquidationStatus[partyA] = true;
        accountLayout.liquidationDetails[partyA] = LiquidationDetail({
            liquidationId: liquidationSig.liquidationId,
            liquidationType: LiquidationType.NONE,
            upnl: liquidationSig.upnl,
            totalUnrealizedLoss: liquidationSig.totalUnrealizedLoss,
            deficit: 0,
            liquidationFee: 0,
            timestamp: liquidationSig.timestamp,
            involvedPartyBCounts: 0,
            partyAAccumulatedUpnl: 0,
            disputed: false,
            liquidationTimestamp: liquidationSig.liquidationTimestamp
        });
        accountLayout.liquidators[partyA].push(msg.sender);
    }

    function deferredSetSymbolsPrice(address partyA, DeferredLiquidationSig memory liquidationSig) internal {
        MAStorage.Layout storage maLayout = MAStorage.layout();
        AccountStorage.Layout storage accountLayout = AccountStorage.layout();

        LibMuon.verifyDeferredLiquidationSig(liquidationSig, partyA);
        require(maLayout.liquidationStatus[partyA], "LiquidationFacet: PartyA is solvent");

        LiquidationDetail storage detail = accountLayout.liquidationDetails[partyA];
        require(keccak256(detail.liquidationId) == keccak256(liquidationSig.liquidationId), "LiquidationFacet: Invalid liquidationId");

        for (uint256 index = 0; index < liquidationSig.symbolIds.length; index++) {
            accountLayout.symbolsPrices[partyA][liquidationSig.symbolIds[index]] = Price(liquidationSig.prices[index], detail.timestamp);
        }

        int256 availableBalance = LibAccount.partyAAvailableBalanceForLiquidation(liquidationSig.upnl, accountLayout.allocatedBalances[partyA], partyA);

        if (detail.liquidationType == LiquidationType.NONE) {
            if (uint256(- availableBalance) < accountLayout.lockedBalances[partyA].lf) {
                uint256 remainingLf = accountLayout.lockedBalances[partyA].lf - uint256(- availableBalance);
                detail.liquidationType = LiquidationType.NORMAL;
                detail.liquidationFee = remainingLf;
            } else if (uint256(- availableBalance) <= accountLayout.lockedBalances[partyA].lf + accountLayout.lockedBalances[partyA].cva) {
                uint256 deficit = uint256(- availableBalance) - accountLayout.lockedBalances[partyA].lf;
                detail.liquidationType = LiquidationType.LATE;
                detail.deficit = deficit;
            } else {
                uint256 deficit = uint256(- availableBalance) - accountLayout.lockedBalances[partyA].lf - accountLayout.lockedBalances[partyA].cva;
                detail.liquidationType = LiquidationType.OVERDUE;
                detail.deficit = deficit;
            }
            accountLayout.liquidators[partyA].push(msg.sender);
        }
    }
}

File 8 of 27 : ILiquidationEvents.sol
// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;
import "../../interfaces/IPartiesEvents.sol";

interface ILiquidationEvents is IPartiesEvents {
	event LiquidatePartyA(address liquidator, address partyA, uint256 allocatedBalance, int256 upnl, int256 totalUnrealizedLoss, bytes liquidationId);
	event LiquidatePartyA(address liquidator, address partyA, uint256 allocatedBalance, int256 upnl, int256 totalUnrealizedLoss); // For backward compatibility, will be removed in future
	event DeferredLiquidatePartyA(
		address liquidator,
		address partyA,
		uint256 allocatedBalance,
		int256 upnl,
		int256 totalUnrealizedLoss,
		bytes liquidationId,
		uint256 liquidationBlockNumber,
		uint256 liquidationTimestamp,
		uint256 liquidationAllocatedBalance
	);
	event LiquidatePositionsPartyA(
		address liquidator,
		address partyA,
		uint256[] quoteIds,
		uint256[] liquidatedAmounts,
		uint256[] closeIds,
		bytes liquidationId
	);
	event LiquidatePositionsPartyA(address liquidator, address partyA, uint256[] quoteIds); // For backward compatibility, will be removed in future
	event LiquidatePendingPositionsPartyA(address liquidator, address partyA, uint256[] quoteIds, uint256[] liquidatedAmounts, bytes liquidationId);
	event LiquidatePendingPositionsPartyA(address liquidator, address partyA); // For backward compatibility, will be removed in future
	event SettlePartyALiquidation(address partyA, address[] partyBs, int256[] amounts, bytes liquidationId);
	event SettlePartyALiquidation(address partyA, address[] partyBs, int256[] amounts); // For backward compatibility, will be removed in future
	event LiquidationDisputed(address partyA, bytes liquidationId);
	event LiquidationDisputed(address partyA); // For backward compatibility, will be removed in future
	event ResolveLiquidationDispute(address partyA, address[] partyBs, int256[] amounts, bool disputed, bytes liquidationId);
	event ResolveLiquidationDispute(address partyA, address[] partyBs, int256[] amounts, bool disputed); // For backward compatibility, will be removed in future
	event FullyLiquidatedPartyA(address partyA, bytes liquidationId);
	event FullyLiquidatedPartyA(address partyA); // For backward compatibility, will be removed in future
	event LiquidatePositionsPartyB(
		address liquidator,
		address partyB,
		address partyA,
		uint256[] quoteIds,
		uint256[] liquidatedAmounts,
		uint256[] closeIds
	);
	event LiquidatePositionsPartyB(address liquidator, address partyB, address partyA, uint256[] quoteIds); // For backward compatibility, will be removed in future
	event FullyLiquidatedPartyB(address partyB, address partyA);
	event SetSymbolsPrices(address liquidator, address partyA, uint256[] symbolIds, uint256[] prices, bytes liquidationId);
	event SetSymbolsPrices(address liquidator, address partyA, uint256[] symbolIds, uint256[] prices); // For backward compatibility, will be removed in future
	event DisputeForLiquidation(address liquidator, address partyA, bytes liquidationId);
}

// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "./ILiquidationEvents.sol";
import "../../storages/AccountStorage.sol";
import "../../storages/MuonStorage.sol";

interface ILiquidationFacet is ILiquidationEvents {
	function liquidatePartyA(address partyA, LiquidationSig memory liquidationSig) external;

	function setSymbolsPrice(address partyA, LiquidationSig memory liquidationSig) external;

	function deferredLiquidatePartyA(address partyA, DeferredLiquidationSig memory liquidationSig) external;

	function deferredSetSymbolsPrice(address partyA, DeferredLiquidationSig memory liquidationSig) external;

	function liquidatePendingPositionsPartyA(address partyA) external;

	function liquidatePositionsPartyA(address partyA, uint256[] memory quoteIds) external;

	function settlePartyALiquidation(address partyA, address[] memory partyBs) external;

	function resolveLiquidationDispute(address partyA, address[] memory partyBs, int256[] memory amounts, bool disputed) external;

	function liquidatePartyB(address partyB, address partyA, SingleUpnlSig memory upnlSig) external;

	function liquidatePositionsPartyB(address partyB, address partyA, QuotePriceSig memory priceSig) external;
}

// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "../../libraries/LibLockedValues.sol";
import "../../libraries/LibMuon.sol";
import "../../libraries/LibAccount.sol";
import "../../libraries/LibQuote.sol";
import "../../libraries/LibLiquidation.sol";
import "../../libraries/SharedEvents.sol";
import "../../storages/MAStorage.sol";
import "../../storages/QuoteStorage.sol";
import "../../storages/MuonStorage.sol";
import "../../storages/AccountStorage.sol";
import "../../storages/SymbolStorage.sol";

library LiquidationFacetImpl {
    using LockedValuesOps for LockedValues;

    function liquidatePartyA(address partyA, LiquidationSig memory liquidationSig) internal {
        MAStorage.Layout storage maLayout = MAStorage.layout();
        AccountStorage.Layout storage accountLayout = AccountStorage.layout();

        LibMuon.verifyLiquidationSig(liquidationSig, partyA);
        require(block.timestamp <= liquidationSig.timestamp + MuonStorage.layout().upnlValidTime, "LiquidationFacet: Expired signature");
        int256 availableBalance = LibAccount.partyAAvailableBalanceForLiquidation(liquidationSig.upnl, accountLayout.allocatedBalances[partyA], partyA);
        require(availableBalance < 0, "LiquidationFacet: PartyA is solvent");
        maLayout.liquidationStatus[partyA] = true;
        accountLayout.liquidationDetails[partyA] = LiquidationDetail({
            liquidationId: liquidationSig.liquidationId,
            liquidationType: LiquidationType.NONE,
            upnl: liquidationSig.upnl,
            totalUnrealizedLoss: liquidationSig.totalUnrealizedLoss,
            deficit: 0,
            liquidationFee: 0,
            timestamp: liquidationSig.timestamp,
            involvedPartyBCounts: 0,
            partyAAccumulatedUpnl: 0,
            disputed: false,
            liquidationTimestamp: liquidationSig.timestamp
        });
        accountLayout.liquidators[partyA].push(msg.sender);
    }

    function setSymbolsPrice(address partyA, LiquidationSig memory liquidationSig) internal{
        MAStorage.Layout storage maLayout = MAStorage.layout();
        AccountStorage.Layout storage accountLayout = AccountStorage.layout();

        LibMuon.verifyLiquidationSig(liquidationSig, partyA);
        require(maLayout.liquidationStatus[partyA], "LiquidationFacet: PartyA is solvent");
        require(
            keccak256(accountLayout.liquidationDetails[partyA].liquidationId) == keccak256(liquidationSig.liquidationId),
            "LiquidationFacet: Invalid liquidationId"
        );
        for (uint256 index = 0; index < liquidationSig.symbolIds.length; index++) {
            accountLayout.symbolsPrices[partyA][liquidationSig.symbolIds[index]] = Price(
                liquidationSig.prices[index],
                accountLayout.liquidationDetails[partyA].timestamp
            );
        }

        int256 availableBalance = LibAccount.partyAAvailableBalanceForLiquidation(liquidationSig.upnl, accountLayout.allocatedBalances[partyA], partyA);
        if (accountLayout.liquidationDetails[partyA].liquidationType == LiquidationType.NONE) {
            if (uint256(-availableBalance) < accountLayout.lockedBalances[partyA].lf) {
                uint256 remainingLf = accountLayout.lockedBalances[partyA].lf - uint256(-availableBalance);
                accountLayout.liquidationDetails[partyA].liquidationType = LiquidationType.NORMAL;
                accountLayout.liquidationDetails[partyA].liquidationFee = remainingLf;
            } else if (uint256(-availableBalance) <= accountLayout.lockedBalances[partyA].lf + accountLayout.lockedBalances[partyA].cva) {
                uint256 deficit = uint256(-availableBalance) - accountLayout.lockedBalances[partyA].lf;
                accountLayout.liquidationDetails[partyA].liquidationType = LiquidationType.LATE;
                accountLayout.liquidationDetails[partyA].deficit = deficit;
            } else {
                uint256 deficit = uint256(-availableBalance) - accountLayout.lockedBalances[partyA].lf - accountLayout.lockedBalances[partyA].cva;
                accountLayout.liquidationDetails[partyA].liquidationType = LiquidationType.OVERDUE;
                accountLayout.liquidationDetails[partyA].deficit = deficit;
            }
            accountLayout.liquidators[partyA].push(msg.sender);
        }
    }


    function liquidatePendingPositionsPartyA(address partyA) internal returns (uint256[] memory liquidatedAmounts, bytes memory liquidationId) {
        QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
        AccountStorage.Layout storage accountLayout = AccountStorage.layout();

        require(MAStorage.layout().liquidationStatus[partyA], "LiquidationFacet: PartyA is solvent");
        liquidatedAmounts = new uint256[](quoteLayout.partyAPendingQuotes[partyA].length);
        liquidationId = accountLayout.liquidationDetails[partyA].liquidationId;
        for (uint256 index = 0; index < quoteLayout.partyAPendingQuotes[partyA].length; index++) {
            Quote storage quote = quoteLayout.quotes[quoteLayout.partyAPendingQuotes[partyA][index]];
            if (
                (quote.quoteStatus == QuoteStatus.LOCKED || quote.quoteStatus == QuoteStatus.CANCEL_PENDING) &&
                quoteLayout.partyBPendingQuotes[quote.partyB][partyA].length > 0
            ) {
                delete quoteLayout.partyBPendingQuotes[quote.partyB][partyA];
                accountLayout.partyBPendingLockedBalances[quote.partyB][partyA].makeZero();
            }
            accountLayout.partyAReimbursement[partyA] += LibQuote.getTradingFee(quote.id);
            quote.quoteStatus = QuoteStatus.LIQUIDATED_PENDING;
            quote.statusModifyTimestamp = block.timestamp;
            liquidatedAmounts[index] = quote.quantity;
        }
        accountLayout.pendingLockedBalances[partyA].makeZero();
        delete quoteLayout.partyAPendingQuotes[partyA];
    }

    function liquidatePositionsPartyA(
        address partyA,
        uint256[] memory quoteIds
    ) internal returns (bool, uint256[] memory liquidatedAmounts, uint256[] memory closeIds, bytes memory liquidationId) {
        AccountStorage.Layout storage accountLayout = AccountStorage.layout();
        MAStorage.Layout storage maLayout = MAStorage.layout();
        QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();

        liquidatedAmounts = new uint256[](quoteIds.length);
        closeIds = new uint256[](quoteIds.length);
        liquidationId = accountLayout.liquidationDetails[partyA].liquidationId;

        require(maLayout.liquidationStatus[partyA], "LiquidationFacet: PartyA is solvent");
        for (uint256 index = 0; index < quoteIds.length; index++) {
            Quote storage quote = quoteLayout.quotes[quoteIds[index]];
            require(
                quote.quoteStatus == QuoteStatus.OPENED ||
                quote.quoteStatus == QuoteStatus.CLOSE_PENDING ||
                quote.quoteStatus == QuoteStatus.CANCEL_CLOSE_PENDING,
                "LiquidationFacet: Invalid state"
            );
            require(!maLayout.partyBLiquidationStatus[quote.partyB][partyA], "LiquidationFacet: PartyB is in liquidation process");
            require(quote.partyA == partyA, "LiquidationFacet: Invalid party");
            require(
                accountLayout.symbolsPrices[partyA][quote.symbolId].timestamp == accountLayout.liquidationDetails[partyA].timestamp,
                "LiquidationFacet: Price should be set"
            );
            liquidatedAmounts[index] = quote.quantity - quote.closedAmount;
            closeIds[index] = quoteLayout.closeIds[quote.id];
            quote.quoteStatus = QuoteStatus.LIQUIDATED;
            quote.statusModifyTimestamp = block.timestamp;

            accountLayout.partyBNonces[quote.partyB][quote.partyA] += 1;

            (bool hasMadeProfit, uint256 amount) = LibQuote.getValueOfQuoteForPartyA(
                accountLayout.symbolsPrices[partyA][quote.symbolId].price,
                LibQuote.quoteOpenAmount(quote),
                quote
            );

            if (!accountLayout.settlementStates[partyA][quote.partyB].pending) {
                accountLayout.settlementStates[partyA][quote.partyB].pending = true;
                accountLayout.liquidationDetails[partyA].involvedPartyBCounts += 1;
            }
            if (accountLayout.liquidationDetails[partyA].liquidationType == LiquidationType.NORMAL) {
                accountLayout.settlementStates[partyA][quote.partyB].cva += quote.lockedValues.cva;

                if (hasMadeProfit) {
                    accountLayout.settlementStates[partyA][quote.partyB].actualAmount += int256(amount);
                } else {
                    accountLayout.settlementStates[partyA][quote.partyB].actualAmount -= int256(amount);
                }
                accountLayout.settlementStates[partyA][quote.partyB].expectedAmount = accountLayout
                    .settlementStates[partyA][quote.partyB].actualAmount;
            } else if (accountLayout.liquidationDetails[partyA].liquidationType == LiquidationType.LATE) {
                accountLayout.settlementStates[partyA][quote.partyB].cva +=
                    quote.lockedValues.cva -
                    ((quote.lockedValues.cva * accountLayout.liquidationDetails[partyA].deficit) / accountLayout.lockedBalances[partyA].cva);
                if (hasMadeProfit) {
                    accountLayout.settlementStates[partyA][quote.partyB].actualAmount += int256(amount);
                } else {
                    accountLayout.settlementStates[partyA][quote.partyB].actualAmount -= int256(amount);
                }
                accountLayout.settlementStates[partyA][quote.partyB].expectedAmount = accountLayout
                    .settlementStates[partyA][quote.partyB].actualAmount;
            } else if (accountLayout.liquidationDetails[partyA].liquidationType == LiquidationType.OVERDUE) {
                if (hasMadeProfit) {
                    accountLayout.settlementStates[partyA][quote.partyB].actualAmount += int256(amount);
                    accountLayout.settlementStates[partyA][quote.partyB].expectedAmount += int256(amount);
                } else {
                    accountLayout.settlementStates[partyA][quote.partyB].actualAmount -= int256(
                        amount -
                        ((amount * accountLayout.liquidationDetails[partyA].deficit) /
                            uint256(- accountLayout.liquidationDetails[partyA].totalUnrealizedLoss))
                    );
                    accountLayout.settlementStates[partyA][quote.partyB].expectedAmount -= int256(amount);
                }
            }
            accountLayout.partyBLockedBalances[quote.partyB][partyA].subQuote(quote);
            quote.avgClosedPrice =
                (quote.avgClosedPrice *
                quote.closedAmount +
                    LibQuote.quoteOpenAmount(quote) *
                    accountLayout.symbolsPrices[partyA][quote.symbolId].price) /
                (quote.closedAmount + LibQuote.quoteOpenAmount(quote));
            quote.closedAmount = quote.quantity;

            LibQuote.removeFromOpenPositions(quote.id);
            quoteLayout.partyAPositionsCount[partyA] -= 1;
            quoteLayout.partyBPositionsCount[quote.partyB][partyA] -= 1;

            if (quoteLayout.partyBPositionsCount[quote.partyB][partyA] == 0) {
                int256 settleAmount = accountLayout.settlementStates[partyA][quote.partyB].expectedAmount;
                if (settleAmount < 0) {
                    accountLayout.liquidationDetails[partyA].partyAAccumulatedUpnl += settleAmount;
                } else {
                    if (accountLayout.partyBAllocatedBalances[quote.partyB][partyA] >= uint256(settleAmount)) {
                        accountLayout.liquidationDetails[partyA].partyAAccumulatedUpnl += settleAmount;
                    } else {
                        accountLayout.liquidationDetails[partyA].partyAAccumulatedUpnl += int256(
                            accountLayout.partyBAllocatedBalances[quote.partyB][partyA]
                        );
                    }
                }
            }
        }
        if (
            quoteLayout.partyAPositionsCount[partyA] == 0 &&
            accountLayout.liquidationDetails[partyA].partyAAccumulatedUpnl != accountLayout.liquidationDetails[partyA].upnl
        ) {
            accountLayout.liquidationDetails[partyA].disputed = true;
            return (true, liquidatedAmounts, closeIds, liquidationId);
        }
        return (false, liquidatedAmounts, closeIds, liquidationId);
    }

    function resolveLiquidationDispute(
        address partyA,
        address[] memory partyBs,
        int256[] memory amounts,
        bool disputed
    ) internal returns (bytes memory) {
        AccountStorage.Layout storage accountLayout = AccountStorage.layout();

        accountLayout.liquidationDetails[partyA].disputed = disputed;
        require(partyBs.length == amounts.length, "LiquidationFacet: Invalid length");
        for (uint256 i = 0; i < partyBs.length; i++) {
            accountLayout.settlementStates[partyA][partyBs[i]].actualAmount = amounts[i];
        }
        return accountLayout.liquidationDetails[partyA].liquidationId;
    }

    function settlePartyALiquidation(
        address partyA,
        address[] memory partyBs
    ) internal returns (int256[] memory settleAmounts, bytes memory liquidationId) {
        AccountStorage.Layout storage accountLayout = AccountStorage.layout();
        QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
        require(
            quoteLayout.partyAPositionsCount[partyA] == 0 && quoteLayout.partyAPendingQuotes[partyA].length == 0,
            "LiquidationFacet: PartyA has still open positions"
        );
        require(MAStorage.layout().liquidationStatus[partyA], "LiquidationFacet: PartyA is solvent");
        require(!accountLayout.liquidationDetails[partyA].disputed, "LiquidationFacet: PartyA liquidation process get disputed");
        liquidationId = accountLayout.liquidationDetails[partyA].liquidationId;
        settleAmounts = new int256[](partyBs.length);
        for (uint256 i = 0; i < partyBs.length; i++) {
            address partyB = partyBs[i];
            require(accountLayout.settlementStates[partyA][partyB].pending, "LiquidationFacet: PartyB is not in settlement");
            accountLayout.settlementStates[partyA][partyB].pending = false;
            accountLayout.liquidationDetails[partyA].involvedPartyBCounts -= 1;

            int256 settleAmount = accountLayout.settlementStates[partyA][partyB].actualAmount;
            accountLayout.partyBAllocatedBalances[partyB][partyA] += accountLayout.settlementStates[partyA][partyB].cva;
            emit SharedEvents.BalanceChangePartyA(partyA, accountLayout.settlementStates[partyA][partyB].cva, SharedEvents.BalanceChangeType.CVA_OUT);
            emit SharedEvents.BalanceChangePartyB(
                partyB,
                partyA,
                accountLayout.settlementStates[partyA][partyB].cva,
                SharedEvents.BalanceChangeType.CVA_IN
            );

            if (settleAmount < 0) {
                accountLayout.partyBAllocatedBalances[partyB][partyA] += uint256(- settleAmount);
                emit SharedEvents.BalanceChangePartyB(partyB, partyA, uint256(- settleAmount), SharedEvents.BalanceChangeType.REALIZED_PNL_IN);
                settleAmounts[i] = settleAmount;
            } else {
                if (accountLayout.partyBAllocatedBalances[partyB][partyA] >= uint256(settleAmount)) {
                    accountLayout.partyBAllocatedBalances[partyB][partyA] -= uint256(settleAmount);
                    settleAmounts[i] = settleAmount;
                    emit SharedEvents.BalanceChangePartyB(partyB, partyA, uint256(settleAmount), SharedEvents.BalanceChangeType.REALIZED_PNL_OUT);
                } else {
                    settleAmounts[i] = int256(accountLayout.partyBAllocatedBalances[partyB][partyA]);
                    accountLayout.partyBAllocatedBalances[partyB][partyA] = 0;
                    emit SharedEvents.BalanceChangePartyB(partyB, partyA, uint256(settleAmounts[i]), SharedEvents.BalanceChangeType.REALIZED_PNL_OUT);
                }
            }
            delete accountLayout.settlementStates[partyA][partyB];
        }
        if (accountLayout.liquidationDetails[partyA].involvedPartyBCounts == 0) {
            emit SharedEvents.BalanceChangePartyA(partyA, accountLayout.allocatedBalances[partyA], SharedEvents.BalanceChangeType.REALIZED_PNL_OUT);
            accountLayout.allocatedBalances[partyA] = accountLayout.partyAReimbursement[partyA];
            emit SharedEvents.BalanceChangePartyA(partyA, accountLayout.partyAReimbursement[partyA], SharedEvents.BalanceChangeType.PLATFORM_FEE_IN);
            accountLayout.partyAReimbursement[partyA] = 0;
            accountLayout.lockedBalances[partyA].makeZero();

            uint256 lf = accountLayout.liquidationDetails[partyA].liquidationFee;
            if (lf > 0) {
                accountLayout.allocatedBalances[accountLayout.liquidators[partyA][0]] += lf / 2;
                accountLayout.allocatedBalances[accountLayout.liquidators[partyA][1]] += lf / 2;
                emit SharedEvents.BalanceChangePartyA(accountLayout.liquidators[partyA][0], lf / 2, SharedEvents.BalanceChangeType.LF_IN);
                emit SharedEvents.BalanceChangePartyA(accountLayout.liquidators[partyA][1], lf / 2, SharedEvents.BalanceChangeType.LF_IN);
            }
            delete accountLayout.liquidators[partyA];
            delete accountLayout.liquidationDetails[partyA].liquidationType;
            MAStorage.layout().liquidationStatus[partyA] = false;
            accountLayout.partyANonces[partyA] += 1;
        }
    }

    function liquidatePartyB(address partyB, address partyA, SingleUpnlSig memory upnlSig) internal {
        LibMuon.verifyPartyBUpnl(upnlSig, partyB, partyA);
        LibLiquidation.liquidatePartyB(partyB, partyA, upnlSig.upnl, upnlSig.timestamp);
    }

    function liquidatePositionsPartyB(
        address partyB,
        address partyA,
        QuotePriceSig memory priceSig
    ) internal returns (uint256[] memory liquidatedAmounts, uint256[] memory closeIds) {
        AccountStorage.Layout storage accountLayout = AccountStorage.layout();
        MAStorage.Layout storage maLayout = MAStorage.layout();
        QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();

        LibMuon.verifyQuotePrices(priceSig);
        require(
            priceSig.timestamp <= maLayout.partyBLiquidationTimestamp[partyB][partyA] + maLayout.liquidationTimeout,
            "LiquidationFacet: Invalid signature"
        );
        require(maLayout.partyBLiquidationStatus[partyB][partyA], "LiquidationFacet: PartyB is solvent");
        require(maLayout.partyBLiquidationTimestamp[partyB][partyA] <= priceSig.timestamp, "LiquidationFacet: Expired signature");

        liquidatedAmounts = new uint256[](priceSig.quoteIds.length);
        closeIds = new uint256[](priceSig.quoteIds.length);

        for (uint256 index = 0; index < priceSig.quoteIds.length; index++) {
            Quote storage quote = quoteLayout.quotes[priceSig.quoteIds[index]];
            require(
                quote.quoteStatus == QuoteStatus.OPENED ||
                quote.quoteStatus == QuoteStatus.CLOSE_PENDING ||
                quote.quoteStatus == QuoteStatus.CANCEL_CLOSE_PENDING,
                "LiquidationFacet: Invalid state"
            );
            require(quote.partyA == partyA && quote.partyB == partyB, "LiquidationFacet: Invalid party");

            liquidatedAmounts[index] = quote.quantity - quote.closedAmount;
            closeIds[index] = quoteLayout.closeIds[quote.id];
            quote.quoteStatus = QuoteStatus.LIQUIDATED;
            quote.statusModifyTimestamp = block.timestamp;

            accountLayout.lockedBalances[partyA].subQuote(quote);

            quote.avgClosedPrice =
                (quote.avgClosedPrice * quote.closedAmount + LibQuote.quoteOpenAmount(quote) * priceSig.prices[index]) /
                (quote.closedAmount + LibQuote.quoteOpenAmount(quote));
            quote.closedAmount = quote.quantity;

            LibQuote.removeFromOpenPositions(quote.id);
            quoteLayout.partyAPositionsCount[partyA] -= 1;
            quoteLayout.partyBPositionsCount[partyB][partyA] -= 1;
        }
        if (maLayout.partyBPositionLiquidatorsShare[partyB][partyA] > 0) {
            accountLayout.allocatedBalances[msg.sender] += maLayout.partyBPositionLiquidatorsShare[partyB][partyA] * priceSig.quoteIds.length;
        }

        if (quoteLayout.partyBPositionsCount[partyB][partyA] == 0) {
            maLayout.partyBLiquidationStatus[partyB][partyA] = false;
            maLayout.partyBLiquidationTimestamp[partyB][partyA] = 0;
            accountLayout.partyBNonces[partyB][partyA] += 1;
        }
        return (liquidatedAmounts, closeIds);
    }
}

File 11 of 27 : IPartiesEvents.sol
// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "../storages/QuoteStorage.sol";

interface IPartiesEvents {
	event SendQuote(
		address partyA,
		uint256 quoteId,
		address[] partyBsWhiteList,
		uint256 symbolId,
		PositionType positionType,
		OrderType orderType,
		uint256 price,
		uint256 marketPrice,
		uint256 quantity,
		uint256 cva,
		uint256 lf,
		uint256 partyAmm,
		uint256 partyBmm,
		uint256 tradingFee,
		uint256 deadline
	);

	event ExpireQuote(QuoteStatus quoteStatus, uint256 quoteId); // For backward compatibility, will be removed in future

	event ExpireQuoteOpen(QuoteStatus quoteStatus, uint256 quoteId);

	event ExpireQuoteClose(QuoteStatus quoteStatus, uint256 quoteId, uint256 closeId);

	event LiquidatePartyB(address liquidator, address partyB, address partyA, uint256 partyBAllocatedBalance, int256 upnl);
}

// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "../storages/GlobalAppStorage.sol";

library LibAccessibility {
	bytes32 public constant DEFAULT_ADMIN_ROLE = keccak256("DEFAULT_ADMIN_ROLE");
	bytes32 public constant MUON_SETTER_ROLE = keccak256("MUON_SETTER_ROLE");
	bytes32 public constant SYMBOL_MANAGER_ROLE = keccak256("SYMBOL_MANAGER_ROLE");
	bytes32 public constant SETTER_ROLE = keccak256("SETTER_ROLE");
	bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
	bytes32 public constant UNPAUSER_ROLE = keccak256("UNPAUSER_ROLE");
	bytes32 public constant PARTY_B_MANAGER_ROLE = keccak256("PARTY_B_MANAGER_ROLE");
	bytes32 public constant LIQUIDATOR_ROLE = keccak256("LIQUIDATOR_ROLE");
	bytes32 public constant SUSPENDER_ROLE = keccak256("SUSPENDER_ROLE");
	bytes32 public constant DISPUTE_ROLE = keccak256("DISPUTE_ROLE");
	bytes32 public constant AFFILIATE_MANAGER_ROLE = keccak256("AFFILIATE_MANAGER_ROLE");

	/**
	 * @notice Checks if a user has a specific role.
	 * @param user The address of the user.
	 * @param role The role to check.
	 * @return Whether the user has the specified role.
	 */
	function hasRole(address user, bytes32 role) internal view returns (bool) {
		GlobalAppStorage.Layout storage layout = GlobalAppStorage.layout();
		return layout.hasRole[user][role];
	}
}

// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "./LibLockedValues.sol";
import "../storages/AccountStorage.sol";

library LibAccount {
	using LockedValuesOps for LockedValues;

	/**
	 * @notice Calculates the total locked balances of Party A.
	 * @param partyA The address of Party A.
	 * @return The total locked balances of Party A.
	 */
	function partyATotalLockedBalances(address partyA) internal view returns (uint256) {
		AccountStorage.Layout storage accountLayout = AccountStorage.layout();
		return accountLayout.pendingLockedBalances[partyA].totalForPartyA() + accountLayout.lockedBalances[partyA].totalForPartyA();
	}

	/**
	 * @notice Calculates the total locked balances of Party B for a specific Party A.
	 * @param partyB The address of Party B.
	 * @param partyA The address of Party A.
	 * @return The total locked balances of Party B for the specified Party A.
	 */
	function partyBTotalLockedBalances(address partyB, address partyA) internal view returns (uint256) {
		AccountStorage.Layout storage accountLayout = AccountStorage.layout();
		return
			accountLayout.partyBPendingLockedBalances[partyB][partyA].totalForPartyB() +
			accountLayout.partyBLockedBalances[partyB][partyA].totalForPartyB();
	}

	/**
	 * @notice Calculates the available balance for a quote for Party A.
	 * @param upnl The unrealized profit and loss.
	 * @param partyA The address of Party A.
	 * @return The available balance for a quote for Party A.
	 */
	function partyAAvailableForQuote(int256 upnl, address partyA) internal view returns (int256) {
		AccountStorage.Layout storage accountLayout = AccountStorage.layout();
		int256 available;
		if (upnl >= 0) {
			available =
				int256(accountLayout.allocatedBalances[partyA]) +
				upnl -
				int256((accountLayout.lockedBalances[partyA].totalForPartyA() + accountLayout.pendingLockedBalances[partyA].totalForPartyA()));
		} else {
			int256 mm = int256(accountLayout.lockedBalances[partyA].partyAmm);
			int256 considering_mm = -upnl > mm ? -upnl : mm;
			available =
				int256(accountLayout.allocatedBalances[partyA]) -
				int256(
					(accountLayout.lockedBalances[partyA].cva +
						accountLayout.lockedBalances[partyA].lf +
						accountLayout.pendingLockedBalances[partyA].totalForPartyA())
				) -
				considering_mm;
		}
		return available;
	}

	/**
	 * @notice Calculates the available balance for Party A.
	 * @param upnl The unrealized profit and loss.
	 * @param partyA The address of Party A.
	 * @return The available balance for Party A.
	 */
	function partyAAvailableBalance(int256 upnl, address partyA) internal view returns (int256) {
		AccountStorage.Layout storage accountLayout = AccountStorage.layout();
		int256 available;
		if (upnl >= 0) {
			available = int256(accountLayout.allocatedBalances[partyA]) + upnl - int256(accountLayout.lockedBalances[partyA].totalForPartyA());
		} else {
			int256 mm = int256(accountLayout.lockedBalances[partyA].partyAmm);
			int256 considering_mm = -upnl > mm ? -upnl : mm;
			available =
				int256(accountLayout.allocatedBalances[partyA]) -
				int256(accountLayout.lockedBalances[partyA].cva + accountLayout.lockedBalances[partyA].lf) -
				considering_mm;
		}
		return available;
	}

	/**
	 * @notice Calculates the available balance for liquidation for Party A.
	 * @param upnl The unrealized profit and loss.
	 * @param allocatedBalance The allocatedBalance of Party A.
	 * @param partyA The address of Party A.
	 * @return The available balance for liquidation for Party A.
	 */
	function partyAAvailableBalanceForLiquidation(int256 upnl, uint256 allocatedBalance, address partyA) internal view returns (int256) {
		AccountStorage.Layout storage accountLayout = AccountStorage.layout();
		int256 freeBalance = int256(allocatedBalance) -
			int256(accountLayout.lockedBalances[partyA].cva + accountLayout.lockedBalances[partyA].lf);
		return freeBalance + upnl;
	}

	/**
	 * @notice Calculates the available balance for a quote for Party B.
	 * @param upnl The unrealized profit and loss.
	 * @param partyB The address of Party B.
	 * @param partyA The address of Party A.
	 * @return The available balance for a quote for Party B.
	 */
	function partyBAvailableForQuote(int256 upnl, address partyB, address partyA) internal view returns (int256) {
		AccountStorage.Layout storage accountLayout = AccountStorage.layout();
		int256 available;
		if (upnl >= 0) {
			available =
				int256(accountLayout.partyBAllocatedBalances[partyB][partyA]) +
				upnl -
				int256(
					(accountLayout.partyBLockedBalances[partyB][partyA].totalForPartyB() +
						accountLayout.partyBPendingLockedBalances[partyB][partyA].totalForPartyB())
				);
		} else {
			int256 mm = int256(accountLayout.partyBLockedBalances[partyB][partyA].partyBmm);
			int256 considering_mm = -upnl > mm ? -upnl : mm;
			available =
				int256(accountLayout.partyBAllocatedBalances[partyB][partyA]) -
				int256(
					(accountLayout.partyBLockedBalances[partyB][partyA].cva +
						accountLayout.partyBLockedBalances[partyB][partyA].lf +
						accountLayout.partyBPendingLockedBalances[partyB][partyA].totalForPartyB())
				) -
				considering_mm;
		}
		return available;
	}

	/**
	 * @notice Calculates the available balance for Party B.
	 * @param upnl The unrealized profit and loss.
	 * @param partyB The address of Party B.
	 * @param partyA The address of Party A.
	 * @return The available balance for Party B.
	 */
	function partyBAvailableBalance(int256 upnl, address partyB, address partyA) internal view returns (int256) {
		AccountStorage.Layout storage accountLayout = AccountStorage.layout();
		int256 available;
		if (upnl >= 0) {
			available =
				int256(accountLayout.partyBAllocatedBalances[partyB][partyA]) +
				upnl -
				int256(accountLayout.partyBLockedBalances[partyB][partyA].totalForPartyB());
		} else {
			int256 mm = int256(accountLayout.partyBLockedBalances[partyB][partyA].partyBmm);
			int256 considering_mm = -upnl > mm ? -upnl : mm;
			available =
				int256(accountLayout.partyBAllocatedBalances[partyB][partyA]) -
				int256(accountLayout.partyBLockedBalances[partyB][partyA].cva + accountLayout.partyBLockedBalances[partyB][partyA].lf) -
				considering_mm;
		}
		return available;
	}

	/**
	 * @notice Calculates the available balance for liquidation for Party B.
	 * @param upnl The unrealized profit and loss.
	 * @param partyB The address of Party B.
	 * @param partyA The address of Party A.
	 * @return The available balance for liquidation for Party B.
	 */
	function partyBAvailableBalanceForLiquidation(int256 upnl, address partyB, address partyA) internal view returns (int256) {
		AccountStorage.Layout storage accountLayout = AccountStorage.layout();
		int256 a = int256(accountLayout.partyBAllocatedBalances[partyB][partyA]) -
			int256(accountLayout.partyBLockedBalances[partyB][partyA].cva + accountLayout.partyBLockedBalances[partyB][partyA].lf);
		return a + upnl;
	}
}

// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "../storages/MuonStorage.sol";
import "../storages/QuoteStorage.sol";
import "../libraries/SharedEvents.sol";
import "./LibAccount.sol";
import "./LibQuote.sol";

library LibLiquidation {
	using LockedValuesOps for LockedValues;

	/**
	 * @notice Liquidates Party B.
	 * @param partyB The address of Party B.
	 * @param partyA The address of Party A.
	 * @param upnlPartyB The unrealized profit and loss of Party B.
	 * @param timestamp The timestamp of the liquidation.
	 */
	function liquidatePartyB(address partyB, address partyA, int256 upnlPartyB, uint256 timestamp) internal {
		AccountStorage.Layout storage accountLayout = AccountStorage.layout();
		MAStorage.Layout storage maLayout = MAStorage.layout();
		QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();

		// Calculate available balance for liquidation
		int256 availableBalance = LibAccount.partyBAvailableBalanceForLiquidation(upnlPartyB, partyB, partyA);

		// Ensure Party B is insolvent
		require(availableBalance < 0, "LiquidationFacet: partyB is solvent");

		uint256 liquidatorShare;
		uint256 remainingLf;

		// Determine liquidator share and remaining locked funds
		if (uint256(-availableBalance) < accountLayout.partyBLockedBalances[partyB][partyA].lf) {
			remainingLf = accountLayout.partyBLockedBalances[partyB][partyA].lf - uint256(-availableBalance);
			liquidatorShare = (remainingLf * maLayout.liquidatorShare) / 1e18;

			maLayout.partyBPositionLiquidatorsShare[partyB][partyA] =
				(remainingLf - liquidatorShare) /
				quoteLayout.partyBPositionsCount[partyB][partyA];
		} else {
			maLayout.partyBPositionLiquidatorsShare[partyB][partyA] = 0;
		}

		// Update liquidation status and timestamp for Party B
		maLayout.partyBLiquidationStatus[partyB][partyA] = true;
		maLayout.partyBLiquidationTimestamp[partyB][partyA] = timestamp;

		uint256[] storage pendingQuotes = quoteLayout.partyAPendingQuotes[partyA];

		for (uint256 index = 0; index < pendingQuotes.length; ) {
			Quote storage quote = quoteLayout.quotes[pendingQuotes[index]];
			if (quote.partyB == partyB && (quote.quoteStatus == QuoteStatus.LOCKED || quote.quoteStatus == QuoteStatus.CANCEL_PENDING)) {
				accountLayout.pendingLockedBalances[partyA].subQuote(quote);
				uint256 fee = LibQuote.getTradingFee(quote.id);
				accountLayout.allocatedBalances[partyA] += fee;
				emit SharedEvents.BalanceChangePartyA(partyA, fee, SharedEvents.BalanceChangeType.PLATFORM_FEE_IN);
				pendingQuotes[index] = pendingQuotes[pendingQuotes.length - 1];
				pendingQuotes.pop();
				quote.quoteStatus = QuoteStatus.LIQUIDATED_PENDING;
				quote.statusModifyTimestamp = block.timestamp;
			} else {
				index++;
			}
		}

		// Update allocated balances for Party A
		uint256 value = accountLayout.partyBAllocatedBalances[partyB][partyA] - remainingLf;
		accountLayout.allocatedBalances[partyA] += value;
		emit SharedEvents.BalanceChangePartyA(partyA, value, SharedEvents.BalanceChangeType.REALIZED_PNL_IN);

		// Clear pending quotes and reset balances for Party B
		delete quoteLayout.partyBPendingQuotes[partyB][partyA];
		emit SharedEvents.BalanceChangePartyB(partyB, partyA, accountLayout.partyBAllocatedBalances[partyB][partyA],
			SharedEvents.BalanceChangeType.REALIZED_PNL_OUT);
		accountLayout.partyBAllocatedBalances[partyB][partyA] = 0;
		accountLayout.partyBLockedBalances[partyB][partyA].makeZero();
		accountLayout.partyBPendingLockedBalances[partyB][partyA].makeZero();
		accountLayout.partyANonces[partyA] += 1;

		// Transfer liquidator share to the liquidator
		if (liquidatorShare > 0) {
			accountLayout.allocatedBalances[msg.sender] += liquidatorShare;
			emit SharedEvents.BalanceChangePartyA(msg.sender, liquidatorShare, SharedEvents.BalanceChangeType.LF_IN);
		}
	}
}

// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "../storages/QuoteStorage.sol";

struct LockedValues {
	uint256 cva;
	uint256 lf;
	uint256 partyAmm;
	uint256 partyBmm;
}

library LockedValuesOps {
	using SafeMath for uint256;

	/**
	 * @notice Adds the values of two LockedValues structs.
	 * @param self The LockedValues struct to which values will be added.
	 * @param a The LockedValues struct containing values to be added.
	 * @return The updated LockedValues struct.
	 */
	function add(LockedValues storage self, LockedValues memory a) internal returns (LockedValues storage) {
		self.cva = self.cva.add(a.cva);
		self.partyAmm = self.partyAmm.add(a.partyAmm);
		self.partyBmm = self.partyBmm.add(a.partyBmm);
		self.lf = self.lf.add(a.lf);
		return self;
	}

	/**
	 * @notice Adds the locked values of a quote to a LockedValues struct.
	 * @param self The LockedValues struct to which values will be added.
	 * @param quote The Quote struct containing locked values to be added.
	 * @return The updated LockedValues struct.
	 */
	function addQuote(LockedValues storage self, Quote storage quote) internal returns (LockedValues storage) {
		return add(self, quote.lockedValues);
	}

	/**
	 * @notice Subtracts the values of two LockedValues structs.
	 * @param self The LockedValues struct from which values will be subtracted.
	 * @param a The LockedValues struct containing values to be subtracted.
	 * @return The updated LockedValues struct.
	 */
	function sub(LockedValues storage self, LockedValues memory a) internal returns (LockedValues storage) {
		self.cva = self.cva.sub(a.cva);
		self.partyAmm = self.partyAmm.sub(a.partyAmm);
		self.partyBmm = self.partyBmm.sub(a.partyBmm);
		self.lf = self.lf.sub(a.lf);
		return self;
	}

	/**
	 * @notice Subtracts the locked values of a quote from a LockedValues struct.
	 * @param self The LockedValues struct from which values will be subtracted.
	 * @param quote The Quote struct containing locked values to be subtracted.
	 * @return The updated LockedValues struct.
	 */
	function subQuote(LockedValues storage self, Quote storage quote) internal returns (LockedValues storage) {
		return sub(self, quote.lockedValues);
	}

	/**
	 * @notice Sets all values of a LockedValues struct to zero.
	 * @param self The LockedValues struct to be zeroed.
	 * @return The updated LockedValues struct.
	 */
	function makeZero(LockedValues storage self) internal returns (LockedValues storage) {
		self.cva = 0;
		self.partyAmm = 0;
		self.partyBmm = 0;
		self.lf = 0;
		return self;
	}

	/**
	 * @notice Calculates the total locked balance for Party A.
	 * @param self The LockedValues struct containing locked values.
	 * @return The total locked balance for Party A.
	 */
	function totalForPartyA(LockedValues memory self) internal pure returns (uint256) {
		return self.cva + self.partyAmm + self.lf;
	}

	/**
	 * @notice Calculates the total locked balance for Party B.
	 * @param self The LockedValues struct containing locked values.
	 * @return The total locked balance for Party B.
	 */
	function totalForPartyB(LockedValues memory self) internal pure returns (uint256) {
		return self.cva + self.partyBmm + self.lf;
	}

	/**
	 * @notice Multiplies all values of a LockedValues struct by a scalar value.
	 * @param self The LockedValues struct to be multiplied.
	 * @param a The scalar value to multiply by.
	 * @return The updated LockedValues struct.
	 */
	function mul(LockedValues storage self, uint256 a) internal returns (LockedValues storage) {
		self.cva = self.cva.mul(a);
		self.partyAmm = self.partyAmm.mul(a);
		self.partyBmm = self.partyBmm.mul(a);
		self.lf = self.lf.mul(a);
		return self;
	}

	/**
	 * @notice Multiplies all values of a LockedValues struct by a scalar value (memory version).
	 * @param self The LockedValues struct to be multiplied.
	 * @param a The scalar value to multiply by.
	 * @return The updated LockedValues struct.
	 */
	function mulMem(LockedValues memory self, uint256 a) internal pure returns (LockedValues memory) {
		LockedValues memory lockedValues = LockedValues(self.cva.mul(a), self.lf.mul(a), self.partyAmm.mul(a), self.partyBmm.mul(a));
		return lockedValues;
	}

	/**
	 * @notice Divides all values of a LockedValues struct by a scalar value.
	 * @param self The LockedValues struct to be divided.
	 * @param a The scalar value to divide by.
	 * @return The updated LockedValues struct.
	 */
	function div(LockedValues storage self, uint256 a) internal returns (LockedValues storage) {
		self.cva = self.cva.div(a);
		self.partyAmm = self.partyAmm.div(a);
		self.partyBmm = self.partyBmm.div(a);
		self.lf = self.lf.div(a);
		return self;
	}

	/**
	 * @notice Divides all values of a LockedValues struct by a scalar value (memory version).
	 * @param self The LockedValues struct to be divided.
	 * @param a The scalar value to divide by.
	 * @return The updated LockedValues struct.
	 */
	function divMem(LockedValues memory self, uint256 a) internal pure returns (LockedValues memory) {
		LockedValues memory lockedValues = LockedValues(self.cva.div(a), self.lf.div(a), self.partyAmm.div(a), self.partyBmm.div(a));
		return lockedValues;
	}
}

// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "../libraries/LibMuonV04ClientBase.sol";
import "../storages/MuonStorage.sol";
import "../storages/AccountStorage.sol";

library LibMuon {
	using ECDSA for bytes32;

	function getChainId() internal view returns (uint256 id) {
		assembly {
			id := chainid()
		}
	}

	// CONTEXT for commented out lines
	// We're utilizing muon signatures for asset pricing and user uPNLs calculations.
	// Even though these signatures are necessary for full testing of the system, particularly when invoking various methods.
	// The process of creating automated functional signature for tests has proven to be either impractical or excessively time-consuming. therefore, we've established commenting out the necessary code as a workaround specifically for testing.
	// Essentially, during testing, we temporarily disable the code sections responsible for validating these signatures. The sections I'm referring to are located within the LibMuon file. Specifically, the body of the 'verifyTSSAndGateway' method is a prime candidate for temporary disablement. In addition, several 'require' statements within other functions of this file, which examine the signatures' expiration status, also need to be temporarily disabled.
	// However, it is crucial to note that these lines should not be disabled in the production deployed version.
	// We emphasize this because they are only disabled for testing purposes.

	function verifyTSSAndGateway(bytes32 hash, SchnorrSign memory sign, bytes memory gatewaySignature) internal view {
		// == SignatureCheck( ==
		bool verified = LibMuonV04ClientBase.muonVerify(uint256(hash), sign, MuonStorage.layout().muonPublicKey);
		require(verified, "LibMuon: TSS not verified");

		hash = hash.toEthSignedMessageHash();
		address gatewaySignatureSigner = hash.recover(gatewaySignature);

		require(gatewaySignatureSigner == MuonStorage.layout().validGateway, "LibMuon: Gateway is not valid");
		// == ) ==
	}

	function verifyLiquidationSig(LiquidationSig memory liquidationSig, address partyA) internal view {
		MuonStorage.Layout storage muonLayout = MuonStorage.layout();
		require(liquidationSig.prices.length == liquidationSig.symbolIds.length, "LibMuon: Invalid length");
		bytes32 hash = keccak256(
			abi.encodePacked(
				muonLayout.muonAppId,
				liquidationSig.reqId,
				liquidationSig.liquidationId,
				address(this),
				"verifyLiquidationSig",
				partyA,
				AccountStorage.layout().partyANonces[partyA],
				liquidationSig.upnl,
				liquidationSig.totalUnrealizedLoss,
				liquidationSig.symbolIds,
				liquidationSig.prices,
				liquidationSig.timestamp,
				getChainId()
			)
		);
		verifyTSSAndGateway(hash, liquidationSig.sigs, liquidationSig.gatewaySignature);
	}

	function verifyDeferredLiquidationSig(DeferredLiquidationSig memory liquidationSig, address partyA) internal view {
		MuonStorage.Layout storage muonLayout = MuonStorage.layout();
		require(liquidationSig.prices.length == liquidationSig.symbolIds.length, "LibMuon: Invalid length");
		bytes32 hash = keccak256(
			abi.encodePacked(
				muonLayout.muonAppId,
				liquidationSig.reqId,
				liquidationSig.liquidationId,
				address(this),
				"verifyDeferredLiquidationSig",
				partyA,
				AccountStorage.layout().partyANonces[partyA],
				liquidationSig.upnl,
				liquidationSig.totalUnrealizedLoss,
				liquidationSig.symbolIds,
				liquidationSig.prices,
				liquidationSig.timestamp,
				liquidationSig.liquidationBlockNumber,
				liquidationSig.liquidationTimestamp,
				liquidationSig.liquidationAllocatedBalance,
				getChainId()
			)
		);
		verifyTSSAndGateway(hash, liquidationSig.sigs, liquidationSig.gatewaySignature);
	}

	function verifyQuotePrices(QuotePriceSig memory priceSig) internal view {
		MuonStorage.Layout storage muonLayout = MuonStorage.layout();
		require(priceSig.prices.length == priceSig.quoteIds.length, "LibMuon: Invalid length");
		bytes32 hash = keccak256(
			abi.encodePacked(
				muonLayout.muonAppId,
				priceSig.reqId,
				address(this),
				priceSig.quoteIds,
				priceSig.prices,
				priceSig.timestamp,
				getChainId()
			)
		);
		verifyTSSAndGateway(hash, priceSig.sigs, priceSig.gatewaySignature);
	}

	function verifyPartyAUpnl(SingleUpnlSig memory upnlSig, address partyA) internal view {
		MuonStorage.Layout storage muonLayout = MuonStorage.layout();
		// == SignatureCheck( ==
		require(block.timestamp <= upnlSig.timestamp + muonLayout.upnlValidTime, "LibMuon: Expired signature");
		// == ) ==
		bytes32 hash = keccak256(
			abi.encodePacked(
				muonLayout.muonAppId,
				upnlSig.reqId,
				address(this),
				partyA,
				AccountStorage.layout().partyANonces[partyA],
				upnlSig.upnl,
				upnlSig.timestamp,
				getChainId()
			)
		);
		verifyTSSAndGateway(hash, upnlSig.sigs, upnlSig.gatewaySignature);
	}

	function verifyPartyAUpnlAndPrice(SingleUpnlAndPriceSig memory upnlSig, address partyA, uint256 symbolId) internal view {
		MuonStorage.Layout storage muonLayout = MuonStorage.layout();
		// == SignatureCheck( ==
		require(block.timestamp <= upnlSig.timestamp + muonLayout.upnlValidTime, "LibMuon: Expired signature");
		// == ) ==
		bytes32 hash = keccak256(
			abi.encodePacked(
				muonLayout.muonAppId,
				upnlSig.reqId,
				address(this),
				partyA,
				AccountStorage.layout().partyANonces[partyA],
				upnlSig.upnl,
				symbolId,
				upnlSig.price,
				upnlSig.timestamp,
				getChainId()
			)
		);
		verifyTSSAndGateway(hash, upnlSig.sigs, upnlSig.gatewaySignature);
	}

	function verifyPartyBUpnl(SingleUpnlSig memory upnlSig, address partyB, address partyA) internal view {
		MuonStorage.Layout storage muonLayout = MuonStorage.layout();
		// == SignatureCheck( ==
		require(block.timestamp <= upnlSig.timestamp + muonLayout.upnlValidTime, "LibMuon: Expired signature");
		// == ) ==
		bytes32 hash = keccak256(
			abi.encodePacked(
				muonLayout.muonAppId,
				upnlSig.reqId,
				address(this),
				partyB,
				partyA,
				AccountStorage.layout().partyBNonces[partyB][partyA],
				upnlSig.upnl,
				upnlSig.timestamp,
				getChainId()
			)
		);
		verifyTSSAndGateway(hash, upnlSig.sigs, upnlSig.gatewaySignature);
	}

	function verifyPairUpnlAndPrice(PairUpnlAndPriceSig memory upnlSig, address partyB, address partyA, uint256 symbolId) internal view {
		MuonStorage.Layout storage muonLayout = MuonStorage.layout();
		// == SignatureCheck( ==
		require(block.timestamp <= upnlSig.timestamp + muonLayout.upnlValidTime, "LibMuon: Expired signature");
		// == ) ==
		bytes32 hash = keccak256(
			abi.encodePacked(
				muonLayout.muonAppId,
				upnlSig.reqId,
				address(this),
				partyB,
				partyA,
				AccountStorage.layout().partyBNonces[partyB][partyA],
				AccountStorage.layout().partyANonces[partyA],
				upnlSig.upnlPartyB,
				upnlSig.upnlPartyA,
				symbolId,
				upnlSig.price,
				upnlSig.timestamp,
				getChainId()
			)
		);
		verifyTSSAndGateway(hash, upnlSig.sigs, upnlSig.gatewaySignature);
	}

	function verifyPairUpnl(PairUpnlSig memory upnlSig, address partyB, address partyA) internal view {
		MuonStorage.Layout storage muonLayout = MuonStorage.layout();
		// == SignatureCheck( ==
		require(block.timestamp <= upnlSig.timestamp + muonLayout.upnlValidTime, "LibMuon: Expired signature");
		// == ) ==
		bytes32 hash = keccak256(
			abi.encodePacked(
				muonLayout.muonAppId,
				upnlSig.reqId,
				address(this),
				partyB,
				partyA,
				AccountStorage.layout().partyBNonces[partyB][partyA],
				AccountStorage.layout().partyANonces[partyA],
				upnlSig.upnlPartyB,
				upnlSig.upnlPartyA,
				upnlSig.timestamp,
				getChainId()
			)
		);
		verifyTSSAndGateway(hash, upnlSig.sigs, upnlSig.gatewaySignature);
	}

	function verifyHighLowPrice(HighLowPriceSig memory sig, address partyB, address partyA, uint256 symbolId) internal view {
		MuonStorage.Layout storage muonLayout = MuonStorage.layout();
		// == SignatureCheck( ==
		require(block.timestamp <= sig.timestamp + muonLayout.upnlValidTime, "LibMuon: Expired signature");
		// == ) ==
		bytes32 hash = keccak256(
			abi.encodePacked(
				muonLayout.muonAppId,
				sig.reqId,
				address(this),
				partyB,
				partyA,
				AccountStorage.layout().partyBNonces[partyB][partyA],
				AccountStorage.layout().partyANonces[partyA],
				sig.upnlPartyB,
				sig.upnlPartyA,
				symbolId,
				sig.currentPrice,
				sig.startTime,
				sig.endTime,
				sig.lowest,
				sig.highest,
				sig.averagePrice,
				sig.timestamp,
				getChainId()
			)
		);
		verifyTSSAndGateway(hash, sig.sigs, sig.gatewaySignature);
	}
}

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.18;

import "../storages/MuonStorage.sol";

library LibMuonV04ClientBase {
    // See https://en.bitcoin.it/wiki/Secp256k1 for this constant.
    uint256 constant public Q = // Group order of secp256k1
    // solium-disable-next-line indentation
    0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141;
    // solium-disable-next-line zeppelin/no-arithmetic-operations
    uint256 constant public HALF_Q = (Q >> 1) + 1;

    /** **************************************************************************
@notice verifySignature returns true iff passed a valid Schnorr signature.

      @dev See https://en.wikipedia.org/wiki/Schnorr_signature for reference.

      @dev In what follows, let d be your secret key, PK be your public key,
      PKx be the x ordinate of your public key, and PKyp be the parity bit for
      the y ordinate (i.e., 0 if PKy is even, 1 if odd.)
      **************************************************************************
      @dev TO CREATE A VALID SIGNATURE FOR THIS METHOD

      @dev First PKx must be less than HALF_Q. Then follow these instructions
           (see evm/test/schnorr_test.js, for an example of carrying them out):
      @dev 1. Hash the target message to a uint256, called msgHash here, using
              keccak256

      @dev 2. Pick k uniformly and cryptographically securely randomly from
              {0,...,Q-1}. It is critical that k remains confidential, as your
              private key can be reconstructed from k and the signature.

      @dev 3. Compute k*g in the secp256k1 group, where g is the group
              generator. (This is the same as computing the public key from the
              secret key k. But it's OK if k*g's x ordinate is greater than
              HALF_Q.)

      @dev 4. Compute the ethereum address for k*g. This is the lower 160 bits
              of the keccak hash of the concatenated affine coordinates of k*g,
              as 32-byte big-endians. (For instance, you could pass k to
              ethereumjs-utils's privateToAddress to compute this, though that
              should be strictly a development convenience, not for handling
              live secrets, unless you've locked your javascript environment
              down very carefully.) Call this address
              nonceTimesGeneratorAddress.

      @dev 5. Compute e=uint256(keccak256(PKx as a 32-byte big-endian
                                        ‖ PKyp as a single byte
                                        ‖ msgHash
                                        ‖ nonceTimesGeneratorAddress))
              This value e is called "msgChallenge" in verifySignature's source
              code below. Here "‖" means concatenation of the listed byte
              arrays.

      @dev 6. Let x be your secret key. Compute s = (k - d * e) % Q. Add Q to
              it, if it's negative. This is your signature. (d is your secret
              key.)
      **************************************************************************
      @dev TO VERIFY A SIGNATURE

      @dev Given a signature (s, e) of msgHash, constructed as above, compute
      S=e*PK+s*generator in the secp256k1 group law, and then the ethereum
      address of S, as described in step 4. Call that
      nonceTimesGeneratorAddress. Then call the verifySignature method as:

      @dev    verifySignature(PKx, PKyp, s, msgHash,
                              nonceTimesGeneratorAddress)
      **************************************************************************
      @dev This signging scheme deviates slightly from the classical Schnorr
      signature, in that the address of k*g is used in place of k*g itself,
      both when calculating e and when verifying sum S as described in the
      verification paragraph above. This reduces the difficulty of
      brute-forcing a signature by trying random secp256k1 points in place of
      k*g in the signature verification process from 256 bits to 160 bits.
      However, the difficulty of cracking the public key using "baby-step,
      giant-step" is only 128 bits, so this weakening constitutes no compromise
      in the security of the signatures or the key.

      @dev The constraint signingPubKeyX < HALF_Q comes from Eq. (281), p. 24
      of Yellow Paper version 78d7b9a. ecrecover only accepts "s" inputs less
      than HALF_Q, to protect against a signature- malleability vulnerability in
      ECDSA. Schnorr does not have this vulnerability, but we must account for
      ecrecover's defense anyway. And since we are abusing ecrecover by putting
      signingPubKeyX in ecrecover's "s" argument the constraint applies to
      signingPubKeyX, even though it represents a value in the base field, and
      has no natural relationship to the order of the curve's cyclic group.
      **************************************************************************
      @param signingPubKeyX is the x ordinate of the public key. This must be
             less than HALF_Q.
      @param pubKeyYParity is 0 if the y ordinate of the public key is even, 1
             if it's odd.
      @param signature is the actual signature, described as s in the above
             instructions.
      @param msgHash is a 256-bit hash of the message being signed.
      @param nonceTimesGeneratorAddress is the ethereum address of k*g in the
             above instructions
      **************************************************************************
      @return True if passed a valid signature, false otherwise. */
    function verifySignature(
        uint256 signingPubKeyX,
        uint8 pubKeyYParity,
        uint256 signature,
        uint256 msgHash,
        address nonceTimesGeneratorAddress) public pure returns (bool) {
        require(signingPubKeyX < HALF_Q, "Public-key x >= HALF_Q");
        // Avoid signature malleability from multiple representations for ℤ/Qℤ elts
        require(signature < Q, "signature must be reduced modulo Q");

        // Forbid trivial inputs, to avoid ecrecover edge cases. The main thing to
        // avoid is something which causes ecrecover to return 0x0: then trivial
        // signatures could be constructed with the nonceTimesGeneratorAddress input
        // set to 0x0.
        //
        // solium-disable-next-line indentation
        require(nonceTimesGeneratorAddress != address(0) && signingPubKeyX > 0 &&
        signature > 0 && msgHash > 0, "no zero inputs allowed");

        // solium-disable-next-line indentation
        uint256 msgChallenge = // "e"
        // solium-disable-next-line indentation
                            uint256(keccak256(abi.encodePacked(signingPubKeyX, pubKeyYParity,
                msgHash, nonceTimesGeneratorAddress))
            );

        // Verify msgChallenge * signingPubKey + signature * generator ==
        //        nonce * generator
        //
        // https://ethresear.ch/t/you-can-kinda-abuse-ecrecover-to-do-ecmul-in-secp256k1-today/2384/9
        // The point corresponding to the address returned by
        // ecrecover(-s*r,v,r,e*r) is (r⁻¹ mod Q)*(e*r*R-(-s)*r*g)=e*R+s*g, where R
        // is the (v,r) point. See https://crypto.stackexchange.com/a/18106
        //
        // solium-disable-next-line indentation
        address recoveredAddress = ecrecover(
        // solium-disable-next-line zeppelin/no-arithmetic-operations
            bytes32(Q - mulmod(signingPubKeyX, signature, Q)),
            // https://ethereum.github.io/yellowpaper/paper.pdf p. 24, "The
            // value 27 represents an even y value and 28 represents an odd
            // y value."
            (pubKeyYParity == 0) ? 27 : 28,
            bytes32(signingPubKeyX),
            bytes32(mulmod(msgChallenge, signingPubKeyX, Q)));
        return nonceTimesGeneratorAddress == recoveredAddress;
    }

    function validatePubKey(uint256 signingPubKeyX) public pure {
        require(signingPubKeyX < HALF_Q, "Public-key x >= HALF_Q");
    }

    function muonVerify(
        uint256 hash,
        SchnorrSign memory signature,
        PublicKey memory pubKey
    ) internal pure returns (bool) {
        if (!verifySignature(pubKey.x, pubKey.parity,
            signature.signature,
            hash, signature.nonce)) {
            return false;
        }
        return true;
    }
}

// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "./LibLockedValues.sol";
import "../libraries/SharedEvents.sol";
import "../storages/QuoteStorage.sol";
import "../storages/AccountStorage.sol";
import "../storages/GlobalAppStorage.sol";
import "../storages/SymbolStorage.sol";
import "../storages/MAStorage.sol";

library LibQuote {
	using LockedValuesOps for LockedValues;

	/**
	 * @notice Calculates the remaining open amount of a quote.
	 * @param quote The quote for which to calculate the remaining open amount.
	 * @return The remaining open amount of the quote.
	 */
	function quoteOpenAmount(Quote storage quote) internal view returns (uint256) {
		return quote.quantity - quote.closedAmount;
	}

	/**
	 * @notice Gets the index of an item in an array.
	 * @param array_ The array in which to search for the item.
	 * @param item The item to find the index of.
	 * @return The index of the item in the array, or type(uint256).max if the item is not found.
	 */
	function getIndexOfItem(uint256[] storage array_, uint256 item) internal view returns (uint256) {
		for (uint256 index = 0; index < array_.length; index++) {
			if (array_[index] == item) return index;
		}
		return type(uint256).max;
	}

	/**
	 * @notice Removes an item from an array.
	 * @param array_ The array from which to remove the item.
	 * @param item The item to remove from the array.
	 */
	function removeFromArray(uint256[] storage array_, uint256 item) internal {
		uint256 index = getIndexOfItem(array_, item);
		require(index != type(uint256).max, "LibQuote: Item not Found");
		array_[index] = array_[array_.length - 1];
		array_.pop();
	}

	/**
	 * @notice Removes a quote from the pending quotes of Party A.
	 * @param quote The quote to remove from the pending quotes.
	 */
	function removeFromPartyAPendingQuotes(Quote storage quote) internal {
		removeFromArray(QuoteStorage.layout().partyAPendingQuotes[quote.partyA], quote.id);
	}

	/**
	 * @notice Removes a quote from the pending quotes of Party B.
	 * @param quote The quote to remove from the pending quotes.
	 */
	function removeFromPartyBPendingQuotes(Quote storage quote) internal {
		removeFromArray(QuoteStorage.layout().partyBPendingQuotes[quote.partyB][quote.partyA], quote.id);
	}

	/**
	 * @notice Removes a quote from both Party A's and Party B's pending quotes.
	 * @param quote The quote to remove from the pending quotes.
	 */
	function removeFromPendingQuotes(Quote storage quote) internal {
		removeFromPartyAPendingQuotes(quote);
		removeFromPartyBPendingQuotes(quote);
	}

	/**
	 * @notice Adds a quote to the open positions.
	 * @param quoteId The ID of the quote to add to the open positions.
	 */
	function addToOpenPositions(uint256 quoteId) internal {
		QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
		Quote storage quote = quoteLayout.quotes[quoteId];

		quoteLayout.partyAOpenPositions[quote.partyA].push(quote.id);
		quoteLayout.partyBOpenPositions[quote.partyB][quote.partyA].push(quote.id);

		quoteLayout.partyAPositionsIndex[quote.id] = quoteLayout.partyAPositionsCount[quote.partyA];
		quoteLayout.partyBPositionsIndex[quote.id] = quoteLayout.partyBPositionsCount[quote.partyB][quote.partyA];

		quoteLayout.partyAPositionsCount[quote.partyA] += 1;
		quoteLayout.partyBPositionsCount[quote.partyB][quote.partyA] += 1;
	}

	/**
	 * @notice Removes a quote from the open positions.
	 * @param quoteId The ID of the quote to remove from the open positions.
	 */
	function removeFromOpenPositions(uint256 quoteId) internal {
		QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
		Quote storage quote = quoteLayout.quotes[quoteId];
		uint256 indexOfPartyAPosition = quoteLayout.partyAPositionsIndex[quote.id];
		uint256 indexOfPartyBPosition = quoteLayout.partyBPositionsIndex[quote.id];
		uint256 lastOpenPositionIndex = quoteLayout.partyAPositionsCount[quote.partyA] - 1;
		quoteLayout.partyAOpenPositions[quote.partyA][indexOfPartyAPosition] = quoteLayout.partyAOpenPositions[quote.partyA][lastOpenPositionIndex];
		quoteLayout.partyAPositionsIndex[quoteLayout.partyAOpenPositions[quote.partyA][lastOpenPositionIndex]] = indexOfPartyAPosition;
		quoteLayout.partyAOpenPositions[quote.partyA].pop();

		lastOpenPositionIndex = quoteLayout.partyBPositionsCount[quote.partyB][quote.partyA] - 1;
		quoteLayout.partyBOpenPositions[quote.partyB][quote.partyA][indexOfPartyBPosition] = quoteLayout.partyBOpenPositions[quote.partyB][
			quote.partyA
		][lastOpenPositionIndex];
		quoteLayout.partyBPositionsIndex[quoteLayout.partyBOpenPositions[quote.partyB][quote.partyA][lastOpenPositionIndex]] = indexOfPartyBPosition;
		quoteLayout.partyBOpenPositions[quote.partyB][quote.partyA].pop();

		quoteLayout.partyAPositionsIndex[quote.id] = 0;
		quoteLayout.partyBPositionsIndex[quote.id] = 0;
	}

	/**
	 * @notice Calculates the value of a quote for Party A based on the current price and filled amount.
	 * @param currentPrice The current price of the quote.
	 * @param filledAmount The filled amount of the quote.
	 * @param quote The quote for which to calculate the value.
	 * @return hasMadeProfit A boolean indicating whether Party A has made a profit.
	 * @return pnl The profit or loss value for Party A.
	 */
	function getValueOfQuoteForPartyA(
		uint256 currentPrice,
		uint256 filledAmount,
		Quote storage quote
	) internal view returns (bool hasMadeProfit, uint256 pnl) {
		if (currentPrice > quote.openedPrice) {
			if (quote.positionType == PositionType.LONG) {
				hasMadeProfit = true;
			} else {
				hasMadeProfit = false;
			}
			pnl = ((currentPrice - quote.openedPrice) * filledAmount) / 1e18;
		} else {
			if (quote.positionType == PositionType.LONG) {
				hasMadeProfit = false;
			} else {
				hasMadeProfit = true;
			}
			pnl = ((quote.openedPrice - currentPrice) * filledAmount) / 1e18;
		}
	}

	/**
	 * @notice Gets the trading fee for a quote.
	 * @param quoteId The ID of the quote for which to get the trading fee.
	 * @return fee The trading fee for the quote.
	 */
	function getTradingFee(uint256 quoteId) internal view returns (uint256 fee) {
		QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
		Quote storage quote = quoteLayout.quotes[quoteId];
		if (quote.orderType == OrderType.LIMIT) {
			fee = (LibQuote.quoteOpenAmount(quote) * quote.requestedOpenPrice * quote.tradingFee) / 1e36;
		} else {
			fee = (LibQuote.quoteOpenAmount(quote) * quote.marketPrice * quote.tradingFee) / 1e36;
		}
	}

	/**
	 * @notice Closes a quote.
	 * @param quote The quote to close.
	 * @param filledAmount The filled amount of the quote.
	 * @param closedPrice The price at which the quote is closed.
	 */
	function closeQuote(Quote storage quote, uint256 filledAmount, uint256 closedPrice) internal {
		QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
		AccountStorage.Layout storage accountLayout = AccountStorage.layout();
		SymbolStorage.Layout storage symbolLayout = SymbolStorage.layout();

		require(
			quote.lockedValues.cva == 0 || (quote.lockedValues.cva * filledAmount) / LibQuote.quoteOpenAmount(quote) > 0,
			"LibQuote: Low filled amount"
		);
		require(
			quote.lockedValues.partyAmm == 0 || (quote.lockedValues.partyAmm * filledAmount) / LibQuote.quoteOpenAmount(quote) > 0,
			"LibQuote: Low filled amount"
		);
		require(
			quote.lockedValues.partyBmm == 0 || (quote.lockedValues.partyBmm * filledAmount) / LibQuote.quoteOpenAmount(quote) > 0,
			"LibQuote: Low filled amount"
		);
		require((quote.lockedValues.lf * filledAmount) / LibQuote.quoteOpenAmount(quote) > 0, "LibQuote: Low filled amount");
		LockedValues memory lockedValues = LockedValues(
			quote.lockedValues.cva - ((quote.lockedValues.cva * filledAmount) / (LibQuote.quoteOpenAmount(quote))),
			quote.lockedValues.lf - ((quote.lockedValues.lf * filledAmount) / (LibQuote.quoteOpenAmount(quote))),
			quote.lockedValues.partyAmm - ((quote.lockedValues.partyAmm * filledAmount) / (LibQuote.quoteOpenAmount(quote))),
			quote.lockedValues.partyBmm - ((quote.lockedValues.partyBmm * filledAmount) / (LibQuote.quoteOpenAmount(quote)))
		);
		accountLayout.lockedBalances[quote.partyA].subQuote(quote).add(lockedValues);
		accountLayout.partyBLockedBalances[quote.partyB][quote.partyA].subQuote(quote).add(lockedValues);
		quote.lockedValues = lockedValues;

		if (LibQuote.quoteOpenAmount(quote) == quote.quantityToClose) {
			require(
				quote.lockedValues.totalForPartyA() == 0 ||
					quote.lockedValues.totalForPartyA() >= symbolLayout.symbols[quote.symbolId].minAcceptableQuoteValue,
				"LibQuote: Remaining quote value is low"
			);
		}

		(bool hasMadeProfit, uint256 pnl) = LibQuote.getValueOfQuoteForPartyA(closedPrice, filledAmount, quote);

		if (hasMadeProfit) {
			require(
				accountLayout.partyBAllocatedBalances[quote.partyB][quote.partyA] >= pnl,
				"LibQuote: PartyA should first exit its positions that are incurring losses"
			);
			accountLayout.allocatedBalances[quote.partyA] += pnl;
			emit SharedEvents.BalanceChangePartyA(quote.partyA, pnl, SharedEvents.BalanceChangeType.REALIZED_PNL_IN);
			accountLayout.partyBAllocatedBalances[quote.partyB][quote.partyA] -= pnl;
			emit SharedEvents.BalanceChangePartyB(quote.partyB, quote.partyA, pnl, SharedEvents.BalanceChangeType.REALIZED_PNL_OUT);
		} else {
			require(
				accountLayout.allocatedBalances[quote.partyA] >= pnl,
				"LibQuote: PartyA should first exit its positions that are currently in profit."
			);
			accountLayout.allocatedBalances[quote.partyA] -= pnl;
			emit SharedEvents.BalanceChangePartyA(quote.partyA, pnl, SharedEvents.BalanceChangeType.REALIZED_PNL_OUT);
			accountLayout.partyBAllocatedBalances[quote.partyB][quote.partyA] += pnl;
			emit SharedEvents.BalanceChangePartyB(quote.partyB, quote.partyA, pnl, SharedEvents.BalanceChangeType.REALIZED_PNL_IN);
		}

		quote.avgClosedPrice = (quote.avgClosedPrice * quote.closedAmount + filledAmount * closedPrice) / (quote.closedAmount + filledAmount);

		quote.closedAmount += filledAmount;
		quote.quantityToClose -= filledAmount;

		if (quote.closedAmount == quote.quantity) {
			quote.statusModifyTimestamp = block.timestamp;
			quote.quoteStatus = QuoteStatus.CLOSED;
			quote.requestedClosePrice = 0;
			removeFromOpenPositions(quote.id);
			quoteLayout.partyAPositionsCount[quote.partyA] -= 1;
			quoteLayout.partyBPositionsCount[quote.partyB][quote.partyA] -= 1;
		} else if (quote.quoteStatus == QuoteStatus.CANCEL_CLOSE_PENDING || quote.quantityToClose == 0) {
			quote.quoteStatus = QuoteStatus.OPENED;
			quote.statusModifyTimestamp = block.timestamp;
			quote.requestedClosePrice = 0;
			quote.quantityToClose = 0; // for CANCEL_CLOSE_PENDING status
		}
	}

	/**
	 * @notice Expires a quote.
	 * @param quoteId The ID of the quote to expire.
	 * @return result The resulting status of the quote after expiration.
	 */
	function expireQuote(uint256 quoteId) internal returns (QuoteStatus result) {
		QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
		AccountStorage.Layout storage accountLayout = AccountStorage.layout();

		Quote storage quote = quoteLayout.quotes[quoteId];
		require(block.timestamp > quote.deadline, "LibQuote: Quote isn't expired");
		require(
			quote.quoteStatus == QuoteStatus.PENDING ||
				quote.quoteStatus == QuoteStatus.CANCEL_PENDING ||
				quote.quoteStatus == QuoteStatus.LOCKED ||
				quote.quoteStatus == QuoteStatus.CLOSE_PENDING ||
				quote.quoteStatus == QuoteStatus.CANCEL_CLOSE_PENDING,
			"LibQuote: Invalid state"
		);
		require(!MAStorage.layout().liquidationStatus[quote.partyA], "LibQuote: PartyA isn't solvent");
		require(!MAStorage.layout().partyBLiquidationStatus[quote.partyB][quote.partyA], "LibQuote: PartyB isn't solvent");
		if (quote.quoteStatus == QuoteStatus.PENDING || quote.quoteStatus == QuoteStatus.LOCKED || quote.quoteStatus == QuoteStatus.CANCEL_PENDING) {
			quote.statusModifyTimestamp = block.timestamp;
			accountLayout.pendingLockedBalances[quote.partyA].subQuote(quote);

			// send trading Fee back to partyA
			uint256 fee = LibQuote.getTradingFee(quote.id);
			accountLayout.allocatedBalances[quote.partyA] += fee;
			emit SharedEvents.BalanceChangePartyA(quote.partyA, fee, SharedEvents.BalanceChangeType.PLATFORM_FEE_IN);

			removeFromPartyAPendingQuotes(quote);
			if (quote.quoteStatus == QuoteStatus.LOCKED || quote.quoteStatus == QuoteStatus.CANCEL_PENDING) {
				accountLayout.partyBPendingLockedBalances[quote.partyB][quote.partyA].subQuote(quote);
				removeFromPartyBPendingQuotes(quote);
			}
			quote.quoteStatus = QuoteStatus.EXPIRED;
			result = QuoteStatus.EXPIRED;
		} else if (quote.quoteStatus == QuoteStatus.CLOSE_PENDING || quote.quoteStatus == QuoteStatus.CANCEL_CLOSE_PENDING) {
			quote.statusModifyTimestamp = block.timestamp;
			quote.requestedClosePrice = 0;
			quote.quantityToClose = 0;
			quote.quoteStatus = QuoteStatus.OPENED;
			result = QuoteStatus.OPENED;
		}
	}
}

File 19 of 27 : SharedEvents.sol
// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

library SharedEvents {

    enum BalanceChangeType {
        ALLOCATE,
        DEALLOCATE,
        PLATFORM_FEE_IN,
        PLATFORM_FEE_OUT,
        REALIZED_PNL_IN,
        REALIZED_PNL_OUT,
        CVA_IN,
        CVA_OUT,
        LF_IN,
        LF_OUT
    }

    event BalanceChangePartyA(address indexed partyA, uint256 amount, BalanceChangeType _type);

    event BalanceChangePartyB(address indexed partyB, address indexed partyA, uint256 amount, BalanceChangeType _type);
}

File 20 of 27 : AccountStorage.sol
// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "../libraries/LibLockedValues.sol";

enum LiquidationType {
	NONE,
	NORMAL,
	LATE,
	OVERDUE
}

struct SettlementState {
	int256 actualAmount;
	int256 expectedAmount;
	uint256 cva;
	bool pending;
}

struct LiquidationDetail {
	bytes liquidationId;
	LiquidationType liquidationType;
	int256 upnl;
	int256 totalUnrealizedLoss;
	uint256 deficit;
	uint256 liquidationFee;
	uint256 timestamp;
	uint256 involvedPartyBCounts;
	int256 partyAAccumulatedUpnl;
	bool disputed;
	uint256 liquidationTimestamp;
}

struct Price {
	uint256 price;
	uint256 timestamp;
}

library AccountStorage {
	bytes32 internal constant ACCOUNT_STORAGE_SLOT = keccak256("diamond.standard.storage.account");

	struct Layout {
		// Users deposited amounts
		mapping(address => uint256) balances;
		mapping(address => uint256) allocatedBalances;
		// position value will become pending locked before openPosition and will be locked after that
		mapping(address => LockedValues) pendingLockedBalances;
		mapping(address => LockedValues) lockedBalances;
		mapping(address => mapping(address => uint256)) partyBAllocatedBalances;
		mapping(address => mapping(address => LockedValues)) partyBPendingLockedBalances;
		mapping(address => mapping(address => LockedValues)) partyBLockedBalances;
		mapping(address => uint256) withdrawCooldown; // is better to call lastDeallocateTime
		mapping(address => uint256) partyANonces;
		mapping(address => mapping(address => uint256)) partyBNonces;
		mapping(address => bool) suspendedAddresses;
		mapping(address => LiquidationDetail) liquidationDetails;
		mapping(address => mapping(uint256 => Price)) symbolsPrices;
		mapping(address => address[]) liquidators;
		mapping(address => uint256) partyAReimbursement;
		// partyA => partyB => SettlementState
		mapping(address => mapping(address => SettlementState)) settlementStates;
	}

	function layout() internal pure returns (Layout storage l) {
		bytes32 slot = ACCOUNT_STORAGE_SLOT;
		assembly {
			l.slot := slot
		}
	}
}

File 21 of 27 : GlobalAppStorage.sol
// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "../libraries/LibLockedValues.sol";

library GlobalAppStorage {
	bytes32 internal constant GLOBAL_APP_STORAGE_SLOT = keccak256("diamond.standard.storage.global");

	struct Layout {
		address collateral;
		address defaultFeeCollector;
		bool globalPaused;
		bool liquidationPaused;
		bool accountingPaused;
		bool partyBActionsPaused;
		bool partyAActionsPaused;
		bool emergencyMode;
		uint256 balanceLimitPerUser;
		mapping(address => bool) partyBEmergencyStatus;
		mapping(address => mapping(bytes32 => bool)) hasRole;
		bool internalTransferPaused;
		mapping(address => address) affiliateFeeCollector;
	}

	function layout() internal pure returns (Layout storage l) {
		bytes32 slot = GLOBAL_APP_STORAGE_SLOT;
		assembly {
			l.slot := slot
		}
	}
}

File 22 of 27 : MAStorage.sol
// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "../libraries/LibLockedValues.sol";

library MAStorage {
	bytes32 internal constant MA_STORAGE_SLOT = keccak256("diamond.standard.storage.masteragreement");

	struct Layout {
		uint256 deallocateCooldown;
		uint256 forceCancelCooldown;
		uint256 forceCancelCloseCooldown;
		uint256 forceCloseFirstCooldown;
		uint256 liquidationTimeout;
		uint256 liquidatorShare; // in 18 decimals
		uint256 pendingQuotesValidLength;
		uint256 deprecatedForceCloseGapRatio; // DEPRECATED
		mapping(address => bool) partyBStatus;
		mapping(address => bool) liquidationStatus;
		mapping(address => mapping(address => bool)) partyBLiquidationStatus;
		mapping(address => mapping(address => uint256)) partyBLiquidationTimestamp;
		mapping(address => mapping(address => uint256)) partyBPositionLiquidatorsShare;
		address[] partyBList;
		uint256 forceCloseSecondCooldown;
		uint256 forceClosePricePenalty;
		uint256 forceCloseMinSigPeriod;
		uint256 deallocateDebounceTime;
		mapping(address => bool) affiliateStatus;
	}

	function layout() internal pure returns (Layout storage l) {
		bytes32 slot = MA_STORAGE_SLOT;
		assembly {
			l.slot := slot
		}
	}
}

File 23 of 27 : MuonStorage.sol
// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "../libraries/LibLockedValues.sol";

struct SchnorrSign {
	uint256 signature;
	address owner;
	address nonce;
}

struct PublicKey {
	uint256 x;
	uint8 parity;
}

struct SingleUpnlSig {
	bytes reqId;
	uint256 timestamp;
	int256 upnl;
	bytes gatewaySignature;
	SchnorrSign sigs;
}

struct SingleUpnlAndPriceSig {
	bytes reqId;
	uint256 timestamp;
	int256 upnl;
	uint256 price;
	bytes gatewaySignature;
	SchnorrSign sigs;
}

struct PairUpnlSig {
	bytes reqId;
	uint256 timestamp;
	int256 upnlPartyA;
	int256 upnlPartyB;
	bytes gatewaySignature;
	SchnorrSign sigs;
}

struct PairUpnlAndPriceSig {
	bytes reqId;
	uint256 timestamp;
	int256 upnlPartyA;
	int256 upnlPartyB;
	uint256 price;
	bytes gatewaySignature;
	SchnorrSign sigs;
}

struct DeferredLiquidationSig {
	bytes reqId; // Unique identifier for the liquidation request
	uint256 timestamp; // Timestamp when the liquidation signature was created
	uint256 liquidationBlockNumber; // Block number at which the user became insolvent
	uint256 liquidationTimestamp; // Timestamp when the user became insolvent
	uint256 liquidationAllocatedBalance; // User's allocated balance at the time of insolvency
	bytes liquidationId; // Unique identifier for the liquidation event
	int256 upnl; // User's unrealized profit and loss at the time of insolvency
	int256 totalUnrealizedLoss; // Total unrealized loss of the user at the time of insolvency
	uint256[] symbolIds; // List of symbol IDs involved in the liquidation
	uint256[] prices; // Corresponding prices of the symbols involved in the liquidation
	bytes gatewaySignature; // Signature from the gateway for verification
	SchnorrSign sigs; // Schnorr signature for additional verification
}

struct LiquidationSig {
	bytes reqId; // Unique identifier for the liquidation request
	uint256 timestamp; // Timestamp when the liquidation signature was created
	bytes liquidationId; // Unique identifier for the liquidation event
	int256 upnl; // User's unrealized profit and loss at the time of insolvency
	int256 totalUnrealizedLoss; // Total unrealized loss of the user at the time of insolvency
	uint256[] symbolIds; // List of symbol IDs involved in the liquidation
	uint256[] prices; // Corresponding prices of the symbols involved in the liquidation
	bytes gatewaySignature; // Signature from the gateway for verification
	SchnorrSign sigs; // Schnorr signature for additional verification
}

struct QuotePriceSig {
	bytes reqId;
	uint256 timestamp;
	uint256[] quoteIds;
	uint256[] prices;
	bytes gatewaySignature;
	SchnorrSign sigs;
}

struct HighLowPriceSig {
	bytes reqId;
	uint256 timestamp;
	uint256 symbolId;
	uint256 highest;
	uint256 lowest;
	uint256 averagePrice;
	uint256 startTime;
	uint256 endTime;
	int256 upnlPartyB;
	int256 upnlPartyA;
	uint256 currentPrice;
	bytes gatewaySignature;
	SchnorrSign sigs;
}

library MuonStorage {
	bytes32 internal constant MUON_STORAGE_SLOT = keccak256("diamond.standard.storage.muon");

	struct Layout {
		uint256 upnlValidTime;
		uint256 priceValidTime;
		uint256 priceQuantityValidTime; // UNUSED: Should be deleted later
		uint256 muonAppId;
		PublicKey muonPublicKey;
		address validGateway;
	}

	function layout() internal pure returns (Layout storage l) {
		bytes32 slot = MUON_STORAGE_SLOT;
		assembly {
			l.slot := slot
		}
	}
}

File 24 of 27 : QuoteStorage.sol
// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "../libraries/LibLockedValues.sol";

enum PositionType {
	LONG,
	SHORT
}

enum OrderType {
	LIMIT,
	MARKET
}

enum QuoteStatus {
	PENDING, //0
	LOCKED, //1
	CANCEL_PENDING, //2
	CANCELED, //3
	OPENED, //4
	CLOSE_PENDING, //5
	CANCEL_CLOSE_PENDING, //6
	CLOSED, //7
	LIQUIDATED, //8
	EXPIRED, //9
	LIQUIDATED_PENDING //10
}

struct Quote {
	uint256 id;
	address[] partyBsWhiteList;
	uint256 symbolId;
	PositionType positionType;
	OrderType orderType;
	// Price of quote which PartyB opened in 18 decimals
	uint256 openedPrice;
	uint256 initialOpenedPrice;
	// Price of quote which PartyA requested in 18 decimals
	uint256 requestedOpenPrice;
	uint256 marketPrice;
	// Quantity of quote which PartyA requested in 18 decimals
	uint256 quantity;
	// Quantity of quote which PartyB has closed until now in 18 decimals
	uint256 closedAmount;
	LockedValues initialLockedValues;
	LockedValues lockedValues;
	uint256 maxFundingRate;
	address partyA;
	address partyB;
	QuoteStatus quoteStatus;
	uint256 avgClosedPrice;
	uint256 requestedClosePrice;
	uint256 quantityToClose;
	// handle partially open position
	uint256 parentId;
	uint256 createTimestamp;
	uint256 statusModifyTimestamp;
	uint256 lastFundingPaymentTimestamp;
	uint256 deadline;
	uint256 tradingFee;
	address affiliate;
}

library QuoteStorage {
	bytes32 internal constant QUOTE_STORAGE_SLOT = keccak256("diamond.standard.storage.quote");

	struct Layout {
		mapping(address => uint256[]) quoteIdsOf;
		mapping(uint256 => Quote) quotes;
		mapping(address => uint256) partyAPositionsCount;
		mapping(address => mapping(address => uint256)) partyBPositionsCount;
		mapping(address => uint256[]) partyAPendingQuotes;
		mapping(address => mapping(address => uint256[])) partyBPendingQuotes;
		mapping(address => uint256[]) partyAOpenPositions;
		mapping(uint256 => uint256) partyAPositionsIndex;
		mapping(address => mapping(address => uint256[])) partyBOpenPositions;
		mapping(uint256 => uint256) partyBPositionsIndex;
		uint256 lastId;
		uint256 lastCloseId;
		mapping(uint256 => uint256) closeIds;
	}

	function layout() internal pure returns (Layout storage l) {
		bytes32 slot = QUOTE_STORAGE_SLOT;
		assembly {
			l.slot := slot
		}
	}
}

File 25 of 27 : SymbolStorage.sol
// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

struct Symbol {
	uint256 symbolId;
	string name;
	bool isValid;
	uint256 minAcceptableQuoteValue;
	uint256 minAcceptablePortionLF;
	uint256 tradingFee;
	uint256 maxLeverage;
	uint256 fundingRateEpochDuration;
	uint256 fundingRateWindowTime;
}

library SymbolStorage {
	bytes32 internal constant SYMBOL_STORAGE_SLOT = keccak256("diamond.standard.storage.symbol");

	struct Layout {
		mapping(uint256 => Symbol) symbols;
		uint256 lastId;
		mapping(uint256 => uint256) forceCloseGapRatio; //symbolId -> forceCloseGapRatio
	}

	function layout() internal pure returns (Layout storage l) {
		bytes32 slot = SYMBOL_STORAGE_SLOT;
		assembly {
			l.slot := slot
		}
	}
}

File 26 of 27 : Accessibility.sol
// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "../storages/MAStorage.sol";
import "../storages/AccountStorage.sol";
import "../storages/QuoteStorage.sol";
import "../libraries/LibAccessibility.sol";

abstract contract Accessibility {
	modifier onlyPartyB() {
		require(MAStorage.layout().partyBStatus[msg.sender], "Accessibility: Should be partyB");
		_;
	}

	modifier notPartyB() {
		require(!MAStorage.layout().partyBStatus[msg.sender], "Accessibility: Shouldn't be partyB");
		_;
	}

	modifier userNotPartyB(address user) {
		require(!MAStorage.layout().partyBStatus[user], "Accessibility: Shouldn't be partyB");
		_;
	}

	modifier onlyRole(bytes32 role) {
		require(LibAccessibility.hasRole(msg.sender, role), "Accessibility: Must has role");
		_;
	}

	modifier notLiquidatedPartyA(address partyA) {
		require(!MAStorage.layout().liquidationStatus[partyA], "Accessibility: PartyA isn't solvent");
		_;
	}

	modifier notLiquidatedPartyB(address partyB, address partyA) {
		require(!MAStorage.layout().partyBLiquidationStatus[partyB][partyA], "Accessibility: PartyB isn't solvent");
		_;
	}

	modifier notLiquidated(uint256 quoteId) {
		Quote storage quote = QuoteStorage.layout().quotes[quoteId];
		require(!MAStorage.layout().liquidationStatus[quote.partyA], "Accessibility: PartyA isn't solvent");
		require(!MAStorage.layout().partyBLiquidationStatus[quote.partyB][quote.partyA], "Accessibility: PartyB isn't solvent");
		require(quote.quoteStatus != QuoteStatus.LIQUIDATED && quote.quoteStatus != QuoteStatus.CLOSED, "Accessibility: Invalid state");
		_;
	}

	modifier onlyPartyAOfQuote(uint256 quoteId) {
		Quote storage quote = QuoteStorage.layout().quotes[quoteId];
		require(quote.partyA == msg.sender, "Accessibility: Should be partyA of quote");
		_;
	}

	modifier onlyPartyBOfQuote(uint256 quoteId) {
		Quote storage quote = QuoteStorage.layout().quotes[quoteId];
		require(quote.partyB == msg.sender, "Accessibility: Should be partyB of quote");
		_;
	}

	modifier notSuspended(address user) {
		require(!AccountStorage.layout().suspendedAddresses[user], "Accessibility: Sender is Suspended");
		_;
	}
}

File 27 of 27 : Pausable.sol
// SPDX-License-Identifier: SYMM-Core-Business-Source-License-1.1
// This contract is licensed under the SYMM Core Business Source License 1.1
// Copyright (c) 2023 Symmetry Labs AG
// For more information, see https://docs.symm.io/legal-disclaimer/license
pragma solidity >=0.8.18;

import "../storages/GlobalAppStorage.sol";

abstract contract Pausable {
	modifier whenNotGlobalPaused() {
		require(!GlobalAppStorage.layout().globalPaused, "Pausable: Global paused");
		_;
	}

	modifier whenNotLiquidationPaused() {
		require(!GlobalAppStorage.layout().globalPaused, "Pausable: Global paused");
		require(!GlobalAppStorage.layout().liquidationPaused, "Pausable: Liquidation paused");
		_;
	}

	modifier whenNotAccountingPaused() {
		require(!GlobalAppStorage.layout().globalPaused, "Pausable: Global paused");
		require(!GlobalAppStorage.layout().accountingPaused, "Pausable: Accounting paused");
		_;
	}

	modifier whenNotPartyAActionsPaused() {
		require(!GlobalAppStorage.layout().globalPaused, "Pausable: Global paused");
		require(!GlobalAppStorage.layout().partyAActionsPaused, "Pausable: PartyA actions paused");
		_;
	}

	modifier whenNotPartyBActionsPaused() {
		require(!GlobalAppStorage.layout().globalPaused, "Pausable: Global paused");
		require(!GlobalAppStorage.layout().partyBActionsPaused, "Pausable: PartyB actions paused");
		_;
	}

	modifier whenNotInternalTransferPaused() {
		require(!GlobalAppStorage.layout().internalTransferPaused, "Pausable: Internal transfer paused");
		require(!GlobalAppStorage.layout().accountingPaused, "Pausable: Accounting paused");
		_;
	}
}

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

Contract Security Audit

Contract ABI

API
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"uint256","name":"allocatedBalance","type":"uint256"},{"indexed":false,"internalType":"int256","name":"upnl","type":"int256"},{"indexed":false,"internalType":"int256","name":"totalUnrealizedLoss","type":"int256"},{"indexed":false,"internalType":"bytes","name":"liquidationId","type":"bytes"},{"indexed":false,"internalType":"uint256","name":"liquidationBlockNumber","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"liquidationTimestamp","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"liquidationAllocatedBalance","type":"uint256"}],"name":"DeferredLiquidatePartyA","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"bytes","name":"liquidationId","type":"bytes"}],"name":"DisputeForLiquidation","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum QuoteStatus","name":"quoteStatus","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"quoteId","type":"uint256"}],"name":"ExpireQuote","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum QuoteStatus","name":"quoteStatus","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"quoteId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"closeId","type":"uint256"}],"name":"ExpireQuoteClose","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum QuoteStatus","name":"quoteStatus","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"quoteId","type":"uint256"}],"name":"ExpireQuoteOpen","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"bytes","name":"liquidationId","type":"bytes"}],"name":"FullyLiquidatedPartyA","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"partyA","type":"address"}],"name":"FullyLiquidatedPartyA","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"partyB","type":"address"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"}],"name":"FullyLiquidatedPartyB","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"uint256","name":"allocatedBalance","type":"uint256"},{"indexed":false,"internalType":"int256","name":"upnl","type":"int256"},{"indexed":false,"internalType":"int256","name":"totalUnrealizedLoss","type":"int256"},{"indexed":false,"internalType":"bytes","name":"liquidationId","type":"bytes"}],"name":"LiquidatePartyA","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"uint256","name":"allocatedBalance","type":"uint256"},{"indexed":false,"internalType":"int256","name":"upnl","type":"int256"},{"indexed":false,"internalType":"int256","name":"totalUnrealizedLoss","type":"int256"}],"name":"LiquidatePartyA","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"partyB","type":"address"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"uint256","name":"partyBAllocatedBalance","type":"uint256"},{"indexed":false,"internalType":"int256","name":"upnl","type":"int256"}],"name":"LiquidatePartyB","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"quoteIds","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"liquidatedAmounts","type":"uint256[]"},{"indexed":false,"internalType":"bytes","name":"liquidationId","type":"bytes"}],"name":"LiquidatePendingPositionsPartyA","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"}],"name":"LiquidatePendingPositionsPartyA","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"quoteIds","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"liquidatedAmounts","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"closeIds","type":"uint256[]"},{"indexed":false,"internalType":"bytes","name":"liquidationId","type":"bytes"}],"name":"LiquidatePositionsPartyA","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"quoteIds","type":"uint256[]"}],"name":"LiquidatePositionsPartyA","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"partyB","type":"address"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"quoteIds","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"liquidatedAmounts","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"closeIds","type":"uint256[]"}],"name":"LiquidatePositionsPartyB","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"partyB","type":"address"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"quoteIds","type":"uint256[]"}],"name":"LiquidatePositionsPartyB","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"bytes","name":"liquidationId","type":"bytes"}],"name":"LiquidationDisputed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"partyA","type":"address"}],"name":"LiquidationDisputed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"address[]","name":"partyBs","type":"address[]"},{"indexed":false,"internalType":"int256[]","name":"amounts","type":"int256[]"},{"indexed":false,"internalType":"bool","name":"disputed","type":"bool"},{"indexed":false,"internalType":"bytes","name":"liquidationId","type":"bytes"}],"name":"ResolveLiquidationDispute","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"address[]","name":"partyBs","type":"address[]"},{"indexed":false,"internalType":"int256[]","name":"amounts","type":"int256[]"},{"indexed":false,"internalType":"bool","name":"disputed","type":"bool"}],"name":"ResolveLiquidationDispute","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"uint256","name":"quoteId","type":"uint256"},{"indexed":false,"internalType":"address[]","name":"partyBsWhiteList","type":"address[]"},{"indexed":false,"internalType":"uint256","name":"symbolId","type":"uint256"},{"indexed":false,"internalType":"enum PositionType","name":"positionType","type":"uint8"},{"indexed":false,"internalType":"enum OrderType","name":"orderType","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"price","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"marketPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"quantity","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"cva","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lf","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"partyAmm","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"partyBmm","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tradingFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"SendQuote","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"symbolIds","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"prices","type":"uint256[]"},{"indexed":false,"internalType":"bytes","name":"liquidationId","type":"bytes"}],"name":"SetSymbolsPrices","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"liquidator","type":"address"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"symbolIds","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"prices","type":"uint256[]"}],"name":"SetSymbolsPrices","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"address[]","name":"partyBs","type":"address[]"},{"indexed":false,"internalType":"int256[]","name":"amounts","type":"int256[]"},{"indexed":false,"internalType":"bytes","name":"liquidationId","type":"bytes"}],"name":"SettlePartyALiquidation","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"address[]","name":"partyBs","type":"address[]"},{"indexed":false,"internalType":"int256[]","name":"amounts","type":"int256[]"}],"name":"SettlePartyALiquidation","type":"event"},{"inputs":[{"internalType":"address","name":"partyA","type":"address"},{"components":[{"internalType":"bytes","name":"reqId","type":"bytes"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256","name":"liquidationBlockNumber","type":"uint256"},{"internalType":"uint256","name":"liquidationTimestamp","type":"uint256"},{"internalType":"uint256","name":"liquidationAllocatedBalance","type":"uint256"},{"internalType":"bytes","name":"liquidationId","type":"bytes"},{"internalType":"int256","name":"upnl","type":"int256"},{"internalType":"int256","name":"totalUnrealizedLoss","type":"int256"},{"internalType":"uint256[]","name":"symbolIds","type":"uint256[]"},{"internalType":"uint256[]","name":"prices","type":"uint256[]"},{"internalType":"bytes","name":"gatewaySignature","type":"bytes"},{"components":[{"internalType":"uint256","name":"signature","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"nonce","type":"address"}],"internalType":"struct SchnorrSign","name":"sigs","type":"tuple"}],"internalType":"struct DeferredLiquidationSig","name":"liquidationSig","type":"tuple"}],"name":"deferredLiquidatePartyA","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"partyA","type":"address"},{"components":[{"internalType":"bytes","name":"reqId","type":"bytes"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256","name":"liquidationBlockNumber","type":"uint256"},{"internalType":"uint256","name":"liquidationTimestamp","type":"uint256"},{"internalType":"uint256","name":"liquidationAllocatedBalance","type":"uint256"},{"internalType":"bytes","name":"liquidationId","type":"bytes"},{"internalType":"int256","name":"upnl","type":"int256"},{"internalType":"int256","name":"totalUnrealizedLoss","type":"int256"},{"internalType":"uint256[]","name":"symbolIds","type":"uint256[]"},{"internalType":"uint256[]","name":"prices","type":"uint256[]"},{"internalType":"bytes","name":"gatewaySignature","type":"bytes"},{"components":[{"internalType":"uint256","name":"signature","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"nonce","type":"address"}],"internalType":"struct SchnorrSign","name":"sigs","type":"tuple"}],"internalType":"struct DeferredLiquidationSig","name":"liquidationSig","type":"tuple"}],"name":"deferredSetSymbolsPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"partyA","type":"address"},{"components":[{"internalType":"bytes","name":"reqId","type":"bytes"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"bytes","name":"liquidationId","type":"bytes"},{"internalType":"int256","name":"upnl","type":"int256"},{"internalType":"int256","name":"totalUnrealizedLoss","type":"int256"},{"internalType":"uint256[]","name":"symbolIds","type":"uint256[]"},{"internalType":"uint256[]","name":"prices","type":"uint256[]"},{"internalType":"bytes","name":"gatewaySignature","type":"bytes"},{"components":[{"internalType":"uint256","name":"signature","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"nonce","type":"address"}],"internalType":"struct SchnorrSign","name":"sigs","type":"tuple"}],"internalType":"struct LiquidationSig","name":"liquidationSig","type":"tuple"}],"name":"liquidatePartyA","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"partyB","type":"address"},{"internalType":"address","name":"partyA","type":"address"},{"components":[{"internalType":"bytes","name":"reqId","type":"bytes"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"int256","name":"upnl","type":"int256"},{"internalType":"bytes","name":"gatewaySignature","type":"bytes"},{"components":[{"internalType":"uint256","name":"signature","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"nonce","type":"address"}],"internalType":"struct SchnorrSign","name":"sigs","type":"tuple"}],"internalType":"struct SingleUpnlSig","name":"upnlSig","type":"tuple"}],"name":"liquidatePartyB","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"partyA","type":"address"}],"name":"liquidatePendingPositionsPartyA","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"partyA","type":"address"},{"internalType":"uint256[]","name":"quoteIds","type":"uint256[]"}],"name":"liquidatePositionsPartyA","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"partyB","type":"address"},{"internalType":"address","name":"partyA","type":"address"},{"components":[{"internalType":"bytes","name":"reqId","type":"bytes"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256[]","name":"quoteIds","type":"uint256[]"},{"internalType":"uint256[]","name":"prices","type":"uint256[]"},{"internalType":"bytes","name":"gatewaySignature","type":"bytes"},{"components":[{"internalType":"uint256","name":"signature","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"nonce","type":"address"}],"internalType":"struct SchnorrSign","name":"sigs","type":"tuple"}],"internalType":"struct QuotePriceSig","name":"priceSig","type":"tuple"}],"name":"liquidatePositionsPartyB","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"partyA","type":"address"},{"internalType":"address[]","name":"partyBs","type":"address[]"},{"internalType":"int256[]","name":"amounts","type":"int256[]"},{"internalType":"bool","name":"disputed","type":"bool"}],"name":"resolveLiquidationDispute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"partyA","type":"address"},{"components":[{"internalType":"bytes","name":"reqId","type":"bytes"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"bytes","name":"liquidationId","type":"bytes"},{"internalType":"int256","name":"upnl","type":"int256"},{"internalType":"int256","name":"totalUnrealizedLoss","type":"int256"},{"internalType":"uint256[]","name":"symbolIds","type":"uint256[]"},{"internalType":"uint256[]","name":"prices","type":"uint256[]"},{"internalType":"bytes","name":"gatewaySignature","type":"bytes"},{"components":[{"internalType":"uint256","name":"signature","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"nonce","type":"address"}],"internalType":"struct SchnorrSign","name":"sigs","type":"tuple"}],"internalType":"struct LiquidationSig","name":"liquidationSig","type":"tuple"}],"name":"setSymbolsPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"partyA","type":"address"},{"internalType":"address[]","name":"partyBs","type":"address[]"}],"name":"settlePartyALiquidation","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60808060405234610017576155dc90816200001d8239f35b600080fdfe6080604052600436101561001257600080fd5b60003560e01c806303f9af79146127305780633f65c7f41461237c5780635e843f74146120b25780637d50901c14611ee55780637e65a2791461159757806397b75d6114610d80578063a62de5d314610aa2578063b680c57d14610816578063c81ead74146104895763e53a36c01461008a57600080fd5b3461048457610098366132a2565b6100c660ff600080516020615530833981519152546100bc828260a01c16156133eb565b60a81c1615613437565b6100dc60ff6100d4846134f5565b541615613969565b6100e5336136f6565b60008051602061557083398151915260005260205261010b60ff604060002054166139c1565b6101158282614f0c565b610134600061012e8460c085015160808601519061492b565b12613b17565b61014d8260c0830151610146826135d9565b549061492b565b60008113610452575b50610160826134f5565b600160ff1982541617905560a08101519160c082015160e08301516020840151906060850151926040519661019488612f8f565b8752600060208801526040870152606086015260006080860152600060a086015260c0850152600060e0850152600061010085015260006101208501526101408401526101e08161352e565b83518051906001600160401b03821161043c5781906101ff8454613b89565b601f81116103ff575b50602090601f831160011461039357600092610388575b50508160011b916000199060031b1c19161781555b602084015193600485101561037257610140600a916102777fb719a5b382600ecdfa09a202a1c63a759ece0e2ceca4362fb28d7d4ba6af45ff9760018601613bda565b60408101516002850155606081015160038501556080810151600485015560a0810151600585015560c0810151600685015560e0810151600785015561010081015160088501556102de6101208201511515600986019060ff801983541691151516179055565b01519101556102f5336102f083613684565b613c50565b6102fe816135d9565b549160c081015160e08201519161035c60a08201516040830151946080606085015194015194604051988998338a5260018060a01b031660208a015260408901526060880152608087015261012060a0870152610120860190613a30565b9260c085015260e08401526101008301520390a1005b634e487b7160e01b600052602160045260246000fd5b01519050388061021f565b9250836000526020600020906000935b601f19841685106103e4576001945083601f198116106103cb575b505050811b018155610234565b015160001960f88460031b161c191690553880806103be565b818101518355602094850194600190930192909101906103a3565b61042c90856000526020600020601f850160051c81019160208610610432575b601f0160051c0190613bc3565b38610208565b909150819061041f565b634e487b7160e01b600052604160045260246000fd5b61045b836135d9565b610466828254613b6f565b905561047c61047484613612565b918254613b7c565b905538610156565b600080fd5b3461048457602080600319360112610484576104a3612f4f565b906000805160206155308339815191525460ff906104cc8260a0926100bc8282861c16156133eb565b6104d5336136f6565b60008051602061557083398151915260005283526104f982604060002054166139c1565b610502846134bc565b92604051808583829754938481520190600052836000209260005b858282106108005750505061053492500385612fc6565b61054883610541876134f5565b5416613b17565b61055a610554866134bc565b54613e7d565b9261056c6105678761352e565b613c90565b9460005b610579886134bc565b5481101561070b576105938161058e8a6134bc565b613c38565b90549060031b1c6000526000805160206155b0833981519152845260406000209060148201918254908582891c1693600b851015610372578b60089386600161062d9814908115610700575b50806106d7575b610632575b506106026104746105fc8554615492565b92613612565b9055805460ff60a01b1916600560a11b17905542601a82015501546106278289613da1565b52613d92565b610570565b6106a5906001600160a01b0390819061064c9082166138be565b931692836000528b52610669604060002080549060008155613ec2565b8354166001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1d6020526040902090565b9060005288526106cf60406000206000815560006002820155600060038201556000600182015590565b508b8d6105eb565b506001600160a01b036106eb8282166138be565b9083166000528a5260406000205415156105e6565b60029150148f6105df565b7ff8dcce8f9fd5d0192b562c897a6f3d983e968c2b06a9b9c4d53d75f7f8e1c5626107fb897f0de46198ff2f90607fa355d313fcd2e03df429b6fc26efc6b0789eba66ade53289866107d88d6107b16107958760018060a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1a602052604060002090565b6000815560006002820155600060038201556000600182015590565b506107ca6107be876134bc565b80549060008155613ec2565b604051938493873386613a89565b0390a1604080513381526001600160a01b03909216602083015290918291820190565b0390a1005b855484526001958601958a95509301920161051d565b346104845760803660031901126104845761082f612f4f565b6001600160401b039060243582811161048457610850903690600401612ffe565b9060443592831161048457366023840112156104845782600401359161087583612fe7565b936108836040519586612fc6565b83855260209360248587019160051b83010191368311610484576024869101915b838310610a92575050505060643592831515938481036104845761091f906108cb336136f6565b7fc785f0e55c16138ca0f8448186fa6229be092a3a83db3c5d63c9286723c5a2c4600052835261090260ff604060002054166139c1565b600961090d8661352e565b019060ff801983541691151516179055565b8151855103610a4f5760005b825181101561097557806109426109709288613da1565b5161094c86613567565b6001600160a01b0361095e8488613da1565b51166000528452604060002055613d92565b61092b565b5092907f949185f14aeedeedfdc5076094599d22aad89697b88587c73262ace814106cdf94610a36610a44927f7f6500f142c22e49394cc4a37043061a489c9038b97fa703d78e5e9036eacadd610a1c6109d16105678961352e565b9760405191829160018060a01b0316998a835260a08c840152610a086109fa60a0850188613de8565b848103604086015289613a55565b908a60608501528382036080850152613a30565b0390a1608060405197889788528701526080860190613de8565b908482036040860152613a55565b9060608301520390a1005b6064906040519062461bcd60e51b825280600483015260248201527f4c69717569646174696f6e46616365743a20496e76616c6964206c656e6774686044820152fd5b82358152918101918691016108a4565b3461048457610ab0366132a2565b90610ad560ff600080516020615530833981519152546100bc828260a01c16156133eb565b610ade336136f6565b906000805160206155708339815191526000526020918252610b0760ff604060002054166139c1565b610b118184614f0c565b610b1f60ff610541836134f5565b610b288161352e565b91610b3283613c90565b81815191012090610b4f60a0860192835183815191012014613d36565b600684019460005b6101008201805151821015610bc75790610bc2916001610b7c83610120870151613da1565b51918a549060405193610b8e85612fab565b8452878401918252610baa85610ba38c61372f565b9251613da1565b51600052875260406000209251835551910155613d92565b610b57565b86838787610bdd8260c0850151610146826135d9565b90600180860180549660ff8816946004861015610372577f03c77f21badbb57ff9fa265f391f8cd43276bd461fb0c817f9109dcb05dba413986107fb9615610c7c575b50505050507f7f333ff255d30b1324be748744a89e79af239d52dc603165f5221f5b57c1aaf56101008501916101208351960195610c6987519251604051938493893386613a89565b0390a15192516040519384933385613ada565b610c8582613db5565b85610c8f8a61364b565b01541115610cde575091610cba600593610cb486610cac8b61364b565b015491613db5565b90613b6f565b9360ff1982541617905501555b610cd4336102f085613684565b8580808080610c20565b610ce782613db5565b610d0686610cf48b61364b565b0154610cff8b61364b565b5490613b7c565b10610d41575060049293610d1c610d2e92613db5565b90610d268961364b565b015490613b6f565b835460ff19166002179093550155610cc7565b93610d71610d61600392610d5760049795613db5565b90610d268c61364b565b610d6a8a61364b565b5490613b6f565b9460ff19161790550155610cc7565b346104845760031960603682011261048457610d9a612f4f565b610da2612f65565b604435916001600160401b0393848411610484576101009084360301126104845760405160c081018181108682111761043c57604052836004013585811161048457610df49060043691870101613064565b815260208101602495868601358252604486013581811161048457610e1f90600436918901016130ba565b9560408401968752606481013582811161048457610e4390600436918401016130ba565b6060850152608481013591821161048457610e7c610e6a610f6c9360043691850101613064565b916080860192835260a4369101613118565b9060a08501918252610ea860ff600080516020615530833981519152546100bc828260a01c16156133eb565b610eb1336136f6565b600080516020615570833981519152600052602052610ed760ff604060002054166139c1565b610ee960608601515189515114614a2a565b600080516020615550833981519152546054610f5f604088518c51610f4860608c0151610f428c51938651988996602088019b8c52610f318151809260208c8c019101613a0d565b87013060601b898201520190614a76565b90614a76565b908152466020820152036020810184520182612fc6565b5190209151905191614bc4565b8051610f7784613885565b60018060a01b038616600052602052610fb76040600020547f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f8b5490613b7c565b1061154757610fc583613768565b60018060a01b03851660005260205260ff60406000205416156114f75761100d90610fef84613885565b60018060a01b03861660005260205260406000205490511015613e25565b611018845151613e7d565b90611024855151613e7d565b9160005b8651805182101561127a578161103d91613da1565b516000526000805160206155b08339815191526020526040600020601481015490600b60ff8360a01c1610158061126557600460ff8460a01c1614908115611251575b8115611223575b506111a29261109861116a92613ee1565b60138301546001600160a01b038b81169116148061120e575b6110ba90613f2d565b600883018054916110d16009860193845490613b6f565b6110db888a613da1565b5284546000527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad596f602052604060002054611115888c613da1565b5260ff60a01b1916600160a31b17601485015542601a8501556111408461113b8d61364b565b614994565b5061119960158501916111936111888454926111828d61117b8d60606111738c549d8e809b613eaf565b96549d8e613b6f565b930151613da1565b5190613eaf565b90613b7c565b916111828188613b6f565b90613f79565b90555554615291565b6111ab86613483565b8054806000198101116111f9576000190190556111c78561384c565b60018060a01b038716600052602052604060002090815460001981019081116111f9576111f49255613d92565b611028565b89634e487b7160e01b60005260116004526000fd5b506001600160a01b03818116908a16146110b1565b905061123c5760a082901c60ff166006146111a2611087565b89634e487b7160e01b60005260216004526000fd5b50506000600560ff8460a01c161490611080565b8a634e487b7160e01b60005260216004526000fd5b8587868a868d61128986613813565b60018060a01b0386166000526020526040600020546114ba575b6112ac8661384c565b60018060a01b0386166000526020526040600020541561140f575b50907f328ee25cc7980792889a197f270edb1a81452f30ba7dfa4c743422f8208f816361135f7f355c65f88d67030952de45b964d4000f33ec98e98d04e1e5901dbf81854ac806949361136d84519560405193849333855261135160018060a01b038d16998a602088015260018060a01b038d16604088015260c0606088015260c0870190613a55565b908582036080870152613a55565b9083820360a0850152613a55565b0390a151906113a2604051928392338452602084015260018060a01b0386166040840152608060608401526080830190613a55565b0390a16113ae8261384c565b60018060a01b038216600052602052604060002054156113ca57005b604080516001600160a01b0393841681529190921660208201527fe61ecdf2f6757aefa03c992988ff63160eb5f34bb187c005090e66ee6cc54a3091819081016107fb565b61141886613768565b60018060a01b038616600052602052604060002060ff19815416905561143d86613885565b60018060a01b0386166000526020526000604081205561145c866137a1565b60018060a01b0386166000526020526040600020805491600183018093116114a65750557f328ee25cc7980792889a197f270edb1a81452f30ba7dfa4c743422f8208f81636112c7565b634e487b7160e01b60009081526011600452fd5b6114c386613813565b60018060a01b0386166000526020526114e460406000205484515190613eaf565b6114f0610474336135d9565b90556112a3565b60405162461bcd60e51b8152602060048201526023818801527f4c69717569646174696f6e46616365743a2050617274794220697320736f6c76604482015262195b9d60ea1b6064820152608490fd5b60405162461bcd60e51b8152602060048201526023818801527f4c69717569646174696f6e46616365743a20496e76616c6964207369676e617460448201526275726560e81b6064820152608490fd5b3461048457600319606036820112610484576115b1612f4f565b906115ba612f65565b90604435906001600160401b03908183116104845760e0908336030112610484576040519160a083018381108382111761043c5760405280600401358281116104845761160d9060043691840101613064565b835260248101356020840152604481013560408401526064810135918211610484576116426116519260043691840101613064565b60608401526084369101613118565b608082015261167a60ff600080516020615530833981519152546100bc828260a01c16156133eb565b61168383613768565b60018060a01b03831660005260205260ff60406000205416611e94576116ad60ff6100d4846134f5565b6116b6336136f6565b6000805160206155708339815191526000526020526116dc60ff604060002054166139c1565b6116e5836135a0565b60018060a01b0383166000526020527f50700f753d488c61d280103a69a439425af6ddbe080a3ed31b869ace98b22f8260a0604060002054604084015160405191338352600180851b0388166020840152600180851b038716604084015260608301526080820152a161177e60208201517f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79a5490613b7c565b4211611e4f5761184a6000805160206155508339815191525482516117a2866137a1565b60018060a01b03861660005260205261183760fc604060002054926040870151936020880151604051958693602085019889526117e9815180926020604089019101613a0d565b8401923060601b60408501528c6001600160601b0319809160601b1660548601528c60601b166068850152607c840152609c83015260bc8201524660dc8201520360dc810184520182612fc6565b5190206080830151606084015191614bc4565b6118cc6020604083015192015191611861856135a0565b60018060a01b0385166000526020526118c7604060002054611882876137da565b60018060a01b0387166000526020526118c16040600020546118a3896137da565b60018060a01b03891660005260205260016040600020015490613b7c565b90613f99565b613fb2565b6000811215611dfe576000806118e183613db5565b6118ea876137da565b60018060a01b03871660005260205260016040600020015411600014611dd557505061193a90611919856137da565b60018060a01b038516600052602052610cb460016040600020015491613db5565b91670de0b6b3a764000061196f7f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f8c5485613eaf565b04916119a261197e8486613b6f565b6119878761384c565b60018060a01b03851660005260205260406000205490613f79565b6119ab86613813565b60018060a01b0384166000526020526040600020555b6119ca85613768565b60018060a01b0383166000526020526040600020600160ff198254161790556119f285613885565b60018060a01b038316600052602052604060002055611a10816134bc565b916000935b8354851015611bcc57611a288585613c38565b905460039190911b1c60009081526000805160206155b08339815191526020526040902060148101546001600160a01b03808216908916149081611b91575b5015611b80576001600160a01b03841660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1a60205260409020611aaf908290614994565b50611aba8154615492565b611ac3856135d9565b611ace828254613b7c565b905560408051918252600260208301526001600160a01b038616916000805160206155908339815191529190a284546000198101908111611b6a57611b139086613c38565b90549060031b1c611b3e611b278888613c38565b819391549060031b91821b91600019901b19161790565b9055611b4985614954565b60148101805460ff60a01b1916600560a11b17905542601a90910155611a15565b634e487b7160e01b600052601160045260246000fd5b5093611b8b90613d92565b93611a15565b9050600b60ff8260a01c16101561037257600160ff8260a01c1614908115611bbb575b5088611a67565b60a01c60ff16600214905088611bb4565b611d9583611d5c611bfb8994611be1866135a0565b60018060a01b038516600052602052604060002054613b6f565b93611c05836135d9565b611c10868254613b7c565b90556040805195865260046020870152600080516020615590833981519152956001600160a01b038516918791a2611c47816138be565b60018060a01b038416600052602052611c6a604060002080549060008155613ec2565b611c73816135a0565b6001600160a01b03848116600081815260209384526040908190205481519081526005948101949094529092918416917fb4c8993414809cfa5f52991edfe7c5e2510c939d7d3e061895741a3145b46eff9190a3611cd0816135a0565b60018060a01b03841660005260205260006040812055611cef816137da565b60018060a01b038416600052602052611d2260406000206000815560006002820155600060038201556000600182015590565b506001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1d6020526040902090565b60018060a01b038216600052602052611d8f60406000206000815560006002820155600060038201556000600182015590565b506136bd565b80549060018201809211611b6a575581611dab57005b611db4336135d9565b611dbf838254613b7c565b90556040519182526008602083015260403392a2005b9290939150611de385613813565b60018060a01b038316600052602052600060408120556119c1565b60405162461bcd60e51b815260206004820152602360248201527f4c69717569646174696f6e46616365743a2070617274794220697320736f6c76604482015262195b9d60ea1b6064820152608490fd5b60405162461bcd60e51b815260206004820152601a60248201527f4c69624d756f6e3a2045787069726564207369676e61747572650000000000006044820152606490fd5b60405162461bcd60e51b815260206004820152602360248201527f4163636573736962696c6974793a205061727479422069736e277420736f6c76604482015262195b9d60ea1b6064820152608490fd5b3461048457604036600319011261048457611efe612f4f565b6024356001600160401b03811161048457611f1d9036906004016130ba565b611f4160ff600080516020615530833981519152546100bc828260a01c16156133eb565b611f4a336136f6565b600080516020615570833981519152600052602052611f7060ff604060002054166139c1565b6120177f74f4f24eca3f72e3bb723d7b35a487d7f59901d51c2060820babc5f460c8f7ab7f73447b806caa14c6e2b983606ee3eab867afcd0150f0381eae4c33fa82b9deb4612048611fc28587613fce565b9792959196906120256040519283923384526120098d60018060a01b03169b8c602087015260c06040870152611ffb60c087018a613a55565b908682036060880152613a55565b908482036080860152613a55565b82810360a08401528a613a30565b0390a1604051918291338352866020840152606060408401526060830190613a55565b0390a161205157005b7fe77bce16b7c8af767fe0d1d01d5003fa7e0e121278df8ebd8b909fc65bd2ba6c6020927f0861ca558d058e466c908a9183669c285cacbdf70d26f7211662aae86f7091f1946120a660405192839283613dc6565b0390a1604051908152a1005b34610484576120c036613168565b9060008051602061553083398151915254906120e860ff60a0936100bc8282871c16156133eb565b6120f1336136f6565b92600080516020615570833981519152600052602093845261211a60ff604060002054166139c1565b6121248282614aa3565b61213260ff610541846134f5565b61213e6105678361352e565b8481519101209061215b6040820192835187815191012014613d36565b60005b8482018051518210156121cf57906121ca9160016121808360c0870151613da1565b5191600661218d8961352e565b0154906040519361219d85612fab565b84528a84019182526121b285610ba38b61372f565b516000528a5260406000209251835551910155613d92565b61215e565b505091906121e5826060850151610146826135d9565b9060019460ff866121f58661352e565b015416906004821015610372577f03c77f21badbb57ff9fa265f391f8cd43276bd461fb0c817f9109dcb05dba413966107fb947f7f333ff255d30b1324be748744a89e79af239d52dc603165f5221f5b57c1aaf59315612271575b505085019160c08351960195610c6987519251604051938493893386613a89565b61227a81613db5565b826122848961364b565b015411156122d55761229d90610cb483610cac8a61364b565b90806122a88861352e565b019060ff1982541617905560056122be8761352e565b01555b6122ce336102f087613684565b8780612250565b6122de81613db5565b6122f6836122eb8a61364b565b0154610cff8a61364b565b106123395761230761231191613db5565b82610d268961364b565b9061231b8761352e565b01805460ff1916600217905560046123328761352e565b01556122c1565b61235261234861235b92613db5565b83610d268a61364b565b610d6a8861364b565b906123658761352e565b01805460ff1916600317905560046123328761352e565b346104845761238a36613168565b6123ae60ff600080516020615530833981519152546100bc828260a01c16156133eb565b6123bc60ff6100d4846134f5565b6123c5336136f6565b6000805160206155708339815191526000526020526123eb60ff604060002054166139c1565b6123f58282614aa3565b602081019161243261242a84517f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79a5490613b7c565b421115613e25565b612449600061012e836060860151610146826135d9565b612452816134f5565b805460ff191660011790556040828101516060840151608085015195519251959161247c87612f8f565b8652600060208701526040860152606085015260006080850152600060a08501528060c0850152600060e0850152600061010085015260006101208501526101408401526124c98161352e565b9183518051906001600160401b03821161043c5781906124e98654613b89565b601f81116126fe575b50602090601f831160011461269257600092612687575b50508160011b916000199060031b1c19161783555b602084015192600484101561037257600a6101407f21eec8e21aef24daf651df0a9fb3dce2271a7fb9e47cbdd047994a2cd6bc9f499661256360a09760018601613bda565b60408101516002850155606081015160038501556080810151600485015586810151600585015560c0810151600685015560e0810151600785015561010081015160088501556125c96101208201511515600986019060ff801983541691151516179055565b01519101556125db336102f084613684565b61265c6125e7836135d9565b54927f2051e07208dab1fb2fa0986a6fb7217d986feb02ad01eb7c453e62b494671762606084015160808501519061265460408701516040519384933385526001808d1b0388169a8b602087015260408601526060850152608084015260c08a84015260c0830190613a30565b0390a16135d9565b54906080606082015191015191604051933385526020850152604084015260608301526080820152a1005b015190508680612509565b9250856000526020600020906000935b601f19841685106126e3576001945083601f198116106126ca575b505050811b01835561251e565b015160001960f88460031b161c191690558680806126bd565b818101518355602094850194600190930192909101906126a2565b61272a90876000526020600020601f850160051c8101916020861061043257601f0160051c0190613bc3565b876124f2565b3461048457604036600319011261048457612749612f4f565b6024356001600160401b03811161048457612768903690600401612ffe565b9061278d60ff600080516020615530833981519152546100bc828260a01c16156133eb565b61279681613483565b541580612f3e575b15612edf576127b160ff610541836134f5565b60ff60096127be8361352e565b015416612e74576127d16105678261352e565b908251926127de84612fe7565b936127ec6040519586612fc6565b8085526127fb601f1991612fe7565b0136602086013760005b8151811015612b6a576001600160a01b036128208284613da1565b51169061282c84613567565b8260005260205260ff6003604060002001541615612b0f5761284d84613567565b82600052602052600360406000200160ff198154169055600761286f8561352e565b01805480600019810111611b6a57600019019055612a119160009060039061289687613567565b8184526020526040832054906128ab88613567565b818552602052600291826040862001546128c4836135a0565b6001600160a01b038b16875260205260408620805490916128e491613b7c565b90556128ef89613567565b8286526020528260408620015460405190815260076020820152600080516020615590833981519152604060018060a01b038c1692a261292e89613567565b82865260205282604086200154604051908152600660208201527fb4c8993414809cfa5f52991edfe7c5e2510c939d7d3e061895741a3145b46eff90838260408d60018060a01b031693a3828683128714612a16575061298d82613db5565b612996846135a0565b6001600160a01b038c16885260205260408720805490916129b691613b7c565b9055826129c283613db5565b60408051918252600460208301526001600160a01b038d169391a36129e7868c613da1565b525b6129f288613567565b9084526020528260408120918183558160018401558201550155613d92565b612805565b90612a20826135a0565b60018060a01b038c168852602052878d8c8560408b205410158a14612a975791612a77918693612a4f876135a0565b6001600160a01b039091168c5260205260408b208054612a70908690613b6f565b9055613da1565b5260408051938452600560208501526001600160a01b038c1693a36129e9565b5050509150612aa5906135a0565b6001600160a01b038a1686526020526040852054612ac3878d613da1565b52612acd826135a0565b6001600160a01b038a1686526020526040852085905581612aee878d613da1565b5160408051918252600560208301526001600160a01b038c169391a36129e9565b60405162461bcd60e51b815260206004820152602d60248201527f4c69717569646174696f6e46616365743a20506172747942206973206e6f742060448201526c1a5b881cd95d1d1b195b595b9d609a1b6064820152608490fd5b509290926007612b798561352e565b015415612cc6575b612c3590612c437f65f12471930e02be1b7c11eced7c0b58e7669827e98cead050aa3ae69417b92f937fc9a531602b823d6b7e999fe9d22eb296b680b9a7e734a3b68408674e222f7f8560405160018060a01b03891681526080602082015280612c10612c02612bf46080840189613de8565b838103604085015286613a55565b82810360608401528a613a30565b0390a160405193849360018060a01b0389168552606060208601526060850190613de8565b908382036040850152613a55565b0390a160ff612c51836134f5565b541615612c5a57005b7f6a4ef102cfba4a17a36d8734f7684b52fc844118a79fb1e2f5953d781c6436eb917f0a89d65a7c7592cc15c929b125f79869f7a619294a0e5b95e12e16f53172d4ac612cb06020936040519182918583613dc6565b0390a16040516001600160a01b039091168152a1005b612ccf846135d9565b546040805191825260056020830152600080516020615590833981519152916001600160a01b038716918391a2612d0585613612565b54612d0f866135d9565b55612d1985613612565b5460408051918252600260208301526001600160a01b03871691839190a26000612d4286613612565b55612d4f6107958661364b565b506005612d5b8661352e565b015480612db7575b5050612d716107be85613684565b6001612d7c8561352e565b0160ff1990818154169055612d90856134f5565b908154169055612d9f846136bd565b9081549160018301809311611b6a5791909155612b81565b60011c90612de6612dcf612dca88613684565b613bf2565b905460039190911b1c6001600160a01b03166135d9565b612df1838254613b7c565b9055612e07612dcf612e0288613684565b613c1d565b612e12838254613b7c565b9055612e20612dca87613684565b60018060a01b0391549060031b1c16816040805185815260086020820152a26040612e4d612e0288613684565b905482519485526008602086015260039190911b1c6001600160a01b031692a28480612d63565b60405162461bcd60e51b815260206004820152603960248201527f4c69717569646174696f6e46616365743a20506172747941206c69717569646160448201527f74696f6e2070726f6365737320676574206469737075746564000000000000006064820152608490fd5b60405162461bcd60e51b815260206004820152603160248201527f4c69717569646174696f6e46616365743a2050617274794120686173207374696044820152706c6c206f70656e20706f736974696f6e7360781b6064820152608490fd5b50612f48816134bc565b541561279e565b600435906001600160a01b038216820361048457565b602435906001600160a01b038216820361048457565b35906001600160a01b038216820361048457565b61016081019081106001600160401b0382111761043c57604052565b604081019081106001600160401b0382111761043c57604052565b90601f801991011681019081106001600160401b0382111761043c57604052565b6001600160401b03811161043c5760051b60200190565b81601f820112156104845780359161301583612fe7565b926130236040519485612fc6565b808452602092838086019260051b820101928311610484578301905b82821061304d575050505090565b83809161305984612f7b565b81520191019061303f565b81601f82011215610484578035906001600160401b03821161043c5760405192613098601f8401601f191660200185612fc6565b8284526020838301011161048457816000926020809301838601378301015290565b81601f82011215610484578035916130d183612fe7565b926130df6040519485612fc6565b808452602092838086019260051b820101928311610484578301905b828210613109575050505090565b813581529083019083016130fb565b919082606091031261048457604051606081018181106001600160401b0382111761043c5760405260406131638183958035855261315860208201612f7b565b602086015201612f7b565b910152565b9060031960408184011261048457600480356001600160a01b03811681036104845793602435926001600160401b039081851161048457610160908584030112610484576040519361012085018581108382111761328d57604052808401358281116104845783856131dc92840101613064565b855260248101356020860152604481013582811161048457838561320292840101613064565b6040860152606481013560608601526084810135608086015260a4810135828111610484578385613235928401016130ba565b60a086015260c4810135828111610484578385613254928401016130ba565b60c086015260e481013591821161048457613279836132849561010494840101613064565b60e086015201613118565b61010082015290565b604185634e487b7160e01b6000525260246000fd5b9060031960408184011261048457600480356001600160a01b03811681036104845793602435926001600160401b0390818511610484576101c0908584030112610484576040519361018085018581108382111761328d576040528084013582811161048457838561331692840101613064565b85526024810135602086015260448101356040860152606481013560608601526084810135608086015260a481013582811161048457838561335a92840101613064565b60a086015260c481013560c086015260e481013560e086015261010481013582811161048457838561338e928401016130ba565b6101008601526101248101358281116104845783856133af928401016130ba565b610120860152610144810135918211610484576133d6836133e29561016494840101613064565b61014086015201613118565b61016082015290565b156133f257565b60405162461bcd60e51b815260206004820152601760248201527f5061757361626c653a20476c6f62616c207061757365640000000000000000006044820152606490fd5b1561343e57565b60405162461bcd60e51b815260206004820152601c60248201527f5061757361626c653a204c69717569646174696f6e20706175736564000000006044820152606490fd5b6001600160a01b031660009081527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad59656020526040902090565b6001600160a01b031660009081527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad59676020526040902090565b6001600160a01b031660009081527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f906020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb236020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb276020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1c6020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb196020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb266020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1b6020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb256020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb206020526040902090565b6001600160a01b031660009081527f9a4861c42efbcffcc59654e070976ca1f4a2ce14007af3ccc7b4998e5b0326b56020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb246020526040902090565b6001600160a01b031660009081527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f916020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb216020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1e6020526040902090565b6001600160a01b031660009081527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f936020526040902090565b6001600160a01b031660009081527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad59666020526040902090565b6001600160a01b031660009081527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f926020526040902090565b6001600160a01b031660009081527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad59686020526040902090565b6001600160a01b031660009081527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad59696020526040902090565b6001600160a01b031660009081527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad596b6020526040902090565b1561397057565b60405162461bcd60e51b815260206004820152602360248201527f4163636573736962696c6974793a205061727479412069736e277420736f6c76604482015262195b9d60ea1b6064820152608490fd5b156139c857565b60405162461bcd60e51b815260206004820152601c60248201527f4163636573736962696c6974793a204d7573742068617320726f6c65000000006044820152606490fd5b60005b838110613a205750506000910152565b8181015183820152602001613a10565b90602091613a4981518092818552858086019101613a0d565b601f01601f1916010190565b90815180825260208080930193019160005b828110613a75575050505090565b835185529381019392810192600101613a67565b9390613ad79593613abb91613ac99460018060a01b03809216885216602087015260a0604087015260a0860190613a55565b908482036060860152613a55565b916080818403910152613a30565b90565b6001600160a01b03918216815291166020820152608060408201819052613ad7939192613b0991840190613a55565b916060818403910152613a55565b15613b1e57565b60405162461bcd60e51b815260206004820152602360248201527f4c69717569646174696f6e46616365743a2050617274794120697320736f6c76604482015262195b9d60ea1b6064820152608490fd5b91908203918211611b6a57565b91908201809211611b6a57565b90600182811c92168015613bb9575b6020831014613ba357565b634e487b7160e01b600052602260045260246000fd5b91607f1691613b98565b818110613bce575050565b60008155600101613bc3565b9060048110156103725760ff80198354169116179055565b805415613c0757600052602060002090600090565b634e487b7160e01b600052603260045260246000fd5b805460011015613c0757600052600160206000200190600090565b8054821015613c075760005260206000200190600090565b80546801000000000000000081101561043c57613c7291600182018155613c38565b819291549060031b9160018060a01b03809116831b921b1916179055565b9060405191826000825492613ca484613b89565b908184526001948581169081600014613d135750600114613cd0575b5050613cce92500383612fc6565b565b9093915060005260209081600020936000915b818310613cfb575050613cce93508201013880613cc0565b85548884018501529485019487945091830191613ce3565b915050613cce94506020925060ff191682840152151560051b8201013880613cc0565b15613d3d57565b60405162461bcd60e51b815260206004820152602760248201527f4c69717569646174696f6e46616365743a20496e76616c6964206c6971756964604482015266185d1a5bdb925960ca1b6064820152608490fd5b6000198114611b6a5760010190565b8051821015613c075760209160051b010190565b600160ff1b8114611b6a5760000390565b6001600160a01b039091168152604060208201819052613ad792910190613a30565b90815180825260208080930193019160005b828110613e08575050505090565b83516001600160a01b031685529381019392810192600101613dfa565b15613e2c57565b60405162461bcd60e51b815260206004820152602360248201527f4c69717569646174696f6e46616365743a2045787069726564207369676e617460448201526275726560e81b6064820152608490fd5b90613e8782612fe7565b613e946040519182612fc6565b8281528092613ea5601f1991612fe7565b0190602036910137565b81810292918115918404141715611b6a57565b9080613ecc575050565b613cce91600052602060002090810190613bc3565b15613ee857565b60405162461bcd60e51b815260206004820152601f60248201527f4c69717569646174696f6e46616365743a20496e76616c6964207374617465006044820152606490fd5b15613f3457565b60405162461bcd60e51b815260206004820152601f60248201527f4c69717569646174696f6e46616365743a20496e76616c6964207061727479006044820152606490fd5b8115613f83570490565b634e487b7160e01b600052601260045260246000fd5b81810392916000138015828513169184121617611b6a57565b91909160008382019384129112908015821691151617611b6a57565b919091613fdb8351613e7d565b92613fe68151613e7d565b90613ff36105678461352e565b61400160ff610541866134f5565b60005b82518110156148c5576140178184613da1565b516000526000805160206155b0833981519152602052604060002090601482015460ff8160a01c16600b8110158061037257600482149081156148b8575b81156148a5575b506140679150613ee1565b6140796001600160a01b038216613768565b60018060a01b03881660005260205260ff604060002054166148455760138301546001600160a01b0390811691906140b49089168314613f2d565b6140bd8861372f565b600285015460005260205260016040600020015460066140dc8a61352e565b0154036147f257614166906140fa6008860154600987015490613b6f565b614104858d613da1565b5284546000527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad596f60205260406000205461413e858a613da1565b5260ff60a01b198116600160a31b17601486015542601a8601556001600160a01b03166137a1565b9060005260205260406000208054600181018111611b6a57600101905561418c8661372f565b60028301546000526020526040600020546141b06008840154600985015490613b6f565b6004840154808311156147b457670de0b6b3a7640000916141eb6141f09260ff6003890154166141df81615488565b6147ac57600195613b6f565b613eaf565b04905b6141fc88613567565b60018060a01b03601486015416908160005260205260ff6003604060002001541615614766575b5060ff60016142318a61352e565b01541660048110156103725760010361450b57600e84015461425289613567565b60018060a01b036014870154166000526020526142786002604060002001918254613b7c565b9055156144d85761428887613567565b60018060a01b036014850154166000526020526142ab6040600020918254613fb2565b90555b6142b786613567565b60018060a01b036014840154169081600052602052604060002054906142dc88613567565b906000526020526001604060002001555b6014820154614304906001600160a01b03166137da565b60018060a01b038716600052602052614321826040600020614994565b506015820180549061438161433b60098601548094613eaf565b926111936143766008880154956111828d61435f614359878b613b6f565b9161372f565b60028c015460005260205260406000205490613eaf565b916111828187613b6f565b905560098301556143928254615291565b61439b86613483565b80546000199391848201918211611b6a575560148101546143c4906001600160a01b031661384c565b60018060a01b0388166000526020526040600020928354908101908111611b6a576144219355601460018060a01b03910154166144008161384c565b60018060a01b03881660005260205260406000205415614426575b50613d92565b614004565b61442f87613567565b81600052602052600160406000200154906000821260001461446c5750614463600861445a8961352e565b01918254613fb2565b90555b3861441b565b614475816135a0565b6001600160a01b0389166000908152602091909152604090205482116144ab57506144a4600861445a8961352e565b9055614466565b6144b591506135a0565b60018060a01b0387166000526020526040600020546144a4600861445a8961352e565b6144e187613567565b60018060a01b036014850154166000526020526145046040600020918254613f99565b90556142ae565b60ff60016145188a61352e565b0154166004811015610372576002036146375761455c600e850154610cb461454c60046145448d61352e565b015483613eaf565b6145558c61364b565b5490613f79565b61456589613567565b60018060a01b0360148701541660005260205261458b6002604060002001918254613b7c565b9055156146045761459b87613567565b60018060a01b036014850154166000526020526145be6040600020918254613fb2565b90555b6145ca86613567565b60018060a01b036014840154169081600052602052604060002054906145ef88613567565b906000526020526001604060002001556142ed565b61460d87613567565b60018060a01b036014850154166000526020526146306040600020918254613f99565b90556145c1565b60ff60016146448a61352e565b01541660048110156103725760031461465f575b50506142ed565b156146cb5761466d87613567565b60018060a01b036014850154166000526020526040600020614690828254613fb2565b905561469b87613567565b60018060a01b036014850154166000526020526146c16001604060002001918254613fb2565b90555b3880614658565b6147026146fc6146e760046146df8b61352e565b015484613eaf565b61119360036146f58c61352e565b0154613db5565b82613b6f565b61470b88613567565b60018060a01b0360148601541660005260205261472e6040600020918254613f99565b905561473987613567565b60018060a01b0360148501541660005260205261475f6001604060002001918254613f99565b90556146c4565b61476f89613567565b906000526020526003604060002001600160ff1982541617905560076147948961352e565b018054600181018111611b6a57600101905538614223565b600095613b6f565b91670de0b6b3a7640000916141eb6147e39260ff6003890154166147d781615488565b6147ea57600095613b6f565b04906141f3565b600195613b6f565b60405162461bcd60e51b815260206004820152602560248201527f4c69717569646174696f6e46616365743a2050726963652073686f756c64206260448201526419481cd95d60da1b6064820152608490fd5b60405162461bcd60e51b815260206004820152603260248201527f4c69717569646174696f6e46616365743a2050617274794220697320696e206c60448201527169717569646174696f6e2070726f6365737360701b6064820152608490fd5b905061037257600661406791143861405c565b5050600581146000614055565b509290509290926148d581613483565b541580614909575b6148ea5750600093929190565b6148f560099161352e565b01600160ff19825416179055600193929190565b5060086149158261352e565b015460026149228361352e565b015414156148dd565b906118c7906118c1613ad794600161494c6149458361364b565b549261364b565b015490613b7c565b805490811561497e576000199182019161496e8383613c38565b909182549160031b1b1916905555565b634e487b7160e01b600052603160045260246000fd5b90604051608081018181106001600160401b0382111761043c57604052600e820154918282526149e9600f82015493602084019485526060601160108501549460408701958652015494019384528554613b6f565b84556149fd60028501918254905190613b6f565b9055614a1160038401918254905190613b6f565b9055614a2560018301918254905190613b6f565b905590565b15614a3157565b60405162461bcd60e51b815260206004820152601760248201527f4c69624d756f6e3a20496e76616c6964206c656e6774680000000000000000006044820152606490fd5b805160208092019160005b828110614a8f575050505090565b835185529381019392810192600101614a81565b9060c08201908151519160a084019283515114614abf90614a2a565b6000805160206155508339815191525490845193604086015191614ae2856136bd565b549460608801519260808901519051925193602097888b0151966040519a8b998b8b0152805190818c60408d01920191614b1b92613a0d565b8901815191828c60408401920191614b3292613a0d565b01933060601b604086015260548501737665726966794c69717569646174696f6e53696760601b90526001600160601b03199060601b166068850152607c840152609c83015260bc82015260dc01614b8991614a76565b614b9291614a76565b9081524683820152038181018352604001614bad9083612fc6565b8151910120906101008101519060e0015190613cce925b90614c2a9060405190614bd682612fab565b7f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79e54825260ff7f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79f5416602083015283615061565b15614ceb57614c7091614c68917f19457468657265756d205369676e6564204d6573736167653a0a333200000000600052601c52603c600020614e34565b919091614d30565b7f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d7a0546001600160a01b03908116911603614ca657565b60405162461bcd60e51b815260206004820152601d60248201527f4c69624d756f6e3a2047617465776179206973206e6f742076616c69640000006044820152606490fd5b60405162461bcd60e51b815260206004820152601960248201527f4c69624d756f6e3a20545353206e6f74207665726966696564000000000000006044820152606490fd5b60058110156103725780614d415750565b60018103614d8e5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606490fd5b60028103614ddb5760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606490fd5b600314614de457565b60405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608490fd5b906041815114600014614e6257614e5e916020820151906060604084015193015160001a90614e6c565b9091565b5050600090600290565b939291907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311614eff5791614ec39160209360405196879094939260ff6060936080840197845216602083015260408201520152565b836000948592838052039060015afa15614ef25781516001600160a01b03811615614eec579190565b50600190565b50604051903d90823e3d90fd5b5050509050600090600390565b90610120820180515161010084019081515114614f2890614a2a565b600080516020615550833981519152549184519360a086015191614f4b826136bd565b549160c08801519160e0890151955190519160208a01519660408b01519460608c01519660808d015198604051809d819d6020830152805160408193019160200191614f9692613a0d565b8c0181519182604083019160200191614fae92613a0d565b01933060601b6040860152605485017f76657269667944656665727265644c69717569646174696f6e5369670000000090526001600160601b03199060601b166070850152608484015260a483015260c482015260e40161500e91614a76565b61501791614a76565b9384526020840152604083015260608201524660808201520360808101825260a0016150439082612fc6565b805190602001209061016081015190610140015190613cce92614bc4565b825160209384015183516040948501516001600160a01b038082169790969590949390927f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a18510156152545770014551231950b75fc4402da1732fc9bebe19948582101561520557891515806151fc575b806151f3575b806151ea575b156151ad578751938785019582875260ff60f81b8560f81b168a87015260418601526001600160601b03199060601b1660618501526055845260808401948486106001600160401b0387111761043c578690868a5285519020928209860391868311611b6a576000966151749460ff166151a45782601b925b0992865260ff166020860152604085015260608401526080830190565b83805203607f19019060015afa1561519a5750600051160361519557600190565b600090565b513d6000823e3d90fd5b82601c92615157565b875162461bcd60e51b81526004810188905260166024820152751b9bc81e995c9bc81a5b9c1d5d1cc8185b1b1bddd95960521b6044820152606490fd5b508415156150de565b508115156150d8565b508015156150d2565b875162461bcd60e51b815260048101889052602260248201527f7369676e6174757265206d7573742062652072656475636564206d6f64756c6f604482015261205160f01b6064820152608490fd5b865162461bcd60e51b81526004810187905260166024820152755075626c69632d6b65792078203e3d2048414c465f5160501b6044820152606490fd5b600090815260206000805160206155b0833981519152815260409081832090815484527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad596a9182825283852054927f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad596c9384845285872054601384019160018060a01b0391828454169161532283613483565b5460001993848201918211615474579061058e615373836153568661534d8661058e615381996138f7565b959054936138f7565b91909360031b1c9083549060031b91821b91600019901b19161790565b905561058e868854166138f7565b90549060031b1c8b52858852898b20556153a56153a0848654166138f7565b614954565b6014860191838354168b6153b88261384c565b868854168092528a528b8d20549283019283116154745761544e94928c8e84615437948e6153e78c9a98613930565b82855281526154086153fb87878720613c38565b90549060031b1c93613930565b9184525261541b611b2787858520613c38565b905561542987875416613930565b878b541682528d5220613c38565b90549060031b1c8c528989528a8c20555416613930565b91541687528352615460858720614954565b815486528252848481205554845252812055565b634e487b7160e01b8d52601160045260248dfd5b6002111561037257565b6000526000805160206155b08339815191526020526ec097ce7bc90715b34b9f1000000000604060002060ff600382015460081c166154d081615488565b6155085780601d6154fb6154f06008615504950154600985015490613b6f565b600684015490613eaf565b91015490613eaf565b0490565b80601d6154fb6155246008615504950154600985015490613b6f565b600784015490613eaf56fe9a4861c42efbcffcc59654e070976ca1f4a2ce14007af3ccc7b4998e5b0326b227436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79d5e17fc5225d4a099df75359ce1f405503ca79498a8dc46a7d583235a0ee45c1612f926682e9716435703a506b436993346a19a8d2f4378b264fee4c5a87f34a26e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad5964a164736f6c6343000812000a

Deployed Bytecode

0x6080604052600436101561001257600080fd5b60003560e01c806303f9af79146127305780633f65c7f41461237c5780635e843f74146120b25780637d50901c14611ee55780637e65a2791461159757806397b75d6114610d80578063a62de5d314610aa2578063b680c57d14610816578063c81ead74146104895763e53a36c01461008a57600080fd5b3461048457610098366132a2565b6100c660ff600080516020615530833981519152546100bc828260a01c16156133eb565b60a81c1615613437565b6100dc60ff6100d4846134f5565b541615613969565b6100e5336136f6565b60008051602061557083398151915260005260205261010b60ff604060002054166139c1565b6101158282614f0c565b610134600061012e8460c085015160808601519061492b565b12613b17565b61014d8260c0830151610146826135d9565b549061492b565b60008113610452575b50610160826134f5565b600160ff1982541617905560a08101519160c082015160e08301516020840151906060850151926040519661019488612f8f565b8752600060208801526040870152606086015260006080860152600060a086015260c0850152600060e0850152600061010085015260006101208501526101408401526101e08161352e565b83518051906001600160401b03821161043c5781906101ff8454613b89565b601f81116103ff575b50602090601f831160011461039357600092610388575b50508160011b916000199060031b1c19161781555b602084015193600485101561037257610140600a916102777fb719a5b382600ecdfa09a202a1c63a759ece0e2ceca4362fb28d7d4ba6af45ff9760018601613bda565b60408101516002850155606081015160038501556080810151600485015560a0810151600585015560c0810151600685015560e0810151600785015561010081015160088501556102de6101208201511515600986019060ff801983541691151516179055565b01519101556102f5336102f083613684565b613c50565b6102fe816135d9565b549160c081015160e08201519161035c60a08201516040830151946080606085015194015194604051988998338a5260018060a01b031660208a015260408901526060880152608087015261012060a0870152610120860190613a30565b9260c085015260e08401526101008301520390a1005b634e487b7160e01b600052602160045260246000fd5b01519050388061021f565b9250836000526020600020906000935b601f19841685106103e4576001945083601f198116106103cb575b505050811b018155610234565b015160001960f88460031b161c191690553880806103be565b818101518355602094850194600190930192909101906103a3565b61042c90856000526020600020601f850160051c81019160208610610432575b601f0160051c0190613bc3565b38610208565b909150819061041f565b634e487b7160e01b600052604160045260246000fd5b61045b836135d9565b610466828254613b6f565b905561047c61047484613612565b918254613b7c565b905538610156565b600080fd5b3461048457602080600319360112610484576104a3612f4f565b906000805160206155308339815191525460ff906104cc8260a0926100bc8282861c16156133eb565b6104d5336136f6565b60008051602061557083398151915260005283526104f982604060002054166139c1565b610502846134bc565b92604051808583829754938481520190600052836000209260005b858282106108005750505061053492500385612fc6565b61054883610541876134f5565b5416613b17565b61055a610554866134bc565b54613e7d565b9261056c6105678761352e565b613c90565b9460005b610579886134bc565b5481101561070b576105938161058e8a6134bc565b613c38565b90549060031b1c6000526000805160206155b0833981519152845260406000209060148201918254908582891c1693600b851015610372578b60089386600161062d9814908115610700575b50806106d7575b610632575b506106026104746105fc8554615492565b92613612565b9055805460ff60a01b1916600560a11b17905542601a82015501546106278289613da1565b52613d92565b610570565b6106a5906001600160a01b0390819061064c9082166138be565b931692836000528b52610669604060002080549060008155613ec2565b8354166001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1d6020526040902090565b9060005288526106cf60406000206000815560006002820155600060038201556000600182015590565b508b8d6105eb565b506001600160a01b036106eb8282166138be565b9083166000528a5260406000205415156105e6565b60029150148f6105df565b7ff8dcce8f9fd5d0192b562c897a6f3d983e968c2b06a9b9c4d53d75f7f8e1c5626107fb897f0de46198ff2f90607fa355d313fcd2e03df429b6fc26efc6b0789eba66ade53289866107d88d6107b16107958760018060a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1a602052604060002090565b6000815560006002820155600060038201556000600182015590565b506107ca6107be876134bc565b80549060008155613ec2565b604051938493873386613a89565b0390a1604080513381526001600160a01b03909216602083015290918291820190565b0390a1005b855484526001958601958a95509301920161051d565b346104845760803660031901126104845761082f612f4f565b6001600160401b039060243582811161048457610850903690600401612ffe565b9060443592831161048457366023840112156104845782600401359161087583612fe7565b936108836040519586612fc6565b83855260209360248587019160051b83010191368311610484576024869101915b838310610a92575050505060643592831515938481036104845761091f906108cb336136f6565b7fc785f0e55c16138ca0f8448186fa6229be092a3a83db3c5d63c9286723c5a2c4600052835261090260ff604060002054166139c1565b600961090d8661352e565b019060ff801983541691151516179055565b8151855103610a4f5760005b825181101561097557806109426109709288613da1565b5161094c86613567565b6001600160a01b0361095e8488613da1565b51166000528452604060002055613d92565b61092b565b5092907f949185f14aeedeedfdc5076094599d22aad89697b88587c73262ace814106cdf94610a36610a44927f7f6500f142c22e49394cc4a37043061a489c9038b97fa703d78e5e9036eacadd610a1c6109d16105678961352e565b9760405191829160018060a01b0316998a835260a08c840152610a086109fa60a0850188613de8565b848103604086015289613a55565b908a60608501528382036080850152613a30565b0390a1608060405197889788528701526080860190613de8565b908482036040860152613a55565b9060608301520390a1005b6064906040519062461bcd60e51b825280600483015260248201527f4c69717569646174696f6e46616365743a20496e76616c6964206c656e6774686044820152fd5b82358152918101918691016108a4565b3461048457610ab0366132a2565b90610ad560ff600080516020615530833981519152546100bc828260a01c16156133eb565b610ade336136f6565b906000805160206155708339815191526000526020918252610b0760ff604060002054166139c1565b610b118184614f0c565b610b1f60ff610541836134f5565b610b288161352e565b91610b3283613c90565b81815191012090610b4f60a0860192835183815191012014613d36565b600684019460005b6101008201805151821015610bc75790610bc2916001610b7c83610120870151613da1565b51918a549060405193610b8e85612fab565b8452878401918252610baa85610ba38c61372f565b9251613da1565b51600052875260406000209251835551910155613d92565b610b57565b86838787610bdd8260c0850151610146826135d9565b90600180860180549660ff8816946004861015610372577f03c77f21badbb57ff9fa265f391f8cd43276bd461fb0c817f9109dcb05dba413986107fb9615610c7c575b50505050507f7f333ff255d30b1324be748744a89e79af239d52dc603165f5221f5b57c1aaf56101008501916101208351960195610c6987519251604051938493893386613a89565b0390a15192516040519384933385613ada565b610c8582613db5565b85610c8f8a61364b565b01541115610cde575091610cba600593610cb486610cac8b61364b565b015491613db5565b90613b6f565b9360ff1982541617905501555b610cd4336102f085613684565b8580808080610c20565b610ce782613db5565b610d0686610cf48b61364b565b0154610cff8b61364b565b5490613b7c565b10610d41575060049293610d1c610d2e92613db5565b90610d268961364b565b015490613b6f565b835460ff19166002179093550155610cc7565b93610d71610d61600392610d5760049795613db5565b90610d268c61364b565b610d6a8a61364b565b5490613b6f565b9460ff19161790550155610cc7565b346104845760031960603682011261048457610d9a612f4f565b610da2612f65565b604435916001600160401b0393848411610484576101009084360301126104845760405160c081018181108682111761043c57604052836004013585811161048457610df49060043691870101613064565b815260208101602495868601358252604486013581811161048457610e1f90600436918901016130ba565b9560408401968752606481013582811161048457610e4390600436918401016130ba565b6060850152608481013591821161048457610e7c610e6a610f6c9360043691850101613064565b916080860192835260a4369101613118565b9060a08501918252610ea860ff600080516020615530833981519152546100bc828260a01c16156133eb565b610eb1336136f6565b600080516020615570833981519152600052602052610ed760ff604060002054166139c1565b610ee960608601515189515114614a2a565b600080516020615550833981519152546054610f5f604088518c51610f4860608c0151610f428c51938651988996602088019b8c52610f318151809260208c8c019101613a0d565b87013060601b898201520190614a76565b90614a76565b908152466020820152036020810184520182612fc6565b5190209151905191614bc4565b8051610f7784613885565b60018060a01b038616600052602052610fb76040600020547f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f8b5490613b7c565b1061154757610fc583613768565b60018060a01b03851660005260205260ff60406000205416156114f75761100d90610fef84613885565b60018060a01b03861660005260205260406000205490511015613e25565b611018845151613e7d565b90611024855151613e7d565b9160005b8651805182101561127a578161103d91613da1565b516000526000805160206155b08339815191526020526040600020601481015490600b60ff8360a01c1610158061126557600460ff8460a01c1614908115611251575b8115611223575b506111a29261109861116a92613ee1565b60138301546001600160a01b038b81169116148061120e575b6110ba90613f2d565b600883018054916110d16009860193845490613b6f565b6110db888a613da1565b5284546000527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad596f602052604060002054611115888c613da1565b5260ff60a01b1916600160a31b17601485015542601a8501556111408461113b8d61364b565b614994565b5061119960158501916111936111888454926111828d61117b8d60606111738c549d8e809b613eaf565b96549d8e613b6f565b930151613da1565b5190613eaf565b90613b7c565b916111828188613b6f565b90613f79565b90555554615291565b6111ab86613483565b8054806000198101116111f9576000190190556111c78561384c565b60018060a01b038716600052602052604060002090815460001981019081116111f9576111f49255613d92565b611028565b89634e487b7160e01b60005260116004526000fd5b506001600160a01b03818116908a16146110b1565b905061123c5760a082901c60ff166006146111a2611087565b89634e487b7160e01b60005260216004526000fd5b50506000600560ff8460a01c161490611080565b8a634e487b7160e01b60005260216004526000fd5b8587868a868d61128986613813565b60018060a01b0386166000526020526040600020546114ba575b6112ac8661384c565b60018060a01b0386166000526020526040600020541561140f575b50907f328ee25cc7980792889a197f270edb1a81452f30ba7dfa4c743422f8208f816361135f7f355c65f88d67030952de45b964d4000f33ec98e98d04e1e5901dbf81854ac806949361136d84519560405193849333855261135160018060a01b038d16998a602088015260018060a01b038d16604088015260c0606088015260c0870190613a55565b908582036080870152613a55565b9083820360a0850152613a55565b0390a151906113a2604051928392338452602084015260018060a01b0386166040840152608060608401526080830190613a55565b0390a16113ae8261384c565b60018060a01b038216600052602052604060002054156113ca57005b604080516001600160a01b0393841681529190921660208201527fe61ecdf2f6757aefa03c992988ff63160eb5f34bb187c005090e66ee6cc54a3091819081016107fb565b61141886613768565b60018060a01b038616600052602052604060002060ff19815416905561143d86613885565b60018060a01b0386166000526020526000604081205561145c866137a1565b60018060a01b0386166000526020526040600020805491600183018093116114a65750557f328ee25cc7980792889a197f270edb1a81452f30ba7dfa4c743422f8208f81636112c7565b634e487b7160e01b60009081526011600452fd5b6114c386613813565b60018060a01b0386166000526020526114e460406000205484515190613eaf565b6114f0610474336135d9565b90556112a3565b60405162461bcd60e51b8152602060048201526023818801527f4c69717569646174696f6e46616365743a2050617274794220697320736f6c76604482015262195b9d60ea1b6064820152608490fd5b60405162461bcd60e51b8152602060048201526023818801527f4c69717569646174696f6e46616365743a20496e76616c6964207369676e617460448201526275726560e81b6064820152608490fd5b3461048457600319606036820112610484576115b1612f4f565b906115ba612f65565b90604435906001600160401b03908183116104845760e0908336030112610484576040519160a083018381108382111761043c5760405280600401358281116104845761160d9060043691840101613064565b835260248101356020840152604481013560408401526064810135918211610484576116426116519260043691840101613064565b60608401526084369101613118565b608082015261167a60ff600080516020615530833981519152546100bc828260a01c16156133eb565b61168383613768565b60018060a01b03831660005260205260ff60406000205416611e94576116ad60ff6100d4846134f5565b6116b6336136f6565b6000805160206155708339815191526000526020526116dc60ff604060002054166139c1565b6116e5836135a0565b60018060a01b0383166000526020527f50700f753d488c61d280103a69a439425af6ddbe080a3ed31b869ace98b22f8260a0604060002054604084015160405191338352600180851b0388166020840152600180851b038716604084015260608301526080820152a161177e60208201517f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79a5490613b7c565b4211611e4f5761184a6000805160206155508339815191525482516117a2866137a1565b60018060a01b03861660005260205261183760fc604060002054926040870151936020880151604051958693602085019889526117e9815180926020604089019101613a0d565b8401923060601b60408501528c6001600160601b0319809160601b1660548601528c60601b166068850152607c840152609c83015260bc8201524660dc8201520360dc810184520182612fc6565b5190206080830151606084015191614bc4565b6118cc6020604083015192015191611861856135a0565b60018060a01b0385166000526020526118c7604060002054611882876137da565b60018060a01b0387166000526020526118c16040600020546118a3896137da565b60018060a01b03891660005260205260016040600020015490613b7c565b90613f99565b613fb2565b6000811215611dfe576000806118e183613db5565b6118ea876137da565b60018060a01b03871660005260205260016040600020015411600014611dd557505061193a90611919856137da565b60018060a01b038516600052602052610cb460016040600020015491613db5565b91670de0b6b3a764000061196f7f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f8c5485613eaf565b04916119a261197e8486613b6f565b6119878761384c565b60018060a01b03851660005260205260406000205490613f79565b6119ab86613813565b60018060a01b0384166000526020526040600020555b6119ca85613768565b60018060a01b0383166000526020526040600020600160ff198254161790556119f285613885565b60018060a01b038316600052602052604060002055611a10816134bc565b916000935b8354851015611bcc57611a288585613c38565b905460039190911b1c60009081526000805160206155b08339815191526020526040902060148101546001600160a01b03808216908916149081611b91575b5015611b80576001600160a01b03841660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1a60205260409020611aaf908290614994565b50611aba8154615492565b611ac3856135d9565b611ace828254613b7c565b905560408051918252600260208301526001600160a01b038616916000805160206155908339815191529190a284546000198101908111611b6a57611b139086613c38565b90549060031b1c611b3e611b278888613c38565b819391549060031b91821b91600019901b19161790565b9055611b4985614954565b60148101805460ff60a01b1916600560a11b17905542601a90910155611a15565b634e487b7160e01b600052601160045260246000fd5b5093611b8b90613d92565b93611a15565b9050600b60ff8260a01c16101561037257600160ff8260a01c1614908115611bbb575b5088611a67565b60a01c60ff16600214905088611bb4565b611d9583611d5c611bfb8994611be1866135a0565b60018060a01b038516600052602052604060002054613b6f565b93611c05836135d9565b611c10868254613b7c565b90556040805195865260046020870152600080516020615590833981519152956001600160a01b038516918791a2611c47816138be565b60018060a01b038416600052602052611c6a604060002080549060008155613ec2565b611c73816135a0565b6001600160a01b03848116600081815260209384526040908190205481519081526005948101949094529092918416917fb4c8993414809cfa5f52991edfe7c5e2510c939d7d3e061895741a3145b46eff9190a3611cd0816135a0565b60018060a01b03841660005260205260006040812055611cef816137da565b60018060a01b038416600052602052611d2260406000206000815560006002820155600060038201556000600182015590565b506001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1d6020526040902090565b60018060a01b038216600052602052611d8f60406000206000815560006002820155600060038201556000600182015590565b506136bd565b80549060018201809211611b6a575581611dab57005b611db4336135d9565b611dbf838254613b7c565b90556040519182526008602083015260403392a2005b9290939150611de385613813565b60018060a01b038316600052602052600060408120556119c1565b60405162461bcd60e51b815260206004820152602360248201527f4c69717569646174696f6e46616365743a2070617274794220697320736f6c76604482015262195b9d60ea1b6064820152608490fd5b60405162461bcd60e51b815260206004820152601a60248201527f4c69624d756f6e3a2045787069726564207369676e61747572650000000000006044820152606490fd5b60405162461bcd60e51b815260206004820152602360248201527f4163636573736962696c6974793a205061727479422069736e277420736f6c76604482015262195b9d60ea1b6064820152608490fd5b3461048457604036600319011261048457611efe612f4f565b6024356001600160401b03811161048457611f1d9036906004016130ba565b611f4160ff600080516020615530833981519152546100bc828260a01c16156133eb565b611f4a336136f6565b600080516020615570833981519152600052602052611f7060ff604060002054166139c1565b6120177f74f4f24eca3f72e3bb723d7b35a487d7f59901d51c2060820babc5f460c8f7ab7f73447b806caa14c6e2b983606ee3eab867afcd0150f0381eae4c33fa82b9deb4612048611fc28587613fce565b9792959196906120256040519283923384526120098d60018060a01b03169b8c602087015260c06040870152611ffb60c087018a613a55565b908682036060880152613a55565b908482036080860152613a55565b82810360a08401528a613a30565b0390a1604051918291338352866020840152606060408401526060830190613a55565b0390a161205157005b7fe77bce16b7c8af767fe0d1d01d5003fa7e0e121278df8ebd8b909fc65bd2ba6c6020927f0861ca558d058e466c908a9183669c285cacbdf70d26f7211662aae86f7091f1946120a660405192839283613dc6565b0390a1604051908152a1005b34610484576120c036613168565b9060008051602061553083398151915254906120e860ff60a0936100bc8282871c16156133eb565b6120f1336136f6565b92600080516020615570833981519152600052602093845261211a60ff604060002054166139c1565b6121248282614aa3565b61213260ff610541846134f5565b61213e6105678361352e565b8481519101209061215b6040820192835187815191012014613d36565b60005b8482018051518210156121cf57906121ca9160016121808360c0870151613da1565b5191600661218d8961352e565b0154906040519361219d85612fab565b84528a84019182526121b285610ba38b61372f565b516000528a5260406000209251835551910155613d92565b61215e565b505091906121e5826060850151610146826135d9565b9060019460ff866121f58661352e565b015416906004821015610372577f03c77f21badbb57ff9fa265f391f8cd43276bd461fb0c817f9109dcb05dba413966107fb947f7f333ff255d30b1324be748744a89e79af239d52dc603165f5221f5b57c1aaf59315612271575b505085019160c08351960195610c6987519251604051938493893386613a89565b61227a81613db5565b826122848961364b565b015411156122d55761229d90610cb483610cac8a61364b565b90806122a88861352e565b019060ff1982541617905560056122be8761352e565b01555b6122ce336102f087613684565b8780612250565b6122de81613db5565b6122f6836122eb8a61364b565b0154610cff8a61364b565b106123395761230761231191613db5565b82610d268961364b565b9061231b8761352e565b01805460ff1916600217905560046123328761352e565b01556122c1565b61235261234861235b92613db5565b83610d268a61364b565b610d6a8861364b565b906123658761352e565b01805460ff1916600317905560046123328761352e565b346104845761238a36613168565b6123ae60ff600080516020615530833981519152546100bc828260a01c16156133eb565b6123bc60ff6100d4846134f5565b6123c5336136f6565b6000805160206155708339815191526000526020526123eb60ff604060002054166139c1565b6123f58282614aa3565b602081019161243261242a84517f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79a5490613b7c565b421115613e25565b612449600061012e836060860151610146826135d9565b612452816134f5565b805460ff191660011790556040828101516060840151608085015195519251959161247c87612f8f565b8652600060208701526040860152606085015260006080850152600060a08501528060c0850152600060e0850152600061010085015260006101208501526101408401526124c98161352e565b9183518051906001600160401b03821161043c5781906124e98654613b89565b601f81116126fe575b50602090601f831160011461269257600092612687575b50508160011b916000199060031b1c19161783555b602084015192600484101561037257600a6101407f21eec8e21aef24daf651df0a9fb3dce2271a7fb9e47cbdd047994a2cd6bc9f499661256360a09760018601613bda565b60408101516002850155606081015160038501556080810151600485015586810151600585015560c0810151600685015560e0810151600785015561010081015160088501556125c96101208201511515600986019060ff801983541691151516179055565b01519101556125db336102f084613684565b61265c6125e7836135d9565b54927f2051e07208dab1fb2fa0986a6fb7217d986feb02ad01eb7c453e62b494671762606084015160808501519061265460408701516040519384933385526001808d1b0388169a8b602087015260408601526060850152608084015260c08a84015260c0830190613a30565b0390a16135d9565b54906080606082015191015191604051933385526020850152604084015260608301526080820152a1005b015190508680612509565b9250856000526020600020906000935b601f19841685106126e3576001945083601f198116106126ca575b505050811b01835561251e565b015160001960f88460031b161c191690558680806126bd565b818101518355602094850194600190930192909101906126a2565b61272a90876000526020600020601f850160051c8101916020861061043257601f0160051c0190613bc3565b876124f2565b3461048457604036600319011261048457612749612f4f565b6024356001600160401b03811161048457612768903690600401612ffe565b9061278d60ff600080516020615530833981519152546100bc828260a01c16156133eb565b61279681613483565b541580612f3e575b15612edf576127b160ff610541836134f5565b60ff60096127be8361352e565b015416612e74576127d16105678261352e565b908251926127de84612fe7565b936127ec6040519586612fc6565b8085526127fb601f1991612fe7565b0136602086013760005b8151811015612b6a576001600160a01b036128208284613da1565b51169061282c84613567565b8260005260205260ff6003604060002001541615612b0f5761284d84613567565b82600052602052600360406000200160ff198154169055600761286f8561352e565b01805480600019810111611b6a57600019019055612a119160009060039061289687613567565b8184526020526040832054906128ab88613567565b818552602052600291826040862001546128c4836135a0565b6001600160a01b038b16875260205260408620805490916128e491613b7c565b90556128ef89613567565b8286526020528260408620015460405190815260076020820152600080516020615590833981519152604060018060a01b038c1692a261292e89613567565b82865260205282604086200154604051908152600660208201527fb4c8993414809cfa5f52991edfe7c5e2510c939d7d3e061895741a3145b46eff90838260408d60018060a01b031693a3828683128714612a16575061298d82613db5565b612996846135a0565b6001600160a01b038c16885260205260408720805490916129b691613b7c565b9055826129c283613db5565b60408051918252600460208301526001600160a01b038d169391a36129e7868c613da1565b525b6129f288613567565b9084526020528260408120918183558160018401558201550155613d92565b612805565b90612a20826135a0565b60018060a01b038c168852602052878d8c8560408b205410158a14612a975791612a77918693612a4f876135a0565b6001600160a01b039091168c5260205260408b208054612a70908690613b6f565b9055613da1565b5260408051938452600560208501526001600160a01b038c1693a36129e9565b5050509150612aa5906135a0565b6001600160a01b038a1686526020526040852054612ac3878d613da1565b52612acd826135a0565b6001600160a01b038a1686526020526040852085905581612aee878d613da1565b5160408051918252600560208301526001600160a01b038c169391a36129e9565b60405162461bcd60e51b815260206004820152602d60248201527f4c69717569646174696f6e46616365743a20506172747942206973206e6f742060448201526c1a5b881cd95d1d1b195b595b9d609a1b6064820152608490fd5b509290926007612b798561352e565b015415612cc6575b612c3590612c437f65f12471930e02be1b7c11eced7c0b58e7669827e98cead050aa3ae69417b92f937fc9a531602b823d6b7e999fe9d22eb296b680b9a7e734a3b68408674e222f7f8560405160018060a01b03891681526080602082015280612c10612c02612bf46080840189613de8565b838103604085015286613a55565b82810360608401528a613a30565b0390a160405193849360018060a01b0389168552606060208601526060850190613de8565b908382036040850152613a55565b0390a160ff612c51836134f5565b541615612c5a57005b7f6a4ef102cfba4a17a36d8734f7684b52fc844118a79fb1e2f5953d781c6436eb917f0a89d65a7c7592cc15c929b125f79869f7a619294a0e5b95e12e16f53172d4ac612cb06020936040519182918583613dc6565b0390a16040516001600160a01b039091168152a1005b612ccf846135d9565b546040805191825260056020830152600080516020615590833981519152916001600160a01b038716918391a2612d0585613612565b54612d0f866135d9565b55612d1985613612565b5460408051918252600260208301526001600160a01b03871691839190a26000612d4286613612565b55612d4f6107958661364b565b506005612d5b8661352e565b015480612db7575b5050612d716107be85613684565b6001612d7c8561352e565b0160ff1990818154169055612d90856134f5565b908154169055612d9f846136bd565b9081549160018301809311611b6a5791909155612b81565b60011c90612de6612dcf612dca88613684565b613bf2565b905460039190911b1c6001600160a01b03166135d9565b612df1838254613b7c565b9055612e07612dcf612e0288613684565b613c1d565b612e12838254613b7c565b9055612e20612dca87613684565b60018060a01b0391549060031b1c16816040805185815260086020820152a26040612e4d612e0288613684565b905482519485526008602086015260039190911b1c6001600160a01b031692a28480612d63565b60405162461bcd60e51b815260206004820152603960248201527f4c69717569646174696f6e46616365743a20506172747941206c69717569646160448201527f74696f6e2070726f6365737320676574206469737075746564000000000000006064820152608490fd5b60405162461bcd60e51b815260206004820152603160248201527f4c69717569646174696f6e46616365743a2050617274794120686173207374696044820152706c6c206f70656e20706f736974696f6e7360781b6064820152608490fd5b50612f48816134bc565b541561279e565b600435906001600160a01b038216820361048457565b602435906001600160a01b038216820361048457565b35906001600160a01b038216820361048457565b61016081019081106001600160401b0382111761043c57604052565b604081019081106001600160401b0382111761043c57604052565b90601f801991011681019081106001600160401b0382111761043c57604052565b6001600160401b03811161043c5760051b60200190565b81601f820112156104845780359161301583612fe7565b926130236040519485612fc6565b808452602092838086019260051b820101928311610484578301905b82821061304d575050505090565b83809161305984612f7b565b81520191019061303f565b81601f82011215610484578035906001600160401b03821161043c5760405192613098601f8401601f191660200185612fc6565b8284526020838301011161048457816000926020809301838601378301015290565b81601f82011215610484578035916130d183612fe7565b926130df6040519485612fc6565b808452602092838086019260051b820101928311610484578301905b828210613109575050505090565b813581529083019083016130fb565b919082606091031261048457604051606081018181106001600160401b0382111761043c5760405260406131638183958035855261315860208201612f7b565b602086015201612f7b565b910152565b9060031960408184011261048457600480356001600160a01b03811681036104845793602435926001600160401b039081851161048457610160908584030112610484576040519361012085018581108382111761328d57604052808401358281116104845783856131dc92840101613064565b855260248101356020860152604481013582811161048457838561320292840101613064565b6040860152606481013560608601526084810135608086015260a4810135828111610484578385613235928401016130ba565b60a086015260c4810135828111610484578385613254928401016130ba565b60c086015260e481013591821161048457613279836132849561010494840101613064565b60e086015201613118565b61010082015290565b604185634e487b7160e01b6000525260246000fd5b9060031960408184011261048457600480356001600160a01b03811681036104845793602435926001600160401b0390818511610484576101c0908584030112610484576040519361018085018581108382111761328d576040528084013582811161048457838561331692840101613064565b85526024810135602086015260448101356040860152606481013560608601526084810135608086015260a481013582811161048457838561335a92840101613064565b60a086015260c481013560c086015260e481013560e086015261010481013582811161048457838561338e928401016130ba565b6101008601526101248101358281116104845783856133af928401016130ba565b610120860152610144810135918211610484576133d6836133e29561016494840101613064565b61014086015201613118565b61016082015290565b156133f257565b60405162461bcd60e51b815260206004820152601760248201527f5061757361626c653a20476c6f62616c207061757365640000000000000000006044820152606490fd5b1561343e57565b60405162461bcd60e51b815260206004820152601c60248201527f5061757361626c653a204c69717569646174696f6e20706175736564000000006044820152606490fd5b6001600160a01b031660009081527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad59656020526040902090565b6001600160a01b031660009081527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad59676020526040902090565b6001600160a01b031660009081527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f906020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb236020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb276020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1c6020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb196020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb266020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1b6020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb256020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb206020526040902090565b6001600160a01b031660009081527f9a4861c42efbcffcc59654e070976ca1f4a2ce14007af3ccc7b4998e5b0326b56020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb246020526040902090565b6001600160a01b031660009081527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f916020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb216020526040902090565b6001600160a01b031660009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1e6020526040902090565b6001600160a01b031660009081527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f936020526040902090565b6001600160a01b031660009081527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad59666020526040902090565b6001600160a01b031660009081527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f926020526040902090565b6001600160a01b031660009081527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad59686020526040902090565b6001600160a01b031660009081527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad59696020526040902090565b6001600160a01b031660009081527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad596b6020526040902090565b1561397057565b60405162461bcd60e51b815260206004820152602360248201527f4163636573736962696c6974793a205061727479412069736e277420736f6c76604482015262195b9d60ea1b6064820152608490fd5b156139c857565b60405162461bcd60e51b815260206004820152601c60248201527f4163636573736962696c6974793a204d7573742068617320726f6c65000000006044820152606490fd5b60005b838110613a205750506000910152565b8181015183820152602001613a10565b90602091613a4981518092818552858086019101613a0d565b601f01601f1916010190565b90815180825260208080930193019160005b828110613a75575050505090565b835185529381019392810192600101613a67565b9390613ad79593613abb91613ac99460018060a01b03809216885216602087015260a0604087015260a0860190613a55565b908482036060860152613a55565b916080818403910152613a30565b90565b6001600160a01b03918216815291166020820152608060408201819052613ad7939192613b0991840190613a55565b916060818403910152613a55565b15613b1e57565b60405162461bcd60e51b815260206004820152602360248201527f4c69717569646174696f6e46616365743a2050617274794120697320736f6c76604482015262195b9d60ea1b6064820152608490fd5b91908203918211611b6a57565b91908201809211611b6a57565b90600182811c92168015613bb9575b6020831014613ba357565b634e487b7160e01b600052602260045260246000fd5b91607f1691613b98565b818110613bce575050565b60008155600101613bc3565b9060048110156103725760ff80198354169116179055565b805415613c0757600052602060002090600090565b634e487b7160e01b600052603260045260246000fd5b805460011015613c0757600052600160206000200190600090565b8054821015613c075760005260206000200190600090565b80546801000000000000000081101561043c57613c7291600182018155613c38565b819291549060031b9160018060a01b03809116831b921b1916179055565b9060405191826000825492613ca484613b89565b908184526001948581169081600014613d135750600114613cd0575b5050613cce92500383612fc6565b565b9093915060005260209081600020936000915b818310613cfb575050613cce93508201013880613cc0565b85548884018501529485019487945091830191613ce3565b915050613cce94506020925060ff191682840152151560051b8201013880613cc0565b15613d3d57565b60405162461bcd60e51b815260206004820152602760248201527f4c69717569646174696f6e46616365743a20496e76616c6964206c6971756964604482015266185d1a5bdb925960ca1b6064820152608490fd5b6000198114611b6a5760010190565b8051821015613c075760209160051b010190565b600160ff1b8114611b6a5760000390565b6001600160a01b039091168152604060208201819052613ad792910190613a30565b90815180825260208080930193019160005b828110613e08575050505090565b83516001600160a01b031685529381019392810192600101613dfa565b15613e2c57565b60405162461bcd60e51b815260206004820152602360248201527f4c69717569646174696f6e46616365743a2045787069726564207369676e617460448201526275726560e81b6064820152608490fd5b90613e8782612fe7565b613e946040519182612fc6565b8281528092613ea5601f1991612fe7565b0190602036910137565b81810292918115918404141715611b6a57565b9080613ecc575050565b613cce91600052602060002090810190613bc3565b15613ee857565b60405162461bcd60e51b815260206004820152601f60248201527f4c69717569646174696f6e46616365743a20496e76616c6964207374617465006044820152606490fd5b15613f3457565b60405162461bcd60e51b815260206004820152601f60248201527f4c69717569646174696f6e46616365743a20496e76616c6964207061727479006044820152606490fd5b8115613f83570490565b634e487b7160e01b600052601260045260246000fd5b81810392916000138015828513169184121617611b6a57565b91909160008382019384129112908015821691151617611b6a57565b919091613fdb8351613e7d565b92613fe68151613e7d565b90613ff36105678461352e565b61400160ff610541866134f5565b60005b82518110156148c5576140178184613da1565b516000526000805160206155b0833981519152602052604060002090601482015460ff8160a01c16600b8110158061037257600482149081156148b8575b81156148a5575b506140679150613ee1565b6140796001600160a01b038216613768565b60018060a01b03881660005260205260ff604060002054166148455760138301546001600160a01b0390811691906140b49089168314613f2d565b6140bd8861372f565b600285015460005260205260016040600020015460066140dc8a61352e565b0154036147f257614166906140fa6008860154600987015490613b6f565b614104858d613da1565b5284546000527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad596f60205260406000205461413e858a613da1565b5260ff60a01b198116600160a31b17601486015542601a8601556001600160a01b03166137a1565b9060005260205260406000208054600181018111611b6a57600101905561418c8661372f565b60028301546000526020526040600020546141b06008840154600985015490613b6f565b6004840154808311156147b457670de0b6b3a7640000916141eb6141f09260ff6003890154166141df81615488565b6147ac57600195613b6f565b613eaf565b04905b6141fc88613567565b60018060a01b03601486015416908160005260205260ff6003604060002001541615614766575b5060ff60016142318a61352e565b01541660048110156103725760010361450b57600e84015461425289613567565b60018060a01b036014870154166000526020526142786002604060002001918254613b7c565b9055156144d85761428887613567565b60018060a01b036014850154166000526020526142ab6040600020918254613fb2565b90555b6142b786613567565b60018060a01b036014840154169081600052602052604060002054906142dc88613567565b906000526020526001604060002001555b6014820154614304906001600160a01b03166137da565b60018060a01b038716600052602052614321826040600020614994565b506015820180549061438161433b60098601548094613eaf565b926111936143766008880154956111828d61435f614359878b613b6f565b9161372f565b60028c015460005260205260406000205490613eaf565b916111828187613b6f565b905560098301556143928254615291565b61439b86613483565b80546000199391848201918211611b6a575560148101546143c4906001600160a01b031661384c565b60018060a01b0388166000526020526040600020928354908101908111611b6a576144219355601460018060a01b03910154166144008161384c565b60018060a01b03881660005260205260406000205415614426575b50613d92565b614004565b61442f87613567565b81600052602052600160406000200154906000821260001461446c5750614463600861445a8961352e565b01918254613fb2565b90555b3861441b565b614475816135a0565b6001600160a01b0389166000908152602091909152604090205482116144ab57506144a4600861445a8961352e565b9055614466565b6144b591506135a0565b60018060a01b0387166000526020526040600020546144a4600861445a8961352e565b6144e187613567565b60018060a01b036014850154166000526020526145046040600020918254613f99565b90556142ae565b60ff60016145188a61352e565b0154166004811015610372576002036146375761455c600e850154610cb461454c60046145448d61352e565b015483613eaf565b6145558c61364b565b5490613f79565b61456589613567565b60018060a01b0360148701541660005260205261458b6002604060002001918254613b7c565b9055156146045761459b87613567565b60018060a01b036014850154166000526020526145be6040600020918254613fb2565b90555b6145ca86613567565b60018060a01b036014840154169081600052602052604060002054906145ef88613567565b906000526020526001604060002001556142ed565b61460d87613567565b60018060a01b036014850154166000526020526146306040600020918254613f99565b90556145c1565b60ff60016146448a61352e565b01541660048110156103725760031461465f575b50506142ed565b156146cb5761466d87613567565b60018060a01b036014850154166000526020526040600020614690828254613fb2565b905561469b87613567565b60018060a01b036014850154166000526020526146c16001604060002001918254613fb2565b90555b3880614658565b6147026146fc6146e760046146df8b61352e565b015484613eaf565b61119360036146f58c61352e565b0154613db5565b82613b6f565b61470b88613567565b60018060a01b0360148601541660005260205261472e6040600020918254613f99565b905561473987613567565b60018060a01b0360148501541660005260205261475f6001604060002001918254613f99565b90556146c4565b61476f89613567565b906000526020526003604060002001600160ff1982541617905560076147948961352e565b018054600181018111611b6a57600101905538614223565b600095613b6f565b91670de0b6b3a7640000916141eb6147e39260ff6003890154166147d781615488565b6147ea57600095613b6f565b04906141f3565b600195613b6f565b60405162461bcd60e51b815260206004820152602560248201527f4c69717569646174696f6e46616365743a2050726963652073686f756c64206260448201526419481cd95d60da1b6064820152608490fd5b60405162461bcd60e51b815260206004820152603260248201527f4c69717569646174696f6e46616365743a2050617274794220697320696e206c60448201527169717569646174696f6e2070726f6365737360701b6064820152608490fd5b905061037257600661406791143861405c565b5050600581146000614055565b509290509290926148d581613483565b541580614909575b6148ea5750600093929190565b6148f560099161352e565b01600160ff19825416179055600193929190565b5060086149158261352e565b015460026149228361352e565b015414156148dd565b906118c7906118c1613ad794600161494c6149458361364b565b549261364b565b015490613b7c565b805490811561497e576000199182019161496e8383613c38565b909182549160031b1b1916905555565b634e487b7160e01b600052603160045260246000fd5b90604051608081018181106001600160401b0382111761043c57604052600e820154918282526149e9600f82015493602084019485526060601160108501549460408701958652015494019384528554613b6f565b84556149fd60028501918254905190613b6f565b9055614a1160038401918254905190613b6f565b9055614a2560018301918254905190613b6f565b905590565b15614a3157565b60405162461bcd60e51b815260206004820152601760248201527f4c69624d756f6e3a20496e76616c6964206c656e6774680000000000000000006044820152606490fd5b805160208092019160005b828110614a8f575050505090565b835185529381019392810192600101614a81565b9060c08201908151519160a084019283515114614abf90614a2a565b6000805160206155508339815191525490845193604086015191614ae2856136bd565b549460608801519260808901519051925193602097888b0151966040519a8b998b8b0152805190818c60408d01920191614b1b92613a0d565b8901815191828c60408401920191614b3292613a0d565b01933060601b604086015260548501737665726966794c69717569646174696f6e53696760601b90526001600160601b03199060601b166068850152607c840152609c83015260bc82015260dc01614b8991614a76565b614b9291614a76565b9081524683820152038181018352604001614bad9083612fc6565b8151910120906101008101519060e0015190613cce925b90614c2a9060405190614bd682612fab565b7f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79e54825260ff7f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79f5416602083015283615061565b15614ceb57614c7091614c68917f19457468657265756d205369676e6564204d6573736167653a0a333200000000600052601c52603c600020614e34565b919091614d30565b7f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d7a0546001600160a01b03908116911603614ca657565b60405162461bcd60e51b815260206004820152601d60248201527f4c69624d756f6e3a2047617465776179206973206e6f742076616c69640000006044820152606490fd5b60405162461bcd60e51b815260206004820152601960248201527f4c69624d756f6e3a20545353206e6f74207665726966696564000000000000006044820152606490fd5b60058110156103725780614d415750565b60018103614d8e5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606490fd5b60028103614ddb5760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606490fd5b600314614de457565b60405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608490fd5b906041815114600014614e6257614e5e916020820151906060604084015193015160001a90614e6c565b9091565b5050600090600290565b939291907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311614eff5791614ec39160209360405196879094939260ff6060936080840197845216602083015260408201520152565b836000948592838052039060015afa15614ef25781516001600160a01b03811615614eec579190565b50600190565b50604051903d90823e3d90fd5b5050509050600090600390565b90610120820180515161010084019081515114614f2890614a2a565b600080516020615550833981519152549184519360a086015191614f4b826136bd565b549160c08801519160e0890151955190519160208a01519660408b01519460608c01519660808d015198604051809d819d6020830152805160408193019160200191614f9692613a0d565b8c0181519182604083019160200191614fae92613a0d565b01933060601b6040860152605485017f76657269667944656665727265644c69717569646174696f6e5369670000000090526001600160601b03199060601b166070850152608484015260a483015260c482015260e40161500e91614a76565b61501791614a76565b9384526020840152604083015260608201524660808201520360808101825260a0016150439082612fc6565b805190602001209061016081015190610140015190613cce92614bc4565b825160209384015183516040948501516001600160a01b038082169790969590949390927f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a18510156152545770014551231950b75fc4402da1732fc9bebe19948582101561520557891515806151fc575b806151f3575b806151ea575b156151ad578751938785019582875260ff60f81b8560f81b168a87015260418601526001600160601b03199060601b1660618501526055845260808401948486106001600160401b0387111761043c578690868a5285519020928209860391868311611b6a576000966151749460ff166151a45782601b925b0992865260ff166020860152604085015260608401526080830190565b83805203607f19019060015afa1561519a5750600051160361519557600190565b600090565b513d6000823e3d90fd5b82601c92615157565b875162461bcd60e51b81526004810188905260166024820152751b9bc81e995c9bc81a5b9c1d5d1cc8185b1b1bddd95960521b6044820152606490fd5b508415156150de565b508115156150d8565b508015156150d2565b875162461bcd60e51b815260048101889052602260248201527f7369676e6174757265206d7573742062652072656475636564206d6f64756c6f604482015261205160f01b6064820152608490fd5b865162461bcd60e51b81526004810187905260166024820152755075626c69632d6b65792078203e3d2048414c465f5160501b6044820152606490fd5b600090815260206000805160206155b0833981519152815260409081832090815484527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad596a9182825283852054927f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad596c9384845285872054601384019160018060a01b0391828454169161532283613483565b5460001993848201918211615474579061058e615373836153568661534d8661058e615381996138f7565b959054936138f7565b91909360031b1c9083549060031b91821b91600019901b19161790565b905561058e868854166138f7565b90549060031b1c8b52858852898b20556153a56153a0848654166138f7565b614954565b6014860191838354168b6153b88261384c565b868854168092528a528b8d20549283019283116154745761544e94928c8e84615437948e6153e78c9a98613930565b82855281526154086153fb87878720613c38565b90549060031b1c93613930565b9184525261541b611b2787858520613c38565b905561542987875416613930565b878b541682528d5220613c38565b90549060031b1c8c528989528a8c20555416613930565b91541687528352615460858720614954565b815486528252848481205554845252812055565b634e487b7160e01b8d52601160045260248dfd5b6002111561037257565b6000526000805160206155b08339815191526020526ec097ce7bc90715b34b9f1000000000604060002060ff600382015460081c166154d081615488565b6155085780601d6154fb6154f06008615504950154600985015490613b6f565b600684015490613eaf565b91015490613eaf565b0490565b80601d6154fb6155246008615504950154600985015490613b6f565b600784015490613eaf56fe9a4861c42efbcffcc59654e070976ca1f4a2ce14007af3ccc7b4998e5b0326b227436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79d5e17fc5225d4a099df75359ce1f405503ca79498a8dc46a7d583235a0ee45c1612f926682e9716435703a506b436993346a19a8d2f4378b264fee4c5a87f34a26e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad5964a164736f6c6343000812000a

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

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.