Skip to content

Instantly share code, notes, and snippets.

@PaulRBerg
Last active December 18, 2023 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulRBerg/5b130690330ffa6cf28fc5fa238e56ce to your computer and use it in GitHub Desktop.
Save PaulRBerg/5b130690330ffa6cf28fc5fa238e56ce to your computer and use it in GitHub Desktop.
Standard JSON input to verify the SablierV2LockupLinear contract (V2.1 release) on Ethereum Mainnet
0x00000000000000000000000079fb3e81aac012c08501f41296ccc145a1e15844000000000000000000000000c3be6bffaeab7b297c03383b4254aa3af2b9a5ba00000000000000000000000023ed5da55af4286c0de55facb414dee2e317f4cb
{
"language": "Solidity",
"sources": {
"src/SablierV2LockupLinear.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity >=0.8.19;\n\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { ERC721 } from \"@openzeppelin/contracts/token/ERC721/ERC721.sol\";\nimport { UD60x18, ud } from \"@prb/math/src/UD60x18.sol\";\n\nimport { SablierV2Lockup } from \"./abstracts/SablierV2Lockup.sol\";\nimport { ISablierV2Comptroller } from \"./interfaces/ISablierV2Comptroller.sol\";\nimport { ISablierV2Lockup } from \"./interfaces/ISablierV2Lockup.sol\";\nimport { ISablierV2LockupLinear } from \"./interfaces/ISablierV2LockupLinear.sol\";\nimport { ISablierV2NFTDescriptor } from \"./interfaces/ISablierV2NFTDescriptor.sol\";\nimport { ISablierV2LockupRecipient } from \"./interfaces/hooks/ISablierV2LockupRecipient.sol\";\nimport { Errors } from \"./libraries/Errors.sol\";\nimport { Helpers } from \"./libraries/Helpers.sol\";\nimport { Lockup, LockupLinear } from \"./types/DataTypes.sol\";\n\n/*\n\n███████╗ █████╗ ██████╗ ██╗ ██╗███████╗██████╗ ██╗ ██╗██████╗\n██╔════╝██╔══██╗██╔══██╗██║ ██║██╔════╝██╔══██╗ ██║ ██║╚════██╗\n███████╗███████║██████╔╝██║ ██║█████╗ ██████╔╝ ██║ ██║ █████╔╝\n╚════██║██╔══██║██╔══██╗██║ ██║██╔══╝ ██╔══██╗ ╚██╗ ██╔╝██╔═══╝\n███████║██║ ██║██████╔╝███████╗██║███████╗██║ ██║ ╚████╔╝ ███████╗\n╚══════╝╚═╝ ╚═╝╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚══════╝\n\n██╗ ██████╗ ██████╗██╗ ██╗██╗ ██╗██████╗ ██╗ ██╗███╗ ██╗███████╗ █████╗ ██████╗\n██║ ██╔═══██╗██╔════╝██║ ██╔╝██║ ██║██╔══██╗ ██║ ██║████╗ ██║██╔════╝██╔══██╗██╔══██╗\n██║ ██║ ██║██║ █████╔╝ ██║ ██║██████╔╝ ██║ ██║██╔██╗ ██║█████╗ ███████║██████╔╝\n██║ ██║ ██║██║ ██╔═██╗ ██║ ██║██╔═══╝ ██║ ██║██║╚██╗██║██╔══╝ ██╔══██║██╔══██╗\n███████╗╚██████╔╝╚██████╗██║ ██╗╚██████╔╝██║ ███████╗██║██║ ╚████║███████╗██║ ██║██║ ██║\n╚══════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝\n\n*/\n\n/// @title SablierV2LockupLinear\n/// @notice See the documentation in {ISablierV2LockupLinear}.\ncontract SablierV2LockupLinear is\n ISablierV2LockupLinear, // 5 inherited components\n SablierV2Lockup // 14 inherited components\n{\n using SafeERC20 for IERC20;\n\n /*//////////////////////////////////////////////////////////////////////////\n PRIVATE STORAGE\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @dev Sablier V2 Lockup Linear streams mapped by unsigned integers.\n mapping(uint256 id => LockupLinear.Stream stream) private _streams;\n\n /*//////////////////////////////////////////////////////////////////////////\n CONSTRUCTOR\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @dev Emits a {TransferAdmin} event.\n /// @param initialAdmin The address of the initial contract admin.\n /// @param initialComptroller The address of the initial comptroller.\n /// @param initialNFTDescriptor The address of the initial NFT descriptor.\n constructor(\n address initialAdmin,\n ISablierV2Comptroller initialComptroller,\n ISablierV2NFTDescriptor initialNFTDescriptor\n )\n ERC721(\"Sablier V2 Lockup Linear NFT\", \"SAB-V2-LOCKUP-LIN\")\n SablierV2Lockup(initialAdmin, initialComptroller, initialNFTDescriptor)\n {\n nextStreamId = 1;\n }\n\n /*//////////////////////////////////////////////////////////////////////////\n USER-FACING CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @inheritdoc ISablierV2Lockup\n function getAsset(uint256 streamId) external view override notNull(streamId) returns (IERC20 asset) {\n asset = _streams[streamId].asset;\n }\n\n /// @inheritdoc ISablierV2LockupLinear\n function getCliffTime(uint256 streamId) external view override notNull(streamId) returns (uint40 cliffTime) {\n cliffTime = _streams[streamId].cliffTime;\n }\n\n /// @inheritdoc ISablierV2Lockup\n function getDepositedAmount(uint256 streamId)\n external\n view\n override\n notNull(streamId)\n returns (uint128 depositedAmount)\n {\n depositedAmount = _streams[streamId].amounts.deposited;\n }\n\n /// @inheritdoc ISablierV2Lockup\n function getEndTime(uint256 streamId) external view override notNull(streamId) returns (uint40 endTime) {\n endTime = _streams[streamId].endTime;\n }\n\n /// @inheritdoc ISablierV2LockupLinear\n function getRange(uint256 streamId)\n external\n view\n override\n notNull(streamId)\n returns (LockupLinear.Range memory range)\n {\n range = LockupLinear.Range({\n start: _streams[streamId].startTime,\n cliff: _streams[streamId].cliffTime,\n end: _streams[streamId].endTime\n });\n }\n\n /// @inheritdoc ISablierV2Lockup\n function getRefundedAmount(uint256 streamId)\n external\n view\n override\n notNull(streamId)\n returns (uint128 refundedAmount)\n {\n refundedAmount = _streams[streamId].amounts.refunded;\n }\n\n /// @inheritdoc ISablierV2Lockup\n function getSender(uint256 streamId) external view override notNull(streamId) returns (address sender) {\n sender = _streams[streamId].sender;\n }\n\n /// @inheritdoc ISablierV2Lockup\n function getStartTime(uint256 streamId) external view override notNull(streamId) returns (uint40 startTime) {\n startTime = _streams[streamId].startTime;\n }\n\n /// @inheritdoc ISablierV2LockupLinear\n function getStream(uint256 streamId)\n external\n view\n override\n notNull(streamId)\n returns (LockupLinear.Stream memory stream)\n {\n stream = _streams[streamId];\n\n // Settled streams cannot be canceled.\n if (_statusOf(streamId) == Lockup.Status.SETTLED) {\n stream.isCancelable = false;\n }\n }\n\n /// @inheritdoc ISablierV2Lockup\n function getWithdrawnAmount(uint256 streamId)\n external\n view\n override\n notNull(streamId)\n returns (uint128 withdrawnAmount)\n {\n withdrawnAmount = _streams[streamId].amounts.withdrawn;\n }\n\n /// @inheritdoc ISablierV2Lockup\n function isCancelable(uint256 streamId) external view override notNull(streamId) returns (bool result) {\n if (_statusOf(streamId) != Lockup.Status.SETTLED) {\n result = _streams[streamId].isCancelable;\n }\n }\n\n /// @inheritdoc SablierV2Lockup\n function isTransferable(uint256 streamId)\n public\n view\n override(ISablierV2Lockup, SablierV2Lockup)\n notNull(streamId)\n returns (bool result)\n {\n result = _streams[streamId].isTransferable;\n }\n\n /// @inheritdoc ISablierV2Lockup\n function isDepleted(uint256 streamId)\n public\n view\n override(ISablierV2Lockup, SablierV2Lockup)\n notNull(streamId)\n returns (bool result)\n {\n result = _streams[streamId].isDepleted;\n }\n\n /// @inheritdoc ISablierV2Lockup\n function isStream(uint256 streamId) public view override(ISablierV2Lockup, SablierV2Lockup) returns (bool result) {\n result = _streams[streamId].isStream;\n }\n\n /// @inheritdoc ISablierV2Lockup\n function refundableAmountOf(uint256 streamId)\n external\n view\n override\n notNull(streamId)\n returns (uint128 refundableAmount)\n {\n // These checks are needed because {_calculateStreamedAmount} does not look up the stream's status. Note that\n // checking for `isCancelable` also checks if the stream `wasCanceled` thanks to the protocol invariant that\n // canceled streams are not cancelable anymore.\n if (_streams[streamId].isCancelable && !_streams[streamId].isDepleted) {\n refundableAmount = _streams[streamId].amounts.deposited - _calculateStreamedAmount(streamId);\n }\n // Otherwise, the result is implicitly zero.\n }\n\n /// @inheritdoc ISablierV2Lockup\n function statusOf(uint256 streamId) external view override notNull(streamId) returns (Lockup.Status status) {\n status = _statusOf(streamId);\n }\n\n /// @inheritdoc ISablierV2LockupLinear\n function streamedAmountOf(uint256 streamId)\n public\n view\n override(ISablierV2Lockup, ISablierV2LockupLinear)\n notNull(streamId)\n returns (uint128 streamedAmount)\n {\n streamedAmount = _streamedAmountOf(streamId);\n }\n\n /// @inheritdoc ISablierV2Lockup\n function wasCanceled(uint256 streamId)\n public\n view\n override(ISablierV2Lockup, SablierV2Lockup)\n notNull(streamId)\n returns (bool result)\n {\n result = _streams[streamId].wasCanceled;\n }\n\n /*//////////////////////////////////////////////////////////////////////////\n USER-FACING NON-CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @inheritdoc ISablierV2LockupLinear\n function createWithDurations(LockupLinear.CreateWithDurations calldata params)\n external\n override\n noDelegateCall\n returns (uint256 streamId)\n {\n // Set the current block timestamp as the stream's start time.\n LockupLinear.Range memory range;\n range.start = uint40(block.timestamp);\n\n // Calculate the cliff time and the end time. It is safe to use unchecked arithmetic because\n // {_createWithRange} will nonetheless check that the end time is greater than the cliff time,\n // and also that the cliff time is greater than or equal to the start time.\n unchecked {\n range.cliff = range.start + params.durations.cliff;\n range.end = range.start + params.durations.total;\n }\n // Checks, Effects and Interactions: create the stream.\n streamId = _createWithRange(\n LockupLinear.CreateWithRange({\n asset: params.asset,\n broker: params.broker,\n cancelable: params.cancelable,\n transferable: params.transferable,\n range: range,\n recipient: params.recipient,\n sender: params.sender,\n totalAmount: params.totalAmount\n })\n );\n }\n\n /// @inheritdoc ISablierV2LockupLinear\n function createWithRange(LockupLinear.CreateWithRange calldata params)\n external\n override\n noDelegateCall\n returns (uint256 streamId)\n {\n // Checks, Effects and Interactions: create the stream.\n streamId = _createWithRange(params);\n }\n\n /*//////////////////////////////////////////////////////////////////////////\n INTERNAL CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @dev Calculates the streamed amount without looking up the stream's status.\n function _calculateStreamedAmount(uint256 streamId) internal view returns (uint128) {\n // If the cliff time is in the future, return zero.\n uint256 cliffTime = uint256(_streams[streamId].cliffTime);\n uint256 currentTime = block.timestamp;\n if (cliffTime > currentTime) {\n return 0;\n }\n\n // If the end time is not in the future, return the deposited amount.\n uint256 endTime = uint256(_streams[streamId].endTime);\n if (currentTime >= endTime) {\n return _streams[streamId].amounts.deposited;\n }\n\n // In all other cases, calculate the amount streamed so far. Normalization to 18 decimals is not needed\n // because there is no mix of amounts with different decimals.\n unchecked {\n // Calculate how much time has passed since the stream started, and the stream's total duration.\n uint256 startTime = uint256(_streams[streamId].startTime);\n UD60x18 elapsedTime = ud(currentTime - startTime);\n UD60x18 totalTime = ud(endTime - startTime);\n\n // Divide the elapsed time by the stream's total duration.\n UD60x18 elapsedTimePercentage = elapsedTime.div(totalTime);\n\n // Cast the deposited amount to UD60x18.\n UD60x18 depositedAmount = ud(_streams[streamId].amounts.deposited);\n\n // Calculate the streamed amount by multiplying the elapsed time percentage by the deposited amount.\n UD60x18 streamedAmount = elapsedTimePercentage.mul(depositedAmount);\n\n // Although the streamed amount should never exceed the deposited amount, this condition is checked\n // without asserting to avoid locking funds in case of a bug. If this situation occurs, the withdrawn\n // amount is considered to be the streamed amount, and the stream is effectively frozen.\n if (streamedAmount.gt(depositedAmount)) {\n return _streams[streamId].amounts.withdrawn;\n }\n\n // Cast the streamed amount to uint128. This is safe due to the check above.\n return uint128(streamedAmount.intoUint256());\n }\n }\n\n /// @inheritdoc SablierV2Lockup\n function _isCallerStreamSender(uint256 streamId) internal view override returns (bool) {\n return msg.sender == _streams[streamId].sender;\n }\n\n /// @inheritdoc SablierV2Lockup\n function _statusOf(uint256 streamId) internal view override returns (Lockup.Status) {\n if (_streams[streamId].isDepleted) {\n return Lockup.Status.DEPLETED;\n } else if (_streams[streamId].wasCanceled) {\n return Lockup.Status.CANCELED;\n }\n\n if (block.timestamp < _streams[streamId].startTime) {\n return Lockup.Status.PENDING;\n }\n\n if (_calculateStreamedAmount(streamId) < _streams[streamId].amounts.deposited) {\n return Lockup.Status.STREAMING;\n } else {\n return Lockup.Status.SETTLED;\n }\n }\n\n /// @dev See the documentation for the user-facing functions that call this internal function.\n function _streamedAmountOf(uint256 streamId) internal view returns (uint128) {\n Lockup.Amounts memory amounts = _streams[streamId].amounts;\n\n if (_streams[streamId].isDepleted) {\n return amounts.withdrawn;\n } else if (_streams[streamId].wasCanceled) {\n return amounts.deposited - amounts.refunded;\n }\n\n return _calculateStreamedAmount(streamId);\n }\n\n /// @dev See the documentation for the user-facing functions that call this internal function.\n function _withdrawableAmountOf(uint256 streamId) internal view override returns (uint128) {\n return _streamedAmountOf(streamId) - _streams[streamId].amounts.withdrawn;\n }\n\n /*//////////////////////////////////////////////////////////////////////////\n INTERNAL NON-CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @dev See the documentation for the user-facing functions that call this internal function.\n function _cancel(uint256 streamId) internal override {\n // Calculate the streamed amount.\n uint128 streamedAmount = _calculateStreamedAmount(streamId);\n\n // Retrieve the amounts from storage.\n Lockup.Amounts memory amounts = _streams[streamId].amounts;\n\n // Checks: the stream is not settled.\n if (streamedAmount >= amounts.deposited) {\n revert Errors.SablierV2Lockup_StreamSettled(streamId);\n }\n\n // Checks: the stream is cancelable.\n if (!_streams[streamId].isCancelable) {\n revert Errors.SablierV2Lockup_StreamNotCancelable(streamId);\n }\n\n // Calculate the sender's and the recipient's amount.\n uint128 senderAmount = amounts.deposited - streamedAmount;\n uint128 recipientAmount = streamedAmount - amounts.withdrawn;\n\n // Effects: mark the stream as canceled.\n _streams[streamId].wasCanceled = true;\n\n // Effects: make the stream not cancelable anymore, because a stream can only be canceled once.\n _streams[streamId].isCancelable = false;\n\n // Effects: If there are no assets left for the recipient to withdraw, mark the stream as depleted.\n if (recipientAmount == 0) {\n _streams[streamId].isDepleted = true;\n }\n\n // Effects: set the refunded amount.\n _streams[streamId].amounts.refunded = senderAmount;\n\n // Retrieve the sender and the recipient from storage.\n address sender = _streams[streamId].sender;\n address recipient = _ownerOf(streamId);\n\n // Retrieve the ERC-20 asset from storage.\n IERC20 asset = _streams[streamId].asset;\n\n // Interactions: refund the sender.\n asset.safeTransfer({ to: sender, value: senderAmount });\n\n // Log the cancellation.\n emit ISablierV2Lockup.CancelLockupStream(streamId, sender, recipient, asset, senderAmount, recipientAmount);\n\n // Emits an ERC-4906 event to trigger an update of the NFT metadata.\n emit MetadataUpdate({ _tokenId: streamId });\n\n // Interactions: if the recipient is a contract, try to invoke the cancel hook on the recipient without\n // reverting if the hook is not implemented, and without bubbling up any potential revert.\n if (recipient.code.length > 0) {\n try ISablierV2LockupRecipient(recipient).onStreamCanceled({\n streamId: streamId,\n sender: sender,\n senderAmount: senderAmount,\n recipientAmount: recipientAmount\n }) { } catch { }\n }\n }\n\n /// @dev See the documentation for the user-facing functions that call this internal function.\n function _createWithRange(LockupLinear.CreateWithRange memory params) internal returns (uint256 streamId) {\n // Safe Interactions: query the protocol fee. This is safe because it's a known Sablier contract that does\n // not call other unknown contracts.\n UD60x18 protocolFee = comptroller.protocolFees(params.asset);\n\n // Checks: check the fees and calculate the fee amounts.\n Lockup.CreateAmounts memory createAmounts =\n Helpers.checkAndCalculateFees(params.totalAmount, protocolFee, params.broker.fee, MAX_FEE);\n\n // Checks: validate the user-provided parameters.\n Helpers.checkCreateWithRange(createAmounts.deposit, params.range);\n\n // Load the stream id.\n streamId = nextStreamId;\n\n // Effects: create the stream.\n _streams[streamId] = LockupLinear.Stream({\n amounts: Lockup.Amounts({ deposited: createAmounts.deposit, refunded: 0, withdrawn: 0 }),\n asset: params.asset,\n cliffTime: params.range.cliff,\n endTime: params.range.end,\n isCancelable: params.cancelable,\n isTransferable: params.transferable,\n isDepleted: false,\n isStream: true,\n sender: params.sender,\n startTime: params.range.start,\n wasCanceled: false\n });\n\n // Effects: bump the next stream id and record the protocol fee.\n // Using unchecked arithmetic because these calculations cannot realistically overflow, ever.\n unchecked {\n nextStreamId = streamId + 1;\n protocolRevenues[params.asset] = protocolRevenues[params.asset] + createAmounts.protocolFee;\n }\n\n // Effects: mint the NFT to the recipient.\n _mint({ to: params.recipient, tokenId: streamId });\n\n // Interactions: transfer the deposit and the protocol fee.\n // Using unchecked arithmetic because the deposit and the protocol fee are bounded by the total amount.\n unchecked {\n params.asset.safeTransferFrom({\n from: msg.sender,\n to: address(this),\n value: createAmounts.deposit + createAmounts.protocolFee\n });\n }\n\n // Interactions: pay the broker fee, if not zero.\n if (createAmounts.brokerFee > 0) {\n params.asset.safeTransferFrom({ from: msg.sender, to: params.broker.account, value: createAmounts.brokerFee });\n }\n\n // Log the newly created stream.\n emit ISablierV2LockupLinear.CreateLockupLinearStream({\n streamId: streamId,\n funder: msg.sender,\n sender: params.sender,\n recipient: params.recipient,\n amounts: createAmounts,\n asset: params.asset,\n cancelable: params.cancelable,\n transferable: params.transferable,\n range: params.range,\n broker: params.broker.account\n });\n }\n\n /// @dev See the documentation for the user-facing functions that call this internal function.\n function _renounce(uint256 streamId) internal override {\n // Checks: the stream is cancelable.\n if (!_streams[streamId].isCancelable) {\n revert Errors.SablierV2Lockup_StreamNotCancelable(streamId);\n }\n\n // Effects: renounce the stream by making it not cancelable.\n _streams[streamId].isCancelable = false;\n }\n\n /// @dev See the documentation for the user-facing functions that call this internal function.\n function _withdraw(uint256 streamId, address to, uint128 amount) internal override {\n // Effects: update the withdrawn amount.\n _streams[streamId].amounts.withdrawn = _streams[streamId].amounts.withdrawn + amount;\n\n // Retrieve the amounts from storage.\n Lockup.Amounts memory amounts = _streams[streamId].amounts;\n\n // Using \">=\" instead of \"==\" for additional safety reasons. In the event of an unforeseen increase in the\n // withdrawn amount, the stream will still be marked as depleted.\n if (amounts.withdrawn >= amounts.deposited - amounts.refunded) {\n // Effects: mark the stream as depleted.\n _streams[streamId].isDepleted = true;\n\n // Effects: make the stream not cancelable anymore, because a depleted stream cannot be canceled.\n _streams[streamId].isCancelable = false;\n }\n\n // Retrieve the ERC-20 asset from storage.\n IERC20 asset = _streams[streamId].asset;\n\n // Interactions: perform the ERC-20 transfer.\n asset.safeTransfer({ to: to, value: amount });\n\n // Log the withdrawal.\n emit ISablierV2Lockup.WithdrawFromLockupStream(streamId, to, asset, amount);\n }\n}\n"
},
"node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\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 amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` 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 amount) 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 `amount` as the allowance of `spender` over the 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 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` 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 amount) external returns (bool);\n}\n"
},
"node_modules/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\nimport \"../extensions/IERC20Permit.sol\";\nimport \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n using Address for address;\n\n /**\n * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n */\n function safeTransfer(IERC20 token, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n }\n\n /**\n * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\n * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\n */\n function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n }\n\n /**\n * @dev Deprecated. This function has issues similar to the ones found in\n * {IERC20-approve}, and its usage is discouraged.\n *\n * Whenever possible, use {safeIncreaseAllowance} and\n * {safeDecreaseAllowance} instead.\n */\n function safeApprove(IERC20 token, address spender, uint256 value) internal {\n // safeApprove should only be called when setting an initial allowance,\n // or when resetting it to zero. To increase and decrease it, use\n // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n require(\n (value == 0) || (token.allowance(address(this), spender) == 0),\n \"SafeERC20: approve from non-zero to non-zero allowance\"\n );\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n }\n\n /**\n * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n */\n function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n uint256 oldAllowance = token.allowance(address(this), spender);\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));\n }\n\n /**\n * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n */\n function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n unchecked {\n uint256 oldAllowance = token.allowance(address(this), spender);\n require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));\n }\n }\n\n /**\n * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to\n * 0 before setting it to a non-zero value.\n */\n function forceApprove(IERC20 token, address spender, uint256 value) internal {\n bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);\n\n if (!_callOptionalReturnBool(token, approvalCall)) {\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));\n _callOptionalReturn(token, approvalCall);\n }\n }\n\n /**\n * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.\n * Revert on invalid signature.\n */\n function safePermit(\n IERC20Permit token,\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal {\n uint256 nonceBefore = token.nonces(owner);\n token.permit(owner, spender, value, deadline, v, r, s);\n uint256 nonceAfter = token.nonces(owner);\n require(nonceAfter == nonceBefore + 1, \"SafeERC20: permit did not succeed\");\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that\n // the target address contains contract code and also asserts for success in the low-level call.\n\n bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n require(returndata.length == 0 || abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.\n */\n function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false\n // and not revert is the subcall reverts.\n\n (bool success, bytes memory returndata) = address(token).call(data);\n return\n success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));\n }\n}\n"
},
"node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/ERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC721.sol\";\nimport \"./IERC721Receiver.sol\";\nimport \"./extensions/IERC721Metadata.sol\";\nimport \"../../utils/Address.sol\";\nimport \"../../utils/Context.sol\";\nimport \"../../utils/Strings.sol\";\nimport \"../../utils/introspection/ERC165.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 */\ncontract ERC721 is Context, ERC165, IERC721, IERC721Metadata {\n using Address for address;\n using Strings for uint256;\n\n // Token name\n string private _name;\n\n // Token symbol\n string private _symbol;\n\n // Mapping from token ID to owner address\n mapping(uint256 => address) private _owners;\n\n // Mapping owner address to token count\n mapping(address => uint256) private _balances;\n\n // Mapping from token ID to approved address\n mapping(uint256 => address) private _tokenApprovals;\n\n // Mapping from owner to operator approvals\n mapping(address => mapping(address => 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\n interfaceId == type(IERC721).interfaceId ||\n 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 override returns (uint256) {\n require(owner != address(0), \"ERC721: address zero is not a valid owner\");\n return _balances[owner];\n }\n\n /**\n * @dev See {IERC721-ownerOf}.\n */\n function ownerOf(uint256 tokenId) public view virtual override returns (address) {\n address owner = _ownerOf(tokenId);\n require(owner != address(0), \"ERC721: invalid token ID\");\n return owner;\n }\n\n /**\n * @dev See {IERC721Metadata-name}.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev See {IERC721Metadata-symbol}.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev See {IERC721Metadata-tokenURI}.\n */\n function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {\n _requireMinted(tokenId);\n\n string memory baseURI = _baseURI();\n return bytes(baseURI).length > 0 ? string(abi.encodePacked(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 override {\n address owner = ERC721.ownerOf(tokenId);\n require(to != owner, \"ERC721: approval to current owner\");\n\n require(\n _msgSender() == owner || isApprovedForAll(owner, _msgSender()),\n \"ERC721: approve caller is not token owner or approved for all\"\n );\n\n _approve(to, tokenId);\n }\n\n /**\n * @dev See {IERC721-getApproved}.\n */\n function getApproved(uint256 tokenId) public view virtual override returns (address) {\n _requireMinted(tokenId);\n\n return _tokenApprovals[tokenId];\n }\n\n /**\n * @dev See {IERC721-setApprovalForAll}.\n */\n function setApprovalForAll(address operator, bool approved) public virtual override {\n _setApprovalForAll(_msgSender(), operator, approved);\n }\n\n /**\n * @dev See {IERC721-isApprovedForAll}.\n */\n function isApprovedForAll(address owner, address operator) public view virtual override 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 override {\n //solhint-disable-next-line max-line-length\n require(_isApprovedOrOwner(_msgSender(), tokenId), \"ERC721: caller is not token owner or approved\");\n\n _transfer(from, to, tokenId);\n }\n\n /**\n * @dev See {IERC721-safeTransferFrom}.\n */\n function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {\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 override {\n require(_isApprovedOrOwner(_msgSender(), tokenId), \"ERC721: caller is not token owner or approved\");\n _safeTransfer(from, to, tokenId, data);\n }\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n * are aware of the ERC721 protocol 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 equivalent to {safeTransferFrom}, and can be used to e.g.\n * implement alternative mechanisms to perform token transfer, such as signature-based.\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 `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, bytes memory data) internal virtual {\n _transfer(from, to, tokenId);\n require(_checkOnERC721Received(from, to, tokenId, data), \"ERC721: transfer to non ERC721Receiver implementer\");\n }\n\n /**\n * @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist\n */\n function _ownerOf(uint256 tokenId) internal view virtual returns (address) {\n return _owners[tokenId];\n }\n\n /**\n * @dev Returns whether `tokenId` exists.\n *\n * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.\n *\n * Tokens start existing when they are minted (`_mint`),\n * and stop existing when they are burned (`_burn`).\n */\n function _exists(uint256 tokenId) internal view virtual returns (bool) {\n return _ownerOf(tokenId) != address(0);\n }\n\n /**\n * @dev Returns whether `spender` is allowed to manage `tokenId`.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {\n address owner = ERC721.ownerOf(tokenId);\n return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);\n }\n\n /**\n * @dev Safely mints `tokenId` and transfers it to `to`.\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 virtual {\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 require(\n _checkOnERC721Received(address(0), to, tokenId, data),\n \"ERC721: transfer to non ERC721Receiver implementer\"\n );\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 virtual {\n require(to != address(0), \"ERC721: mint to the zero address\");\n require(!_exists(tokenId), \"ERC721: token already minted\");\n\n _beforeTokenTransfer(address(0), to, tokenId, 1);\n\n // Check that tokenId was not minted by `_beforeTokenTransfer` hook\n require(!_exists(tokenId), \"ERC721: token already minted\");\n\n unchecked {\n // Will not overflow unless all 2**256 token ids are minted to the same owner.\n // Given that tokens are minted one by one, it is impossible in practice that\n // this ever happens. Might change if we allow batch minting.\n // The ERC fails to describe this case.\n _balances[to] += 1;\n }\n\n _owners[tokenId] = to;\n\n emit Transfer(address(0), to, tokenId);\n\n _afterTokenTransfer(address(0), to, tokenId, 1);\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 virtual {\n address owner = ERC721.ownerOf(tokenId);\n\n _beforeTokenTransfer(owner, address(0), tokenId, 1);\n\n // Update ownership in case tokenId was transferred by `_beforeTokenTransfer` hook\n owner = ERC721.ownerOf(tokenId);\n\n // Clear approvals\n delete _tokenApprovals[tokenId];\n\n unchecked {\n // Cannot overflow, as that would require more tokens to be burned/transferred\n // out than the owner initially received through minting and transferring in.\n _balances[owner] -= 1;\n }\n delete _owners[tokenId];\n\n emit Transfer(owner, address(0), tokenId);\n\n _afterTokenTransfer(owner, address(0), tokenId, 1);\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 virtual {\n require(ERC721.ownerOf(tokenId) == from, \"ERC721: transfer from incorrect owner\");\n require(to != address(0), \"ERC721: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, tokenId, 1);\n\n // Check that tokenId was not transferred by `_beforeTokenTransfer` hook\n require(ERC721.ownerOf(tokenId) == from, \"ERC721: transfer from incorrect owner\");\n\n // Clear approvals from the previous owner\n delete _tokenApprovals[tokenId];\n\n unchecked {\n // `_balances[from]` cannot overflow for the same reason as described in `_burn`:\n // `from`'s balance is the number of token held, which is at least one before the current\n // transfer.\n // `_balances[to]` could overflow in the conditions described in `_mint`. That would require\n // all 2**256 token ids to be minted, which in practice is impossible.\n _balances[from] -= 1;\n _balances[to] += 1;\n }\n _owners[tokenId] = to;\n\n emit Transfer(from, to, tokenId);\n\n _afterTokenTransfer(from, to, tokenId, 1);\n }\n\n /**\n * @dev Approve `to` to operate on `tokenId`\n *\n * Emits an {Approval} event.\n */\n function _approve(address to, uint256 tokenId) internal virtual {\n _tokenApprovals[tokenId] = to;\n emit Approval(ERC721.ownerOf(tokenId), to, tokenId);\n }\n\n /**\n * @dev Approve `operator` to operate on all of `owner` tokens\n *\n * Emits an {ApprovalForAll} event.\n */\n function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {\n require(owner != operator, \"ERC721: approve to caller\");\n _operatorApprovals[owner][operator] = approved;\n emit ApprovalForAll(owner, operator, approved);\n }\n\n /**\n * @dev Reverts if the `tokenId` has not been minted yet.\n */\n function _requireMinted(uint256 tokenId) internal view virtual {\n require(_exists(tokenId), \"ERC721: invalid token ID\");\n }\n\n /**\n * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.\n * 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 * @return bool whether the call correctly returned the expected magic value\n */\n function _checkOnERC721Received(\n address from,\n address to,\n uint256 tokenId,\n bytes memory data\n ) private returns (bool) {\n if (to.isContract()) {\n try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {\n return retval == IERC721Receiver.onERC721Received.selector;\n } catch (bytes memory reason) {\n if (reason.length == 0) {\n revert(\"ERC721: transfer to non ERC721Receiver implementer\");\n } else {\n /// @solidity memory-safe-assembly\n assembly {\n revert(add(32, reason), mload(reason))\n }\n }\n }\n } else {\n return true;\n }\n }\n\n /**\n * @dev Hook that is called before any token transfer. This includes minting and burning. If {ERC721Consecutive} is\n * used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.\n *\n * Calling conditions:\n *\n * - When `from` and `to` are both non-zero, ``from``'s tokens will be transferred to `to`.\n * - When `from` is zero, the tokens will be minted for `to`.\n * - When `to` is zero, ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n * - `batchSize` is non-zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual {}\n\n /**\n * @dev Hook that is called after any token transfer. This includes minting and burning. If {ERC721Consecutive} is\n * used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.\n *\n * Calling conditions:\n *\n * - When `from` and `to` are both non-zero, ``from``'s tokens were transferred to `to`.\n * - When `from` is zero, the tokens were minted for `to`.\n * - When `to` is zero, ``from``'s tokens were burned.\n * - `from` and `to` are never both zero.\n * - `batchSize` is non-zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _afterTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual {}\n\n /**\n * @dev Unsafe write access to the balances, used by extensions that \"mint\" tokens using an {ownerOf} override.\n *\n * WARNING: Anyone calling this MUST ensure that the balances remain consistent with the ownership. The invariant\n * being that for any address `a` the value returned by `balanceOf(a)` must be equal to the number of tokens such\n * that `ownerOf(tokenId)` is `a`.\n */\n // solhint-disable-next-line func-name-mixedcase\n function __unsafe_increaseBalance(address account, uint256 amount) internal {\n _balances[account] += amount;\n }\n}\n"
},
"node_modules/@prb/math/src/UD60x18.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\n/*\n\n██████╗ ██████╗ ██████╗ ███╗ ███╗ █████╗ ████████╗██╗ ██╗\n██╔══██╗██╔══██╗██╔══██╗████╗ ████║██╔══██╗╚══██╔══╝██║ ██║\n██████╔╝██████╔╝██████╔╝██╔████╔██║███████║ ██║ ███████║\n██╔═══╝ ██╔══██╗██╔══██╗██║╚██╔╝██║██╔══██║ ██║ ██╔══██║\n██║ ██║ ██║██████╔╝██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║\n╚═╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝\n\n██╗ ██╗██████╗ ██████╗ ██████╗ ██╗ ██╗ ██╗ █████╗\n██║ ██║██╔══██╗██╔════╝ ██╔═████╗╚██╗██╔╝███║██╔══██╗\n██║ ██║██║ ██║███████╗ ██║██╔██║ ╚███╔╝ ╚██║╚█████╔╝\n██║ ██║██║ ██║██╔═══██╗████╔╝██║ ██╔██╗ ██║██╔══██╗\n╚██████╔╝██████╔╝╚██████╔╝╚██████╔╝██╔╝ ██╗ ██║╚█████╔╝\n ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚════╝\n\n*/\n\nimport \"./ud60x18/Casting.sol\";\nimport \"./ud60x18/Constants.sol\";\nimport \"./ud60x18/Conversions.sol\";\nimport \"./ud60x18/Errors.sol\";\nimport \"./ud60x18/Helpers.sol\";\nimport \"./ud60x18/Math.sol\";\nimport \"./ud60x18/ValueType.sol\";\n"
},
"src/abstracts/SablierV2Lockup.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity >=0.8.19;\n\nimport { IERC4906 } from \"@openzeppelin/contracts/interfaces/IERC4906.sol\";\nimport { ERC721 } from \"@openzeppelin/contracts/token/ERC721/ERC721.sol\";\nimport { IERC721Metadata } from \"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol\";\n\nimport { ISablierV2Comptroller } from \"../interfaces/ISablierV2Comptroller.sol\";\nimport { ISablierV2Lockup } from \"../interfaces/ISablierV2Lockup.sol\";\nimport { ISablierV2NFTDescriptor } from \"../interfaces/ISablierV2NFTDescriptor.sol\";\nimport { ISablierV2LockupRecipient } from \"../interfaces/hooks/ISablierV2LockupRecipient.sol\";\nimport { Errors } from \"../libraries/Errors.sol\";\nimport { Lockup } from \"../types/DataTypes.sol\";\nimport { SablierV2Base } from \"./SablierV2Base.sol\";\n\n/// @title SablierV2Lockup\n/// @notice See the documentation in {ISablierV2Lockup}.\nabstract contract SablierV2Lockup is\n IERC4906, // 2 inherited components\n SablierV2Base, // 4 inherited components\n ISablierV2Lockup, // 4 inherited components\n ERC721 // 6 inherited components\n{\n /*//////////////////////////////////////////////////////////////////////////\n USER-FACING STORAGE\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @inheritdoc ISablierV2Lockup\n uint256 public override nextStreamId;\n\n /*//////////////////////////////////////////////////////////////////////////\n INTERNAL STORAGE\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @dev Contract that generates the non-fungible token URI.\n ISablierV2NFTDescriptor internal _nftDescriptor;\n\n /*//////////////////////////////////////////////////////////////////////////\n CONSTRUCTOR\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @param initialAdmin The address of the initial contract admin.\n /// @param initialComptroller The address of the initial comptroller.\n /// @param initialNFTDescriptor The address of the initial NFT descriptor.\n constructor(\n address initialAdmin,\n ISablierV2Comptroller initialComptroller,\n ISablierV2NFTDescriptor initialNFTDescriptor\n )\n SablierV2Base(initialAdmin, initialComptroller)\n {\n _nftDescriptor = initialNFTDescriptor;\n }\n\n /*//////////////////////////////////////////////////////////////////////////\n MODIFIERS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @dev Checks that `streamId` does not reference a null stream.\n modifier notNull(uint256 streamId) {\n if (!isStream(streamId)) {\n revert Errors.SablierV2Lockup_Null(streamId);\n }\n _;\n }\n\n /// @dev Emits an ERC-4906 event to trigger an update of the NFT metadata.\n modifier updateMetadata(uint256 streamId) {\n _;\n emit MetadataUpdate({ _tokenId: streamId });\n }\n\n /*//////////////////////////////////////////////////////////////////////////\n USER-FACING CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @inheritdoc ISablierV2Lockup\n function getRecipient(uint256 streamId) external view override returns (address recipient) {\n // Checks: the stream NFT exists.\n _requireMinted({ tokenId: streamId });\n\n // The NFT owner is the stream's recipient.\n recipient = _ownerOf(streamId);\n }\n\n /// @inheritdoc ISablierV2Lockup\n function isCold(uint256 streamId) external view override notNull(streamId) returns (bool result) {\n Lockup.Status status = _statusOf(streamId);\n result = status == Lockup.Status.SETTLED || status == Lockup.Status.CANCELED || status == Lockup.Status.DEPLETED;\n }\n\n /// @inheritdoc ISablierV2Lockup\n function isDepleted(uint256 streamId) public view virtual override returns (bool result);\n\n /// @inheritdoc ISablierV2Lockup\n function isStream(uint256 streamId) public view virtual override returns (bool result);\n\n /// @inheritdoc ISablierV2Lockup\n function isWarm(uint256 streamId) external view override notNull(streamId) returns (bool result) {\n Lockup.Status status = _statusOf(streamId);\n result = status == Lockup.Status.PENDING || status == Lockup.Status.STREAMING;\n }\n\n /// @inheritdoc ERC721\n function tokenURI(uint256 streamId) public view override(IERC721Metadata, ERC721) returns (string memory uri) {\n // Checks: the stream NFT exists.\n _requireMinted({ tokenId: streamId });\n\n // Generate the URI describing the stream NFT.\n uri = _nftDescriptor.tokenURI({ sablier: this, streamId: streamId });\n }\n\n /// @inheritdoc ISablierV2Lockup\n function wasCanceled(uint256 streamId) public view virtual override returns (bool result);\n\n /// @inheritdoc ISablierV2Lockup\n function withdrawableAmountOf(uint256 streamId)\n external\n view\n override\n notNull(streamId)\n returns (uint128 withdrawableAmount)\n {\n withdrawableAmount = _withdrawableAmountOf(streamId);\n }\n\n /// @inheritdoc ISablierV2Lockup\n function isTransferable(uint256 streamId) public view virtual returns (bool);\n\n /*//////////////////////////////////////////////////////////////////////////\n USER-FACING NON-CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @inheritdoc ISablierV2Lockup\n function burn(uint256 streamId) external override noDelegateCall {\n // Checks: only depleted streams can be burned. This also checks that the stream is not null.\n if (!isDepleted(streamId)) {\n revert Errors.SablierV2Lockup_StreamNotDepleted(streamId);\n }\n\n // Checks:\n // 1. NFT exists (see {IERC721.getApproved}).\n // 2. `msg.sender` is either the owner of the NFT or an approved third party.\n if (!_isCallerStreamRecipientOrApproved(streamId)) {\n revert Errors.SablierV2Lockup_Unauthorized(streamId, msg.sender);\n }\n\n // Effects: burn the NFT.\n _burn({ tokenId: streamId });\n }\n\n /// @inheritdoc ISablierV2Lockup\n function cancel(uint256 streamId) public override noDelegateCall {\n // Checks: the stream is neither depleted nor canceled. This also checks that the stream is not null.\n if (isDepleted(streamId)) {\n revert Errors.SablierV2Lockup_StreamDepleted(streamId);\n } else if (wasCanceled(streamId)) {\n revert Errors.SablierV2Lockup_StreamCanceled(streamId);\n }\n\n // Checks: `msg.sender` is the stream's sender.\n if (!_isCallerStreamSender(streamId)) {\n revert Errors.SablierV2Lockup_Unauthorized(streamId, msg.sender);\n }\n\n // Checks, Effects and Interactions: cancel the stream.\n _cancel(streamId);\n }\n\n /// @inheritdoc ISablierV2Lockup\n function cancelMultiple(uint256[] calldata streamIds) external override noDelegateCall {\n // Iterate over the provided array of stream ids and cancel each stream.\n uint256 count = streamIds.length;\n for (uint256 i = 0; i < count;) {\n // Effects and Interactions: cancel the stream.\n cancel(streamIds[i]);\n\n // Increment the loop iterator.\n unchecked {\n i += 1;\n }\n }\n }\n\n /// @inheritdoc ISablierV2Lockup\n function renounce(uint256 streamId) external override noDelegateCall notNull(streamId) updateMetadata(streamId) {\n // Checks: the stream is not cold.\n Lockup.Status status = _statusOf(streamId);\n if (status == Lockup.Status.DEPLETED) {\n revert Errors.SablierV2Lockup_StreamDepleted(streamId);\n } else if (status == Lockup.Status.CANCELED) {\n revert Errors.SablierV2Lockup_StreamCanceled(streamId);\n } else if (status == Lockup.Status.SETTLED) {\n revert Errors.SablierV2Lockup_StreamSettled(streamId);\n }\n\n // Checks: `msg.sender` is the stream's sender.\n if (!_isCallerStreamSender(streamId)) {\n revert Errors.SablierV2Lockup_Unauthorized(streamId, msg.sender);\n }\n\n // Checks and Effects: renounce the stream.\n _renounce(streamId);\n\n // Log the renouncement.\n emit ISablierV2Lockup.RenounceLockupStream(streamId);\n\n // Interactions: if the recipient is a contract, try to invoke the renounce hook on the recipient without\n // reverting if the hook is not implemented, and also without bubbling up any potential revert.\n address recipient = _ownerOf(streamId);\n if (recipient.code.length > 0) {\n try ISablierV2LockupRecipient(recipient).onStreamRenounced(streamId) { } catch { }\n }\n }\n\n /// @inheritdoc ISablierV2Lockup\n function setNFTDescriptor(ISablierV2NFTDescriptor newNFTDescriptor) external override onlyAdmin {\n // Effects: set the NFT descriptor.\n ISablierV2NFTDescriptor oldNftDescriptor = _nftDescriptor;\n _nftDescriptor = newNFTDescriptor;\n\n // Log the change of the NFT descriptor.\n emit ISablierV2Lockup.SetNFTDescriptor({\n admin: msg.sender,\n oldNFTDescriptor: oldNftDescriptor,\n newNFTDescriptor: newNFTDescriptor\n });\n\n // Refresh the NFT metadata for all streams.\n emit BatchMetadataUpdate({ _fromTokenId: 1, _toTokenId: nextStreamId - 1 });\n }\n\n /// @inheritdoc ISablierV2Lockup\n function withdraw(\n uint256 streamId,\n address to,\n uint128 amount\n )\n public\n override\n noDelegateCall\n updateMetadata(streamId)\n {\n // Checks: the stream is not depleted. This also checks that the stream is not null.\n if (isDepleted(streamId)) {\n revert Errors.SablierV2Lockup_StreamDepleted(streamId);\n }\n\n bool isCallerStreamSender = _isCallerStreamSender(streamId);\n\n // Checks: `msg.sender` is the stream's sender, the stream's recipient, or an approved third party.\n if (!isCallerStreamSender && !_isCallerStreamRecipientOrApproved(streamId)) {\n revert Errors.SablierV2Lockup_Unauthorized(streamId, msg.sender);\n }\n\n // Retrieve the recipient from storage.\n address recipient = _ownerOf(streamId);\n\n // Checks: if `msg.sender` is the stream's sender, the withdrawal address must be the recipient.\n if (isCallerStreamSender && to != recipient) {\n revert Errors.SablierV2Lockup_InvalidSenderWithdrawal(streamId, msg.sender, to);\n }\n\n // Checks: the withdrawal address is not zero.\n if (to == address(0)) {\n revert Errors.SablierV2Lockup_WithdrawToZeroAddress();\n }\n\n // Checks: the withdraw amount is not zero.\n if (amount == 0) {\n revert Errors.SablierV2Lockup_WithdrawAmountZero(streamId);\n }\n\n // Checks: the withdraw amount is not greater than the withdrawable amount.\n uint128 withdrawableAmount = _withdrawableAmountOf(streamId);\n if (amount > withdrawableAmount) {\n revert Errors.SablierV2Lockup_Overdraw(streamId, amount, withdrawableAmount);\n }\n\n // Effects and Interactions: make the withdrawal.\n _withdraw(streamId, to, amount);\n\n // Interactions: if `msg.sender` is not the recipient and the recipient is a contract, try to invoke the\n // withdraw hook on it without reverting if the hook is not implemented, and also without bubbling up\n // any potential revert.\n if (msg.sender != recipient && recipient.code.length > 0) {\n try ISablierV2LockupRecipient(recipient).onStreamWithdrawn({\n streamId: streamId,\n caller: msg.sender,\n to: to,\n amount: amount\n }) { } catch { }\n }\n }\n\n /// @inheritdoc ISablierV2Lockup\n function withdrawMax(uint256 streamId, address to) external override {\n withdraw({ streamId: streamId, to: to, amount: _withdrawableAmountOf(streamId) });\n }\n\n /// @inheritdoc ISablierV2Lockup\n function withdrawMaxAndTransfer(\n uint256 streamId,\n address newRecipient\n )\n external\n override\n noDelegateCall\n notNull(streamId)\n {\n // Checks: the caller is the current recipient. This also checks that the NFT was not burned.\n address currentRecipient = _ownerOf(streamId);\n if (msg.sender != currentRecipient) {\n revert Errors.SablierV2Lockup_Unauthorized(streamId, msg.sender);\n }\n\n // Skip the withdrawal if the withdrawable amount is zero.\n uint128 withdrawableAmount = _withdrawableAmountOf(streamId);\n if (withdrawableAmount > 0) {\n withdraw({ streamId: streamId, to: currentRecipient, amount: withdrawableAmount });\n }\n\n // Checks and Effects: transfer the NFT.\n _transfer({ from: currentRecipient, to: newRecipient, tokenId: streamId });\n }\n\n /// @inheritdoc ISablierV2Lockup\n function withdrawMultiple(\n uint256[] calldata streamIds,\n address to,\n uint128[] calldata amounts\n )\n external\n override\n noDelegateCall\n {\n // Checks: there is an equal number of `streamIds` and `amounts`.\n uint256 streamIdsCount = streamIds.length;\n uint256 amountsCount = amounts.length;\n if (streamIdsCount != amountsCount) {\n revert Errors.SablierV2Lockup_WithdrawArrayCountsNotEqual(streamIdsCount, amountsCount);\n }\n\n // Iterate over the provided array of stream ids and withdraw from each stream.\n for (uint256 i = 0; i < streamIdsCount;) {\n // Checks, Effects and Interactions: check the parameters and make the withdrawal.\n withdraw(streamIds[i], to, amounts[i]);\n\n // Increment the loop iterator.\n unchecked {\n i += 1;\n }\n }\n }\n\n /*//////////////////////////////////////////////////////////////////////////\n INTERNAL CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Overrides the internal ERC-721 transfer function to emit an ERC-4906 event upon transfer. The goal is to\n /// refresh the NFT metadata on external platforms.\n /// @dev This event is also emitted when the NFT is minted or burned.\n function _afterTokenTransfer(\n address, /* from */\n address, /* to */\n uint256 streamId,\n uint256 /* batchSize */\n )\n internal\n override\n updateMetadata(streamId)\n { }\n\n /// @notice Overrides the internal ERC-721 transfer function to check that the stream is transferable.\n /// @dev There are two cases when the transferable flag is ignored:\n /// - If `from` is 0, then the transfer is a mint and is allowed.\n /// - If `to` is 0, then the transfer is a burn and is also allowed.\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 streamId,\n uint256 /* batchSize */\n )\n internal\n view\n override\n {\n if (!isTransferable(streamId) && to != address(0) && from != address(0)) {\n revert Errors.SablierV2Lockup_NotTransferable(streamId);\n }\n }\n\n /// @notice Checks whether `msg.sender` is the stream's recipient or an approved third party.\n /// @param streamId The stream id for the query.\n function _isCallerStreamRecipientOrApproved(uint256 streamId) internal view returns (bool) {\n address recipient = _ownerOf(streamId);\n return msg.sender == recipient || isApprovedForAll({ owner: recipient, operator: msg.sender })\n || getApproved(streamId) == msg.sender;\n }\n\n /// @notice Checks whether `msg.sender` is the stream's sender.\n /// @param streamId The stream id for the query.\n function _isCallerStreamSender(uint256 streamId) internal view virtual returns (bool);\n\n /// @dev Retrieves the stream's status without performing a null check.\n function _statusOf(uint256 streamId) internal view virtual returns (Lockup.Status);\n\n /// @dev See the documentation for the user-facing functions that call this internal function.\n function _withdrawableAmountOf(uint256 streamId) internal view virtual returns (uint128);\n\n /*//////////////////////////////////////////////////////////////////////////\n INTERNAL NON-CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @dev See the documentation for the user-facing functions that call this internal function.\n function _cancel(uint256 tokenId) internal virtual;\n\n /// @dev See the documentation for the user-facing functions that call this internal function.\n function _renounce(uint256 streamId) internal virtual;\n\n /// @dev See the documentation for the user-facing functions that call this internal function.\n function _withdraw(uint256 streamId, address to, uint128 amount) internal virtual;\n}\n"
},
"src/interfaces/ISablierV2Comptroller.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity >=0.8.19;\n\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport { UD60x18 } from \"@prb/math/src/UD60x18.sol\";\n\nimport { IAdminable } from \"./IAdminable.sol\";\n\n/// @title ISablierV2Controller\n/// @notice This contract is in charge of the Sablier V2 protocol configuration, handling such values as the\n/// protocol fees.\ninterface ISablierV2Comptroller is IAdminable {\n /*//////////////////////////////////////////////////////////////////////////\n EVENTS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Emitted when the admin sets a new flash fee.\n /// @param admin The address of the contract admin.\n /// @param oldFlashFee The old flash fee, denoted as a fixed-point number.\n /// @param newFlashFee The new flash fee, denoted as a fixed-point number.\n event SetFlashFee(address indexed admin, UD60x18 oldFlashFee, UD60x18 newFlashFee);\n\n /// @notice Emitted when the admin sets a new protocol fee for the provided ERC-20 asset.\n /// @param admin The address of the contract admin.\n /// @param asset The contract address of the ERC-20 asset the new protocol fee has been set for.\n /// @param oldProtocolFee The old protocol fee, denoted as a fixed-point number.\n /// @param newProtocolFee The new protocol fee, denoted as a fixed-point number.\n event SetProtocolFee(address indexed admin, IERC20 indexed asset, UD60x18 oldProtocolFee, UD60x18 newProtocolFee);\n\n /// @notice Emitted when the admin enables or disables an ERC-20 asset for flash loaning.\n /// @param admin The address of the contract admin.\n /// @param asset The contract address of the ERC-20 asset to toggle.\n /// @param newFlag Whether the ERC-20 asset can be flash loaned.\n event ToggleFlashAsset(address indexed admin, IERC20 indexed asset, bool newFlag);\n\n /*//////////////////////////////////////////////////////////////////////////\n CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Retrieves the global flash fee, denoted as a fixed-point number where 1e18 is 100%.\n ///\n /// @dev Notes:\n /// - This fee represents a percentage, not an amount. Do not confuse it with {IERC3156FlashLender.flashFee},\n /// which calculates the fee amount for a specified flash loan amount.\n /// - Unlike the protocol fee, this is a global fee applied to all flash loans, not a per-asset fee.\n function flashFee() external view returns (UD60x18 fee);\n\n /// @notice Retrieves a flag indicating whether the provided ERC-20 asset can be flash loaned.\n /// @param token The contract address of the ERC-20 asset to check.\n function isFlashAsset(IERC20 token) external view returns (bool result);\n\n /// @notice Retrieves the protocol fee for all streams created with the provided ERC-20 asset.\n /// @param asset The contract address of the ERC-20 asset to query.\n /// @return fee The protocol fee denoted as a fixed-point number where 1e18 is 100%.\n function protocolFees(IERC20 asset) external view returns (UD60x18 fee);\n\n /*//////////////////////////////////////////////////////////////////////////\n NON-CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Updates the flash fee charged on all flash loans made with any ERC-20 asset.\n ///\n /// @dev Emits a {SetFlashFee} event.\n ///\n /// Notes:\n /// - Does not revert if the fee is the same.\n ///\n /// Requirements:\n /// - `msg.sender` must be the contract admin.\n ///\n /// @param newFlashFee The new flash fee to set, denoted as a fixed-point number where 1e18 is 100%.\n function setFlashFee(UD60x18 newFlashFee) external;\n\n /// @notice Sets a new protocol fee that will be charged on all streams created with the provided ERC-20 asset.\n ///\n /// @dev Emits a {SetProtocolFee} event.\n ///\n /// Notes:\n /// - The fee is not denoted in units of the asset's decimals; it is a fixed-point number. Refer to the\n /// PRBMath documentation for more detail on the logic of UD60x18.\n /// - Does not revert if the fee is the same.\n ///\n /// Requirements:\n /// - `msg.sender` must be the contract admin.\n ///\n /// @param asset The contract address of the ERC-20 asset to update the fee for.\n /// @param newProtocolFee The new protocol fee, denoted as a fixed-point number where 1e18 is 100%.\n function setProtocolFee(IERC20 asset, UD60x18 newProtocolFee) external;\n\n /// @notice Toggles the flash loanability of an ERC-20 asset.\n ///\n /// @dev Emits a {ToggleFlashAsset} event.\n ///\n /// Requirements:\n /// - `msg.sender` must be the admin.\n ///\n /// @param asset The address of the ERC-20 asset to toggle.\n function toggleFlashAsset(IERC20 asset) external;\n}\n"
},
"src/interfaces/ISablierV2Lockup.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity >=0.8.19;\n\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport { IERC721Metadata } from \"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol\";\n\nimport { Lockup } from \"../types/DataTypes.sol\";\nimport { ISablierV2Base } from \"./ISablierV2Base.sol\";\nimport { ISablierV2NFTDescriptor } from \"./ISablierV2NFTDescriptor.sol\";\n\n/// @title ISablierV2Lockup\n/// @notice Common logic between all Sablier V2 Lockup streaming contracts.\ninterface ISablierV2Lockup is\n ISablierV2Base, // 1 inherited component\n IERC721Metadata // 2 inherited components\n{\n /*//////////////////////////////////////////////////////////////////////////\n EVENTS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Emitted when a stream is canceled.\n /// @param streamId The id of the stream.\n /// @param sender The address of the stream's sender.\n /// @param recipient The address of the stream's recipient.\n /// @param asset The contract address of the ERC-20 asset used for streaming.\n /// @param senderAmount The amount of assets refunded to the stream's sender, denoted in units of the asset's\n /// decimals.\n /// @param recipientAmount The amount of assets left for the stream's recipient to withdraw, denoted in units of the\n /// asset's decimals.\n event CancelLockupStream(\n uint256 streamId,\n address indexed sender,\n address indexed recipient,\n IERC20 indexed asset,\n uint128 senderAmount,\n uint128 recipientAmount\n );\n\n /// @notice Emitted when a sender gives up the right to cancel a stream.\n /// @param streamId The id of the stream.\n event RenounceLockupStream(uint256 indexed streamId);\n\n /// @notice Emitted when the admin sets a new NFT descriptor contract.\n /// @param admin The address of the current contract admin.\n /// @param oldNFTDescriptor The address of the old NFT descriptor contract.\n /// @param newNFTDescriptor The address of the new NFT descriptor contract.\n event SetNFTDescriptor(\n address indexed admin, ISablierV2NFTDescriptor oldNFTDescriptor, ISablierV2NFTDescriptor newNFTDescriptor\n );\n\n /// @notice Emitted when assets are withdrawn from a stream.\n /// @param streamId The id of the stream.\n /// @param to The address that has received the withdrawn assets.\n /// @param asset The contract address of the ERC-20 asset used for streaming.\n /// @param amount The amount of assets withdrawn, denoted in units of the asset's decimals.\n event WithdrawFromLockupStream(uint256 indexed streamId, address indexed to, IERC20 indexed asset, uint128 amount);\n\n /*//////////////////////////////////////////////////////////////////////////\n CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Retrieves the address of the ERC-20 asset used for streaming.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function getAsset(uint256 streamId) external view returns (IERC20 asset);\n\n /// @notice Retrieves the amount deposited in the stream, denoted in units of the asset's decimals.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function getDepositedAmount(uint256 streamId) external view returns (uint128 depositedAmount);\n\n /// @notice Retrieves the stream's end time, which is a Unix timestamp.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function getEndTime(uint256 streamId) external view returns (uint40 endTime);\n\n /// @notice Retrieves the stream's recipient.\n /// @dev Reverts if the NFT has been burned.\n /// @param streamId The stream id for the query.\n function getRecipient(uint256 streamId) external view returns (address recipient);\n\n /// @notice Retrieves the amount refunded to the sender after a cancellation, denoted in units of the asset's\n /// decimals. This amount is always zero unless the stream was canceled.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function getRefundedAmount(uint256 streamId) external view returns (uint128 refundedAmount);\n\n /// @notice Retrieves the stream's sender.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function getSender(uint256 streamId) external view returns (address sender);\n\n /// @notice Retrieves the stream's start time, which is a Unix timestamp.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function getStartTime(uint256 streamId) external view returns (uint40 startTime);\n\n /// @notice Retrieves the amount withdrawn from the stream, denoted in units of the asset's decimals.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function getWithdrawnAmount(uint256 streamId) external view returns (uint128 withdrawnAmount);\n\n /// @notice Retrieves a flag indicating whether the stream can be canceled. When the stream is cold, this\n /// flag is always `false`.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function isCancelable(uint256 streamId) external view returns (bool result);\n\n /// @notice Retrieves a flag indicating whether the stream is cold, i.e. settled, canceled, or depleted.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function isCold(uint256 streamId) external view returns (bool result);\n\n /// @notice Retrieves a flag indicating whether the stream is depleted.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function isDepleted(uint256 streamId) external view returns (bool result);\n\n /// @notice Retrieves a flag indicating whether the stream exists.\n /// @dev Does not revert if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function isStream(uint256 streamId) external view returns (bool result);\n\n /// @notice Retrieves a flag indicating whether the stream NFT can be transferred.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function isTransferable(uint256 streamId) external view returns (bool result);\n\n /// @notice Retrieves a flag indicating whether the stream is warm, i.e. either pending or streaming.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function isWarm(uint256 streamId) external view returns (bool result);\n\n /// @notice Counter for stream ids, used in the create functions.\n function nextStreamId() external view returns (uint256);\n\n /// @notice Calculates the amount that the sender would be refunded if the stream were canceled, denoted in units\n /// of the asset's decimals.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function refundableAmountOf(uint256 streamId) external view returns (uint128 refundableAmount);\n\n /// @notice Retrieves the stream's status.\n /// @param streamId The stream id for the query.\n function statusOf(uint256 streamId) external view returns (Lockup.Status status);\n\n /// @notice Calculates the amount streamed to the recipient, denoted in units of the asset's decimals.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function streamedAmountOf(uint256 streamId) external view returns (uint128 streamedAmount);\n\n /// @notice Retrieves a flag indicating whether the stream was canceled.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function wasCanceled(uint256 streamId) external view returns (bool result);\n\n /// @notice Calculates the amount that the recipient can withdraw from the stream, denoted in units of the asset's\n /// decimals.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function withdrawableAmountOf(uint256 streamId) external view returns (uint128 withdrawableAmount);\n\n /*//////////////////////////////////////////////////////////////////////////\n NON-CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Burns the NFT associated with the stream.\n ///\n /// @dev Emits a {Transfer} event.\n ///\n /// Requirements:\n /// - Must not be delegate called.\n /// - `streamId` must reference a depleted stream.\n /// - The NFT must exist.\n /// - `msg.sender` must be either the NFT owner or an approved third party.\n ///\n /// @param streamId The id of the stream NFT to burn.\n function burn(uint256 streamId) external;\n\n /// @notice Cancels the stream and refunds any remaining assets to the sender.\n ///\n /// @dev Emits a {Transfer}, {CancelLockupStream}, and {MetadataUpdate} event.\n ///\n /// Notes:\n /// - If there any assets left for the recipient to withdraw, the stream is marked as canceled. Otherwise, the\n /// stream is marked as depleted.\n /// - This function attempts to invoke a hook on the recipient, if the resolved address is a contract.\n ///\n /// Requirements:\n /// - Must not be delegate called.\n /// - The stream must be warm and cancelable.\n /// - `msg.sender` must be the stream's sender.\n ///\n /// @param streamId The id of the stream to cancel.\n function cancel(uint256 streamId) external;\n\n /// @notice Cancels multiple streams and refunds any remaining assets to the sender.\n ///\n /// @dev Emits multiple {Transfer}, {CancelLockupStream}, and {MetadataUpdate} events.\n ///\n /// Notes:\n /// - Refer to the notes in {cancel}.\n ///\n /// Requirements:\n /// - All requirements from {cancel} must be met for each stream.\n ///\n /// @param streamIds The ids of the streams to cancel.\n function cancelMultiple(uint256[] calldata streamIds) external;\n\n /// @notice Removes the right of the stream's sender to cancel the stream.\n ///\n /// @dev Emits a {RenounceLockupStream} and {MetadataUpdate} event.\n ///\n /// Notes:\n /// - This is an irreversible operation.\n /// - This function attempts to invoke a hook on the stream's recipient, provided that the recipient is a contract.\n ///\n /// Requirements:\n /// - Must not be delegate called.\n /// - `streamId` must reference a warm stream.\n /// - `msg.sender` must be the stream's sender.\n /// - The stream must be cancelable.\n ///\n /// @param streamId The id of the stream to renounce.\n function renounce(uint256 streamId) external;\n\n /// @notice Sets a new NFT descriptor contract, which produces the URI describing the Sablier stream NFTs.\n ///\n /// @dev Emits a {SetNFTDescriptor} and {BatchMetadataUpdate} event.\n ///\n /// Notes:\n /// - Does not revert if the NFT descriptor is the same.\n ///\n /// Requirements:\n /// - `msg.sender` must be the contract admin.\n ///\n /// @param newNFTDescriptor The address of the new NFT descriptor contract.\n function setNFTDescriptor(ISablierV2NFTDescriptor newNFTDescriptor) external;\n\n /// @notice Withdraws the provided amount of assets from the stream to the `to` address.\n ///\n /// @dev Emits a {Transfer}, {WithdrawFromLockupStream}, and {MetadataUpdate} event.\n ///\n /// Notes:\n /// - This function attempts to invoke a hook on the stream's recipient, provided that the recipient is a contract\n /// and `msg.sender` is either the sender or an approved operator.\n ///\n /// Requirements:\n /// - Must not be delegate called.\n /// - `streamId` must not reference a null or depleted stream.\n /// - `msg.sender` must be the stream's sender, the stream's recipient or an approved third party.\n /// - `to` must be the recipient if `msg.sender` is the stream's sender.\n /// - `to` must not be the zero address.\n /// - `amount` must be greater than zero and must not exceed the withdrawable amount.\n ///\n /// @param streamId The id of the stream to withdraw from.\n /// @param to The address receiving the withdrawn assets.\n /// @param amount The amount to withdraw, denoted in units of the asset's decimals.\n function withdraw(uint256 streamId, address to, uint128 amount) external;\n\n /// @notice Withdraws the maximum withdrawable amount from the stream to the provided address `to`.\n ///\n /// @dev Emits a {Transfer}, {WithdrawFromLockupStream}, and {MetadataUpdate} event.\n ///\n /// Notes:\n /// - Refer to the notes in {withdraw}.\n ///\n /// Requirements:\n /// - Refer to the requirements in {withdraw}.\n ///\n /// @param streamId The id of the stream to withdraw from.\n /// @param to The address receiving the withdrawn assets.\n function withdrawMax(uint256 streamId, address to) external;\n\n /// @notice Withdraws the maximum withdrawable amount from the stream to the current recipient, and transfers the\n /// NFT to `newRecipient`.\n ///\n /// @dev Emits a {WithdrawFromLockupStream} and a {Transfer} event.\n ///\n /// Notes:\n /// - If the withdrawable amount is zero, the withdrawal is skipped.\n /// - Refer to the notes in {withdraw}.\n ///\n /// Requirements:\n /// - `msg.sender` must be the stream's recipient.\n /// - Refer to the requirements in {withdraw}.\n /// - Refer to the requirements in {IERC721.transferFrom}.\n ///\n /// @param streamId The id of the stream NFT to transfer.\n /// @param newRecipient The address of the new owner of the stream NFT.\n function withdrawMaxAndTransfer(uint256 streamId, address newRecipient) external;\n\n /// @notice Withdraws assets from streams to the provided address `to`.\n ///\n /// @dev Emits multiple {Transfer}, {WithdrawFromLockupStream}, and {MetadataUpdate} events.\n ///\n /// Notes:\n /// - This function attempts to call a hook on the recipient of each stream, unless `msg.sender` is the recipient.\n ///\n /// Requirements:\n /// - All requirements from {withdraw} must be met for each stream.\n /// - There must be an equal number of `streamIds` and `amounts`.\n ///\n /// @param streamIds The ids of the streams to withdraw from.\n /// @param to The address receiving the withdrawn assets.\n /// @param amounts The amounts to withdraw, denoted in units of the asset's decimals.\n function withdrawMultiple(uint256[] calldata streamIds, address to, uint128[] calldata amounts) external;\n}\n"
},
"src/interfaces/ISablierV2LockupLinear.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity >=0.8.19;\n\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\nimport { Lockup, LockupLinear } from \"../types/DataTypes.sol\";\nimport { ISablierV2Lockup } from \"./ISablierV2Lockup.sol\";\n\n/// @title ISablierV2LockupLinear\n/// @notice Creates and manages Lockup streams with linear streaming functions.\ninterface ISablierV2LockupLinear is ISablierV2Lockup {\n /*//////////////////////////////////////////////////////////////////////////\n EVENTS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Emitted when a stream is created.\n /// @param streamId The id of the newly created stream.\n /// @param funder The address which funded the stream.\n /// @param sender The address streaming the assets, with the ability to cancel the stream.\n /// @param recipient The address receiving the assets.\n /// @param amounts Struct containing (i) the deposit amount, (ii) the protocol fee amount, and (iii) the\n /// broker fee amount, all denoted in units of the asset's decimals.\n /// @param asset The contract address of the ERC-20 asset used for streaming.\n /// @param cancelable Boolean indicating whether the stream will be cancelable or not.\n /// @param transferable Boolean indicating whether the stream NFT is transferable or not.\n /// @param range Struct containing (i) the stream's start time, (ii) cliff time, and (iii) end time, all as Unix\n /// timestamps.\n /// @param broker The address of the broker who has helped create the stream, e.g. a front-end website.\n event CreateLockupLinearStream(\n uint256 streamId,\n address funder,\n address indexed sender,\n address indexed recipient,\n Lockup.CreateAmounts amounts,\n IERC20 indexed asset,\n bool cancelable,\n bool transferable,\n LockupLinear.Range range,\n address broker\n );\n\n /*//////////////////////////////////////////////////////////////////////////\n CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Retrieves the stream's cliff time, which is a Unix timestamp.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function getCliffTime(uint256 streamId) external view returns (uint40 cliffTime);\n\n /// @notice Retrieves the stream's range, which is a struct containing (i) the stream's start time, (ii) cliff\n /// time, and (iii) end time, all as Unix timestamps.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function getRange(uint256 streamId) external view returns (LockupLinear.Range memory range);\n\n /// @notice Retrieves the stream entity.\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function getStream(uint256 streamId) external view returns (LockupLinear.Stream memory stream);\n\n /// @notice Calculates the amount streamed to the recipient, denoted in units of the asset's decimals.\n ///\n /// When the stream is warm, the streaming function is:\n ///\n /// $$\n /// f(x) = x * d + c\n /// $$\n ///\n /// Where:\n ///\n /// - $x$ is the elapsed time divided by the stream's total duration.\n /// - $d$ is the deposited amount.\n /// - $c$ is the cliff amount.\n ///\n /// Upon cancellation of the stream, the amount streamed is calculated as the difference between the deposited\n /// amount and the refunded amount. Ultimately, when the stream becomes depleted, the streamed amount is equivalent\n /// to the total amount withdrawn.\n ///\n /// @dev Reverts if `streamId` references a null stream.\n /// @param streamId The stream id for the query.\n function streamedAmountOf(uint256 streamId) external view returns (uint128 streamedAmount);\n\n /*//////////////////////////////////////////////////////////////////////////\n NON-CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Creates a stream by setting the start time to `block.timestamp`, and the end time to\n /// the sum of `block.timestamp` and `params.durations.total`. The stream is funded by `msg.sender` and is wrapped\n /// in an ERC-721 NFT.\n ///\n /// @dev Emits a {Transfer} and {CreateLockupLinearStream} event.\n ///\n /// Requirements:\n /// - All requirements in {createWithRange} must be met for the calculated parameters.\n ///\n /// @param params Struct encapsulating the function parameters, which are documented in {DataTypes}.\n /// @return streamId The id of the newly created stream.\n function createWithDurations(LockupLinear.CreateWithDurations calldata params)\n external\n returns (uint256 streamId);\n\n /// @notice Creates a stream with the provided start time and end time as the range. The stream is\n /// funded by `msg.sender` and is wrapped in an ERC-721 NFT.\n ///\n /// @dev Emits a {Transfer} and {CreateLockupLinearStream} event.\n ///\n /// Notes:\n /// - As long as the times are ordered, it is not an error for the start or the cliff time to be in the past.\n ///\n /// Requirements:\n /// - Must not be delegate called.\n /// - `params.totalAmount` must be greater than zero.\n /// - If set, `params.broker.fee` must not be greater than `MAX_FEE`.\n /// - `params.range.start` must be less than or equal to `params.range.cliff`.\n /// - `params.range.cliff` must be less than `params.range.end`.\n /// - `params.range.end` must be in the future.\n /// - `params.recipient` must not be the zero address.\n /// - `msg.sender` must have allowed this contract to spend at least `params.totalAmount` assets.\n ///\n /// @param params Struct encapsulating the function parameters, which are documented in {DataTypes}.\n /// @return streamId The id of the newly created stream.\n function createWithRange(LockupLinear.CreateWithRange calldata params) external returns (uint256 streamId);\n}\n"
},
"src/interfaces/ISablierV2NFTDescriptor.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity >=0.8.19;\n\nimport { IERC721Metadata } from \"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol\";\n\n/// @title ISablierV2NFTDescriptor\n/// @notice This contract generates the URI describing the Sablier V2 stream NFTs.\n/// @dev Inspired by Uniswap V3 Positions NFTs.\ninterface ISablierV2NFTDescriptor {\n /// @notice Produces the URI describing a particular stream NFT.\n /// @dev This is a data URI with the JSON contents directly inlined.\n /// @param sablier The address of the Sablier contract the stream was created in.\n /// @param streamId The id of the stream for which to produce a description.\n /// @return uri The URI of the ERC721-compliant metadata.\n function tokenURI(IERC721Metadata sablier, uint256 streamId) external view returns (string memory uri);\n}\n"
},
"src/interfaces/hooks/ISablierV2LockupRecipient.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity >=0.8.19;\n\n/// @title ISablierV2LockupRecipient\n/// @notice Interface for recipient contracts capable of reacting to cancellations, renouncements, and withdrawals.\n/// @dev Implementation of this interface is optional. If a recipient contract doesn't implement this\n/// interface or implements it partially, function execution will not revert.\ninterface ISablierV2LockupRecipient {\n /// @notice Responds to sender-triggered cancellations.\n ///\n /// @dev Notes:\n /// - This function may revert, but the Sablier contract will ignore the revert.\n ///\n /// @param streamId The id of the canceled stream.\n /// @param sender The stream's sender, who canceled the stream.\n /// @param senderAmount The amount of assets refunded to the stream's sender, denoted in units of the asset's\n /// decimals.\n /// @param recipientAmount The amount of assets left for the stream's recipient to withdraw, denoted in units of\n /// the asset's decimals.\n function onStreamCanceled(\n uint256 streamId,\n address sender,\n uint128 senderAmount,\n uint128 recipientAmount\n )\n external;\n\n /// @notice Responds to renouncements.\n ///\n /// @dev Notes:\n /// - This function may revert, but the Sablier contract will ignore the revert.\n ///\n /// @param streamId The id of the renounced stream.\n function onStreamRenounced(uint256 streamId) external;\n\n /// @notice Responds to withdrawals triggered by either the stream's sender or an approved third party.\n ///\n /// @dev Notes:\n /// - This function may revert, but the Sablier contract will ignore the revert.\n ///\n /// @param streamId The id of the stream being withdrawn from.\n /// @param caller The original `msg.sender` address that triggered the withdrawal.\n /// @param to The address receiving the withdrawn assets.\n /// @param amount The amount of assets withdrawn, denoted in units of the asset's decimals.\n function onStreamWithdrawn(uint256 streamId, address caller, address to, uint128 amount) external;\n}\n"
},
"src/libraries/Errors.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity >=0.8.19;\n\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport { IERC721Metadata } from \"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol\";\nimport { UD60x18 } from \"@prb/math/src/UD60x18.sol\";\n\n/// @title Errors\n/// @notice Library containing all custom errors the protocol may revert with.\nlibrary Errors {\n /*//////////////////////////////////////////////////////////////////////////\n GENERICS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Thrown when `msg.sender` is not the admin.\n error CallerNotAdmin(address admin, address caller);\n\n /// @notice Thrown when trying to delegate call to a function that disallows delegate calls.\n error DelegateCall();\n\n /*//////////////////////////////////////////////////////////////////////////\n SABLIER-V2-BASE\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Thrown when trying to claim protocol revenues for an asset with no accrued revenues.\n error SablierV2Base_NoProtocolRevenues(IERC20 asset);\n\n /*//////////////////////////////////////////////////////////////////////////\n SABLIER-V2-FLASH-LOAN\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Thrown when trying to flash loan an unsupported asset.\n error SablierV2FlashLoan_AssetNotFlashLoanable(IERC20 asset);\n\n /// @notice Thrown when trying to flash loan an amount greater than or equal to 2^128.\n error SablierV2FlashLoan_AmountTooHigh(uint256 amount);\n\n /// @notice Thrown when the calculated fee during a flash loan is greater than or equal to 2^128.\n error SablierV2FlashLoan_CalculatedFeeTooHigh(uint256 amount);\n\n /// @notice Thrown when the callback to the flash borrower fails.\n error SablierV2FlashLoan_FlashBorrowFail();\n\n /*//////////////////////////////////////////////////////////////////////////\n SABLIER-V2-LOCKUP\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Thrown when the broker fee exceeds the maximum allowed fee.\n error SablierV2Lockup_BrokerFeeTooHigh(UD60x18 brokerFee, UD60x18 maxFee);\n\n /// @notice Thrown when trying to create a stream with a zero deposit amount.\n error SablierV2Lockup_DepositAmountZero();\n\n /// @notice Thrown when trying to create a stream with an end time not in the future.\n error SablierV2Lockup_EndTimeNotInTheFuture(uint40 currentTime, uint40 endTime);\n\n /// @notice Thrown when the stream's sender tries to withdraw to an address other than the recipient's.\n error SablierV2Lockup_InvalidSenderWithdrawal(uint256 streamId, address sender, address to);\n\n /// @notice Thrown when trying to transfer Stream NFT when transferability is disabled.\n error SablierV2Lockup_NotTransferable(uint256 tokenId);\n\n /// @notice Thrown when the id references a null stream.\n error SablierV2Lockup_Null(uint256 streamId);\n\n /// @notice Thrown when trying to withdraw an amount greater than the withdrawable amount.\n error SablierV2Lockup_Overdraw(uint256 streamId, uint128 amount, uint128 withdrawableAmount);\n\n /// @notice Thrown when the protocol fee exceeds the maximum allowed fee.\n error SablierV2Lockup_ProtocolFeeTooHigh(UD60x18 protocolFee, UD60x18 maxFee);\n\n /// @notice Thrown when trying to cancel or renounce a canceled stream.\n error SablierV2Lockup_StreamCanceled(uint256 streamId);\n\n /// @notice Thrown when trying to cancel, renounce, or withdraw from a depleted stream.\n error SablierV2Lockup_StreamDepleted(uint256 streamId);\n\n /// @notice Thrown when trying to cancel or renounce a stream that is not cancelable.\n error SablierV2Lockup_StreamNotCancelable(uint256 streamId);\n\n /// @notice Thrown when trying to burn a stream that is not depleted.\n error SablierV2Lockup_StreamNotDepleted(uint256 streamId);\n\n /// @notice Thrown when trying to cancel or renounce a settled stream.\n error SablierV2Lockup_StreamSettled(uint256 streamId);\n\n /// @notice Thrown when `msg.sender` lacks authorization to perform an action.\n error SablierV2Lockup_Unauthorized(uint256 streamId, address caller);\n\n /// @notice Thrown when trying to withdraw zero assets from a stream.\n error SablierV2Lockup_WithdrawAmountZero(uint256 streamId);\n\n /// @notice Thrown when trying to withdraw from multiple streams and the number of stream ids does\n /// not match the number of withdraw amounts.\n error SablierV2Lockup_WithdrawArrayCountsNotEqual(uint256 streamIdsCount, uint256 amountsCount);\n\n /// @notice Thrown when trying to withdraw to the zero address.\n error SablierV2Lockup_WithdrawToZeroAddress();\n\n /*//////////////////////////////////////////////////////////////////////////\n SABLIER-V2-LOCKUP-DYNAMIC\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Thrown when trying to create a stream with a deposit amount not equal to the sum of the\n /// segment amounts.\n error SablierV2LockupDynamic_DepositAmountNotEqualToSegmentAmountsSum(\n uint128 depositAmount, uint128 segmentAmountsSum\n );\n\n /// @notice Thrown when trying to create a stream with more segments than the maximum allowed.\n error SablierV2LockupDynamic_SegmentCountTooHigh(uint256 count);\n\n /// @notice Thrown when trying to create a stream with no segments.\n error SablierV2LockupDynamic_SegmentCountZero();\n\n /// @notice Thrown when trying to create a stream with unordered segment milestones.\n error SablierV2LockupDynamic_SegmentMilestonesNotOrdered(\n uint256 index, uint40 previousMilestone, uint40 currentMilestone\n );\n\n /// @notice Thrown when trying to create a stream with a start time not strictly less than the first\n /// segment milestone.\n error SablierV2LockupDynamic_StartTimeNotLessThanFirstSegmentMilestone(\n uint40 startTime, uint40 firstSegmentMilestone\n );\n\n /*//////////////////////////////////////////////////////////////////////////\n SABLIER-V2-LOCKUP-LINEAR\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Thrown when trying to create a stream with a cliff time not strictly less than the end time.\n error SablierV2LockupLinear_CliffTimeNotLessThanEndTime(uint40 cliffTime, uint40 endTime);\n\n /// @notice Thrown when trying to create a stream with a start time greater than the cliff time.\n error SablierV2LockupLinear_StartTimeGreaterThanCliffTime(uint40 startTime, uint40 cliffTime);\n\n /*//////////////////////////////////////////////////////////////////////////\n SABLIER-V2-NFT-DESCRIPTOR\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Thrown when trying to generate the token URI for an unknown ERC-721 NFT contract.\n error SablierV2NFTDescriptor_UnknownNFT(IERC721Metadata nft, string symbol);\n}\n"
},
"src/libraries/Helpers.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity >=0.8.19;\n\nimport { UD60x18, ud } from \"@prb/math/src/UD60x18.sol\";\n\nimport { Lockup, LockupDynamic, LockupLinear } from \"../types/DataTypes.sol\";\nimport { Errors } from \"./Errors.sol\";\n\n/// @title Helpers\n/// @notice Library with helper functions needed across the Sablier V2 contracts.\nlibrary Helpers {\n /*//////////////////////////////////////////////////////////////////////////\n INTERNAL CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @dev Checks that neither fee is greater than `maxFee`, and then calculates the protocol fee amount, the\n /// broker fee amount, and the deposit amount from the total amount.\n function checkAndCalculateFees(\n uint128 totalAmount,\n UD60x18 protocolFee,\n UD60x18 brokerFee,\n UD60x18 maxFee\n )\n internal\n pure\n returns (Lockup.CreateAmounts memory amounts)\n {\n // When the total amount is zero, the fees are also zero.\n if (totalAmount == 0) {\n return Lockup.CreateAmounts(0, 0, 0);\n }\n\n // Checks: the protocol fee is not greater than `maxFee`.\n if (protocolFee.gt(maxFee)) {\n revert Errors.SablierV2Lockup_ProtocolFeeTooHigh(protocolFee, maxFee);\n }\n // Checks: the broker fee is not greater than `maxFee`.\n if (brokerFee.gt(maxFee)) {\n revert Errors.SablierV2Lockup_BrokerFeeTooHigh(brokerFee, maxFee);\n }\n\n // Calculate the protocol fee amount.\n // The cast to uint128 is safe because the maximum fee is hard coded.\n amounts.protocolFee = uint128(ud(totalAmount).mul(protocolFee).intoUint256());\n\n // Calculate the broker fee amount.\n // The cast to uint128 is safe because the maximum fee is hard coded.\n amounts.brokerFee = uint128(ud(totalAmount).mul(brokerFee).intoUint256());\n\n // Assert that the total amount is strictly greater than the sum of the protocol fee amount and the\n // broker fee amount.\n assert(totalAmount > amounts.protocolFee + amounts.brokerFee);\n\n // Calculate the deposit amount (the amount to stream, net of fees).\n amounts.deposit = totalAmount - amounts.protocolFee - amounts.brokerFee;\n }\n\n /// @dev Checks the parameters of the {SablierV2LockupDynamic-_createWithMilestones} function.\n function checkCreateWithMilestones(\n uint128 depositAmount,\n LockupDynamic.Segment[] memory segments,\n uint256 maxSegmentCount,\n uint40 startTime\n )\n internal\n view\n {\n // Checks: the deposit amount is not zero.\n if (depositAmount == 0) {\n revert Errors.SablierV2Lockup_DepositAmountZero();\n }\n\n // Checks: the segment count is not zero.\n uint256 segmentCount = segments.length;\n if (segmentCount == 0) {\n revert Errors.SablierV2LockupDynamic_SegmentCountZero();\n }\n\n // Checks: the segment count is not greater than the maximum allowed.\n if (segmentCount > maxSegmentCount) {\n revert Errors.SablierV2LockupDynamic_SegmentCountTooHigh(segmentCount);\n }\n\n // Checks: requirements of segments variables.\n _checkSegments(segments, depositAmount, startTime);\n }\n\n /// @dev Checks the parameters of the {SablierV2LockupLinear-_createWithRange} function.\n function checkCreateWithRange(uint128 depositAmount, LockupLinear.Range memory range) internal view {\n // Checks: the deposit amount is not zero.\n if (depositAmount == 0) {\n revert Errors.SablierV2Lockup_DepositAmountZero();\n }\n\n // Checks: the start time is less than or equal to the cliff time.\n if (range.start > range.cliff) {\n revert Errors.SablierV2LockupLinear_StartTimeGreaterThanCliffTime(range.start, range.cliff);\n }\n\n // Checks: the cliff time is strictly less than the end time.\n if (range.cliff >= range.end) {\n revert Errors.SablierV2LockupLinear_CliffTimeNotLessThanEndTime(range.cliff, range.end);\n }\n\n // Checks: the end time is in the future.\n uint40 currentTime = uint40(block.timestamp);\n if (currentTime >= range.end) {\n revert Errors.SablierV2Lockup_EndTimeNotInTheFuture(currentTime, range.end);\n }\n }\n\n /// @dev Checks that the segment array counts match, and then adjusts the segments by calculating the milestones.\n function checkDeltasAndCalculateMilestones(LockupDynamic.SegmentWithDelta[] memory segments)\n internal\n view\n returns (LockupDynamic.Segment[] memory segmentsWithMilestones)\n {\n uint256 segmentCount = segments.length;\n segmentsWithMilestones = new LockupDynamic.Segment[](segmentCount);\n\n // Make the current time the stream's start time.\n uint40 startTime = uint40(block.timestamp);\n\n // It is safe to use unchecked arithmetic because {_createWithMilestone} will nonetheless check the soundness\n // of the calculated segment milestones.\n unchecked {\n // Precompute the first segment because of the need to add the start time to the first segment delta.\n segmentsWithMilestones[0] = LockupDynamic.Segment({\n amount: segments[0].amount,\n exponent: segments[0].exponent,\n milestone: startTime + segments[0].delta\n });\n\n // Copy the segment amounts and exponents, and calculate the segment milestones.\n for (uint256 i = 1; i < segmentCount; ++i) {\n segmentsWithMilestones[i] = LockupDynamic.Segment({\n amount: segments[i].amount,\n exponent: segments[i].exponent,\n milestone: segmentsWithMilestones[i - 1].milestone + segments[i].delta\n });\n }\n }\n }\n\n /*//////////////////////////////////////////////////////////////////////////\n PRIVATE CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @dev Checks that:\n ///\n /// 1. The first milestone is strictly greater than the start time.\n /// 2. The milestones are ordered chronologically.\n /// 3. There are no duplicate milestones.\n /// 4. The deposit amount is equal to the sum of all segment amounts.\n function _checkSegments(\n LockupDynamic.Segment[] memory segments,\n uint128 depositAmount,\n uint40 startTime\n )\n private\n view\n {\n // Checks: the start time is strictly less than the first segment milestone.\n if (startTime >= segments[0].milestone) {\n revert Errors.SablierV2LockupDynamic_StartTimeNotLessThanFirstSegmentMilestone(\n startTime, segments[0].milestone\n );\n }\n\n // Pre-declare the variables needed in the for loop.\n uint128 segmentAmountsSum;\n uint40 currentMilestone;\n uint40 previousMilestone;\n\n // Iterate over the segments to:\n //\n // 1. Calculate the sum of all segment amounts.\n // 2. Check that the milestones are ordered.\n uint256 count = segments.length;\n for (uint256 index = 0; index < count;) {\n // Add the current segment amount to the sum.\n segmentAmountsSum += segments[index].amount;\n\n // Checks: the current milestone is strictly greater than the previous milestone.\n currentMilestone = segments[index].milestone;\n if (currentMilestone <= previousMilestone) {\n revert Errors.SablierV2LockupDynamic_SegmentMilestonesNotOrdered(\n index, previousMilestone, currentMilestone\n );\n }\n\n // Make the current milestone the previous milestone of the next loop iteration.\n previousMilestone = currentMilestone;\n\n // Increment the loop iterator.\n unchecked {\n index += 1;\n }\n }\n\n // Checks: the last milestone is in the future.\n // When the loop exits, the current milestone is the last milestone, i.e. the stream's end time.\n uint40 currentTime = uint40(block.timestamp);\n if (currentTime >= currentMilestone) {\n revert Errors.SablierV2Lockup_EndTimeNotInTheFuture(currentTime, currentMilestone);\n }\n\n // Checks: the deposit amount is equal to the segment amounts sum.\n if (depositAmount != segmentAmountsSum) {\n revert Errors.SablierV2LockupDynamic_DepositAmountNotEqualToSegmentAmountsSum(\n depositAmount, segmentAmountsSum\n );\n }\n }\n}\n"
},
"src/types/DataTypes.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity >=0.8.19;\n\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport { UD2x18 } from \"@prb/math/src/UD2x18.sol\";\nimport { UD60x18 } from \"@prb/math/src/UD60x18.sol\";\n\n// DataTypes.sol\n//\n// This file defines all structs used in V2 Core, most of which are organized under three namespaces:\n//\n// - Lockup\n// - LockupDynamic\n// - LockupLinear\n//\n// You will notice that some structs contain \"slot\" annotations - they are used to indicate the\n// storage layout of the struct. It is more gas efficient to group small data types together so\n// that they fit in a single 32-byte slot.\n\n/// @notice Struct encapsulating the broker parameters passed to the create functions. Both can be set to zero.\n/// @param account The address receiving the broker's fee.\n/// @param fee The broker's percentage fee from the total amount, denoted as a fixed-point number where 1e18 is 100%.\nstruct Broker {\n address account;\n UD60x18 fee;\n}\n\n/// @notice Namespace for the structs used in both {SablierV2LockupLinear} and {SablierV2LockupDynamic}.\nlibrary Lockup {\n /// @notice Struct encapsulating the deposit, withdrawn, and refunded amounts, all denoted in units\n /// of the asset's decimals.\n /// @dev Because the deposited and the withdrawn amount are often read together, declaring them in\n /// the same slot saves gas.\n /// @param deposited The initial amount deposited in the stream, net of fees.\n /// @param withdrawn The cumulative amount withdrawn from the stream.\n /// @param refunded The amount refunded to the sender. Unless the stream was canceled, this is always zero.\n struct Amounts {\n // slot 0\n uint128 deposited;\n uint128 withdrawn;\n // slot 1\n uint128 refunded;\n }\n\n /// @notice Struct encapsulating the deposit amount, the protocol fee amount, and the broker fee amount,\n /// all denoted in units of the asset's decimals.\n /// @param deposit The amount to deposit in the stream.\n /// @param protocolFee The protocol fee amount.\n /// @param brokerFee The broker fee amount.\n struct CreateAmounts {\n uint128 deposit;\n uint128 protocolFee;\n uint128 brokerFee;\n }\n\n /// @notice Enum representing the different statuses of a stream.\n /// @custom:value PENDING Stream created but not started; assets are in a pending state.\n /// @custom:value STREAMING Active stream where assets are currently being streamed.\n /// @custom:value SETTLED All assets have been streamed; recipient is due to withdraw them.\n /// @custom:value CANCELED Canceled stream; remaining assets await recipient's withdrawal.\n /// @custom:value DEPLETED Depleted stream; all assets have been withdrawn and/or refunded.\n enum Status {\n PENDING, // value 0\n STREAMING, // value 1\n SETTLED, // value 2\n CANCELED, // value 3\n DEPLETED // value 4\n }\n}\n\n/// @notice Namespace for the structs used in {SablierV2LockupDynamic}.\nlibrary LockupDynamic {\n /// @notice Struct encapsulating the parameters for the {SablierV2LockupDynamic.createWithDeltas} function.\n /// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the\n /// same as `msg.sender`.\n /// @param recipient The address receiving the assets.\n /// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential\n /// fees, all denoted in units of the asset's decimals.\n /// @param asset The contract address of the ERC-20 asset used for streaming.\n /// @param cancelable Indicates if the stream is cancelable.\n /// @param transferable Indicates if the stream NFT is transferable.\n /// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the\n /// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.\n /// @param segments Segments with deltas used to compose the custom streaming curve. Milestones are calculated by\n /// starting from `block.timestamp` and adding each delta to the previous milestone.\n struct CreateWithDeltas {\n address sender;\n bool cancelable;\n bool transferable;\n address recipient;\n uint128 totalAmount;\n IERC20 asset;\n Broker broker;\n SegmentWithDelta[] segments;\n }\n\n /// @notice Struct encapsulating the parameters for the {SablierV2LockupDynamic.createWithMilestones}\n /// function.\n /// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the\n /// same as `msg.sender`.\n /// @param startTime The Unix timestamp indicating the stream's start.\n /// @param cancelable Indicates if the stream is cancelable.\n /// @param transferable Indicates if the stream NFT is transferable.\n /// @param recipient The address receiving the assets.\n /// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential\n /// fees, all denoted in units of the asset's decimals.\n /// @param asset The contract address of the ERC-20 asset used for streaming.\n /// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the\n /// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.\n /// @param segments Segments used to compose the custom streaming curve.\n struct CreateWithMilestones {\n address sender;\n uint40 startTime;\n bool cancelable;\n bool transferable;\n address recipient;\n uint128 totalAmount;\n IERC20 asset;\n Broker broker;\n Segment[] segments;\n }\n\n /// @notice Struct encapsulating the time range.\n /// @param start The Unix timestamp indicating the stream's start.\n /// @param end The Unix timestamp indicating the stream's end.\n struct Range {\n uint40 start;\n uint40 end;\n }\n\n /// @notice Segment struct used in the Lockup Dynamic stream.\n /// @param amount The amount of assets to be streamed in this segment, denoted in units of the asset's decimals.\n /// @param exponent The exponent of this segment, denoted as a fixed-point number.\n /// @param milestone The Unix timestamp indicating this segment's end.\n struct Segment {\n // slot 0\n uint128 amount;\n UD2x18 exponent;\n uint40 milestone;\n }\n\n /// @notice Segment struct used at runtime in {SablierV2LockupDynamic.createWithDeltas}.\n /// @param amount The amount of assets to be streamed in this segment, denoted in units of the asset's decimals.\n /// @param exponent The exponent of this segment, denoted as a fixed-point number.\n /// @param delta The time difference in seconds between this segment and the previous one.\n struct SegmentWithDelta {\n uint128 amount;\n UD2x18 exponent;\n uint40 delta;\n }\n\n /// @notice Lockup Dynamic stream.\n /// @dev The fields are arranged like this to save gas via tight variable packing.\n /// @param sender The address streaming the assets, with the ability to cancel the stream.\n /// @param startTime The Unix timestamp indicating the stream's start.\n /// @param endTime The Unix timestamp indicating the stream's end.\n /// @param isCancelable Boolean indicating if the stream is cancelable.\n /// @param wasCanceled Boolean indicating if the stream was canceled.\n /// @param asset The contract address of the ERC-20 asset used for streaming.\n /// @param isDepleted Boolean indicating if the stream is depleted.\n /// @param isStream Boolean indicating if the struct entity exists.\n /// @param isTransferable Boolean indicating if the stream NFT is transferable.\n /// @param amounts Struct containing the deposit, withdrawn, and refunded amounts, all denoted in units of the\n /// asset's decimals.\n /// @param segments Segments used to compose the custom streaming curve.\n struct Stream {\n // slot 0\n address sender;\n uint40 startTime;\n uint40 endTime;\n bool isCancelable;\n bool wasCanceled;\n // slot 1\n IERC20 asset;\n bool isDepleted;\n bool isStream;\n bool isTransferable;\n // slot 2 and 3\n Lockup.Amounts amounts;\n // slots [4..n]\n Segment[] segments;\n }\n}\n\n/// @notice Namespace for the structs used in {SablierV2LockupLinear}.\nlibrary LockupLinear {\n /// @notice Struct encapsulating the parameters for the {SablierV2LockupLinear.createWithDurations} function.\n /// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the\n /// same as `msg.sender`.\n /// @param recipient The address receiving the assets.\n /// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential\n /// fees, all denoted in units of the asset's decimals.\n /// @param asset The contract address of the ERC-20 asset used for streaming.\n /// @param cancelable Indicates if the stream is cancelable.\n /// @param transferable Indicates if the stream NFT is transferable.\n /// @param durations Struct containing (i) cliff period duration and (ii) total stream duration, both in seconds.\n /// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the\n /// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.\n struct CreateWithDurations {\n address sender;\n address recipient;\n uint128 totalAmount;\n IERC20 asset;\n bool cancelable;\n bool transferable;\n Durations durations;\n Broker broker;\n }\n\n /// @notice Struct encapsulating the parameters for the {SablierV2LockupLinear.createWithRange} function.\n /// @param sender The address streaming the assets, with the ability to cancel the stream. It doesn't have to be the\n /// same as `msg.sender`.\n /// @param recipient The address receiving the assets.\n /// @param totalAmount The total amount of ERC-20 assets to be paid, including the stream deposit and any potential\n /// fees, all denoted in units of the asset's decimals.\n /// @param asset The contract address of the ERC-20 asset used for streaming.\n /// @param cancelable Indicates if the stream is cancelable.\n /// @param transferable Indicates if the stream NFT is transferable.\n /// @param range Struct containing (i) the stream's start time, (ii) cliff time, and (iii) end time, all as Unix\n /// timestamps.\n /// @param broker Struct containing (i) the address of the broker assisting in creating the stream, and (ii) the\n /// percentage fee paid to the broker from `totalAmount`, denoted as a fixed-point number. Both can be set to zero.\n struct CreateWithRange {\n address sender;\n address recipient;\n uint128 totalAmount;\n IERC20 asset;\n bool cancelable;\n bool transferable;\n Range range;\n Broker broker;\n }\n\n /// @notice Struct encapsulating the cliff duration and the total duration.\n /// @param cliff The cliff duration in seconds.\n /// @param total The total duration in seconds.\n struct Durations {\n uint40 cliff;\n uint40 total;\n }\n\n /// @notice Struct encapsulating the time range.\n /// @param start The Unix timestamp for the stream's start.\n /// @param cliff The Unix timestamp for the cliff period's end.\n /// @param end The Unix timestamp for the stream's end.\n struct Range {\n uint40 start;\n uint40 cliff;\n uint40 end;\n }\n\n /// @notice Lockup Linear stream.\n /// @dev The fields are arranged like this to save gas via tight variable packing.\n /// @param sender The address streaming the assets, with the ability to cancel the stream.\n /// @param startTime The Unix timestamp indicating the stream's start.\n /// @param cliffTime The Unix timestamp indicating the cliff period's end.\n /// @param isCancelable Boolean indicating if the stream is cancelable.\n /// @param wasCanceled Boolean indicating if the stream was canceled.\n /// @param asset The contract address of the ERC-20 asset used for streaming.\n /// @param endTime The Unix timestamp indicating the stream's end.\n /// @param isDepleted Boolean indicating if the stream is depleted.\n /// @param isStream Boolean indicating if the struct entity exists.\n /// @param isTransferable Boolean indicating if the stream NFT is transferable.\n /// @param amounts Struct containing the deposit, withdrawn, and refunded amounts, all denoted in units of the\n /// asset's decimals.\n struct Stream {\n // slot 0\n address sender;\n uint40 startTime;\n uint40 cliffTime;\n bool isCancelable;\n bool wasCanceled;\n // slot 1\n IERC20 asset;\n uint40 endTime;\n bool isDepleted;\n bool isStream;\n bool isTransferable;\n // slot 2 and 3\n Lockup.Amounts amounts;\n }\n}\n"
},
"node_modules/@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n */\ninterface IERC20Permit {\n /**\n * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n * given ``owner``'s signed approval.\n *\n * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n * ordering also apply here.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `deadline` must be a timestamp in the future.\n * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n * over the EIP712-formatted function arguments.\n * - the signature must use ``owner``'s current nonce (see {nonces}).\n *\n * For more information on the signature format, see the\n * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n * section].\n */\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n\n /**\n * @dev Returns the current nonce for `owner`. This value must be\n * included whenever a signature is generated for {permit}.\n *\n * Every successful call to {permit} increases ``owner``'s nonce by one. This\n * prevents a signature from being used multiple times.\n */\n function nonces(address owner) external view returns (uint256);\n\n /**\n * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n */\n // solhint-disable-next-line func-name-mixedcase\n function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
},
"node_modules/@openzeppelin/contracts/utils/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n *\n * Furthermore, `isContract` will also return true if the target contract within\n * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n * which only has an effect at the end of a transaction.\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n *\n * _Available since v4.8._\n */\n function verifyCallResultFromTarget(\n address target,\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n if (success) {\n if (returndata.length == 0) {\n // only check isContract if the call was successful and the return data is empty\n // otherwise we already know that it was a contract\n require(isContract(target), \"Address: call to non-contract\");\n }\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n /**\n * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason or using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n function _revert(bytes memory returndata, string memory errorMessage) private pure {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n}\n"
},
"node_modules/@openzeppelin/contracts/token/ERC721/IERC721.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC721 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 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 ERC721 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 {setApprovalForAll}.\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 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 ERC721\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 caller.\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"
},
"node_modules/@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title ERC721 token receiver interface\n * @dev Interface for any contract that wants to support safeTransfers\n * from ERC721 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 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"
},
"node_modules/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../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"
},
"node_modules/@openzeppelin/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\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"
},
"node_modules/@openzeppelin/contracts/utils/Strings.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./math/Math.sol\";\nimport \"./math/SignedMath.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n bytes16 private constant _SYMBOLS = \"0123456789abcdef\";\n uint8 private constant _ADDRESS_LENGTH = 20;\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), _SYMBOLS))\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 toString(int256 value) internal pure returns (string memory) {\n return string(abi.encodePacked(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 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] = _SYMBOLS[value & 0xf];\n value >>= 4;\n }\n require(value == 0, \"Strings: hex length insufficient\");\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 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 keccak256(bytes(a)) == keccak256(bytes(b));\n }\n}\n"
},
"node_modules/@openzeppelin/contracts/utils/introspection/ERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 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 *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n"
},
"node_modules/@prb/math/src/ud60x18/Casting.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport \"./Errors.sol\" as CastingErrors;\nimport { MAX_UINT128, MAX_UINT40 } from \"../Common.sol\";\nimport { uMAX_SD1x18 } from \"../sd1x18/Constants.sol\";\nimport { SD1x18 } from \"../sd1x18/ValueType.sol\";\nimport { uMAX_SD59x18 } from \"../sd59x18/Constants.sol\";\nimport { SD59x18 } from \"../sd59x18/ValueType.sol\";\nimport { uMAX_UD2x18 } from \"../ud2x18/Constants.sol\";\nimport { UD2x18 } from \"../ud2x18/ValueType.sol\";\nimport { UD60x18 } from \"./ValueType.sol\";\n\n/// @notice Casts a UD60x18 number into SD1x18.\n/// @dev Requirements:\n/// - x must be less than or equal to `uMAX_SD1x18`.\nfunction intoSD1x18(UD60x18 x) pure returns (SD1x18 result) {\n uint256 xUint = UD60x18.unwrap(x);\n if (xUint > uint256(int256(uMAX_SD1x18))) {\n revert CastingErrors.PRBMath_UD60x18_IntoSD1x18_Overflow(x);\n }\n result = SD1x18.wrap(int64(uint64(xUint)));\n}\n\n/// @notice Casts a UD60x18 number into UD2x18.\n/// @dev Requirements:\n/// - x must be less than or equal to `uMAX_UD2x18`.\nfunction intoUD2x18(UD60x18 x) pure returns (UD2x18 result) {\n uint256 xUint = UD60x18.unwrap(x);\n if (xUint > uMAX_UD2x18) {\n revert CastingErrors.PRBMath_UD60x18_IntoUD2x18_Overflow(x);\n }\n result = UD2x18.wrap(uint64(xUint));\n}\n\n/// @notice Casts a UD60x18 number into SD59x18.\n/// @dev Requirements:\n/// - x must be less than or equal to `uMAX_SD59x18`.\nfunction intoSD59x18(UD60x18 x) pure returns (SD59x18 result) {\n uint256 xUint = UD60x18.unwrap(x);\n if (xUint > uint256(uMAX_SD59x18)) {\n revert CastingErrors.PRBMath_UD60x18_IntoSD59x18_Overflow(x);\n }\n result = SD59x18.wrap(int256(xUint));\n}\n\n/// @notice Casts a UD60x18 number into uint128.\n/// @dev This is basically an alias for {unwrap}.\nfunction intoUint256(UD60x18 x) pure returns (uint256 result) {\n result = UD60x18.unwrap(x);\n}\n\n/// @notice Casts a UD60x18 number into uint128.\n/// @dev Requirements:\n/// - x must be less than or equal to `MAX_UINT128`.\nfunction intoUint128(UD60x18 x) pure returns (uint128 result) {\n uint256 xUint = UD60x18.unwrap(x);\n if (xUint > MAX_UINT128) {\n revert CastingErrors.PRBMath_UD60x18_IntoUint128_Overflow(x);\n }\n result = uint128(xUint);\n}\n\n/// @notice Casts a UD60x18 number into uint40.\n/// @dev Requirements:\n/// - x must be less than or equal to `MAX_UINT40`.\nfunction intoUint40(UD60x18 x) pure returns (uint40 result) {\n uint256 xUint = UD60x18.unwrap(x);\n if (xUint > MAX_UINT40) {\n revert CastingErrors.PRBMath_UD60x18_IntoUint40_Overflow(x);\n }\n result = uint40(xUint);\n}\n\n/// @notice Alias for {wrap}.\nfunction ud(uint256 x) pure returns (UD60x18 result) {\n result = UD60x18.wrap(x);\n}\n\n/// @notice Alias for {wrap}.\nfunction ud60x18(uint256 x) pure returns (UD60x18 result) {\n result = UD60x18.wrap(x);\n}\n\n/// @notice Unwraps a UD60x18 number into uint256.\nfunction unwrap(UD60x18 x) pure returns (uint256 result) {\n result = UD60x18.unwrap(x);\n}\n\n/// @notice Wraps a uint256 number into the UD60x18 value type.\nfunction wrap(uint256 x) pure returns (UD60x18 result) {\n result = UD60x18.wrap(x);\n}\n"
},
"node_modules/@prb/math/src/ud60x18/Constants.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport { UD60x18 } from \"./ValueType.sol\";\n\n// NOTICE: the \"u\" prefix stands for \"unwrapped\".\n\n/// @dev Euler's number as a UD60x18 number.\nUD60x18 constant E = UD60x18.wrap(2_718281828459045235);\n\n/// @dev The maximum input permitted in {exp}.\nuint256 constant uEXP_MAX_INPUT = 133_084258667509499440;\nUD60x18 constant EXP_MAX_INPUT = UD60x18.wrap(uEXP_MAX_INPUT);\n\n/// @dev The maximum input permitted in {exp2}.\nuint256 constant uEXP2_MAX_INPUT = 192e18 - 1;\nUD60x18 constant EXP2_MAX_INPUT = UD60x18.wrap(uEXP2_MAX_INPUT);\n\n/// @dev Half the UNIT number.\nuint256 constant uHALF_UNIT = 0.5e18;\nUD60x18 constant HALF_UNIT = UD60x18.wrap(uHALF_UNIT);\n\n/// @dev $log_2(10)$ as a UD60x18 number.\nuint256 constant uLOG2_10 = 3_321928094887362347;\nUD60x18 constant LOG2_10 = UD60x18.wrap(uLOG2_10);\n\n/// @dev $log_2(e)$ as a UD60x18 number.\nuint256 constant uLOG2_E = 1_442695040888963407;\nUD60x18 constant LOG2_E = UD60x18.wrap(uLOG2_E);\n\n/// @dev The maximum value a UD60x18 number can have.\nuint256 constant uMAX_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_584007913129639935;\nUD60x18 constant MAX_UD60x18 = UD60x18.wrap(uMAX_UD60x18);\n\n/// @dev The maximum whole value a UD60x18 number can have.\nuint256 constant uMAX_WHOLE_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_000000000000000000;\nUD60x18 constant MAX_WHOLE_UD60x18 = UD60x18.wrap(uMAX_WHOLE_UD60x18);\n\n/// @dev PI as a UD60x18 number.\nUD60x18 constant PI = UD60x18.wrap(3_141592653589793238);\n\n/// @dev The unit number, which gives the decimal precision of UD60x18.\nuint256 constant uUNIT = 1e18;\nUD60x18 constant UNIT = UD60x18.wrap(uUNIT);\n\n/// @dev The unit number squared.\nuint256 constant uUNIT_SQUARED = 1e36;\nUD60x18 constant UNIT_SQUARED = UD60x18.wrap(uUNIT_SQUARED);\n\n/// @dev Zero as a UD60x18 number.\nUD60x18 constant ZERO = UD60x18.wrap(0);\n"
},
"node_modules/@prb/math/src/ud60x18/Conversions.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport { uMAX_UD60x18, uUNIT } from \"./Constants.sol\";\nimport { PRBMath_UD60x18_Convert_Overflow } from \"./Errors.sol\";\nimport { UD60x18 } from \"./ValueType.sol\";\n\n/// @notice Converts a UD60x18 number to a simple integer by dividing it by `UNIT`.\n/// @dev The result is rounded toward zero.\n/// @param x The UD60x18 number to convert.\n/// @return result The same number in basic integer form.\nfunction convert(UD60x18 x) pure returns (uint256 result) {\n result = UD60x18.unwrap(x) / uUNIT;\n}\n\n/// @notice Converts a simple integer to UD60x18 by multiplying it by `UNIT`.\n///\n/// @dev Requirements:\n/// - x must be less than or equal to `MAX_UD60x18 / UNIT`.\n///\n/// @param x The basic integer to convert.\n/// @param result The same number converted to UD60x18.\nfunction convert(uint256 x) pure returns (UD60x18 result) {\n if (x > uMAX_UD60x18 / uUNIT) {\n revert PRBMath_UD60x18_Convert_Overflow(x);\n }\n unchecked {\n result = UD60x18.wrap(x * uUNIT);\n }\n}\n"
},
"node_modules/@prb/math/src/ud60x18/Errors.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport { UD60x18 } from \"./ValueType.sol\";\n\n/// @notice Thrown when ceiling a number overflows UD60x18.\nerror PRBMath_UD60x18_Ceil_Overflow(UD60x18 x);\n\n/// @notice Thrown when converting a basic integer to the fixed-point format overflows UD60x18.\nerror PRBMath_UD60x18_Convert_Overflow(uint256 x);\n\n/// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.\nerror PRBMath_UD60x18_Exp_InputTooBig(UD60x18 x);\n\n/// @notice Thrown when taking the binary exponent of a base greater than 192e18.\nerror PRBMath_UD60x18_Exp2_InputTooBig(UD60x18 x);\n\n/// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows UD60x18.\nerror PRBMath_UD60x18_Gm_Overflow(UD60x18 x, UD60x18 y);\n\n/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.\nerror PRBMath_UD60x18_IntoSD1x18_Overflow(UD60x18 x);\n\n/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD59x18.\nerror PRBMath_UD60x18_IntoSD59x18_Overflow(UD60x18 x);\n\n/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.\nerror PRBMath_UD60x18_IntoUD2x18_Overflow(UD60x18 x);\n\n/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.\nerror PRBMath_UD60x18_IntoUint128_Overflow(UD60x18 x);\n\n/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.\nerror PRBMath_UD60x18_IntoUint40_Overflow(UD60x18 x);\n\n/// @notice Thrown when taking the logarithm of a number less than 1.\nerror PRBMath_UD60x18_Log_InputTooSmall(UD60x18 x);\n\n/// @notice Thrown when calculating the square root overflows UD60x18.\nerror PRBMath_UD60x18_Sqrt_Overflow(UD60x18 x);\n"
},
"node_modules/@prb/math/src/ud60x18/Helpers.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport { wrap } from \"./Casting.sol\";\nimport { UD60x18 } from \"./ValueType.sol\";\n\n/// @notice Implements the checked addition operation (+) in the UD60x18 type.\nfunction add(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {\n result = wrap(x.unwrap() + y.unwrap());\n}\n\n/// @notice Implements the AND (&) bitwise operation in the UD60x18 type.\nfunction and(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {\n result = wrap(x.unwrap() & bits);\n}\n\n/// @notice Implements the AND (&) bitwise operation in the UD60x18 type.\nfunction and2(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {\n result = wrap(x.unwrap() & y.unwrap());\n}\n\n/// @notice Implements the equal operation (==) in the UD60x18 type.\nfunction eq(UD60x18 x, UD60x18 y) pure returns (bool result) {\n result = x.unwrap() == y.unwrap();\n}\n\n/// @notice Implements the greater than operation (>) in the UD60x18 type.\nfunction gt(UD60x18 x, UD60x18 y) pure returns (bool result) {\n result = x.unwrap() > y.unwrap();\n}\n\n/// @notice Implements the greater than or equal to operation (>=) in the UD60x18 type.\nfunction gte(UD60x18 x, UD60x18 y) pure returns (bool result) {\n result = x.unwrap() >= y.unwrap();\n}\n\n/// @notice Implements a zero comparison check function in the UD60x18 type.\nfunction isZero(UD60x18 x) pure returns (bool result) {\n // This wouldn't work if x could be negative.\n result = x.unwrap() == 0;\n}\n\n/// @notice Implements the left shift operation (<<) in the UD60x18 type.\nfunction lshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {\n result = wrap(x.unwrap() << bits);\n}\n\n/// @notice Implements the lower than operation (<) in the UD60x18 type.\nfunction lt(UD60x18 x, UD60x18 y) pure returns (bool result) {\n result = x.unwrap() < y.unwrap();\n}\n\n/// @notice Implements the lower than or equal to operation (<=) in the UD60x18 type.\nfunction lte(UD60x18 x, UD60x18 y) pure returns (bool result) {\n result = x.unwrap() <= y.unwrap();\n}\n\n/// @notice Implements the checked modulo operation (%) in the UD60x18 type.\nfunction mod(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {\n result = wrap(x.unwrap() % y.unwrap());\n}\n\n/// @notice Implements the not equal operation (!=) in the UD60x18 type.\nfunction neq(UD60x18 x, UD60x18 y) pure returns (bool result) {\n result = x.unwrap() != y.unwrap();\n}\n\n/// @notice Implements the NOT (~) bitwise operation in the UD60x18 type.\nfunction not(UD60x18 x) pure returns (UD60x18 result) {\n result = wrap(~x.unwrap());\n}\n\n/// @notice Implements the OR (|) bitwise operation in the UD60x18 type.\nfunction or(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {\n result = wrap(x.unwrap() | y.unwrap());\n}\n\n/// @notice Implements the right shift operation (>>) in the UD60x18 type.\nfunction rshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {\n result = wrap(x.unwrap() >> bits);\n}\n\n/// @notice Implements the checked subtraction operation (-) in the UD60x18 type.\nfunction sub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {\n result = wrap(x.unwrap() - y.unwrap());\n}\n\n/// @notice Implements the unchecked addition operation (+) in the UD60x18 type.\nfunction uncheckedAdd(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {\n unchecked {\n result = wrap(x.unwrap() + y.unwrap());\n }\n}\n\n/// @notice Implements the unchecked subtraction operation (-) in the UD60x18 type.\nfunction uncheckedSub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {\n unchecked {\n result = wrap(x.unwrap() - y.unwrap());\n }\n}\n\n/// @notice Implements the XOR (^) bitwise operation in the UD60x18 type.\nfunction xor(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {\n result = wrap(x.unwrap() ^ y.unwrap());\n}\n"
},
"node_modules/@prb/math/src/ud60x18/Math.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport \"../Common.sol\" as Common;\nimport \"./Errors.sol\" as Errors;\nimport { wrap } from \"./Casting.sol\";\nimport {\n uEXP_MAX_INPUT,\n uEXP2_MAX_INPUT,\n uHALF_UNIT,\n uLOG2_10,\n uLOG2_E,\n uMAX_UD60x18,\n uMAX_WHOLE_UD60x18,\n UNIT,\n uUNIT,\n uUNIT_SQUARED,\n ZERO\n} from \"./Constants.sol\";\nimport { UD60x18 } from \"./ValueType.sol\";\n\n/*//////////////////////////////////////////////////////////////////////////\n MATHEMATICAL FUNCTIONS\n//////////////////////////////////////////////////////////////////////////*/\n\n/// @notice Calculates the arithmetic average of x and y using the following formula:\n///\n/// $$\n/// avg(x, y) = (x & y) + ((xUint ^ yUint) / 2)\n/// $$\n//\n/// In English, this is what this formula does:\n///\n/// 1. AND x and y.\n/// 2. Calculate half of XOR x and y.\n/// 3. Add the two results together.\n///\n/// This technique is known as SWAR, which stands for \"SIMD within a register\". You can read more about it here:\n/// https://devblogs.microsoft.com/oldnewthing/20220207-00/?p=106223\n///\n/// @dev Notes:\n/// - The result is rounded toward zero.\n///\n/// @param x The first operand as a UD60x18 number.\n/// @param y The second operand as a UD60x18 number.\n/// @return result The arithmetic average as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction avg(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {\n uint256 xUint = x.unwrap();\n uint256 yUint = y.unwrap();\n unchecked {\n result = wrap((xUint & yUint) + ((xUint ^ yUint) >> 1));\n }\n}\n\n/// @notice Yields the smallest whole number greater than or equal to x.\n///\n/// @dev This is optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional\n/// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.\n///\n/// Requirements:\n/// - x must be less than or equal to `MAX_WHOLE_UD60x18`.\n///\n/// @param x The UD60x18 number to ceil.\n/// @param result The smallest whole number greater than or equal to x, as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction ceil(UD60x18 x) pure returns (UD60x18 result) {\n uint256 xUint = x.unwrap();\n if (xUint > uMAX_WHOLE_UD60x18) {\n revert Errors.PRBMath_UD60x18_Ceil_Overflow(x);\n }\n\n assembly (\"memory-safe\") {\n // Equivalent to `x % UNIT`.\n let remainder := mod(x, uUNIT)\n\n // Equivalent to `UNIT - remainder`.\n let delta := sub(uUNIT, remainder)\n\n // Equivalent to `x + remainder > 0 ? delta : 0`.\n result := add(x, mul(delta, gt(remainder, 0)))\n }\n}\n\n/// @notice Divides two UD60x18 numbers, returning a new UD60x18 number.\n///\n/// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.\n///\n/// Notes:\n/// - Refer to the notes in {Common.mulDiv}.\n///\n/// Requirements:\n/// - Refer to the requirements in {Common.mulDiv}.\n///\n/// @param x The numerator as a UD60x18 number.\n/// @param y The denominator as a UD60x18 number.\n/// @param result The quotient as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction div(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {\n result = wrap(Common.mulDiv(x.unwrap(), uUNIT, y.unwrap()));\n}\n\n/// @notice Calculates the natural exponent of x using the following formula:\n///\n/// $$\n/// e^x = 2^{x * log_2{e}}\n/// $$\n///\n/// @dev Requirements:\n/// - x must be less than 133_084258667509499441.\n///\n/// @param x The exponent as a UD60x18 number.\n/// @return result The result as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction exp(UD60x18 x) pure returns (UD60x18 result) {\n uint256 xUint = x.unwrap();\n\n // This check prevents values greater than 192e18 from being passed to {exp2}.\n if (xUint > uEXP_MAX_INPUT) {\n revert Errors.PRBMath_UD60x18_Exp_InputTooBig(x);\n }\n\n unchecked {\n // Inline the fixed-point multiplication to save gas.\n uint256 doubleUnitProduct = xUint * uLOG2_E;\n result = exp2(wrap(doubleUnitProduct / uUNIT));\n }\n}\n\n/// @notice Calculates the binary exponent of x using the binary fraction method.\n///\n/// @dev See https://ethereum.stackexchange.com/q/79903/24693\n///\n/// Requirements:\n/// - x must be less than 192e18.\n/// - The result must fit in UD60x18.\n///\n/// @param x The exponent as a UD60x18 number.\n/// @return result The result as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction exp2(UD60x18 x) pure returns (UD60x18 result) {\n uint256 xUint = x.unwrap();\n\n // Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.\n if (xUint > uEXP2_MAX_INPUT) {\n revert Errors.PRBMath_UD60x18_Exp2_InputTooBig(x);\n }\n\n // Convert x to the 192.64-bit fixed-point format.\n uint256 x_192x64 = (xUint << 64) / uUNIT;\n\n // Pass x to the {Common.exp2} function, which uses the 192.64-bit fixed-point number representation.\n result = wrap(Common.exp2(x_192x64));\n}\n\n/// @notice Yields the greatest whole number less than or equal to x.\n/// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.\n/// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.\n/// @param x The UD60x18 number to floor.\n/// @param result The greatest whole number less than or equal to x, as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction floor(UD60x18 x) pure returns (UD60x18 result) {\n assembly (\"memory-safe\") {\n // Equivalent to `x % UNIT`.\n let remainder := mod(x, uUNIT)\n\n // Equivalent to `x - remainder > 0 ? remainder : 0)`.\n result := sub(x, mul(remainder, gt(remainder, 0)))\n }\n}\n\n/// @notice Yields the excess beyond the floor of x using the odd function definition.\n/// @dev See https://en.wikipedia.org/wiki/Fractional_part.\n/// @param x The UD60x18 number to get the fractional part of.\n/// @param result The fractional part of x as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction frac(UD60x18 x) pure returns (UD60x18 result) {\n assembly (\"memory-safe\") {\n result := mod(x, uUNIT)\n }\n}\n\n/// @notice Calculates the geometric mean of x and y, i.e. $\\sqrt{x * y}$, rounding down.\n///\n/// @dev Requirements:\n/// - x * y must fit in UD60x18.\n///\n/// @param x The first operand as a UD60x18 number.\n/// @param y The second operand as a UD60x18 number.\n/// @return result The result as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction gm(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {\n uint256 xUint = x.unwrap();\n uint256 yUint = y.unwrap();\n if (xUint == 0 || yUint == 0) {\n return ZERO;\n }\n\n unchecked {\n // Checking for overflow this way is faster than letting Solidity do it.\n uint256 xyUint = xUint * yUint;\n if (xyUint / xUint != yUint) {\n revert Errors.PRBMath_UD60x18_Gm_Overflow(x, y);\n }\n\n // We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`\n // during multiplication. See the comments in {Common.sqrt}.\n result = wrap(Common.sqrt(xyUint));\n }\n}\n\n/// @notice Calculates the inverse of x.\n///\n/// @dev Notes:\n/// - The result is rounded toward zero.\n///\n/// Requirements:\n/// - x must not be zero.\n///\n/// @param x The UD60x18 number for which to calculate the inverse.\n/// @return result The inverse as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction inv(UD60x18 x) pure returns (UD60x18 result) {\n unchecked {\n result = wrap(uUNIT_SQUARED / x.unwrap());\n }\n}\n\n/// @notice Calculates the natural logarithm of x using the following formula:\n///\n/// $$\n/// ln{x} = log_2{x} / log_2{e}\n/// $$\n///\n/// @dev Notes:\n/// - Refer to the notes in {log2}.\n/// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.\n///\n/// Requirements:\n/// - Refer to the requirements in {log2}.\n///\n/// @param x The UD60x18 number for which to calculate the natural logarithm.\n/// @return result The natural logarithm as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction ln(UD60x18 x) pure returns (UD60x18 result) {\n unchecked {\n // Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that\n // {log2} can return is ~196_205294292027477728.\n result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);\n }\n}\n\n/// @notice Calculates the common logarithm of x using the following formula:\n///\n/// $$\n/// log_{10}{x} = log_2{x} / log_2{10}\n/// $$\n///\n/// However, if x is an exact power of ten, a hard coded value is returned.\n///\n/// @dev Notes:\n/// - Refer to the notes in {log2}.\n///\n/// Requirements:\n/// - Refer to the requirements in {log2}.\n///\n/// @param x The UD60x18 number for which to calculate the common logarithm.\n/// @return result The common logarithm as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction log10(UD60x18 x) pure returns (UD60x18 result) {\n uint256 xUint = x.unwrap();\n if (xUint < uUNIT) {\n revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);\n }\n\n // Note that the `mul` in this assembly block is the standard multiplication operation, not {UD60x18.mul}.\n // prettier-ignore\n assembly (\"memory-safe\") {\n switch x\n case 1 { result := mul(uUNIT, sub(0, 18)) }\n case 10 { result := mul(uUNIT, sub(1, 18)) }\n case 100 { result := mul(uUNIT, sub(2, 18)) }\n case 1000 { result := mul(uUNIT, sub(3, 18)) }\n case 10000 { result := mul(uUNIT, sub(4, 18)) }\n case 100000 { result := mul(uUNIT, sub(5, 18)) }\n case 1000000 { result := mul(uUNIT, sub(6, 18)) }\n case 10000000 { result := mul(uUNIT, sub(7, 18)) }\n case 100000000 { result := mul(uUNIT, sub(8, 18)) }\n case 1000000000 { result := mul(uUNIT, sub(9, 18)) }\n case 10000000000 { result := mul(uUNIT, sub(10, 18)) }\n case 100000000000 { result := mul(uUNIT, sub(11, 18)) }\n case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }\n case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }\n case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }\n case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }\n case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }\n case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }\n case 1000000000000000000 { result := 0 }\n case 10000000000000000000 { result := uUNIT }\n case 100000000000000000000 { result := mul(uUNIT, 2) }\n case 1000000000000000000000 { result := mul(uUNIT, 3) }\n case 10000000000000000000000 { result := mul(uUNIT, 4) }\n case 100000000000000000000000 { result := mul(uUNIT, 5) }\n case 1000000000000000000000000 { result := mul(uUNIT, 6) }\n case 10000000000000000000000000 { result := mul(uUNIT, 7) }\n case 100000000000000000000000000 { result := mul(uUNIT, 8) }\n case 1000000000000000000000000000 { result := mul(uUNIT, 9) }\n case 10000000000000000000000000000 { result := mul(uUNIT, 10) }\n case 100000000000000000000000000000 { result := mul(uUNIT, 11) }\n case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }\n case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }\n case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }\n case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }\n case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }\n case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }\n case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }\n case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }\n case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }\n case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }\n case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }\n case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }\n case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }\n case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }\n case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }\n case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }\n case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }\n case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }\n case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }\n case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }\n case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }\n case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }\n case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }\n case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }\n case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }\n case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }\n case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }\n case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }\n case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }\n case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }\n case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }\n case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }\n case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }\n case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }\n case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }\n case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }\n case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }\n case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }\n case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }\n case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }\n case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }\n case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }\n case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }\n case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }\n case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }\n case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }\n case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }\n case 100000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 59) }\n default { result := uMAX_UD60x18 }\n }\n\n if (result.unwrap() == uMAX_UD60x18) {\n unchecked {\n // Inline the fixed-point division to save gas.\n result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);\n }\n }\n}\n\n/// @notice Calculates the binary logarithm of x using the iterative approximation algorithm:\n///\n/// $$\n/// log_2{x} = n + log_2{y}, \\text{ where } y = x*2^{-n}, \\ y \\in [1, 2)\n/// $$\n///\n/// For $0 \\leq x \\lt 1$, the input is inverted:\n///\n/// $$\n/// log_2{x} = -log_2{\\frac{1}{x}}\n/// $$\n///\n/// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation\n///\n/// Notes:\n/// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.\n///\n/// Requirements:\n/// - x must be greater than zero.\n///\n/// @param x The UD60x18 number for which to calculate the binary logarithm.\n/// @return result The binary logarithm as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction log2(UD60x18 x) pure returns (UD60x18 result) {\n uint256 xUint = x.unwrap();\n\n if (xUint < uUNIT) {\n revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);\n }\n\n unchecked {\n // Calculate the integer part of the logarithm.\n uint256 n = Common.msb(xUint / uUNIT);\n\n // This is the integer part of the logarithm as a UD60x18 number. The operation can't overflow because n\n // n is at most 255 and UNIT is 1e18.\n uint256 resultUint = n * uUNIT;\n\n // Calculate $y = x * 2^{-n}$.\n uint256 y = xUint >> n;\n\n // If y is the unit number, the fractional part is zero.\n if (y == uUNIT) {\n return wrap(resultUint);\n }\n\n // Calculate the fractional part via the iterative approximation.\n // The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.\n uint256 DOUBLE_UNIT = 2e18;\n for (uint256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {\n y = (y * y) / uUNIT;\n\n // Is y^2 >= 2e18 and so in the range [2e18, 4e18)?\n if (y >= DOUBLE_UNIT) {\n // Add the 2^{-m} factor to the logarithm.\n resultUint += delta;\n\n // Halve y, which corresponds to z/2 in the Wikipedia article.\n y >>= 1;\n }\n }\n result = wrap(resultUint);\n }\n}\n\n/// @notice Multiplies two UD60x18 numbers together, returning a new UD60x18 number.\n///\n/// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.\n///\n/// Notes:\n/// - Refer to the notes in {Common.mulDiv}.\n///\n/// Requirements:\n/// - Refer to the requirements in {Common.mulDiv}.\n///\n/// @dev See the documentation in {Common.mulDiv18}.\n/// @param x The multiplicand as a UD60x18 number.\n/// @param y The multiplier as a UD60x18 number.\n/// @return result The product as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction mul(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {\n result = wrap(Common.mulDiv18(x.unwrap(), y.unwrap()));\n}\n\n/// @notice Raises x to the power of y.\n///\n/// For $1 \\leq x \\leq \\infty$, the following standard formula is used:\n///\n/// $$\n/// x^y = 2^{log_2{x} * y}\n/// $$\n///\n/// For $0 \\leq x \\lt 1$, since the unsigned {log2} is undefined, an equivalent formula is used:\n///\n/// $$\n/// i = \\frac{1}{x}\n/// w = 2^{log_2{i} * y}\n/// x^y = \\frac{1}{w}\n/// $$\n///\n/// @dev Notes:\n/// - Refer to the notes in {log2} and {mul}.\n/// - Returns `UNIT` for 0^0.\n/// - It may not perform well with very small values of x. Consider using SD59x18 as an alternative.\n///\n/// Requirements:\n/// - Refer to the requirements in {exp2}, {log2}, and {mul}.\n///\n/// @param x The base as a UD60x18 number.\n/// @param y The exponent as a UD60x18 number.\n/// @return result The result as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction pow(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {\n uint256 xUint = x.unwrap();\n uint256 yUint = y.unwrap();\n\n // If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.\n if (xUint == 0) {\n return yUint == 0 ? UNIT : ZERO;\n }\n // If x is `UNIT`, the result is always `UNIT`.\n else if (xUint == uUNIT) {\n return UNIT;\n }\n\n // If y is zero, the result is always `UNIT`.\n if (yUint == 0) {\n return UNIT;\n }\n // If y is `UNIT`, the result is always x.\n else if (yUint == uUNIT) {\n return x;\n }\n\n // If x is greater than `UNIT`, use the standard formula.\n if (xUint > uUNIT) {\n result = exp2(mul(log2(x), y));\n }\n // Conversely, if x is less than `UNIT`, use the equivalent formula.\n else {\n UD60x18 i = wrap(uUNIT_SQUARED / xUint);\n UD60x18 w = exp2(mul(log2(i), y));\n result = wrap(uUNIT_SQUARED / w.unwrap());\n }\n}\n\n/// @notice Raises x (a UD60x18 number) to the power y (an unsigned basic integer) using the well-known\n/// algorithm \"exponentiation by squaring\".\n///\n/// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.\n///\n/// Notes:\n/// - Refer to the notes in {Common.mulDiv18}.\n/// - Returns `UNIT` for 0^0.\n///\n/// Requirements:\n/// - The result must fit in UD60x18.\n///\n/// @param x The base as a UD60x18 number.\n/// @param y The exponent as a uint256.\n/// @return result The result as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction powu(UD60x18 x, uint256 y) pure returns (UD60x18 result) {\n // Calculate the first iteration of the loop in advance.\n uint256 xUint = x.unwrap();\n uint256 resultUint = y & 1 > 0 ? xUint : uUNIT;\n\n // Equivalent to `for(y /= 2; y > 0; y /= 2)`.\n for (y >>= 1; y > 0; y >>= 1) {\n xUint = Common.mulDiv18(xUint, xUint);\n\n // Equivalent to `y % 2 == 1`.\n if (y & 1 > 0) {\n resultUint = Common.mulDiv18(resultUint, xUint);\n }\n }\n result = wrap(resultUint);\n}\n\n/// @notice Calculates the square root of x using the Babylonian method.\n///\n/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.\n///\n/// Notes:\n/// - The result is rounded toward zero.\n///\n/// Requirements:\n/// - x must be less than `MAX_UD60x18 / UNIT`.\n///\n/// @param x The UD60x18 number for which to calculate the square root.\n/// @return result The result as a UD60x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction sqrt(UD60x18 x) pure returns (UD60x18 result) {\n uint256 xUint = x.unwrap();\n\n unchecked {\n if (xUint > uMAX_UD60x18 / uUNIT) {\n revert Errors.PRBMath_UD60x18_Sqrt_Overflow(x);\n }\n // Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two UD60x18 numbers.\n // In this case, the two numbers are both the square root.\n result = wrap(Common.sqrt(xUint * uUNIT));\n }\n}\n"
},
"node_modules/@prb/math/src/ud60x18/ValueType.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport \"./Casting.sol\" as Casting;\nimport \"./Helpers.sol\" as Helpers;\nimport \"./Math.sol\" as Math;\n\n/// @notice The unsigned 60.18-decimal fixed-point number representation, which can have up to 60 digits and up to 18\n/// decimals. The values of this are bound by the minimum and the maximum values permitted by the Solidity type uint256.\n/// @dev The value type is defined here so it can be imported in all other files.\ntype UD60x18 is uint256;\n\n/*//////////////////////////////////////////////////////////////////////////\n CASTING\n//////////////////////////////////////////////////////////////////////////*/\n\nusing {\n Casting.intoSD1x18,\n Casting.intoUD2x18,\n Casting.intoSD59x18,\n Casting.intoUint128,\n Casting.intoUint256,\n Casting.intoUint40,\n Casting.unwrap\n} for UD60x18 global;\n\n/*//////////////////////////////////////////////////////////////////////////\n MATHEMATICAL FUNCTIONS\n//////////////////////////////////////////////////////////////////////////*/\n\n// The global \"using for\" directive makes the functions in this library callable on the UD60x18 type.\nusing {\n Math.avg,\n Math.ceil,\n Math.div,\n Math.exp,\n Math.exp2,\n Math.floor,\n Math.frac,\n Math.gm,\n Math.inv,\n Math.ln,\n Math.log10,\n Math.log2,\n Math.mul,\n Math.pow,\n Math.powu,\n Math.sqrt\n} for UD60x18 global;\n\n/*//////////////////////////////////////////////////////////////////////////\n HELPER FUNCTIONS\n//////////////////////////////////////////////////////////////////////////*/\n\n// The global \"using for\" directive makes the functions in this library callable on the UD60x18 type.\nusing {\n Helpers.add,\n Helpers.and,\n Helpers.eq,\n Helpers.gt,\n Helpers.gte,\n Helpers.isZero,\n Helpers.lshift,\n Helpers.lt,\n Helpers.lte,\n Helpers.mod,\n Helpers.neq,\n Helpers.not,\n Helpers.or,\n Helpers.rshift,\n Helpers.sub,\n Helpers.uncheckedAdd,\n Helpers.uncheckedSub,\n Helpers.xor\n} for UD60x18 global;\n\n/*//////////////////////////////////////////////////////////////////////////\n OPERATORS\n//////////////////////////////////////////////////////////////////////////*/\n\n// The global \"using for\" directive makes it possible to use these operators on the UD60x18 type.\nusing {\n Helpers.add as +,\n Helpers.and2 as &,\n Math.div as /,\n Helpers.eq as ==,\n Helpers.gt as >,\n Helpers.gte as >=,\n Helpers.lt as <,\n Helpers.lte as <=,\n Helpers.or as |,\n Helpers.mod as %,\n Math.mul as *,\n Helpers.neq as !=,\n Helpers.not as ~,\n Helpers.sub as -,\n Helpers.xor as ^\n} for UD60x18 global;\n"
},
"node_modules/@openzeppelin/contracts/interfaces/IERC4906.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC4906.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\nimport \"./IERC721.sol\";\n\n/// @title EIP-721 Metadata Update Extension\ninterface IERC4906 is IERC165, IERC721 {\n /// @dev This event emits when the metadata of a token is changed.\n /// So that the third-party platforms such as NFT market could\n /// timely update the images and related attributes of the NFT.\n event MetadataUpdate(uint256 _tokenId);\n\n /// @dev This event emits when the metadata of a range of tokens is changed.\n /// So that the third-party platforms such as NFT market could\n /// timely update the images and related attributes of the NFTs.\n event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);\n}\n"
},
"src/abstracts/SablierV2Base.sol": {
"content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity >=0.8.19;\n\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { UD60x18 } from \"@prb/math/src/UD60x18.sol\";\n\nimport { IAdminable } from \"../interfaces/IAdminable.sol\";\nimport { ISablierV2Base } from \"../interfaces/ISablierV2Base.sol\";\nimport { ISablierV2Comptroller } from \"../interfaces/ISablierV2Comptroller.sol\";\nimport { Errors } from \"../libraries/Errors.sol\";\nimport { Adminable } from \"./Adminable.sol\";\nimport { NoDelegateCall } from \"./NoDelegateCall.sol\";\n\n/// @title SablierV2Base\n/// @notice See the documentation in {ISablierV2Base}.\nabstract contract SablierV2Base is\n NoDelegateCall, // 0 inherited components\n ISablierV2Base, // 1 inherited component\n Adminable // 1 inherited component\n{\n using SafeERC20 for IERC20;\n\n /*//////////////////////////////////////////////////////////////////////////\n PUBLIC CONSTANTS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @inheritdoc ISablierV2Base\n UD60x18 public constant override MAX_FEE = UD60x18.wrap(0.1e18);\n\n /*//////////////////////////////////////////////////////////////////////////\n PUBLIC STORAGE\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @inheritdoc ISablierV2Base\n ISablierV2Comptroller public override comptroller;\n\n /// @inheritdoc ISablierV2Base\n mapping(IERC20 asset => uint128 revenues) public override protocolRevenues;\n\n /*//////////////////////////////////////////////////////////////////////////\n CONSTRUCTOR\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @dev Emits a {TransferAdmin} event.\n /// @param initialAdmin The address of the initial contract admin.\n /// @param initialComptroller The address of the initial comptroller.\n constructor(address initialAdmin, ISablierV2Comptroller initialComptroller) {\n admin = initialAdmin;\n comptroller = initialComptroller;\n emit IAdminable.TransferAdmin({ oldAdmin: address(0), newAdmin: initialAdmin });\n }\n\n /*//////////////////////////////////////////////////////////////////////////\n USER-FACING NON-CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @inheritdoc ISablierV2Base\n function claimProtocolRevenues(IERC20 asset) external override onlyAdmin {\n // Checks: the protocol revenues are not zero.\n uint128 revenues = protocolRevenues[asset];\n if (revenues == 0) {\n revert Errors.SablierV2Base_NoProtocolRevenues(asset);\n }\n\n // Effects: set the protocol revenues to zero.\n protocolRevenues[asset] = 0;\n\n // Interactions: perform the ERC-20 transfer to pay the protocol revenues.\n asset.safeTransfer({ to: msg.sender, value: revenues });\n\n // Log the claim of the protocol revenues.\n emit ISablierV2Base.ClaimProtocolRevenues({ admin: msg.sender, asset: asset, protocolRevenues: revenues });\n }\n\n /// @inheritdoc ISablierV2Base\n function setComptroller(ISablierV2Comptroller newComptroller) external override onlyAdmin {\n // Effects: set the new comptroller.\n ISablierV2Comptroller oldComptroller = comptroller;\n comptroller = newComptroller;\n\n // Log the change of the comptroller.\n emit ISablierV2Base.SetComptroller({\n admin: msg.sender,\n oldComptroller: oldComptroller,\n newComptroller: newComptroller\n });\n }\n}\n"
},
"src/interfaces/IAdminable.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity >=0.8.19;\n\n/// @title IAdminable\n/// @notice Contract module that provides a basic access control mechanism, with an admin that can be\n/// granted exclusive access to specific functions. The inheriting contract must set the initial admin\n/// in the constructor.\ninterface IAdminable {\n /*//////////////////////////////////////////////////////////////////////////\n EVENTS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Emitted when the admin is transferred.\n /// @param oldAdmin The address of the old admin.\n /// @param newAdmin The address of the new admin.\n event TransferAdmin(address indexed oldAdmin, address indexed newAdmin);\n\n /*//////////////////////////////////////////////////////////////////////////\n CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice The address of the admin account or contract.\n function admin() external view returns (address);\n\n /*//////////////////////////////////////////////////////////////////////////\n NON-CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Transfers the contract admin to a new address.\n ///\n /// @dev Notes:\n /// - Does not revert if the admin is the same.\n /// - This function can potentially leave the contract without an admin, thereby removing any\n /// functionality that is only available to the admin.\n ///\n /// Requirements:\n /// - `msg.sender` must be the contract admin.\n ///\n /// @param newAdmin The address of the new admin.\n function transferAdmin(address newAdmin) external;\n}\n"
},
"src/interfaces/ISablierV2Base.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity >=0.8.19;\n\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport { UD60x18 } from \"@prb/math/src/UD60x18.sol\";\n\nimport { IAdminable } from \"./IAdminable.sol\";\nimport { ISablierV2Comptroller } from \"./ISablierV2Comptroller.sol\";\n\n/// @title ISablierV2Base\n/// @notice Base logic for all Sablier V2 streaming contracts.\ninterface ISablierV2Base is IAdminable {\n /*//////////////////////////////////////////////////////////////////////////\n EVENTS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Emitted when the admin claims all protocol revenues accrued for a particular ERC-20 asset.\n /// @param admin The address of the contract admin.\n /// @param asset The contract address of the ERC-20 asset the protocol revenues have been claimed for.\n /// @param protocolRevenues The amount of protocol revenues claimed, denoted in units of the asset's decimals.\n event ClaimProtocolRevenues(address indexed admin, IERC20 indexed asset, uint128 protocolRevenues);\n\n /// @notice Emitted when the admin sets a new comptroller contract.\n /// @param admin The address of the contract admin.\n /// @param oldComptroller The address of the old comptroller contract.\n /// @param newComptroller The address of the new comptroller contract.\n event SetComptroller(\n address indexed admin, ISablierV2Comptroller oldComptroller, ISablierV2Comptroller newComptroller\n );\n\n /*//////////////////////////////////////////////////////////////////////////\n CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Retrieves the maximum fee that can be charged by the protocol or a broker, denoted as a fixed-point\n /// number where 1e18 is 100%.\n /// @dev This value is hard coded as a constant.\n function MAX_FEE() external view returns (UD60x18);\n\n /// @notice Retrieves the address of the comptroller contract, responsible for the Sablier V2 protocol\n /// configuration.\n function comptroller() external view returns (ISablierV2Comptroller);\n\n /// @notice Retrieves the protocol revenues accrued for the provided ERC-20 asset, in units of the asset's\n /// decimals.\n /// @param asset The contract address of the ERC-20 asset to query.\n function protocolRevenues(IERC20 asset) external view returns (uint128 revenues);\n\n /*//////////////////////////////////////////////////////////////////////////\n NON-CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Claims all accumulated protocol revenues for the provided ERC-20 asset.\n ///\n /// @dev Emits a {ClaimProtocolRevenues} event.\n ///\n /// Requirements:\n /// - `msg.sender` must be the contract admin.\n ///\n /// @param asset The contract address of the ERC-20 asset for which to claim protocol revenues.\n function claimProtocolRevenues(IERC20 asset) external;\n\n /// @notice Assigns a new comptroller contract responsible for the protocol configuration.\n ///\n /// @dev Emits a {SetComptroller} event.\n ///\n /// Notes:\n /// - Does not revert if the comptroller is the same.\n ///\n /// Requirements:\n /// - `msg.sender` must be the contract admin.\n ///\n /// @param newComptroller The address of the new comptroller contract.\n function setComptroller(ISablierV2Comptroller newComptroller) external;\n}\n"
},
"node_modules/@prb/math/src/UD2x18.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\n/*\n\n██████╗ ██████╗ ██████╗ ███╗ ███╗ █████╗ ████████╗██╗ ██╗\n██╔══██╗██╔══██╗██╔══██╗████╗ ████║██╔══██╗╚══██╔══╝██║ ██║\n██████╔╝██████╔╝██████╔╝██╔████╔██║███████║ ██║ ███████║\n██╔═══╝ ██╔══██╗██╔══██╗██║╚██╔╝██║██╔══██║ ██║ ██╔══██║\n██║ ██║ ██║██████╔╝██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║\n╚═╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝\n\n██╗ ██╗██████╗ ██████╗ ██╗ ██╗ ██╗ █████╗\n██║ ██║██╔══██╗╚════██╗╚██╗██╔╝███║██╔══██╗\n██║ ██║██║ ██║ █████╔╝ ╚███╔╝ ╚██║╚█████╔╝\n██║ ██║██║ ██║██╔═══╝ ██╔██╗ ██║██╔══██╗\n╚██████╔╝██████╔╝███████╗██╔╝ ██╗ ██║╚█████╔╝\n ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚════╝\n\n*/\n\nimport \"./ud2x18/Casting.sol\";\nimport \"./ud2x18/Constants.sol\";\nimport \"./ud2x18/Errors.sol\";\nimport \"./ud2x18/ValueType.sol\";\n"
},
"node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\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[EIP 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"
},
"node_modules/@openzeppelin/contracts/utils/math/Math.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Down, // Toward negative infinity\n Up, // Toward infinity\n Zero // Toward zero\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 up instead\n * of rounding down.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b - 1) / b can overflow on addition, so we distribute.\n return a == 0 ? 0 : (a - 1) / b + 1;\n }\n\n /**\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\n * with further edits by 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^256 and mod 2^256 - 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^256 + prod0.\n uint256 prod0; // 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 prod0 := mul(x, y)\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^256. Also prevents denominator == 0.\n require(denominator > prod1, \"Math: mulDiv overflow\");\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. Always >= 1.\n // See https://cs.stackexchange.com/q/138556/92363.\n\n // Does not overflow because the denominator cannot be zero at this stage in the function.\n uint256 twos = denominator & (~denominator + 1);\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^256 / 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^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv = 1 mod 2^4.\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 works\n // in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\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^256. Since the preconditions guarantee that the outcome is\n // less than 2^256, 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 * @notice 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 uint256 result = mulDiv(x, y, denominator);\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\n result += 1;\n }\n return result;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n *\n * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n if (a == 0) {\n return 0;\n }\n\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n //\n // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n //\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n //\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n uint256 result = 1 << (log2(a) >> 1);\n\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n // into the expected uint128 result.\n unchecked {\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n return min(result, a / result);\n }\n }\n\n /**\n * @notice 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 + (rounding == Rounding.Up && result * result < a ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 2, rounded down, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 128;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 64;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 32;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 16;\n }\n if (value >> 8 > 0) {\n value >>= 8;\n result += 8;\n }\n if (value >> 4 > 0) {\n value >>= 4;\n result += 4;\n }\n if (value >> 2 > 0) {\n value >>= 2;\n result += 2;\n }\n if (value >> 1 > 0) {\n result += 1;\n }\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 + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 10, rounded down, of a positive value.\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 + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 256, rounded down, of a positive value.\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 unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 16;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 8;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 4;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 2;\n }\n if (value >> 8 > 0) {\n result += 1;\n }\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 + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);\n }\n }\n}\n"
},
"node_modules/@openzeppelin/contracts/utils/math/SignedMath.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)\n\npragma solidity ^0.8.0;\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 // must be unchecked in order to support `n = type(int256).min`\n return uint256(n >= 0 ? n : -n);\n }\n }\n}\n"
},
"node_modules/@prb/math/src/Common.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\n// Common.sol\n//\n// Common mathematical functions needed by both SD59x18 and UD60x18. Note that these global functions do not\n// always operate with SD59x18 and UD60x18 numbers.\n\n/*//////////////////////////////////////////////////////////////////////////\n CUSTOM ERRORS\n//////////////////////////////////////////////////////////////////////////*/\n\n/// @notice Thrown when the resultant value in {mulDiv} overflows uint256.\nerror PRBMath_MulDiv_Overflow(uint256 x, uint256 y, uint256 denominator);\n\n/// @notice Thrown when the resultant value in {mulDiv18} overflows uint256.\nerror PRBMath_MulDiv18_Overflow(uint256 x, uint256 y);\n\n/// @notice Thrown when one of the inputs passed to {mulDivSigned} is `type(int256).min`.\nerror PRBMath_MulDivSigned_InputTooSmall();\n\n/// @notice Thrown when the resultant value in {mulDivSigned} overflows int256.\nerror PRBMath_MulDivSigned_Overflow(int256 x, int256 y);\n\n/*//////////////////////////////////////////////////////////////////////////\n CONSTANTS\n//////////////////////////////////////////////////////////////////////////*/\n\n/// @dev The maximum value a uint128 number can have.\nuint128 constant MAX_UINT128 = type(uint128).max;\n\n/// @dev The maximum value a uint40 number can have.\nuint40 constant MAX_UINT40 = type(uint40).max;\n\n/// @dev The unit number, which the decimal precision of the fixed-point types.\nuint256 constant UNIT = 1e18;\n\n/// @dev The unit number inverted mod 2^256.\nuint256 constant UNIT_INVERSE = 78156646155174841979727994598816262306175212592076161876661_508869554232690281;\n\n/// @dev The the largest power of two that divides the decimal value of `UNIT`. The logarithm of this value is the least significant\n/// bit in the binary representation of `UNIT`.\nuint256 constant UNIT_LPOTD = 262144;\n\n/*//////////////////////////////////////////////////////////////////////////\n FUNCTIONS\n//////////////////////////////////////////////////////////////////////////*/\n\n/// @notice Calculates the binary exponent of x using the binary fraction method.\n/// @dev Has to use 192.64-bit fixed-point numbers. See https://ethereum.stackexchange.com/a/96594/24693.\n/// @param x The exponent as an unsigned 192.64-bit fixed-point number.\n/// @return result The result as an unsigned 60.18-decimal fixed-point number.\n/// @custom:smtchecker abstract-function-nondet\nfunction exp2(uint256 x) pure returns (uint256 result) {\n unchecked {\n // Start from 0.5 in the 192.64-bit fixed-point format.\n result = 0x800000000000000000000000000000000000000000000000;\n\n // The following logic multiplies the result by $\\sqrt{2^{-i}}$ when the bit at position i is 1. Key points:\n //\n // 1. Intermediate results will not overflow, as the starting point is 2^191 and all magic factors are under 2^65.\n // 2. The rationale for organizing the if statements into groups of 8 is gas savings. If the result of performing\n // a bitwise AND operation between x and any value in the array [0x80; 0x40; 0x20; 0x10; 0x08; 0x04; 0x02; 0x01] is 1,\n // we know that `x & 0xFF` is also 1.\n if (x & 0xFF00000000000000 > 0) {\n if (x & 0x8000000000000000 > 0) {\n result = (result * 0x16A09E667F3BCC909) >> 64;\n }\n if (x & 0x4000000000000000 > 0) {\n result = (result * 0x1306FE0A31B7152DF) >> 64;\n }\n if (x & 0x2000000000000000 > 0) {\n result = (result * 0x1172B83C7D517ADCE) >> 64;\n }\n if (x & 0x1000000000000000 > 0) {\n result = (result * 0x10B5586CF9890F62A) >> 64;\n }\n if (x & 0x800000000000000 > 0) {\n result = (result * 0x1059B0D31585743AE) >> 64;\n }\n if (x & 0x400000000000000 > 0) {\n result = (result * 0x102C9A3E778060EE7) >> 64;\n }\n if (x & 0x200000000000000 > 0) {\n result = (result * 0x10163DA9FB33356D8) >> 64;\n }\n if (x & 0x100000000000000 > 0) {\n result = (result * 0x100B1AFA5ABCBED61) >> 64;\n }\n }\n\n if (x & 0xFF000000000000 > 0) {\n if (x & 0x80000000000000 > 0) {\n result = (result * 0x10058C86DA1C09EA2) >> 64;\n }\n if (x & 0x40000000000000 > 0) {\n result = (result * 0x1002C605E2E8CEC50) >> 64;\n }\n if (x & 0x20000000000000 > 0) {\n result = (result * 0x100162F3904051FA1) >> 64;\n }\n if (x & 0x10000000000000 > 0) {\n result = (result * 0x1000B175EFFDC76BA) >> 64;\n }\n if (x & 0x8000000000000 > 0) {\n result = (result * 0x100058BA01FB9F96D) >> 64;\n }\n if (x & 0x4000000000000 > 0) {\n result = (result * 0x10002C5CC37DA9492) >> 64;\n }\n if (x & 0x2000000000000 > 0) {\n result = (result * 0x1000162E525EE0547) >> 64;\n }\n if (x & 0x1000000000000 > 0) {\n result = (result * 0x10000B17255775C04) >> 64;\n }\n }\n\n if (x & 0xFF0000000000 > 0) {\n if (x & 0x800000000000 > 0) {\n result = (result * 0x1000058B91B5BC9AE) >> 64;\n }\n if (x & 0x400000000000 > 0) {\n result = (result * 0x100002C5C89D5EC6D) >> 64;\n }\n if (x & 0x200000000000 > 0) {\n result = (result * 0x10000162E43F4F831) >> 64;\n }\n if (x & 0x100000000000 > 0) {\n result = (result * 0x100000B1721BCFC9A) >> 64;\n }\n if (x & 0x80000000000 > 0) {\n result = (result * 0x10000058B90CF1E6E) >> 64;\n }\n if (x & 0x40000000000 > 0) {\n result = (result * 0x1000002C5C863B73F) >> 64;\n }\n if (x & 0x20000000000 > 0) {\n result = (result * 0x100000162E430E5A2) >> 64;\n }\n if (x & 0x10000000000 > 0) {\n result = (result * 0x1000000B172183551) >> 64;\n }\n }\n\n if (x & 0xFF00000000 > 0) {\n if (x & 0x8000000000 > 0) {\n result = (result * 0x100000058B90C0B49) >> 64;\n }\n if (x & 0x4000000000 > 0) {\n result = (result * 0x10000002C5C8601CC) >> 64;\n }\n if (x & 0x2000000000 > 0) {\n result = (result * 0x1000000162E42FFF0) >> 64;\n }\n if (x & 0x1000000000 > 0) {\n result = (result * 0x10000000B17217FBB) >> 64;\n }\n if (x & 0x800000000 > 0) {\n result = (result * 0x1000000058B90BFCE) >> 64;\n }\n if (x & 0x400000000 > 0) {\n result = (result * 0x100000002C5C85FE3) >> 64;\n }\n if (x & 0x200000000 > 0) {\n result = (result * 0x10000000162E42FF1) >> 64;\n }\n if (x & 0x100000000 > 0) {\n result = (result * 0x100000000B17217F8) >> 64;\n }\n }\n\n if (x & 0xFF000000 > 0) {\n if (x & 0x80000000 > 0) {\n result = (result * 0x10000000058B90BFC) >> 64;\n }\n if (x & 0x40000000 > 0) {\n result = (result * 0x1000000002C5C85FE) >> 64;\n }\n if (x & 0x20000000 > 0) {\n result = (result * 0x100000000162E42FF) >> 64;\n }\n if (x & 0x10000000 > 0) {\n result = (result * 0x1000000000B17217F) >> 64;\n }\n if (x & 0x8000000 > 0) {\n result = (result * 0x100000000058B90C0) >> 64;\n }\n if (x & 0x4000000 > 0) {\n result = (result * 0x10000000002C5C860) >> 64;\n }\n if (x & 0x2000000 > 0) {\n result = (result * 0x1000000000162E430) >> 64;\n }\n if (x & 0x1000000 > 0) {\n result = (result * 0x10000000000B17218) >> 64;\n }\n }\n\n if (x & 0xFF0000 > 0) {\n if (x & 0x800000 > 0) {\n result = (result * 0x1000000000058B90C) >> 64;\n }\n if (x & 0x400000 > 0) {\n result = (result * 0x100000000002C5C86) >> 64;\n }\n if (x & 0x200000 > 0) {\n result = (result * 0x10000000000162E43) >> 64;\n }\n if (x & 0x100000 > 0) {\n result = (result * 0x100000000000B1721) >> 64;\n }\n if (x & 0x80000 > 0) {\n result = (result * 0x10000000000058B91) >> 64;\n }\n if (x & 0x40000 > 0) {\n result = (result * 0x1000000000002C5C8) >> 64;\n }\n if (x & 0x20000 > 0) {\n result = (result * 0x100000000000162E4) >> 64;\n }\n if (x & 0x10000 > 0) {\n result = (result * 0x1000000000000B172) >> 64;\n }\n }\n\n if (x & 0xFF00 > 0) {\n if (x & 0x8000 > 0) {\n result = (result * 0x100000000000058B9) >> 64;\n }\n if (x & 0x4000 > 0) {\n result = (result * 0x10000000000002C5D) >> 64;\n }\n if (x & 0x2000 > 0) {\n result = (result * 0x1000000000000162E) >> 64;\n }\n if (x & 0x1000 > 0) {\n result = (result * 0x10000000000000B17) >> 64;\n }\n if (x & 0x800 > 0) {\n result = (result * 0x1000000000000058C) >> 64;\n }\n if (x & 0x400 > 0) {\n result = (result * 0x100000000000002C6) >> 64;\n }\n if (x & 0x200 > 0) {\n result = (result * 0x10000000000000163) >> 64;\n }\n if (x & 0x100 > 0) {\n result = (result * 0x100000000000000B1) >> 64;\n }\n }\n\n if (x & 0xFF > 0) {\n if (x & 0x80 > 0) {\n result = (result * 0x10000000000000059) >> 64;\n }\n if (x & 0x40 > 0) {\n result = (result * 0x1000000000000002C) >> 64;\n }\n if (x & 0x20 > 0) {\n result = (result * 0x10000000000000016) >> 64;\n }\n if (x & 0x10 > 0) {\n result = (result * 0x1000000000000000B) >> 64;\n }\n if (x & 0x8 > 0) {\n result = (result * 0x10000000000000006) >> 64;\n }\n if (x & 0x4 > 0) {\n result = (result * 0x10000000000000003) >> 64;\n }\n if (x & 0x2 > 0) {\n result = (result * 0x10000000000000001) >> 64;\n }\n if (x & 0x1 > 0) {\n result = (result * 0x10000000000000001) >> 64;\n }\n }\n\n // In the code snippet below, two operations are executed simultaneously:\n //\n // 1. The result is multiplied by $(2^n + 1)$, where $2^n$ represents the integer part, and the additional 1\n // accounts for the initial guess of 0.5. This is achieved by subtracting from 191 instead of 192.\n // 2. The result is then converted to an unsigned 60.18-decimal fixed-point format.\n //\n // The underlying logic is based on the relationship $2^{191-ip} = 2^{ip} / 2^{191}$, where $ip$ denotes the,\n // integer part, $2^n$.\n result *= UNIT;\n result >>= (191 - (x >> 64));\n }\n}\n\n/// @notice Finds the zero-based index of the first 1 in the binary representation of x.\n///\n/// @dev See the note on \"msb\" in this Wikipedia article: https://en.wikipedia.org/wiki/Find_first_set\n///\n/// Each step in this implementation is equivalent to this high-level code:\n///\n/// ```solidity\n/// if (x >= 2 ** 128) {\n/// x >>= 128;\n/// result += 128;\n/// }\n/// ```\n///\n/// Where 128 is replaced with each respective power of two factor. See the full high-level implementation here:\n/// https://gist.github.com/PaulRBerg/f932f8693f2733e30c4d479e8e980948\n///\n/// The Yul instructions used below are:\n///\n/// - \"gt\" is \"greater than\"\n/// - \"or\" is the OR bitwise operator\n/// - \"shl\" is \"shift left\"\n/// - \"shr\" is \"shift right\"\n///\n/// @param x The uint256 number for which to find the index of the most significant bit.\n/// @return result The index of the most significant bit as a uint256.\n/// @custom:smtchecker abstract-function-nondet\nfunction msb(uint256 x) pure returns (uint256 result) {\n // 2^128\n assembly (\"memory-safe\") {\n let factor := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n x := shr(factor, x)\n result := or(result, factor)\n }\n // 2^64\n assembly (\"memory-safe\") {\n let factor := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))\n x := shr(factor, x)\n result := or(result, factor)\n }\n // 2^32\n assembly (\"memory-safe\") {\n let factor := shl(5, gt(x, 0xFFFFFFFF))\n x := shr(factor, x)\n result := or(result, factor)\n }\n // 2^16\n assembly (\"memory-safe\") {\n let factor := shl(4, gt(x, 0xFFFF))\n x := shr(factor, x)\n result := or(result, factor)\n }\n // 2^8\n assembly (\"memory-safe\") {\n let factor := shl(3, gt(x, 0xFF))\n x := shr(factor, x)\n result := or(result, factor)\n }\n // 2^4\n assembly (\"memory-safe\") {\n let factor := shl(2, gt(x, 0xF))\n x := shr(factor, x)\n result := or(result, factor)\n }\n // 2^2\n assembly (\"memory-safe\") {\n let factor := shl(1, gt(x, 0x3))\n x := shr(factor, x)\n result := or(result, factor)\n }\n // 2^1\n // No need to shift x any more.\n assembly (\"memory-safe\") {\n let factor := gt(x, 0x1)\n result := or(result, factor)\n }\n}\n\n/// @notice Calculates x*y÷denominator with 512-bit precision.\n///\n/// @dev Credits to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv.\n///\n/// Notes:\n/// - The result is rounded toward zero.\n///\n/// Requirements:\n/// - The denominator must not be zero.\n/// - The result must fit in uint256.\n///\n/// @param x The multiplicand as a uint256.\n/// @param y The multiplier as a uint256.\n/// @param denominator The divisor as a uint256.\n/// @return result The result as a uint256.\n/// @custom:smtchecker abstract-function-nondet\nfunction mulDiv(uint256 x, uint256 y, uint256 denominator) pure returns (uint256 result) {\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 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^256 + prod0.\n uint256 prod0; // Least significant 256 bits of the product\n uint256 prod1; // Most significant 256 bits of the product\n assembly (\"memory-safe\") {\n let mm := mulmod(x, y, not(0))\n prod0 := mul(x, y)\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 unchecked {\n return prod0 / denominator;\n }\n }\n\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\n if (prod1 >= denominator) {\n revert PRBMath_MulDiv_Overflow(x, y, denominator);\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 (\"memory-safe\") {\n // Compute remainder using the mulmod Yul instruction.\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 unchecked {\n // Calculate the largest power of two divisor of the denominator using the unary operator ~. This operation cannot overflow\n // because the denominator cannot be zero at this point in the function execution. The result is always >= 1.\n // For more detail, see https://cs.stackexchange.com/q/138556/92363.\n uint256 lpotdod = denominator & (~denominator + 1);\n uint256 flippedLpotdod;\n\n assembly (\"memory-safe\") {\n // Factor powers of two out of denominator.\n denominator := div(denominator, lpotdod)\n\n // Divide [prod1 prod0] by lpotdod.\n prod0 := div(prod0, lpotdod)\n\n // Get the flipped value `2^256 / lpotdod`. If the `lpotdod` is zero, the flipped value is one.\n // `sub(0, lpotdod)` produces the two's complement version of `lpotdod`, which is equivalent to flipping all the bits.\n // However, `div` interprets this value as an unsigned value: https://ethereum.stackexchange.com/q/147168/24693\n flippedLpotdod := add(div(sub(0, lpotdod), lpotdod), 1)\n }\n\n // Shift in bits from prod1 into prod0.\n prod0 |= prod1 * flippedLpotdod;\n\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv = 1 mod 2^4.\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 works\n // in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\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^256. Since the preconditions guarantee that the outcome is\n // less than 2^256, 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 }\n}\n\n/// @notice Calculates x*y÷1e18 with 512-bit precision.\n///\n/// @dev A variant of {mulDiv} with constant folding, i.e. in which the denominator is hard coded to 1e18.\n///\n/// Notes:\n/// - The body is purposely left uncommented; to understand how this works, see the documentation in {mulDiv}.\n/// - The result is rounded toward zero.\n/// - We take as an axiom that the result cannot be `MAX_UINT256` when x and y solve the following system of equations:\n///\n/// $$\n/// \\begin{cases}\n/// x * y = MAX\\_UINT256 * UNIT \\\\\n/// (x * y) \\% UNIT \\geq \\frac{UNIT}{2}\n/// \\end{cases}\n/// $$\n///\n/// Requirements:\n/// - Refer to the requirements in {mulDiv}.\n/// - The result must fit in uint256.\n///\n/// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.\n/// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.\n/// @return result The result as an unsigned 60.18-decimal fixed-point number.\n/// @custom:smtchecker abstract-function-nondet\nfunction mulDiv18(uint256 x, uint256 y) pure returns (uint256 result) {\n uint256 prod0;\n uint256 prod1;\n assembly (\"memory-safe\") {\n let mm := mulmod(x, y, not(0))\n prod0 := mul(x, y)\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n }\n\n if (prod1 == 0) {\n unchecked {\n return prod0 / UNIT;\n }\n }\n\n if (prod1 >= UNIT) {\n revert PRBMath_MulDiv18_Overflow(x, y);\n }\n\n uint256 remainder;\n assembly (\"memory-safe\") {\n remainder := mulmod(x, y, UNIT)\n result :=\n mul(\n or(\n div(sub(prod0, remainder), UNIT_LPOTD),\n mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, UNIT_LPOTD), UNIT_LPOTD), 1))\n ),\n UNIT_INVERSE\n )\n }\n}\n\n/// @notice Calculates x*y÷denominator with 512-bit precision.\n///\n/// @dev This is an extension of {mulDiv} for signed numbers, which works by computing the signs and the absolute values separately.\n///\n/// Notes:\n/// - The result is rounded toward zero.\n///\n/// Requirements:\n/// - Refer to the requirements in {mulDiv}.\n/// - None of the inputs can be `type(int256).min`.\n/// - The result must fit in int256.\n///\n/// @param x The multiplicand as an int256.\n/// @param y The multiplier as an int256.\n/// @param denominator The divisor as an int256.\n/// @return result The result as an int256.\n/// @custom:smtchecker abstract-function-nondet\nfunction mulDivSigned(int256 x, int256 y, int256 denominator) pure returns (int256 result) {\n if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) {\n revert PRBMath_MulDivSigned_InputTooSmall();\n }\n\n // Get hold of the absolute values of x, y and the denominator.\n uint256 xAbs;\n uint256 yAbs;\n uint256 dAbs;\n unchecked {\n xAbs = x < 0 ? uint256(-x) : uint256(x);\n yAbs = y < 0 ? uint256(-y) : uint256(y);\n dAbs = denominator < 0 ? uint256(-denominator) : uint256(denominator);\n }\n\n // Compute the absolute value of x*y÷denominator. The result must fit in int256.\n uint256 resultAbs = mulDiv(xAbs, yAbs, dAbs);\n if (resultAbs > uint256(type(int256).max)) {\n revert PRBMath_MulDivSigned_Overflow(x, y);\n }\n\n // Get the signs of x, y and the denominator.\n uint256 sx;\n uint256 sy;\n uint256 sd;\n assembly (\"memory-safe\") {\n // \"sgt\" is the \"signed greater than\" assembly instruction and \"sub(0,1)\" is -1 in two's complement.\n sx := sgt(x, sub(0, 1))\n sy := sgt(y, sub(0, 1))\n sd := sgt(denominator, sub(0, 1))\n }\n\n // XOR over sx, sy and sd. What this does is to check whether there are 1 or 3 negative signs in the inputs.\n // If there are, the result should be negative. Otherwise, it should be positive.\n unchecked {\n result = sx ^ sy ^ sd == 0 ? -int256(resultAbs) : int256(resultAbs);\n }\n}\n\n/// @notice Calculates the square root of x using the Babylonian method.\n///\n/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.\n///\n/// Notes:\n/// - If x is not a perfect square, the result is rounded down.\n/// - Credits to OpenZeppelin for the explanations in comments below.\n///\n/// @param x The uint256 number for which to calculate the square root.\n/// @return result The result as a uint256.\n/// @custom:smtchecker abstract-function-nondet\nfunction sqrt(uint256 x) pure returns (uint256 result) {\n if (x == 0) {\n return 0;\n }\n\n // For our first guess, we calculate the biggest power of 2 which is smaller than the square root of x.\n //\n // We know that the \"msb\" (most significant bit) of x is a power of 2 such that we have:\n //\n // $$\n // msb(x) <= x <= 2*msb(x)$\n // $$\n //\n // We write $msb(x)$ as $2^k$, and we get:\n //\n // $$\n // k = log_2(x)\n // $$\n //\n // Thus, we can write the initial inequality as:\n //\n // $$\n // 2^{log_2(x)} <= x <= 2*2^{log_2(x)+1} \\\\\n // sqrt(2^k) <= sqrt(x) < sqrt(2^{k+1}) \\\\\n // 2^{k/2} <= sqrt(x) < 2^{(k+1)/2} <= 2^{(k/2)+1}\n // $$\n //\n // Consequently, $2^{log_2(x) /2} is a good first approximation of sqrt(x) with at least one correct bit.\n uint256 xAux = uint256(x);\n result = 1;\n if (xAux >= 2 ** 128) {\n xAux >>= 128;\n result <<= 64;\n }\n if (xAux >= 2 ** 64) {\n xAux >>= 64;\n result <<= 32;\n }\n if (xAux >= 2 ** 32) {\n xAux >>= 32;\n result <<= 16;\n }\n if (xAux >= 2 ** 16) {\n xAux >>= 16;\n result <<= 8;\n }\n if (xAux >= 2 ** 8) {\n xAux >>= 8;\n result <<= 4;\n }\n if (xAux >= 2 ** 4) {\n xAux >>= 4;\n result <<= 2;\n }\n if (xAux >= 2 ** 2) {\n result <<= 1;\n }\n\n // At this point, `result` is an estimation with at least one bit of precision. We know the true value has at\n // most 128 bits, since it is the square root of a uint256. Newton's method converges quadratically (precision\n // doubles at every iteration). We thus need at most 7 iteration to turn our partial result with one bit of\n // precision into the expected uint128 result.\n unchecked {\n result = (result + x / result) >> 1;\n result = (result + x / result) >> 1;\n result = (result + x / result) >> 1;\n result = (result + x / result) >> 1;\n result = (result + x / result) >> 1;\n result = (result + x / result) >> 1;\n result = (result + x / result) >> 1;\n\n // If x is not a perfect square, round the result toward zero.\n uint256 roundedResult = x / result;\n if (result >= roundedResult) {\n result = roundedResult;\n }\n }\n}\n"
},
"node_modules/@prb/math/src/sd1x18/Constants.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport { SD1x18 } from \"./ValueType.sol\";\n\n/// @dev Euler's number as an SD1x18 number.\nSD1x18 constant E = SD1x18.wrap(2_718281828459045235);\n\n/// @dev The maximum value an SD1x18 number can have.\nint64 constant uMAX_SD1x18 = 9_223372036854775807;\nSD1x18 constant MAX_SD1x18 = SD1x18.wrap(uMAX_SD1x18);\n\n/// @dev The maximum value an SD1x18 number can have.\nint64 constant uMIN_SD1x18 = -9_223372036854775808;\nSD1x18 constant MIN_SD1x18 = SD1x18.wrap(uMIN_SD1x18);\n\n/// @dev PI as an SD1x18 number.\nSD1x18 constant PI = SD1x18.wrap(3_141592653589793238);\n\n/// @dev The unit number, which gives the decimal precision of SD1x18.\nSD1x18 constant UNIT = SD1x18.wrap(1e18);\nint256 constant uUNIT = 1e18;\n"
},
"node_modules/@prb/math/src/sd1x18/ValueType.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport \"./Casting.sol\" as Casting;\n\n/// @notice The signed 1.18-decimal fixed-point number representation, which can have up to 1 digit and up to 18\n/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity\n/// type int64. This is useful when end users want to use int64 to save gas, e.g. with tight variable packing in contract\n/// storage.\ntype SD1x18 is int64;\n\n/*//////////////////////////////////////////////////////////////////////////\n CASTING\n//////////////////////////////////////////////////////////////////////////*/\n\nusing {\n Casting.intoSD59x18,\n Casting.intoUD2x18,\n Casting.intoUD60x18,\n Casting.intoUint256,\n Casting.intoUint128,\n Casting.intoUint40,\n Casting.unwrap\n} for SD1x18 global;\n"
},
"node_modules/@prb/math/src/sd59x18/Constants.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport { SD59x18 } from \"./ValueType.sol\";\n\n// NOTICE: the \"u\" prefix stands for \"unwrapped\".\n\n/// @dev Euler's number as an SD59x18 number.\nSD59x18 constant E = SD59x18.wrap(2_718281828459045235);\n\n/// @dev The maximum input permitted in {exp}.\nint256 constant uEXP_MAX_INPUT = 133_084258667509499440;\nSD59x18 constant EXP_MAX_INPUT = SD59x18.wrap(uEXP_MAX_INPUT);\n\n/// @dev The maximum input permitted in {exp2}.\nint256 constant uEXP2_MAX_INPUT = 192e18 - 1;\nSD59x18 constant EXP2_MAX_INPUT = SD59x18.wrap(uEXP2_MAX_INPUT);\n\n/// @dev Half the UNIT number.\nint256 constant uHALF_UNIT = 0.5e18;\nSD59x18 constant HALF_UNIT = SD59x18.wrap(uHALF_UNIT);\n\n/// @dev $log_2(10)$ as an SD59x18 number.\nint256 constant uLOG2_10 = 3_321928094887362347;\nSD59x18 constant LOG2_10 = SD59x18.wrap(uLOG2_10);\n\n/// @dev $log_2(e)$ as an SD59x18 number.\nint256 constant uLOG2_E = 1_442695040888963407;\nSD59x18 constant LOG2_E = SD59x18.wrap(uLOG2_E);\n\n/// @dev The maximum value an SD59x18 number can have.\nint256 constant uMAX_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_792003956564819967;\nSD59x18 constant MAX_SD59x18 = SD59x18.wrap(uMAX_SD59x18);\n\n/// @dev The maximum whole value an SD59x18 number can have.\nint256 constant uMAX_WHOLE_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_000000000000000000;\nSD59x18 constant MAX_WHOLE_SD59x18 = SD59x18.wrap(uMAX_WHOLE_SD59x18);\n\n/// @dev The minimum value an SD59x18 number can have.\nint256 constant uMIN_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_792003956564819968;\nSD59x18 constant MIN_SD59x18 = SD59x18.wrap(uMIN_SD59x18);\n\n/// @dev The minimum whole value an SD59x18 number can have.\nint256 constant uMIN_WHOLE_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_000000000000000000;\nSD59x18 constant MIN_WHOLE_SD59x18 = SD59x18.wrap(uMIN_WHOLE_SD59x18);\n\n/// @dev PI as an SD59x18 number.\nSD59x18 constant PI = SD59x18.wrap(3_141592653589793238);\n\n/// @dev The unit number, which gives the decimal precision of SD59x18.\nint256 constant uUNIT = 1e18;\nSD59x18 constant UNIT = SD59x18.wrap(1e18);\n\n/// @dev The unit number squared.\nint256 constant uUNIT_SQUARED = 1e36;\nSD59x18 constant UNIT_SQUARED = SD59x18.wrap(uUNIT_SQUARED);\n\n/// @dev Zero as an SD59x18 number.\nSD59x18 constant ZERO = SD59x18.wrap(0);\n"
},
"node_modules/@prb/math/src/sd59x18/ValueType.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport \"./Casting.sol\" as Casting;\nimport \"./Helpers.sol\" as Helpers;\nimport \"./Math.sol\" as Math;\n\n/// @notice The signed 59.18-decimal fixed-point number representation, which can have up to 59 digits and up to 18\n/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity\n/// type int256.\ntype SD59x18 is int256;\n\n/*//////////////////////////////////////////////////////////////////////////\n CASTING\n//////////////////////////////////////////////////////////////////////////*/\n\nusing {\n Casting.intoInt256,\n Casting.intoSD1x18,\n Casting.intoUD2x18,\n Casting.intoUD60x18,\n Casting.intoUint256,\n Casting.intoUint128,\n Casting.intoUint40,\n Casting.unwrap\n} for SD59x18 global;\n\n/*//////////////////////////////////////////////////////////////////////////\n MATHEMATICAL FUNCTIONS\n//////////////////////////////////////////////////////////////////////////*/\n\nusing {\n Math.abs,\n Math.avg,\n Math.ceil,\n Math.div,\n Math.exp,\n Math.exp2,\n Math.floor,\n Math.frac,\n Math.gm,\n Math.inv,\n Math.log10,\n Math.log2,\n Math.ln,\n Math.mul,\n Math.pow,\n Math.powu,\n Math.sqrt\n} for SD59x18 global;\n\n/*//////////////////////////////////////////////////////////////////////////\n HELPER FUNCTIONS\n//////////////////////////////////////////////////////////////////////////*/\n\nusing {\n Helpers.add,\n Helpers.and,\n Helpers.eq,\n Helpers.gt,\n Helpers.gte,\n Helpers.isZero,\n Helpers.lshift,\n Helpers.lt,\n Helpers.lte,\n Helpers.mod,\n Helpers.neq,\n Helpers.not,\n Helpers.or,\n Helpers.rshift,\n Helpers.sub,\n Helpers.uncheckedAdd,\n Helpers.uncheckedSub,\n Helpers.uncheckedUnary,\n Helpers.xor\n} for SD59x18 global;\n\n/*//////////////////////////////////////////////////////////////////////////\n OPERATORS\n//////////////////////////////////////////////////////////////////////////*/\n\n// The global \"using for\" directive makes it possible to use these operators on the SD59x18 type.\nusing {\n Helpers.add as +,\n Helpers.and2 as &,\n Math.div as /,\n Helpers.eq as ==,\n Helpers.gt as >,\n Helpers.gte as >=,\n Helpers.lt as <,\n Helpers.lte as <=,\n Helpers.mod as %,\n Math.mul as *,\n Helpers.neq as !=,\n Helpers.not as ~,\n Helpers.or as |,\n Helpers.sub as -,\n Helpers.unary as -,\n Helpers.xor as ^\n} for SD59x18 global;\n"
},
"node_modules/@prb/math/src/ud2x18/Constants.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport { UD2x18 } from \"./ValueType.sol\";\n\n/// @dev Euler's number as a UD2x18 number.\nUD2x18 constant E = UD2x18.wrap(2_718281828459045235);\n\n/// @dev The maximum value a UD2x18 number can have.\nuint64 constant uMAX_UD2x18 = 18_446744073709551615;\nUD2x18 constant MAX_UD2x18 = UD2x18.wrap(uMAX_UD2x18);\n\n/// @dev PI as a UD2x18 number.\nUD2x18 constant PI = UD2x18.wrap(3_141592653589793238);\n\n/// @dev The unit number, which gives the decimal precision of UD2x18.\nuint256 constant uUNIT = 1e18;\nUD2x18 constant UNIT = UD2x18.wrap(1e18);\n"
},
"node_modules/@prb/math/src/ud2x18/ValueType.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport \"./Casting.sol\" as Casting;\n\n/// @notice The unsigned 2.18-decimal fixed-point number representation, which can have up to 2 digits and up to 18\n/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity\n/// type uint64. This is useful when end users want to use uint64 to save gas, e.g. with tight variable packing in contract\n/// storage.\ntype UD2x18 is uint64;\n\n/*//////////////////////////////////////////////////////////////////////////\n CASTING\n//////////////////////////////////////////////////////////////////////////*/\n\nusing {\n Casting.intoSD1x18,\n Casting.intoSD59x18,\n Casting.intoUD60x18,\n Casting.intoUint256,\n Casting.intoUint128,\n Casting.intoUint40,\n Casting.unwrap\n} for UD2x18 global;\n"
},
"node_modules/@openzeppelin/contracts/interfaces/IERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (interfaces/IERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/introspection/IERC165.sol\";\n"
},
"node_modules/@openzeppelin/contracts/interfaces/IERC721.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (interfaces/IERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../token/ERC721/IERC721.sol\";\n"
},
"src/abstracts/Adminable.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity >=0.8.19;\n\nimport { IAdminable } from \"../interfaces/IAdminable.sol\";\nimport { Errors } from \"../libraries/Errors.sol\";\n\n/// @title Adminable\n/// @notice See the documentation in {IAdminable}.\nabstract contract Adminable is IAdminable {\n /*//////////////////////////////////////////////////////////////////////////\n STORAGE\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @inheritdoc IAdminable\n address public override admin;\n\n /*//////////////////////////////////////////////////////////////////////////\n MODIFIERS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @notice Reverts if called by any account other than the admin.\n modifier onlyAdmin() {\n if (admin != msg.sender) {\n revert Errors.CallerNotAdmin({ admin: admin, caller: msg.sender });\n }\n _;\n }\n\n /*//////////////////////////////////////////////////////////////////////////\n USER-FACING NON-CONSTANT FUNCTIONS\n //////////////////////////////////////////////////////////////////////////*/\n\n /// @inheritdoc IAdminable\n function transferAdmin(address newAdmin) public virtual override onlyAdmin {\n // Effects: update the admin.\n admin = newAdmin;\n\n // Log the transfer of the admin.\n emit IAdminable.TransferAdmin({ oldAdmin: msg.sender, newAdmin: newAdmin });\n }\n}\n"
},
"src/abstracts/NoDelegateCall.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity >=0.8.19;\n\nimport { Errors } from \"../libraries/Errors.sol\";\n\n/// @title NoDelegateCall\n/// @notice This contract implements logic to prevent delegate calls.\nabstract contract NoDelegateCall {\n /// @dev The address of the original contract that was deployed.\n address private immutable ORIGINAL;\n\n /// @dev Sets the original contract address.\n constructor() {\n ORIGINAL = address(this);\n }\n\n /// @notice Prevents delegate calls.\n modifier noDelegateCall() {\n _preventDelegateCall();\n _;\n }\n\n /// @dev This function checks whether the current call is a delegate call, and reverts if it is.\n ///\n /// - A private function is used instead of inlining this logic in a modifier because Solidity copies modifiers into\n /// every function that uses them. The `ORIGINAL` address would get copied in every place the modifier is used,\n /// which would increase the contract size. By using a function instead, we can avoid this duplication of code\n /// and reduce the overall size of the contract.\n function _preventDelegateCall() private view {\n if (address(this) != ORIGINAL) {\n revert Errors.DelegateCall();\n }\n }\n}\n"
},
"node_modules/@prb/math/src/ud2x18/Casting.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport \"../Common.sol\" as Common;\nimport \"./Errors.sol\" as Errors;\nimport { uMAX_SD1x18 } from \"../sd1x18/Constants.sol\";\nimport { SD1x18 } from \"../sd1x18/ValueType.sol\";\nimport { SD59x18 } from \"../sd59x18/ValueType.sol\";\nimport { UD2x18 } from \"../ud2x18/ValueType.sol\";\nimport { UD60x18 } from \"../ud60x18/ValueType.sol\";\nimport { UD2x18 } from \"./ValueType.sol\";\n\n/// @notice Casts a UD2x18 number into SD1x18.\n/// - x must be less than or equal to `uMAX_SD1x18`.\nfunction intoSD1x18(UD2x18 x) pure returns (SD1x18 result) {\n uint64 xUint = UD2x18.unwrap(x);\n if (xUint > uint64(uMAX_SD1x18)) {\n revert Errors.PRBMath_UD2x18_IntoSD1x18_Overflow(x);\n }\n result = SD1x18.wrap(int64(xUint));\n}\n\n/// @notice Casts a UD2x18 number into SD59x18.\n/// @dev There is no overflow check because the domain of UD2x18 is a subset of SD59x18.\nfunction intoSD59x18(UD2x18 x) pure returns (SD59x18 result) {\n result = SD59x18.wrap(int256(uint256(UD2x18.unwrap(x))));\n}\n\n/// @notice Casts a UD2x18 number into UD60x18.\n/// @dev There is no overflow check because the domain of UD2x18 is a subset of UD60x18.\nfunction intoUD60x18(UD2x18 x) pure returns (UD60x18 result) {\n result = UD60x18.wrap(UD2x18.unwrap(x));\n}\n\n/// @notice Casts a UD2x18 number into uint128.\n/// @dev There is no overflow check because the domain of UD2x18 is a subset of uint128.\nfunction intoUint128(UD2x18 x) pure returns (uint128 result) {\n result = uint128(UD2x18.unwrap(x));\n}\n\n/// @notice Casts a UD2x18 number into uint256.\n/// @dev There is no overflow check because the domain of UD2x18 is a subset of uint256.\nfunction intoUint256(UD2x18 x) pure returns (uint256 result) {\n result = uint256(UD2x18.unwrap(x));\n}\n\n/// @notice Casts a UD2x18 number into uint40.\n/// @dev Requirements:\n/// - x must be less than or equal to `MAX_UINT40`.\nfunction intoUint40(UD2x18 x) pure returns (uint40 result) {\n uint64 xUint = UD2x18.unwrap(x);\n if (xUint > uint64(Common.MAX_UINT40)) {\n revert Errors.PRBMath_UD2x18_IntoUint40_Overflow(x);\n }\n result = uint40(xUint);\n}\n\n/// @notice Alias for {wrap}.\nfunction ud2x18(uint64 x) pure returns (UD2x18 result) {\n result = UD2x18.wrap(x);\n}\n\n/// @notice Unwrap a UD2x18 number into uint64.\nfunction unwrap(UD2x18 x) pure returns (uint64 result) {\n result = UD2x18.unwrap(x);\n}\n\n/// @notice Wraps a uint64 number into UD2x18.\nfunction wrap(uint64 x) pure returns (UD2x18 result) {\n result = UD2x18.wrap(x);\n}\n"
},
"node_modules/@prb/math/src/ud2x18/Errors.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport { UD2x18 } from \"./ValueType.sol\";\n\n/// @notice Thrown when trying to cast a UD2x18 number that doesn't fit in SD1x18.\nerror PRBMath_UD2x18_IntoSD1x18_Overflow(UD2x18 x);\n\n/// @notice Thrown when trying to cast a UD2x18 number that doesn't fit in uint40.\nerror PRBMath_UD2x18_IntoUint40_Overflow(UD2x18 x);\n"
},
"node_modules/@prb/math/src/sd1x18/Casting.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport \"../Common.sol\" as Common;\nimport \"./Errors.sol\" as CastingErrors;\nimport { SD59x18 } from \"../sd59x18/ValueType.sol\";\nimport { UD2x18 } from \"../ud2x18/ValueType.sol\";\nimport { UD60x18 } from \"../ud60x18/ValueType.sol\";\nimport { SD1x18 } from \"./ValueType.sol\";\n\n/// @notice Casts an SD1x18 number into SD59x18.\n/// @dev There is no overflow check because the domain of SD1x18 is a subset of SD59x18.\nfunction intoSD59x18(SD1x18 x) pure returns (SD59x18 result) {\n result = SD59x18.wrap(int256(SD1x18.unwrap(x)));\n}\n\n/// @notice Casts an SD1x18 number into UD2x18.\n/// - x must be positive.\nfunction intoUD2x18(SD1x18 x) pure returns (UD2x18 result) {\n int64 xInt = SD1x18.unwrap(x);\n if (xInt < 0) {\n revert CastingErrors.PRBMath_SD1x18_ToUD2x18_Underflow(x);\n }\n result = UD2x18.wrap(uint64(xInt));\n}\n\n/// @notice Casts an SD1x18 number into UD60x18.\n/// @dev Requirements:\n/// - x must be positive.\nfunction intoUD60x18(SD1x18 x) pure returns (UD60x18 result) {\n int64 xInt = SD1x18.unwrap(x);\n if (xInt < 0) {\n revert CastingErrors.PRBMath_SD1x18_ToUD60x18_Underflow(x);\n }\n result = UD60x18.wrap(uint64(xInt));\n}\n\n/// @notice Casts an SD1x18 number into uint256.\n/// @dev Requirements:\n/// - x must be positive.\nfunction intoUint256(SD1x18 x) pure returns (uint256 result) {\n int64 xInt = SD1x18.unwrap(x);\n if (xInt < 0) {\n revert CastingErrors.PRBMath_SD1x18_ToUint256_Underflow(x);\n }\n result = uint256(uint64(xInt));\n}\n\n/// @notice Casts an SD1x18 number into uint128.\n/// @dev Requirements:\n/// - x must be positive.\nfunction intoUint128(SD1x18 x) pure returns (uint128 result) {\n int64 xInt = SD1x18.unwrap(x);\n if (xInt < 0) {\n revert CastingErrors.PRBMath_SD1x18_ToUint128_Underflow(x);\n }\n result = uint128(uint64(xInt));\n}\n\n/// @notice Casts an SD1x18 number into uint40.\n/// @dev Requirements:\n/// - x must be positive.\n/// - x must be less than or equal to `MAX_UINT40`.\nfunction intoUint40(SD1x18 x) pure returns (uint40 result) {\n int64 xInt = SD1x18.unwrap(x);\n if (xInt < 0) {\n revert CastingErrors.PRBMath_SD1x18_ToUint40_Underflow(x);\n }\n if (xInt > int64(uint64(Common.MAX_UINT40))) {\n revert CastingErrors.PRBMath_SD1x18_ToUint40_Overflow(x);\n }\n result = uint40(uint64(xInt));\n}\n\n/// @notice Alias for {wrap}.\nfunction sd1x18(int64 x) pure returns (SD1x18 result) {\n result = SD1x18.wrap(x);\n}\n\n/// @notice Unwraps an SD1x18 number into int64.\nfunction unwrap(SD1x18 x) pure returns (int64 result) {\n result = SD1x18.unwrap(x);\n}\n\n/// @notice Wraps an int64 number into SD1x18.\nfunction wrap(int64 x) pure returns (SD1x18 result) {\n result = SD1x18.wrap(x);\n}\n"
},
"node_modules/@prb/math/src/sd59x18/Casting.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport \"./Errors.sol\" as CastingErrors;\nimport { MAX_UINT128, MAX_UINT40 } from \"../Common.sol\";\nimport { uMAX_SD1x18, uMIN_SD1x18 } from \"../sd1x18/Constants.sol\";\nimport { SD1x18 } from \"../sd1x18/ValueType.sol\";\nimport { uMAX_UD2x18 } from \"../ud2x18/Constants.sol\";\nimport { UD2x18 } from \"../ud2x18/ValueType.sol\";\nimport { UD60x18 } from \"../ud60x18/ValueType.sol\";\nimport { SD59x18 } from \"./ValueType.sol\";\n\n/// @notice Casts an SD59x18 number into int256.\n/// @dev This is basically a functional alias for {unwrap}.\nfunction intoInt256(SD59x18 x) pure returns (int256 result) {\n result = SD59x18.unwrap(x);\n}\n\n/// @notice Casts an SD59x18 number into SD1x18.\n/// @dev Requirements:\n/// - x must be greater than or equal to `uMIN_SD1x18`.\n/// - x must be less than or equal to `uMAX_SD1x18`.\nfunction intoSD1x18(SD59x18 x) pure returns (SD1x18 result) {\n int256 xInt = SD59x18.unwrap(x);\n if (xInt < uMIN_SD1x18) {\n revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Underflow(x);\n }\n if (xInt > uMAX_SD1x18) {\n revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Overflow(x);\n }\n result = SD1x18.wrap(int64(xInt));\n}\n\n/// @notice Casts an SD59x18 number into UD2x18.\n/// @dev Requirements:\n/// - x must be positive.\n/// - x must be less than or equal to `uMAX_UD2x18`.\nfunction intoUD2x18(SD59x18 x) pure returns (UD2x18 result) {\n int256 xInt = SD59x18.unwrap(x);\n if (xInt < 0) {\n revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Underflow(x);\n }\n if (xInt > int256(uint256(uMAX_UD2x18))) {\n revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Overflow(x);\n }\n result = UD2x18.wrap(uint64(uint256(xInt)));\n}\n\n/// @notice Casts an SD59x18 number into UD60x18.\n/// @dev Requirements:\n/// - x must be positive.\nfunction intoUD60x18(SD59x18 x) pure returns (UD60x18 result) {\n int256 xInt = SD59x18.unwrap(x);\n if (xInt < 0) {\n revert CastingErrors.PRBMath_SD59x18_IntoUD60x18_Underflow(x);\n }\n result = UD60x18.wrap(uint256(xInt));\n}\n\n/// @notice Casts an SD59x18 number into uint256.\n/// @dev Requirements:\n/// - x must be positive.\nfunction intoUint256(SD59x18 x) pure returns (uint256 result) {\n int256 xInt = SD59x18.unwrap(x);\n if (xInt < 0) {\n revert CastingErrors.PRBMath_SD59x18_IntoUint256_Underflow(x);\n }\n result = uint256(xInt);\n}\n\n/// @notice Casts an SD59x18 number into uint128.\n/// @dev Requirements:\n/// - x must be positive.\n/// - x must be less than or equal to `uMAX_UINT128`.\nfunction intoUint128(SD59x18 x) pure returns (uint128 result) {\n int256 xInt = SD59x18.unwrap(x);\n if (xInt < 0) {\n revert CastingErrors.PRBMath_SD59x18_IntoUint128_Underflow(x);\n }\n if (xInt > int256(uint256(MAX_UINT128))) {\n revert CastingErrors.PRBMath_SD59x18_IntoUint128_Overflow(x);\n }\n result = uint128(uint256(xInt));\n}\n\n/// @notice Casts an SD59x18 number into uint40.\n/// @dev Requirements:\n/// - x must be positive.\n/// - x must be less than or equal to `MAX_UINT40`.\nfunction intoUint40(SD59x18 x) pure returns (uint40 result) {\n int256 xInt = SD59x18.unwrap(x);\n if (xInt < 0) {\n revert CastingErrors.PRBMath_SD59x18_IntoUint40_Underflow(x);\n }\n if (xInt > int256(uint256(MAX_UINT40))) {\n revert CastingErrors.PRBMath_SD59x18_IntoUint40_Overflow(x);\n }\n result = uint40(uint256(xInt));\n}\n\n/// @notice Alias for {wrap}.\nfunction sd(int256 x) pure returns (SD59x18 result) {\n result = SD59x18.wrap(x);\n}\n\n/// @notice Alias for {wrap}.\nfunction sd59x18(int256 x) pure returns (SD59x18 result) {\n result = SD59x18.wrap(x);\n}\n\n/// @notice Unwraps an SD59x18 number into int256.\nfunction unwrap(SD59x18 x) pure returns (int256 result) {\n result = SD59x18.unwrap(x);\n}\n\n/// @notice Wraps an int256 number into SD59x18.\nfunction wrap(int256 x) pure returns (SD59x18 result) {\n result = SD59x18.wrap(x);\n}\n"
},
"node_modules/@prb/math/src/sd59x18/Helpers.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport { wrap } from \"./Casting.sol\";\nimport { SD59x18 } from \"./ValueType.sol\";\n\n/// @notice Implements the checked addition operation (+) in the SD59x18 type.\nfunction add(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {\n return wrap(x.unwrap() + y.unwrap());\n}\n\n/// @notice Implements the AND (&) bitwise operation in the SD59x18 type.\nfunction and(SD59x18 x, int256 bits) pure returns (SD59x18 result) {\n return wrap(x.unwrap() & bits);\n}\n\n/// @notice Implements the AND (&) bitwise operation in the SD59x18 type.\nfunction and2(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {\n return wrap(x.unwrap() & y.unwrap());\n}\n\n/// @notice Implements the equal (=) operation in the SD59x18 type.\nfunction eq(SD59x18 x, SD59x18 y) pure returns (bool result) {\n result = x.unwrap() == y.unwrap();\n}\n\n/// @notice Implements the greater than operation (>) in the SD59x18 type.\nfunction gt(SD59x18 x, SD59x18 y) pure returns (bool result) {\n result = x.unwrap() > y.unwrap();\n}\n\n/// @notice Implements the greater than or equal to operation (>=) in the SD59x18 type.\nfunction gte(SD59x18 x, SD59x18 y) pure returns (bool result) {\n result = x.unwrap() >= y.unwrap();\n}\n\n/// @notice Implements a zero comparison check function in the SD59x18 type.\nfunction isZero(SD59x18 x) pure returns (bool result) {\n result = x.unwrap() == 0;\n}\n\n/// @notice Implements the left shift operation (<<) in the SD59x18 type.\nfunction lshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {\n result = wrap(x.unwrap() << bits);\n}\n\n/// @notice Implements the lower than operation (<) in the SD59x18 type.\nfunction lt(SD59x18 x, SD59x18 y) pure returns (bool result) {\n result = x.unwrap() < y.unwrap();\n}\n\n/// @notice Implements the lower than or equal to operation (<=) in the SD59x18 type.\nfunction lte(SD59x18 x, SD59x18 y) pure returns (bool result) {\n result = x.unwrap() <= y.unwrap();\n}\n\n/// @notice Implements the unchecked modulo operation (%) in the SD59x18 type.\nfunction mod(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {\n result = wrap(x.unwrap() % y.unwrap());\n}\n\n/// @notice Implements the not equal operation (!=) in the SD59x18 type.\nfunction neq(SD59x18 x, SD59x18 y) pure returns (bool result) {\n result = x.unwrap() != y.unwrap();\n}\n\n/// @notice Implements the NOT (~) bitwise operation in the SD59x18 type.\nfunction not(SD59x18 x) pure returns (SD59x18 result) {\n result = wrap(~x.unwrap());\n}\n\n/// @notice Implements the OR (|) bitwise operation in the SD59x18 type.\nfunction or(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {\n result = wrap(x.unwrap() | y.unwrap());\n}\n\n/// @notice Implements the right shift operation (>>) in the SD59x18 type.\nfunction rshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {\n result = wrap(x.unwrap() >> bits);\n}\n\n/// @notice Implements the checked subtraction operation (-) in the SD59x18 type.\nfunction sub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {\n result = wrap(x.unwrap() - y.unwrap());\n}\n\n/// @notice Implements the checked unary minus operation (-) in the SD59x18 type.\nfunction unary(SD59x18 x) pure returns (SD59x18 result) {\n result = wrap(-x.unwrap());\n}\n\n/// @notice Implements the unchecked addition operation (+) in the SD59x18 type.\nfunction uncheckedAdd(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {\n unchecked {\n result = wrap(x.unwrap() + y.unwrap());\n }\n}\n\n/// @notice Implements the unchecked subtraction operation (-) in the SD59x18 type.\nfunction uncheckedSub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {\n unchecked {\n result = wrap(x.unwrap() - y.unwrap());\n }\n}\n\n/// @notice Implements the unchecked unary minus operation (-) in the SD59x18 type.\nfunction uncheckedUnary(SD59x18 x) pure returns (SD59x18 result) {\n unchecked {\n result = wrap(-x.unwrap());\n }\n}\n\n/// @notice Implements the XOR (^) bitwise operation in the SD59x18 type.\nfunction xor(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {\n result = wrap(x.unwrap() ^ y.unwrap());\n}\n"
},
"node_modules/@prb/math/src/sd59x18/Math.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport \"../Common.sol\" as Common;\nimport \"./Errors.sol\" as Errors;\nimport {\n uEXP_MAX_INPUT,\n uEXP2_MAX_INPUT,\n uHALF_UNIT,\n uLOG2_10,\n uLOG2_E,\n uMAX_SD59x18,\n uMAX_WHOLE_SD59x18,\n uMIN_SD59x18,\n uMIN_WHOLE_SD59x18,\n UNIT,\n uUNIT,\n uUNIT_SQUARED,\n ZERO\n} from \"./Constants.sol\";\nimport { wrap } from \"./Helpers.sol\";\nimport { SD59x18 } from \"./ValueType.sol\";\n\n/// @notice Calculates the absolute value of x.\n///\n/// @dev Requirements:\n/// - x must be greater than `MIN_SD59x18`.\n///\n/// @param x The SD59x18 number for which to calculate the absolute value.\n/// @param result The absolute value of x as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction abs(SD59x18 x) pure returns (SD59x18 result) {\n int256 xInt = x.unwrap();\n if (xInt == uMIN_SD59x18) {\n revert Errors.PRBMath_SD59x18_Abs_MinSD59x18();\n }\n result = xInt < 0 ? wrap(-xInt) : x;\n}\n\n/// @notice Calculates the arithmetic average of x and y.\n///\n/// @dev Notes:\n/// - The result is rounded toward zero.\n///\n/// @param x The first operand as an SD59x18 number.\n/// @param y The second operand as an SD59x18 number.\n/// @return result The arithmetic average as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction avg(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {\n int256 xInt = x.unwrap();\n int256 yInt = y.unwrap();\n\n unchecked {\n // This operation is equivalent to `x / 2 + y / 2`, and it can never overflow.\n int256 sum = (xInt >> 1) + (yInt >> 1);\n\n if (sum < 0) {\n // If at least one of x and y is odd, add 1 to the result, because shifting negative numbers to the right\n // rounds toward negative infinity. The right part is equivalent to `sum + (x % 2 == 1 || y % 2 == 1)`.\n assembly (\"memory-safe\") {\n result := add(sum, and(or(xInt, yInt), 1))\n }\n } else {\n // Add 1 if both x and y are odd to account for the double 0.5 remainder truncated after shifting.\n result = wrap(sum + (xInt & yInt & 1));\n }\n }\n}\n\n/// @notice Yields the smallest whole number greater than or equal to x.\n///\n/// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.\n/// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.\n///\n/// Requirements:\n/// - x must be less than or equal to `MAX_WHOLE_SD59x18`.\n///\n/// @param x The SD59x18 number to ceil.\n/// @param result The smallest whole number greater than or equal to x, as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction ceil(SD59x18 x) pure returns (SD59x18 result) {\n int256 xInt = x.unwrap();\n if (xInt > uMAX_WHOLE_SD59x18) {\n revert Errors.PRBMath_SD59x18_Ceil_Overflow(x);\n }\n\n int256 remainder = xInt % uUNIT;\n if (remainder == 0) {\n result = x;\n } else {\n unchecked {\n // Solidity uses C fmod style, which returns a modulus with the same sign as x.\n int256 resultInt = xInt - remainder;\n if (xInt > 0) {\n resultInt += uUNIT;\n }\n result = wrap(resultInt);\n }\n }\n}\n\n/// @notice Divides two SD59x18 numbers, returning a new SD59x18 number.\n///\n/// @dev This is an extension of {Common.mulDiv} for signed numbers, which works by computing the signs and the absolute\n/// values separately.\n///\n/// Notes:\n/// - Refer to the notes in {Common.mulDiv}.\n/// - The result is rounded toward zero.\n///\n/// Requirements:\n/// - Refer to the requirements in {Common.mulDiv}.\n/// - None of the inputs can be `MIN_SD59x18`.\n/// - The denominator must not be zero.\n/// - The result must fit in SD59x18.\n///\n/// @param x The numerator as an SD59x18 number.\n/// @param y The denominator as an SD59x18 number.\n/// @param result The quotient as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction div(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {\n int256 xInt = x.unwrap();\n int256 yInt = y.unwrap();\n if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {\n revert Errors.PRBMath_SD59x18_Div_InputTooSmall();\n }\n\n // Get hold of the absolute values of x and y.\n uint256 xAbs;\n uint256 yAbs;\n unchecked {\n xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);\n yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);\n }\n\n // Compute the absolute value (x*UNIT÷y). The resulting value must fit in SD59x18.\n uint256 resultAbs = Common.mulDiv(xAbs, uint256(uUNIT), yAbs);\n if (resultAbs > uint256(uMAX_SD59x18)) {\n revert Errors.PRBMath_SD59x18_Div_Overflow(x, y);\n }\n\n // Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for\n // negative, 0 for positive or zero).\n bool sameSign = (xInt ^ yInt) > -1;\n\n // If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.\n unchecked {\n result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));\n }\n}\n\n/// @notice Calculates the natural exponent of x using the following formula:\n///\n/// $$\n/// e^x = 2^{x * log_2{e}}\n/// $$\n///\n/// @dev Notes:\n/// - Refer to the notes in {exp2}.\n///\n/// Requirements:\n/// - Refer to the requirements in {exp2}.\n/// - x must be less than 133_084258667509499441.\n///\n/// @param x The exponent as an SD59x18 number.\n/// @return result The result as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction exp(SD59x18 x) pure returns (SD59x18 result) {\n int256 xInt = x.unwrap();\n\n // This check prevents values greater than 192e18 from being passed to {exp2}.\n if (xInt > uEXP_MAX_INPUT) {\n revert Errors.PRBMath_SD59x18_Exp_InputTooBig(x);\n }\n\n unchecked {\n // Inline the fixed-point multiplication to save gas.\n int256 doubleUnitProduct = xInt * uLOG2_E;\n result = exp2(wrap(doubleUnitProduct / uUNIT));\n }\n}\n\n/// @notice Calculates the binary exponent of x using the binary fraction method using the following formula:\n///\n/// $$\n/// 2^{-x} = \\frac{1}{2^x}\n/// $$\n///\n/// @dev See https://ethereum.stackexchange.com/q/79903/24693.\n///\n/// Notes:\n/// - If x is less than -59_794705707972522261, the result is zero.\n///\n/// Requirements:\n/// - x must be less than 192e18.\n/// - The result must fit in SD59x18.\n///\n/// @param x The exponent as an SD59x18 number.\n/// @return result The result as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction exp2(SD59x18 x) pure returns (SD59x18 result) {\n int256 xInt = x.unwrap();\n if (xInt < 0) {\n // The inverse of any number less than this is truncated to zero.\n if (xInt < -59_794705707972522261) {\n return ZERO;\n }\n\n unchecked {\n // Inline the fixed-point inversion to save gas.\n result = wrap(uUNIT_SQUARED / exp2(wrap(-xInt)).unwrap());\n }\n } else {\n // Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.\n if (xInt > uEXP2_MAX_INPUT) {\n revert Errors.PRBMath_SD59x18_Exp2_InputTooBig(x);\n }\n\n unchecked {\n // Convert x to the 192.64-bit fixed-point format.\n uint256 x_192x64 = uint256((xInt << 64) / uUNIT);\n\n // It is safe to cast the result to int256 due to the checks above.\n result = wrap(int256(Common.exp2(x_192x64)));\n }\n }\n}\n\n/// @notice Yields the greatest whole number less than or equal to x.\n///\n/// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional\n/// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.\n///\n/// Requirements:\n/// - x must be greater than or equal to `MIN_WHOLE_SD59x18`.\n///\n/// @param x The SD59x18 number to floor.\n/// @param result The greatest whole number less than or equal to x, as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction floor(SD59x18 x) pure returns (SD59x18 result) {\n int256 xInt = x.unwrap();\n if (xInt < uMIN_WHOLE_SD59x18) {\n revert Errors.PRBMath_SD59x18_Floor_Underflow(x);\n }\n\n int256 remainder = xInt % uUNIT;\n if (remainder == 0) {\n result = x;\n } else {\n unchecked {\n // Solidity uses C fmod style, which returns a modulus with the same sign as x.\n int256 resultInt = xInt - remainder;\n if (xInt < 0) {\n resultInt -= uUNIT;\n }\n result = wrap(resultInt);\n }\n }\n}\n\n/// @notice Yields the excess beyond the floor of x for positive numbers and the part of the number to the right.\n/// of the radix point for negative numbers.\n/// @dev Based on the odd function definition. https://en.wikipedia.org/wiki/Fractional_part\n/// @param x The SD59x18 number to get the fractional part of.\n/// @param result The fractional part of x as an SD59x18 number.\nfunction frac(SD59x18 x) pure returns (SD59x18 result) {\n result = wrap(x.unwrap() % uUNIT);\n}\n\n/// @notice Calculates the geometric mean of x and y, i.e. $\\sqrt{x * y}$.\n///\n/// @dev Notes:\n/// - The result is rounded toward zero.\n///\n/// Requirements:\n/// - x * y must fit in SD59x18.\n/// - x * y must not be negative, since complex numbers are not supported.\n///\n/// @param x The first operand as an SD59x18 number.\n/// @param y The second operand as an SD59x18 number.\n/// @return result The result as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction gm(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {\n int256 xInt = x.unwrap();\n int256 yInt = y.unwrap();\n if (xInt == 0 || yInt == 0) {\n return ZERO;\n }\n\n unchecked {\n // Equivalent to `xy / x != y`. Checking for overflow this way is faster than letting Solidity do it.\n int256 xyInt = xInt * yInt;\n if (xyInt / xInt != yInt) {\n revert Errors.PRBMath_SD59x18_Gm_Overflow(x, y);\n }\n\n // The product must not be negative, since complex numbers are not supported.\n if (xyInt < 0) {\n revert Errors.PRBMath_SD59x18_Gm_NegativeProduct(x, y);\n }\n\n // We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`\n // during multiplication. See the comments in {Common.sqrt}.\n uint256 resultUint = Common.sqrt(uint256(xyInt));\n result = wrap(int256(resultUint));\n }\n}\n\n/// @notice Calculates the inverse of x.\n///\n/// @dev Notes:\n/// - The result is rounded toward zero.\n///\n/// Requirements:\n/// - x must not be zero.\n///\n/// @param x The SD59x18 number for which to calculate the inverse.\n/// @return result The inverse as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction inv(SD59x18 x) pure returns (SD59x18 result) {\n result = wrap(uUNIT_SQUARED / x.unwrap());\n}\n\n/// @notice Calculates the natural logarithm of x using the following formula:\n///\n/// $$\n/// ln{x} = log_2{x} / log_2{e}\n/// $$\n///\n/// @dev Notes:\n/// - Refer to the notes in {log2}.\n/// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.\n///\n/// Requirements:\n/// - Refer to the requirements in {log2}.\n///\n/// @param x The SD59x18 number for which to calculate the natural logarithm.\n/// @return result The natural logarithm as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction ln(SD59x18 x) pure returns (SD59x18 result) {\n // Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that\n // {log2} can return is ~195_205294292027477728.\n result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);\n}\n\n/// @notice Calculates the common logarithm of x using the following formula:\n///\n/// $$\n/// log_{10}{x} = log_2{x} / log_2{10}\n/// $$\n///\n/// However, if x is an exact power of ten, a hard coded value is returned.\n///\n/// @dev Notes:\n/// - Refer to the notes in {log2}.\n///\n/// Requirements:\n/// - Refer to the requirements in {log2}.\n///\n/// @param x The SD59x18 number for which to calculate the common logarithm.\n/// @return result The common logarithm as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction log10(SD59x18 x) pure returns (SD59x18 result) {\n int256 xInt = x.unwrap();\n if (xInt < 0) {\n revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);\n }\n\n // Note that the `mul` in this block is the standard multiplication operation, not {SD59x18.mul}.\n // prettier-ignore\n assembly (\"memory-safe\") {\n switch x\n case 1 { result := mul(uUNIT, sub(0, 18)) }\n case 10 { result := mul(uUNIT, sub(1, 18)) }\n case 100 { result := mul(uUNIT, sub(2, 18)) }\n case 1000 { result := mul(uUNIT, sub(3, 18)) }\n case 10000 { result := mul(uUNIT, sub(4, 18)) }\n case 100000 { result := mul(uUNIT, sub(5, 18)) }\n case 1000000 { result := mul(uUNIT, sub(6, 18)) }\n case 10000000 { result := mul(uUNIT, sub(7, 18)) }\n case 100000000 { result := mul(uUNIT, sub(8, 18)) }\n case 1000000000 { result := mul(uUNIT, sub(9, 18)) }\n case 10000000000 { result := mul(uUNIT, sub(10, 18)) }\n case 100000000000 { result := mul(uUNIT, sub(11, 18)) }\n case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }\n case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }\n case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }\n case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }\n case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }\n case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }\n case 1000000000000000000 { result := 0 }\n case 10000000000000000000 { result := uUNIT }\n case 100000000000000000000 { result := mul(uUNIT, 2) }\n case 1000000000000000000000 { result := mul(uUNIT, 3) }\n case 10000000000000000000000 { result := mul(uUNIT, 4) }\n case 100000000000000000000000 { result := mul(uUNIT, 5) }\n case 1000000000000000000000000 { result := mul(uUNIT, 6) }\n case 10000000000000000000000000 { result := mul(uUNIT, 7) }\n case 100000000000000000000000000 { result := mul(uUNIT, 8) }\n case 1000000000000000000000000000 { result := mul(uUNIT, 9) }\n case 10000000000000000000000000000 { result := mul(uUNIT, 10) }\n case 100000000000000000000000000000 { result := mul(uUNIT, 11) }\n case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }\n case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }\n case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }\n case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }\n case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }\n case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }\n case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }\n case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }\n case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }\n case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }\n case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }\n case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }\n case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }\n case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }\n case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }\n case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }\n case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }\n case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }\n case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }\n case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }\n case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }\n case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }\n case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }\n case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }\n case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }\n case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }\n case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }\n case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }\n case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }\n case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }\n case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }\n case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }\n case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }\n case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }\n case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }\n case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }\n case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }\n case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }\n case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }\n case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }\n case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }\n case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }\n case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }\n case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }\n case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }\n case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }\n case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }\n default { result := uMAX_SD59x18 }\n }\n\n if (result.unwrap() == uMAX_SD59x18) {\n unchecked {\n // Inline the fixed-point division to save gas.\n result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);\n }\n }\n}\n\n/// @notice Calculates the binary logarithm of x using the iterative approximation algorithm:\n///\n/// $$\n/// log_2{x} = n + log_2{y}, \\text{ where } y = x*2^{-n}, \\ y \\in [1, 2)\n/// $$\n///\n/// For $0 \\leq x \\lt 1$, the input is inverted:\n///\n/// $$\n/// log_2{x} = -log_2{\\frac{1}{x}}\n/// $$\n///\n/// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation.\n///\n/// Notes:\n/// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.\n///\n/// Requirements:\n/// - x must be greater than zero.\n///\n/// @param x The SD59x18 number for which to calculate the binary logarithm.\n/// @return result The binary logarithm as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction log2(SD59x18 x) pure returns (SD59x18 result) {\n int256 xInt = x.unwrap();\n if (xInt <= 0) {\n revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);\n }\n\n unchecked {\n int256 sign;\n if (xInt >= uUNIT) {\n sign = 1;\n } else {\n sign = -1;\n // Inline the fixed-point inversion to save gas.\n xInt = uUNIT_SQUARED / xInt;\n }\n\n // Calculate the integer part of the logarithm.\n uint256 n = Common.msb(uint256(xInt / uUNIT));\n\n // This is the integer part of the logarithm as an SD59x18 number. The operation can't overflow\n // because n is at most 255, `UNIT` is 1e18, and the sign is either 1 or -1.\n int256 resultInt = int256(n) * uUNIT;\n\n // Calculate $y = x * 2^{-n}$.\n int256 y = xInt >> n;\n\n // If y is the unit number, the fractional part is zero.\n if (y == uUNIT) {\n return wrap(resultInt * sign);\n }\n\n // Calculate the fractional part via the iterative approximation.\n // The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.\n int256 DOUBLE_UNIT = 2e18;\n for (int256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {\n y = (y * y) / uUNIT;\n\n // Is y^2 >= 2e18 and so in the range [2e18, 4e18)?\n if (y >= DOUBLE_UNIT) {\n // Add the 2^{-m} factor to the logarithm.\n resultInt = resultInt + delta;\n\n // Halve y, which corresponds to z/2 in the Wikipedia article.\n y >>= 1;\n }\n }\n resultInt *= sign;\n result = wrap(resultInt);\n }\n}\n\n/// @notice Multiplies two SD59x18 numbers together, returning a new SD59x18 number.\n///\n/// @dev Notes:\n/// - Refer to the notes in {Common.mulDiv18}.\n///\n/// Requirements:\n/// - Refer to the requirements in {Common.mulDiv18}.\n/// - None of the inputs can be `MIN_SD59x18`.\n/// - The result must fit in SD59x18.\n///\n/// @param x The multiplicand as an SD59x18 number.\n/// @param y The multiplier as an SD59x18 number.\n/// @return result The product as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction mul(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {\n int256 xInt = x.unwrap();\n int256 yInt = y.unwrap();\n if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {\n revert Errors.PRBMath_SD59x18_Mul_InputTooSmall();\n }\n\n // Get hold of the absolute values of x and y.\n uint256 xAbs;\n uint256 yAbs;\n unchecked {\n xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);\n yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);\n }\n\n // Compute the absolute value (x*y÷UNIT). The resulting value must fit in SD59x18.\n uint256 resultAbs = Common.mulDiv18(xAbs, yAbs);\n if (resultAbs > uint256(uMAX_SD59x18)) {\n revert Errors.PRBMath_SD59x18_Mul_Overflow(x, y);\n }\n\n // Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for\n // negative, 0 for positive or zero).\n bool sameSign = (xInt ^ yInt) > -1;\n\n // If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.\n unchecked {\n result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));\n }\n}\n\n/// @notice Raises x to the power of y using the following formula:\n///\n/// $$\n/// x^y = 2^{log_2{x} * y}\n/// $$\n///\n/// @dev Notes:\n/// - Refer to the notes in {exp2}, {log2}, and {mul}.\n/// - Returns `UNIT` for 0^0.\n///\n/// Requirements:\n/// - Refer to the requirements in {exp2}, {log2}, and {mul}.\n///\n/// @param x The base as an SD59x18 number.\n/// @param y Exponent to raise x to, as an SD59x18 number\n/// @return result x raised to power y, as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction pow(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {\n int256 xInt = x.unwrap();\n int256 yInt = y.unwrap();\n\n // If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.\n if (xInt == 0) {\n return yInt == 0 ? UNIT : ZERO;\n }\n // If x is `UNIT`, the result is always `UNIT`.\n else if (xInt == uUNIT) {\n return UNIT;\n }\n\n // If y is zero, the result is always `UNIT`.\n if (yInt == 0) {\n return UNIT;\n }\n // If y is `UNIT`, the result is always x.\n else if (yInt == uUNIT) {\n return x;\n }\n\n // Calculate the result using the formula.\n result = exp2(mul(log2(x), y));\n}\n\n/// @notice Raises x (an SD59x18 number) to the power y (an unsigned basic integer) using the well-known\n/// algorithm \"exponentiation by squaring\".\n///\n/// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.\n///\n/// Notes:\n/// - Refer to the notes in {Common.mulDiv18}.\n/// - Returns `UNIT` for 0^0.\n///\n/// Requirements:\n/// - Refer to the requirements in {abs} and {Common.mulDiv18}.\n/// - The result must fit in SD59x18.\n///\n/// @param x The base as an SD59x18 number.\n/// @param y The exponent as a uint256.\n/// @return result The result as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction powu(SD59x18 x, uint256 y) pure returns (SD59x18 result) {\n uint256 xAbs = uint256(abs(x).unwrap());\n\n // Calculate the first iteration of the loop in advance.\n uint256 resultAbs = y & 1 > 0 ? xAbs : uint256(uUNIT);\n\n // Equivalent to `for(y /= 2; y > 0; y /= 2)`.\n uint256 yAux = y;\n for (yAux >>= 1; yAux > 0; yAux >>= 1) {\n xAbs = Common.mulDiv18(xAbs, xAbs);\n\n // Equivalent to `y % 2 == 1`.\n if (yAux & 1 > 0) {\n resultAbs = Common.mulDiv18(resultAbs, xAbs);\n }\n }\n\n // The result must fit in SD59x18.\n if (resultAbs > uint256(uMAX_SD59x18)) {\n revert Errors.PRBMath_SD59x18_Powu_Overflow(x, y);\n }\n\n unchecked {\n // Is the base negative and the exponent odd? If yes, the result should be negative.\n int256 resultInt = int256(resultAbs);\n bool isNegative = x.unwrap() < 0 && y & 1 == 1;\n if (isNegative) {\n resultInt = -resultInt;\n }\n result = wrap(resultInt);\n }\n}\n\n/// @notice Calculates the square root of x using the Babylonian method.\n///\n/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.\n///\n/// Notes:\n/// - Only the positive root is returned.\n/// - The result is rounded toward zero.\n///\n/// Requirements:\n/// - x cannot be negative, since complex numbers are not supported.\n/// - x must be less than `MAX_SD59x18 / UNIT`.\n///\n/// @param x The SD59x18 number for which to calculate the square root.\n/// @return result The result as an SD59x18 number.\n/// @custom:smtchecker abstract-function-nondet\nfunction sqrt(SD59x18 x) pure returns (SD59x18 result) {\n int256 xInt = x.unwrap();\n if (xInt < 0) {\n revert Errors.PRBMath_SD59x18_Sqrt_NegativeInput(x);\n }\n if (xInt > uMAX_SD59x18 / uUNIT) {\n revert Errors.PRBMath_SD59x18_Sqrt_Overflow(x);\n }\n\n unchecked {\n // Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two SD59x18 numbers.\n // In this case, the two numbers are both the square root.\n uint256 resultUint = Common.sqrt(uint256(xInt * uUNIT));\n result = wrap(int256(resultUint));\n }\n}\n"
},
"node_modules/@prb/math/src/sd1x18/Errors.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport { SD1x18 } from \"./ValueType.sol\";\n\n/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in UD2x18.\nerror PRBMath_SD1x18_ToUD2x18_Underflow(SD1x18 x);\n\n/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in UD60x18.\nerror PRBMath_SD1x18_ToUD60x18_Underflow(SD1x18 x);\n\n/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint128.\nerror PRBMath_SD1x18_ToUint128_Underflow(SD1x18 x);\n\n/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint256.\nerror PRBMath_SD1x18_ToUint256_Underflow(SD1x18 x);\n\n/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint40.\nerror PRBMath_SD1x18_ToUint40_Overflow(SD1x18 x);\n\n/// @notice Thrown when trying to cast a SD1x18 number that doesn't fit in uint40.\nerror PRBMath_SD1x18_ToUint40_Underflow(SD1x18 x);\n"
},
"node_modules/@prb/math/src/sd59x18/Errors.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.19;\n\nimport { SD59x18 } from \"./ValueType.sol\";\n\n/// @notice Thrown when taking the absolute value of `MIN_SD59x18`.\nerror PRBMath_SD59x18_Abs_MinSD59x18();\n\n/// @notice Thrown when ceiling a number overflows SD59x18.\nerror PRBMath_SD59x18_Ceil_Overflow(SD59x18 x);\n\n/// @notice Thrown when converting a basic integer to the fixed-point format overflows SD59x18.\nerror PRBMath_SD59x18_Convert_Overflow(int256 x);\n\n/// @notice Thrown when converting a basic integer to the fixed-point format underflows SD59x18.\nerror PRBMath_SD59x18_Convert_Underflow(int256 x);\n\n/// @notice Thrown when dividing two numbers and one of them is `MIN_SD59x18`.\nerror PRBMath_SD59x18_Div_InputTooSmall();\n\n/// @notice Thrown when dividing two numbers and one of the intermediary unsigned results overflows SD59x18.\nerror PRBMath_SD59x18_Div_Overflow(SD59x18 x, SD59x18 y);\n\n/// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.\nerror PRBMath_SD59x18_Exp_InputTooBig(SD59x18 x);\n\n/// @notice Thrown when taking the binary exponent of a base greater than 192e18.\nerror PRBMath_SD59x18_Exp2_InputTooBig(SD59x18 x);\n\n/// @notice Thrown when flooring a number underflows SD59x18.\nerror PRBMath_SD59x18_Floor_Underflow(SD59x18 x);\n\n/// @notice Thrown when taking the geometric mean of two numbers and their product is negative.\nerror PRBMath_SD59x18_Gm_NegativeProduct(SD59x18 x, SD59x18 y);\n\n/// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows SD59x18.\nerror PRBMath_SD59x18_Gm_Overflow(SD59x18 x, SD59x18 y);\n\n/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.\nerror PRBMath_SD59x18_IntoSD1x18_Overflow(SD59x18 x);\n\n/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.\nerror PRBMath_SD59x18_IntoSD1x18_Underflow(SD59x18 x);\n\n/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.\nerror PRBMath_SD59x18_IntoUD2x18_Overflow(SD59x18 x);\n\n/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.\nerror PRBMath_SD59x18_IntoUD2x18_Underflow(SD59x18 x);\n\n/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD60x18.\nerror PRBMath_SD59x18_IntoUD60x18_Underflow(SD59x18 x);\n\n/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.\nerror PRBMath_SD59x18_IntoUint128_Overflow(SD59x18 x);\n\n/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.\nerror PRBMath_SD59x18_IntoUint128_Underflow(SD59x18 x);\n\n/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint256.\nerror PRBMath_SD59x18_IntoUint256_Underflow(SD59x18 x);\n\n/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.\nerror PRBMath_SD59x18_IntoUint40_Overflow(SD59x18 x);\n\n/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.\nerror PRBMath_SD59x18_IntoUint40_Underflow(SD59x18 x);\n\n/// @notice Thrown when taking the logarithm of a number less than or equal to zero.\nerror PRBMath_SD59x18_Log_InputTooSmall(SD59x18 x);\n\n/// @notice Thrown when multiplying two numbers and one of the inputs is `MIN_SD59x18`.\nerror PRBMath_SD59x18_Mul_InputTooSmall();\n\n/// @notice Thrown when multiplying two numbers and the intermediary absolute result overflows SD59x18.\nerror PRBMath_SD59x18_Mul_Overflow(SD59x18 x, SD59x18 y);\n\n/// @notice Thrown when raising a number to a power and hte intermediary absolute result overflows SD59x18.\nerror PRBMath_SD59x18_Powu_Overflow(SD59x18 x, uint256 y);\n\n/// @notice Thrown when taking the square root of a negative number.\nerror PRBMath_SD59x18_Sqrt_NegativeInput(SD59x18 x);\n\n/// @notice Thrown when the calculating the square root overflows SD59x18.\nerror PRBMath_SD59x18_Sqrt_Overflow(SD59x18 x);\n"
}
},
"settings": {
"remappings": [
"@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
"@prb/math/=node_modules/@prb/math/",
"@prb/test/=node_modules/@prb/test/",
"forge-std/=node_modules/forge-std/",
"solady/=node_modules/solady/",
"solarray/=node_modules/solarray/"
],
"optimizer": {
"enabled": true,
"runs": 1000
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "none",
"appendCBOR": true
},
"outputSelection": {
"*": {
"": [
"ast"
],
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata"
]
}
},
"evmVersion": "paris",
"viaIR": true,
"libraries": {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment