diff --git a/deploy/BookManager.ts b/deploy/BookManager.ts index 7e783bb..17a3b0c 100644 --- a/deploy/BookManager.ts +++ b/deploy/BookManager.ts @@ -10,15 +10,15 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro const deployer = (await getNamedAccounts())['deployer'] as Address const chain = await getChain(network.provider) + if (await deployments.getOrNull('BookManager')) { + return + } + let bookLibraryAddress = (await deployments.getOrNull('Book'))?.address if (!bookLibraryAddress) { bookLibraryAddress = await deployWithVerify(hre, 'Book', []) } - if (await deployments.getOrNull('BookManager')) { - return - } - let owner: Address = '0x' let defaultProvider: Address = '0x' if (chain.testnet || isDevelopmentNetwork(chain.id)) { @@ -30,7 +30,7 @@ const deployFunction: DeployFunction = async function (hre: HardhatRuntimeEnviro throw new Error('Unknown chain') } - const entropy = 256n + const entropy = 1000n await deployCreate3WithVerify( deployer, entropy, diff --git a/deployments/421614/Book.json b/deployments/421614/Book.json index c029cf1..e35ceab 100644 --- a/deployments/421614/Book.json +++ b/deployments/421614/Book.json @@ -1,5 +1,5 @@ { - "address": "0xD5fBc07bB8Dea016f1c6F206162Cd80eAF616322", + "address": "0xc87c5c0561a500960aE4f0f171265b8c55aCF153", "abi": [ { "inputs": [], @@ -87,28 +87,28 @@ "type": "error" } ], - "transactionHash": "0x22f19c445db03127b640278cf60add67fe359c5d6b2ebec0902be11d165d5f10", + "transactionHash": "0x44d3523aa69a1e06213e51f8339fc0520fb6e813eba10c2fd70e3d9320a8587f", "receipt": { "to": null, "from": "0x5F79EE8f8fA862E98201120d83c4eC39D9468D49", - "contractAddress": "0xD5fBc07bB8Dea016f1c6F206162Cd80eAF616322", - "transactionIndex": 5, - "gasUsed": "1804253", + "contractAddress": "0xc87c5c0561a500960aE4f0f171265b8c55aCF153", + "transactionIndex": 1, + "gasUsed": "1430608", "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "blockHash": "0x630ef435cb774676ab9cd0d695bd08a46ef54316e07f014325008d2e8b0eda04", - "transactionHash": "0x22f19c445db03127b640278cf60add67fe359c5d6b2ebec0902be11d165d5f10", + "blockHash": "0xa6e37ed1c90ae08b197e87c075fefa24ccafd30eded67097733ef1883c0bea42", + "transactionHash": "0x44d3523aa69a1e06213e51f8339fc0520fb6e813eba10c2fd70e3d9320a8587f", "logs": [], - "blockNumber": 44582295, - "cumulativeGasUsed": "2710001", + "blockNumber": 87385436, + "cumulativeGasUsed": "1430608", "status": 1, "byzantium": true }, "args": [], "numDeployments": 1, - "solcInputHash": "8a82f52b63e7fb0e34e4313934d89336", - "metadata": "{\"compiler\":{\"version\":\"0.8.25+commit.b61c2a91\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"AlreadyExistsError\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"BookAlreadyOpened\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"BookNotOpened\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"maxCancelableUnit\",\"type\":\"uint64\"}],\"name\":\"CancelFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"errorCode\",\"type\":\"uint256\"}],\"name\":\"DirtyUint64Error\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"errorCode\",\"type\":\"uint256\"}],\"name\":\"PackedUint256Error\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"QueueReplaceFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"bits\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"SafeCastOverflowedUintDowncast\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"errorCode\",\"type\":\"uint256\"}],\"name\":\"SegmentedSegmentTreeError\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"ZeroUnit\",\"type\":\"error\"}],\"devdoc\":{\"errors\":{\"SafeCastOverflowedUintDowncast(uint8,uint256)\":[{\"details\":\"Value doesn't fit in an uint of `bits` size.\"}]},\"kind\":\"dev\",\"methods\":{\"take(Book.State storage,int24,uint64)\":{\"params\":{\"maxTakeUnit\":\"The maximum unit to take\",\"self\":\"The book state\"},\"returns\":{\"takenUnit\":\"The actual unit to take\"}}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"take(Book.State storage,int24,uint64)\":{\"notice\":\"Take orders from the book\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/libraries/Book.sol\":\"Book\"},\"evmVersion\":\"cancun\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":1000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/token/ERC20/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)\\n\\npragma solidity ^0.8.20;\\n\\n/**\\n * @dev Interface of the ERC-20 standard as defined in the ERC.\\n */\\ninterface IERC20 {\\n /**\\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\\n * another (`to`).\\n *\\n * Note that `value` may be zero.\\n */\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n /**\\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\\n * a call to {approve}. `value` is the new allowance.\\n */\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n\\n /**\\n * @dev Returns the value of tokens in existence.\\n */\\n function totalSupply() external view returns (uint256);\\n\\n /**\\n * @dev Returns the value of tokens owned by `account`.\\n */\\n function balanceOf(address account) external view returns (uint256);\\n\\n /**\\n * @dev Moves a `value` amount of tokens from the caller's account to `to`.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transfer(address to, uint256 value) external returns (bool);\\n\\n /**\\n * @dev Returns the remaining number of tokens that `spender` will be\\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\\n * zero by default.\\n *\\n * This value changes when {approve} or {transferFrom} are called.\\n */\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n /**\\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\\n * caller's tokens.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\\n * that someone may use both the old and the new allowance by unfortunate\\n * transaction ordering. One possible solution to mitigate this race\\n * condition is to first reduce the spender's allowance to 0 and set the\\n * desired value afterwards:\\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\\n *\\n * Emits an {Approval} event.\\n */\\n function approve(address spender, uint256 value) external returns (bool);\\n\\n /**\\n * @dev Moves a `value` amount of tokens from `from` to `to` using the\\n * allowance mechanism. `value` is then deducted from the caller's\\n * allowance.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transferFrom(address from, address to, uint256 value) external returns (bool);\\n}\\n\",\"keccak256\":\"0xee2337af2dc162a973b4be6d3f7c16f06298259e0af48c5470d2839bfa8a22f4\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC721/IERC721.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)\\n\\npragma solidity ^0.8.20;\\n\\nimport {IERC165} from \\\"../../utils/introspection/IERC165.sol\\\";\\n\\n/**\\n * @dev Required interface of an ERC-721 compliant contract.\\n */\\ninterface IERC721 is IERC165 {\\n /**\\n * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\\n */\\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\\n\\n /**\\n * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\\n */\\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\\n\\n /**\\n * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\\n */\\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\\n\\n /**\\n * @dev Returns the number of tokens in ``owner``'s account.\\n */\\n function balanceOf(address owner) external view returns (uint256 balance);\\n\\n /**\\n * @dev Returns the owner of the `tokenId` token.\\n *\\n * Requirements:\\n *\\n * - `tokenId` must exist.\\n */\\n function ownerOf(uint256 tokenId) external view returns (address owner);\\n\\n /**\\n * @dev Safely transfers `tokenId` token from `from` to `to`.\\n *\\n * Requirements:\\n *\\n * - `from` cannot be the zero address.\\n * - `to` cannot be the zero address.\\n * - `tokenId` token must exist and be owned by `from`.\\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon\\n * a safe transfer.\\n *\\n * Emits a {Transfer} event.\\n */\\n function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;\\n\\n /**\\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\\n * are aware of the ERC-721 protocol to prevent tokens from being forever locked.\\n *\\n * Requirements:\\n *\\n * - `from` cannot be the zero address.\\n * - `to` cannot be the zero address.\\n * - `tokenId` token must exist and be owned by `from`.\\n * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or\\n * {setApprovalForAll}.\\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon\\n * a safe transfer.\\n *\\n * Emits a {Transfer} event.\\n */\\n function safeTransferFrom(address from, address to, uint256 tokenId) external;\\n\\n /**\\n * @dev Transfers `tokenId` token from `from` to `to`.\\n *\\n * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721\\n * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must\\n * understand this adds an external call which potentially creates a reentrancy vulnerability.\\n *\\n * Requirements:\\n *\\n * - `from` cannot be the zero address.\\n * - `to` cannot be the zero address.\\n * - `tokenId` token must be owned by `from`.\\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transferFrom(address from, address to, uint256 tokenId) external;\\n\\n /**\\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\\n * The approval is cleared when the token is transferred.\\n *\\n * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\\n *\\n * Requirements:\\n *\\n * - The caller must own the token or be an approved operator.\\n * - `tokenId` must exist.\\n *\\n * Emits an {Approval} event.\\n */\\n function approve(address to, uint256 tokenId) external;\\n\\n /**\\n * @dev Approve or remove `operator` as an operator for the caller.\\n * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\\n *\\n * Requirements:\\n *\\n * - The `operator` cannot be the address zero.\\n *\\n * Emits an {ApprovalForAll} event.\\n */\\n function setApprovalForAll(address operator, bool approved) external;\\n\\n /**\\n * @dev Returns the account approved for `tokenId` token.\\n *\\n * Requirements:\\n *\\n * - `tokenId` must exist.\\n */\\n function getApproved(uint256 tokenId) external view returns (address operator);\\n\\n /**\\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\\n *\\n * See {setApprovalForAll}\\n */\\n function isApprovedForAll(address owner, address operator) external view returns (bool);\\n}\\n\",\"keccak256\":\"0xe0e3a2099f2e2ce3579dd35548f613928739642058dfec95b1745f93364ce3de\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)\\n\\npragma solidity ^0.8.20;\\n\\nimport {IERC721} from \\\"../IERC721.sol\\\";\\n\\n/**\\n * @title ERC-721 Non-Fungible Token Standard, optional metadata extension\\n * @dev See https://eips.ethereum.org/EIPS/eip-721\\n */\\ninterface IERC721Metadata is IERC721 {\\n /**\\n * @dev Returns the token collection name.\\n */\\n function name() external view returns (string memory);\\n\\n /**\\n * @dev Returns the token collection symbol.\\n */\\n function symbol() external view returns (string memory);\\n\\n /**\\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\\n */\\n function tokenURI(uint256 tokenId) external view returns (string memory);\\n}\\n\",\"keccak256\":\"0x37d1aaaa5a2908a09e9dcf56a26ddf762ecf295afb5964695937344fc6802ce1\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.20;\\n\\n/**\\n * @dev Interface of the ERC-165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[ERC].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0xc859863e3bda7ec3cddf6dafe2ffe91bcbe648d1395b856b839c32ee9617c44c\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/math/SafeCast.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)\\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\\n\\npragma solidity ^0.8.20;\\n\\n/**\\n * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow\\n * checks.\\n *\\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\\n * easily result in undesired exploitation or bugs, since developers usually\\n * assume that overflows raise errors. `SafeCast` restores this intuition by\\n * reverting the transaction when such an operation overflows.\\n *\\n * Using this library instead of the unchecked operations eliminates an entire\\n * class of bugs, so it's recommended to use it always.\\n */\\nlibrary SafeCast {\\n /**\\n * @dev Value doesn't fit in an uint of `bits` size.\\n */\\n error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);\\n\\n /**\\n * @dev An int value doesn't fit in an uint of `bits` size.\\n */\\n error SafeCastOverflowedIntToUint(int256 value);\\n\\n /**\\n * @dev Value doesn't fit in an int of `bits` size.\\n */\\n error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);\\n\\n /**\\n * @dev An uint value doesn't fit in an int of `bits` size.\\n */\\n error SafeCastOverflowedUintToInt(uint256 value);\\n\\n /**\\n * @dev Returns the downcasted uint248 from uint256, reverting on\\n * overflow (when the input is greater than largest uint248).\\n *\\n * Counterpart to Solidity's `uint248` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 248 bits\\n */\\n function toUint248(uint256 value) internal pure returns (uint248) {\\n if (value > type(uint248).max) {\\n revert SafeCastOverflowedUintDowncast(248, value);\\n }\\n return uint248(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint240 from uint256, reverting on\\n * overflow (when the input is greater than largest uint240).\\n *\\n * Counterpart to Solidity's `uint240` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 240 bits\\n */\\n function toUint240(uint256 value) internal pure returns (uint240) {\\n if (value > type(uint240).max) {\\n revert SafeCastOverflowedUintDowncast(240, value);\\n }\\n return uint240(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint232 from uint256, reverting on\\n * overflow (when the input is greater than largest uint232).\\n *\\n * Counterpart to Solidity's `uint232` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 232 bits\\n */\\n function toUint232(uint256 value) internal pure returns (uint232) {\\n if (value > type(uint232).max) {\\n revert SafeCastOverflowedUintDowncast(232, value);\\n }\\n return uint232(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint224 from uint256, reverting on\\n * overflow (when the input is greater than largest uint224).\\n *\\n * Counterpart to Solidity's `uint224` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 224 bits\\n */\\n function toUint224(uint256 value) internal pure returns (uint224) {\\n if (value > type(uint224).max) {\\n revert SafeCastOverflowedUintDowncast(224, value);\\n }\\n return uint224(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint216 from uint256, reverting on\\n * overflow (when the input is greater than largest uint216).\\n *\\n * Counterpart to Solidity's `uint216` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 216 bits\\n */\\n function toUint216(uint256 value) internal pure returns (uint216) {\\n if (value > type(uint216).max) {\\n revert SafeCastOverflowedUintDowncast(216, value);\\n }\\n return uint216(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint208 from uint256, reverting on\\n * overflow (when the input is greater than largest uint208).\\n *\\n * Counterpart to Solidity's `uint208` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 208 bits\\n */\\n function toUint208(uint256 value) internal pure returns (uint208) {\\n if (value > type(uint208).max) {\\n revert SafeCastOverflowedUintDowncast(208, value);\\n }\\n return uint208(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint200 from uint256, reverting on\\n * overflow (when the input is greater than largest uint200).\\n *\\n * Counterpart to Solidity's `uint200` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 200 bits\\n */\\n function toUint200(uint256 value) internal pure returns (uint200) {\\n if (value > type(uint200).max) {\\n revert SafeCastOverflowedUintDowncast(200, value);\\n }\\n return uint200(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint192 from uint256, reverting on\\n * overflow (when the input is greater than largest uint192).\\n *\\n * Counterpart to Solidity's `uint192` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 192 bits\\n */\\n function toUint192(uint256 value) internal pure returns (uint192) {\\n if (value > type(uint192).max) {\\n revert SafeCastOverflowedUintDowncast(192, value);\\n }\\n return uint192(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint184 from uint256, reverting on\\n * overflow (when the input is greater than largest uint184).\\n *\\n * Counterpart to Solidity's `uint184` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 184 bits\\n */\\n function toUint184(uint256 value) internal pure returns (uint184) {\\n if (value > type(uint184).max) {\\n revert SafeCastOverflowedUintDowncast(184, value);\\n }\\n return uint184(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint176 from uint256, reverting on\\n * overflow (when the input is greater than largest uint176).\\n *\\n * Counterpart to Solidity's `uint176` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 176 bits\\n */\\n function toUint176(uint256 value) internal pure returns (uint176) {\\n if (value > type(uint176).max) {\\n revert SafeCastOverflowedUintDowncast(176, value);\\n }\\n return uint176(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint168 from uint256, reverting on\\n * overflow (when the input is greater than largest uint168).\\n *\\n * Counterpart to Solidity's `uint168` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 168 bits\\n */\\n function toUint168(uint256 value) internal pure returns (uint168) {\\n if (value > type(uint168).max) {\\n revert SafeCastOverflowedUintDowncast(168, value);\\n }\\n return uint168(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint160 from uint256, reverting on\\n * overflow (when the input is greater than largest uint160).\\n *\\n * Counterpart to Solidity's `uint160` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 160 bits\\n */\\n function toUint160(uint256 value) internal pure returns (uint160) {\\n if (value > type(uint160).max) {\\n revert SafeCastOverflowedUintDowncast(160, value);\\n }\\n return uint160(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint152 from uint256, reverting on\\n * overflow (when the input is greater than largest uint152).\\n *\\n * Counterpart to Solidity's `uint152` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 152 bits\\n */\\n function toUint152(uint256 value) internal pure returns (uint152) {\\n if (value > type(uint152).max) {\\n revert SafeCastOverflowedUintDowncast(152, value);\\n }\\n return uint152(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint144 from uint256, reverting on\\n * overflow (when the input is greater than largest uint144).\\n *\\n * Counterpart to Solidity's `uint144` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 144 bits\\n */\\n function toUint144(uint256 value) internal pure returns (uint144) {\\n if (value > type(uint144).max) {\\n revert SafeCastOverflowedUintDowncast(144, value);\\n }\\n return uint144(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint136 from uint256, reverting on\\n * overflow (when the input is greater than largest uint136).\\n *\\n * Counterpart to Solidity's `uint136` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 136 bits\\n */\\n function toUint136(uint256 value) internal pure returns (uint136) {\\n if (value > type(uint136).max) {\\n revert SafeCastOverflowedUintDowncast(136, value);\\n }\\n return uint136(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint128 from uint256, reverting on\\n * overflow (when the input is greater than largest uint128).\\n *\\n * Counterpart to Solidity's `uint128` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 128 bits\\n */\\n function toUint128(uint256 value) internal pure returns (uint128) {\\n if (value > type(uint128).max) {\\n revert SafeCastOverflowedUintDowncast(128, value);\\n }\\n return uint128(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint120 from uint256, reverting on\\n * overflow (when the input is greater than largest uint120).\\n *\\n * Counterpart to Solidity's `uint120` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 120 bits\\n */\\n function toUint120(uint256 value) internal pure returns (uint120) {\\n if (value > type(uint120).max) {\\n revert SafeCastOverflowedUintDowncast(120, value);\\n }\\n return uint120(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint112 from uint256, reverting on\\n * overflow (when the input is greater than largest uint112).\\n *\\n * Counterpart to Solidity's `uint112` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 112 bits\\n */\\n function toUint112(uint256 value) internal pure returns (uint112) {\\n if (value > type(uint112).max) {\\n revert SafeCastOverflowedUintDowncast(112, value);\\n }\\n return uint112(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint104 from uint256, reverting on\\n * overflow (when the input is greater than largest uint104).\\n *\\n * Counterpart to Solidity's `uint104` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 104 bits\\n */\\n function toUint104(uint256 value) internal pure returns (uint104) {\\n if (value > type(uint104).max) {\\n revert SafeCastOverflowedUintDowncast(104, value);\\n }\\n return uint104(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint96 from uint256, reverting on\\n * overflow (when the input is greater than largest uint96).\\n *\\n * Counterpart to Solidity's `uint96` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 96 bits\\n */\\n function toUint96(uint256 value) internal pure returns (uint96) {\\n if (value > type(uint96).max) {\\n revert SafeCastOverflowedUintDowncast(96, value);\\n }\\n return uint96(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint88 from uint256, reverting on\\n * overflow (when the input is greater than largest uint88).\\n *\\n * Counterpart to Solidity's `uint88` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 88 bits\\n */\\n function toUint88(uint256 value) internal pure returns (uint88) {\\n if (value > type(uint88).max) {\\n revert SafeCastOverflowedUintDowncast(88, value);\\n }\\n return uint88(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint80 from uint256, reverting on\\n * overflow (when the input is greater than largest uint80).\\n *\\n * Counterpart to Solidity's `uint80` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 80 bits\\n */\\n function toUint80(uint256 value) internal pure returns (uint80) {\\n if (value > type(uint80).max) {\\n revert SafeCastOverflowedUintDowncast(80, value);\\n }\\n return uint80(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint72 from uint256, reverting on\\n * overflow (when the input is greater than largest uint72).\\n *\\n * Counterpart to Solidity's `uint72` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 72 bits\\n */\\n function toUint72(uint256 value) internal pure returns (uint72) {\\n if (value > type(uint72).max) {\\n revert SafeCastOverflowedUintDowncast(72, value);\\n }\\n return uint72(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint64 from uint256, reverting on\\n * overflow (when the input is greater than largest uint64).\\n *\\n * Counterpart to Solidity's `uint64` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 64 bits\\n */\\n function toUint64(uint256 value) internal pure returns (uint64) {\\n if (value > type(uint64).max) {\\n revert SafeCastOverflowedUintDowncast(64, value);\\n }\\n return uint64(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint56 from uint256, reverting on\\n * overflow (when the input is greater than largest uint56).\\n *\\n * Counterpart to Solidity's `uint56` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 56 bits\\n */\\n function toUint56(uint256 value) internal pure returns (uint56) {\\n if (value > type(uint56).max) {\\n revert SafeCastOverflowedUintDowncast(56, value);\\n }\\n return uint56(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint48 from uint256, reverting on\\n * overflow (when the input is greater than largest uint48).\\n *\\n * Counterpart to Solidity's `uint48` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 48 bits\\n */\\n function toUint48(uint256 value) internal pure returns (uint48) {\\n if (value > type(uint48).max) {\\n revert SafeCastOverflowedUintDowncast(48, value);\\n }\\n return uint48(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint40 from uint256, reverting on\\n * overflow (when the input is greater than largest uint40).\\n *\\n * Counterpart to Solidity's `uint40` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 40 bits\\n */\\n function toUint40(uint256 value) internal pure returns (uint40) {\\n if (value > type(uint40).max) {\\n revert SafeCastOverflowedUintDowncast(40, value);\\n }\\n return uint40(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint32 from uint256, reverting on\\n * overflow (when the input is greater than largest uint32).\\n *\\n * Counterpart to Solidity's `uint32` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 32 bits\\n */\\n function toUint32(uint256 value) internal pure returns (uint32) {\\n if (value > type(uint32).max) {\\n revert SafeCastOverflowedUintDowncast(32, value);\\n }\\n return uint32(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint24 from uint256, reverting on\\n * overflow (when the input is greater than largest uint24).\\n *\\n * Counterpart to Solidity's `uint24` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 24 bits\\n */\\n function toUint24(uint256 value) internal pure returns (uint24) {\\n if (value > type(uint24).max) {\\n revert SafeCastOverflowedUintDowncast(24, value);\\n }\\n return uint24(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint16 from uint256, reverting on\\n * overflow (when the input is greater than largest uint16).\\n *\\n * Counterpart to Solidity's `uint16` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 16 bits\\n */\\n function toUint16(uint256 value) internal pure returns (uint16) {\\n if (value > type(uint16).max) {\\n revert SafeCastOverflowedUintDowncast(16, value);\\n }\\n return uint16(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint8 from uint256, reverting on\\n * overflow (when the input is greater than largest uint8).\\n *\\n * Counterpart to Solidity's `uint8` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 8 bits\\n */\\n function toUint8(uint256 value) internal pure returns (uint8) {\\n if (value > type(uint8).max) {\\n revert SafeCastOverflowedUintDowncast(8, value);\\n }\\n return uint8(value);\\n }\\n\\n /**\\n * @dev Converts a signed int256 into an unsigned uint256.\\n *\\n * Requirements:\\n *\\n * - input must be greater than or equal to 0.\\n */\\n function toUint256(int256 value) internal pure returns (uint256) {\\n if (value < 0) {\\n revert SafeCastOverflowedIntToUint(value);\\n }\\n return uint256(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted int248 from int256, reverting on\\n * overflow (when the input is less than smallest int248 or\\n * greater than largest int248).\\n *\\n * Counterpart to Solidity's `int248` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 248 bits\\n */\\n function toInt248(int256 value) internal pure returns (int248 downcasted) {\\n downcasted = int248(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(248, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int240 from int256, reverting on\\n * overflow (when the input is less than smallest int240 or\\n * greater than largest int240).\\n *\\n * Counterpart to Solidity's `int240` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 240 bits\\n */\\n function toInt240(int256 value) internal pure returns (int240 downcasted) {\\n downcasted = int240(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(240, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int232 from int256, reverting on\\n * overflow (when the input is less than smallest int232 or\\n * greater than largest int232).\\n *\\n * Counterpart to Solidity's `int232` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 232 bits\\n */\\n function toInt232(int256 value) internal pure returns (int232 downcasted) {\\n downcasted = int232(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(232, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int224 from int256, reverting on\\n * overflow (when the input is less than smallest int224 or\\n * greater than largest int224).\\n *\\n * Counterpart to Solidity's `int224` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 224 bits\\n */\\n function toInt224(int256 value) internal pure returns (int224 downcasted) {\\n downcasted = int224(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(224, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int216 from int256, reverting on\\n * overflow (when the input is less than smallest int216 or\\n * greater than largest int216).\\n *\\n * Counterpart to Solidity's `int216` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 216 bits\\n */\\n function toInt216(int256 value) internal pure returns (int216 downcasted) {\\n downcasted = int216(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(216, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int208 from int256, reverting on\\n * overflow (when the input is less than smallest int208 or\\n * greater than largest int208).\\n *\\n * Counterpart to Solidity's `int208` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 208 bits\\n */\\n function toInt208(int256 value) internal pure returns (int208 downcasted) {\\n downcasted = int208(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(208, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int200 from int256, reverting on\\n * overflow (when the input is less than smallest int200 or\\n * greater than largest int200).\\n *\\n * Counterpart to Solidity's `int200` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 200 bits\\n */\\n function toInt200(int256 value) internal pure returns (int200 downcasted) {\\n downcasted = int200(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(200, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int192 from int256, reverting on\\n * overflow (when the input is less than smallest int192 or\\n * greater than largest int192).\\n *\\n * Counterpart to Solidity's `int192` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 192 bits\\n */\\n function toInt192(int256 value) internal pure returns (int192 downcasted) {\\n downcasted = int192(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(192, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int184 from int256, reverting on\\n * overflow (when the input is less than smallest int184 or\\n * greater than largest int184).\\n *\\n * Counterpart to Solidity's `int184` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 184 bits\\n */\\n function toInt184(int256 value) internal pure returns (int184 downcasted) {\\n downcasted = int184(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(184, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int176 from int256, reverting on\\n * overflow (when the input is less than smallest int176 or\\n * greater than largest int176).\\n *\\n * Counterpart to Solidity's `int176` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 176 bits\\n */\\n function toInt176(int256 value) internal pure returns (int176 downcasted) {\\n downcasted = int176(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(176, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int168 from int256, reverting on\\n * overflow (when the input is less than smallest int168 or\\n * greater than largest int168).\\n *\\n * Counterpart to Solidity's `int168` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 168 bits\\n */\\n function toInt168(int256 value) internal pure returns (int168 downcasted) {\\n downcasted = int168(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(168, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int160 from int256, reverting on\\n * overflow (when the input is less than smallest int160 or\\n * greater than largest int160).\\n *\\n * Counterpart to Solidity's `int160` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 160 bits\\n */\\n function toInt160(int256 value) internal pure returns (int160 downcasted) {\\n downcasted = int160(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(160, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int152 from int256, reverting on\\n * overflow (when the input is less than smallest int152 or\\n * greater than largest int152).\\n *\\n * Counterpart to Solidity's `int152` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 152 bits\\n */\\n function toInt152(int256 value) internal pure returns (int152 downcasted) {\\n downcasted = int152(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(152, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int144 from int256, reverting on\\n * overflow (when the input is less than smallest int144 or\\n * greater than largest int144).\\n *\\n * Counterpart to Solidity's `int144` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 144 bits\\n */\\n function toInt144(int256 value) internal pure returns (int144 downcasted) {\\n downcasted = int144(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(144, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int136 from int256, reverting on\\n * overflow (when the input is less than smallest int136 or\\n * greater than largest int136).\\n *\\n * Counterpart to Solidity's `int136` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 136 bits\\n */\\n function toInt136(int256 value) internal pure returns (int136 downcasted) {\\n downcasted = int136(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(136, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int128 from int256, reverting on\\n * overflow (when the input is less than smallest int128 or\\n * greater than largest int128).\\n *\\n * Counterpart to Solidity's `int128` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 128 bits\\n */\\n function toInt128(int256 value) internal pure returns (int128 downcasted) {\\n downcasted = int128(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(128, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int120 from int256, reverting on\\n * overflow (when the input is less than smallest int120 or\\n * greater than largest int120).\\n *\\n * Counterpart to Solidity's `int120` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 120 bits\\n */\\n function toInt120(int256 value) internal pure returns (int120 downcasted) {\\n downcasted = int120(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(120, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int112 from int256, reverting on\\n * overflow (when the input is less than smallest int112 or\\n * greater than largest int112).\\n *\\n * Counterpart to Solidity's `int112` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 112 bits\\n */\\n function toInt112(int256 value) internal pure returns (int112 downcasted) {\\n downcasted = int112(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(112, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int104 from int256, reverting on\\n * overflow (when the input is less than smallest int104 or\\n * greater than largest int104).\\n *\\n * Counterpart to Solidity's `int104` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 104 bits\\n */\\n function toInt104(int256 value) internal pure returns (int104 downcasted) {\\n downcasted = int104(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(104, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int96 from int256, reverting on\\n * overflow (when the input is less than smallest int96 or\\n * greater than largest int96).\\n *\\n * Counterpart to Solidity's `int96` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 96 bits\\n */\\n function toInt96(int256 value) internal pure returns (int96 downcasted) {\\n downcasted = int96(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(96, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int88 from int256, reverting on\\n * overflow (when the input is less than smallest int88 or\\n * greater than largest int88).\\n *\\n * Counterpart to Solidity's `int88` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 88 bits\\n */\\n function toInt88(int256 value) internal pure returns (int88 downcasted) {\\n downcasted = int88(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(88, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int80 from int256, reverting on\\n * overflow (when the input is less than smallest int80 or\\n * greater than largest int80).\\n *\\n * Counterpart to Solidity's `int80` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 80 bits\\n */\\n function toInt80(int256 value) internal pure returns (int80 downcasted) {\\n downcasted = int80(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(80, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int72 from int256, reverting on\\n * overflow (when the input is less than smallest int72 or\\n * greater than largest int72).\\n *\\n * Counterpart to Solidity's `int72` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 72 bits\\n */\\n function toInt72(int256 value) internal pure returns (int72 downcasted) {\\n downcasted = int72(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(72, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int64 from int256, reverting on\\n * overflow (when the input is less than smallest int64 or\\n * greater than largest int64).\\n *\\n * Counterpart to Solidity's `int64` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 64 bits\\n */\\n function toInt64(int256 value) internal pure returns (int64 downcasted) {\\n downcasted = int64(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(64, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int56 from int256, reverting on\\n * overflow (when the input is less than smallest int56 or\\n * greater than largest int56).\\n *\\n * Counterpart to Solidity's `int56` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 56 bits\\n */\\n function toInt56(int256 value) internal pure returns (int56 downcasted) {\\n downcasted = int56(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(56, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int48 from int256, reverting on\\n * overflow (when the input is less than smallest int48 or\\n * greater than largest int48).\\n *\\n * Counterpart to Solidity's `int48` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 48 bits\\n */\\n function toInt48(int256 value) internal pure returns (int48 downcasted) {\\n downcasted = int48(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(48, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int40 from int256, reverting on\\n * overflow (when the input is less than smallest int40 or\\n * greater than largest int40).\\n *\\n * Counterpart to Solidity's `int40` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 40 bits\\n */\\n function toInt40(int256 value) internal pure returns (int40 downcasted) {\\n downcasted = int40(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(40, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int32 from int256, reverting on\\n * overflow (when the input is less than smallest int32 or\\n * greater than largest int32).\\n *\\n * Counterpart to Solidity's `int32` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 32 bits\\n */\\n function toInt32(int256 value) internal pure returns (int32 downcasted) {\\n downcasted = int32(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(32, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int24 from int256, reverting on\\n * overflow (when the input is less than smallest int24 or\\n * greater than largest int24).\\n *\\n * Counterpart to Solidity's `int24` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 24 bits\\n */\\n function toInt24(int256 value) internal pure returns (int24 downcasted) {\\n downcasted = int24(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(24, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int16 from int256, reverting on\\n * overflow (when the input is less than smallest int16 or\\n * greater than largest int16).\\n *\\n * Counterpart to Solidity's `int16` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 16 bits\\n */\\n function toInt16(int256 value) internal pure returns (int16 downcasted) {\\n downcasted = int16(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(16, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int8 from int256, reverting on\\n * overflow (when the input is less than smallest int8 or\\n * greater than largest int8).\\n *\\n * Counterpart to Solidity's `int8` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 8 bits\\n */\\n function toInt8(int256 value) internal pure returns (int8 downcasted) {\\n downcasted = int8(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(8, value);\\n }\\n }\\n\\n /**\\n * @dev Converts an unsigned uint256 into a signed int256.\\n *\\n * Requirements:\\n *\\n * - input must be less than or equal to maxInt256.\\n */\\n function toInt256(uint256 value) internal pure returns (int256) {\\n // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\\n if (value > uint256(type(int256).max)) {\\n revert SafeCastOverflowedUintToInt(value);\\n }\\n return int256(value);\\n }\\n\\n /**\\n * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.\\n */\\n function toUint(bool b) internal pure returns (uint256 u) {\\n /// @solidity memory-safe-assembly\\n assembly {\\n u := iszero(iszero(b))\\n }\\n }\\n}\\n\",\"keccak256\":\"0x8cd59334ed58b8884cd1f775afc9400db702e674e5d6a7a438c655b9de788d7e\",\"license\":\"MIT\"},\"src/interfaces/IBookManager.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n\\npragma solidity ^0.8.0;\\n\\nimport {IERC721Metadata} from \\\"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol\\\";\\n\\nimport {BookId} from \\\"../libraries/BookId.sol\\\";\\nimport {Currency} from \\\"../libraries/Currency.sol\\\";\\nimport {OrderId} from \\\"../libraries/OrderId.sol\\\";\\nimport {Tick} from \\\"../libraries/Tick.sol\\\";\\nimport {FeePolicy} from \\\"../libraries/FeePolicy.sol\\\";\\nimport {IERC721Permit} from \\\"./IERC721Permit.sol\\\";\\nimport {IHooks} from \\\"./IHooks.sol\\\";\\n\\n/**\\n * @title IBookManager\\n * @notice The interface for the BookManager contract\\n */\\ninterface IBookManager is IERC721Metadata, IERC721Permit {\\n error InvalidUnitSize();\\n error InvalidFeePolicy();\\n error InvalidProvider(address provider);\\n error LockedBy(address locker, address hook);\\n error CurrencyNotSettled();\\n\\n /**\\n * @notice Event emitted when a new book is opened\\n * @param id The book id\\n * @param base The base currency\\n * @param quote The quote currency\\n * @param unitSize The unit size of the book\\n * @param makerPolicy The maker fee policy\\n * @param takerPolicy The taker fee policy\\n * @param hooks The hooks contract\\n */\\n event Open(\\n BookId indexed id,\\n Currency indexed base,\\n Currency indexed quote,\\n uint64 unitSize,\\n FeePolicy makerPolicy,\\n FeePolicy takerPolicy,\\n IHooks hooks\\n );\\n\\n /**\\n * @notice Event emitted when a new order is made\\n * @param bookId The book id\\n * @param user The user address\\n * @param tick The order tick\\n * @param orderIndex The order index\\n * @param unit The order unit\\n * @param provider The provider address\\n */\\n event Make(\\n BookId indexed bookId, address indexed user, Tick tick, uint256 orderIndex, uint64 unit, address provider\\n );\\n\\n /**\\n * @notice Event emitted when an order is taken\\n * @param bookId The book id\\n * @param user The user address\\n * @param tick The order tick\\n * @param unit The order unit\\n */\\n event Take(BookId indexed bookId, address indexed user, Tick tick, uint64 unit);\\n\\n /**\\n * @notice Event emitted when an order is canceled\\n * @param orderId The order id\\n * @param unit The canceled unit\\n */\\n event Cancel(OrderId indexed orderId, uint64 unit);\\n\\n /**\\n * @notice Event emitted when an order is claimed\\n * @param orderId The order id\\n * @param unit The claimed unit\\n */\\n event Claim(OrderId indexed orderId, uint64 unit);\\n\\n /**\\n * @notice Event emitted when a provider is whitelisted\\n * @param provider The provider address\\n */\\n event Whitelist(address indexed provider);\\n\\n /**\\n * @notice Event emitted when a provider is delisted\\n * @param provider The provider address\\n */\\n event Delist(address indexed provider);\\n\\n /**\\n * @notice Event emitted when a provider collects fees\\n * @param provider The provider address\\n * @param recipient The recipient address\\n * @param currency The currency\\n * @param amount The collected amount\\n */\\n event Collect(address indexed provider, address indexed recipient, Currency indexed currency, uint256 amount);\\n\\n /**\\n * @notice Event emitted when new default provider is set\\n * @param newDefaultProvider The new default provider address\\n */\\n event SetDefaultProvider(address indexed newDefaultProvider);\\n\\n /**\\n * @notice This structure represents a unique identifier for a book in the BookManager.\\n * @param base The base currency of the book\\n * @param unitSize The unit size of the book\\n * @param quote The quote currency of the book\\n * @param makerPolicy The maker fee policy of the book\\n * @param hooks The hooks contract of the book\\n * @param takerPolicy The taker fee policy of the book\\n */\\n struct BookKey {\\n Currency base;\\n uint64 unitSize;\\n Currency quote;\\n FeePolicy makerPolicy;\\n IHooks hooks;\\n FeePolicy takerPolicy;\\n }\\n\\n /**\\n * @notice Returns the base URI\\n * @return The base URI\\n */\\n function baseURI() external view returns (string memory);\\n\\n /**\\n * @notice Returns the contract URI\\n * @return The contract URI\\n */\\n function contractURI() external view returns (string memory);\\n\\n /**\\n * @notice Returns the default provider\\n * @return The default provider\\n */\\n function defaultProvider() external view returns (address);\\n\\n /**\\n * @notice Returns the total reserves of a given currency\\n * @param currency The currency in question\\n * @return The total reserves amount\\n */\\n function reservesOf(Currency currency) external view returns (uint256);\\n\\n /**\\n * @notice Checks if a provider is whitelisted\\n * @param provider The address of the provider\\n * @return True if the provider is whitelisted, false otherwise\\n */\\n function isWhitelisted(address provider) external view returns (bool);\\n\\n /**\\n * @notice Verifies if an owner has authorized a spender for a token\\n * @param owner The address of the token owner\\n * @param spender The address of the spender\\n * @param tokenId The token ID\\n */\\n function checkAuthorized(address owner, address spender, uint256 tokenId) external view;\\n\\n /**\\n * @notice Calculates the amount owed to a provider in a given currency\\n * @param provider The provider's address\\n * @param currency The currency in question\\n * @return The owed amount\\n */\\n function tokenOwed(address provider, Currency currency) external view returns (uint256);\\n\\n /**\\n * @notice Calculates the currency balance changes for a given locker\\n * @param locker The address of the locker\\n * @param currency The currency in question\\n * @return The net change in currency balance\\n */\\n function getCurrencyDelta(address locker, Currency currency) external view returns (int256);\\n\\n /**\\n * @notice Retrieves the book key for a given book ID\\n * @param id The book ID\\n * @return The book key\\n */\\n function getBookKey(BookId id) external view returns (BookKey memory);\\n\\n /**\\n * @notice This structure represents a current status for an order in the BookManager.\\n * @param provider The provider of the order\\n * @param open The open unit of the order\\n * @param claimable The claimable unit of the order\\n */\\n struct OrderInfo {\\n address provider;\\n uint64 open;\\n uint64 claimable;\\n }\\n\\n /**\\n * @notice Provides information about an order\\n * @param id The order ID\\n * @return Order information including provider, open status, and claimable unit\\n */\\n function getOrder(OrderId id) external view returns (OrderInfo memory);\\n\\n /**\\n * @notice Retrieves the locker and caller addresses for a given lock\\n * @param i The index of the lock\\n * @return locker The locker's address\\n * @return lockCaller The caller's address\\n */\\n function getLock(uint256 i) external view returns (address locker, address lockCaller);\\n\\n /**\\n * @notice Provides the lock data\\n * @return The lock data including necessary numeric values\\n */\\n function getLockData() external view returns (uint128, uint128);\\n\\n /**\\n * @notice Returns the depth of a given book ID and tick\\n * @param id The book ID\\n * @param tick The tick\\n * @return The depth of the tick\\n */\\n function getDepth(BookId id, Tick tick) external view returns (uint64);\\n\\n /**\\n * @notice Retrieves the highest tick for a given book ID\\n * @param id The book ID\\n * @return tick The highest tick\\n */\\n function getHighest(BookId id) external view returns (Tick tick);\\n\\n /**\\n * @notice Finds the maximum tick less than a specified tick in a book\\n * @dev Returns `Tick.wrap(type(int24).min)` if the specified tick is the lowest\\n * @param id The book ID\\n * @param tick The specified tick\\n * @return The next lower tick\\n */\\n function maxLessThan(BookId id, Tick tick) external view returns (Tick);\\n\\n /**\\n * @notice Checks if a book is opened\\n * @param id The book ID\\n * @return True if the book is opened, false otherwise\\n */\\n function isOpened(BookId id) external view returns (bool);\\n\\n /**\\n * @notice Checks if a book is empty\\n * @param id The book ID\\n * @return True if the book is empty, false otherwise\\n */\\n function isEmpty(BookId id) external view returns (bool);\\n\\n /**\\n * @notice Encodes a BookKey into a BookId\\n * @param key The BookKey to encode\\n * @return The encoded BookId\\n */\\n function encodeBookKey(BookKey calldata key) external pure returns (BookId);\\n\\n /**\\n * @notice Loads a value from a specific storage slot\\n * @param slot The storage slot\\n * @return The value in the slot\\n */\\n function load(bytes32 slot) external view returns (bytes32);\\n\\n /**\\n * @notice Loads a sequence of values starting from a specific slot\\n * @param startSlot The starting slot\\n * @param nSlot The number of slots to load\\n * @return The sequence of values\\n */\\n function load(bytes32 startSlot, uint256 nSlot) external view returns (bytes memory);\\n\\n /**\\n * @notice Opens a new book\\n * @param key The book key\\n * @param hookData The hook data\\n */\\n function open(BookKey calldata key, bytes calldata hookData) external;\\n\\n /**\\n * @notice Locks a book manager function\\n * @param locker The locker address\\n * @param data The lock data\\n * @return The lock return data\\n */\\n function lock(address locker, bytes calldata data) external returns (bytes memory);\\n\\n /**\\n * @notice This structure represents the parameters for making an order.\\n * @param key The book key for the order\\n * @param tick The tick for the order\\n * @param unit The unit for the order. Times key.unitSize to get actual bid amount.\\n * @param provider The provider for the order. The limit order service provider address to collect fees.\\n */\\n struct MakeParams {\\n BookKey key;\\n Tick tick;\\n uint64 unit;\\n address provider;\\n }\\n\\n /**\\n * @notice Make a limit order\\n * @param params The order parameters\\n * @param hookData The hook data\\n * @return id The order id. Returns 0 if the order is not settled\\n * @return quoteAmount The amount of quote currency to be paid\\n */\\n function make(MakeParams calldata params, bytes calldata hookData)\\n external\\n returns (OrderId id, uint256 quoteAmount);\\n\\n /**\\n * @notice This structure represents the parameters for taking orders in the specified tick.\\n * @param key The book key for the order\\n * @param tick The tick for the order\\n * @param maxUnit The max unit to take\\n */\\n struct TakeParams {\\n BookKey key;\\n Tick tick;\\n uint64 maxUnit;\\n }\\n\\n /**\\n * @notice Take a limit order at specific tick\\n * @param params The order parameters\\n * @param hookData The hook data\\n * @return quoteAmount The amount of quote currency to be received\\n * @return baseAmount The amount of base currency to be paid\\n */\\n function take(TakeParams calldata params, bytes calldata hookData)\\n external\\n returns (uint256 quoteAmount, uint256 baseAmount);\\n\\n /**\\n * @notice This structure represents the parameters for canceling an order.\\n * @param id The order id for the order\\n * @param toUnit The remaining open unit for the order after cancellation. Must not exceed the current open unit.\\n */\\n struct CancelParams {\\n OrderId id;\\n uint64 toUnit;\\n }\\n\\n /**\\n * @notice Cancel a limit order\\n * @param params The order parameters\\n * @param hookData The hook data\\n * @return canceledAmount The amount of quote currency canceled\\n */\\n function cancel(CancelParams calldata params, bytes calldata hookData) external returns (uint256 canceledAmount);\\n\\n /**\\n * @notice Claims an order\\n * @param id The order ID\\n * @param hookData The hook data\\n * @return claimedAmount The amount claimed\\n */\\n function claim(OrderId id, bytes calldata hookData) external returns (uint256 claimedAmount);\\n\\n /**\\n * @notice Collects fees from a provider\\n * @param recipient The recipient address\\n * @param currency The currency\\n * @return The collected amount\\n */\\n function collect(address recipient, Currency currency) external returns (uint256);\\n\\n /**\\n * @notice Withdraws a currency\\n * @param currency The currency\\n * @param to The recipient address\\n * @param amount The amount\\n */\\n function withdraw(Currency currency, address to, uint256 amount) external;\\n\\n /**\\n * @notice Settles a currency\\n * @param currency The currency\\n * @return The settled amount\\n */\\n function settle(Currency currency) external payable returns (uint256);\\n\\n /**\\n * @notice Whitelists a provider\\n * @param provider The provider address\\n */\\n function whitelist(address provider) external;\\n\\n /**\\n * @notice Delists a provider\\n * @param provider The provider address\\n */\\n function delist(address provider) external;\\n\\n /**\\n * @notice Sets the default provider\\n * @param newDefaultProvider The new default provider address\\n */\\n function setDefaultProvider(address newDefaultProvider) external;\\n}\\n\",\"keccak256\":\"0xda8dffc751ac3554033e084919f1e431eb2585c80e1e30b9a0198366a8607086\",\"license\":\"MIT\"},\"src/interfaces/IERC721Permit.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n\\npragma solidity ^0.8.0;\\n\\nimport {IERC721} from \\\"@openzeppelin/contracts/token/ERC721/IERC721.sol\\\";\\n\\n/**\\n * @title IERC721Permit\\n * @notice An interface for the ERC721 permit extension\\n */\\ninterface IERC721Permit is IERC721 {\\n error InvalidSignature();\\n error PermitExpired();\\n\\n /**\\n * @notice The EIP-712 typehash for the permit struct used by the contract\\n */\\n function PERMIT_TYPEHASH() external pure returns (bytes32);\\n\\n /**\\n * @notice The EIP-712 domain separator for this contract\\n */\\n function DOMAIN_SEPARATOR() external view returns (bytes32);\\n\\n /**\\n * @notice Approve the spender to transfer the given tokenId\\n * @param spender The address to approve\\n * @param tokenId The tokenId to approve\\n * @param deadline The deadline for the signature\\n * @param v The recovery id of the signature\\n * @param r The r value of the signature\\n * @param s The s value of the signature\\n */\\n function permit(address spender, uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external;\\n\\n /**\\n * @notice Get the current nonce for a token\\n * @param tokenId The tokenId to get the nonce for\\n * @return The current nonce\\n */\\n function nonces(uint256 tokenId) external view returns (uint256);\\n}\\n\",\"keccak256\":\"0xd6baab4710fa674981395f428bd6550c4e288ac44a1a5d38c2a58fd67234d57e\",\"license\":\"MIT\"},\"src/interfaces/IHooks.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n\\npragma solidity ^0.8.20;\\n\\nimport {IBookManager} from \\\"./IBookManager.sol\\\";\\nimport {OrderId} from \\\"../libraries/OrderId.sol\\\";\\n\\n/**\\n * @title IHooks\\n * @notice Interface for the hooks contract\\n */\\ninterface IHooks {\\n /**\\n * @notice Hook called before opening a new book\\n * @param sender The sender of the open transaction\\n * @param key The key of the book being opened\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function beforeOpen(address sender, IBookManager.BookKey calldata key, bytes calldata hookData)\\n external\\n returns (bytes4);\\n\\n /**\\n * @notice Hook called after opening a new book\\n * @param sender The sender of the open transaction\\n * @param key The key of the book being opened\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function afterOpen(address sender, IBookManager.BookKey calldata key, bytes calldata hookData)\\n external\\n returns (bytes4);\\n\\n /**\\n * @notice Hook called before making a new order\\n * @param sender The sender of the make transaction\\n * @param params The parameters of the make transaction\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function beforeMake(address sender, IBookManager.MakeParams calldata params, bytes calldata hookData)\\n external\\n returns (bytes4);\\n\\n /**\\n * @notice Hook called after making a new order\\n * @param sender The sender of the make transaction\\n * @param params The parameters of the make transaction\\n * @param orderId The id of the order that was made\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function afterMake(\\n address sender,\\n IBookManager.MakeParams calldata params,\\n OrderId orderId,\\n bytes calldata hookData\\n ) external returns (bytes4);\\n\\n /**\\n * @notice Hook called before taking an order\\n * @param sender The sender of the take transaction\\n * @param params The parameters of the take transaction\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function beforeTake(address sender, IBookManager.TakeParams calldata params, bytes calldata hookData)\\n external\\n returns (bytes4);\\n\\n /**\\n * @notice Hook called after taking an order\\n * @param sender The sender of the take transaction\\n * @param params The parameters of the take transaction\\n * @param takenUnit The unit that was taken\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function afterTake(\\n address sender,\\n IBookManager.TakeParams calldata params,\\n uint64 takenUnit,\\n bytes calldata hookData\\n ) external returns (bytes4);\\n\\n /**\\n * @notice Hook called before canceling an order\\n * @param sender The sender of the cancel transaction\\n * @param params The parameters of the cancel transaction\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function beforeCancel(address sender, IBookManager.CancelParams calldata params, bytes calldata hookData)\\n external\\n returns (bytes4);\\n\\n /**\\n * @notice Hook called after canceling an order\\n * @param sender The sender of the cancel transaction\\n * @param params The parameters of the cancel transaction\\n * @param canceledUnit The unit that was canceled\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function afterCancel(\\n address sender,\\n IBookManager.CancelParams calldata params,\\n uint64 canceledUnit,\\n bytes calldata hookData\\n ) external returns (bytes4);\\n\\n /**\\n * @notice Hook called before claiming an order\\n * @param sender The sender of the claim transaction\\n * @param orderId The id of the order being claimed\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function beforeClaim(address sender, OrderId orderId, bytes calldata hookData) external returns (bytes4);\\n\\n /**\\n * @notice Hook called after claiming an order\\n * @param sender The sender of the claim transaction\\n * @param orderId The id of the order being claimed\\n * @param claimedUnit The unit that was claimed\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function afterClaim(address sender, OrderId orderId, uint64 claimedUnit, bytes calldata hookData)\\n external\\n returns (bytes4);\\n}\\n\",\"keccak256\":\"0xbff95e07debd7d51cb3aa79172fd3c31efb57cea1c03d21b5740a565198d8343\",\"license\":\"MIT\"},\"src/libraries/Book.sol\":{\"content\":\"// SPDX-License-Identifier: -\\n// License: https://license.clober.io/LICENSE_V2.pdf\\n\\npragma solidity ^0.8.20;\\n\\nimport {SafeCast} from \\\"@openzeppelin/contracts/utils/math/SafeCast.sol\\\";\\n\\nimport {IBookManager} from \\\"../interfaces/IBookManager.sol\\\";\\nimport {SegmentedSegmentTree} from \\\"./SegmentedSegmentTree.sol\\\";\\nimport {Tick, TickLibrary} from \\\"./Tick.sol\\\";\\nimport {OrderId, OrderIdLibrary} from \\\"./OrderId.sol\\\";\\nimport {TotalClaimableMap} from \\\"./TotalClaimableMap.sol\\\";\\nimport {TickBitmap} from \\\"./TickBitmap.sol\\\";\\n\\nlibrary Book {\\n using Book for State;\\n using TickBitmap for mapping(uint256 => uint256);\\n using SegmentedSegmentTree for SegmentedSegmentTree.Core;\\n using TotalClaimableMap for mapping(uint24 => uint256);\\n using TickLibrary for Tick;\\n using OrderIdLibrary for OrderId;\\n\\n error ZeroUnit();\\n error BookAlreadyOpened();\\n error BookNotOpened();\\n error QueueReplaceFailed();\\n error CancelFailed(uint64 maxCancelableUnit);\\n\\n // @dev Due to the segment tree implementation, the maximum order size is 2 ** 15.\\n uint40 internal constant MAX_ORDER = 2 ** 15; // 32768\\n uint256 internal constant MAX_ORDER_M = 2 ** 15 - 1; // % 32768\\n\\n struct Order {\\n address provider;\\n uint64 pending; // @dev unfilled unit + filled(claimable) unit\\n }\\n\\n struct Queue {\\n SegmentedSegmentTree.Core tree;\\n Order[] orders;\\n }\\n\\n struct State {\\n IBookManager.BookKey key;\\n mapping(Tick tick => Queue) queues;\\n mapping(uint256 => uint256) tickBitmap;\\n // @dev Four values of totalClaimable are stored in one uint256\\n mapping(uint24 groupIndex => uint256) totalClaimableOf;\\n }\\n\\n function open(State storage self, IBookManager.BookKey calldata key) external {\\n if (self.isOpened()) revert BookAlreadyOpened();\\n self.key = key;\\n }\\n\\n function isOpened(State storage self) internal view returns (bool) {\\n return self.key.unitSize != 0;\\n }\\n\\n function checkOpened(State storage self) internal view {\\n if (!self.isOpened()) revert BookNotOpened();\\n }\\n\\n function depth(State storage self, Tick tick) internal view returns (uint64) {\\n return self.queues[tick].tree.total() - self.totalClaimableOf.get(tick);\\n }\\n\\n function highest(State storage self) internal view returns (Tick) {\\n return self.tickBitmap.highest();\\n }\\n\\n function maxLessThan(State storage self, Tick tick) internal view returns (Tick) {\\n return self.tickBitmap.maxLessThan(tick);\\n }\\n\\n function isEmpty(State storage self) internal view returns (bool) {\\n return self.tickBitmap.isEmpty();\\n }\\n\\n function _getOrder(State storage self, Tick tick, uint40 index) private view returns (Order storage) {\\n return self.queues[tick].orders[index];\\n }\\n\\n function getOrder(State storage self, Tick tick, uint40 index) internal view returns (Order memory) {\\n return _getOrder(self, tick, index);\\n }\\n\\n function make(State storage self, Tick tick, uint64 unit, address provider) external returns (uint40 orderIndex) {\\n if (unit == 0) revert ZeroUnit();\\n if (!self.tickBitmap.has(tick)) self.tickBitmap.set(tick);\\n\\n Queue storage queue = self.queues[tick];\\n // @dev Assume that orders.length cannot reach to type(uint40).max + 1.\\n orderIndex = SafeCast.toUint40(queue.orders.length);\\n\\n if (orderIndex >= MAX_ORDER) {\\n unchecked {\\n uint40 staleOrderIndex = orderIndex - MAX_ORDER;\\n uint64 stalePendingUnit = queue.orders[staleOrderIndex].pending;\\n if (stalePendingUnit > 0) {\\n // If the order is not settled completely, we cannot replace it\\n uint64 claimable = calculateClaimableUnit(self, tick, staleOrderIndex);\\n if (claimable != stalePendingUnit) revert QueueReplaceFailed();\\n }\\n }\\n\\n // The stale order is settled completely, so remove it from the totalClaimableOf.\\n // We can determine the stale order is claimable.\\n uint64 staleOrderedUnit = queue.tree.get(orderIndex & MAX_ORDER_M);\\n if (staleOrderedUnit > 0) self.totalClaimableOf.sub(tick, staleOrderedUnit);\\n }\\n\\n queue.tree.update(orderIndex & MAX_ORDER_M, unit);\\n\\n queue.orders.push(Order({pending: unit, provider: provider}));\\n }\\n\\n /**\\n * @notice Take orders from the book\\n * @param self The book state\\n * @param maxTakeUnit The maximum unit to take\\n * @return takenUnit The actual unit to take\\n */\\n function take(State storage self, Tick tick, uint64 maxTakeUnit) external returns (uint64 takenUnit) {\\n uint64 currentDepth = depth(self, tick);\\n if (currentDepth > maxTakeUnit) {\\n takenUnit = maxTakeUnit;\\n } else {\\n takenUnit = currentDepth;\\n self.tickBitmap.clear(tick);\\n }\\n\\n self.totalClaimableOf.add(tick, takenUnit);\\n }\\n\\n function cancel(State storage self, OrderId orderId, uint64 to)\\n external\\n returns (uint64 canceled, uint64 afterPending)\\n {\\n (, Tick tick, uint40 orderIndex) = orderId.decode();\\n Queue storage queue = self.queues[tick];\\n uint64 pendingUnit = queue.orders[orderIndex].pending;\\n uint64 claimableUnit = calculateClaimableUnit(self, tick, orderIndex);\\n afterPending = to + claimableUnit;\\n unchecked {\\n if (pendingUnit < afterPending) revert CancelFailed(pendingUnit - claimableUnit);\\n canceled = pendingUnit - afterPending;\\n\\n self.queues[tick].tree.update(\\n orderIndex & MAX_ORDER_M, self.queues[tick].tree.get(orderIndex & MAX_ORDER_M) - canceled\\n );\\n }\\n queue.orders[orderIndex].pending = afterPending;\\n\\n if (depth(self, tick) == 0) {\\n // clear() won't revert so we can cancel with to=0 even if the depth() is already zero\\n // works even if bitmap is empty\\n self.tickBitmap.clear(tick);\\n }\\n }\\n\\n function claim(State storage self, Tick tick, uint40 index) external returns (uint64 claimedUnit) {\\n Order storage order = _getOrder(self, tick, index);\\n\\n claimedUnit = calculateClaimableUnit(self, tick, index);\\n unchecked {\\n order.pending -= claimedUnit;\\n }\\n }\\n\\n function calculateClaimableUnit(State storage self, Tick tick, uint40 index) public view returns (uint64) {\\n uint64 orderUnit = self.getOrder(tick, index).pending;\\n\\n Queue storage queue = self.queues[tick];\\n // @dev Book logic always considers replaced orders as claimable.\\n unchecked {\\n if (uint256(index) + MAX_ORDER < queue.orders.length) return orderUnit;\\n uint64 totalClaimableUnit = self.totalClaimableOf.get(tick);\\n uint64 rangeRight = _getClaimRangeRight(queue, index);\\n if (rangeRight - orderUnit >= totalClaimableUnit) return 0;\\n\\n // -------- totalClaimable ---------|---\\n // ------|---- orderUnit ----|--------\\n // rangeLeft rangeRight\\n if (rangeRight <= totalClaimableUnit) return orderUnit;\\n // -- totalClaimable --|----------------\\n // ------|---- orderUnit ----|--------\\n // rangeLeft rangeRight\\n else return totalClaimableUnit - (rangeRight - orderUnit);\\n }\\n }\\n\\n function _getClaimRangeRight(Queue storage queue, uint256 orderIndex) private view returns (uint64 rangeRight) {\\n uint256 l = queue.orders.length & MAX_ORDER_M;\\n uint256 r = (orderIndex + 1) & MAX_ORDER_M;\\n rangeRight = (l < r) ? queue.tree.query(l, r) : queue.tree.total() - queue.tree.query(r, l);\\n }\\n}\\n\",\"keccak256\":\"0x8c15ba2fe1bb7f08ed5767c66b4d250e0b00863e4eae25781b3296636bddcdc0\",\"license\":\"-\"},\"src/libraries/BookId.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-2.0-or-later\\n\\npragma solidity ^0.8.20;\\n\\nimport {IBookManager} from \\\"../interfaces/IBookManager.sol\\\";\\n\\ntype BookId is uint192;\\n\\nlibrary BookIdLibrary {\\n function toId(IBookManager.BookKey memory bookKey) internal pure returns (BookId id) {\\n bytes32 hash = keccak256(abi.encode(bookKey));\\n assembly {\\n id := and(hash, 0xffffffffffffffffffffffffffffffffffffffffffffffff)\\n }\\n }\\n}\\n\",\"keccak256\":\"0x60f9ed99dfb9a5ce14c29359a5ad8b43de0c756e44b2e5f581e8ea6db7cacbeb\",\"license\":\"GPL-2.0-or-later\"},\"src/libraries/Currency.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-2.0-or-later\\n\\npragma solidity ^0.8.20;\\n\\nimport {IERC20} from \\\"@openzeppelin/contracts/token/ERC20/IERC20.sol\\\";\\n\\ntype Currency is address;\\n\\n/// @title CurrencyLibrary\\n/// @dev This library allows for transferring and holding native tokens and ERC20 tokens\\nlibrary CurrencyLibrary {\\n using CurrencyLibrary for Currency;\\n\\n /// @notice Thrown when a native transfer fails\\n error NativeTransferFailed();\\n\\n /// @notice Thrown when an ERC20 transfer fails\\n error ERC20TransferFailed();\\n\\n Currency public constant NATIVE = Currency.wrap(address(0));\\n\\n function transfer(Currency currency, address to, uint256 amount) internal {\\n // implementation from\\n // https://github.com/transmissions11/solmate/blob/e8f96f25d48fe702117ce76c79228ca4f20206cb/src/utils/SafeTransferLib.sol\\n\\n bool success;\\n if (currency.isNative()) {\\n assembly {\\n // Transfer the ETH and store if it succeeded or not.\\n success := call(gas(), to, amount, 0, 0, 0, 0)\\n }\\n\\n if (!success) revert NativeTransferFailed();\\n } else {\\n assembly {\\n // Get a pointer to some free memory.\\n let freeMemoryPointer := mload(0x40)\\n\\n // Write the abi-encoded calldata into memory, beginning with the function selector.\\n mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)\\n mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the \\\"to\\\" argument.\\n mstore(add(freeMemoryPointer, 36), amount) // Append the \\\"amount\\\" argument. Masking not required as it's a full 32 byte type.\\n\\n success :=\\n and(\\n // Set success to whether the call reverted, if not we check it either\\n // returned exactly 1 (can't just be non-zero data), or had no return data.\\n or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),\\n // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.\\n // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.\\n // Counterintuitively, this call must be positioned second to the or() call in the\\n // surrounding and() call or else returndatasize() will be zero during the computation.\\n call(gas(), currency, 0, freeMemoryPointer, 68, 0, 32)\\n )\\n }\\n\\n if (!success) revert ERC20TransferFailed();\\n }\\n }\\n\\n function balanceOfSelf(Currency currency) internal view returns (uint256) {\\n if (currency.isNative()) return address(this).balance;\\n else return IERC20(Currency.unwrap(currency)).balanceOf(address(this));\\n }\\n\\n function equals(Currency currency, Currency other) internal pure returns (bool) {\\n return Currency.unwrap(currency) == Currency.unwrap(other);\\n }\\n\\n function isNative(Currency currency) internal pure returns (bool) {\\n return Currency.unwrap(currency) == Currency.unwrap(NATIVE);\\n }\\n\\n function toId(Currency currency) internal pure returns (uint256) {\\n return uint160(Currency.unwrap(currency));\\n }\\n\\n function fromId(uint256 id) internal pure returns (Currency) {\\n return Currency.wrap(address(uint160(id)));\\n }\\n}\\n\",\"keccak256\":\"0xf04f76015a51981ad0f84fd3ebb0a4eb6c31685604c22584669915aa8dd7ac54\",\"license\":\"GPL-2.0-or-later\"},\"src/libraries/DirtyUint64.sol\":{\"content\":\"// SPDX-License-Identifier: -\\n// License: https://license.clober.io/LICENSE.pdf\\n\\npragma solidity ^0.8.0;\\n\\nlibrary DirtyUint64 {\\n error DirtyUint64Error(uint256 errorCode);\\n\\n uint256 private constant _OVERFLOW_ERROR = 0;\\n uint256 private constant _UNDERFLOW_ERROR = 1;\\n\\n function toDirtyUnsafe(uint64 cleanUint) internal pure returns (uint64 dirtyUint) {\\n assembly {\\n dirtyUint := add(cleanUint, 1)\\n }\\n }\\n\\n function toDirty(uint64 cleanUint) internal pure returns (uint64 dirtyUint) {\\n assembly {\\n dirtyUint := add(cleanUint, 1)\\n }\\n if (dirtyUint == 0) {\\n revert DirtyUint64Error(_OVERFLOW_ERROR);\\n }\\n }\\n\\n function toClean(uint64 dirtyUint) internal pure returns (uint64 cleanUint) {\\n assembly {\\n cleanUint := sub(dirtyUint, gt(dirtyUint, 0))\\n }\\n }\\n\\n function addClean(uint64 current, uint64 cleanUint) internal pure returns (uint64) {\\n assembly {\\n current := add(add(current, iszero(current)), cleanUint)\\n }\\n if (current < cleanUint) {\\n revert DirtyUint64Error(_OVERFLOW_ERROR);\\n }\\n return current;\\n }\\n\\n function addDirty(uint64 current, uint64 dirtyUint) internal pure returns (uint64) {\\n assembly {\\n current := sub(add(add(current, iszero(current)), add(dirtyUint, iszero(dirtyUint))), 1)\\n }\\n if (current < dirtyUint) {\\n revert DirtyUint64Error(_OVERFLOW_ERROR);\\n }\\n return current;\\n }\\n\\n function subClean(uint64 current, uint64 cleanUint) internal pure returns (uint64 ret) {\\n assembly {\\n current := add(current, iszero(current))\\n ret := sub(current, cleanUint)\\n }\\n if (current < ret || ret == 0) {\\n revert DirtyUint64Error(_UNDERFLOW_ERROR);\\n }\\n }\\n\\n function subDirty(uint64 current, uint64 dirtyUint) internal pure returns (uint64 ret) {\\n assembly {\\n current := add(current, iszero(current))\\n ret := sub(add(current, 1), add(dirtyUint, iszero(dirtyUint)))\\n }\\n if (current < ret || ret == 0) {\\n revert DirtyUint64Error(_UNDERFLOW_ERROR);\\n }\\n }\\n\\n function sumPackedUnsafe(uint256 packed, uint256 from, uint256 to) internal pure returns (uint64 ret) {\\n packed = packed >> (from << 6);\\n unchecked {\\n for (uint256 i = from; i < to; ++i) {\\n assembly {\\n let element := and(packed, 0xffffffffffffffff)\\n ret := add(ret, add(element, iszero(element)))\\n packed := shr(64, packed)\\n }\\n }\\n }\\n assembly {\\n ret := sub(ret, sub(to, from))\\n }\\n }\\n}\\n\",\"keccak256\":\"0xe9021ccfef31d7fc17242134eea12c0313bf38a2998c46ac91eb2b34e76fc8db\",\"license\":\"-\"},\"src/libraries/FeePolicy.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-2.0-or-later\\n\\npragma solidity ^0.8.20;\\n\\nimport {Math} from \\\"./Math.sol\\\";\\n\\ntype FeePolicy is uint24;\\n\\nlibrary FeePolicyLibrary {\\n uint256 internal constant RATE_PRECISION = 10 ** 6;\\n int256 internal constant MAX_FEE_RATE = 500000;\\n int256 internal constant MIN_FEE_RATE = -500000;\\n\\n uint256 internal constant RATE_MASK = 0x7fffff; // 23 bits\\n\\n error InvalidFeePolicy();\\n\\n function encode(bool usesQuote_, int24 rate_) internal pure returns (FeePolicy feePolicy) {\\n if (rate_ > MAX_FEE_RATE || rate_ < MIN_FEE_RATE) {\\n revert InvalidFeePolicy();\\n }\\n\\n uint256 mask = usesQuote_ ? 1 << 23 : 0;\\n assembly {\\n feePolicy := or(mask, add(and(rate_, 0xffffff), MAX_FEE_RATE))\\n }\\n }\\n\\n function isValid(FeePolicy self) internal pure returns (bool) {\\n int24 r = rate(self);\\n\\n return !(r > MAX_FEE_RATE || r < MIN_FEE_RATE);\\n }\\n\\n function usesQuote(FeePolicy self) internal pure returns (bool f) {\\n assembly {\\n f := shr(23, self)\\n }\\n }\\n\\n function rate(FeePolicy self) internal pure returns (int24 r) {\\n assembly {\\n r := sub(and(self, RATE_MASK), MAX_FEE_RATE)\\n }\\n }\\n\\n function calculateFee(FeePolicy self, uint256 amount, bool reverseRounding) internal pure returns (int256 fee) {\\n int24 r = rate(self);\\n\\n bool positive = r > 0;\\n uint256 absRate;\\n unchecked {\\n absRate = uint256(uint24(positive ? r : -r));\\n }\\n // @dev absFee must be less than type(int256).max\\n uint256 absFee = Math.divide(amount * absRate, RATE_PRECISION, reverseRounding ? !positive : positive);\\n fee = positive ? int256(absFee) : -int256(absFee);\\n }\\n\\n function calculateOriginalAmount(FeePolicy self, uint256 amount, bool reverseFee)\\n internal\\n pure\\n returns (uint256 originalAmount)\\n {\\n int24 r = rate(self);\\n\\n bool positive = r > 0;\\n uint256 divider;\\n assembly {\\n if reverseFee { r := sub(0, r) }\\n divider := add(RATE_PRECISION, r)\\n }\\n originalAmount = Math.divide(amount * RATE_PRECISION, divider, positive);\\n }\\n}\\n\",\"keccak256\":\"0x91f98ffef9d8a0bb460bcbc31d10820d9a1bee9bbf3df04eef23ca2937a4a26a\",\"license\":\"GPL-2.0-or-later\"},\"src/libraries/Math.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-2.0-or-later\\n\\npragma solidity ^0.8.0;\\n\\nlibrary Math {\\n function divide(uint256 a, uint256 b, bool roundingUp) internal pure returns (uint256 ret) {\\n // In the OrderBook contract code, b is never zero.\\n assembly {\\n ret := add(div(a, b), and(gt(mod(a, b), 0), roundingUp))\\n }\\n }\\n\\n /// @dev Returns `ln(x)`, denominated in `WAD`.\\n /// Credit to Remco Bloemen under MIT license: https://2\\u03c0.com/22/exp-ln\\n function lnWad(int256 x) internal pure returns (int256 r) {\\n /// @solidity memory-safe-assembly\\n assembly {\\n // We want to convert `x` from `10**18` fixed point to `2**96` fixed point.\\n // We do this by multiplying by `2**96 / 10**18`. But since\\n // `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here\\n // and add `ln(2**96 / 10**18)` at the end.\\n\\n // Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`.\\n r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\\n r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))\\n r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\\n r := or(r, shl(4, lt(0xffff, shr(r, x))))\\n r := or(r, shl(3, lt(0xff, shr(r, x))))\\n // We place the check here for more optimal stack operations.\\n if iszero(sgt(x, 0)) {\\n mstore(0x00, 0x1615e638) // `LnWadUndefined()`.\\n revert(0x1c, 0x04)\\n }\\n // forgefmt: disable-next-item\\n r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),\\n 0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff))\\n\\n // Reduce range of x to (1, 2) * 2**96\\n // ln(2^k * x) = k * ln(2) + ln(x)\\n x := shr(159, shl(r, x))\\n\\n // Evaluate using a (8, 8)-term rational approximation.\\n // `p` is made monic, we will multiply by a scale factor later.\\n // forgefmt: disable-next-item\\n let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir.\\n sar(96, mul(add(43456485725739037958740375743393,\\n sar(96, mul(add(24828157081833163892658089445524,\\n sar(96, mul(add(3273285459638523848632254066296,\\n x), x))), x))), x)), 11111509109440967052023855526967)\\n p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857)\\n p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526)\\n p := sub(mul(p, x), shl(96, 795164235651350426258249787498))\\n // We leave `p` in `2**192` basis so we don't need to scale it back up for the division.\\n\\n // `q` is monic by convention.\\n let q := add(5573035233440673466300451813936, x)\\n q := add(71694874799317883764090561454958, sar(96, mul(x, q)))\\n q := add(283447036172924575727196451306956, sar(96, mul(x, q)))\\n q := add(401686690394027663651624208769553, sar(96, mul(x, q)))\\n q := add(204048457590392012362485061816622, sar(96, mul(x, q)))\\n q := add(31853899698501571402653359427138, sar(96, mul(x, q)))\\n q := add(909429971244387300277376558375, sar(96, mul(x, q)))\\n\\n // `p / q` is in the range `(0, 0.125) * 2**96`.\\n\\n // Finalization, we need to:\\n // - Multiply by the scale factor `s = 5.549\\u2026`.\\n // - Add `ln(2**96 / 10**18)`.\\n // - Add `k * ln(2)`.\\n // - Multiply by `10**18 / 2**96 = 5**18 >> 78`.\\n\\n // The q polynomial is known not to have zeros in the domain.\\n // No scaling required because p is already `2**96` too large.\\n p := sdiv(p, q)\\n // Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`.\\n p := mul(1677202110996718588342820967067443963516166, p)\\n // Add `ln(2) * k * 5**18 * 2**192`.\\n // forgefmt: disable-next-item\\n p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p)\\n // Base conversion: mul `2**96 / (5**18 * 2**192)`.\\n r := sdiv(p, 302231454903657293676544000000000000000000)\\n }\\n }\\n}\\n\",\"keccak256\":\"0xb2dc502dd66a9e36e6c4bb8c4fb3d21120f9f0ff7a934dcfe21ec820cac72275\",\"license\":\"GPL-2.0-or-later\"},\"src/libraries/OrderId.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-2.0-or-later\\n\\npragma solidity ^0.8.0;\\n\\nimport {Tick} from \\\"./Tick.sol\\\";\\nimport {BookId} from \\\"./BookId.sol\\\";\\n\\ntype OrderId is uint256;\\n\\nlibrary OrderIdLibrary {\\n /**\\n * @dev Encode the order id.\\n * @param bookId The book id.\\n * @param tick The tick.\\n * @param index The index.\\n * @return id The order id.\\n */\\n function encode(BookId bookId, Tick tick, uint40 index) internal pure returns (OrderId id) {\\n // @dev If we just use tick at the assembly code, the code will convert tick into bytes32.\\n // e.g. When index == -2, the shifted value( shl(40, tick) ) will be\\n // 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0000000000 instead of 0xfffffffe0000000000\\n // Therefore, we have to safely cast tick into uint256 first.\\n uint256 _tick = uint256(uint24(Tick.unwrap(tick)));\\n assembly {\\n id := add(index, add(shl(40, _tick), shl(64, bookId)))\\n }\\n }\\n\\n function decode(OrderId id) internal pure returns (BookId bookId, Tick tick, uint40 index) {\\n assembly {\\n bookId := shr(64, id)\\n tick := and(shr(40, id), 0xffffff)\\n index := and(id, 0xffffffffff)\\n }\\n }\\n\\n function getBookId(OrderId id) internal pure returns (BookId bookId) {\\n assembly {\\n bookId := shr(64, id)\\n }\\n }\\n\\n function getTick(OrderId id) internal pure returns (Tick tick) {\\n assembly {\\n tick := and(shr(40, id), 0xffffff)\\n }\\n }\\n\\n function getIndex(OrderId id) internal pure returns (uint40 index) {\\n assembly {\\n index := and(id, 0xffffffffff)\\n }\\n }\\n}\\n\",\"keccak256\":\"0x78c384badc4971d774987c6f5bce9d578712c7469688735b3c1eafaf2e748fe6\",\"license\":\"GPL-2.0-or-later\"},\"src/libraries/PackedUint256.sol\":{\"content\":\"// SPDX-License-Identifier: -\\n// License: https://license.clober.io/LICENSE.pdf\\n\\npragma solidity ^0.8.0;\\n\\nlibrary PackedUint256 {\\n error PackedUint256Error(uint256 errorCode);\\n\\n uint256 private constant _UINT8_INDEX_ERROR = 0;\\n uint256 private constant _UINT16_INDEX_ERROR = 1;\\n uint256 private constant _UINT32_INDEX_ERROR = 2;\\n uint256 private constant _UINT64_INDEX_ERROR = 3;\\n\\n uint256 private constant _MAX_UINT64 = type(uint64).max;\\n uint256 private constant _MAX_UINT32 = type(uint32).max;\\n uint256 private constant _MAX_UINT16 = type(uint16).max;\\n uint256 private constant _MAX_UINT8 = type(uint8).max;\\n\\n function get8Unsafe(uint256 packed, uint256 index) internal pure returns (uint8 ret) {\\n assembly {\\n ret := and(shr(shl(3, index), packed), 0xff)\\n }\\n }\\n\\n function get8(uint256 packed, uint256 index) internal pure returns (uint8 ret) {\\n if (index > 31) {\\n revert PackedUint256Error(_UINT8_INDEX_ERROR);\\n }\\n assembly {\\n ret := and(shr(shl(3, index), packed), 0xff)\\n }\\n }\\n\\n function get16Unsafe(uint256 packed, uint256 index) internal pure returns (uint16 ret) {\\n assembly {\\n ret := and(shr(shl(4, index), packed), 0xffff)\\n }\\n }\\n\\n function get16(uint256 packed, uint256 index) internal pure returns (uint16 ret) {\\n if (index > 15) {\\n revert PackedUint256Error(_UINT16_INDEX_ERROR);\\n }\\n assembly {\\n ret := and(shr(shl(4, index), packed), 0xffff)\\n }\\n }\\n\\n function get32Unsafe(uint256 packed, uint256 index) internal pure returns (uint32 ret) {\\n assembly {\\n ret := and(shr(shl(5, index), packed), 0xffffffff)\\n }\\n }\\n\\n function get32(uint256 packed, uint256 index) internal pure returns (uint32 ret) {\\n if (index > 7) {\\n revert PackedUint256Error(_UINT32_INDEX_ERROR);\\n }\\n assembly {\\n ret := and(shr(shl(5, index), packed), 0xffffffff)\\n }\\n }\\n\\n function get64Unsafe(uint256 packed, uint256 index) internal pure returns (uint64 ret) {\\n assembly {\\n ret := and(shr(shl(6, index), packed), 0xffffffffffffffff)\\n }\\n }\\n\\n function get64(uint256 packed, uint256 index) internal pure returns (uint64 ret) {\\n if (index > 3) {\\n revert PackedUint256Error(_UINT64_INDEX_ERROR);\\n }\\n assembly {\\n ret := and(shr(shl(6, index), packed), 0xffffffffffffffff)\\n }\\n }\\n\\n function add8Unsafe(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := add(packed, shl(shl(3, index), and(value, 0xff)))\\n }\\n }\\n\\n function add8(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\\n if (index > 31) {\\n revert PackedUint256Error(_UINT8_INDEX_ERROR);\\n }\\n uint8 current = get8Unsafe(packed, index);\\n current += value;\\n ret = update8Unsafe(packed, index, current);\\n }\\n\\n function add16Unsafe(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := add(packed, shl(shl(4, index), and(value, 0xffff)))\\n }\\n }\\n\\n function add16(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\\n if (index > 15) {\\n revert PackedUint256Error(_UINT16_INDEX_ERROR);\\n }\\n uint16 current = get16Unsafe(packed, index);\\n current += value;\\n ret = update16Unsafe(packed, index, current);\\n }\\n\\n function add32Unsafe(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := add(packed, shl(shl(5, index), and(value, 0xffffffff)))\\n }\\n }\\n\\n function add32(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\\n if (index > 7) {\\n revert PackedUint256Error(_UINT32_INDEX_ERROR);\\n }\\n uint32 current = get32Unsafe(packed, index);\\n current += value;\\n ret = update32Unsafe(packed, index, current);\\n }\\n\\n function add64Unsafe(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := add(packed, shl(shl(6, index), and(value, 0xffffffffffffffff)))\\n }\\n }\\n\\n function add64(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\\n if (index > 3) {\\n revert PackedUint256Error(_UINT64_INDEX_ERROR);\\n }\\n uint64 current = get64Unsafe(packed, index);\\n current += value;\\n ret = update64Unsafe(packed, index, current);\\n }\\n\\n function sub8Unsafe(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := sub(packed, shl(shl(3, index), and(value, 0xff)))\\n }\\n }\\n\\n function sub8(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\\n if (index > 31) {\\n revert PackedUint256Error(_UINT8_INDEX_ERROR);\\n }\\n uint8 current = get8Unsafe(packed, index);\\n current -= value;\\n ret = update8Unsafe(packed, index, current);\\n }\\n\\n function sub16Unsafe(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := sub(packed, shl(shl(4, index), and(value, 0xffff)))\\n }\\n }\\n\\n function sub16(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\\n if (index > 15) {\\n revert PackedUint256Error(_UINT16_INDEX_ERROR);\\n }\\n uint16 current = get16Unsafe(packed, index);\\n current -= value;\\n ret = update16Unsafe(packed, index, current);\\n }\\n\\n function sub32Unsafe(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := sub(packed, shl(shl(5, index), and(value, 0xffffffff)))\\n }\\n }\\n\\n function sub32(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\\n if (index > 7) {\\n revert PackedUint256Error(_UINT32_INDEX_ERROR);\\n }\\n uint32 current = get32Unsafe(packed, index);\\n current -= value;\\n ret = update32Unsafe(packed, index, current);\\n }\\n\\n function sub64Unsafe(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := sub(packed, shl(shl(6, index), and(value, 0xffffffffffffffff)))\\n }\\n }\\n\\n function sub64(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\\n if (index > 3) {\\n revert PackedUint256Error(_UINT64_INDEX_ERROR);\\n }\\n uint64 current = get64Unsafe(packed, index);\\n current -= value;\\n ret = update64Unsafe(packed, index, current);\\n }\\n\\n function update8Unsafe(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\\n unchecked {\\n index = index << 3;\\n packed = packed - (packed & (_MAX_UINT8 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xff)))\\n }\\n }\\n\\n function update8(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\\n if (index > 31) {\\n revert PackedUint256Error(_UINT8_INDEX_ERROR);\\n }\\n unchecked {\\n index = index << 3;\\n packed = packed - (packed & (_MAX_UINT8 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xff)))\\n }\\n }\\n\\n function update16Unsafe(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\\n unchecked {\\n index = index << 4;\\n packed = packed - (packed & (_MAX_UINT16 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xffff)))\\n }\\n }\\n\\n function update16(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\\n if (index > 15) {\\n revert PackedUint256Error(_UINT16_INDEX_ERROR);\\n }\\n unchecked {\\n index = index << 4;\\n packed = packed - (packed & (_MAX_UINT16 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xffff)))\\n }\\n }\\n\\n function update32Unsafe(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\\n unchecked {\\n index = index << 5;\\n packed = packed - (packed & (_MAX_UINT32 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xffffffff)))\\n }\\n }\\n\\n function update32(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\\n if (index > 7) {\\n revert PackedUint256Error(_UINT32_INDEX_ERROR);\\n }\\n unchecked {\\n index = index << 5;\\n packed = packed - (packed & (_MAX_UINT32 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xffffffff)))\\n }\\n }\\n\\n function update64Unsafe(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\\n unchecked {\\n index = index << 6;\\n packed = packed - (packed & (_MAX_UINT64 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xffffffffffffffff)))\\n }\\n }\\n\\n function update64(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\\n if (index > 3) {\\n revert PackedUint256Error(_UINT64_INDEX_ERROR);\\n }\\n unchecked {\\n index = index << 6;\\n packed = packed - (packed & (_MAX_UINT64 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xffffffffffffffff)))\\n }\\n }\\n\\n function total32(uint256 packed) internal pure returns (uint256) {\\n unchecked {\\n uint256 ret = _MAX_UINT32 & packed;\\n for (uint256 i = 0; i < 7; ++i) {\\n packed = packed >> 32;\\n ret += _MAX_UINT32 & packed;\\n }\\n return ret;\\n }\\n }\\n\\n function total64(uint256 packed) internal pure returns (uint256) {\\n unchecked {\\n uint256 ret = _MAX_UINT64 & packed;\\n for (uint256 i = 0; i < 3; ++i) {\\n packed = packed >> 64;\\n ret += _MAX_UINT64 & packed;\\n }\\n return ret;\\n }\\n }\\n\\n function sum32(uint256 packed, uint256 from, uint256 to) internal pure returns (uint256) {\\n unchecked {\\n packed = packed >> (from << 5);\\n uint256 ret = 0;\\n for (uint256 i = from; i < to; ++i) {\\n ret += _MAX_UINT32 & packed;\\n packed = packed >> 32;\\n }\\n return ret;\\n }\\n }\\n\\n function sum64(uint256 packed, uint256 from, uint256 to) internal pure returns (uint256) {\\n unchecked {\\n packed = packed >> (from << 6);\\n uint256 ret = 0;\\n for (uint256 i = from; i < to; ++i) {\\n ret += _MAX_UINT64 & packed;\\n packed = packed >> 64;\\n }\\n return ret;\\n }\\n }\\n}\\n\",\"keccak256\":\"0x02c63e757709f39c3e46e4350ecf1df15f423f512eed51fef34f584fdb219c82\",\"license\":\"-\"},\"src/libraries/SegmentedSegmentTree.sol\":{\"content\":\"// SPDX-License-Identifier: -\\n// License: https://license.clober.io/LICENSE.pdf\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./PackedUint256.sol\\\";\\nimport \\\"./DirtyUint64.sol\\\";\\n\\n/**\\n * \\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\n *\\n * Segmented Segment Tree\\n * by Clober\\n *\\n * ____________/\\\\\\\\\\\\_______________/\\\\\\\\\\\\\\\\\\\\____________/\\\\\\\\\\\\____\\n * __________/\\\\\\\\\\\\\\\\\\\\___________/\\\\\\\\\\\\\\\\////___________/\\\\\\\\\\\\\\\\\\\\____\\n * ________/\\\\\\\\\\\\/\\\\\\\\\\\\________/\\\\\\\\\\\\///______________/\\\\\\\\\\\\/\\\\\\\\\\\\____\\n * ______/\\\\\\\\\\\\/\\\\/\\\\\\\\\\\\______/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_________/\\\\\\\\\\\\/\\\\/\\\\\\\\\\\\____\\n * ____/\\\\\\\\\\\\/__\\\\/\\\\\\\\\\\\_____/\\\\\\\\\\\\\\\\///////\\\\\\\\\\\\_____/\\\\\\\\\\\\/__\\\\/\\\\\\\\\\\\____\\n * __/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_\\\\/\\\\\\\\\\\\______\\\\//\\\\\\\\\\\\__/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_\\n * _\\\\///////////\\\\\\\\\\\\//__\\\\//\\\\\\\\\\\\______/\\\\\\\\\\\\__\\\\///////////\\\\\\\\\\\\//__\\n * ___________\\\\/\\\\\\\\\\\\_____\\\\///\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/_____________\\\\/\\\\\\\\\\\\____\\n * ___________\\\\///________\\\\/////////_______________\\\\///_____\\n *\\n * 4 Layers of 64-bit nodes, hence 464\\n *\\n * \\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\n */\\nlibrary SegmentedSegmentTree {\\n using PackedUint256 for uint256;\\n using DirtyUint64 for uint64;\\n\\n error SegmentedSegmentTreeError(uint256 errorCode);\\n\\n uint256 private constant _INDEX_ERROR = 0;\\n uint256 private constant _OVERFLOW_ERROR = 1;\\n\\n // uint8 private constant _R = 2; // There are `2` root node groups\\n // uint8 private constant _C = 4; // There are `4` children (each child is a node group of its own) for each node\\n uint8 private constant _L = 4; // There are `4` layers of node groups\\n uint256 private constant _P = 4; // uint256 / uint64 = `4`\\n uint256 private constant _P_M = 3; // % 4 = & `3`\\n uint256 private constant _P_P = 2; // 2 ** `2` = 4\\n uint256 private constant _N_P = 4; // C * P = 2 ** `4`\\n uint256 private constant _MAX_NODES = 2 ** 15; // (R * P) * ((C * P) ** (L - 1)) = `32768`\\n uint256 private constant _MAX_NODES_P_MINUS_ONE = 14; // MAX_NODES / R = 2 ** `14`\\n\\n struct Core {\\n mapping(uint256 => uint256)[_L] layers;\\n }\\n\\n struct LayerIndex {\\n uint256 group;\\n uint256 node;\\n }\\n\\n function get(Core storage core, uint256 index) internal view returns (uint64 ret) {\\n if (index >= _MAX_NODES) {\\n revert SegmentedSegmentTreeError(_INDEX_ERROR);\\n }\\n unchecked {\\n ret = core.layers[_L - 1][index >> _P_P].get64(index & _P_M).toClean();\\n }\\n }\\n\\n function total(Core storage core) internal view returns (uint64) {\\n return DirtyUint64.sumPackedUnsafe(core.layers[0][0], 0, _P)\\n + DirtyUint64.sumPackedUnsafe(core.layers[0][1], 0, _P);\\n }\\n\\n function query(Core storage core, uint256 left, uint256 right) internal view returns (uint64 sum) {\\n if (left == right) {\\n return 0;\\n }\\n // right should be greater than left\\n if (left >= right) {\\n revert SegmentedSegmentTreeError(_INDEX_ERROR);\\n }\\n if (right > _MAX_NODES) {\\n revert SegmentedSegmentTreeError(_INDEX_ERROR);\\n }\\n\\n LayerIndex[] memory leftIndices = _getLayerIndices(left);\\n LayerIndex[] memory rightIndices = _getLayerIndices(right);\\n uint256 ret;\\n uint256 deficit;\\n\\n unchecked {\\n uint256 leftNodeIndex;\\n uint256 rightNodeIndex;\\n for (uint256 l = _L - 1;; --l) {\\n LayerIndex memory leftIndex = leftIndices[l];\\n LayerIndex memory rightIndex = rightIndices[l];\\n leftNodeIndex += leftIndex.node;\\n rightNodeIndex += rightIndex.node;\\n\\n if (rightIndex.group == leftIndex.group) {\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, rightNodeIndex);\\n break;\\n }\\n\\n if (rightIndex.group - leftIndex.group < 4) {\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, _P);\\n\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], 0, rightNodeIndex);\\n\\n for (uint256 group = leftIndex.group + 1; group < rightIndex.group; group++) {\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][group], 0, _P);\\n }\\n break;\\n }\\n\\n if (leftIndex.group % 4 == 0) {\\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], 0, leftNodeIndex);\\n leftNodeIndex = 0;\\n } else if (leftIndex.group % 4 == 1) {\\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group - 1], 0, _P);\\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], 0, leftNodeIndex);\\n leftNodeIndex = 0;\\n } else if (leftIndex.group % 4 == 2) {\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, _P);\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group + 1], 0, _P);\\n leftNodeIndex = 1;\\n } else {\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, _P);\\n leftNodeIndex = 1;\\n }\\n\\n if (rightIndex.group % 4 == 0) {\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], 0, rightNodeIndex);\\n rightNodeIndex = 0;\\n } else if (rightIndex.group % 4 == 1) {\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group - 1], 0, _P);\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], 0, rightNodeIndex);\\n rightNodeIndex = 0;\\n } else if (rightIndex.group % 4 == 2) {\\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], rightNodeIndex, _P);\\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group + 1], 0, _P);\\n rightNodeIndex = 1;\\n } else {\\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], rightNodeIndex, _P);\\n rightNodeIndex = 1;\\n }\\n }\\n ret -= deficit;\\n }\\n sum = uint64(ret);\\n }\\n\\n function update(Core storage core, uint256 index, uint64 value) internal returns (uint64 replaced) {\\n if (index >= _MAX_NODES) {\\n revert SegmentedSegmentTreeError(_INDEX_ERROR);\\n }\\n LayerIndex[] memory indices = _getLayerIndices(index);\\n unchecked {\\n LayerIndex memory bottomIndex = indices[_L - 1];\\n replaced = core.layers[_L - 1][bottomIndex.group].get64Unsafe(bottomIndex.node).toClean();\\n if (replaced >= value) {\\n uint64 diff = replaced - value;\\n for (uint256 l = 0; l < _L; ++l) {\\n LayerIndex memory layerIndex = indices[l];\\n uint256 node = core.layers[l][layerIndex.group];\\n core.layers[l][layerIndex.group] =\\n node.update64(layerIndex.node, node.get64(layerIndex.node).subClean(diff));\\n }\\n } else {\\n uint64 diff = value - replaced;\\n if (total(core) > type(uint64).max - diff) revert SegmentedSegmentTreeError(_OVERFLOW_ERROR);\\n for (uint256 l = 0; l < _L; ++l) {\\n LayerIndex memory layerIndex = indices[l];\\n uint256 node = core.layers[l][layerIndex.group];\\n core.layers[l][layerIndex.group] =\\n node.update64(layerIndex.node, node.get64(layerIndex.node).addClean(diff));\\n }\\n }\\n }\\n }\\n\\n function _getLayerIndices(uint256 index) private pure returns (LayerIndex[] memory) {\\n unchecked {\\n LayerIndex[] memory indices = new LayerIndex[](_L);\\n uint256 shifter = _MAX_NODES_P_MINUS_ONE;\\n for (uint256 l = 0; l < _L; ++l) {\\n indices[l] = LayerIndex({group: index >> shifter, node: (index >> (shifter - _P_P)) & _P_M});\\n shifter = shifter - _N_P;\\n }\\n return indices;\\n }\\n }\\n}\\n\\n/*\\n * Segmented Segment Tree is a Segment Tree\\n * that has been compressed so that `C` nodes\\n * are compressed into a single uint256.\\n *\\n * Each node in a non-leaf node group is the sum of the\\n * total sum of each child node group that it represents.\\n * Each non-leaf node represents `E` node groups.\\n *\\n * A node group consists of `S` uint256.\\n *\\n * By expressing the index in `N` notation,\\n * we can find the index in each respective layer\\n *\\n * S: Size of each node group\\n * C: Compression Coefficient\\n * E: Expansion Coefficient\\n * L: Number of Layers\\n * N: Notation, S * C * E\\n *\\n * `E` will not be considered for this version of the implementation. (E = 2)\\n */\\n\",\"keccak256\":\"0x27d4261adeea576c6e163c4e1d9ccca1c4b56bb695c8cbf40c0345ba17cb87c2\",\"license\":\"-\"},\"src/libraries/SignificantBit.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-2.0-or-later\\n\\npragma solidity ^0.8.0;\\n\\nlibrary SignificantBit {\\n // http://supertech.csail.mit.edu/papers/debruijn.pdf\\n uint256 internal constant DEBRUIJN_SEQ = 0x818283848586878898A8B8C8D8E8F929395969799A9B9D9E9FAAEB6BEDEEFF;\\n bytes internal constant DEBRUIJN_INDEX =\\n hex\\\"0001020903110a19042112290b311a3905412245134d2a550c5d32651b6d3a7506264262237d468514804e8d2b95569d0d495ea533a966b11c886eb93bc176c9071727374353637324837e9b47af86c7155181ad4fd18ed32c9096db57d59ee30e2e4a6a5f92a6be3498aae067ddb2eb1d5989b56fd7baf33ca0c2ee77e5caf7ff0810182028303840444c545c646c7425617c847f8c949c48a4a8b087b8c0c816365272829aaec650acd0d28fdad4e22d6991bd97dfdcea58b4d6f29fede4f6fe0f1f2f3f4b5b6b607b8b93a3a7b7bf357199c5abcfd9e168bcdee9b3f1ecf5fd1e3e5a7a8aa2b670c4ced8bbe8f0f4fc3d79a1c3cde7effb78cce6facbf9f8\\\";\\n\\n /**\\n * @notice Finds the index of the least significant bit.\\n * @param x The value to compute the least significant bit for. Must be a non-zero value.\\n * @return ret The index of the least significant bit.\\n */\\n function leastSignificantBit(uint256 x) internal pure returns (uint8) {\\n require(x > 0);\\n uint256 index;\\n assembly {\\n index := shr(248, mul(and(x, add(not(x), 1)), DEBRUIJN_SEQ))\\n }\\n return uint8(DEBRUIJN_INDEX[index]); // can optimize with CODECOPY opcode\\n }\\n\\n function mostSignificantBit(uint256 x) internal pure returns (uint8 msb) {\\n require(x > 0);\\n assembly {\\n let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\\n msb := or(msb, f)\\n x := shr(f, x)\\n f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\\n msb := or(msb, f)\\n x := shr(f, x)\\n f := shl(5, gt(x, 0xFFFFFFFF))\\n msb := or(msb, f)\\n x := shr(f, x)\\n f := shl(4, gt(x, 0xFFFF))\\n msb := or(msb, f)\\n x := shr(f, x)\\n f := shl(3, gt(x, 0xFF))\\n msb := or(msb, f)\\n x := shr(f, x)\\n f := shl(2, gt(x, 0xF))\\n msb := or(msb, f)\\n x := shr(f, x)\\n f := shl(1, gt(x, 0x3))\\n msb := or(msb, f)\\n x := shr(f, x)\\n f := gt(x, 0x1)\\n msb := or(msb, f)\\n }\\n }\\n}\\n\",\"keccak256\":\"0x7ffeb68f2f666cdbefa20efc0376c922f049a8765d9a25871c9ade4fabc9e604\",\"license\":\"GPL-2.0-or-later\"},\"src/libraries/Tick.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-2.0-or-later\\n\\npragma solidity ^0.8.20;\\n\\nimport {Math} from \\\"./Math.sol\\\";\\n\\ntype Tick is int24;\\n\\nlibrary TickLibrary {\\n using Math for *;\\n using TickLibrary for Tick;\\n\\n error InvalidTick();\\n error InvalidPrice();\\n error TickOverflow();\\n\\n int24 internal constant MAX_TICK = 2 ** 19 - 1;\\n int24 internal constant MIN_TICK = -MAX_TICK;\\n\\n uint256 internal constant MIN_PRICE = 1350587;\\n uint256 internal constant MAX_PRICE = 4647684107270898330752324302845848816923571339324334;\\n\\n uint256 private constant _R0 = 0xfff97272373d413259a46990;\\n uint256 private constant _R1 = 0xfff2e50f5f656932ef12357c;\\n uint256 private constant _R2 = 0xffe5caca7e10e4e61c3624ea;\\n uint256 private constant _R3 = 0xffcb9843d60f6159c9db5883;\\n uint256 private constant _R4 = 0xff973b41fa98c081472e6896;\\n uint256 private constant _R5 = 0xff2ea16466c96a3843ec78b3;\\n uint256 private constant _R6 = 0xfe5dee046a99a2a811c461f1;\\n uint256 private constant _R7 = 0xfcbe86c7900a88aedcffc83b;\\n uint256 private constant _R8 = 0xf987a7253ac413176f2b074c;\\n uint256 private constant _R9 = 0xf3392b0822b70005940c7a39;\\n uint256 private constant _R10 = 0xe7159475a2c29b7443b29c7f;\\n uint256 private constant _R11 = 0xd097f3bdfd2022b8845ad8f7;\\n uint256 private constant _R12 = 0xa9f746462d870fdf8a65dc1f;\\n uint256 private constant _R13 = 0x70d869a156d2a1b890bb3df6;\\n uint256 private constant _R14 = 0x31be135f97d08fd981231505;\\n uint256 private constant _R15 = 0x9aa508b5b7a84e1c677de54;\\n uint256 private constant _R16 = 0x5d6af8dedb81196699c329;\\n uint256 private constant _R17 = 0x2216e584f5fa1ea92604;\\n uint256 private constant _R18 = 0x48a170391f7dc42;\\n uint256 private constant _R19 = 0x149b34;\\n\\n function validateTick(Tick tick) internal pure {\\n if (Tick.unwrap(tick) > MAX_TICK || Tick.unwrap(tick) < MIN_TICK) revert InvalidTick();\\n }\\n\\n modifier validatePrice(uint256 price) {\\n if (price > MAX_PRICE || price < MIN_PRICE) revert InvalidPrice();\\n _;\\n }\\n\\n function fromPrice(uint256 price) internal pure validatePrice(price) returns (Tick) {\\n unchecked {\\n int24 tick = int24((int256(price).lnWad() * 42951820407860) / 2 ** 128);\\n if (toPrice(Tick.wrap(tick)) > price) return Tick.wrap(tick - 1);\\n return Tick.wrap(tick);\\n }\\n }\\n\\n function toPrice(Tick tick) internal pure returns (uint256 price) {\\n validateTick(tick);\\n int24 tickValue = Tick.unwrap(tick);\\n uint256 absTick = uint24(tickValue < 0 ? -tickValue : tickValue);\\n\\n unchecked {\\n if (absTick & 0x1 != 0) price = _R0;\\n else price = 1 << 96;\\n if (absTick & 0x2 != 0) price = (price * _R1) >> 96;\\n if (absTick & 0x4 != 0) price = (price * _R2) >> 96;\\n if (absTick & 0x8 != 0) price = (price * _R3) >> 96;\\n if (absTick & 0x10 != 0) price = (price * _R4) >> 96;\\n if (absTick & 0x20 != 0) price = (price * _R5) >> 96;\\n if (absTick & 0x40 != 0) price = (price * _R6) >> 96;\\n if (absTick & 0x80 != 0) price = (price * _R7) >> 96;\\n if (absTick & 0x100 != 0) price = (price * _R8) >> 96;\\n if (absTick & 0x200 != 0) price = (price * _R9) >> 96;\\n if (absTick & 0x400 != 0) price = (price * _R10) >> 96;\\n if (absTick & 0x800 != 0) price = (price * _R11) >> 96;\\n if (absTick & 0x1000 != 0) price = (price * _R12) >> 96;\\n if (absTick & 0x2000 != 0) price = (price * _R13) >> 96;\\n if (absTick & 0x4000 != 0) price = (price * _R14) >> 96;\\n if (absTick & 0x8000 != 0) price = (price * _R15) >> 96;\\n if (absTick & 0x10000 != 0) price = (price * _R16) >> 96;\\n if (absTick & 0x20000 != 0) price = (price * _R17) >> 96;\\n if (absTick & 0x40000 != 0) price = (price * _R18) >> 96;\\n }\\n if (tickValue > 0) price = 0x1000000000000000000000000000000000000000000000000 / price;\\n }\\n\\n function gt(Tick a, Tick b) internal pure returns (bool) {\\n return Tick.unwrap(a) > Tick.unwrap(b);\\n }\\n\\n function baseToQuote(Tick tick, uint256 base, bool roundingUp) internal pure returns (uint256) {\\n return Math.divide((base * tick.toPrice()), 1 << 96, roundingUp);\\n }\\n\\n function quoteToBase(Tick tick, uint256 quote, bool roundingUp) internal pure returns (uint256) {\\n // @dev quote = unit(uint64) * unitSize(uint64) < 2^96\\n // We don't need to check overflow here\\n return Math.divide(quote << 96, tick.toPrice(), roundingUp);\\n }\\n}\\n\",\"keccak256\":\"0xffbe19efd2b2e4e1eee3ed15c9363f5c45d70a6058b0b85ec9199e34de3b6b9b\",\"license\":\"GPL-2.0-or-later\"},\"src/libraries/TickBitmap.sol\":{\"content\":\"// SPDX-License-Identifier: -\\n// License: https://license.clober.io/LICENSE_V2.pdf\\n\\npragma solidity ^0.8.0;\\n\\nimport {SignificantBit} from \\\"./SignificantBit.sol\\\";\\nimport {Tick} from \\\"./Tick.sol\\\";\\n\\nlibrary TickBitmap {\\n using SignificantBit for uint256;\\n\\n error EmptyError();\\n error AlreadyExistsError();\\n\\n uint256 public constant B0_BITMAP_KEY = uint256(keccak256(\\\"TickBitmap\\\")) + 1;\\n uint256 public constant MAX_UINT_256_MINUS_1 = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe;\\n\\n function has(mapping(uint256 => uint256) storage self, Tick tick) internal view returns (bool) {\\n (uint256 b0b1, uint256 b2) = _split(tick);\\n uint256 mask = 1 << b2;\\n return self[b0b1] & mask == mask;\\n }\\n\\n function isEmpty(mapping(uint256 => uint256) storage self) internal view returns (bool) {\\n return self[B0_BITMAP_KEY] == 0;\\n }\\n\\n function _split(Tick tick) private pure returns (uint256 b0b1, uint256 b2) {\\n assembly {\\n let value := add(not(tick), 0x800000)\\n b0b1 := shr(8, and(value, 0xffff00))\\n b2 := and(value, 0xff)\\n }\\n }\\n\\n function highest(mapping(uint256 => uint256) storage self) internal view returns (Tick) {\\n if (isEmpty(self)) revert EmptyError();\\n\\n uint256 b0 = self[B0_BITMAP_KEY].leastSignificantBit();\\n uint256 b0b1 = (b0 << 8) | (self[~b0].leastSignificantBit());\\n uint256 b2 = self[b0b1].leastSignificantBit();\\n return _toTick((b0b1 << 8) | b2);\\n }\\n\\n function set(mapping(uint256 => uint256) storage self, Tick tick) internal {\\n (uint256 b0b1, uint256 b2) = _split(tick);\\n uint256 mask = 1 << b2;\\n uint256 b2Bitmap = self[b0b1];\\n if (b2Bitmap & mask > 0) revert AlreadyExistsError();\\n\\n self[b0b1] = b2Bitmap | mask;\\n if (b2Bitmap == 0) {\\n mask = 1 << (b0b1 & 0xff);\\n uint256 b1BitmapKey = ~(b0b1 >> 8);\\n uint256 b1Bitmap = self[b1BitmapKey];\\n self[b1BitmapKey] = b1Bitmap | mask;\\n\\n if (b1Bitmap == 0) self[B0_BITMAP_KEY] = self[B0_BITMAP_KEY] | (1 << ~b1BitmapKey);\\n }\\n }\\n\\n function clear(mapping(uint256 => uint256) storage self, Tick tick) internal {\\n (uint256 b0b1, uint256 b2) = _split(tick);\\n uint256 mask = 1 << b2;\\n uint256 b2Bitmap = self[b0b1];\\n\\n self[b0b1] = b2Bitmap & (~mask);\\n if (b2Bitmap == mask) {\\n mask = 1 << (b0b1 & 0xff);\\n uint256 b1BitmapKey = ~(b0b1 >> 8);\\n uint256 b1Bitmap = self[b1BitmapKey];\\n\\n self[b1BitmapKey] = b1Bitmap & (~mask);\\n if (mask == b1Bitmap) {\\n mask = 1 << (~b1BitmapKey);\\n self[B0_BITMAP_KEY] = self[B0_BITMAP_KEY] & (~mask);\\n }\\n }\\n }\\n\\n function maxLessThan(mapping(uint256 => uint256) storage self, Tick tick) internal view returns (Tick) {\\n (uint256 b0b1, uint256 b2) = _split(tick);\\n uint256 b2Bitmap = (MAX_UINT_256_MINUS_1 << b2) & self[b0b1];\\n if (b2Bitmap == 0) {\\n uint256 b0 = b0b1 >> 8;\\n uint256 b1Bitmap = (MAX_UINT_256_MINUS_1 << (b0b1 & 0xff)) & self[~b0];\\n if (b1Bitmap == 0) {\\n uint256 b0Bitmap = (MAX_UINT_256_MINUS_1 << b0) & self[B0_BITMAP_KEY];\\n if (b0Bitmap == 0) return Tick.wrap(type(int24).min);\\n b0 = b0Bitmap.leastSignificantBit();\\n b1Bitmap = self[~b0];\\n }\\n b0b1 = (b0 << 8) | b1Bitmap.leastSignificantBit();\\n b2Bitmap = self[b0b1];\\n }\\n b2 = b2Bitmap.leastSignificantBit();\\n return _toTick((b0b1 << 8) | b2);\\n }\\n\\n function _toTick(uint256 raw) private pure returns (Tick t) {\\n assembly {\\n t := and(not(sub(raw, 0x800000)), 0xffffff)\\n }\\n }\\n}\\n\",\"keccak256\":\"0xa7074d79b62ca6bd62c8d281c8c3cdb67a9dae04d42a0c8bdbf315cc6259ad83\",\"license\":\"-\"},\"src/libraries/TotalClaimableMap.sol\":{\"content\":\"// SPDX-License-Identifier: -\\n// License: https://license.clober.io/LICENSE_V2.pdf\\n\\npragma solidity ^0.8.20;\\n\\nimport {DirtyUint64} from \\\"./DirtyUint64.sol\\\";\\nimport {PackedUint256} from \\\"./PackedUint256.sol\\\";\\nimport {Tick} from \\\"./Tick.sol\\\";\\n\\nlibrary TotalClaimableMap {\\n using DirtyUint64 for uint64;\\n using PackedUint256 for uint256;\\n\\n // @dev n should be less than type(uint64).max due to the dirty storage logic.\\n function add(mapping(uint24 => uint256) storage self, Tick tick, uint64 n) internal {\\n (uint24 groupIndex, uint8 elementIndex) = _splitTick(tick);\\n uint256 group = self[groupIndex];\\n // @notice Be aware of dirty storage add logic\\n self[groupIndex] = group.update64Unsafe(\\n elementIndex, // elementIndex < 4\\n group.get64Unsafe(elementIndex).addClean(n)\\n );\\n }\\n\\n function sub(mapping(uint24 => uint256) storage self, Tick tick, uint64 n) internal {\\n (uint24 groupIndex, uint8 elementIndex) = _splitTick(tick);\\n self[groupIndex] = self[groupIndex].sub64Unsafe(elementIndex, n);\\n }\\n\\n function get(mapping(uint24 => uint256) storage self, Tick tick) internal view returns (uint64) {\\n (uint24 groupIndex, uint8 elementIndex) = _splitTick(tick);\\n return self[groupIndex].get64Unsafe(elementIndex).toClean();\\n }\\n\\n function _splitTick(Tick tick) internal pure returns (uint24 groupIndex, uint8 elementIndex) {\\n uint256 casted = uint24(Tick.unwrap(tick));\\n assembly {\\n groupIndex := shr(2, casted) // div 4\\n elementIndex := and(casted, 3) // mod 4\\n }\\n }\\n}\\n\",\"keccak256\":\"0xed7fe09b007218a0055d34c8e8f55b0682c7b5780f86817de046430f5b26b031\",\"license\":\"-\"}},\"version\":1}", - "bytecode": "0x6118ef610034600b8282823980515f1a607314602857634e487b7160e01b5f525f60045260245ffd5b305f52607381538281f3fe730000000000000000000000000000000000000000301460806040526004361061007a575f3560e01c8063ab8a7e3f11610058578063ab8a7e3f1461010e578063c49d26211461012f578063ffa0afb51461014e575f80fd5b8063329b4a011461007e5780633ac502c1146100af578063a151a7e1146100ef575b5f80fd5b61009161008c366004611567565b610183565b60405167ffffffffffffffff90911681526020015b60405180910390f35b8180156100ba575f80fd5b506100ce6100c93660046115c5565b61025e565b6040805167ffffffffffffffff9384168152929091166020830152016100a6565b8180156100fa575f80fd5b506100916101093660046115f0565b61040b565b818015610119575f80fd5b5061012d610128366004611622565b610463565b005b81801561013a575f80fd5b50610091610149366004611567565b6104bf565b818015610159575f80fd5b5061016d61016836600461166b565b610525565b60405164ffffffffff90911681526020016100a6565b5f80610190858585610776565b602090810151600286900b5f90815260038801909252604090912060048101549192509064ffffffffff85166180000110156101ce57509050610257565b5f6101dc60058801876107ca565b90505f6101f0838764ffffffffff1661081f565b90508167ffffffffffffffff1684820367ffffffffffffffff161061021b575f945050505050610257565b8167ffffffffffffffff168167ffffffffffffffff16116102425783945050505050610257565b8381038203945050505050610257565b505050505b9392505050565b602882901c62ffffff16600281900b5f908152600385016020526040812060048101805492938493909264ffffffffff8816929091859190849081106102a6576102a66116b9565b5f918252602082200154600160a01b900467ffffffffffffffff1691506102ce8a8686610183565b90506102da81896116e1565b95508567ffffffffffffffff168267ffffffffffffffff16101561033d576040517fc332559a00000000000000000000000000000000000000000000000000000000815267ffffffffffffffff8284031660048201526024015b60405180910390fd5b600285900b5f90815260038b0160205260409020868303975061038990617fff861690899061036c9083610872565b600289900b5f90815260038f0160205260409020929190036108be565b5085836004018564ffffffffff16815481106103a7576103a76116b9565b905f5260205f20015f0160146101000a81548167ffffffffffffffff021916908367ffffffffffffffff1602179055506103e18a86610b16565b67ffffffffffffffff165f036103fe576103fe60048b0186610b4b565b5050505050935093915050565b5f806104178585610b16565b90508267ffffffffffffffff168167ffffffffffffffff16111561043d5782915061044d565b90508061044d6004860185610b4b565b61045b600586018584610c49565b509392505050565b8154600160a01b900467ffffffffffffffff16156104ad576040517fc15ba32200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80826104b9828261171c565b50505050565b5f806104cc858585610cc7565b90506104d9858585610183565b815467ffffffffffffffff600160a01b8083048216849003909116027fffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffff90911617909155949350505050565b5f8267ffffffffffffffff165f03610569576040517ff21c16aa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b62800000841901600881901c61ffff165f908152600487016020526040902054600160ff9092169190911b908116146105a9576105a96004860185610d08565b600284900b5f908152600386016020526040902060048101546105cb90610e28565b915061800064ffffffffff8316106106dd575f618000830390505f826004018264ffffffffff1681548110610602576106026116b9565b5f91825260209091200154600160a01b900467ffffffffffffffff1690508015610683575f610632898985610183565b90508167ffffffffffffffff168167ffffffffffffffff1614610681576040517ff2f9ac9900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b505f905061069582617fff8516610872565b905067ffffffffffffffff8116156106db57623fffff600287901c165f9081526005880160205260409020805467ffffffffffffffff831660c060068a901b161b900390555b505b6106ec81617fff8416866108be565b50604080518082019091526001600160a01b03938416815267ffffffffffffffff9485166020808301918252600490930180546001810182555f91825293902091519190920180549251909516600160a01b027fffffffff000000000000000000000000000000000000000000000000000000009092169316929092179190911790915592915050565b604080518082019091525f8082526020820152610794848484610cc7565b6040805180820190915290546001600160a01b0381168252600160a01b900467ffffffffffffffff166020820152949350505050565b600281901c623fffff165f81815260208490526040812054909190600384169061081490600686901b60c0161c67ffffffffffffffff165b67ffffffffffffffff16801515900390565b925050505b92915050565b60048201545f90617fff90811690829061083a856001611885565b1690508082106108675761084f858284610e76565b61085886611319565b6108629190611898565b610814565b610814858383610e76565b5f61800082106108975760405163163da48960e01b81525f6004820152602401610334565b6102576108026003848116908690600287901c5f9081529101602052604090205490611358565b5f61800083106108e35760405163163da48960e01b81525f6004820152602401610334565b5f6108ed84611390565b90505f81600160040360ff1681518110610909576109096116b9565b60209081029190910181015190810151909150610949906108029088600385515f908152910160205260409020549060061b1c67ffffffffffffffff1690565b92508367ffffffffffffffff168367ffffffffffffffff1610610a20578383035f5b6004811015610a19575f848281518110610987576109876116b9565b602002602001015190505f895f0183600481106109a6576109a66116b9565b83515f90815291016020908152604090912054908301519091506109ea906109e2866109d28584611358565b67ffffffffffffffff1690611436565b839190611483565b8a84600481106109fc576109fc6116b9565b93515f90815293016020526040909220919091555060010161096b565b5050610b0d565b82840367ffffffffffffffff81810316610a3988611319565b67ffffffffffffffff161115610a655760405163163da48960e01b815260016004820152602401610334565b5f5b6004811015610252575f848281518110610a8357610a836116b9565b602002602001015190505f895f018360048110610aa257610aa26116b9565b83515f9081529101602090815260409091205490830151909150610ade906109e286610ace8584611358565b67ffffffffffffffff16906114ca565b8a8460048110610af057610af06116b9565b93515f908152930160205260409092209190915550600101610a67565b50509392505050565b5f610b2460058401836107ca565b600283900b5f9081526003850160205260409020610b4190611319565b6102579190611898565b62800000811901600881901c61ffff165f8181526020859052604090208054600160ff90941693841b80198216909255919291818103610c4157600884901c195f8181526020889052604090208054600160ff88161b80198216909255909350808403610c3e5781196001901b93508319885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610bed9190611885565b81526020019081526020015f205416885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610c2d9190611885565b815260208101919091526040015f20555b50505b505050505050565b623fffff600283901c165f818152602085905260409020546003841690610ca782610c888667ffffffffffffffff60c060068b901b1686901c16610ace565b67ffffffffffffffff90811660069290921b91821b911b831683030190565b62ffffff9093165f90815260209690965250506040909320929092555050565b600282900b5f9081526003840160205260408120600401805464ffffffffff8416908110610cf757610cf76116b9565b905f5260205f200190509392505050565b62800000811901600881901c61ffff165f81815260208590526040902054909160ff16906001821b9081811615610d6b576040517feb73dbfd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8481526020879052604081208284179055819003610c4157600884901c195f8181526020889052604081208054600160ff89161b81811790925590945090819003610c3e5781196001901b885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610de89190611885565b81526020019081526020015f205417885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610c2d9190611885565b5f64ffffffffff821115610e72576040517f6dfcc6500000000000000000000000000000000000000000000000000000000081526028600482015260248101839052604401610334565b5090565b5f818303610e8557505f610257565b818310610ea75760405163163da48960e01b81525f6004820152602401610334565b618000821115610ecc5760405163163da48960e01b81525f6004820152602401610334565b5f610ed684611390565b90505f610ee284611390565b90505f80808060035b5f878281518110610efe57610efe6116b9565b602002602001015190505f878381518110610f1b57610f1b6116b9565b60200260200101519050816020015185019450806020015184019350815f0151815f015103610f8557610f708d8460048110610f5957610f596116b9565b84515f908152910160205260409020548686611511565b67ffffffffffffffff1687019650505061130a565b815181516004919003101561106757610fc18d8460048110610fa957610fa96116b9565b84515f90815291016020526040902054866004611511565b67ffffffffffffffff169690960195610ffc8d8460048110610fe557610fe56116b9565b83515f908152910160205260408120549086611511565b825167ffffffffffffffff9190911697909701966001015b815181101561105f576110488e8560048110611032576110326116b9565b5f84815291016020526040812054906004611511565b67ffffffffffffffff169790970196600101611014565b50505061130a565b81516003165f036110b45761109e8d8460048110611087576110876116b9565b84515f908152910160205260408120549087611511565b67ffffffffffffffff16860195505f94506111b3565b8151600316600103611114576110f08d84600481106110d5576110d56116b9565b84515f19015f90815291016020526040812054906004611511565b67ffffffffffffffff16959095019461109e8d8460048110611087576110876116b9565b815160031660020361118b576111358d8460048110610fa957610fa96116b9565b67ffffffffffffffff1696909601956111748d8460048110611159576111596116b9565b84516001015f90815291016020526040812054906004611511565b67ffffffffffffffff1687019650600194506111b3565b6111a08d8460048110610fa957610fa96116b9565b67ffffffffffffffff1687019650600194505b80516003165f036111e9576111d38d8460048110610fe557610fe56116b9565b67ffffffffffffffff16870196505f9350611300565b8051600316600103611249576112258d846004811061120a5761120a6116b9565b83515f19015f90815291016020526040812054906004611511565b67ffffffffffffffff1696909601956111d38d8460048110610fe557610fe56116b9565b80516003166002036112d8576112828d846004811061126a5761126a6116b9565b83515f90815291016020526040902054856004611511565b67ffffffffffffffff1695909501946112c18d84600481106112a6576112a66116b9565b83516001015f90815291016020526040812054906004611511565b67ffffffffffffffff168601955060019350611300565b6112ed8d846004811061126a5761126a6116b9565b67ffffffffffffffff1686019550600193505b50505f1901610eeb565b50505090039695505050505050565b60015f9081526020829052604081205461133590826004611511565b5f8080526020849052604081205461134e916004611511565b61081991906116e1565b5f600382111561137e5760405163b8710e2160e01b815260036004820152602401610334565b5060061b1c67ffffffffffffffff1690565b60408051600480825260a082019092526060915f9190816020015b604080518082019091525f80825260208201528152602001906001900390816113ab579050509050600e5f5b600481101561142d5760405180604001604052808387901c815260200160036002850388901c16815250838281518110611413576114136116b9565b6020908102919091010152600319909101906001016113d7565b50909392505050565b81159091019080820367ffffffffffffffff8082169084161080611462575067ffffffffffffffff8116155b1561081957604051633e6c0de960e11b815260016004820152602401610334565b5f60038311156114a95760405163b8710e2160e01b815260036004820152602401610334565b5067ffffffffffffffff90811660069290921b91821b911b82169091030190565b5f81831584010192508167ffffffffffffffff168367ffffffffffffffff16101561150a57604051633e6c0de960e11b81525f6004820152602401610334565b5090919050565b600682901b9290921c915f825b8281101561154657604085901c9467ffffffffffffffff16801501919091019060010161151e565b509190039003919050565b8035600281900b8114611562575f80fd5b919050565b5f805f60608486031215611579575f80fd5b8335925061158960208501611551565b9150604084013564ffffffffff811681146115a2575f80fd5b809150509250925092565b67ffffffffffffffff811681146115c2575f80fd5b50565b5f805f606084860312156115d7575f80fd5b833592506020840135915060408401356115a2816115ad565b5f805f60608486031215611602575f80fd5b8335925061161260208501611551565b915060408401356115a2816115ad565b5f8082840360e0811215611634575f80fd5b8335925060c0601f1982011215611649575f80fd5b506020830190509250929050565b6001600160a01b03811681146115c2575f80fd5b5f805f806080858703121561167e575f80fd5b8435935061168e60208601611551565b9250604085013561169e816115ad565b915060608501356116ae81611657565b939692955090935050565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b67ffffffffffffffff818116838216019080821115611702576117026116cd565b5092915050565b5f813562ffffff81168114610819575f80fd5b813561172781611657565b815473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03821617825550602082013561175c816115ad565b81547fffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffff1660a09190911b7bffffffffffffffff0000000000000000000000000000000000000000161781556001810160408301356117b981611657565b815473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b038216178255506118376117ef60608501611709565b82547fffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffff1660a09190911b76ffffff000000000000000000000000000000000000000016178255565b5060028101608083013561184a81611657565b815473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b038216178255506118806117ef60a08501611709565b505050565b80820180821115610819576108196116cd565b67ffffffffffffffff828116828216039080821115611702576117026116cd56fea264697066735822122069b7602b7537e063464a4265a4ef66d51373069689a6f88b9e9b30908039f06c64736f6c63430008190033", - "deployedBytecode": "0x730000000000000000000000000000000000000000301460806040526004361061007a575f3560e01c8063ab8a7e3f11610058578063ab8a7e3f1461010e578063c49d26211461012f578063ffa0afb51461014e575f80fd5b8063329b4a011461007e5780633ac502c1146100af578063a151a7e1146100ef575b5f80fd5b61009161008c366004611567565b610183565b60405167ffffffffffffffff90911681526020015b60405180910390f35b8180156100ba575f80fd5b506100ce6100c93660046115c5565b61025e565b6040805167ffffffffffffffff9384168152929091166020830152016100a6565b8180156100fa575f80fd5b506100916101093660046115f0565b61040b565b818015610119575f80fd5b5061012d610128366004611622565b610463565b005b81801561013a575f80fd5b50610091610149366004611567565b6104bf565b818015610159575f80fd5b5061016d61016836600461166b565b610525565b60405164ffffffffff90911681526020016100a6565b5f80610190858585610776565b602090810151600286900b5f90815260038801909252604090912060048101549192509064ffffffffff85166180000110156101ce57509050610257565b5f6101dc60058801876107ca565b90505f6101f0838764ffffffffff1661081f565b90508167ffffffffffffffff1684820367ffffffffffffffff161061021b575f945050505050610257565b8167ffffffffffffffff168167ffffffffffffffff16116102425783945050505050610257565b8381038203945050505050610257565b505050505b9392505050565b602882901c62ffffff16600281900b5f908152600385016020526040812060048101805492938493909264ffffffffff8816929091859190849081106102a6576102a66116b9565b5f918252602082200154600160a01b900467ffffffffffffffff1691506102ce8a8686610183565b90506102da81896116e1565b95508567ffffffffffffffff168267ffffffffffffffff16101561033d576040517fc332559a00000000000000000000000000000000000000000000000000000000815267ffffffffffffffff8284031660048201526024015b60405180910390fd5b600285900b5f90815260038b0160205260409020868303975061038990617fff861690899061036c9083610872565b600289900b5f90815260038f0160205260409020929190036108be565b5085836004018564ffffffffff16815481106103a7576103a76116b9565b905f5260205f20015f0160146101000a81548167ffffffffffffffff021916908367ffffffffffffffff1602179055506103e18a86610b16565b67ffffffffffffffff165f036103fe576103fe60048b0186610b4b565b5050505050935093915050565b5f806104178585610b16565b90508267ffffffffffffffff168167ffffffffffffffff16111561043d5782915061044d565b90508061044d6004860185610b4b565b61045b600586018584610c49565b509392505050565b8154600160a01b900467ffffffffffffffff16156104ad576040517fc15ba32200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80826104b9828261171c565b50505050565b5f806104cc858585610cc7565b90506104d9858585610183565b815467ffffffffffffffff600160a01b8083048216849003909116027fffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffff90911617909155949350505050565b5f8267ffffffffffffffff165f03610569576040517ff21c16aa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b62800000841901600881901c61ffff165f908152600487016020526040902054600160ff9092169190911b908116146105a9576105a96004860185610d08565b600284900b5f908152600386016020526040902060048101546105cb90610e28565b915061800064ffffffffff8316106106dd575f618000830390505f826004018264ffffffffff1681548110610602576106026116b9565b5f91825260209091200154600160a01b900467ffffffffffffffff1690508015610683575f610632898985610183565b90508167ffffffffffffffff168167ffffffffffffffff1614610681576040517ff2f9ac9900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b505f905061069582617fff8516610872565b905067ffffffffffffffff8116156106db57623fffff600287901c165f9081526005880160205260409020805467ffffffffffffffff831660c060068a901b161b900390555b505b6106ec81617fff8416866108be565b50604080518082019091526001600160a01b03938416815267ffffffffffffffff9485166020808301918252600490930180546001810182555f91825293902091519190920180549251909516600160a01b027fffffffff000000000000000000000000000000000000000000000000000000009092169316929092179190911790915592915050565b604080518082019091525f8082526020820152610794848484610cc7565b6040805180820190915290546001600160a01b0381168252600160a01b900467ffffffffffffffff166020820152949350505050565b600281901c623fffff165f81815260208490526040812054909190600384169061081490600686901b60c0161c67ffffffffffffffff165b67ffffffffffffffff16801515900390565b925050505b92915050565b60048201545f90617fff90811690829061083a856001611885565b1690508082106108675761084f858284610e76565b61085886611319565b6108629190611898565b610814565b610814858383610e76565b5f61800082106108975760405163163da48960e01b81525f6004820152602401610334565b6102576108026003848116908690600287901c5f9081529101602052604090205490611358565b5f61800083106108e35760405163163da48960e01b81525f6004820152602401610334565b5f6108ed84611390565b90505f81600160040360ff1681518110610909576109096116b9565b60209081029190910181015190810151909150610949906108029088600385515f908152910160205260409020549060061b1c67ffffffffffffffff1690565b92508367ffffffffffffffff168367ffffffffffffffff1610610a20578383035f5b6004811015610a19575f848281518110610987576109876116b9565b602002602001015190505f895f0183600481106109a6576109a66116b9565b83515f90815291016020908152604090912054908301519091506109ea906109e2866109d28584611358565b67ffffffffffffffff1690611436565b839190611483565b8a84600481106109fc576109fc6116b9565b93515f90815293016020526040909220919091555060010161096b565b5050610b0d565b82840367ffffffffffffffff81810316610a3988611319565b67ffffffffffffffff161115610a655760405163163da48960e01b815260016004820152602401610334565b5f5b6004811015610252575f848281518110610a8357610a836116b9565b602002602001015190505f895f018360048110610aa257610aa26116b9565b83515f9081529101602090815260409091205490830151909150610ade906109e286610ace8584611358565b67ffffffffffffffff16906114ca565b8a8460048110610af057610af06116b9565b93515f908152930160205260409092209190915550600101610a67565b50509392505050565b5f610b2460058401836107ca565b600283900b5f9081526003850160205260409020610b4190611319565b6102579190611898565b62800000811901600881901c61ffff165f8181526020859052604090208054600160ff90941693841b80198216909255919291818103610c4157600884901c195f8181526020889052604090208054600160ff88161b80198216909255909350808403610c3e5781196001901b93508319885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610bed9190611885565b81526020019081526020015f205416885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610c2d9190611885565b815260208101919091526040015f20555b50505b505050505050565b623fffff600283901c165f818152602085905260409020546003841690610ca782610c888667ffffffffffffffff60c060068b901b1686901c16610ace565b67ffffffffffffffff90811660069290921b91821b911b831683030190565b62ffffff9093165f90815260209690965250506040909320929092555050565b600282900b5f9081526003840160205260408120600401805464ffffffffff8416908110610cf757610cf76116b9565b905f5260205f200190509392505050565b62800000811901600881901c61ffff165f81815260208590526040902054909160ff16906001821b9081811615610d6b576040517feb73dbfd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8481526020879052604081208284179055819003610c4157600884901c195f8181526020889052604081208054600160ff89161b81811790925590945090819003610c3e5781196001901b885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610de89190611885565b81526020019081526020015f205417885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610c2d9190611885565b5f64ffffffffff821115610e72576040517f6dfcc6500000000000000000000000000000000000000000000000000000000081526028600482015260248101839052604401610334565b5090565b5f818303610e8557505f610257565b818310610ea75760405163163da48960e01b81525f6004820152602401610334565b618000821115610ecc5760405163163da48960e01b81525f6004820152602401610334565b5f610ed684611390565b90505f610ee284611390565b90505f80808060035b5f878281518110610efe57610efe6116b9565b602002602001015190505f878381518110610f1b57610f1b6116b9565b60200260200101519050816020015185019450806020015184019350815f0151815f015103610f8557610f708d8460048110610f5957610f596116b9565b84515f908152910160205260409020548686611511565b67ffffffffffffffff1687019650505061130a565b815181516004919003101561106757610fc18d8460048110610fa957610fa96116b9565b84515f90815291016020526040902054866004611511565b67ffffffffffffffff169690960195610ffc8d8460048110610fe557610fe56116b9565b83515f908152910160205260408120549086611511565b825167ffffffffffffffff9190911697909701966001015b815181101561105f576110488e8560048110611032576110326116b9565b5f84815291016020526040812054906004611511565b67ffffffffffffffff169790970196600101611014565b50505061130a565b81516003165f036110b45761109e8d8460048110611087576110876116b9565b84515f908152910160205260408120549087611511565b67ffffffffffffffff16860195505f94506111b3565b8151600316600103611114576110f08d84600481106110d5576110d56116b9565b84515f19015f90815291016020526040812054906004611511565b67ffffffffffffffff16959095019461109e8d8460048110611087576110876116b9565b815160031660020361118b576111358d8460048110610fa957610fa96116b9565b67ffffffffffffffff1696909601956111748d8460048110611159576111596116b9565b84516001015f90815291016020526040812054906004611511565b67ffffffffffffffff1687019650600194506111b3565b6111a08d8460048110610fa957610fa96116b9565b67ffffffffffffffff1687019650600194505b80516003165f036111e9576111d38d8460048110610fe557610fe56116b9565b67ffffffffffffffff16870196505f9350611300565b8051600316600103611249576112258d846004811061120a5761120a6116b9565b83515f19015f90815291016020526040812054906004611511565b67ffffffffffffffff1696909601956111d38d8460048110610fe557610fe56116b9565b80516003166002036112d8576112828d846004811061126a5761126a6116b9565b83515f90815291016020526040902054856004611511565b67ffffffffffffffff1695909501946112c18d84600481106112a6576112a66116b9565b83516001015f90815291016020526040812054906004611511565b67ffffffffffffffff168601955060019350611300565b6112ed8d846004811061126a5761126a6116b9565b67ffffffffffffffff1686019550600193505b50505f1901610eeb565b50505090039695505050505050565b60015f9081526020829052604081205461133590826004611511565b5f8080526020849052604081205461134e916004611511565b61081991906116e1565b5f600382111561137e5760405163b8710e2160e01b815260036004820152602401610334565b5060061b1c67ffffffffffffffff1690565b60408051600480825260a082019092526060915f9190816020015b604080518082019091525f80825260208201528152602001906001900390816113ab579050509050600e5f5b600481101561142d5760405180604001604052808387901c815260200160036002850388901c16815250838281518110611413576114136116b9565b6020908102919091010152600319909101906001016113d7565b50909392505050565b81159091019080820367ffffffffffffffff8082169084161080611462575067ffffffffffffffff8116155b1561081957604051633e6c0de960e11b815260016004820152602401610334565b5f60038311156114a95760405163b8710e2160e01b815260036004820152602401610334565b5067ffffffffffffffff90811660069290921b91821b911b82169091030190565b5f81831584010192508167ffffffffffffffff168367ffffffffffffffff16101561150a57604051633e6c0de960e11b81525f6004820152602401610334565b5090919050565b600682901b9290921c915f825b8281101561154657604085901c9467ffffffffffffffff16801501919091019060010161151e565b509190039003919050565b8035600281900b8114611562575f80fd5b919050565b5f805f60608486031215611579575f80fd5b8335925061158960208501611551565b9150604084013564ffffffffff811681146115a2575f80fd5b809150509250925092565b67ffffffffffffffff811681146115c2575f80fd5b50565b5f805f606084860312156115d7575f80fd5b833592506020840135915060408401356115a2816115ad565b5f805f60608486031215611602575f80fd5b8335925061161260208501611551565b915060408401356115a2816115ad565b5f8082840360e0811215611634575f80fd5b8335925060c0601f1982011215611649575f80fd5b506020830190509250929050565b6001600160a01b03811681146115c2575f80fd5b5f805f806080858703121561167e575f80fd5b8435935061168e60208601611551565b9250604085013561169e816115ad565b915060608501356116ae81611657565b939692955090935050565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b67ffffffffffffffff818116838216019080821115611702576117026116cd565b5092915050565b5f813562ffffff81168114610819575f80fd5b813561172781611657565b815473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03821617825550602082013561175c816115ad565b81547fffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffff1660a09190911b7bffffffffffffffff0000000000000000000000000000000000000000161781556001810160408301356117b981611657565b815473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b038216178255506118376117ef60608501611709565b82547fffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffff1660a09190911b76ffffff000000000000000000000000000000000000000016178255565b5060028101608083013561184a81611657565b815473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b038216178255506118806117ef60a08501611709565b505050565b80820180821115610819576108196116cd565b67ffffffffffffffff828116828216039080821115611702576117026116cd56fea264697066735822122069b7602b7537e063464a4265a4ef66d51373069689a6f88b9e9b30908039f06c64736f6c63430008190033", + "solcInputHash": "61c41691f2d6c9050f42543a62f11089", + "metadata": "{\"compiler\":{\"version\":\"0.8.25+commit.b61c2a91\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"AlreadyExistsError\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"BookAlreadyOpened\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"BookNotOpened\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"maxCancelableUnit\",\"type\":\"uint64\"}],\"name\":\"CancelFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"errorCode\",\"type\":\"uint256\"}],\"name\":\"DirtyUint64Error\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"errorCode\",\"type\":\"uint256\"}],\"name\":\"PackedUint256Error\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"QueueReplaceFailed\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"bits\",\"type\":\"uint8\"},{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"SafeCastOverflowedUintDowncast\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"errorCode\",\"type\":\"uint256\"}],\"name\":\"SegmentedSegmentTreeError\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"ZeroUnit\",\"type\":\"error\"}],\"devdoc\":{\"errors\":{\"SafeCastOverflowedUintDowncast(uint8,uint256)\":[{\"details\":\"Value doesn't fit in an uint of `bits` size.\"}]},\"kind\":\"dev\",\"methods\":{\"take(Book.State storage,int24,uint64)\":{\"params\":{\"maxTakeUnit\":\"The maximum unit to take\",\"self\":\"The book state\"},\"returns\":{\"takenUnit\":\"The actual unit to take\"}}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{\"take(Book.State storage,int24,uint64)\":{\"notice\":\"Take orders from the book\"}},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/libraries/Book.sol\":\"Book\"},\"evmVersion\":\"cancun\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":1000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/token/ERC20/IERC20.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)\\n\\npragma solidity ^0.8.20;\\n\\n/**\\n * @dev Interface of the ERC-20 standard as defined in the ERC.\\n */\\ninterface IERC20 {\\n /**\\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\\n * another (`to`).\\n *\\n * Note that `value` may be zero.\\n */\\n event Transfer(address indexed from, address indexed to, uint256 value);\\n\\n /**\\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\\n * a call to {approve}. `value` is the new allowance.\\n */\\n event Approval(address indexed owner, address indexed spender, uint256 value);\\n\\n /**\\n * @dev Returns the value of tokens in existence.\\n */\\n function totalSupply() external view returns (uint256);\\n\\n /**\\n * @dev Returns the value of tokens owned by `account`.\\n */\\n function balanceOf(address account) external view returns (uint256);\\n\\n /**\\n * @dev Moves a `value` amount of tokens from the caller's account to `to`.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transfer(address to, uint256 value) external returns (bool);\\n\\n /**\\n * @dev Returns the remaining number of tokens that `spender` will be\\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\\n * zero by default.\\n *\\n * This value changes when {approve} or {transferFrom} are called.\\n */\\n function allowance(address owner, address spender) external view returns (uint256);\\n\\n /**\\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\\n * caller's tokens.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\\n * that someone may use both the old and the new allowance by unfortunate\\n * transaction ordering. One possible solution to mitigate this race\\n * condition is to first reduce the spender's allowance to 0 and set the\\n * desired value afterwards:\\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\\n *\\n * Emits an {Approval} event.\\n */\\n function approve(address spender, uint256 value) external returns (bool);\\n\\n /**\\n * @dev Moves a `value` amount of tokens from `from` to `to` using the\\n * allowance mechanism. `value` is then deducted from the caller's\\n * allowance.\\n *\\n * Returns a boolean value indicating whether the operation succeeded.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transferFrom(address from, address to, uint256 value) external returns (bool);\\n}\\n\",\"keccak256\":\"0xee2337af2dc162a973b4be6d3f7c16f06298259e0af48c5470d2839bfa8a22f4\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC721/IERC721.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)\\n\\npragma solidity ^0.8.20;\\n\\nimport {IERC165} from \\\"../../utils/introspection/IERC165.sol\\\";\\n\\n/**\\n * @dev Required interface of an ERC-721 compliant contract.\\n */\\ninterface IERC721 is IERC165 {\\n /**\\n * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\\n */\\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\\n\\n /**\\n * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\\n */\\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\\n\\n /**\\n * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\\n */\\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\\n\\n /**\\n * @dev Returns the number of tokens in ``owner``'s account.\\n */\\n function balanceOf(address owner) external view returns (uint256 balance);\\n\\n /**\\n * @dev Returns the owner of the `tokenId` token.\\n *\\n * Requirements:\\n *\\n * - `tokenId` must exist.\\n */\\n function ownerOf(uint256 tokenId) external view returns (address owner);\\n\\n /**\\n * @dev Safely transfers `tokenId` token from `from` to `to`.\\n *\\n * Requirements:\\n *\\n * - `from` cannot be the zero address.\\n * - `to` cannot be the zero address.\\n * - `tokenId` token must exist and be owned by `from`.\\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon\\n * a safe transfer.\\n *\\n * Emits a {Transfer} event.\\n */\\n function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;\\n\\n /**\\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\\n * are aware of the ERC-721 protocol to prevent tokens from being forever locked.\\n *\\n * Requirements:\\n *\\n * - `from` cannot be the zero address.\\n * - `to` cannot be the zero address.\\n * - `tokenId` token must exist and be owned by `from`.\\n * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or\\n * {setApprovalForAll}.\\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon\\n * a safe transfer.\\n *\\n * Emits a {Transfer} event.\\n */\\n function safeTransferFrom(address from, address to, uint256 tokenId) external;\\n\\n /**\\n * @dev Transfers `tokenId` token from `from` to `to`.\\n *\\n * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721\\n * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must\\n * understand this adds an external call which potentially creates a reentrancy vulnerability.\\n *\\n * Requirements:\\n *\\n * - `from` cannot be the zero address.\\n * - `to` cannot be the zero address.\\n * - `tokenId` token must be owned by `from`.\\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\\n *\\n * Emits a {Transfer} event.\\n */\\n function transferFrom(address from, address to, uint256 tokenId) external;\\n\\n /**\\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\\n * The approval is cleared when the token is transferred.\\n *\\n * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\\n *\\n * Requirements:\\n *\\n * - The caller must own the token or be an approved operator.\\n * - `tokenId` must exist.\\n *\\n * Emits an {Approval} event.\\n */\\n function approve(address to, uint256 tokenId) external;\\n\\n /**\\n * @dev Approve or remove `operator` as an operator for the caller.\\n * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\\n *\\n * Requirements:\\n *\\n * - The `operator` cannot be the address zero.\\n *\\n * Emits an {ApprovalForAll} event.\\n */\\n function setApprovalForAll(address operator, bool approved) external;\\n\\n /**\\n * @dev Returns the account approved for `tokenId` token.\\n *\\n * Requirements:\\n *\\n * - `tokenId` must exist.\\n */\\n function getApproved(uint256 tokenId) external view returns (address operator);\\n\\n /**\\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\\n *\\n * See {setApprovalForAll}\\n */\\n function isApprovedForAll(address owner, address operator) external view returns (bool);\\n}\\n\",\"keccak256\":\"0xe0e3a2099f2e2ce3579dd35548f613928739642058dfec95b1745f93364ce3de\",\"license\":\"MIT\"},\"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)\\n\\npragma solidity ^0.8.20;\\n\\nimport {IERC721} from \\\"../IERC721.sol\\\";\\n\\n/**\\n * @title ERC-721 Non-Fungible Token Standard, optional metadata extension\\n * @dev See https://eips.ethereum.org/EIPS/eip-721\\n */\\ninterface IERC721Metadata is IERC721 {\\n /**\\n * @dev Returns the token collection name.\\n */\\n function name() external view returns (string memory);\\n\\n /**\\n * @dev Returns the token collection symbol.\\n */\\n function symbol() external view returns (string memory);\\n\\n /**\\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\\n */\\n function tokenURI(uint256 tokenId) external view returns (string memory);\\n}\\n\",\"keccak256\":\"0x37d1aaaa5a2908a09e9dcf56a26ddf762ecf295afb5964695937344fc6802ce1\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.20;\\n\\n/**\\n * @dev Interface of the ERC-165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[ERC].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0xc859863e3bda7ec3cddf6dafe2ffe91bcbe648d1395b856b839c32ee9617c44c\",\"license\":\"MIT\"},\"@openzeppelin/contracts/utils/math/SafeCast.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)\\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\\n\\npragma solidity ^0.8.20;\\n\\n/**\\n * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow\\n * checks.\\n *\\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\\n * easily result in undesired exploitation or bugs, since developers usually\\n * assume that overflows raise errors. `SafeCast` restores this intuition by\\n * reverting the transaction when such an operation overflows.\\n *\\n * Using this library instead of the unchecked operations eliminates an entire\\n * class of bugs, so it's recommended to use it always.\\n */\\nlibrary SafeCast {\\n /**\\n * @dev Value doesn't fit in an uint of `bits` size.\\n */\\n error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);\\n\\n /**\\n * @dev An int value doesn't fit in an uint of `bits` size.\\n */\\n error SafeCastOverflowedIntToUint(int256 value);\\n\\n /**\\n * @dev Value doesn't fit in an int of `bits` size.\\n */\\n error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);\\n\\n /**\\n * @dev An uint value doesn't fit in an int of `bits` size.\\n */\\n error SafeCastOverflowedUintToInt(uint256 value);\\n\\n /**\\n * @dev Returns the downcasted uint248 from uint256, reverting on\\n * overflow (when the input is greater than largest uint248).\\n *\\n * Counterpart to Solidity's `uint248` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 248 bits\\n */\\n function toUint248(uint256 value) internal pure returns (uint248) {\\n if (value > type(uint248).max) {\\n revert SafeCastOverflowedUintDowncast(248, value);\\n }\\n return uint248(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint240 from uint256, reverting on\\n * overflow (when the input is greater than largest uint240).\\n *\\n * Counterpart to Solidity's `uint240` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 240 bits\\n */\\n function toUint240(uint256 value) internal pure returns (uint240) {\\n if (value > type(uint240).max) {\\n revert SafeCastOverflowedUintDowncast(240, value);\\n }\\n return uint240(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint232 from uint256, reverting on\\n * overflow (when the input is greater than largest uint232).\\n *\\n * Counterpart to Solidity's `uint232` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 232 bits\\n */\\n function toUint232(uint256 value) internal pure returns (uint232) {\\n if (value > type(uint232).max) {\\n revert SafeCastOverflowedUintDowncast(232, value);\\n }\\n return uint232(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint224 from uint256, reverting on\\n * overflow (when the input is greater than largest uint224).\\n *\\n * Counterpart to Solidity's `uint224` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 224 bits\\n */\\n function toUint224(uint256 value) internal pure returns (uint224) {\\n if (value > type(uint224).max) {\\n revert SafeCastOverflowedUintDowncast(224, value);\\n }\\n return uint224(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint216 from uint256, reverting on\\n * overflow (when the input is greater than largest uint216).\\n *\\n * Counterpart to Solidity's `uint216` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 216 bits\\n */\\n function toUint216(uint256 value) internal pure returns (uint216) {\\n if (value > type(uint216).max) {\\n revert SafeCastOverflowedUintDowncast(216, value);\\n }\\n return uint216(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint208 from uint256, reverting on\\n * overflow (when the input is greater than largest uint208).\\n *\\n * Counterpart to Solidity's `uint208` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 208 bits\\n */\\n function toUint208(uint256 value) internal pure returns (uint208) {\\n if (value > type(uint208).max) {\\n revert SafeCastOverflowedUintDowncast(208, value);\\n }\\n return uint208(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint200 from uint256, reverting on\\n * overflow (when the input is greater than largest uint200).\\n *\\n * Counterpart to Solidity's `uint200` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 200 bits\\n */\\n function toUint200(uint256 value) internal pure returns (uint200) {\\n if (value > type(uint200).max) {\\n revert SafeCastOverflowedUintDowncast(200, value);\\n }\\n return uint200(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint192 from uint256, reverting on\\n * overflow (when the input is greater than largest uint192).\\n *\\n * Counterpart to Solidity's `uint192` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 192 bits\\n */\\n function toUint192(uint256 value) internal pure returns (uint192) {\\n if (value > type(uint192).max) {\\n revert SafeCastOverflowedUintDowncast(192, value);\\n }\\n return uint192(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint184 from uint256, reverting on\\n * overflow (when the input is greater than largest uint184).\\n *\\n * Counterpart to Solidity's `uint184` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 184 bits\\n */\\n function toUint184(uint256 value) internal pure returns (uint184) {\\n if (value > type(uint184).max) {\\n revert SafeCastOverflowedUintDowncast(184, value);\\n }\\n return uint184(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint176 from uint256, reverting on\\n * overflow (when the input is greater than largest uint176).\\n *\\n * Counterpart to Solidity's `uint176` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 176 bits\\n */\\n function toUint176(uint256 value) internal pure returns (uint176) {\\n if (value > type(uint176).max) {\\n revert SafeCastOverflowedUintDowncast(176, value);\\n }\\n return uint176(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint168 from uint256, reverting on\\n * overflow (when the input is greater than largest uint168).\\n *\\n * Counterpart to Solidity's `uint168` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 168 bits\\n */\\n function toUint168(uint256 value) internal pure returns (uint168) {\\n if (value > type(uint168).max) {\\n revert SafeCastOverflowedUintDowncast(168, value);\\n }\\n return uint168(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint160 from uint256, reverting on\\n * overflow (when the input is greater than largest uint160).\\n *\\n * Counterpart to Solidity's `uint160` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 160 bits\\n */\\n function toUint160(uint256 value) internal pure returns (uint160) {\\n if (value > type(uint160).max) {\\n revert SafeCastOverflowedUintDowncast(160, value);\\n }\\n return uint160(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint152 from uint256, reverting on\\n * overflow (when the input is greater than largest uint152).\\n *\\n * Counterpart to Solidity's `uint152` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 152 bits\\n */\\n function toUint152(uint256 value) internal pure returns (uint152) {\\n if (value > type(uint152).max) {\\n revert SafeCastOverflowedUintDowncast(152, value);\\n }\\n return uint152(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint144 from uint256, reverting on\\n * overflow (when the input is greater than largest uint144).\\n *\\n * Counterpart to Solidity's `uint144` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 144 bits\\n */\\n function toUint144(uint256 value) internal pure returns (uint144) {\\n if (value > type(uint144).max) {\\n revert SafeCastOverflowedUintDowncast(144, value);\\n }\\n return uint144(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint136 from uint256, reverting on\\n * overflow (when the input is greater than largest uint136).\\n *\\n * Counterpart to Solidity's `uint136` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 136 bits\\n */\\n function toUint136(uint256 value) internal pure returns (uint136) {\\n if (value > type(uint136).max) {\\n revert SafeCastOverflowedUintDowncast(136, value);\\n }\\n return uint136(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint128 from uint256, reverting on\\n * overflow (when the input is greater than largest uint128).\\n *\\n * Counterpart to Solidity's `uint128` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 128 bits\\n */\\n function toUint128(uint256 value) internal pure returns (uint128) {\\n if (value > type(uint128).max) {\\n revert SafeCastOverflowedUintDowncast(128, value);\\n }\\n return uint128(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint120 from uint256, reverting on\\n * overflow (when the input is greater than largest uint120).\\n *\\n * Counterpart to Solidity's `uint120` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 120 bits\\n */\\n function toUint120(uint256 value) internal pure returns (uint120) {\\n if (value > type(uint120).max) {\\n revert SafeCastOverflowedUintDowncast(120, value);\\n }\\n return uint120(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint112 from uint256, reverting on\\n * overflow (when the input is greater than largest uint112).\\n *\\n * Counterpart to Solidity's `uint112` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 112 bits\\n */\\n function toUint112(uint256 value) internal pure returns (uint112) {\\n if (value > type(uint112).max) {\\n revert SafeCastOverflowedUintDowncast(112, value);\\n }\\n return uint112(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint104 from uint256, reverting on\\n * overflow (when the input is greater than largest uint104).\\n *\\n * Counterpart to Solidity's `uint104` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 104 bits\\n */\\n function toUint104(uint256 value) internal pure returns (uint104) {\\n if (value > type(uint104).max) {\\n revert SafeCastOverflowedUintDowncast(104, value);\\n }\\n return uint104(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint96 from uint256, reverting on\\n * overflow (when the input is greater than largest uint96).\\n *\\n * Counterpart to Solidity's `uint96` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 96 bits\\n */\\n function toUint96(uint256 value) internal pure returns (uint96) {\\n if (value > type(uint96).max) {\\n revert SafeCastOverflowedUintDowncast(96, value);\\n }\\n return uint96(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint88 from uint256, reverting on\\n * overflow (when the input is greater than largest uint88).\\n *\\n * Counterpart to Solidity's `uint88` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 88 bits\\n */\\n function toUint88(uint256 value) internal pure returns (uint88) {\\n if (value > type(uint88).max) {\\n revert SafeCastOverflowedUintDowncast(88, value);\\n }\\n return uint88(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint80 from uint256, reverting on\\n * overflow (when the input is greater than largest uint80).\\n *\\n * Counterpart to Solidity's `uint80` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 80 bits\\n */\\n function toUint80(uint256 value) internal pure returns (uint80) {\\n if (value > type(uint80).max) {\\n revert SafeCastOverflowedUintDowncast(80, value);\\n }\\n return uint80(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint72 from uint256, reverting on\\n * overflow (when the input is greater than largest uint72).\\n *\\n * Counterpart to Solidity's `uint72` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 72 bits\\n */\\n function toUint72(uint256 value) internal pure returns (uint72) {\\n if (value > type(uint72).max) {\\n revert SafeCastOverflowedUintDowncast(72, value);\\n }\\n return uint72(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint64 from uint256, reverting on\\n * overflow (when the input is greater than largest uint64).\\n *\\n * Counterpart to Solidity's `uint64` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 64 bits\\n */\\n function toUint64(uint256 value) internal pure returns (uint64) {\\n if (value > type(uint64).max) {\\n revert SafeCastOverflowedUintDowncast(64, value);\\n }\\n return uint64(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint56 from uint256, reverting on\\n * overflow (when the input is greater than largest uint56).\\n *\\n * Counterpart to Solidity's `uint56` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 56 bits\\n */\\n function toUint56(uint256 value) internal pure returns (uint56) {\\n if (value > type(uint56).max) {\\n revert SafeCastOverflowedUintDowncast(56, value);\\n }\\n return uint56(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint48 from uint256, reverting on\\n * overflow (when the input is greater than largest uint48).\\n *\\n * Counterpart to Solidity's `uint48` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 48 bits\\n */\\n function toUint48(uint256 value) internal pure returns (uint48) {\\n if (value > type(uint48).max) {\\n revert SafeCastOverflowedUintDowncast(48, value);\\n }\\n return uint48(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint40 from uint256, reverting on\\n * overflow (when the input is greater than largest uint40).\\n *\\n * Counterpart to Solidity's `uint40` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 40 bits\\n */\\n function toUint40(uint256 value) internal pure returns (uint40) {\\n if (value > type(uint40).max) {\\n revert SafeCastOverflowedUintDowncast(40, value);\\n }\\n return uint40(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint32 from uint256, reverting on\\n * overflow (when the input is greater than largest uint32).\\n *\\n * Counterpart to Solidity's `uint32` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 32 bits\\n */\\n function toUint32(uint256 value) internal pure returns (uint32) {\\n if (value > type(uint32).max) {\\n revert SafeCastOverflowedUintDowncast(32, value);\\n }\\n return uint32(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint24 from uint256, reverting on\\n * overflow (when the input is greater than largest uint24).\\n *\\n * Counterpart to Solidity's `uint24` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 24 bits\\n */\\n function toUint24(uint256 value) internal pure returns (uint24) {\\n if (value > type(uint24).max) {\\n revert SafeCastOverflowedUintDowncast(24, value);\\n }\\n return uint24(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint16 from uint256, reverting on\\n * overflow (when the input is greater than largest uint16).\\n *\\n * Counterpart to Solidity's `uint16` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 16 bits\\n */\\n function toUint16(uint256 value) internal pure returns (uint16) {\\n if (value > type(uint16).max) {\\n revert SafeCastOverflowedUintDowncast(16, value);\\n }\\n return uint16(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted uint8 from uint256, reverting on\\n * overflow (when the input is greater than largest uint8).\\n *\\n * Counterpart to Solidity's `uint8` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 8 bits\\n */\\n function toUint8(uint256 value) internal pure returns (uint8) {\\n if (value > type(uint8).max) {\\n revert SafeCastOverflowedUintDowncast(8, value);\\n }\\n return uint8(value);\\n }\\n\\n /**\\n * @dev Converts a signed int256 into an unsigned uint256.\\n *\\n * Requirements:\\n *\\n * - input must be greater than or equal to 0.\\n */\\n function toUint256(int256 value) internal pure returns (uint256) {\\n if (value < 0) {\\n revert SafeCastOverflowedIntToUint(value);\\n }\\n return uint256(value);\\n }\\n\\n /**\\n * @dev Returns the downcasted int248 from int256, reverting on\\n * overflow (when the input is less than smallest int248 or\\n * greater than largest int248).\\n *\\n * Counterpart to Solidity's `int248` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 248 bits\\n */\\n function toInt248(int256 value) internal pure returns (int248 downcasted) {\\n downcasted = int248(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(248, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int240 from int256, reverting on\\n * overflow (when the input is less than smallest int240 or\\n * greater than largest int240).\\n *\\n * Counterpart to Solidity's `int240` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 240 bits\\n */\\n function toInt240(int256 value) internal pure returns (int240 downcasted) {\\n downcasted = int240(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(240, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int232 from int256, reverting on\\n * overflow (when the input is less than smallest int232 or\\n * greater than largest int232).\\n *\\n * Counterpart to Solidity's `int232` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 232 bits\\n */\\n function toInt232(int256 value) internal pure returns (int232 downcasted) {\\n downcasted = int232(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(232, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int224 from int256, reverting on\\n * overflow (when the input is less than smallest int224 or\\n * greater than largest int224).\\n *\\n * Counterpart to Solidity's `int224` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 224 bits\\n */\\n function toInt224(int256 value) internal pure returns (int224 downcasted) {\\n downcasted = int224(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(224, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int216 from int256, reverting on\\n * overflow (when the input is less than smallest int216 or\\n * greater than largest int216).\\n *\\n * Counterpart to Solidity's `int216` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 216 bits\\n */\\n function toInt216(int256 value) internal pure returns (int216 downcasted) {\\n downcasted = int216(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(216, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int208 from int256, reverting on\\n * overflow (when the input is less than smallest int208 or\\n * greater than largest int208).\\n *\\n * Counterpart to Solidity's `int208` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 208 bits\\n */\\n function toInt208(int256 value) internal pure returns (int208 downcasted) {\\n downcasted = int208(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(208, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int200 from int256, reverting on\\n * overflow (when the input is less than smallest int200 or\\n * greater than largest int200).\\n *\\n * Counterpart to Solidity's `int200` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 200 bits\\n */\\n function toInt200(int256 value) internal pure returns (int200 downcasted) {\\n downcasted = int200(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(200, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int192 from int256, reverting on\\n * overflow (when the input is less than smallest int192 or\\n * greater than largest int192).\\n *\\n * Counterpart to Solidity's `int192` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 192 bits\\n */\\n function toInt192(int256 value) internal pure returns (int192 downcasted) {\\n downcasted = int192(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(192, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int184 from int256, reverting on\\n * overflow (when the input is less than smallest int184 or\\n * greater than largest int184).\\n *\\n * Counterpart to Solidity's `int184` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 184 bits\\n */\\n function toInt184(int256 value) internal pure returns (int184 downcasted) {\\n downcasted = int184(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(184, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int176 from int256, reverting on\\n * overflow (when the input is less than smallest int176 or\\n * greater than largest int176).\\n *\\n * Counterpart to Solidity's `int176` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 176 bits\\n */\\n function toInt176(int256 value) internal pure returns (int176 downcasted) {\\n downcasted = int176(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(176, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int168 from int256, reverting on\\n * overflow (when the input is less than smallest int168 or\\n * greater than largest int168).\\n *\\n * Counterpart to Solidity's `int168` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 168 bits\\n */\\n function toInt168(int256 value) internal pure returns (int168 downcasted) {\\n downcasted = int168(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(168, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int160 from int256, reverting on\\n * overflow (when the input is less than smallest int160 or\\n * greater than largest int160).\\n *\\n * Counterpart to Solidity's `int160` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 160 bits\\n */\\n function toInt160(int256 value) internal pure returns (int160 downcasted) {\\n downcasted = int160(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(160, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int152 from int256, reverting on\\n * overflow (when the input is less than smallest int152 or\\n * greater than largest int152).\\n *\\n * Counterpart to Solidity's `int152` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 152 bits\\n */\\n function toInt152(int256 value) internal pure returns (int152 downcasted) {\\n downcasted = int152(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(152, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int144 from int256, reverting on\\n * overflow (when the input is less than smallest int144 or\\n * greater than largest int144).\\n *\\n * Counterpart to Solidity's `int144` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 144 bits\\n */\\n function toInt144(int256 value) internal pure returns (int144 downcasted) {\\n downcasted = int144(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(144, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int136 from int256, reverting on\\n * overflow (when the input is less than smallest int136 or\\n * greater than largest int136).\\n *\\n * Counterpart to Solidity's `int136` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 136 bits\\n */\\n function toInt136(int256 value) internal pure returns (int136 downcasted) {\\n downcasted = int136(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(136, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int128 from int256, reverting on\\n * overflow (when the input is less than smallest int128 or\\n * greater than largest int128).\\n *\\n * Counterpart to Solidity's `int128` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 128 bits\\n */\\n function toInt128(int256 value) internal pure returns (int128 downcasted) {\\n downcasted = int128(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(128, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int120 from int256, reverting on\\n * overflow (when the input is less than smallest int120 or\\n * greater than largest int120).\\n *\\n * Counterpart to Solidity's `int120` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 120 bits\\n */\\n function toInt120(int256 value) internal pure returns (int120 downcasted) {\\n downcasted = int120(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(120, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int112 from int256, reverting on\\n * overflow (when the input is less than smallest int112 or\\n * greater than largest int112).\\n *\\n * Counterpart to Solidity's `int112` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 112 bits\\n */\\n function toInt112(int256 value) internal pure returns (int112 downcasted) {\\n downcasted = int112(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(112, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int104 from int256, reverting on\\n * overflow (when the input is less than smallest int104 or\\n * greater than largest int104).\\n *\\n * Counterpart to Solidity's `int104` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 104 bits\\n */\\n function toInt104(int256 value) internal pure returns (int104 downcasted) {\\n downcasted = int104(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(104, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int96 from int256, reverting on\\n * overflow (when the input is less than smallest int96 or\\n * greater than largest int96).\\n *\\n * Counterpart to Solidity's `int96` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 96 bits\\n */\\n function toInt96(int256 value) internal pure returns (int96 downcasted) {\\n downcasted = int96(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(96, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int88 from int256, reverting on\\n * overflow (when the input is less than smallest int88 or\\n * greater than largest int88).\\n *\\n * Counterpart to Solidity's `int88` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 88 bits\\n */\\n function toInt88(int256 value) internal pure returns (int88 downcasted) {\\n downcasted = int88(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(88, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int80 from int256, reverting on\\n * overflow (when the input is less than smallest int80 or\\n * greater than largest int80).\\n *\\n * Counterpart to Solidity's `int80` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 80 bits\\n */\\n function toInt80(int256 value) internal pure returns (int80 downcasted) {\\n downcasted = int80(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(80, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int72 from int256, reverting on\\n * overflow (when the input is less than smallest int72 or\\n * greater than largest int72).\\n *\\n * Counterpart to Solidity's `int72` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 72 bits\\n */\\n function toInt72(int256 value) internal pure returns (int72 downcasted) {\\n downcasted = int72(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(72, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int64 from int256, reverting on\\n * overflow (when the input is less than smallest int64 or\\n * greater than largest int64).\\n *\\n * Counterpart to Solidity's `int64` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 64 bits\\n */\\n function toInt64(int256 value) internal pure returns (int64 downcasted) {\\n downcasted = int64(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(64, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int56 from int256, reverting on\\n * overflow (when the input is less than smallest int56 or\\n * greater than largest int56).\\n *\\n * Counterpart to Solidity's `int56` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 56 bits\\n */\\n function toInt56(int256 value) internal pure returns (int56 downcasted) {\\n downcasted = int56(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(56, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int48 from int256, reverting on\\n * overflow (when the input is less than smallest int48 or\\n * greater than largest int48).\\n *\\n * Counterpart to Solidity's `int48` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 48 bits\\n */\\n function toInt48(int256 value) internal pure returns (int48 downcasted) {\\n downcasted = int48(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(48, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int40 from int256, reverting on\\n * overflow (when the input is less than smallest int40 or\\n * greater than largest int40).\\n *\\n * Counterpart to Solidity's `int40` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 40 bits\\n */\\n function toInt40(int256 value) internal pure returns (int40 downcasted) {\\n downcasted = int40(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(40, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int32 from int256, reverting on\\n * overflow (when the input is less than smallest int32 or\\n * greater than largest int32).\\n *\\n * Counterpart to Solidity's `int32` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 32 bits\\n */\\n function toInt32(int256 value) internal pure returns (int32 downcasted) {\\n downcasted = int32(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(32, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int24 from int256, reverting on\\n * overflow (when the input is less than smallest int24 or\\n * greater than largest int24).\\n *\\n * Counterpart to Solidity's `int24` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 24 bits\\n */\\n function toInt24(int256 value) internal pure returns (int24 downcasted) {\\n downcasted = int24(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(24, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int16 from int256, reverting on\\n * overflow (when the input is less than smallest int16 or\\n * greater than largest int16).\\n *\\n * Counterpart to Solidity's `int16` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 16 bits\\n */\\n function toInt16(int256 value) internal pure returns (int16 downcasted) {\\n downcasted = int16(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(16, value);\\n }\\n }\\n\\n /**\\n * @dev Returns the downcasted int8 from int256, reverting on\\n * overflow (when the input is less than smallest int8 or\\n * greater than largest int8).\\n *\\n * Counterpart to Solidity's `int8` operator.\\n *\\n * Requirements:\\n *\\n * - input must fit into 8 bits\\n */\\n function toInt8(int256 value) internal pure returns (int8 downcasted) {\\n downcasted = int8(value);\\n if (downcasted != value) {\\n revert SafeCastOverflowedIntDowncast(8, value);\\n }\\n }\\n\\n /**\\n * @dev Converts an unsigned uint256 into a signed int256.\\n *\\n * Requirements:\\n *\\n * - input must be less than or equal to maxInt256.\\n */\\n function toInt256(uint256 value) internal pure returns (int256) {\\n // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\\n if (value > uint256(type(int256).max)) {\\n revert SafeCastOverflowedUintToInt(value);\\n }\\n return int256(value);\\n }\\n\\n /**\\n * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.\\n */\\n function toUint(bool b) internal pure returns (uint256 u) {\\n /// @solidity memory-safe-assembly\\n assembly {\\n u := iszero(iszero(b))\\n }\\n }\\n}\\n\",\"keccak256\":\"0x8cd59334ed58b8884cd1f775afc9400db702e674e5d6a7a438c655b9de788d7e\",\"license\":\"MIT\"},\"src/interfaces/IBookManager.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n\\npragma solidity ^0.8.0;\\n\\nimport {IERC721Metadata} from \\\"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol\\\";\\n\\nimport {BookId} from \\\"../libraries/BookId.sol\\\";\\nimport {Currency} from \\\"../libraries/Currency.sol\\\";\\nimport {OrderId} from \\\"../libraries/OrderId.sol\\\";\\nimport {Tick} from \\\"../libraries/Tick.sol\\\";\\nimport {FeePolicy} from \\\"../libraries/FeePolicy.sol\\\";\\nimport {IERC721Permit} from \\\"./IERC721Permit.sol\\\";\\nimport {IHooks} from \\\"./IHooks.sol\\\";\\n\\n/**\\n * @title IBookManager\\n * @notice The interface for the BookManager contract\\n */\\ninterface IBookManager is IERC721Metadata, IERC721Permit {\\n error InvalidUnitSize();\\n error InvalidFeePolicy();\\n error InvalidProvider(address provider);\\n error LockedBy(address locker, address hook);\\n error CurrencyNotSettled();\\n\\n /**\\n * @notice Event emitted when a new book is opened\\n * @param id The book id\\n * @param base The base currency\\n * @param quote The quote currency\\n * @param unitSize The unit size of the book\\n * @param makerPolicy The maker fee policy\\n * @param takerPolicy The taker fee policy\\n * @param hooks The hooks contract\\n */\\n event Open(\\n BookId indexed id,\\n Currency indexed base,\\n Currency indexed quote,\\n uint64 unitSize,\\n FeePolicy makerPolicy,\\n FeePolicy takerPolicy,\\n IHooks hooks\\n );\\n\\n /**\\n * @notice Event emitted when a new order is made\\n * @param bookId The book id\\n * @param user The user address\\n * @param tick The order tick\\n * @param orderIndex The order index\\n * @param unit The order unit\\n * @param provider The provider address\\n */\\n event Make(\\n BookId indexed bookId, address indexed user, Tick tick, uint256 orderIndex, uint64 unit, address provider\\n );\\n\\n /**\\n * @notice Event emitted when an order is taken\\n * @param bookId The book id\\n * @param user The user address\\n * @param tick The order tick\\n * @param unit The order unit\\n */\\n event Take(BookId indexed bookId, address indexed user, Tick tick, uint64 unit);\\n\\n /**\\n * @notice Event emitted when an order is canceled\\n * @param orderId The order id\\n * @param unit The canceled unit\\n */\\n event Cancel(OrderId indexed orderId, uint64 unit);\\n\\n /**\\n * @notice Event emitted when an order is claimed\\n * @param orderId The order id\\n * @param unit The claimed unit\\n */\\n event Claim(OrderId indexed orderId, uint64 unit);\\n\\n /**\\n * @notice Event emitted when a provider is whitelisted\\n * @param provider The provider address\\n */\\n event Whitelist(address indexed provider);\\n\\n /**\\n * @notice Event emitted when a provider is delisted\\n * @param provider The provider address\\n */\\n event Delist(address indexed provider);\\n\\n /**\\n * @notice Event emitted when a provider collects fees\\n * @param provider The provider address\\n * @param recipient The recipient address\\n * @param currency The currency\\n * @param amount The collected amount\\n */\\n event Collect(address indexed provider, address indexed recipient, Currency indexed currency, uint256 amount);\\n\\n /**\\n * @notice Event emitted when new default provider is set\\n * @param newDefaultProvider The new default provider address\\n */\\n event SetDefaultProvider(address indexed newDefaultProvider);\\n\\n /**\\n * @notice This structure represents a unique identifier for a book in the BookManager.\\n * @param base The base currency of the book\\n * @param unitSize The unit size of the book\\n * @param quote The quote currency of the book\\n * @param makerPolicy The maker fee policy of the book\\n * @param hooks The hooks contract of the book\\n * @param takerPolicy The taker fee policy of the book\\n */\\n struct BookKey {\\n Currency base;\\n uint64 unitSize;\\n Currency quote;\\n FeePolicy makerPolicy;\\n IHooks hooks;\\n FeePolicy takerPolicy;\\n }\\n\\n /**\\n * @notice Returns the base URI\\n * @return The base URI\\n */\\n function baseURI() external view returns (string memory);\\n\\n /**\\n * @notice Returns the contract URI\\n * @return The contract URI\\n */\\n function contractURI() external view returns (string memory);\\n\\n /**\\n * @notice Returns the default provider\\n * @return The default provider\\n */\\n function defaultProvider() external view returns (address);\\n\\n /**\\n * @notice Returns the total reserves of a given currency\\n * @param currency The currency in question\\n * @return The total reserves amount\\n */\\n function reservesOf(Currency currency) external view returns (uint256);\\n\\n /**\\n * @notice Checks if a provider is whitelisted\\n * @param provider The address of the provider\\n * @return True if the provider is whitelisted, false otherwise\\n */\\n function isWhitelisted(address provider) external view returns (bool);\\n\\n /**\\n * @notice Verifies if an owner has authorized a spender for a token\\n * @param owner The address of the token owner\\n * @param spender The address of the spender\\n * @param tokenId The token ID\\n */\\n function checkAuthorized(address owner, address spender, uint256 tokenId) external view;\\n\\n /**\\n * @notice Calculates the amount owed to a provider in a given currency\\n * @param provider The provider's address\\n * @param currency The currency in question\\n * @return The owed amount\\n */\\n function tokenOwed(address provider, Currency currency) external view returns (uint256);\\n\\n /**\\n * @notice Calculates the currency balance changes for a given locker\\n * @param locker The address of the locker\\n * @param currency The currency in question\\n * @return The net change in currency balance\\n */\\n function getCurrencyDelta(address locker, Currency currency) external view returns (int256);\\n\\n /**\\n * @notice Retrieves the book key for a given book ID\\n * @param id The book ID\\n * @return The book key\\n */\\n function getBookKey(BookId id) external view returns (BookKey memory);\\n\\n /**\\n * @notice This structure represents a current status for an order in the BookManager.\\n * @param provider The provider of the order\\n * @param open The open unit of the order\\n * @param claimable The claimable unit of the order\\n */\\n struct OrderInfo {\\n address provider;\\n uint64 open;\\n uint64 claimable;\\n }\\n\\n /**\\n * @notice Provides information about an order\\n * @param id The order ID\\n * @return Order information including provider, open status, and claimable unit\\n */\\n function getOrder(OrderId id) external view returns (OrderInfo memory);\\n\\n /**\\n * @notice Retrieves the locker and caller addresses for a given lock\\n * @param i The index of the lock\\n * @return locker The locker's address\\n * @return lockCaller The caller's address\\n */\\n function getLock(uint256 i) external view returns (address locker, address lockCaller);\\n\\n /**\\n * @notice Provides the lock data\\n * @return The lock data including necessary numeric values\\n */\\n function getLockData() external view returns (uint128, uint128);\\n\\n /**\\n * @notice Returns the depth of a given book ID and tick\\n * @param id The book ID\\n * @param tick The tick\\n * @return The depth of the tick\\n */\\n function getDepth(BookId id, Tick tick) external view returns (uint64);\\n\\n /**\\n * @notice Retrieves the highest tick for a given book ID\\n * @param id The book ID\\n * @return tick The highest tick\\n */\\n function getHighest(BookId id) external view returns (Tick tick);\\n\\n /**\\n * @notice Finds the maximum tick less than a specified tick in a book\\n * @dev Returns `Tick.wrap(type(int24).min)` if the specified tick is the lowest\\n * @param id The book ID\\n * @param tick The specified tick\\n * @return The next lower tick\\n */\\n function maxLessThan(BookId id, Tick tick) external view returns (Tick);\\n\\n /**\\n * @notice Checks if a book is opened\\n * @param id The book ID\\n * @return True if the book is opened, false otherwise\\n */\\n function isOpened(BookId id) external view returns (bool);\\n\\n /**\\n * @notice Checks if a book is empty\\n * @param id The book ID\\n * @return True if the book is empty, false otherwise\\n */\\n function isEmpty(BookId id) external view returns (bool);\\n\\n /**\\n * @notice Encodes a BookKey into a BookId\\n * @param key The BookKey to encode\\n * @return The encoded BookId\\n */\\n function encodeBookKey(BookKey calldata key) external pure returns (BookId);\\n\\n /**\\n * @notice Loads a value from a specific storage slot\\n * @param slot The storage slot\\n * @return The value in the slot\\n */\\n function load(bytes32 slot) external view returns (bytes32);\\n\\n /**\\n * @notice Loads a sequence of values starting from a specific slot\\n * @param startSlot The starting slot\\n * @param nSlot The number of slots to load\\n * @return The sequence of values\\n */\\n function load(bytes32 startSlot, uint256 nSlot) external view returns (bytes memory);\\n\\n /**\\n * @notice Opens a new book\\n * @param key The book key\\n * @param hookData The hook data\\n */\\n function open(BookKey calldata key, bytes calldata hookData) external;\\n\\n /**\\n * @notice Locks a book manager function\\n * @param locker The locker address\\n * @param data The lock data\\n * @return The lock return data\\n */\\n function lock(address locker, bytes calldata data) external returns (bytes memory);\\n\\n /**\\n * @notice This structure represents the parameters for making an order.\\n * @param key The book key for the order\\n * @param tick The tick for the order\\n * @param unit The unit for the order. Times key.unitSize to get actual bid amount.\\n * @param provider The provider for the order. The limit order service provider address to collect fees.\\n */\\n struct MakeParams {\\n BookKey key;\\n Tick tick;\\n uint64 unit;\\n address provider;\\n }\\n\\n /**\\n * @notice Make a limit order\\n * @param params The order parameters\\n * @param hookData The hook data\\n * @return id The order id. Returns 0 if the order is not settled\\n * @return quoteAmount The amount of quote currency to be paid\\n */\\n function make(MakeParams calldata params, bytes calldata hookData)\\n external\\n returns (OrderId id, uint256 quoteAmount);\\n\\n /**\\n * @notice This structure represents the parameters for taking orders in the specified tick.\\n * @param key The book key for the order\\n * @param tick The tick for the order\\n * @param maxUnit The max unit to take\\n */\\n struct TakeParams {\\n BookKey key;\\n Tick tick;\\n uint64 maxUnit;\\n }\\n\\n /**\\n * @notice Take a limit order at specific tick\\n * @param params The order parameters\\n * @param hookData The hook data\\n * @return quoteAmount The amount of quote currency to be received\\n * @return baseAmount The amount of base currency to be paid\\n */\\n function take(TakeParams calldata params, bytes calldata hookData)\\n external\\n returns (uint256 quoteAmount, uint256 baseAmount);\\n\\n /**\\n * @notice This structure represents the parameters for canceling an order.\\n * @param id The order id for the order\\n * @param toUnit The remaining open unit for the order after cancellation. Must not exceed the current open unit.\\n */\\n struct CancelParams {\\n OrderId id;\\n uint64 toUnit;\\n }\\n\\n /**\\n * @notice Cancel a limit order\\n * @param params The order parameters\\n * @param hookData The hook data\\n * @return canceledAmount The amount of quote currency canceled\\n */\\n function cancel(CancelParams calldata params, bytes calldata hookData) external returns (uint256 canceledAmount);\\n\\n /**\\n * @notice Claims an order\\n * @param id The order ID\\n * @param hookData The hook data\\n * @return claimedAmount The amount claimed\\n */\\n function claim(OrderId id, bytes calldata hookData) external returns (uint256 claimedAmount);\\n\\n /**\\n * @notice Collects fees from a provider\\n * @param recipient The recipient address\\n * @param currency The currency\\n * @return The collected amount\\n */\\n function collect(address recipient, Currency currency) external returns (uint256);\\n\\n /**\\n * @notice Withdraws a currency\\n * @param currency The currency\\n * @param to The recipient address\\n * @param amount The amount\\n */\\n function withdraw(Currency currency, address to, uint256 amount) external;\\n\\n /**\\n * @notice Settles a currency\\n * @param currency The currency\\n * @return The settled amount\\n */\\n function settle(Currency currency) external payable returns (uint256);\\n\\n /**\\n * @notice Whitelists a provider\\n * @param provider The provider address\\n */\\n function whitelist(address provider) external;\\n\\n /**\\n * @notice Delists a provider\\n * @param provider The provider address\\n */\\n function delist(address provider) external;\\n\\n /**\\n * @notice Sets the default provider\\n * @param newDefaultProvider The new default provider address\\n */\\n function setDefaultProvider(address newDefaultProvider) external;\\n}\\n\",\"keccak256\":\"0xda8dffc751ac3554033e084919f1e431eb2585c80e1e30b9a0198366a8607086\",\"license\":\"MIT\"},\"src/interfaces/IERC721Permit.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n\\npragma solidity ^0.8.0;\\n\\nimport {IERC721} from \\\"@openzeppelin/contracts/token/ERC721/IERC721.sol\\\";\\n\\n/**\\n * @title IERC721Permit\\n * @notice An interface for the ERC721 permit extension\\n */\\ninterface IERC721Permit is IERC721 {\\n error InvalidSignature();\\n error PermitExpired();\\n\\n /**\\n * @notice The EIP-712 typehash for the permit struct used by the contract\\n */\\n function PERMIT_TYPEHASH() external pure returns (bytes32);\\n\\n /**\\n * @notice The EIP-712 domain separator for this contract\\n */\\n function DOMAIN_SEPARATOR() external view returns (bytes32);\\n\\n /**\\n * @notice Approve the spender to transfer the given tokenId\\n * @param spender The address to approve\\n * @param tokenId The tokenId to approve\\n * @param deadline The deadline for the signature\\n * @param v The recovery id of the signature\\n * @param r The r value of the signature\\n * @param s The s value of the signature\\n */\\n function permit(address spender, uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external;\\n\\n /**\\n * @notice Get the current nonce for a token\\n * @param tokenId The tokenId to get the nonce for\\n * @return The current nonce\\n */\\n function nonces(uint256 tokenId) external view returns (uint256);\\n}\\n\",\"keccak256\":\"0xd6baab4710fa674981395f428bd6550c4e288ac44a1a5d38c2a58fd67234d57e\",\"license\":\"MIT\"},\"src/interfaces/IHooks.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n\\npragma solidity ^0.8.20;\\n\\nimport {IBookManager} from \\\"./IBookManager.sol\\\";\\nimport {OrderId} from \\\"../libraries/OrderId.sol\\\";\\n\\n/**\\n * @title IHooks\\n * @notice Interface for the hooks contract\\n */\\ninterface IHooks {\\n /**\\n * @notice Hook called before opening a new book\\n * @param sender The sender of the open transaction\\n * @param key The key of the book being opened\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function beforeOpen(address sender, IBookManager.BookKey calldata key, bytes calldata hookData)\\n external\\n returns (bytes4);\\n\\n /**\\n * @notice Hook called after opening a new book\\n * @param sender The sender of the open transaction\\n * @param key The key of the book being opened\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function afterOpen(address sender, IBookManager.BookKey calldata key, bytes calldata hookData)\\n external\\n returns (bytes4);\\n\\n /**\\n * @notice Hook called before making a new order\\n * @param sender The sender of the make transaction\\n * @param params The parameters of the make transaction\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function beforeMake(address sender, IBookManager.MakeParams calldata params, bytes calldata hookData)\\n external\\n returns (bytes4);\\n\\n /**\\n * @notice Hook called after making a new order\\n * @param sender The sender of the make transaction\\n * @param params The parameters of the make transaction\\n * @param orderId The id of the order that was made\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function afterMake(\\n address sender,\\n IBookManager.MakeParams calldata params,\\n OrderId orderId,\\n bytes calldata hookData\\n ) external returns (bytes4);\\n\\n /**\\n * @notice Hook called before taking an order\\n * @param sender The sender of the take transaction\\n * @param params The parameters of the take transaction\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function beforeTake(address sender, IBookManager.TakeParams calldata params, bytes calldata hookData)\\n external\\n returns (bytes4);\\n\\n /**\\n * @notice Hook called after taking an order\\n * @param sender The sender of the take transaction\\n * @param params The parameters of the take transaction\\n * @param takenUnit The unit that was taken\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function afterTake(\\n address sender,\\n IBookManager.TakeParams calldata params,\\n uint64 takenUnit,\\n bytes calldata hookData\\n ) external returns (bytes4);\\n\\n /**\\n * @notice Hook called before canceling an order\\n * @param sender The sender of the cancel transaction\\n * @param params The parameters of the cancel transaction\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function beforeCancel(address sender, IBookManager.CancelParams calldata params, bytes calldata hookData)\\n external\\n returns (bytes4);\\n\\n /**\\n * @notice Hook called after canceling an order\\n * @param sender The sender of the cancel transaction\\n * @param params The parameters of the cancel transaction\\n * @param canceledUnit The unit that was canceled\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function afterCancel(\\n address sender,\\n IBookManager.CancelParams calldata params,\\n uint64 canceledUnit,\\n bytes calldata hookData\\n ) external returns (bytes4);\\n\\n /**\\n * @notice Hook called before claiming an order\\n * @param sender The sender of the claim transaction\\n * @param orderId The id of the order being claimed\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function beforeClaim(address sender, OrderId orderId, bytes calldata hookData) external returns (bytes4);\\n\\n /**\\n * @notice Hook called after claiming an order\\n * @param sender The sender of the claim transaction\\n * @param orderId The id of the order being claimed\\n * @param claimedUnit The unit that was claimed\\n * @param hookData The data passed to the hook\\n * @return Returns the function selector if the hook is successful\\n */\\n function afterClaim(address sender, OrderId orderId, uint64 claimedUnit, bytes calldata hookData)\\n external\\n returns (bytes4);\\n}\\n\",\"keccak256\":\"0xbff95e07debd7d51cb3aa79172fd3c31efb57cea1c03d21b5740a565198d8343\",\"license\":\"MIT\"},\"src/libraries/Book.sol\":{\"content\":\"// SPDX-License-Identifier: -\\n// License: https://license.clober.io/LICENSE_V2.pdf\\n\\npragma solidity ^0.8.20;\\n\\nimport {SafeCast} from \\\"@openzeppelin/contracts/utils/math/SafeCast.sol\\\";\\n\\nimport {IBookManager} from \\\"../interfaces/IBookManager.sol\\\";\\nimport {SegmentedSegmentTree} from \\\"./SegmentedSegmentTree.sol\\\";\\nimport {Tick, TickLibrary} from \\\"./Tick.sol\\\";\\nimport {OrderId, OrderIdLibrary} from \\\"./OrderId.sol\\\";\\nimport {TotalClaimableMap} from \\\"./TotalClaimableMap.sol\\\";\\nimport {TickBitmap} from \\\"./TickBitmap.sol\\\";\\n\\nlibrary Book {\\n using Book for State;\\n using TickBitmap for mapping(uint256 => uint256);\\n using SegmentedSegmentTree for SegmentedSegmentTree.Core;\\n using TotalClaimableMap for mapping(uint24 => uint256);\\n using TickLibrary for Tick;\\n using OrderIdLibrary for OrderId;\\n\\n error ZeroUnit();\\n error BookAlreadyOpened();\\n error BookNotOpened();\\n error QueueReplaceFailed();\\n error CancelFailed(uint64 maxCancelableUnit);\\n\\n // @dev Due to the segment tree implementation, the maximum order size is 2 ** 15.\\n uint40 internal constant MAX_ORDER = 2 ** 15; // 32768\\n uint256 internal constant MAX_ORDER_M = 2 ** 15 - 1; // % 32768\\n\\n struct Order {\\n address provider;\\n uint64 pending; // @dev unfilled unit + filled(claimable) unit\\n }\\n\\n struct Queue {\\n SegmentedSegmentTree.Core tree;\\n Order[] orders;\\n }\\n\\n struct State {\\n IBookManager.BookKey key;\\n mapping(Tick tick => Queue) queues;\\n mapping(uint256 => uint256) tickBitmap;\\n // @dev Four values of totalClaimable are stored in one uint256\\n mapping(uint24 groupIndex => uint256) totalClaimableOf;\\n }\\n\\n function open(State storage self, IBookManager.BookKey calldata key) external {\\n if (self.isOpened()) revert BookAlreadyOpened();\\n self.key = key;\\n }\\n\\n function isOpened(State storage self) internal view returns (bool) {\\n return self.key.unitSize != 0;\\n }\\n\\n function checkOpened(State storage self) internal view {\\n if (!self.isOpened()) revert BookNotOpened();\\n }\\n\\n function depth(State storage self, Tick tick) internal view returns (uint64) {\\n return self.queues[tick].tree.total() - self.totalClaimableOf.get(tick);\\n }\\n\\n function highest(State storage self) internal view returns (Tick) {\\n return self.tickBitmap.highest();\\n }\\n\\n function maxLessThan(State storage self, Tick tick) internal view returns (Tick) {\\n return self.tickBitmap.maxLessThan(tick);\\n }\\n\\n function isEmpty(State storage self) internal view returns (bool) {\\n return self.tickBitmap.isEmpty();\\n }\\n\\n function _getOrder(State storage self, Tick tick, uint40 index) private view returns (Order storage) {\\n return self.queues[tick].orders[index];\\n }\\n\\n function getOrder(State storage self, Tick tick, uint40 index) internal view returns (Order memory) {\\n return _getOrder(self, tick, index);\\n }\\n\\n function make(State storage self, Tick tick, uint64 unit, address provider) external returns (uint40 orderIndex) {\\n if (unit == 0) revert ZeroUnit();\\n if (!self.tickBitmap.has(tick)) self.tickBitmap.set(tick);\\n\\n Queue storage queue = self.queues[tick];\\n // @dev Assume that orders.length cannot reach to type(uint40).max + 1.\\n orderIndex = SafeCast.toUint40(queue.orders.length);\\n\\n if (orderIndex >= MAX_ORDER) {\\n unchecked {\\n uint40 staleOrderIndex = orderIndex - MAX_ORDER;\\n uint64 stalePendingUnit = queue.orders[staleOrderIndex].pending;\\n if (stalePendingUnit > 0) {\\n // If the order is not settled completely, we cannot replace it\\n uint64 claimable = calculateClaimableUnit(self, tick, staleOrderIndex);\\n if (claimable != stalePendingUnit) revert QueueReplaceFailed();\\n }\\n }\\n\\n // The stale order is settled completely, so remove it from the totalClaimableOf.\\n // We can determine the stale order is claimable.\\n uint64 staleOrderedUnit = queue.tree.get(orderIndex & MAX_ORDER_M);\\n if (staleOrderedUnit > 0) self.totalClaimableOf.sub(tick, staleOrderedUnit);\\n }\\n\\n queue.tree.update(orderIndex & MAX_ORDER_M, unit);\\n\\n queue.orders.push(Order({pending: unit, provider: provider}));\\n }\\n\\n /**\\n * @notice Take orders from the book\\n * @param self The book state\\n * @param maxTakeUnit The maximum unit to take\\n * @return takenUnit The actual unit to take\\n */\\n function take(State storage self, Tick tick, uint64 maxTakeUnit) external returns (uint64 takenUnit) {\\n uint64 currentDepth = depth(self, tick);\\n if (currentDepth > maxTakeUnit) {\\n takenUnit = maxTakeUnit;\\n } else {\\n takenUnit = currentDepth;\\n self.tickBitmap.clear(tick);\\n }\\n\\n self.totalClaimableOf.add(tick, takenUnit);\\n }\\n\\n function cancel(State storage self, OrderId orderId, uint64 to)\\n external\\n returns (uint64 canceled, uint64 afterPending)\\n {\\n (, Tick tick, uint40 orderIndex) = orderId.decode();\\n Queue storage queue = self.queues[tick];\\n uint64 pendingUnit = queue.orders[orderIndex].pending;\\n uint64 claimableUnit = calculateClaimableUnit(self, tick, orderIndex);\\n afterPending = to + claimableUnit;\\n unchecked {\\n if (pendingUnit < afterPending) revert CancelFailed(pendingUnit - claimableUnit);\\n canceled = pendingUnit - afterPending;\\n\\n self.queues[tick].tree.update(\\n orderIndex & MAX_ORDER_M, self.queues[tick].tree.get(orderIndex & MAX_ORDER_M) - canceled\\n );\\n }\\n queue.orders[orderIndex].pending = afterPending;\\n\\n if (depth(self, tick) == 0) {\\n // clear() won't revert so we can cancel with to=0 even if the depth() is already zero\\n // works even if bitmap is empty\\n self.tickBitmap.clear(tick);\\n }\\n }\\n\\n function claim(State storage self, Tick tick, uint40 index) external returns (uint64 claimedUnit) {\\n Order storage order = _getOrder(self, tick, index);\\n\\n claimedUnit = calculateClaimableUnit(self, tick, index);\\n unchecked {\\n order.pending -= claimedUnit;\\n }\\n }\\n\\n function calculateClaimableUnit(State storage self, Tick tick, uint40 index) public view returns (uint64) {\\n uint64 orderUnit = self.getOrder(tick, index).pending;\\n\\n Queue storage queue = self.queues[tick];\\n // @dev Book logic always considers replaced orders as claimable.\\n unchecked {\\n if (uint256(index) + MAX_ORDER < queue.orders.length) return orderUnit;\\n uint64 totalClaimableUnit = self.totalClaimableOf.get(tick);\\n uint64 rangeRight = _getClaimRangeRight(queue, index);\\n if (rangeRight - orderUnit >= totalClaimableUnit) return 0;\\n\\n // -------- totalClaimable ---------|---\\n // ------|---- orderUnit ----|--------\\n // rangeLeft rangeRight\\n if (rangeRight <= totalClaimableUnit) return orderUnit;\\n // -- totalClaimable --|----------------\\n // ------|---- orderUnit ----|--------\\n // rangeLeft rangeRight\\n else return totalClaimableUnit - (rangeRight - orderUnit);\\n }\\n }\\n\\n function _getClaimRangeRight(Queue storage queue, uint256 orderIndex) private view returns (uint64 rangeRight) {\\n uint256 l = queue.orders.length & MAX_ORDER_M;\\n uint256 r = (orderIndex + 1) & MAX_ORDER_M;\\n rangeRight = (l < r) ? queue.tree.query(l, r) : queue.tree.total() - queue.tree.query(r, l);\\n }\\n}\\n\",\"keccak256\":\"0x8c15ba2fe1bb7f08ed5767c66b4d250e0b00863e4eae25781b3296636bddcdc0\",\"license\":\"-\"},\"src/libraries/BookId.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-2.0-or-later\\n\\npragma solidity ^0.8.20;\\n\\nimport {IBookManager} from \\\"../interfaces/IBookManager.sol\\\";\\n\\ntype BookId is uint192;\\n\\nlibrary BookIdLibrary {\\n function toId(IBookManager.BookKey memory bookKey) internal pure returns (BookId id) {\\n bytes32 hash = keccak256(abi.encode(bookKey));\\n assembly {\\n id := and(hash, 0xffffffffffffffffffffffffffffffffffffffffffffffff)\\n }\\n }\\n}\\n\",\"keccak256\":\"0x60f9ed99dfb9a5ce14c29359a5ad8b43de0c756e44b2e5f581e8ea6db7cacbeb\",\"license\":\"GPL-2.0-or-later\"},\"src/libraries/Currency.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-2.0-or-later\\n\\npragma solidity ^0.8.20;\\n\\nimport {IERC20} from \\\"@openzeppelin/contracts/token/ERC20/IERC20.sol\\\";\\n\\ntype Currency is address;\\n\\n/// @title CurrencyLibrary\\n/// @dev This library allows for transferring and holding native tokens and ERC20 tokens\\nlibrary CurrencyLibrary {\\n using CurrencyLibrary for Currency;\\n\\n /// @notice Thrown when a native transfer fails\\n error NativeTransferFailed();\\n\\n /// @notice Thrown when an ERC20 transfer fails\\n error ERC20TransferFailed();\\n\\n Currency public constant NATIVE = Currency.wrap(address(0));\\n\\n function transfer(Currency currency, address to, uint256 amount) internal {\\n // implementation from\\n // https://github.com/transmissions11/solmate/blob/e8f96f25d48fe702117ce76c79228ca4f20206cb/src/utils/SafeTransferLib.sol\\n\\n bool success;\\n if (currency.isNative()) {\\n assembly {\\n // Transfer the ETH and store if it succeeded or not.\\n success := call(gas(), to, amount, 0, 0, 0, 0)\\n }\\n\\n if (!success) revert NativeTransferFailed();\\n } else {\\n assembly {\\n // Get a pointer to some free memory.\\n let freeMemoryPointer := mload(0x40)\\n\\n // Write the abi-encoded calldata into memory, beginning with the function selector.\\n mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)\\n mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the \\\"to\\\" argument.\\n mstore(add(freeMemoryPointer, 36), amount) // Append the \\\"amount\\\" argument. Masking not required as it's a full 32 byte type.\\n\\n success :=\\n and(\\n // Set success to whether the call reverted, if not we check it either\\n // returned exactly 1 (can't just be non-zero data), or had no return data.\\n or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),\\n // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.\\n // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.\\n // Counterintuitively, this call must be positioned second to the or() call in the\\n // surrounding and() call or else returndatasize() will be zero during the computation.\\n call(gas(), currency, 0, freeMemoryPointer, 68, 0, 32)\\n )\\n }\\n\\n if (!success) revert ERC20TransferFailed();\\n }\\n }\\n\\n function balanceOfSelf(Currency currency) internal view returns (uint256) {\\n if (currency.isNative()) return address(this).balance;\\n else return IERC20(Currency.unwrap(currency)).balanceOf(address(this));\\n }\\n\\n function equals(Currency currency, Currency other) internal pure returns (bool) {\\n return Currency.unwrap(currency) == Currency.unwrap(other);\\n }\\n\\n function isNative(Currency currency) internal pure returns (bool) {\\n return Currency.unwrap(currency) == Currency.unwrap(NATIVE);\\n }\\n\\n function toId(Currency currency) internal pure returns (uint256) {\\n return uint160(Currency.unwrap(currency));\\n }\\n\\n function fromId(uint256 id) internal pure returns (Currency) {\\n return Currency.wrap(address(uint160(id)));\\n }\\n}\\n\",\"keccak256\":\"0xf04f76015a51981ad0f84fd3ebb0a4eb6c31685604c22584669915aa8dd7ac54\",\"license\":\"GPL-2.0-or-later\"},\"src/libraries/DirtyUint64.sol\":{\"content\":\"// SPDX-License-Identifier: -\\n// License: https://license.clober.io/LICENSE.pdf\\n\\npragma solidity ^0.8.0;\\n\\nlibrary DirtyUint64 {\\n error DirtyUint64Error(uint256 errorCode);\\n\\n uint256 private constant _OVERFLOW_ERROR = 0;\\n uint256 private constant _UNDERFLOW_ERROR = 1;\\n\\n function toDirtyUnsafe(uint64 cleanUint) internal pure returns (uint64 dirtyUint) {\\n assembly {\\n dirtyUint := add(cleanUint, 1)\\n }\\n }\\n\\n function toDirty(uint64 cleanUint) internal pure returns (uint64 dirtyUint) {\\n assembly {\\n dirtyUint := add(cleanUint, 1)\\n }\\n if (dirtyUint == 0) {\\n revert DirtyUint64Error(_OVERFLOW_ERROR);\\n }\\n }\\n\\n function toClean(uint64 dirtyUint) internal pure returns (uint64 cleanUint) {\\n assembly {\\n cleanUint := sub(dirtyUint, gt(dirtyUint, 0))\\n }\\n }\\n\\n function addClean(uint64 current, uint64 cleanUint) internal pure returns (uint64) {\\n assembly {\\n current := add(add(current, iszero(current)), cleanUint)\\n }\\n if (current < cleanUint) {\\n revert DirtyUint64Error(_OVERFLOW_ERROR);\\n }\\n return current;\\n }\\n\\n function addDirty(uint64 current, uint64 dirtyUint) internal pure returns (uint64) {\\n assembly {\\n current := sub(add(add(current, iszero(current)), add(dirtyUint, iszero(dirtyUint))), 1)\\n }\\n if (current < dirtyUint) {\\n revert DirtyUint64Error(_OVERFLOW_ERROR);\\n }\\n return current;\\n }\\n\\n function subClean(uint64 current, uint64 cleanUint) internal pure returns (uint64 ret) {\\n assembly {\\n current := add(current, iszero(current))\\n ret := sub(current, cleanUint)\\n }\\n if (current < ret || ret == 0) {\\n revert DirtyUint64Error(_UNDERFLOW_ERROR);\\n }\\n }\\n\\n function subDirty(uint64 current, uint64 dirtyUint) internal pure returns (uint64 ret) {\\n assembly {\\n current := add(current, iszero(current))\\n ret := sub(add(current, 1), add(dirtyUint, iszero(dirtyUint)))\\n }\\n if (current < ret || ret == 0) {\\n revert DirtyUint64Error(_UNDERFLOW_ERROR);\\n }\\n }\\n\\n function sumPackedUnsafe(uint256 packed, uint256 from, uint256 to) internal pure returns (uint64 ret) {\\n packed = packed >> (from << 6);\\n unchecked {\\n for (uint256 i = from; i < to; ++i) {\\n assembly {\\n let element := and(packed, 0xffffffffffffffff)\\n ret := add(ret, add(element, iszero(element)))\\n packed := shr(64, packed)\\n }\\n }\\n }\\n assembly {\\n ret := sub(ret, sub(to, from))\\n }\\n }\\n}\\n\",\"keccak256\":\"0xe9021ccfef31d7fc17242134eea12c0313bf38a2998c46ac91eb2b34e76fc8db\",\"license\":\"-\"},\"src/libraries/FeePolicy.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-2.0-or-later\\n\\npragma solidity ^0.8.20;\\n\\nimport {Math} from \\\"./Math.sol\\\";\\n\\ntype FeePolicy is uint24;\\n\\nlibrary FeePolicyLibrary {\\n uint256 internal constant RATE_PRECISION = 10 ** 6;\\n int256 internal constant MAX_FEE_RATE = 500000;\\n int256 internal constant MIN_FEE_RATE = -500000;\\n\\n uint256 internal constant RATE_MASK = 0x7fffff; // 23 bits\\n\\n error InvalidFeePolicy();\\n\\n function encode(bool usesQuote_, int24 rate_) internal pure returns (FeePolicy feePolicy) {\\n if (rate_ > MAX_FEE_RATE || rate_ < MIN_FEE_RATE) {\\n revert InvalidFeePolicy();\\n }\\n\\n uint256 mask = usesQuote_ ? 1 << 23 : 0;\\n assembly {\\n feePolicy := or(mask, add(and(rate_, 0xffffff), MAX_FEE_RATE))\\n }\\n }\\n\\n function isValid(FeePolicy self) internal pure returns (bool) {\\n int24 r = rate(self);\\n\\n return !(r > MAX_FEE_RATE || r < MIN_FEE_RATE);\\n }\\n\\n function usesQuote(FeePolicy self) internal pure returns (bool f) {\\n assembly {\\n f := shr(23, self)\\n }\\n }\\n\\n function rate(FeePolicy self) internal pure returns (int24 r) {\\n assembly {\\n r := sub(and(self, RATE_MASK), MAX_FEE_RATE)\\n }\\n }\\n\\n function calculateFee(FeePolicy self, uint256 amount, bool reverseRounding) internal pure returns (int256 fee) {\\n int24 r = rate(self);\\n\\n bool positive = r > 0;\\n uint256 absRate;\\n unchecked {\\n absRate = uint256(uint24(positive ? r : -r));\\n }\\n // @dev absFee must be less than type(int256).max\\n uint256 absFee = Math.divide(amount * absRate, RATE_PRECISION, reverseRounding ? !positive : positive);\\n fee = positive ? int256(absFee) : -int256(absFee);\\n }\\n\\n function calculateOriginalAmount(FeePolicy self, uint256 amount, bool reverseFee)\\n internal\\n pure\\n returns (uint256 originalAmount)\\n {\\n int24 r = rate(self);\\n\\n uint256 divider;\\n assembly {\\n if reverseFee { r := sub(0, r) }\\n divider := add(RATE_PRECISION, r)\\n }\\n originalAmount = Math.divide(amount * RATE_PRECISION, divider, reverseFee);\\n }\\n}\\n\",\"keccak256\":\"0xa945c8e3ced4dd6f7be34da0306de74d466bf1a6ea74de5c54672fb49234cfef\",\"license\":\"GPL-2.0-or-later\"},\"src/libraries/Math.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-2.0-or-later\\n\\npragma solidity ^0.8.0;\\n\\nlibrary Math {\\n function divide(uint256 a, uint256 b, bool roundingUp) internal pure returns (uint256 ret) {\\n // In the OrderBook contract code, b is never zero.\\n assembly {\\n ret := add(div(a, b), and(gt(mod(a, b), 0), roundingUp))\\n }\\n }\\n\\n /// @dev Returns `ln(x)`, denominated in `WAD`.\\n /// Credit to Remco Bloemen under MIT license: https://2\\u03c0.com/22/exp-ln\\n function lnWad(int256 x) internal pure returns (int256 r) {\\n /// @solidity memory-safe-assembly\\n assembly {\\n // We want to convert `x` from `10**18` fixed point to `2**96` fixed point.\\n // We do this by multiplying by `2**96 / 10**18`. But since\\n // `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here\\n // and add `ln(2**96 / 10**18)` at the end.\\n\\n // Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`.\\n r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\\n r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))\\n r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\\n r := or(r, shl(4, lt(0xffff, shr(r, x))))\\n r := or(r, shl(3, lt(0xff, shr(r, x))))\\n // We place the check here for more optimal stack operations.\\n if iszero(sgt(x, 0)) {\\n mstore(0x00, 0x1615e638) // `LnWadUndefined()`.\\n revert(0x1c, 0x04)\\n }\\n // forgefmt: disable-next-item\\n r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),\\n 0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff))\\n\\n // Reduce range of x to (1, 2) * 2**96\\n // ln(2^k * x) = k * ln(2) + ln(x)\\n x := shr(159, shl(r, x))\\n\\n // Evaluate using a (8, 8)-term rational approximation.\\n // `p` is made monic, we will multiply by a scale factor later.\\n // forgefmt: disable-next-item\\n let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir.\\n sar(96, mul(add(43456485725739037958740375743393,\\n sar(96, mul(add(24828157081833163892658089445524,\\n sar(96, mul(add(3273285459638523848632254066296,\\n x), x))), x))), x)), 11111509109440967052023855526967)\\n p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857)\\n p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526)\\n p := sub(mul(p, x), shl(96, 795164235651350426258249787498))\\n // We leave `p` in `2**192` basis so we don't need to scale it back up for the division.\\n\\n // `q` is monic by convention.\\n let q := add(5573035233440673466300451813936, x)\\n q := add(71694874799317883764090561454958, sar(96, mul(x, q)))\\n q := add(283447036172924575727196451306956, sar(96, mul(x, q)))\\n q := add(401686690394027663651624208769553, sar(96, mul(x, q)))\\n q := add(204048457590392012362485061816622, sar(96, mul(x, q)))\\n q := add(31853899698501571402653359427138, sar(96, mul(x, q)))\\n q := add(909429971244387300277376558375, sar(96, mul(x, q)))\\n\\n // `p / q` is in the range `(0, 0.125) * 2**96`.\\n\\n // Finalization, we need to:\\n // - Multiply by the scale factor `s = 5.549\\u2026`.\\n // - Add `ln(2**96 / 10**18)`.\\n // - Add `k * ln(2)`.\\n // - Multiply by `10**18 / 2**96 = 5**18 >> 78`.\\n\\n // The q polynomial is known not to have zeros in the domain.\\n // No scaling required because p is already `2**96` too large.\\n p := sdiv(p, q)\\n // Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`.\\n p := mul(1677202110996718588342820967067443963516166, p)\\n // Add `ln(2) * k * 5**18 * 2**192`.\\n // forgefmt: disable-next-item\\n p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p)\\n // Base conversion: mul `2**96 / (5**18 * 2**192)`.\\n r := sdiv(p, 302231454903657293676544000000000000000000)\\n }\\n }\\n}\\n\",\"keccak256\":\"0xb2dc502dd66a9e36e6c4bb8c4fb3d21120f9f0ff7a934dcfe21ec820cac72275\",\"license\":\"GPL-2.0-or-later\"},\"src/libraries/OrderId.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-2.0-or-later\\n\\npragma solidity ^0.8.0;\\n\\nimport {Tick} from \\\"./Tick.sol\\\";\\nimport {BookId} from \\\"./BookId.sol\\\";\\n\\ntype OrderId is uint256;\\n\\nlibrary OrderIdLibrary {\\n /**\\n * @dev Encode the order id.\\n * @param bookId The book id.\\n * @param tick The tick.\\n * @param index The index.\\n * @return id The order id.\\n */\\n function encode(BookId bookId, Tick tick, uint40 index) internal pure returns (OrderId id) {\\n // @dev If we just use tick at the assembly code, the code will convert tick into bytes32.\\n // e.g. When index == -2, the shifted value( shl(40, tick) ) will be\\n // 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0000000000 instead of 0xfffffffe0000000000\\n // Therefore, we have to safely cast tick into uint256 first.\\n uint256 _tick = uint256(uint24(Tick.unwrap(tick)));\\n assembly {\\n id := add(index, add(shl(40, _tick), shl(64, bookId)))\\n }\\n }\\n\\n function decode(OrderId id) internal pure returns (BookId bookId, Tick tick, uint40 index) {\\n assembly {\\n bookId := shr(64, id)\\n tick := and(shr(40, id), 0xffffff)\\n index := and(id, 0xffffffffff)\\n }\\n }\\n\\n function getBookId(OrderId id) internal pure returns (BookId bookId) {\\n assembly {\\n bookId := shr(64, id)\\n }\\n }\\n\\n function getTick(OrderId id) internal pure returns (Tick tick) {\\n assembly {\\n tick := and(shr(40, id), 0xffffff)\\n }\\n }\\n\\n function getIndex(OrderId id) internal pure returns (uint40 index) {\\n assembly {\\n index := and(id, 0xffffffffff)\\n }\\n }\\n}\\n\",\"keccak256\":\"0x78c384badc4971d774987c6f5bce9d578712c7469688735b3c1eafaf2e748fe6\",\"license\":\"GPL-2.0-or-later\"},\"src/libraries/PackedUint256.sol\":{\"content\":\"// SPDX-License-Identifier: -\\n// License: https://license.clober.io/LICENSE.pdf\\n\\npragma solidity ^0.8.0;\\n\\nlibrary PackedUint256 {\\n error PackedUint256Error(uint256 errorCode);\\n\\n uint256 private constant _UINT8_INDEX_ERROR = 0;\\n uint256 private constant _UINT16_INDEX_ERROR = 1;\\n uint256 private constant _UINT32_INDEX_ERROR = 2;\\n uint256 private constant _UINT64_INDEX_ERROR = 3;\\n\\n uint256 private constant _MAX_UINT64 = type(uint64).max;\\n uint256 private constant _MAX_UINT32 = type(uint32).max;\\n uint256 private constant _MAX_UINT16 = type(uint16).max;\\n uint256 private constant _MAX_UINT8 = type(uint8).max;\\n\\n function get8Unsafe(uint256 packed, uint256 index) internal pure returns (uint8 ret) {\\n assembly {\\n ret := and(shr(shl(3, index), packed), 0xff)\\n }\\n }\\n\\n function get8(uint256 packed, uint256 index) internal pure returns (uint8 ret) {\\n if (index > 31) {\\n revert PackedUint256Error(_UINT8_INDEX_ERROR);\\n }\\n assembly {\\n ret := and(shr(shl(3, index), packed), 0xff)\\n }\\n }\\n\\n function get16Unsafe(uint256 packed, uint256 index) internal pure returns (uint16 ret) {\\n assembly {\\n ret := and(shr(shl(4, index), packed), 0xffff)\\n }\\n }\\n\\n function get16(uint256 packed, uint256 index) internal pure returns (uint16 ret) {\\n if (index > 15) {\\n revert PackedUint256Error(_UINT16_INDEX_ERROR);\\n }\\n assembly {\\n ret := and(shr(shl(4, index), packed), 0xffff)\\n }\\n }\\n\\n function get32Unsafe(uint256 packed, uint256 index) internal pure returns (uint32 ret) {\\n assembly {\\n ret := and(shr(shl(5, index), packed), 0xffffffff)\\n }\\n }\\n\\n function get32(uint256 packed, uint256 index) internal pure returns (uint32 ret) {\\n if (index > 7) {\\n revert PackedUint256Error(_UINT32_INDEX_ERROR);\\n }\\n assembly {\\n ret := and(shr(shl(5, index), packed), 0xffffffff)\\n }\\n }\\n\\n function get64Unsafe(uint256 packed, uint256 index) internal pure returns (uint64 ret) {\\n assembly {\\n ret := and(shr(shl(6, index), packed), 0xffffffffffffffff)\\n }\\n }\\n\\n function get64(uint256 packed, uint256 index) internal pure returns (uint64 ret) {\\n if (index > 3) {\\n revert PackedUint256Error(_UINT64_INDEX_ERROR);\\n }\\n assembly {\\n ret := and(shr(shl(6, index), packed), 0xffffffffffffffff)\\n }\\n }\\n\\n function add8Unsafe(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := add(packed, shl(shl(3, index), and(value, 0xff)))\\n }\\n }\\n\\n function add8(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\\n if (index > 31) {\\n revert PackedUint256Error(_UINT8_INDEX_ERROR);\\n }\\n uint8 current = get8Unsafe(packed, index);\\n current += value;\\n ret = update8Unsafe(packed, index, current);\\n }\\n\\n function add16Unsafe(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := add(packed, shl(shl(4, index), and(value, 0xffff)))\\n }\\n }\\n\\n function add16(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\\n if (index > 15) {\\n revert PackedUint256Error(_UINT16_INDEX_ERROR);\\n }\\n uint16 current = get16Unsafe(packed, index);\\n current += value;\\n ret = update16Unsafe(packed, index, current);\\n }\\n\\n function add32Unsafe(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := add(packed, shl(shl(5, index), and(value, 0xffffffff)))\\n }\\n }\\n\\n function add32(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\\n if (index > 7) {\\n revert PackedUint256Error(_UINT32_INDEX_ERROR);\\n }\\n uint32 current = get32Unsafe(packed, index);\\n current += value;\\n ret = update32Unsafe(packed, index, current);\\n }\\n\\n function add64Unsafe(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := add(packed, shl(shl(6, index), and(value, 0xffffffffffffffff)))\\n }\\n }\\n\\n function add64(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\\n if (index > 3) {\\n revert PackedUint256Error(_UINT64_INDEX_ERROR);\\n }\\n uint64 current = get64Unsafe(packed, index);\\n current += value;\\n ret = update64Unsafe(packed, index, current);\\n }\\n\\n function sub8Unsafe(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := sub(packed, shl(shl(3, index), and(value, 0xff)))\\n }\\n }\\n\\n function sub8(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\\n if (index > 31) {\\n revert PackedUint256Error(_UINT8_INDEX_ERROR);\\n }\\n uint8 current = get8Unsafe(packed, index);\\n current -= value;\\n ret = update8Unsafe(packed, index, current);\\n }\\n\\n function sub16Unsafe(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := sub(packed, shl(shl(4, index), and(value, 0xffff)))\\n }\\n }\\n\\n function sub16(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\\n if (index > 15) {\\n revert PackedUint256Error(_UINT16_INDEX_ERROR);\\n }\\n uint16 current = get16Unsafe(packed, index);\\n current -= value;\\n ret = update16Unsafe(packed, index, current);\\n }\\n\\n function sub32Unsafe(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := sub(packed, shl(shl(5, index), and(value, 0xffffffff)))\\n }\\n }\\n\\n function sub32(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\\n if (index > 7) {\\n revert PackedUint256Error(_UINT32_INDEX_ERROR);\\n }\\n uint32 current = get32Unsafe(packed, index);\\n current -= value;\\n ret = update32Unsafe(packed, index, current);\\n }\\n\\n function sub64Unsafe(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\\n assembly {\\n ret := sub(packed, shl(shl(6, index), and(value, 0xffffffffffffffff)))\\n }\\n }\\n\\n function sub64(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\\n if (index > 3) {\\n revert PackedUint256Error(_UINT64_INDEX_ERROR);\\n }\\n uint64 current = get64Unsafe(packed, index);\\n current -= value;\\n ret = update64Unsafe(packed, index, current);\\n }\\n\\n function update8Unsafe(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\\n unchecked {\\n index = index << 3;\\n packed = packed - (packed & (_MAX_UINT8 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xff)))\\n }\\n }\\n\\n function update8(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\\n if (index > 31) {\\n revert PackedUint256Error(_UINT8_INDEX_ERROR);\\n }\\n unchecked {\\n index = index << 3;\\n packed = packed - (packed & (_MAX_UINT8 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xff)))\\n }\\n }\\n\\n function update16Unsafe(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\\n unchecked {\\n index = index << 4;\\n packed = packed - (packed & (_MAX_UINT16 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xffff)))\\n }\\n }\\n\\n function update16(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\\n if (index > 15) {\\n revert PackedUint256Error(_UINT16_INDEX_ERROR);\\n }\\n unchecked {\\n index = index << 4;\\n packed = packed - (packed & (_MAX_UINT16 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xffff)))\\n }\\n }\\n\\n function update32Unsafe(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\\n unchecked {\\n index = index << 5;\\n packed = packed - (packed & (_MAX_UINT32 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xffffffff)))\\n }\\n }\\n\\n function update32(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\\n if (index > 7) {\\n revert PackedUint256Error(_UINT32_INDEX_ERROR);\\n }\\n unchecked {\\n index = index << 5;\\n packed = packed - (packed & (_MAX_UINT32 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xffffffff)))\\n }\\n }\\n\\n function update64Unsafe(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\\n unchecked {\\n index = index << 6;\\n packed = packed - (packed & (_MAX_UINT64 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xffffffffffffffff)))\\n }\\n }\\n\\n function update64(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\\n if (index > 3) {\\n revert PackedUint256Error(_UINT64_INDEX_ERROR);\\n }\\n unchecked {\\n index = index << 6;\\n packed = packed - (packed & (_MAX_UINT64 << index));\\n }\\n assembly {\\n ret := add(packed, shl(index, and(value, 0xffffffffffffffff)))\\n }\\n }\\n\\n function total32(uint256 packed) internal pure returns (uint256) {\\n unchecked {\\n uint256 ret = _MAX_UINT32 & packed;\\n for (uint256 i = 0; i < 7; ++i) {\\n packed = packed >> 32;\\n ret += _MAX_UINT32 & packed;\\n }\\n return ret;\\n }\\n }\\n\\n function total64(uint256 packed) internal pure returns (uint256) {\\n unchecked {\\n uint256 ret = _MAX_UINT64 & packed;\\n for (uint256 i = 0; i < 3; ++i) {\\n packed = packed >> 64;\\n ret += _MAX_UINT64 & packed;\\n }\\n return ret;\\n }\\n }\\n\\n function sum32(uint256 packed, uint256 from, uint256 to) internal pure returns (uint256) {\\n unchecked {\\n packed = packed >> (from << 5);\\n uint256 ret = 0;\\n for (uint256 i = from; i < to; ++i) {\\n ret += _MAX_UINT32 & packed;\\n packed = packed >> 32;\\n }\\n return ret;\\n }\\n }\\n\\n function sum64(uint256 packed, uint256 from, uint256 to) internal pure returns (uint256) {\\n unchecked {\\n packed = packed >> (from << 6);\\n uint256 ret = 0;\\n for (uint256 i = from; i < to; ++i) {\\n ret += _MAX_UINT64 & packed;\\n packed = packed >> 64;\\n }\\n return ret;\\n }\\n }\\n}\\n\",\"keccak256\":\"0x02c63e757709f39c3e46e4350ecf1df15f423f512eed51fef34f584fdb219c82\",\"license\":\"-\"},\"src/libraries/SegmentedSegmentTree.sol\":{\"content\":\"// SPDX-License-Identifier: -\\n// License: https://license.clober.io/LICENSE.pdf\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./PackedUint256.sol\\\";\\nimport \\\"./DirtyUint64.sol\\\";\\n\\n/**\\n * \\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\n *\\n * Segmented Segment Tree\\n * by Clober\\n *\\n * ____________/\\\\\\\\\\\\_______________/\\\\\\\\\\\\\\\\\\\\____________/\\\\\\\\\\\\____\\n * __________/\\\\\\\\\\\\\\\\\\\\___________/\\\\\\\\\\\\\\\\////___________/\\\\\\\\\\\\\\\\\\\\____\\n * ________/\\\\\\\\\\\\/\\\\\\\\\\\\________/\\\\\\\\\\\\///______________/\\\\\\\\\\\\/\\\\\\\\\\\\____\\n * ______/\\\\\\\\\\\\/\\\\/\\\\\\\\\\\\______/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_________/\\\\\\\\\\\\/\\\\/\\\\\\\\\\\\____\\n * ____/\\\\\\\\\\\\/__\\\\/\\\\\\\\\\\\_____/\\\\\\\\\\\\\\\\///////\\\\\\\\\\\\_____/\\\\\\\\\\\\/__\\\\/\\\\\\\\\\\\____\\n * __/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_\\\\/\\\\\\\\\\\\______\\\\//\\\\\\\\\\\\__/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_\\n * _\\\\///////////\\\\\\\\\\\\//__\\\\//\\\\\\\\\\\\______/\\\\\\\\\\\\__\\\\///////////\\\\\\\\\\\\//__\\n * ___________\\\\/\\\\\\\\\\\\_____\\\\///\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/_____________\\\\/\\\\\\\\\\\\____\\n * ___________\\\\///________\\\\/////////_______________\\\\///_____\\n *\\n * 4 Layers of 64-bit nodes, hence 464\\n *\\n * \\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\ud83c\\udf32\\n */\\nlibrary SegmentedSegmentTree {\\n using PackedUint256 for uint256;\\n using DirtyUint64 for uint64;\\n\\n error SegmentedSegmentTreeError(uint256 errorCode);\\n\\n uint256 private constant _INDEX_ERROR = 0;\\n uint256 private constant _OVERFLOW_ERROR = 1;\\n\\n // uint8 private constant _R = 2; // There are `2` root node groups\\n // uint8 private constant _C = 4; // There are `4` children (each child is a node group of its own) for each node\\n uint8 private constant _L = 4; // There are `4` layers of node groups\\n uint256 private constant _P = 4; // uint256 / uint64 = `4`\\n uint256 private constant _P_M = 3; // % 4 = & `3`\\n uint256 private constant _P_P = 2; // 2 ** `2` = 4\\n uint256 private constant _N_P = 4; // C * P = 2 ** `4`\\n uint256 private constant _MAX_NODES = 2 ** 15; // (R * P) * ((C * P) ** (L - 1)) = `32768`\\n uint256 private constant _MAX_NODES_P_MINUS_ONE = 14; // MAX_NODES / R = 2 ** `14`\\n\\n struct Core {\\n mapping(uint256 => uint256)[_L] layers;\\n }\\n\\n struct LayerIndex {\\n uint256 group;\\n uint256 node;\\n }\\n\\n function get(Core storage core, uint256 index) internal view returns (uint64 ret) {\\n if (index >= _MAX_NODES) {\\n revert SegmentedSegmentTreeError(_INDEX_ERROR);\\n }\\n unchecked {\\n ret = core.layers[_L - 1][index >> _P_P].get64(index & _P_M).toClean();\\n }\\n }\\n\\n function total(Core storage core) internal view returns (uint64) {\\n return DirtyUint64.sumPackedUnsafe(core.layers[0][0], 0, _P)\\n + DirtyUint64.sumPackedUnsafe(core.layers[0][1], 0, _P);\\n }\\n\\n function query(Core storage core, uint256 left, uint256 right) internal view returns (uint64 sum) {\\n if (left == right) {\\n return 0;\\n }\\n // right should be greater than left\\n if (left >= right) {\\n revert SegmentedSegmentTreeError(_INDEX_ERROR);\\n }\\n if (right > _MAX_NODES) {\\n revert SegmentedSegmentTreeError(_INDEX_ERROR);\\n }\\n\\n LayerIndex[] memory leftIndices = _getLayerIndices(left);\\n LayerIndex[] memory rightIndices = _getLayerIndices(right);\\n uint256 ret;\\n uint256 deficit;\\n\\n unchecked {\\n uint256 leftNodeIndex;\\n uint256 rightNodeIndex;\\n for (uint256 l = _L - 1;; --l) {\\n LayerIndex memory leftIndex = leftIndices[l];\\n LayerIndex memory rightIndex = rightIndices[l];\\n leftNodeIndex += leftIndex.node;\\n rightNodeIndex += rightIndex.node;\\n\\n if (rightIndex.group == leftIndex.group) {\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, rightNodeIndex);\\n break;\\n }\\n\\n if (rightIndex.group - leftIndex.group < 4) {\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, _P);\\n\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], 0, rightNodeIndex);\\n\\n for (uint256 group = leftIndex.group + 1; group < rightIndex.group; group++) {\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][group], 0, _P);\\n }\\n break;\\n }\\n\\n if (leftIndex.group % 4 == 0) {\\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], 0, leftNodeIndex);\\n leftNodeIndex = 0;\\n } else if (leftIndex.group % 4 == 1) {\\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group - 1], 0, _P);\\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], 0, leftNodeIndex);\\n leftNodeIndex = 0;\\n } else if (leftIndex.group % 4 == 2) {\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, _P);\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group + 1], 0, _P);\\n leftNodeIndex = 1;\\n } else {\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, _P);\\n leftNodeIndex = 1;\\n }\\n\\n if (rightIndex.group % 4 == 0) {\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], 0, rightNodeIndex);\\n rightNodeIndex = 0;\\n } else if (rightIndex.group % 4 == 1) {\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group - 1], 0, _P);\\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], 0, rightNodeIndex);\\n rightNodeIndex = 0;\\n } else if (rightIndex.group % 4 == 2) {\\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], rightNodeIndex, _P);\\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group + 1], 0, _P);\\n rightNodeIndex = 1;\\n } else {\\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], rightNodeIndex, _P);\\n rightNodeIndex = 1;\\n }\\n }\\n ret -= deficit;\\n }\\n sum = uint64(ret);\\n }\\n\\n function update(Core storage core, uint256 index, uint64 value) internal returns (uint64 replaced) {\\n if (index >= _MAX_NODES) {\\n revert SegmentedSegmentTreeError(_INDEX_ERROR);\\n }\\n LayerIndex[] memory indices = _getLayerIndices(index);\\n unchecked {\\n LayerIndex memory bottomIndex = indices[_L - 1];\\n replaced = core.layers[_L - 1][bottomIndex.group].get64Unsafe(bottomIndex.node).toClean();\\n if (replaced >= value) {\\n uint64 diff = replaced - value;\\n for (uint256 l = 0; l < _L; ++l) {\\n LayerIndex memory layerIndex = indices[l];\\n uint256 node = core.layers[l][layerIndex.group];\\n core.layers[l][layerIndex.group] =\\n node.update64(layerIndex.node, node.get64(layerIndex.node).subClean(diff));\\n }\\n } else {\\n uint64 diff = value - replaced;\\n if (total(core) > type(uint64).max - diff) revert SegmentedSegmentTreeError(_OVERFLOW_ERROR);\\n for (uint256 l = 0; l < _L; ++l) {\\n LayerIndex memory layerIndex = indices[l];\\n uint256 node = core.layers[l][layerIndex.group];\\n core.layers[l][layerIndex.group] =\\n node.update64(layerIndex.node, node.get64(layerIndex.node).addClean(diff));\\n }\\n }\\n }\\n }\\n\\n function _getLayerIndices(uint256 index) private pure returns (LayerIndex[] memory) {\\n unchecked {\\n LayerIndex[] memory indices = new LayerIndex[](_L);\\n uint256 shifter = _MAX_NODES_P_MINUS_ONE;\\n for (uint256 l = 0; l < _L; ++l) {\\n indices[l] = LayerIndex({group: index >> shifter, node: (index >> (shifter - _P_P)) & _P_M});\\n shifter = shifter - _N_P;\\n }\\n return indices;\\n }\\n }\\n}\\n\\n/*\\n * Segmented Segment Tree is a Segment Tree\\n * that has been compressed so that `C` nodes\\n * are compressed into a single uint256.\\n *\\n * Each node in a non-leaf node group is the sum of the\\n * total sum of each child node group that it represents.\\n * Each non-leaf node represents `E` node groups.\\n *\\n * A node group consists of `S` uint256.\\n *\\n * By expressing the index in `N` notation,\\n * we can find the index in each respective layer\\n *\\n * S: Size of each node group\\n * C: Compression Coefficient\\n * E: Expansion Coefficient\\n * L: Number of Layers\\n * N: Notation, S * C * E\\n *\\n * `E` will not be considered for this version of the implementation. (E = 2)\\n */\\n\",\"keccak256\":\"0x27d4261adeea576c6e163c4e1d9ccca1c4b56bb695c8cbf40c0345ba17cb87c2\",\"license\":\"-\"},\"src/libraries/SignificantBit.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-2.0-or-later\\n\\npragma solidity ^0.8.0;\\n\\nlibrary SignificantBit {\\n // http://supertech.csail.mit.edu/papers/debruijn.pdf\\n uint256 internal constant DEBRUIJN_SEQ = 0x818283848586878898A8B8C8D8E8F929395969799A9B9D9E9FAAEB6BEDEEFF;\\n bytes internal constant DEBRUIJN_INDEX =\\n hex\\\"0001020903110a19042112290b311a3905412245134d2a550c5d32651b6d3a7506264262237d468514804e8d2b95569d0d495ea533a966b11c886eb93bc176c9071727374353637324837e9b47af86c7155181ad4fd18ed32c9096db57d59ee30e2e4a6a5f92a6be3498aae067ddb2eb1d5989b56fd7baf33ca0c2ee77e5caf7ff0810182028303840444c545c646c7425617c847f8c949c48a4a8b087b8c0c816365272829aaec650acd0d28fdad4e22d6991bd97dfdcea58b4d6f29fede4f6fe0f1f2f3f4b5b6b607b8b93a3a7b7bf357199c5abcfd9e168bcdee9b3f1ecf5fd1e3e5a7a8aa2b670c4ced8bbe8f0f4fc3d79a1c3cde7effb78cce6facbf9f8\\\";\\n\\n /**\\n * @notice Finds the index of the least significant bit.\\n * @param x The value to compute the least significant bit for. Must be a non-zero value.\\n * @return ret The index of the least significant bit.\\n */\\n function leastSignificantBit(uint256 x) internal pure returns (uint8) {\\n require(x > 0);\\n uint256 index;\\n assembly {\\n index := shr(248, mul(and(x, add(not(x), 1)), DEBRUIJN_SEQ))\\n }\\n return uint8(DEBRUIJN_INDEX[index]); // can optimize with CODECOPY opcode\\n }\\n\\n function mostSignificantBit(uint256 x) internal pure returns (uint8 msb) {\\n require(x > 0);\\n assembly {\\n let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\\n msb := or(msb, f)\\n x := shr(f, x)\\n f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\\n msb := or(msb, f)\\n x := shr(f, x)\\n f := shl(5, gt(x, 0xFFFFFFFF))\\n msb := or(msb, f)\\n x := shr(f, x)\\n f := shl(4, gt(x, 0xFFFF))\\n msb := or(msb, f)\\n x := shr(f, x)\\n f := shl(3, gt(x, 0xFF))\\n msb := or(msb, f)\\n x := shr(f, x)\\n f := shl(2, gt(x, 0xF))\\n msb := or(msb, f)\\n x := shr(f, x)\\n f := shl(1, gt(x, 0x3))\\n msb := or(msb, f)\\n x := shr(f, x)\\n f := gt(x, 0x1)\\n msb := or(msb, f)\\n }\\n }\\n}\\n\",\"keccak256\":\"0x7ffeb68f2f666cdbefa20efc0376c922f049a8765d9a25871c9ade4fabc9e604\",\"license\":\"GPL-2.0-or-later\"},\"src/libraries/Tick.sol\":{\"content\":\"// SPDX-License-Identifier: GPL-2.0-or-later\\n\\npragma solidity ^0.8.20;\\n\\nimport {Math} from \\\"./Math.sol\\\";\\n\\ntype Tick is int24;\\n\\nlibrary TickLibrary {\\n using Math for *;\\n using TickLibrary for Tick;\\n\\n error InvalidTick();\\n error InvalidPrice();\\n error TickOverflow();\\n\\n int24 internal constant MAX_TICK = 2 ** 19 - 1;\\n int24 internal constant MIN_TICK = -MAX_TICK;\\n\\n uint256 internal constant MIN_PRICE = 1350587;\\n uint256 internal constant MAX_PRICE = 4647684107270898330752324302845848816923571339324334;\\n\\n uint256 private constant _R0 = 0xfff97272373d413259a46990;\\n uint256 private constant _R1 = 0xfff2e50f5f656932ef12357c;\\n uint256 private constant _R2 = 0xffe5caca7e10e4e61c3624ea;\\n uint256 private constant _R3 = 0xffcb9843d60f6159c9db5883;\\n uint256 private constant _R4 = 0xff973b41fa98c081472e6896;\\n uint256 private constant _R5 = 0xff2ea16466c96a3843ec78b3;\\n uint256 private constant _R6 = 0xfe5dee046a99a2a811c461f1;\\n uint256 private constant _R7 = 0xfcbe86c7900a88aedcffc83b;\\n uint256 private constant _R8 = 0xf987a7253ac413176f2b074c;\\n uint256 private constant _R9 = 0xf3392b0822b70005940c7a39;\\n uint256 private constant _R10 = 0xe7159475a2c29b7443b29c7f;\\n uint256 private constant _R11 = 0xd097f3bdfd2022b8845ad8f7;\\n uint256 private constant _R12 = 0xa9f746462d870fdf8a65dc1f;\\n uint256 private constant _R13 = 0x70d869a156d2a1b890bb3df6;\\n uint256 private constant _R14 = 0x31be135f97d08fd981231505;\\n uint256 private constant _R15 = 0x9aa508b5b7a84e1c677de54;\\n uint256 private constant _R16 = 0x5d6af8dedb81196699c329;\\n uint256 private constant _R17 = 0x2216e584f5fa1ea92604;\\n uint256 private constant _R18 = 0x48a170391f7dc42;\\n uint256 private constant _R19 = 0x149b34;\\n\\n function validateTick(Tick tick) internal pure {\\n if (Tick.unwrap(tick) > MAX_TICK || Tick.unwrap(tick) < MIN_TICK) revert InvalidTick();\\n }\\n\\n modifier validatePrice(uint256 price) {\\n if (price > MAX_PRICE || price < MIN_PRICE) revert InvalidPrice();\\n _;\\n }\\n\\n function fromPrice(uint256 price) internal pure validatePrice(price) returns (Tick) {\\n unchecked {\\n int24 tick = int24((int256(price).lnWad() * 42951820407860) / 2 ** 128);\\n if (toPrice(Tick.wrap(tick)) > price) return Tick.wrap(tick - 1);\\n return Tick.wrap(tick);\\n }\\n }\\n\\n function toPrice(Tick tick) internal pure returns (uint256 price) {\\n validateTick(tick);\\n int24 tickValue = Tick.unwrap(tick);\\n uint256 absTick = uint24(tickValue < 0 ? -tickValue : tickValue);\\n\\n unchecked {\\n if (absTick & 0x1 != 0) price = _R0;\\n else price = 1 << 96;\\n if (absTick & 0x2 != 0) price = (price * _R1) >> 96;\\n if (absTick & 0x4 != 0) price = (price * _R2) >> 96;\\n if (absTick & 0x8 != 0) price = (price * _R3) >> 96;\\n if (absTick & 0x10 != 0) price = (price * _R4) >> 96;\\n if (absTick & 0x20 != 0) price = (price * _R5) >> 96;\\n if (absTick & 0x40 != 0) price = (price * _R6) >> 96;\\n if (absTick & 0x80 != 0) price = (price * _R7) >> 96;\\n if (absTick & 0x100 != 0) price = (price * _R8) >> 96;\\n if (absTick & 0x200 != 0) price = (price * _R9) >> 96;\\n if (absTick & 0x400 != 0) price = (price * _R10) >> 96;\\n if (absTick & 0x800 != 0) price = (price * _R11) >> 96;\\n if (absTick & 0x1000 != 0) price = (price * _R12) >> 96;\\n if (absTick & 0x2000 != 0) price = (price * _R13) >> 96;\\n if (absTick & 0x4000 != 0) price = (price * _R14) >> 96;\\n if (absTick & 0x8000 != 0) price = (price * _R15) >> 96;\\n if (absTick & 0x10000 != 0) price = (price * _R16) >> 96;\\n if (absTick & 0x20000 != 0) price = (price * _R17) >> 96;\\n if (absTick & 0x40000 != 0) price = (price * _R18) >> 96;\\n }\\n if (tickValue > 0) price = 0x1000000000000000000000000000000000000000000000000 / price;\\n }\\n\\n function gt(Tick a, Tick b) internal pure returns (bool) {\\n return Tick.unwrap(a) > Tick.unwrap(b);\\n }\\n\\n function baseToQuote(Tick tick, uint256 base, bool roundingUp) internal pure returns (uint256) {\\n return Math.divide((base * tick.toPrice()), 1 << 96, roundingUp);\\n }\\n\\n function quoteToBase(Tick tick, uint256 quote, bool roundingUp) internal pure returns (uint256) {\\n // @dev quote = unit(uint64) * unitSize(uint64) < 2^96\\n // We don't need to check overflow here\\n return Math.divide(quote << 96, tick.toPrice(), roundingUp);\\n }\\n}\\n\",\"keccak256\":\"0xffbe19efd2b2e4e1eee3ed15c9363f5c45d70a6058b0b85ec9199e34de3b6b9b\",\"license\":\"GPL-2.0-or-later\"},\"src/libraries/TickBitmap.sol\":{\"content\":\"// SPDX-License-Identifier: -\\n// License: https://license.clober.io/LICENSE_V2.pdf\\n\\npragma solidity ^0.8.0;\\n\\nimport {SignificantBit} from \\\"./SignificantBit.sol\\\";\\nimport {Tick} from \\\"./Tick.sol\\\";\\n\\nlibrary TickBitmap {\\n using SignificantBit for uint256;\\n\\n error EmptyError();\\n error AlreadyExistsError();\\n\\n uint256 public constant B0_BITMAP_KEY = uint256(keccak256(\\\"TickBitmap\\\")) + 1;\\n uint256 public constant MAX_UINT_256_MINUS_1 = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe;\\n\\n function has(mapping(uint256 => uint256) storage self, Tick tick) internal view returns (bool) {\\n (uint256 b0b1, uint256 b2) = _split(tick);\\n uint256 mask = 1 << b2;\\n return self[b0b1] & mask == mask;\\n }\\n\\n function isEmpty(mapping(uint256 => uint256) storage self) internal view returns (bool) {\\n return self[B0_BITMAP_KEY] == 0;\\n }\\n\\n function _split(Tick tick) private pure returns (uint256 b0b1, uint256 b2) {\\n assembly {\\n let value := add(not(tick), 0x800000)\\n b0b1 := shr(8, and(value, 0xffff00))\\n b2 := and(value, 0xff)\\n }\\n }\\n\\n function highest(mapping(uint256 => uint256) storage self) internal view returns (Tick) {\\n if (isEmpty(self)) revert EmptyError();\\n\\n uint256 b0 = self[B0_BITMAP_KEY].leastSignificantBit();\\n uint256 b0b1 = (b0 << 8) | (self[~b0].leastSignificantBit());\\n uint256 b2 = self[b0b1].leastSignificantBit();\\n return _toTick((b0b1 << 8) | b2);\\n }\\n\\n function set(mapping(uint256 => uint256) storage self, Tick tick) internal {\\n (uint256 b0b1, uint256 b2) = _split(tick);\\n uint256 mask = 1 << b2;\\n uint256 b2Bitmap = self[b0b1];\\n if (b2Bitmap & mask > 0) revert AlreadyExistsError();\\n\\n self[b0b1] = b2Bitmap | mask;\\n if (b2Bitmap == 0) {\\n mask = 1 << (b0b1 & 0xff);\\n uint256 b1BitmapKey = ~(b0b1 >> 8);\\n uint256 b1Bitmap = self[b1BitmapKey];\\n self[b1BitmapKey] = b1Bitmap | mask;\\n\\n if (b1Bitmap == 0) self[B0_BITMAP_KEY] = self[B0_BITMAP_KEY] | (1 << ~b1BitmapKey);\\n }\\n }\\n\\n function clear(mapping(uint256 => uint256) storage self, Tick tick) internal {\\n (uint256 b0b1, uint256 b2) = _split(tick);\\n uint256 mask = 1 << b2;\\n uint256 b2Bitmap = self[b0b1];\\n\\n self[b0b1] = b2Bitmap & (~mask);\\n if (b2Bitmap == mask) {\\n mask = 1 << (b0b1 & 0xff);\\n uint256 b1BitmapKey = ~(b0b1 >> 8);\\n uint256 b1Bitmap = self[b1BitmapKey];\\n\\n self[b1BitmapKey] = b1Bitmap & (~mask);\\n if (mask == b1Bitmap) {\\n mask = 1 << (~b1BitmapKey);\\n self[B0_BITMAP_KEY] = self[B0_BITMAP_KEY] & (~mask);\\n }\\n }\\n }\\n\\n function maxLessThan(mapping(uint256 => uint256) storage self, Tick tick) internal view returns (Tick) {\\n (uint256 b0b1, uint256 b2) = _split(tick);\\n uint256 b2Bitmap = (MAX_UINT_256_MINUS_1 << b2) & self[b0b1];\\n if (b2Bitmap == 0) {\\n uint256 b0 = b0b1 >> 8;\\n uint256 b1Bitmap = (MAX_UINT_256_MINUS_1 << (b0b1 & 0xff)) & self[~b0];\\n if (b1Bitmap == 0) {\\n uint256 b0Bitmap = (MAX_UINT_256_MINUS_1 << b0) & self[B0_BITMAP_KEY];\\n if (b0Bitmap == 0) return Tick.wrap(type(int24).min);\\n b0 = b0Bitmap.leastSignificantBit();\\n b1Bitmap = self[~b0];\\n }\\n b0b1 = (b0 << 8) | b1Bitmap.leastSignificantBit();\\n b2Bitmap = self[b0b1];\\n }\\n b2 = b2Bitmap.leastSignificantBit();\\n return _toTick((b0b1 << 8) | b2);\\n }\\n\\n function _toTick(uint256 raw) private pure returns (Tick t) {\\n assembly {\\n t := and(not(sub(raw, 0x800000)), 0xffffff)\\n }\\n }\\n}\\n\",\"keccak256\":\"0xa7074d79b62ca6bd62c8d281c8c3cdb67a9dae04d42a0c8bdbf315cc6259ad83\",\"license\":\"-\"},\"src/libraries/TotalClaimableMap.sol\":{\"content\":\"// SPDX-License-Identifier: -\\n// License: https://license.clober.io/LICENSE_V2.pdf\\n\\npragma solidity ^0.8.20;\\n\\nimport {DirtyUint64} from \\\"./DirtyUint64.sol\\\";\\nimport {PackedUint256} from \\\"./PackedUint256.sol\\\";\\nimport {Tick} from \\\"./Tick.sol\\\";\\n\\nlibrary TotalClaimableMap {\\n using DirtyUint64 for uint64;\\n using PackedUint256 for uint256;\\n\\n // @dev n should be less than type(uint64).max due to the dirty storage logic.\\n function add(mapping(uint24 => uint256) storage self, Tick tick, uint64 n) internal {\\n (uint24 groupIndex, uint8 elementIndex) = _splitTick(tick);\\n uint256 group = self[groupIndex];\\n // @notice Be aware of dirty storage add logic\\n self[groupIndex] = group.update64Unsafe(\\n elementIndex, // elementIndex < 4\\n group.get64Unsafe(elementIndex).addClean(n)\\n );\\n }\\n\\n function sub(mapping(uint24 => uint256) storage self, Tick tick, uint64 n) internal {\\n (uint24 groupIndex, uint8 elementIndex) = _splitTick(tick);\\n self[groupIndex] = self[groupIndex].sub64Unsafe(elementIndex, n);\\n }\\n\\n function get(mapping(uint24 => uint256) storage self, Tick tick) internal view returns (uint64) {\\n (uint24 groupIndex, uint8 elementIndex) = _splitTick(tick);\\n return self[groupIndex].get64Unsafe(elementIndex).toClean();\\n }\\n\\n function _splitTick(Tick tick) internal pure returns (uint24 groupIndex, uint8 elementIndex) {\\n uint256 casted = uint24(Tick.unwrap(tick));\\n assembly {\\n groupIndex := shr(2, casted) // div 4\\n elementIndex := and(casted, 3) // mod 4\\n }\\n }\\n}\\n\",\"keccak256\":\"0xed7fe09b007218a0055d34c8e8f55b0682c7b5780f86817de046430f5b26b031\",\"license\":\"-\"}},\"version\":1}", + "bytecode": "0x6118ef610034600b8282823980515f1a607314602857634e487b7160e01b5f525f60045260245ffd5b305f52607381538281f3fe730000000000000000000000000000000000000000301460806040526004361061007a575f3560e01c8063ab8a7e3f11610058578063ab8a7e3f1461010e578063c49d26211461012f578063ffa0afb51461014e575f80fd5b8063329b4a011461007e5780633ac502c1146100af578063a151a7e1146100ef575b5f80fd5b61009161008c366004611567565b610183565b60405167ffffffffffffffff90911681526020015b60405180910390f35b8180156100ba575f80fd5b506100ce6100c93660046115c5565b61025e565b6040805167ffffffffffffffff9384168152929091166020830152016100a6565b8180156100fa575f80fd5b506100916101093660046115f0565b61040b565b818015610119575f80fd5b5061012d610128366004611622565b610463565b005b81801561013a575f80fd5b50610091610149366004611567565b6104bf565b818015610159575f80fd5b5061016d61016836600461166b565b610525565b60405164ffffffffff90911681526020016100a6565b5f80610190858585610776565b602090810151600286900b5f90815260038801909252604090912060048101549192509064ffffffffff85166180000110156101ce57509050610257565b5f6101dc60058801876107ca565b90505f6101f0838764ffffffffff1661081f565b90508167ffffffffffffffff1684820367ffffffffffffffff161061021b575f945050505050610257565b8167ffffffffffffffff168167ffffffffffffffff16116102425783945050505050610257565b8381038203945050505050610257565b505050505b9392505050565b602882901c62ffffff16600281900b5f908152600385016020526040812060048101805492938493909264ffffffffff8816929091859190849081106102a6576102a66116b9565b5f918252602082200154600160a01b900467ffffffffffffffff1691506102ce8a8686610183565b90506102da81896116e1565b95508567ffffffffffffffff168267ffffffffffffffff16101561033d576040517fc332559a00000000000000000000000000000000000000000000000000000000815267ffffffffffffffff8284031660048201526024015b60405180910390fd5b600285900b5f90815260038b0160205260409020868303975061038990617fff861690899061036c9083610872565b600289900b5f90815260038f0160205260409020929190036108be565b5085836004018564ffffffffff16815481106103a7576103a76116b9565b905f5260205f20015f0160146101000a81548167ffffffffffffffff021916908367ffffffffffffffff1602179055506103e18a86610b16565b67ffffffffffffffff165f036103fe576103fe60048b0186610b4b565b5050505050935093915050565b5f806104178585610b16565b90508267ffffffffffffffff168167ffffffffffffffff16111561043d5782915061044d565b90508061044d6004860185610b4b565b61045b600586018584610c49565b509392505050565b8154600160a01b900467ffffffffffffffff16156104ad576040517fc15ba32200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80826104b9828261171c565b50505050565b5f806104cc858585610cc7565b90506104d9858585610183565b815467ffffffffffffffff600160a01b8083048216849003909116027fffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffff90911617909155949350505050565b5f8267ffffffffffffffff165f03610569576040517ff21c16aa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b62800000841901600881901c61ffff165f908152600487016020526040902054600160ff9092169190911b908116146105a9576105a96004860185610d08565b600284900b5f908152600386016020526040902060048101546105cb90610e28565b915061800064ffffffffff8316106106dd575f618000830390505f826004018264ffffffffff1681548110610602576106026116b9565b5f91825260209091200154600160a01b900467ffffffffffffffff1690508015610683575f610632898985610183565b90508167ffffffffffffffff168167ffffffffffffffff1614610681576040517ff2f9ac9900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b505f905061069582617fff8516610872565b905067ffffffffffffffff8116156106db57623fffff600287901c165f9081526005880160205260409020805467ffffffffffffffff831660c060068a901b161b900390555b505b6106ec81617fff8416866108be565b50604080518082019091526001600160a01b03938416815267ffffffffffffffff9485166020808301918252600490930180546001810182555f91825293902091519190920180549251909516600160a01b027fffffffff000000000000000000000000000000000000000000000000000000009092169316929092179190911790915592915050565b604080518082019091525f8082526020820152610794848484610cc7565b6040805180820190915290546001600160a01b0381168252600160a01b900467ffffffffffffffff166020820152949350505050565b600281901c623fffff165f81815260208490526040812054909190600384169061081490600686901b60c0161c67ffffffffffffffff165b67ffffffffffffffff16801515900390565b925050505b92915050565b60048201545f90617fff90811690829061083a856001611885565b1690508082106108675761084f858284610e76565b61085886611319565b6108629190611898565b610814565b610814858383610e76565b5f61800082106108975760405163163da48960e01b81525f6004820152602401610334565b6102576108026003848116908690600287901c5f9081529101602052604090205490611358565b5f61800083106108e35760405163163da48960e01b81525f6004820152602401610334565b5f6108ed84611390565b90505f81600160040360ff1681518110610909576109096116b9565b60209081029190910181015190810151909150610949906108029088600385515f908152910160205260409020549060061b1c67ffffffffffffffff1690565b92508367ffffffffffffffff168367ffffffffffffffff1610610a20578383035f5b6004811015610a19575f848281518110610987576109876116b9565b602002602001015190505f895f0183600481106109a6576109a66116b9565b83515f90815291016020908152604090912054908301519091506109ea906109e2866109d28584611358565b67ffffffffffffffff1690611436565b839190611483565b8a84600481106109fc576109fc6116b9565b93515f90815293016020526040909220919091555060010161096b565b5050610b0d565b82840367ffffffffffffffff81810316610a3988611319565b67ffffffffffffffff161115610a655760405163163da48960e01b815260016004820152602401610334565b5f5b6004811015610252575f848281518110610a8357610a836116b9565b602002602001015190505f895f018360048110610aa257610aa26116b9565b83515f9081529101602090815260409091205490830151909150610ade906109e286610ace8584611358565b67ffffffffffffffff16906114ca565b8a8460048110610af057610af06116b9565b93515f908152930160205260409092209190915550600101610a67565b50509392505050565b5f610b2460058401836107ca565b600283900b5f9081526003850160205260409020610b4190611319565b6102579190611898565b62800000811901600881901c61ffff165f8181526020859052604090208054600160ff90941693841b80198216909255919291818103610c4157600884901c195f8181526020889052604090208054600160ff88161b80198216909255909350808403610c3e5781196001901b93508319885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610bed9190611885565b81526020019081526020015f205416885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610c2d9190611885565b815260208101919091526040015f20555b50505b505050505050565b623fffff600283901c165f818152602085905260409020546003841690610ca782610c888667ffffffffffffffff60c060068b901b1686901c16610ace565b67ffffffffffffffff90811660069290921b91821b911b831683030190565b62ffffff9093165f90815260209690965250506040909320929092555050565b600282900b5f9081526003840160205260408120600401805464ffffffffff8416908110610cf757610cf76116b9565b905f5260205f200190509392505050565b62800000811901600881901c61ffff165f81815260208590526040902054909160ff16906001821b9081811615610d6b576040517feb73dbfd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8481526020879052604081208284179055819003610c4157600884901c195f8181526020889052604081208054600160ff89161b81811790925590945090819003610c3e5781196001901b885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610de89190611885565b81526020019081526020015f205417885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610c2d9190611885565b5f64ffffffffff821115610e72576040517f6dfcc6500000000000000000000000000000000000000000000000000000000081526028600482015260248101839052604401610334565b5090565b5f818303610e8557505f610257565b818310610ea75760405163163da48960e01b81525f6004820152602401610334565b618000821115610ecc5760405163163da48960e01b81525f6004820152602401610334565b5f610ed684611390565b90505f610ee284611390565b90505f80808060035b5f878281518110610efe57610efe6116b9565b602002602001015190505f878381518110610f1b57610f1b6116b9565b60200260200101519050816020015185019450806020015184019350815f0151815f015103610f8557610f708d8460048110610f5957610f596116b9565b84515f908152910160205260409020548686611511565b67ffffffffffffffff1687019650505061130a565b815181516004919003101561106757610fc18d8460048110610fa957610fa96116b9565b84515f90815291016020526040902054866004611511565b67ffffffffffffffff169690960195610ffc8d8460048110610fe557610fe56116b9565b83515f908152910160205260408120549086611511565b825167ffffffffffffffff9190911697909701966001015b815181101561105f576110488e8560048110611032576110326116b9565b5f84815291016020526040812054906004611511565b67ffffffffffffffff169790970196600101611014565b50505061130a565b81516003165f036110b45761109e8d8460048110611087576110876116b9565b84515f908152910160205260408120549087611511565b67ffffffffffffffff16860195505f94506111b3565b8151600316600103611114576110f08d84600481106110d5576110d56116b9565b84515f19015f90815291016020526040812054906004611511565b67ffffffffffffffff16959095019461109e8d8460048110611087576110876116b9565b815160031660020361118b576111358d8460048110610fa957610fa96116b9565b67ffffffffffffffff1696909601956111748d8460048110611159576111596116b9565b84516001015f90815291016020526040812054906004611511565b67ffffffffffffffff1687019650600194506111b3565b6111a08d8460048110610fa957610fa96116b9565b67ffffffffffffffff1687019650600194505b80516003165f036111e9576111d38d8460048110610fe557610fe56116b9565b67ffffffffffffffff16870196505f9350611300565b8051600316600103611249576112258d846004811061120a5761120a6116b9565b83515f19015f90815291016020526040812054906004611511565b67ffffffffffffffff1696909601956111d38d8460048110610fe557610fe56116b9565b80516003166002036112d8576112828d846004811061126a5761126a6116b9565b83515f90815291016020526040902054856004611511565b67ffffffffffffffff1695909501946112c18d84600481106112a6576112a66116b9565b83516001015f90815291016020526040812054906004611511565b67ffffffffffffffff168601955060019350611300565b6112ed8d846004811061126a5761126a6116b9565b67ffffffffffffffff1686019550600193505b50505f1901610eeb565b50505090039695505050505050565b60015f9081526020829052604081205461133590826004611511565b5f8080526020849052604081205461134e916004611511565b61081991906116e1565b5f600382111561137e5760405163b8710e2160e01b815260036004820152602401610334565b5060061b1c67ffffffffffffffff1690565b60408051600480825260a082019092526060915f9190816020015b604080518082019091525f80825260208201528152602001906001900390816113ab579050509050600e5f5b600481101561142d5760405180604001604052808387901c815260200160036002850388901c16815250838281518110611413576114136116b9565b6020908102919091010152600319909101906001016113d7565b50909392505050565b81159091019080820367ffffffffffffffff8082169084161080611462575067ffffffffffffffff8116155b1561081957604051633e6c0de960e11b815260016004820152602401610334565b5f60038311156114a95760405163b8710e2160e01b815260036004820152602401610334565b5067ffffffffffffffff90811660069290921b91821b911b82169091030190565b5f81831584010192508167ffffffffffffffff168367ffffffffffffffff16101561150a57604051633e6c0de960e11b81525f6004820152602401610334565b5090919050565b600682901b9290921c915f825b8281101561154657604085901c9467ffffffffffffffff16801501919091019060010161151e565b509190039003919050565b8035600281900b8114611562575f80fd5b919050565b5f805f60608486031215611579575f80fd5b8335925061158960208501611551565b9150604084013564ffffffffff811681146115a2575f80fd5b809150509250925092565b67ffffffffffffffff811681146115c2575f80fd5b50565b5f805f606084860312156115d7575f80fd5b833592506020840135915060408401356115a2816115ad565b5f805f60608486031215611602575f80fd5b8335925061161260208501611551565b915060408401356115a2816115ad565b5f8082840360e0811215611634575f80fd5b8335925060c0601f1982011215611649575f80fd5b506020830190509250929050565b6001600160a01b03811681146115c2575f80fd5b5f805f806080858703121561167e575f80fd5b8435935061168e60208601611551565b9250604085013561169e816115ad565b915060608501356116ae81611657565b939692955090935050565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b67ffffffffffffffff818116838216019080821115611702576117026116cd565b5092915050565b5f813562ffffff81168114610819575f80fd5b813561172781611657565b815473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03821617825550602082013561175c816115ad565b81547fffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffff1660a09190911b7bffffffffffffffff0000000000000000000000000000000000000000161781556001810160408301356117b981611657565b815473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b038216178255506118376117ef60608501611709565b82547fffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffff1660a09190911b76ffffff000000000000000000000000000000000000000016178255565b5060028101608083013561184a81611657565b815473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b038216178255506118806117ef60a08501611709565b505050565b80820180821115610819576108196116cd565b67ffffffffffffffff828116828216039080821115611702576117026116cd56fea26469706673582212206630f72154ccf4fe3876481dd8a093b25ea74a99f594141695b908a632d6688064736f6c63430008190033", + "deployedBytecode": "0x730000000000000000000000000000000000000000301460806040526004361061007a575f3560e01c8063ab8a7e3f11610058578063ab8a7e3f1461010e578063c49d26211461012f578063ffa0afb51461014e575f80fd5b8063329b4a011461007e5780633ac502c1146100af578063a151a7e1146100ef575b5f80fd5b61009161008c366004611567565b610183565b60405167ffffffffffffffff90911681526020015b60405180910390f35b8180156100ba575f80fd5b506100ce6100c93660046115c5565b61025e565b6040805167ffffffffffffffff9384168152929091166020830152016100a6565b8180156100fa575f80fd5b506100916101093660046115f0565b61040b565b818015610119575f80fd5b5061012d610128366004611622565b610463565b005b81801561013a575f80fd5b50610091610149366004611567565b6104bf565b818015610159575f80fd5b5061016d61016836600461166b565b610525565b60405164ffffffffff90911681526020016100a6565b5f80610190858585610776565b602090810151600286900b5f90815260038801909252604090912060048101549192509064ffffffffff85166180000110156101ce57509050610257565b5f6101dc60058801876107ca565b90505f6101f0838764ffffffffff1661081f565b90508167ffffffffffffffff1684820367ffffffffffffffff161061021b575f945050505050610257565b8167ffffffffffffffff168167ffffffffffffffff16116102425783945050505050610257565b8381038203945050505050610257565b505050505b9392505050565b602882901c62ffffff16600281900b5f908152600385016020526040812060048101805492938493909264ffffffffff8816929091859190849081106102a6576102a66116b9565b5f918252602082200154600160a01b900467ffffffffffffffff1691506102ce8a8686610183565b90506102da81896116e1565b95508567ffffffffffffffff168267ffffffffffffffff16101561033d576040517fc332559a00000000000000000000000000000000000000000000000000000000815267ffffffffffffffff8284031660048201526024015b60405180910390fd5b600285900b5f90815260038b0160205260409020868303975061038990617fff861690899061036c9083610872565b600289900b5f90815260038f0160205260409020929190036108be565b5085836004018564ffffffffff16815481106103a7576103a76116b9565b905f5260205f20015f0160146101000a81548167ffffffffffffffff021916908367ffffffffffffffff1602179055506103e18a86610b16565b67ffffffffffffffff165f036103fe576103fe60048b0186610b4b565b5050505050935093915050565b5f806104178585610b16565b90508267ffffffffffffffff168167ffffffffffffffff16111561043d5782915061044d565b90508061044d6004860185610b4b565b61045b600586018584610c49565b509392505050565b8154600160a01b900467ffffffffffffffff16156104ad576040517fc15ba32200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80826104b9828261171c565b50505050565b5f806104cc858585610cc7565b90506104d9858585610183565b815467ffffffffffffffff600160a01b8083048216849003909116027fffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffff90911617909155949350505050565b5f8267ffffffffffffffff165f03610569576040517ff21c16aa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b62800000841901600881901c61ffff165f908152600487016020526040902054600160ff9092169190911b908116146105a9576105a96004860185610d08565b600284900b5f908152600386016020526040902060048101546105cb90610e28565b915061800064ffffffffff8316106106dd575f618000830390505f826004018264ffffffffff1681548110610602576106026116b9565b5f91825260209091200154600160a01b900467ffffffffffffffff1690508015610683575f610632898985610183565b90508167ffffffffffffffff168167ffffffffffffffff1614610681576040517ff2f9ac9900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505b505f905061069582617fff8516610872565b905067ffffffffffffffff8116156106db57623fffff600287901c165f9081526005880160205260409020805467ffffffffffffffff831660c060068a901b161b900390555b505b6106ec81617fff8416866108be565b50604080518082019091526001600160a01b03938416815267ffffffffffffffff9485166020808301918252600490930180546001810182555f91825293902091519190920180549251909516600160a01b027fffffffff000000000000000000000000000000000000000000000000000000009092169316929092179190911790915592915050565b604080518082019091525f8082526020820152610794848484610cc7565b6040805180820190915290546001600160a01b0381168252600160a01b900467ffffffffffffffff166020820152949350505050565b600281901c623fffff165f81815260208490526040812054909190600384169061081490600686901b60c0161c67ffffffffffffffff165b67ffffffffffffffff16801515900390565b925050505b92915050565b60048201545f90617fff90811690829061083a856001611885565b1690508082106108675761084f858284610e76565b61085886611319565b6108629190611898565b610814565b610814858383610e76565b5f61800082106108975760405163163da48960e01b81525f6004820152602401610334565b6102576108026003848116908690600287901c5f9081529101602052604090205490611358565b5f61800083106108e35760405163163da48960e01b81525f6004820152602401610334565b5f6108ed84611390565b90505f81600160040360ff1681518110610909576109096116b9565b60209081029190910181015190810151909150610949906108029088600385515f908152910160205260409020549060061b1c67ffffffffffffffff1690565b92508367ffffffffffffffff168367ffffffffffffffff1610610a20578383035f5b6004811015610a19575f848281518110610987576109876116b9565b602002602001015190505f895f0183600481106109a6576109a66116b9565b83515f90815291016020908152604090912054908301519091506109ea906109e2866109d28584611358565b67ffffffffffffffff1690611436565b839190611483565b8a84600481106109fc576109fc6116b9565b93515f90815293016020526040909220919091555060010161096b565b5050610b0d565b82840367ffffffffffffffff81810316610a3988611319565b67ffffffffffffffff161115610a655760405163163da48960e01b815260016004820152602401610334565b5f5b6004811015610252575f848281518110610a8357610a836116b9565b602002602001015190505f895f018360048110610aa257610aa26116b9565b83515f9081529101602090815260409091205490830151909150610ade906109e286610ace8584611358565b67ffffffffffffffff16906114ca565b8a8460048110610af057610af06116b9565b93515f908152930160205260409092209190915550600101610a67565b50509392505050565b5f610b2460058401836107ca565b600283900b5f9081526003850160205260409020610b4190611319565b6102579190611898565b62800000811901600881901c61ffff165f8181526020859052604090208054600160ff90941693841b80198216909255919291818103610c4157600884901c195f8181526020889052604090208054600160ff88161b80198216909255909350808403610c3e5781196001901b93508319885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610bed9190611885565b81526020019081526020015f205416885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610c2d9190611885565b815260208101919091526040015f20555b50505b505050505050565b623fffff600283901c165f818152602085905260409020546003841690610ca782610c888667ffffffffffffffff60c060068b901b1686901c16610ace565b67ffffffffffffffff90811660069290921b91821b911b831683030190565b62ffffff9093165f90815260209690965250506040909320929092555050565b600282900b5f9081526003840160205260408120600401805464ffffffffff8416908110610cf757610cf76116b9565b905f5260205f200190509392505050565b62800000811901600881901c61ffff165f81815260208590526040902054909160ff16906001821b9081811615610d6b576040517feb73dbfd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8481526020879052604081208284179055819003610c4157600884901c195f8181526020889052604081208054600160ff89161b81811790925590945090819003610c3e5781196001901b885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610de89190611885565b81526020019081526020015f205417885f7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b9545f1c6001610c2d9190611885565b5f64ffffffffff821115610e72576040517f6dfcc6500000000000000000000000000000000000000000000000000000000081526028600482015260248101839052604401610334565b5090565b5f818303610e8557505f610257565b818310610ea75760405163163da48960e01b81525f6004820152602401610334565b618000821115610ecc5760405163163da48960e01b81525f6004820152602401610334565b5f610ed684611390565b90505f610ee284611390565b90505f80808060035b5f878281518110610efe57610efe6116b9565b602002602001015190505f878381518110610f1b57610f1b6116b9565b60200260200101519050816020015185019450806020015184019350815f0151815f015103610f8557610f708d8460048110610f5957610f596116b9565b84515f908152910160205260409020548686611511565b67ffffffffffffffff1687019650505061130a565b815181516004919003101561106757610fc18d8460048110610fa957610fa96116b9565b84515f90815291016020526040902054866004611511565b67ffffffffffffffff169690960195610ffc8d8460048110610fe557610fe56116b9565b83515f908152910160205260408120549086611511565b825167ffffffffffffffff9190911697909701966001015b815181101561105f576110488e8560048110611032576110326116b9565b5f84815291016020526040812054906004611511565b67ffffffffffffffff169790970196600101611014565b50505061130a565b81516003165f036110b45761109e8d8460048110611087576110876116b9565b84515f908152910160205260408120549087611511565b67ffffffffffffffff16860195505f94506111b3565b8151600316600103611114576110f08d84600481106110d5576110d56116b9565b84515f19015f90815291016020526040812054906004611511565b67ffffffffffffffff16959095019461109e8d8460048110611087576110876116b9565b815160031660020361118b576111358d8460048110610fa957610fa96116b9565b67ffffffffffffffff1696909601956111748d8460048110611159576111596116b9565b84516001015f90815291016020526040812054906004611511565b67ffffffffffffffff1687019650600194506111b3565b6111a08d8460048110610fa957610fa96116b9565b67ffffffffffffffff1687019650600194505b80516003165f036111e9576111d38d8460048110610fe557610fe56116b9565b67ffffffffffffffff16870196505f9350611300565b8051600316600103611249576112258d846004811061120a5761120a6116b9565b83515f19015f90815291016020526040812054906004611511565b67ffffffffffffffff1696909601956111d38d8460048110610fe557610fe56116b9565b80516003166002036112d8576112828d846004811061126a5761126a6116b9565b83515f90815291016020526040902054856004611511565b67ffffffffffffffff1695909501946112c18d84600481106112a6576112a66116b9565b83516001015f90815291016020526040812054906004611511565b67ffffffffffffffff168601955060019350611300565b6112ed8d846004811061126a5761126a6116b9565b67ffffffffffffffff1686019550600193505b50505f1901610eeb565b50505090039695505050505050565b60015f9081526020829052604081205461133590826004611511565b5f8080526020849052604081205461134e916004611511565b61081991906116e1565b5f600382111561137e5760405163b8710e2160e01b815260036004820152602401610334565b5060061b1c67ffffffffffffffff1690565b60408051600480825260a082019092526060915f9190816020015b604080518082019091525f80825260208201528152602001906001900390816113ab579050509050600e5f5b600481101561142d5760405180604001604052808387901c815260200160036002850388901c16815250838281518110611413576114136116b9565b6020908102919091010152600319909101906001016113d7565b50909392505050565b81159091019080820367ffffffffffffffff8082169084161080611462575067ffffffffffffffff8116155b1561081957604051633e6c0de960e11b815260016004820152602401610334565b5f60038311156114a95760405163b8710e2160e01b815260036004820152602401610334565b5067ffffffffffffffff90811660069290921b91821b911b82169091030190565b5f81831584010192508167ffffffffffffffff168367ffffffffffffffff16101561150a57604051633e6c0de960e11b81525f6004820152602401610334565b5090919050565b600682901b9290921c915f825b8281101561154657604085901c9467ffffffffffffffff16801501919091019060010161151e565b509190039003919050565b8035600281900b8114611562575f80fd5b919050565b5f805f60608486031215611579575f80fd5b8335925061158960208501611551565b9150604084013564ffffffffff811681146115a2575f80fd5b809150509250925092565b67ffffffffffffffff811681146115c2575f80fd5b50565b5f805f606084860312156115d7575f80fd5b833592506020840135915060408401356115a2816115ad565b5f805f60608486031215611602575f80fd5b8335925061161260208501611551565b915060408401356115a2816115ad565b5f8082840360e0811215611634575f80fd5b8335925060c0601f1982011215611649575f80fd5b506020830190509250929050565b6001600160a01b03811681146115c2575f80fd5b5f805f806080858703121561167e575f80fd5b8435935061168e60208601611551565b9250604085013561169e816115ad565b915060608501356116ae81611657565b939692955090935050565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b67ffffffffffffffff818116838216019080821115611702576117026116cd565b5092915050565b5f813562ffffff81168114610819575f80fd5b813561172781611657565b815473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03821617825550602082013561175c816115ad565b81547fffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffff1660a09190911b7bffffffffffffffff0000000000000000000000000000000000000000161781556001810160408301356117b981611657565b815473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b038216178255506118376117ef60608501611709565b82547fffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffff1660a09190911b76ffffff000000000000000000000000000000000000000016178255565b5060028101608083013561184a81611657565b815473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b038216178255506118806117ef60a08501611709565b505050565b80820180821115610819576108196116cd565b67ffffffffffffffff828116828216039080821115611702576117026116cd56fea26469706673582212206630f72154ccf4fe3876481dd8a093b25ea74a99f594141695b908a632d6688064736f6c63430008190033", "devdoc": { "errors": { "SafeCastOverflowedUintDowncast(uint8,uint256)": [ diff --git a/deployments/421614/BookManager.json b/deployments/421614/BookManager.json index 806f5f0..d2fbbbd 100644 --- a/deployments/421614/BookManager.json +++ b/deployments/421614/BookManager.json @@ -1,5 +1,5 @@ { - "address": "0xC528b9ED5d56d1D0d3C18A2342954CE1069138a4", + "address": "0xAA9575d63dFC224b9583fC303dB3188C08d5C85A", "abi": [ { "inputs": [ @@ -1990,7 +1990,7 @@ "type": "receive" } ], - "transactionHash": "0x", + "transactionHash": "0x3985a4b3485b43478af6f287e1f500197567650c90fc2200c1800fca6b116548", "args": [ "0x5F79EE8f8fA862E98201120d83c4eC39D9468D49", "0x5F79EE8f8fA862E98201120d83c4eC39D9468D49", @@ -2000,5 +2000,5 @@ "CLOB-ORDER" ], "numDeployments": 1, - "bytecode": "0x610160604052348015610010575f80fd5b5060405161625738038061625783398101604081905261002f91610361565b6040805180820190915260018152601960f91b60208201528290829082818a82855f61005b83826104aa565b50600161006882826104aa565b5050506001600160a01b03811661009957604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b6100a281610185565b506100ae8260076101a1565b610120526100bd8160086101a1565b61014052815160208084019190912060e052815190820120610100524660a05261014960e05161010051604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201529081019290925260608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b60805250503060c0525061016091508690506101d3565b600a61016c85826104aa565b50600b61017984826104aa565b505050505050506105c1565b600680546001600160a01b031916905561019e8161021c565b50565b5f6020835110156101bc576101b58361026d565b90506101cd565b816101c784826104aa565b5060ff90505b92915050565b600c80546001600160a01b0319166001600160a01b0383169081179091556040517fef673bbfc2ac7e4d4b810bffda0b15a1f2b48c2aa4d178d3fca87d0d1f337062905f90a250565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b5f80829050601f81511115610297578260405163305a27a960e01b81526004016100909190610569565b80516102a28261059e565b179392505050565b80516001600160a01b03811681146102c0575f80fd5b919050565b634e487b7160e01b5f52604160045260245ffd5b5f82601f8301126102e8575f80fd5b81516001600160401b0380821115610302576103026102c5565b604051601f8301601f19908116603f0116810190828211818310171561032a5761032a6102c5565b81604052838152866020858801011115610342575f80fd5b8360208701602083015e5f602085830101528094505050505092915050565b5f805f805f8060c08789031215610376575f80fd5b61037f876102aa565b955061038d602088016102aa565b60408801519095506001600160401b03808211156103a9575f80fd5b6103b58a838b016102d9565b955060608901519150808211156103ca575f80fd5b6103d68a838b016102d9565b945060808901519150808211156103eb575f80fd5b6103f78a838b016102d9565b935060a089015191508082111561040c575f80fd5b5061041989828a016102d9565b9150509295509295509295565b600181811c9082168061043a57607f821691505b60208210810361045857634e487b7160e01b5f52602260045260245ffd5b50919050565b601f8211156104a557805f5260205f20601f840160051c810160208510156104835750805b601f840160051c820191505b818110156104a2575f815560010161048f565b50505b505050565b81516001600160401b038111156104c3576104c36102c5565b6104d7816104d18454610426565b8461045e565b602080601f83116001811461050a575f84156104f35750858301515b5f19600386901b1c1916600185901b178555610561565b5f85815260208120601f198616915b8281101561053857888601518255948401946001909101908401610519565b508582101561055557878501515f19600388901b60f8161c191681555b505060018460011b0185555b505050505050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b80516020808301519190811015610458575f1960209190910360031b1b16919050565b60805160a05160c05160e051610100516101205161014051615c456106125f395f6136d301525f6136a601525f61313b01525f61311301525f61306e01525f61309801525f6130c20152615c455ff3fe608060405260043610610353575f3560e01c80637ac2ff7b116101bd578063cdc92f2d116100f2578063e8a3d48511610092578063f2fde38b1161006d578063f2fde38b14610bd5578063f86a11b314610bf4578063fcc8fc9b14610c13578063fefc7c5114610c32575f80fd5b8063e8a3d48514610b5c578063e985e9c514610b70578063f035079914610bb7575f80fd5b8063d83747e8116100cd578063d83747e814610ae2578063d9caed1214610b01578063de4478ec14610b20578063e30c397814610b3f575f80fd5b8063cdc92f2d146109dd578063d09ef241146109fc578063d68f4dd114610a58575f80fd5b80639b22917d1161015d578063a179dadc11610138578063a179dadc1461094e578063a22cb46514610980578063b88d4fde1461099f578063c87b56dd146109be575f80fd5b80639b22917d146108335780639ca1799814610910578063a12ef25e1461092f575f80fd5b806393c85a211161019857806393c85a21146107b657806395d89b41146107e15780639611cf6c146107f55780639b19251a14610814575f80fd5b80637ac2ff7b1461075357806384b0196e146107725780638da5cb5b14610799575f80fd5b80633af32abf116102935780636352211e116102335780636c0360eb1161020e5780636c0360eb146106f857806370a082311461070c578063715018a61461072b57806379ba50971461073f575f80fd5b80636352211e146106a75780636a256b29146106c65780636b2cc75c146106d9575f80fd5b806341a8bb881161026e57806341a8bb88146105f857806342842e0e146106305780634c02bf0b1461064f57806355af6a3214610688575f80fd5b80633af32abf146105755780633b9500b0146105a35780633e547b06146105c2575f80fd5b80631dbef488116102fe5780632f584a6d116102d95780632f584a6d146104f057806330adf81f1461050f5780633644e5151461054257806338926b6d14610556575f80fd5b80631dbef488146104665780631ff63f931461049a57806323b872dd146104d1575f80fd5b8063095ea7b31161032e578063095ea7b3146103ea578063141a468c1461040b57806314d6a9eb14610447575f80fd5b806301ffc9a71461035e57806306fdde0314610392578063081812fc146103b3575f80fd5b3661035a57005b5f80fd5b348015610369575f80fd5b5061037d610378366004614ac4565b610c51565b60405190151581526020015b60405180910390f35b34801561039d575f80fd5b506103a6610c94565b6040516103899190614b0d565b3480156103be575f80fd5b506103d26103cd366004614b1f565b610d23565b6040516001600160a01b039091168152602001610389565b3480156103f5575f80fd5b50610409610404366004614b4a565b610d4a565b005b348015610416575f80fd5b50610439610425366004614b1f565b5f9081526009602052604090205460a01c90565b604051908152602001610389565b348015610452575f80fd5b50610439610461366004614bb9565b610d59565b348015610471575f80fd5b50610485610480366004614c0f565b610f9a565b60408051928352602083019190915201610389565b3480156104a5575f80fd5b506104b96104b4366004614c5e565b61138b565b6040516001600160c01b039091168152602001610389565b3480156104dc575f80fd5b506104096104eb366004614c78565b61139e565b3480156104fb575f80fd5b5061040961050a366004614c78565b611440565b34801561051a575f80fd5b506104397f49ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9ad81565b34801561054d575f80fd5b50610439611450565b348015610561575f80fd5b50610439610570366004614cb6565b61145e565b348015610580575f80fd5b5061037d61058f366004614ce5565b600f6020525f908152604090205460ff1681565b3480156105ae575f80fd5b506104856105bd366004614d00565b611821565b3480156105cd575f80fd5b506104396105dc366004614d23565b601060209081525f928352604080842090915290825290205481565b348015610603575f80fd5b50610617610612366004614d81565b611aea565b60405167ffffffffffffffff9091168152602001610389565b34801561063b575f80fd5b5061040961064a366004614c78565b611b12565b34801561065a575f80fd5b50604080515f80516020615af08339815191525c6001600160801b038116825260801c602082015201610389565b348015610693575f80fd5b5061037d6106a2366004614db2565b611b2c565b3480156106b2575f80fd5b506103d26106c1366004614b1f565b611b5c565b6104396106d4366004614ce5565b611b66565b3480156106e4575f80fd5b506104096106f3366004614ce5565b611bcc565b348015610703575f80fd5b506103a6611c1c565b348015610717575f80fd5b50610439610726366004614ce5565b611ca8565b348015610736575f80fd5b50610409611d06565b34801561074a575f80fd5b50610409611d19565b34801561075e575f80fd5b5061040961076d366004614dcb565b611d5d565b34801561077d575f80fd5b50610786611fbe565b6040516103899796959493929190614e28565b3480156107a4575f80fd5b506005546001600160a01b03166103d2565b3480156107c1575f80fd5b506104396107d0366004614ce5565b600d6020525f908152604090205481565b3480156107ec575f80fd5b506103a661201c565b348015610800575f80fd5b5061043961080f366004614d23565b61202b565b34801561081f575f80fd5b5061040961082e366004614ce5565b61203f565b34801561083e575f80fd5b5061090361084d366004614db2565b6040805160c0810182525f80825260208201819052918101829052606081018290526080810182905260a0810191909152506001600160c01b03165f908152600e6020908152604091829020825160c08101845281546001600160a01b03808216835267ffffffffffffffff600160a01b92839004169483019490945260018301548085169583019590955262ffffff94819004851660608301526002909201549283166080820152910490911660a082015290565b6040516103899190614edb565b34801561091b575f80fd5b506103a661092a366004614f42565b612092565b34801561093a575f80fd5b50610439610949366004614d23565b6121a6565b348015610959575f80fd5b5061096d610968366004614d81565b61225d565b60405160029190910b8152602001610389565b34801561098b575f80fd5b5061040961099a366004614f7a565b61227e565b3480156109aa575f80fd5b506104096109b9366004615016565b612289565b3480156109c9575f80fd5b506103a66109d8366004614b1f565b6122a0565b3480156109e8575f80fd5b5061096d6109f7366004614db2565b612304565b348015610a07575f80fd5b50610a1b610a16366004614b1f565b612324565b6040805182516001600160a01b0316815260208084015167ffffffffffffffff908116918301919091529282015190921690820152606001610389565b348015610a63575f80fd5b50610ac2610a72366004614b1f565b6002027f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b181015c917f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b29091015c90565b604080516001600160a01b03938416815292909116602083015201610389565b348015610aed575f80fd5b50600c546103d2906001600160a01b031681565b348015610b0c575f80fd5b50610409610b1b366004614c78565b612468565b348015610b2b575f80fd5b50610409610b3a366004614ce5565b6124ce565b348015610b4a575f80fd5b506006546001600160a01b03166103d2565b348015610b67575f80fd5b506103a66124df565b348015610b7b575f80fd5b5061037d610b8a366004614d23565b6001600160a01b039182165f90815260046020908152604080832093909416825291909152205460ff1690565b348015610bc2575f80fd5b50610439610bd1366004614b1f565b5490565b348015610be0575f80fd5b50610409610bef366004614ce5565b6124ec565b348015610bff575f80fd5b506103a6610c0e3660046150be565b61255d565b348015610c1e575f80fd5b5061037d610c2d366004614db2565b6125d9565b348015610c3d575f80fd5b50610409610c4c3660046150de565b6125f9565b5f6001600160e01b031982167f6831a4fd000000000000000000000000000000000000000000000000000000001480610c8e5750610c8e82612966565b92915050565b60605f8054610ca290615115565b80601f0160208091040260200160405190810160405280929190818152602001828054610cce90615115565b8015610d195780601f10610cf057610100808354040283529160200191610d19565b820191905f5260205f20905b815481529060010190602001808311610cfc57829003601f168201915b5050505050905090565b5f610d2d82612a00565b505f828152600360205260409020546001600160a01b0316610c8e565b610d55828233612a38565b5050565b5f610d6333612a45565b610d84610d7c85355f9081526009602052604090205490565b338635612b06565b8335604090811c5f908152600e602090815290829020825160c08101845281546001600160a01b03808216835267ffffffffffffffff600160a01b92839004169483019490945260018301548085169583019590955262ffffff9481900485166060830152600283015493841660808301819052930490931660a08401529190610e1090878787612b83565b5f8073D5fBc07bB8Dea016f1c6F206162Cd80eAF616322633ac502c1858a35610e3f60408d0160208e0161515c565b6040516001600160e01b031960e086901b1681526004810193909352602483019190915267ffffffffffffffff1660448201526064016040805180830381865af4158015610e8f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610eb39190615177565b91509150826020015167ffffffffffffffff168267ffffffffffffffff16029450610ee7836060015162ffffff1660171c90565b15610f0b5760608301515f90610f049062ffffff16876001612c03565b9590950194505b8067ffffffffffffffff165f03610f2657610f268835612c83565b610f34836040015186612cbb565b60405167ffffffffffffffff831681528835907f0c6ba7ef5064094c17cce013aa4c617a23e2582f867774d07a5931de43b85d729060200160405180910390a26080830151610f8f906001600160a01b031689848a8a612d02565b505050509392505050565b5f80610fa533612a45565b5f610fb861012087016101008801614ce5565b6001600160a01b031614158015610ffd5750600f5f610fdf61012088016101008901614ce5565b6001600160a01b0316815260208101919091526040015f205460ff16155b156110575761101461012086016101008701614ce5565b6040517f962715990000000000000000000000000000000000000000000000000000000081526001600160a01b0390911660048201526024015b60405180910390fd5b61107261106a60e0870160c088016151a4565b60020b612d8b565b5f61108a61108536889003880188615277565b612de7565b6001600160c01b0381165f908152600e602052604090209091506110ad81612e22565b6110e26110bf36899003890189615291565b87876110d160a08c0160808d01614ce5565b6001600160a01b0316929190612e6b565b5f73D5fBc07bB8Dea016f1c6F206162Cd80eAF61632263ffa0afb58361110e60e08c0160c08d016151a4565b61111f6101008d0160e08e0161515c565b6111316101208e016101008f01614ce5565b6040516001600160e01b031960e087901b168152600481019490945260029290920b602484015267ffffffffffffffff1660448301526001600160a01b03166064820152608401602060405180830381865af4158015611193573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111b79190615313565b90506111e9836111cd60e08b0160c08c016151a4565b60409190911b60289190911b67ffffff00000000001601820190565b94505f6111fc60408a0160208b0161515c565b67ffffffffffffffff166112176101008b0160e08c0161515c565b67ffffffffffffffff1602945084905061124561123a60808b0160608c01615337565b62ffffff1660171c90565b156112705761126b855f61125f60808d0160608e01615337565b62ffffff169190612c03565b019350835b61129161128360608b0160408c01614ce5565b61128c83615364565b612cbb565b61129b3387612ea9565b336001600160c01b0385167f251db4df45fa692f68b4e3f072919384c5b71995c71bf22888385168930fd22a6112d760e08d0160c08e016151a4565b858d60e00160208101906112eb919061515c565b8e6101000160208101906112ff9190614ce5565b6040805160029590950b855264ffffffffff93909316602085015267ffffffffffffffff91909116838301526001600160a01b03166060830152519081900360800190a361137f611355368b90038b018b615291565b878a8a8d5f01608001602081019061136d9190614ce5565b6001600160a01b031693929190612f23565b50505050935093915050565b5f610c8e61108536849003840184615277565b6001600160a01b0382166113c757604051633250574960e11b81525f600482015260240161104e565b5f6113d3838333612f63565b9050836001600160a01b0316816001600160a01b03161461143a576040517f64283d7b0000000000000000000000000000000000000000000000000000000081526001600160a01b038086166004830152602482018490528216604482015260640161104e565b50505050565b61144b838383612b06565b505050565b5f611459613062565b905090565b5f61146833612a45565b5f84815260096020526040902054611481903386612b06565b604084811c5f908152600e602090815290829020825160c08101845281546001600160a01b03808216835267ffffffffffffffff600160a01b92839004169483019490945260018301548085169583019590955262ffffff94819004851660608301526002830154938416608083018190529304841660a0820152602888901c9093169264ffffffffff88169261151a9089898961318b565b6040517fc49d262100000000000000000000000000000000000000000000000000000000815260048101839052600285900b602482015264ffffffffff841660448201525f9073D5fBc07bB8Dea016f1c6F206162Cd80eAF6163229063c49d262190606401602060405180830381865af415801561159a573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115be919061539a565b60208301519091505f90819067ffffffffffffffff8085169116026115e8600289900b82846131c8565b606086015160a0870151919a509061160562ffffff821660171c90565b156116225761161b62ffffff8216846001612c03565b9450611636565b61163362ffffff82168c6001612c03565b93505b6116458262ffffff1660171c90565b1561166c5761165b62ffffff8316846001612c03565b61166590866153b5565b94506116b8565b5f61167d62ffffff84168d83612c03565b905061168981866153b5565b94505f81136116aa5761169b81615364565b6116a5908d6153dc565b6116b4565b6116b4818d6153ef565b9b50505b505f91506116c990508689896131f2565b80519091506001600160a01b0381166116ea5750600c546001600160a01b03165b5f84131561173b576116fb84613246565b6001600160a01b038083165f9081526010602090815260408083208b820151909416835292905290812080549091906117359084906153dc565b90915550505b5f83131561178a5761174c83613246565b6001600160a01b038083165f9081526010602090815260408083208b51909416835292905290812080549091906117849084906153dc565b90915550505b816020015167ffffffffffffffff165f036117a8576117a88d612c83565b85516117b79061128c8c613288565b60405167ffffffffffffffff861681528d907ffc7df80a30ee916cc040221cf6fcfb3c6dc994b3fa4c4ab23e8a0f134de5c0c09060200160405180910390a26080860151611811906001600160a01b03168e878f8f6132e6565b5050505050505050509392505050565b5f8061182c33612a45565b61183f61106a60e0870160c088016151a4565b5f61185261108536889003880188615277565b6001600160c01b0381165f908152600e6020526040902090915061187581612e22565b6118aa61188736899003890189615402565b878761189960a08c0160808d01614ce5565b6001600160a01b0316929190613325565b5f73D5fBc07bB8Dea016f1c6F206162Cd80eAF61632263a151a7e1836118d660e08c0160c08d016151a4565b6118e76101008d0160e08e0161515c565b6040516001600160e01b031960e086901b168152600481019390935260029190910b602483015267ffffffffffffffff166044820152606401602060405180830381865af415801561193b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061195f919061539a565b90506119716040890160208a0161515c565b67ffffffffffffffff82811691160294506119a285600161199860e08c0160c08d016151a4565b60020b91906131c8565b9350845f6119af86613288565b90506119c461123a60c08c0160a08d01615337565b156119f2576119de875f61125f60c08e0160a08f01615337565b6119e89083615470565b9150819650611a17565b611a07865f61125f60c08e0160a08f01615337565b611a1190826153b5565b90508095505b611a30611a2a60608c0160408d01614ce5565b83612cbb565b611a4061128360208c018c614ce5565b336001600160c01b0386167fc4c20b9c4a5ada3b01b7a391a08dd81a1be01dd8ef63170dd9da44ecee3db11b611a7c60e08e0160c08f016151a4565b6040805160029290920b825267ffffffffffffffff881660208301520160405180910390a3611add611ab3368c90038c018c615402565b848b8b8e5f016080016020810190611acb9190614ce5565b6001600160a01b031693929190613363565b5050505050935093915050565b6001600160c01b0382165f908152600e60205260408120611b0b90836133a3565b9392505050565b61144b83838360405180602001604052805f815250612289565b6001600160c01b0381165f908152600e6020526040812054600160a01b900467ffffffffffffffff161515610c8e565b5f610c8e82612a00565b5f611b7033612a45565b6001600160a01b0382165f818152600d602052604090205490611b92906133d8565b6001600160a01b0384165f908152600d60205260409020819055611bb79082906153ef565b9150611bc68361128c84613288565b50919050565b611bd4613472565b6001600160a01b0381165f818152600f6020526040808220805460ff19169055517f88f58aa68e1f754fecfec41a6758d18d4a53fa15d4e206fd54bbdfe7a9e98da79190a250565b600a8054611c2990615115565b80601f0160208091040260200160405190810160405280929190818152602001828054611c5590615115565b8015611ca05780601f10611c7757610100808354040283529160200191611ca0565b820191905f5260205f20905b815481529060010190602001808311611c8357829003601f168201915b505050505081565b5f6001600160a01b038216611ceb576040517f89c62b640000000000000000000000000000000000000000000000000000000081525f600482015260240161104e565b506001600160a01b03165f9081526002602052604090205490565b611d0e613472565b611d175f61349f565b565b60065433906001600160a01b03168114611d515760405163118cdaa760e01b81526001600160a01b038216600482015260240161104e565b611d5a8161349f565b50565b83421115611d97576040517f1a15a3cc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f611e147f49ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9ad8888611dc7816134b8565b6040805160208101959095526001600160a01b03909316928401929092526060830152608082015260a0810187905260c001604051602081830303815290604052805190602001206134f1565b90505f611e2087611b5c565b9050806001600160a01b0316886001600160a01b031603611e5457604051638baa579f60e01b815260040160405180910390fd5b6001600160a01b0381163b15611f6a57604080516020810186905280820185905260f887901b7fff000000000000000000000000000000000000000000000000000000000000001660608201528151604181830301815260618201928390527f1626ba7e000000000000000000000000000000000000000000000000000000009092526001600160a01b03831691631626ba7e91611ef691869160650161548f565b602060405180830381865afa158015611f11573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f3591906154a7565b6001600160e01b031916631626ba7e60e01b14611f6557604051638baa579f60e01b815260040160405180910390fd5b611fa7565b806001600160a01b0316611f8083878787613538565b6001600160a01b031614611fa757604051638baa579f60e01b815260040160405180910390fd5b611fb48888836001613564565b5050505050505050565b5f6060805f805f6060611fcf61369f565b611fd76136cc565b604080515f808252602082019092527f0f000000000000000000000000000000000000000000000000000000000000009b939a50919850469750309650945092509050565b606060018054610ca290615115565b5f611b0b83836014525f526028600c205c90565b612047613472565b6001600160a01b0381165f818152600f6020526040808220805460ff19166001179055517feb73900b98b6a3e2b8b01708fe544760cf570d21e7fbe5225f24e48b5b2b432e9190a250565b606061209e84336136f9565b6040517f15c7afb40000000000000000000000000000000000000000000000000000000081526001600160a01b038516906315c7afb4906120e7903390879087906004016154ea565b5f604051808303815f875af1158015612102573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052612129919081019061550c565b9050612133613759565b5f80516020615af08339815191525c6001600160801b0381169060801c8115801561216657506001600160801b03811615155b1561219d576040517f5212cba100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50509392505050565b335f9081526010602090815260408083206001600160a01b03851684528252808320805490849055600d90925282208054919283926121e69084906153ef565b9091555061220090506001600160a01b03831684836137ce565b816001600160a01b0316836001600160a01b0316336001600160a01b03167f1c4f94f28cc9152354d4b98b8614b28c6c828a98d88228fa9577c7b9475e120c8460405161224f91815260200190565b60405180910390a492915050565b6001600160c01b0382165f908152600e60205260408120611b0b90836138ab565b610d553383836138b9565b61229484848461139e565b61143a84848484613970565b60606122ab82612a00565b505f6122b5613a8f565b90505f8151116122d35760405180602001604052805f815250611b0b565b806122dd84613a9e565b6040516020016122ee929190615598565b6040516020818303038152906040529392505050565b6001600160c01b0381165f908152600e60205260408120610c8e90613b3b565b604080516060810182525f808252602080830182905282840182905284841c808352600e909152928120919291602885901c62ffffff169164ffffffffff861691906123718285856131f2565b6040517f329b4a0100000000000000000000000000000000000000000000000000000000815260048101849052600286900b602482015264ffffffffff851660448201529091505f9073D5fBc07bB8Dea016f1c6F206162Cd80eAF6163229063329b4a0190606401602060405180830381865af41580156123f4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612418919061539a565b90506040518060600160405280835f01516001600160a01b031681526020018284602001510367ffffffffffffffff1681526020018267ffffffffffffffff168152509650505050505050919050565b61247133612a45565b801561144b5761248d8361248483613288565b61128c90615364565b6001600160a01b0383165f908152600d6020526040812080548392906124b49084906153ef565b9091555061144b90506001600160a01b03841683836137ce565b6124d6613472565b611d5a81613b48565b600b8054611c2990615115565b6124f4613472565b600680546001600160a01b0383166001600160a01b031990911681179091556125256005546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b606061256a8260206155ac565b67ffffffffffffffff81111561258257612582614faa565b6040519080825280601f01601f1916602001820160405280156125ac576020820181803683370190505b5090505f5b828110156125d25780840154602060018301028301526001810190506125b1565b5092915050565b6001600160c01b0381165f908152600e60205260408120610c8e90613b91565b61260233612a45565b612612604084016020850161515c565b67ffffffffffffffff165f03612654576040517faf6c36ab00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6126656080850160608601615337565b90505f61267860c0860160a08701615337565b90506126888262ffffff16613b9e565b801561269d575061269d8162ffffff16613b9e565b6126ba57604051637a34030f60e01b815260040160405180910390fd5b5f620f423f19627fffff848116908416010160020b12156126ee57604051637a34030f60e01b815260040160405180910390fd5b5f627fffff83166207a11f190160020b128061271757505f627fffff82166207a11f190160020b125b1561275c5761272b8162ffffff1660171c90565b151561273c8362ffffff1660171c90565b15151461275c57604051637a34030f60e01b815260040160405180910390fd5b5f61276d60a0870160808801614ce5565b9050612781816001600160a01b0316613bce565b6127c2576040517fe65af6a00000000000000000000000000000000000000000000000000000000081526001600160a01b038216600482015260240161104e565b6127e66127d436889003880188615277565b6001600160a01b038316908787613c05565b5f6127f961108536899003890189615277565b6001600160c01b0381165f908152600e60205260409081902090517fab8a7e3f00000000000000000000000000000000000000000000000000000000815291925073D5fBc07bB8Dea016f1c6F206162Cd80eAF6163229163ab8a7e3f91612864918b906004016155c3565b5f6040518083038186803b15801561287a575f80fd5b505af415801561288c573d5f803e3d5ffd5b506128a1925050506060880160408901614ce5565b6001600160a01b03166128b76020890189614ce5565b6001600160a01b03166001600160c01b0383167f803427d75ce3214f82dc7aa4910635170a6655e2c1663dc03429dd04100cba5a6128fb60408c0160208d0161515c565b6040805167ffffffffffffffff909216825262ffffff808b1660208401528916908201526001600160a01b038716606082015260800160405180910390a461295d61294b36899003890189615277565b6001600160a01b038416908888613c43565b50505050505050565b5f6001600160e01b031982167f80ac58cd0000000000000000000000000000000000000000000000000000000014806129c857506001600160e01b031982167f5b5e139f00000000000000000000000000000000000000000000000000000000145b80610c8e57507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b0319831614610c8e565b5f818152600960205260408120546001600160a01b038116610c8e57604051637e27328960e01b81526004810184905260240161104e565b61144b8383836001613564565b5f612a4e613c81565b90506001600160801b035f80516020615af08339815191525c167ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be422015c6001600160a01b0380831690841603612aa357505050565b806001600160a01b0316836001600160a01b031603612ac157505050565b6040517f74d863650000000000000000000000000000000000000000000000000000000081526001600160a01b0380841660048301528216602482015260440161104e565b612b11838383613cd6565b61144b576001600160a01b038316612b3f57604051637e27328960e01b81526004810182905260240161104e565b6040517f177e802f0000000000000000000000000000000000000000000000000000000081526001600160a01b03831660048201526024810182905260440161104e565b73020000000000000000000000000000000000000084161561143a5761143a63295b52c560e01b33858585604051602401612bc19493929190615693565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526001600160a01b03861690613d56565b5f6207a11f19627fffff851601600281900b82128281612c2557825f03612c27565b825b62ffffff1690505f612c60612c3c83896155ac565b620f424088612c52578581830615151691040190565b808206151586151691040190565b905082612c7557612c7081615364565b612c77565b805b98975050505050505050565b5f612c8f5f835f612f63565b90506001600160a01b038116610d5557604051637e27328960e01b81526004810183905260240161104e565b805f03612cc6575050565b5f612ccf613c81565b90505f612cdd828585613db3565b9050805f03612cf357612cee613dd1565b61143a565b82810361143a5761143a613e04565b730100000000000000000000000000000000000000851615612d8457612d84635125ce9c60e01b3386868686604051602401612d429594939291906156c2565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526001600160a01b03871690613d56565b5050505050565b6207ffff600282900b1380612db05750612da76207ffff61570c565b60020b8160020b125b15611d5a576040517fce8ef7fc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8082604051602001612dfa9190614edb565b60408051601f1981840301815291905280516020909101206001600160c01b03169392505050565b8054600160a01b900467ffffffffffffffff16611d5a576040517f1e3636e600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73200000000000000000000000000000000000000084161561143a5761143a633fda46bb60e01b33858585604051602401612bc194939291906157c7565b6001600160a01b038216612ed257604051633250574960e11b81525f600482015260240161104e565b5f612ede83835f612f63565b90506001600160a01b0381161561144b576040517f73c6ac6e0000000000000000000000000000000000000000000000000000000081525f600482015260240161104e565b731000000000000000000000000000000000000000851615612d8457612d8463eba8155960e01b3386868686604051602401612d429594939291906157f8565b5f828152600960205260408120546001600160a01b03831615612f8b57612f8b818486612b06565b6001600160a01b03811615612fc557612fa65f855f80613564565b6001600160a01b0381165f90815260026020526040902080545f190190555b6001600160a01b03851615612ff3576001600160a01b0385165f908152600260205260409020805460010190555b5f84815260096020526040902080546001600160a01b0319166001600160a01b03871617905583856001600160a01b0316826001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4949350505050565b5f306001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161480156130ba57507f000000000000000000000000000000000000000000000000000000000000000046145b156130e457507f000000000000000000000000000000000000000000000000000000000000000090565b611459604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f0000000000000000000000000000000000000000000000000000000000000000918101919091527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b728000000000000000000000000000000000000084161561143a5761143a63827e0eb260e01b33858585604051602401612bc19493929190615830565b5f6131ea606084901b6131dd8660020b613e37565b8082061515851691040190565b949350505050565b604080518082019091525f80825260208201526132108484846140ff565b6040805180820190915290546001600160a01b0381168252600160a01b900467ffffffffffffffff166020820152949350505050565b5f80821215613284576040517fa8ce44320000000000000000000000000000000000000000000000000000000081526004810183905260240161104e565b5090565b5f7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821115613284576040517f24775e060000000000000000000000000000000000000000000000000000000081526004810183905260240161104e565b7240000000000000000000000000000000000000851615612d8457612d846348042cf460e01b3386868686604051602401612d42959493929190615858565b73080000000000000000000000000000000000000084161561143a5761143a63fab3c75660e01b33858585604051602401612bc19493929190615917565b730400000000000000000000000000000000000000851615612d8457612d84639eb477b260e01b3386868686604051602401612d42959493929190615948565b5f6133b16005840183614140565b600283900b5f90815260038501602052604090206133ce90614182565b611b0b919061598a565b5f6001600160a01b0382166133ee575047919050565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa158015613449573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c8e91906159ab565b919050565b6005546001600160a01b03163314611d175760405163118cdaa760e01b815233600482015260240161104e565b600680546001600160a01b0319169055611d5a816141c1565b5f8181526009602052604090205460a081901c906134da81600160a01b6153dc565b5f9384526009602052604090932092909255919050565b5f610c8e6134fd613062565b836040517f19010000000000000000000000000000000000000000000000000000000000008152600281019290925260228201526042902090565b5f805f8061354888888888614212565b92509250925061355882826142da565b50909695505050505050565b808061357857506001600160a01b03821615155b15613670575f61358784612a00565b90506001600160a01b038316158015906135b35750826001600160a01b0316816001600160a01b031614155b80156135e457506001600160a01b038082165f9081526004602090815260408083209387168352929052205460ff16155b15613626576040517fa9fbf51f0000000000000000000000000000000000000000000000000000000081526001600160a01b038416600482015260240161104e565b811561366e5783856001600160a01b0316826001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45b505b50505f90815260036020526040902080546001600160a01b0319166001600160a01b0392909216919091179055565b60606114597f000000000000000000000000000000000000000000000000000000000000000060076143dd565b60606114597f000000000000000000000000000000000000000000000000000000000000000060086143dd565b5f80516020615af08339815191525c7f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b160026001600160801b038316020183815d82600182015d50600181015f80516020615af08339815191525d505050565b5f80516020615af08339815191525c6001600160801b038116806137845763f1c77ed05f526004601cfd5b7f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b15f19909101600202015f815d5f600182015d50600181035f80516020615af08339815191525d50565b5f6001600160a01b03841661381e575f805f8085875af1905080612cee576040517ff4b3b1bc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517fa9059cbb0000000000000000000000000000000000000000000000000000000081526001600160a01b038416600482015282602482015260205f6044835f895af13d15601f3d1160015f51141617169150508061143a576040517ff27f64e400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f611b0b6004840183614486565b6001600160a01b038216613904576040517f5b08ba180000000000000000000000000000000000000000000000000000000081526001600160a01b038316600482015260240161104e565b6001600160a01b038381165f81815260046020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6001600160a01b0383163b1561143a57604051630a85bd0160e11b81526001600160a01b0384169063150b7a02906139b29033908890879087906004016159c2565b6020604051808303815f875af19250505080156139ec575060408051601f3d908101601f191682019092526139e9918101906154a7565b60015b613a53573d808015613a19576040519150601f19603f3d011682016040523d82523d5f602084013e613a1e565b606091505b5080515f03613a4b57604051633250574960e11b81526001600160a01b038516600482015260240161104e565b805181602001fd5b6001600160e01b03198116630a85bd0160e11b14612d8457604051633250574960e11b81526001600160a01b038516600482015260240161104e565b6060600a8054610ca290615115565b60605f613aaa836145b4565b60010190505f8167ffffffffffffffff811115613ac957613ac9614faa565b6040519080825280601f01601f191660200182016040528015613af3576020820181803683370190505b5090508181016020015b5f19017f3031323334353637383961626364656600000000000000000000000000000000600a86061a8153600a8504945084613afd57509392505050565b5f610c8e82600401614695565b600c80546001600160a01b0319166001600160a01b0383169081179091556040517fef673bbfc2ac7e4d4b810bffda0b15a1f2b48c2aa4d178d3fca87d0d1f337062905f90a250565b5f610c8e82600401614780565b5f6207a11f19627fffff8316016207a120600282900b1380613bc657506207a11f198160020b125b159392505050565b5f6001600160a01b0382161580610c8e57505072400000000000000000000000000000000000006001600160a01b03909116101590565b73800000000000000000000000000000000000000084161561143a5761143a635df4d91860e01b33858585604051602401612bc194939291906159f3565b73400000000000000000000000000000000000000084161561143a5761143a6371ded94360e01b33858585604051602401612bc194939291906159f3565b5f5f80516020615af08339815191525c6001600160801b031680613ca5575f613cd0565b60025f198201027f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b1015c5b91505090565b5f6001600160a01b038316158015906131ea5750826001600160a01b0316846001600160a01b03161480613d2e57506001600160a01b038085165f9081526004602090815260408083209387168352929052205460ff165b806131ea5750505f908152600360205260409020546001600160a01b03908116911614919050565b5f80613d6284846147c5565b91509150816001600160e01b031916816001600160e01b0319161461143a576040517f1e048e1d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f82601452835f526028600c2082815c01915081815d509392505050565b7001000000000000000000000000000000005f80516020615af08339815191525c035f80516020615af08339815191525d565b7001000000000000000000000000000000005f80516020615af08339815191525c015f80516020615af08339815191525d565b5f613e4182612d8b565b815f600282900b8113613e545781613e5d565b613e5d8261570c565b62ffffff8116915060011615613e81576bfff97272373d413259a469909250613e92565b6c0100000000000000000000000092505b6002811615613eb15760606bfff2e50f5f656932ef12357c8402901c92505b6004811615613ed05760606bffe5caca7e10e4e61c3624ea8402901c92505b6008811615613eef5760606bffcb9843d60f6159c9db58838402901c92505b6010811615613f0e5760606bff973b41fa98c081472e68968402901c92505b6020811615613f2d5760606bff2ea16466c96a3843ec78b38402901c92505b6040811615613f4c5760606bfe5dee046a99a2a811c461f18402901c92505b6080811615613f6b5760606bfcbe86c7900a88aedcffc83b8402901c92505b610100811615613f8b5760606bf987a7253ac413176f2b074c8402901c92505b610200811615613fab5760606bf3392b0822b70005940c7a398402901c92505b610400811615613fcb5760606be7159475a2c29b7443b29c7f8402901c92505b610800811615613feb5760606bd097f3bdfd2022b8845ad8f78402901c92505b61100081161561400b5760606ba9f746462d870fdf8a65dc1f8402901c92505b61200081161561402b5760606b70d869a156d2a1b890bb3df68402901c92505b61400081161561404b5760606b31be135f97d08fd9812315058402901c92505b61800081161561406b5760606b09aa508b5b7a84e1c677de548402901c92505b6201000081161561408b5760606a5d6af8dedb81196699c3298402901c92505b620200008116156140aa576060692216e584f5fa1ea926048402901c92505b620400008116156140c757606067048a170391f7dc428402901c92505b5f8260020b13156140f8576140f5837801000000000000000000000000000000000000000000000000615a7c565b92505b5050919050565b600282900b5f9081526003840160205260408120600401805464ffffffffff841690811061412f5761412f615a9b565b905f5260205f200190509392505050565b600281901c623fffff165f818152602084905260408120549091906003841690600685901b60c0161c67ffffffffffffffff1680151590035b95945050505050565b60015f9081526020829052604081205461419e90826004614873565b5f808052602084905260408120546141b7916004614873565b610c8e9190615aaf565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b5f80807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084111561424b57505f915060039050826142d0565b604080515f808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa15801561429c573d5f803e3d5ffd5b5050604051601f1901519150506001600160a01b0381166142c757505f9250600191508290506142d0565b92505f91508190505b9450945094915050565b5f8260038111156142ed576142ed615ad0565b036142f6575050565b600182600381111561430a5761430a615ad0565b03614341576040517ff645eedf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600282600381111561435557614355615ad0565b0361438f576040517ffce698f70000000000000000000000000000000000000000000000000000000081526004810182905260240161104e565b60038260038111156143a3576143a3615ad0565b03610d55576040517fd78bce0c0000000000000000000000000000000000000000000000000000000081526004810182905260240161104e565b606060ff83146143f7576143f0836148b3565b9050610c8e565b81805461440390615115565b80601f016020809104026020016040519081016040528092919081815260200182805461442f90615115565b801561447a5780601f106144515761010080835404028352916020019161447a565b820191905f5260205f20905b81548152906001019060200180831161445d57829003601f168201915b50505050509050610c8e565b62800000811901600881901c61ffff165f81815260208590526040812054909260ff1690600119821b1680840361458857600883901c80195f9081526020889052604081205460011960ff87161b169081900361455e575f888161450b7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b95460016153dc565b81526020019081526020015f205483600119901b169050805f0361453b57627fffff199650505050505050610c8e565b614544816148f0565b60ff1680195f90815260208b905260409020549093509150505b614567816148f0565b60ff16600883901b179450875f8681526020019081526020015f2054925050505b614591816148f0565b60ff16915062ffffff627fffff19600885901b84170119165b9695505050505050565b5f807a184f03e93ff9f4daa797ed6e38ed64bf6a1f01000000000000000083106145fc577a184f03e93ff9f4daa797ed6e38ed64bf6a1f010000000000000000830492506040015b6d04ee2d6d415b85acef81000000008310614628576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc10000831061464657662386f26fc10000830492506010015b6305f5e100831061465e576305f5e100830492506008015b612710831061467257612710830492506004015b60648310614684576064830492506002015b600a8310610c8e5760010192915050565b5f61469f82614780565b156146d6576040517f4f3d7def00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f61471a83826147077f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b95460016153dc565b81526020019081526020015f20546148f0565b60ff1690505f61473a845f841981526020019081526020015f20546148f0565b60ff16600883901b1790505f61475f855f8481526020019081526020015f20546148f0565b60ff16905062ffffff627fffff19600884901b831701191695945050505050565b5f81816147ae7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b95460016153dc565b81526020019081526020015f20545f149050919050565b5f805f6147d185614966565b9050602084015192505f80866001600160a01b0316866040516147f49190615ae4565b5f604051808303815f865af19150503d805f811461482d576040519150601f19603f3d011682016040523d82523d5f602084013e614832565b606091505b50915091508161484557614845816149f5565b8080602001905181019061485991906154a7565b9350821561486957614869614a2f565b5050509250929050565b600682901b9290921c915f825b828110156148a857604085901c9467ffffffffffffffff168015019190910190600101614880565b509190039003919050565b60605f6148bf83614a6f565b6040805160208082528183019092529192505f91906020820181803683375050509182525060208101929092525090565b5f8082116148fc575f80fd5b5f7e818283848586878898a8b8c8d8e8f929395969799a9b9d9e9faaeb6bedeeff600184190184160260f81c90506040518061012001604052806101008152602001615b106101009139818151811061495757614957615a9b565b016020015160f81c9392505050565b5f6001600160a01b036001600160801b035f80516020615af08339815191525c167ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be422015c1661346d575f80516020615af08339815191525c6001600160801b0316827ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be42282015d50600192915050565b80515f03613a4b576040517f36bc48c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f80516020615af08339815191525c6001600160801b03165f7ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be42282015d50565b5f60ff8216601f811115610c8e576040517fb3512b0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160e01b031981168114611d5a575f80fd5b5f60208284031215614ad4575f80fd5b8135611b0b81614aaf565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f611b0b6020830184614adf565b5f60208284031215614b2f575f80fd5b5035919050565b6001600160a01b0381168114611d5a575f80fd5b5f8060408385031215614b5b575f80fd5b8235614b6681614b36565b946020939093013593505050565b5f8083601f840112614b84575f80fd5b50813567ffffffffffffffff811115614b9b575f80fd5b602083019150836020828501011115614bb2575f80fd5b9250929050565b5f805f8385036060811215614bcc575f80fd5b6040811215614bd9575f80fd5b50839250604084013567ffffffffffffffff811115614bf6575f80fd5b614c0286828701614b74565b9497909650939450505050565b5f805f838503610140811215614c23575f80fd5b61012080821215614c32575f80fd5b859450840135905067ffffffffffffffff811115614bf6575f80fd5b5f60c08284031215611bc6575f80fd5b5f60c08284031215614c6e575f80fd5b611b0b8383614c4e565b5f805f60608486031215614c8a575f80fd5b8335614c9581614b36565b92506020840135614ca581614b36565b929592945050506040919091013590565b5f805f60408486031215614cc8575f80fd5b83359250602084013567ffffffffffffffff811115614bf6575f80fd5b5f60208284031215614cf5575f80fd5b8135611b0b81614b36565b5f805f838503610120811215614d14575f80fd5b61010080821215614c32575f80fd5b5f8060408385031215614d34575f80fd5b8235614d3f81614b36565b91506020830135614d4f81614b36565b809150509250929050565b80356001600160c01b038116811461346d575f80fd5b8035600281900b811461346d575f80fd5b5f8060408385031215614d92575f80fd5b614d9b83614d5a565b9150614da960208401614d70565b90509250929050565b5f60208284031215614dc2575f80fd5b611b0b82614d5a565b5f805f805f8060c08789031215614de0575f80fd5b8635614deb81614b36565b95506020870135945060408701359350606087013560ff81168114614e0e575f80fd5b9598949750929560808101359460a0909101359350915050565b7fff00000000000000000000000000000000000000000000000000000000000000881681525f602060e06020840152614e6460e084018a614adf565b8381036040850152614e76818a614adf565b606085018990526001600160a01b038816608086015260a0850187905284810360c0860152855180825260208088019350909101905f5b81811015614ec957835183529284019291840191600101614ead565b50909c9b505050505050505050505050565b60c08101610c8e82846001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b5f805f60408486031215614f54575f80fd5b8335614f5f81614b36565b9250602084013567ffffffffffffffff811115614bf6575f80fd5b5f8060408385031215614f8b575f80fd5b8235614f9681614b36565b915060208301358015158114614d4f575f80fd5b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f1916810167ffffffffffffffff81118282101715614fe757614fe7614faa565b604052919050565b5f67ffffffffffffffff82111561500857615008614faa565b50601f01601f191660200190565b5f805f8060808587031215615029575f80fd5b843561503481614b36565b9350602085013561504481614b36565b925060408501359150606085013567ffffffffffffffff811115615066575f80fd5b8501601f81018713615076575f80fd5b803561508961508482614fef565b614fbe565b81815288602083850101111561509d575f80fd5b816020840160208301375f6020838301015280935050505092959194509250565b5f80604083850312156150cf575f80fd5b50508035926020909101359150565b5f805f60e084860312156150f0575f80fd5b6150fa8585614c4e565b925060c084013567ffffffffffffffff811115614bf6575f80fd5b600181811c9082168061512957607f821691505b602082108103611bc657634e487b7160e01b5f52602260045260245ffd5b67ffffffffffffffff81168114611d5a575f80fd5b5f6020828403121561516c575f80fd5b8135611b0b81615147565b5f8060408385031215615188575f80fd5b825161519381615147565b6020840151909250614d4f81615147565b5f602082840312156151b4575f80fd5b611b0b82614d70565b803562ffffff8116811461346d575f80fd5b5f60c082840312156151df575f80fd5b60405160c0810181811067ffffffffffffffff8211171561520257615202614faa565b604052905080823561521381614b36565b8152602083013561522381615147565b6020820152604083013561523681614b36565b6040820152615247606084016151bd565b6060820152608083013561525a81614b36565b608082015261526b60a084016151bd565b60a08201525092915050565b5f60c08284031215615287575f80fd5b611b0b83836151cf565b5f61012082840312156152a2575f80fd5b6040516080810181811067ffffffffffffffff821117156152c5576152c5614faa565b6040526152d284846151cf565b81526152e060c08401614d70565b602082015260e08301356152f381615147565b604082015261010083013561530781614b36565b60608201529392505050565b5f60208284031215615323575f80fd5b815164ffffffffff81168114611b0b575f80fd5b5f60208284031215615347575f80fd5b611b0b826151bd565b634e487b7160e01b5f52601160045260245ffd5b5f7f8000000000000000000000000000000000000000000000000000000000000000820361539457615394615350565b505f0390565b5f602082840312156153aa575f80fd5b8151611b0b81615147565b8082018281125f8312801582168215821617156153d4576153d4615350565b505092915050565b80820180821115610c8e57610c8e615350565b81810381811115610c8e57610c8e615350565b5f6101008284031215615413575f80fd5b6040516060810181811067ffffffffffffffff8211171561543657615436614faa565b60405261544384846151cf565b815261545160c08401614d70565b602082015260e083013561546481615147565b60408201529392505050565b8181035f8312801583831316838312821617156125d2576125d2615350565b828152604060208201525f6131ea6040830184614adf565b5f602082840312156154b7575f80fd5b8151611b0b81614aaf565b81835281816020850137505f828201602090810191909152601f909101601f19169091010190565b6001600160a01b0384168152604060208201525f6141796040830184866154c2565b5f6020828403121561551c575f80fd5b815167ffffffffffffffff811115615532575f80fd5b8201601f81018413615542575f80fd5b805161555061508482614fef565b818152856020838501011115615564575f80fd5b8160208401602083015e5f91810160200191909152949350505050565b5f81518060208401855e5f93019283525090919050565b5f6131ea6155a68386615581565b84615581565b8082028115828204841417610c8e57610c8e615350565b82815260e0810182356155d581614b36565b6001600160a01b038082166020850152602085013591506155f582615147565b67ffffffffffffffff821660408501526040850135915061561582614b36565b8082166060850152615629606086016151bd565b915062ffffff80831660808601526080860135925061564783614b36565b81831660a08601528061565c60a088016151bd565b1660c08601525050509392505050565b80358252602081013561567e81615147565b67ffffffffffffffff81166020840152505050565b6001600160a01b03851681526156ac602082018561566c565b608060608201525f6145aa6080830184866154c2565b6001600160a01b03861681526156db602082018661566c565b67ffffffffffffffff8416606082015260a060808201525f61570160a0830184866154c2565b979650505050505050565b5f8160020b627fffff19810361572457615724615350565b5f0392915050565b6157908282516001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b602081015160020b60c0830152604081015167ffffffffffffffff1660e0830152606001516001600160a01b031661010090910152565b5f6101606001600160a01b03871683526157e4602084018761572c565b8061014084015261570181840185876154c2565b5f6101806001600160a01b0388168352615815602084018861572c565b8561014084015280610160840152612c7781840185876154c2565b6001600160a01b0385168152836020820152606060408201525f6145aa6060830184866154c2565b6001600160a01b038616815284602082015267ffffffffffffffff84166040820152608060608201525f6157016080830184866154c2565b6158f48282516001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b602081015160020b60c08301526040015167ffffffffffffffff1660e090910152565b5f6101406001600160a01b03871683526159346020840187615890565b8061012084015261570181840185876154c2565b5f6101606001600160a01b03881683526159656020840188615890565b67ffffffffffffffff861661012084015280610140840152612c7781840185876154c2565b67ffffffffffffffff8281168282160390808211156125d2576125d2615350565b5f602082840312156159bb575f80fd5b5051919050565b5f6001600160a01b038087168352808616602084015250836040830152608060608301526145aa6080830184614adf565b5f6101006001600160a01b0387168352615a6960208401876001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b8060e084015261570181840185876154c2565b5f82615a9657634e487b7160e01b5f52601260045260245ffd5b500490565b634e487b7160e01b5f52603260045260245ffd5b67ffffffffffffffff8181168382160190808211156125d2576125d2615350565b634e487b7160e01b5f52602160045260245ffd5b5f611b0b828461558156fe760a9a962ae3d184e99c0483cf5684fb3170f47116ca4f445c50209da4f4f9070001020903110a19042112290b311a3905412245134d2a550c5d32651b6d3a7506264262237d468514804e8d2b95569d0d495ea533a966b11c886eb93bc176c9071727374353637324837e9b47af86c7155181ad4fd18ed32c9096db57d59ee30e2e4a6a5f92a6be3498aae067ddb2eb1d5989b56fd7baf33ca0c2ee77e5caf7ff0810182028303840444c545c646c7425617c847f8c949c48a4a8b087b8c0c816365272829aaec650acd0d28fdad4e22d6991bd97dfdcea58b4d6f29fede4f6fe0f1f2f3f4b5b6b607b8b93a3a7b7bf357199c5abcfd9e168bcdee9b3f1ecf5fd1e3e5a7a8aa2b670c4ced8bbe8f0f4fc3d79a1c3cde7effb78cce6facbf9f8a26469706673582212208c4dd75452b8efdcaf6f2e1d817153f9a5bf5e3db82b00b1eae0652771ff14ef64736f6c63430008190033" + "bytecode": "0x610160604052348015610010575f80fd5b5060405161625738038061625783398101604081905261002f91610361565b6040805180820190915260018152601960f91b60208201528290829082818a82855f61005b83826104aa565b50600161006882826104aa565b5050506001600160a01b03811661009957604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b6100a281610185565b506100ae8260076101a1565b610120526100bd8160086101a1565b61014052815160208084019190912060e052815190820120610100524660a05261014960e05161010051604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201529081019290925260608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b60805250503060c0525061016091508690506101d3565b600a61016c85826104aa565b50600b61017984826104aa565b505050505050506105c1565b600680546001600160a01b031916905561019e8161021c565b50565b5f6020835110156101bc576101b58361026d565b90506101cd565b816101c784826104aa565b5060ff90505b92915050565b600c80546001600160a01b0319166001600160a01b0383169081179091556040517fef673bbfc2ac7e4d4b810bffda0b15a1f2b48c2aa4d178d3fca87d0d1f337062905f90a250565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b5f80829050601f81511115610297578260405163305a27a960e01b81526004016100909190610569565b80516102a28261059e565b179392505050565b80516001600160a01b03811681146102c0575f80fd5b919050565b634e487b7160e01b5f52604160045260245ffd5b5f82601f8301126102e8575f80fd5b81516001600160401b0380821115610302576103026102c5565b604051601f8301601f19908116603f0116810190828211818310171561032a5761032a6102c5565b81604052838152866020858801011115610342575f80fd5b8360208701602083015e5f602085830101528094505050505092915050565b5f805f805f8060c08789031215610376575f80fd5b61037f876102aa565b955061038d602088016102aa565b60408801519095506001600160401b03808211156103a9575f80fd5b6103b58a838b016102d9565b955060608901519150808211156103ca575f80fd5b6103d68a838b016102d9565b945060808901519150808211156103eb575f80fd5b6103f78a838b016102d9565b935060a089015191508082111561040c575f80fd5b5061041989828a016102d9565b9150509295509295509295565b600181811c9082168061043a57607f821691505b60208210810361045857634e487b7160e01b5f52602260045260245ffd5b50919050565b601f8211156104a557805f5260205f20601f840160051c810160208510156104835750805b601f840160051c820191505b818110156104a2575f815560010161048f565b50505b505050565b81516001600160401b038111156104c3576104c36102c5565b6104d7816104d18454610426565b8461045e565b602080601f83116001811461050a575f84156104f35750858301515b5f19600386901b1c1916600185901b178555610561565b5f85815260208120601f198616915b8281101561053857888601518255948401946001909101908401610519565b508582101561055557878501515f19600388901b60f8161c191681555b505060018460011b0185555b505050505050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b80516020808301519190811015610458575f1960209190910360031b1b16919050565b60805160a05160c05160e051610100516101205161014051615c456106125f395f6136d301525f6136a601525f61313b01525f61311301525f61306e01525f61309801525f6130c20152615c455ff3fe608060405260043610610353575f3560e01c80637ac2ff7b116101bd578063cdc92f2d116100f2578063e8a3d48511610092578063f2fde38b1161006d578063f2fde38b14610bd5578063f86a11b314610bf4578063fcc8fc9b14610c13578063fefc7c5114610c32575f80fd5b8063e8a3d48514610b5c578063e985e9c514610b70578063f035079914610bb7575f80fd5b8063d83747e8116100cd578063d83747e814610ae2578063d9caed1214610b01578063de4478ec14610b20578063e30c397814610b3f575f80fd5b8063cdc92f2d146109dd578063d09ef241146109fc578063d68f4dd114610a58575f80fd5b80639b22917d1161015d578063a179dadc11610138578063a179dadc1461094e578063a22cb46514610980578063b88d4fde1461099f578063c87b56dd146109be575f80fd5b80639b22917d146108335780639ca1799814610910578063a12ef25e1461092f575f80fd5b806393c85a211161019857806393c85a21146107b657806395d89b41146107e15780639611cf6c146107f55780639b19251a14610814575f80fd5b80637ac2ff7b1461075357806384b0196e146107725780638da5cb5b14610799575f80fd5b80633af32abf116102935780636352211e116102335780636c0360eb1161020e5780636c0360eb146106f857806370a082311461070c578063715018a61461072b57806379ba50971461073f575f80fd5b80636352211e146106a75780636a256b29146106c65780636b2cc75c146106d9575f80fd5b806341a8bb881161026e57806341a8bb88146105f857806342842e0e146106305780634c02bf0b1461064f57806355af6a3214610688575f80fd5b80633af32abf146105755780633b9500b0146105a35780633e547b06146105c2575f80fd5b80631dbef488116102fe5780632f584a6d116102d95780632f584a6d146104f057806330adf81f1461050f5780633644e5151461054257806338926b6d14610556575f80fd5b80631dbef488146104665780631ff63f931461049a57806323b872dd146104d1575f80fd5b8063095ea7b31161032e578063095ea7b3146103ea578063141a468c1461040b57806314d6a9eb14610447575f80fd5b806301ffc9a71461035e57806306fdde0314610392578063081812fc146103b3575f80fd5b3661035a57005b5f80fd5b348015610369575f80fd5b5061037d610378366004614ac4565b610c51565b60405190151581526020015b60405180910390f35b34801561039d575f80fd5b506103a6610c94565b6040516103899190614b0d565b3480156103be575f80fd5b506103d26103cd366004614b1f565b610d23565b6040516001600160a01b039091168152602001610389565b3480156103f5575f80fd5b50610409610404366004614b4a565b610d4a565b005b348015610416575f80fd5b50610439610425366004614b1f565b5f9081526009602052604090205460a01c90565b604051908152602001610389565b348015610452575f80fd5b50610439610461366004614bb9565b610d59565b348015610471575f80fd5b50610485610480366004614c0f565b610f9a565b60408051928352602083019190915201610389565b3480156104a5575f80fd5b506104b96104b4366004614c5e565b61138b565b6040516001600160c01b039091168152602001610389565b3480156104dc575f80fd5b506104096104eb366004614c78565b61139e565b3480156104fb575f80fd5b5061040961050a366004614c78565b611440565b34801561051a575f80fd5b506104397f49ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9ad81565b34801561054d575f80fd5b50610439611450565b348015610561575f80fd5b50610439610570366004614cb6565b61145e565b348015610580575f80fd5b5061037d61058f366004614ce5565b600f6020525f908152604090205460ff1681565b3480156105ae575f80fd5b506104856105bd366004614d00565b611821565b3480156105cd575f80fd5b506104396105dc366004614d23565b601060209081525f928352604080842090915290825290205481565b348015610603575f80fd5b50610617610612366004614d81565b611aea565b60405167ffffffffffffffff9091168152602001610389565b34801561063b575f80fd5b5061040961064a366004614c78565b611b12565b34801561065a575f80fd5b50604080515f80516020615af08339815191525c6001600160801b038116825260801c602082015201610389565b348015610693575f80fd5b5061037d6106a2366004614db2565b611b2c565b3480156106b2575f80fd5b506103d26106c1366004614b1f565b611b5c565b6104396106d4366004614ce5565b611b66565b3480156106e4575f80fd5b506104096106f3366004614ce5565b611bcc565b348015610703575f80fd5b506103a6611c1c565b348015610717575f80fd5b50610439610726366004614ce5565b611ca8565b348015610736575f80fd5b50610409611d06565b34801561074a575f80fd5b50610409611d19565b34801561075e575f80fd5b5061040961076d366004614dcb565b611d5d565b34801561077d575f80fd5b50610786611fbe565b6040516103899796959493929190614e28565b3480156107a4575f80fd5b506005546001600160a01b03166103d2565b3480156107c1575f80fd5b506104396107d0366004614ce5565b600d6020525f908152604090205481565b3480156107ec575f80fd5b506103a661201c565b348015610800575f80fd5b5061043961080f366004614d23565b61202b565b34801561081f575f80fd5b5061040961082e366004614ce5565b61203f565b34801561083e575f80fd5b5061090361084d366004614db2565b6040805160c0810182525f80825260208201819052918101829052606081018290526080810182905260a0810191909152506001600160c01b03165f908152600e6020908152604091829020825160c08101845281546001600160a01b03808216835267ffffffffffffffff600160a01b92839004169483019490945260018301548085169583019590955262ffffff94819004851660608301526002909201549283166080820152910490911660a082015290565b6040516103899190614edb565b34801561091b575f80fd5b506103a661092a366004614f42565b612092565b34801561093a575f80fd5b50610439610949366004614d23565b6121a6565b348015610959575f80fd5b5061096d610968366004614d81565b61225d565b60405160029190910b8152602001610389565b34801561098b575f80fd5b5061040961099a366004614f7a565b61227e565b3480156109aa575f80fd5b506104096109b9366004615016565b612289565b3480156109c9575f80fd5b506103a66109d8366004614b1f565b6122a0565b3480156109e8575f80fd5b5061096d6109f7366004614db2565b612304565b348015610a07575f80fd5b50610a1b610a16366004614b1f565b612324565b6040805182516001600160a01b0316815260208084015167ffffffffffffffff908116918301919091529282015190921690820152606001610389565b348015610a63575f80fd5b50610ac2610a72366004614b1f565b6002027f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b181015c917f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b29091015c90565b604080516001600160a01b03938416815292909116602083015201610389565b348015610aed575f80fd5b50600c546103d2906001600160a01b031681565b348015610b0c575f80fd5b50610409610b1b366004614c78565b612468565b348015610b2b575f80fd5b50610409610b3a366004614ce5565b6124ce565b348015610b4a575f80fd5b506006546001600160a01b03166103d2565b348015610b67575f80fd5b506103a66124df565b348015610b7b575f80fd5b5061037d610b8a366004614d23565b6001600160a01b039182165f90815260046020908152604080832093909416825291909152205460ff1690565b348015610bc2575f80fd5b50610439610bd1366004614b1f565b5490565b348015610be0575f80fd5b50610409610bef366004614ce5565b6124ec565b348015610bff575f80fd5b506103a6610c0e3660046150be565b61255d565b348015610c1e575f80fd5b5061037d610c2d366004614db2565b6125d9565b348015610c3d575f80fd5b50610409610c4c3660046150de565b6125f9565b5f6001600160e01b031982167f6831a4fd000000000000000000000000000000000000000000000000000000001480610c8e5750610c8e82612966565b92915050565b60605f8054610ca290615115565b80601f0160208091040260200160405190810160405280929190818152602001828054610cce90615115565b8015610d195780601f10610cf057610100808354040283529160200191610d19565b820191905f5260205f20905b815481529060010190602001808311610cfc57829003601f168201915b5050505050905090565b5f610d2d82612a00565b505f828152600360205260409020546001600160a01b0316610c8e565b610d55828233612a38565b5050565b5f610d6333612a45565b610d84610d7c85355f9081526009602052604090205490565b338635612b06565b8335604090811c5f908152600e602090815290829020825160c08101845281546001600160a01b03808216835267ffffffffffffffff600160a01b92839004169483019490945260018301548085169583019590955262ffffff9481900485166060830152600283015493841660808301819052930490931660a08401529190610e1090878787612b83565b5f8073c87c5c0561a500960aE4f0f171265b8c55aCF153633ac502c1858a35610e3f60408d0160208e0161515c565b6040516001600160e01b031960e086901b1681526004810193909352602483019190915267ffffffffffffffff1660448201526064016040805180830381865af4158015610e8f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610eb39190615177565b91509150826020015167ffffffffffffffff168267ffffffffffffffff16029450610ee7836060015162ffffff1660171c90565b15610f0b5760608301515f90610f049062ffffff16876001612c03565b9590950194505b8067ffffffffffffffff165f03610f2657610f268835612c83565b610f34836040015186612cbb565b60405167ffffffffffffffff831681528835907f0c6ba7ef5064094c17cce013aa4c617a23e2582f867774d07a5931de43b85d729060200160405180910390a26080830151610f8f906001600160a01b031689848a8a612d02565b505050509392505050565b5f80610fa533612a45565b5f610fb861012087016101008801614ce5565b6001600160a01b031614158015610ffd5750600f5f610fdf61012088016101008901614ce5565b6001600160a01b0316815260208101919091526040015f205460ff16155b156110575761101461012086016101008701614ce5565b6040517f962715990000000000000000000000000000000000000000000000000000000081526001600160a01b0390911660048201526024015b60405180910390fd5b61107261106a60e0870160c088016151a4565b60020b612d8b565b5f61108a61108536889003880188615277565b612de7565b6001600160c01b0381165f908152600e602052604090209091506110ad81612e22565b6110e26110bf36899003890189615291565b87876110d160a08c0160808d01614ce5565b6001600160a01b0316929190612e6b565b5f73c87c5c0561a500960aE4f0f171265b8c55aCF15363ffa0afb58361110e60e08c0160c08d016151a4565b61111f6101008d0160e08e0161515c565b6111316101208e016101008f01614ce5565b6040516001600160e01b031960e087901b168152600481019490945260029290920b602484015267ffffffffffffffff1660448301526001600160a01b03166064820152608401602060405180830381865af4158015611193573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111b79190615313565b90506111e9836111cd60e08b0160c08c016151a4565b60409190911b60289190911b67ffffff00000000001601820190565b94505f6111fc60408a0160208b0161515c565b67ffffffffffffffff166112176101008b0160e08c0161515c565b67ffffffffffffffff1602945084905061124561123a60808b0160608c01615337565b62ffffff1660171c90565b156112705761126b855f61125f60808d0160608e01615337565b62ffffff169190612c03565b019350835b61129161128360608b0160408c01614ce5565b61128c83615364565b612cbb565b61129b3387612ea9565b336001600160c01b0385167f251db4df45fa692f68b4e3f072919384c5b71995c71bf22888385168930fd22a6112d760e08d0160c08e016151a4565b858d60e00160208101906112eb919061515c565b8e6101000160208101906112ff9190614ce5565b6040805160029590950b855264ffffffffff93909316602085015267ffffffffffffffff91909116838301526001600160a01b03166060830152519081900360800190a361137f611355368b90038b018b615291565b878a8a8d5f01608001602081019061136d9190614ce5565b6001600160a01b031693929190612f23565b50505050935093915050565b5f610c8e61108536849003840184615277565b6001600160a01b0382166113c757604051633250574960e11b81525f600482015260240161104e565b5f6113d3838333612f63565b9050836001600160a01b0316816001600160a01b03161461143a576040517f64283d7b0000000000000000000000000000000000000000000000000000000081526001600160a01b038086166004830152602482018490528216604482015260640161104e565b50505050565b61144b838383612b06565b505050565b5f611459613062565b905090565b5f61146833612a45565b5f84815260096020526040902054611481903386612b06565b604084811c5f908152600e602090815290829020825160c08101845281546001600160a01b03808216835267ffffffffffffffff600160a01b92839004169483019490945260018301548085169583019590955262ffffff94819004851660608301526002830154938416608083018190529304841660a0820152602888901c9093169264ffffffffff88169261151a9089898961318b565b6040517fc49d262100000000000000000000000000000000000000000000000000000000815260048101839052600285900b602482015264ffffffffff841660448201525f9073c87c5c0561a500960aE4f0f171265b8c55aCF1539063c49d262190606401602060405180830381865af415801561159a573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115be919061539a565b60208301519091505f90819067ffffffffffffffff8085169116026115e8600289900b82846131c8565b606086015160a0870151919a509061160562ffffff821660171c90565b156116225761161b62ffffff8216846001612c03565b9450611636565b61163362ffffff82168c6001612c03565b93505b6116458262ffffff1660171c90565b1561166c5761165b62ffffff8316846001612c03565b61166590866153b5565b94506116b8565b5f61167d62ffffff84168d83612c03565b905061168981866153b5565b94505f81136116aa5761169b81615364565b6116a5908d6153dc565b6116b4565b6116b4818d6153ef565b9b50505b505f91506116c990508689896131f2565b80519091506001600160a01b0381166116ea5750600c546001600160a01b03165b5f84131561173b576116fb84613246565b6001600160a01b038083165f9081526010602090815260408083208b820151909416835292905290812080549091906117359084906153dc565b90915550505b5f83131561178a5761174c83613246565b6001600160a01b038083165f9081526010602090815260408083208b51909416835292905290812080549091906117849084906153dc565b90915550505b816020015167ffffffffffffffff165f036117a8576117a88d612c83565b85516117b79061128c8c613288565b60405167ffffffffffffffff861681528d907ffc7df80a30ee916cc040221cf6fcfb3c6dc994b3fa4c4ab23e8a0f134de5c0c09060200160405180910390a26080860151611811906001600160a01b03168e878f8f6132e6565b5050505050505050509392505050565b5f8061182c33612a45565b61183f61106a60e0870160c088016151a4565b5f61185261108536889003880188615277565b6001600160c01b0381165f908152600e6020526040902090915061187581612e22565b6118aa61188736899003890189615402565b878761189960a08c0160808d01614ce5565b6001600160a01b0316929190613325565b5f73c87c5c0561a500960aE4f0f171265b8c55aCF15363a151a7e1836118d660e08c0160c08d016151a4565b6118e76101008d0160e08e0161515c565b6040516001600160e01b031960e086901b168152600481019390935260029190910b602483015267ffffffffffffffff166044820152606401602060405180830381865af415801561193b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061195f919061539a565b90506119716040890160208a0161515c565b67ffffffffffffffff82811691160294506119a285600161199860e08c0160c08d016151a4565b60020b91906131c8565b9350845f6119af86613288565b90506119c461123a60c08c0160a08d01615337565b156119f2576119de875f61125f60c08e0160a08f01615337565b6119e89083615470565b9150819650611a17565b611a07865f61125f60c08e0160a08f01615337565b611a1190826153b5565b90508095505b611a30611a2a60608c0160408d01614ce5565b83612cbb565b611a4061128360208c018c614ce5565b336001600160c01b0386167fc4c20b9c4a5ada3b01b7a391a08dd81a1be01dd8ef63170dd9da44ecee3db11b611a7c60e08e0160c08f016151a4565b6040805160029290920b825267ffffffffffffffff881660208301520160405180910390a3611add611ab3368c90038c018c615402565b848b8b8e5f016080016020810190611acb9190614ce5565b6001600160a01b031693929190613363565b5050505050935093915050565b6001600160c01b0382165f908152600e60205260408120611b0b90836133a3565b9392505050565b61144b83838360405180602001604052805f815250612289565b6001600160c01b0381165f908152600e6020526040812054600160a01b900467ffffffffffffffff161515610c8e565b5f610c8e82612a00565b5f611b7033612a45565b6001600160a01b0382165f818152600d602052604090205490611b92906133d8565b6001600160a01b0384165f908152600d60205260409020819055611bb79082906153ef565b9150611bc68361128c84613288565b50919050565b611bd4613472565b6001600160a01b0381165f818152600f6020526040808220805460ff19169055517f88f58aa68e1f754fecfec41a6758d18d4a53fa15d4e206fd54bbdfe7a9e98da79190a250565b600a8054611c2990615115565b80601f0160208091040260200160405190810160405280929190818152602001828054611c5590615115565b8015611ca05780601f10611c7757610100808354040283529160200191611ca0565b820191905f5260205f20905b815481529060010190602001808311611c8357829003601f168201915b505050505081565b5f6001600160a01b038216611ceb576040517f89c62b640000000000000000000000000000000000000000000000000000000081525f600482015260240161104e565b506001600160a01b03165f9081526002602052604090205490565b611d0e613472565b611d175f61349f565b565b60065433906001600160a01b03168114611d515760405163118cdaa760e01b81526001600160a01b038216600482015260240161104e565b611d5a8161349f565b50565b83421115611d97576040517f1a15a3cc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f611e147f49ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9ad8888611dc7816134b8565b6040805160208101959095526001600160a01b03909316928401929092526060830152608082015260a0810187905260c001604051602081830303815290604052805190602001206134f1565b90505f611e2087611b5c565b9050806001600160a01b0316886001600160a01b031603611e5457604051638baa579f60e01b815260040160405180910390fd5b6001600160a01b0381163b15611f6a57604080516020810186905280820185905260f887901b7fff000000000000000000000000000000000000000000000000000000000000001660608201528151604181830301815260618201928390527f1626ba7e000000000000000000000000000000000000000000000000000000009092526001600160a01b03831691631626ba7e91611ef691869160650161548f565b602060405180830381865afa158015611f11573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f3591906154a7565b6001600160e01b031916631626ba7e60e01b14611f6557604051638baa579f60e01b815260040160405180910390fd5b611fa7565b806001600160a01b0316611f8083878787613538565b6001600160a01b031614611fa757604051638baa579f60e01b815260040160405180910390fd5b611fb48888836001613564565b5050505050505050565b5f6060805f805f6060611fcf61369f565b611fd76136cc565b604080515f808252602082019092527f0f000000000000000000000000000000000000000000000000000000000000009b939a50919850469750309650945092509050565b606060018054610ca290615115565b5f611b0b83836014525f526028600c205c90565b612047613472565b6001600160a01b0381165f818152600f6020526040808220805460ff19166001179055517feb73900b98b6a3e2b8b01708fe544760cf570d21e7fbe5225f24e48b5b2b432e9190a250565b606061209e84336136f9565b6040517f15c7afb40000000000000000000000000000000000000000000000000000000081526001600160a01b038516906315c7afb4906120e7903390879087906004016154ea565b5f604051808303815f875af1158015612102573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052612129919081019061550c565b9050612133613759565b5f80516020615af08339815191525c6001600160801b0381169060801c8115801561216657506001600160801b03811615155b1561219d576040517f5212cba100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50509392505050565b335f9081526010602090815260408083206001600160a01b03851684528252808320805490849055600d90925282208054919283926121e69084906153ef565b9091555061220090506001600160a01b03831684836137ce565b816001600160a01b0316836001600160a01b0316336001600160a01b03167f1c4f94f28cc9152354d4b98b8614b28c6c828a98d88228fa9577c7b9475e120c8460405161224f91815260200190565b60405180910390a492915050565b6001600160c01b0382165f908152600e60205260408120611b0b90836138ab565b610d553383836138b9565b61229484848461139e565b61143a84848484613970565b60606122ab82612a00565b505f6122b5613a8f565b90505f8151116122d35760405180602001604052805f815250611b0b565b806122dd84613a9e565b6040516020016122ee929190615598565b6040516020818303038152906040529392505050565b6001600160c01b0381165f908152600e60205260408120610c8e90613b3b565b604080516060810182525f808252602080830182905282840182905284841c808352600e909152928120919291602885901c62ffffff169164ffffffffff861691906123718285856131f2565b6040517f329b4a0100000000000000000000000000000000000000000000000000000000815260048101849052600286900b602482015264ffffffffff851660448201529091505f9073c87c5c0561a500960aE4f0f171265b8c55aCF1539063329b4a0190606401602060405180830381865af41580156123f4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612418919061539a565b90506040518060600160405280835f01516001600160a01b031681526020018284602001510367ffffffffffffffff1681526020018267ffffffffffffffff168152509650505050505050919050565b61247133612a45565b801561144b5761248d8361248483613288565b61128c90615364565b6001600160a01b0383165f908152600d6020526040812080548392906124b49084906153ef565b9091555061144b90506001600160a01b03841683836137ce565b6124d6613472565b611d5a81613b48565b600b8054611c2990615115565b6124f4613472565b600680546001600160a01b0383166001600160a01b031990911681179091556125256005546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b606061256a8260206155ac565b67ffffffffffffffff81111561258257612582614faa565b6040519080825280601f01601f1916602001820160405280156125ac576020820181803683370190505b5090505f5b828110156125d25780840154602060018301028301526001810190506125b1565b5092915050565b6001600160c01b0381165f908152600e60205260408120610c8e90613b91565b61260233612a45565b612612604084016020850161515c565b67ffffffffffffffff165f03612654576040517faf6c36ab00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6126656080850160608601615337565b90505f61267860c0860160a08701615337565b90506126888262ffffff16613b9e565b801561269d575061269d8162ffffff16613b9e565b6126ba57604051637a34030f60e01b815260040160405180910390fd5b5f620f423f19627fffff848116908416010160020b12156126ee57604051637a34030f60e01b815260040160405180910390fd5b5f627fffff83166207a11f190160020b128061271757505f627fffff82166207a11f190160020b125b1561275c5761272b8162ffffff1660171c90565b151561273c8362ffffff1660171c90565b15151461275c57604051637a34030f60e01b815260040160405180910390fd5b5f61276d60a0870160808801614ce5565b9050612781816001600160a01b0316613bce565b6127c2576040517fe65af6a00000000000000000000000000000000000000000000000000000000081526001600160a01b038216600482015260240161104e565b6127e66127d436889003880188615277565b6001600160a01b038316908787613c05565b5f6127f961108536899003890189615277565b6001600160c01b0381165f908152600e60205260409081902090517fab8a7e3f00000000000000000000000000000000000000000000000000000000815291925073c87c5c0561a500960aE4f0f171265b8c55aCF1539163ab8a7e3f91612864918b906004016155c3565b5f6040518083038186803b15801561287a575f80fd5b505af415801561288c573d5f803e3d5ffd5b506128a1925050506060880160408901614ce5565b6001600160a01b03166128b76020890189614ce5565b6001600160a01b03166001600160c01b0383167f803427d75ce3214f82dc7aa4910635170a6655e2c1663dc03429dd04100cba5a6128fb60408c0160208d0161515c565b6040805167ffffffffffffffff909216825262ffffff808b1660208401528916908201526001600160a01b038716606082015260800160405180910390a461295d61294b36899003890189615277565b6001600160a01b038416908888613c43565b50505050505050565b5f6001600160e01b031982167f80ac58cd0000000000000000000000000000000000000000000000000000000014806129c857506001600160e01b031982167f5b5e139f00000000000000000000000000000000000000000000000000000000145b80610c8e57507f01ffc9a7000000000000000000000000000000000000000000000000000000006001600160e01b0319831614610c8e565b5f818152600960205260408120546001600160a01b038116610c8e57604051637e27328960e01b81526004810184905260240161104e565b61144b8383836001613564565b5f612a4e613c81565b90506001600160801b035f80516020615af08339815191525c167ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be422015c6001600160a01b0380831690841603612aa357505050565b806001600160a01b0316836001600160a01b031603612ac157505050565b6040517f74d863650000000000000000000000000000000000000000000000000000000081526001600160a01b0380841660048301528216602482015260440161104e565b612b11838383613cd6565b61144b576001600160a01b038316612b3f57604051637e27328960e01b81526004810182905260240161104e565b6040517f177e802f0000000000000000000000000000000000000000000000000000000081526001600160a01b03831660048201526024810182905260440161104e565b73020000000000000000000000000000000000000084161561143a5761143a63295b52c560e01b33858585604051602401612bc19493929190615693565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526001600160a01b03861690613d56565b5f6207a11f19627fffff851601600281900b82128281612c2557825f03612c27565b825b62ffffff1690505f612c60612c3c83896155ac565b620f424088612c52578581830615151691040190565b808206151586151691040190565b905082612c7557612c7081615364565b612c77565b805b98975050505050505050565b5f612c8f5f835f612f63565b90506001600160a01b038116610d5557604051637e27328960e01b81526004810183905260240161104e565b805f03612cc6575050565b5f612ccf613c81565b90505f612cdd828585613db3565b9050805f03612cf357612cee613dd1565b61143a565b82810361143a5761143a613e04565b730100000000000000000000000000000000000000851615612d8457612d84635125ce9c60e01b3386868686604051602401612d429594939291906156c2565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526001600160a01b03871690613d56565b5050505050565b6207ffff600282900b1380612db05750612da76207ffff61570c565b60020b8160020b125b15611d5a576040517fce8ef7fc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8082604051602001612dfa9190614edb565b60408051601f1981840301815291905280516020909101206001600160c01b03169392505050565b8054600160a01b900467ffffffffffffffff16611d5a576040517f1e3636e600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73200000000000000000000000000000000000000084161561143a5761143a633fda46bb60e01b33858585604051602401612bc194939291906157c7565b6001600160a01b038216612ed257604051633250574960e11b81525f600482015260240161104e565b5f612ede83835f612f63565b90506001600160a01b0381161561144b576040517f73c6ac6e0000000000000000000000000000000000000000000000000000000081525f600482015260240161104e565b731000000000000000000000000000000000000000851615612d8457612d8463eba8155960e01b3386868686604051602401612d429594939291906157f8565b5f828152600960205260408120546001600160a01b03831615612f8b57612f8b818486612b06565b6001600160a01b03811615612fc557612fa65f855f80613564565b6001600160a01b0381165f90815260026020526040902080545f190190555b6001600160a01b03851615612ff3576001600160a01b0385165f908152600260205260409020805460010190555b5f84815260096020526040902080546001600160a01b0319166001600160a01b03871617905583856001600160a01b0316826001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a4949350505050565b5f306001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161480156130ba57507f000000000000000000000000000000000000000000000000000000000000000046145b156130e457507f000000000000000000000000000000000000000000000000000000000000000090565b611459604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f0000000000000000000000000000000000000000000000000000000000000000918101919091527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b728000000000000000000000000000000000000084161561143a5761143a63827e0eb260e01b33858585604051602401612bc19493929190615830565b5f6131ea606084901b6131dd8660020b613e37565b8082061515851691040190565b949350505050565b604080518082019091525f80825260208201526132108484846140ff565b6040805180820190915290546001600160a01b0381168252600160a01b900467ffffffffffffffff166020820152949350505050565b5f80821215613284576040517fa8ce44320000000000000000000000000000000000000000000000000000000081526004810183905260240161104e565b5090565b5f7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821115613284576040517f24775e060000000000000000000000000000000000000000000000000000000081526004810183905260240161104e565b7240000000000000000000000000000000000000851615612d8457612d846348042cf460e01b3386868686604051602401612d42959493929190615858565b73080000000000000000000000000000000000000084161561143a5761143a63fab3c75660e01b33858585604051602401612bc19493929190615917565b730400000000000000000000000000000000000000851615612d8457612d84639eb477b260e01b3386868686604051602401612d42959493929190615948565b5f6133b16005840183614140565b600283900b5f90815260038501602052604090206133ce90614182565b611b0b919061598a565b5f6001600160a01b0382166133ee575047919050565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa158015613449573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c8e91906159ab565b919050565b6005546001600160a01b03163314611d175760405163118cdaa760e01b815233600482015260240161104e565b600680546001600160a01b0319169055611d5a816141c1565b5f8181526009602052604090205460a081901c906134da81600160a01b6153dc565b5f9384526009602052604090932092909255919050565b5f610c8e6134fd613062565b836040517f19010000000000000000000000000000000000000000000000000000000000008152600281019290925260228201526042902090565b5f805f8061354888888888614212565b92509250925061355882826142da565b50909695505050505050565b808061357857506001600160a01b03821615155b15613670575f61358784612a00565b90506001600160a01b038316158015906135b35750826001600160a01b0316816001600160a01b031614155b80156135e457506001600160a01b038082165f9081526004602090815260408083209387168352929052205460ff16155b15613626576040517fa9fbf51f0000000000000000000000000000000000000000000000000000000081526001600160a01b038416600482015260240161104e565b811561366e5783856001600160a01b0316826001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45b505b50505f90815260036020526040902080546001600160a01b0319166001600160a01b0392909216919091179055565b60606114597f000000000000000000000000000000000000000000000000000000000000000060076143dd565b60606114597f000000000000000000000000000000000000000000000000000000000000000060086143dd565b5f80516020615af08339815191525c7f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b160026001600160801b038316020183815d82600182015d50600181015f80516020615af08339815191525d505050565b5f80516020615af08339815191525c6001600160801b038116806137845763f1c77ed05f526004601cfd5b7f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b15f19909101600202015f815d5f600182015d50600181035f80516020615af08339815191525d50565b5f6001600160a01b03841661381e575f805f8085875af1905080612cee576040517ff4b3b1bc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517fa9059cbb0000000000000000000000000000000000000000000000000000000081526001600160a01b038416600482015282602482015260205f6044835f895af13d15601f3d1160015f51141617169150508061143a576040517ff27f64e400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f611b0b6004840183614486565b6001600160a01b038216613904576040517f5b08ba180000000000000000000000000000000000000000000000000000000081526001600160a01b038316600482015260240161104e565b6001600160a01b038381165f81815260046020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6001600160a01b0383163b1561143a57604051630a85bd0160e11b81526001600160a01b0384169063150b7a02906139b29033908890879087906004016159c2565b6020604051808303815f875af19250505080156139ec575060408051601f3d908101601f191682019092526139e9918101906154a7565b60015b613a53573d808015613a19576040519150601f19603f3d011682016040523d82523d5f602084013e613a1e565b606091505b5080515f03613a4b57604051633250574960e11b81526001600160a01b038516600482015260240161104e565b805181602001fd5b6001600160e01b03198116630a85bd0160e11b14612d8457604051633250574960e11b81526001600160a01b038516600482015260240161104e565b6060600a8054610ca290615115565b60605f613aaa836145b4565b60010190505f8167ffffffffffffffff811115613ac957613ac9614faa565b6040519080825280601f01601f191660200182016040528015613af3576020820181803683370190505b5090508181016020015b5f19017f3031323334353637383961626364656600000000000000000000000000000000600a86061a8153600a8504945084613afd57509392505050565b5f610c8e82600401614695565b600c80546001600160a01b0319166001600160a01b0383169081179091556040517fef673bbfc2ac7e4d4b810bffda0b15a1f2b48c2aa4d178d3fca87d0d1f337062905f90a250565b5f610c8e82600401614780565b5f6207a11f19627fffff8316016207a120600282900b1380613bc657506207a11f198160020b125b159392505050565b5f6001600160a01b0382161580610c8e57505072400000000000000000000000000000000000006001600160a01b03909116101590565b73800000000000000000000000000000000000000084161561143a5761143a635df4d91860e01b33858585604051602401612bc194939291906159f3565b73400000000000000000000000000000000000000084161561143a5761143a6371ded94360e01b33858585604051602401612bc194939291906159f3565b5f5f80516020615af08339815191525c6001600160801b031680613ca5575f613cd0565b60025f198201027f722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b1015c5b91505090565b5f6001600160a01b038316158015906131ea5750826001600160a01b0316846001600160a01b03161480613d2e57506001600160a01b038085165f9081526004602090815260408083209387168352929052205460ff165b806131ea5750505f908152600360205260409020546001600160a01b03908116911614919050565b5f80613d6284846147c5565b91509150816001600160e01b031916816001600160e01b0319161461143a576040517f1e048e1d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f82601452835f526028600c2082815c01915081815d509392505050565b7001000000000000000000000000000000005f80516020615af08339815191525c035f80516020615af08339815191525d565b7001000000000000000000000000000000005f80516020615af08339815191525c015f80516020615af08339815191525d565b5f613e4182612d8b565b815f600282900b8113613e545781613e5d565b613e5d8261570c565b62ffffff8116915060011615613e81576bfff97272373d413259a469909250613e92565b6c0100000000000000000000000092505b6002811615613eb15760606bfff2e50f5f656932ef12357c8402901c92505b6004811615613ed05760606bffe5caca7e10e4e61c3624ea8402901c92505b6008811615613eef5760606bffcb9843d60f6159c9db58838402901c92505b6010811615613f0e5760606bff973b41fa98c081472e68968402901c92505b6020811615613f2d5760606bff2ea16466c96a3843ec78b38402901c92505b6040811615613f4c5760606bfe5dee046a99a2a811c461f18402901c92505b6080811615613f6b5760606bfcbe86c7900a88aedcffc83b8402901c92505b610100811615613f8b5760606bf987a7253ac413176f2b074c8402901c92505b610200811615613fab5760606bf3392b0822b70005940c7a398402901c92505b610400811615613fcb5760606be7159475a2c29b7443b29c7f8402901c92505b610800811615613feb5760606bd097f3bdfd2022b8845ad8f78402901c92505b61100081161561400b5760606ba9f746462d870fdf8a65dc1f8402901c92505b61200081161561402b5760606b70d869a156d2a1b890bb3df68402901c92505b61400081161561404b5760606b31be135f97d08fd9812315058402901c92505b61800081161561406b5760606b09aa508b5b7a84e1c677de548402901c92505b6201000081161561408b5760606a5d6af8dedb81196699c3298402901c92505b620200008116156140aa576060692216e584f5fa1ea926048402901c92505b620400008116156140c757606067048a170391f7dc428402901c92505b5f8260020b13156140f8576140f5837801000000000000000000000000000000000000000000000000615a7c565b92505b5050919050565b600282900b5f9081526003840160205260408120600401805464ffffffffff841690811061412f5761412f615a9b565b905f5260205f200190509392505050565b600281901c623fffff165f818152602084905260408120549091906003841690600685901b60c0161c67ffffffffffffffff1680151590035b95945050505050565b60015f9081526020829052604081205461419e90826004614873565b5f808052602084905260408120546141b7916004614873565b610c8e9190615aaf565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b5f80807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084111561424b57505f915060039050826142d0565b604080515f808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa15801561429c573d5f803e3d5ffd5b5050604051601f1901519150506001600160a01b0381166142c757505f9250600191508290506142d0565b92505f91508190505b9450945094915050565b5f8260038111156142ed576142ed615ad0565b036142f6575050565b600182600381111561430a5761430a615ad0565b03614341576040517ff645eedf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600282600381111561435557614355615ad0565b0361438f576040517ffce698f70000000000000000000000000000000000000000000000000000000081526004810182905260240161104e565b60038260038111156143a3576143a3615ad0565b03610d55576040517fd78bce0c0000000000000000000000000000000000000000000000000000000081526004810182905260240161104e565b606060ff83146143f7576143f0836148b3565b9050610c8e565b81805461440390615115565b80601f016020809104026020016040519081016040528092919081815260200182805461442f90615115565b801561447a5780601f106144515761010080835404028352916020019161447a565b820191905f5260205f20905b81548152906001019060200180831161445d57829003601f168201915b50505050509050610c8e565b62800000811901600881901c61ffff165f81815260208590526040812054909260ff1690600119821b1680840361458857600883901c80195f9081526020889052604081205460011960ff87161b169081900361455e575f888161450b7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b95460016153dc565b81526020019081526020015f205483600119901b169050805f0361453b57627fffff199650505050505050610c8e565b614544816148f0565b60ff1680195f90815260208b905260409020549093509150505b614567816148f0565b60ff16600883901b179450875f8681526020019081526020015f2054925050505b614591816148f0565b60ff16915062ffffff627fffff19600885901b84170119165b9695505050505050565b5f807a184f03e93ff9f4daa797ed6e38ed64bf6a1f01000000000000000083106145fc577a184f03e93ff9f4daa797ed6e38ed64bf6a1f010000000000000000830492506040015b6d04ee2d6d415b85acef81000000008310614628576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc10000831061464657662386f26fc10000830492506010015b6305f5e100831061465e576305f5e100830492506008015b612710831061467257612710830492506004015b60648310614684576064830492506002015b600a8310610c8e5760010192915050565b5f61469f82614780565b156146d6576040517f4f3d7def00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f61471a83826147077f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b95460016153dc565b81526020019081526020015f20546148f0565b60ff1690505f61473a845f841981526020019081526020015f20546148f0565b60ff16600883901b1790505f61475f855f8481526020019081526020015f20546148f0565b60ff16905062ffffff627fffff19600884901b831701191695945050505050565b5f81816147ae7f7710c0702d438d37259561c892984b894ff622adfa3d98b5dfe5a9763f94b95460016153dc565b81526020019081526020015f20545f149050919050565b5f805f6147d185614966565b9050602084015192505f80866001600160a01b0316866040516147f49190615ae4565b5f604051808303815f865af19150503d805f811461482d576040519150601f19603f3d011682016040523d82523d5f602084013e614832565b606091505b50915091508161484557614845816149f5565b8080602001905181019061485991906154a7565b9350821561486957614869614a2f565b5050509250929050565b600682901b9290921c915f825b828110156148a857604085901c9467ffffffffffffffff168015019190910190600101614880565b509190039003919050565b60605f6148bf83614a6f565b6040805160208082528183019092529192505f91906020820181803683375050509182525060208101929092525090565b5f8082116148fc575f80fd5b5f7e818283848586878898a8b8c8d8e8f929395969799a9b9d9e9faaeb6bedeeff600184190184160260f81c90506040518061012001604052806101008152602001615b106101009139818151811061495757614957615a9b565b016020015160f81c9392505050565b5f6001600160a01b036001600160801b035f80516020615af08339815191525c167ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be422015c1661346d575f80516020615af08339815191525c6001600160801b0316827ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be42282015d50600192915050565b80515f03613a4b576040517f36bc48c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f80516020615af08339815191525c6001600160801b03165f7ffcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be42282015d50565b5f60ff8216601f811115610c8e576040517fb3512b0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160e01b031981168114611d5a575f80fd5b5f60208284031215614ad4575f80fd5b8135611b0b81614aaf565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f611b0b6020830184614adf565b5f60208284031215614b2f575f80fd5b5035919050565b6001600160a01b0381168114611d5a575f80fd5b5f8060408385031215614b5b575f80fd5b8235614b6681614b36565b946020939093013593505050565b5f8083601f840112614b84575f80fd5b50813567ffffffffffffffff811115614b9b575f80fd5b602083019150836020828501011115614bb2575f80fd5b9250929050565b5f805f8385036060811215614bcc575f80fd5b6040811215614bd9575f80fd5b50839250604084013567ffffffffffffffff811115614bf6575f80fd5b614c0286828701614b74565b9497909650939450505050565b5f805f838503610140811215614c23575f80fd5b61012080821215614c32575f80fd5b859450840135905067ffffffffffffffff811115614bf6575f80fd5b5f60c08284031215611bc6575f80fd5b5f60c08284031215614c6e575f80fd5b611b0b8383614c4e565b5f805f60608486031215614c8a575f80fd5b8335614c9581614b36565b92506020840135614ca581614b36565b929592945050506040919091013590565b5f805f60408486031215614cc8575f80fd5b83359250602084013567ffffffffffffffff811115614bf6575f80fd5b5f60208284031215614cf5575f80fd5b8135611b0b81614b36565b5f805f838503610120811215614d14575f80fd5b61010080821215614c32575f80fd5b5f8060408385031215614d34575f80fd5b8235614d3f81614b36565b91506020830135614d4f81614b36565b809150509250929050565b80356001600160c01b038116811461346d575f80fd5b8035600281900b811461346d575f80fd5b5f8060408385031215614d92575f80fd5b614d9b83614d5a565b9150614da960208401614d70565b90509250929050565b5f60208284031215614dc2575f80fd5b611b0b82614d5a565b5f805f805f8060c08789031215614de0575f80fd5b8635614deb81614b36565b95506020870135945060408701359350606087013560ff81168114614e0e575f80fd5b9598949750929560808101359460a0909101359350915050565b7fff00000000000000000000000000000000000000000000000000000000000000881681525f602060e06020840152614e6460e084018a614adf565b8381036040850152614e76818a614adf565b606085018990526001600160a01b038816608086015260a0850187905284810360c0860152855180825260208088019350909101905f5b81811015614ec957835183529284019291840191600101614ead565b50909c9b505050505050505050505050565b60c08101610c8e82846001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b5f805f60408486031215614f54575f80fd5b8335614f5f81614b36565b9250602084013567ffffffffffffffff811115614bf6575f80fd5b5f8060408385031215614f8b575f80fd5b8235614f9681614b36565b915060208301358015158114614d4f575f80fd5b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f1916810167ffffffffffffffff81118282101715614fe757614fe7614faa565b604052919050565b5f67ffffffffffffffff82111561500857615008614faa565b50601f01601f191660200190565b5f805f8060808587031215615029575f80fd5b843561503481614b36565b9350602085013561504481614b36565b925060408501359150606085013567ffffffffffffffff811115615066575f80fd5b8501601f81018713615076575f80fd5b803561508961508482614fef565b614fbe565b81815288602083850101111561509d575f80fd5b816020840160208301375f6020838301015280935050505092959194509250565b5f80604083850312156150cf575f80fd5b50508035926020909101359150565b5f805f60e084860312156150f0575f80fd5b6150fa8585614c4e565b925060c084013567ffffffffffffffff811115614bf6575f80fd5b600181811c9082168061512957607f821691505b602082108103611bc657634e487b7160e01b5f52602260045260245ffd5b67ffffffffffffffff81168114611d5a575f80fd5b5f6020828403121561516c575f80fd5b8135611b0b81615147565b5f8060408385031215615188575f80fd5b825161519381615147565b6020840151909250614d4f81615147565b5f602082840312156151b4575f80fd5b611b0b82614d70565b803562ffffff8116811461346d575f80fd5b5f60c082840312156151df575f80fd5b60405160c0810181811067ffffffffffffffff8211171561520257615202614faa565b604052905080823561521381614b36565b8152602083013561522381615147565b6020820152604083013561523681614b36565b6040820152615247606084016151bd565b6060820152608083013561525a81614b36565b608082015261526b60a084016151bd565b60a08201525092915050565b5f60c08284031215615287575f80fd5b611b0b83836151cf565b5f61012082840312156152a2575f80fd5b6040516080810181811067ffffffffffffffff821117156152c5576152c5614faa565b6040526152d284846151cf565b81526152e060c08401614d70565b602082015260e08301356152f381615147565b604082015261010083013561530781614b36565b60608201529392505050565b5f60208284031215615323575f80fd5b815164ffffffffff81168114611b0b575f80fd5b5f60208284031215615347575f80fd5b611b0b826151bd565b634e487b7160e01b5f52601160045260245ffd5b5f7f8000000000000000000000000000000000000000000000000000000000000000820361539457615394615350565b505f0390565b5f602082840312156153aa575f80fd5b8151611b0b81615147565b8082018281125f8312801582168215821617156153d4576153d4615350565b505092915050565b80820180821115610c8e57610c8e615350565b81810381811115610c8e57610c8e615350565b5f6101008284031215615413575f80fd5b6040516060810181811067ffffffffffffffff8211171561543657615436614faa565b60405261544384846151cf565b815261545160c08401614d70565b602082015260e083013561546481615147565b60408201529392505050565b8181035f8312801583831316838312821617156125d2576125d2615350565b828152604060208201525f6131ea6040830184614adf565b5f602082840312156154b7575f80fd5b8151611b0b81614aaf565b81835281816020850137505f828201602090810191909152601f909101601f19169091010190565b6001600160a01b0384168152604060208201525f6141796040830184866154c2565b5f6020828403121561551c575f80fd5b815167ffffffffffffffff811115615532575f80fd5b8201601f81018413615542575f80fd5b805161555061508482614fef565b818152856020838501011115615564575f80fd5b8160208401602083015e5f91810160200191909152949350505050565b5f81518060208401855e5f93019283525090919050565b5f6131ea6155a68386615581565b84615581565b8082028115828204841417610c8e57610c8e615350565b82815260e0810182356155d581614b36565b6001600160a01b038082166020850152602085013591506155f582615147565b67ffffffffffffffff821660408501526040850135915061561582614b36565b8082166060850152615629606086016151bd565b915062ffffff80831660808601526080860135925061564783614b36565b81831660a08601528061565c60a088016151bd565b1660c08601525050509392505050565b80358252602081013561567e81615147565b67ffffffffffffffff81166020840152505050565b6001600160a01b03851681526156ac602082018561566c565b608060608201525f6145aa6080830184866154c2565b6001600160a01b03861681526156db602082018661566c565b67ffffffffffffffff8416606082015260a060808201525f61570160a0830184866154c2565b979650505050505050565b5f8160020b627fffff19810361572457615724615350565b5f0392915050565b6157908282516001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b602081015160020b60c0830152604081015167ffffffffffffffff1660e0830152606001516001600160a01b031661010090910152565b5f6101606001600160a01b03871683526157e4602084018761572c565b8061014084015261570181840185876154c2565b5f6101806001600160a01b0388168352615815602084018861572c565b8561014084015280610160840152612c7781840185876154c2565b6001600160a01b0385168152836020820152606060408201525f6145aa6060830184866154c2565b6001600160a01b038616815284602082015267ffffffffffffffff84166040820152608060608201525f6157016080830184866154c2565b6158f48282516001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b602081015160020b60c08301526040015167ffffffffffffffff1660e090910152565b5f6101406001600160a01b03871683526159346020840187615890565b8061012084015261570181840185876154c2565b5f6101606001600160a01b03881683526159656020840188615890565b67ffffffffffffffff861661012084015280610140840152612c7781840185876154c2565b67ffffffffffffffff8281168282160390808211156125d2576125d2615350565b5f602082840312156159bb575f80fd5b5051919050565b5f6001600160a01b038087168352808616602084015250836040830152608060608301526145aa6080830184614adf565b5f6101006001600160a01b0387168352615a6960208401876001600160a01b0380825116835267ffffffffffffffff6020830151166020840152806040830151166040840152606082015162ffffff80821660608601528260808501511660808601528060a08501511660a08601525050505050565b8060e084015261570181840185876154c2565b5f82615a9657634e487b7160e01b5f52601260045260245ffd5b500490565b634e487b7160e01b5f52603260045260245ffd5b67ffffffffffffffff8181168382160190808211156125d2576125d2615350565b634e487b7160e01b5f52602160045260245ffd5b5f611b0b828461558156fe760a9a962ae3d184e99c0483cf5684fb3170f47116ca4f445c50209da4f4f9070001020903110a19042112290b311a3905412245134d2a550c5d32651b6d3a7506264262237d468514804e8d2b95569d0d495ea533a966b11c886eb93bc176c9071727374353637324837e9b47af86c7155181ad4fd18ed32c9096db57d59ee30e2e4a6a5f92a6be3498aae067ddb2eb1d5989b56fd7baf33ca0c2ee77e5caf7ff0810182028303840444c545c646c7425617c847f8c949c48a4a8b087b8c0c816365272829aaec650acd0d28fdad4e22d6991bd97dfdcea58b4d6f29fede4f6fe0f1f2f3f4b5b6b607b8b93a3a7b7bf357199c5abcfd9e168bcdee9b3f1ecf5fd1e3e5a7a8aa2b670c4ced8bbe8f0f4fc3d79a1c3cde7effb78cce6facbf9f8a2646970667358221220ff3e8cb4594e46fa897577e64bdf19501b281e3db0fabe14efc300b88247c70564736f6c63430008190033" } \ No newline at end of file diff --git a/deployments/421614/solcInputs/61c41691f2d6c9050f42543a62f11089.json b/deployments/421614/solcInputs/61c41691f2d6c9050f42543a62f11089.json new file mode 100644 index 0000000..3401b1e --- /dev/null +++ b/deployments/421614/solcInputs/61c41691f2d6c9050f42543a62f11089.json @@ -0,0 +1,171 @@ +{ + "language": "Solidity", + "sources": { + "@openzeppelin/contracts/access/Ownable.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * The initial owner is set to the address provided by the deployer. This can\n * later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n /**\n * @dev The caller account is not authorized to perform an operation.\n */\n error OwnableUnauthorizedAccount(address account);\n\n /**\n * @dev The owner is not a valid owner account. (eg. `address(0)`)\n */\n error OwnableInvalidOwner(address owner);\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n */\n constructor(address initialOwner) {\n if (initialOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(initialOwner);\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n if (owner() != _msgSender()) {\n revert OwnableUnauthorizedAccount(_msgSender());\n }\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby disabling any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n if (newOwner == address(0)) {\n revert OwnableInvalidOwner(address(0));\n }\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n" + }, + "@openzeppelin/contracts/access/Ownable2Step.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)\n\npragma solidity ^0.8.20;\n\nimport {Ownable} from \"./Ownable.sol\";\n\n/**\n * @dev Contract module which provides access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * This extension of the {Ownable} contract includes a two-step mechanism to transfer\n * ownership, where the new owner must call {acceptOwnership} in order to replace the\n * old one. This can help prevent common mistakes, such as transfers of ownership to\n * incorrect accounts, or to contracts that are unable to interact with the\n * permission system.\n *\n * The initial owner is specified at deployment time in the constructor for `Ownable`. This\n * can later be changed with {transferOwnership} and {acceptOwnership}.\n *\n * This module is used through inheritance. It will make available all functions\n * from parent (Ownable).\n */\nabstract contract Ownable2Step is Ownable {\n address private _pendingOwner;\n\n event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Returns the address of the pending owner.\n */\n function pendingOwner() public view virtual returns (address) {\n return _pendingOwner;\n }\n\n /**\n * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual override onlyOwner {\n _pendingOwner = newOwner;\n emit OwnershipTransferStarted(owner(), newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual override {\n delete _pendingOwner;\n super._transferOwnership(newOwner);\n }\n\n /**\n * @dev The new owner accepts the ownership transfer.\n */\n function acceptOwnership() public virtual {\n address sender = _msgSender();\n if (pendingOwner() != sender) {\n revert OwnableUnauthorizedAccount(sender);\n }\n _transferOwnership(sender);\n }\n}\n" + }, + "@openzeppelin/contracts/interfaces/draft-IERC6093.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard ERC-20 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.\n */\ninterface IERC20Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC20InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC20InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n * @param allowance Amount of tokens a `spender` is allowed to operate with.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC20InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `spender` to be approved. Used in approvals.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC20InvalidSpender(address spender);\n}\n\n/**\n * @dev Standard ERC-721 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.\n */\ninterface IERC721Errors {\n /**\n * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.\n * Used in balance queries.\n * @param owner Address of the current owner of a token.\n */\n error ERC721InvalidOwner(address owner);\n\n /**\n * @dev Indicates a `tokenId` whose `owner` is the zero address.\n * @param tokenId Identifier number of a token.\n */\n error ERC721NonexistentToken(uint256 tokenId);\n\n /**\n * @dev Indicates an error related to the ownership over a particular token. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param tokenId Identifier number of a token.\n * @param owner Address of the current owner of a token.\n */\n error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC721InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC721InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param tokenId Identifier number of a token.\n */\n error ERC721InsufficientApproval(address operator, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC721InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC721InvalidOperator(address operator);\n}\n\n/**\n * @dev Standard ERC-1155 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.\n */\ninterface IERC1155Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n * @param tokenId Identifier number of a token.\n */\n error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC1155InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC1155InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param owner Address of the current owner of a token.\n */\n error ERC1155MissingApprovalForAll(address operator, address owner);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC1155InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC1155InvalidOperator(address operator);\n\n /**\n * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.\n * Used in batch transfers.\n * @param idsLength Length of the array of token identifiers\n * @param valuesLength Length of the array of token amounts\n */\n error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);\n}\n" + }, + "@openzeppelin/contracts/interfaces/IERC1271.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1271.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-1271 standard signature validation method for\n * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].\n */\ninterface IERC1271 {\n /**\n * @dev Should return whether the signature provided is valid for the provided data\n * @param hash Hash of the data to be signed\n * @param signature Signature byte array associated with _data\n */\n function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);\n}\n" + }, + "@openzeppelin/contracts/interfaces/IERC5267.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)\n\npragma solidity ^0.8.20;\n\ninterface IERC5267 {\n /**\n * @dev MAY be emitted to signal that the domain could have changed.\n */\n event EIP712DomainChanged();\n\n /**\n * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712\n * signature.\n */\n function eip712Domain()\n external\n view\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n );\n}\n" + }, + "@openzeppelin/contracts/token/ERC20/IERC20.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-20 standard as defined in the ERC.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the value of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the value of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the\n * allowance mechanism. `value` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n" + }, + "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC721} from \"../IERC721.sol\";\n\n/**\n * @title ERC-721 Non-Fungible Token Standard, optional metadata extension\n * @dev See https://eips.ethereum.org/EIPS/eip-721\n */\ninterface IERC721Metadata is IERC721 {\n /**\n * @dev Returns the token collection name.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the token collection symbol.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\n */\n function tokenURI(uint256 tokenId) external view returns (string memory);\n}\n" + }, + "@openzeppelin/contracts/token/ERC721/IERC721.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC-721 compliant contract.\n */\ninterface IERC721 is IERC165 {\n /**\n * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\n */\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\n */\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\n */\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n /**\n * @dev Returns the number of tokens in ``owner``'s account.\n */\n function balanceOf(address owner) external view returns (uint256 balance);\n\n /**\n * @dev Returns the owner of the `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function ownerOf(uint256 tokenId) external view returns (address owner);\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon\n * a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n * are aware of the ERC-721 protocol to prevent tokens from being forever locked.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or\n * {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon\n * a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(address from, address to, uint256 tokenId) external;\n\n /**\n * @dev Transfers `tokenId` token from `from` to `to`.\n *\n * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721\n * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must\n * understand this adds an external call which potentially creates a reentrancy vulnerability.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address from, address to, uint256 tokenId) external;\n\n /**\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n * The approval is cleared when the token is transferred.\n *\n * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\n *\n * Requirements:\n *\n * - The caller must own the token or be an approved operator.\n * - `tokenId` must exist.\n *\n * Emits an {Approval} event.\n */\n function approve(address to, uint256 tokenId) external;\n\n /**\n * @dev Approve or remove `operator` as an operator for the caller.\n * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\n *\n * Requirements:\n *\n * - The `operator` cannot be the address zero.\n *\n * Emits an {ApprovalForAll} event.\n */\n function setApprovalForAll(address operator, bool approved) external;\n\n /**\n * @dev Returns the account approved for `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function getApproved(uint256 tokenId) external view returns (address operator);\n\n /**\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n *\n * See {setApprovalForAll}\n */\n function isApprovedForAll(address owner, address operator) external view returns (bool);\n}\n" + }, + "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @title ERC-721 token receiver interface\n * @dev Interface for any contract that wants to support safeTransfers\n * from ERC-721 asset contracts.\n */\ninterface IERC721Receiver {\n /**\n * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\n * by `operator` from `from`, this function is called.\n *\n * It must return its Solidity selector to confirm the token transfer.\n * If any other value is returned or the interface is not implemented by the recipient, the transfer will be\n * reverted.\n *\n * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.\n */\n function onERC721Received(\n address operator,\n address from,\n uint256 tokenId,\n bytes calldata data\n ) external returns (bytes4);\n}\n" + }, + "@openzeppelin/contracts/utils/Context.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n function _contextSuffixLength() internal view virtual returns (uint256) {\n return 0;\n }\n}\n" + }, + "@openzeppelin/contracts/utils/cryptography/ECDSA.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n enum RecoverError {\n NoError,\n InvalidSignature,\n InvalidSignatureLength,\n InvalidSignatureS\n }\n\n /**\n * @dev The signature derives the `address(0)`.\n */\n error ECDSAInvalidSignature();\n\n /**\n * @dev The signature has an invalid length.\n */\n error ECDSAInvalidSignatureLength(uint256 length);\n\n /**\n * @dev The signature has an S value that is in the upper half order.\n */\n error ECDSAInvalidSignatureS(bytes32 s);\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not\n * return address(0) without also returning an error description. Errors are documented using an enum (error type)\n * and a bytes32 providing additional information about the error.\n *\n * If no error is returned, then the address can be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n *\n * Documentation for signature generation:\n * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n */\n function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {\n if (signature.length == 65) {\n bytes32 r;\n bytes32 s;\n uint8 v;\n // ecrecover takes the signature parameters, and the only way to get them\n // currently is to use assembly.\n /// @solidity memory-safe-assembly\n assembly {\n r := mload(add(signature, 0x20))\n s := mload(add(signature, 0x40))\n v := byte(0, mload(add(signature, 0x60)))\n }\n return tryRecover(hash, v, r, s);\n } else {\n return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature`. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n */\n function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n *\n * See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]\n */\n function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {\n unchecked {\n bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n // We do not check for an overflow here since the shift operation results in 0 or 1.\n uint8 v = uint8((uint256(vs) >> 255) + 27);\n return tryRecover(hash, v, r, s);\n }\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n */\n function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function tryRecover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address, RecoverError, bytes32) {\n // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n //\n // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n // these malleable signatures as well.\n if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n return (address(0), RecoverError.InvalidSignatureS, s);\n }\n\n // If the signature is valid (and not malleable), return the signer address\n address signer = ecrecover(hash, v, r, s);\n if (signer == address(0)) {\n return (address(0), RecoverError.InvalidSignature, bytes32(0));\n }\n\n return (signer, RecoverError.NoError, bytes32(0));\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.\n */\n function _throwError(RecoverError error, bytes32 errorArg) private pure {\n if (error == RecoverError.NoError) {\n return; // no error: do nothing\n } else if (error == RecoverError.InvalidSignature) {\n revert ECDSAInvalidSignature();\n } else if (error == RecoverError.InvalidSignatureLength) {\n revert ECDSAInvalidSignatureLength(uint256(errorArg));\n } else if (error == RecoverError.InvalidSignatureS) {\n revert ECDSAInvalidSignatureS(errorArg);\n }\n }\n}\n" + }, + "@openzeppelin/contracts/utils/cryptography/EIP712.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/EIP712.sol)\n\npragma solidity ^0.8.20;\n\nimport {MessageHashUtils} from \"./MessageHashUtils.sol\";\nimport {ShortStrings, ShortString} from \"../ShortStrings.sol\";\nimport {IERC5267} from \"../../interfaces/IERC5267.sol\";\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-712[EIP-712] is a standard for hashing and signing of typed structured data.\n *\n * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose\n * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract\n * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to\n * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.\n *\n * This contract implements the EIP-712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding\n * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA\n * ({_hashTypedDataV4}).\n *\n * The implementation of the domain separator was designed to be as efficient as possible while still properly updating\n * the chain id to protect against replay attacks on an eventual fork of the chain.\n *\n * NOTE: This contract implements the version of the encoding known as \"v4\", as implemented by the JSON RPC method\n * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].\n *\n * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain\n * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the\n * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.\n *\n * @custom:oz-upgrades-unsafe-allow state-variable-immutable\n */\nabstract contract EIP712 is IERC5267 {\n using ShortStrings for *;\n\n bytes32 private constant TYPE_HASH =\n keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\");\n\n // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to\n // invalidate the cached domain separator if the chain id changes.\n bytes32 private immutable _cachedDomainSeparator;\n uint256 private immutable _cachedChainId;\n address private immutable _cachedThis;\n\n bytes32 private immutable _hashedName;\n bytes32 private immutable _hashedVersion;\n\n ShortString private immutable _name;\n ShortString private immutable _version;\n string private _nameFallback;\n string private _versionFallback;\n\n /**\n * @dev Initializes the domain separator and parameter caches.\n *\n * The meaning of `name` and `version` is specified in\n * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP-712]:\n *\n * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.\n * - `version`: the current major version of the signing domain.\n *\n * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart\n * contract upgrade].\n */\n constructor(string memory name, string memory version) {\n _name = name.toShortStringWithFallback(_nameFallback);\n _version = version.toShortStringWithFallback(_versionFallback);\n _hashedName = keccak256(bytes(name));\n _hashedVersion = keccak256(bytes(version));\n\n _cachedChainId = block.chainid;\n _cachedDomainSeparator = _buildDomainSeparator();\n _cachedThis = address(this);\n }\n\n /**\n * @dev Returns the domain separator for the current chain.\n */\n function _domainSeparatorV4() internal view returns (bytes32) {\n if (address(this) == _cachedThis && block.chainid == _cachedChainId) {\n return _cachedDomainSeparator;\n } else {\n return _buildDomainSeparator();\n }\n }\n\n function _buildDomainSeparator() private view returns (bytes32) {\n return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));\n }\n\n /**\n * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this\n * function returns the hash of the fully encoded EIP712 message for this domain.\n *\n * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:\n *\n * ```solidity\n * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(\n * keccak256(\"Mail(address to,string contents)\"),\n * mailTo,\n * keccak256(bytes(mailContents))\n * )));\n * address signer = ECDSA.recover(digest, signature);\n * ```\n */\n function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {\n return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);\n }\n\n /**\n * @dev See {IERC-5267}.\n */\n function eip712Domain()\n public\n view\n virtual\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n )\n {\n return (\n hex\"0f\", // 01111\n _EIP712Name(),\n _EIP712Version(),\n block.chainid,\n address(this),\n bytes32(0),\n new uint256[](0)\n );\n }\n\n /**\n * @dev The name parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _name which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Name() internal view returns (string memory) {\n return _name.toStringWithFallback(_nameFallback);\n }\n\n /**\n * @dev The version parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _version which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Version() internal view returns (string memory) {\n return _version.toStringWithFallback(_versionFallback);\n }\n}\n" + }, + "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)\n\npragma solidity ^0.8.20;\n\nimport {Strings} from \"../Strings.sol\";\n\n/**\n * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.\n *\n * The library provides methods for generating a hash of a message that conforms to the\n * https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]\n * specifications.\n */\nlibrary MessageHashUtils {\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing a bytes32 `messageHash` with\n * `\"\\x19Ethereum Signed Message:\\n32\"` and hashing the result. It corresponds with the\n * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with\n * keccak256, although any bytes32 value can be safely used because the final digest will\n * be re-hashed.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {\n /// @solidity memory-safe-assembly\n assembly {\n mstore(0x00, \"\\x19Ethereum Signed Message:\\n32\") // 32 is the bytes-length of messageHash\n mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix\n digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing an arbitrary `message` with\n * `\"\\x19Ethereum Signed Message:\\n\" + len(message)` and hashing the result. It corresponds with the\n * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {\n return\n keccak256(bytes.concat(\"\\x19Ethereum Signed Message:\\n\", bytes(Strings.toString(message.length)), message));\n }\n\n /**\n * @dev Returns the keccak256 digest of an ERC-191 signed data with version\n * `0x00` (data with intended validator).\n *\n * The digest is calculated by prefixing an arbitrary `data` with `\"\\x19\\x00\"` and the intended\n * `validator` address. Then hashing the result.\n *\n * See {ECDSA-recover}.\n */\n function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(hex\"19_00\", validator, data));\n }\n\n /**\n * @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).\n *\n * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with\n * `\\x19\\x01` and hashing the result. It corresponds to the hash signed by the\n * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.\n *\n * See {ECDSA-recover}.\n */\n function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {\n /// @solidity memory-safe-assembly\n assembly {\n let ptr := mload(0x40)\n mstore(ptr, hex\"19_01\")\n mstore(add(ptr, 0x02), domainSeparator)\n mstore(add(ptr, 0x22), structHash)\n digest := keccak256(ptr, 0x42)\n }\n }\n}\n" + }, + "@openzeppelin/contracts/utils/introspection/ERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n" + }, + "@openzeppelin/contracts/utils/introspection/IERC165.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC-165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[ERC].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n" + }, + "@openzeppelin/contracts/utils/math/Math.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.20;\n\nimport {Panic} from \"../Panic.sol\";\nimport {SafeCast} from \"./SafeCast.sol\";\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Floor, // Toward negative infinity\n Ceil, // Toward positive infinity\n Trunc, // Toward zero\n Expand // Away from zero\n }\n\n /**\n * @dev Returns the addition of two unsigned integers, with an success flag (no overflow).\n */\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n uint256 c = a + b;\n if (c < a) return (false, 0);\n return (true, c);\n }\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow).\n */\n function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n if (b > a) return (false, 0);\n return (true, a - b);\n }\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow).\n */\n function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n if (a == 0) return (true, 0);\n uint256 c = a * b;\n if (c / a != b) return (false, 0);\n return (true, c);\n }\n }\n\n /**\n * @dev Returns the division of two unsigned integers, with a success flag (no division by zero).\n */\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n if (b == 0) return (false, 0);\n return (true, a / b);\n }\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).\n */\n function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {\n unchecked {\n if (b == 0) return (false, 0);\n return (true, a % b);\n }\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return a > b ? a : b;\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return a < b ? a : b;\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds towards infinity instead\n * of rounding towards zero.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n if (b == 0) {\n // Guarantee the same behavior as in a regular Solidity division.\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n\n // The following calculation ensures accurate ceiling division without overflow.\n // Since a is non-zero, (a - 1) / b will not overflow.\n // The largest possible result occurs when (a - 1) / b is type(uint256).max,\n // but the largest value we can obtain is type(uint256).max - 1, which happens\n // when a = type(uint256).max and b = 1.\n unchecked {\n return a == 0 ? 0 : (a - 1) / b + 1;\n }\n }\n\n /**\n * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or\n * denominator == 0.\n *\n * Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by\n * Uniswap Labs also under MIT license.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\n unchecked {\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = prod1 * 2²⁵⁶ + prod0.\n uint256 prod0 = x * y; // Least significant 256 bits of the product\n uint256 prod1; // Most significant 256 bits of the product\n assembly {\n let mm := mulmod(x, y, not(0))\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n }\n\n // Handle non-overflow cases, 256 by 256 division.\n if (prod1 == 0) {\n // Solidity will revert if denominator == 0, unlike the div opcode on its own.\n // The surrounding unchecked block does not change this fact.\n // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\n return prod0 / denominator;\n }\n\n // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.\n if (denominator <= prod1) {\n Panic.panic(denominator == 0 ? Panic.DIVISION_BY_ZERO : Panic.UNDER_OVERFLOW);\n }\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [prod1 prod0].\n uint256 remainder;\n assembly {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n prod1 := sub(prod1, gt(remainder, prod0))\n prod0 := sub(prod0, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator.\n // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.\n\n uint256 twos = denominator & (0 - denominator);\n assembly {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [prod1 prod0] by twos.\n prod0 := div(prod0, twos)\n\n // Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from prod1 into prod0.\n prod0 |= prod1 * twos;\n\n // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such\n // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv ≡ 1 mod 2⁴.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also\n // works in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶\n inverse *= 2 - denominator * inverse; // inverse mod 2³²\n inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴\n inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸\n inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is\n // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and prod1\n // is no longer required.\n result = prod0 * inverse;\n return result;\n }\n }\n\n /**\n * @dev Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\n return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);\n }\n\n /**\n * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.\n *\n * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, expect 0.\n * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.\n *\n * If the input value is not inversible, 0 is returned.\n *\n * 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\n * inverse using `Math.modExp(a, n - 2, n)`.\n */\n function invMod(uint256 a, uint256 n) internal pure returns (uint256) {\n unchecked {\n if (n == 0) return 0;\n\n // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)\n // Used to compute integers x and y such that: ax + ny = gcd(a, n).\n // When the gcd is 1, then the inverse of a modulo n exists and it's x.\n // ax + ny = 1\n // ax = 1 + (-y)n\n // ax ≡ 1 (mod n) # x is the inverse of a modulo n\n\n // If the remainder is 0 the gcd is n right away.\n uint256 remainder = a % n;\n uint256 gcd = n;\n\n // Therefore the initial coefficients are:\n // ax + ny = gcd(a, n) = n\n // 0a + 1n = n\n int256 x = 0;\n int256 y = 1;\n\n while (remainder != 0) {\n uint256 quotient = gcd / remainder;\n\n (gcd, remainder) = (\n // The old remainder is the next gcd to try.\n remainder,\n // Compute the next remainder.\n // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd\n // where gcd is at most n (capped to type(uint256).max)\n gcd - remainder * quotient\n );\n\n (x, y) = (\n // Increment the coefficient of a.\n y,\n // Decrement the coefficient of n.\n // Can overflow, but the result is casted to uint256 so that the\n // next value of y is \"wrapped around\" to a value between 0 and n - 1.\n x - y * int256(quotient)\n );\n }\n\n if (gcd != 1) return 0; // No inverse exists.\n return x < 0 ? (n - uint256(-x)) : uint256(x); // Wrap the result if it's negative.\n }\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)\n *\n * Requirements:\n * - modulus can't be zero\n * - underlying staticcall to precompile must succeed\n *\n * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make\n * sure the chain you're using it on supports the precompiled contract for modular exponentiation\n * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,\n * the underlying function will succeed given the lack of a revert, but the result may be incorrectly\n * interpreted as 0.\n */\n function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {\n (bool success, uint256 result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).\n * It includes a success flag indicating if the operation succeeded. Operation will be marked has failed if trying\n * to operate modulo 0 or if the underlying precompile reverted.\n *\n * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain\n * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in\n * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack\n * of a revert, but the result may be incorrectly interpreted as 0.\n */\n function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {\n if (m == 0) return (false, 0);\n /// @solidity memory-safe-assembly\n assembly {\n let ptr := mload(0x40)\n // | Offset | Content | Content (Hex) |\n // |-----------|------------|--------------------------------------------------------------------|\n // | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |\n // | 0x60:0x7f | value of b | 0x<.............................................................b> |\n // | 0x80:0x9f | value of e | 0x<.............................................................e> |\n // | 0xa0:0xbf | value of m | 0x<.............................................................m> |\n mstore(ptr, 0x20)\n mstore(add(ptr, 0x20), 0x20)\n mstore(add(ptr, 0x40), 0x20)\n mstore(add(ptr, 0x60), b)\n mstore(add(ptr, 0x80), e)\n mstore(add(ptr, 0xa0), m)\n\n // Given the result < m, it's guaranteed to fit in 32 bytes,\n // so we can use the memory scratch space located at offset 0.\n success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)\n result := mload(0x00)\n }\n }\n\n /**\n * @dev Variant of {modExp} that supports inputs of arbitrary length.\n */\n function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {\n (bool success, bytes memory result) = tryModExp(b, e, m);\n if (!success) {\n Panic.panic(Panic.DIVISION_BY_ZERO);\n }\n return result;\n }\n\n /**\n * @dev Variant of {tryModExp} that supports inputs of arbitrary length.\n */\n function tryModExp(\n bytes memory b,\n bytes memory e,\n bytes memory m\n ) internal view returns (bool success, bytes memory result) {\n if (_zeroBytes(m)) return (false, new bytes(0));\n\n uint256 mLen = m.length;\n\n // Encode call args in result and move the free memory pointer\n result = abi.encodePacked(b.length, e.length, mLen, b, e, m);\n\n /// @solidity memory-safe-assembly\n assembly {\n let dataPtr := add(result, 0x20)\n // Write result on top of args to avoid allocating extra memory.\n success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)\n // Overwrite the length.\n // result.length > returndatasize() is guaranteed because returndatasize() == m.length\n mstore(result, mLen)\n // Set the memory pointer after the returned data.\n mstore(0x40, add(dataPtr, mLen))\n }\n }\n\n /**\n * @dev Returns whether the provided byte array is zero.\n */\n function _zeroBytes(bytes memory byteArray) private pure returns (bool) {\n for (uint256 i = 0; i < byteArray.length; ++i) {\n if (byteArray[i] != 0) {\n return false;\n }\n }\n return true;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded\n * towards zero.\n *\n * This method is based on Newton's method for computing square roots; the algorithm is restricted to only\n * using integer operations.\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n unchecked {\n // Take care of easy edge cases when a == 0 or a == 1\n if (a <= 1) {\n return a;\n }\n\n // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a\n // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between\n // the current value as `ε_n = | x_n - sqrt(a) |`.\n //\n // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root\n // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is\n // bigger than any uint256.\n //\n // By noticing that\n // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`\n // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar\n // to the msb function.\n uint256 aa = a;\n uint256 xn = 1;\n\n if (aa >= (1 << 128)) {\n aa >>= 128;\n xn <<= 64;\n }\n if (aa >= (1 << 64)) {\n aa >>= 64;\n xn <<= 32;\n }\n if (aa >= (1 << 32)) {\n aa >>= 32;\n xn <<= 16;\n }\n if (aa >= (1 << 16)) {\n aa >>= 16;\n xn <<= 8;\n }\n if (aa >= (1 << 8)) {\n aa >>= 8;\n xn <<= 4;\n }\n if (aa >= (1 << 4)) {\n aa >>= 4;\n xn <<= 2;\n }\n if (aa >= (1 << 2)) {\n xn <<= 1;\n }\n\n // 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).\n //\n // We can refine our estimation by noticing that the middle of that interval minimizes the error.\n // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).\n // This is going to be our x_0 (and ε_0)\n xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)\n\n // From here, Newton's method give us:\n // x_{n+1} = (x_n + a / x_n) / 2\n //\n // One should note that:\n // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a\n // = ((x_n² + a) / (2 * x_n))² - a\n // = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a\n // = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)\n // = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)\n // = (x_n² - a)² / (2 * x_n)²\n // = ((x_n² - a) / (2 * x_n))²\n // ≥ 0\n // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n\n //\n // This gives us the proof of quadratic convergence of the sequence:\n // ε_{n+1} = | x_{n+1} - sqrt(a) |\n // = | (x_n + a / x_n) / 2 - sqrt(a) |\n // = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |\n // = | (x_n - sqrt(a))² / (2 * x_n) |\n // = | ε_n² / (2 * x_n) |\n // = ε_n² / | (2 * x_n) |\n //\n // For the first iteration, we have a special case where x_0 is known:\n // ε_1 = ε_0² / | (2 * x_0) |\n // ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))\n // ≤ 2**(2*e-4) / (3 * 2**(e-1))\n // ≤ 2**(e-3) / 3\n // ≤ 2**(e-3-log2(3))\n // ≤ 2**(e-4.5)\n //\n // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:\n // ε_{n+1} = ε_n² / | (2 * x_n) |\n // ≤ (2**(e-k))² / (2 * 2**(e-1))\n // ≤ 2**(2*e-2*k) / 2**e\n // ≤ 2**(e-2*k)\n xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above\n xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5\n xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9\n xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18\n xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36\n xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72\n\n // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision\n // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either\n // sqrt(a) or sqrt(a) + 1.\n return xn - SafeCast.toUint(xn > a / xn);\n }\n }\n\n /**\n * @dev Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);\n }\n }\n\n /**\n * @dev Return the log in base 2 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log2(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n uint256 exp;\n unchecked {\n exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);\n value >>= exp;\n result += exp;\n\n exp = 64 * SafeCast.toUint(value > (1 << 64) - 1);\n value >>= exp;\n result += exp;\n\n exp = 32 * SafeCast.toUint(value > (1 << 32) - 1);\n value >>= exp;\n result += exp;\n\n exp = 16 * SafeCast.toUint(value > (1 << 16) - 1);\n value >>= exp;\n result += exp;\n\n exp = 8 * SafeCast.toUint(value > (1 << 8) - 1);\n value >>= exp;\n result += exp;\n\n exp = 4 * SafeCast.toUint(value > (1 << 4) - 1);\n value >>= exp;\n result += exp;\n\n exp = 2 * SafeCast.toUint(value > (1 << 2) - 1);\n value >>= exp;\n result += exp;\n\n result += SafeCast.toUint(value > 1);\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);\n }\n }\n\n /**\n * @dev Return the log in base 10 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10 ** 64) {\n value /= 10 ** 64;\n result += 64;\n }\n if (value >= 10 ** 32) {\n value /= 10 ** 32;\n result += 32;\n }\n if (value >= 10 ** 16) {\n value /= 10 ** 16;\n result += 16;\n }\n if (value >= 10 ** 8) {\n value /= 10 ** 8;\n result += 8;\n }\n if (value >= 10 ** 4) {\n value /= 10 ** 4;\n result += 4;\n }\n if (value >= 10 ** 2) {\n value /= 10 ** 2;\n result += 2;\n }\n if (value >= 10 ** 1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);\n }\n }\n\n /**\n * @dev Return the log in base 256 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n uint256 isGt;\n unchecked {\n isGt = SafeCast.toUint(value > (1 << 128) - 1);\n value >>= isGt * 128;\n result += isGt * 16;\n\n isGt = SafeCast.toUint(value > (1 << 64) - 1);\n value >>= isGt * 64;\n result += isGt * 8;\n\n isGt = SafeCast.toUint(value > (1 << 32) - 1);\n value >>= isGt * 32;\n result += isGt * 4;\n\n isGt = SafeCast.toUint(value > (1 << 16) - 1);\n value >>= isGt * 16;\n result += isGt * 2;\n\n result += SafeCast.toUint(value > (1 << 8) - 1);\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);\n }\n }\n\n /**\n * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.\n */\n function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {\n return uint8(rounding) % 2 == 1;\n }\n}\n" + }, + "@openzeppelin/contracts/utils/math/SafeCast.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeCast {\n /**\n * @dev Value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);\n\n /**\n * @dev An int value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedIntToUint(int256 value);\n\n /**\n * @dev Value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);\n\n /**\n * @dev An uint value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedUintToInt(uint256 value);\n\n /**\n * @dev Returns the downcasted uint248 from uint256, reverting on\n * overflow (when the input is greater than largest uint248).\n *\n * Counterpart to Solidity's `uint248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toUint248(uint256 value) internal pure returns (uint248) {\n if (value > type(uint248).max) {\n revert SafeCastOverflowedUintDowncast(248, value);\n }\n return uint248(value);\n }\n\n /**\n * @dev Returns the downcasted uint240 from uint256, reverting on\n * overflow (when the input is greater than largest uint240).\n *\n * Counterpart to Solidity's `uint240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toUint240(uint256 value) internal pure returns (uint240) {\n if (value > type(uint240).max) {\n revert SafeCastOverflowedUintDowncast(240, value);\n }\n return uint240(value);\n }\n\n /**\n * @dev Returns the downcasted uint232 from uint256, reverting on\n * overflow (when the input is greater than largest uint232).\n *\n * Counterpart to Solidity's `uint232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toUint232(uint256 value) internal pure returns (uint232) {\n if (value > type(uint232).max) {\n revert SafeCastOverflowedUintDowncast(232, value);\n }\n return uint232(value);\n }\n\n /**\n * @dev Returns the downcasted uint224 from uint256, reverting on\n * overflow (when the input is greater than largest uint224).\n *\n * Counterpart to Solidity's `uint224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toUint224(uint256 value) internal pure returns (uint224) {\n if (value > type(uint224).max) {\n revert SafeCastOverflowedUintDowncast(224, value);\n }\n return uint224(value);\n }\n\n /**\n * @dev Returns the downcasted uint216 from uint256, reverting on\n * overflow (when the input is greater than largest uint216).\n *\n * Counterpart to Solidity's `uint216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toUint216(uint256 value) internal pure returns (uint216) {\n if (value > type(uint216).max) {\n revert SafeCastOverflowedUintDowncast(216, value);\n }\n return uint216(value);\n }\n\n /**\n * @dev Returns the downcasted uint208 from uint256, reverting on\n * overflow (when the input is greater than largest uint208).\n *\n * Counterpart to Solidity's `uint208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toUint208(uint256 value) internal pure returns (uint208) {\n if (value > type(uint208).max) {\n revert SafeCastOverflowedUintDowncast(208, value);\n }\n return uint208(value);\n }\n\n /**\n * @dev Returns the downcasted uint200 from uint256, reverting on\n * overflow (when the input is greater than largest uint200).\n *\n * Counterpart to Solidity's `uint200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toUint200(uint256 value) internal pure returns (uint200) {\n if (value > type(uint200).max) {\n revert SafeCastOverflowedUintDowncast(200, value);\n }\n return uint200(value);\n }\n\n /**\n * @dev Returns the downcasted uint192 from uint256, reverting on\n * overflow (when the input is greater than largest uint192).\n *\n * Counterpart to Solidity's `uint192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toUint192(uint256 value) internal pure returns (uint192) {\n if (value > type(uint192).max) {\n revert SafeCastOverflowedUintDowncast(192, value);\n }\n return uint192(value);\n }\n\n /**\n * @dev Returns the downcasted uint184 from uint256, reverting on\n * overflow (when the input is greater than largest uint184).\n *\n * Counterpart to Solidity's `uint184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toUint184(uint256 value) internal pure returns (uint184) {\n if (value > type(uint184).max) {\n revert SafeCastOverflowedUintDowncast(184, value);\n }\n return uint184(value);\n }\n\n /**\n * @dev Returns the downcasted uint176 from uint256, reverting on\n * overflow (when the input is greater than largest uint176).\n *\n * Counterpart to Solidity's `uint176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toUint176(uint256 value) internal pure returns (uint176) {\n if (value > type(uint176).max) {\n revert SafeCastOverflowedUintDowncast(176, value);\n }\n return uint176(value);\n }\n\n /**\n * @dev Returns the downcasted uint168 from uint256, reverting on\n * overflow (when the input is greater than largest uint168).\n *\n * Counterpart to Solidity's `uint168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toUint168(uint256 value) internal pure returns (uint168) {\n if (value > type(uint168).max) {\n revert SafeCastOverflowedUintDowncast(168, value);\n }\n return uint168(value);\n }\n\n /**\n * @dev Returns the downcasted uint160 from uint256, reverting on\n * overflow (when the input is greater than largest uint160).\n *\n * Counterpart to Solidity's `uint160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toUint160(uint256 value) internal pure returns (uint160) {\n if (value > type(uint160).max) {\n revert SafeCastOverflowedUintDowncast(160, value);\n }\n return uint160(value);\n }\n\n /**\n * @dev Returns the downcasted uint152 from uint256, reverting on\n * overflow (when the input is greater than largest uint152).\n *\n * Counterpart to Solidity's `uint152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toUint152(uint256 value) internal pure returns (uint152) {\n if (value > type(uint152).max) {\n revert SafeCastOverflowedUintDowncast(152, value);\n }\n return uint152(value);\n }\n\n /**\n * @dev Returns the downcasted uint144 from uint256, reverting on\n * overflow (when the input is greater than largest uint144).\n *\n * Counterpart to Solidity's `uint144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toUint144(uint256 value) internal pure returns (uint144) {\n if (value > type(uint144).max) {\n revert SafeCastOverflowedUintDowncast(144, value);\n }\n return uint144(value);\n }\n\n /**\n * @dev Returns the downcasted uint136 from uint256, reverting on\n * overflow (when the input is greater than largest uint136).\n *\n * Counterpart to Solidity's `uint136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toUint136(uint256 value) internal pure returns (uint136) {\n if (value > type(uint136).max) {\n revert SafeCastOverflowedUintDowncast(136, value);\n }\n return uint136(value);\n }\n\n /**\n * @dev Returns the downcasted uint128 from uint256, reverting on\n * overflow (when the input is greater than largest uint128).\n *\n * Counterpart to Solidity's `uint128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toUint128(uint256 value) internal pure returns (uint128) {\n if (value > type(uint128).max) {\n revert SafeCastOverflowedUintDowncast(128, value);\n }\n return uint128(value);\n }\n\n /**\n * @dev Returns the downcasted uint120 from uint256, reverting on\n * overflow (when the input is greater than largest uint120).\n *\n * Counterpart to Solidity's `uint120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toUint120(uint256 value) internal pure returns (uint120) {\n if (value > type(uint120).max) {\n revert SafeCastOverflowedUintDowncast(120, value);\n }\n return uint120(value);\n }\n\n /**\n * @dev Returns the downcasted uint112 from uint256, reverting on\n * overflow (when the input is greater than largest uint112).\n *\n * Counterpart to Solidity's `uint112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toUint112(uint256 value) internal pure returns (uint112) {\n if (value > type(uint112).max) {\n revert SafeCastOverflowedUintDowncast(112, value);\n }\n return uint112(value);\n }\n\n /**\n * @dev Returns the downcasted uint104 from uint256, reverting on\n * overflow (when the input is greater than largest uint104).\n *\n * Counterpart to Solidity's `uint104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toUint104(uint256 value) internal pure returns (uint104) {\n if (value > type(uint104).max) {\n revert SafeCastOverflowedUintDowncast(104, value);\n }\n return uint104(value);\n }\n\n /**\n * @dev Returns the downcasted uint96 from uint256, reverting on\n * overflow (when the input is greater than largest uint96).\n *\n * Counterpart to Solidity's `uint96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toUint96(uint256 value) internal pure returns (uint96) {\n if (value > type(uint96).max) {\n revert SafeCastOverflowedUintDowncast(96, value);\n }\n return uint96(value);\n }\n\n /**\n * @dev Returns the downcasted uint88 from uint256, reverting on\n * overflow (when the input is greater than largest uint88).\n *\n * Counterpart to Solidity's `uint88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toUint88(uint256 value) internal pure returns (uint88) {\n if (value > type(uint88).max) {\n revert SafeCastOverflowedUintDowncast(88, value);\n }\n return uint88(value);\n }\n\n /**\n * @dev Returns the downcasted uint80 from uint256, reverting on\n * overflow (when the input is greater than largest uint80).\n *\n * Counterpart to Solidity's `uint80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toUint80(uint256 value) internal pure returns (uint80) {\n if (value > type(uint80).max) {\n revert SafeCastOverflowedUintDowncast(80, value);\n }\n return uint80(value);\n }\n\n /**\n * @dev Returns the downcasted uint72 from uint256, reverting on\n * overflow (when the input is greater than largest uint72).\n *\n * Counterpart to Solidity's `uint72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toUint72(uint256 value) internal pure returns (uint72) {\n if (value > type(uint72).max) {\n revert SafeCastOverflowedUintDowncast(72, value);\n }\n return uint72(value);\n }\n\n /**\n * @dev Returns the downcasted uint64 from uint256, reverting on\n * overflow (when the input is greater than largest uint64).\n *\n * Counterpart to Solidity's `uint64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toUint64(uint256 value) internal pure returns (uint64) {\n if (value > type(uint64).max) {\n revert SafeCastOverflowedUintDowncast(64, value);\n }\n return uint64(value);\n }\n\n /**\n * @dev Returns the downcasted uint56 from uint256, reverting on\n * overflow (when the input is greater than largest uint56).\n *\n * Counterpart to Solidity's `uint56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toUint56(uint256 value) internal pure returns (uint56) {\n if (value > type(uint56).max) {\n revert SafeCastOverflowedUintDowncast(56, value);\n }\n return uint56(value);\n }\n\n /**\n * @dev Returns the downcasted uint48 from uint256, reverting on\n * overflow (when the input is greater than largest uint48).\n *\n * Counterpart to Solidity's `uint48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toUint48(uint256 value) internal pure returns (uint48) {\n if (value > type(uint48).max) {\n revert SafeCastOverflowedUintDowncast(48, value);\n }\n return uint48(value);\n }\n\n /**\n * @dev Returns the downcasted uint40 from uint256, reverting on\n * overflow (when the input is greater than largest uint40).\n *\n * Counterpart to Solidity's `uint40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toUint40(uint256 value) internal pure returns (uint40) {\n if (value > type(uint40).max) {\n revert SafeCastOverflowedUintDowncast(40, value);\n }\n return uint40(value);\n }\n\n /**\n * @dev Returns the downcasted uint32 from uint256, reverting on\n * overflow (when the input is greater than largest uint32).\n *\n * Counterpart to Solidity's `uint32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toUint32(uint256 value) internal pure returns (uint32) {\n if (value > type(uint32).max) {\n revert SafeCastOverflowedUintDowncast(32, value);\n }\n return uint32(value);\n }\n\n /**\n * @dev Returns the downcasted uint24 from uint256, reverting on\n * overflow (when the input is greater than largest uint24).\n *\n * Counterpart to Solidity's `uint24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toUint24(uint256 value) internal pure returns (uint24) {\n if (value > type(uint24).max) {\n revert SafeCastOverflowedUintDowncast(24, value);\n }\n return uint24(value);\n }\n\n /**\n * @dev Returns the downcasted uint16 from uint256, reverting on\n * overflow (when the input is greater than largest uint16).\n *\n * Counterpart to Solidity's `uint16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toUint16(uint256 value) internal pure returns (uint16) {\n if (value > type(uint16).max) {\n revert SafeCastOverflowedUintDowncast(16, value);\n }\n return uint16(value);\n }\n\n /**\n * @dev Returns the downcasted uint8 from uint256, reverting on\n * overflow (when the input is greater than largest uint8).\n *\n * Counterpart to Solidity's `uint8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toUint8(uint256 value) internal pure returns (uint8) {\n if (value > type(uint8).max) {\n revert SafeCastOverflowedUintDowncast(8, value);\n }\n return uint8(value);\n }\n\n /**\n * @dev Converts a signed int256 into an unsigned uint256.\n *\n * Requirements:\n *\n * - input must be greater than or equal to 0.\n */\n function toUint256(int256 value) internal pure returns (uint256) {\n if (value < 0) {\n revert SafeCastOverflowedIntToUint(value);\n }\n return uint256(value);\n }\n\n /**\n * @dev Returns the downcasted int248 from int256, reverting on\n * overflow (when the input is less than smallest int248 or\n * greater than largest int248).\n *\n * Counterpart to Solidity's `int248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toInt248(int256 value) internal pure returns (int248 downcasted) {\n downcasted = int248(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(248, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int240 from int256, reverting on\n * overflow (when the input is less than smallest int240 or\n * greater than largest int240).\n *\n * Counterpart to Solidity's `int240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toInt240(int256 value) internal pure returns (int240 downcasted) {\n downcasted = int240(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(240, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int232 from int256, reverting on\n * overflow (when the input is less than smallest int232 or\n * greater than largest int232).\n *\n * Counterpart to Solidity's `int232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toInt232(int256 value) internal pure returns (int232 downcasted) {\n downcasted = int232(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(232, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int224 from int256, reverting on\n * overflow (when the input is less than smallest int224 or\n * greater than largest int224).\n *\n * Counterpart to Solidity's `int224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toInt224(int256 value) internal pure returns (int224 downcasted) {\n downcasted = int224(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(224, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int216 from int256, reverting on\n * overflow (when the input is less than smallest int216 or\n * greater than largest int216).\n *\n * Counterpart to Solidity's `int216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toInt216(int256 value) internal pure returns (int216 downcasted) {\n downcasted = int216(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(216, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int208 from int256, reverting on\n * overflow (when the input is less than smallest int208 or\n * greater than largest int208).\n *\n * Counterpart to Solidity's `int208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toInt208(int256 value) internal pure returns (int208 downcasted) {\n downcasted = int208(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(208, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int200 from int256, reverting on\n * overflow (when the input is less than smallest int200 or\n * greater than largest int200).\n *\n * Counterpart to Solidity's `int200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toInt200(int256 value) internal pure returns (int200 downcasted) {\n downcasted = int200(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(200, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int192 from int256, reverting on\n * overflow (when the input is less than smallest int192 or\n * greater than largest int192).\n *\n * Counterpart to Solidity's `int192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toInt192(int256 value) internal pure returns (int192 downcasted) {\n downcasted = int192(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(192, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int184 from int256, reverting on\n * overflow (when the input is less than smallest int184 or\n * greater than largest int184).\n *\n * Counterpart to Solidity's `int184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toInt184(int256 value) internal pure returns (int184 downcasted) {\n downcasted = int184(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(184, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int176 from int256, reverting on\n * overflow (when the input is less than smallest int176 or\n * greater than largest int176).\n *\n * Counterpart to Solidity's `int176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toInt176(int256 value) internal pure returns (int176 downcasted) {\n downcasted = int176(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(176, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int168 from int256, reverting on\n * overflow (when the input is less than smallest int168 or\n * greater than largest int168).\n *\n * Counterpart to Solidity's `int168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toInt168(int256 value) internal pure returns (int168 downcasted) {\n downcasted = int168(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(168, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int160 from int256, reverting on\n * overflow (when the input is less than smallest int160 or\n * greater than largest int160).\n *\n * Counterpart to Solidity's `int160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toInt160(int256 value) internal pure returns (int160 downcasted) {\n downcasted = int160(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(160, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int152 from int256, reverting on\n * overflow (when the input is less than smallest int152 or\n * greater than largest int152).\n *\n * Counterpart to Solidity's `int152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toInt152(int256 value) internal pure returns (int152 downcasted) {\n downcasted = int152(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(152, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int144 from int256, reverting on\n * overflow (when the input is less than smallest int144 or\n * greater than largest int144).\n *\n * Counterpart to Solidity's `int144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toInt144(int256 value) internal pure returns (int144 downcasted) {\n downcasted = int144(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(144, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int136 from int256, reverting on\n * overflow (when the input is less than smallest int136 or\n * greater than largest int136).\n *\n * Counterpart to Solidity's `int136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toInt136(int256 value) internal pure returns (int136 downcasted) {\n downcasted = int136(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(136, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int128 from int256, reverting on\n * overflow (when the input is less than smallest int128 or\n * greater than largest int128).\n *\n * Counterpart to Solidity's `int128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toInt128(int256 value) internal pure returns (int128 downcasted) {\n downcasted = int128(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(128, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int120 from int256, reverting on\n * overflow (when the input is less than smallest int120 or\n * greater than largest int120).\n *\n * Counterpart to Solidity's `int120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toInt120(int256 value) internal pure returns (int120 downcasted) {\n downcasted = int120(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(120, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int112 from int256, reverting on\n * overflow (when the input is less than smallest int112 or\n * greater than largest int112).\n *\n * Counterpart to Solidity's `int112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toInt112(int256 value) internal pure returns (int112 downcasted) {\n downcasted = int112(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(112, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int104 from int256, reverting on\n * overflow (when the input is less than smallest int104 or\n * greater than largest int104).\n *\n * Counterpart to Solidity's `int104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toInt104(int256 value) internal pure returns (int104 downcasted) {\n downcasted = int104(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(104, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int96 from int256, reverting on\n * overflow (when the input is less than smallest int96 or\n * greater than largest int96).\n *\n * Counterpart to Solidity's `int96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toInt96(int256 value) internal pure returns (int96 downcasted) {\n downcasted = int96(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(96, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int88 from int256, reverting on\n * overflow (when the input is less than smallest int88 or\n * greater than largest int88).\n *\n * Counterpart to Solidity's `int88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toInt88(int256 value) internal pure returns (int88 downcasted) {\n downcasted = int88(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(88, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int80 from int256, reverting on\n * overflow (when the input is less than smallest int80 or\n * greater than largest int80).\n *\n * Counterpart to Solidity's `int80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toInt80(int256 value) internal pure returns (int80 downcasted) {\n downcasted = int80(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(80, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int72 from int256, reverting on\n * overflow (when the input is less than smallest int72 or\n * greater than largest int72).\n *\n * Counterpart to Solidity's `int72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toInt72(int256 value) internal pure returns (int72 downcasted) {\n downcasted = int72(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(72, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int64 from int256, reverting on\n * overflow (when the input is less than smallest int64 or\n * greater than largest int64).\n *\n * Counterpart to Solidity's `int64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toInt64(int256 value) internal pure returns (int64 downcasted) {\n downcasted = int64(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(64, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int56 from int256, reverting on\n * overflow (when the input is less than smallest int56 or\n * greater than largest int56).\n *\n * Counterpart to Solidity's `int56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toInt56(int256 value) internal pure returns (int56 downcasted) {\n downcasted = int56(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(56, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int48 from int256, reverting on\n * overflow (when the input is less than smallest int48 or\n * greater than largest int48).\n *\n * Counterpart to Solidity's `int48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toInt48(int256 value) internal pure returns (int48 downcasted) {\n downcasted = int48(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(48, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int40 from int256, reverting on\n * overflow (when the input is less than smallest int40 or\n * greater than largest int40).\n *\n * Counterpart to Solidity's `int40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toInt40(int256 value) internal pure returns (int40 downcasted) {\n downcasted = int40(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(40, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int32 from int256, reverting on\n * overflow (when the input is less than smallest int32 or\n * greater than largest int32).\n *\n * Counterpart to Solidity's `int32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toInt32(int256 value) internal pure returns (int32 downcasted) {\n downcasted = int32(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(32, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int24 from int256, reverting on\n * overflow (when the input is less than smallest int24 or\n * greater than largest int24).\n *\n * Counterpart to Solidity's `int24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toInt24(int256 value) internal pure returns (int24 downcasted) {\n downcasted = int24(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(24, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int16 from int256, reverting on\n * overflow (when the input is less than smallest int16 or\n * greater than largest int16).\n *\n * Counterpart to Solidity's `int16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toInt16(int256 value) internal pure returns (int16 downcasted) {\n downcasted = int16(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(16, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int8 from int256, reverting on\n * overflow (when the input is less than smallest int8 or\n * greater than largest int8).\n *\n * Counterpart to Solidity's `int8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toInt8(int256 value) internal pure returns (int8 downcasted) {\n downcasted = int8(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(8, value);\n }\n }\n\n /**\n * @dev Converts an unsigned uint256 into a signed int256.\n *\n * Requirements:\n *\n * - input must be less than or equal to maxInt256.\n */\n function toInt256(uint256 value) internal pure returns (int256) {\n // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n if (value > uint256(type(int256).max)) {\n revert SafeCastOverflowedUintToInt(value);\n }\n return int256(value);\n }\n\n /**\n * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.\n */\n function toUint(bool b) internal pure returns (uint256 u) {\n /// @solidity memory-safe-assembly\n assembly {\n u := iszero(iszero(b))\n }\n }\n}\n" + }, + "@openzeppelin/contracts/utils/math/SignedMath.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard signed math utilities missing in the Solidity language.\n */\nlibrary SignedMath {\n /**\n * @dev Returns the largest of two signed numbers.\n */\n function max(int256 a, int256 b) internal pure returns (int256) {\n return a > b ? a : b;\n }\n\n /**\n * @dev Returns the smallest of two signed numbers.\n */\n function min(int256 a, int256 b) internal pure returns (int256) {\n return a < b ? a : b;\n }\n\n /**\n * @dev Returns the average of two signed numbers without overflow.\n * The result is rounded towards zero.\n */\n function average(int256 a, int256 b) internal pure returns (int256) {\n // Formula from the book \"Hacker's Delight\"\n int256 x = (a & b) + ((a ^ b) >> 1);\n return x + (int256(uint256(x) >> 255) & (a ^ b));\n }\n\n /**\n * @dev Returns the absolute unsigned value of a signed value.\n */\n function abs(int256 n) internal pure returns (uint256) {\n unchecked {\n // Formula from the \"Bit Twiddling Hacks\" by Sean Eron Anderson.\n // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,\n // taking advantage of the most significant (or \"sign\" bit) in two's complement representation.\n // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,\n // the mask will either be `bytes(0)` (if n is positive) or `~bytes32(0)` (if n is negative).\n int256 mask = n >> 255;\n\n // A `bytes(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.\n return uint256((n + mask) ^ mask);\n }\n }\n}\n" + }, + "@openzeppelin/contracts/utils/Panic.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Helper library for emitting standardized panic codes.\n *\n * ```solidity\n * contract Example {\n * using Panic for uint256;\n *\n * // Use any of the declared internal constants\n * function foo() { Panic.GENERIC.panic(); }\n *\n * // Alternatively\n * function foo() { Panic.panic(Panic.GENERIC); }\n * }\n * ```\n *\n * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].\n */\n// slither-disable-next-line unused-state\nlibrary Panic {\n /// @dev generic / unspecified error\n uint256 internal constant GENERIC = 0x00;\n /// @dev used by the assert() builtin\n uint256 internal constant ASSERT = 0x01;\n /// @dev arithmetic underflow or overflow\n uint256 internal constant UNDER_OVERFLOW = 0x11;\n /// @dev division or modulo by zero\n uint256 internal constant DIVISION_BY_ZERO = 0x12;\n /// @dev enum conversion error\n uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;\n /// @dev invalid encoding in storage\n uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;\n /// @dev empty array pop\n uint256 internal constant EMPTY_ARRAY_POP = 0x31;\n /// @dev array out of bounds access\n uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;\n /// @dev resource error (too large allocation or too large array)\n uint256 internal constant RESOURCE_ERROR = 0x41;\n /// @dev calling invalid internal function\n uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;\n\n /// @dev Reverts with a panic code. Recommended to use with\n /// the internal constants with predefined codes.\n function panic(uint256 code) internal pure {\n /// @solidity memory-safe-assembly\n assembly {\n mstore(0x00, 0x4e487b71)\n mstore(0x20, code)\n revert(0x1c, 0x24)\n }\n }\n}\n" + }, + "@openzeppelin/contracts/utils/ShortStrings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/ShortStrings.sol)\n\npragma solidity ^0.8.20;\n\nimport {StorageSlot} from \"./StorageSlot.sol\";\n\n// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |\n// | length | 0x BB |\ntype ShortString is bytes32;\n\n/**\n * @dev This library provides functions to convert short memory strings\n * into a `ShortString` type that can be used as an immutable variable.\n *\n * Strings of arbitrary length can be optimized using this library if\n * they are short enough (up to 31 bytes) by packing them with their\n * length (1 byte) in a single EVM word (32 bytes). Additionally, a\n * fallback mechanism can be used for every other case.\n *\n * Usage example:\n *\n * ```solidity\n * contract Named {\n * using ShortStrings for *;\n *\n * ShortString private immutable _name;\n * string private _nameFallback;\n *\n * constructor(string memory contractName) {\n * _name = contractName.toShortStringWithFallback(_nameFallback);\n * }\n *\n * function name() external view returns (string memory) {\n * return _name.toStringWithFallback(_nameFallback);\n * }\n * }\n * ```\n */\nlibrary ShortStrings {\n // Used as an identifier for strings longer than 31 bytes.\n bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;\n\n error StringTooLong(string str);\n error InvalidShortString();\n\n /**\n * @dev Encode a string of at most 31 chars into a `ShortString`.\n *\n * This will trigger a `StringTooLong` error is the input string is too long.\n */\n function toShortString(string memory str) internal pure returns (ShortString) {\n bytes memory bstr = bytes(str);\n if (bstr.length > 31) {\n revert StringTooLong(str);\n }\n return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));\n }\n\n /**\n * @dev Decode a `ShortString` back to a \"normal\" string.\n */\n function toString(ShortString sstr) internal pure returns (string memory) {\n uint256 len = byteLength(sstr);\n // using `new string(len)` would work locally but is not memory safe.\n string memory str = new string(32);\n /// @solidity memory-safe-assembly\n assembly {\n mstore(str, len)\n mstore(add(str, 0x20), sstr)\n }\n return str;\n }\n\n /**\n * @dev Return the length of a `ShortString`.\n */\n function byteLength(ShortString sstr) internal pure returns (uint256) {\n uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;\n if (result > 31) {\n revert InvalidShortString();\n }\n return result;\n }\n\n /**\n * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.\n */\n function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {\n if (bytes(value).length < 32) {\n return toShortString(value);\n } else {\n StorageSlot.getStringSlot(store).value = value;\n return ShortString.wrap(FALLBACK_SENTINEL);\n }\n }\n\n /**\n * @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.\n */\n function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return toString(value);\n } else {\n return store;\n }\n }\n\n /**\n * @dev Return the length of a string that was encoded to `ShortString` or written to storage using\n * {setWithFallback}.\n *\n * WARNING: This will return the \"byte length\" of the string. This may not reflect the actual length in terms of\n * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.\n */\n function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return byteLength(value);\n } else {\n return bytes(store).length;\n }\n }\n}\n" + }, + "@openzeppelin/contracts/utils/StorageSlot.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)\n// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.\n\npragma solidity ^0.8.24;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC-1967 implementation slot:\n * ```solidity\n * contract ERC1967 {\n * // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.\n * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n * function _getImplementation() internal view returns (address) {\n * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n * }\n *\n * function _setImplementation(address newImplementation) internal {\n * require(newImplementation.code.length > 0);\n * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n * }\n * }\n * ```\n *\n * Since version 5.1, this library also support writing and reading value types to and from transient storage.\n *\n * * Example using transient storage:\n * ```solidity\n * contract Lock {\n * // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.\n * bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;\n *\n * modifier locked() {\n * require(!_LOCK_SLOT.asBoolean().tload());\n *\n * _LOCK_SLOT.asBoolean().tstore(true);\n * _;\n * _LOCK_SLOT.asBoolean().tstore(false);\n * }\n * }\n * ```\n *\n * TIP: Consider using this library along with {SlotDerivation}.\n */\nlibrary StorageSlot {\n struct AddressSlot {\n address value;\n }\n\n struct BooleanSlot {\n bool value;\n }\n\n struct Bytes32Slot {\n bytes32 value;\n }\n\n struct Uint256Slot {\n uint256 value;\n }\n\n struct Int256Slot {\n int256 value;\n }\n\n struct StringSlot {\n string value;\n }\n\n struct BytesSlot {\n bytes value;\n }\n\n /**\n * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n */\n function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BooleanSlot` with member `value` located at `slot`.\n */\n function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.\n */\n function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `Uint256Slot` with member `value` located at `slot`.\n */\n function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `Int256Slot` with member `value` located at `slot`.\n */\n function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `StringSlot` with member `value` located at `slot`.\n */\n function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `StringSlot` representation of the string storage pointer `store`.\n */\n function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := store.slot\n }\n }\n\n /**\n * @dev Returns an `BytesSlot` with member `value` located at `slot`.\n */\n function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.\n */\n function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := store.slot\n }\n }\n\n /**\n * @dev UDVT that represent a slot holding a address.\n */\n type AddressSlotType is bytes32;\n\n /**\n * @dev Cast an arbitrary slot to a AddressSlotType.\n */\n function asAddress(bytes32 slot) internal pure returns (AddressSlotType) {\n return AddressSlotType.wrap(slot);\n }\n\n /**\n * @dev UDVT that represent a slot holding a bool.\n */\n type BooleanSlotType is bytes32;\n\n /**\n * @dev Cast an arbitrary slot to a BooleanSlotType.\n */\n function asBoolean(bytes32 slot) internal pure returns (BooleanSlotType) {\n return BooleanSlotType.wrap(slot);\n }\n\n /**\n * @dev UDVT that represent a slot holding a bytes32.\n */\n type Bytes32SlotType is bytes32;\n\n /**\n * @dev Cast an arbitrary slot to a Bytes32SlotType.\n */\n function asBytes32(bytes32 slot) internal pure returns (Bytes32SlotType) {\n return Bytes32SlotType.wrap(slot);\n }\n\n /**\n * @dev UDVT that represent a slot holding a uint256.\n */\n type Uint256SlotType is bytes32;\n\n /**\n * @dev Cast an arbitrary slot to a Uint256SlotType.\n */\n function asUint256(bytes32 slot) internal pure returns (Uint256SlotType) {\n return Uint256SlotType.wrap(slot);\n }\n\n /**\n * @dev UDVT that represent a slot holding a int256.\n */\n type Int256SlotType is bytes32;\n\n /**\n * @dev Cast an arbitrary slot to a Int256SlotType.\n */\n function asInt256(bytes32 slot) internal pure returns (Int256SlotType) {\n return Int256SlotType.wrap(slot);\n }\n\n /**\n * @dev Load the value held at location `slot` in transient storage.\n */\n function tload(AddressSlotType slot) internal view returns (address value) {\n /// @solidity memory-safe-assembly\n assembly {\n value := tload(slot)\n }\n }\n\n /**\n * @dev Store `value` at location `slot` in transient storage.\n */\n function tstore(AddressSlotType slot, address value) internal {\n /// @solidity memory-safe-assembly\n assembly {\n tstore(slot, value)\n }\n }\n\n /**\n * @dev Load the value held at location `slot` in transient storage.\n */\n function tload(BooleanSlotType slot) internal view returns (bool value) {\n /// @solidity memory-safe-assembly\n assembly {\n value := tload(slot)\n }\n }\n\n /**\n * @dev Store `value` at location `slot` in transient storage.\n */\n function tstore(BooleanSlotType slot, bool value) internal {\n /// @solidity memory-safe-assembly\n assembly {\n tstore(slot, value)\n }\n }\n\n /**\n * @dev Load the value held at location `slot` in transient storage.\n */\n function tload(Bytes32SlotType slot) internal view returns (bytes32 value) {\n /// @solidity memory-safe-assembly\n assembly {\n value := tload(slot)\n }\n }\n\n /**\n * @dev Store `value` at location `slot` in transient storage.\n */\n function tstore(Bytes32SlotType slot, bytes32 value) internal {\n /// @solidity memory-safe-assembly\n assembly {\n tstore(slot, value)\n }\n }\n\n /**\n * @dev Load the value held at location `slot` in transient storage.\n */\n function tload(Uint256SlotType slot) internal view returns (uint256 value) {\n /// @solidity memory-safe-assembly\n assembly {\n value := tload(slot)\n }\n }\n\n /**\n * @dev Store `value` at location `slot` in transient storage.\n */\n function tstore(Uint256SlotType slot, uint256 value) internal {\n /// @solidity memory-safe-assembly\n assembly {\n tstore(slot, value)\n }\n }\n\n /**\n * @dev Load the value held at location `slot` in transient storage.\n */\n function tload(Int256SlotType slot) internal view returns (int256 value) {\n /// @solidity memory-safe-assembly\n assembly {\n value := tload(slot)\n }\n }\n\n /**\n * @dev Store `value` at location `slot` in transient storage.\n */\n function tstore(Int256SlotType slot, int256 value) internal {\n /// @solidity memory-safe-assembly\n assembly {\n tstore(slot, value)\n }\n }\n}\n" + }, + "@openzeppelin/contracts/utils/Strings.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)\n\npragma solidity ^0.8.20;\n\nimport {Math} from \"./math/Math.sol\";\nimport {SignedMath} from \"./math/SignedMath.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n bytes16 private constant HEX_DIGITS = \"0123456789abcdef\";\n uint8 private constant ADDRESS_LENGTH = 20;\n\n /**\n * @dev The `value` string doesn't fit in the specified `length`.\n */\n error StringsInsufficientHexLength(uint256 value, uint256 length);\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n /// @solidity memory-safe-assembly\n assembly {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n /// @solidity memory-safe-assembly\n assembly {\n mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `int256` to its ASCII `string` decimal representation.\n */\n function toStringSigned(int256 value) internal pure returns (string memory) {\n return string.concat(value < 0 ? \"-\" : \"\", toString(SignedMath.abs(value)));\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n uint256 localValue = value;\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = HEX_DIGITS[localValue & 0xf];\n localValue >>= 4;\n }\n if (localValue != 0) {\n revert StringsInsufficientHexLength(value, length);\n }\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal\n * representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);\n }\n\n /**\n * @dev Returns true if the two strings are equal.\n */\n function equal(string memory a, string memory b) internal pure returns (bool) {\n return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));\n }\n}\n" + }, + "src/BookManager.sol": { + "content": "// SPDX-License-Identifier: -\n// License: https://license.clober.io/LICENSE_V2.pdf\n\npragma solidity ^0.8.20;\n\nimport {Ownable2Step, Ownable} from \"@openzeppelin/contracts/access/Ownable2Step.sol\";\nimport {SafeCast} from \"@openzeppelin/contracts/utils/math/SafeCast.sol\";\n\nimport {IBookManager} from \"./interfaces/IBookManager.sol\";\nimport {ILocker} from \"./interfaces/ILocker.sol\";\nimport {IHooks} from \"./interfaces/IHooks.sol\";\nimport {BookId, BookIdLibrary} from \"./libraries/BookId.sol\";\nimport {Book} from \"./libraries/Book.sol\";\nimport {Currency, CurrencyLibrary} from \"./libraries/Currency.sol\";\nimport {FeePolicy, FeePolicyLibrary} from \"./libraries/FeePolicy.sol\";\nimport {Tick, TickLibrary} from \"./libraries/Tick.sol\";\nimport {OrderId, OrderIdLibrary} from \"./libraries/OrderId.sol\";\nimport {Lockers} from \"./libraries/Lockers.sol\";\nimport {CurrencyDelta} from \"./libraries/CurrencyDelta.sol\";\nimport {ERC721Permit} from \"./libraries/ERC721Permit.sol\";\nimport {Hooks} from \"./libraries/Hooks.sol\";\n\ncontract BookManager is IBookManager, Ownable2Step, ERC721Permit {\n using SafeCast for *;\n using BookIdLibrary for IBookManager.BookKey;\n using TickLibrary for Tick;\n using Book for Book.State;\n using OrderIdLibrary for OrderId;\n using CurrencyLibrary for Currency;\n using FeePolicyLibrary for FeePolicy;\n using Hooks for IHooks;\n\n string public override baseURI; // slot 10\n string public override contractURI;\n address public override defaultProvider;\n\n mapping(Currency currency => uint256) public override reservesOf;\n mapping(BookId id => Book.State) internal _books;\n mapping(address provider => bool) public override isWhitelisted;\n mapping(address provider => mapping(Currency currency => uint256 amount)) public override tokenOwed;\n\n constructor(\n address owner_,\n address defaultProvider_,\n string memory baseURI_,\n string memory contractURI_,\n string memory name_,\n string memory symbol_\n ) Ownable(owner_) ERC721Permit(name_, symbol_, \"2\") {\n _setDefaultProvider(defaultProvider_);\n baseURI = baseURI_;\n contractURI = contractURI_;\n }\n\n modifier onlyByLocker() {\n _checkLocker(msg.sender);\n _;\n }\n\n function checkAuthorized(address owner, address spender, uint256 tokenId) external view {\n _checkAuthorized(owner, spender, tokenId);\n }\n\n function _checkLocker(address caller) internal view {\n address locker = Lockers.getCurrentLocker();\n IHooks hook = Lockers.getCurrentHook();\n if (caller == locker) return;\n if (caller == address(hook)) return;\n revert LockedBy(locker, address(hook));\n }\n\n function getBookKey(BookId id) external view returns (BookKey memory) {\n return _books[id].key;\n }\n\n function getOrder(OrderId id) external view returns (OrderInfo memory) {\n (BookId bookId, Tick tick, uint40 orderIndex) = id.decode();\n Book.State storage book = _books[bookId];\n Book.Order memory order = book.getOrder(tick, orderIndex);\n uint64 claimable = book.calculateClaimableUnit(tick, orderIndex);\n unchecked {\n return OrderInfo({provider: order.provider, open: order.pending - claimable, claimable: claimable});\n }\n }\n\n function open(BookKey calldata key, bytes calldata hookData) external onlyByLocker {\n // @dev Also, the book opener should set unit size at least circulatingTotalSupply / type(uint64).max to avoid overflow.\n // But it is not checked here because it is not possible to check it without knowing circulatingTotalSupply.\n if (key.unitSize == 0) revert InvalidUnitSize();\n\n FeePolicy makerPolicy = key.makerPolicy;\n FeePolicy takerPolicy = key.takerPolicy;\n if (!(makerPolicy.isValid() && takerPolicy.isValid())) revert InvalidFeePolicy();\n unchecked {\n if (makerPolicy.rate() + takerPolicy.rate() < 0) revert InvalidFeePolicy();\n }\n if (makerPolicy.rate() < 0 || takerPolicy.rate() < 0) {\n if (makerPolicy.usesQuote() != takerPolicy.usesQuote()) revert InvalidFeePolicy();\n }\n IHooks hooks = key.hooks;\n if (!hooks.isValidHookAddress()) revert Hooks.HookAddressNotValid(address(hooks));\n\n hooks.beforeOpen(key, hookData);\n\n BookId id = key.toId();\n _books[id].open(key);\n\n emit Open(id, key.base, key.quote, key.unitSize, makerPolicy, takerPolicy, hooks);\n\n hooks.afterOpen(key, hookData);\n }\n\n function lock(address locker, bytes calldata data) external returns (bytes memory result) {\n // Add the locker to the stack\n Lockers.push(locker, msg.sender);\n\n // The locker does everything in this callback, including paying what they owe via calls to settle\n result = ILocker(locker).lockAcquired(msg.sender, data);\n\n // Remove the locker from the stack\n Lockers.pop();\n\n (uint128 length, uint128 nonzeroDeltaCount) = Lockers.lockData();\n // @dev The locker must settle all currency balances to zero.\n if (length == 0 && nonzeroDeltaCount != 0) revert CurrencyNotSettled();\n }\n\n function getCurrencyDelta(address locker, Currency currency) external view returns (int256) {\n return CurrencyDelta.get(locker, currency);\n }\n\n function getLock(uint256 i) external view returns (address, address) {\n return (Lockers.getLocker(i), Lockers.getLockCaller(i));\n }\n\n function getLockData() external view returns (uint128, uint128) {\n return Lockers.lockData();\n }\n\n function getDepth(BookId id, Tick tick) external view returns (uint64) {\n return _books[id].depth(tick);\n }\n\n function getHighest(BookId id) external view returns (Tick) {\n return _books[id].highest();\n }\n\n function maxLessThan(BookId id, Tick tick) external view returns (Tick) {\n return _books[id].maxLessThan(tick);\n }\n\n function isOpened(BookId id) external view returns (bool) {\n return _books[id].isOpened();\n }\n\n function isEmpty(BookId id) external view returns (bool) {\n return _books[id].isEmpty();\n }\n\n function encodeBookKey(BookKey calldata key) external pure returns (BookId) {\n return key.toId();\n }\n\n function make(MakeParams calldata params, bytes calldata hookData)\n external\n onlyByLocker\n returns (OrderId id, uint256 quoteAmount)\n {\n if (params.provider != address(0) && !isWhitelisted[params.provider]) revert InvalidProvider(params.provider);\n params.tick.validateTick();\n BookId bookId = params.key.toId();\n Book.State storage book = _books[bookId];\n book.checkOpened();\n\n params.key.hooks.beforeMake(params, hookData);\n\n uint40 orderIndex = book.make(params.tick, params.unit, params.provider);\n id = OrderIdLibrary.encode(bookId, params.tick, orderIndex);\n int256 quoteDelta;\n unchecked {\n // @dev uint64 * uint64 < type(uint256).max\n quoteAmount = uint256(params.unit) * params.key.unitSize;\n\n // @dev 0 < uint64 * uint64 + rate * uint64 * uint64 < type(int256).max\n quoteDelta = int256(quoteAmount);\n if (params.key.makerPolicy.usesQuote()) {\n quoteDelta += params.key.makerPolicy.calculateFee(quoteAmount, false);\n quoteAmount = uint256(quoteDelta);\n }\n }\n\n _accountDelta(params.key.quote, -quoteDelta);\n\n _mint(msg.sender, OrderId.unwrap(id));\n\n emit Make(bookId, msg.sender, params.tick, orderIndex, params.unit, params.provider);\n\n params.key.hooks.afterMake(params, id, hookData);\n }\n\n function take(TakeParams calldata params, bytes calldata hookData)\n external\n onlyByLocker\n returns (uint256 quoteAmount, uint256 baseAmount)\n {\n params.tick.validateTick();\n BookId bookId = params.key.toId();\n Book.State storage book = _books[bookId];\n book.checkOpened();\n\n params.key.hooks.beforeTake(params, hookData);\n\n uint64 takenUnit = book.take(params.tick, params.maxUnit);\n unchecked {\n quoteAmount = uint256(takenUnit) * params.key.unitSize;\n }\n baseAmount = params.tick.quoteToBase(quoteAmount, true);\n\n int256 quoteDelta = int256(quoteAmount);\n int256 baseDelta = baseAmount.toInt256();\n if (params.key.takerPolicy.usesQuote()) {\n quoteDelta -= params.key.takerPolicy.calculateFee(quoteAmount, false);\n quoteAmount = uint256(quoteDelta);\n } else {\n baseDelta += params.key.takerPolicy.calculateFee(baseAmount, false);\n baseAmount = uint256(baseDelta);\n }\n _accountDelta(params.key.quote, quoteDelta);\n _accountDelta(params.key.base, -baseDelta);\n\n emit Take(bookId, msg.sender, params.tick, takenUnit);\n\n params.key.hooks.afterTake(params, takenUnit, hookData);\n }\n\n function cancel(CancelParams calldata params, bytes calldata hookData)\n external\n onlyByLocker\n returns (uint256 canceledAmount)\n {\n _checkAuthorized(_ownerOf(OrderId.unwrap(params.id)), msg.sender, OrderId.unwrap(params.id));\n\n Book.State storage book = _books[params.id.getBookId()];\n BookKey memory key = book.key;\n\n key.hooks.beforeCancel(params, hookData);\n\n (uint64 canceledUnit, uint64 pendingUnit) = book.cancel(params.id, params.toUnit);\n\n unchecked {\n canceledAmount = uint256(canceledUnit) * key.unitSize;\n if (key.makerPolicy.usesQuote()) {\n int256 quoteFee = key.makerPolicy.calculateFee(canceledAmount, true);\n canceledAmount = uint256(int256(canceledAmount) + quoteFee);\n }\n }\n\n if (pendingUnit == 0) _burn(OrderId.unwrap(params.id));\n\n _accountDelta(key.quote, int256(canceledAmount));\n\n emit Cancel(params.id, canceledUnit);\n\n key.hooks.afterCancel(params, canceledUnit, hookData);\n }\n\n function claim(OrderId id, bytes calldata hookData) external onlyByLocker returns (uint256 claimedAmount) {\n _checkAuthorized(_ownerOf(OrderId.unwrap(id)), msg.sender, OrderId.unwrap(id));\n\n Tick tick;\n uint40 orderIndex;\n Book.State storage book;\n {\n BookId bookId;\n (bookId, tick, orderIndex) = id.decode();\n book = _books[bookId];\n }\n IBookManager.BookKey memory key = book.key;\n\n key.hooks.beforeClaim(id, hookData);\n\n uint64 claimedUnit = book.claim(tick, orderIndex);\n\n int256 quoteFee;\n int256 baseFee;\n {\n uint256 claimedInQuote;\n unchecked {\n claimedInQuote = uint256(claimedUnit) * key.unitSize;\n }\n claimedAmount = tick.quoteToBase(claimedInQuote, false);\n\n FeePolicy makerPolicy = key.makerPolicy;\n FeePolicy takerPolicy = key.takerPolicy;\n if (takerPolicy.usesQuote()) {\n quoteFee = takerPolicy.calculateFee(claimedInQuote, true);\n } else {\n baseFee = takerPolicy.calculateFee(claimedAmount, true);\n }\n\n if (makerPolicy.usesQuote()) {\n quoteFee += makerPolicy.calculateFee(claimedInQuote, true);\n } else {\n int256 makeFee = makerPolicy.calculateFee(claimedAmount, false);\n baseFee += makeFee;\n claimedAmount = makeFee > 0 ? claimedAmount - uint256(makeFee) : claimedAmount + uint256(-makeFee);\n }\n }\n\n Book.Order memory order = book.getOrder(tick, orderIndex);\n address provider = order.provider;\n if (provider == address(0)) provider = defaultProvider;\n if (quoteFee > 0) tokenOwed[provider][key.quote] += quoteFee.toUint256();\n if (baseFee > 0) tokenOwed[provider][key.base] += baseFee.toUint256();\n\n if (order.pending == 0) _burn(OrderId.unwrap(id));\n\n _accountDelta(key.base, claimedAmount.toInt256());\n\n emit Claim(id, claimedUnit);\n\n key.hooks.afterClaim(id, claimedUnit, hookData);\n }\n\n function collect(address recipient, Currency currency) external returns (uint256 amount) {\n amount = tokenOwed[msg.sender][currency];\n tokenOwed[msg.sender][currency] = 0;\n reservesOf[currency] -= amount;\n currency.transfer(recipient, amount);\n emit Collect(msg.sender, recipient, currency, amount);\n }\n\n function withdraw(Currency currency, address to, uint256 amount) external onlyByLocker {\n if (amount > 0) {\n _accountDelta(currency, -amount.toInt256());\n reservesOf[currency] -= amount;\n currency.transfer(to, amount);\n }\n }\n\n function settle(Currency currency) external payable onlyByLocker returns (uint256 paid) {\n uint256 reservesBefore = reservesOf[currency];\n reservesOf[currency] = currency.balanceOfSelf();\n paid = reservesOf[currency] - reservesBefore;\n // subtraction must be safe\n _accountDelta(currency, paid.toInt256());\n }\n\n function whitelist(address provider) external onlyOwner {\n isWhitelisted[provider] = true;\n emit Whitelist(provider);\n }\n\n function delist(address provider) external onlyOwner {\n isWhitelisted[provider] = false;\n emit Delist(provider);\n }\n\n function setDefaultProvider(address newDefaultProvider) external onlyOwner {\n _setDefaultProvider(newDefaultProvider);\n }\n\n function _setDefaultProvider(address newDefaultProvider) internal {\n defaultProvider = newDefaultProvider;\n emit SetDefaultProvider(newDefaultProvider);\n }\n\n function _baseURI() internal view override returns (string memory) {\n return baseURI;\n }\n\n function _accountDelta(Currency currency, int256 delta) internal {\n if (delta == 0) return;\n\n address locker = Lockers.getCurrentLocker();\n int256 next = CurrencyDelta.add(locker, currency, delta);\n\n if (next == 0) Lockers.decrementNonzeroDeltaCount();\n else if (next == delta) Lockers.incrementNonzeroDeltaCount();\n }\n\n function load(bytes32 slot) external view returns (bytes32 value) {\n assembly {\n value := sload(slot)\n }\n }\n\n function load(bytes32 startSlot, uint256 nSlot) external view returns (bytes memory value) {\n value = new bytes(32 * nSlot);\n\n assembly {\n for { let i := 0 } lt(i, nSlot) { i := add(i, 1) } {\n mstore(add(value, mul(add(i, 1), 32)), sload(add(startSlot, i)))\n }\n }\n }\n\n receive() external payable {}\n}\n" + }, + "src/interfaces/IBookManager.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport {IERC721Metadata} from \"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol\";\n\nimport {BookId} from \"../libraries/BookId.sol\";\nimport {Currency} from \"../libraries/Currency.sol\";\nimport {OrderId} from \"../libraries/OrderId.sol\";\nimport {Tick} from \"../libraries/Tick.sol\";\nimport {FeePolicy} from \"../libraries/FeePolicy.sol\";\nimport {IERC721Permit} from \"./IERC721Permit.sol\";\nimport {IHooks} from \"./IHooks.sol\";\n\n/**\n * @title IBookManager\n * @notice The interface for the BookManager contract\n */\ninterface IBookManager is IERC721Metadata, IERC721Permit {\n error InvalidUnitSize();\n error InvalidFeePolicy();\n error InvalidProvider(address provider);\n error LockedBy(address locker, address hook);\n error CurrencyNotSettled();\n\n /**\n * @notice Event emitted when a new book is opened\n * @param id The book id\n * @param base The base currency\n * @param quote The quote currency\n * @param unitSize The unit size of the book\n * @param makerPolicy The maker fee policy\n * @param takerPolicy The taker fee policy\n * @param hooks The hooks contract\n */\n event Open(\n BookId indexed id,\n Currency indexed base,\n Currency indexed quote,\n uint64 unitSize,\n FeePolicy makerPolicy,\n FeePolicy takerPolicy,\n IHooks hooks\n );\n\n /**\n * @notice Event emitted when a new order is made\n * @param bookId The book id\n * @param user The user address\n * @param tick The order tick\n * @param orderIndex The order index\n * @param unit The order unit\n * @param provider The provider address\n */\n event Make(\n BookId indexed bookId, address indexed user, Tick tick, uint256 orderIndex, uint64 unit, address provider\n );\n\n /**\n * @notice Event emitted when an order is taken\n * @param bookId The book id\n * @param user The user address\n * @param tick The order tick\n * @param unit The order unit\n */\n event Take(BookId indexed bookId, address indexed user, Tick tick, uint64 unit);\n\n /**\n * @notice Event emitted when an order is canceled\n * @param orderId The order id\n * @param unit The canceled unit\n */\n event Cancel(OrderId indexed orderId, uint64 unit);\n\n /**\n * @notice Event emitted when an order is claimed\n * @param orderId The order id\n * @param unit The claimed unit\n */\n event Claim(OrderId indexed orderId, uint64 unit);\n\n /**\n * @notice Event emitted when a provider is whitelisted\n * @param provider The provider address\n */\n event Whitelist(address indexed provider);\n\n /**\n * @notice Event emitted when a provider is delisted\n * @param provider The provider address\n */\n event Delist(address indexed provider);\n\n /**\n * @notice Event emitted when a provider collects fees\n * @param provider The provider address\n * @param recipient The recipient address\n * @param currency The currency\n * @param amount The collected amount\n */\n event Collect(address indexed provider, address indexed recipient, Currency indexed currency, uint256 amount);\n\n /**\n * @notice Event emitted when new default provider is set\n * @param newDefaultProvider The new default provider address\n */\n event SetDefaultProvider(address indexed newDefaultProvider);\n\n /**\n * @notice This structure represents a unique identifier for a book in the BookManager.\n * @param base The base currency of the book\n * @param unitSize The unit size of the book\n * @param quote The quote currency of the book\n * @param makerPolicy The maker fee policy of the book\n * @param hooks The hooks contract of the book\n * @param takerPolicy The taker fee policy of the book\n */\n struct BookKey {\n Currency base;\n uint64 unitSize;\n Currency quote;\n FeePolicy makerPolicy;\n IHooks hooks;\n FeePolicy takerPolicy;\n }\n\n /**\n * @notice Returns the base URI\n * @return The base URI\n */\n function baseURI() external view returns (string memory);\n\n /**\n * @notice Returns the contract URI\n * @return The contract URI\n */\n function contractURI() external view returns (string memory);\n\n /**\n * @notice Returns the default provider\n * @return The default provider\n */\n function defaultProvider() external view returns (address);\n\n /**\n * @notice Returns the total reserves of a given currency\n * @param currency The currency in question\n * @return The total reserves amount\n */\n function reservesOf(Currency currency) external view returns (uint256);\n\n /**\n * @notice Checks if a provider is whitelisted\n * @param provider The address of the provider\n * @return True if the provider is whitelisted, false otherwise\n */\n function isWhitelisted(address provider) external view returns (bool);\n\n /**\n * @notice Verifies if an owner has authorized a spender for a token\n * @param owner The address of the token owner\n * @param spender The address of the spender\n * @param tokenId The token ID\n */\n function checkAuthorized(address owner, address spender, uint256 tokenId) external view;\n\n /**\n * @notice Calculates the amount owed to a provider in a given currency\n * @param provider The provider's address\n * @param currency The currency in question\n * @return The owed amount\n */\n function tokenOwed(address provider, Currency currency) external view returns (uint256);\n\n /**\n * @notice Calculates the currency balance changes for a given locker\n * @param locker The address of the locker\n * @param currency The currency in question\n * @return The net change in currency balance\n */\n function getCurrencyDelta(address locker, Currency currency) external view returns (int256);\n\n /**\n * @notice Retrieves the book key for a given book ID\n * @param id The book ID\n * @return The book key\n */\n function getBookKey(BookId id) external view returns (BookKey memory);\n\n /**\n * @notice This structure represents a current status for an order in the BookManager.\n * @param provider The provider of the order\n * @param open The open unit of the order\n * @param claimable The claimable unit of the order\n */\n struct OrderInfo {\n address provider;\n uint64 open;\n uint64 claimable;\n }\n\n /**\n * @notice Provides information about an order\n * @param id The order ID\n * @return Order information including provider, open status, and claimable unit\n */\n function getOrder(OrderId id) external view returns (OrderInfo memory);\n\n /**\n * @notice Retrieves the locker and caller addresses for a given lock\n * @param i The index of the lock\n * @return locker The locker's address\n * @return lockCaller The caller's address\n */\n function getLock(uint256 i) external view returns (address locker, address lockCaller);\n\n /**\n * @notice Provides the lock data\n * @return The lock data including necessary numeric values\n */\n function getLockData() external view returns (uint128, uint128);\n\n /**\n * @notice Returns the depth of a given book ID and tick\n * @param id The book ID\n * @param tick The tick\n * @return The depth of the tick\n */\n function getDepth(BookId id, Tick tick) external view returns (uint64);\n\n /**\n * @notice Retrieves the highest tick for a given book ID\n * @param id The book ID\n * @return tick The highest tick\n */\n function getHighest(BookId id) external view returns (Tick tick);\n\n /**\n * @notice Finds the maximum tick less than a specified tick in a book\n * @dev Returns `Tick.wrap(type(int24).min)` if the specified tick is the lowest\n * @param id The book ID\n * @param tick The specified tick\n * @return The next lower tick\n */\n function maxLessThan(BookId id, Tick tick) external view returns (Tick);\n\n /**\n * @notice Checks if a book is opened\n * @param id The book ID\n * @return True if the book is opened, false otherwise\n */\n function isOpened(BookId id) external view returns (bool);\n\n /**\n * @notice Checks if a book is empty\n * @param id The book ID\n * @return True if the book is empty, false otherwise\n */\n function isEmpty(BookId id) external view returns (bool);\n\n /**\n * @notice Encodes a BookKey into a BookId\n * @param key The BookKey to encode\n * @return The encoded BookId\n */\n function encodeBookKey(BookKey calldata key) external pure returns (BookId);\n\n /**\n * @notice Loads a value from a specific storage slot\n * @param slot The storage slot\n * @return The value in the slot\n */\n function load(bytes32 slot) external view returns (bytes32);\n\n /**\n * @notice Loads a sequence of values starting from a specific slot\n * @param startSlot The starting slot\n * @param nSlot The number of slots to load\n * @return The sequence of values\n */\n function load(bytes32 startSlot, uint256 nSlot) external view returns (bytes memory);\n\n /**\n * @notice Opens a new book\n * @param key The book key\n * @param hookData The hook data\n */\n function open(BookKey calldata key, bytes calldata hookData) external;\n\n /**\n * @notice Locks a book manager function\n * @param locker The locker address\n * @param data The lock data\n * @return The lock return data\n */\n function lock(address locker, bytes calldata data) external returns (bytes memory);\n\n /**\n * @notice This structure represents the parameters for making an order.\n * @param key The book key for the order\n * @param tick The tick for the order\n * @param unit The unit for the order. Times key.unitSize to get actual bid amount.\n * @param provider The provider for the order. The limit order service provider address to collect fees.\n */\n struct MakeParams {\n BookKey key;\n Tick tick;\n uint64 unit;\n address provider;\n }\n\n /**\n * @notice Make a limit order\n * @param params The order parameters\n * @param hookData The hook data\n * @return id The order id. Returns 0 if the order is not settled\n * @return quoteAmount The amount of quote currency to be paid\n */\n function make(MakeParams calldata params, bytes calldata hookData)\n external\n returns (OrderId id, uint256 quoteAmount);\n\n /**\n * @notice This structure represents the parameters for taking orders in the specified tick.\n * @param key The book key for the order\n * @param tick The tick for the order\n * @param maxUnit The max unit to take\n */\n struct TakeParams {\n BookKey key;\n Tick tick;\n uint64 maxUnit;\n }\n\n /**\n * @notice Take a limit order at specific tick\n * @param params The order parameters\n * @param hookData The hook data\n * @return quoteAmount The amount of quote currency to be received\n * @return baseAmount The amount of base currency to be paid\n */\n function take(TakeParams calldata params, bytes calldata hookData)\n external\n returns (uint256 quoteAmount, uint256 baseAmount);\n\n /**\n * @notice This structure represents the parameters for canceling an order.\n * @param id The order id for the order\n * @param toUnit The remaining open unit for the order after cancellation. Must not exceed the current open unit.\n */\n struct CancelParams {\n OrderId id;\n uint64 toUnit;\n }\n\n /**\n * @notice Cancel a limit order\n * @param params The order parameters\n * @param hookData The hook data\n * @return canceledAmount The amount of quote currency canceled\n */\n function cancel(CancelParams calldata params, bytes calldata hookData) external returns (uint256 canceledAmount);\n\n /**\n * @notice Claims an order\n * @param id The order ID\n * @param hookData The hook data\n * @return claimedAmount The amount claimed\n */\n function claim(OrderId id, bytes calldata hookData) external returns (uint256 claimedAmount);\n\n /**\n * @notice Collects fees from a provider\n * @param recipient The recipient address\n * @param currency The currency\n * @return The collected amount\n */\n function collect(address recipient, Currency currency) external returns (uint256);\n\n /**\n * @notice Withdraws a currency\n * @param currency The currency\n * @param to The recipient address\n * @param amount The amount\n */\n function withdraw(Currency currency, address to, uint256 amount) external;\n\n /**\n * @notice Settles a currency\n * @param currency The currency\n * @return The settled amount\n */\n function settle(Currency currency) external payable returns (uint256);\n\n /**\n * @notice Whitelists a provider\n * @param provider The provider address\n */\n function whitelist(address provider) external;\n\n /**\n * @notice Delists a provider\n * @param provider The provider address\n */\n function delist(address provider) external;\n\n /**\n * @notice Sets the default provider\n * @param newDefaultProvider The new default provider address\n */\n function setDefaultProvider(address newDefaultProvider) external;\n}\n" + }, + "src/interfaces/IERC721Permit.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport {IERC721} from \"@openzeppelin/contracts/token/ERC721/IERC721.sol\";\n\n/**\n * @title IERC721Permit\n * @notice An interface for the ERC721 permit extension\n */\ninterface IERC721Permit is IERC721 {\n error InvalidSignature();\n error PermitExpired();\n\n /**\n * @notice The EIP-712 typehash for the permit struct used by the contract\n */\n function PERMIT_TYPEHASH() external pure returns (bytes32);\n\n /**\n * @notice The EIP-712 domain separator for this contract\n */\n function DOMAIN_SEPARATOR() external view returns (bytes32);\n\n /**\n * @notice Approve the spender to transfer the given tokenId\n * @param spender The address to approve\n * @param tokenId The tokenId to approve\n * @param deadline The deadline for the signature\n * @param v The recovery id of the signature\n * @param r The r value of the signature\n * @param s The s value of the signature\n */\n function permit(address spender, uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external;\n\n /**\n * @notice Get the current nonce for a token\n * @param tokenId The tokenId to get the nonce for\n * @return The current nonce\n */\n function nonces(uint256 tokenId) external view returns (uint256);\n}\n" + }, + "src/interfaces/IHooks.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport {IBookManager} from \"./IBookManager.sol\";\nimport {OrderId} from \"../libraries/OrderId.sol\";\n\n/**\n * @title IHooks\n * @notice Interface for the hooks contract\n */\ninterface IHooks {\n /**\n * @notice Hook called before opening a new book\n * @param sender The sender of the open transaction\n * @param key The key of the book being opened\n * @param hookData The data passed to the hook\n * @return Returns the function selector if the hook is successful\n */\n function beforeOpen(address sender, IBookManager.BookKey calldata key, bytes calldata hookData)\n external\n returns (bytes4);\n\n /**\n * @notice Hook called after opening a new book\n * @param sender The sender of the open transaction\n * @param key The key of the book being opened\n * @param hookData The data passed to the hook\n * @return Returns the function selector if the hook is successful\n */\n function afterOpen(address sender, IBookManager.BookKey calldata key, bytes calldata hookData)\n external\n returns (bytes4);\n\n /**\n * @notice Hook called before making a new order\n * @param sender The sender of the make transaction\n * @param params The parameters of the make transaction\n * @param hookData The data passed to the hook\n * @return Returns the function selector if the hook is successful\n */\n function beforeMake(address sender, IBookManager.MakeParams calldata params, bytes calldata hookData)\n external\n returns (bytes4);\n\n /**\n * @notice Hook called after making a new order\n * @param sender The sender of the make transaction\n * @param params The parameters of the make transaction\n * @param orderId The id of the order that was made\n * @param hookData The data passed to the hook\n * @return Returns the function selector if the hook is successful\n */\n function afterMake(\n address sender,\n IBookManager.MakeParams calldata params,\n OrderId orderId,\n bytes calldata hookData\n ) external returns (bytes4);\n\n /**\n * @notice Hook called before taking an order\n * @param sender The sender of the take transaction\n * @param params The parameters of the take transaction\n * @param hookData The data passed to the hook\n * @return Returns the function selector if the hook is successful\n */\n function beforeTake(address sender, IBookManager.TakeParams calldata params, bytes calldata hookData)\n external\n returns (bytes4);\n\n /**\n * @notice Hook called after taking an order\n * @param sender The sender of the take transaction\n * @param params The parameters of the take transaction\n * @param takenUnit The unit that was taken\n * @param hookData The data passed to the hook\n * @return Returns the function selector if the hook is successful\n */\n function afterTake(\n address sender,\n IBookManager.TakeParams calldata params,\n uint64 takenUnit,\n bytes calldata hookData\n ) external returns (bytes4);\n\n /**\n * @notice Hook called before canceling an order\n * @param sender The sender of the cancel transaction\n * @param params The parameters of the cancel transaction\n * @param hookData The data passed to the hook\n * @return Returns the function selector if the hook is successful\n */\n function beforeCancel(address sender, IBookManager.CancelParams calldata params, bytes calldata hookData)\n external\n returns (bytes4);\n\n /**\n * @notice Hook called after canceling an order\n * @param sender The sender of the cancel transaction\n * @param params The parameters of the cancel transaction\n * @param canceledUnit The unit that was canceled\n * @param hookData The data passed to the hook\n * @return Returns the function selector if the hook is successful\n */\n function afterCancel(\n address sender,\n IBookManager.CancelParams calldata params,\n uint64 canceledUnit,\n bytes calldata hookData\n ) external returns (bytes4);\n\n /**\n * @notice Hook called before claiming an order\n * @param sender The sender of the claim transaction\n * @param orderId The id of the order being claimed\n * @param hookData The data passed to the hook\n * @return Returns the function selector if the hook is successful\n */\n function beforeClaim(address sender, OrderId orderId, bytes calldata hookData) external returns (bytes4);\n\n /**\n * @notice Hook called after claiming an order\n * @param sender The sender of the claim transaction\n * @param orderId The id of the order being claimed\n * @param claimedUnit The unit that was claimed\n * @param hookData The data passed to the hook\n * @return Returns the function selector if the hook is successful\n */\n function afterClaim(address sender, OrderId orderId, uint64 claimedUnit, bytes calldata hookData)\n external\n returns (bytes4);\n}\n" + }, + "src/interfaces/ILocker.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\n/**\n * @title ILocker\n * @notice Interface for the locker contract\n */\ninterface ILocker {\n /**\n * @notice Called by the book manager on `msg.sender` when a lock is acquired\n * @param data The data that was passed to the call to lock\n * @return Any data that you want to be returned from the lock call\n */\n function lockAcquired(address lockCaller, bytes calldata data) external returns (bytes memory);\n}\n" + }, + "src/interfaces/uniswap-v3/IUniswapV3SwapCallback.sol": { + "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Callback for IUniswapV3PoolActions#swap\n/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface\ninterface IUniswapV3SwapCallback {\n /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.\n /// @dev In the implementation you must pay the pool tokens owed for the swap.\n /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.\n /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.\n /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by\n /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.\n /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by\n /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.\n /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call\n function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external;\n}\n" + }, + "src/libraries/Book.sol": { + "content": "// SPDX-License-Identifier: -\n// License: https://license.clober.io/LICENSE_V2.pdf\n\npragma solidity ^0.8.20;\n\nimport {SafeCast} from \"@openzeppelin/contracts/utils/math/SafeCast.sol\";\n\nimport {IBookManager} from \"../interfaces/IBookManager.sol\";\nimport {SegmentedSegmentTree} from \"./SegmentedSegmentTree.sol\";\nimport {Tick, TickLibrary} from \"./Tick.sol\";\nimport {OrderId, OrderIdLibrary} from \"./OrderId.sol\";\nimport {TotalClaimableMap} from \"./TotalClaimableMap.sol\";\nimport {TickBitmap} from \"./TickBitmap.sol\";\n\nlibrary Book {\n using Book for State;\n using TickBitmap for mapping(uint256 => uint256);\n using SegmentedSegmentTree for SegmentedSegmentTree.Core;\n using TotalClaimableMap for mapping(uint24 => uint256);\n using TickLibrary for Tick;\n using OrderIdLibrary for OrderId;\n\n error ZeroUnit();\n error BookAlreadyOpened();\n error BookNotOpened();\n error QueueReplaceFailed();\n error CancelFailed(uint64 maxCancelableUnit);\n\n // @dev Due to the segment tree implementation, the maximum order size is 2 ** 15.\n uint40 internal constant MAX_ORDER = 2 ** 15; // 32768\n uint256 internal constant MAX_ORDER_M = 2 ** 15 - 1; // % 32768\n\n struct Order {\n address provider;\n uint64 pending; // @dev unfilled unit + filled(claimable) unit\n }\n\n struct Queue {\n SegmentedSegmentTree.Core tree;\n Order[] orders;\n }\n\n struct State {\n IBookManager.BookKey key;\n mapping(Tick tick => Queue) queues;\n mapping(uint256 => uint256) tickBitmap;\n // @dev Four values of totalClaimable are stored in one uint256\n mapping(uint24 groupIndex => uint256) totalClaimableOf;\n }\n\n function open(State storage self, IBookManager.BookKey calldata key) external {\n if (self.isOpened()) revert BookAlreadyOpened();\n self.key = key;\n }\n\n function isOpened(State storage self) internal view returns (bool) {\n return self.key.unitSize != 0;\n }\n\n function checkOpened(State storage self) internal view {\n if (!self.isOpened()) revert BookNotOpened();\n }\n\n function depth(State storage self, Tick tick) internal view returns (uint64) {\n return self.queues[tick].tree.total() - self.totalClaimableOf.get(tick);\n }\n\n function highest(State storage self) internal view returns (Tick) {\n return self.tickBitmap.highest();\n }\n\n function maxLessThan(State storage self, Tick tick) internal view returns (Tick) {\n return self.tickBitmap.maxLessThan(tick);\n }\n\n function isEmpty(State storage self) internal view returns (bool) {\n return self.tickBitmap.isEmpty();\n }\n\n function _getOrder(State storage self, Tick tick, uint40 index) private view returns (Order storage) {\n return self.queues[tick].orders[index];\n }\n\n function getOrder(State storage self, Tick tick, uint40 index) internal view returns (Order memory) {\n return _getOrder(self, tick, index);\n }\n\n function make(State storage self, Tick tick, uint64 unit, address provider) external returns (uint40 orderIndex) {\n if (unit == 0) revert ZeroUnit();\n if (!self.tickBitmap.has(tick)) self.tickBitmap.set(tick);\n\n Queue storage queue = self.queues[tick];\n // @dev Assume that orders.length cannot reach to type(uint40).max + 1.\n orderIndex = SafeCast.toUint40(queue.orders.length);\n\n if (orderIndex >= MAX_ORDER) {\n unchecked {\n uint40 staleOrderIndex = orderIndex - MAX_ORDER;\n uint64 stalePendingUnit = queue.orders[staleOrderIndex].pending;\n if (stalePendingUnit > 0) {\n // If the order is not settled completely, we cannot replace it\n uint64 claimable = calculateClaimableUnit(self, tick, staleOrderIndex);\n if (claimable != stalePendingUnit) revert QueueReplaceFailed();\n }\n }\n\n // The stale order is settled completely, so remove it from the totalClaimableOf.\n // We can determine the stale order is claimable.\n uint64 staleOrderedUnit = queue.tree.get(orderIndex & MAX_ORDER_M);\n if (staleOrderedUnit > 0) self.totalClaimableOf.sub(tick, staleOrderedUnit);\n }\n\n queue.tree.update(orderIndex & MAX_ORDER_M, unit);\n\n queue.orders.push(Order({pending: unit, provider: provider}));\n }\n\n /**\n * @notice Take orders from the book\n * @param self The book state\n * @param maxTakeUnit The maximum unit to take\n * @return takenUnit The actual unit to take\n */\n function take(State storage self, Tick tick, uint64 maxTakeUnit) external returns (uint64 takenUnit) {\n uint64 currentDepth = depth(self, tick);\n if (currentDepth > maxTakeUnit) {\n takenUnit = maxTakeUnit;\n } else {\n takenUnit = currentDepth;\n self.tickBitmap.clear(tick);\n }\n\n self.totalClaimableOf.add(tick, takenUnit);\n }\n\n function cancel(State storage self, OrderId orderId, uint64 to)\n external\n returns (uint64 canceled, uint64 afterPending)\n {\n (, Tick tick, uint40 orderIndex) = orderId.decode();\n Queue storage queue = self.queues[tick];\n uint64 pendingUnit = queue.orders[orderIndex].pending;\n uint64 claimableUnit = calculateClaimableUnit(self, tick, orderIndex);\n afterPending = to + claimableUnit;\n unchecked {\n if (pendingUnit < afterPending) revert CancelFailed(pendingUnit - claimableUnit);\n canceled = pendingUnit - afterPending;\n\n self.queues[tick].tree.update(\n orderIndex & MAX_ORDER_M, self.queues[tick].tree.get(orderIndex & MAX_ORDER_M) - canceled\n );\n }\n queue.orders[orderIndex].pending = afterPending;\n\n if (depth(self, tick) == 0) {\n // clear() won't revert so we can cancel with to=0 even if the depth() is already zero\n // works even if bitmap is empty\n self.tickBitmap.clear(tick);\n }\n }\n\n function claim(State storage self, Tick tick, uint40 index) external returns (uint64 claimedUnit) {\n Order storage order = _getOrder(self, tick, index);\n\n claimedUnit = calculateClaimableUnit(self, tick, index);\n unchecked {\n order.pending -= claimedUnit;\n }\n }\n\n function calculateClaimableUnit(State storage self, Tick tick, uint40 index) public view returns (uint64) {\n uint64 orderUnit = self.getOrder(tick, index).pending;\n\n Queue storage queue = self.queues[tick];\n // @dev Book logic always considers replaced orders as claimable.\n unchecked {\n if (uint256(index) + MAX_ORDER < queue.orders.length) return orderUnit;\n uint64 totalClaimableUnit = self.totalClaimableOf.get(tick);\n uint64 rangeRight = _getClaimRangeRight(queue, index);\n if (rangeRight - orderUnit >= totalClaimableUnit) return 0;\n\n // -------- totalClaimable ---------|---\n // ------|---- orderUnit ----|--------\n // rangeLeft rangeRight\n if (rangeRight <= totalClaimableUnit) return orderUnit;\n // -- totalClaimable --|----------------\n // ------|---- orderUnit ----|--------\n // rangeLeft rangeRight\n else return totalClaimableUnit - (rangeRight - orderUnit);\n }\n }\n\n function _getClaimRangeRight(Queue storage queue, uint256 orderIndex) private view returns (uint64 rangeRight) {\n uint256 l = queue.orders.length & MAX_ORDER_M;\n uint256 r = (orderIndex + 1) & MAX_ORDER_M;\n rangeRight = (l < r) ? queue.tree.query(l, r) : queue.tree.total() - queue.tree.query(r, l);\n }\n}\n" + }, + "src/libraries/BookId.sol": { + "content": "// SPDX-License-Identifier: GPL-2.0-or-later\n\npragma solidity ^0.8.20;\n\nimport {IBookManager} from \"../interfaces/IBookManager.sol\";\n\ntype BookId is uint192;\n\nlibrary BookIdLibrary {\n function toId(IBookManager.BookKey memory bookKey) internal pure returns (BookId id) {\n bytes32 hash = keccak256(abi.encode(bookKey));\n assembly {\n id := and(hash, 0xffffffffffffffffffffffffffffffffffffffffffffffff)\n }\n }\n}\n" + }, + "src/libraries/Currency.sol": { + "content": "// SPDX-License-Identifier: GPL-2.0-or-later\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\ntype Currency is address;\n\n/// @title CurrencyLibrary\n/// @dev This library allows for transferring and holding native tokens and ERC20 tokens\nlibrary CurrencyLibrary {\n using CurrencyLibrary for Currency;\n\n /// @notice Thrown when a native transfer fails\n error NativeTransferFailed();\n\n /// @notice Thrown when an ERC20 transfer fails\n error ERC20TransferFailed();\n\n Currency public constant NATIVE = Currency.wrap(address(0));\n\n function transfer(Currency currency, address to, uint256 amount) internal {\n // implementation from\n // https://github.com/transmissions11/solmate/blob/e8f96f25d48fe702117ce76c79228ca4f20206cb/src/utils/SafeTransferLib.sol\n\n bool success;\n if (currency.isNative()) {\n assembly {\n // Transfer the ETH and store if it succeeded or not.\n success := call(gas(), to, amount, 0, 0, 0, 0)\n }\n\n if (!success) revert NativeTransferFailed();\n } else {\n assembly {\n // Get a pointer to some free memory.\n let freeMemoryPointer := mload(0x40)\n\n // Write the abi-encoded calldata into memory, beginning with the function selector.\n mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)\n mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the \"to\" argument.\n mstore(add(freeMemoryPointer, 36), amount) // Append the \"amount\" argument. Masking not required as it's a full 32 byte type.\n\n success :=\n and(\n // Set success to whether the call reverted, if not we check it either\n // returned exactly 1 (can't just be non-zero data), or had no return data.\n or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),\n // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.\n // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.\n // Counterintuitively, this call must be positioned second to the or() call in the\n // surrounding and() call or else returndatasize() will be zero during the computation.\n call(gas(), currency, 0, freeMemoryPointer, 68, 0, 32)\n )\n }\n\n if (!success) revert ERC20TransferFailed();\n }\n }\n\n function balanceOfSelf(Currency currency) internal view returns (uint256) {\n if (currency.isNative()) return address(this).balance;\n else return IERC20(Currency.unwrap(currency)).balanceOf(address(this));\n }\n\n function equals(Currency currency, Currency other) internal pure returns (bool) {\n return Currency.unwrap(currency) == Currency.unwrap(other);\n }\n\n function isNative(Currency currency) internal pure returns (bool) {\n return Currency.unwrap(currency) == Currency.unwrap(NATIVE);\n }\n\n function toId(Currency currency) internal pure returns (uint256) {\n return uint160(Currency.unwrap(currency));\n }\n\n function fromId(uint256 id) internal pure returns (Currency) {\n return Currency.wrap(address(uint160(id)));\n }\n}\n" + }, + "src/libraries/CurrencyDelta.sol": { + "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\nimport {Currency, CurrencyLibrary} from \"./Currency.sol\";\n\nlibrary CurrencyDelta {\n // uint256(keccak256(\"CurrencyDelta\")) + 1\n uint256 internal constant CURRENCY_DELTA_SLOT = 0x95b400a0305233758f18c75aa62cbbb5d6882951dd55f1407390ee7b6924e26f;\n\n function get(address locker, Currency currency) internal view returns (int256 delta) {\n assembly {\n mstore(0x14, currency)\n mstore(0x00, locker)\n delta := tload(keccak256(0x0c, 0x28))\n }\n }\n\n function add(address locker, Currency currency, int256 delta) internal returns (int256 result) {\n assembly {\n mstore(0x14, currency)\n mstore(0x00, locker)\n let slot := keccak256(0x0c, 0x28)\n result := add(tload(slot), delta)\n tstore(slot, result)\n }\n }\n}\n" + }, + "src/libraries/DirtyUint64.sol": { + "content": "// SPDX-License-Identifier: -\n// License: https://license.clober.io/LICENSE.pdf\n\npragma solidity ^0.8.0;\n\nlibrary DirtyUint64 {\n error DirtyUint64Error(uint256 errorCode);\n\n uint256 private constant _OVERFLOW_ERROR = 0;\n uint256 private constant _UNDERFLOW_ERROR = 1;\n\n function toDirtyUnsafe(uint64 cleanUint) internal pure returns (uint64 dirtyUint) {\n assembly {\n dirtyUint := add(cleanUint, 1)\n }\n }\n\n function toDirty(uint64 cleanUint) internal pure returns (uint64 dirtyUint) {\n assembly {\n dirtyUint := add(cleanUint, 1)\n }\n if (dirtyUint == 0) {\n revert DirtyUint64Error(_OVERFLOW_ERROR);\n }\n }\n\n function toClean(uint64 dirtyUint) internal pure returns (uint64 cleanUint) {\n assembly {\n cleanUint := sub(dirtyUint, gt(dirtyUint, 0))\n }\n }\n\n function addClean(uint64 current, uint64 cleanUint) internal pure returns (uint64) {\n assembly {\n current := add(add(current, iszero(current)), cleanUint)\n }\n if (current < cleanUint) {\n revert DirtyUint64Error(_OVERFLOW_ERROR);\n }\n return current;\n }\n\n function addDirty(uint64 current, uint64 dirtyUint) internal pure returns (uint64) {\n assembly {\n current := sub(add(add(current, iszero(current)), add(dirtyUint, iszero(dirtyUint))), 1)\n }\n if (current < dirtyUint) {\n revert DirtyUint64Error(_OVERFLOW_ERROR);\n }\n return current;\n }\n\n function subClean(uint64 current, uint64 cleanUint) internal pure returns (uint64 ret) {\n assembly {\n current := add(current, iszero(current))\n ret := sub(current, cleanUint)\n }\n if (current < ret || ret == 0) {\n revert DirtyUint64Error(_UNDERFLOW_ERROR);\n }\n }\n\n function subDirty(uint64 current, uint64 dirtyUint) internal pure returns (uint64 ret) {\n assembly {\n current := add(current, iszero(current))\n ret := sub(add(current, 1), add(dirtyUint, iszero(dirtyUint)))\n }\n if (current < ret || ret == 0) {\n revert DirtyUint64Error(_UNDERFLOW_ERROR);\n }\n }\n\n function sumPackedUnsafe(uint256 packed, uint256 from, uint256 to) internal pure returns (uint64 ret) {\n packed = packed >> (from << 6);\n unchecked {\n for (uint256 i = from; i < to; ++i) {\n assembly {\n let element := and(packed, 0xffffffffffffffff)\n ret := add(ret, add(element, iszero(element)))\n packed := shr(64, packed)\n }\n }\n }\n assembly {\n ret := sub(ret, sub(to, from))\n }\n }\n}\n" + }, + "src/libraries/ERC721.sol": { + "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/ERC721.sol)\n// Modified by Clober Team\n\npragma solidity ^0.8.20;\n\nimport {IERC721} from \"@openzeppelin/contracts/token/ERC721/IERC721.sol\";\nimport {IERC721Receiver} from \"@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol\";\nimport {IERC721Metadata} from \"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol\";\nimport {Context} from \"@openzeppelin/contracts/utils/Context.sol\";\nimport {Strings} from \"@openzeppelin/contracts/utils/Strings.sol\";\nimport {IERC165, ERC165} from \"@openzeppelin/contracts/utils/introspection/ERC165.sol\";\nimport {IERC721Errors} from \"@openzeppelin/contracts/interfaces/draft-IERC6093.sol\";\n\n/**\n * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including\n * the Metadata extension, but not including the Enumerable extension, which is available separately as\n * {ERC721Enumerable}.\n */\nabstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors {\n using Strings for uint256;\n\n // Token name\n string private _name;\n\n // Token symbol\n string private _symbol;\n\n mapping(address owner => uint256) private _balances;\n\n mapping(uint256 tokenId => address) private _tokenApprovals;\n\n mapping(address owner => mapping(address operator => bool)) private _operatorApprovals;\n\n /**\n * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {\n return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId\n || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev See {IERC721-balanceOf}.\n */\n function balanceOf(address owner) public view virtual returns (uint256) {\n if (owner == address(0)) {\n revert ERC721InvalidOwner(address(0));\n }\n return _balances[owner];\n }\n\n /**\n * @dev See {IERC721-ownerOf}.\n */\n function ownerOf(uint256 tokenId) public view virtual returns (address) {\n return _requireOwned(tokenId);\n }\n\n /**\n * @dev See {IERC721Metadata-name}.\n */\n function name() public view virtual returns (string memory) {\n return _name;\n }\n\n /**\n * @dev See {IERC721Metadata-symbol}.\n */\n function symbol() public view virtual returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev See {IERC721Metadata-tokenURI}.\n */\n function tokenURI(uint256 tokenId) public view virtual returns (string memory) {\n _requireOwned(tokenId);\n\n string memory baseURI = _baseURI();\n return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : \"\";\n }\n\n /**\n * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each\n * token will be the concatenation of the `baseURI` and the `tokenId`. Empty\n * by default, can be overridden in child contracts.\n */\n function _baseURI() internal view virtual returns (string memory) {\n return \"\";\n }\n\n /**\n * @dev See {IERC721-approve}.\n */\n function approve(address to, uint256 tokenId) public virtual {\n _approve(to, tokenId, _msgSender());\n }\n\n /**\n * @dev See {IERC721-getApproved}.\n */\n function getApproved(uint256 tokenId) public view virtual returns (address) {\n _requireOwned(tokenId);\n\n return _getApproved(tokenId);\n }\n\n /**\n * @dev See {IERC721-setApprovalForAll}.\n */\n function setApprovalForAll(address operator, bool approved) public virtual {\n _setApprovalForAll(_msgSender(), operator, approved);\n }\n\n /**\n * @dev See {IERC721-isApprovedForAll}.\n */\n function isApprovedForAll(address owner, address operator) public view virtual returns (bool) {\n return _operatorApprovals[owner][operator];\n }\n\n /**\n * @dev See {IERC721-transferFrom}.\n */\n function transferFrom(address from, address to, uint256 tokenId) public virtual {\n if (to == address(0)) {\n revert ERC721InvalidReceiver(address(0));\n }\n // Setting an \"auth\" arguments enables the `_isAuthorized` check which verifies that the token exists\n // (from != 0). Therefore, it is not needed to verify that the return value is not 0 here.\n address previousOwner = _update(to, tokenId, _msgSender());\n if (previousOwner != from) {\n revert ERC721IncorrectOwner(from, tokenId, previousOwner);\n }\n }\n\n /**\n * @dev See {IERC721-safeTransferFrom}.\n */\n function safeTransferFrom(address from, address to, uint256 tokenId) public {\n safeTransferFrom(from, to, tokenId, \"\");\n }\n\n /**\n * @dev See {IERC721-safeTransferFrom}.\n */\n function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual {\n transferFrom(from, to, tokenId);\n _checkOnERC721Received(from, to, tokenId, data);\n }\n\n /**\n * @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist\n *\n * IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the\n * core ERC721 logic MUST be matched with the use of {_increaseBalance} to keep balances\n * consistent with ownership. The invariant to preserve is that for any address `a` the value returned by\n * `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`.\n */\n function _ownerOf(uint256 tokenId) internal view virtual returns (address);\n\n /**\n * @dev Returns the approved address for `tokenId`. Returns 0 if `tokenId` is not minted.\n */\n function _getApproved(uint256 tokenId) internal view virtual returns (address) {\n return _tokenApprovals[tokenId];\n }\n\n /**\n * @dev Returns whether `spender` is allowed to manage `owner`'s tokens, or `tokenId` in\n * particular (ignoring whether it is owned by `owner`).\n *\n * WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this\n * assumption.\n */\n function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) {\n return spender != address(0)\n && (owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender);\n }\n\n /**\n * @dev Checks if `spender` can operate on `tokenId`, assuming the provided `owner` is the actual owner.\n * Reverts if `spender` does not have approval from the provided `owner` for the given token or for all its assets\n * the `spender` for the specific `tokenId`.\n *\n * WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this\n * assumption.\n */\n function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual {\n if (!_isAuthorized(owner, spender, tokenId)) {\n if (owner == address(0)) {\n revert ERC721NonexistentToken(tokenId);\n } else {\n revert ERC721InsufficientApproval(spender, tokenId);\n }\n }\n }\n\n /**\n * @dev Unsafe write access to the balances, used by extensions that \"mint\" tokens using an {ownerOf} override.\n *\n * NOTE: the value is limited to type(uint128).max. This protect against _balance overflow. It is unrealistic that\n * a uint256 would ever overflow from increments when these increments are bounded to uint128 values.\n *\n * WARNING: Increasing an account's balance using this function tends to be paired with an override of the\n * {_ownerOf} function to resolve the ownership of the corresponding tokens so that balances and ownership\n * remain consistent with one another.\n */\n function _increaseBalance(address account, uint128 value) internal virtual {\n unchecked {\n _balances[account] += value;\n }\n }\n\n /**\n * @dev Transfers `tokenId` from its current owner to `to`, or alternatively mints (or burns) if the current owner\n * (or `to`) is the zero address. Returns the owner of the `tokenId` before the update.\n *\n * The `auth` argument is optional. If the value passed is non 0, then this function will check that\n * `auth` is either the owner of the token, or approved to operate on the token (by the owner).\n *\n * Emits a {Transfer} event.\n *\n * NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}.\n */\n function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) {\n address from = _ownerOf(tokenId);\n\n // Perform (optional) operator check\n if (auth != address(0)) {\n _checkAuthorized(from, auth, tokenId);\n }\n\n // Execute the update\n if (from != address(0)) {\n // Clear approval. No need to re-authorize or emit the Approval event\n _approve(address(0), tokenId, address(0), false);\n\n unchecked {\n _balances[from] -= 1;\n }\n }\n\n if (to != address(0)) {\n unchecked {\n _balances[to] += 1;\n }\n }\n\n // @dev MODIFIED: Define _setOwner\n _setOwner(tokenId, to);\n\n emit Transfer(from, to, tokenId);\n\n return from;\n }\n\n /**\n * @dev Mints `tokenId` and transfers it to `to`.\n *\n * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible\n *\n * Requirements:\n *\n * - `tokenId` must not exist.\n * - `to` cannot be the zero address.\n *\n * Emits a {Transfer} event.\n */\n function _mint(address to, uint256 tokenId) internal {\n if (to == address(0)) {\n revert ERC721InvalidReceiver(address(0));\n }\n address previousOwner = _update(to, tokenId, address(0));\n if (previousOwner != address(0)) {\n revert ERC721InvalidSender(address(0));\n }\n }\n\n /**\n * @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance.\n *\n * Requirements:\n *\n * - `tokenId` must not exist.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function _safeMint(address to, uint256 tokenId) internal {\n _safeMint(to, tokenId, \"\");\n }\n\n /**\n * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is\n * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.\n */\n function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {\n _mint(to, tokenId);\n _checkOnERC721Received(address(0), to, tokenId, data);\n }\n\n /**\n * @dev Destroys `tokenId`.\n * The approval is cleared when the token is burned.\n * This is an internal function that does not check if the sender is authorized to operate on the token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n *\n * Emits a {Transfer} event.\n */\n function _burn(uint256 tokenId) internal {\n address previousOwner = _update(address(0), tokenId, address(0));\n if (previousOwner == address(0)) {\n revert ERC721NonexistentToken(tokenId);\n }\n }\n\n /**\n * @dev Transfers `tokenId` from `from` to `to`.\n * As opposed to {transferFrom}, this imposes no restrictions on msg.sender.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n *\n * Emits a {Transfer} event.\n */\n function _transfer(address from, address to, uint256 tokenId) internal {\n if (to == address(0)) {\n revert ERC721InvalidReceiver(address(0));\n }\n address previousOwner = _update(to, tokenId, address(0));\n if (previousOwner == address(0)) {\n revert ERC721NonexistentToken(tokenId);\n } else if (previousOwner != from) {\n revert ERC721IncorrectOwner(from, tokenId, previousOwner);\n }\n }\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking that contract recipients\n * are aware of the ERC721 standard to prevent tokens from being forever locked.\n *\n * `data` is additional data, it has no specified format and it is sent in call to `to`.\n *\n * This internal function is like {safeTransferFrom} in the sense that it invokes\n * {IERC721Receiver-onERC721Received} on the receiver, and can be used to e.g.\n * implement alternative mechanisms to perform token transfer, such as signature-based.\n *\n * Requirements:\n *\n * - `tokenId` token must exist and be owned by `from`.\n * - `to` cannot be the zero address.\n * - `from` cannot be the zero address.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function _safeTransfer(address from, address to, uint256 tokenId) internal {\n _safeTransfer(from, to, tokenId, \"\");\n }\n\n /**\n * @dev Same as {xref-ERC721-_safeTransfer-address-address-uint256-}[`_safeTransfer`], with an additional `data` parameter which is\n * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.\n */\n function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {\n _transfer(from, to, tokenId);\n _checkOnERC721Received(from, to, tokenId, data);\n }\n\n /**\n * @dev Approve `to` to operate on `tokenId`\n *\n * The `auth` argument is optional. If the value passed is non 0, then this function will check that `auth` is\n * either the owner of the token, or approved to operate on all tokens held by this owner.\n *\n * Emits an {Approval} event.\n *\n * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.\n */\n function _approve(address to, uint256 tokenId, address auth) internal {\n _approve(to, tokenId, auth, true);\n }\n\n /**\n * @dev Variant of `_approve` with an optional flag to enable or disable the {Approval} event. The event is not\n * emitted in the context of transfers.\n */\n function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual {\n // Avoid reading the owner unless necessary\n if (emitEvent || auth != address(0)) {\n address owner = _requireOwned(tokenId);\n\n // We do not use _isAuthorized because single-token approvals should not be able to call approve\n if (auth != address(0) && owner != auth && !isApprovedForAll(owner, auth)) {\n revert ERC721InvalidApprover(auth);\n }\n\n if (emitEvent) {\n emit Approval(owner, to, tokenId);\n }\n }\n\n _tokenApprovals[tokenId] = to;\n }\n\n /**\n * @dev Approve `operator` to operate on all of `owner` tokens\n *\n * Requirements:\n * - operator can't be the address zero.\n *\n * Emits an {ApprovalForAll} event.\n */\n function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {\n if (operator == address(0)) {\n revert ERC721InvalidOperator(operator);\n }\n _operatorApprovals[owner][operator] = approved;\n emit ApprovalForAll(owner, operator, approved);\n }\n\n /**\n * @dev Reverts if the `tokenId` doesn't have a current owner (it hasn't been minted, or it has been burned).\n * Returns the owner.\n *\n * Overrides to ownership logic should be done to {_ownerOf}.\n */\n function _requireOwned(uint256 tokenId) internal view returns (address) {\n address owner = _ownerOf(tokenId);\n if (owner == address(0)) {\n revert ERC721NonexistentToken(tokenId);\n }\n return owner;\n }\n\n /**\n * @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target address. This will revert if the\n * recipient doesn't accept the token transfer. The call is not executed if the target address is not a contract.\n *\n * @param from address representing the previous owner of the given token ID\n * @param to target address that will receive the tokens\n * @param tokenId uint256 ID of the token to be transferred\n * @param data bytes optional data to send along with the call\n */\n function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private {\n if (to.code.length > 0) {\n try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {\n if (retval != IERC721Receiver.onERC721Received.selector) {\n revert ERC721InvalidReceiver(to);\n }\n } catch (bytes memory reason) {\n if (reason.length == 0) {\n revert ERC721InvalidReceiver(to);\n } else {\n /// @solidity memory-safe-assembly\n assembly {\n revert(add(32, reason), mload(reason))\n }\n }\n }\n }\n }\n\n /**\n * @dev Override this function to set owner\n */\n function _setOwner(uint256 tokenId, address owner) internal virtual;\n}\n" + }, + "src/libraries/ERC721Permit.sol": { + "content": "// SPDX-License-Identifier: GPL-2.0-or-later\n\npragma solidity ^0.8.0;\n\nimport {IERC1271} from \"@openzeppelin/contracts/interfaces/IERC1271.sol\";\nimport {IERC165} from \"@openzeppelin/contracts/utils/introspection/IERC165.sol\";\nimport {ECDSA} from \"@openzeppelin/contracts/utils/cryptography/ECDSA.sol\";\nimport {EIP712} from \"@openzeppelin/contracts/utils/cryptography/EIP712.sol\";\n\nimport {ERC721} from \"./ERC721.sol\";\nimport {IERC721Permit} from \"../interfaces/IERC721Permit.sol\";\n\ncontract ERC721Permit is ERC721, IERC721Permit, EIP712 {\n // keccak256(\"Permit(address spender,uint256 tokenId,uint256 nonce,uint256 deadline)\");\n bytes32 public constant override PERMIT_TYPEHASH =\n 0x49ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9ad;\n\n uint256 private constant _NONCE_MASK = uint256(0xffffffffffffffffffffffff) << 160;\n\n // @dev tokenId => (nonce << 160 | owner)\n mapping(uint256 => uint256) private _nonceAndOwner;\n\n constructor(string memory name_, string memory symbol_, string memory version_)\n ERC721(name_, symbol_)\n EIP712(name_, version_)\n {}\n\n function permit(address spender, uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s)\n external\n override\n {\n if (block.timestamp > deadline) revert PermitExpired();\n\n bytes32 digest = _hashTypedDataV4(\n keccak256(abi.encode(PERMIT_TYPEHASH, spender, tokenId, _getAndIncrementNonce(tokenId), deadline))\n );\n\n address owner = ownerOf(tokenId);\n if (spender == owner) revert InvalidSignature();\n\n if (owner.code.length > 0) {\n if (IERC1271(owner).isValidSignature(digest, abi.encodePacked(r, s, v)) != 0x1626ba7e) {\n revert InvalidSignature();\n }\n } else {\n if (ECDSA.recover(digest, v, r, s) != owner) revert InvalidSignature();\n }\n\n _approve(spender, tokenId, owner, true);\n }\n\n function DOMAIN_SEPARATOR() public view override returns (bytes32) {\n return _domainSeparatorV4();\n }\n\n function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, IERC165) returns (bool) {\n return interfaceId == type(IERC721Permit).interfaceId || super.supportsInterface(interfaceId);\n }\n\n function nonces(uint256 id) external view returns (uint256) {\n return _nonceAndOwner[id] >> 160;\n }\n\n function _getAndIncrementNonce(uint256 tokenId) internal returns (uint256 nonce) {\n uint256 nonceAndOwner = _nonceAndOwner[tokenId];\n nonce = nonceAndOwner >> 160;\n _nonceAndOwner[tokenId] = nonceAndOwner + (1 << 160);\n }\n\n function _ownerOf(uint256 tokenId) internal view override returns (address) {\n return address(uint160(_nonceAndOwner[tokenId]));\n }\n\n function _setOwner(uint256 tokenId, address owner) internal override {\n _nonceAndOwner[tokenId] = (_nonceAndOwner[tokenId] & _NONCE_MASK) | uint256(uint160(owner));\n }\n}\n" + }, + "src/libraries/FeePolicy.sol": { + "content": "// SPDX-License-Identifier: GPL-2.0-or-later\n\npragma solidity ^0.8.20;\n\nimport {Math} from \"./Math.sol\";\n\ntype FeePolicy is uint24;\n\nlibrary FeePolicyLibrary {\n uint256 internal constant RATE_PRECISION = 10 ** 6;\n int256 internal constant MAX_FEE_RATE = 500000;\n int256 internal constant MIN_FEE_RATE = -500000;\n\n uint256 internal constant RATE_MASK = 0x7fffff; // 23 bits\n\n error InvalidFeePolicy();\n\n function encode(bool usesQuote_, int24 rate_) internal pure returns (FeePolicy feePolicy) {\n if (rate_ > MAX_FEE_RATE || rate_ < MIN_FEE_RATE) {\n revert InvalidFeePolicy();\n }\n\n uint256 mask = usesQuote_ ? 1 << 23 : 0;\n assembly {\n feePolicy := or(mask, add(and(rate_, 0xffffff), MAX_FEE_RATE))\n }\n }\n\n function isValid(FeePolicy self) internal pure returns (bool) {\n int24 r = rate(self);\n\n return !(r > MAX_FEE_RATE || r < MIN_FEE_RATE);\n }\n\n function usesQuote(FeePolicy self) internal pure returns (bool f) {\n assembly {\n f := shr(23, self)\n }\n }\n\n function rate(FeePolicy self) internal pure returns (int24 r) {\n assembly {\n r := sub(and(self, RATE_MASK), MAX_FEE_RATE)\n }\n }\n\n function calculateFee(FeePolicy self, uint256 amount, bool reverseRounding) internal pure returns (int256 fee) {\n int24 r = rate(self);\n\n bool positive = r > 0;\n uint256 absRate;\n unchecked {\n absRate = uint256(uint24(positive ? r : -r));\n }\n // @dev absFee must be less than type(int256).max\n uint256 absFee = Math.divide(amount * absRate, RATE_PRECISION, reverseRounding ? !positive : positive);\n fee = positive ? int256(absFee) : -int256(absFee);\n }\n\n function calculateOriginalAmount(FeePolicy self, uint256 amount, bool reverseFee)\n internal\n pure\n returns (uint256 originalAmount)\n {\n int24 r = rate(self);\n\n uint256 divider;\n assembly {\n if reverseFee { r := sub(0, r) }\n divider := add(RATE_PRECISION, r)\n }\n originalAmount = Math.divide(amount * RATE_PRECISION, divider, reverseFee);\n }\n}\n" + }, + "src/libraries/Hooks.sol": { + "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.20;\n\nimport {Lockers} from \"./Lockers.sol\";\nimport {IBookManager} from \"../interfaces/IBookManager.sol\";\nimport {IHooks} from \"../interfaces/IHooks.sol\";\nimport {OrderId} from \"../libraries/OrderId.sol\";\n\n/// @author Clober\n/// @author Modified from Uniswap V4 (https://github.com/Uniswap/v4-core/blob/1f350fa95e862ba8c56c8ff7e146d47c9043465e)\n/// @notice V4 decides whether to invoke specific hooks by inspecting the leading bits of the address that\n/// the hooks contract is deployed to.\n/// For example, a hooks contract deployed to address: 0x9000000000000000000000000000000000000000\n/// has leading bits '1001' which would cause the 'before open' and 'after make' hooks to be used.\nlibrary Hooks {\n using Hooks for IHooks;\n\n uint256 internal constant BEFORE_OPEN_FLAG = 1 << 159;\n uint256 internal constant AFTER_OPEN_FLAG = 1 << 158;\n uint256 internal constant BEFORE_MAKE_FLAG = 1 << 157;\n uint256 internal constant AFTER_MAKE_FLAG = 1 << 156;\n uint256 internal constant BEFORE_TAKE_FLAG = 1 << 155;\n uint256 internal constant AFTER_TAKE_FLAG = 1 << 154;\n uint256 internal constant BEFORE_CANCEL_FLAG = 1 << 153;\n uint256 internal constant AFTER_CANCEL_FLAG = 1 << 152;\n uint256 internal constant BEFORE_CLAIM_FLAG = 1 << 151;\n uint256 internal constant AFTER_CLAIM_FLAG = 1 << 150;\n\n struct Permissions {\n bool beforeOpen;\n bool afterOpen;\n bool beforeMake;\n bool afterMake;\n bool beforeTake;\n bool afterTake;\n bool beforeCancel;\n bool afterCancel;\n bool beforeClaim;\n bool afterClaim;\n }\n\n /// @notice Thrown if the address will not lead to the specified hook calls being called\n /// @param hooks The address of the hooks contract\n error HookAddressNotValid(address hooks);\n\n /// @notice Hook did not return its selector\n error InvalidHookResponse();\n\n /// @notice thrown when a hook call fails\n error FailedHookCall();\n\n /// @notice Utility function intended to be used in hook constructors to ensure\n /// the deployed hooks address causes the intended hooks to be called\n /// @param permissions The hooks that are intended to be called\n /// @dev permissions param is memory as the function will be called from constructors\n function validateHookPermissions(IHooks self, Permissions memory permissions) internal pure {\n if (\n permissions.beforeOpen != self.hasPermission(BEFORE_OPEN_FLAG)\n || permissions.afterOpen != self.hasPermission(AFTER_OPEN_FLAG)\n || permissions.beforeMake != self.hasPermission(BEFORE_MAKE_FLAG)\n || permissions.afterMake != self.hasPermission(AFTER_MAKE_FLAG)\n || permissions.beforeTake != self.hasPermission(BEFORE_TAKE_FLAG)\n || permissions.afterTake != self.hasPermission(AFTER_TAKE_FLAG)\n || permissions.beforeCancel != self.hasPermission(BEFORE_CANCEL_FLAG)\n || permissions.afterCancel != self.hasPermission(AFTER_CANCEL_FLAG)\n || permissions.beforeClaim != self.hasPermission(BEFORE_CLAIM_FLAG)\n || permissions.afterClaim != self.hasPermission(AFTER_CLAIM_FLAG)\n ) {\n revert HookAddressNotValid(address(self));\n }\n }\n\n /// @notice Ensures that the hook address includes at least one hook flag or is the 0 address\n /// @param hook The hook to verify\n function isValidHookAddress(IHooks hook) internal pure returns (bool) {\n // If a hook contract is set, it must have at least 1 flag set\n return address(hook) == address(0) || uint160(address(hook)) >= AFTER_CLAIM_FLAG;\n }\n\n /// @notice performs a hook call using the given calldata on the given hook\n /// @return expectedSelector The selector that the hook is expected to return\n /// @return selector The selector that the hook actually returned\n function _callHook(IHooks self, bytes memory data) private returns (bytes4 expectedSelector, bytes4 selector) {\n bool set = Lockers.setCurrentHook(self);\n\n assembly {\n expectedSelector := mload(add(data, 0x20))\n }\n\n (bool success, bytes memory result) = address(self).call(data);\n if (!success) _revert(result);\n\n selector = abi.decode(result, (bytes4));\n\n // We only want to clear the current hook if it was set in setCurrentHook in this execution frame.\n if (set) Lockers.clearCurrentHook();\n }\n\n /// @notice performs a hook call using the given calldata on the given hook\n function callHook(IHooks self, bytes memory data) internal {\n (bytes4 expectedSelector, bytes4 selector) = _callHook(self, data);\n\n if (selector != expectedSelector) revert InvalidHookResponse();\n }\n\n /// @notice calls beforeOpen hook if permissioned and validates return value\n function beforeOpen(IHooks self, IBookManager.BookKey memory key, bytes calldata hookData) internal {\n if (self.hasPermission(BEFORE_OPEN_FLAG)) {\n self.callHook(abi.encodeWithSelector(IHooks.beforeOpen.selector, msg.sender, key, hookData));\n }\n }\n\n /// @notice calls afterOpen hook if permissioned and validates return value\n function afterOpen(IHooks self, IBookManager.BookKey memory key, bytes calldata hookData) internal {\n if (self.hasPermission(AFTER_OPEN_FLAG)) {\n self.callHook(abi.encodeWithSelector(IHooks.afterOpen.selector, msg.sender, key, hookData));\n }\n }\n\n /// @notice calls beforeMake hook if permissioned and validates return value\n function beforeMake(IHooks self, IBookManager.MakeParams memory params, bytes calldata hookData) internal {\n if (self.hasPermission(BEFORE_MAKE_FLAG)) {\n self.callHook(abi.encodeWithSelector(IHooks.beforeMake.selector, msg.sender, params, hookData));\n }\n }\n\n /// @notice calls afterMake hook if permissioned and validates return value\n function afterMake(IHooks self, IBookManager.MakeParams memory params, OrderId orderId, bytes calldata hookData)\n internal\n {\n if (self.hasPermission(AFTER_MAKE_FLAG)) {\n self.callHook(abi.encodeWithSelector(IHooks.afterMake.selector, msg.sender, params, orderId, hookData));\n }\n }\n\n /// @notice calls beforeTake hook if permissioned and validates return value\n function beforeTake(IHooks self, IBookManager.TakeParams memory params, bytes calldata hookData) internal {\n if (self.hasPermission(BEFORE_TAKE_FLAG)) {\n self.callHook(abi.encodeWithSelector(IHooks.beforeTake.selector, msg.sender, params, hookData));\n }\n }\n\n /// @notice calls afterTake hook if permissioned and validates return value\n function afterTake(IHooks self, IBookManager.TakeParams memory params, uint64 takenAmount, bytes calldata hookData)\n internal\n {\n if (self.hasPermission(AFTER_TAKE_FLAG)) {\n self.callHook(abi.encodeWithSelector(IHooks.afterTake.selector, msg.sender, params, takenAmount, hookData));\n }\n }\n\n /// @notice calls beforeCancel hook if permissioned and validates return value\n function beforeCancel(IHooks self, IBookManager.CancelParams calldata params, bytes calldata hookData) internal {\n if (self.hasPermission(BEFORE_CANCEL_FLAG)) {\n self.callHook(abi.encodeWithSelector(IHooks.beforeCancel.selector, msg.sender, params, hookData));\n }\n }\n\n /// @notice calls afterCancel hook if permissioned and validates return value\n function afterCancel(\n IHooks self,\n IBookManager.CancelParams calldata params,\n uint64 canceledAmount,\n bytes calldata hookData\n ) internal {\n if (self.hasPermission(AFTER_CANCEL_FLAG)) {\n self.callHook(\n abi.encodeWithSelector(IHooks.afterCancel.selector, msg.sender, params, canceledAmount, hookData)\n );\n }\n }\n\n /// @notice calls beforeClaim hook if permissioned and validates return value\n function beforeClaim(IHooks self, OrderId orderId, bytes calldata hookData) internal {\n if (self.hasPermission(BEFORE_CLAIM_FLAG)) {\n self.callHook(abi.encodeWithSelector(IHooks.beforeClaim.selector, msg.sender, orderId, hookData));\n }\n }\n\n /// @notice calls afterClaim hook if permissioned and validates return value\n function afterClaim(IHooks self, OrderId orderId, uint64 claimedAmount, bytes calldata hookData) internal {\n if (self.hasPermission(AFTER_CLAIM_FLAG)) {\n self.callHook(\n abi.encodeWithSelector(IHooks.afterClaim.selector, msg.sender, orderId, claimedAmount, hookData)\n );\n }\n }\n\n function hasPermission(IHooks self, uint256 flag) internal pure returns (bool) {\n return uint256(uint160(address(self))) & flag != 0;\n }\n\n /// @notice bubble up revert if present. Else throw FailedHookCall\n function _revert(bytes memory result) private pure {\n if (result.length == 0) revert FailedHookCall();\n assembly {\n revert(add(0x20, result), mload(result))\n }\n }\n}\n" + }, + "src/libraries/Lockers.sol": { + "content": "// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity ^0.8.23;\n\nimport {IHooks} from \"../interfaces/IHooks.sol\";\n\n/// @author Clober\n/// @author Modified from Uniswap V4 (https://github.com/Uniswap/v4-core/tree/98680ebc1a654120e995d53a5b10ec6fe153066f)\n/// @notice Contains data about pool lockers.\n\n/// @dev This library manages a custom storage implementation for a queue\n/// that tracks current lockers. The \"sentinel\" storage slot for this data structure,\n/// always passed in as IPoolManager.LockData storage self, stores not just the current\n/// length of the queue but also the global count of non-zero deltas across all lockers.\n/// The values of the data structure start at OFFSET, and each value is a locker address.\nlibrary Lockers {\n /// struct LockData {\n /// /// @notice The current number of active lockers\n /// uint128 length;\n /// /// @notice The total number of nonzero deltas over all active + completed lockers\n /// uint128 nonzeroDeltaCount;\n /// }\n // uint256(keccak256(\"LockData\")) + 1\n uint256 internal constant LOCK_DATA_SLOT = 0x760a9a962ae3d184e99c0483cf5684fb3170f47116ca4f445c50209da4f4f907;\n\n // uint256(keccak256(\"Lockers\")) + 1\n uint256 internal constant LOCKERS_SLOT = 0x722b431450ce53c44434ec138439e45a0639fe031b803ee019b776fae5cfa2b1;\n\n // The number of slots per item in the lockers array\n uint256 internal constant LOCKER_STRUCT_SIZE = 2;\n\n // uint256(keccak256(\"HookAddress\")) + 1\n uint256 internal constant HOOK_ADDRESS_SLOT = 0xfcac7593714b88fec0c578a53e9f3f6e4b47eb26c9dcaa7eff23a3ac156be422;\n\n uint256 internal constant NONZERO_DELTA_COUNT_OFFSET = 2 ** 128;\n\n uint256 internal constant LENGTH_MASK = (1 << 128) - 1;\n\n /// @dev Pushes a locker onto the end of the queue, and updates the sentinel storage slot.\n function push(address locker, address lockCaller) internal {\n assembly {\n let data := tload(LOCK_DATA_SLOT)\n let l := and(data, LENGTH_MASK)\n\n // LOCKERS_SLOT + l * LOCKER_STRUCT_SIZE\n let indexToWrite := add(LOCKERS_SLOT, mul(l, LOCKER_STRUCT_SIZE))\n\n // in the next storage slot, write the locker and lockCaller\n tstore(indexToWrite, locker)\n tstore(add(indexToWrite, 1), lockCaller)\n\n // increase the length\n tstore(LOCK_DATA_SLOT, add(data, 1))\n }\n }\n\n function lockData() internal view returns (uint128 l, uint128 nonzeroDeltaCount) {\n assembly {\n let data := tload(LOCK_DATA_SLOT)\n l := and(data, LENGTH_MASK)\n nonzeroDeltaCount := shr(128, data)\n }\n }\n\n function length() internal view returns (uint128 l) {\n assembly {\n l := and(tload(LOCK_DATA_SLOT), LENGTH_MASK)\n }\n }\n\n /// @dev Pops a locker off the end of the queue. Note that no storage gets cleared.\n function pop() internal {\n assembly {\n let data := tload(LOCK_DATA_SLOT)\n let l := and(data, LENGTH_MASK)\n if iszero(l) {\n mstore(0x00, 0xf1c77ed0) // LockersPopFailed()\n revert(0x1c, 0x04)\n }\n\n // LOCKERS_SLOT + (l - 1) * LOCKER_STRUCT_SIZE\n let indexToWrite := add(LOCKERS_SLOT, mul(sub(l, 1), LOCKER_STRUCT_SIZE))\n\n // in the next storage slot, delete the locker and lockCaller\n tstore(indexToWrite, 0)\n tstore(add(indexToWrite, 1), 0)\n\n // decrease the length\n tstore(LOCK_DATA_SLOT, sub(data, 1))\n }\n }\n\n function getLocker(uint256 i) internal view returns (address locker) {\n assembly {\n // LOCKERS_SLOT + (i * LOCKER_STRUCT_SIZE)\n locker := tload(add(LOCKERS_SLOT, mul(i, LOCKER_STRUCT_SIZE)))\n }\n }\n\n function getLockCaller(uint256 i) internal view returns (address locker) {\n assembly {\n // LOCKERS_SLOT + (i * LOCKER_STRUCT_SIZE + 1)\n locker := tload(add(LOCKERS_SLOT, add(mul(i, LOCKER_STRUCT_SIZE), 1)))\n }\n }\n\n function getCurrentLocker() internal view returns (address) {\n unchecked {\n uint256 l = length();\n return l > 0 ? getLocker(l - 1) : address(0);\n }\n }\n\n function getCurrentLockCaller() internal view returns (address) {\n unchecked {\n uint256 l = length();\n return l > 0 ? getLockCaller(l - 1) : address(0);\n }\n }\n\n function incrementNonzeroDeltaCount() internal {\n assembly {\n tstore(LOCK_DATA_SLOT, add(tload(LOCK_DATA_SLOT), NONZERO_DELTA_COUNT_OFFSET))\n }\n }\n\n function decrementNonzeroDeltaCount() internal {\n assembly {\n tstore(LOCK_DATA_SLOT, sub(tload(LOCK_DATA_SLOT), NONZERO_DELTA_COUNT_OFFSET))\n }\n }\n\n function getCurrentHook() internal view returns (IHooks currentHook) {\n return IHooks(getHook(length()));\n }\n\n function getHook(uint256 i) internal view returns (address hook) {\n assembly {\n hook := tload(add(HOOK_ADDRESS_SLOT, i))\n }\n }\n\n function setCurrentHook(IHooks currentHook) internal returns (bool set) {\n // Set the hook address for the current locker if the address is 0.\n // 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.\n if (address(getCurrentHook()) == address(0)) {\n uint256 l = length();\n assembly {\n tstore(add(HOOK_ADDRESS_SLOT, l), currentHook)\n }\n return true;\n }\n }\n\n function clearCurrentHook() internal {\n uint256 l = length();\n assembly {\n tstore(add(HOOK_ADDRESS_SLOT, l), 0)\n }\n }\n}\n" + }, + "src/libraries/Math.sol": { + "content": "// SPDX-License-Identifier: GPL-2.0-or-later\n\npragma solidity ^0.8.0;\n\nlibrary Math {\n function divide(uint256 a, uint256 b, bool roundingUp) internal pure returns (uint256 ret) {\n // In the OrderBook contract code, b is never zero.\n assembly {\n ret := add(div(a, b), and(gt(mod(a, b), 0), roundingUp))\n }\n }\n\n /// @dev Returns `ln(x)`, denominated in `WAD`.\n /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln\n function lnWad(int256 x) internal pure returns (int256 r) {\n /// @solidity memory-safe-assembly\n assembly {\n // We want to convert `x` from `10**18` fixed point to `2**96` fixed point.\n // We do this by multiplying by `2**96 / 10**18`. But since\n // `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here\n // and add `ln(2**96 / 10**18)` at the end.\n\n // Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`.\n r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\n r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))\n r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\n r := or(r, shl(4, lt(0xffff, shr(r, x))))\n r := or(r, shl(3, lt(0xff, shr(r, x))))\n // We place the check here for more optimal stack operations.\n if iszero(sgt(x, 0)) {\n mstore(0x00, 0x1615e638) // `LnWadUndefined()`.\n revert(0x1c, 0x04)\n }\n // forgefmt: disable-next-item\n r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),\n 0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff))\n\n // Reduce range of x to (1, 2) * 2**96\n // ln(2^k * x) = k * ln(2) + ln(x)\n x := shr(159, shl(r, x))\n\n // Evaluate using a (8, 8)-term rational approximation.\n // `p` is made monic, we will multiply by a scale factor later.\n // forgefmt: disable-next-item\n let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir.\n sar(96, mul(add(43456485725739037958740375743393,\n sar(96, mul(add(24828157081833163892658089445524,\n sar(96, mul(add(3273285459638523848632254066296,\n x), x))), x))), x)), 11111509109440967052023855526967)\n p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857)\n p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526)\n p := sub(mul(p, x), shl(96, 795164235651350426258249787498))\n // We leave `p` in `2**192` basis so we don't need to scale it back up for the division.\n\n // `q` is monic by convention.\n let q := add(5573035233440673466300451813936, x)\n q := add(71694874799317883764090561454958, sar(96, mul(x, q)))\n q := add(283447036172924575727196451306956, sar(96, mul(x, q)))\n q := add(401686690394027663651624208769553, sar(96, mul(x, q)))\n q := add(204048457590392012362485061816622, sar(96, mul(x, q)))\n q := add(31853899698501571402653359427138, sar(96, mul(x, q)))\n q := add(909429971244387300277376558375, sar(96, mul(x, q)))\n\n // `p / q` is in the range `(0, 0.125) * 2**96`.\n\n // Finalization, we need to:\n // - Multiply by the scale factor `s = 5.549…`.\n // - Add `ln(2**96 / 10**18)`.\n // - Add `k * ln(2)`.\n // - Multiply by `10**18 / 2**96 = 5**18 >> 78`.\n\n // The q polynomial is known not to have zeros in the domain.\n // No scaling required because p is already `2**96` too large.\n p := sdiv(p, q)\n // Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`.\n p := mul(1677202110996718588342820967067443963516166, p)\n // Add `ln(2) * k * 5**18 * 2**192`.\n // forgefmt: disable-next-item\n p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p)\n // Base conversion: mul `2**96 / (5**18 * 2**192)`.\n r := sdiv(p, 302231454903657293676544000000000000000000)\n }\n }\n}\n" + }, + "src/libraries/OrderId.sol": { + "content": "// SPDX-License-Identifier: GPL-2.0-or-later\n\npragma solidity ^0.8.0;\n\nimport {Tick} from \"./Tick.sol\";\nimport {BookId} from \"./BookId.sol\";\n\ntype OrderId is uint256;\n\nlibrary OrderIdLibrary {\n /**\n * @dev Encode the order id.\n * @param bookId The book id.\n * @param tick The tick.\n * @param index The index.\n * @return id The order id.\n */\n function encode(BookId bookId, Tick tick, uint40 index) internal pure returns (OrderId id) {\n // @dev If we just use tick at the assembly code, the code will convert tick into bytes32.\n // e.g. When index == -2, the shifted value( shl(40, tick) ) will be\n // 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0000000000 instead of 0xfffffffe0000000000\n // Therefore, we have to safely cast tick into uint256 first.\n uint256 _tick = uint256(uint24(Tick.unwrap(tick)));\n assembly {\n id := add(index, add(shl(40, _tick), shl(64, bookId)))\n }\n }\n\n function decode(OrderId id) internal pure returns (BookId bookId, Tick tick, uint40 index) {\n assembly {\n bookId := shr(64, id)\n tick := and(shr(40, id), 0xffffff)\n index := and(id, 0xffffffffff)\n }\n }\n\n function getBookId(OrderId id) internal pure returns (BookId bookId) {\n assembly {\n bookId := shr(64, id)\n }\n }\n\n function getTick(OrderId id) internal pure returns (Tick tick) {\n assembly {\n tick := and(shr(40, id), 0xffffff)\n }\n }\n\n function getIndex(OrderId id) internal pure returns (uint40 index) {\n assembly {\n index := and(id, 0xffffffffff)\n }\n }\n}\n" + }, + "src/libraries/PackedUint256.sol": { + "content": "// SPDX-License-Identifier: -\n// License: https://license.clober.io/LICENSE.pdf\n\npragma solidity ^0.8.0;\n\nlibrary PackedUint256 {\n error PackedUint256Error(uint256 errorCode);\n\n uint256 private constant _UINT8_INDEX_ERROR = 0;\n uint256 private constant _UINT16_INDEX_ERROR = 1;\n uint256 private constant _UINT32_INDEX_ERROR = 2;\n uint256 private constant _UINT64_INDEX_ERROR = 3;\n\n uint256 private constant _MAX_UINT64 = type(uint64).max;\n uint256 private constant _MAX_UINT32 = type(uint32).max;\n uint256 private constant _MAX_UINT16 = type(uint16).max;\n uint256 private constant _MAX_UINT8 = type(uint8).max;\n\n function get8Unsafe(uint256 packed, uint256 index) internal pure returns (uint8 ret) {\n assembly {\n ret := and(shr(shl(3, index), packed), 0xff)\n }\n }\n\n function get8(uint256 packed, uint256 index) internal pure returns (uint8 ret) {\n if (index > 31) {\n revert PackedUint256Error(_UINT8_INDEX_ERROR);\n }\n assembly {\n ret := and(shr(shl(3, index), packed), 0xff)\n }\n }\n\n function get16Unsafe(uint256 packed, uint256 index) internal pure returns (uint16 ret) {\n assembly {\n ret := and(shr(shl(4, index), packed), 0xffff)\n }\n }\n\n function get16(uint256 packed, uint256 index) internal pure returns (uint16 ret) {\n if (index > 15) {\n revert PackedUint256Error(_UINT16_INDEX_ERROR);\n }\n assembly {\n ret := and(shr(shl(4, index), packed), 0xffff)\n }\n }\n\n function get32Unsafe(uint256 packed, uint256 index) internal pure returns (uint32 ret) {\n assembly {\n ret := and(shr(shl(5, index), packed), 0xffffffff)\n }\n }\n\n function get32(uint256 packed, uint256 index) internal pure returns (uint32 ret) {\n if (index > 7) {\n revert PackedUint256Error(_UINT32_INDEX_ERROR);\n }\n assembly {\n ret := and(shr(shl(5, index), packed), 0xffffffff)\n }\n }\n\n function get64Unsafe(uint256 packed, uint256 index) internal pure returns (uint64 ret) {\n assembly {\n ret := and(shr(shl(6, index), packed), 0xffffffffffffffff)\n }\n }\n\n function get64(uint256 packed, uint256 index) internal pure returns (uint64 ret) {\n if (index > 3) {\n revert PackedUint256Error(_UINT64_INDEX_ERROR);\n }\n assembly {\n ret := and(shr(shl(6, index), packed), 0xffffffffffffffff)\n }\n }\n\n function add8Unsafe(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\n assembly {\n ret := add(packed, shl(shl(3, index), and(value, 0xff)))\n }\n }\n\n function add8(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\n if (index > 31) {\n revert PackedUint256Error(_UINT8_INDEX_ERROR);\n }\n uint8 current = get8Unsafe(packed, index);\n current += value;\n ret = update8Unsafe(packed, index, current);\n }\n\n function add16Unsafe(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\n assembly {\n ret := add(packed, shl(shl(4, index), and(value, 0xffff)))\n }\n }\n\n function add16(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\n if (index > 15) {\n revert PackedUint256Error(_UINT16_INDEX_ERROR);\n }\n uint16 current = get16Unsafe(packed, index);\n current += value;\n ret = update16Unsafe(packed, index, current);\n }\n\n function add32Unsafe(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\n assembly {\n ret := add(packed, shl(shl(5, index), and(value, 0xffffffff)))\n }\n }\n\n function add32(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\n if (index > 7) {\n revert PackedUint256Error(_UINT32_INDEX_ERROR);\n }\n uint32 current = get32Unsafe(packed, index);\n current += value;\n ret = update32Unsafe(packed, index, current);\n }\n\n function add64Unsafe(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\n assembly {\n ret := add(packed, shl(shl(6, index), and(value, 0xffffffffffffffff)))\n }\n }\n\n function add64(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\n if (index > 3) {\n revert PackedUint256Error(_UINT64_INDEX_ERROR);\n }\n uint64 current = get64Unsafe(packed, index);\n current += value;\n ret = update64Unsafe(packed, index, current);\n }\n\n function sub8Unsafe(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\n assembly {\n ret := sub(packed, shl(shl(3, index), and(value, 0xff)))\n }\n }\n\n function sub8(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\n if (index > 31) {\n revert PackedUint256Error(_UINT8_INDEX_ERROR);\n }\n uint8 current = get8Unsafe(packed, index);\n current -= value;\n ret = update8Unsafe(packed, index, current);\n }\n\n function sub16Unsafe(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\n assembly {\n ret := sub(packed, shl(shl(4, index), and(value, 0xffff)))\n }\n }\n\n function sub16(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\n if (index > 15) {\n revert PackedUint256Error(_UINT16_INDEX_ERROR);\n }\n uint16 current = get16Unsafe(packed, index);\n current -= value;\n ret = update16Unsafe(packed, index, current);\n }\n\n function sub32Unsafe(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\n assembly {\n ret := sub(packed, shl(shl(5, index), and(value, 0xffffffff)))\n }\n }\n\n function sub32(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\n if (index > 7) {\n revert PackedUint256Error(_UINT32_INDEX_ERROR);\n }\n uint32 current = get32Unsafe(packed, index);\n current -= value;\n ret = update32Unsafe(packed, index, current);\n }\n\n function sub64Unsafe(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\n assembly {\n ret := sub(packed, shl(shl(6, index), and(value, 0xffffffffffffffff)))\n }\n }\n\n function sub64(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\n if (index > 3) {\n revert PackedUint256Error(_UINT64_INDEX_ERROR);\n }\n uint64 current = get64Unsafe(packed, index);\n current -= value;\n ret = update64Unsafe(packed, index, current);\n }\n\n function update8Unsafe(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\n unchecked {\n index = index << 3;\n packed = packed - (packed & (_MAX_UINT8 << index));\n }\n assembly {\n ret := add(packed, shl(index, and(value, 0xff)))\n }\n }\n\n function update8(uint256 packed, uint256 index, uint8 value) internal pure returns (uint256 ret) {\n if (index > 31) {\n revert PackedUint256Error(_UINT8_INDEX_ERROR);\n }\n unchecked {\n index = index << 3;\n packed = packed - (packed & (_MAX_UINT8 << index));\n }\n assembly {\n ret := add(packed, shl(index, and(value, 0xff)))\n }\n }\n\n function update16Unsafe(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\n unchecked {\n index = index << 4;\n packed = packed - (packed & (_MAX_UINT16 << index));\n }\n assembly {\n ret := add(packed, shl(index, and(value, 0xffff)))\n }\n }\n\n function update16(uint256 packed, uint256 index, uint16 value) internal pure returns (uint256 ret) {\n if (index > 15) {\n revert PackedUint256Error(_UINT16_INDEX_ERROR);\n }\n unchecked {\n index = index << 4;\n packed = packed - (packed & (_MAX_UINT16 << index));\n }\n assembly {\n ret := add(packed, shl(index, and(value, 0xffff)))\n }\n }\n\n function update32Unsafe(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\n unchecked {\n index = index << 5;\n packed = packed - (packed & (_MAX_UINT32 << index));\n }\n assembly {\n ret := add(packed, shl(index, and(value, 0xffffffff)))\n }\n }\n\n function update32(uint256 packed, uint256 index, uint32 value) internal pure returns (uint256 ret) {\n if (index > 7) {\n revert PackedUint256Error(_UINT32_INDEX_ERROR);\n }\n unchecked {\n index = index << 5;\n packed = packed - (packed & (_MAX_UINT32 << index));\n }\n assembly {\n ret := add(packed, shl(index, and(value, 0xffffffff)))\n }\n }\n\n function update64Unsafe(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\n unchecked {\n index = index << 6;\n packed = packed - (packed & (_MAX_UINT64 << index));\n }\n assembly {\n ret := add(packed, shl(index, and(value, 0xffffffffffffffff)))\n }\n }\n\n function update64(uint256 packed, uint256 index, uint64 value) internal pure returns (uint256 ret) {\n if (index > 3) {\n revert PackedUint256Error(_UINT64_INDEX_ERROR);\n }\n unchecked {\n index = index << 6;\n packed = packed - (packed & (_MAX_UINT64 << index));\n }\n assembly {\n ret := add(packed, shl(index, and(value, 0xffffffffffffffff)))\n }\n }\n\n function total32(uint256 packed) internal pure returns (uint256) {\n unchecked {\n uint256 ret = _MAX_UINT32 & packed;\n for (uint256 i = 0; i < 7; ++i) {\n packed = packed >> 32;\n ret += _MAX_UINT32 & packed;\n }\n return ret;\n }\n }\n\n function total64(uint256 packed) internal pure returns (uint256) {\n unchecked {\n uint256 ret = _MAX_UINT64 & packed;\n for (uint256 i = 0; i < 3; ++i) {\n packed = packed >> 64;\n ret += _MAX_UINT64 & packed;\n }\n return ret;\n }\n }\n\n function sum32(uint256 packed, uint256 from, uint256 to) internal pure returns (uint256) {\n unchecked {\n packed = packed >> (from << 5);\n uint256 ret = 0;\n for (uint256 i = from; i < to; ++i) {\n ret += _MAX_UINT32 & packed;\n packed = packed >> 32;\n }\n return ret;\n }\n }\n\n function sum64(uint256 packed, uint256 from, uint256 to) internal pure returns (uint256) {\n unchecked {\n packed = packed >> (from << 6);\n uint256 ret = 0;\n for (uint256 i = from; i < to; ++i) {\n ret += _MAX_UINT64 & packed;\n packed = packed >> 64;\n }\n return ret;\n }\n }\n}\n" + }, + "src/libraries/SegmentedSegmentTree.sol": { + "content": "// SPDX-License-Identifier: -\n// License: https://license.clober.io/LICENSE.pdf\n\npragma solidity ^0.8.0;\n\nimport \"./PackedUint256.sol\";\nimport \"./DirtyUint64.sol\";\n\n/**\n * 🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲\n *\n * Segmented Segment Tree\n * by Clober\n *\n * ____________/\\\\\\_______________/\\\\\\\\\\____________/\\\\\\____\n * __________/\\\\\\\\\\___________/\\\\\\\\////___________/\\\\\\\\\\____\n * ________/\\\\\\/\\\\\\________/\\\\\\///______________/\\\\\\/\\\\\\____\n * ______/\\\\\\/\\/\\\\\\______/\\\\\\\\\\\\\\\\\\\\\\_________/\\\\\\/\\/\\\\\\____\n * ____/\\\\\\/__\\/\\\\\\_____/\\\\\\\\///////\\\\\\_____/\\\\\\/__\\/\\\\\\____\n * __/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_\\/\\\\\\______\\//\\\\\\__/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_\n * _\\///////////\\\\\\//__\\//\\\\\\______/\\\\\\__\\///////////\\\\\\//__\n * ___________\\/\\\\\\_____\\///\\\\\\\\\\\\\\\\\\/_____________\\/\\\\\\____\n * ___________\\///________\\/////////_______________\\///_____\n *\n * 4 Layers of 64-bit nodes, hence 464\n *\n * 🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲\n */\nlibrary SegmentedSegmentTree {\n using PackedUint256 for uint256;\n using DirtyUint64 for uint64;\n\n error SegmentedSegmentTreeError(uint256 errorCode);\n\n uint256 private constant _INDEX_ERROR = 0;\n uint256 private constant _OVERFLOW_ERROR = 1;\n\n // uint8 private constant _R = 2; // There are `2` root node groups\n // uint8 private constant _C = 4; // There are `4` children (each child is a node group of its own) for each node\n uint8 private constant _L = 4; // There are `4` layers of node groups\n uint256 private constant _P = 4; // uint256 / uint64 = `4`\n uint256 private constant _P_M = 3; // % 4 = & `3`\n uint256 private constant _P_P = 2; // 2 ** `2` = 4\n uint256 private constant _N_P = 4; // C * P = 2 ** `4`\n uint256 private constant _MAX_NODES = 2 ** 15; // (R * P) * ((C * P) ** (L - 1)) = `32768`\n uint256 private constant _MAX_NODES_P_MINUS_ONE = 14; // MAX_NODES / R = 2 ** `14`\n\n struct Core {\n mapping(uint256 => uint256)[_L] layers;\n }\n\n struct LayerIndex {\n uint256 group;\n uint256 node;\n }\n\n function get(Core storage core, uint256 index) internal view returns (uint64 ret) {\n if (index >= _MAX_NODES) {\n revert SegmentedSegmentTreeError(_INDEX_ERROR);\n }\n unchecked {\n ret = core.layers[_L - 1][index >> _P_P].get64(index & _P_M).toClean();\n }\n }\n\n function total(Core storage core) internal view returns (uint64) {\n return DirtyUint64.sumPackedUnsafe(core.layers[0][0], 0, _P)\n + DirtyUint64.sumPackedUnsafe(core.layers[0][1], 0, _P);\n }\n\n function query(Core storage core, uint256 left, uint256 right) internal view returns (uint64 sum) {\n if (left == right) {\n return 0;\n }\n // right should be greater than left\n if (left >= right) {\n revert SegmentedSegmentTreeError(_INDEX_ERROR);\n }\n if (right > _MAX_NODES) {\n revert SegmentedSegmentTreeError(_INDEX_ERROR);\n }\n\n LayerIndex[] memory leftIndices = _getLayerIndices(left);\n LayerIndex[] memory rightIndices = _getLayerIndices(right);\n uint256 ret;\n uint256 deficit;\n\n unchecked {\n uint256 leftNodeIndex;\n uint256 rightNodeIndex;\n for (uint256 l = _L - 1;; --l) {\n LayerIndex memory leftIndex = leftIndices[l];\n LayerIndex memory rightIndex = rightIndices[l];\n leftNodeIndex += leftIndex.node;\n rightNodeIndex += rightIndex.node;\n\n if (rightIndex.group == leftIndex.group) {\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, rightNodeIndex);\n break;\n }\n\n if (rightIndex.group - leftIndex.group < 4) {\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, _P);\n\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], 0, rightNodeIndex);\n\n for (uint256 group = leftIndex.group + 1; group < rightIndex.group; group++) {\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][group], 0, _P);\n }\n break;\n }\n\n if (leftIndex.group % 4 == 0) {\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], 0, leftNodeIndex);\n leftNodeIndex = 0;\n } else if (leftIndex.group % 4 == 1) {\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group - 1], 0, _P);\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], 0, leftNodeIndex);\n leftNodeIndex = 0;\n } else if (leftIndex.group % 4 == 2) {\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, _P);\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group + 1], 0, _P);\n leftNodeIndex = 1;\n } else {\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][leftIndex.group], leftNodeIndex, _P);\n leftNodeIndex = 1;\n }\n\n if (rightIndex.group % 4 == 0) {\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], 0, rightNodeIndex);\n rightNodeIndex = 0;\n } else if (rightIndex.group % 4 == 1) {\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group - 1], 0, _P);\n ret += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], 0, rightNodeIndex);\n rightNodeIndex = 0;\n } else if (rightIndex.group % 4 == 2) {\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], rightNodeIndex, _P);\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group + 1], 0, _P);\n rightNodeIndex = 1;\n } else {\n deficit += DirtyUint64.sumPackedUnsafe(core.layers[l][rightIndex.group], rightNodeIndex, _P);\n rightNodeIndex = 1;\n }\n }\n ret -= deficit;\n }\n sum = uint64(ret);\n }\n\n function update(Core storage core, uint256 index, uint64 value) internal returns (uint64 replaced) {\n if (index >= _MAX_NODES) {\n revert SegmentedSegmentTreeError(_INDEX_ERROR);\n }\n LayerIndex[] memory indices = _getLayerIndices(index);\n unchecked {\n LayerIndex memory bottomIndex = indices[_L - 1];\n replaced = core.layers[_L - 1][bottomIndex.group].get64Unsafe(bottomIndex.node).toClean();\n if (replaced >= value) {\n uint64 diff = replaced - value;\n for (uint256 l = 0; l < _L; ++l) {\n LayerIndex memory layerIndex = indices[l];\n uint256 node = core.layers[l][layerIndex.group];\n core.layers[l][layerIndex.group] =\n node.update64(layerIndex.node, node.get64(layerIndex.node).subClean(diff));\n }\n } else {\n uint64 diff = value - replaced;\n if (total(core) > type(uint64).max - diff) revert SegmentedSegmentTreeError(_OVERFLOW_ERROR);\n for (uint256 l = 0; l < _L; ++l) {\n LayerIndex memory layerIndex = indices[l];\n uint256 node = core.layers[l][layerIndex.group];\n core.layers[l][layerIndex.group] =\n node.update64(layerIndex.node, node.get64(layerIndex.node).addClean(diff));\n }\n }\n }\n }\n\n function _getLayerIndices(uint256 index) private pure returns (LayerIndex[] memory) {\n unchecked {\n LayerIndex[] memory indices = new LayerIndex[](_L);\n uint256 shifter = _MAX_NODES_P_MINUS_ONE;\n for (uint256 l = 0; l < _L; ++l) {\n indices[l] = LayerIndex({group: index >> shifter, node: (index >> (shifter - _P_P)) & _P_M});\n shifter = shifter - _N_P;\n }\n return indices;\n }\n }\n}\n\n/*\n * Segmented Segment Tree is a Segment Tree\n * that has been compressed so that `C` nodes\n * are compressed into a single uint256.\n *\n * Each node in a non-leaf node group is the sum of the\n * total sum of each child node group that it represents.\n * Each non-leaf node represents `E` node groups.\n *\n * A node group consists of `S` uint256.\n *\n * By expressing the index in `N` notation,\n * we can find the index in each respective layer\n *\n * S: Size of each node group\n * C: Compression Coefficient\n * E: Expansion Coefficient\n * L: Number of Layers\n * N: Notation, S * C * E\n *\n * `E` will not be considered for this version of the implementation. (E = 2)\n */\n" + }, + "src/libraries/SignificantBit.sol": { + "content": "// SPDX-License-Identifier: GPL-2.0-or-later\n\npragma solidity ^0.8.0;\n\nlibrary SignificantBit {\n // http://supertech.csail.mit.edu/papers/debruijn.pdf\n uint256 internal constant DEBRUIJN_SEQ = 0x818283848586878898A8B8C8D8E8F929395969799A9B9D9E9FAAEB6BEDEEFF;\n bytes internal constant DEBRUIJN_INDEX =\n hex\"0001020903110a19042112290b311a3905412245134d2a550c5d32651b6d3a7506264262237d468514804e8d2b95569d0d495ea533a966b11c886eb93bc176c9071727374353637324837e9b47af86c7155181ad4fd18ed32c9096db57d59ee30e2e4a6a5f92a6be3498aae067ddb2eb1d5989b56fd7baf33ca0c2ee77e5caf7ff0810182028303840444c545c646c7425617c847f8c949c48a4a8b087b8c0c816365272829aaec650acd0d28fdad4e22d6991bd97dfdcea58b4d6f29fede4f6fe0f1f2f3f4b5b6b607b8b93a3a7b7bf357199c5abcfd9e168bcdee9b3f1ecf5fd1e3e5a7a8aa2b670c4ced8bbe8f0f4fc3d79a1c3cde7effb78cce6facbf9f8\";\n\n /**\n * @notice Finds the index of the least significant bit.\n * @param x The value to compute the least significant bit for. Must be a non-zero value.\n * @return ret The index of the least significant bit.\n */\n function leastSignificantBit(uint256 x) internal pure returns (uint8) {\n require(x > 0);\n uint256 index;\n assembly {\n index := shr(248, mul(and(x, add(not(x), 1)), DEBRUIJN_SEQ))\n }\n return uint8(DEBRUIJN_INDEX[index]); // can optimize with CODECOPY opcode\n }\n\n function mostSignificantBit(uint256 x) internal pure returns (uint8 msb) {\n require(x > 0);\n assembly {\n let f := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n msb := or(msb, f)\n x := shr(f, x)\n f := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n msb := or(msb, f)\n x := shr(f, x)\n f := shl(5, gt(x, 0xFFFFFFFF))\n msb := or(msb, f)\n x := shr(f, x)\n f := shl(4, gt(x, 0xFFFF))\n msb := or(msb, f)\n x := shr(f, x)\n f := shl(3, gt(x, 0xFF))\n msb := or(msb, f)\n x := shr(f, x)\n f := shl(2, gt(x, 0xF))\n msb := or(msb, f)\n x := shr(f, x)\n f := shl(1, gt(x, 0x3))\n msb := or(msb, f)\n x := shr(f, x)\n f := gt(x, 0x1)\n msb := or(msb, f)\n }\n }\n}\n" + }, + "src/libraries/Tick.sol": { + "content": "// SPDX-License-Identifier: GPL-2.0-or-later\n\npragma solidity ^0.8.20;\n\nimport {Math} from \"./Math.sol\";\n\ntype Tick is int24;\n\nlibrary TickLibrary {\n using Math for *;\n using TickLibrary for Tick;\n\n error InvalidTick();\n error InvalidPrice();\n error TickOverflow();\n\n int24 internal constant MAX_TICK = 2 ** 19 - 1;\n int24 internal constant MIN_TICK = -MAX_TICK;\n\n uint256 internal constant MIN_PRICE = 1350587;\n uint256 internal constant MAX_PRICE = 4647684107270898330752324302845848816923571339324334;\n\n uint256 private constant _R0 = 0xfff97272373d413259a46990;\n uint256 private constant _R1 = 0xfff2e50f5f656932ef12357c;\n uint256 private constant _R2 = 0xffe5caca7e10e4e61c3624ea;\n uint256 private constant _R3 = 0xffcb9843d60f6159c9db5883;\n uint256 private constant _R4 = 0xff973b41fa98c081472e6896;\n uint256 private constant _R5 = 0xff2ea16466c96a3843ec78b3;\n uint256 private constant _R6 = 0xfe5dee046a99a2a811c461f1;\n uint256 private constant _R7 = 0xfcbe86c7900a88aedcffc83b;\n uint256 private constant _R8 = 0xf987a7253ac413176f2b074c;\n uint256 private constant _R9 = 0xf3392b0822b70005940c7a39;\n uint256 private constant _R10 = 0xe7159475a2c29b7443b29c7f;\n uint256 private constant _R11 = 0xd097f3bdfd2022b8845ad8f7;\n uint256 private constant _R12 = 0xa9f746462d870fdf8a65dc1f;\n uint256 private constant _R13 = 0x70d869a156d2a1b890bb3df6;\n uint256 private constant _R14 = 0x31be135f97d08fd981231505;\n uint256 private constant _R15 = 0x9aa508b5b7a84e1c677de54;\n uint256 private constant _R16 = 0x5d6af8dedb81196699c329;\n uint256 private constant _R17 = 0x2216e584f5fa1ea92604;\n uint256 private constant _R18 = 0x48a170391f7dc42;\n uint256 private constant _R19 = 0x149b34;\n\n function validateTick(Tick tick) internal pure {\n if (Tick.unwrap(tick) > MAX_TICK || Tick.unwrap(tick) < MIN_TICK) revert InvalidTick();\n }\n\n modifier validatePrice(uint256 price) {\n if (price > MAX_PRICE || price < MIN_PRICE) revert InvalidPrice();\n _;\n }\n\n function fromPrice(uint256 price) internal pure validatePrice(price) returns (Tick) {\n unchecked {\n int24 tick = int24((int256(price).lnWad() * 42951820407860) / 2 ** 128);\n if (toPrice(Tick.wrap(tick)) > price) return Tick.wrap(tick - 1);\n return Tick.wrap(tick);\n }\n }\n\n function toPrice(Tick tick) internal pure returns (uint256 price) {\n validateTick(tick);\n int24 tickValue = Tick.unwrap(tick);\n uint256 absTick = uint24(tickValue < 0 ? -tickValue : tickValue);\n\n unchecked {\n if (absTick & 0x1 != 0) price = _R0;\n else price = 1 << 96;\n if (absTick & 0x2 != 0) price = (price * _R1) >> 96;\n if (absTick & 0x4 != 0) price = (price * _R2) >> 96;\n if (absTick & 0x8 != 0) price = (price * _R3) >> 96;\n if (absTick & 0x10 != 0) price = (price * _R4) >> 96;\n if (absTick & 0x20 != 0) price = (price * _R5) >> 96;\n if (absTick & 0x40 != 0) price = (price * _R6) >> 96;\n if (absTick & 0x80 != 0) price = (price * _R7) >> 96;\n if (absTick & 0x100 != 0) price = (price * _R8) >> 96;\n if (absTick & 0x200 != 0) price = (price * _R9) >> 96;\n if (absTick & 0x400 != 0) price = (price * _R10) >> 96;\n if (absTick & 0x800 != 0) price = (price * _R11) >> 96;\n if (absTick & 0x1000 != 0) price = (price * _R12) >> 96;\n if (absTick & 0x2000 != 0) price = (price * _R13) >> 96;\n if (absTick & 0x4000 != 0) price = (price * _R14) >> 96;\n if (absTick & 0x8000 != 0) price = (price * _R15) >> 96;\n if (absTick & 0x10000 != 0) price = (price * _R16) >> 96;\n if (absTick & 0x20000 != 0) price = (price * _R17) >> 96;\n if (absTick & 0x40000 != 0) price = (price * _R18) >> 96;\n }\n if (tickValue > 0) price = 0x1000000000000000000000000000000000000000000000000 / price;\n }\n\n function gt(Tick a, Tick b) internal pure returns (bool) {\n return Tick.unwrap(a) > Tick.unwrap(b);\n }\n\n function baseToQuote(Tick tick, uint256 base, bool roundingUp) internal pure returns (uint256) {\n return Math.divide((base * tick.toPrice()), 1 << 96, roundingUp);\n }\n\n function quoteToBase(Tick tick, uint256 quote, bool roundingUp) internal pure returns (uint256) {\n // @dev quote = unit(uint64) * unitSize(uint64) < 2^96\n // We don't need to check overflow here\n return Math.divide(quote << 96, tick.toPrice(), roundingUp);\n }\n}\n" + }, + "src/libraries/TickBitmap.sol": { + "content": "// SPDX-License-Identifier: -\n// License: https://license.clober.io/LICENSE_V2.pdf\n\npragma solidity ^0.8.0;\n\nimport {SignificantBit} from \"./SignificantBit.sol\";\nimport {Tick} from \"./Tick.sol\";\n\nlibrary TickBitmap {\n using SignificantBit for uint256;\n\n error EmptyError();\n error AlreadyExistsError();\n\n uint256 public constant B0_BITMAP_KEY = uint256(keccak256(\"TickBitmap\")) + 1;\n uint256 public constant MAX_UINT_256_MINUS_1 = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe;\n\n function has(mapping(uint256 => uint256) storage self, Tick tick) internal view returns (bool) {\n (uint256 b0b1, uint256 b2) = _split(tick);\n uint256 mask = 1 << b2;\n return self[b0b1] & mask == mask;\n }\n\n function isEmpty(mapping(uint256 => uint256) storage self) internal view returns (bool) {\n return self[B0_BITMAP_KEY] == 0;\n }\n\n function _split(Tick tick) private pure returns (uint256 b0b1, uint256 b2) {\n assembly {\n let value := add(not(tick), 0x800000)\n b0b1 := shr(8, and(value, 0xffff00))\n b2 := and(value, 0xff)\n }\n }\n\n function highest(mapping(uint256 => uint256) storage self) internal view returns (Tick) {\n if (isEmpty(self)) revert EmptyError();\n\n uint256 b0 = self[B0_BITMAP_KEY].leastSignificantBit();\n uint256 b0b1 = (b0 << 8) | (self[~b0].leastSignificantBit());\n uint256 b2 = self[b0b1].leastSignificantBit();\n return _toTick((b0b1 << 8) | b2);\n }\n\n function set(mapping(uint256 => uint256) storage self, Tick tick) internal {\n (uint256 b0b1, uint256 b2) = _split(tick);\n uint256 mask = 1 << b2;\n uint256 b2Bitmap = self[b0b1];\n if (b2Bitmap & mask > 0) revert AlreadyExistsError();\n\n self[b0b1] = b2Bitmap | mask;\n if (b2Bitmap == 0) {\n mask = 1 << (b0b1 & 0xff);\n uint256 b1BitmapKey = ~(b0b1 >> 8);\n uint256 b1Bitmap = self[b1BitmapKey];\n self[b1BitmapKey] = b1Bitmap | mask;\n\n if (b1Bitmap == 0) self[B0_BITMAP_KEY] = self[B0_BITMAP_KEY] | (1 << ~b1BitmapKey);\n }\n }\n\n function clear(mapping(uint256 => uint256) storage self, Tick tick) internal {\n (uint256 b0b1, uint256 b2) = _split(tick);\n uint256 mask = 1 << b2;\n uint256 b2Bitmap = self[b0b1];\n\n self[b0b1] = b2Bitmap & (~mask);\n if (b2Bitmap == mask) {\n mask = 1 << (b0b1 & 0xff);\n uint256 b1BitmapKey = ~(b0b1 >> 8);\n uint256 b1Bitmap = self[b1BitmapKey];\n\n self[b1BitmapKey] = b1Bitmap & (~mask);\n if (mask == b1Bitmap) {\n mask = 1 << (~b1BitmapKey);\n self[B0_BITMAP_KEY] = self[B0_BITMAP_KEY] & (~mask);\n }\n }\n }\n\n function maxLessThan(mapping(uint256 => uint256) storage self, Tick tick) internal view returns (Tick) {\n (uint256 b0b1, uint256 b2) = _split(tick);\n uint256 b2Bitmap = (MAX_UINT_256_MINUS_1 << b2) & self[b0b1];\n if (b2Bitmap == 0) {\n uint256 b0 = b0b1 >> 8;\n uint256 b1Bitmap = (MAX_UINT_256_MINUS_1 << (b0b1 & 0xff)) & self[~b0];\n if (b1Bitmap == 0) {\n uint256 b0Bitmap = (MAX_UINT_256_MINUS_1 << b0) & self[B0_BITMAP_KEY];\n if (b0Bitmap == 0) return Tick.wrap(type(int24).min);\n b0 = b0Bitmap.leastSignificantBit();\n b1Bitmap = self[~b0];\n }\n b0b1 = (b0 << 8) | b1Bitmap.leastSignificantBit();\n b2Bitmap = self[b0b1];\n }\n b2 = b2Bitmap.leastSignificantBit();\n return _toTick((b0b1 << 8) | b2);\n }\n\n function _toTick(uint256 raw) private pure returns (Tick t) {\n assembly {\n t := and(not(sub(raw, 0x800000)), 0xffffff)\n }\n }\n}\n" + }, + "src/libraries/TotalClaimableMap.sol": { + "content": "// SPDX-License-Identifier: -\n// License: https://license.clober.io/LICENSE_V2.pdf\n\npragma solidity ^0.8.20;\n\nimport {DirtyUint64} from \"./DirtyUint64.sol\";\nimport {PackedUint256} from \"./PackedUint256.sol\";\nimport {Tick} from \"./Tick.sol\";\n\nlibrary TotalClaimableMap {\n using DirtyUint64 for uint64;\n using PackedUint256 for uint256;\n\n // @dev n should be less than type(uint64).max due to the dirty storage logic.\n function add(mapping(uint24 => uint256) storage self, Tick tick, uint64 n) internal {\n (uint24 groupIndex, uint8 elementIndex) = _splitTick(tick);\n uint256 group = self[groupIndex];\n // @notice Be aware of dirty storage add logic\n self[groupIndex] = group.update64Unsafe(\n elementIndex, // elementIndex < 4\n group.get64Unsafe(elementIndex).addClean(n)\n );\n }\n\n function sub(mapping(uint24 => uint256) storage self, Tick tick, uint64 n) internal {\n (uint24 groupIndex, uint8 elementIndex) = _splitTick(tick);\n self[groupIndex] = self[groupIndex].sub64Unsafe(elementIndex, n);\n }\n\n function get(mapping(uint24 => uint256) storage self, Tick tick) internal view returns (uint64) {\n (uint24 groupIndex, uint8 elementIndex) = _splitTick(tick);\n return self[groupIndex].get64Unsafe(elementIndex).toClean();\n }\n\n function _splitTick(Tick tick) internal pure returns (uint24 groupIndex, uint8 elementIndex) {\n uint256 casted = uint24(Tick.unwrap(tick));\n assembly {\n groupIndex := shr(2, casted) // div 4\n elementIndex := and(casted, 3) // mod 4\n }\n }\n}\n" + } + }, + "settings": { + "evmVersion": "cancun", + "optimizer": { + "enabled": true, + "runs": 1000 + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "evm.bytecode", + "evm.deployedBytecode", + "evm.methodIdentifiers", + "metadata", + "devdoc", + "userdoc", + "storageLayout", + "evm.gasEstimates" + ], + "": [ + "ast" + ] + } + }, + "metadata": { + "useLiteralContent": true + } + } +} \ No newline at end of file