Source Code
Overview
S Balance
S Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Contract Name:
PartyBQuoteActionsFacet
Compiler Version
v0.8.18+commit.87f61d96
Optimization Enabled:
Yes with 400 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// 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 "./PartyBQuoteActionsFacetImpl.sol";
import "../../utils/Accessibility.sol";
import "../../utils/Pausable.sol";
import "./IPartyBQuoteActionsFacet.sol";
contract PartyBQuoteActionsFacet is Accessibility, Pausable, IPartyBQuoteActionsFacet {
using LockedValuesOps for LockedValues;
/**
* @notice Once a user issues a quote, any PartyB can secure it by providing sufficient funds, based on their estimated profit and loss from opening the position.
* @param quoteId The ID of the quote to be locked.
* @param upnlSig The Muon signature containing the upnl value used to lock the quote.
*/
function lockQuote(uint256 quoteId, SingleUpnlSig memory upnlSig) external whenNotPartyBActionsPaused onlyPartyB notLiquidated(quoteId) {
PartyBQuoteActionsFacetImpl.lockQuote(quoteId, upnlSig);
Quote storage quote = QuoteStorage.layout().quotes[quoteId];
emit LockQuote(quote.partyB, quoteId);
}
/**
* @notice Unlocks the specified quote.
* @param quoteId The ID of the quote to be unlocked.
*/
function unlockQuote(uint256 quoteId) external whenNotPartyBActionsPaused onlyPartyBOfQuote(quoteId) notLiquidated(quoteId) {
QuoteStatus res = PartyBQuoteActionsFacetImpl.unlockQuote(quoteId);
if (res == QuoteStatus.EXPIRED) {
emit ExpireQuoteOpen(res, quoteId);
} else if (res == QuoteStatus.PENDING) {
emit UnlockQuote(msg.sender, quoteId, QuoteStatus.PENDING);
}
}
/**
* @notice Accepts the cancellation request for the specified quote.
* @param quoteId The ID of the quote for which the cancellation request is accepted.
*/
function acceptCancelRequest(uint256 quoteId) external whenNotPartyBActionsPaused onlyPartyBOfQuote(quoteId) notLiquidated(quoteId) {
PartyBQuoteActionsFacetImpl.acceptCancelRequest(quoteId);
emit AcceptCancelRequest(quoteId, QuoteStatus.CANCELED);
}
}// 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 "../../interfaces/IPartiesEvents.sol";
interface IPartyBQuoteActionsEvents is IPartiesEvents {
event LockQuote(address partyB, uint256 quoteId);
event AllocatePartyB(address partyB, address partyA, uint256 amount);
event UnlockQuote(address partyB, uint256 quoteId, QuoteStatus quoteStatus);
}// 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 "./IPartyBQuoteActionsEvents.sol";
interface IPartyBQuoteActionsFacet is IPartyBQuoteActionsEvents {
function lockQuote(uint256 quoteId, SingleUpnlSig memory upnlSig) external;
function unlockQuote(uint256 quoteId) external;
function acceptCancelRequest(uint256 quoteId) 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/muon/LibMuonPartyB.sol";
import "../../libraries/LibQuote.sol";
import "../../libraries/LibPartyBQuoteActions.sol";
library PartyBQuoteActionsFacetImpl {
using LockedValuesOps for LockedValues;
function lockQuote(uint256 quoteId, SingleUpnlSig memory upnlSig) internal {
QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
Quote storage quote = quoteLayout.quotes[quoteId];
LibMuonPartyB.verifyPartyBUpnl(upnlSig, msg.sender, quote.partyA);
int256 availableBalance = LibAccount.partyBAvailableForQuote(upnlSig.upnl, msg.sender, quote.partyA);
require(availableBalance >= 0, "PartyBFacet: Available balance is lower than zero");
require(uint256(availableBalance) >= quote.lockedValues.totalForPartyB(), "PartyBFacet: insufficient available balance");
LibPartyBQuoteActions.lockQuote(quoteId);
}
function unlockQuote(uint256 quoteId) internal returns (QuoteStatus) {
AccountStorage.Layout storage accountLayout = AccountStorage.layout();
QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
Quote storage quote = quoteLayout.quotes[quoteId];
require(quote.quoteStatus == QuoteStatus.LOCKED, "PartyBFacet: Invalid state");
if (block.timestamp > quote.deadline) {
QuoteStatus result = LibQuote.expireQuote(quoteId);
return result;
} else {
quote.statusModifyTimestamp = block.timestamp;
quote.quoteStatus = QuoteStatus.PENDING;
accountLayout.partyBPendingLockedBalances[quote.partyB][quote.partyA].subQuote(quote);
LibQuote.removeFromPartyBPendingQuotes(quote);
quote.partyB = address(0);
return QuoteStatus.PENDING;
}
}
function acceptCancelRequest(uint256 quoteId) internal {
AccountStorage.Layout storage accountLayout = AccountStorage.layout();
Quote storage quote = QuoteStorage.layout().quotes[quoteId];
require(quote.quoteStatus == QuoteStatus.CANCEL_PENDING, "PartyBFacet: Invalid state");
quote.statusModifyTimestamp = block.timestamp;
quote.quoteStatus = QuoteStatus.CANCELED;
accountLayout.pendingLockedBalances[quote.partyA].subQuote(quote);
accountLayout.partyBPendingLockedBalances[quote.partyB][quote.partyA].subQuote(quote);
// send trading Fee back to partyA
uint256 fee = LibQuote.getTradingFee(quoteId);
accountLayout.allocatedBalances[quote.partyA] += fee;
emit SharedEvents.BalanceChangePartyA(quote.partyA, fee, SharedEvents.BalanceChangeType.PLATFORM_FEE_IN);
LibQuote.removeFromPendingQuotes(quote);
}
}// 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";
import "../storages/MuonStorage.sol";
interface IPartiesEvents {
event AcceptCancelRequest(uint256 quoteId, QuoteStatus quoteStatus);
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 OpenPosition(uint256 quoteId, address partyA, address partyB, uint256 filledAmount, uint256 openedPrice);
event FillCloseRequest(
uint256 quoteId,
address partyA,
address partyB,
uint256 filledAmount,
uint256 closedPrice,
QuoteStatus quoteStatus,
uint256 closeId
);
event FillCloseRequest(uint256 quoteId, address partyA, address partyB, uint256 filledAmount, uint256 closedPrice, QuoteStatus quoteStatus); // For backward compatibility, will be removed in future
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 "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "../storages/QuoteStorage.sol";
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: 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 "../storages/QuoteStorage.sol";
import "../storages/MAStorage.sol";
import "./LibAccount.sol";
import "./LibLockedValues.sol";
library LibPartyBQuoteActions {
using LockedValuesOps for LockedValues;
function lockQuote(uint256 quoteId) internal {
QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
AccountStorage.Layout storage accountLayout = AccountStorage.layout();
Quote storage quote = quoteLayout.quotes[quoteId];
require(quote.quoteStatus == QuoteStatus.PENDING, "PartyBFacet: Invalid state");
require(block.timestamp <= quote.deadline, "PartyBFacet: Quote is expired");
require(quoteId <= quoteLayout.lastId, "PartyBFacet: Invalid quoteId");
require(!MAStorage.layout().partyBLiquidationStatus[msg.sender][quote.partyA], "PartyBFacet: PartyB isn't solvent");
bool isValidPartyB;
if (quote.partyBsWhiteList.length == 0) {
require(msg.sender != quote.partyA, "PartyBFacet: PartyA can't be partyB too");
isValidPartyB = true;
} else {
for (uint8 index = 0; index < quote.partyBsWhiteList.length; index++) {
if (msg.sender == quote.partyBsWhiteList[index]) {
isValidPartyB = true;
break;
}
}
}
require(isValidPartyB, "PartyBFacet: Sender isn't whitelisted");
quote.statusModifyTimestamp = block.timestamp;
quote.quoteStatus = QuoteStatus.LOCKED;
quote.partyB = msg.sender;
// lock funds for partyB
accountLayout.partyBPendingLockedBalances[msg.sender][quote.partyA].addQuote(quote);
quoteLayout.partyBPendingQuotes[msg.sender][quote.partyA].push(quote.id);
}
}// 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;
}
}
}// 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 "../LibMuonV04ClientBase.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");
// == ) ==
}
// Used in PartyB/Account/Liquidation
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);
}
}// 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 "./LibMuon.sol";
library LibMuonPartyB {
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,
LibMuon.getChainId()
)
);
LibMuon.verifyTSSAndGateway(hash, upnlSig.sigs, upnlSig.gatewaySignature);
}
function verifyPartyBUpnl(SingleUpnlSig memory upnlSig, address partyB, address partyA) internal view {
LibMuon.verifyPartyBUpnl(upnlSig, partyB, partyA);
}
}// 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,
FUNDING_FEE_IN,
FUNDING_FEE_OUT
}
event BalanceChangePartyA(address indexed partyA, uint256 amount, BalanceChangeType _type);
event BalanceChangePartyB(address indexed partyB, address indexed partyA, uint256 amount, BalanceChangeType _type);
}// 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;
mapping(address => uint256) reserveVault;
}
function layout() internal pure returns (Layout storage l) {
bytes32 slot = ACCOUNT_STORAGE_SLOT;
assembly {
l.slot := slot
}
}
}// 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
}
}
}// 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;
uint256 settlementCooldown;
mapping(address => mapping(address => mapping(address => uint256))) lastUpnlSettlementTimestamp; // subject partyB => object partyB => partyA => timestamp
}
function layout() internal pure returns (Layout storage l) {
bytes32 slot = MA_STORAGE_SLOT;
assembly {
l.slot := slot
}
}
}// 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 PairUpnlAndPricesSig {
bytes reqId;
uint256 timestamp;
int256 upnlPartyA;
int256 upnlPartyB;
uint256[] symbolIds;
uint256[] prices;
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;
}
struct QuoteSettlementData {
uint256 quoteId;
uint256 currentPrice;
uint8 partyBUpnlIndex;
}
struct SettlementSig {
bytes reqId;
uint256 timestamp;
QuoteSettlementData[] quotesSettlementsData;
int256[] upnlPartyBs;
int256 upnlPartyA;
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
}
}
}// 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;
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 LockedValues {
uint256 cva;
uint256 lf;
uint256 partyAmm;
uint256 partyBmm;
}
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
}
}
}// 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
}
}
}// 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.LIQUIDATED_PENDING &&
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");
_;
}
}// 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");
_;
}
}{
"metadata": {
"bytecodeHash": "none"
},
"optimizer": {
"enabled": true,
"runs": 400
},
"viaIR": true,
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"quoteId","type":"uint256"},{"indexed":false,"internalType":"enum QuoteStatus","name":"quoteStatus","type":"uint8"}],"name":"AcceptCancelRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"partyB","type":"address"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"AllocatePartyB","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":"uint256","name":"quoteId","type":"uint256"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"address","name":"partyB","type":"address"},{"indexed":false,"internalType":"uint256","name":"filledAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"closedPrice","type":"uint256"},{"indexed":false,"internalType":"enum QuoteStatus","name":"quoteStatus","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"closeId","type":"uint256"}],"name":"FillCloseRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"quoteId","type":"uint256"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"address","name":"partyB","type":"address"},{"indexed":false,"internalType":"uint256","name":"filledAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"closedPrice","type":"uint256"},{"indexed":false,"internalType":"enum QuoteStatus","name":"quoteStatus","type":"uint8"}],"name":"FillCloseRequest","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":"partyB","type":"address"},{"indexed":false,"internalType":"uint256","name":"quoteId","type":"uint256"}],"name":"LockQuote","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"quoteId","type":"uint256"},{"indexed":false,"internalType":"address","name":"partyA","type":"address"},{"indexed":false,"internalType":"address","name":"partyB","type":"address"},{"indexed":false,"internalType":"uint256","name":"filledAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"openedPrice","type":"uint256"}],"name":"OpenPosition","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":"partyB","type":"address"},{"indexed":false,"internalType":"uint256","name":"quoteId","type":"uint256"},{"indexed":false,"internalType":"enum QuoteStatus","name":"quoteStatus","type":"uint8"}],"name":"UnlockQuote","type":"event"},{"inputs":[{"internalType":"uint256","name":"quoteId","type":"uint256"}],"name":"acceptCancelRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"quoteId","type":"uint256"},{"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":"lockQuote","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"quoteId","type":"uint256"}],"name":"unlockQuote","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
608080604052346100165761251e908161001c8239f35b600080fdfe6080604052600436101561001257600080fd5b60003560e01c80631bc1045614611256578063606a243b14610f0f5763ca6b88de1461003d57600080fd5b34610f0a57600319604036820112610f0a57602490813567ffffffffffffffff8111610f0a5760e081360392830112610f0a576040519160a0830183811067ffffffffffffffff821117610ef557604052816004013567ffffffffffffffff8111610f0a576100b29060043691850101611495565b83528382013560208401526044820135604084015260648201359067ffffffffffffffff8211610f0a576100ee60609260043691860101611495565b848301526083190112610f0a57604051906060820182811067ffffffffffffffff821117610ef55761013e9160c4916040526084810135845261013360a482016114ec565b6020850152016114ec565b6040820152608082015261018860ff7f9a4861c42efbcffcc59654e070976ca1f4a2ce14007af3ccc7b4998e5b0326b25461017e828260a01c1615611500565b60b81c161561154c565b336000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f8f60205260ff6040600020541615610eb1576004356000526000805160206124f2833981519152602052604060002060146001600160a01b036013830154169161023560ff61022d856001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f90602052604060002090565b541615611598565b01549061027d6001600160a01b0383166001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f91602052604060002090565b9060005260205261029660ff60406000205416156115f0565b600b60ff8260a01c16101580610b0457600860ff8360a01c1614159081610e9c575b81610e6d575b506102c99150611648565b6004356000526000805160206124f283398151915260205260406000209060138201549061031d60208201517f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79a5490611d2b565b4211610e29577f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79d54815190336000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb2160205260406000206001600160a01b038516600052602052604060002054906040840151602085015190604051948593602085015280519060005b828110610e115750509161040b9491849360fc9501923060601b60408501523360601b60548501526bffffffffffffffffffffffff198a60601b166068850152607c840152609c83015260bc8201524660dc8201520360dc81018452018261145d565b6020815191012060808201519060608301519160405180604081011067ffffffffffffffff604083011117610dfc5761049991604082016040527f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79e54825260ff7f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79f54166020830152836122af565b15610db8576104df916104d7917f19457468657265756d205369676e6564204d6573736167653a0a333200000000600052601c52603c6000206121d7565b9190916120d3565b6001600160a01b03807f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d7a05416911603610d74576040015160008112610bf0573360009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1c602052604090206001600160a01b03831660005260205260406000205460008282019283129112908015821691151617610bdb5761064461064a926105bc336001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1e602052604060002090565b6001600160a01b0382166000526020526105e16105dc60406000206116f1565b611de7565b906001600160a01b03610626336001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1d602052604060002090565b911660005260205261063e6105dc60406000206116f1565b90611d2b565b90611d5f565b905b60008212610b71576105dc600e61066392016116f1565b11610b19576004356000526000805160206124f28339815191526020526040600020601481015460ff8160a01c16600b811015610b04576106a49015611734565b601c8201544211610ac0577f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad596d5460043511610a7c573360009081527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f9160205260409020906001600160a01b03601384015416918260005260205260ff60406000205416610a2e576000600184015480156000146109c057505081331461096c5760015b1561091a5742601a84015574ffffffffffffffffffffffffffffffffffffffffff191633908117600160a01b1760148401556107b5906001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1d602052604060002090565b90600052602052604060002061081d60016107d2600e85016116f1565b926107e08154855190611d2b565b8155600281016107f68154604087015190611d2b565b90556003810161080c8154606087015190611d2b565b905501916020835491015190611d2b565b90553360009081527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad5968602052604090206001600160a01b036013830154166000526020526040600020905490805492680100000000000000008410156109065750826108919160016108aa95018155611e09565b90919082549060031b91821b91600019901b1916179055565b6004356000526000805160206124f28339815191526020527fbd146e7cbb5d500e754c322f31ac6fff088d4b1037f7451c55520b9a5ad00cb860406001600160a01b0360148260002001541681519081526004356020820152a1005b634e487b7160e01b60009081526041600452fd5b60405162461bcd60e51b8152602060048201526025818601527f50617274794246616365743a2053656e6465722069736e27742077686974656c6044820152641a5cdd195960da1b6064820152608490fd5b60405162461bcd60e51b8152602060048201526027818601527f50617274794246616365743a205061727479412063616e27742062652070617260448201526674794220746f6f60c81b6064820152608490fd5b60005b8160ff8216106109d5575b5050610747565b6001600160a01b036109ea8260018901611e09565b90549060031b1c163314610a225760ff80821614610a0d5760ff166001016109c3565b86634e487b7160e01b60005260116004526000fd5b505050600138806109ce565b60405162461bcd60e51b8152602060048201526021818601527f50617274794246616365743a205061727479422069736e277420736f6c76656e6044820152601d60fa1b6064820152608490fd5b60405162461bcd60e51b815260206004820152601c818501527f50617274794246616365743a20496e76616c69642071756f74654964000000006044820152606490fd5b60405162461bcd60e51b815260206004820152601d818501527f50617274794246616365743a2051756f746520697320657870697265640000006044820152606490fd5b83634e487b7160e01b60005260216004526000fd5b608490602b6040519162461bcd60e51b8352602060048401528201527f50617274794246616365743a20696e73756666696369656e7420617661696c6160448201526a626c652062616c616e636560a81b6064820152fd5b60405162461bcd60e51b8152602060048201526031818501527f50617274794246616365743a20417661696c61626c652062616c616e6365206960448201527f73206c6f776572207468616e207a65726f0000000000000000000000000000006064820152608490fd5b83634e487b7160e01b60005260116004526000fd5b90610d62610d6792610c34336001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1e602052604060002090565b6001600160a01b0384166000526020526003604060002001549081610c5882611d4e565b1315610d6d57610c689150611d4e565b915b3360009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1c602052604090206001600160a01b03821660005260205261064460406000205491610cee336001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1e602052604060002090565b6001600160a01b0382166000526020526105e1604060002054610d43336001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1e602052604060002090565b6001600160a01b03841660005260205260016040600020015490611d2b565b611d5f565b9061064c565b5091610c6a565b60405162461bcd60e51b815260206004820152601d818601527f4c69624d756f6e3a2047617465776179206973206e6f742076616c69640000006044820152606490fd5b60405162461bcd60e51b8152602060048201526019818801527f4c69624d756f6e3a20545353206e6f74207665726966696564000000000000006044820152606490fd5b87634e487b7160e01b60005260416004526000fd5b602082820181015160408a84010152889650016103a8565b60405162461bcd60e51b815260206004820152601a818601527f4c69624d756f6e3a2045787069726564207369676e61747572650000000000006044820152606490fd5b9050610e8757600760ff6102c99260a01c161415386102be565b82634e487b7160e01b60005260216004526000fd5b50506000600a60ff8360a01c161415906102b8565b60405162461bcd60e51b815260206004820152601f818401527f4163636573736962696c6974793a2053686f756c6420626520706172747942006044820152606490fd5b84634e487b7160e01b60005260416004526000fd5b600080fd5b34610f0a57602080600319360112610f0a576004357f9a4861c42efbcffcc59654e070976ca1f4a2ce14007af3ccc7b4998e5b0326b25490610f5d60ff8361017e82809660a01c1615611500565b806000526000805160206124f2833981519152928381526001600160a01b0393610f9285601460406000200154163314611694565b8260005280825283604060002060148760138301541691610fe98461022d856001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f90602052604060002090565b01549061102a8883166001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f91602052604060002090565b9060005284526110418260406000205416156115f0565b60a01c16600b8110158061121e5760088214159081611248575b81611234575b5061106c9150611648565b82600052815260406000209060148201948554948560a01c1692600b84101561121e577f43991f038b9f0ae4f9909dade97fec1b0c77ba32582ee8a26fc4c8cf82fb839e967f12f926682e9716435703a506b436993346a19a8d2f4378b264fee4c5a87f34a260406112139481996110e8600260039a14611734565b42601a8701558860a01b9060ff60a01b191617845561118981601387019561114e88611149848a54166001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1a602052604060002090565b611d78565b5054166001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1d602052604060002090565b81855416600052875261119f8583600020611d78565b506111a989612034565b936111e9828254166001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb19602052604060002090565b6111f4868254611d2b565b90555416928151908152600287820152a261120e81611fdb565b611e37565b8351928352820152a1005b634e487b7160e01b600052602160045260246000fd5b905061121e57600761106c91141587611061565b5050600a811415600061105b565b34610f0a57602080600319360112610f0a576004356112a160ff7f9a4861c42efbcffcc59654e070976ca1f4a2ce14007af3ccc7b4998e5b0326b25461017e828260a01c1615611500565b8060005260ff6000805160206124f28339815191528084526001600160a01b03906112d782601460406000200154163314611694565b836000528452604060002061136c6014836013840154169261132f8661022d866001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f90602052604060002090565b01549283166001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f91602052604060002090565b9060005284526113838260406000205416156115f0565b60a01c16600b8110158061121e576008821415908161144f575b8161143b575b506113ae9150611648565b6113b781611780565b91600b83101561121e57600983036113fa57916040917f74d402b085f265915a355c4518ab27527803e4130516698dcabc84e215b2994d938351928352820152a1005b911561140257005b7f5f1255d6db4923f0a48e5c6a465dd7510bfccfdc6128e4a7205d0cf5dd815072916060916040519133835282015260006040820152a1005b905061121e5760076113ae911415846113a3565b5050600a811415600061139d565b90601f8019910116810190811067ffffffffffffffff82111761147f57604052565b634e487b7160e01b600052604160045260246000fd5b81601f82011215610f0a5780359067ffffffffffffffff821161147f57604051926114ca601f8401601f19166020018561145d565b82845260208383010111610f0a57816000926020809301838601378301015290565b35906001600160a01b0382168203610f0a57565b1561150757565b60405162461bcd60e51b815260206004820152601760248201527f5061757361626c653a20476c6f62616c207061757365640000000000000000006044820152606490fd5b1561155357565b60405162461bcd60e51b815260206004820152601f60248201527f5061757361626c653a2050617274794220616374696f6e7320706175736564006044820152606490fd5b1561159f57565b60405162461bcd60e51b815260206004820152602360248201527f4163636573736962696c6974793a205061727479412069736e277420736f6c76604482015262195b9d60ea1b6064820152608490fd5b156115f757565b60405162461bcd60e51b815260206004820152602360248201527f4163636573736962696c6974793a205061727479422069736e277420736f6c76604482015262195b9d60ea1b6064820152608490fd5b1561164f57565b60405162461bcd60e51b815260206004820152601c60248201527f4163636573736962696c6974793a20496e76616c6964207374617465000000006044820152606490fd5b1561169b57565b60405162461bcd60e51b815260206004820152602860248201527f4163636573736962696c6974793a2053686f756c6420626520706172747942206044820152676f662071756f746560c01b6064820152608490fd5b906040516080810181811067ffffffffffffffff82111761147f576040526060600382948054845260018101546020850152600281015460408501520154910152565b1561173b57565b60405162461bcd60e51b815260206004820152601a60248201527f50617274794246616365743a20496e76616c69642073746174650000000000006044820152606490fd5b60008181526000805160206124f2833981519152916020918383526040938482206014810190815460ff8160a01c16600b811015611d175760016117c49114611734565b601c820154421115611c825750505081928252835283812091601c830154421115611c3e57601483019485549260ff8460a01c1692600b8410159485611a7f57841594859686159687611c32575b818115611c22575b8115611c12575b8115611c02575b5015611bbe5760138901966001600160a01b03988989541660ff61187e826001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f90602052604060002090565b5416611b7a576118c28b87166001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f91602052604060002090565b9088528c5260ff8888205416611b365782611b225790611b16575b818115611af2575b5015611a93575050505042601a86015561193885611149868654166001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1a602052604060002090565b506119438554612034565b611982858554166001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb19602052604060002090565b61198d828254611d2b565b90557f12f926682e9716435703a506b436993346a19a8d2f4378b264fee4c5a87f34a2838686541692815190815260028a820152a26119cb85611fdb565b86549260ff8460a01c16600b811015611a7f5760018114908115611a74575b50611a0f575b5050855460ff60a01b1916600960a01b17909555506009949350505050565b611a689685611a56611a62978997166001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1d602052604060002090565b92541683525220611d78565b50611e37565b388080808080806119f0565b6002915014386119ea565b634e487b7160e01b83526021600452602483fd5b9396509350959350969550611a7f5760058114908115611ae7575b50611abb575b5050505090565b42601a820155601681018290556017015560ff60a01b1916600160a21b17905550600438808080611ab4565b600691501438611aae565b9050611b025760028214816118e5565b634e487b7160e01b85526021600452602485fd5b505083600182146118dd565b634e487b7160e01b87526021600452602487fd5b875162461bcd60e51b8152600481018d9052601e60248201527f4c696251756f74653a205061727479422069736e277420736f6c76656e7400006044820152606490fd5b885162461bcd60e51b8152600481018e9052601e60248201527f4c696251756f74653a205061727479412069736e277420736f6c76656e7400006044820152606490fd5b855162461bcd60e51b8152600481018b9052601760248201527f4c696251756f74653a20496e76616c69642073746174650000000000000000006044820152606490fd5b9050611b02576006821481611828565b9050611b02576005821481611821565b9050611b0257600182148161181a565b50508360028214611812565b845162461bcd60e51b815260048101859052601d60248201527f4c696251756f74653a2051756f74652069736e277420657870697265640000006044820152606490fd5b611cf99550611a62935081949791929642601a85015560ff60a01b1982168855611ce86001600160a01b038093166001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1d602052604060002090565b916013850154168952528620611d78565b805473ffffffffffffffffffffffffffffffffffffffff1916905590565b634e487b7160e01b86526021600452602486fd5b91908201809211611d3857565b634e487b7160e01b600052601160045260246000fd5b600160ff1b8114611d385760000390565b81810392916000138015828513169184121617611d3857565b90600e611d8591016116f1565b611d928254825190611dda565b825560028201611da88154604084015190611dda565b905560038201611dbe8154606084015190611dda565b9055611dd560018301916020835491015190611dda565b905590565b91908203918211611d3857565b611e06906020611dfd8251606084015190611d2b565b91015190611d2b565b90565b8054821015611e215760005260206000200190600090565b634e487b7160e01b600052603260045260246000fd5b611e9f906001600160a01b03611e85816014840154166001600160a01b03166000527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad5968602052604060002090565b906013830154166000526020526040600020905490611ea1565b565b90611eac9082611f7d565b6000199190828114611f38578154838101908111611d3857611efd91611ed5611edf9285611e09565b9290549185611e09565b91909260031b1c9082549060031b91821b91600019901b1916179055565b80548015611f2257820191611f128383611e09565b909182549160031b1b1916905555565b634e487b7160e01b600052603160045260246000fd5b60405162461bcd60e51b815260206004820152601860248201527f4c696251756f74653a204974656d206e6f7420466f756e6400000000000000006044820152606490fd5b91600091825b8454811015611fd05781611f978287611e09565b90549060031b1c14611fc8576000198114611fb457600101611f83565b634e487b7160e01b84526011600452602484fd5b925050915090565b505091505060001990565b611e9f906001600160a01b036013820154166000527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad59676020526040600020905490611ea1565b81810292918115918404141715611d3857565b6000526000805160206124f2833981519152602052604060002060ff600382015460081c1690600282101561121e576ec097ce7bc90715b34b9f1000000000916120ac5780601d61209f61209460086120a8950154600985015490611dda565b600684015490612021565b91015490612021565b0490565b80601d61209f6120c860086120a8950154600985015490611dda565b600784015490612021565b600581101561121e57806120e45750565b600181036121315760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606490fd5b6002810361217e5760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606490fd5b60031461218757565b60405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608490fd5b90604181511460001461220557612201916020820151906060604084015193015160001a9061220f565b9091565b5050600090600290565b939291907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a083116122a257916122669160209360405196879094939260ff6060936080840197845216602083015260408201520152565b836000948592838052039060015afa156122955781516001600160a01b0381161561228f579190565b50600190565b50604051903d90823e3d90fd5b5050509050600090600390565b9190815191602080910151928251946040809401516001600160a01b0395868216977f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a18510156124ad5770014551231950b75fc4402da1732fc9bebe19948582101561245e5789151580612455575b8061244c575b80612443575b156123ff578751938785019582875260ff60f81b8560f81b168a87015260418601526bffffffffffffffffffffffff199060601b16606185015260558452608084019484861067ffffffffffffffff87111761147f578690868a5285519020928209860391868311611d38576000966123c69460ff166123f65782601b925b0992865260ff166020860152604085015260608401526080830190565b83805203607f19019060015afa156123ec575060005116036123e757600190565b600090565b513d6000823e3d90fd5b82601c926123a9565b875162461bcd60e51b815260048101889052601660248201527f6e6f207a65726f20696e7075747320616c6c6f776564000000000000000000006044820152606490fd5b5084151561232a565b50811515612324565b5080151561231e565b875162461bcd60e51b815260048101889052602260248201527f7369676e6174757265206d7573742062652072656475636564206d6f64756c6f604482015261205160f01b6064820152608490fd5b865162461bcd60e51b815260048101879052601660248201527f5075626c69632d6b65792078203e3d2048414c465f51000000000000000000006044820152606490fdfe6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad5964a164736f6c6343000812000a
Deployed Bytecode
0x6080604052600436101561001257600080fd5b60003560e01c80631bc1045614611256578063606a243b14610f0f5763ca6b88de1461003d57600080fd5b34610f0a57600319604036820112610f0a57602490813567ffffffffffffffff8111610f0a5760e081360392830112610f0a576040519160a0830183811067ffffffffffffffff821117610ef557604052816004013567ffffffffffffffff8111610f0a576100b29060043691850101611495565b83528382013560208401526044820135604084015260648201359067ffffffffffffffff8211610f0a576100ee60609260043691860101611495565b848301526083190112610f0a57604051906060820182811067ffffffffffffffff821117610ef55761013e9160c4916040526084810135845261013360a482016114ec565b6020850152016114ec565b6040820152608082015261018860ff7f9a4861c42efbcffcc59654e070976ca1f4a2ce14007af3ccc7b4998e5b0326b25461017e828260a01c1615611500565b60b81c161561154c565b336000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f8f60205260ff6040600020541615610eb1576004356000526000805160206124f2833981519152602052604060002060146001600160a01b036013830154169161023560ff61022d856001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f90602052604060002090565b541615611598565b01549061027d6001600160a01b0383166001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f91602052604060002090565b9060005260205261029660ff60406000205416156115f0565b600b60ff8260a01c16101580610b0457600860ff8360a01c1614159081610e9c575b81610e6d575b506102c99150611648565b6004356000526000805160206124f283398151915260205260406000209060138201549061031d60208201517f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79a5490611d2b565b4211610e29577f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79d54815190336000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb2160205260406000206001600160a01b038516600052602052604060002054906040840151602085015190604051948593602085015280519060005b828110610e115750509161040b9491849360fc9501923060601b60408501523360601b60548501526bffffffffffffffffffffffff198a60601b166068850152607c840152609c83015260bc8201524660dc8201520360dc81018452018261145d565b6020815191012060808201519060608301519160405180604081011067ffffffffffffffff604083011117610dfc5761049991604082016040527f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79e54825260ff7f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d79f54166020830152836122af565b15610db8576104df916104d7917f19457468657265756d205369676e6564204d6573736167653a0a333200000000600052601c52603c6000206121d7565b9190916120d3565b6001600160a01b03807f27436b8f74caac3ab9de71cfb0971b5326ec400f880709c18d86f9d76139d7a05416911603610d74576040015160008112610bf0573360009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1c602052604090206001600160a01b03831660005260205260406000205460008282019283129112908015821691151617610bdb5761064461064a926105bc336001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1e602052604060002090565b6001600160a01b0382166000526020526105e16105dc60406000206116f1565b611de7565b906001600160a01b03610626336001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1d602052604060002090565b911660005260205261063e6105dc60406000206116f1565b90611d2b565b90611d5f565b905b60008212610b71576105dc600e61066392016116f1565b11610b19576004356000526000805160206124f28339815191526020526040600020601481015460ff8160a01c16600b811015610b04576106a49015611734565b601c8201544211610ac0577f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad596d5460043511610a7c573360009081527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f9160205260409020906001600160a01b03601384015416918260005260205260ff60406000205416610a2e576000600184015480156000146109c057505081331461096c5760015b1561091a5742601a84015574ffffffffffffffffffffffffffffffffffffffffff191633908117600160a01b1760148401556107b5906001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1d602052604060002090565b90600052602052604060002061081d60016107d2600e85016116f1565b926107e08154855190611d2b565b8155600281016107f68154604087015190611d2b565b90556003810161080c8154606087015190611d2b565b905501916020835491015190611d2b565b90553360009081527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad5968602052604090206001600160a01b036013830154166000526020526040600020905490805492680100000000000000008410156109065750826108919160016108aa95018155611e09565b90919082549060031b91821b91600019901b1916179055565b6004356000526000805160206124f28339815191526020527fbd146e7cbb5d500e754c322f31ac6fff088d4b1037f7451c55520b9a5ad00cb860406001600160a01b0360148260002001541681519081526004356020820152a1005b634e487b7160e01b60009081526041600452fd5b60405162461bcd60e51b8152602060048201526025818601527f50617274794246616365743a2053656e6465722069736e27742077686974656c6044820152641a5cdd195960da1b6064820152608490fd5b60405162461bcd60e51b8152602060048201526027818601527f50617274794246616365743a205061727479412063616e27742062652070617260448201526674794220746f6f60c81b6064820152608490fd5b60005b8160ff8216106109d5575b5050610747565b6001600160a01b036109ea8260018901611e09565b90549060031b1c163314610a225760ff80821614610a0d5760ff166001016109c3565b86634e487b7160e01b60005260116004526000fd5b505050600138806109ce565b60405162461bcd60e51b8152602060048201526021818601527f50617274794246616365743a205061727479422069736e277420736f6c76656e6044820152601d60fa1b6064820152608490fd5b60405162461bcd60e51b815260206004820152601c818501527f50617274794246616365743a20496e76616c69642071756f74654964000000006044820152606490fd5b60405162461bcd60e51b815260206004820152601d818501527f50617274794246616365743a2051756f746520697320657870697265640000006044820152606490fd5b83634e487b7160e01b60005260216004526000fd5b608490602b6040519162461bcd60e51b8352602060048401528201527f50617274794246616365743a20696e73756666696369656e7420617661696c6160448201526a626c652062616c616e636560a81b6064820152fd5b60405162461bcd60e51b8152602060048201526031818501527f50617274794246616365743a20417661696c61626c652062616c616e6365206960448201527f73206c6f776572207468616e207a65726f0000000000000000000000000000006064820152608490fd5b83634e487b7160e01b60005260116004526000fd5b90610d62610d6792610c34336001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1e602052604060002090565b6001600160a01b0384166000526020526003604060002001549081610c5882611d4e565b1315610d6d57610c689150611d4e565b915b3360009081527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1c602052604090206001600160a01b03821660005260205261064460406000205491610cee336001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1e602052604060002090565b6001600160a01b0382166000526020526105e1604060002054610d43336001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1e602052604060002090565b6001600160a01b03841660005260205260016040600020015490611d2b565b611d5f565b9061064c565b5091610c6a565b60405162461bcd60e51b815260206004820152601d818601527f4c69624d756f6e3a2047617465776179206973206e6f742076616c69640000006044820152606490fd5b60405162461bcd60e51b8152602060048201526019818801527f4c69624d756f6e3a20545353206e6f74207665726966696564000000000000006044820152606490fd5b87634e487b7160e01b60005260416004526000fd5b602082820181015160408a84010152889650016103a8565b60405162461bcd60e51b815260206004820152601a818601527f4c69624d756f6e3a2045787069726564207369676e61747572650000000000006044820152606490fd5b9050610e8757600760ff6102c99260a01c161415386102be565b82634e487b7160e01b60005260216004526000fd5b50506000600a60ff8360a01c161415906102b8565b60405162461bcd60e51b815260206004820152601f818401527f4163636573736962696c6974793a2053686f756c6420626520706172747942006044820152606490fd5b84634e487b7160e01b60005260416004526000fd5b600080fd5b34610f0a57602080600319360112610f0a576004357f9a4861c42efbcffcc59654e070976ca1f4a2ce14007af3ccc7b4998e5b0326b25490610f5d60ff8361017e82809660a01c1615611500565b806000526000805160206124f2833981519152928381526001600160a01b0393610f9285601460406000200154163314611694565b8260005280825283604060002060148760138301541691610fe98461022d856001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f90602052604060002090565b01549061102a8883166001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f91602052604060002090565b9060005284526110418260406000205416156115f0565b60a01c16600b8110158061121e5760088214159081611248575b81611234575b5061106c9150611648565b82600052815260406000209060148201948554948560a01c1692600b84101561121e577f43991f038b9f0ae4f9909dade97fec1b0c77ba32582ee8a26fc4c8cf82fb839e967f12f926682e9716435703a506b436993346a19a8d2f4378b264fee4c5a87f34a260406112139481996110e8600260039a14611734565b42601a8701558860a01b9060ff60a01b191617845561118981601387019561114e88611149848a54166001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1a602052604060002090565b611d78565b5054166001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1d602052604060002090565b81855416600052875261119f8583600020611d78565b506111a989612034565b936111e9828254166001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb19602052604060002090565b6111f4868254611d2b565b90555416928151908152600287820152a261120e81611fdb565b611e37565b8351928352820152a1005b634e487b7160e01b600052602160045260246000fd5b905061121e57600761106c91141587611061565b5050600a811415600061105b565b34610f0a57602080600319360112610f0a576004356112a160ff7f9a4861c42efbcffcc59654e070976ca1f4a2ce14007af3ccc7b4998e5b0326b25461017e828260a01c1615611500565b8060005260ff6000805160206124f28339815191528084526001600160a01b03906112d782601460406000200154163314611694565b836000528452604060002061136c6014836013840154169261132f8661022d866001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f90602052604060002090565b01549283166001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f91602052604060002090565b9060005284526113838260406000205416156115f0565b60a01c16600b8110158061121e576008821415908161144f575b8161143b575b506113ae9150611648565b6113b781611780565b91600b83101561121e57600983036113fa57916040917f74d402b085f265915a355c4518ab27527803e4130516698dcabc84e215b2994d938351928352820152a1005b911561140257005b7f5f1255d6db4923f0a48e5c6a465dd7510bfccfdc6128e4a7205d0cf5dd815072916060916040519133835282015260006040820152a1005b905061121e5760076113ae911415846113a3565b5050600a811415600061139d565b90601f8019910116810190811067ffffffffffffffff82111761147f57604052565b634e487b7160e01b600052604160045260246000fd5b81601f82011215610f0a5780359067ffffffffffffffff821161147f57604051926114ca601f8401601f19166020018561145d565b82845260208383010111610f0a57816000926020809301838601378301015290565b35906001600160a01b0382168203610f0a57565b1561150757565b60405162461bcd60e51b815260206004820152601760248201527f5061757361626c653a20476c6f62616c207061757365640000000000000000006044820152606490fd5b1561155357565b60405162461bcd60e51b815260206004820152601f60248201527f5061757361626c653a2050617274794220616374696f6e7320706175736564006044820152606490fd5b1561159f57565b60405162461bcd60e51b815260206004820152602360248201527f4163636573736962696c6974793a205061727479412069736e277420736f6c76604482015262195b9d60ea1b6064820152608490fd5b156115f757565b60405162461bcd60e51b815260206004820152602360248201527f4163636573736962696c6974793a205061727479422069736e277420736f6c76604482015262195b9d60ea1b6064820152608490fd5b1561164f57565b60405162461bcd60e51b815260206004820152601c60248201527f4163636573736962696c6974793a20496e76616c6964207374617465000000006044820152606490fd5b1561169b57565b60405162461bcd60e51b815260206004820152602860248201527f4163636573736962696c6974793a2053686f756c6420626520706172747942206044820152676f662071756f746560c01b6064820152608490fd5b906040516080810181811067ffffffffffffffff82111761147f576040526060600382948054845260018101546020850152600281015460408501520154910152565b1561173b57565b60405162461bcd60e51b815260206004820152601a60248201527f50617274794246616365743a20496e76616c69642073746174650000000000006044820152606490fd5b60008181526000805160206124f2833981519152916020918383526040938482206014810190815460ff8160a01c16600b811015611d175760016117c49114611734565b601c820154421115611c825750505081928252835283812091601c830154421115611c3e57601483019485549260ff8460a01c1692600b8410159485611a7f57841594859686159687611c32575b818115611c22575b8115611c12575b8115611c02575b5015611bbe5760138901966001600160a01b03988989541660ff61187e826001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f90602052604060002090565b5416611b7a576118c28b87166001600160a01b03166000527f0e82e3bc6a0f65adfd723bc988cd4fad093e63c62b76ca41e910a3b2adf78f91602052604060002090565b9088528c5260ff8888205416611b365782611b225790611b16575b818115611af2575b5015611a93575050505042601a86015561193885611149868654166001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1a602052604060002090565b506119438554612034565b611982858554166001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb19602052604060002090565b61198d828254611d2b565b90557f12f926682e9716435703a506b436993346a19a8d2f4378b264fee4c5a87f34a2838686541692815190815260028a820152a26119cb85611fdb565b86549260ff8460a01c16600b811015611a7f5760018114908115611a74575b50611a0f575b5050855460ff60a01b1916600960a01b17909555506009949350505050565b611a689685611a56611a62978997166001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1d602052604060002090565b92541683525220611d78565b50611e37565b388080808080806119f0565b6002915014386119ea565b634e487b7160e01b83526021600452602483fd5b9396509350959350969550611a7f5760058114908115611ae7575b50611abb575b5050505090565b42601a820155601681018290556017015560ff60a01b1916600160a21b17905550600438808080611ab4565b600691501438611aae565b9050611b025760028214816118e5565b634e487b7160e01b85526021600452602485fd5b505083600182146118dd565b634e487b7160e01b87526021600452602487fd5b875162461bcd60e51b8152600481018d9052601e60248201527f4c696251756f74653a205061727479422069736e277420736f6c76656e7400006044820152606490fd5b885162461bcd60e51b8152600481018e9052601e60248201527f4c696251756f74653a205061727479412069736e277420736f6c76656e7400006044820152606490fd5b855162461bcd60e51b8152600481018b9052601760248201527f4c696251756f74653a20496e76616c69642073746174650000000000000000006044820152606490fd5b9050611b02576006821481611828565b9050611b02576005821481611821565b9050611b0257600182148161181a565b50508360028214611812565b845162461bcd60e51b815260048101859052601d60248201527f4c696251756f74653a2051756f74652069736e277420657870697265640000006044820152606490fd5b611cf99550611a62935081949791929642601a85015560ff60a01b1982168855611ce86001600160a01b038093166001600160a01b03166000527fdd1d6d04e1f24037b02215b0852708bab55d9f1305ee6cb777ad46ae2573bb1d602052604060002090565b916013850154168952528620611d78565b805473ffffffffffffffffffffffffffffffffffffffff1916905590565b634e487b7160e01b86526021600452602486fd5b91908201809211611d3857565b634e487b7160e01b600052601160045260246000fd5b600160ff1b8114611d385760000390565b81810392916000138015828513169184121617611d3857565b90600e611d8591016116f1565b611d928254825190611dda565b825560028201611da88154604084015190611dda565b905560038201611dbe8154606084015190611dda565b9055611dd560018301916020835491015190611dda565b905590565b91908203918211611d3857565b611e06906020611dfd8251606084015190611d2b565b91015190611d2b565b90565b8054821015611e215760005260206000200190600090565b634e487b7160e01b600052603260045260246000fd5b611e9f906001600160a01b03611e85816014840154166001600160a01b03166000527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad5968602052604060002090565b906013830154166000526020526040600020905490611ea1565b565b90611eac9082611f7d565b6000199190828114611f38578154838101908111611d3857611efd91611ed5611edf9285611e09565b9290549185611e09565b91909260031b1c9082549060031b91821b91600019901b1916179055565b80548015611f2257820191611f128383611e09565b909182549160031b1b1916905555565b634e487b7160e01b600052603160045260246000fd5b60405162461bcd60e51b815260206004820152601860248201527f4c696251756f74653a204974656d206e6f7420466f756e6400000000000000006044820152606490fd5b91600091825b8454811015611fd05781611f978287611e09565b90549060031b1c14611fc8576000198114611fb457600101611f83565b634e487b7160e01b84526011600452602484fd5b925050915090565b505091505060001990565b611e9f906001600160a01b036013820154166000527f6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad59676020526040600020905490611ea1565b81810292918115918404141715611d3857565b6000526000805160206124f2833981519152602052604060002060ff600382015460081c1690600282101561121e576ec097ce7bc90715b34b9f1000000000916120ac5780601d61209f61209460086120a8950154600985015490611dda565b600684015490612021565b91015490612021565b0490565b80601d61209f6120c860086120a8950154600985015490611dda565b600784015490612021565b600581101561121e57806120e45750565b600181036121315760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606490fd5b6002810361217e5760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606490fd5b60031461218757565b60405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608490fd5b90604181511460001461220557612201916020820151906060604084015193015160001a9061220f565b9091565b5050600090600290565b939291907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a083116122a257916122669160209360405196879094939260ff6060936080840197845216602083015260408201520152565b836000948592838052039060015afa156122955781516001600160a01b0381161561228f579190565b50600190565b50604051903d90823e3d90fd5b5050509050600090600390565b9190815191602080910151928251946040809401516001600160a01b0395868216977f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a18510156124ad5770014551231950b75fc4402da1732fc9bebe19948582101561245e5789151580612455575b8061244c575b80612443575b156123ff578751938785019582875260ff60f81b8560f81b168a87015260418601526bffffffffffffffffffffffff199060601b16606185015260558452608084019484861067ffffffffffffffff87111761147f578690868a5285519020928209860391868311611d38576000966123c69460ff166123f65782601b925b0992865260ff166020860152604085015260608401526080830190565b83805203607f19019060015afa156123ec575060005116036123e757600190565b600090565b513d6000823e3d90fd5b82601c926123a9565b875162461bcd60e51b815260048101889052601660248201527f6e6f207a65726f20696e7075747320616c6c6f776564000000000000000000006044820152606490fd5b5084151561232a565b50811515612324565b5080151561231e565b875162461bcd60e51b815260048101889052602260248201527f7369676e6174757265206d7573742062652072656475636564206d6f64756c6f604482015261205160f01b6064820152608490fd5b865162461bcd60e51b815260048101879052601660248201527f5075626c69632d6b65792078203e3d2048414c465f51000000000000000000006044820152606490fdfe6e3ce8ccb9896cca9f260ce5aafef55eeba408a86f8fca5b71d23e31e7ad5964a164736f6c6343000812000a
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in S
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
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.