Overview
TokenID
4056240849895704727964105775268495384433...
Total Transfers
-
Market
Onchain Market Cap
-
Circulating Supply Market Cap
-
Other Info
Token Contract
Loading...
Loading
Loading...
Loading
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Source Code Verified (Exact Match)
Contract Name:
BookManager
Compiler Version
v0.8.25+commit.b61c2a91
Optimization Enabled:
Yes with 1000 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: - // License: https://license.sonic.market/LICENSE.pdf pragma solidity ^0.8.20; import {Ownable2Step, Ownable} from "@openzeppelin/contracts/access/Ownable2Step.sol"; import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import {IBookManager} from "./interfaces/IBookManager.sol"; import {ILocker} from "./interfaces/ILocker.sol"; import {IHooks} from "./interfaces/IHooks.sol"; import {BookId, BookIdLibrary} from "./libraries/BookId.sol"; import {Book} from "./libraries/Book.sol"; import {Currency, CurrencyLibrary} from "./libraries/Currency.sol"; import {FeePolicy, FeePolicyLibrary} from "./libraries/FeePolicy.sol"; import {Tick, TickLibrary} from "./libraries/Tick.sol"; import {OrderId, OrderIdLibrary} from "./libraries/OrderId.sol"; import {Lockers} from "./libraries/Lockers.sol"; import {CurrencyDelta} from "./libraries/CurrencyDelta.sol"; import {ERC721Permit} from "./libraries/ERC721Permit.sol"; import {Hooks} from "./libraries/Hooks.sol"; contract BookManager is IBookManager, Ownable2Step, ERC721Permit { using SafeCast for *; using BookIdLibrary for IBookManager.BookKey; using TickLibrary for Tick; using Book for Book.State; using OrderIdLibrary for OrderId; using CurrencyLibrary for Currency; using FeePolicyLibrary for FeePolicy; using Hooks for IHooks; string public override baseURI; // slot 10 string public override contractURI; address public override defaultProvider; mapping(Currency currency => uint256) public override reservesOf; mapping(BookId id => Book.State) internal _books; mapping(address provider => bool) public override isWhitelisted; mapping(address provider => mapping(Currency currency => uint256 amount)) public override tokenOwed; constructor( address owner_, address defaultProvider_, string memory baseURI_, string memory contractURI_, string memory name_, string memory symbol_ ) Ownable(owner_) ERC721Permit(name_, symbol_, "2") { _setDefaultProvider(defaultProvider_); baseURI = baseURI_; contractURI = contractURI_; } modifier onlyByLocker() { _checkLocker(msg.sender); _; } function checkAuthorized(address owner, address spender, uint256 tokenId) external view { _checkAuthorized(owner, spender, tokenId); } function _checkLocker(address caller) internal view { address locker = Lockers.getCurrentLocker(); IHooks hook = Lockers.getCurrentHook(); if (caller == locker) return; if (caller == address(hook)) return; revert LockedBy(locker, address(hook)); } function getBookKey(BookId id) external view returns (BookKey memory) { return _books[id].key; } function getOrder(OrderId id) external view returns (OrderInfo memory) { (BookId bookId, Tick tick, uint40 orderIndex) = id.decode(); Book.State storage book = _books[bookId]; Book.Order memory order = book.getOrder(tick, orderIndex); uint64 claimable = book.calculateClaimableUnit(tick, orderIndex); unchecked { return OrderInfo({provider: order.provider, open: order.pending - claimable, claimable: claimable}); } } function open(BookKey calldata key, bytes calldata hookData) external onlyByLocker { // @dev Also, the book opener should set unit size at least circulatingTotalSupply / type(uint64).max to avoid overflow. // But it is not checked here because it is not possible to check it without knowing circulatingTotalSupply. if (key.unitSize == 0) revert InvalidUnitSize(); FeePolicy makerPolicy = key.makerPolicy; FeePolicy takerPolicy = key.takerPolicy; if (!(makerPolicy.isValid() && takerPolicy.isValid())) revert InvalidFeePolicy(); unchecked { if (makerPolicy.rate() + takerPolicy.rate() < 0) revert InvalidFeePolicy(); } if (makerPolicy.rate() < 0 || takerPolicy.rate() < 0) { if (makerPolicy.usesQuote() != takerPolicy.usesQuote()) revert InvalidFeePolicy(); } IHooks hooks = key.hooks; if (!hooks.isValidHookAddress()) revert Hooks.HookAddressNotValid(address(hooks)); hooks.beforeOpen(key, hookData); BookId id = key.toId(); _books[id].open(key); emit Open(id, key.base, key.quote, key.unitSize, makerPolicy, takerPolicy, hooks); hooks.afterOpen(key, hookData); } function lock(address locker, bytes calldata data) external returns (bytes memory result) { // Add the locker to the stack Lockers.push(locker, msg.sender); // The locker does everything in this callback, including paying what they owe via calls to settle result = ILocker(locker).lockAcquired(msg.sender, data); // Remove the locker from the stack Lockers.pop(); (uint128 length, uint128 nonzeroDeltaCount) = Lockers.lockData(); // @dev The locker must settle all currency balances to zero. if (length == 0 && nonzeroDeltaCount != 0) revert CurrencyNotSettled(); } function getCurrencyDelta(address locker, Currency currency) external view returns (int256) { return CurrencyDelta.get(locker, currency); } function getLock(uint256 i) external view returns (address, address) { return (Lockers.getLocker(i), Lockers.getLockCaller(i)); } function getLockData() external view returns (uint128, uint128) { return Lockers.lockData(); } function getDepth(BookId id, Tick tick) external view returns (uint64) { return _books[id].depth(tick); } function getHighest(BookId id) external view returns (Tick) { return _books[id].highest(); } function maxLessThan(BookId id, Tick tick) external view returns (Tick) { return _books[id].maxLessThan(tick); } function isOpened(BookId id) external view returns (bool) { return _books[id].isOpened(); } function isEmpty(BookId id) external view returns (bool) { return _books[id].isEmpty(); } function encodeBookKey(BookKey calldata key) external pure returns (BookId) { return key.toId(); } function make(MakeParams calldata params, bytes calldata hookData) external onlyByLocker returns (OrderId id, uint256 quoteAmount) { if (params.provider != address(0) && !isWhitelisted[params.provider]) revert InvalidProvider(params.provider); params.tick.validateTick(); BookId bookId = params.key.toId(); Book.State storage book = _books[bookId]; book.checkOpened(); params.key.hooks.beforeMake(params, hookData); uint40 orderIndex = book.make(params.tick, params.unit, params.provider); id = OrderIdLibrary.encode(bookId, params.tick, orderIndex); int256 quoteDelta; unchecked { // @dev uint64 * uint64 < type(uint256).max quoteAmount = uint256(params.unit) * params.key.unitSize; // @dev 0 < uint64 * uint64 + rate * uint64 * uint64 < type(int256).max quoteDelta = int256(quoteAmount); if (params.key.makerPolicy.usesQuote()) { quoteDelta += params.key.makerPolicy.calculateFee(quoteAmount, false); quoteAmount = uint256(quoteDelta); } } _accountDelta(params.key.quote, -quoteDelta); _mint(msg.sender, OrderId.unwrap(id)); emit Make(bookId, msg.sender, params.tick, orderIndex, params.unit, params.provider); params.key.hooks.afterMake(params, id, hookData); } function take(TakeParams calldata params, bytes calldata hookData) external onlyByLocker returns (uint256 quoteAmount, uint256 baseAmount) { params.tick.validateTick(); BookId bookId = params.key.toId(); Book.State storage book = _books[bookId]; book.checkOpened(); params.key.hooks.beforeTake(params, hookData); uint64 takenUnit = book.take(params.tick, params.maxUnit); unchecked { quoteAmount = uint256(takenUnit) * params.key.unitSize; } baseAmount = params.tick.quoteToBase(quoteAmount, true); int256 quoteDelta = int256(quoteAmount); int256 baseDelta = baseAmount.toInt256(); if (params.key.takerPolicy.usesQuote()) { quoteDelta -= params.key.takerPolicy.calculateFee(quoteAmount, false); quoteAmount = uint256(quoteDelta); } else { baseDelta += params.key.takerPolicy.calculateFee(baseAmount, false); baseAmount = uint256(baseDelta); } _accountDelta(params.key.quote, quoteDelta); _accountDelta(params.key.base, -baseDelta); emit Take(bookId, msg.sender, params.tick, takenUnit); params.key.hooks.afterTake(params, takenUnit, hookData); } function cancel(CancelParams calldata params, bytes calldata hookData) external onlyByLocker returns (uint256 canceledAmount) { _checkAuthorized(_ownerOf(OrderId.unwrap(params.id)), msg.sender, OrderId.unwrap(params.id)); Book.State storage book = _books[params.id.getBookId()]; BookKey memory key = book.key; key.hooks.beforeCancel(params, hookData); (uint64 canceledUnit, uint64 pendingUnit) = book.cancel(params.id, params.toUnit); unchecked { canceledAmount = uint256(canceledUnit) * key.unitSize; if (key.makerPolicy.usesQuote()) { int256 quoteFee = key.makerPolicy.calculateFee(canceledAmount, true); canceledAmount = uint256(int256(canceledAmount) + quoteFee); } } if (pendingUnit == 0) _burn(OrderId.unwrap(params.id)); _accountDelta(key.quote, int256(canceledAmount)); emit Cancel(params.id, canceledUnit); key.hooks.afterCancel(params, canceledUnit, hookData); } function claim(OrderId id, bytes calldata hookData) external onlyByLocker returns (uint256 claimedAmount) { _checkAuthorized(_ownerOf(OrderId.unwrap(id)), msg.sender, OrderId.unwrap(id)); Tick tick; uint40 orderIndex; Book.State storage book; { BookId bookId; (bookId, tick, orderIndex) = id.decode(); book = _books[bookId]; } IBookManager.BookKey memory key = book.key; key.hooks.beforeClaim(id, hookData); uint64 claimedUnit = book.claim(tick, orderIndex); int256 quoteFee; int256 baseFee; { uint256 claimedInQuote; unchecked { claimedInQuote = uint256(claimedUnit) * key.unitSize; } claimedAmount = tick.quoteToBase(claimedInQuote, false); FeePolicy makerPolicy = key.makerPolicy; FeePolicy takerPolicy = key.takerPolicy; if (takerPolicy.usesQuote()) { quoteFee = takerPolicy.calculateFee(claimedInQuote, true); } else { baseFee = takerPolicy.calculateFee(claimedAmount, true); } if (makerPolicy.usesQuote()) { quoteFee += makerPolicy.calculateFee(claimedInQuote, true); } else { int256 makeFee = makerPolicy.calculateFee(claimedAmount, false); baseFee += makeFee; claimedAmount = makeFee > 0 ? claimedAmount - uint256(makeFee) : claimedAmount + uint256(-makeFee); } } Book.Order memory order = book.getOrder(tick, orderIndex); address provider = order.provider; if (provider == address(0)) provider = defaultProvider; if (quoteFee > 0) tokenOwed[provider][key.quote] += quoteFee.toUint256(); if (baseFee > 0) tokenOwed[provider][key.base] += baseFee.toUint256(); if (order.pending == 0) _burn(OrderId.unwrap(id)); _accountDelta(key.base, claimedAmount.toInt256()); emit Claim(id, claimedUnit); key.hooks.afterClaim(id, claimedUnit, hookData); } function collect(address recipient, Currency currency) external returns (uint256 amount) { amount = tokenOwed[msg.sender][currency]; tokenOwed[msg.sender][currency] = 0; reservesOf[currency] -= amount; currency.transfer(recipient, amount); emit Collect(msg.sender, recipient, currency, amount); } function withdraw(Currency currency, address to, uint256 amount) external onlyByLocker { if (amount > 0) { _accountDelta(currency, -amount.toInt256()); reservesOf[currency] -= amount; currency.transfer(to, amount); } } function settle(Currency currency) external payable onlyByLocker returns (uint256 paid) { uint256 reservesBefore = reservesOf[currency]; reservesOf[currency] = currency.balanceOfSelf(); paid = reservesOf[currency] - reservesBefore; // subtraction must be safe _accountDelta(currency, paid.toInt256()); } function whitelist(address provider) external onlyOwner { isWhitelisted[provider] = true; emit Whitelist(provider); } function delist(address provider) external onlyOwner { isWhitelisted[provider] = false; emit Delist(provider); } function setDefaultProvider(address newDefaultProvider) external onlyOwner { _setDefaultProvider(newDefaultProvider); } function _setDefaultProvider(address newDefaultProvider) internal { defaultProvider = newDefaultProvider; emit SetDefaultProvider(newDefaultProvider); } function _baseURI() internal view override returns (string memory) { return baseURI; } function _accountDelta(Currency currency, int256 delta) internal { if (delta == 0) return; address locker = Lockers.getCurrentLocker(); int256 next = CurrencyDelta.add(locker, currency, delta); if (next == 0) Lockers.decrementNonzeroDeltaCount(); else if (next == delta) Lockers.incrementNonzeroDeltaCount(); } function load(bytes32 slot) external view returns (bytes32 value) { assembly { value := sload(slot) } } function load(bytes32 startSlot, uint256 nSlot) external view returns (bytes memory value) { value = new bytes(32 * nSlot); assembly { for { let i := 0 } lt(i, nSlot) { i := add(i, 1) } { mstore(add(value, mul(add(i, 1), 32)), sload(add(startSlot, i))) } } } receive() external payable {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol) pragma solidity ^0.8.20; import {Context} from "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * The initial owner is set to the address provided by the deployer. This can * later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; /** * @dev The caller account is not authorized to perform an operation. */ error OwnableUnauthorizedAccount(address account); /** * @dev The owner is not a valid owner account. (eg. `address(0)`) */ error OwnableInvalidOwner(address owner); event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the address provided by the deployer as the initial owner. */ constructor(address initialOwner) { if (initialOwner == address(0)) { revert OwnableInvalidOwner(address(0)); } _transferOwnership(initialOwner); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { if (owner() != _msgSender()) { revert OwnableUnauthorizedAccount(_msgSender()); } } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby disabling any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { if (newOwner == address(0)) { revert OwnableInvalidOwner(address(0)); } _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol) pragma solidity ^0.8.20; import {Ownable} from "./Ownable.sol"; /** * @dev Contract module which provides access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * This extension of the {Ownable} contract includes a two-step mechanism to transfer * ownership, where the new owner must call {acceptOwnership} in order to replace the * old one. This can help prevent common mistakes, such as transfers of ownership to * incorrect accounts, or to contracts that are unable to interact with the * permission system. * * The initial owner is specified at deployment time in the constructor for `Ownable`. This * can later be changed with {transferOwnership} and {acceptOwnership}. * * This module is used through inheritance. It will make available all functions * from parent (Ownable). */ abstract contract Ownable2Step is Ownable { address private _pendingOwner; event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner); /** * @dev Returns the address of the pending owner. */ function pendingOwner() public view virtual returns (address) { return _pendingOwner; } /** * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual override onlyOwner { _pendingOwner = newOwner; emit OwnershipTransferStarted(owner(), newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner. * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual override { delete _pendingOwner; super._transferOwnership(newOwner); } /** * @dev The new owner accepts the ownership transfer. */ function acceptOwnership() public virtual { address sender = _msgSender(); if (pendingOwner() != sender) { revert OwnableUnauthorizedAccount(sender); } _transferOwnership(sender); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol) pragma solidity ^0.8.20; /** * @dev Standard ERC-20 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens. */ interface IERC20Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC20InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC20InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers. * @param spender Address that may be allowed to operate on tokens without being their owner. * @param allowance Amount of tokens a `spender` is allowed to operate with. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC20InvalidApprover(address approver); /** * @dev Indicates a failure with the `spender` to be approved. Used in approvals. * @param spender Address that may be allowed to operate on tokens without being their owner. */ error ERC20InvalidSpender(address spender); } /** * @dev Standard ERC-721 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens. */ interface IERC721Errors { /** * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20. * Used in balance queries. * @param owner Address of the current owner of a token. */ error ERC721InvalidOwner(address owner); /** * @dev Indicates a `tokenId` whose `owner` is the zero address. * @param tokenId Identifier number of a token. */ error ERC721NonexistentToken(uint256 tokenId); /** * @dev Indicates an error related to the ownership over a particular token. Used in transfers. * @param sender Address whose tokens are being transferred. * @param tokenId Identifier number of a token. * @param owner Address of the current owner of a token. */ error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC721InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC721InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param tokenId Identifier number of a token. */ error ERC721InsufficientApproval(address operator, uint256 tokenId); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC721InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC721InvalidOperator(address operator); } /** * @dev Standard ERC-1155 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens. */ interface IERC1155Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. * @param tokenId Identifier number of a token. */ error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC1155InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC1155InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param owner Address of the current owner of a token. */ error ERC1155MissingApprovalForAll(address operator, address owner); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC1155InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC1155InvalidOperator(address operator); /** * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation. * Used in batch transfers. * @param idsLength Length of the array of token identifiers * @param valuesLength Length of the array of token amounts */ error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1271.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC-1271 standard signature validation method for * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271]. */ interface IERC1271 { /** * @dev Should return whether the signature provided is valid for the provided data * @param hash Hash of the data to be signed * @param signature Signature byte array associated with _data */ function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue); }
// 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.0.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.0.0) (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.20; import {IERC721} from "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.20; import {IERC165} from "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC-721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon * a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC-721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or * {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon * a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721 * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must * understand this adds an external call which potentially creates a reentrancy vulnerability. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 tokenId) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the address zero. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.20; /** * @title ERC-721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC-721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be * reverted. * * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol) pragma solidity ^0.8.20; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } function _contextSuffixLength() internal view virtual returns (uint256) { return 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.20; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS } /** * @dev The signature derives the `address(0)`. */ error ECDSAInvalidSignature(); /** * @dev The signature has an invalid length. */ error ECDSAInvalidSignatureLength(uint256 length); /** * @dev The signature has an S value that is in the upper half order. */ error ECDSAInvalidSignatureS(bytes32 s); /** * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not * return address(0) without also returning an error description. Errors are documented using an enum (error type) * and a bytes32 providing additional information about the error. * * If no error is returned, then the address can be used for verification purposes. * * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. /// @solidity memory-safe-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length)); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature); _throwError(error, errorArg); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures] */ function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) { unchecked { bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); // We do not check for an overflow here since the shift operation results in 0 or 1. uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. */ function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) { (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs); _throwError(error, errorArg); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError, bytes32) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS, s); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature, bytes32(0)); } return (signer, RecoverError.NoError, bytes32(0)); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) { (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s); _throwError(error, errorArg); return recovered; } /** * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided. */ function _throwError(RecoverError error, bytes32 errorArg) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert ECDSAInvalidSignature(); } else if (error == RecoverError.InvalidSignatureLength) { revert ECDSAInvalidSignatureLength(uint256(errorArg)); } else if (error == RecoverError.InvalidSignatureS) { revert ECDSAInvalidSignatureS(errorArg); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.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.0.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) { /// @solidity memory-safe-assembly assembly { 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) { /// @solidity memory-safe-assembly assembly { 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.0.0) (utils/introspection/ERC165.sol) pragma solidity ^0.8.20; import {IERC165} from "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) { return interfaceId == type(IERC165).interfaceId; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.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.0.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 Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds 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 a == 0 ? 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 // 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(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, expect 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 Ferma's little theorem and get the * inverse using `Math.modExp(a, n - 2, n)`. */ 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 x < 0 ? (n - uint256(-x)) : uint256(x); // Wrap the result if it's negative. } } /** * @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 has 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); /// @solidity memory-safe-assembly assembly { 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); /// @solidity memory-safe-assembly assembly { 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 value) internal pure returns (uint256) { uint256 result = 0; uint256 exp; unchecked { exp = 128 * SafeCast.toUint(value > (1 << 128) - 1); value >>= exp; result += exp; exp = 64 * SafeCast.toUint(value > (1 << 64) - 1); value >>= exp; result += exp; exp = 32 * SafeCast.toUint(value > (1 << 32) - 1); value >>= exp; result += exp; exp = 16 * SafeCast.toUint(value > (1 << 16) - 1); value >>= exp; result += exp; exp = 8 * SafeCast.toUint(value > (1 << 8) - 1); value >>= exp; result += exp; exp = 4 * SafeCast.toUint(value > (1 << 4) - 1); value >>= exp; result += exp; exp = 2 * SafeCast.toUint(value > (1 << 2) - 1); value >>= exp; result += exp; result += SafeCast.toUint(value > 1); } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + 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 value) internal pure returns (uint256) { uint256 result = 0; uint256 isGt; unchecked { isGt = SafeCast.toUint(value > (1 << 128) - 1); value >>= isGt * 128; result += isGt * 16; isGt = SafeCast.toUint(value > (1 << 64) - 1); value >>= isGt * 64; result += isGt * 8; isGt = SafeCast.toUint(value > (1 << 32) - 1); value >>= isGt * 32; result += isGt * 4; isGt = SafeCast.toUint(value > (1 << 16) - 1); value >>= isGt * 16; result += isGt * 2; result += SafeCast.toUint(value > (1 << 8) - 1); } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + 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.0.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) { /// @solidity memory-safe-assembly assembly { u := iszero(iszero(b)) } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.20; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMath { /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return a > b ? a : b; } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return a < b ? a : b; } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // 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 `bytes(0)` (if n is positive) or `~bytes32(0)` (if n is negative). int256 mask = n >> 255; // A `bytes(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it. return uint256((n + mask) ^ mask); } } }
// SPDX-License-Identifier: MIT 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]. */ // 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 { /// @solidity memory-safe-assembly assembly { mstore(0x00, 0x4e487b71) mstore(0x20, code) revert(0x1c, 0x24) } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.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); /// @solidity memory-safe-assembly assembly { 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) (utils/StorageSlot.sol) // This file was procedurally generated from scripts/generate/templates/StorageSlot.js. pragma solidity ^0.8.24; /** * @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; * } * } * ``` * * Since version 5.1, this library also support writing and reading value types to and from transient storage. * * * Example using transient storage: * ```solidity * contract Lock { * // Define the slot. Alternatively, use the SlotDerivation library to derive the slot. * bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542; * * modifier locked() { * require(!_LOCK_SLOT.asBoolean().tload()); * * _LOCK_SLOT.asBoolean().tstore(true); * _; * _LOCK_SLOT.asBoolean().tstore(false); * } * } * ``` * * 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) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Int256Slot` with member `value` located at `slot`. */ function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `StringSlot` with member `value` located at `slot`. */ function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) { /// @solidity memory-safe-assembly assembly { 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) { /// @solidity memory-safe-assembly assembly { r.slot := store.slot } } /** * @dev Returns an `BytesSlot` with member `value` located at `slot`. */ function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) { /// @solidity memory-safe-assembly assembly { 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) { /// @solidity memory-safe-assembly assembly { r.slot := store.slot } } /** * @dev UDVT that represent a slot holding a address. */ type AddressSlotType is bytes32; /** * @dev Cast an arbitrary slot to a AddressSlotType. */ function asAddress(bytes32 slot) internal pure returns (AddressSlotType) { return AddressSlotType.wrap(slot); } /** * @dev UDVT that represent a slot holding a bool. */ type BooleanSlotType is bytes32; /** * @dev Cast an arbitrary slot to a BooleanSlotType. */ function asBoolean(bytes32 slot) internal pure returns (BooleanSlotType) { return BooleanSlotType.wrap(slot); } /** * @dev UDVT that represent a slot holding a bytes32. */ type Bytes32SlotType is bytes32; /** * @dev Cast an arbitrary slot to a Bytes32SlotType. */ function asBytes32(bytes32 slot) internal pure returns (Bytes32SlotType) { return Bytes32SlotType.wrap(slot); } /** * @dev UDVT that represent a slot holding a uint256. */ type Uint256SlotType is bytes32; /** * @dev Cast an arbitrary slot to a Uint256SlotType. */ function asUint256(bytes32 slot) internal pure returns (Uint256SlotType) { return Uint256SlotType.wrap(slot); } /** * @dev UDVT that represent a slot holding a int256. */ type Int256SlotType is bytes32; /** * @dev Cast an arbitrary slot to a Int256SlotType. */ function asInt256(bytes32 slot) internal pure returns (Int256SlotType) { return Int256SlotType.wrap(slot); } /** * @dev Load the value held at location `slot` in transient storage. */ function tload(AddressSlotType slot) internal view returns (address value) { /// @solidity memory-safe-assembly assembly { value := tload(slot) } } /** * @dev Store `value` at location `slot` in transient storage. */ function tstore(AddressSlotType slot, address value) internal { /// @solidity memory-safe-assembly assembly { tstore(slot, value) } } /** * @dev Load the value held at location `slot` in transient storage. */ function tload(BooleanSlotType slot) internal view returns (bool value) { /// @solidity memory-safe-assembly assembly { value := tload(slot) } } /** * @dev Store `value` at location `slot` in transient storage. */ function tstore(BooleanSlotType slot, bool value) internal { /// @solidity memory-safe-assembly assembly { tstore(slot, value) } } /** * @dev Load the value held at location `slot` in transient storage. */ function tload(Bytes32SlotType slot) internal view returns (bytes32 value) { /// @solidity memory-safe-assembly assembly { value := tload(slot) } } /** * @dev Store `value` at location `slot` in transient storage. */ function tstore(Bytes32SlotType slot, bytes32 value) internal { /// @solidity memory-safe-assembly assembly { tstore(slot, value) } } /** * @dev Load the value held at location `slot` in transient storage. */ function tload(Uint256SlotType slot) internal view returns (uint256 value) { /// @solidity memory-safe-assembly assembly { value := tload(slot) } } /** * @dev Store `value` at location `slot` in transient storage. */ function tstore(Uint256SlotType slot, uint256 value) internal { /// @solidity memory-safe-assembly assembly { tstore(slot, value) } } /** * @dev Load the value held at location `slot` in transient storage. */ function tload(Int256SlotType slot) internal view returns (int256 value) { /// @solidity memory-safe-assembly assembly { value := tload(slot) } } /** * @dev Store `value` at location `slot` in transient storage. */ function tstore(Int256SlotType slot, int256 value) internal { /// @solidity memory-safe-assembly assembly { tstore(slot, value) } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol) pragma solidity ^0.8.20; import {Math} from "./math/Math.sol"; import {SignedMath} from "./math/SignedMath.sol"; /** * @dev String operations. */ library Strings { 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 Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), 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 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)); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {IERC721Metadata} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol"; import {BookId} from "../libraries/BookId.sol"; import {Currency} from "../libraries/Currency.sol"; import {OrderId} from "../libraries/OrderId.sol"; import {Tick} from "../libraries/Tick.sol"; import {FeePolicy} from "../libraries/FeePolicy.sol"; import {IERC721Permit} from "./IERC721Permit.sol"; import {IHooks} from "./IHooks.sol"; /** * @title IBookManager * @notice The interface for the BookManager contract */ interface IBookManager is IERC721Metadata, IERC721Permit { error InvalidUnitSize(); error InvalidFeePolicy(); error InvalidProvider(address provider); error LockedBy(address locker, address hook); error CurrencyNotSettled(); /** * @notice Event emitted when a new book is opened * @param id The book id * @param base The base currency * @param quote The quote currency * @param unitSize The unit size of the book * @param makerPolicy The maker fee policy * @param takerPolicy The taker fee policy * @param hooks The hooks contract */ event Open( BookId indexed id, Currency indexed base, Currency indexed quote, uint64 unitSize, FeePolicy makerPolicy, FeePolicy takerPolicy, IHooks hooks ); /** * @notice Event emitted when a new order is made * @param bookId The book id * @param user The user address * @param tick The order tick * @param orderIndex The order index * @param unit The order unit * @param provider The provider address */ event Make( BookId indexed bookId, address indexed user, Tick tick, uint256 orderIndex, uint64 unit, address provider ); /** * @notice Event emitted when an order is taken * @param bookId The book id * @param user The user address * @param tick The order tick * @param unit The order unit */ event Take(BookId indexed bookId, address indexed user, Tick tick, uint64 unit); /** * @notice Event emitted when an order is canceled * @param orderId The order id * @param unit The canceled unit */ event Cancel(OrderId indexed orderId, uint64 unit); /** * @notice Event emitted when an order is claimed * @param orderId The order id * @param unit The claimed unit */ event Claim(OrderId indexed orderId, uint64 unit); /** * @notice Event emitted when a provider is whitelisted * @param provider The provider address */ event Whitelist(address indexed provider); /** * @notice Event emitted when a provider is delisted * @param provider The provider address */ event Delist(address indexed provider); /** * @notice Event emitted when a provider collects fees * @param provider The provider address * @param recipient The recipient address * @param currency The currency * @param amount The collected amount */ event Collect(address indexed provider, address indexed recipient, Currency indexed currency, uint256 amount); /** * @notice Event emitted when new default provider is set * @param newDefaultProvider The new default provider address */ event SetDefaultProvider(address indexed newDefaultProvider); /** * @notice This structure represents a unique identifier for a book in the BookManager. * @param base The base currency of the book * @param unitSize The unit size of the book * @param quote The quote currency of the book * @param makerPolicy The maker fee policy of the book * @param hooks The hooks contract of the book * @param takerPolicy The taker fee policy of the book */ struct BookKey { Currency base; uint64 unitSize; Currency quote; FeePolicy makerPolicy; IHooks hooks; FeePolicy takerPolicy; } /** * @notice Returns the base URI * @return The base URI */ function baseURI() external view returns (string memory); /** * @notice Returns the contract URI * @return The contract URI */ function contractURI() external view returns (string memory); /** * @notice Returns the default provider * @return The default provider */ function defaultProvider() external view returns (address); /** * @notice Returns the total reserves of a given currency * @param currency The currency in question * @return The total reserves amount */ function reservesOf(Currency currency) external view returns (uint256); /** * @notice Checks if a provider is whitelisted * @param provider The address of the provider * @return True if the provider is whitelisted, false otherwise */ function isWhitelisted(address provider) external view returns (bool); /** * @notice Verifies if an owner has authorized a spender for a token * @param owner The address of the token owner * @param spender The address of the spender * @param tokenId The token ID */ function checkAuthorized(address owner, address spender, uint256 tokenId) external view; /** * @notice Calculates the amount owed to a provider in a given currency * @param provider The provider's address * @param currency The currency in question * @return The owed amount */ function tokenOwed(address provider, Currency currency) external view returns (uint256); /** * @notice Calculates the currency balance changes for a given locker * @param locker The address of the locker * @param currency The currency in question * @return The net change in currency balance */ function getCurrencyDelta(address locker, Currency currency) external view returns (int256); /** * @notice Retrieves the book key for a given book ID * @param id The book ID * @return The book key */ function getBookKey(BookId id) external view returns (BookKey memory); /** * @notice This structure represents a current status for an order in the BookManager. * @param provider The provider of the order * @param open The open unit of the order * @param claimable The claimable unit of the order */ struct OrderInfo { address provider; uint64 open; uint64 claimable; } /** * @notice Provides information about an order * @param id The order ID * @return Order information including provider, open status, and claimable unit */ function getOrder(OrderId id) external view returns (OrderInfo memory); /** * @notice Retrieves the locker and caller addresses for a given lock * @param i The index of the lock * @return locker The locker's address * @return lockCaller The caller's address */ function getLock(uint256 i) external view returns (address locker, address lockCaller); /** * @notice Provides the lock data * @return The lock data including necessary numeric values */ function getLockData() external view returns (uint128, uint128); /** * @notice Returns the depth of a given book ID and tick * @param id The book ID * @param tick The tick * @return The depth of the tick */ function getDepth(BookId id, Tick tick) external view returns (uint64); /** * @notice Retrieves the highest tick for a given book ID * @param id The book ID * @return tick The highest tick */ function getHighest(BookId id) external view returns (Tick tick); /** * @notice Finds the maximum tick less than a specified tick in a book * @dev Returns `Tick.wrap(type(int24).min)` if the specified tick is the lowest * @param id The book ID * @param tick The specified tick * @return The next lower tick */ function maxLessThan(BookId id, Tick tick) external view returns (Tick); /** * @notice Checks if a book is opened * @param id The book ID * @return True if the book is opened, false otherwise */ function isOpened(BookId id) external view returns (bool); /** * @notice Checks if a book is empty * @param id The book ID * @return True if the book is empty, false otherwise */ function isEmpty(BookId id) external view returns (bool); /** * @notice Encodes a BookKey into a BookId * @param key The BookKey to encode * @return The encoded BookId */ function encodeBookKey(BookKey calldata key) external pure returns (BookId); /** * @notice Loads a value from a specific storage slot * @param slot The storage slot * @return The value in the slot */ function load(bytes32 slot) external view returns (bytes32); /** * @notice Loads a sequence of values starting from a specific slot * @param startSlot The starting slot * @param nSlot The number of slots to load * @return The sequence of values */ function load(bytes32 startSlot, uint256 nSlot) external view returns (bytes memory); /** * @notice Opens a new book * @param key The book key * @param hookData The hook data */ function open(BookKey calldata key, bytes calldata hookData) external; /** * @notice Locks a book manager function * @param locker The locker address * @param data The lock data * @return The lock return data */ function lock(address locker, bytes calldata data) external returns (bytes memory); /** * @notice This structure represents the parameters for making an order. * @param key The book key for the order * @param tick The tick for the order * @param unit The unit for the order. Times key.unitSize to get actual bid amount. * @param provider The provider for the order. The limit order service provider address to collect fees. */ struct MakeParams { BookKey key; Tick tick; uint64 unit; address provider; } /** * @notice Make a limit order * @param params The order parameters * @param hookData The hook data * @return id The order id. Returns 0 if the order is not settled * @return quoteAmount The amount of quote currency to be paid */ function make(MakeParams calldata params, bytes calldata hookData) external returns (OrderId id, uint256 quoteAmount); /** * @notice This structure represents the parameters for taking orders in the specified tick. * @param key The book key for the order * @param tick The tick for the order * @param maxUnit The max unit to take */ struct TakeParams { BookKey key; Tick tick; uint64 maxUnit; } /** * @notice Take a limit order at specific tick * @param params The order parameters * @param hookData The hook data * @return quoteAmount The amount of quote currency to be received * @return baseAmount The amount of base currency to be paid */ function take(TakeParams calldata params, bytes calldata hookData) external returns (uint256 quoteAmount, uint256 baseAmount); /** * @notice This structure represents the parameters for canceling an order. * @param id The order id for the order * @param toUnit The remaining open unit for the order after cancellation. Must not exceed the current open unit. */ struct CancelParams { OrderId id; uint64 toUnit; } /** * @notice Cancel a limit order * @param params The order parameters * @param hookData The hook data * @return canceledAmount The amount of quote currency canceled */ function cancel(CancelParams calldata params, bytes calldata hookData) external returns (uint256 canceledAmount); /** * @notice Claims an order * @param id The order ID * @param hookData The hook data * @return claimedAmount The amount claimed */ function claim(OrderId id, bytes calldata hookData) external returns (uint256 claimedAmount); /** * @notice Collects fees from a provider * @param recipient The recipient address * @param currency The currency * @return The collected amount */ function collect(address recipient, Currency currency) external returns (uint256); /** * @notice Withdraws a currency * @param currency The currency * @param to The recipient address * @param amount The amount */ function withdraw(Currency currency, address to, uint256 amount) external; /** * @notice Settles a currency * @param currency The currency * @return The settled amount */ function settle(Currency currency) external payable returns (uint256); /** * @notice Whitelists a provider * @param provider The provider address */ function whitelist(address provider) external; /** * @notice Delists a provider * @param provider The provider address */ function delist(address provider) external; /** * @notice Sets the default provider * @param newDefaultProvider The new default provider address */ function setDefaultProvider(address newDefaultProvider) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; /** * @title IERC721Permit * @notice An interface for the ERC721 permit extension */ interface IERC721Permit is IERC721 { error InvalidSignature(); error PermitExpired(); /** * @notice The EIP-712 typehash for the permit struct used by the contract */ function PERMIT_TYPEHASH() external pure returns (bytes32); /** * @notice The EIP-712 domain separator for this contract */ function DOMAIN_SEPARATOR() external view returns (bytes32); /** * @notice Approve the spender to transfer the given tokenId * @param spender The address to approve * @param tokenId The tokenId to approve * @param deadline The deadline for the signature * @param v The recovery id of the signature * @param r The r value of the signature * @param s The s value of the signature */ function permit(address spender, uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external; /** * @notice Get the current nonce for a token * @param tokenId The tokenId to get the nonce for * @return The current nonce */ function nonces(uint256 tokenId) external view returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import {IBookManager} from "./IBookManager.sol"; import {OrderId} from "../libraries/OrderId.sol"; /** * @title IHooks * @notice Interface for the hooks contract */ interface IHooks { /** * @notice Hook called before opening a new book * @param sender The sender of the open transaction * @param key The key of the book being opened * @param hookData The data passed to the hook * @return Returns the function selector if the hook is successful */ function beforeOpen(address sender, IBookManager.BookKey calldata key, bytes calldata hookData) external returns (bytes4); /** * @notice Hook called after opening a new book * @param sender The sender of the open transaction * @param key The key of the book being opened * @param hookData The data passed to the hook * @return Returns the function selector if the hook is successful */ function afterOpen(address sender, IBookManager.BookKey calldata key, bytes calldata hookData) external returns (bytes4); /** * @notice Hook called before making a new order * @param sender The sender of the make transaction * @param params The parameters of the make transaction * @param hookData The data passed to the hook * @return Returns the function selector if the hook is successful */ function beforeMake(address sender, IBookManager.MakeParams calldata params, bytes calldata hookData) external returns (bytes4); /** * @notice Hook called after making a new order * @param sender The sender of the make transaction * @param params The parameters of the make transaction * @param orderId The id of the order that was made * @param hookData The data passed to the hook * @return Returns the function selector if the hook is successful */ function afterMake( address sender, IBookManager.MakeParams calldata params, OrderId orderId, bytes calldata hookData ) external returns (bytes4); /** * @notice Hook called before taking an order * @param sender The sender of the take transaction * @param params The parameters of the take transaction * @param hookData The data passed to the hook * @return Returns the function selector if the hook is successful */ function beforeTake(address sender, IBookManager.TakeParams calldata params, bytes calldata hookData) external returns (bytes4); /** * @notice Hook called after taking an order * @param sender The sender of the take transaction * @param params The parameters of the take transaction * @param takenUnit The unit that was taken * @param hookData The data passed to the hook * @return Returns the function selector if the hook is successful */ function afterTake( address sender, IBookManager.TakeParams calldata params, uint64 takenUnit, bytes calldata hookData ) external returns (bytes4); /** * @notice Hook called before canceling an order * @param sender The sender of the cancel transaction * @param params The parameters of the cancel transaction * @param hookData The data passed to the hook * @return Returns the function selector if the hook is successful */ function beforeCancel(address sender, IBookManager.CancelParams calldata params, bytes calldata hookData) external returns (bytes4); /** * @notice Hook called after canceling an order * @param sender The sender of the cancel transaction * @param params The parameters of the cancel transaction * @param canceledUnit The unit that was canceled * @param hookData The data passed to the hook * @return Returns the function selector if the hook is successful */ function afterCancel( address sender, IBookManager.CancelParams calldata params, uint64 canceledUnit, bytes calldata hookData ) external returns (bytes4); /** * @notice Hook called before claiming an order * @param sender The sender of the claim transaction * @param orderId The id of the order being claimed * @param hookData The data passed to the hook * @return Returns the function selector if the hook is successful */ function beforeClaim(address sender, OrderId orderId, bytes calldata hookData) external returns (bytes4); /** * @notice Hook called after claiming an order * @param sender The sender of the claim transaction * @param orderId The id of the order being claimed * @param claimedUnit The unit that was claimed * @param hookData The data passed to the hook * @return Returns the function selector if the hook is successful */ function afterClaim(address sender, OrderId orderId, uint64 claimedUnit, bytes calldata hookData) external returns (bytes4); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @title ILocker * @notice Interface for the locker contract */ interface ILocker { /** * @notice Called by the book manager on `msg.sender` when a lock is acquired * @param data The data that was passed to the call to lock * @return Any data that you want to be returned from the lock call */ function lockAcquired(address lockCaller, bytes calldata data) external returns (bytes memory); }
// SPDX-License-Identifier: - // License: https://license.sonic.market/LICENSE.pdf pragma solidity ^0.8.20; import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import {IBookManager} from "../interfaces/IBookManager.sol"; import {SegmentedSegmentTree} from "./SegmentedSegmentTree.sol"; import {Tick, TickLibrary} from "./Tick.sol"; import {OrderId, OrderIdLibrary} from "./OrderId.sol"; import {TotalClaimableMap} from "./TotalClaimableMap.sol"; import {TickBitmap} from "./TickBitmap.sol"; library Book { using Book for State; using TickBitmap for mapping(uint256 => uint256); using SegmentedSegmentTree for SegmentedSegmentTree.Core; using TotalClaimableMap for mapping(uint24 => uint256); using TickLibrary for Tick; using OrderIdLibrary for OrderId; error ZeroUnit(); error BookAlreadyOpened(); error BookNotOpened(); error QueueReplaceFailed(); error CancelFailed(uint64 maxCancelableUnit); // @dev Due to the segment tree implementation, the maximum order size is 2 ** 15. uint40 internal constant MAX_ORDER = 2 ** 15; // 32768 uint256 internal constant MAX_ORDER_M = 2 ** 15 - 1; // % 32768 struct Order { address provider; uint64 pending; // @dev unfilled unit + filled(claimable) unit } struct Queue { SegmentedSegmentTree.Core tree; Order[] orders; } struct State { IBookManager.BookKey key; mapping(Tick tick => Queue) queues; mapping(uint256 => uint256) tickBitmap; // @dev Four values of totalClaimable are stored in one uint256 mapping(uint24 groupIndex => uint256) totalClaimableOf; } function open(State storage self, IBookManager.BookKey calldata key) external { if (self.isOpened()) revert BookAlreadyOpened(); self.key = key; } function isOpened(State storage self) internal view returns (bool) { return self.key.unitSize != 0; } function checkOpened(State storage self) internal view { if (!self.isOpened()) revert BookNotOpened(); } function depth(State storage self, Tick tick) internal view returns (uint64) { return self.queues[tick].tree.total() - self.totalClaimableOf.get(tick); } function highest(State storage self) internal view returns (Tick) { return self.tickBitmap.highest(); } function maxLessThan(State storage self, Tick tick) internal view returns (Tick) { return self.tickBitmap.maxLessThan(tick); } function isEmpty(State storage self) internal view returns (bool) { return self.tickBitmap.isEmpty(); } function _getOrder(State storage self, Tick tick, uint40 index) private view returns (Order storage) { return self.queues[tick].orders[index]; } function getOrder(State storage self, Tick tick, uint40 index) internal view returns (Order memory) { return _getOrder(self, tick, index); } function make(State storage self, Tick tick, uint64 unit, address provider) external returns (uint40 orderIndex) { if (unit == 0) revert ZeroUnit(); if (!self.tickBitmap.has(tick)) self.tickBitmap.set(tick); Queue storage queue = self.queues[tick]; // @dev Assume that orders.length cannot reach to type(uint40).max + 1. orderIndex = SafeCast.toUint40(queue.orders.length); if (orderIndex >= MAX_ORDER) { unchecked { uint40 staleOrderIndex = orderIndex - MAX_ORDER; uint64 stalePendingUnit = queue.orders[staleOrderIndex].pending; if (stalePendingUnit > 0) { // If the order is not settled completely, we cannot replace it uint64 claimable = calculateClaimableUnit(self, tick, staleOrderIndex); if (claimable != stalePendingUnit) revert QueueReplaceFailed(); } } // The stale order is settled completely, so remove it from the totalClaimableOf. // We can determine the stale order is claimable. uint64 staleOrderedUnit = queue.tree.get(orderIndex & MAX_ORDER_M); if (staleOrderedUnit > 0) self.totalClaimableOf.sub(tick, staleOrderedUnit); } queue.tree.update(orderIndex & MAX_ORDER_M, unit); queue.orders.push(Order({pending: unit, provider: provider})); } /** * @notice Take orders from the book * @param self The book state * @param maxTakeUnit The maximum unit to take * @return takenUnit The actual unit to take */ function take(State storage self, Tick tick, uint64 maxTakeUnit) external returns (uint64 takenUnit) { uint64 currentDepth = depth(self, tick); if (currentDepth > maxTakeUnit) { takenUnit = maxTakeUnit; } else { takenUnit = currentDepth; self.tickBitmap.clear(tick); } self.totalClaimableOf.add(tick, takenUnit); } function cancel(State storage self, OrderId orderId, uint64 to) external returns (uint64 canceled, uint64 afterPending) { (, Tick tick, uint40 orderIndex) = orderId.decode(); Queue storage queue = self.queues[tick]; uint64 pendingUnit = queue.orders[orderIndex].pending; uint64 claimableUnit = calculateClaimableUnit(self, tick, orderIndex); afterPending = to + claimableUnit; unchecked { if (pendingUnit < afterPending) revert CancelFailed(pendingUnit - claimableUnit); canceled = pendingUnit - afterPending; self.queues[tick].tree.update( orderIndex & MAX_ORDER_M, self.queues[tick].tree.get(orderIndex & MAX_ORDER_M) - canceled ); } queue.orders[orderIndex].pending = afterPending; if (depth(self, tick) == 0) { // clear() won't revert so we can cancel with to=0 even if the depth() is already zero // works even if bitmap is empty self.tickBitmap.clear(tick); } } function claim(State storage self, Tick tick, uint40 index) external returns (uint64 claimedUnit) { Order storage order = _getOrder(self, tick, index); claimedUnit = calculateClaimableUnit(self, tick, index); unchecked { order.pending -= claimedUnit; } } function calculateClaimableUnit(State storage self, Tick tick, uint40 index) public view returns (uint64) { uint64 orderUnit = self.getOrder(tick, index).pending; Queue storage queue = self.queues[tick]; // @dev Book logic always considers replaced orders as claimable. unchecked { if (uint256(index) + MAX_ORDER < queue.orders.length) return orderUnit; uint64 totalClaimableUnit = self.totalClaimableOf.get(tick); uint64 rangeRight = _getClaimRangeRight(queue, index); if (rangeRight - orderUnit >= totalClaimableUnit) return 0; // -------- totalClaimable ---------|--- // ------|---- orderUnit ----|-------- // rangeLeft rangeRight if (rangeRight <= totalClaimableUnit) return orderUnit; // -- totalClaimable --|---------------- // ------|---- orderUnit ----|-------- // rangeLeft rangeRight else return totalClaimableUnit - (rangeRight - orderUnit); } } function _getClaimRangeRight(Queue storage queue, uint256 orderIndex) private view returns (uint64 rangeRight) { uint256 l = queue.orders.length & MAX_ORDER_M; uint256 r = (orderIndex + 1) & MAX_ORDER_M; rangeRight = (l < r) ? queue.tree.query(l, r) : queue.tree.total() - queue.tree.query(r, l); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.20; import {IBookManager} from "../interfaces/IBookManager.sol"; type BookId is uint192; library BookIdLibrary { function toId(IBookManager.BookKey memory bookKey) internal pure returns (BookId id) { bytes32 hash = keccak256(abi.encode(bookKey)); assembly { id := and(hash, 0xffffffffffffffffffffffffffffffffffffffffffffffff) } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.20; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; type Currency is address; /// @title CurrencyLibrary /// @dev This library allows for transferring and holding native tokens and ERC20 tokens library CurrencyLibrary { using CurrencyLibrary for Currency; /// @notice Thrown when a native transfer fails error NativeTransferFailed(); /// @notice Thrown when an ERC20 transfer fails error ERC20TransferFailed(); Currency public constant NATIVE = Currency.wrap(address(0)); function transfer(Currency currency, address to, uint256 amount) internal { // implementation from // https://github.com/transmissions11/solmate/blob/e8f96f25d48fe702117ce76c79228ca4f20206cb/src/utils/SafeTransferLib.sol bool success; if (currency.isNative()) { assembly { // Transfer the ETH and store if it succeeded or not. success := call(gas(), to, amount, 0, 0, 0, 0) } if (!success) revert NativeTransferFailed(); } else { assembly { // Get a pointer to some free memory. let freeMemoryPointer := mload(0x40) // Write the abi-encoded calldata into memory, beginning with the function selector. mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000) mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument. mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type. success := and( // Set success to whether the call reverted, if not we check it either // returned exactly 1 (can't just be non-zero data), or had no return data. or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())), // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2. // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space. // Counterintuitively, this call must be positioned second to the or() call in the // surrounding and() call or else returndatasize() will be zero during the computation. call(gas(), currency, 0, freeMemoryPointer, 68, 0, 32) ) } if (!success) revert ERC20TransferFailed(); } } function balanceOfSelf(Currency currency) internal view returns (uint256) { if (currency.isNative()) return address(this).balance; else return IERC20(Currency.unwrap(currency)).balanceOf(address(this)); } function equals(Currency currency, Currency other) internal pure returns (bool) { return Currency.unwrap(currency) == Currency.unwrap(other); } function isNative(Currency currency) internal pure returns (bool) { return Currency.unwrap(currency) == Currency.unwrap(NATIVE); } function toId(Currency currency) internal pure returns (uint256) { return uint160(Currency.unwrap(currency)); } function fromId(uint256 id) internal pure returns (Currency) { return Currency.wrap(address(uint160(id))); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; import {Currency, CurrencyLibrary} from "./Currency.sol"; library CurrencyDelta { // uint256(keccak256("CurrencyDelta")) + 1 uint256 internal constant CURRENCY_DELTA_SLOT = 0x95b400a0305233758f18c75aa62cbbb5d6882951dd55f1407390ee7b6924e26f; function get(address locker, Currency currency) internal view returns (int256 delta) { assembly { mstore(0x14, currency) mstore(0x00, locker) delta := tload(keccak256(0x0c, 0x28)) } } function add(address locker, Currency currency, int256 delta) internal returns (int256 result) { assembly { mstore(0x14, currency) mstore(0x00, locker) let slot := keccak256(0x0c, 0x28) result := add(tload(slot), delta) tstore(slot, result) } } }
// SPDX-License-Identifier: - // License: https://license.sonic.market/LICENSE.pdf pragma solidity ^0.8.0; library DirtyUint64 { error DirtyUint64Error(uint256 errorCode); uint256 private constant _OVERFLOW_ERROR = 0; uint256 private constant _UNDERFLOW_ERROR = 1; function toDirtyUnsafe(uint64 cleanUint) internal pure returns (uint64 dirtyUint) { assembly { dirtyUint := add(cleanUint, 1) } } function toDirty(uint64 cleanUint) internal pure returns (uint64 dirtyUint) { assembly { dirtyUint := add(cleanUint, 1) } if (dirtyUint == 0) { revert DirtyUint64Error(_OVERFLOW_ERROR); } } function toClean(uint64 dirtyUint) internal pure returns (uint64 cleanUint) { assembly { cleanUint := sub(dirtyUint, gt(dirtyUint, 0)) } } function addClean(uint64 current, uint64 cleanUint) internal pure returns (uint64) { assembly { current := add(add(current, iszero(current)), cleanUint) } if (current < cleanUint) { revert DirtyUint64Error(_OVERFLOW_ERROR); } return current; } function addDirty(uint64 current, uint64 dirtyUint) internal pure returns (uint64) { assembly { current := sub(add(add(current, iszero(current)), add(dirtyUint, iszero(dirtyUint))), 1) } if (current < dirtyUint) { revert DirtyUint64Error(_OVERFLOW_ERROR); } return current; } function subClean(uint64 current, uint64 cleanUint) internal pure returns (uint64 ret) { assembly { current := add(current, iszero(current)) ret := sub(current, cleanUint) } if (current < ret || ret == 0) { revert DirtyUint64Error(_UNDERFLOW_ERROR); } } function subDirty(uint64 current, uint64 dirtyUint) internal pure returns (uint64 ret) { assembly { current := add(current, iszero(current)) ret := sub(add(current, 1), add(dirtyUint, iszero(dirtyUint))) } if (current < ret || ret == 0) { revert DirtyUint64Error(_UNDERFLOW_ERROR); } } function sumPackedUnsafe(uint256 packed, uint256 from, uint256 to) internal pure returns (uint64 ret) { packed = packed >> (from << 6); unchecked { for (uint256 i = from; i < to; ++i) { assembly { let element := and(packed, 0xffffffffffffffff) ret := add(ret, add(element, iszero(element))) packed := shr(64, packed) } } } assembly { ret := sub(ret, sub(to, from)) } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/ERC721.sol) // Modified by Sonic Market Team pragma solidity ^0.8.20; import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; import {IERC721Metadata} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol"; import {Context} from "@openzeppelin/contracts/utils/Context.sol"; import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; import {IERC165, ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol"; import {IERC721Errors} from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol"; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors { using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; mapping(address owner => uint256) private _balances; mapping(uint256 tokenId => address) private _tokenApprovals; mapping(address owner => mapping(address operator => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual returns (uint256) { if (owner == address(0)) { revert ERC721InvalidOwner(address(0)); } return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual returns (address) { return _requireOwned(tokenId); } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual returns (string memory) { _requireOwned(tokenId); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overridden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual { _approve(to, tokenId, _msgSender()); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual returns (address) { _requireOwned(tokenId); return _getApproved(tokenId); } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom(address from, address to, uint256 tokenId) public virtual { if (to == address(0)) { revert ERC721InvalidReceiver(address(0)); } // Setting an "auth" arguments enables the `_isAuthorized` check which verifies that the token exists // (from != 0). Therefore, it is not needed to verify that the return value is not 0 here. address previousOwner = _update(to, tokenId, _msgSender()); if (previousOwner != from) { revert ERC721IncorrectOwner(from, tokenId, previousOwner); } } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId) public { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual { transferFrom(from, to, tokenId); _checkOnERC721Received(from, to, tokenId, data); } /** * @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist * * IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the * core ERC721 logic MUST be matched with the use of {_increaseBalance} to keep balances * consistent with ownership. The invariant to preserve is that for any address `a` the value returned by * `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`. */ function _ownerOf(uint256 tokenId) internal view virtual returns (address); /** * @dev Returns the approved address for `tokenId`. Returns 0 if `tokenId` is not minted. */ function _getApproved(uint256 tokenId) internal view virtual returns (address) { return _tokenApprovals[tokenId]; } /** * @dev Returns whether `spender` is allowed to manage `owner`'s tokens, or `tokenId` in * particular (ignoring whether it is owned by `owner`). * * WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this * assumption. */ function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) { return spender != address(0) && (owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender); } /** * @dev Checks if `spender` can operate on `tokenId`, assuming the provided `owner` is the actual owner. * Reverts if `spender` does not have approval from the provided `owner` for the given token or for all its assets * the `spender` for the specific `tokenId`. * * WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this * assumption. */ function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual { if (!_isAuthorized(owner, spender, tokenId)) { if (owner == address(0)) { revert ERC721NonexistentToken(tokenId); } else { revert ERC721InsufficientApproval(spender, tokenId); } } } /** * @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override. * * NOTE: the value is limited to type(uint128).max. This protect against _balance overflow. It is unrealistic that * a uint256 would ever overflow from increments when these increments are bounded to uint128 values. * * WARNING: Increasing an account's balance using this function tends to be paired with an override of the * {_ownerOf} function to resolve the ownership of the corresponding tokens so that balances and ownership * remain consistent with one another. */ function _increaseBalance(address account, uint128 value) internal virtual { unchecked { _balances[account] += value; } } /** * @dev Transfers `tokenId` from its current owner to `to`, or alternatively mints (or burns) if the current owner * (or `to`) is the zero address. Returns the owner of the `tokenId` before the update. * * The `auth` argument is optional. If the value passed is non 0, then this function will check that * `auth` is either the owner of the token, or approved to operate on the token (by the owner). * * Emits a {Transfer} event. * * NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}. */ function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) { address from = _ownerOf(tokenId); // Perform (optional) operator check if (auth != address(0)) { _checkAuthorized(from, auth, tokenId); } // Execute the update if (from != address(0)) { // Clear approval. No need to re-authorize or emit the Approval event _approve(address(0), tokenId, address(0), false); unchecked { _balances[from] -= 1; } } if (to != address(0)) { unchecked { _balances[to] += 1; } } // @dev MODIFIED: Define _setOwner _setOwner(tokenId, to); emit Transfer(from, to, tokenId); return from; } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal { if (to == address(0)) { revert ERC721InvalidReceiver(address(0)); } address previousOwner = _update(to, tokenId, address(0)); if (previousOwner != address(0)) { revert ERC721InvalidSender(address(0)); } } /** * @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual { _mint(to, tokenId); _checkOnERC721Received(address(0), to, tokenId, data); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * This is an internal function that does not check if the sender is authorized to operate on the token. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal { address previousOwner = _update(address(0), tokenId, address(0)); if (previousOwner == address(0)) { revert ERC721NonexistentToken(tokenId); } } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer(address from, address to, uint256 tokenId) internal { if (to == address(0)) { revert ERC721InvalidReceiver(address(0)); } address previousOwner = _update(to, tokenId, address(0)); if (previousOwner == address(0)) { revert ERC721NonexistentToken(tokenId); } else if (previousOwner != from) { revert ERC721IncorrectOwner(from, tokenId, previousOwner); } } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking that contract recipients * are aware of the ERC721 standard to prevent tokens from being forever locked. * * `data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is like {safeTransferFrom} in the sense that it invokes * {IERC721Receiver-onERC721Received} on the receiver, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `tokenId` token must exist and be owned by `from`. * - `to` cannot be the zero address. * - `from` cannot be the zero address. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId) internal { _safeTransfer(from, to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeTransfer-address-address-uint256-}[`_safeTransfer`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual { _transfer(from, to, tokenId); _checkOnERC721Received(from, to, tokenId, data); } /** * @dev Approve `to` to operate on `tokenId` * * The `auth` argument is optional. If the value passed is non 0, then this function will check that `auth` is * either the owner of the token, or approved to operate on all tokens held by this owner. * * Emits an {Approval} event. * * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument. */ function _approve(address to, uint256 tokenId, address auth) internal { _approve(to, tokenId, auth, true); } /** * @dev Variant of `_approve` with an optional flag to enable or disable the {Approval} event. The event is not * emitted in the context of transfers. */ function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual { // Avoid reading the owner unless necessary if (emitEvent || auth != address(0)) { address owner = _requireOwned(tokenId); // We do not use _isAuthorized because single-token approvals should not be able to call approve if (auth != address(0) && owner != auth && !isApprovedForAll(owner, auth)) { revert ERC721InvalidApprover(auth); } if (emitEvent) { emit Approval(owner, to, tokenId); } } _tokenApprovals[tokenId] = to; } /** * @dev Approve `operator` to operate on all of `owner` tokens * * Requirements: * - operator can't be the address zero. * * Emits an {ApprovalForAll} event. */ function _setApprovalForAll(address owner, address operator, bool approved) internal virtual { if (operator == address(0)) { revert ERC721InvalidOperator(operator); } _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Reverts if the `tokenId` doesn't have a current owner (it hasn't been minted, or it has been burned). * Returns the owner. * * Overrides to ownership logic should be done to {_ownerOf}. */ function _requireOwned(uint256 tokenId) internal view returns (address) { address owner = _ownerOf(tokenId); if (owner == address(0)) { revert ERC721NonexistentToken(tokenId); } return owner; } /** * @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target address. This will revert if the * recipient doesn't accept the token transfer. The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param data bytes optional data to send along with the call */ function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private { if (to.code.length > 0) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) { if (retval != IERC721Receiver.onERC721Received.selector) { revert ERC721InvalidReceiver(to); } } catch (bytes memory reason) { if (reason.length == 0) { revert ERC721InvalidReceiver(to); } else { /// @solidity memory-safe-assembly assembly { revert(add(32, reason), mload(reason)) } } } } } /** * @dev Override this function to set owner */ function _setOwner(uint256 tokenId, address owner) internal virtual; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol"; import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; import {ERC721} from "./ERC721.sol"; import {IERC721Permit} from "../interfaces/IERC721Permit.sol"; contract ERC721Permit is ERC721, IERC721Permit, EIP712 { // keccak256("Permit(address spender,uint256 tokenId,uint256 nonce,uint256 deadline)"); bytes32 public constant override PERMIT_TYPEHASH = 0x49ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9ad; uint256 private constant _NONCE_MASK = uint256(0xffffffffffffffffffffffff) << 160; // @dev tokenId => (nonce << 160 | owner) mapping(uint256 => uint256) private _nonceAndOwner; constructor(string memory name_, string memory symbol_, string memory version_) ERC721(name_, symbol_) EIP712(name_, version_) {} function permit(address spender, uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external override { if (block.timestamp > deadline) revert PermitExpired(); bytes32 digest = _hashTypedDataV4( keccak256(abi.encode(PERMIT_TYPEHASH, spender, tokenId, _getAndIncrementNonce(tokenId), deadline)) ); address owner = ownerOf(tokenId); if (spender == owner) revert InvalidSignature(); if (owner.code.length > 0) { if (IERC1271(owner).isValidSignature(digest, abi.encodePacked(r, s, v)) != 0x1626ba7e) { revert InvalidSignature(); } } else { if (ECDSA.recover(digest, v, r, s) != owner) revert InvalidSignature(); } _approve(spender, tokenId, owner, true); } function DOMAIN_SEPARATOR() public view override returns (bytes32) { return _domainSeparatorV4(); } function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, IERC165) returns (bool) { return interfaceId == type(IERC721Permit).interfaceId || super.supportsInterface(interfaceId); } function nonces(uint256 id) external view returns (uint256) { return _nonceAndOwner[id] >> 160; } function _getAndIncrementNonce(uint256 tokenId) internal returns (uint256 nonce) { uint256 nonceAndOwner = _nonceAndOwner[tokenId]; nonce = nonceAndOwner >> 160; _nonceAndOwner[tokenId] = nonceAndOwner + (1 << 160); } function _ownerOf(uint256 tokenId) internal view override returns (address) { return address(uint160(_nonceAndOwner[tokenId])); } function _setOwner(uint256 tokenId, address owner) internal override { _nonceAndOwner[tokenId] = (_nonceAndOwner[tokenId] & _NONCE_MASK) | uint256(uint160(owner)); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.20; import {Math} from "./Math.sol"; type FeePolicy is uint24; library FeePolicyLibrary { uint256 internal constant RATE_PRECISION = 10 ** 6; int256 internal constant MAX_FEE_RATE = 500000; int256 internal constant MIN_FEE_RATE = -500000; uint256 internal constant RATE_MASK = 0x7fffff; // 23 bits error InvalidFeePolicy(); function encode(bool usesQuote_, int24 rate_) internal pure returns (FeePolicy feePolicy) { if (rate_ > MAX_FEE_RATE || rate_ < MIN_FEE_RATE) { revert InvalidFeePolicy(); } uint256 mask = usesQuote_ ? 1 << 23 : 0; assembly { feePolicy := or(mask, add(and(rate_, 0xffffff), MAX_FEE_RATE)) } } function isValid(FeePolicy self) internal pure returns (bool) { int24 r = rate(self); return !(r > MAX_FEE_RATE || r < MIN_FEE_RATE); } function usesQuote(FeePolicy self) internal pure returns (bool f) { assembly { f := shr(23, self) } } function rate(FeePolicy self) internal pure returns (int24 r) { assembly { r := sub(and(self, RATE_MASK), MAX_FEE_RATE) } } function calculateFee(FeePolicy self, uint256 amount, bool reverseRounding) internal pure returns (int256 fee) { int24 r = rate(self); bool positive = r > 0; uint256 absRate; unchecked { absRate = uint256(uint24(positive ? r : -r)); } // @dev absFee must be less than type(int256).max uint256 absFee = Math.divide(amount * absRate, RATE_PRECISION, reverseRounding ? !positive : positive); fee = positive ? int256(absFee) : -int256(absFee); } function calculateOriginalAmount(FeePolicy self, uint256 amount, bool reverseFee) internal pure returns (uint256 originalAmount) { int24 r = rate(self); uint256 divider; assembly { if reverseFee { r := sub(0, r) } divider := add(RATE_PRECISION, r) } originalAmount = Math.divide(amount * RATE_PRECISION, divider, reverseFee); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import {Lockers} from "./Lockers.sol"; import {IBookManager} from "../interfaces/IBookManager.sol"; import {IHooks} from "../interfaces/IHooks.sol"; import {OrderId} from "../libraries/OrderId.sol"; /// @author Sonic Market /// @author Modified from Uniswap V4 (https://github.com/Uniswap/v4-core/blob/1f350fa95e862ba8c56c8ff7e146d47c9043465e) /// @notice V4 decides whether to invoke specific hooks by inspecting the leading bits of the address that /// the hooks contract is deployed to. /// For example, a hooks contract deployed to address: 0x9000000000000000000000000000000000000000 /// has leading bits '1001' which would cause the 'before open' and 'after make' hooks to be used. library Hooks { using Hooks for IHooks; uint256 internal constant BEFORE_OPEN_FLAG = 1 << 159; uint256 internal constant AFTER_OPEN_FLAG = 1 << 158; uint256 internal constant BEFORE_MAKE_FLAG = 1 << 157; uint256 internal constant AFTER_MAKE_FLAG = 1 << 156; uint256 internal constant BEFORE_TAKE_FLAG = 1 << 155; uint256 internal constant AFTER_TAKE_FLAG = 1 << 154; uint256 internal constant BEFORE_CANCEL_FLAG = 1 << 153; uint256 internal constant AFTER_CANCEL_FLAG = 1 << 152; uint256 internal constant BEFORE_CLAIM_FLAG = 1 << 151; uint256 internal constant AFTER_CLAIM_FLAG = 1 << 150; struct Permissions { bool beforeOpen; bool afterOpen; bool beforeMake; bool afterMake; bool beforeTake; bool afterTake; bool beforeCancel; bool afterCancel; bool beforeClaim; bool afterClaim; } /// @notice Thrown if the address will not lead to the specified hook calls being called /// @param hooks The address of the hooks contract error HookAddressNotValid(address hooks); /// @notice Hook did not return its selector error InvalidHookResponse(); /// @notice thrown when a hook call fails error FailedHookCall(); /// @notice Utility function intended to be used in hook constructors to ensure /// the deployed hooks address causes the intended hooks to be called /// @param permissions The hooks that are intended to be called /// @dev permissions param is memory as the function will be called from constructors function validateHookPermissions(IHooks self, Permissions memory permissions) internal pure { if ( permissions.beforeOpen != self.hasPermission(BEFORE_OPEN_FLAG) || permissions.afterOpen != self.hasPermission(AFTER_OPEN_FLAG) || permissions.beforeMake != self.hasPermission(BEFORE_MAKE_FLAG) || permissions.afterMake != self.hasPermission(AFTER_MAKE_FLAG) || permissions.beforeTake != self.hasPermission(BEFORE_TAKE_FLAG) || permissions.afterTake != self.hasPermission(AFTER_TAKE_FLAG) || permissions.beforeCancel != self.hasPermission(BEFORE_CANCEL_FLAG) || permissions.afterCancel != self.hasPermission(AFTER_CANCEL_FLAG) || permissions.beforeClaim != self.hasPermission(BEFORE_CLAIM_FLAG) || permissions.afterClaim != self.hasPermission(AFTER_CLAIM_FLAG) ) { revert HookAddressNotValid(address(self)); } } /// @notice Ensures that the hook address includes at least one hook flag or is the 0 address /// @param hook The hook to verify function isValidHookAddress(IHooks hook) internal pure returns (bool) { // If a hook contract is set, it must have at least 1 flag set return address(hook) == address(0) || uint160(address(hook)) >= AFTER_CLAIM_FLAG; } /// @notice performs a hook call using the given calldata on the given hook /// @return expectedSelector The selector that the hook is expected to return /// @return selector The selector that the hook actually returned function _callHook(IHooks self, bytes memory data) private returns (bytes4 expectedSelector, bytes4 selector) { bool set = Lockers.setCurrentHook(self); assembly { expectedSelector := mload(add(data, 0x20)) } (bool success, bytes memory result) = address(self).call(data); if (!success) _revert(result); selector = abi.decode(result, (bytes4)); // We only want to clear the current hook if it was set in setCurrentHook in this execution frame. if (set) Lockers.clearCurrentHook(); } /// @notice performs a hook call using the given calldata on the given hook function callHook(IHooks self, bytes memory data) internal { (bytes4 expectedSelector, bytes4 selector) = _callHook(self, data); if (selector != expectedSelector) revert InvalidHookResponse(); } /// @notice calls beforeOpen hook if permissioned and validates return value function beforeOpen(IHooks self, IBookManager.BookKey memory key, bytes calldata hookData) internal { if (self.hasPermission(BEFORE_OPEN_FLAG)) { self.callHook(abi.encodeWithSelector(IHooks.beforeOpen.selector, msg.sender, key, hookData)); } } /// @notice calls afterOpen hook if permissioned and validates return value function afterOpen(IHooks self, IBookManager.BookKey memory key, bytes calldata hookData) internal { if (self.hasPermission(AFTER_OPEN_FLAG)) { self.callHook(abi.encodeWithSelector(IHooks.afterOpen.selector, msg.sender, key, hookData)); } } /// @notice calls beforeMake hook if permissioned and validates return value function beforeMake(IHooks self, IBookManager.MakeParams memory params, bytes calldata hookData) internal { if (self.hasPermission(BEFORE_MAKE_FLAG)) { self.callHook(abi.encodeWithSelector(IHooks.beforeMake.selector, msg.sender, params, hookData)); } } /// @notice calls afterMake hook if permissioned and validates return value function afterMake(IHooks self, IBookManager.MakeParams memory params, OrderId orderId, bytes calldata hookData) internal { if (self.hasPermission(AFTER_MAKE_FLAG)) { self.callHook(abi.encodeWithSelector(IHooks.afterMake.selector, msg.sender, params, orderId, hookData)); } } /// @notice calls beforeTake hook if permissioned and validates return value function beforeTake(IHooks self, IBookManager.TakeParams memory params, bytes calldata hookData) internal { if (self.hasPermission(BEFORE_TAKE_FLAG)) { self.callHook(abi.encodeWithSelector(IHooks.beforeTake.selector, msg.sender, params, hookData)); } } /// @notice calls afterTake hook if permissioned and validates return value function afterTake(IHooks self, IBookManager.TakeParams memory params, uint64 takenAmount, bytes calldata hookData) internal { if (self.hasPermission(AFTER_TAKE_FLAG)) { self.callHook(abi.encodeWithSelector(IHooks.afterTake.selector, msg.sender, params, takenAmount, hookData)); } } /// @notice calls beforeCancel hook if permissioned and validates return value function beforeCancel(IHooks self, IBookManager.CancelParams calldata params, bytes calldata hookData) internal { if (self.hasPermission(BEFORE_CANCEL_FLAG)) { self.callHook(abi.encodeWithSelector(IHooks.beforeCancel.selector, msg.sender, params, hookData)); } } /// @notice calls afterCancel hook if permissioned and validates return value function afterCancel( IHooks self, IBookManager.CancelParams calldata params, uint64 canceledAmount, bytes calldata hookData ) internal { if (self.hasPermission(AFTER_CANCEL_FLAG)) { self.callHook( abi.encodeWithSelector(IHooks.afterCancel.selector, msg.sender, params, canceledAmount, hookData) ); } } /// @notice calls beforeClaim hook if permissioned and validates return value function beforeClaim(IHooks self, OrderId orderId, bytes calldata hookData) internal { if (self.hasPermission(BEFORE_CLAIM_FLAG)) { self.callHook(abi.encodeWithSelector(IHooks.beforeClaim.selector, msg.sender, orderId, hookData)); } } /// @notice calls afterClaim hook if permissioned and validates return value function afterClaim(IHooks self, OrderId orderId, uint64 claimedAmount, bytes calldata hookData) internal { if (self.hasPermission(AFTER_CLAIM_FLAG)) { self.callHook( abi.encodeWithSelector(IHooks.afterClaim.selector, msg.sender, orderId, claimedAmount, hookData) ); } } function hasPermission(IHooks self, uint256 flag) internal pure returns (bool) { return uint256(uint160(address(self))) & flag != 0; } /// @notice bubble up revert if present. Else throw FailedHookCall function _revert(bytes memory result) private pure { if (result.length == 0) revert FailedHookCall(); assembly { revert(add(0x20, result), mload(result)) } } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.23; import {IHooks} from "../interfaces/IHooks.sol"; /// @author Sonic Market /// @author Modified from Uniswap V4 (https://github.com/Uniswap/v4-core/tree/98680ebc1a654120e995d53a5b10ec6fe153066f) /// @notice Contains data about pool lockers. /// @dev This library manages a custom storage implementation for a queue /// that tracks current lockers. The "sentinel" storage slot for this data structure, /// always passed in as IPoolManager.LockData storage self, stores not just the current /// length of the queue but also the global count of non-zero deltas across all lockers. /// The values of the data structure start at OFFSET, and each value is a locker address. library Lockers { /// struct LockData { /// /// @notice The current number of active lockers /// uint128 length; /// /// @notice The total number of nonzero deltas over all active + completed lockers /// uint128 nonzeroDeltaCount; /// } // uint256(keccak256("LockData")) + 1 uint256 internal constant LOCK_DATA_SLOT = 0x760a9a962ae3d184e99c0483cf5684fb3170f47116ca4f445c50209da4f4f907; // uint256(keccak256("Lockers")) + 1 uint256 internal constant LOCKERS_SLOT = 0x722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b1; // The number of slots per item in the lockers array uint256 internal constant LOCKER_STRUCT_SIZE = 2; // uint256(keccak256("HookAddress")) + 1 uint256 internal constant HOOK_ADDRESS_SLOT = 0xfcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be422; uint256 internal constant NONZERO_DELTA_COUNT_OFFSET = 2 ** 128; uint256 internal constant LENGTH_MASK = (1 << 128) - 1; /// @dev Pushes a locker onto the end of the queue, and updates the sentinel storage slot. function push(address locker, address lockCaller) internal { assembly { let data := tload(LOCK_DATA_SLOT) let l := and(data, LENGTH_MASK) // LOCKERS_SLOT + l * LOCKER_STRUCT_SIZE let indexToWrite := add(LOCKERS_SLOT, mul(l, LOCKER_STRUCT_SIZE)) // in the next storage slot, write the locker and lockCaller tstore(indexToWrite, locker) tstore(add(indexToWrite, 1), lockCaller) // increase the length tstore(LOCK_DATA_SLOT, add(data, 1)) } } function lockData() internal view returns (uint128 l, uint128 nonzeroDeltaCount) { assembly { let data := tload(LOCK_DATA_SLOT) l := and(data, LENGTH_MASK) nonzeroDeltaCount := shr(128, data) } } function length() internal view returns (uint128 l) { assembly { l := and(tload(LOCK_DATA_SLOT), LENGTH_MASK) } } /// @dev Pops a locker off the end of the queue. Note that no storage gets cleared. function pop() internal { assembly { let data := tload(LOCK_DATA_SLOT) let l := and(data, LENGTH_MASK) if iszero(l) { mstore(0x00, 0xf1c77ed0) // LockersPopFailed() revert(0x1c, 0x04) } // LOCKERS_SLOT + (l - 1) * LOCKER_STRUCT_SIZE let indexToWrite := add(LOCKERS_SLOT, mul(sub(l, 1), LOCKER_STRUCT_SIZE)) // in the next storage slot, delete the locker and lockCaller tstore(indexToWrite, 0) tstore(add(indexToWrite, 1), 0) // decrease the length tstore(LOCK_DATA_SLOT, sub(data, 1)) } } function getLocker(uint256 i) internal view returns (address locker) { assembly { // LOCKERS_SLOT + (i * LOCKER_STRUCT_SIZE) locker := tload(add(LOCKERS_SLOT, mul(i, LOCKER_STRUCT_SIZE))) } } function getLockCaller(uint256 i) internal view returns (address locker) { assembly { // LOCKERS_SLOT + (i * LOCKER_STRUCT_SIZE + 1) locker := tload(add(LOCKERS_SLOT, add(mul(i, LOCKER_STRUCT_SIZE), 1))) } } function getCurrentLocker() internal view returns (address) { unchecked { uint256 l = length(); return l > 0 ? getLocker(l - 1) : address(0); } } function getCurrentLockCaller() internal view returns (address) { unchecked { uint256 l = length(); return l > 0 ? getLockCaller(l - 1) : address(0); } } function incrementNonzeroDeltaCount() internal { assembly { tstore(LOCK_DATA_SLOT, add(tload(LOCK_DATA_SLOT), NONZERO_DELTA_COUNT_OFFSET)) } } function decrementNonzeroDeltaCount() internal { assembly { tstore(LOCK_DATA_SLOT, sub(tload(LOCK_DATA_SLOT), NONZERO_DELTA_COUNT_OFFSET)) } } function getCurrentHook() internal view returns (IHooks currentHook) { return IHooks(getHook(length())); } function getHook(uint256 i) internal view returns (address hook) { assembly { hook := tload(add(HOOK_ADDRESS_SLOT, i)) } } function setCurrentHook(IHooks currentHook) internal returns (bool set) { // Set the hook address for the current locker if the address is 0. // If the address is nonzero, a hook has already been set for this lock, and is not allowed to be updated or cleared at the end of the call. if (address(getCurrentHook()) == address(0)) { uint256 l = length(); assembly { tstore(add(HOOK_ADDRESS_SLOT, l), currentHook) } return true; } } function clearCurrentHook() internal { uint256 l = length(); assembly { tstore(add(HOOK_ADDRESS_SLOT, l), 0) } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; library Math { function divide(uint256 a, uint256 b, bool roundingUp) internal pure returns (uint256 ret) { // In the OrderBook contract code, b is never zero. assembly { ret := add(div(a, b), and(gt(mod(a, b), 0), roundingUp)) } } /// @dev Returns `ln(x)`, denominated in `WAD`. /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln function lnWad(int256 x) internal pure returns (int256 r) { /// @solidity memory-safe-assembly assembly { // We want to convert `x` from `10**18` fixed point to `2**96` fixed point. // We do this by multiplying by `2**96 / 10**18`. But since // `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here // and add `ln(2**96 / 10**18)` at the end. // Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`. r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) // We place the check here for more optimal stack operations. if iszero(sgt(x, 0)) { mstore(0x00, 0x1615e638) // `LnWadUndefined()`. revert(0x1c, 0x04) } // forgefmt: disable-next-item r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)), 0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff)) // Reduce range of x to (1, 2) * 2**96 // ln(2^k * x) = k * ln(2) + ln(x) x := shr(159, shl(r, x)) // Evaluate using a (8, 8)-term rational approximation. // `p` is made monic, we will multiply by a scale factor later. // forgefmt: disable-next-item let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir. sar(96, mul(add(43456485725739037958740375743393, sar(96, mul(add(24828157081833163892658089445524, sar(96, mul(add(3273285459638523848632254066296, x), x))), x))), x)), 11111509109440967052023855526967) p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857) p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526) p := sub(mul(p, x), shl(96, 795164235651350426258249787498)) // We leave `p` in `2**192` basis so we don't need to scale it back up for the division. // `q` is monic by convention. let q := add(5573035233440673466300451813936, x) q := add(71694874799317883764090561454958, sar(96, mul(x, q))) q := add(283447036172924575727196451306956, sar(96, mul(x, q))) q := add(401686690394027663651624208769553, sar(96, mul(x, q))) q := add(204048457590392012362485061816622, sar(96, mul(x, q))) q := add(31853899698501571402653359427138, sar(96, mul(x, q))) q := add(909429971244387300277376558375, sar(96, mul(x, q))) // `p / q` is in the range `(0, 0.125) * 2**96`. // Finalization, we need to: // - Multiply by the scale factor `s = 5.549…`. // - Add `ln(2**96 / 10**18)`. // - Add `k * ln(2)`. // - Multiply by `10**18 / 2**96 = 5**18 >> 78`. // The q polynomial is known not to have zeros in the domain. // No scaling required because p is already `2**96` too large. p := sdiv(p, q) // Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`. p := mul(1677202110996718588342820967067443963516166, p) // Add `ln(2) * k * 5**18 * 2**192`. // forgefmt: disable-next-item p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p) // Base conversion: mul `2**96 / (5**18 * 2**192)`. r := sdiv(p, 302231454903657293676544000000000000000000) } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; import {Tick} from "./Tick.sol"; import {BookId} from "./BookId.sol"; type OrderId is uint256; library OrderIdLibrary { /** * @dev Encode the order id. * @param bookId The book id. * @param tick The tick. * @param index The index. * @return id The order id. */ function encode(BookId bookId, Tick tick, uint40 index) internal pure returns (OrderId id) { // @dev If we just use tick at the assembly code, the code will convert tick into bytes32. // e.g. When index == -2, the shifted value( shl(40, tick) ) will be // 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0000000000 instead of 0xfffffffe0000000000 // Therefore, we have to safely cast tick into uint256 first. uint256 _tick = uint256(uint24(Tick.unwrap(tick))); assembly { id := add(index, add(shl(40, _tick), shl(64, bookId))) } } function decode(OrderId id) internal pure returns (BookId bookId, Tick tick, uint40 index) { assembly { bookId := shr(64, id) tick := and(shr(40, id), 0xffffff) index := and(id, 0xffffffffff) } } function getBookId(OrderId id) internal pure returns (BookId bookId) { assembly { bookId := shr(64, id) } } function getTick(OrderId id) internal pure returns (Tick tick) { assembly { tick := and(shr(40, id), 0xffffff) } } function getIndex(OrderId id) internal pure returns (uint40 index) { assembly { index := and(id, 0xffffffffff) } } }
// SPDX-License-Identifier: - // License: https://license.sonic.market/LICENSE.pdf pragma solidity ^0.8.0; library PackedUint256 { error PackedUint256Error(uint256 errorCode); uint256 private constant _UINT8_INDEX_ERROR = 0; uint256 private constant _UINT16_INDEX_ERROR = 1; uint256 private constant _UINT32_INDEX_ERROR = 2; uint256 private constant _UINT64_INDEX_ERROR = 3; uint256 private constant _MAX_UINT64 = type(uint64).max; uint256 private constant _MAX_UINT32 = type(uint32).max; uint256 private constant _MAX_UINT16 = type(uint16).max; uint256 private constant _MAX_UINT8 = type(uint8).max; function get8Unsafe(uint256 packed, uint256 index) internal pure returns (uint8 ret) { assembly { ret := and(shr(shl(3, index), packed), 0xff) } } function get8(uint256 packed, uint256 index) internal pure returns (uint8 ret) { if (index > 31) { revert PackedUint256Error(_UINT8_INDEX_ERROR); } assembly { ret := and(shr(shl(3, index), packed), 0xff) } } function get16Unsafe(uint256 packed, uint256 index) internal pure returns (uint16 ret) { assembly { ret := and(shr(shl(4, index), packed), 0xffff) } } function get16(uint256 packed, uint256 index) internal pure returns (uint16 ret) { if (index > 15) { revert PackedUint256Error(_UINT16_INDEX_ERROR); } assembly { ret := and(shr(shl(4, index), packed), 0xffff) } } function get32Unsafe(uint256 packed, uint256 index) internal pure returns (uint32 ret) { assembly { ret := and(shr(shl(5, index), packed), 0xffffffff) } } function get32(uint256 packed, uint256 index) internal pure returns (uint32 ret) { if (index > 7) { revert PackedUint256Error(_UINT32_INDEX_ERROR); } assembly { ret := and(shr(shl(5, index), packed), 0xffffffff) } } function get64Unsafe(uint256 packed, uint256 index) internal pure returns (uint64 ret) { assembly { ret := and(shr(shl(6, index), packed), 0xffffffffffffffff) } } function get64(uint256 packed, uint256 index) internal pure returns (uint64 ret) { if (index > 3) { revert PackedUint256Error(_UINT64_INDEX_ERROR); } assembly { ret := and(shr(shl(6, index), packed), 0xffffffffffffffff) } } function add8Unsafe(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) { assembly { ret := add(packed, shl(shl(3, index), and(value, 0xff))) } } function add8(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) { if (index > 31) { revert PackedUint256Error(_UINT8_INDEX_ERROR); } uint8 current = get8Unsafe(packed, index); current += value; ret = update8Unsafe(packed, index, current); } function add16Unsafe(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) { assembly { ret := add(packed, shl(shl(4, index), and(value, 0xffff))) } } function add16(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) { if (index > 15) { revert PackedUint256Error(_UINT16_INDEX_ERROR); } uint16 current = get16Unsafe(packed, index); current += value; ret = update16Unsafe(packed, index, current); } function add32Unsafe(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) { assembly { ret := add(packed, shl(shl(5, index), and(value, 0xffffffff))) } } function add32(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) { if (index > 7) { revert PackedUint256Error(_UINT32_INDEX_ERROR); } uint32 current = get32Unsafe(packed, index); current += value; ret = update32Unsafe(packed, index, current); } function add64Unsafe(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) { assembly { ret := add(packed, shl(shl(6, index), and(value, 0xffffffffffffffff))) } } function add64(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) { if (index > 3) { revert PackedUint256Error(_UINT64_INDEX_ERROR); } uint64 current = get64Unsafe(packed, index); current += value; ret = update64Unsafe(packed, index, current); } function sub8Unsafe(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) { assembly { ret := sub(packed, shl(shl(3, index), and(value, 0xff))) } } function sub8(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) { if (index > 31) { revert PackedUint256Error(_UINT8_INDEX_ERROR); } uint8 current = get8Unsafe(packed, index); current -= value; ret = update8Unsafe(packed, index, current); } function sub16Unsafe(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) { assembly { ret := sub(packed, shl(shl(4, index), and(value, 0xffff))) } } function sub16(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) { if (index > 15) { revert PackedUint256Error(_UINT16_INDEX_ERROR); } uint16 current = get16Unsafe(packed, index); current -= value; ret = update16Unsafe(packed, index, current); } function sub32Unsafe(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) { assembly { ret := sub(packed, shl(shl(5, index), and(value, 0xffffffff))) } } function sub32(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) { if (index > 7) { revert PackedUint256Error(_UINT32_INDEX_ERROR); } uint32 current = get32Unsafe(packed, index); current -= value; ret = update32Unsafe(packed, index, current); } function sub64Unsafe(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) { assembly { ret := sub(packed, shl(shl(6, index), and(value, 0xffffffffffffffff))) } } function sub64(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) { if (index > 3) { revert PackedUint256Error(_UINT64_INDEX_ERROR); } uint64 current = get64Unsafe(packed, index); current -= value; ret = update64Unsafe(packed, index, current); } function update8Unsafe(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) { unchecked { index = index << 3; packed = packed - (packed & (_MAX_UINT8 << index)); } assembly { ret := add(packed, shl(index, and(value, 0xff))) } } function update8(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) { if (index > 31) { revert PackedUint256Error(_UINT8_INDEX_ERROR); } unchecked { index = index << 3; packed = packed - (packed & (_MAX_UINT8 << index)); } assembly { ret := add(packed, shl(index, and(value, 0xff))) } } function update16Unsafe(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) { unchecked { index = index << 4; packed = packed - (packed & (_MAX_UINT16 << index)); } assembly { ret := add(packed, shl(index, and(value, 0xffff))) } } function update16(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) { if (index > 15) { revert PackedUint256Error(_UINT16_INDEX_ERROR); } unchecked { index = index << 4; packed = packed - (packed & (_MAX_UINT16 << index)); } assembly { ret := add(packed, shl(index, and(value, 0xffff))) } } function update32Unsafe(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) { unchecked { index = index << 5; packed = packed - (packed & (_MAX_UINT32 << index)); } assembly { ret := add(packed, shl(index, and(value, 0xffffffff))) } } function update32(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) { if (index > 7) { revert PackedUint256Error(_UINT32_INDEX_ERROR); } unchecked { index = index << 5; packed = packed - (packed & (_MAX_UINT32 << index)); } assembly { ret := add(packed, shl(index, and(value, 0xffffffff))) } } function update64Unsafe(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) { unchecked { index = index << 6; packed = packed - (packed & (_MAX_UINT64 << index)); } assembly { ret := add(packed, shl(index, and(value, 0xffffffffffffffff))) } } function update64(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) { if (index > 3) { revert PackedUint256Error(_UINT64_INDEX_ERROR); } unchecked { index = index << 6; packed = packed - (packed & (_MAX_UINT64 << index)); } assembly { ret := add(packed, shl(index, and(value, 0xffffffffffffffff))) } } function total32(uint256 packed) internal pure returns (uint256) { unchecked { uint256 ret = _MAX_UINT32 & packed; for (uint256 i = 0; i < 7; ++i) { packed = packed >> 32; ret += _MAX_UINT32 & packed; } return ret; } } function total64(uint256 packed) internal pure returns (uint256) { unchecked { uint256 ret = _MAX_UINT64 & packed; for (uint256 i = 0; i < 3; ++i) { packed = packed >> 64; ret += _MAX_UINT64 & packed; } return ret; } } function sum32(uint256 packed, uint256 from, uint256 to) internal pure returns (uint256) { unchecked { packed = packed >> (from << 5); uint256 ret = 0; for (uint256 i = from; i < to; ++i) { ret += _MAX_UINT32 & packed; packed = packed >> 32; } return ret; } } function sum64(uint256 packed, uint256 from, uint256 to) internal pure returns (uint256) { unchecked { packed = packed >> (from << 6); uint256 ret = 0; for (uint256 i = from; i < to; ++i) { ret += _MAX_UINT64 & packed; packed = packed >> 64; } return ret; } } }
// SPDX-License-Identifier: - // License: https://license.sonic.market/LICENSE.pdf pragma solidity ^0.8.0; import "./PackedUint256.sol"; import "./DirtyUint64.sol"; /** * 🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲 * * Segmented Segment Tree * by Sonic Market * * ____________/\\\_______________/\\\\\____________/\\\____ * __________/\\\\\___________/\\\\////___________/\\\\\____ * ________/\\\/\\\________/\\\///______________/\\\/\\\____ * ______/\\\/\/\\\______/\\\\\\\\\\\_________/\\\/\/\\\____ * ____/\\\/__\/\\\_____/\\\\///////\\\_____/\\\/__\/\\\____ * __/\\\\\\\\\\\\\\\\_\/\\\______\//\\\__/\\\\\\\\\\\\\\\\_ * _\///////////\\\//__\//\\\______/\\\__\///////////\\\//__ * ___________\/\\\_____\///\\\\\\\\\/_____________\/\\\____ * ___________\///________\/////////_______________\///_____ * * 4 Layers of 64-bit nodes, hence 464 * * 🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲 */ library SegmentedSegmentTree { using PackedUint256 for uint256; using DirtyUint64 for uint64; error SegmentedSegmentTreeError(uint256 errorCode); uint256 private constant _INDEX_ERROR = 0; uint256 private constant _OVERFLOW_ERROR = 1; // uint8 private constant _R = 2; // There are `2` root node groups // uint8 private constant _C = 4; // There are `4` children (each child is a node group of its own) for each node uint8 private constant _L = 4; // There are `4` layers of node groups uint256 private constant _P = 4; // uint256 / uint64 = `4` uint256 private constant _P_M = 3; // % 4 = & `3` uint256 private constant _P_P = 2; // 2 ** `2` = 4 uint256 private constant _N_P = 4; // C * P = 2 ** `4` uint256 private constant _MAX_NODES = 2 ** 15; // (R * P) * ((C * P) ** (L - 1)) = `32768` uint256 private constant _MAX_NODES_P_MINUS_ONE = 14; // MAX_NODES / R = 2 ** `14` struct Core { mapping(uint256 => uint256)[_L] layers; } struct LayerIndex { uint256 group; uint256 node; } function get(Core storage core, uint256 index) internal view returns (uint64 ret) { if (index >= _MAX_NODES) { revert SegmentedSegmentTreeError(_INDEX_ERROR); } unchecked { ret = core.layers[_L - 1][index >> _P_P].get64(index & _P_M).toClean(); } } function total(Core storage core) internal view returns (uint64) { return DirtyUint64.sumPackedUnsafe(core.layers[0][0], 0, _P) + DirtyUint64.sumPackedUnsafe(core.layers[0][1], 0, _P); } function query(Core storage core, uint256 left, uint256 right) internal view returns (uint64 sum) { if (left == right) { return 0; } // right should be greater than left if (left >= right) { revert SegmentedSegmentTreeError(_INDEX_ERROR); } if (right > _MAX_NODES) { revert SegmentedSegmentTreeError(_INDEX_ERROR); } LayerIndex[] memory leftIndices = _getLayerIndices(left); LayerIndex[] memory rightIndices = _getLayerIndices(right); uint256 ret; uint256 deficit; unchecked { uint256 leftNodeIndex; uint256 rightNodeIndex; for (uint256 l = _L - 1;; --l) { LayerIndex memory leftIndex = leftIndices[l]; LayerIndex memory rightIndex = rightIndices[l]; leftNodeIndex += leftIndex.node; rightNodeIndex += rightIndex.node; if (rightIndex.group == leftIndex.group) { ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, rightNodeIndex); break; } if (rightIndex.group - leftIndex.group < 4) { ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, _P); ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], 0, rightNodeIndex); for (uint256 group = leftIndex.group + 1; group < rightIndex.group; group++) { ret += DirtyUint64.sumPackedUnsafe(core.layers[l][group], 0, _P); } break; } if (leftIndex.group % 4 == 0) { deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], 0, leftNodeIndex); leftNodeIndex = 0; } else if (leftIndex.group % 4 == 1) { deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group - 1], 0, _P); deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], 0, leftNodeIndex); leftNodeIndex = 0; } else if (leftIndex.group % 4 == 2) { ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, _P); ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group + 1], 0, _P); leftNodeIndex = 1; } else { ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, _P); leftNodeIndex = 1; } if (rightIndex.group % 4 == 0) { ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], 0, rightNodeIndex); rightNodeIndex = 0; } else if (rightIndex.group % 4 == 1) { ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group - 1], 0, _P); ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], 0, rightNodeIndex); rightNodeIndex = 0; } else if (rightIndex.group % 4 == 2) { deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], rightNodeIndex, _P); deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group + 1], 0, _P); rightNodeIndex = 1; } else { deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], rightNodeIndex, _P); rightNodeIndex = 1; } } ret -= deficit; } sum = uint64(ret); } function update(Core storage core, uint256 index, uint64 value) internal returns (uint64 replaced) { if (index >= _MAX_NODES) { revert SegmentedSegmentTreeError(_INDEX_ERROR); } LayerIndex[] memory indices = _getLayerIndices(index); unchecked { LayerIndex memory bottomIndex = indices[_L - 1]; replaced = core.layers[_L - 1][bottomIndex.group].get64Unsafe(bottomIndex.node).toClean(); if (replaced >= value) { uint64 diff = replaced - value; for (uint256 l = 0; l < _L; ++l) { LayerIndex memory layerIndex = indices[l]; uint256 node = core.layers[l][layerIndex.group]; core.layers[l][layerIndex.group] = node.update64(layerIndex.node, node.get64(layerIndex.node).subClean(diff)); } } else { uint64 diff = value - replaced; if (total(core) > type(uint64).max - diff) revert SegmentedSegmentTreeError(_OVERFLOW_ERROR); for (uint256 l = 0; l < _L; ++l) { LayerIndex memory layerIndex = indices[l]; uint256 node = core.layers[l][layerIndex.group]; core.layers[l][layerIndex.group] = node.update64(layerIndex.node, node.get64(layerIndex.node).addClean(diff)); } } } } function _getLayerIndices(uint256 index) private pure returns (LayerIndex[] memory) { unchecked { LayerIndex[] memory indices = new LayerIndex[](_L); uint256 shifter = _MAX_NODES_P_MINUS_ONE; for (uint256 l = 0; l < _L; ++l) { indices[l] = LayerIndex({group: index >> shifter, node: (index >> (shifter - _P_P)) & _P_M}); shifter = shifter - _N_P; } return indices; } } } /* * Segmented Segment Tree is a Segment Tree * that has been compressed so that `C` nodes * are compressed into a single uint256. * * Each node in a non-leaf node group is the sum of the * total sum of each child node group that it represents. * Each non-leaf node represents `E` node groups. * * A node group consists of `S` uint256. * * By expressing the index in `N` notation, * we can find the index in each respective layer * * S: Size of each node group * C: Compression Coefficient * E: Expansion Coefficient * L: Number of Layers * N: Notation, S * C * E * * `E` will not be considered for this version of the implementation. (E = 2) */
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; library SignificantBit { // http://supertech.csail.mit.edu/papers/debruijn.pdf uint256 internal constant DEBRUIJN_SEQ = 0x818283848586878898A8B8C8D8E8F929395969799A9B9D9E9FAAEB6BEDEEFF; bytes internal constant DEBRUIJN_INDEX = hex"0001020903110a19042112290b311a3905412245134d2a550c5d32651b6d3a7506264262237d468514804e8d2b95569d0d495ea533a966b11c886eb93bc176c9071727374353637324837e9b47af86c7155181ad4fd18ed32c9096db57d59ee30e2e4a6a5f92a6be3498aae067ddb2eb1d5989b56fd7baf33ca0c2ee77e5caf7ff0810182028303840444c545c646c7425617c847f8c949c48a4a8b087b8c0c816365272829aaec650acd0d28fdad4e22d6991bd97dfdcea58b4d6f29fede4f6fe0f1f2f3f4b5b6b607b8b93a3a7b7bf357199c5abcfd9e168bcdee9b3f1ecf5fd1e3e5a7a8aa2b670c4ced8bbe8f0f4fc3d79a1c3cde7effb78cce6facbf9f8"; /** * @notice Finds the index of the least significant bit. * @param x The value to compute the least significant bit for. Must be a non-zero value. * @return ret The index of the least significant bit. */ function leastSignificantBit(uint256 x) internal pure returns (uint8) { require(x > 0); uint256 index; assembly { index := shr(248, mul(and(x, add(not(x), 1)), DEBRUIJN_SEQ)) } return uint8(DEBRUIJN_INDEX[index]); // can optimize with CODECOPY opcode } function mostSignificantBit(uint256 x) internal pure returns (uint8 msb) { require(x > 0); assembly { let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) msb := or(msb, f) x := shr(f, x) f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF)) msb := or(msb, f) x := shr(f, x) f := shl(5, gt(x, 0xFFFFFFFF)) msb := or(msb, f) x := shr(f, x) f := shl(4, gt(x, 0xFFFF)) msb := or(msb, f) x := shr(f, x) f := shl(3, gt(x, 0xFF)) msb := or(msb, f) x := shr(f, x) f := shl(2, gt(x, 0xF)) msb := or(msb, f) x := shr(f, x) f := shl(1, gt(x, 0x3)) msb := or(msb, f) x := shr(f, x) f := gt(x, 0x1) msb := or(msb, f) } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.20; import {Math} from "./Math.sol"; type Tick is int24; library TickLibrary { using Math for *; using TickLibrary for Tick; error InvalidTick(); error InvalidPrice(); error TickOverflow(); int24 internal constant MAX_TICK = 2 ** 19 - 1; int24 internal constant MIN_TICK = -MAX_TICK; uint256 internal constant MIN_PRICE = 1350587; uint256 internal constant MAX_PRICE = 4647684107270898330752324302845848816923571339324334; uint256 private constant _R0 = 0xfff97272373d413259a46990; uint256 private constant _R1 = 0xfff2e50f5f656932ef12357c; uint256 private constant _R2 = 0xffe5caca7e10e4e61c3624ea; uint256 private constant _R3 = 0xffcb9843d60f6159c9db5883; uint256 private constant _R4 = 0xff973b41fa98c081472e6896; uint256 private constant _R5 = 0xff2ea16466c96a3843ec78b3; uint256 private constant _R6 = 0xfe5dee046a99a2a811c461f1; uint256 private constant _R7 = 0xfcbe86c7900a88aedcffc83b; uint256 private constant _R8 = 0xf987a7253ac413176f2b074c; uint256 private constant _R9 = 0xf3392b0822b70005940c7a39; uint256 private constant _R10 = 0xe7159475a2c29b7443b29c7f; uint256 private constant _R11 = 0xd097f3bdfd2022b8845ad8f7; uint256 private constant _R12 = 0xa9f746462d870fdf8a65dc1f; uint256 private constant _R13 = 0x70d869a156d2a1b890bb3df6; uint256 private constant _R14 = 0x31be135f97d08fd981231505; uint256 private constant _R15 = 0x9aa508b5b7a84e1c677de54; uint256 private constant _R16 = 0x5d6af8dedb81196699c329; uint256 private constant _R17 = 0x2216e584f5fa1ea92604; uint256 private constant _R18 = 0x48a170391f7dc42; uint256 private constant _R19 = 0x149b34; function validateTick(Tick tick) internal pure { if (Tick.unwrap(tick) > MAX_TICK || Tick.unwrap(tick) < MIN_TICK) revert InvalidTick(); } modifier validatePrice(uint256 price) { if (price > MAX_PRICE || price < MIN_PRICE) revert InvalidPrice(); _; } function fromPrice(uint256 price) internal pure validatePrice(price) returns (Tick) { unchecked { int24 tick = int24((int256(price).lnWad() * 42951820407860) / 2 ** 128); if (toPrice(Tick.wrap(tick)) > price) return Tick.wrap(tick - 1); return Tick.wrap(tick); } } function toPrice(Tick tick) internal pure returns (uint256 price) { validateTick(tick); int24 tickValue = Tick.unwrap(tick); uint256 absTick = uint24(tickValue < 0 ? -tickValue : tickValue); unchecked { if (absTick & 0x1 != 0) price = _R0; else price = 1 << 96; if (absTick & 0x2 != 0) price = (price * _R1) >> 96; if (absTick & 0x4 != 0) price = (price * _R2) >> 96; if (absTick & 0x8 != 0) price = (price * _R3) >> 96; if (absTick & 0x10 != 0) price = (price * _R4) >> 96; if (absTick & 0x20 != 0) price = (price * _R5) >> 96; if (absTick & 0x40 != 0) price = (price * _R6) >> 96; if (absTick & 0x80 != 0) price = (price * _R7) >> 96; if (absTick & 0x100 != 0) price = (price * _R8) >> 96; if (absTick & 0x200 != 0) price = (price * _R9) >> 96; if (absTick & 0x400 != 0) price = (price * _R10) >> 96; if (absTick & 0x800 != 0) price = (price * _R11) >> 96; if (absTick & 0x1000 != 0) price = (price * _R12) >> 96; if (absTick & 0x2000 != 0) price = (price * _R13) >> 96; if (absTick & 0x4000 != 0) price = (price * _R14) >> 96; if (absTick & 0x8000 != 0) price = (price * _R15) >> 96; if (absTick & 0x10000 != 0) price = (price * _R16) >> 96; if (absTick & 0x20000 != 0) price = (price * _R17) >> 96; if (absTick & 0x40000 != 0) price = (price * _R18) >> 96; } if (tickValue > 0) price = 0x1000000000000000000000000000000000000000000000000 / price; } function gt(Tick a, Tick b) internal pure returns (bool) { return Tick.unwrap(a) > Tick.unwrap(b); } function baseToQuote(Tick tick, uint256 base, bool roundingUp) internal pure returns (uint256) { return Math.divide((base * tick.toPrice()), 1 << 96, roundingUp); } function quoteToBase(Tick tick, uint256 quote, bool roundingUp) internal pure returns (uint256) { // @dev quote = unit(uint64) * unitSize(uint64) < 2^96 // We don't need to check overflow here return Math.divide(quote << 96, tick.toPrice(), roundingUp); } }
// SPDX-License-Identifier: - // License: https://license.sonic.market/LICENSE.pdf pragma solidity ^0.8.0; import {SignificantBit} from "./SignificantBit.sol"; import {Tick} from "./Tick.sol"; library TickBitmap { using SignificantBit for uint256; error EmptyError(); error AlreadyExistsError(); uint256 public constant B0_BITMAP_KEY = uint256(keccak256("TickBitmap")) + 1; uint256 public constant MAX_UINT_256_MINUS_1 = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe; function has(mapping(uint256 => uint256) storage self, Tick tick) internal view returns (bool) { (uint256 b0b1, uint256 b2) = _split(tick); uint256 mask = 1 << b2; return self[b0b1] & mask == mask; } function isEmpty(mapping(uint256 => uint256) storage self) internal view returns (bool) { return self[B0_BITMAP_KEY] == 0; } function _split(Tick tick) private pure returns (uint256 b0b1, uint256 b2) { assembly { let value := add(not(tick), 0x800000) b0b1 := shr(8, and(value, 0xffff00)) b2 := and(value, 0xff) } } function highest(mapping(uint256 => uint256) storage self) internal view returns (Tick) { if (isEmpty(self)) revert EmptyError(); uint256 b0 = self[B0_BITMAP_KEY].leastSignificantBit(); uint256 b0b1 = (b0 << 8) | (self[~b0].leastSignificantBit()); uint256 b2 = self[b0b1].leastSignificantBit(); return _toTick((b0b1 << 8) | b2); } function set(mapping(uint256 => uint256) storage self, Tick tick) internal { (uint256 b0b1, uint256 b2) = _split(tick); uint256 mask = 1 << b2; uint256 b2Bitmap = self[b0b1]; if (b2Bitmap & mask > 0) revert AlreadyExistsError(); self[b0b1] = b2Bitmap | mask; if (b2Bitmap == 0) { mask = 1 << (b0b1 & 0xff); uint256 b1BitmapKey = ~(b0b1 >> 8); uint256 b1Bitmap = self[b1BitmapKey]; self[b1BitmapKey] = b1Bitmap | mask; if (b1Bitmap == 0) self[B0_BITMAP_KEY] = self[B0_BITMAP_KEY] | (1 << ~b1BitmapKey); } } function clear(mapping(uint256 => uint256) storage self, Tick tick) internal { (uint256 b0b1, uint256 b2) = _split(tick); uint256 mask = 1 << b2; uint256 b2Bitmap = self[b0b1]; self[b0b1] = b2Bitmap & (~mask); if (b2Bitmap == mask) { mask = 1 << (b0b1 & 0xff); uint256 b1BitmapKey = ~(b0b1 >> 8); uint256 b1Bitmap = self[b1BitmapKey]; self[b1BitmapKey] = b1Bitmap & (~mask); if (mask == b1Bitmap) { mask = 1 << (~b1BitmapKey); self[B0_BITMAP_KEY] = self[B0_BITMAP_KEY] & (~mask); } } } function maxLessThan(mapping(uint256 => uint256) storage self, Tick tick) internal view returns (Tick) { (uint256 b0b1, uint256 b2) = _split(tick); uint256 b2Bitmap = (MAX_UINT_256_MINUS_1 << b2) & self[b0b1]; if (b2Bitmap == 0) { uint256 b0 = b0b1 >> 8; uint256 b1Bitmap = (MAX_UINT_256_MINUS_1 << (b0b1 & 0xff)) & self[~b0]; if (b1Bitmap == 0) { uint256 b0Bitmap = (MAX_UINT_256_MINUS_1 << b0) & self[B0_BITMAP_KEY]; if (b0Bitmap == 0) return Tick.wrap(type(int24).min); b0 = b0Bitmap.leastSignificantBit(); b1Bitmap = self[~b0]; } b0b1 = (b0 << 8) | b1Bitmap.leastSignificantBit(); b2Bitmap = self[b0b1]; } b2 = b2Bitmap.leastSignificantBit(); return _toTick((b0b1 << 8) | b2); } function _toTick(uint256 raw) private pure returns (Tick t) { assembly { t := and(not(sub(raw, 0x800000)), 0xffffff) } } }
// SPDX-License-Identifier: - // License: https://license.sonic.market/LICENSE.pdf pragma solidity ^0.8.20; import {DirtyUint64} from "./DirtyUint64.sol"; import {PackedUint256} from "./PackedUint256.sol"; import {Tick} from "./Tick.sol"; library TotalClaimableMap { using DirtyUint64 for uint64; using PackedUint256 for uint256; // @dev n should be less than type(uint64).max due to the dirty storage logic. function add(mapping(uint24 => uint256) storage self, Tick tick, uint64 n) internal { (uint24 groupIndex, uint8 elementIndex) = _splitTick(tick); uint256 group = self[groupIndex]; // @notice Be aware of dirty storage add logic self[groupIndex] = group.update64Unsafe( elementIndex, // elementIndex < 4 group.get64Unsafe(elementIndex).addClean(n) ); } function sub(mapping(uint24 => uint256) storage self, Tick tick, uint64 n) internal { (uint24 groupIndex, uint8 elementIndex) = _splitTick(tick); self[groupIndex] = self[groupIndex].sub64Unsafe(elementIndex, n); } function get(mapping(uint24 => uint256) storage self, Tick tick) internal view returns (uint64) { (uint24 groupIndex, uint8 elementIndex) = _splitTick(tick); return self[groupIndex].get64Unsafe(elementIndex).toClean(); } function _splitTick(Tick tick) internal pure returns (uint24 groupIndex, uint8 elementIndex) { uint256 casted = uint24(Tick.unwrap(tick)); assembly { groupIndex := shr(2, casted) // div 4 elementIndex := and(casted, 3) // mod 4 } } }
{ "evmVersion": "cancun", "optimizer": { "enabled": true, "runs": 1000 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": { "src/libraries/Book.sol": { "Book": "0x5489922f8312c812fbb7184ebf70b9dbfaeed9d4" } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"owner_","type":"address"},{"internalType":"address","name":"defaultProvider_","type":"address"},{"internalType":"string","name":"baseURI_","type":"string"},{"internalType":"string","name":"contractURI_","type":"string"},{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"BookNotOpened","type":"error"},{"inputs":[],"name":"CurrencyNotSettled","type":"error"},{"inputs":[],"name":"ECDSAInvalidSignature","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"ECDSAInvalidSignatureLength","type":"error"},{"inputs":[{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"ECDSAInvalidSignatureS","type":"error"},{"inputs":[],"name":"ERC20TransferFailed","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"}],"name":"ERC721IncorrectOwner","type":"error"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ERC721InsufficientApproval","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC721InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"operator","type":"address"}],"name":"ERC721InvalidOperator","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"ERC721InvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC721InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC721InvalidSender","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ERC721NonexistentToken","type":"error"},{"inputs":[],"name":"EmptyError","type":"error"},{"inputs":[],"name":"FailedHookCall","type":"error"},{"inputs":[{"internalType":"address","name":"hooks","type":"address"}],"name":"HookAddressNotValid","type":"error"},{"inputs":[],"name":"InvalidFeePolicy","type":"error"},{"inputs":[],"name":"InvalidHookResponse","type":"error"},{"inputs":[{"internalType":"address","name":"provider","type":"address"}],"name":"InvalidProvider","type":"error"},{"inputs":[],"name":"InvalidShortString","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[],"name":"InvalidTick","type":"error"},{"inputs":[],"name":"InvalidUnitSize","type":"error"},{"inputs":[{"internalType":"address","name":"locker","type":"address"},{"internalType":"address","name":"hook","type":"address"}],"name":"LockedBy","type":"error"},{"inputs":[],"name":"NativeTransferFailed","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"PermitExpired","type":"error"},{"inputs":[{"internalType":"int256","name":"value","type":"int256"}],"name":"SafeCastOverflowedIntToUint","type":"error"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintToInt","type":"error"},{"inputs":[{"internalType":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"OrderId","name":"orderId","type":"uint256"},{"indexed":false,"internalType":"uint64","name":"unit","type":"uint64"}],"name":"Cancel","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"OrderId","name":"orderId","type":"uint256"},{"indexed":false,"internalType":"uint64","name":"unit","type":"uint64"}],"name":"Claim","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"provider","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":true,"internalType":"Currency","name":"currency","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Collect","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"provider","type":"address"}],"name":"Delist","type":"event"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"BookId","name":"bookId","type":"uint192"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"Tick","name":"tick","type":"int24"},{"indexed":false,"internalType":"uint256","name":"orderIndex","type":"uint256"},{"indexed":false,"internalType":"uint64","name":"unit","type":"uint64"},{"indexed":false,"internalType":"address","name":"provider","type":"address"}],"name":"Make","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"BookId","name":"id","type":"uint192"},{"indexed":true,"internalType":"Currency","name":"base","type":"address"},{"indexed":true,"internalType":"Currency","name":"quote","type":"address"},{"indexed":false,"internalType":"uint64","name":"unitSize","type":"uint64"},{"indexed":false,"internalType":"FeePolicy","name":"makerPolicy","type":"uint24"},{"indexed":false,"internalType":"FeePolicy","name":"takerPolicy","type":"uint24"},{"indexed":false,"internalType":"contract IHooks","name":"hooks","type":"address"}],"name":"Open","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newDefaultProvider","type":"address"}],"name":"SetDefaultProvider","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"BookId","name":"bookId","type":"uint192"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"Tick","name":"tick","type":"int24"},{"indexed":false,"internalType":"uint64","name":"unit","type":"uint64"}],"name":"Take","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"provider","type":"address"}],"name":"Whitelist","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"baseURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"OrderId","name":"id","type":"uint256"},{"internalType":"uint64","name":"toUnit","type":"uint64"}],"internalType":"struct IBookManager.CancelParams","name":"params","type":"tuple"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"cancel","outputs":[{"internalType":"uint256","name":"canceledAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"checkAuthorized","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"OrderId","name":"id","type":"uint256"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"claim","outputs":[{"internalType":"uint256","name":"claimedAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"Currency","name":"currency","type":"address"}],"name":"collect","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"contractURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultProvider","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"provider","type":"address"}],"name":"delist","outputs":[],"stateMutability":"nonpayable","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":[{"components":[{"internalType":"Currency","name":"base","type":"address"},{"internalType":"uint64","name":"unitSize","type":"uint64"},{"internalType":"Currency","name":"quote","type":"address"},{"internalType":"FeePolicy","name":"makerPolicy","type":"uint24"},{"internalType":"contract IHooks","name":"hooks","type":"address"},{"internalType":"FeePolicy","name":"takerPolicy","type":"uint24"}],"internalType":"struct IBookManager.BookKey","name":"key","type":"tuple"}],"name":"encodeBookKey","outputs":[{"internalType":"BookId","name":"","type":"uint192"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"BookId","name":"id","type":"uint192"}],"name":"getBookKey","outputs":[{"components":[{"internalType":"Currency","name":"base","type":"address"},{"internalType":"uint64","name":"unitSize","type":"uint64"},{"internalType":"Currency","name":"quote","type":"address"},{"internalType":"FeePolicy","name":"makerPolicy","type":"uint24"},{"internalType":"contract IHooks","name":"hooks","type":"address"},{"internalType":"FeePolicy","name":"takerPolicy","type":"uint24"}],"internalType":"struct IBookManager.BookKey","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"locker","type":"address"},{"internalType":"Currency","name":"currency","type":"address"}],"name":"getCurrencyDelta","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"BookId","name":"id","type":"uint192"},{"internalType":"Tick","name":"tick","type":"int24"}],"name":"getDepth","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"BookId","name":"id","type":"uint192"}],"name":"getHighest","outputs":[{"internalType":"Tick","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"i","type":"uint256"}],"name":"getLock","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLockData","outputs":[{"internalType":"uint128","name":"","type":"uint128"},{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"OrderId","name":"id","type":"uint256"}],"name":"getOrder","outputs":[{"components":[{"internalType":"address","name":"provider","type":"address"},{"internalType":"uint64","name":"open","type":"uint64"},{"internalType":"uint64","name":"claimable","type":"uint64"}],"internalType":"struct IBookManager.OrderInfo","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"BookId","name":"id","type":"uint192"}],"name":"isEmpty","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"BookId","name":"id","type":"uint192"}],"name":"isOpened","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"provider","type":"address"}],"name":"isWhitelisted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"slot","type":"bytes32"}],"name":"load","outputs":[{"internalType":"bytes32","name":"value","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"startSlot","type":"bytes32"},{"internalType":"uint256","name":"nSlot","type":"uint256"}],"name":"load","outputs":[{"internalType":"bytes","name":"value","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"locker","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"lock","outputs":[{"internalType":"bytes","name":"result","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"Currency","name":"base","type":"address"},{"internalType":"uint64","name":"unitSize","type":"uint64"},{"internalType":"Currency","name":"quote","type":"address"},{"internalType":"FeePolicy","name":"makerPolicy","type":"uint24"},{"internalType":"contract IHooks","name":"hooks","type":"address"},{"internalType":"FeePolicy","name":"takerPolicy","type":"uint24"}],"internalType":"struct IBookManager.BookKey","name":"key","type":"tuple"},{"internalType":"Tick","name":"tick","type":"int24"},{"internalType":"uint64","name":"unit","type":"uint64"},{"internalType":"address","name":"provider","type":"address"}],"internalType":"struct IBookManager.MakeParams","name":"params","type":"tuple"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"make","outputs":[{"internalType":"OrderId","name":"id","type":"uint256"},{"internalType":"uint256","name":"quoteAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"BookId","name":"id","type":"uint192"},{"internalType":"Tick","name":"tick","type":"int24"}],"name":"maxLessThan","outputs":[{"internalType":"Tick","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"Currency","name":"base","type":"address"},{"internalType":"uint64","name":"unitSize","type":"uint64"},{"internalType":"Currency","name":"quote","type":"address"},{"internalType":"FeePolicy","name":"makerPolicy","type":"uint24"},{"internalType":"contract IHooks","name":"hooks","type":"address"},{"internalType":"FeePolicy","name":"takerPolicy","type":"uint24"}],"internalType":"struct IBookManager.BookKey","name":"key","type":"tuple"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"open","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Currency","name":"currency","type":"address"}],"name":"reservesOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newDefaultProvider","type":"address"}],"name":"setDefaultProvider","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Currency","name":"currency","type":"address"}],"name":"settle","outputs":[{"internalType":"uint256","name":"paid","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"Currency","name":"base","type":"address"},{"internalType":"uint64","name":"unitSize","type":"uint64"},{"internalType":"Currency","name":"quote","type":"address"},{"internalType":"FeePolicy","name":"makerPolicy","type":"uint24"},{"internalType":"contract IHooks","name":"hooks","type":"address"},{"internalType":"FeePolicy","name":"takerPolicy","type":"uint24"}],"internalType":"struct IBookManager.BookKey","name":"key","type":"tuple"},{"internalType":"Tick","name":"tick","type":"int24"},{"internalType":"uint64","name":"maxUnit","type":"uint64"}],"internalType":"struct IBookManager.TakeParams","name":"params","type":"tuple"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"take","outputs":[{"internalType":"uint256","name":"quoteAmount","type":"uint256"},{"internalType":"uint256","name":"baseAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"provider","type":"address"},{"internalType":"Currency","name":"currency","type":"address"}],"name":"tokenOwed","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"provider","type":"address"}],"name":"whitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Currency","name":"currency","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
610160604052348015610010575f80fd5b5060405161625738038061625783398101604081905261002f91610361565b6040805180820190915260018152601960f91b60208201528290829082818a82855f61005b83826104aa565b50600161006882826104aa565b5050506001600160a01b03811661009957604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b6100a281610185565b506100ae8260076101a1565b610120526100bd8160086101a1565b61014052815160208084019190912060e052815190820120610100524660a05261014960e05161010051604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201529081019290925260608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b60805250503060c0525061016091508690506101d3565b600a61016c85826104aa565b50600b61017984826104aa565b505050505050506105c1565b600680546001600160a01b031916905561019e8161021c565b50565b5f6020835110156101bc576101b58361026d565b90506101cd565b816101c784826104aa565b5060ff90505b92915050565b600c80546001600160a01b0319166001600160a01b0383169081179091556040517fef673bbfc2ac7e4d4b810bffda0b15a1f2b48c2aa4d178d3fca87d0d1f337062905f90a250565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b5f80829050601f81511115610297578260405163305a27a960e01b81526004016100909190610569565b80516102a28261059e565b179392505050565b80516001600160a01b03811681146102c0575f80fd5b919050565b634e487b7160e01b5f52604160045260245ffd5b5f82601f8301126102e8575f80fd5b81516001600160401b0380821115610302576103026102c5565b604051601f8301601f19908116603f0116810190828211818310171561032a5761032a6102c5565b81604052838152866020858801011115610342575f80fd5b8360208701602083015e5f602085830101528094505050505092915050565b5f805f805f8060c08789031215610376575f80fd5b61037f876102aa565b955061038d602088016102aa565b60408801519095506001600160401b03808211156103a9575f80fd5b6103b58a838b016102d9565b955060608901519150808211156103ca575f80fd5b6103d68a838b016102d9565b945060808901519150808211156103eb575f80fd5b6103f78a838b016102d9565b935060a089015191508082111561040c575f80fd5b5061041989828a016102d9565b9150509295509295509295565b600181811c9082168061043a57607f821691505b60208210810361045857634e487b7160e01b5f52602260045260245ffd5b50919050565b601f8211156104a557805f5260205f20601f840160051c810160208510156104835750805b601f840160051c820191505b818110156104a2575f815560010161048f565b50505b505050565b81516001600160401b038111156104c3576104c36102c5565b6104d7816104d18454610426565b8461045e565b602080601f83116001811461050a575f84156104f35750858301515b5f19600386901b1c1916600185901b178555610561565b5f85815260208120601f198616915b8281101561053857888601518255948401946001909101908401610519565b508582101561055557878501515f19600388901b60f8161c191681555b505060018460011b0185555b505050505050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b80516020808301519190811015610458575f1960209190910360031b1b16919050565b60805160a05160c05160e051610100516101205161014051615c456106125f395f6136d301525f6136a601525f61313b01525f61311301525f61306e01525f61309801525f6130c20152615c455ff3fe608060405260043610610353575f3560e01c80637ac2ff7b116101bd578063cdc92f2d116100f2578063e8a3d48511610092578063f2fde38b1161006d578063f2fde38b14610bd5578063f86a11b314610bf4578063fcc8fc9b14610c13578063fefc7c5114610c32575f80fd5b8063e8a3d48514610b5c578063e985e9c514610b70578063f035079914610bb7575f80fd5b8063d83747e8116100cd578063d83747e814610ae2578063d9caed1214610b01578063de4478ec14610b20578063e30c397814610b3f575f80fd5b8063cdc92f2d146109dd578063d09ef241146109fc578063d68f4dd114610a58575f80fd5b80639b22917d1161015d578063a179dadc11610138578063a179dadc1461094e578063a22cb46514610980578063b88d4fde1461099f578063c87b56dd146109be575f80fd5b80639b22917d146108335780639ca1799814610910578063a12ef25e1461092f575f80fd5b806393c85a211161019857806393c85a21146107b657806395d89b41146107e15780639611cf6c146107f55780639b19251a14610814575f80fd5b80637ac2ff7b1461075357806384b0196e146107725780638da5cb5b14610799575f80fd5b80633af32abf116102935780636352211e116102335780636c0360eb1161020e5780636c0360eb146106f857806370a082311461070c578063715018a61461072b57806379ba50971461073f575f80fd5b80636352211e146106a75780636a256b29146106c65780636b2cc75c146106d9575f80fd5b806341a8bb881161026e57806341a8bb88146105f857806342842e0e146106305780634c02bf0b1461064f57806355af6a3214610688575f80fd5b80633af32abf146105755780633b9500b0146105a35780633e547b06146105c2575f80fd5b80631dbef488116102fe5780632f584a6d116102d95780632f584a6d146104f057806330adf81f1461050f5780633644e5151461054257806338926b6d14610556575f80fd5b80631dbef488146104665780631ff63f931461049a57806323b872dd146104d1575f80fd5b8063095ea7b31161032e578063095ea7b3146103ea578063141a468c1461040b57806314d6a9eb14610447575f80fd5b806301ffc9a71461035e57806306fdde0314610392578063081812fc146103b3575f80fd5b3661035a57005b5f80fd5b348015610369575f80fd5b5061037d610378366004614ac4565b610c51565b60405190151581526020015b60405180910390f35b34801561039d575f80fd5b506103a6610c94565b6040516103899190614b0d565b3480156103be575f80fd5b506103d26103cd366004614b1f565b610d23565b6040516001600160a01b039091168152602001610389565b3480156103f5575f80fd5b50610409610404366004614b4a565b610d4a565b005b348015610416575f80fd5b50610439610425366004614b1f565b5f9081526009602052604090205460a01c90565b604051908152602001610389565b348015610452575f80fd5b50610439610461366004614bb9565b610d59565b348015610471575f80fd5b50610485610480366004614c0f565b610f9a565b60408051928352602083019190915201610389565b3480156104a5575f80fd5b506104b96104b4366004614c5e565b61138b565b6040516001600160c01b039091168152602001610389565b3480156104dc575f80fd5b506104096104eb366004614c78565b61139e565b3480156104fb575f80fd5b5061040961050a366004614c78565b611440565b34801561051a575f80fd5b506104397f49ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9ad81565b34801561054d575f80fd5b50610439611450565b348015610561575f80fd5b50610439610570366004614cb6565b61145e565b348015610580575f80fd5b5061037d61058f366004614ce5565b600f6020525f908152604090205460ff1681565b3480156105ae575f80fd5b506104856105bd366004614d00565b611821565b3480156105cd575f80fd5b506104396105dc366004614d23565b601060209081525f928352604080842090915290825290205481565b348015610603575f80fd5b50610617610612366004614d81565b611aea565b60405167ffffffffffffffff9091168152602001610389565b34801561063b575f80fd5b5061040961064a366004614c78565b611b12565b34801561065a575f80fd5b50604080515f80516020615af08339815191525c6001600160801b038116825260801c602082015201610389565b348015610693575f80fd5b5061037d6106a2366004614db2565b611b2c565b3480156106b2575f80fd5b506103d26106c1366004614b1f565b611b5c565b6104396106d4366004614ce5565b611b66565b3480156106e4575f80fd5b506104096106f3366004614ce5565b611bcc565b348015610703575f80fd5b506103a6611c1c565b348015610717575f80fd5b50610439610726366004614ce5565b611ca8565b348015610736575f80fd5b50610409611d06565b34801561074a575f80fd5b50610409611d19565b34801561075e575f80fd5b5061040961076d366004614dcb565b611d5d565b34801561077d575f80fd5b50610786611fbe565b6040516103899796959493929190614e28565b3480156107a4575f80fd5b506005546001600160a01b03166103d2565b3480156107c1575f80fd5b506104396107d0366004614ce5565b600d6020525f908152604090205481565b3480156107ec575f80fd5b506103a661201c565b348015610800575f80fd5b5061043961080f366004614d23565b61202b565b34801561081f575f80fd5b5061040961082e366004614ce5565b61203f565b34801561083e575f80fd5b5061090361084d366004614db2565b6040805160c0810182525f80825260208201819052918101829052606081018290526080810182905260a0810191909152506001600160c01b03165f908152600e6020908152604091829020825160c08101845281546001600160a01b03808216835267ffffffffffffffff600160a01b92839004169483019490945260018301548085169583019590955262ffffff94819004851660608301526002909201549283166080820152910490911660a082015290565b6040516103899190614edb565b34801561091b575f80fd5b506103a661092a366004614f42565b612092565b34801561093a575f80fd5b50610439610949366004614d23565b6121a6565b348015610959575f80fd5b5061096d610968366004614d81565b61225d565b60405160029190910b8152602001610389565b34801561098b575f80fd5b5061040961099a366004614f7a565b61227e565b3480156109aa575f80fd5b506104096109b9366004615016565b612289565b3480156109c9575f80fd5b506103a66109d8366004614b1f565b6122a0565b3480156109e8575f80fd5b5061096d6109f7366004614db2565b612304565b348015610a07575f80fd5b50610a1b610a16366004614b1f565b612324565b6040805182516001600160a01b0316815260208084015167ffffffffffffffff908116918301919091529282015190921690820152606001610389565b348015610a63575f80fd5b50610ac2610a72366004614b1f565b6002027f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b181015c917f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b29091015c90565b604080516001600160a01b03938416815292909116602083015201610389565b348015610aed575f80fd5b50600c546103d2906001600160a01b031681565b348015610b0c575f80fd5b50610409610b1b366004614c78565b612468565b348015610b2b575f80fd5b50610409610b3a366004614ce5565b6124ce565b348015610b4a575f80fd5b506006546001600160a01b03166103d2565b348015610b67575f80fd5b506103a66124df565b348015610b7b575f80fd5b5061037d610b8a366004614d23565b6001600160a01b039182165f90815260046020908152604080832093909416825291909152205460ff1690565b348015610bc2575f80fd5b50610439610bd1366004614b1f565b5490565b348015610be0575f80fd5b50610409610bef366004614ce5565b6124ec565b348015610bff575f80fd5b506103a6610c0e3660046150be565b61255d565b348015610c1e575f80fd5b5061037d610c2d366004614db2565b6125d9565b348015610c3d575f80fd5b50610409610c4c3660046150de565b6125f9565b5f6001600160e01b031982167f6831a4fd000000000000000000000000000000000000000000000000000000001480610c8e5750610c8e82612966565b92915050565b60605f8054610ca290615115565b80601f0160208091040260200160405190810160405280929190818152602001828054610cce90615115565b8015610d195780601f10610cf057610100808354040283529160200191610d19565b820191905f5260205f20905b815481529060010190602001808311610cfc57829003601f168201915b5050505050905090565b5f610d2d82612a00565b505f828152600360205260409020546001600160a01b0316610c8e565b610d55828233612a38565b5050565b5f610d6333612a45565b610d84610d7c85355f9081526009602052604090205490565b338635612b06565b8335604090811c5f908152600e602090815290829020825160c08101845281546001600160a01b03808216835267ffffffffffffffff600160a01b92839004169483019490945260018301548085169583019590955262ffffff9481900485166060830152600283015493841660808301819052930490931660a08401529190610e1090878787612b83565b5f80735489922f8312c812fbb7184ebf70b9dbfaeed9d4633ac502c1858a35610e3f60408d0160208e0161515c565b6040516001600160e01b031960e086901b1681526004810193909352602483019190915267ffffffffffffffff1660448201526064016040805180830381865af4158015610e8f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610eb39190615177565b91509150826020015167ffffffffffffffff168267ffffffffffffffff16029450610ee7836060015162ffffff1660171c90565b15610f0b5760608301515f90610f049062ffffff16876001612c03565b9590950194505b8067ffffffffffffffff165f03610f2657610f268835612c83565b610f34836040015186612cbb565b60405167ffffffffffffffff831681528835907f0c6ba7ef5064094c17cce013aa4c617a23e2582f867774d07a5931de43b85d729060200160405180910390a26080830151610f8f906001600160a01b031689848a8a612d02565b505050509392505050565b5f80610fa533612a45565b5f610fb861012087016101008801614ce5565b6001600160a01b031614158015610ffd5750600f5f610fdf61012088016101008901614ce5565b6001600160a01b0316815260208101919091526040015f205460ff16155b156110575761101461012086016101008701614ce5565b6040517f962715990000000000000000000000000000000000000000000000000000000081526001600160a01b0390911660048201526024015b60405180910390fd5b61107261106a60e0870160c088016151a4565b60020b612d8b565b5f61108a61108536889003880188615277565b612de7565b6001600160c01b0381165f908152600e602052604090209091506110ad81612e22565b6110e26110bf36899003890189615291565b87876110d160a08c0160808d01614ce5565b6001600160a01b0316929190612e6b565b5f735489922f8312c812fbb7184ebf70b9dbfaeed9d463ffa0afb58361110e60e08c0160c08d016151a4565b61111f6101008d0160e08e0161515c565b6111316101208e016101008f01614ce5565b6040516001600160e01b031960e087901b168152600481019490945260029290920b602484015267ffffffffffffffff1660448301526001600160a01b03166064820152608401602060405180830381865af4158015611193573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111b79190615313565b90506111e9836111cd60e08b0160c08c016151a4565b60409190911b60289190911b67ffffff00000000001601820190565b94505f6111fc60408a0160208b0161515c565b67ffffffffffffffff166112176101008b0160e08c0161515c565b67ffffffffffffffff1602945084905061124561123a60808b0160608c01615337565b62ffffff1660171c90565b156112705761126b855f61125f60808d0160608e01615337565b62ffffff169190612c03565b019350835b61129161128360608b0160408c01614ce5565b61128c83615364565b612cbb565b61129b3387612ea9565b336001600160c01b0385167f251db4df45fa692f68b4e3f072919384c5b71995c71bf22888385168930fd22a6112d760e08d0160c08e016151a4565b858d60e00160208101906112eb919061515c565b8e6101000160208101906112ff9190614ce5565b6040805160029590950b855264ffffffffff93909316602085015267ffffffffffffffff91909116838301526001600160a01b03166060830152519081900360800190a361137f611355368b90038b018b615291565b878a8a8d5f01608001602081019061136d9190614ce5565b6001600160a01b031693929190612f23565b50505050935093915050565b5f610c8e61108536849003840184615277565b6001600160a01b0382166113c757604051633250574960e11b81525f600482015260240161104e565b5f6113d3838333612f63565b9050836001600160a01b0316816001600160a01b03161461143a576040517f64283d7b0000000000000000000000000000000000000000000000000000000081526001600160a01b038086166004830152602482018490528216604482015260640161104e565b50505050565b61144b838383612b06565b505050565b5f611459613062565b905090565b5f61146833612a45565b5f84815260096020526040902054611481903386612b06565b604084811c5f908152600e602090815290829020825160c08101845281546001600160a01b03808216835267ffffffffffffffff600160a01b92839004169483019490945260018301548085169583019590955262ffffff94819004851660608301526002830154938416608083018190529304841660a0820152602888901c9093169264ffffffffff88169261151a9089898961318b565b6040517fc49d262100000000000000000000000000000000000000000000000000000000815260048101839052600285900b602482015264ffffffffff841660448201525f90735489922f8312c812fbb7184ebf70b9dbfaeed9d49063c49d262190606401602060405180830381865af415801561159a573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115be919061539a565b60208301519091505f90819067ffffffffffffffff8085169116026115e8600289900b82846131c8565b606086015160a0870151919a509061160562ffffff821660171c90565b156116225761161b62ffffff8216846001612c03565b9450611636565b61163362ffffff82168c6001612c03565b93505b6116458262ffffff1660171c90565b1561166c5761165b62ffffff8316846001612c03565b61166590866153b5565b94506116b8565b5f61167d62ffffff84168d83612c03565b905061168981866153b5565b94505f81136116aa5761169b81615364565b6116a5908d6153dc565b6116b4565b6116b4818d6153ef565b9b50505b505f91506116c990508689896131f2565b80519091506001600160a01b0381166116ea5750600c546001600160a01b03165b5f84131561173b576116fb84613246565b6001600160a01b038083165f9081526010602090815260408083208b820151909416835292905290812080549091906117359084906153dc565b90915550505b5f83131561178a5761174c83613246565b6001600160a01b038083165f9081526010602090815260408083208b51909416835292905290812080549091906117849084906153dc565b90915550505b816020015167ffffffffffffffff165f036117a8576117a88d612c83565b85516117b79061128c8c613288565b60405167ffffffffffffffff861681528d907ffc7df80a30ee916cc040221cf6fcfb3c6dc994b3fa4c4ab23e8a0f134de5c0c09060200160405180910390a26080860151611811906001600160a01b03168e878f8f6132e6565b5050505050505050509392505050565b5f8061182c33612a45565b61183f61106a60e0870160c088016151a4565b5f61185261108536889003880188615277565b6001600160c01b0381165f908152600e6020526040902090915061187581612e22565b6118aa61188736899003890189615402565b878761189960a08c0160808d01614ce5565b6001600160a01b0316929190613325565b5f735489922f8312c812fbb7184ebf70b9dbfaeed9d463a151a7e1836118d660e08c0160c08d016151a4565b6118e76101008d0160e08e0161515c565b6040516001600160e01b031960e086901b168152600481019390935260029190910b602483015267ffffffffffffffff166044820152606401602060405180830381865af415801561193b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061195f919061539a565b90506119716040890160208a0161515c565b67ffffffffffffffff82811691160294506119a285600161199860e08c0160c08d016151a4565b60020b91906131c8565b9350845f6119af86613288565b90506119c461123a60c08c0160a08d01615337565b156119f2576119de875f61125f60c08e0160a08f01615337565b6119e89083615470565b9150819650611a17565b611a07865f61125f60c08e0160a08f01615337565b611a1190826153b5565b90508095505b611a30611a2a60608c0160408d01614ce5565b83612cbb565b611a4061128360208c018c614ce5565b336001600160c01b0386167fc4c20b9c4a5ada3b01b7a391a08dd81a1be01dd8ef63170dd9da44ecee3db11b611a7c60e08e0160c08f016151a4565b6040805160029290920b825267ffffffffffffffff881660208301520160405180910390a3611add611ab3368c90038c018c615402565b848b8b8e5f016080016020810190611acb9190614ce5565b6001600160a01b031693929190613363565b5050505050935093915050565b6001600160c01b0382165f908152600e60205260408120611b0b90836133a3565b9392505050565b61144b83838360405180602001604052805f815250612289565b6001600160c01b0381165f908152600e6020526040812054600160a01b900467ffffffffffffffff161515610c8e565b5f610c8e82612a00565b5f611b7033612a45565b6001600160a01b0382165f818152600d602052604090205490611b92906133d8565b6001600160a01b0384165f908152600d60205260409020819055611bb79082906153ef565b9150611bc68361128c84613288565b50919050565b611bd4613472565b6001600160a01b0381165f818152600f6020526040808220805460ff19169055517f88f58aa68e1f754fecfec41a6758d18d4a53fa15d4e206fd54bbdfe7a9e98da79190a250565b600a8054611c2990615115565b80601f0160208091040260200160405190810160405280929190818152602001828054611c5590615115565b8015611ca05780601f10611c7757610100808354040283529160200191611ca0565b820191905f5260205f20905b815481529060010190602001808311611c8357829003601f168201915b505050505081565b5f6001600160a01b038216611ceb576040517f89c62b640000000000000000000000000000000000000000000000000000000081525f600482015260240161104e565b506001600160a01b03165f9081526002602052604090205490565b611d0e613472565b611d175f61349f565b565b60065433906001600160a01b03168114611d515760405163118cdaa760e01b81526001600160a01b038216600482015260240161104e565b611d5a8161349f565b50565b83421115611d97576040517f1a15a3cc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f611e147f49ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9ad8888611dc7816134b8565b6040805160208101959095526001600160a01b03909316928401929092526060830152608082015260a0810187905260c001604051602081830303815290604052805190602001206134f1565b90505f611e2087611b5c565b9050806001600160a01b0316886001600160a01b031603611e5457604051638baa579f60e01b815260040160405180910390fd5b6001600160a01b0381163b15611f6a57604080516020810186905280820185905260f887901b7fff000000000000000000000000000000000000000000000000000000000000001660608201528151604181830301815260618201928390527f1626ba7e000000000000000000000000000000000000000000000000000000009092526001600160a01b03831691631626ba7e91611ef691869160650161548f565b602060405180830381865afa158015611f11573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f3591906154a7565b6001600160e01b031916631626ba7e60e01b14611f6557604051638baa579f60e01b815260040160405180910390fd5b611fa7565b806001600160a01b0316611f8083878787613538565b6001600160a01b031614611fa757604051638baa579f60e01b815260040160405180910390fd5b611fb48888836001613564565b5050505050505050565b5f6060805f805f6060611fcf61369f565b611fd76136cc565b604080515f808252602082019092527f0f000000000000000000000000000000000000000000000000000000000000009b939a50919850469750309650945092509050565b606060018054610ca290615115565b5f611b0b83836014525f526028600c205c90565b612047613472565b6001600160a01b0381165f818152600f6020526040808220805460ff19166001179055517feb73900b98b6a3e2b8b01708fe544760cf570d21e7fbe5225f24e48b5b2b432e9190a250565b606061209e84336136f9565b6040517f15c7afb40000000000000000000000000000000000000000000000000000000081526001600160a01b038516906315c7afb4906120e7903390879087906004016154ea565b5f604051808303815f875af1158015612102573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052612129919081019061550c565b9050612133613759565b5f80516020615af08339815191525c6001600160801b0381169060801c8115801561216657506001600160801b03811615155b1561219d576040517f5212cba100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50509392505050565b335f9081526010602090815260408083206001600160a01b03851684528252808320805490849055600d90925282208054919283926121e69084906153ef565b9091555061220090506001600160a01b03831684836137ce565b816001600160a01b0316836001600160a01b0316336001600160a01b03167f1c4f94f28cc9152354d4b98b8614b28c6c828a98d88228fa9577c7b9475e120c8460405161224f91815260200190565b60405180910390a492915050565b6001600160c01b0382165f908152600e60205260408120611b0b90836138ab565b610d553383836138b9565b61229484848461139e565b61143a84848484613970565b60606122ab82612a00565b505f6122b5613a8f565b90505f8151116122d35760405180602001604052805f815250611b0b565b806122dd84613a9e565b6040516020016122ee929190615598565b6040516020818303038152906040529392505050565b6001600160c01b0381165f908152600e60205260408120610c8e90613b3b565b604080516060810182525f808252602080830182905282840182905284841c808352600e909152928120919291602885901c62ffffff169164ffffffffff861691906123718285856131f2565b6040517f329b4a0100000000000000000000000000000000000000000000000000000000815260048101849052600286900b602482015264ffffffffff851660448201529091505f90735489922f8312c812fbb7184ebf70b9dbfaeed9d49063329b4a0190606401602060405180830381865af41580156123f4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612418919061539a565b90506040518060600160405280835f01516001600160a01b031681526020018284602001510367ffffffffffffffff1681526020018267ffffffffffffffff168152509650505050505050919050565b61247133612a45565b801561144b5761248d8361248483613288565b61128c90615364565b6001600160a01b0383165f908152600d6020526040812080548392906124b49084906153ef565b9091555061144b90506001600160a01b03841683836137ce565b6124d6613472565b611d5a81613b48565b600b8054611c2990615115565b6124f4613472565b600680546001600160a01b0383166001600160a01b031990911681179091556125256005546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b606061256a8260206155ac565b67ffffffffffffffff81111561258257612582614faa565b6040519080825280601f01601f1916602001820160405280156125ac576020820181803683370190505b5090505f5b828110156125d25780840154602060018301028301526001810190506125b1565b5092915050565b6001600160c01b0381165f908152600e60205260408120610c8e90613b91565b61260233612a45565b612612604084016020850161515c565b67ffffffffffffffff165f03612654576040517faf6c36ab00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6126656080850160608601615337565b90505f61267860c0860160a08701615337565b90506126888262ffffff16613b9e565b801561269d575061269d8162ffffff16613b9e565b6126ba57604051637a34030f60e01b815260040160405180910390fd5b5f620f423f19627fffff848116908416010160020b12156126ee57604051637a34030f60e01b815260040160405180910390fd5b5f627fffff83166207a11f190160020b128061271757505f627fffff82166207a11f190160020b125b1561275c5761272b8162ffffff1660171c90565b151561273c8362ffffff1660171c90565b15151461275c57604051637a34030f60e01b815260040160405180910390fd5b5f61276d60a0870160808801614ce5565b9050612781816001600160a01b0316613bce565b6127c2576040517fe65af6a00000000000000000000000000000000000000000000000000000000081526001600160a01b038216600482015260240161104e565b6127e66127d436889003880188615277565b6001600160a01b038316908787613c05565b5f6127f961108536899003890189615277565b6001600160c01b0381165f908152600e60205260409081902090517fab8a7e3f000000000000000000000000000000000000000000000000000000008152919250735489922f8312c812fbb7184ebf70b9dbfaeed9d49163ab8a7e3f91612864918b906004016155c3565b5f6040518083038186803b15801561287a575f80fd5b505af415801561288c573d5f803e3d5ffd5b506128a1925050506060880160408901614ce5565b6001600160a01b03166128b76020890189614ce5565b6001600160a01b03166001600160c01b0383167f803427d75ce3214f82dc7aa4910635170a6655e2c1663dc03429dd04100cba5a6128fb60408c0160208d0161515c565b6040805167ffffffffffffffff909216825262ffffff808b1660208401528916908201526001600160a01b038716606082015260800160405180910390a461295d61294b36899003890189615277565b6001600160a01b038416908888613c43565b50505050505050565b5f6001600160e01b031982167f80ac58cd0000000000000000000000000000000000000000000000000000000014806129c857506001600160e01b031982167f5b5e139f00000000000000000000000000000000000000000000000000000000145b80610c8e57507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b0319831614610c8e565b5f818152600960205260408120546001600160a01b038116610c8e57604051637e27328960e01b81526004810184905260240161104e565b61144b8383836001613564565b5f612a4e613c81565b90506001600160801b035f80516020615af08339815191525c167ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be422015c6001600160a01b0380831690841603612aa357505050565b806001600160a01b0316836001600160a01b031603612ac157505050565b6040517f74d863650000000000000000000000000000000000000000000000000000000081526001600160a01b0380841660048301528216602482015260440161104e565b612b11838383613cd6565b61144b576001600160a01b038316612b3f57604051637e27328960e01b81526004810182905260240161104e565b6040517f177e802f0000000000000000000000000000000000000000000000000000000081526001600160a01b03831660048201526024810182905260440161104e565b73020000000000000000000000000000000000000084161561143a5761143a63295b52c560e01b33858585604051602401612bc19493929190615693565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526001600160a01b03861690613d56565b5f6207a11f19627fffff851601600281900b82128281612c2557825f03612c27565b825b62ffffff1690505f612c60612c3c83896155ac565b620f424088612c52578581830615151691040190565b808206151586151691040190565b905082612c7557612c7081615364565b612c77565b805b98975050505050505050565b5f612c8f5f835f612f63565b90506001600160a01b038116610d5557604051637e27328960e01b81526004810183905260240161104e565b805f03612cc6575050565b5f612ccf613c81565b90505f612cdd828585613db3565b9050805f03612cf357612cee613dd1565b61143a565b82810361143a5761143a613e04565b730100000000000000000000000000000000000000851615612d8457612d84635125ce9c60e01b3386868686604051602401612d429594939291906156c2565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526001600160a01b03871690613d56565b5050505050565b6207ffff600282900b1380612db05750612da76207ffff61570c565b60020b8160020b125b15611d5a576040517fce8ef7fc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8082604051602001612dfa9190614edb565b60408051601f1981840301815291905280516020909101206001600160c01b03169392505050565b8054600160a01b900467ffffffffffffffff16611d5a576040517f1e3636e600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73200000000000000000000000000000000000000084161561143a5761143a633fda46bb60e01b33858585604051602401612bc194939291906157c7565b6001600160a01b038216612ed257604051633250574960e11b81525f600482015260240161104e565b5f612ede83835f612f63565b90506001600160a01b0381161561144b576040517f73c6ac6e0000000000000000000000000000000000000000000000000000000081525f600482015260240161104e565b731000000000000000000000000000000000000000851615612d8457612d8463eba8155960e01b3386868686604051602401612d429594939291906157f8565b5f828152600960205260408120546001600160a01b03831615612f8b57612f8b818486612b06565b6001600160a01b03811615612fc557612fa65f855f80613564565b6001600160a01b0381165f90815260026020526040902080545f190190555b6001600160a01b03851615612ff3576001600160a01b0385165f908152600260205260409020805460010190555b5f84815260096020526040902080546001600160a01b0319166001600160a01b03871617905583856001600160a01b0316826001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4949350505050565b5f306001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161480156130ba57507f000000000000000000000000000000000000000000000000000000000000000046145b156130e457507f000000000000000000000000000000000000000000000000000000000000000090565b611459604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f0000000000000000000000000000000000000000000000000000000000000000918101919091527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b728000000000000000000000000000000000000084161561143a5761143a63827e0eb260e01b33858585604051602401612bc19493929190615830565b5f6131ea606084901b6131dd8660020b613e37565b8082061515851691040190565b949350505050565b604080518082019091525f80825260208201526132108484846140ff565b6040805180820190915290546001600160a01b0381168252600160a01b900467ffffffffffffffff166020820152949350505050565b5f80821215613284576040517fa8ce44320000000000000000000000000000000000000000000000000000000081526004810183905260240161104e565b5090565b5f7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821115613284576040517f24775e060000000000000000000000000000000000000000000000000000000081526004810183905260240161104e565b7240000000000000000000000000000000000000851615612d8457612d846348042cf460e01b3386868686604051602401612d42959493929190615858565b73080000000000000000000000000000000000000084161561143a5761143a63fab3c75660e01b33858585604051602401612bc19493929190615917565b730400000000000000000000000000000000000000851615612d8457612d84639eb477b260e01b3386868686604051602401612d42959493929190615948565b5f6133b16005840183614140565b600283900b5f90815260038501602052604090206133ce90614182565b611b0b919061598a565b5f6001600160a01b0382166133ee575047919050565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa158015613449573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c8e91906159ab565b919050565b6005546001600160a01b03163314611d175760405163118cdaa760e01b815233600482015260240161104e565b600680546001600160a01b0319169055611d5a816141c1565b5f8181526009602052604090205460a081901c906134da81600160a01b6153dc565b5f9384526009602052604090932092909255919050565b5f610c8e6134fd613062565b836040517f19010000000000000000000000000000000000000000000000000000000000008152600281019290925260228201526042902090565b5f805f8061354888888888614212565b92509250925061355882826142da565b50909695505050505050565b808061357857506001600160a01b03821615155b15613670575f61358784612a00565b90506001600160a01b038316158015906135b35750826001600160a01b0316816001600160a01b031614155b80156135e457506001600160a01b038082165f9081526004602090815260408083209387168352929052205460ff16155b15613626576040517fa9fbf51f0000000000000000000000000000000000000000000000000000000081526001600160a01b038416600482015260240161104e565b811561366e5783856001600160a01b0316826001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45b505b50505f90815260036020526040902080546001600160a01b0319166001600160a01b0392909216919091179055565b60606114597f000000000000000000000000000000000000000000000000000000000000000060076143dd565b60606114597f000000000000000000000000000000000000000000000000000000000000000060086143dd565b5f80516020615af08339815191525c7f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b160026001600160801b038316020183815d82600182015d50600181015f80516020615af08339815191525d505050565b5f80516020615af08339815191525c6001600160801b038116806137845763f1c77ed05f526004601cfd5b7f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b15f19909101600202015f815d5f600182015d50600181035f80516020615af08339815191525d50565b5f6001600160a01b03841661381e575f805f8085875af1905080612cee576040517ff4b3b1bc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517fa9059cbb0000000000000000000000000000000000000000000000000000000081526001600160a01b038416600482015282602482015260205f6044835f895af13d15601f3d1160015f51141617169150508061143a576040517ff27f64e400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f611b0b6004840183614486565b6001600160a01b038216613904576040517f5b08ba180000000000000000000000000000000000000000000000000000000081526001600160a01b038316600482015260240161104e565b6001600160a01b038381165f81815260046020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6001600160a01b0383163b1561143a57604051630a85bd0160e11b81526001600160a01b0384169063150b7a02906139b29033908890879087906004016159c2565b6020604051808303815f875af19250505080156139ec575060408051601f3d908101601f191682019092526139e9918101906154a7565b60015b613a53573d808015613a19576040519150601f19603f3d011682016040523d82523d5f602084013e613a1e565b606091505b5080515f03613a4b57604051633250574960e11b81526001600160a01b038516600482015260240161104e565b805181602001fd5b6001600160e01b03198116630a85bd0160e11b14612d8457604051633250574960e11b81526001600160a01b038516600482015260240161104e565b6060600a8054610ca290615115565b60605f613aaa836145b4565b60010190505f8167ffffffffffffffff811115613ac957613ac9614faa565b6040519080825280601f01601f191660200182016040528015613af3576020820181803683370190505b5090508181016020015b5f19017f3031323334353637383961626364656600000000000000000000000000000000600a86061a8153600a8504945084613afd57509392505050565b5f610c8e82600401614695565b600c80546001600160a01b0319166001600160a01b0383169081179091556040517fef673bbfc2ac7e4d4b810bffda0b15a1f2b48c2aa4d178d3fca87d0d1f337062905f90a250565b5f610c8e82600401614780565b5f6207a11f19627fffff8316016207a120600282900b1380613bc657506207a11f198160020b125b159392505050565b5f6001600160a01b0382161580610c8e57505072400000000000000000000000000000000000006001600160a01b03909116101590565b73800000000000000000000000000000000000000084161561143a5761143a635df4d91860e01b33858585604051602401612bc194939291906159f3565b73400000000000000000000000000000000000000084161561143a5761143a6371ded94360e01b33858585604051602401612bc194939291906159f3565b5f5f80516020615af08339815191525c6001600160801b031680613ca5575f613cd0565b60025f198201027f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b1015c5b91505090565b5f6001600160a01b038316158015906131ea5750826001600160a01b0316846001600160a01b03161480613d2e57506001600160a01b038085165f9081526004602090815260408083209387168352929052205460ff165b806131ea5750505f908152600360205260409020546001600160a01b03908116911614919050565b5f80613d6284846147c5565b91509150816001600160e01b031916816001600160e01b0319161461143a576040517f1e048e1d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f82601452835f526028600c2082815c01915081815d509392505050565b7001000000000000000000000000000000005f80516020615af08339815191525c035f80516020615af08339815191525d565b7001000000000000000000000000000000005f80516020615af08339815191525c015f80516020615af08339815191525d565b5f613e4182612d8b565b815f600282900b8113613e545781613e5d565b613e5d8261570c565b62ffffff8116915060011615613e81576bfff97272373d413259a469909250613e92565b6c0100000000000000000000000092505b6002811615613eb15760606bfff2e50f5f656932ef12357c8402901c92505b6004811615613ed05760606bffe5caca7e10e4e61c3624ea8402901c92505b6008811615613eef5760606bffcb9843d60f6159c9db58838402901c92505b6010811615613f0e5760606bff973b41fa98c081472e68968402901c92505b6020811615613f2d5760606bff2ea16466c96a3843ec78b38402901c92505b6040811615613f4c5760606bfe5dee046a99a2a811c461f18402901c92505b6080811615613f6b5760606bfcbe86c7900a88aedcffc83b8402901c92505b610100811615613f8b5760606bf987a7253ac413176f2b074c8402901c92505b610200811615613fab5760606bf3392b0822b70005940c7a398402901c92505b610400811615613fcb5760606be7159475a2c29b7443b29c7f8402901c92505b610800811615613feb5760606bd097f3bdfd2022b8845ad8f78402901c92505b61100081161561400b5760606ba9f746462d870fdf8a65dc1f8402901c92505b61200081161561402b5760606b70d869a156d2a1b890bb3df68402901c92505b61400081161561404b5760606b31be135f97d08fd9812315058402901c92505b61800081161561406b5760606b09aa508b5b7a84e1c677de548402901c92505b6201000081161561408b5760606a5d6af8dedb81196699c3298402901c92505b620200008116156140aa576060692216e584f5fa1ea926048402901c92505b620400008116156140c757606067048a170391f7dc428402901c92505b5f8260020b13156140f8576140f5837801000000000000000000000000000000000000000000000000615a7c565b92505b5050919050565b600282900b5f9081526003840160205260408120600401805464ffffffffff841690811061412f5761412f615a9b565b905f5260205f200190509392505050565b600281901c623fffff165f818152602084905260408120549091906003841690600685901b60c0161c67ffffffffffffffff1680151590035b95945050505050565b60015f9081526020829052604081205461419e90826004614873565b5f808052602084905260408120546141b7916004614873565b610c8e9190615aaf565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b5f80807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084111561424b57505f915060039050826142d0565b604080515f808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa15801561429c573d5f803e3d5ffd5b5050604051601f1901519150506001600160a01b0381166142c757505f9250600191508290506142d0565b92505f91508190505b9450945094915050565b5f8260038111156142ed576142ed615ad0565b036142f6575050565b600182600381111561430a5761430a615ad0565b03614341576040517ff645eedf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600282600381111561435557614355615ad0565b0361438f576040517ffce698f70000000000000000000000000000000000000000000000000000000081526004810182905260240161104e565b60038260038111156143a3576143a3615ad0565b03610d55576040517fd78bce0c0000000000000000000000000000000000000000000000000000000081526004810182905260240161104e565b606060ff83146143f7576143f0836148b3565b9050610c8e565b81805461440390615115565b80601f016020809104026020016040519081016040528092919081815260200182805461442f90615115565b801561447a5780601f106144515761010080835404028352916020019161447a565b820191905f5260205f20905b81548152906001019060200180831161445d57829003601f168201915b50505050509050610c8e565b62800000811901600881901c61ffff165f81815260208590526040812054909260ff1690600119821b1680840361458857600883901c80195f9081526020889052604081205460011960ff87161b169081900361455e575f888161450b7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b95460016153dc565b81526020019081526020015f205483600119901b169050805f0361453b57627fffff199650505050505050610c8e565b614544816148f0565b60ff1680195f90815260208b905260409020549093509150505b614567816148f0565b60ff16600883901b179450875f8681526020019081526020015f2054925050505b614591816148f0565b60ff16915062ffffff627fffff19600885901b84170119165b9695505050505050565b5f807a184f03e93ff9f4daa797ed6e38ed64bf6a1f01000000000000000083106145fc577a184f03e93ff9f4daa797ed6e38ed64bf6a1f010000000000000000830492506040015b6d04ee2d6d415b85acef81000000008310614628576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc10000831061464657662386f26fc10000830492506010015b6305f5e100831061465e576305f5e100830492506008015b612710831061467257612710830492506004015b60648310614684576064830492506002015b600a8310610c8e5760010192915050565b5f61469f82614780565b156146d6576040517f4f3d7def00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f61471a83826147077f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b95460016153dc565b81526020019081526020015f20546148f0565b60ff1690505f61473a845f841981526020019081526020015f20546148f0565b60ff16600883901b1790505f61475f855f8481526020019081526020015f20546148f0565b60ff16905062ffffff627fffff19600884901b831701191695945050505050565b5f81816147ae7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b95460016153dc565b81526020019081526020015f20545f149050919050565b5f805f6147d185614966565b9050602084015192505f80866001600160a01b0316866040516147f49190615ae4565b5f604051808303815f865af19150503d805f811461482d576040519150601f19603f3d011682016040523d82523d5f602084013e614832565b606091505b50915091508161484557614845816149f5565b8080602001905181019061485991906154a7565b9350821561486957614869614a2f565b5050509250929050565b600682901b9290921c915f825b828110156148a857604085901c9467ffffffffffffffff168015019190910190600101614880565b509190039003919050565b60605f6148bf83614a6f565b6040805160208082528183019092529192505f91906020820181803683375050509182525060208101929092525090565b5f8082116148fc575f80fd5b5f7e818283848586878898a8b8c8d8e8f929395969799a9b9d9e9faaeb6bedeeff600184190184160260f81c90506040518061012001604052806101008152602001615b106101009139818151811061495757614957615a9b565b016020015160f81c9392505050565b5f6001600160a01b036001600160801b035f80516020615af08339815191525c167ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be422015c1661346d575f80516020615af08339815191525c6001600160801b0316827ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be42282015d50600192915050565b80515f03613a4b576040517f36bc48c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f80516020615af08339815191525c6001600160801b03165f7ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be42282015d50565b5f60ff8216601f811115610c8e576040517fb3512b0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160e01b031981168114611d5a575f80fd5b5f60208284031215614ad4575f80fd5b8135611b0b81614aaf565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f611b0b6020830184614adf565b5f60208284031215614b2f575f80fd5b5035919050565b6001600160a01b0381168114611d5a575f80fd5b5f8060408385031215614b5b575f80fd5b8235614b6681614b36565b946020939093013593505050565b5f8083601f840112614b84575f80fd5b50813567ffffffffffffffff811115614b9b575f80fd5b602083019150836020828501011115614bb2575f80fd5b9250929050565b5f805f8385036060811215614bcc575f80fd5b6040811215614bd9575f80fd5b50839250604084013567ffffffffffffffff811115614bf6575f80fd5b614c0286828701614b74565b9497909650939450505050565b5f805f838503610140811215614c23575f80fd5b61012080821215614c32575f80fd5b859450840135905067ffffffffffffffff811115614bf6575f80fd5b5f60c08284031215611bc6575f80fd5b5f60c08284031215614c6e575f80fd5b611b0b8383614c4e565b5f805f60608486031215614c8a575f80fd5b8335614c9581614b36565b92506020840135614ca581614b36565b929592945050506040919091013590565b5f805f60408486031215614cc8575f80fd5b83359250602084013567ffffffffffffffff811115614bf6575f80fd5b5f60208284031215614cf5575f80fd5b8135611b0b81614b36565b5f805f838503610120811215614d14575f80fd5b61010080821215614c32575f80fd5b5f8060408385031215614d34575f80fd5b8235614d3f81614b36565b91506020830135614d4f81614b36565b809150509250929050565b80356001600160c01b038116811461346d575f80fd5b8035600281900b811461346d575f80fd5b5f8060408385031215614d92575f80fd5b614d9b83614d5a565b9150614da960208401614d70565b90509250929050565b5f60208284031215614dc2575f80fd5b611b0b82614d5a565b5f805f805f8060c08789031215614de0575f80fd5b8635614deb81614b36565b95506020870135945060408701359350606087013560ff81168114614e0e575f80fd5b9598949750929560808101359460a0909101359350915050565b7fff00000000000000000000000000000000000000000000000000000000000000881681525f602060e06020840152614e6460e084018a614adf565b8381036040850152614e76818a614adf565b606085018990526001600160a01b038816608086015260a0850187905284810360c0860152855180825260208088019350909101905f5b81811015614ec957835183529284019291840191600101614ead565b50909c9b505050505050505050505050565b60c08101610c8e82846001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b5f805f60408486031215614f54575f80fd5b8335614f5f81614b36565b9250602084013567ffffffffffffffff811115614bf6575f80fd5b5f8060408385031215614f8b575f80fd5b8235614f9681614b36565b915060208301358015158114614d4f575f80fd5b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f1916810167ffffffffffffffff81118282101715614fe757614fe7614faa565b604052919050565b5f67ffffffffffffffff82111561500857615008614faa565b50601f01601f191660200190565b5f805f8060808587031215615029575f80fd5b843561503481614b36565b9350602085013561504481614b36565b925060408501359150606085013567ffffffffffffffff811115615066575f80fd5b8501601f81018713615076575f80fd5b803561508961508482614fef565b614fbe565b81815288602083850101111561509d575f80fd5b816020840160208301375f6020838301015280935050505092959194509250565b5f80604083850312156150cf575f80fd5b50508035926020909101359150565b5f805f60e084860312156150f0575f80fd5b6150fa8585614c4e565b925060c084013567ffffffffffffffff811115614bf6575f80fd5b600181811c9082168061512957607f821691505b602082108103611bc657634e487b7160e01b5f52602260045260245ffd5b67ffffffffffffffff81168114611d5a575f80fd5b5f6020828403121561516c575f80fd5b8135611b0b81615147565b5f8060408385031215615188575f80fd5b825161519381615147565b6020840151909250614d4f81615147565b5f602082840312156151b4575f80fd5b611b0b82614d70565b803562ffffff8116811461346d575f80fd5b5f60c082840312156151df575f80fd5b60405160c0810181811067ffffffffffffffff8211171561520257615202614faa565b604052905080823561521381614b36565b8152602083013561522381615147565b6020820152604083013561523681614b36565b6040820152615247606084016151bd565b6060820152608083013561525a81614b36565b608082015261526b60a084016151bd565b60a08201525092915050565b5f60c08284031215615287575f80fd5b611b0b83836151cf565b5f61012082840312156152a2575f80fd5b6040516080810181811067ffffffffffffffff821117156152c5576152c5614faa565b6040526152d284846151cf565b81526152e060c08401614d70565b602082015260e08301356152f381615147565b604082015261010083013561530781614b36565b60608201529392505050565b5f60208284031215615323575f80fd5b815164ffffffffff81168114611b0b575f80fd5b5f60208284031215615347575f80fd5b611b0b826151bd565b634e487b7160e01b5f52601160045260245ffd5b5f7f8000000000000000000000000000000000000000000000000000000000000000820361539457615394615350565b505f0390565b5f602082840312156153aa575f80fd5b8151611b0b81615147565b8082018281125f8312801582168215821617156153d4576153d4615350565b505092915050565b80820180821115610c8e57610c8e615350565b81810381811115610c8e57610c8e615350565b5f6101008284031215615413575f80fd5b6040516060810181811067ffffffffffffffff8211171561543657615436614faa565b60405261544384846151cf565b815261545160c08401614d70565b602082015260e083013561546481615147565b60408201529392505050565b8181035f8312801583831316838312821617156125d2576125d2615350565b828152604060208201525f6131ea6040830184614adf565b5f602082840312156154b7575f80fd5b8151611b0b81614aaf565b81835281816020850137505f828201602090810191909152601f909101601f19169091010190565b6001600160a01b0384168152604060208201525f6141796040830184866154c2565b5f6020828403121561551c575f80fd5b815167ffffffffffffffff811115615532575f80fd5b8201601f81018413615542575f80fd5b805161555061508482614fef565b818152856020838501011115615564575f80fd5b8160208401602083015e5f91810160200191909152949350505050565b5f81518060208401855e5f93019283525090919050565b5f6131ea6155a68386615581565b84615581565b8082028115828204841417610c8e57610c8e615350565b82815260e0810182356155d581614b36565b6001600160a01b038082166020850152602085013591506155f582615147565b67ffffffffffffffff821660408501526040850135915061561582614b36565b8082166060850152615629606086016151bd565b915062ffffff80831660808601526080860135925061564783614b36565b81831660a08601528061565c60a088016151bd565b1660c08601525050509392505050565b80358252602081013561567e81615147565b67ffffffffffffffff81166020840152505050565b6001600160a01b03851681526156ac602082018561566c565b608060608201525f6145aa6080830184866154c2565b6001600160a01b03861681526156db602082018661566c565b67ffffffffffffffff8416606082015260a060808201525f61570160a0830184866154c2565b979650505050505050565b5f8160020b627fffff19810361572457615724615350565b5f0392915050565b6157908282516001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b602081015160020b60c0830152604081015167ffffffffffffffff1660e0830152606001516001600160a01b031661010090910152565b5f6101606001600160a01b03871683526157e4602084018761572c565b8061014084015261570181840185876154c2565b5f6101806001600160a01b0388168352615815602084018861572c565b8561014084015280610160840152612c7781840185876154c2565b6001600160a01b0385168152836020820152606060408201525f6145aa6060830184866154c2565b6001600160a01b038616815284602082015267ffffffffffffffff84166040820152608060608201525f6157016080830184866154c2565b6158f48282516001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b602081015160020b60c08301526040015167ffffffffffffffff1660e090910152565b5f6101406001600160a01b03871683526159346020840187615890565b8061012084015261570181840185876154c2565b5f6101606001600160a01b03881683526159656020840188615890565b67ffffffffffffffff861661012084015280610140840152612c7781840185876154c2565b67ffffffffffffffff8281168282160390808211156125d2576125d2615350565b5f602082840312156159bb575f80fd5b5051919050565b5f6001600160a01b038087168352808616602084015250836040830152608060608301526145aa6080830184614adf565b5f6101006001600160a01b0387168352615a6960208401876001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b8060e084015261570181840185876154c2565b5f82615a9657634e487b7160e01b5f52601260045260245ffd5b500490565b634e487b7160e01b5f52603260045260245ffd5b67ffffffffffffffff8181168382160190808211156125d2576125d2615350565b634e487b7160e01b5f52602160045260245ffd5b5f611b0b828461558156fe760a9a962ae3d184e99c0483cf5684fb3170f47116ca4f445c50209da4f4f9070001020903110a19042112290b311a3905412245134d2a550c5d32651b6d3a7506264262237d468514804e8d2b95569d0d495ea533a966b11c886eb93bc176c9071727374353637324837e9b47af86c7155181ad4fd18ed32c9096db57d59ee30e2e4a6a5f92a6be3498aae067ddb2eb1d5989b56fd7baf33ca0c2ee77e5caf7ff0810182028303840444c545c646c7425617c847f8c949c48a4a8b087b8c0c816365272829aaec650acd0d28fdad4e22d6991bd97dfdcea58b4d6f29fede4f6fe0f1f2f3f4b5b6b607b8b93a3a7b7bf357199c5abcfd9e168bcdee9b3f1ecf5fd1e3e5a7a8aa2b670c4ced8bbe8f0f4fc3d79a1c3cde7effb78cce6facbf9f8a264697066735822122064f09b2cf4df87a40a102856d4e12ddac16787c8abd3963f52a4293d32e4b81064736f6c634300081900330000000000000000000000004587dd6356d7293e5f10db4d853332bd5b218c0b000000000000000000000000cc92364b6b886158e71fd4e4da5c682d33d1491e00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000002f68747470733a2f2f736f6e69632e6d61726b65742f6170692f6e66742f636861696e732f3134362f6f72646572732f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c68747470733a2f2f736f6e69632e6d61726b65742f6170692f636f6e74726163742f636861696e732f31343600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022536f6e6963204d61726b6574204f72646572626f6f6b204d616b6572204f726465720000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012534f4e49432d4d41524b45542d4f524445520000000000000000000000000000
Deployed Bytecode
0x608060405260043610610353575f3560e01c80637ac2ff7b116101bd578063cdc92f2d116100f2578063e8a3d48511610092578063f2fde38b1161006d578063f2fde38b14610bd5578063f86a11b314610bf4578063fcc8fc9b14610c13578063fefc7c5114610c32575f80fd5b8063e8a3d48514610b5c578063e985e9c514610b70578063f035079914610bb7575f80fd5b8063d83747e8116100cd578063d83747e814610ae2578063d9caed1214610b01578063de4478ec14610b20578063e30c397814610b3f575f80fd5b8063cdc92f2d146109dd578063d09ef241146109fc578063d68f4dd114610a58575f80fd5b80639b22917d1161015d578063a179dadc11610138578063a179dadc1461094e578063a22cb46514610980578063b88d4fde1461099f578063c87b56dd146109be575f80fd5b80639b22917d146108335780639ca1799814610910578063a12ef25e1461092f575f80fd5b806393c85a211161019857806393c85a21146107b657806395d89b41146107e15780639611cf6c146107f55780639b19251a14610814575f80fd5b80637ac2ff7b1461075357806384b0196e146107725780638da5cb5b14610799575f80fd5b80633af32abf116102935780636352211e116102335780636c0360eb1161020e5780636c0360eb146106f857806370a082311461070c578063715018a61461072b57806379ba50971461073f575f80fd5b80636352211e146106a75780636a256b29146106c65780636b2cc75c146106d9575f80fd5b806341a8bb881161026e57806341a8bb88146105f857806342842e0e146106305780634c02bf0b1461064f57806355af6a3214610688575f80fd5b80633af32abf146105755780633b9500b0146105a35780633e547b06146105c2575f80fd5b80631dbef488116102fe5780632f584a6d116102d95780632f584a6d146104f057806330adf81f1461050f5780633644e5151461054257806338926b6d14610556575f80fd5b80631dbef488146104665780631ff63f931461049a57806323b872dd146104d1575f80fd5b8063095ea7b31161032e578063095ea7b3146103ea578063141a468c1461040b57806314d6a9eb14610447575f80fd5b806301ffc9a71461035e57806306fdde0314610392578063081812fc146103b3575f80fd5b3661035a57005b5f80fd5b348015610369575f80fd5b5061037d610378366004614ac4565b610c51565b60405190151581526020015b60405180910390f35b34801561039d575f80fd5b506103a6610c94565b6040516103899190614b0d565b3480156103be575f80fd5b506103d26103cd366004614b1f565b610d23565b6040516001600160a01b039091168152602001610389565b3480156103f5575f80fd5b50610409610404366004614b4a565b610d4a565b005b348015610416575f80fd5b50610439610425366004614b1f565b5f9081526009602052604090205460a01c90565b604051908152602001610389565b348015610452575f80fd5b50610439610461366004614bb9565b610d59565b348015610471575f80fd5b50610485610480366004614c0f565b610f9a565b60408051928352602083019190915201610389565b3480156104a5575f80fd5b506104b96104b4366004614c5e565b61138b565b6040516001600160c01b039091168152602001610389565b3480156104dc575f80fd5b506104096104eb366004614c78565b61139e565b3480156104fb575f80fd5b5061040961050a366004614c78565b611440565b34801561051a575f80fd5b506104397f49ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9ad81565b34801561054d575f80fd5b50610439611450565b348015610561575f80fd5b50610439610570366004614cb6565b61145e565b348015610580575f80fd5b5061037d61058f366004614ce5565b600f6020525f908152604090205460ff1681565b3480156105ae575f80fd5b506104856105bd366004614d00565b611821565b3480156105cd575f80fd5b506104396105dc366004614d23565b601060209081525f928352604080842090915290825290205481565b348015610603575f80fd5b50610617610612366004614d81565b611aea565b60405167ffffffffffffffff9091168152602001610389565b34801561063b575f80fd5b5061040961064a366004614c78565b611b12565b34801561065a575f80fd5b50604080515f80516020615af08339815191525c6001600160801b038116825260801c602082015201610389565b348015610693575f80fd5b5061037d6106a2366004614db2565b611b2c565b3480156106b2575f80fd5b506103d26106c1366004614b1f565b611b5c565b6104396106d4366004614ce5565b611b66565b3480156106e4575f80fd5b506104096106f3366004614ce5565b611bcc565b348015610703575f80fd5b506103a6611c1c565b348015610717575f80fd5b50610439610726366004614ce5565b611ca8565b348015610736575f80fd5b50610409611d06565b34801561074a575f80fd5b50610409611d19565b34801561075e575f80fd5b5061040961076d366004614dcb565b611d5d565b34801561077d575f80fd5b50610786611fbe565b6040516103899796959493929190614e28565b3480156107a4575f80fd5b506005546001600160a01b03166103d2565b3480156107c1575f80fd5b506104396107d0366004614ce5565b600d6020525f908152604090205481565b3480156107ec575f80fd5b506103a661201c565b348015610800575f80fd5b5061043961080f366004614d23565b61202b565b34801561081f575f80fd5b5061040961082e366004614ce5565b61203f565b34801561083e575f80fd5b5061090361084d366004614db2565b6040805160c0810182525f80825260208201819052918101829052606081018290526080810182905260a0810191909152506001600160c01b03165f908152600e6020908152604091829020825160c08101845281546001600160a01b03808216835267ffffffffffffffff600160a01b92839004169483019490945260018301548085169583019590955262ffffff94819004851660608301526002909201549283166080820152910490911660a082015290565b6040516103899190614edb565b34801561091b575f80fd5b506103a661092a366004614f42565b612092565b34801561093a575f80fd5b50610439610949366004614d23565b6121a6565b348015610959575f80fd5b5061096d610968366004614d81565b61225d565b60405160029190910b8152602001610389565b34801561098b575f80fd5b5061040961099a366004614f7a565b61227e565b3480156109aa575f80fd5b506104096109b9366004615016565b612289565b3480156109c9575f80fd5b506103a66109d8366004614b1f565b6122a0565b3480156109e8575f80fd5b5061096d6109f7366004614db2565b612304565b348015610a07575f80fd5b50610a1b610a16366004614b1f565b612324565b6040805182516001600160a01b0316815260208084015167ffffffffffffffff908116918301919091529282015190921690820152606001610389565b348015610a63575f80fd5b50610ac2610a72366004614b1f565b6002027f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b181015c917f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b29091015c90565b604080516001600160a01b03938416815292909116602083015201610389565b348015610aed575f80fd5b50600c546103d2906001600160a01b031681565b348015610b0c575f80fd5b50610409610b1b366004614c78565b612468565b348015610b2b575f80fd5b50610409610b3a366004614ce5565b6124ce565b348015610b4a575f80fd5b506006546001600160a01b03166103d2565b348015610b67575f80fd5b506103a66124df565b348015610b7b575f80fd5b5061037d610b8a366004614d23565b6001600160a01b039182165f90815260046020908152604080832093909416825291909152205460ff1690565b348015610bc2575f80fd5b50610439610bd1366004614b1f565b5490565b348015610be0575f80fd5b50610409610bef366004614ce5565b6124ec565b348015610bff575f80fd5b506103a6610c0e3660046150be565b61255d565b348015610c1e575f80fd5b5061037d610c2d366004614db2565b6125d9565b348015610c3d575f80fd5b50610409610c4c3660046150de565b6125f9565b5f6001600160e01b031982167f6831a4fd000000000000000000000000000000000000000000000000000000001480610c8e5750610c8e82612966565b92915050565b60605f8054610ca290615115565b80601f0160208091040260200160405190810160405280929190818152602001828054610cce90615115565b8015610d195780601f10610cf057610100808354040283529160200191610d19565b820191905f5260205f20905b815481529060010190602001808311610cfc57829003601f168201915b5050505050905090565b5f610d2d82612a00565b505f828152600360205260409020546001600160a01b0316610c8e565b610d55828233612a38565b5050565b5f610d6333612a45565b610d84610d7c85355f9081526009602052604090205490565b338635612b06565b8335604090811c5f908152600e602090815290829020825160c08101845281546001600160a01b03808216835267ffffffffffffffff600160a01b92839004169483019490945260018301548085169583019590955262ffffff9481900485166060830152600283015493841660808301819052930490931660a08401529190610e1090878787612b83565b5f80735489922f8312c812fbb7184ebf70b9dbfaeed9d4633ac502c1858a35610e3f60408d0160208e0161515c565b6040516001600160e01b031960e086901b1681526004810193909352602483019190915267ffffffffffffffff1660448201526064016040805180830381865af4158015610e8f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610eb39190615177565b91509150826020015167ffffffffffffffff168267ffffffffffffffff16029450610ee7836060015162ffffff1660171c90565b15610f0b5760608301515f90610f049062ffffff16876001612c03565b9590950194505b8067ffffffffffffffff165f03610f2657610f268835612c83565b610f34836040015186612cbb565b60405167ffffffffffffffff831681528835907f0c6ba7ef5064094c17cce013aa4c617a23e2582f867774d07a5931de43b85d729060200160405180910390a26080830151610f8f906001600160a01b031689848a8a612d02565b505050509392505050565b5f80610fa533612a45565b5f610fb861012087016101008801614ce5565b6001600160a01b031614158015610ffd5750600f5f610fdf61012088016101008901614ce5565b6001600160a01b0316815260208101919091526040015f205460ff16155b156110575761101461012086016101008701614ce5565b6040517f962715990000000000000000000000000000000000000000000000000000000081526001600160a01b0390911660048201526024015b60405180910390fd5b61107261106a60e0870160c088016151a4565b60020b612d8b565b5f61108a61108536889003880188615277565b612de7565b6001600160c01b0381165f908152600e602052604090209091506110ad81612e22565b6110e26110bf36899003890189615291565b87876110d160a08c0160808d01614ce5565b6001600160a01b0316929190612e6b565b5f735489922f8312c812fbb7184ebf70b9dbfaeed9d463ffa0afb58361110e60e08c0160c08d016151a4565b61111f6101008d0160e08e0161515c565b6111316101208e016101008f01614ce5565b6040516001600160e01b031960e087901b168152600481019490945260029290920b602484015267ffffffffffffffff1660448301526001600160a01b03166064820152608401602060405180830381865af4158015611193573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111b79190615313565b90506111e9836111cd60e08b0160c08c016151a4565b60409190911b60289190911b67ffffff00000000001601820190565b94505f6111fc60408a0160208b0161515c565b67ffffffffffffffff166112176101008b0160e08c0161515c565b67ffffffffffffffff1602945084905061124561123a60808b0160608c01615337565b62ffffff1660171c90565b156112705761126b855f61125f60808d0160608e01615337565b62ffffff169190612c03565b019350835b61129161128360608b0160408c01614ce5565b61128c83615364565b612cbb565b61129b3387612ea9565b336001600160c01b0385167f251db4df45fa692f68b4e3f072919384c5b71995c71bf22888385168930fd22a6112d760e08d0160c08e016151a4565b858d60e00160208101906112eb919061515c565b8e6101000160208101906112ff9190614ce5565b6040805160029590950b855264ffffffffff93909316602085015267ffffffffffffffff91909116838301526001600160a01b03166060830152519081900360800190a361137f611355368b90038b018b615291565b878a8a8d5f01608001602081019061136d9190614ce5565b6001600160a01b031693929190612f23565b50505050935093915050565b5f610c8e61108536849003840184615277565b6001600160a01b0382166113c757604051633250574960e11b81525f600482015260240161104e565b5f6113d3838333612f63565b9050836001600160a01b0316816001600160a01b03161461143a576040517f64283d7b0000000000000000000000000000000000000000000000000000000081526001600160a01b038086166004830152602482018490528216604482015260640161104e565b50505050565b61144b838383612b06565b505050565b5f611459613062565b905090565b5f61146833612a45565b5f84815260096020526040902054611481903386612b06565b604084811c5f908152600e602090815290829020825160c08101845281546001600160a01b03808216835267ffffffffffffffff600160a01b92839004169483019490945260018301548085169583019590955262ffffff94819004851660608301526002830154938416608083018190529304841660a0820152602888901c9093169264ffffffffff88169261151a9089898961318b565b6040517fc49d262100000000000000000000000000000000000000000000000000000000815260048101839052600285900b602482015264ffffffffff841660448201525f90735489922f8312c812fbb7184ebf70b9dbfaeed9d49063c49d262190606401602060405180830381865af415801561159a573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115be919061539a565b60208301519091505f90819067ffffffffffffffff8085169116026115e8600289900b82846131c8565b606086015160a0870151919a509061160562ffffff821660171c90565b156116225761161b62ffffff8216846001612c03565b9450611636565b61163362ffffff82168c6001612c03565b93505b6116458262ffffff1660171c90565b1561166c5761165b62ffffff8316846001612c03565b61166590866153b5565b94506116b8565b5f61167d62ffffff84168d83612c03565b905061168981866153b5565b94505f81136116aa5761169b81615364565b6116a5908d6153dc565b6116b4565b6116b4818d6153ef565b9b50505b505f91506116c990508689896131f2565b80519091506001600160a01b0381166116ea5750600c546001600160a01b03165b5f84131561173b576116fb84613246565b6001600160a01b038083165f9081526010602090815260408083208b820151909416835292905290812080549091906117359084906153dc565b90915550505b5f83131561178a5761174c83613246565b6001600160a01b038083165f9081526010602090815260408083208b51909416835292905290812080549091906117849084906153dc565b90915550505b816020015167ffffffffffffffff165f036117a8576117a88d612c83565b85516117b79061128c8c613288565b60405167ffffffffffffffff861681528d907ffc7df80a30ee916cc040221cf6fcfb3c6dc994b3fa4c4ab23e8a0f134de5c0c09060200160405180910390a26080860151611811906001600160a01b03168e878f8f6132e6565b5050505050505050509392505050565b5f8061182c33612a45565b61183f61106a60e0870160c088016151a4565b5f61185261108536889003880188615277565b6001600160c01b0381165f908152600e6020526040902090915061187581612e22565b6118aa61188736899003890189615402565b878761189960a08c0160808d01614ce5565b6001600160a01b0316929190613325565b5f735489922f8312c812fbb7184ebf70b9dbfaeed9d463a151a7e1836118d660e08c0160c08d016151a4565b6118e76101008d0160e08e0161515c565b6040516001600160e01b031960e086901b168152600481019390935260029190910b602483015267ffffffffffffffff166044820152606401602060405180830381865af415801561193b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061195f919061539a565b90506119716040890160208a0161515c565b67ffffffffffffffff82811691160294506119a285600161199860e08c0160c08d016151a4565b60020b91906131c8565b9350845f6119af86613288565b90506119c461123a60c08c0160a08d01615337565b156119f2576119de875f61125f60c08e0160a08f01615337565b6119e89083615470565b9150819650611a17565b611a07865f61125f60c08e0160a08f01615337565b611a1190826153b5565b90508095505b611a30611a2a60608c0160408d01614ce5565b83612cbb565b611a4061128360208c018c614ce5565b336001600160c01b0386167fc4c20b9c4a5ada3b01b7a391a08dd81a1be01dd8ef63170dd9da44ecee3db11b611a7c60e08e0160c08f016151a4565b6040805160029290920b825267ffffffffffffffff881660208301520160405180910390a3611add611ab3368c90038c018c615402565b848b8b8e5f016080016020810190611acb9190614ce5565b6001600160a01b031693929190613363565b5050505050935093915050565b6001600160c01b0382165f908152600e60205260408120611b0b90836133a3565b9392505050565b61144b83838360405180602001604052805f815250612289565b6001600160c01b0381165f908152600e6020526040812054600160a01b900467ffffffffffffffff161515610c8e565b5f610c8e82612a00565b5f611b7033612a45565b6001600160a01b0382165f818152600d602052604090205490611b92906133d8565b6001600160a01b0384165f908152600d60205260409020819055611bb79082906153ef565b9150611bc68361128c84613288565b50919050565b611bd4613472565b6001600160a01b0381165f818152600f6020526040808220805460ff19169055517f88f58aa68e1f754fecfec41a6758d18d4a53fa15d4e206fd54bbdfe7a9e98da79190a250565b600a8054611c2990615115565b80601f0160208091040260200160405190810160405280929190818152602001828054611c5590615115565b8015611ca05780601f10611c7757610100808354040283529160200191611ca0565b820191905f5260205f20905b815481529060010190602001808311611c8357829003601f168201915b505050505081565b5f6001600160a01b038216611ceb576040517f89c62b640000000000000000000000000000000000000000000000000000000081525f600482015260240161104e565b506001600160a01b03165f9081526002602052604090205490565b611d0e613472565b611d175f61349f565b565b60065433906001600160a01b03168114611d515760405163118cdaa760e01b81526001600160a01b038216600482015260240161104e565b611d5a8161349f565b50565b83421115611d97576040517f1a15a3cc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f611e147f49ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9ad8888611dc7816134b8565b6040805160208101959095526001600160a01b03909316928401929092526060830152608082015260a0810187905260c001604051602081830303815290604052805190602001206134f1565b90505f611e2087611b5c565b9050806001600160a01b0316886001600160a01b031603611e5457604051638baa579f60e01b815260040160405180910390fd5b6001600160a01b0381163b15611f6a57604080516020810186905280820185905260f887901b7fff000000000000000000000000000000000000000000000000000000000000001660608201528151604181830301815260618201928390527f1626ba7e000000000000000000000000000000000000000000000000000000009092526001600160a01b03831691631626ba7e91611ef691869160650161548f565b602060405180830381865afa158015611f11573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f3591906154a7565b6001600160e01b031916631626ba7e60e01b14611f6557604051638baa579f60e01b815260040160405180910390fd5b611fa7565b806001600160a01b0316611f8083878787613538565b6001600160a01b031614611fa757604051638baa579f60e01b815260040160405180910390fd5b611fb48888836001613564565b5050505050505050565b5f6060805f805f6060611fcf61369f565b611fd76136cc565b604080515f808252602082019092527f0f000000000000000000000000000000000000000000000000000000000000009b939a50919850469750309650945092509050565b606060018054610ca290615115565b5f611b0b83836014525f526028600c205c90565b612047613472565b6001600160a01b0381165f818152600f6020526040808220805460ff19166001179055517feb73900b98b6a3e2b8b01708fe544760cf570d21e7fbe5225f24e48b5b2b432e9190a250565b606061209e84336136f9565b6040517f15c7afb40000000000000000000000000000000000000000000000000000000081526001600160a01b038516906315c7afb4906120e7903390879087906004016154ea565b5f604051808303815f875af1158015612102573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052612129919081019061550c565b9050612133613759565b5f80516020615af08339815191525c6001600160801b0381169060801c8115801561216657506001600160801b03811615155b1561219d576040517f5212cba100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50509392505050565b335f9081526010602090815260408083206001600160a01b03851684528252808320805490849055600d90925282208054919283926121e69084906153ef565b9091555061220090506001600160a01b03831684836137ce565b816001600160a01b0316836001600160a01b0316336001600160a01b03167f1c4f94f28cc9152354d4b98b8614b28c6c828a98d88228fa9577c7b9475e120c8460405161224f91815260200190565b60405180910390a492915050565b6001600160c01b0382165f908152600e60205260408120611b0b90836138ab565b610d553383836138b9565b61229484848461139e565b61143a84848484613970565b60606122ab82612a00565b505f6122b5613a8f565b90505f8151116122d35760405180602001604052805f815250611b0b565b806122dd84613a9e565b6040516020016122ee929190615598565b6040516020818303038152906040529392505050565b6001600160c01b0381165f908152600e60205260408120610c8e90613b3b565b604080516060810182525f808252602080830182905282840182905284841c808352600e909152928120919291602885901c62ffffff169164ffffffffff861691906123718285856131f2565b6040517f329b4a0100000000000000000000000000000000000000000000000000000000815260048101849052600286900b602482015264ffffffffff851660448201529091505f90735489922f8312c812fbb7184ebf70b9dbfaeed9d49063329b4a0190606401602060405180830381865af41580156123f4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612418919061539a565b90506040518060600160405280835f01516001600160a01b031681526020018284602001510367ffffffffffffffff1681526020018267ffffffffffffffff168152509650505050505050919050565b61247133612a45565b801561144b5761248d8361248483613288565b61128c90615364565b6001600160a01b0383165f908152600d6020526040812080548392906124b49084906153ef565b9091555061144b90506001600160a01b03841683836137ce565b6124d6613472565b611d5a81613b48565b600b8054611c2990615115565b6124f4613472565b600680546001600160a01b0383166001600160a01b031990911681179091556125256005546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b606061256a8260206155ac565b67ffffffffffffffff81111561258257612582614faa565b6040519080825280601f01601f1916602001820160405280156125ac576020820181803683370190505b5090505f5b828110156125d25780840154602060018301028301526001810190506125b1565b5092915050565b6001600160c01b0381165f908152600e60205260408120610c8e90613b91565b61260233612a45565b612612604084016020850161515c565b67ffffffffffffffff165f03612654576040517faf6c36ab00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6126656080850160608601615337565b90505f61267860c0860160a08701615337565b90506126888262ffffff16613b9e565b801561269d575061269d8162ffffff16613b9e565b6126ba57604051637a34030f60e01b815260040160405180910390fd5b5f620f423f19627fffff848116908416010160020b12156126ee57604051637a34030f60e01b815260040160405180910390fd5b5f627fffff83166207a11f190160020b128061271757505f627fffff82166207a11f190160020b125b1561275c5761272b8162ffffff1660171c90565b151561273c8362ffffff1660171c90565b15151461275c57604051637a34030f60e01b815260040160405180910390fd5b5f61276d60a0870160808801614ce5565b9050612781816001600160a01b0316613bce565b6127c2576040517fe65af6a00000000000000000000000000000000000000000000000000000000081526001600160a01b038216600482015260240161104e565b6127e66127d436889003880188615277565b6001600160a01b038316908787613c05565b5f6127f961108536899003890189615277565b6001600160c01b0381165f908152600e60205260409081902090517fab8a7e3f000000000000000000000000000000000000000000000000000000008152919250735489922f8312c812fbb7184ebf70b9dbfaeed9d49163ab8a7e3f91612864918b906004016155c3565b5f6040518083038186803b15801561287a575f80fd5b505af415801561288c573d5f803e3d5ffd5b506128a1925050506060880160408901614ce5565b6001600160a01b03166128b76020890189614ce5565b6001600160a01b03166001600160c01b0383167f803427d75ce3214f82dc7aa4910635170a6655e2c1663dc03429dd04100cba5a6128fb60408c0160208d0161515c565b6040805167ffffffffffffffff909216825262ffffff808b1660208401528916908201526001600160a01b038716606082015260800160405180910390a461295d61294b36899003890189615277565b6001600160a01b038416908888613c43565b50505050505050565b5f6001600160e01b031982167f80ac58cd0000000000000000000000000000000000000000000000000000000014806129c857506001600160e01b031982167f5b5e139f00000000000000000000000000000000000000000000000000000000145b80610c8e57507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b0319831614610c8e565b5f818152600960205260408120546001600160a01b038116610c8e57604051637e27328960e01b81526004810184905260240161104e565b61144b8383836001613564565b5f612a4e613c81565b90506001600160801b035f80516020615af08339815191525c167ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be422015c6001600160a01b0380831690841603612aa357505050565b806001600160a01b0316836001600160a01b031603612ac157505050565b6040517f74d863650000000000000000000000000000000000000000000000000000000081526001600160a01b0380841660048301528216602482015260440161104e565b612b11838383613cd6565b61144b576001600160a01b038316612b3f57604051637e27328960e01b81526004810182905260240161104e565b6040517f177e802f0000000000000000000000000000000000000000000000000000000081526001600160a01b03831660048201526024810182905260440161104e565b73020000000000000000000000000000000000000084161561143a5761143a63295b52c560e01b33858585604051602401612bc19493929190615693565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526001600160a01b03861690613d56565b5f6207a11f19627fffff851601600281900b82128281612c2557825f03612c27565b825b62ffffff1690505f612c60612c3c83896155ac565b620f424088612c52578581830615151691040190565b808206151586151691040190565b905082612c7557612c7081615364565b612c77565b805b98975050505050505050565b5f612c8f5f835f612f63565b90506001600160a01b038116610d5557604051637e27328960e01b81526004810183905260240161104e565b805f03612cc6575050565b5f612ccf613c81565b90505f612cdd828585613db3565b9050805f03612cf357612cee613dd1565b61143a565b82810361143a5761143a613e04565b730100000000000000000000000000000000000000851615612d8457612d84635125ce9c60e01b3386868686604051602401612d429594939291906156c2565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526001600160a01b03871690613d56565b5050505050565b6207ffff600282900b1380612db05750612da76207ffff61570c565b60020b8160020b125b15611d5a576040517fce8ef7fc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8082604051602001612dfa9190614edb565b60408051601f1981840301815291905280516020909101206001600160c01b03169392505050565b8054600160a01b900467ffffffffffffffff16611d5a576040517f1e3636e600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73200000000000000000000000000000000000000084161561143a5761143a633fda46bb60e01b33858585604051602401612bc194939291906157c7565b6001600160a01b038216612ed257604051633250574960e11b81525f600482015260240161104e565b5f612ede83835f612f63565b90506001600160a01b0381161561144b576040517f73c6ac6e0000000000000000000000000000000000000000000000000000000081525f600482015260240161104e565b731000000000000000000000000000000000000000851615612d8457612d8463eba8155960e01b3386868686604051602401612d429594939291906157f8565b5f828152600960205260408120546001600160a01b03831615612f8b57612f8b818486612b06565b6001600160a01b03811615612fc557612fa65f855f80613564565b6001600160a01b0381165f90815260026020526040902080545f190190555b6001600160a01b03851615612ff3576001600160a01b0385165f908152600260205260409020805460010190555b5f84815260096020526040902080546001600160a01b0319166001600160a01b03871617905583856001600160a01b0316826001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4949350505050565b5f306001600160a01b037f000000000000000000000000d4ad5ed9e1436904624b6db8b1be31f36317c636161480156130ba57507f000000000000000000000000000000000000000000000000000000000000009246145b156130e457507fb48fc330d60bb7619feea5289d78c2fd0e5c7576d211c0c0c4e470582e86db3490565b611459604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f75be1fec1bd1466097211759efa67a9b8bbd0c3d59967403e1b47406a219fcdd918101919091527fad7c5bef027816a800da1736444fb58a807ef4c9603b7848673f7e3a68eb14a560608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b728000000000000000000000000000000000000084161561143a5761143a63827e0eb260e01b33858585604051602401612bc19493929190615830565b5f6131ea606084901b6131dd8660020b613e37565b8082061515851691040190565b949350505050565b604080518082019091525f80825260208201526132108484846140ff565b6040805180820190915290546001600160a01b0381168252600160a01b900467ffffffffffffffff166020820152949350505050565b5f80821215613284576040517fa8ce44320000000000000000000000000000000000000000000000000000000081526004810183905260240161104e565b5090565b5f7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821115613284576040517f24775e060000000000000000000000000000000000000000000000000000000081526004810183905260240161104e565b7240000000000000000000000000000000000000851615612d8457612d846348042cf460e01b3386868686604051602401612d42959493929190615858565b73080000000000000000000000000000000000000084161561143a5761143a63fab3c75660e01b33858585604051602401612bc19493929190615917565b730400000000000000000000000000000000000000851615612d8457612d84639eb477b260e01b3386868686604051602401612d42959493929190615948565b5f6133b16005840183614140565b600283900b5f90815260038501602052604090206133ce90614182565b611b0b919061598a565b5f6001600160a01b0382166133ee575047919050565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa158015613449573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c8e91906159ab565b919050565b6005546001600160a01b03163314611d175760405163118cdaa760e01b815233600482015260240161104e565b600680546001600160a01b0319169055611d5a816141c1565b5f8181526009602052604090205460a081901c906134da81600160a01b6153dc565b5f9384526009602052604090932092909255919050565b5f610c8e6134fd613062565b836040517f19010000000000000000000000000000000000000000000000000000000000008152600281019290925260228201526042902090565b5f805f8061354888888888614212565b92509250925061355882826142da565b50909695505050505050565b808061357857506001600160a01b03821615155b15613670575f61358784612a00565b90506001600160a01b038316158015906135b35750826001600160a01b0316816001600160a01b031614155b80156135e457506001600160a01b038082165f9081526004602090815260408083209387168352929052205460ff16155b15613626576040517fa9fbf51f0000000000000000000000000000000000000000000000000000000081526001600160a01b038416600482015260240161104e565b811561366e5783856001600160a01b0316826001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45b505b50505f90815260036020526040902080546001600160a01b0319166001600160a01b0392909216919091179055565b60606114597f00000000000000000000000000000000000000000000000000000000000000ff60076143dd565b60606114597f320000000000000000000000000000000000000000000000000000000000000160086143dd565b5f80516020615af08339815191525c7f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b160026001600160801b038316020183815d82600182015d50600181015f80516020615af08339815191525d505050565b5f80516020615af08339815191525c6001600160801b038116806137845763f1c77ed05f526004601cfd5b7f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b15f19909101600202015f815d5f600182015d50600181035f80516020615af08339815191525d50565b5f6001600160a01b03841661381e575f805f8085875af1905080612cee576040517ff4b3b1bc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517fa9059cbb0000000000000000000000000000000000000000000000000000000081526001600160a01b038416600482015282602482015260205f6044835f895af13d15601f3d1160015f51141617169150508061143a576040517ff27f64e400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f611b0b6004840183614486565b6001600160a01b038216613904576040517f5b08ba180000000000000000000000000000000000000000000000000000000081526001600160a01b038316600482015260240161104e565b6001600160a01b038381165f81815260046020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6001600160a01b0383163b1561143a57604051630a85bd0160e11b81526001600160a01b0384169063150b7a02906139b29033908890879087906004016159c2565b6020604051808303815f875af19250505080156139ec575060408051601f3d908101601f191682019092526139e9918101906154a7565b60015b613a53573d808015613a19576040519150601f19603f3d011682016040523d82523d5f602084013e613a1e565b606091505b5080515f03613a4b57604051633250574960e11b81526001600160a01b038516600482015260240161104e565b805181602001fd5b6001600160e01b03198116630a85bd0160e11b14612d8457604051633250574960e11b81526001600160a01b038516600482015260240161104e565b6060600a8054610ca290615115565b60605f613aaa836145b4565b60010190505f8167ffffffffffffffff811115613ac957613ac9614faa565b6040519080825280601f01601f191660200182016040528015613af3576020820181803683370190505b5090508181016020015b5f19017f3031323334353637383961626364656600000000000000000000000000000000600a86061a8153600a8504945084613afd57509392505050565b5f610c8e82600401614695565b600c80546001600160a01b0319166001600160a01b0383169081179091556040517fef673bbfc2ac7e4d4b810bffda0b15a1f2b48c2aa4d178d3fca87d0d1f337062905f90a250565b5f610c8e82600401614780565b5f6207a11f19627fffff8316016207a120600282900b1380613bc657506207a11f198160020b125b159392505050565b5f6001600160a01b0382161580610c8e57505072400000000000000000000000000000000000006001600160a01b03909116101590565b73800000000000000000000000000000000000000084161561143a5761143a635df4d91860e01b33858585604051602401612bc194939291906159f3565b73400000000000000000000000000000000000000084161561143a5761143a6371ded94360e01b33858585604051602401612bc194939291906159f3565b5f5f80516020615af08339815191525c6001600160801b031680613ca5575f613cd0565b60025f198201027f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b1015c5b91505090565b5f6001600160a01b038316158015906131ea5750826001600160a01b0316846001600160a01b03161480613d2e57506001600160a01b038085165f9081526004602090815260408083209387168352929052205460ff165b806131ea5750505f908152600360205260409020546001600160a01b03908116911614919050565b5f80613d6284846147c5565b91509150816001600160e01b031916816001600160e01b0319161461143a576040517f1e048e1d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f82601452835f526028600c2082815c01915081815d509392505050565b7001000000000000000000000000000000005f80516020615af08339815191525c035f80516020615af08339815191525d565b7001000000000000000000000000000000005f80516020615af08339815191525c015f80516020615af08339815191525d565b5f613e4182612d8b565b815f600282900b8113613e545781613e5d565b613e5d8261570c565b62ffffff8116915060011615613e81576bfff97272373d413259a469909250613e92565b6c0100000000000000000000000092505b6002811615613eb15760606bfff2e50f5f656932ef12357c8402901c92505b6004811615613ed05760606bffe5caca7e10e4e61c3624ea8402901c92505b6008811615613eef5760606bffcb9843d60f6159c9db58838402901c92505b6010811615613f0e5760606bff973b41fa98c081472e68968402901c92505b6020811615613f2d5760606bff2ea16466c96a3843ec78b38402901c92505b6040811615613f4c5760606bfe5dee046a99a2a811c461f18402901c92505b6080811615613f6b5760606bfcbe86c7900a88aedcffc83b8402901c92505b610100811615613f8b5760606bf987a7253ac413176f2b074c8402901c92505b610200811615613fab5760606bf3392b0822b70005940c7a398402901c92505b610400811615613fcb5760606be7159475a2c29b7443b29c7f8402901c92505b610800811615613feb5760606bd097f3bdfd2022b8845ad8f78402901c92505b61100081161561400b5760606ba9f746462d870fdf8a65dc1f8402901c92505b61200081161561402b5760606b70d869a156d2a1b890bb3df68402901c92505b61400081161561404b5760606b31be135f97d08fd9812315058402901c92505b61800081161561406b5760606b09aa508b5b7a84e1c677de548402901c92505b6201000081161561408b5760606a5d6af8dedb81196699c3298402901c92505b620200008116156140aa576060692216e584f5fa1ea926048402901c92505b620400008116156140c757606067048a170391f7dc428402901c92505b5f8260020b13156140f8576140f5837801000000000000000000000000000000000000000000000000615a7c565b92505b5050919050565b600282900b5f9081526003840160205260408120600401805464ffffffffff841690811061412f5761412f615a9b565b905f5260205f200190509392505050565b600281901c623fffff165f818152602084905260408120549091906003841690600685901b60c0161c67ffffffffffffffff1680151590035b95945050505050565b60015f9081526020829052604081205461419e90826004614873565b5f808052602084905260408120546141b7916004614873565b610c8e9190615aaf565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b5f80807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084111561424b57505f915060039050826142d0565b604080515f808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa15801561429c573d5f803e3d5ffd5b5050604051601f1901519150506001600160a01b0381166142c757505f9250600191508290506142d0565b92505f91508190505b9450945094915050565b5f8260038111156142ed576142ed615ad0565b036142f6575050565b600182600381111561430a5761430a615ad0565b03614341576040517ff645eedf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600282600381111561435557614355615ad0565b0361438f576040517ffce698f70000000000000000000000000000000000000000000000000000000081526004810182905260240161104e565b60038260038111156143a3576143a3615ad0565b03610d55576040517fd78bce0c0000000000000000000000000000000000000000000000000000000081526004810182905260240161104e565b606060ff83146143f7576143f0836148b3565b9050610c8e565b81805461440390615115565b80601f016020809104026020016040519081016040528092919081815260200182805461442f90615115565b801561447a5780601f106144515761010080835404028352916020019161447a565b820191905f5260205f20905b81548152906001019060200180831161445d57829003601f168201915b50505050509050610c8e565b62800000811901600881901c61ffff165f81815260208590526040812054909260ff1690600119821b1680840361458857600883901c80195f9081526020889052604081205460011960ff87161b169081900361455e575f888161450b7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b95460016153dc565b81526020019081526020015f205483600119901b169050805f0361453b57627fffff199650505050505050610c8e565b614544816148f0565b60ff1680195f90815260208b905260409020549093509150505b614567816148f0565b60ff16600883901b179450875f8681526020019081526020015f2054925050505b614591816148f0565b60ff16915062ffffff627fffff19600885901b84170119165b9695505050505050565b5f807a184f03e93ff9f4daa797ed6e38ed64bf6a1f01000000000000000083106145fc577a184f03e93ff9f4daa797ed6e38ed64bf6a1f010000000000000000830492506040015b6d04ee2d6d415b85acef81000000008310614628576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc10000831061464657662386f26fc10000830492506010015b6305f5e100831061465e576305f5e100830492506008015b612710831061467257612710830492506004015b60648310614684576064830492506002015b600a8310610c8e5760010192915050565b5f61469f82614780565b156146d6576040517f4f3d7def00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f61471a83826147077f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b95460016153dc565b81526020019081526020015f20546148f0565b60ff1690505f61473a845f841981526020019081526020015f20546148f0565b60ff16600883901b1790505f61475f855f8481526020019081526020015f20546148f0565b60ff16905062ffffff627fffff19600884901b831701191695945050505050565b5f81816147ae7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b95460016153dc565b81526020019081526020015f20545f149050919050565b5f805f6147d185614966565b9050602084015192505f80866001600160a01b0316866040516147f49190615ae4565b5f604051808303815f865af19150503d805f811461482d576040519150601f19603f3d011682016040523d82523d5f602084013e614832565b606091505b50915091508161484557614845816149f5565b8080602001905181019061485991906154a7565b9350821561486957614869614a2f565b5050509250929050565b600682901b9290921c915f825b828110156148a857604085901c9467ffffffffffffffff168015019190910190600101614880565b509190039003919050565b60605f6148bf83614a6f565b6040805160208082528183019092529192505f91906020820181803683375050509182525060208101929092525090565b5f8082116148fc575f80fd5b5f7e818283848586878898a8b8c8d8e8f929395969799a9b9d9e9faaeb6bedeeff600184190184160260f81c90506040518061012001604052806101008152602001615b106101009139818151811061495757614957615a9b565b016020015160f81c9392505050565b5f6001600160a01b036001600160801b035f80516020615af08339815191525c167ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be422015c1661346d575f80516020615af08339815191525c6001600160801b0316827ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be42282015d50600192915050565b80515f03613a4b576040517f36bc48c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f80516020615af08339815191525c6001600160801b03165f7ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be42282015d50565b5f60ff8216601f811115610c8e576040517fb3512b0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160e01b031981168114611d5a575f80fd5b5f60208284031215614ad4575f80fd5b8135611b0b81614aaf565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f611b0b6020830184614adf565b5f60208284031215614b2f575f80fd5b5035919050565b6001600160a01b0381168114611d5a575f80fd5b5f8060408385031215614b5b575f80fd5b8235614b6681614b36565b946020939093013593505050565b5f8083601f840112614b84575f80fd5b50813567ffffffffffffffff811115614b9b575f80fd5b602083019150836020828501011115614bb2575f80fd5b9250929050565b5f805f8385036060811215614bcc575f80fd5b6040811215614bd9575f80fd5b50839250604084013567ffffffffffffffff811115614bf6575f80fd5b614c0286828701614b74565b9497909650939450505050565b5f805f838503610140811215614c23575f80fd5b61012080821215614c32575f80fd5b859450840135905067ffffffffffffffff811115614bf6575f80fd5b5f60c08284031215611bc6575f80fd5b5f60c08284031215614c6e575f80fd5b611b0b8383614c4e565b5f805f60608486031215614c8a575f80fd5b8335614c9581614b36565b92506020840135614ca581614b36565b929592945050506040919091013590565b5f805f60408486031215614cc8575f80fd5b83359250602084013567ffffffffffffffff811115614bf6575f80fd5b5f60208284031215614cf5575f80fd5b8135611b0b81614b36565b5f805f838503610120811215614d14575f80fd5b61010080821215614c32575f80fd5b5f8060408385031215614d34575f80fd5b8235614d3f81614b36565b91506020830135614d4f81614b36565b809150509250929050565b80356001600160c01b038116811461346d575f80fd5b8035600281900b811461346d575f80fd5b5f8060408385031215614d92575f80fd5b614d9b83614d5a565b9150614da960208401614d70565b90509250929050565b5f60208284031215614dc2575f80fd5b611b0b82614d5a565b5f805f805f8060c08789031215614de0575f80fd5b8635614deb81614b36565b95506020870135945060408701359350606087013560ff81168114614e0e575f80fd5b9598949750929560808101359460a0909101359350915050565b7fff00000000000000000000000000000000000000000000000000000000000000881681525f602060e06020840152614e6460e084018a614adf565b8381036040850152614e76818a614adf565b606085018990526001600160a01b038816608086015260a0850187905284810360c0860152855180825260208088019350909101905f5b81811015614ec957835183529284019291840191600101614ead565b50909c9b505050505050505050505050565b60c08101610c8e82846001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b5f805f60408486031215614f54575f80fd5b8335614f5f81614b36565b9250602084013567ffffffffffffffff811115614bf6575f80fd5b5f8060408385031215614f8b575f80fd5b8235614f9681614b36565b915060208301358015158114614d4f575f80fd5b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f1916810167ffffffffffffffff81118282101715614fe757614fe7614faa565b604052919050565b5f67ffffffffffffffff82111561500857615008614faa565b50601f01601f191660200190565b5f805f8060808587031215615029575f80fd5b843561503481614b36565b9350602085013561504481614b36565b925060408501359150606085013567ffffffffffffffff811115615066575f80fd5b8501601f81018713615076575f80fd5b803561508961508482614fef565b614fbe565b81815288602083850101111561509d575f80fd5b816020840160208301375f6020838301015280935050505092959194509250565b5f80604083850312156150cf575f80fd5b50508035926020909101359150565b5f805f60e084860312156150f0575f80fd5b6150fa8585614c4e565b925060c084013567ffffffffffffffff811115614bf6575f80fd5b600181811c9082168061512957607f821691505b602082108103611bc657634e487b7160e01b5f52602260045260245ffd5b67ffffffffffffffff81168114611d5a575f80fd5b5f6020828403121561516c575f80fd5b8135611b0b81615147565b5f8060408385031215615188575f80fd5b825161519381615147565b6020840151909250614d4f81615147565b5f602082840312156151b4575f80fd5b611b0b82614d70565b803562ffffff8116811461346d575f80fd5b5f60c082840312156151df575f80fd5b60405160c0810181811067ffffffffffffffff8211171561520257615202614faa565b604052905080823561521381614b36565b8152602083013561522381615147565b6020820152604083013561523681614b36565b6040820152615247606084016151bd565b6060820152608083013561525a81614b36565b608082015261526b60a084016151bd565b60a08201525092915050565b5f60c08284031215615287575f80fd5b611b0b83836151cf565b5f61012082840312156152a2575f80fd5b6040516080810181811067ffffffffffffffff821117156152c5576152c5614faa565b6040526152d284846151cf565b81526152e060c08401614d70565b602082015260e08301356152f381615147565b604082015261010083013561530781614b36565b60608201529392505050565b5f60208284031215615323575f80fd5b815164ffffffffff81168114611b0b575f80fd5b5f60208284031215615347575f80fd5b611b0b826151bd565b634e487b7160e01b5f52601160045260245ffd5b5f7f8000000000000000000000000000000000000000000000000000000000000000820361539457615394615350565b505f0390565b5f602082840312156153aa575f80fd5b8151611b0b81615147565b8082018281125f8312801582168215821617156153d4576153d4615350565b505092915050565b80820180821115610c8e57610c8e615350565b81810381811115610c8e57610c8e615350565b5f6101008284031215615413575f80fd5b6040516060810181811067ffffffffffffffff8211171561543657615436614faa565b60405261544384846151cf565b815261545160c08401614d70565b602082015260e083013561546481615147565b60408201529392505050565b8181035f8312801583831316838312821617156125d2576125d2615350565b828152604060208201525f6131ea6040830184614adf565b5f602082840312156154b7575f80fd5b8151611b0b81614aaf565b81835281816020850137505f828201602090810191909152601f909101601f19169091010190565b6001600160a01b0384168152604060208201525f6141796040830184866154c2565b5f6020828403121561551c575f80fd5b815167ffffffffffffffff811115615532575f80fd5b8201601f81018413615542575f80fd5b805161555061508482614fef565b818152856020838501011115615564575f80fd5b8160208401602083015e5f91810160200191909152949350505050565b5f81518060208401855e5f93019283525090919050565b5f6131ea6155a68386615581565b84615581565b8082028115828204841417610c8e57610c8e615350565b82815260e0810182356155d581614b36565b6001600160a01b038082166020850152602085013591506155f582615147565b67ffffffffffffffff821660408501526040850135915061561582614b36565b8082166060850152615629606086016151bd565b915062ffffff80831660808601526080860135925061564783614b36565b81831660a08601528061565c60a088016151bd565b1660c08601525050509392505050565b80358252602081013561567e81615147565b67ffffffffffffffff81166020840152505050565b6001600160a01b03851681526156ac602082018561566c565b608060608201525f6145aa6080830184866154c2565b6001600160a01b03861681526156db602082018661566c565b67ffffffffffffffff8416606082015260a060808201525f61570160a0830184866154c2565b979650505050505050565b5f8160020b627fffff19810361572457615724615350565b5f0392915050565b6157908282516001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b602081015160020b60c0830152604081015167ffffffffffffffff1660e0830152606001516001600160a01b031661010090910152565b5f6101606001600160a01b03871683526157e4602084018761572c565b8061014084015261570181840185876154c2565b5f6101806001600160a01b0388168352615815602084018861572c565b8561014084015280610160840152612c7781840185876154c2565b6001600160a01b0385168152836020820152606060408201525f6145aa6060830184866154c2565b6001600160a01b038616815284602082015267ffffffffffffffff84166040820152608060608201525f6157016080830184866154c2565b6158f48282516001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b602081015160020b60c08301526040015167ffffffffffffffff1660e090910152565b5f6101406001600160a01b03871683526159346020840187615890565b8061012084015261570181840185876154c2565b5f6101606001600160a01b03881683526159656020840188615890565b67ffffffffffffffff861661012084015280610140840152612c7781840185876154c2565b67ffffffffffffffff8281168282160390808211156125d2576125d2615350565b5f602082840312156159bb575f80fd5b5051919050565b5f6001600160a01b038087168352808616602084015250836040830152608060608301526145aa6080830184614adf565b5f6101006001600160a01b0387168352615a6960208401876001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b8060e084015261570181840185876154c2565b5f82615a9657634e487b7160e01b5f52601260045260245ffd5b500490565b634e487b7160e01b5f52603260045260245ffd5b67ffffffffffffffff8181168382160190808211156125d2576125d2615350565b634e487b7160e01b5f52602160045260245ffd5b5f611b0b828461558156fe760a9a962ae3d184e99c0483cf5684fb3170f47116ca4f445c50209da4f4f9070001020903110a19042112290b311a3905412245134d2a550c5d32651b6d3a7506264262237d468514804e8d2b95569d0d495ea533a966b11c886eb93bc176c9071727374353637324837e9b47af86c7155181ad4fd18ed32c9096db57d59ee30e2e4a6a5f92a6be3498aae067ddb2eb1d5989b56fd7baf33ca0c2ee77e5caf7ff0810182028303840444c545c646c7425617c847f8c949c48a4a8b087b8c0c816365272829aaec650acd0d28fdad4e22d6991bd97dfdcea58b4d6f29fede4f6fe0f1f2f3f4b5b6b607b8b93a3a7b7bf357199c5abcfd9e168bcdee9b3f1ecf5fd1e3e5a7a8aa2b670c4ced8bbe8f0f4fc3d79a1c3cde7effb78cce6facbf9f8a264697066735822122064f09b2cf4df87a40a102856d4e12ddac16787c8abd3963f52a4293d32e4b81064736f6c63430008190033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000004587dd6356d7293e5f10db4d853332bd5b218c0b000000000000000000000000cc92364b6b886158e71fd4e4da5c682d33d1491e00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000002f68747470733a2f2f736f6e69632e6d61726b65742f6170692f6e66742f636861696e732f3134362f6f72646572732f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c68747470733a2f2f736f6e69632e6d61726b65742f6170692f636f6e74726163742f636861696e732f31343600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022536f6e6963204d61726b6574204f72646572626f6f6b204d616b6572204f726465720000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012534f4e49432d4d41524b45542d4f524445520000000000000000000000000000
-----Decoded View---------------
Arg [0] : owner_ (address): 0x4587dd6356d7293E5f10db4D853332BD5b218C0B
Arg [1] : defaultProvider_ (address): 0xcC92364b6B886158e71Fd4e4Da5C682D33d1491e
Arg [2] : baseURI_ (string): https://sonic.market/api/nft/chains/146/orders/
Arg [3] : contractURI_ (string): https://sonic.market/api/contract/chains/146
Arg [4] : name_ (string): Sonic Market Orderbook Maker Order
Arg [5] : symbol_ (string): SONIC-MARKET-ORDER
-----Encoded View---------------
17 Constructor Arguments found :
Arg [0] : 0000000000000000000000004587dd6356d7293e5f10db4d853332bd5b218c0b
Arg [1] : 000000000000000000000000cc92364b6b886158e71fd4e4da5c682d33d1491e
Arg [2] : 00000000000000000000000000000000000000000000000000000000000000c0
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000120
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000180
Arg [5] : 00000000000000000000000000000000000000000000000000000000000001e0
Arg [6] : 000000000000000000000000000000000000000000000000000000000000002f
Arg [7] : 68747470733a2f2f736f6e69632e6d61726b65742f6170692f6e66742f636861
Arg [8] : 696e732f3134362f6f72646572732f0000000000000000000000000000000000
Arg [9] : 000000000000000000000000000000000000000000000000000000000000002c
Arg [10] : 68747470733a2f2f736f6e69632e6d61726b65742f6170692f636f6e74726163
Arg [11] : 742f636861696e732f3134360000000000000000000000000000000000000000
Arg [12] : 0000000000000000000000000000000000000000000000000000000000000022
Arg [13] : 536f6e6963204d61726b6574204f72646572626f6f6b204d616b6572204f7264
Arg [14] : 6572000000000000000000000000000000000000000000000000000000000000
Arg [15] : 0000000000000000000000000000000000000000000000000000000000000012
Arg [16] : 534f4e49432d4d41524b45542d4f524445520000000000000000000000000000
[ Download: CSV Export ]
A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.