Overview
S Balance
S Value
$0.00More Info
Private Name Tags
ContractCreator
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
RfqProxyLOB
Compiler Version
v0.8.28+commit.7893614a
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1 // (c) Long Gamma Labs, 2024. pragma solidity ^0.8.28; import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { IERC20Permit } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol"; import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { IPyth } from "@pythnetwork/pyth-sdk-solidity/IPyth.sol"; import { FixedPointMathLib } from "@solmate/src/utils/FixedPointMathLib.sol"; import { ILPManager } from "./interfaces/ILPManager.sol"; import { IOnchainLOB } from "./interfaces/IOnchainLOB.sol"; import { IProxyLOB } from "./interfaces/IProxyLOB.sol"; import { Ecdsa } from "./utils/Ecdsa.sol"; import { ProxyLOB } from "./ProxyLOB.sol"; import { ClientOrder, RfqOrderLib } from "./utils/RfqOrderLib.sol"; import { ErrorReporter } from "./ErrorReporter.sol"; import { PythPriceHelper } from "./utils/PythPriceHelper.sol"; contract RfqProxyLOB is ReentrancyGuard, EIP712 { using FixedPointMathLib for uint256; using RfqOrderLib for ClientOrder; using SafeERC20 for IERC20; mapping (bytes32 => bool) orderHashes; IPyth immutable internal pyth; event ClientOrderPlaced( address indexed lobAddress, address indexed owner, address lpManagerAddress, address marketMaker, bool targetValueTransaction, bool isAsk, uint128 quantity, uint72 price, uint128 nonce ); constructor( address pythAddress, string memory _domainName ) EIP712(_domainName, "4") { require(pythAddress != address(0), ErrorReporter.ZeroAddress()); require(bytes(_domainName).length > 0, ErrorReporter.EmptyDomainName()); pyth = IPyth(pythAddress); } receive() external payable {} function swapWithRfqOrderWithPermit( address lpManagerAddress, uint8 lobId, uint128 quoteQty, uint72 quotePrice, bool quoteMarketOnly, bool quotePostOnly, uint256 inputAmount, ClientOrder calldata clientOrder, uint8 v, bytes32 r, bytes32 s, address inputToken, uint8 vPermit, bytes32 rPermit, bytes32 sPermit, bytes[] calldata priceUpdateData ) external payable { IERC20Permit token = IERC20Permit(inputToken); try token.permit( clientOrder.userAddress, address(this), inputAmount, clientOrder.expires, vPermit, rPermit, sPermit ) {} catch {} swapWithRfqOrder( lpManagerAddress, lobId, quoteQty, quotePrice, quoteMarketOnly, quotePostOnly, inputAmount, clientOrder, v, r, s, priceUpdateData ); } function swapWithRfqOrder( address lpManagerAddress, uint8 lobId, uint128 quoteQty, uint72 quotePrice, bool quoteMarketOnly, bool quotePostOnly, uint256 inputAmount, ClientOrder calldata clientOrder, uint8 v, bytes32 r, bytes32 s, bytes[] calldata priceUpdateData ) public payable nonReentrant { PythPriceHelper.updatePrices(pyth, priceUpdateData); ILPManager lpManager = ILPManager(payable(lpManagerAddress)); IProxyLOB proxyLOB = IProxyLOB(payable(lpManagerAddress)); require(lpManager.marketMakers(msg.sender), ErrorReporter.InvalidTrader()); address userAddress = clientOrder.userAddress; require(userAddress != address(0), ErrorReporter.ZeroAddress()); // checking signature bytes32 orderHash = clientOrder.hash(_domainSeparator()); address signer = Ecdsa.recover(orderHash, v, r, s); require(signer == userAddress, ErrorReporter.InvalidSignature()); (address lobAddress,,,,) = lpManager.lobs(lobId); require(lobAddress == clientOrder.lobAddress, ErrorReporter.InvalidLobAddress()); IOnchainLOB lob = IOnchainLOB(payable(lobAddress)); require(!orderHashes[orderHash], ErrorReporter.OrderAlreadyUsed()); orderHashes[orderHash] = true; uint256 expires = clientOrder.expires; bool clientIsAsk = clientOrder.isAsk; // try place maker's order uint64 makerOrderId = proxyLOB.placeOrder( lobId, !clientIsAsk, quoteQty, quotePrice, type(uint128).max, quoteMarketOnly, quotePostOnly, expires, new bytes[](0) ); (,, address tokenX, address tokenY,,,,,,,,,) = lob.getConfig(); IERC20 transferToken = clientIsAsk ? IERC20(tokenX) : IERC20(tokenY); transferToken.safeTransferFrom(userAddress, address(this), inputAmount); transferToken.approve(lobAddress, inputAmount); uint128 clientOrderAmount = clientOrder.orderAmount; uint72 clientPrice = clientOrder.price; bool clientTargetValueTransaction = clientOrder.targetValueTransaction; emit ClientOrderPlaced( lobAddress, userAddress, lpManagerAddress, msg.sender, clientTargetValueTransaction, clientIsAsk, clientOrderAmount, clientPrice, clientOrder.nonce ); if (clientTargetValueTransaction) { lob.placeMarketOrderWithTargetValue( clientIsAsk, clientOrderAmount, clientPrice, type(uint128).max, true, expires ); } else { lob.placeOrder( clientIsAsk, clientOrderAmount, clientPrice, type(uint128).max, true, false, true, expires ); } uint256 newBalanceTokenX = IERC20(tokenX).balanceOf(address(this)); if (newBalanceTokenX > 0) { IERC20(tokenX).safeTransfer(userAddress, newBalanceTokenX); } uint256 newBalanceTokenY = IERC20(tokenY).balanceOf(address(this)); if (newBalanceTokenY > 0) { IERC20(tokenY).safeTransfer(userAddress, newBalanceTokenY); } uint256 contractBalance = address(this).balance; if (contractBalance > 0) { PythPriceHelper.sendGASToken(userAddress, contractBalance); } // try claim maker's order if (makerOrderId > 0) { proxyLOB.claimOrder(lobId, makerOrderId, false, expires); } } /// @notice Returns the domain separator used in EIP-712 signatures. /// @dev Delegates to OpenZeppelin's EIP712Upgradeable implementation. /// @return bytes32 The domain separator hash. function _domainSeparator() internal view returns (bytes32) { return _domainSeparatorV4(); } /// @notice Returns the contract's domain separator for EIP-712 signatures. /// @return bytes32 The domain separator hash. function DOMAIN_SEPARATOR() external view returns (bytes32) { return _domainSeparatorV4(); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/EIP712.sol) pragma solidity ^0.8.20; import {MessageHashUtils} from "./MessageHashUtils.sol"; import {ShortStrings, ShortString} from "../ShortStrings.sol"; import {IERC5267} from "../../interfaces/IERC5267.sol"; /** * @dev https://eips.ethereum.org/EIPS/eip-712[EIP-712] is a standard for hashing and signing of typed structured data. * * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`. * * This contract implements the EIP-712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA * ({_hashTypedDataV4}). * * The implementation of the domain separator was designed to be as efficient as possible while still properly updating * the chain id to protect against replay attacks on an eventual fork of the chain. * * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask]. * * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the * separator from the immutable values, which is cheaper than accessing a cached version in cold storage. * * @custom:oz-upgrades-unsafe-allow state-variable-immutable */ abstract contract EIP712 is IERC5267 { using ShortStrings for *; bytes32 private constant TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to // invalidate the cached domain separator if the chain id changes. bytes32 private immutable _cachedDomainSeparator; uint256 private immutable _cachedChainId; address private immutable _cachedThis; bytes32 private immutable _hashedName; bytes32 private immutable _hashedVersion; ShortString private immutable _name; ShortString private immutable _version; string private _nameFallback; string private _versionFallback; /** * @dev Initializes the domain separator and parameter caches. * * The meaning of `name` and `version` is specified in * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP-712]: * * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol. * - `version`: the current major version of the signing domain. * * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart * contract upgrade]. */ constructor(string memory name, string memory version) { _name = name.toShortStringWithFallback(_nameFallback); _version = version.toShortStringWithFallback(_versionFallback); _hashedName = keccak256(bytes(name)); _hashedVersion = keccak256(bytes(version)); _cachedChainId = block.chainid; _cachedDomainSeparator = _buildDomainSeparator(); _cachedThis = address(this); } /** * @dev Returns the domain separator for the current chain. */ function _domainSeparatorV4() internal view returns (bytes32) { if (address(this) == _cachedThis && block.chainid == _cachedChainId) { return _cachedDomainSeparator; } else { return _buildDomainSeparator(); } } function _buildDomainSeparator() private view returns (bytes32) { return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this))); } /** * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this * function returns the hash of the fully encoded EIP712 message for this domain. * * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example: * * ```solidity * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( * keccak256("Mail(address to,string contents)"), * mailTo, * keccak256(bytes(mailContents)) * ))); * address signer = ECDSA.recover(digest, signature); * ``` */ function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) { return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash); } /** * @dev See {IERC-5267}. */ function eip712Domain() public view virtual returns ( bytes1 fields, string memory name, string memory version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] memory extensions ) { return ( hex"0f", // 01111 _EIP712Name(), _EIP712Version(), block.chainid, address(this), bytes32(0), new uint256[](0) ); } /** * @dev The name parameter for the EIP712 domain. * * NOTE: By default this function reads _name which is an immutable value. * It only reads from storage if necessary (in case the value is too large to fit in a ShortString). */ // solhint-disable-next-line func-name-mixedcase function _EIP712Name() internal view returns (string memory) { return _name.toStringWithFallback(_nameFallback); } /** * @dev The version parameter for the EIP712 domain. * * NOTE: By default this function reads _version which is an immutable value. * It only reads from storage if necessary (in case the value is too large to fit in a ShortString). */ // solhint-disable-next-line func-name-mixedcase function _EIP712Version() internal view returns (string memory) { return _version.toStringWithFallback(_versionFallback); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC-20 standard as defined in the ERC. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the value of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the value of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves a `value` amount of tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 value) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets a `value` amount of tokens as the allowance of `spender` over the * caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the * allowance mechanism. `value` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 value) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC-20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[ERC-2612]. * * Adds the {permit} method, which can be used to change an account's ERC-20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. * * ==== Security Considerations * * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be * considered as an intention to spend the allowance in any specific way. The second is that because permits have * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be * generally recommended is: * * ```solidity * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public { * try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {} * doThing(..., value); * } * * function doThing(..., uint256 value) public { * token.safeTransferFrom(msg.sender, address(this), value); * ... * } * ``` * * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also * {SafeERC20-safeTransferFrom}). * * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so * contracts should have entry points that don't rely on permit. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. * * CAUTION: See Security Considerations above. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol) pragma solidity ^0.8.20; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at, * consider using {ReentrancyGuardTransient} instead. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant NOT_ENTERED = 1; uint256 private constant ENTERED = 2; uint256 private _status; /** * @dev Unauthorized reentrant call. */ error ReentrancyGuardReentrantCall(); constructor() { _status = NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be NOT_ENTERED if (_status == ENTERED) { revert ReentrancyGuardReentrantCall(); } // Any calls to nonReentrant after this point will fail _status = ENTERED; } function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = NOT_ENTERED; } /** * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a * `nonReentrant` function in the call stack. */ function _reentrancyGuardEntered() internal view returns (bool) { return _status == ENTERED; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "../IERC20.sol"; import {IERC1363} from "../../../interfaces/IERC1363.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC-20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { /** * @dev An operation with an ERC-20 token failed. */ error SafeERC20FailedOperation(address token); /** * @dev Indicates a failed `decreaseAllowance` request. */ error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease); /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value))); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value))); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. * * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client" * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior. */ function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); forceApprove(token, spender, oldAllowance + value); } /** * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no * value, non-reverting calls are assumed to be successful. * * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client" * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior. */ function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal { unchecked { uint256 currentAllowance = token.allowance(address(this), spender); if (currentAllowance < requestedDecrease) { revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease); } forceApprove(token, spender, currentAllowance - requestedDecrease); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval * to be set to zero before setting it to a non-zero value, such as USDT. * * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being * set here. */ function forceApprove(IERC20 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value)); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0))); _callOptionalReturn(token, approvalCall); } } /** * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when * targeting contracts. * * Reverts if the returned value is other than `true`. */ function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal { if (to.code.length == 0) { safeTransfer(token, to, value); } else if (!token.transferAndCall(to, value, data)) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when * targeting contracts. * * Reverts if the returned value is other than `true`. */ function transferFromAndCallRelaxed( IERC1363 token, address from, address to, uint256 value, bytes memory data ) internal { if (to.code.length == 0) { safeTransferFrom(token, from, to, value); } else if (!token.transferFromAndCall(from, to, value, data)) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when * targeting contracts. * * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}. * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall} * once without retrying, and relies on the returned value to be true. * * Reverts if the returned value is other than `true`. */ function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal { if (to.code.length == 0) { forceApprove(token, to, value); } else if (!token.approveAndCall(to, value, data)) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements. */ function _callOptionalReturn(IERC20 token, bytes memory data) private { uint256 returnSize; uint256 returnValue; assembly ("memory-safe") { let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20) // bubble errors if iszero(success) { let ptr := mload(0x40) returndatacopy(ptr, 0, returndatasize()) revert(ptr, returndatasize()) } returnSize := returndatasize() returnValue := mload(0) } if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) { bool success; uint256 returnSize; uint256 returnValue; assembly ("memory-safe") { success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20) returnSize := returndatasize() returnValue := mload(0) } return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1); } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.0; import "./PythStructs.sol"; import "./IPythEvents.sol"; /// @title Consume prices from the Pyth Network (https://pyth.network/). /// @dev Please refer to the guidance at https://docs.pyth.network/consumers/best-practices for how to consume prices safely. /// @author Pyth Data Association interface IPyth is IPythEvents { /// @notice Returns the period (in seconds) that a price feed is considered valid since its publish time function getValidTimePeriod() external view returns (uint validTimePeriod); /// @notice Returns the price and confidence interval. /// @dev Reverts if the price has not been updated within the last `getValidTimePeriod()` seconds. /// @param id The Pyth Price Feed ID of which to fetch the price and confidence interval. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getPrice( bytes32 id ) external view returns (PythStructs.Price memory price); /// @notice Returns the exponentially-weighted moving average price and confidence interval. /// @dev Reverts if the EMA price is not available. /// @param id The Pyth Price Feed ID of which to fetch the EMA price and confidence interval. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getEmaPrice( bytes32 id ) external view returns (PythStructs.Price memory price); /// @notice Returns the price of a price feed without any sanity checks. /// @dev This function returns the most recent price update in this contract without any recency checks. /// This function is unsafe as the returned price update may be arbitrarily far in the past. /// /// Users of this function should check the `publishTime` in the price to ensure that the returned price is /// sufficiently recent for their application. If you are considering using this function, it may be /// safer / easier to use either `getPrice` or `getPriceNoOlderThan`. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getPriceUnsafe( bytes32 id ) external view returns (PythStructs.Price memory price); /// @notice Returns the price that is no older than `age` seconds of the current time. /// @dev This function is a sanity-checked version of `getPriceUnsafe` which is useful in /// applications that require a sufficiently-recent price. Reverts if the price wasn't updated sufficiently /// recently. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getPriceNoOlderThan( bytes32 id, uint age ) external view returns (PythStructs.Price memory price); /// @notice Returns the exponentially-weighted moving average price of a price feed without any sanity checks. /// @dev This function returns the same price as `getEmaPrice` in the case where the price is available. /// However, if the price is not recent this function returns the latest available price. /// /// The returned price can be from arbitrarily far in the past; this function makes no guarantees that /// the returned price is recent or useful for any particular application. /// /// Users of this function should check the `publishTime` in the price to ensure that the returned price is /// sufficiently recent for their application. If you are considering using this function, it may be /// safer / easier to use either `getEmaPrice` or `getEmaPriceNoOlderThan`. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getEmaPriceUnsafe( bytes32 id ) external view returns (PythStructs.Price memory price); /// @notice Returns the exponentially-weighted moving average price that is no older than `age` seconds /// of the current time. /// @dev This function is a sanity-checked version of `getEmaPriceUnsafe` which is useful in /// applications that require a sufficiently-recent price. Reverts if the price wasn't updated sufficiently /// recently. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getEmaPriceNoOlderThan( bytes32 id, uint age ) external view returns (PythStructs.Price memory price); /// @notice Update price feeds with given update messages. /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling /// `getUpdateFee` with the length of the `updateData` array. /// Prices will be updated if they are more recent than the current stored prices. /// The call will succeed even if the update is not the most recent. /// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid. /// @param updateData Array of price update data. function updatePriceFeeds(bytes[] calldata updateData) external payable; /// @notice Wrapper around updatePriceFeeds that rejects fast if a price update is not necessary. A price update is /// necessary if the current on-chain publishTime is older than the given publishTime. It relies solely on the /// given `publishTimes` for the price feeds and does not read the actual price update publish time within `updateData`. /// /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling /// `getUpdateFee` with the length of the `updateData` array. /// /// `priceIds` and `publishTimes` are two arrays with the same size that correspond to senders known publishTime /// of each priceId when calling this method. If all of price feeds within `priceIds` have updated and have /// a newer or equal publish time than the given publish time, it will reject the transaction to save gas. /// Otherwise, it calls updatePriceFeeds method to update the prices. /// /// @dev Reverts if update is not needed or the transferred fee is not sufficient or the updateData is invalid. /// @param updateData Array of price update data. /// @param priceIds Array of price ids. /// @param publishTimes Array of publishTimes. `publishTimes[i]` corresponds to known `publishTime` of `priceIds[i]` function updatePriceFeedsIfNecessary( bytes[] calldata updateData, bytes32[] calldata priceIds, uint64[] calldata publishTimes ) external payable; /// @notice Returns the required fee to update an array of price updates. /// @param updateData Array of price update data. /// @return feeAmount The required fee in Wei. function getUpdateFee( bytes[] calldata updateData ) external view returns (uint feeAmount); /// @notice Parse `updateData` and return price feeds of the given `priceIds` if they are all published /// within `minPublishTime` and `maxPublishTime`. /// /// You can use this method if you want to use a Pyth price at a fixed time and not the most recent price; /// otherwise, please consider using `updatePriceFeeds`. This method does not store the price updates on-chain. /// /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling /// `getUpdateFee` with the length of the `updateData` array. /// /// /// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid or there is /// no update for any of the given `priceIds` within the given time range. /// @param updateData Array of price update data. /// @param priceIds Array of price ids. /// @param minPublishTime minimum acceptable publishTime for the given `priceIds`. /// @param maxPublishTime maximum acceptable publishTime for the given `priceIds`. /// @return priceFeeds Array of the price feeds corresponding to the given `priceIds` (with the same order). function parsePriceFeedUpdates( bytes[] calldata updateData, bytes32[] calldata priceIds, uint64 minPublishTime, uint64 maxPublishTime ) external payable returns (PythStructs.PriceFeed[] memory priceFeeds); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; /// @notice Arithmetic library with operations for fixed-point numbers. /// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol) /// @author Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol) library FixedPointMathLib { /*////////////////////////////////////////////////////////////// SIMPLIFIED FIXED POINT OPERATIONS //////////////////////////////////////////////////////////////*/ uint256 internal constant MAX_UINT256 = 2**256 - 1; uint256 internal constant WAD = 1e18; // The scalar of ETH and most ERC20s. function mulWadDown(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivDown(x, y, WAD); // Equivalent to (x * y) / WAD rounded down. } function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivUp(x, y, WAD); // Equivalent to (x * y) / WAD rounded up. } function divWadDown(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivDown(x, WAD, y); // Equivalent to (x * WAD) / y rounded down. } function divWadUp(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivUp(x, WAD, y); // Equivalent to (x * WAD) / y rounded up. } /*////////////////////////////////////////////////////////////// LOW LEVEL FIXED POINT OPERATIONS //////////////////////////////////////////////////////////////*/ function mulDivDown( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to require(denominator != 0 && (y == 0 || x <= type(uint256).max / y)) if iszero(mul(denominator, iszero(mul(y, gt(x, div(MAX_UINT256, y)))))) { revert(0, 0) } // Divide x * y by the denominator. z := div(mul(x, y), denominator) } } function mulDivUp( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to require(denominator != 0 && (y == 0 || x <= type(uint256).max / y)) if iszero(mul(denominator, iszero(mul(y, gt(x, div(MAX_UINT256, y)))))) { revert(0, 0) } // If x * y modulo the denominator is strictly greater than 0, // 1 is added to round up the division of x * y by the denominator. z := add(gt(mod(mul(x, y), denominator), 0), div(mul(x, y), denominator)) } } function rpow( uint256 x, uint256 n, uint256 scalar ) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { switch x case 0 { switch n case 0 { // 0 ** 0 = 1 z := scalar } default { // 0 ** n = 0 z := 0 } } default { switch mod(n, 2) case 0 { // If n is even, store scalar in z for now. z := scalar } default { // If n is odd, store x in z for now. z := x } // Shifting right by 1 is like dividing by 2. let half := shr(1, scalar) for { // Shift n right by 1 before looping to halve it. n := shr(1, n) } n { // Shift n right by 1 each iteration to halve it. n := shr(1, n) } { // Revert immediately if x ** 2 would overflow. // Equivalent to iszero(eq(div(xx, x), x)) here. if shr(128, x) { revert(0, 0) } // Store x squared. let xx := mul(x, x) // Round to the nearest number. let xxRound := add(xx, half) // Revert if xx + half overflowed. if lt(xxRound, xx) { revert(0, 0) } // Set x to scaled xxRound. x := div(xxRound, scalar) // If n is even: if mod(n, 2) { // Compute z * x. let zx := mul(z, x) // If z * x overflowed: if iszero(eq(div(zx, x), z)) { // Revert if x is non-zero. if iszero(iszero(x)) { revert(0, 0) } } // Round to the nearest number. let zxRound := add(zx, half) // Revert if zx + half overflowed. if lt(zxRound, zx) { revert(0, 0) } // Return properly scaled zxRound. z := div(zxRound, scalar) } } } } } /*////////////////////////////////////////////////////////////// GENERAL NUMBER UTILITIES //////////////////////////////////////////////////////////////*/ function sqrt(uint256 x) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { let y := x // We start y at x, which will help us make our initial estimate. z := 181 // The "correct" value is 1, but this saves a multiplication later. // This segment is to get a reasonable initial estimate for the Babylonian method. With a bad // start, the correct # of bits increases ~linearly each iteration instead of ~quadratically. // We check y >= 2^(k + 8) but shift right by k bits // each branch to ensure that if x >= 256, then y >= 256. if iszero(lt(y, 0x10000000000000000000000000000000000)) { y := shr(128, y) z := shl(64, z) } if iszero(lt(y, 0x1000000000000000000)) { y := shr(64, y) z := shl(32, z) } if iszero(lt(y, 0x10000000000)) { y := shr(32, y) z := shl(16, z) } if iszero(lt(y, 0x1000000)) { y := shr(16, y) z := shl(8, z) } // Goal was to get z*z*y within a small factor of x. More iterations could // get y in a tighter range. Currently, we will have y in [256, 256*2^16). // We ensured y >= 256 so that the relative difference between y and y+1 is small. // That's not possible if x < 256 but we can just verify those cases exhaustively. // Now, z*z*y <= x < z*z*(y+1), and y <= 2^(16+8), and either y >= 256, or x < 256. // Correctness can be checked exhaustively for x < 256, so we assume y >= 256. // Then z*sqrt(y) is within sqrt(257)/sqrt(256) of sqrt(x), or about 20bps. // For s in the range [1/256, 256], the estimate f(s) = (181/1024) * (s+1) is in the range // (1/2.84 * sqrt(s), 2.84 * sqrt(s)), with largest error when s = 1 and when s = 256 or 1/256. // Since y is in [256, 256*2^16), let a = y/65536, so that a is in [1/256, 256). Then we can estimate // sqrt(y) using sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2^18. // There is no overflow risk here since y < 2^136 after the first branch above. z := shr(18, mul(z, add(y, 65536))) // A mul() is saved from starting z at 181. // Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough. z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) // If x+1 is a perfect square, the Babylonian method cycles between // floor(sqrt(x)) and ceil(sqrt(x)). This statement ensures we return floor. // See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division // Since the ceil is rare, we save gas on the assignment and repeat division in the rare case. // If you don't care whether the floor or ceil square root is returned, you can remove this statement. z := sub(z, lt(div(x, z), z)) } } function unsafeMod(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Mod x by y. Note this will return // 0 instead of reverting if y is zero. z := mod(x, y) } } function unsafeDiv(uint256 x, uint256 y) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { // Divide x by y. Note this will return // 0 instead of reverting if y is zero. r := div(x, y) } } function unsafeDivUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Add 1 to x * y if x % y > 0. Note this will // return 0 instead of reverting if y is zero. z := add(gt(mod(x, y), 0), div(x, y)) } } }
// SPDX-License-Identifier: BUSL-1.1 // (c) Long Gamma Labs, 2024. pragma solidity ^0.8.28; struct FeeConfig { /// @notice Enable or disable dynamic fees adjustment based on token weight imbalances. bool dynamicFeesEnabled; /// @notice Admin fee for minting LP tokens (100 = 1%, maximum 1000 = 10%). uint16 adminMintLPFeeBps; /// @notice Admin fee for burning LP tokens (100 = 1%, maximum 1000 = 10%). uint16 adminBurnLPFeeBps; /// @notice Base protocol fee (100 = 1%, maximum 1000 = 10%). uint16 feeBasisBps; /// @notice Additional tax fee for imbalanced operations (100 = 1%, maximum 1000 = 10%). uint16 taxBasisBps; /// @notice Performance fee in basis points charged when LP token price reaches new high-water mark (100 = 1%, maximum 3000 = 30%). uint16 perfFeeBps; /// @notice Admin's share of the performance fee in basis points (100 = 1%, maximum 10000 = 100%). uint16 adminPerfFeeBps; /// @notice The address that will receive the admin fees. address adminFeeRecipient; } struct LiquidityConfig { /// @notice Lockup period after adding liquidity in seconds /// during which removeLiquidity and LP token transfers are blocked /// (maximum 16 777 215 seconds ≈ 194 days) uint24 cooldownDuration; /// @notice Minimum liquidity value in USD (scaled by 1e18). uint128 minLiquidityValueUsd; /// @notice Maximum liquidity value in USD (scaled by 1e18). uint128 maxLiquidityValueUsd; } struct MarketMakerConfig { /// @notice Enable or disable minimum market maker share in LP tokens. bool marketMakerLPShareEnabled; /// @notice Minimum market maker share in LP tokens (100 = 1%, maximum 10000 = 100%). uint16 marketMakerLPShareBps; } struct NativeTokenConfig { /// @notice Flag to enable or disable the use of the native GAS token for transactions. bool enabled; /// @notice The index of the token in the tokens array that is used as the native GAS token, if enabled. uint8 tokenId; } struct PriceConfig { /// @notice Maximum allowable age of oracle price data in seconds. uint16 maxOracleAge; /// @notice The period in seconds for which the LP token price is considered valid. uint24 priceValidityPeriod; /// @notice Base multiplier for calculating the allowed LP token price deviation (scaled by 1e18). uint64 baseMultiplier; /// @notice The maximum allowed deviation of the LP token price from the previous valid price. uint64 maxAllowedPriceDeviation; } interface ILPManager { // governance function setConfig( FeeConfig calldata feeConfig, LiquidityConfig calldata liquidityConfig, MarketMakerConfig calldata mmConfig, NativeTokenConfig calldata nativeConfig, PriceConfig calldata priceConfig ) external; function getConfig() external view returns ( FeeConfig memory feeConfig, LiquidityConfig memory liquidityConfig, MarketMakerConfig memory mmConfig, NativeTokenConfig memory nativeConfig, PriceConfig memory priceConfig, bool slashingStatus ); function changeToken( address tokenAddress, bool isActive, uint16 targetWeight, uint16 lowerBoundWeight, uint16 upperBoundWeight, uint8 decimals, uint24 oracleConfRel, bytes32 oraclePriceId ) external; function changeLob( address lobAddress, bool isActive, uint8 tokenIdX, uint8 tokenIdY, uint16 maxOrderDistanceBps ) external; function slashMakersShares(uint256 amount) external; function disableSlashingStatus() external; function pause() external; function validateLPPriceAndDistributeFees(bytes[] calldata priceUpdateData) payable external; // client entries function addLiquidity( uint8 tokenID, uint256 amount, uint256 minUsdValue, uint256 minLPMinted, uint256 expires, bytes[] calldata priceUpdateData ) external payable returns (uint256); function removeLiquidity( uint8 tokenID, uint256 burnLP, uint256 minUsdValue, uint256 minTokenGet, uint256 expires, bytes[] calldata priceUpdateData ) external payable returns (uint256); function collectFees() external; // views function getFeeBasisPoints( uint256 totalValue, uint256 initialTokenValue, uint256 nextTokenValue, uint16 targetTokenWeight ) external view returns (uint256); function tokens(uint256 index) external view returns ( address tokenAddress, bool isActive, uint16 targetWeight, uint16 lowerBoundWeight, uint16 upperBoundWeight, uint8 decimals, uint24 oracleConfRel, bytes32 oraclePriceId ); function lastAddedAt(address account) external view returns (uint256); function totalWeight() external view returns (uint24); function checkCooldown(address account) external view; function getTokensCount() external view returns (uint256); function marketMakers(address account) external view returns (bool); function primaryMarketMaker() external view returns (address); function validateMarketMakerLPShare() external view; function ensureNotPartiallyPaused() external view; function lobs(uint256 index) external view returns ( address lobAddress, uint8 tokenIdX, uint8 tokenIdY, bool isActive, uint16 maxOrderDistanceBps ); }
// SPDX-License-Identifier: BUSL-1.1 // (c) Long Gamma Labs, 2024. pragma solidity ^0.8.28; interface IOnchainLOB { function getConfig() external view returns ( uint256 scalingFactorTokenX, uint256 scalingFactorTokenY, address tokenX, address tokenY, bool supportsNativeEth, bool isTokenXWeth, address askTrie, address bidTrie, uint64 adminCommissionRate, uint64 totalAggressiveCommissionRate, uint64 totalPassiveCommissionRate, uint64 passiveOrderPayoutRate, bool shouldInvokeOnTrade ); function placeOrder( bool isAsk, uint128 quantity, uint72 price, uint128 max_commission, bool market_only, bool post_only, bool transfer_executed_tokens, uint256 expires ) external payable returns ( uint64 order_id, uint128 executed_shares, uint128 executed_value, uint128 aggressive_fee ); function placeMarketOrderWithTargetValue( bool isAsk, uint128 target_token_y_value, uint72 price, uint128 max_commission, bool transfer_executed_tokens, uint256 expires ) external payable returns ( uint128 executed_shares, uint128 executed_value, uint128 aggressive_fee ); function claimOrder( uint64 order_id, bool only_claim, bool transfer_tokens, uint256 expires ) external; function setClaimableStatus(bool status) external; function transferFees() external; function depositTokens(uint128 token_x_amount, uint128 token_y_amount) external; function withdrawTokens(bool withdraw_all, uint128 token_x_amount, uint128 token_y_amount) external; }
// SPDX-License-Identifier: BUSL-1.1 // (c) Long Gamma Labs, 2024. pragma solidity ^0.8.28; interface IProxyLOB { function lobReservesByTokenId(uint8 tokenId) external view returns (uint256); function getPriceOf(uint8 tokenId) external view returns (uint256, int32); function placeOrder( uint8 lobId, bool isAsk, uint128 quantity, uint72 price, uint128 maxCommission, bool marketOnly, bool postOnly, uint256 expires, bytes[] calldata priceUpdateData ) external payable returns (uint64 orderId); function claimOrder(uint8 lobId, uint64 orderId, bool onlyClaim, uint256 expires) external; }
// SPDX-License-Identifier: BUSL-1.1 // (c) Long Gamma Labs, 2024. pragma solidity ^0.8.28; library Ecdsa { uint256 private constant _S_BOUNDARY = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0 + 1; uint256 private constant _COMPACT_S_MASK = 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; uint256 private constant _COMPACT_V_SHIFT = 255; /** * @notice Recovers the signer's address from the signature. * @dev Recovers the address that has signed a hash with `(v, r, s)` signature. * @param hash The keccak256 hash of the data signed. * @param v The recovery byte of the signature. * @param r The first 32 bytes of the signature. * @param s The second 32 bytes of the signature. * @return signer The address of the signer. */ function recover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal view returns (address signer) { assembly ("memory-safe") { // solhint-disable-line no-inline-assembly if lt(s, _S_BOUNDARY) { let ptr := mload(0x40) mstore(ptr, hash) mstore(add(ptr, 0x20), v) mstore(add(ptr, 0x40), r) mstore(add(ptr, 0x60), s) mstore(0, 0) pop(staticcall(gas(), 0x1, ptr, 0x80, 0, 0x20)) signer := mload(0) } } } /** * @notice Recovers the signer's address from the signature using `r` and `vs` components. * @dev Recovers the address that has signed a hash with `r` and `vs`, where `vs` combines `v` and `s`. * @param hash The keccak256 hash of the data signed. * @param r The first 32 bytes of the signature. * @param vs The combined `v` and `s` values of the signature. * @return signer The address of the signer. */ function recover( bytes32 hash, bytes32 r, bytes32 vs ) internal view returns (address signer) { assembly ("memory-safe") { // solhint-disable-line no-inline-assembly let s := and(vs, _COMPACT_S_MASK) if lt(s, _S_BOUNDARY) { let ptr := mload(0x40) mstore(ptr, hash) mstore(add(ptr, 0x20), add(27, shr(_COMPACT_V_SHIFT, vs))) mstore(add(ptr, 0x40), r) mstore(add(ptr, 0x60), s) mstore(0, 0) pop(staticcall(gas(), 0x1, ptr, 0x80, 0, 0x20)) signer := mload(0) } } } /** * @notice Generates an EIP-712 compliant hash. * @dev Encodes the domain separator and the struct hash according to EIP-712. * @param domainSeparator The EIP-712 domain separator. * @param structHash The EIP-712 struct hash. * @return res The EIP-712 compliant hash. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 res) { // return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); assembly ("memory-safe") { // solhint-disable-line no-inline-assembly let ptr := mload(0x40) mstore(ptr, 0x1901000000000000000000000000000000000000000000000000000000000000) // "\x19\x01" mstore(add(ptr, 0x02), domainSeparator) mstore(add(ptr, 0x22), structHash) res := keccak256(ptr, 66) } } }
// SPDX-License-Identifier: BUSL-1.1 // (c) Long Gamma Labs, 2024. pragma solidity ^0.8.28; import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol"; import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol"; import { IPyth } from "@pythnetwork/pyth-sdk-solidity/IPyth.sol"; import { FixedPointMathLib } from "@solmate/src/utils/FixedPointMathLib.sol"; import { IOnchainLOB } from "./interfaces/IOnchainLOB.sol"; import { IOnchainTrie } from "./interfaces/IOnchainTrie.sol"; import { IProxyLOB } from "./interfaces/IProxyLOB.sol"; import { ErrorReporter } from "./ErrorReporter.sol"; import { PythPriceHelper } from "./utils/PythPriceHelper.sol"; abstract contract ProxyLOB is IProxyLOB, PausableUpgradeable, ReentrancyGuardUpgradeable { using FixedPointMathLib for uint256; uint8 constant nonceLength = 39; uint16 constant BASIS_POINTS_DIVISOR = 1e4; mapping (uint8 => uint256) public lobReservesByTokenId; IPyth immutable pyth; function placeOrder( uint8 lobId, bool isAsk, uint128 quantity, uint72 price, uint128 maxCommission, bool marketOnly, bool postOnly, uint256 expires, bytes[] calldata priceUpdateData ) external nonReentrant payable returns (uint64 orderId) { _checkTrader(msg.sender); _checkLOB(lobId); PythPriceHelper.updatePrices(pyth, priceUpdateData); (orderId,,,) = _placeOrder( lobId, isAsk, quantity, price, maxCommission, marketOnly, postOnly, expires ); } function claimOrder( uint8 lobId, uint64 orderId, bool onlyClaim, uint256 expires ) external nonReentrant { _checkLOB(lobId); if (!onlyClaim) { _checkTrader(msg.sender); } _claimOrder(lobId, orderId, onlyClaim, expires); } function _checkTrader(address) virtual internal; function _checkLOB(uint8) virtual internal; function ensureNotPartiallyPaused() virtual public view; function _getLobById(uint8) virtual internal returns ( address lobAddress, uint8 tokenIdX, uint8 tokenIdY, uint16 maxOrderDistanceBps ); function _getTokenDecimalsById(uint8) virtual internal returns (uint8); function getPriceOf(uint8 tokenId) virtual public view returns (uint256, int32); function _validateLPPriceAndDistributeFees() virtual internal; function _sync(uint8 tokenId) virtual internal; function _placeOrder( uint8 lobId, bool isAsk, uint128 quantity, uint72 price, uint128 maxCommission, bool marketOnly, bool postOnly, uint256 expires ) internal returns (uint64 orderId, uint128 executedShares, uint128 executedValue, uint128 aggressiveFee) { _requireNotPaused(); ensureNotPartiallyPaused(); (address lobAddress, uint8 tokenIdX, uint8 tokenIdY, uint16 maxOrderDistanceBps) = _getLobById(lobId); IOnchainLOB lob = IOnchainLOB(payable(lobAddress)); ( uint256 scalingFactorTokenX, uint256 scalingFactorTokenY, , , , , , , , , uint64 passiveCommissionRate, , ) = lob.getConfig(); uint8 scalingFactorTokenXExpo = _log10(scalingFactorTokenX); uint8 scalingFactorTokenYExpo = _log10(scalingFactorTokenY); (uint256 priceX, int32 expoX) = getPriceOf(tokenIdX); (uint256 priceY, int32 expoY) = getPriceOf(tokenIdY); int256 decimalAdjustment; unchecked { // Safe to use unchecked as the maximum possible value fits within int256 range // Max value: ~2^32 + 255 + 255 // Min value: ~-2^32 - 255 - 255 // int256 range: ±2^255 - 1 decimalAdjustment = ( int256(expoX) - int256(expoY) - int256(uint256(_getTokenDecimalsById(tokenIdX))) + int256(uint256(_getTokenDecimalsById(tokenIdY))) - int256(uint256(scalingFactorTokenYExpo)) + int256(uint256(scalingFactorTokenXExpo)) ); } uint256 scaledPrice = priceY * price; uint256 scaledOraclePrice = priceX; if (decimalAdjustment > 0) { scaledOraclePrice *= 10 ** uint256(decimalAdjustment); } else { scaledPrice *= 10 ** uint256(-decimalAdjustment); } if (isAsk) { require( scaledPrice * (BASIS_POINTS_DIVISOR + uint256(maxOrderDistanceBps)) >= scaledOraclePrice * BASIS_POINTS_DIVISOR, ErrorReporter.PriceTooSmall() ); } else { require( scaledPrice * BASIS_POINTS_DIVISOR <= scaledOraclePrice * (BASIS_POINTS_DIVISOR + uint256(maxOrderDistanceBps)), ErrorReporter.PriceTooBig() ); } (orderId, executedShares, executedValue, aggressiveFee) = lob.placeOrder( isAsk, quantity, price, maxCommission, marketOnly, postOnly, true, expires ); uint128 remainShares = marketOnly ? 0 : quantity - executedShares; // add remainShares to reserves if (remainShares > 0) { if (isAsk) { lobReservesByTokenId[tokenIdX] += remainShares * scalingFactorTokenX; } else { uint256 remainValue = remainShares * price; uint256 passiveFee = remainValue.mulWadUp(passiveCommissionRate); lobReservesByTokenId[tokenIdY] += (remainValue + passiveFee) * scalingFactorTokenY; } } _validateLPPriceAndDistributeFees(); _sync(tokenIdX); _sync(tokenIdY); } function _claimOrder(uint8 lobId, uint64 orderId, bool onlyClaim, uint256 expires) internal whenNotPaused { (address lob, uint8 tokenIdX, uint8 tokenIdY,) = _getLobById(lobId); ( uint256 scalingFactorTokenX, uint256 scalingFactorTokenY, , , , , address askTrie, address bidTrie, , , uint64 passiveCommissionRate, , ) = IOnchainLOB(payable(lob)).getConfig(); (bool isAsk, uint72 price) = _extractDirectionAndPrice(orderId); address trie = isAsk ? askTrie : bidTrie; (uint128 totalShares, uint128 remainShares) = IOnchainTrie(payable(trie)).getOrderInfo(orderId | 0x1); IOnchainLOB(payable(lob)).claimOrder(orderId, onlyClaim, true, expires); uint128 executedShares = totalShares - remainShares; uint128 returnedShares = onlyClaim ? executedShares : totalShares; if (isAsk) { lobReservesByTokenId[tokenIdX] -= returnedShares * scalingFactorTokenX; } else { uint256 returnedValue = returnedShares * price; uint256 passiveFee = returnedValue.mulWadUp(passiveCommissionRate); uint256 returnedAmount = (returnedValue + passiveFee) * scalingFactorTokenY; uint256 lobReservesTokenY = lobReservesByTokenId[tokenIdY]; uint256 newReservesTokenY; // possible minor error accumulation in passiveFee if (returnedAmount <= lobReservesTokenY) { unchecked { newReservesTokenY = lobReservesTokenY - returnedAmount; } } lobReservesByTokenId[tokenIdY] = newReservesTokenY; } _sync(tokenIdX); _sync(tokenIdY); } function _isAsk(uint64 orderId) internal pure returns (bool) { return (orderId & uint64(0x1)) == 0x1; } /// @notice Extracts the direction and price from the given order ID. /// @param orderId The unique identifier of the order. /// @return isAsk A boolean indicating if the order is an ask (true) or a bid (false). /// @return price The price of the order. function _extractDirectionAndPrice(uint64 orderId) internal pure returns (bool isAsk, uint72 price) { isAsk = _isAsk(orderId); uint24 packedPrice = uint24(orderId >> (nonceLength + 1)); if (isAsk) { unchecked{ packedPrice = type(uint24).max - packedPrice; } } price = _unPackFP24(packedPrice); } /// @dev Converts a uint24 floating point number into a uint72 number. /// @param p The uint24 floating point number to be converted. /// @return a The uint72 number representation of the input floating point number. function _unPackFP24(uint24 p) internal pure returns (uint72) { uint72 e = uint72(p >> 20); uint72 a = uint72(p & 0xfffff); require(0 < a && a <= 999999, ErrorReporter.InvalidFloatingPointRepresentation()); a *= uint72(10 ** e); return a; } function _log10(uint256 value) internal pure returns (uint8 l) { require(value > 0, ErrorReporter.WrongNumber()); while (value != 1) { require(value % 10 == 0, ErrorReporter.WrongNumber()); l += 1; value /= 10; } } }
// SPDX-License-Identifier: BUSL-1.1 // (c) Long Gamma Labs, 2024. pragma solidity ^0.8.28; import { Ecdsa } from "./Ecdsa.sol"; struct ClientOrder { address userAddress; address lobAddress; bool targetValueTransaction; uint128 orderAmount; uint72 price; bool isAsk; uint256 expires; uint128 nonce; } library RfqOrderLib { /// @dev The typehash of the order struct. bytes32 constant internal _CLIENT_ORDER_TYPEHASH = keccak256( "ClientOrder(" "address userAddress," "address lobAddress," "bool targetValueTransaction," "uint128 qty," "uint72 price," "bool isAsk," "uint256 expires," "uint128 nonce" ")" ); uint256 constant internal _ORDER_STRUCT_SIZE = 8 * 32; uint256 constant internal _DATA_HASH_SIZE = 9 * 32; function hash(ClientOrder calldata order, bytes32 domainSeparator) internal pure returns(bytes32 result) { bytes32 typehash = _CLIENT_ORDER_TYPEHASH; assembly ("memory-safe") { // solhint-disable-line no-inline-assembly let ptr := mload(0x40) // keccak256(abi.encode(_CLIENT_ORDER_TYPEHASH, order)); mstore(ptr, typehash) calldatacopy(add(ptr, 0x20), order, _ORDER_STRUCT_SIZE) result := keccak256(ptr, _DATA_HASH_SIZE) } result = Ecdsa.toTypedDataHash(domainSeparator, result); } function hashWithEncode(ClientOrder calldata order, bytes32 domainSeparator) internal pure returns(bytes32 result) { result = keccak256(abi.encode(_CLIENT_ORDER_TYPEHASH, order)); result = Ecdsa.toTypedDataHash(domainSeparator, result); } }
// SPDX-License-Identifier: BUSL-1.1 // (c) Long Gamma Labs, 2024. pragma solidity ^0.8.28; contract ErrorReporter { error CooldownDurationNotYetPassed(); // 0x5fba365d error EmptyDomainName(); // 0x2f601761 error EmptyTokenName(); // 0xe2592aed error EmptyTokenSymbol(); // 0x19c7070a error Expired(); // 0x203d82d8 error FeeBpsExceedsMaximum(); // 0x132df9c5 error Forbidden(); // 0xee90c468 error InsufficientBalance(); // 0xf4d678b8 error InsufficientFeeForPythUpdate(); // 0xe4764c6f error InsufficientLiquidityValue(); // 0x5b635d0b error InsufficientMarketMakerLPShare(); // 0x28f53493 error InsufficientMintedLP(); // 0x212c18d0 error InsufficientTokenAmount(); // 0x2ec48042 error InsufficientUSDValue(); // 0xd6f69157 error InvalidFloatingPointRepresentation(); // 0xa25f85b7 error InvalidLob(); // 0xb9c44f1a error InvalidLobAddress(); // 0xec09da35 error InvalidOracleConfidenceLevel(); // 0xe6b9bbad error InvalidSignature(); // 0x8baa579f error InvalidTokenWeights(); // 0x4b8072c3 error InvalidTrader(); // 0xfb7595a2 error InvalidTransfer(); // 0x2f352531 error LobDisabled(); // 0xa6876da4 error MarketMakerLPShareExceedsMaximum(); // 0x84d3d6cb error MaxLiquidityValueExceeded(); // 0x9009a2d8 error MaxOracleAgeExceedsMaximum(); // 0x8b7df994 error NativeGasTokenDisabled(); // 0x60787531 error NonPositivePrice(); // 0x13caeeae error NotImplementedYet(); // 0xf88c75b4 error OracleConfTooHigh(); // 0x004f2349 error OrderAlreadyUsed(); // 0x88b39043 error PartiallyPaused(); // 0x1fa6172a error PriceTooBig(); // 0x9bec8e38 error PriceTooSmall(); // 0x8460540d error SlashingUnAvailable(); // 0xd7b45887 error TokenDisabled(); // 0x1931ea85 error TokenWeightExceeded(); // 0x725ad4f5 error TransferFailed(); // 0x90b8ec18 error UnknownLob(); // 0x0b1066eb error WrongNumber(); // 0x3546a07e error WrongTokenId(); // 0x749aeece error ZeroAddress(); // 0xd92e233d error ZeroAmount(); // 0x1f2a2005 }
// SPDX-License-Identifier: BUSL-1.1 // (c) Long Gamma Labs, 2024. pragma solidity ^0.8.28; import { IPyth } from "@pythnetwork/pyth-sdk-solidity/IPyth.sol"; import { ErrorReporter } from "../ErrorReporter.sol"; library PythPriceHelper { function updatePrices(IPyth pyth, bytes[] calldata priceUpdateData) internal returns (uint256) { uint256 fee = 0; if (priceUpdateData.length != 0) { fee = pyth.getUpdateFee(priceUpdateData); require(msg.value >= fee, ErrorReporter.InsufficientFeeForPythUpdate()); pyth.updatePriceFeeds{value: fee}(priceUpdateData); } uint256 rest; unchecked { rest = msg.value - fee; } sendGASToken(msg.sender, rest); return rest; } function sendGASToken(address to, uint256 value) internal { if (value == 0) { return; } (bool success, ) = to.call{value: value}(""); require(success, ErrorReporter.TransferFailed()); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/MessageHashUtils.sol) pragma solidity ^0.8.20; import {Strings} from "../Strings.sol"; /** * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing. * * The library provides methods for generating a hash of a message that conforms to the * https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712] * specifications. */ library MessageHashUtils { /** * @dev Returns the keccak256 digest of an ERC-191 signed data with version * `0x45` (`personal_sign` messages). * * The digest is calculated by prefixing a bytes32 `messageHash` with * `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method. * * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with * keccak256, although any bytes32 value can be safely used because the final digest will * be re-hashed. * * See {ECDSA-recover}. */ function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) { assembly ("memory-safe") { mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20) } } /** * @dev Returns the keccak256 digest of an ERC-191 signed data with version * `0x45` (`personal_sign` messages). * * The digest is calculated by prefixing an arbitrary `message` with * `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method. * * See {ECDSA-recover}. */ function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) { return keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message)); } /** * @dev Returns the keccak256 digest of an ERC-191 signed data with version * `0x00` (data with intended validator). * * The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended * `validator` address. Then hashing the result. * * See {ECDSA-recover}. */ function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) { return keccak256(abi.encodePacked(hex"19_00", validator, data)); } /** * @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`). * * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with * `\x19\x01` and hashing the result. It corresponds to the hash signed by the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712. * * See {ECDSA-recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) { assembly ("memory-safe") { let ptr := mload(0x40) mstore(ptr, hex"19_01") mstore(add(ptr, 0x02), domainSeparator) mstore(add(ptr, 0x22), structHash) digest := keccak256(ptr, 0x42) } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/ShortStrings.sol) pragma solidity ^0.8.20; import {StorageSlot} from "./StorageSlot.sol"; // | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | // | length | 0x BB | type ShortString is bytes32; /** * @dev This library provides functions to convert short memory strings * into a `ShortString` type that can be used as an immutable variable. * * Strings of arbitrary length can be optimized using this library if * they are short enough (up to 31 bytes) by packing them with their * length (1 byte) in a single EVM word (32 bytes). Additionally, a * fallback mechanism can be used for every other case. * * Usage example: * * ```solidity * contract Named { * using ShortStrings for *; * * ShortString private immutable _name; * string private _nameFallback; * * constructor(string memory contractName) { * _name = contractName.toShortStringWithFallback(_nameFallback); * } * * function name() external view returns (string memory) { * return _name.toStringWithFallback(_nameFallback); * } * } * ``` */ library ShortStrings { // Used as an identifier for strings longer than 31 bytes. bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF; error StringTooLong(string str); error InvalidShortString(); /** * @dev Encode a string of at most 31 chars into a `ShortString`. * * This will trigger a `StringTooLong` error is the input string is too long. */ function toShortString(string memory str) internal pure returns (ShortString) { bytes memory bstr = bytes(str); if (bstr.length > 31) { revert StringTooLong(str); } return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length)); } /** * @dev Decode a `ShortString` back to a "normal" string. */ function toString(ShortString sstr) internal pure returns (string memory) { uint256 len = byteLength(sstr); // using `new string(len)` would work locally but is not memory safe. string memory str = new string(32); assembly ("memory-safe") { mstore(str, len) mstore(add(str, 0x20), sstr) } return str; } /** * @dev Return the length of a `ShortString`. */ function byteLength(ShortString sstr) internal pure returns (uint256) { uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF; if (result > 31) { revert InvalidShortString(); } return result; } /** * @dev Encode a string into a `ShortString`, or write it to storage if it is too long. */ function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) { if (bytes(value).length < 32) { return toShortString(value); } else { StorageSlot.getStringSlot(store).value = value; return ShortString.wrap(FALLBACK_SENTINEL); } } /** * @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}. */ function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) { if (ShortString.unwrap(value) != FALLBACK_SENTINEL) { return toString(value); } else { return store; } } /** * @dev Return the length of a string that was encoded to `ShortString` or written to storage using * {setWithFallback}. * * WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of * actual characters as the UTF-8 encoding of a single character can span over multiple bytes. */ function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) { if (ShortString.unwrap(value) != FALLBACK_SENTINEL) { return byteLength(value); } else { return bytes(store).length; } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol) pragma solidity ^0.8.20; interface IERC5267 { /** * @dev MAY be emitted to signal that the domain could have changed. */ event EIP712DomainChanged(); /** * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712 * signature. */ function eip712Domain() external view returns ( bytes1 fields, string memory name, string memory version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] memory extensions ); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol) pragma solidity ^0.8.20; import {IERC20} from "./IERC20.sol"; import {IERC165} from "./IERC165.sol"; /** * @title IERC1363 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363]. * * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction. */ interface IERC1363 is IERC20, IERC165 { /* * Note: the ERC-165 identifier for this interface is 0xb0202a11. * 0xb0202a11 === * bytes4(keccak256('transferAndCall(address,uint256)')) ^ * bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^ * bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^ * bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^ * bytes4(keccak256('approveAndCall(address,uint256)')) ^ * bytes4(keccak256('approveAndCall(address,uint256,bytes)')) */ /** * @dev Moves a `value` amount of tokens from the caller's account to `to` * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferAndCall(address to, uint256 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from the caller's account to `to` * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @param data Additional data with no specified format, sent in call to `to`. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param from The address which you want to send tokens from. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferFromAndCall(address from, address to, uint256 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param from The address which you want to send tokens from. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @param data Additional data with no specified format, sent in call to `to`. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool); /** * @dev Sets a `value` amount of tokens as the allowance of `spender` over the * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`. * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function approveAndCall(address spender, uint256 value) external returns (bool); /** * @dev Sets a `value` amount of tokens as the allowance of `spender` over the * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`. * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. * @param data Additional data with no specified format, sent in call to `spender`. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool); }
// SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.0; contract PythStructs { // A price with a degree of uncertainty, represented as a price +- a confidence interval. // // The confidence interval roughly corresponds to the standard error of a normal distribution. // Both the price and confidence are stored in a fixed-point numeric representation, // `x * (10^expo)`, where `expo` is the exponent. // // Please refer to the documentation at https://docs.pyth.network/consumers/best-practices for how // to how this price safely. struct Price { // Price int64 price; // Confidence interval around the price uint64 conf; // Price exponent int32 expo; // Unix timestamp describing when the price was published uint publishTime; } // PriceFeed represents a current aggregate price from pyth publisher feeds. struct PriceFeed { // The price ID. bytes32 id; // Latest available price Price price; // Latest available exponentially-weighted moving average price Price emaPrice; } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.0; /// @title IPythEvents contains the events that Pyth contract emits. /// @dev This interface can be used for listening to the updates for off-chain and testing purposes. interface IPythEvents { /// @dev Emitted when the price feed with `id` has received a fresh update. /// @param id The Pyth Price Feed ID. /// @param publishTime Publish time of the given price update. /// @param price Price of the given price update. /// @param conf Confidence interval of the given price update. event PriceFeedUpdate( bytes32 indexed id, uint64 publishTime, int64 price, uint64 conf ); /// @dev Emitted when a batch price update is processed successfully. /// @param chainId ID of the source chain that the batch price update comes from. /// @param sequenceNumber Sequence number of the batch price update. event BatchPriceFeedUpdate(uint16 chainId, uint64 sequenceNumber); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol) pragma solidity ^0.8.20; import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol"; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract PausableUpgradeable is Initializable, ContextUpgradeable { /// @custom:storage-location erc7201:openzeppelin.storage.Pausable struct PausableStorage { bool _paused; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Pausable")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant PausableStorageLocation = 0xcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300; function _getPausableStorage() private pure returns (PausableStorage storage $) { assembly { $.slot := PausableStorageLocation } } /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); /** * @dev The operation failed because the contract is paused. */ error EnforcedPause(); /** * @dev The operation failed because the contract is not paused. */ error ExpectedPause(); /** * @dev Initializes the contract in unpaused state. */ function __Pausable_init() internal onlyInitializing { __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { PausableStorage storage $ = _getPausableStorage(); $._paused = false; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { PausableStorage storage $ = _getPausableStorage(); return $._paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { if (paused()) { revert EnforcedPause(); } } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { if (!paused()) { revert ExpectedPause(); } } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { PausableStorage storage $ = _getPausableStorage(); $._paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { PausableStorage storage $ = _getPausableStorage(); $._paused = false; emit Unpaused(_msgSender()); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol) pragma solidity ^0.8.20; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at, * consider using {ReentrancyGuardTransient} instead. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuardUpgradeable is Initializable { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant NOT_ENTERED = 1; uint256 private constant ENTERED = 2; /// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard struct ReentrancyGuardStorage { uint256 _status; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant ReentrancyGuardStorageLocation = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00; function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) { assembly { $.slot := ReentrancyGuardStorageLocation } } /** * @dev Unauthorized reentrant call. */ error ReentrancyGuardReentrantCall(); function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage(); $._status = NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage(); // On the first call to nonReentrant, _status will be NOT_ENTERED if ($._status == ENTERED) { revert ReentrancyGuardReentrantCall(); } // Any calls to nonReentrant after this point will fail $._status = ENTERED; } function _nonReentrantAfter() private { ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage(); // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) $._status = NOT_ENTERED; } /** * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a * `nonReentrant` function in the call stack. */ function _reentrancyGuardEntered() internal view returns (bool) { ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage(); return $._status == ENTERED; } }
// SPDX-License-Identifier: BUSL-1.1 // (c) Long Gamma Labs, 2024. pragma solidity ^0.8.28; interface IOnchainTrie { function getOrderInfo(uint64 orderId) external view returns (uint128 totalShares, uint128 remainShares); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/Strings.sol) pragma solidity ^0.8.20; import {Math} from "./math/Math.sol"; import {SafeCast} from "./math/SafeCast.sol"; import {SignedMath} from "./math/SignedMath.sol"; /** * @dev String operations. */ library Strings { using SafeCast for *; bytes16 private constant HEX_DIGITS = "0123456789abcdef"; uint8 private constant ADDRESS_LENGTH = 20; /** * @dev The `value` string doesn't fit in the specified `length`. */ error StringsInsufficientHexLength(uint256 value, uint256 length); /** * @dev The string being parsed contains characters that are not in scope of the given base. */ error StringsInvalidChar(); /** * @dev The string being parsed is not a properly formatted address. */ error StringsInvalidAddressFormat(); /** * @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; assembly ("memory-safe") { ptr := add(buffer, add(32, length)) } while (true) { ptr--; assembly ("memory-safe") { mstore8(ptr, byte(mod(value, 10), HEX_DIGITS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toStringSigned(int256 value) internal pure returns (string memory) { return string.concat(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) { uint256 localValue = value; 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] = HEX_DIGITS[localValue & 0xf]; localValue >>= 4; } if (localValue != 0) { revert StringsInsufficientHexLength(value, length); } 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 Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal * representation, according to EIP-55. */ function toChecksumHexString(address addr) internal pure returns (string memory) { bytes memory buffer = bytes(toHexString(addr)); // hash the hex part of buffer (skip length + 2 bytes, length 40) uint256 hashValue; assembly ("memory-safe") { hashValue := shr(96, keccak256(add(buffer, 0x22), 40)) } for (uint256 i = 41; i > 1; --i) { // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f) if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) { // case shift by xoring with 0x20 buffer[i] ^= 0x20; } hashValue >>= 4; } return string(buffer); } /** * @dev Returns true if the two strings are equal. */ function equal(string memory a, string memory b) internal pure returns (bool) { return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b)); } /** * @dev Parse a decimal string and returns the value as a `uint256`. * * Requirements: * - The string must be formatted as `[0-9]*` * - The result must fit into an `uint256` type */ function parseUint(string memory input) internal pure returns (uint256) { return parseUint(input, 0, bytes(input).length); } /** * @dev Variant of {parseUint} that parses a substring of `input` located between position `begin` (included) and * `end` (excluded). * * Requirements: * - The substring must be formatted as `[0-9]*` * - The result must fit into an `uint256` type */ function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) { (bool success, uint256 value) = tryParseUint(input, begin, end); if (!success) revert StringsInvalidChar(); return value; } /** * @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character. * * NOTE: This function will revert if the result does not fit in a `uint256`. */ function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) { return _tryParseUintUncheckedBounds(input, 0, bytes(input).length); } /** * @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid * character. * * NOTE: This function will revert if the result does not fit in a `uint256`. */ function tryParseUint( string memory input, uint256 begin, uint256 end ) internal pure returns (bool success, uint256 value) { if (end > bytes(input).length || begin > end) return (false, 0); return _tryParseUintUncheckedBounds(input, begin, end); } /** * @dev Implementation of {tryParseUint} that does not check bounds. Caller should make sure that * `begin <= end <= input.length`. Other inputs would result in undefined behavior. */ function _tryParseUintUncheckedBounds( string memory input, uint256 begin, uint256 end ) private pure returns (bool success, uint256 value) { bytes memory buffer = bytes(input); uint256 result = 0; for (uint256 i = begin; i < end; ++i) { uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i))); if (chr > 9) return (false, 0); result *= 10; result += chr; } return (true, result); } /** * @dev Parse a decimal string and returns the value as a `int256`. * * Requirements: * - The string must be formatted as `[-+]?[0-9]*` * - The result must fit in an `int256` type. */ function parseInt(string memory input) internal pure returns (int256) { return parseInt(input, 0, bytes(input).length); } /** * @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and * `end` (excluded). * * Requirements: * - The substring must be formatted as `[-+]?[0-9]*` * - The result must fit in an `int256` type. */ function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) { (bool success, int256 value) = tryParseInt(input, begin, end); if (!success) revert StringsInvalidChar(); return value; } /** * @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if * the result does not fit in a `int256`. * * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`. */ function tryParseInt(string memory input) internal pure returns (bool success, int256 value) { return _tryParseIntUncheckedBounds(input, 0, bytes(input).length); } uint256 private constant ABS_MIN_INT256 = 2 ** 255; /** * @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid * character or if the result does not fit in a `int256`. * * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`. */ function tryParseInt( string memory input, uint256 begin, uint256 end ) internal pure returns (bool success, int256 value) { if (end > bytes(input).length || begin > end) return (false, 0); return _tryParseIntUncheckedBounds(input, begin, end); } /** * @dev Implementation of {tryParseInt} that does not check bounds. Caller should make sure that * `begin <= end <= input.length`. Other inputs would result in undefined behavior. */ function _tryParseIntUncheckedBounds( string memory input, uint256 begin, uint256 end ) private pure returns (bool success, int256 value) { bytes memory buffer = bytes(input); // Check presence of a negative sign. bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty bool positiveSign = sign == bytes1("+"); bool negativeSign = sign == bytes1("-"); uint256 offset = (positiveSign || negativeSign).toUint(); (bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end); if (absSuccess && absValue < ABS_MIN_INT256) { return (true, negativeSign ? -int256(absValue) : int256(absValue)); } else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) { return (true, type(int256).min); } else return (false, 0); } /** * @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as a `uint256`. * * Requirements: * - The string must be formatted as `(0x)?[0-9a-fA-F]*` * - The result must fit in an `uint256` type. */ function parseHexUint(string memory input) internal pure returns (uint256) { return parseHexUint(input, 0, bytes(input).length); } /** * @dev Variant of {parseHexUint} that parses a substring of `input` located between position `begin` (included) and * `end` (excluded). * * Requirements: * - The substring must be formatted as `(0x)?[0-9a-fA-F]*` * - The result must fit in an `uint256` type. */ function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) { (bool success, uint256 value) = tryParseHexUint(input, begin, end); if (!success) revert StringsInvalidChar(); return value; } /** * @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character. * * NOTE: This function will revert if the result does not fit in a `uint256`. */ function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) { return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length); } /** * @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an * invalid character. * * NOTE: This function will revert if the result does not fit in a `uint256`. */ function tryParseHexUint( string memory input, uint256 begin, uint256 end ) internal pure returns (bool success, uint256 value) { if (end > bytes(input).length || begin > end) return (false, 0); return _tryParseHexUintUncheckedBounds(input, begin, end); } /** * @dev Implementation of {tryParseHexUint} that does not check bounds. Caller should make sure that * `begin <= end <= input.length`. Other inputs would result in undefined behavior. */ function _tryParseHexUintUncheckedBounds( string memory input, uint256 begin, uint256 end ) private pure returns (bool success, uint256 value) { bytes memory buffer = bytes(input); // skip 0x prefix if present bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty uint256 offset = hasPrefix.toUint() * 2; uint256 result = 0; for (uint256 i = begin + offset; i < end; ++i) { uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i))); if (chr > 15) return (false, 0); result *= 16; unchecked { // Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check). // This guaratees that adding a value < 16 will not cause an overflow, hence the unchecked. result += chr; } } return (true, result); } /** * @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as an `address`. * * Requirements: * - The string must be formatted as `(0x)?[0-9a-fA-F]{40}` */ function parseAddress(string memory input) internal pure returns (address) { return parseAddress(input, 0, bytes(input).length); } /** * @dev Variant of {parseAddress} that parses a substring of `input` located between position `begin` (included) and * `end` (excluded). * * Requirements: * - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}` */ function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) { (bool success, address value) = tryParseAddress(input, begin, end); if (!success) revert StringsInvalidAddressFormat(); return value; } /** * @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly * formatted address. See {parseAddress} requirements. */ function tryParseAddress(string memory input) internal pure returns (bool success, address value) { return tryParseAddress(input, 0, bytes(input).length); } /** * @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly * formatted address. See {parseAddress} requirements. */ function tryParseAddress( string memory input, uint256 begin, uint256 end ) internal pure returns (bool success, address value) { if (end > bytes(input).length || begin > end) return (false, address(0)); bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty uint256 expectedLength = 40 + hasPrefix.toUint() * 2; // check that input is the correct length if (end - begin == expectedLength) { // length guarantees that this does not overflow, and value is at most type(uint160).max (bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end); return (s, address(uint160(v))); } else { return (false, address(0)); } } function _tryParseChr(bytes1 chr) private pure returns (uint8) { uint8 value = uint8(chr); // Try to parse `chr`: // - Case 1: [0-9] // - Case 2: [a-f] // - Case 3: [A-F] // - otherwise not supported unchecked { if (value > 47 && value < 58) value -= 48; else if (value > 96 && value < 103) value -= 87; else if (value > 64 && value < 71) value -= 55; else return type(uint8).max; } return value; } /** * @dev Reads a bytes32 from a bytes array without bounds checking. * * NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the * assembly block as such would prevent some optimizations. */ function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) { // This is not memory safe in the general case, but all calls to this private function are within bounds. assembly ("memory-safe") { value := mload(add(buffer, add(0x20, offset))) } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol) // This file was procedurally generated from scripts/generate/templates/StorageSlot.js. pragma solidity ^0.8.20; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC-1967 implementation slot: * ```solidity * contract ERC1967 { * // Define the slot. Alternatively, use the SlotDerivation library to derive the slot. * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(newImplementation.code.length > 0); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * TIP: Consider using this library along with {SlotDerivation}. */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } struct Int256Slot { int256 value; } struct StringSlot { string value; } struct BytesSlot { bytes value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly ("memory-safe") { r.slot := slot } } /** * @dev Returns a `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly ("memory-safe") { r.slot := slot } } /** * @dev Returns a `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly ("memory-safe") { r.slot := slot } } /** * @dev Returns a `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly ("memory-safe") { r.slot := slot } } /** * @dev Returns a `Int256Slot` with member `value` located at `slot`. */ function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) { assembly ("memory-safe") { r.slot := slot } } /** * @dev Returns a `StringSlot` with member `value` located at `slot`. */ function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) { assembly ("memory-safe") { r.slot := slot } } /** * @dev Returns an `StringSlot` representation of the string storage pointer `store`. */ function getStringSlot(string storage store) internal pure returns (StringSlot storage r) { assembly ("memory-safe") { r.slot := store.slot } } /** * @dev Returns a `BytesSlot` with member `value` located at `slot`. */ function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) { assembly ("memory-safe") { r.slot := slot } } /** * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`. */ function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) { assembly ("memory-safe") { r.slot := store.slot } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "../token/ERC20/IERC20.sol";
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol) pragma solidity ^0.8.20; import {IERC165} from "../utils/introspection/IERC165.sol";
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol) pragma solidity ^0.8.20; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } function _contextSuffixLength() internal view virtual returns (uint256) { return 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.20; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ```solidity * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Storage of the initializable contract. * * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions * when using with upgradeable contracts. * * @custom:storage-location erc7201:openzeppelin.storage.Initializable */ struct InitializableStorage { /** * @dev Indicates that the contract has been initialized. */ uint64 _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool _initializing; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00; /** * @dev The contract is already initialized. */ error InvalidInitialization(); /** * @dev The contract is not initializing. */ error NotInitializing(); /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint64 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in * production. * * Emits an {Initialized} event. */ modifier initializer() { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); // Cache values to avoid duplicated sloads bool isTopLevelCall = !$._initializing; uint64 initialized = $._initialized; // Allowed calls: // - initialSetup: the contract is not in the initializing state and no previous version was // initialized // - construction: the contract is initialized at version 1 (no reininitialization) and the // current contract is just being deployed bool initialSetup = initialized == 0 && isTopLevelCall; bool construction = initialized == 1 && address(this).code.length == 0; if (!initialSetup && !construction) { revert InvalidInitialization(); } $._initialized = 1; if (isTopLevelCall) { $._initializing = true; } _; if (isTopLevelCall) { $._initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint64 version) { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); if ($._initializing || $._initialized >= version) { revert InvalidInitialization(); } $._initialized = version; $._initializing = true; _; $._initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { _checkInitializing(); _; } /** * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}. */ function _checkInitializing() internal view virtual { if (!_isInitializing()) { revert NotInitializing(); } } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); if ($._initializing) { revert InvalidInitialization(); } if ($._initialized != type(uint64).max) { $._initialized = type(uint64).max; emit Initialized(type(uint64).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint64) { return _getInitializableStorage()._initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _getInitializableStorage()._initializing; } /** * @dev Returns a pointer to the storage namespace. */ // solhint-disable-next-line var-name-mixedcase function _getInitializableStorage() private pure returns (InitializableStorage storage $) { assembly { $.slot := INITIALIZABLE_STORAGE } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/math/Math.sol) pragma solidity ^0.8.20; import {Panic} from "../Panic.sol"; import {SafeCast} from "./SafeCast.sol"; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Floor, // Toward negative infinity Ceil, // Toward positive infinity Trunc, // Toward zero Expand // Away from zero } /** * @dev Returns the addition of two unsigned integers, with an success flag (no overflow). */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow). */ function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow). */ function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { 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 success flag (no division by zero). */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero). */ function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant. * * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone. * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute * one branch when needed, making this function more expensive. */ function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) { unchecked { // branchless ternary works because: // b ^ (a ^ b) == a // b ^ 0 == b return b ^ ((a ^ b) * SafeCast.toUint(condition)); } } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return ternary(a > b, a, b); } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return ternary(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 towards infinity instead * of rounding towards zero. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { if (b == 0) { // Guarantee the same behavior as in a regular Solidity division. Panic.panic(Panic.DIVISION_BY_ZERO); } // The following calculation ensures accurate ceiling division without overflow. // Since a is non-zero, (a - 1) / b will not overflow. // The largest possible result occurs when (a - 1) / b is type(uint256).max, // but the largest value we can obtain is type(uint256).max - 1, which happens // when a = type(uint256).max and b = 1. unchecked { return SafeCast.toUint(a > 0) * ((a - 1) / b + 1); } } /** * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or * denominator == 0. * * 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²⁵⁶ and mod 2²⁵⁶ - 1, then use // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2²⁵⁶ + prod0. uint256 prod0 = x * y; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) 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²⁵⁶. Also prevents denominator == 0. if (denominator <= prod1) { Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_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. uint256 twos = denominator & (0 - denominator); 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²⁵⁶ / 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²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv ≡ 1 mod 2⁴. 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⁸ inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶ inverse *= 2 - denominator * inverse; // inverse mod 2³² inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴ inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸ inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶ // 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²⁵⁶. Since the preconditions guarantee that the outcome is // less than 2²⁵⁶, 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; } } /** * @dev 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) { return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0); } /** * @dev Calculate the modular multiplicative inverse of a number in Z/nZ. * * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0. * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible. * * If the input value is not inversible, 0 is returned. * * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}. */ function invMod(uint256 a, uint256 n) internal pure returns (uint256) { unchecked { if (n == 0) return 0; // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version) // Used to compute integers x and y such that: ax + ny = gcd(a, n). // When the gcd is 1, then the inverse of a modulo n exists and it's x. // ax + ny = 1 // ax = 1 + (-y)n // ax ≡ 1 (mod n) # x is the inverse of a modulo n // If the remainder is 0 the gcd is n right away. uint256 remainder = a % n; uint256 gcd = n; // Therefore the initial coefficients are: // ax + ny = gcd(a, n) = n // 0a + 1n = n int256 x = 0; int256 y = 1; while (remainder != 0) { uint256 quotient = gcd / remainder; (gcd, remainder) = ( // The old remainder is the next gcd to try. remainder, // Compute the next remainder. // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd // where gcd is at most n (capped to type(uint256).max) gcd - remainder * quotient ); (x, y) = ( // Increment the coefficient of a. y, // Decrement the coefficient of n. // Can overflow, but the result is casted to uint256 so that the // next value of y is "wrapped around" to a value between 0 and n - 1. x - y * int256(quotient) ); } if (gcd != 1) return 0; // No inverse exists. return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative. } } /** * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`. * * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that * `a**(p-2)` is the modular multiplicative inverse of a in Fp. * * NOTE: this function does NOT check that `p` is a prime greater than `2`. */ function invModPrime(uint256 a, uint256 p) internal view returns (uint256) { unchecked { return Math.modExp(a, p - 2, p); } } /** * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m) * * Requirements: * - modulus can't be zero * - underlying staticcall to precompile must succeed * * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make * sure the chain you're using it on supports the precompiled contract for modular exponentiation * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, * the underlying function will succeed given the lack of a revert, but the result may be incorrectly * interpreted as 0. */ function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) { (bool success, uint256 result) = tryModExp(b, e, m); if (!success) { Panic.panic(Panic.DIVISION_BY_ZERO); } return result; } /** * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m). * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying * to operate modulo 0 or if the underlying precompile reverted. * * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack * of a revert, but the result may be incorrectly interpreted as 0. */ function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) { if (m == 0) return (false, 0); assembly ("memory-safe") { let ptr := mload(0x40) // | Offset | Content | Content (Hex) | // |-----------|------------|--------------------------------------------------------------------| // | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 | // | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 | // | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 | // | 0x60:0x7f | value of b | 0x<.............................................................b> | // | 0x80:0x9f | value of e | 0x<.............................................................e> | // | 0xa0:0xbf | value of m | 0x<.............................................................m> | mstore(ptr, 0x20) mstore(add(ptr, 0x20), 0x20) mstore(add(ptr, 0x40), 0x20) mstore(add(ptr, 0x60), b) mstore(add(ptr, 0x80), e) mstore(add(ptr, 0xa0), m) // Given the result < m, it's guaranteed to fit in 32 bytes, // so we can use the memory scratch space located at offset 0. success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20) result := mload(0x00) } } /** * @dev Variant of {modExp} that supports inputs of arbitrary length. */ function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) { (bool success, bytes memory result) = tryModExp(b, e, m); if (!success) { Panic.panic(Panic.DIVISION_BY_ZERO); } return result; } /** * @dev Variant of {tryModExp} that supports inputs of arbitrary length. */ function tryModExp( bytes memory b, bytes memory e, bytes memory m ) internal view returns (bool success, bytes memory result) { if (_zeroBytes(m)) return (false, new bytes(0)); uint256 mLen = m.length; // Encode call args in result and move the free memory pointer result = abi.encodePacked(b.length, e.length, mLen, b, e, m); assembly ("memory-safe") { let dataPtr := add(result, 0x20) // Write result on top of args to avoid allocating extra memory. success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen) // Overwrite the length. // result.length > returndatasize() is guaranteed because returndatasize() == m.length mstore(result, mLen) // Set the memory pointer after the returned data. mstore(0x40, add(dataPtr, mLen)) } } /** * @dev Returns whether the provided byte array is zero. */ function _zeroBytes(bytes memory byteArray) private pure returns (bool) { for (uint256 i = 0; i < byteArray.length; ++i) { if (byteArray[i] != 0) { return false; } } return true; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded * towards zero. * * This method is based on Newton's method for computing square roots; the algorithm is restricted to only * using integer operations. */ function sqrt(uint256 a) internal pure returns (uint256) { unchecked { // Take care of easy edge cases when a == 0 or a == 1 if (a <= 1) { return a; } // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between // the current value as `ε_n = | x_n - sqrt(a) |`. // // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is // bigger than any uint256. // // By noticing that // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)` // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar // to the msb function. uint256 aa = a; uint256 xn = 1; if (aa >= (1 << 128)) { aa >>= 128; xn <<= 64; } if (aa >= (1 << 64)) { aa >>= 64; xn <<= 32; } if (aa >= (1 << 32)) { aa >>= 32; xn <<= 16; } if (aa >= (1 << 16)) { aa >>= 16; xn <<= 8; } if (aa >= (1 << 8)) { aa >>= 8; xn <<= 4; } if (aa >= (1 << 4)) { aa >>= 4; xn <<= 2; } if (aa >= (1 << 2)) { xn <<= 1; } // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1). // // We can refine our estimation by noticing that the middle of that interval minimizes the error. // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2). // This is going to be our x_0 (and ε_0) xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2) // From here, Newton's method give us: // x_{n+1} = (x_n + a / x_n) / 2 // // One should note that: // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a // = ((x_n² + a) / (2 * x_n))² - a // = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a // = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²) // = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²) // = (x_n² - a)² / (2 * x_n)² // = ((x_n² - a) / (2 * x_n))² // ≥ 0 // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n // // This gives us the proof of quadratic convergence of the sequence: // ε_{n+1} = | x_{n+1} - sqrt(a) | // = | (x_n + a / x_n) / 2 - sqrt(a) | // = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) | // = | (x_n - sqrt(a))² / (2 * x_n) | // = | ε_n² / (2 * x_n) | // = ε_n² / | (2 * x_n) | // // For the first iteration, we have a special case where x_0 is known: // ε_1 = ε_0² / | (2 * x_0) | // ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2))) // ≤ 2**(2*e-4) / (3 * 2**(e-1)) // ≤ 2**(e-3) / 3 // ≤ 2**(e-3-log2(3)) // ≤ 2**(e-4.5) // // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n: // ε_{n+1} = ε_n² / | (2 * x_n) | // ≤ (2**(e-k))² / (2 * 2**(e-1)) // ≤ 2**(2*e-2*k) / 2**e // ≤ 2**(e-2*k) xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5 xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9 xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18 xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36 xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72 // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either // sqrt(a) or sqrt(a) + 1. return xn - SafeCast.toUint(xn > a / xn); } } /** * @dev 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a); } } /** * @dev Return the log in base 2 of a positive value rounded towards zero. * Returns 0 if given 0. */ function log2(uint256 x) internal pure returns (uint256 r) { // If value has upper 128 bits set, log2 result is at least 128 r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7; // If upper 64 bits of 128-bit half set, add 64 to result r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6; // If upper 32 bits of 64-bit half set, add 32 to result r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5; // If upper 16 bits of 32-bit half set, add 16 to result r |= SafeCast.toUint((x >> r) > 0xffff) << 4; // If upper 8 bits of 16-bit half set, add 8 to result r |= SafeCast.toUint((x >> r) > 0xff) << 3; // If upper 4 bits of 8-bit half set, add 4 to result r |= SafeCast.toUint((x >> r) > 0xf) << 2; // Shifts value right by the current result and use it as an index into this lookup table: // // | x (4 bits) | index | table[index] = MSB position | // |------------|---------|-----------------------------| // | 0000 | 0 | table[0] = 0 | // | 0001 | 1 | table[1] = 0 | // | 0010 | 2 | table[2] = 1 | // | 0011 | 3 | table[3] = 1 | // | 0100 | 4 | table[4] = 2 | // | 0101 | 5 | table[5] = 2 | // | 0110 | 6 | table[6] = 2 | // | 0111 | 7 | table[7] = 2 | // | 1000 | 8 | table[8] = 3 | // | 1001 | 9 | table[9] = 3 | // | 1010 | 10 | table[10] = 3 | // | 1011 | 11 | table[11] = 3 | // | 1100 | 12 | table[12] = 3 | // | 1101 | 13 | table[13] = 3 | // | 1110 | 14 | table[14] = 3 | // | 1111 | 15 | table[15] = 3 | // // The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes. assembly ("memory-safe") { r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000)) } } /** * @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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value); } } /** * @dev Return the log in base 10 of a positive value rounded towards zero. * 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value); } } /** * @dev Return the log in base 256 of a positive value rounded towards zero. * 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 x) internal pure returns (uint256 r) { // If value has upper 128 bits set, log2 result is at least 128 r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7; // If upper 64 bits of 128-bit half set, add 64 to result r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6; // If upper 32 bits of 64-bit half set, add 32 to result r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5; // If upper 16 bits of 32-bit half set, add 16 to result r |= SafeCast.toUint((x >> r) > 0xffff) << 4; // Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8 return (r >> 3) | SafeCast.toUint((x >> r) > 0xff); } /** * @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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value); } } /** * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers. */ function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) { return uint8(rounding) % 2 == 1; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol) // This file was procedurally generated from scripts/generate/templates/SafeCast.js. pragma solidity ^0.8.20; /** * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeCast { /** * @dev Value doesn't fit in an uint of `bits` size. */ error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value); /** * @dev An int value doesn't fit in an uint of `bits` size. */ error SafeCastOverflowedIntToUint(int256 value); /** * @dev Value doesn't fit in an int of `bits` size. */ error SafeCastOverflowedIntDowncast(uint8 bits, int256 value); /** * @dev An uint value doesn't fit in an int of `bits` size. */ error SafeCastOverflowedUintToInt(uint256 value); /** * @dev Returns the downcasted uint248 from uint256, reverting on * overflow (when the input is greater than largest uint248). * * Counterpart to Solidity's `uint248` operator. * * Requirements: * * - input must fit into 248 bits */ function toUint248(uint256 value) internal pure returns (uint248) { if (value > type(uint248).max) { revert SafeCastOverflowedUintDowncast(248, value); } return uint248(value); } /** * @dev Returns the downcasted uint240 from uint256, reverting on * overflow (when the input is greater than largest uint240). * * Counterpart to Solidity's `uint240` operator. * * Requirements: * * - input must fit into 240 bits */ function toUint240(uint256 value) internal pure returns (uint240) { if (value > type(uint240).max) { revert SafeCastOverflowedUintDowncast(240, value); } return uint240(value); } /** * @dev Returns the downcasted uint232 from uint256, reverting on * overflow (when the input is greater than largest uint232). * * Counterpart to Solidity's `uint232` operator. * * Requirements: * * - input must fit into 232 bits */ function toUint232(uint256 value) internal pure returns (uint232) { if (value > type(uint232).max) { revert SafeCastOverflowedUintDowncast(232, value); } return uint232(value); } /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits */ function toUint224(uint256 value) internal pure returns (uint224) { if (value > type(uint224).max) { revert SafeCastOverflowedUintDowncast(224, value); } return uint224(value); } /** * @dev Returns the downcasted uint216 from uint256, reverting on * overflow (when the input is greater than largest uint216). * * Counterpart to Solidity's `uint216` operator. * * Requirements: * * - input must fit into 216 bits */ function toUint216(uint256 value) internal pure returns (uint216) { if (value > type(uint216).max) { revert SafeCastOverflowedUintDowncast(216, value); } return uint216(value); } /** * @dev Returns the downcasted uint208 from uint256, reverting on * overflow (when the input is greater than largest uint208). * * Counterpart to Solidity's `uint208` operator. * * Requirements: * * - input must fit into 208 bits */ function toUint208(uint256 value) internal pure returns (uint208) { if (value > type(uint208).max) { revert SafeCastOverflowedUintDowncast(208, value); } return uint208(value); } /** * @dev Returns the downcasted uint200 from uint256, reverting on * overflow (when the input is greater than largest uint200). * * Counterpart to Solidity's `uint200` operator. * * Requirements: * * - input must fit into 200 bits */ function toUint200(uint256 value) internal pure returns (uint200) { if (value > type(uint200).max) { revert SafeCastOverflowedUintDowncast(200, value); } return uint200(value); } /** * @dev Returns the downcasted uint192 from uint256, reverting on * overflow (when the input is greater than largest uint192). * * Counterpart to Solidity's `uint192` operator. * * Requirements: * * - input must fit into 192 bits */ function toUint192(uint256 value) internal pure returns (uint192) { if (value > type(uint192).max) { revert SafeCastOverflowedUintDowncast(192, value); } return uint192(value); } /** * @dev Returns the downcasted uint184 from uint256, reverting on * overflow (when the input is greater than largest uint184). * * Counterpart to Solidity's `uint184` operator. * * Requirements: * * - input must fit into 184 bits */ function toUint184(uint256 value) internal pure returns (uint184) { if (value > type(uint184).max) { revert SafeCastOverflowedUintDowncast(184, value); } return uint184(value); } /** * @dev Returns the downcasted uint176 from uint256, reverting on * overflow (when the input is greater than largest uint176). * * Counterpart to Solidity's `uint176` operator. * * Requirements: * * - input must fit into 176 bits */ function toUint176(uint256 value) internal pure returns (uint176) { if (value > type(uint176).max) { revert SafeCastOverflowedUintDowncast(176, value); } return uint176(value); } /** * @dev Returns the downcasted uint168 from uint256, reverting on * overflow (when the input is greater than largest uint168). * * Counterpart to Solidity's `uint168` operator. * * Requirements: * * - input must fit into 168 bits */ function toUint168(uint256 value) internal pure returns (uint168) { if (value > type(uint168).max) { revert SafeCastOverflowedUintDowncast(168, value); } return uint168(value); } /** * @dev Returns the downcasted uint160 from uint256, reverting on * overflow (when the input is greater than largest uint160). * * Counterpart to Solidity's `uint160` operator. * * Requirements: * * - input must fit into 160 bits */ function toUint160(uint256 value) internal pure returns (uint160) { if (value > type(uint160).max) { revert SafeCastOverflowedUintDowncast(160, value); } return uint160(value); } /** * @dev Returns the downcasted uint152 from uint256, reverting on * overflow (when the input is greater than largest uint152). * * Counterpart to Solidity's `uint152` operator. * * Requirements: * * - input must fit into 152 bits */ function toUint152(uint256 value) internal pure returns (uint152) { if (value > type(uint152).max) { revert SafeCastOverflowedUintDowncast(152, value); } return uint152(value); } /** * @dev Returns the downcasted uint144 from uint256, reverting on * overflow (when the input is greater than largest uint144). * * Counterpart to Solidity's `uint144` operator. * * Requirements: * * - input must fit into 144 bits */ function toUint144(uint256 value) internal pure returns (uint144) { if (value > type(uint144).max) { revert SafeCastOverflowedUintDowncast(144, value); } return uint144(value); } /** * @dev Returns the downcasted uint136 from uint256, reverting on * overflow (when the input is greater than largest uint136). * * Counterpart to Solidity's `uint136` operator. * * Requirements: * * - input must fit into 136 bits */ function toUint136(uint256 value) internal pure returns (uint136) { if (value > type(uint136).max) { revert SafeCastOverflowedUintDowncast(136, value); } return uint136(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits */ function toUint128(uint256 value) internal pure returns (uint128) { if (value > type(uint128).max) { revert SafeCastOverflowedUintDowncast(128, value); } return uint128(value); } /** * @dev Returns the downcasted uint120 from uint256, reverting on * overflow (when the input is greater than largest uint120). * * Counterpart to Solidity's `uint120` operator. * * Requirements: * * - input must fit into 120 bits */ function toUint120(uint256 value) internal pure returns (uint120) { if (value > type(uint120).max) { revert SafeCastOverflowedUintDowncast(120, value); } return uint120(value); } /** * @dev Returns the downcasted uint112 from uint256, reverting on * overflow (when the input is greater than largest uint112). * * Counterpart to Solidity's `uint112` operator. * * Requirements: * * - input must fit into 112 bits */ function toUint112(uint256 value) internal pure returns (uint112) { if (value > type(uint112).max) { revert SafeCastOverflowedUintDowncast(112, value); } return uint112(value); } /** * @dev Returns the downcasted uint104 from uint256, reverting on * overflow (when the input is greater than largest uint104). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 104 bits */ function toUint104(uint256 value) internal pure returns (uint104) { if (value > type(uint104).max) { revert SafeCastOverflowedUintDowncast(104, value); } return uint104(value); } /** * @dev Returns the downcasted uint96 from uint256, reverting on * overflow (when the input is greater than largest uint96). * * Counterpart to Solidity's `uint96` operator. * * Requirements: * * - input must fit into 96 bits */ function toUint96(uint256 value) internal pure returns (uint96) { if (value > type(uint96).max) { revert SafeCastOverflowedUintDowncast(96, value); } return uint96(value); } /** * @dev Returns the downcasted uint88 from uint256, reverting on * overflow (when the input is greater than largest uint88). * * Counterpart to Solidity's `uint88` operator. * * Requirements: * * - input must fit into 88 bits */ function toUint88(uint256 value) internal pure returns (uint88) { if (value > type(uint88).max) { revert SafeCastOverflowedUintDowncast(88, value); } return uint88(value); } /** * @dev Returns the downcasted uint80 from uint256, reverting on * overflow (when the input is greater than largest uint80). * * Counterpart to Solidity's `uint80` operator. * * Requirements: * * - input must fit into 80 bits */ function toUint80(uint256 value) internal pure returns (uint80) { if (value > type(uint80).max) { revert SafeCastOverflowedUintDowncast(80, value); } return uint80(value); } /** * @dev Returns the downcasted uint72 from uint256, reverting on * overflow (when the input is greater than largest uint72). * * Counterpart to Solidity's `uint72` operator. * * Requirements: * * - input must fit into 72 bits */ function toUint72(uint256 value) internal pure returns (uint72) { if (value > type(uint72).max) { revert SafeCastOverflowedUintDowncast(72, value); } return uint72(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits */ function toUint64(uint256 value) internal pure returns (uint64) { if (value > type(uint64).max) { revert SafeCastOverflowedUintDowncast(64, value); } return uint64(value); } /** * @dev Returns the downcasted uint56 from uint256, reverting on * overflow (when the input is greater than largest uint56). * * Counterpart to Solidity's `uint56` operator. * * Requirements: * * - input must fit into 56 bits */ function toUint56(uint256 value) internal pure returns (uint56) { if (value > type(uint56).max) { revert SafeCastOverflowedUintDowncast(56, value); } return uint56(value); } /** * @dev Returns the downcasted uint48 from uint256, reverting on * overflow (when the input is greater than largest uint48). * * Counterpart to Solidity's `uint48` operator. * * Requirements: * * - input must fit into 48 bits */ function toUint48(uint256 value) internal pure returns (uint48) { if (value > type(uint48).max) { revert SafeCastOverflowedUintDowncast(48, value); } return uint48(value); } /** * @dev Returns the downcasted uint40 from uint256, reverting on * overflow (when the input is greater than largest uint40). * * Counterpart to Solidity's `uint40` operator. * * Requirements: * * - input must fit into 40 bits */ function toUint40(uint256 value) internal pure returns (uint40) { if (value > type(uint40).max) { revert SafeCastOverflowedUintDowncast(40, value); } return uint40(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits */ function toUint32(uint256 value) internal pure returns (uint32) { if (value > type(uint32).max) { revert SafeCastOverflowedUintDowncast(32, value); } return uint32(value); } /** * @dev Returns the downcasted uint24 from uint256, reverting on * overflow (when the input is greater than largest uint24). * * Counterpart to Solidity's `uint24` operator. * * Requirements: * * - input must fit into 24 bits */ function toUint24(uint256 value) internal pure returns (uint24) { if (value > type(uint24).max) { revert SafeCastOverflowedUintDowncast(24, value); } return uint24(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits */ function toUint16(uint256 value) internal pure returns (uint16) { if (value > type(uint16).max) { revert SafeCastOverflowedUintDowncast(16, value); } return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits */ function toUint8(uint256 value) internal pure returns (uint8) { if (value > type(uint8).max) { revert SafeCastOverflowedUintDowncast(8, value); } return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. */ function toUint256(int256 value) internal pure returns (uint256) { if (value < 0) { revert SafeCastOverflowedIntToUint(value); } return uint256(value); } /** * @dev Returns the downcasted int248 from int256, reverting on * overflow (when the input is less than smallest int248 or * greater than largest int248). * * Counterpart to Solidity's `int248` operator. * * Requirements: * * - input must fit into 248 bits */ function toInt248(int256 value) internal pure returns (int248 downcasted) { downcasted = int248(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(248, value); } } /** * @dev Returns the downcasted int240 from int256, reverting on * overflow (when the input is less than smallest int240 or * greater than largest int240). * * Counterpart to Solidity's `int240` operator. * * Requirements: * * - input must fit into 240 bits */ function toInt240(int256 value) internal pure returns (int240 downcasted) { downcasted = int240(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(240, value); } } /** * @dev Returns the downcasted int232 from int256, reverting on * overflow (when the input is less than smallest int232 or * greater than largest int232). * * Counterpart to Solidity's `int232` operator. * * Requirements: * * - input must fit into 232 bits */ function toInt232(int256 value) internal pure returns (int232 downcasted) { downcasted = int232(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(232, value); } } /** * @dev Returns the downcasted int224 from int256, reverting on * overflow (when the input is less than smallest int224 or * greater than largest int224). * * Counterpart to Solidity's `int224` operator. * * Requirements: * * - input must fit into 224 bits */ function toInt224(int256 value) internal pure returns (int224 downcasted) { downcasted = int224(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(224, value); } } /** * @dev Returns the downcasted int216 from int256, reverting on * overflow (when the input is less than smallest int216 or * greater than largest int216). * * Counterpart to Solidity's `int216` operator. * * Requirements: * * - input must fit into 216 bits */ function toInt216(int256 value) internal pure returns (int216 downcasted) { downcasted = int216(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(216, value); } } /** * @dev Returns the downcasted int208 from int256, reverting on * overflow (when the input is less than smallest int208 or * greater than largest int208). * * Counterpart to Solidity's `int208` operator. * * Requirements: * * - input must fit into 208 bits */ function toInt208(int256 value) internal pure returns (int208 downcasted) { downcasted = int208(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(208, value); } } /** * @dev Returns the downcasted int200 from int256, reverting on * overflow (when the input is less than smallest int200 or * greater than largest int200). * * Counterpart to Solidity's `int200` operator. * * Requirements: * * - input must fit into 200 bits */ function toInt200(int256 value) internal pure returns (int200 downcasted) { downcasted = int200(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(200, value); } } /** * @dev Returns the downcasted int192 from int256, reverting on * overflow (when the input is less than smallest int192 or * greater than largest int192). * * Counterpart to Solidity's `int192` operator. * * Requirements: * * - input must fit into 192 bits */ function toInt192(int256 value) internal pure returns (int192 downcasted) { downcasted = int192(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(192, value); } } /** * @dev Returns the downcasted int184 from int256, reverting on * overflow (when the input is less than smallest int184 or * greater than largest int184). * * Counterpart to Solidity's `int184` operator. * * Requirements: * * - input must fit into 184 bits */ function toInt184(int256 value) internal pure returns (int184 downcasted) { downcasted = int184(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(184, value); } } /** * @dev Returns the downcasted int176 from int256, reverting on * overflow (when the input is less than smallest int176 or * greater than largest int176). * * Counterpart to Solidity's `int176` operator. * * Requirements: * * - input must fit into 176 bits */ function toInt176(int256 value) internal pure returns (int176 downcasted) { downcasted = int176(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(176, value); } } /** * @dev Returns the downcasted int168 from int256, reverting on * overflow (when the input is less than smallest int168 or * greater than largest int168). * * Counterpart to Solidity's `int168` operator. * * Requirements: * * - input must fit into 168 bits */ function toInt168(int256 value) internal pure returns (int168 downcasted) { downcasted = int168(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(168, value); } } /** * @dev Returns the downcasted int160 from int256, reverting on * overflow (when the input is less than smallest int160 or * greater than largest int160). * * Counterpart to Solidity's `int160` operator. * * Requirements: * * - input must fit into 160 bits */ function toInt160(int256 value) internal pure returns (int160 downcasted) { downcasted = int160(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(160, value); } } /** * @dev Returns the downcasted int152 from int256, reverting on * overflow (when the input is less than smallest int152 or * greater than largest int152). * * Counterpart to Solidity's `int152` operator. * * Requirements: * * - input must fit into 152 bits */ function toInt152(int256 value) internal pure returns (int152 downcasted) { downcasted = int152(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(152, value); } } /** * @dev Returns the downcasted int144 from int256, reverting on * overflow (when the input is less than smallest int144 or * greater than largest int144). * * Counterpart to Solidity's `int144` operator. * * Requirements: * * - input must fit into 144 bits */ function toInt144(int256 value) internal pure returns (int144 downcasted) { downcasted = int144(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(144, value); } } /** * @dev Returns the downcasted int136 from int256, reverting on * overflow (when the input is less than smallest int136 or * greater than largest int136). * * Counterpart to Solidity's `int136` operator. * * Requirements: * * - input must fit into 136 bits */ function toInt136(int256 value) internal pure returns (int136 downcasted) { downcasted = int136(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(136, value); } } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits */ function toInt128(int256 value) internal pure returns (int128 downcasted) { downcasted = int128(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(128, value); } } /** * @dev Returns the downcasted int120 from int256, reverting on * overflow (when the input is less than smallest int120 or * greater than largest int120). * * Counterpart to Solidity's `int120` operator. * * Requirements: * * - input must fit into 120 bits */ function toInt120(int256 value) internal pure returns (int120 downcasted) { downcasted = int120(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(120, value); } } /** * @dev Returns the downcasted int112 from int256, reverting on * overflow (when the input is less than smallest int112 or * greater than largest int112). * * Counterpart to Solidity's `int112` operator. * * Requirements: * * - input must fit into 112 bits */ function toInt112(int256 value) internal pure returns (int112 downcasted) { downcasted = int112(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(112, value); } } /** * @dev Returns the downcasted int104 from int256, reverting on * overflow (when the input is less than smallest int104 or * greater than largest int104). * * Counterpart to Solidity's `int104` operator. * * Requirements: * * - input must fit into 104 bits */ function toInt104(int256 value) internal pure returns (int104 downcasted) { downcasted = int104(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(104, value); } } /** * @dev Returns the downcasted int96 from int256, reverting on * overflow (when the input is less than smallest int96 or * greater than largest int96). * * Counterpart to Solidity's `int96` operator. * * Requirements: * * - input must fit into 96 bits */ function toInt96(int256 value) internal pure returns (int96 downcasted) { downcasted = int96(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(96, value); } } /** * @dev Returns the downcasted int88 from int256, reverting on * overflow (when the input is less than smallest int88 or * greater than largest int88). * * Counterpart to Solidity's `int88` operator. * * Requirements: * * - input must fit into 88 bits */ function toInt88(int256 value) internal pure returns (int88 downcasted) { downcasted = int88(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(88, value); } } /** * @dev Returns the downcasted int80 from int256, reverting on * overflow (when the input is less than smallest int80 or * greater than largest int80). * * Counterpart to Solidity's `int80` operator. * * Requirements: * * - input must fit into 80 bits */ function toInt80(int256 value) internal pure returns (int80 downcasted) { downcasted = int80(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(80, value); } } /** * @dev Returns the downcasted int72 from int256, reverting on * overflow (when the input is less than smallest int72 or * greater than largest int72). * * Counterpart to Solidity's `int72` operator. * * Requirements: * * - input must fit into 72 bits */ function toInt72(int256 value) internal pure returns (int72 downcasted) { downcasted = int72(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(72, value); } } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits */ function toInt64(int256 value) internal pure returns (int64 downcasted) { downcasted = int64(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(64, value); } } /** * @dev Returns the downcasted int56 from int256, reverting on * overflow (when the input is less than smallest int56 or * greater than largest int56). * * Counterpart to Solidity's `int56` operator. * * Requirements: * * - input must fit into 56 bits */ function toInt56(int256 value) internal pure returns (int56 downcasted) { downcasted = int56(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(56, value); } } /** * @dev Returns the downcasted int48 from int256, reverting on * overflow (when the input is less than smallest int48 or * greater than largest int48). * * Counterpart to Solidity's `int48` operator. * * Requirements: * * - input must fit into 48 bits */ function toInt48(int256 value) internal pure returns (int48 downcasted) { downcasted = int48(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(48, value); } } /** * @dev Returns the downcasted int40 from int256, reverting on * overflow (when the input is less than smallest int40 or * greater than largest int40). * * Counterpart to Solidity's `int40` operator. * * Requirements: * * - input must fit into 40 bits */ function toInt40(int256 value) internal pure returns (int40 downcasted) { downcasted = int40(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(40, value); } } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits */ function toInt32(int256 value) internal pure returns (int32 downcasted) { downcasted = int32(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(32, value); } } /** * @dev Returns the downcasted int24 from int256, reverting on * overflow (when the input is less than smallest int24 or * greater than largest int24). * * Counterpart to Solidity's `int24` operator. * * Requirements: * * - input must fit into 24 bits */ function toInt24(int256 value) internal pure returns (int24 downcasted) { downcasted = int24(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(24, value); } } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits */ function toInt16(int256 value) internal pure returns (int16 downcasted) { downcasted = int16(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(16, value); } } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits */ function toInt8(int256 value) internal pure returns (int8 downcasted) { downcasted = int8(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(8, value); } } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive if (value > uint256(type(int256).max)) { revert SafeCastOverflowedUintToInt(value); } return int256(value); } /** * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump. */ function toUint(bool b) internal pure returns (uint256 u) { assembly ("memory-safe") { u := iszero(iszero(b)) } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.20; import {SafeCast} from "./SafeCast.sol"; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMath { /** * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant. * * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone. * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute * one branch when needed, making this function more expensive. */ function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) { unchecked { // branchless ternary works because: // b ^ (a ^ b) == a // b ^ 0 == b return b ^ ((a ^ b) * int256(SafeCast.toUint(condition))); } } /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return ternary(a > b, a, b); } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return ternary(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 { // Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson. // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift, // taking advantage of the most significant (or "sign" bit) in two's complement representation. // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result, // the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative). int256 mask = n >> 255; // A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it. return uint256((n + mask) ^ mask); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC-165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[ERC]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol) pragma solidity ^0.8.20; /** * @dev Helper library for emitting standardized panic codes. * * ```solidity * contract Example { * using Panic for uint256; * * // Use any of the declared internal constants * function foo() { Panic.GENERIC.panic(); } * * // Alternatively * function foo() { Panic.panic(Panic.GENERIC); } * } * ``` * * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil]. * * _Available since v5.1._ */ // slither-disable-next-line unused-state library Panic { /// @dev generic / unspecified error uint256 internal constant GENERIC = 0x00; /// @dev used by the assert() builtin uint256 internal constant ASSERT = 0x01; /// @dev arithmetic underflow or overflow uint256 internal constant UNDER_OVERFLOW = 0x11; /// @dev division or modulo by zero uint256 internal constant DIVISION_BY_ZERO = 0x12; /// @dev enum conversion error uint256 internal constant ENUM_CONVERSION_ERROR = 0x21; /// @dev invalid encoding in storage uint256 internal constant STORAGE_ENCODING_ERROR = 0x22; /// @dev empty array pop uint256 internal constant EMPTY_ARRAY_POP = 0x31; /// @dev array out of bounds access uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32; /// @dev resource error (too large allocation or too large array) uint256 internal constant RESOURCE_ERROR = 0x41; /// @dev calling invalid internal function uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51; /// @dev Reverts with a panic code. Recommended to use with /// the internal constants with predefined codes. function panic(uint256 code) internal pure { assembly ("memory-safe") { mstore(0x00, 0x4e487b71) mstore(0x20, code) revert(0x1c, 0x24) } } }
{ "remappings": [ "forge-std/=lib/forge-std/src/", "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/", "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/", "@onchainclob/contracts/=lib/onchain-clob-contracts/src/", "@pythnetwork/pyth-sdk-solidity/=lib/pyth-sdk-solidity/", "@solmate/src/=lib/onchain-clob-contracts/lib/solmate/src/", "ds-test/=lib/solmate/lib/ds-test/src/", "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/", "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/", "onchain-clob-contracts/=lib/onchain-clob-contracts/src/", "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/", "openzeppelin-contracts/=lib/openzeppelin-contracts/", "pyth-sdk-solidity/=lib/pyth-sdk-solidity/", "solmate/=lib/solmate/src/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "abi" ] } }, "evmVersion": "cancun", "viaIR": true, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"pythAddress","type":"address"},{"internalType":"string","name":"_domainName","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"EmptyDomainName","type":"error"},{"inputs":[],"name":"InsufficientFeeForPythUpdate","type":"error"},{"inputs":[],"name":"InvalidLobAddress","type":"error"},{"inputs":[],"name":"InvalidShortString","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[],"name":"InvalidTrader","type":"error"},{"inputs":[],"name":"OrderAlreadyUsed","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[{"internalType":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"inputs":[],"name":"TransferFailed","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"lobAddress","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"address","name":"lpManagerAddress","type":"address"},{"indexed":false,"internalType":"address","name":"marketMaker","type":"address"},{"indexed":false,"internalType":"bool","name":"targetValueTransaction","type":"bool"},{"indexed":false,"internalType":"bool","name":"isAsk","type":"bool"},{"indexed":false,"internalType":"uint128","name":"quantity","type":"uint128"},{"indexed":false,"internalType":"uint72","name":"price","type":"uint72"},{"indexed":false,"internalType":"uint128","name":"nonce","type":"uint128"}],"name":"ClientOrderPlaced","type":"event"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"lpManagerAddress","type":"address"},{"internalType":"uint8","name":"lobId","type":"uint8"},{"internalType":"uint128","name":"quoteQty","type":"uint128"},{"internalType":"uint72","name":"quotePrice","type":"uint72"},{"internalType":"bool","name":"quoteMarketOnly","type":"bool"},{"internalType":"bool","name":"quotePostOnly","type":"bool"},{"internalType":"uint256","name":"inputAmount","type":"uint256"},{"components":[{"internalType":"address","name":"userAddress","type":"address"},{"internalType":"address","name":"lobAddress","type":"address"},{"internalType":"bool","name":"targetValueTransaction","type":"bool"},{"internalType":"uint128","name":"orderAmount","type":"uint128"},{"internalType":"uint72","name":"price","type":"uint72"},{"internalType":"bool","name":"isAsk","type":"bool"},{"internalType":"uint256","name":"expires","type":"uint256"},{"internalType":"uint128","name":"nonce","type":"uint128"}],"internalType":"struct ClientOrder","name":"clientOrder","type":"tuple"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"bytes[]","name":"priceUpdateData","type":"bytes[]"}],"name":"swapWithRfqOrder","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"lpManagerAddress","type":"address"},{"internalType":"uint8","name":"lobId","type":"uint8"},{"internalType":"uint128","name":"quoteQty","type":"uint128"},{"internalType":"uint72","name":"quotePrice","type":"uint72"},{"internalType":"bool","name":"quoteMarketOnly","type":"bool"},{"internalType":"bool","name":"quotePostOnly","type":"bool"},{"internalType":"uint256","name":"inputAmount","type":"uint256"},{"components":[{"internalType":"address","name":"userAddress","type":"address"},{"internalType":"address","name":"lobAddress","type":"address"},{"internalType":"bool","name":"targetValueTransaction","type":"bool"},{"internalType":"uint128","name":"orderAmount","type":"uint128"},{"internalType":"uint72","name":"price","type":"uint72"},{"internalType":"bool","name":"isAsk","type":"bool"},{"internalType":"uint256","name":"expires","type":"uint256"},{"internalType":"uint128","name":"nonce","type":"uint128"}],"internalType":"struct ClientOrder","name":"clientOrder","type":"tuple"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"uint8","name":"vPermit","type":"uint8"},{"internalType":"bytes32","name":"rPermit","type":"bytes32"},{"internalType":"bytes32","name":"sPermit","type":"bytes32"},{"internalType":"bytes[]","name":"priceUpdateData","type":"bytes[]"}],"name":"swapWithRfqOrderWithPermit","outputs":[],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
61018080604052346101e2576123b4803803809161001d82856101fa565b83398101906040818303126101e25780516001600160a01b03811691908290036101e2576020810151906001600160401b0382116101e2570182601f820112156101e25780516001600160401b0381116101e65760405191610089601f8301601f1916602001846101fa565b8183526020830194602083830101116101e257815f926020809301875e830101526040928351906100ba85836101fa565b600182526020820190600d60fa1b825260015f556100d78461021d565b610120526100e4836103b8565b6101405283519020918260e05251902080610100524660a05284519060208201927f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f84528683015260608201524660808201523060a082015260a0815261014c60c0826101fa565b5190206080523060c05281156101d35751156101c4576101605251611ec390816104f1823960805181611b4e015260a05181611c0b015260c05181611b18015260e05181611b9d01526101005181611bc3015261012051816069015261014051816093015261016051818181610c0201526116ee0152f35b632f60176160e01b5f5260045ffd5b63d92e233d60e01b5f5260045ffd5b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b601f909101601f19168101906001600160401b038211908210176101e657604052565b908151602081105f14610297575090601f815111610257576020815191015160208210610248571790565b5f198260200360031b1b161790565b604460209160405192839163305a27a960e01b83528160048401528051918291826024860152018484015e5f828201840152601f01601f19168101030190fd5b6001600160401b0381116101e657600154600181811c911680156103ae575b602082101461039a57601f8111610367575b50602092601f821160011461030657928192935f926102fb575b50508160011b915f199060031b1c19161760015560ff90565b015190505f806102e2565b601f1982169360015f52805f20915f5b86811061034f5750836001959610610337575b505050811b0160015560ff90565b01515f1960f88460031b161c191690555f8080610329565b91926020600181928685015181550194019201610316565b60015f52601f60205f20910160051c810190601f830160051c015b81811061038f57506102c8565b5f8155600101610382565b634e487b7160e01b5f52602260045260245ffd5b90607f16906102b6565b908151602081105f146103e3575090601f815111610257576020815191015160208210610248571790565b6001600160401b0381116101e657600254600181811c911680156104e6575b602082101461039a57601f81116104b3575b50602092601f821160011461045257928192935f92610447575b50508160011b915f199060031b1c19161760025560ff90565b015190505f8061042e565b601f1982169360025f52805f20915f5b86811061049b5750836001959610610483575b505050811b0160025560ff90565b01515f1960f88460031b161c191690555f8080610475565b91926020600181928685015181550194019201610462565b60025f52601f60205f20910160051c810190601f830160051c015b8181106104db5750610414565b5f81556001016104ce565b90607f169061040256fe608080604052600436101561001c575b50361561001a575f80fd5b005b5f905f3560e01c9081632813631614610d18575080632d5c9a35146101715780633644e5151461014e576384b0196e0361000f573461014b578060031936011261014b576100ef9061008d7f0000000000000000000000000000000000000000000000000000000000000000611c94565b906100b77f0000000000000000000000000000000000000000000000000000000000000000611dbd565b9060206100fd604051936100cb83866118ed565b8385525f368137604051968796600f60f81b885260e08589015260e088019061189c565b90868203604088015261189c565b904660608601523060808601528260a086015284820360c08601528080855193848152019401925b82811061013457505050500390f35b835185528695509381019392810192600101610125565b80fd5b503461014b578060031936011261014b576020610169611b15565b604051908152f35b5061026036600319011261014b576101876117e8565b906101906117fe565b9161019961181f565b926101a2611835565b916101ab61184d565b946101b461185c565b956101003660e3190112610d14576101ca61180e565b9061022435976102443567ffffffffffffffff8111610b3d576101f190369060040161186b565b60028a5414610d055760028a55899080610bef575b506102149150340333611ab0565b60405163f60559eb60e01b81523360048201526020816024816001600160a01b038a165afa908115610b49578991610bb5575b5015610ba6576102556118c0565b926001600160a01b03841615610b9757886042610270611b15565b6101206040517f783ffce4219e675737141a1c936ab9c993cdf2ee6d70fc69bbe50ed9fe1c5fa9815261010060e46020830137206040519161190160f01b83526002830152602282015220809b82936fa2a8918ca85bafe22016d0b997e4df5f600160ff1b038210610b63575b505050506001600160a01b03848116911603610b5457604051630349079560e01b815260ff871660048201529060a0826024816001600160a01b038a165afa918215610b49578992610ad3575b506001600160a01b0361033b6118d6565b166001600160a01b03831603610ac457898952600360205260ff60408a205416610ab55768ffffffffffffffffff998952600360205260408920600160ff19825416179055610388611952565b9260209a8b9961039b6040519d8e6118ed565b8b8d526001600160801b03604051986323c9e08160e01b8a5260ff8c1660048b0152871560248b01521660448901521660648701526001600160801b036084870152151560a4860152151560c48501526101a43560e485015261012061010485015288519889610124860152610144850199886101448260051b8801019201908a5b818110610a8857505050889950968480829a9903818a60018060a01b038a165af19384156107bb578794610a4d575b506040516330fe427560e21b8152906101a0826004816001600160a01b0385165afa9283156108085788928994610985575b508015610976576001600160a01b0383165b6040516323b872dd60e01b8c8201526001600160a01b038716602482015230604482015260c43560648083019190915281526104d7906104d16084826118ed565b82611c31565b60405163095ea7b360e01b81526001600160a01b03848116600483015260c435602483015290918c91839160449183918f91165af1801561096b57610935575b50610520611987565b91610164359268ffffffffffffffffff8416809403610931578b918b918a6001600160801b038061054f611962565b9361055861199e565b604080516001600160a01b039687168152339a81019a909a52861515908a015289151560608a015291166080880181905260a088018a9052911660c0870152948a8216918416907fb56a8ebaf3a6f7a43b1ea78f9a031691e0303083d51d0ceeec3cfafd41298b389060e090a315610869579260c49160609460405196879586946356b9e99760e11b865215156004860152602485015260448401526001600160801b036064840152600160848401526101a43560a484015260018060a01b03165af1801561080857610813575b505b6040516370a0823160e01b81523060048201526001600160a01b0391909116908881602481855afa9081156108085788916107d7575b5083816107c6575b50506040516370a0823160e01b81523060048201526001600160a01b03929092169190508781602481855afa9081156107bb578791610778575b5067ffffffffffffffff94959697508281610767575b5050504780610757575b50501691826106d2575b836001815580f35b6001600160a01b0382163b1561075257608460ff9185809460405196879586946368bd322f60e01b865216600485015260248401528160448401526101a435606484015260018060a01b03165af1801561074757610732575b80806106ca565b8161073c916118ed565b61014b57805f61072b565b6040513d84823e3d90fd5b505050fd5b61076091611ab0565b5f806106c0565b61077092611a6d565b5f80826106b6565b94959650509583813d83116107b4575b61079281836118ed565b810103126107b057869567ffffffffffffffff9351879695946106a0565b5f80fd5b503d610788565b6040513d89823e3d90fd5b6107cf92611a6d565b5f8083610666565b809850898092503d8311610801575b6107f081836118ed565b810103126107b0578896515f61065e565b503d6107e6565b6040513d8a823e3d90fd5b6060813d606011610861575b8161082c606093836118ed565b8101031261085d57604081610843610856936119b5565b5061084f8b82016119b5565b50016119b5565b505f610626565b8780fd5b3d915061081f565b92610104916080946040519687958694633d44fbd360e21b865215156004860152602485015260448401526001600160801b036064840152600160848401528160a4840152600160c48401526101a43560e484015260018060a01b03165af18015610808576108d9575b50610628565b6080813d608011610929575b816108f2608093836118ed565b8101031261085d5760608161090961092293611972565b506109158b82016119b5565b5061084f604082016119b5565b505f6108d3565b3d91506108e5565b8a80fd5b8a81813d8311610964575b61094a81836118ed565b810103126109605761095b90611923565b610517565b8980fd5b503d610940565b6040513d8c823e3d90fd5b6001600160a01b038416610490565b925092506101a0823d8211610a45575b816109a36101a093836118ed565b8101031261085d576109b760408301611930565b610a3c6101806109c960608601611930565b946109d660808201611923565b506109e360a08201611923565b506109f060c08201611930565b506109fd60e08201611930565b50610a0b6101008201611972565b50610a196101208201611972565b50610a276101408201611972565b50610a356101608201611972565b5001611923565b5091925f61047e565b3d9150610995565b9093508781813d8311610a81575b610a6581836118ed565b81010312610a7d57610a7690611972565b925f61044c565b8680fd5b503d610a5b565b9091928a80610aa68f93600194610143198d8303019052875161189c565b95019d0191019b91909b61041d565b6388b3904360e01b8952600489fd5b63ec09da3560e01b8952600489fd5b90915060a0813d60a011610b41575b81610aef60a093836118ed565b81010312610b3d576080610b0282611930565b91610b0f60208201611944565b50610b1c60408201611944565b50610b2960608201611923565b50015161ffff811603610b3d57905f61032a565b8880fd5b3d9150610ae2565b6040513d8b823e3d90fd5b638baa579f60e01b8852600488fd5b60209450906080929160405192835285830152610204356040830152606082015282805260015afa508751888a5f806102dd565b63d92e233d60e01b8952600489fd5b637dbacad160e11b8852600488fd5b90506020813d602011610be7575b81610bd0602093836118ed565b81010312610b3d57610be190611923565b5f610247565b3d9150610bc3565b60405163d47eed4560e01b8152929091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169060208480610c3d8685600484016119c9565b0381855afa938415610cfa578c94610cc6575b5083803410610cb757823b15610cb35791610c8493918d93604051809681958294631df3cbc560e31b8452600484016119c9565b03925af1801561096b57908a91610c9e575b829150610206565b81610ca8916118ed565b610b3d57885f610c96565b8c80fd5b63e4764c6f60e01b8d5260048dfd5b9093506020813d602011610cf2575b81610ce2602093836118ed565b810103126107b05751925f610c50565b3d9150610cd5565b6040513d8e823e3d90fd5b633ee5aeb560e01b8a5260048afd5b8580fd5b826102e03660031901126107b057610d2e6117e8565b610d366117fe565b610d3e61181f565b91610d47611835565b92610d5061184d565b610d5861185c565b906101003660e31901126107b057610d6e61180e565b916102243598610244359060018060a01b0382168092036107b057610264359060ff82168092036107b0576102c43567ffffffffffffffff81116107b057610dba90369060040161186b565b929093610dc56118c0565b90803b156107b057835f60e4928195839563d505accf60e01b855260018060a01b0316600485015230602485015260c43560448501526101a435606485015260848401526102843560a48401526102a43560c48401525af16117d3575b5060028a5414610d055760028a558990806116db575b50610e469150340333611ab0565b60405163f60559eb60e01b81523360048201526020816024816001600160a01b038a165afa908115610b495789916116a1575b5015610ba657610e876118c0565b926001600160a01b03841615610b9757886042610ea2611b15565b6101206040517f783ffce4219e675737141a1c936ab9c993cdf2ee6d70fc69bbe50ed9fe1c5fa9815261010060e46020830137206040519161190160f01b83526002830152602282015220809b82936fa2a8918ca85bafe22016d0b997e4df5f600160ff1b03821061166d575b505050506001600160a01b03848116911603610b5457604051630349079560e01b815260ff871660048201529060a0826024816001600160a01b038a165afa918215610b495789926115fb575b506001600160a01b03610f6d6118d6565b166001600160a01b03831603610ac457898952600360205260ff60408a205416610ab55768ffffffffffffffffff998952600360205260408920600160ff19825416179055610fba611952565b9260209a8b99610fcd6040519d8e6118ed565b8b8d526001600160801b03604051986323c9e08160e01b8a5260ff8c1660048b0152871560248b01521660448901521660648701526001600160801b036084870152151560a4860152151560c48501526101a43560e485015261012061010485015288519889610124860152610144850199886101448260051b8801019201908a5b8181106115ce57505050889950968480829a9903818a60018060a01b038a165af19384156107bb578794611597575b506040516330fe427560e21b8152906101a0826004816001600160a01b0385165afa9283156108085788928994611542575b508015611533576001600160a01b0383165b6040516323b872dd60e01b8c8201526001600160a01b038716602482015230604482015260c4356064808301919091528152611103906104d16084826118ed565b60405163095ea7b360e01b81526001600160a01b03848116600483015260c435602483015290918c91839160449183918f91165af1801561096b57611501575b5061114c611987565b91610164359268ffffffffffffffffff8416809403610931578b918b918a6001600160801b038061117b611962565b9361118461199e565b604080516001600160a01b039687168152339a81019a909a52861515908a015289151560608a015291166080880181905260a088018a9052911660c0870152948a8216918416907fb56a8ebaf3a6f7a43b1ea78f9a031691e0303083d51d0ceeec3cfafd41298b389060e090a315611452579260c49160609460405196879586946356b9e99760e11b865215156004860152602485015260448401526001600160801b036064840152600160848401526101a43560a484015260018060a01b03165af1801561080857611413575b505b6040516370a0823160e01b81523060048201526001600160a01b0391909116908881602481855afa9081156108085788916113e2575b5083816113d1575b50506040516370a0823160e01b81523060048201526001600160a01b03929092169190508781602481855afa9081156107bb578791611392575b5067ffffffffffffffff94959697508281611381575b5050504780611371575b50501691826112fd57836001815580f35b6001600160a01b0382163b1561075257608460ff9185809460405196879586946368bd322f60e01b865216600485015260248401528160448401526101a435606484015260018060a01b03165af180156107475761135c5780806106ca565b81611366916118ed565b61014b57808261072b565b61137a91611ab0565b86806112ec565b61138a92611a6d565b8780826112e2565b94959650509583813d83116113ca575b6113ac81836118ed565b810103126107b057869567ffffffffffffffff9351879695946112cc565b503d6113a2565b6113da92611a6d565b888083611292565b809850898092503d831161140c575b6113fb81836118ed565b810103126107b0578896518a61128a565b503d6113f1565b6060813d60601161144a575b8161142c606093836118ed565b8101031261085d57604081610843611443936119b5565b5089611252565b3d915061141f565b92610104916080946040519687958694633d44fbd360e21b865215156004860152602485015260448401526001600160801b036064840152600160848401528160a4840152600160c48401526101a43560e484015260018060a01b03165af18015610808576114c2575b50611254565b6080813d6080116114f9575b816114db608093836118ed565b8101031261085d576060816109096114f293611972565b50896114bc565b3d91506114ce565b8a81813d831161152c575b61151681836118ed565b810103126109605761152790611923565b611143565b503d61150c565b6001600160a01b0384166110c2565b925092506101a0823d821161158f575b816115606101a093836118ed565b8101031261085d5761157460408301611930565b6115866101806109c960608601611930565b5091928b6110b0565b3d9150611552565b9093508781813d83116115c7575b6115af81836118ed565b81010312610a7d576115c090611972565b928961107e565b503d6115a5565b9091928a806115ec8f93600194610143198d8303019052875161189c565b95019d0191019b91909b61104f565b90915060a0813d60a011611665575b8161161760a093836118ed565b81010312610b3d57608061162a82611930565b9161163760208201611944565b5061164460408201611944565b5061165160608201611923565b50015161ffff811603610b3d57908a610f5c565b3d915061160a565b60209450906080929160405192835285830152610204356040830152606082015282805260015afa508751888a8c80610f0f565b90506020813d6020116116d3575b816116bc602093836118ed565b81010312610b3d576116cd90611923565b8a610e79565b3d91506116af565b60405163d47eed4560e01b8152929091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690602084806117298685600484016119c9565b0381855afa938415610cfa578c9461179f575b5083803410610cb757823b15610cb3579161177093918d93604051809681958294631df3cbc560e31b8452600484016119c9565b03925af1801561096b57908a9161178a575b829150610e38565b81611794916118ed565b610b3d57888b611782565b9093506020813d6020116117cb575b816117bb602093836118ed565b810103126107b05751928d61173c565b3d91506117ae565b6117e0919a505f906118ed565b5f988b610e22565b600435906001600160a01b03821682036107b057565b6024359060ff821682036107b057565b6101e4359060ff821682036107b057565b604435906001600160801b03821682036107b057565b6064359068ffffffffffffffffff821682036107b057565b6084359081151582036107b057565b60a4359081151582036107b057565b9181601f840112156107b05782359167ffffffffffffffff83116107b0576020808501948460051b0101116107b057565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b60e4356001600160a01b03811681036107b05790565b610104356001600160a01b03811681036107b05790565b90601f8019910116810190811067ffffffffffffffff82111761190f57604052565b634e487b7160e01b5f52604160045260245ffd5b519081151582036107b057565b51906001600160a01b03821682036107b057565b519060ff821682036107b057565b6101843580151581036107b05790565b6101243580151581036107b05790565b519067ffffffffffffffff821682036107b057565b610144356001600160801b03811681036107b05790565b6101c4356001600160801b03811681036107b05790565b51906001600160801b03821682036107b057565b9180602084016020855252604083019060408160051b85010193835f91601e1982360301905b848410611a00575050505050505090565b90919293949596603f198282030187528735838112156107b0578401906020823592019167ffffffffffffffff81116107b05780360383136107b0576020828280600196849695859652848401375f828201840152601f01601f19160101990197019594019291906119ef565b60405163a9059cbb60e01b60208201526001600160a01b03929092166024830152604480830193909352918152611aae91611aa96064836118ed565b611c31565b565b8115611b11575f80809381935af13d15611b0c573d67ffffffffffffffff811161190f5760405190611aec601f8201601f1916602001836118ed565b81525f60203d92013e5b15611afd57565b6312171d8360e31b5f5260045ffd5b611af6565b5050565b307f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03161480611c08575b15611b70577f000000000000000000000000000000000000000000000000000000000000000090565b60405160208101907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82527f000000000000000000000000000000000000000000000000000000000000000060408201527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a082015260a08152611c0260c0826118ed565b51902090565b507f00000000000000000000000000000000000000000000000000000000000000004614611b47565b905f602091828151910182855af115611c89575f513d611c8057506001600160a01b0381163b155b611c605750565b635274afe760e01b5f9081526001600160a01b0391909116600452602490fd5b60011415611c59565b6040513d5f823e3d90fd5b60ff8114611cda5760ff811690601f8211611ccb5760405191611cb86040846118ed565b6020808452838101919036833783525290565b632cd44ac360e21b5f5260045ffd5b506040515f6001548060011c9160018216918215611db3575b602084108314611d9f578385528492908115611d805750600114611d21575b611d1e925003826118ed565b90565b5060015f90815290917fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b818310611d64575050906020611d1e92820101611d12565b6020919350806001915483858801015201910190918392611d4c565b60209250611d1e94915060ff191682840152151560051b820101611d12565b634e487b7160e01b5f52602260045260245ffd5b92607f1692611cf3565b60ff8114611de15760ff811690601f8211611ccb5760405191611cb86040846118ed565b506040515f6002548060011c9160018216918215611e83575b602084108314611d9f578385528492908115611d805750600114611e2457611d1e925003826118ed565b5060025f90815290917f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace5b818310611e67575050906020611d1e92820101611d12565b6020919350806001915483858801015201910190918392611e4f565b92607f1692611dfa56fea2646970667358221220028bed7974bdf9dcf966206b459f48ab0e8384096e25eb8d06c359869946098e64736f6c634300081c00330000000000000000000000002880ab155794e7179c9ee2e38200202908c17b430000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000a4c50204d616e6167657200000000000000000000000000000000000000000000
Deployed Bytecode
0x608080604052600436101561001c575b50361561001a575f80fd5b005b5f905f3560e01c9081632813631614610d18575080632d5c9a35146101715780633644e5151461014e576384b0196e0361000f573461014b578060031936011261014b576100ef9061008d7f4c50204d616e616765720000000000000000000000000000000000000000000a611c94565b906100b77f3400000000000000000000000000000000000000000000000000000000000001611dbd565b9060206100fd604051936100cb83866118ed565b8385525f368137604051968796600f60f81b885260e08589015260e088019061189c565b90868203604088015261189c565b904660608601523060808601528260a086015284820360c08601528080855193848152019401925b82811061013457505050500390f35b835185528695509381019392810192600101610125565b80fd5b503461014b578060031936011261014b576020610169611b15565b604051908152f35b5061026036600319011261014b576101876117e8565b906101906117fe565b9161019961181f565b926101a2611835565b916101ab61184d565b946101b461185c565b956101003660e3190112610d14576101ca61180e565b9061022435976102443567ffffffffffffffff8111610b3d576101f190369060040161186b565b60028a5414610d055760028a55899080610bef575b506102149150340333611ab0565b60405163f60559eb60e01b81523360048201526020816024816001600160a01b038a165afa908115610b49578991610bb5575b5015610ba6576102556118c0565b926001600160a01b03841615610b9757886042610270611b15565b6101206040517f783ffce4219e675737141a1c936ab9c993cdf2ee6d70fc69bbe50ed9fe1c5fa9815261010060e46020830137206040519161190160f01b83526002830152602282015220809b82936fa2a8918ca85bafe22016d0b997e4df5f600160ff1b038210610b63575b505050506001600160a01b03848116911603610b5457604051630349079560e01b815260ff871660048201529060a0826024816001600160a01b038a165afa918215610b49578992610ad3575b506001600160a01b0361033b6118d6565b166001600160a01b03831603610ac457898952600360205260ff60408a205416610ab55768ffffffffffffffffff998952600360205260408920600160ff19825416179055610388611952565b9260209a8b9961039b6040519d8e6118ed565b8b8d526001600160801b03604051986323c9e08160e01b8a5260ff8c1660048b0152871560248b01521660448901521660648701526001600160801b036084870152151560a4860152151560c48501526101a43560e485015261012061010485015288519889610124860152610144850199886101448260051b8801019201908a5b818110610a8857505050889950968480829a9903818a60018060a01b038a165af19384156107bb578794610a4d575b506040516330fe427560e21b8152906101a0826004816001600160a01b0385165afa9283156108085788928994610985575b508015610976576001600160a01b0383165b6040516323b872dd60e01b8c8201526001600160a01b038716602482015230604482015260c43560648083019190915281526104d7906104d16084826118ed565b82611c31565b60405163095ea7b360e01b81526001600160a01b03848116600483015260c435602483015290918c91839160449183918f91165af1801561096b57610935575b50610520611987565b91610164359268ffffffffffffffffff8416809403610931578b918b918a6001600160801b038061054f611962565b9361055861199e565b604080516001600160a01b039687168152339a81019a909a52861515908a015289151560608a015291166080880181905260a088018a9052911660c0870152948a8216918416907fb56a8ebaf3a6f7a43b1ea78f9a031691e0303083d51d0ceeec3cfafd41298b389060e090a315610869579260c49160609460405196879586946356b9e99760e11b865215156004860152602485015260448401526001600160801b036064840152600160848401526101a43560a484015260018060a01b03165af1801561080857610813575b505b6040516370a0823160e01b81523060048201526001600160a01b0391909116908881602481855afa9081156108085788916107d7575b5083816107c6575b50506040516370a0823160e01b81523060048201526001600160a01b03929092169190508781602481855afa9081156107bb578791610778575b5067ffffffffffffffff94959697508281610767575b5050504780610757575b50501691826106d2575b836001815580f35b6001600160a01b0382163b1561075257608460ff9185809460405196879586946368bd322f60e01b865216600485015260248401528160448401526101a435606484015260018060a01b03165af1801561074757610732575b80806106ca565b8161073c916118ed565b61014b57805f61072b565b6040513d84823e3d90fd5b505050fd5b61076091611ab0565b5f806106c0565b61077092611a6d565b5f80826106b6565b94959650509583813d83116107b4575b61079281836118ed565b810103126107b057869567ffffffffffffffff9351879695946106a0565b5f80fd5b503d610788565b6040513d89823e3d90fd5b6107cf92611a6d565b5f8083610666565b809850898092503d8311610801575b6107f081836118ed565b810103126107b0578896515f61065e565b503d6107e6565b6040513d8a823e3d90fd5b6060813d606011610861575b8161082c606093836118ed565b8101031261085d57604081610843610856936119b5565b5061084f8b82016119b5565b50016119b5565b505f610626565b8780fd5b3d915061081f565b92610104916080946040519687958694633d44fbd360e21b865215156004860152602485015260448401526001600160801b036064840152600160848401528160a4840152600160c48401526101a43560e484015260018060a01b03165af18015610808576108d9575b50610628565b6080813d608011610929575b816108f2608093836118ed565b8101031261085d5760608161090961092293611972565b506109158b82016119b5565b5061084f604082016119b5565b505f6108d3565b3d91506108e5565b8a80fd5b8a81813d8311610964575b61094a81836118ed565b810103126109605761095b90611923565b610517565b8980fd5b503d610940565b6040513d8c823e3d90fd5b6001600160a01b038416610490565b925092506101a0823d8211610a45575b816109a36101a093836118ed565b8101031261085d576109b760408301611930565b610a3c6101806109c960608601611930565b946109d660808201611923565b506109e360a08201611923565b506109f060c08201611930565b506109fd60e08201611930565b50610a0b6101008201611972565b50610a196101208201611972565b50610a276101408201611972565b50610a356101608201611972565b5001611923565b5091925f61047e565b3d9150610995565b9093508781813d8311610a81575b610a6581836118ed565b81010312610a7d57610a7690611972565b925f61044c565b8680fd5b503d610a5b565b9091928a80610aa68f93600194610143198d8303019052875161189c565b95019d0191019b91909b61041d565b6388b3904360e01b8952600489fd5b63ec09da3560e01b8952600489fd5b90915060a0813d60a011610b41575b81610aef60a093836118ed565b81010312610b3d576080610b0282611930565b91610b0f60208201611944565b50610b1c60408201611944565b50610b2960608201611923565b50015161ffff811603610b3d57905f61032a565b8880fd5b3d9150610ae2565b6040513d8b823e3d90fd5b638baa579f60e01b8852600488fd5b60209450906080929160405192835285830152610204356040830152606082015282805260015afa508751888a5f806102dd565b63d92e233d60e01b8952600489fd5b637dbacad160e11b8852600488fd5b90506020813d602011610be7575b81610bd0602093836118ed565b81010312610b3d57610be190611923565b5f610247565b3d9150610bc3565b60405163d47eed4560e01b8152929091507f0000000000000000000000002880ab155794e7179c9ee2e38200202908c17b436001600160a01b03169060208480610c3d8685600484016119c9565b0381855afa938415610cfa578c94610cc6575b5083803410610cb757823b15610cb35791610c8493918d93604051809681958294631df3cbc560e31b8452600484016119c9565b03925af1801561096b57908a91610c9e575b829150610206565b81610ca8916118ed565b610b3d57885f610c96565b8c80fd5b63e4764c6f60e01b8d5260048dfd5b9093506020813d602011610cf2575b81610ce2602093836118ed565b810103126107b05751925f610c50565b3d9150610cd5565b6040513d8e823e3d90fd5b633ee5aeb560e01b8a5260048afd5b8580fd5b826102e03660031901126107b057610d2e6117e8565b610d366117fe565b610d3e61181f565b91610d47611835565b92610d5061184d565b610d5861185c565b906101003660e31901126107b057610d6e61180e565b916102243598610244359060018060a01b0382168092036107b057610264359060ff82168092036107b0576102c43567ffffffffffffffff81116107b057610dba90369060040161186b565b929093610dc56118c0565b90803b156107b057835f60e4928195839563d505accf60e01b855260018060a01b0316600485015230602485015260c43560448501526101a435606485015260848401526102843560a48401526102a43560c48401525af16117d3575b5060028a5414610d055760028a558990806116db575b50610e469150340333611ab0565b60405163f60559eb60e01b81523360048201526020816024816001600160a01b038a165afa908115610b495789916116a1575b5015610ba657610e876118c0565b926001600160a01b03841615610b9757886042610ea2611b15565b6101206040517f783ffce4219e675737141a1c936ab9c993cdf2ee6d70fc69bbe50ed9fe1c5fa9815261010060e46020830137206040519161190160f01b83526002830152602282015220809b82936fa2a8918ca85bafe22016d0b997e4df5f600160ff1b03821061166d575b505050506001600160a01b03848116911603610b5457604051630349079560e01b815260ff871660048201529060a0826024816001600160a01b038a165afa918215610b495789926115fb575b506001600160a01b03610f6d6118d6565b166001600160a01b03831603610ac457898952600360205260ff60408a205416610ab55768ffffffffffffffffff998952600360205260408920600160ff19825416179055610fba611952565b9260209a8b99610fcd6040519d8e6118ed565b8b8d526001600160801b03604051986323c9e08160e01b8a5260ff8c1660048b0152871560248b01521660448901521660648701526001600160801b036084870152151560a4860152151560c48501526101a43560e485015261012061010485015288519889610124860152610144850199886101448260051b8801019201908a5b8181106115ce57505050889950968480829a9903818a60018060a01b038a165af19384156107bb578794611597575b506040516330fe427560e21b8152906101a0826004816001600160a01b0385165afa9283156108085788928994611542575b508015611533576001600160a01b0383165b6040516323b872dd60e01b8c8201526001600160a01b038716602482015230604482015260c4356064808301919091528152611103906104d16084826118ed565b60405163095ea7b360e01b81526001600160a01b03848116600483015260c435602483015290918c91839160449183918f91165af1801561096b57611501575b5061114c611987565b91610164359268ffffffffffffffffff8416809403610931578b918b918a6001600160801b038061117b611962565b9361118461199e565b604080516001600160a01b039687168152339a81019a909a52861515908a015289151560608a015291166080880181905260a088018a9052911660c0870152948a8216918416907fb56a8ebaf3a6f7a43b1ea78f9a031691e0303083d51d0ceeec3cfafd41298b389060e090a315611452579260c49160609460405196879586946356b9e99760e11b865215156004860152602485015260448401526001600160801b036064840152600160848401526101a43560a484015260018060a01b03165af1801561080857611413575b505b6040516370a0823160e01b81523060048201526001600160a01b0391909116908881602481855afa9081156108085788916113e2575b5083816113d1575b50506040516370a0823160e01b81523060048201526001600160a01b03929092169190508781602481855afa9081156107bb578791611392575b5067ffffffffffffffff94959697508281611381575b5050504780611371575b50501691826112fd57836001815580f35b6001600160a01b0382163b1561075257608460ff9185809460405196879586946368bd322f60e01b865216600485015260248401528160448401526101a435606484015260018060a01b03165af180156107475761135c5780806106ca565b81611366916118ed565b61014b57808261072b565b61137a91611ab0565b86806112ec565b61138a92611a6d565b8780826112e2565b94959650509583813d83116113ca575b6113ac81836118ed565b810103126107b057869567ffffffffffffffff9351879695946112cc565b503d6113a2565b6113da92611a6d565b888083611292565b809850898092503d831161140c575b6113fb81836118ed565b810103126107b0578896518a61128a565b503d6113f1565b6060813d60601161144a575b8161142c606093836118ed565b8101031261085d57604081610843611443936119b5565b5089611252565b3d915061141f565b92610104916080946040519687958694633d44fbd360e21b865215156004860152602485015260448401526001600160801b036064840152600160848401528160a4840152600160c48401526101a43560e484015260018060a01b03165af18015610808576114c2575b50611254565b6080813d6080116114f9575b816114db608093836118ed565b8101031261085d576060816109096114f293611972565b50896114bc565b3d91506114ce565b8a81813d831161152c575b61151681836118ed565b810103126109605761152790611923565b611143565b503d61150c565b6001600160a01b0384166110c2565b925092506101a0823d821161158f575b816115606101a093836118ed565b8101031261085d5761157460408301611930565b6115866101806109c960608601611930565b5091928b6110b0565b3d9150611552565b9093508781813d83116115c7575b6115af81836118ed565b81010312610a7d576115c090611972565b928961107e565b503d6115a5565b9091928a806115ec8f93600194610143198d8303019052875161189c565b95019d0191019b91909b61104f565b90915060a0813d60a011611665575b8161161760a093836118ed565b81010312610b3d57608061162a82611930565b9161163760208201611944565b5061164460408201611944565b5061165160608201611923565b50015161ffff811603610b3d57908a610f5c565b3d915061160a565b60209450906080929160405192835285830152610204356040830152606082015282805260015afa508751888a8c80610f0f565b90506020813d6020116116d3575b816116bc602093836118ed565b81010312610b3d576116cd90611923565b8a610e79565b3d91506116af565b60405163d47eed4560e01b8152929091507f0000000000000000000000002880ab155794e7179c9ee2e38200202908c17b436001600160a01b031690602084806117298685600484016119c9565b0381855afa938415610cfa578c9461179f575b5083803410610cb757823b15610cb3579161177093918d93604051809681958294631df3cbc560e31b8452600484016119c9565b03925af1801561096b57908a9161178a575b829150610e38565b81611794916118ed565b610b3d57888b611782565b9093506020813d6020116117cb575b816117bb602093836118ed565b810103126107b05751928d61173c565b3d91506117ae565b6117e0919a505f906118ed565b5f988b610e22565b600435906001600160a01b03821682036107b057565b6024359060ff821682036107b057565b6101e4359060ff821682036107b057565b604435906001600160801b03821682036107b057565b6064359068ffffffffffffffffff821682036107b057565b6084359081151582036107b057565b60a4359081151582036107b057565b9181601f840112156107b05782359167ffffffffffffffff83116107b0576020808501948460051b0101116107b057565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b60e4356001600160a01b03811681036107b05790565b610104356001600160a01b03811681036107b05790565b90601f8019910116810190811067ffffffffffffffff82111761190f57604052565b634e487b7160e01b5f52604160045260245ffd5b519081151582036107b057565b51906001600160a01b03821682036107b057565b519060ff821682036107b057565b6101843580151581036107b05790565b6101243580151581036107b05790565b519067ffffffffffffffff821682036107b057565b610144356001600160801b03811681036107b05790565b6101c4356001600160801b03811681036107b05790565b51906001600160801b03821682036107b057565b9180602084016020855252604083019060408160051b85010193835f91601e1982360301905b848410611a00575050505050505090565b90919293949596603f198282030187528735838112156107b0578401906020823592019167ffffffffffffffff81116107b05780360383136107b0576020828280600196849695859652848401375f828201840152601f01601f19160101990197019594019291906119ef565b60405163a9059cbb60e01b60208201526001600160a01b03929092166024830152604480830193909352918152611aae91611aa96064836118ed565b611c31565b565b8115611b11575f80809381935af13d15611b0c573d67ffffffffffffffff811161190f5760405190611aec601f8201601f1916602001836118ed565b81525f60203d92013e5b15611afd57565b6312171d8360e31b5f5260045ffd5b611af6565b5050565b307f000000000000000000000000db5c8857a39073ca050cf825ef5465edf47dd6156001600160a01b03161480611c08575b15611b70577f9e358958c88fd7f6d656831db245f43d68b48848c6606592f1e6e86c78a58acf90565b60405160208101907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82527f1fe739aaec684efe151f6366afdb07c43a0b4a6f724a751bc32d832745918ce660408201527f13600b294191fc92924bb3ce4b969c1e7e2bab8f4c93c3fc6d0a51733df3c06060608201524660808201523060a082015260a08152611c0260c0826118ed565b51902090565b507f00000000000000000000000000000000000000000000000000000000000000924614611b47565b905f602091828151910182855af115611c89575f513d611c8057506001600160a01b0381163b155b611c605750565b635274afe760e01b5f9081526001600160a01b0391909116600452602490fd5b60011415611c59565b6040513d5f823e3d90fd5b60ff8114611cda5760ff811690601f8211611ccb5760405191611cb86040846118ed565b6020808452838101919036833783525290565b632cd44ac360e21b5f5260045ffd5b506040515f6001548060011c9160018216918215611db3575b602084108314611d9f578385528492908115611d805750600114611d21575b611d1e925003826118ed565b90565b5060015f90815290917fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b818310611d64575050906020611d1e92820101611d12565b6020919350806001915483858801015201910190918392611d4c565b60209250611d1e94915060ff191682840152151560051b820101611d12565b634e487b7160e01b5f52602260045260245ffd5b92607f1692611cf3565b60ff8114611de15760ff811690601f8211611ccb5760405191611cb86040846118ed565b506040515f6002548060011c9160018216918215611e83575b602084108314611d9f578385528492908115611d805750600114611e2457611d1e925003826118ed565b5060025f90815290917f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace5b818310611e67575050906020611d1e92820101611d12565b6020919350806001915483858801015201910190918392611e4f565b92607f1692611dfa56fea2646970667358221220028bed7974bdf9dcf966206b459f48ab0e8384096e25eb8d06c359869946098e64736f6c634300081c0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000002880ab155794e7179c9ee2e38200202908c17b430000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000a4c50204d616e6167657200000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : pythAddress (address): 0x2880aB155794e7179c9eE2e38200202908C17B43
Arg [1] : _domainName (string): LP Manager
-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 0000000000000000000000002880ab155794e7179c9ee2e38200202908c17b43
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000040
Arg [2] : 000000000000000000000000000000000000000000000000000000000000000a
Arg [3] : 4c50204d616e6167657200000000000000000000000000000000000000000000
Deployed Bytecode Sourcemap
1107:6397:28:-:0;;;;;;;;;;-1:-1:-1;1107:6397:28;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6099:5:17;:41;:5;:41;:::i;:::-;6554:8;:47;:8;:47;:::i;:::-;1107:6397:28;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;:::i;:::-;5590:13:17;;1107:6397:28;;;;5625:4:17;1107:6397:28;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1107:6397:28;;;;;;;;6126:13:17;1107:6397:28;;;;;;;;;;;;;;;;;;;;7475:20;;:::i;:::-;1107:6397;;;;;;;-1:-1:-1;1107:6397:28;;-1:-1:-1;;1107:6397:28;;;;;;:::i;:::-;;;;:::i;:::-;;;;:::i;:::-;;;;:::i;:::-;;;;:::i;:::-;;;;:::i;:::-;;;;-1:-1:-1;;1107:6397:28;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;:::i;:::-;1899:1:13;1107:6397:28;;2702:18:13;2698:86;;1899:1;;;353:15:34;382:27;;378:247;;1107:6397:28;688:9:34;748:4;688:9;;;1107:6397:28;736:10:34;748:4;:::i;:::-;1107:6397:28;;-1:-1:-1;;;3712:34:28;;736:10:34;1107:6397:28;3712:34;;1107:6397;;;;;-1:-1:-1;;;;;1107:6397:28;;3712:34;;;;;;;;;;;1107:6397;;;;;3811:23;;:::i;:::-;1107:6397;-1:-1:-1;;;;;1107:6397:28;;3852:25;1107:6397;;7475:20;3086:357:33;7475:20:28;;:::i;:::-;1055:340:35;1107:6397:28;1055:340:35;463:303;1055:340;;1107:6397:28;;;1055:340:35;;;;1107:6397:28;3086:357:33;;;;;;;1899:1:13;3086:357:33;;;;;;;;4031:33:28;;952:14:33;978:457;-1:-1:-1;;;;;978:457:33;;;;1107:6397:28;-1:-1:-1;;;;;;;;;1107:6397:28;;;;;4082:21;1107:6397;;;;-1:-1:-1;;;4176:21:28;;1107:6397;;;;4176:21;;1107:6397;;;;;;-1:-1:-1;;;;;1107:6397:28;;4176:21;;;;;;;;;;;1107:6397;-1:-1:-1;;;;;;4229:22:28;;:::i;:::-;1107:6397;-1:-1:-1;;;;;1107:6397:28;;4215:36;1107:6397;;;;;4367:11;1107:6397;;;;;;;;;;;;;;4367:11;1107:6397;;;;;;;;;;;;;;4540:17;;:::i;:::-;1107:6397;;;;;;;;;;;:::i;:::-;;;;-1:-1:-1;;;;;1107:6397:28;;;;;;4625:256;;1107:6397;;;;4625:256;;1107:6397;4677:12;;1107:6397;;;;;;;;;;;;;;-1:-1:-1;;;;;1107:6397:28;;;;;;;;;;;;;;;;4492:19;1107:6397;;;;;1055:340:35;4229:22:28;1107:6397;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4625:256;;;;;;;;;;;;;1107:6397;;;;;;;;;4625:256;;;;;;;;;;;1107:6397;-1:-1:-1;1107:6397:28;;-1:-1:-1;;;4939:15:28;;1107:6397;4939:15;1107:6397;;;-1:-1:-1;;;;;1107:6397:28;;4939:15;;;;;;;1107:6397;;;4939:15;;;1107:6397;-1:-1:-1;4988:45:28;;;;-1:-1:-1;;;;;1107:6397:28;;4988:45;1107:6397;;-1:-1:-1;;;1745:53:11;;;;-1:-1:-1;;;;;1107:6397:28;;;1745:53:11;;1107:6397:28;5095:4;1107:6397;;;;;;;;;;;;;;1745:53:11;;;;;1107:6397:28;;1745:53:11;:::i;:::-;;;:::i;:::-;1107:6397:28;;-1:-1:-1;;;5124:46:28;;-1:-1:-1;;;;;1107:6397:28;;;;5124:46;;1107:6397;;;;;;;;;;;;;;;;;;;;5124:46;;;;;;;;4988:45;5209:23;;;:::i;:::-;1107:6397;5263:17;1107:6397;;;;;;;;;;5326:34;;;;;-1:-1:-1;;;;;5326:34:28;;;:::i;:::-;5633:17;;;:::i;:::-;1107:6397;;;-1:-1:-1;;;;;1107:6397:28;;;;;736:10:34;1107:6397:28;;;;;;;;;;;;;;4677:12;;1107:6397;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5376:284;;1107:6397;;5376:284;5671:562;;;1107:6397;;;;;;;;;;;;;;;5719:224;;4677:12;1107:6397;;5719:224;;1107:6397;;;;;;;;;-1:-1:-1;;;;;1107:6397:28;;;;;;;;;4492:19;1107:6397;;;;;;;;;;;5719:224;;;;;;;;5671:562;;;1107:6397;;-1:-1:-1;;;6270:39:28;;5095:4;1107:6397;6270:39;;1107:6397;-1:-1:-1;;;;;1107:6397:28;;;;;6270:39;1107:6397;;;;6270:39;;;;;;;;;;;5671:562;6323:20;;;6319:109;;5671:562;-1:-1:-1;;1107:6397:28;;-1:-1:-1;;;6465:39:28;;5095:4;1107:6397;6465:39;;1107:6397;-1:-1:-1;;;;;1107:6397:28;;;;;;-1:-1:-1;6465:39:28;1107:6397;;;;6465:39;;;;;;;;;;;5671:562;6518:20;1107:6397;6518:20;;;;;;;6514:109;;5671:562;6659:21;;;;6694:19;6690:108;;5671:562;1107:6397;;;6847:16;;6843:103;;5671:562;1899:1:13;1107:6397:28;1899:1:13;;1107:6397:28;;6843:103;-1:-1:-1;;;;;1107:6397:28;;6879:56;;;;1107:6397;;;;;;;;;;;;;;;;6879:56;;1107:6397;;6879:56;;1107:6397;;;;;;;;;;4492:19;1107:6397;;;;;;;;;;;6879:56;;;;;;;;6843:103;;;;;6879:56;;;;;:::i;:::-;1107:6397;;6879:56;;;;;1107:6397;;;;;;;;;6879:56;1107:6397;;;;6690:108;6771:15;;;:::i;:::-;6690:108;;;;6514:109;6595:16;;;:::i;:::-;6514:109;;;;;6465:39;;;;;;;;;;;;;;;;;;;:::i;:::-;;;1107:6397;;;;;;;;;6465:39;;;;;;1107:6397;-1:-1:-1;1107:6397:28;;6465:39;;;;;;1107:6397;;;;;;;;;6319:109;6400:16;;;:::i;:::-;6319:109;;;;;6270:39;;;;;;;;;;;;;;;;;;:::i;:::-;;;1107:6397;;;;;;;6270:39;;;;;;;;;1107:6397;;;;;;;;;5719:224;1107:6397;5719:224;;1107:6397;5719:224;;;;;;1107:6397;5719:224;;;:::i;:::-;;;1107:6397;;;;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;:::i;:::-;;5719:224;;;1107:6397;;;;5719:224;;;-1:-1:-1;5719:224:28;;5671:562;1107:6397;4229:22;1107:6397;;;;;;;;;;;;;5974:248;;4677:12;1107:6397;;5974:248;;1107:6397;;;;;;;;;-1:-1:-1;;;;;1107:6397:28;;;;;;;;;;;;;;;;;;;4492:19;1107:6397;;;;;;;;;;;5974:248;;;;;;;;5671:562;;;;5974:248;1107:6397;5974:248;;1107:6397;5974:248;;;;;;1107:6397;5974:248;;;:::i;:::-;;;1107:6397;;;;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;5974:248;;;;;;-1:-1:-1;5974:248:28;;1107:6397;;;;5124:46;;;;;;;;;;;;;;:::i;:::-;;;1107:6397;;;;;;;:::i;:::-;5124:46;;1107:6397;;;;5124:46;;;;;;1107:6397;;;;;;;;;4988:45;-1:-1:-1;;;;;1107:6397:28;;4988:45;;4939:15;;;;;;;;;;;;;;;;;;;:::i;:::-;;;1107:6397;;;;;;;;;:::i;:::-;;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;1055:340:35;1107:6397:28;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;:::i;:::-;;4939:15;;;;;;;;-1:-1:-1;4939:15:28;;4625:256;;;;;;;;;;;;;;;;;:::i;:::-;;;1107:6397;;;;;;;:::i;:::-;4625:256;;;;1107:6397;;;;4625:256;;;;;1107:6397;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;-1:-1:-1;;;1107:6397:28;;;;;;-1:-1:-1;;;1107:6397:28;;;;;4176:21;;;;1107:6397;4176:21;;1107:6397;4176:21;;;;;;1107:6397;4176:21;;;:::i;:::-;;;1107:6397;;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;;;;4176:21;;;;1107:6397;;;;4176:21;;;-1:-1:-1;4176:21:28;;;1107:6397;;;;;;;;;;-1:-1:-1;;;1107:6397:28;;;;;978:457:33;1107:6397:28;978:457:33;;;1107:6397:28;978:457:33;;1107:6397:28;978:457:33;;;;;;;;1107:6397:28;;;978:457:33;;;1107:6397:28;978:457:33;;;;;;1107:6397:28;978:457:33;;;;;;;;;;;1107:6397:28;-1:-1:-1;;;1107:6397:28;;;;;;-1:-1:-1;;;1107:6397:28;;;;;3712:34;;;1107:6397;3712:34;;1107:6397;3712:34;;;;;;1107:6397;3712:34;;;:::i;:::-;;;1107:6397;;;;;;;:::i;:::-;3712:34;;;;;;-1:-1:-1;3712:34:28;;378:247:34;1107:6397:28;;-1:-1:-1;;;431:34:34;;1107:6397:28;;;-1:-1:-1;3532:4:28;-1:-1:-1;;;;;1107:6397:28;;;;;431:34:34;1107:6397:28;;;431:34:34;;;:::i;:::-;;;;;;;;;;;;;;;378:247;425:40;;487:9;;:16;1107:6397:28;;564:50:34;;;;;1107:6397:28;564:50:34;1107:6397:28;;;;;;;;;;;;;;;564:50:34;;1107:6397:28;564:50:34;;;:::i;:::-;;;;;;;;;;;;;;378:247;;;;;;564:50;;;;;:::i;:::-;1107:6397:28;;564:50:34;;;;;1107:6397:28;;;;-1:-1:-1;;;1107:6397:28;;;;;431:34:34;;;;1107:6397:28;431:34:34;;1107:6397:28;431:34:34;;;;;;1107:6397:28;431:34:34;;;:::i;:::-;;;1107:6397:28;;;;;431:34:34;;;;;;;-1:-1:-1;431:34:34;;;1107:6397:28;;;;;;;;;2698:86:13;-1:-1:-1;;;2743:30:13;;1107:6397:28;2743:30:13;;1107:6397:28;;;;;;;;-1:-1:-1;;1107:6397:28;;;;;;:::i;:::-;;;:::i;:::-;;;:::i;:::-;;;;:::i;:::-;;;;:::i;:::-;;;:::i;:::-;;;;-1:-1:-1;;1107:6397:28;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;2582:23;;;;;:::i;:::-;2556:207;;;;;;1107:6397;;;;;;;;;;;2556:207;;1107:6397;;;;;;;2556:207;;1107:6397;2627:4;1107:6397;;;;;;;;;;2671:19;1107:6397;;;;;;;;;;;;;;;;;;;;;2556:207;;;;1107:6397;;1899:1:13;1107:6397:28;;2702:18:13;2698:86;;1899:1;;;353:15:34;382:27;;378:247;;1107:6397:28;688:9:34;748:4;688:9;;;1107:6397:28;736:10:34;748:4;:::i;:::-;1107:6397:28;;-1:-1:-1;;;3712:34:28;;736:10:34;1107:6397:28;3712:34;;1107:6397;;;;;-1:-1:-1;;;;;1107:6397:28;;3712:34;;;;;;;;;;;1107:6397;;;;;3811:23;;:::i;:::-;1107:6397;-1:-1:-1;;;;;1107:6397:28;;3852:25;1107:6397;;7475:20;3086:357:33;7475:20:28;;:::i;:::-;1055:340:35;1107:6397:28;1055:340:35;463:303;1055:340;;1107:6397:28;;;1055:340:35;;;;1107:6397:28;3086:357:33;;;;;;;1899:1:13;3086:357:33;;;;;;;;4031:33:28;;952:14:33;978:457;-1:-1:-1;;;;;978:457:33;;;;1107:6397:28;-1:-1:-1;;;;;;;;;1107:6397:28;;;;;4082:21;1107:6397;;;;-1:-1:-1;;;4176:21:28;;1107:6397;;;;4176:21;;1107:6397;;;;;;-1:-1:-1;;;;;1107:6397:28;;4176:21;;;;;;;;;;;1107:6397;-1:-1:-1;;;;;;4229:22:28;;:::i;:::-;1107:6397;-1:-1:-1;;;;;1107:6397:28;;4215:36;1107:6397;;;;;4367:11;1107:6397;;;;;;;;;;;;;;4367:11;1107:6397;;;;;;;;;;;;;;4540:17;;:::i;:::-;1107:6397;;;;;;;;;;;:::i;:::-;;;;-1:-1:-1;;;;;1107:6397:28;;;;;;4625:256;;1107:6397;;;;4625:256;;1107:6397;4677:12;;1107:6397;;;;;;;;;;;;;;-1:-1:-1;;;;;1107:6397:28;;;;;;;;;;;;;;;;2671:19;1107:6397;;;;;1055:340:35;4229:22:28;1107:6397;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4625:256;;;;;;;;;;;;;1107:6397;;;;;;;;;4625:256;;;;;;;;;;;1107:6397;-1:-1:-1;1107:6397:28;;-1:-1:-1;;;4939:15:28;;1107:6397;4939:15;1107:6397;;;-1:-1:-1;;;;;1107:6397:28;;4939:15;;;;;;;1107:6397;;;4939:15;;;1107:6397;-1:-1:-1;4988:45:28;;;;-1:-1:-1;;;;;1107:6397:28;;4988:45;1107:6397;;-1:-1:-1;;;1745:53:11;;;;-1:-1:-1;;;;;1107:6397:28;;;1745:53:11;;1107:6397:28;2627:4;1107:6397;;;;;;;;;;;;;;1745:53:11;;;;;1107:6397:28;;1745:53:11;:::i;:::-;1107:6397:28;;-1:-1:-1;;;5124:46:28;;-1:-1:-1;;;;;1107:6397:28;;;;5124:46;;1107:6397;;;;;;;;;;;;;;;;;;;;5124:46;;;;;;;;4988:45;5209:23;;;:::i;:::-;1107:6397;5263:17;1107:6397;;;;;;;;;;5326:34;;;;;-1:-1:-1;;;;;5326:34:28;;;:::i;:::-;5633:17;;;:::i;:::-;1107:6397;;;-1:-1:-1;;;;;1107:6397:28;;;;;736:10:34;1107:6397:28;;;;;;;;;;;;;;4677:12;;1107:6397;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5376:284;;1107:6397;;5376:284;5671:562;;;1107:6397;;;;;;;;;;;;;;;5719:224;;4677:12;1107:6397;;5719:224;;1107:6397;;;;;;;;;-1:-1:-1;;;;;1107:6397:28;;;;;;;;;2671:19;1107:6397;;;;;;;;;;;5719:224;;;;;;;;5671:562;;;1107:6397;;-1:-1:-1;;;6270:39:28;;2627:4;1107:6397;6270:39;;1107:6397;-1:-1:-1;;;;;1107:6397:28;;;;;6270:39;1107:6397;;;;6270:39;;;;;;;;;;;5671:562;6323:20;;;6319:109;;5671:562;-1:-1:-1;;1107:6397:28;;-1:-1:-1;;;6465:39:28;;2627:4;1107:6397;6465:39;;1107:6397;-1:-1:-1;;;;;1107:6397:28;;;;;;-1:-1:-1;6465:39:28;1107:6397;;;;6465:39;;;;;;;;;;;5671:562;6518:20;1107:6397;6518:20;;;;;;;6514:109;;5671:562;6659:21;;;;6694:19;6690:108;;5671:562;1107:6397;;;6847:16;;6843:103;;1899:1:13;1107:6397:28;1899:1:13;;1107:6397:28;;6843:103;-1:-1:-1;;;;;1107:6397:28;;6879:56;;;;1107:6397;;;;;;;;;;;;;;;;6879:56;;1107:6397;;6879:56;;1107:6397;;;;;;;;;;2671:19;1107:6397;;;;;;;;;;;6879:56;;;;;;;;6843:103;;;;6879:56;;;;;:::i;:::-;1107:6397;;6879:56;;;;6690:108;6771:15;;;:::i;:::-;6690:108;;;;6514:109;6595:16;;;:::i;:::-;6514:109;;;;;6465:39;;;;;;;;;;;;;;;;;;;:::i;:::-;;;1107:6397;;;;;;;;;6465:39;;;;;;;;;;;6319:109;6400:16;;;:::i;:::-;6319:109;;;;;6270:39;;;;;;;;;;;;;;;;;;:::i;:::-;;;1107:6397;;;;;;;6270:39;;;;;;;;5719:224;1107:6397;5719:224;;1107:6397;5719:224;;;;;;1107:6397;5719:224;;;:::i;:::-;;;1107:6397;;;;;;;;;;:::i;:::-;;5719:224;;;;;;-1:-1:-1;5719:224:28;;5671:562;1107:6397;4229:22;1107:6397;;;;;;;;;;;;;5974:248;;4677:12;1107:6397;;5974:248;;1107:6397;;;;;;;;;-1:-1:-1;;;;;1107:6397:28;;;;;;;;;;;;;;;;;;;2671:19;1107:6397;;;;;;;;;;;5974:248;;;;;;;;5671:562;;;;5974:248;1107:6397;5974:248;;1107:6397;5974:248;;;;;;1107:6397;5974:248;;;:::i;:::-;;;1107:6397;;;;;;;;;;:::i;:::-;;5974:248;;;;;;-1:-1:-1;5974:248:28;;5124:46;;;;;;;;;;;;;;:::i;:::-;;;1107:6397;;;;;;;:::i;:::-;5124:46;;;;;;;4988:45;-1:-1:-1;;;;;1107:6397:28;;4988:45;;4939:15;;;;;;;;;;;;;;;;;;;:::i;:::-;;;1107:6397;;;;;;;;;:::i;:::-;;;;;;;;:::i;:::-;;4939:15;;;;;;;;-1:-1:-1;4939:15:28;;4625:256;;;;;;;;;;;;;;;;;:::i;:::-;;;1107:6397;;;;;;;:::i;:::-;4625:256;;;;;;;;;1107:6397;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;4176:21;;;;1107:6397;4176:21;;1107:6397;4176:21;;;;;;1107:6397;4176:21;;;:::i;:::-;;;1107:6397;;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;;;;4176:21;;;;;;;-1:-1:-1;4176:21:28;;978:457:33;1107:6397:28;978:457:33;;;1107:6397:28;978:457:33;;1107:6397:28;978:457:33;;;;;;;;1107:6397:28;;;978:457:33;;;1107:6397:28;978:457:33;;;;;;1107:6397:28;978:457:33;;;;;;;;;;;3712:34:28;;;1107:6397;3712:34;;1107:6397;3712:34;;;;;;1107:6397;3712:34;;;:::i;:::-;;;1107:6397;;;;;;;:::i;:::-;3712:34;;;;;;-1:-1:-1;3712:34:28;;378:247:34;1107:6397:28;;-1:-1:-1;;;431:34:34;;1107:6397:28;;;-1:-1:-1;3532:4:28;-1:-1:-1;;;;;1107:6397:28;;;;;431:34:34;1107:6397:28;;;431:34:34;;;:::i;:::-;;;;;;;;;;;;;;;378:247;425:40;;487:9;;:16;1107:6397:28;;564:50:34;;;;;1107:6397:28;564:50:34;1107:6397:28;;;;;;;;;;;;;;;564:50:34;;1107:6397:28;564:50:34;;;:::i;:::-;;;;;;;;;;;;;;378:247;;;;;;564:50;;;;;:::i;:::-;1107:6397:28;;564:50:34;;;;431:34;;;;1107:6397:28;431:34:34;;1107:6397:28;431:34:34;;;;;;1107:6397:28;431:34:34;;;:::i;:::-;;;1107:6397:28;;;;;431:34:34;;;;;;;-1:-1:-1;431:34:34;;2556:207:28;;;;;1107:6397;2556:207;;:::i;:::-;1107:6397;2556:207;;;;1107:6397;;;;-1:-1:-1;;;;;1107:6397:28;;;;;;:::o;:::-;;;;;;;;;;;:::o;:::-;;;;;;;;;;;:::o;:::-;;;;-1:-1:-1;;;;;1107:6397:28;;;;;;:::o;:::-;;;;;;;;;;;:::o;:::-;;;;;;;;;;;:::o;:::-;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;-1:-1:-1;1107:6397:28;;;;;;;;-1:-1:-1;;1107:6397:28;;;;:::o;:::-;;;-1:-1:-1;;;;;1107:6397:28;;;;;;;:::o;:::-;4229:22;1107:6397;-1:-1:-1;;;;;1107:6397:28;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;-1:-1:-1;1107:6397:28;;;;;-1:-1:-1;1107:6397:28;;;;;;;;;;;:::o;:::-;;;-1:-1:-1;;;;;1107:6397:28;;;;;;:::o;:::-;;;;;;;;;;:::o;:::-;4540:17;1107:6397;;;;;;;;;:::o;:::-;5326:34;1107:6397;;;;;;;;;:::o;:::-;;;;;;;;;;:::o;:::-;5209:23;1107:6397;-1:-1:-1;;;;;1107:6397:28;;;;;;;:::o;:::-;5633:17;1107:6397;-1:-1:-1;;;;;1107:6397:28;;;;;;;:::o;:::-;;;-1:-1:-1;;;;;1107:6397:28;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;1107:6397:28;;;;;;;;;;;;;;;1219:160:11;1107:6397:28;;-1:-1:-1;;;1328:43:11;;;;-1:-1:-1;;;;;1107:6397:28;;;;1328:43:11;;;1107:6397:28;;;;;;;;;1328:43:11;;;;;;1107:6397:28;;1328:43:11;:::i;:::-;;:::i;:::-;1219:160::o;787:233:34:-;859:10;;855:47;;868:1;930:25;;;;;;;1107:6397:28;;;;;;;;;;;;;;;;;-1:-1:-1;;1107:6397:28;;;;;:::i;:::-;;;868:1:34;1107:6397:28;;;;;;;;;787:233:34:o;1107:6397:28:-;;;;868:1:34;1107:6397:28;;868:1:34;1107:6397:28;;;;855:47:34;885:7;;:::o;3845:262:17:-;3929:4;3938:11;-1:-1:-1;;;;;1107:6397:28;3921:28:17;;:63;;3845:262;3917:184;;;4007:22;4000:29;:::o;3917:184::-;1107:6397:28;;4204:80:17;;;1107:6397:28;2079:95:17;1107:6397:28;;4226:11:17;1107:6397:28;2079:95:17;;1107:6397:28;4239:14:17;2079:95;;;1107:6397:28;4255:13:17;2079:95;;;1107:6397:28;3929:4:17;2079:95;;;1107:6397:28;2079:95:17;4204:80;;;;;;:::i;:::-;1107:6397:28;4194:91:17;;4060:30;:::o;3921:63::-;3970:14;;3953:13;:31;3921:63;;7686:720:11;;-1:-1:-1;7823:421:11;7686:720;7823:421;;;;;;;;;;;;-1:-1:-1;7823:421:11;;8258:15;;-1:-1:-1;;;;;;1107:6397:28;;8276:26:11;:31;8258:68;8254:146;;7686:720;:::o;8254:146::-;-1:-1:-1;;;;8349:40:11;;;-1:-1:-1;;;;;1107:6397:28;;;;8349:40:11;1107:6397:28;;;8349:40:11;8258:68;8325:1;8310:16;;8258:68;;7823:421;;;;-1:-1:-1;7823:421:11;;;;;3358:267:14;1390:66;3481:46;;1390:66;;;2625:40;;2679:11;2688:2;2679:11;;2675:69;;1107:6397:28;;;;;;;:::i;:::-;2311:2:14;1107:6397:28;;;;;;;;;;;2324:106:14;;;3543:22;:::o;2675:69::-;2713:20;;;-1:-1:-1;2713:20:14;;-1:-1:-1;2713:20:14;3477:142;1107:6397:28;;;-1:-1:-1;6126:13:17;1390:66:14;;6126:13:17;1390:66:14;;6126:13:17;1390:66:14;;;;;;;3477:142;1390:66;;;;;;;1107:6397:28;;;;;;1390:66:14;;;;;;;;;;;;;;;;:::i;:::-;3596:12;:::o;1390:66::-;-1:-1:-1;6126:13:17;-1:-1:-1;1390:66:14;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6126:13:17;1390:66:14;;;;;;;;;;;;;;;;;;;1107:6397:28;;1390:66:14;1107:6397:28;;;;;1390:66:14;1107:6397:28;;;1390:66:14;;;;;;;;;;;1107:6397:28;;;-1:-1:-1;1390:66:14;;;;;-1:-1:-1;1390:66:14;;;;;;;;3358:267;1390:66;3481:46;;1390:66;;;2625:40;;2679:11;2688:2;2679:11;;2675:69;;1107:6397:28;;;;;;;:::i;3477:142:14:-;1107:6397:28;;;-1:-1:-1;6584:16:17;1390:66:14;;;;;;;;;;;;;3477:142;1390:66;;;;;;;1107:6397:28;;;;;;1390:66:14;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1;6584:16:17;-1:-1:-1;1390:66:14;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Swarm Source
ipfs://028bed7974bdf9dcf966206b459f48ab0e8384096e25eb8d06c359869946098e
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 31 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
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.