|
{
|
|
"language": "Solidity",
|
|
"sources": {
|
|
"lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC1155Upgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (interfaces/IERC1155.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../token/ERC1155/IERC1155Upgradeable.sol\";\n"
|
|
},
|
|
"lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC2981Upgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (interfaces/IERC2981.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/introspection/IERC165Upgradeable.sol\";\n\n/**\n * @dev Interface for the NFT Royalty Standard.\n *\n * A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal\n * support for royalty payments across all NFT marketplaces and ecosystem participants.\n *\n * _Available since v4.5._\n */\ninterface IERC2981Upgradeable is IERC165Upgradeable {\n /**\n * @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of\n * exchange. The royalty amount is denominated and should be paid in that same unit of exchange.\n */\n function royaltyInfo(uint256 tokenId, uint256 salePrice)\n external\n view\n returns (address receiver, uint256 royaltyAmount);\n}\n"
|
|
},
|
|
"lib/openzeppelin-contracts-upgradeable/contracts/token/ERC1155/IERC1155ReceiverUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165Upgradeable.sol\";\n\n/**\n * @dev _Available since v3.1._\n */\ninterface IERC1155ReceiverUpgradeable is IERC165Upgradeable {\n /**\n * @dev Handles the receipt of a single ERC1155 token type. This function is\n * called at the end of a `safeTransferFrom` after the balance has been updated.\n *\n * NOTE: To accept the transfer, this must return\n * `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))`\n * (i.e. 0xf23a6e61, or its own function selector).\n *\n * @param operator The address which initiated the transfer (i.e. msg.sender)\n * @param from The address which previously owned the token\n * @param id The ID of the token being transferred\n * @param value The amount of tokens being transferred\n * @param data Additional data with no specified format\n * @return `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))` if transfer is allowed\n */\n function onERC1155Received(\n address operator,\n address from,\n uint256 id,\n uint256 value,\n bytes calldata data\n ) external returns (bytes4);\n\n /**\n * @dev Handles the receipt of a multiple ERC1155 token types. This function\n * is called at the end of a `safeBatchTransferFrom` after the balances have\n * been updated.\n *\n * NOTE: To accept the transfer(s), this must return\n * `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))`\n * (i.e. 0xbc197c81, or its own function selector).\n *\n * @param operator The address which initiated the batch transfer (i.e. msg.sender)\n * @param from The address which previously owned the token\n * @param ids An array containing ids of each token being transferred (order and length must match values array)\n * @param values An array containing amounts of each token being transferred (order and length must match ids array)\n * @param data Additional data with no specified format\n * @return `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))` if transfer is allowed\n */\n function onERC1155BatchReceived(\n address operator,\n address from,\n uint256[] calldata ids,\n uint256[] calldata values,\n bytes calldata data\n ) external returns (bytes4);\n}\n"
|
|
},
|
|
"lib/openzeppelin-contracts-upgradeable/contracts/token/ERC1155/IERC1155Upgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165Upgradeable.sol\";\n\n/**\n * @dev Required interface of an ERC1155 compliant contract, as defined in the\n * https://eips.ethereum.org/EIPS/eip-1155[EIP].\n *\n * _Available since v3.1._\n */\ninterface IERC1155Upgradeable is IERC165Upgradeable {\n /**\n * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.\n */\n event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);\n\n /**\n * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all\n * transfers.\n */\n event TransferBatch(\n address indexed operator,\n address indexed from,\n address indexed to,\n uint256[] ids,\n uint256[] values\n );\n\n /**\n * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to\n * `approved`.\n */\n event ApprovalForAll(address indexed account, address indexed operator, bool approved);\n\n /**\n * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.\n *\n * If an {URI} event was emitted for `id`, the standard\n * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value\n * returned by {IERC1155MetadataURI-uri}.\n */\n event URI(string value, uint256 indexed id);\n\n /**\n * @dev Returns the amount of tokens of token type `id` owned by `account`.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function balanceOf(address account, uint256 id) external view returns (uint256);\n\n /**\n * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.\n *\n * Requirements:\n *\n * - `accounts` and `ids` must have the same length.\n */\n function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)\n external\n view\n returns (uint256[] memory);\n\n /**\n * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,\n *\n * Emits an {ApprovalForAll} event.\n *\n * Requirements:\n *\n * - `operator` cannot be the caller.\n */\n function setApprovalForAll(address operator, bool approved) external;\n\n /**\n * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.\n *\n * See {setApprovalForAll}.\n */\n function isApprovedForAll(address account, address operator) external view returns (bool);\n\n /**\n * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.\n *\n * Emits a {TransferSingle} event.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.\n * - `from` must have a balance of tokens of type `id` of at least `amount`.\n * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the\n * acceptance magic value.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 id,\n uint256 amount,\n bytes calldata data\n ) external;\n\n /**\n * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.\n *\n * Emits a {TransferBatch} event.\n *\n * Requirements:\n *\n * - `ids` and `amounts` must have the same length.\n * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the\n * acceptance magic value.\n */\n function safeBatchTransferFrom(\n address from,\n address to,\n uint256[] calldata ids,\n uint256[] calldata amounts,\n bytes calldata data\n ) external;\n}\n"
|
|
},
|
|
"lib/openzeppelin-contracts-upgradeable/contracts/token/ERC721/IERC721ReceiverUpgradeable.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 IERC721ReceiverUpgradeable {\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"
|
|
},
|
|
"lib/openzeppelin-contracts-upgradeable/contracts/utils/introspection/IERC165Upgradeable.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 IERC165Upgradeable {\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"
|
|
},
|
|
"src/Slice/interfaces/IFundsModule.sol": {
|
|
"content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.0;\n\nimport \"./ISlicer.sol\";\nimport \"./ISliceCore.sol\";\n\ninterface IFundsModule {\n function JBProjectId() external view returns (uint256 projectId);\n\n function sliceCore() external view returns (ISliceCore sliceCoreAddress);\n\n function balances(address account, address currency)\n external\n view\n returns (uint128 accountBalance, uint128 protocolPayment);\n\n function depositEth(address account, uint256 protocolPayment)\n external\n payable;\n\n function depositTokenFromSlicer(\n uint256 tokenId,\n address account,\n address currency,\n uint256 amount,\n uint256 protocolPayment\n ) external;\n\n function withdraw(address account, address currency) external;\n\n function batchWithdraw(address account, address[] memory currencies) external;\n\n function withdrawOnRelease(\n uint256 tokenId,\n address account,\n address currency,\n uint256 amount,\n uint256 protocolPayment\n ) external payable;\n\n function batchReleaseSlicers(\n ISlicer[] memory slicers,\n address account,\n address currency,\n bool triggerWithdraw\n ) external;\n}\n"
|
|
},
|
|
"src/Slice/interfaces/IProductsModule.sol": {
|
|
"content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.0;\n\nimport \"../structs/Function.sol\";\nimport \"../structs/Price.sol\";\nimport \"../structs/ProductParams.sol\";\nimport \"../structs/PurchaseParams.sol\";\nimport \"./ISliceCore.sol\";\nimport \"./IFundsModule.sol\";\n\ninterface IProductsModule {\n function sliceCore() external view returns (ISliceCore sliceCoreAddress);\n\n function fundsModule()\n external\n view\n returns (IFundsModule fundsModuleAddress);\n\n function addProduct(\n uint256 slicerId,\n ProductParams memory params,\n Function memory externalCall_\n ) external;\n\n function setProductInfo(\n uint256 slicerId,\n uint256 productId,\n uint8 newMaxUnits,\n bool isFree,\n bool isInfinite,\n uint32 newUnits,\n CurrencyPrice[] memory currencyPrices\n ) external;\n\n function removeProduct(uint256 slicerId, uint256 productId) external;\n\n function payProducts(address buyer, PurchaseParams[] calldata purchases)\n external\n payable;\n\n function releaseEthToSlicer(uint256 slicerId) external;\n\n // function _setCategoryAddress(uint256 categoryIndex, address newCategoryAddress) external;\n\n function ethBalance(uint256 slicerId) external view returns (uint256);\n\n function productPrice(\n uint256 slicerId,\n uint256 productId,\n address currency,\n uint256 quantity,\n address buyer,\n bytes memory data\n ) external view returns (Price memory price);\n\n function validatePurchaseUnits(\n address account,\n uint256 slicerId,\n uint256 productId\n ) external view returns (uint256 purchases);\n\n function validatePurchase(uint256 slicerId, uint256 productId)\n external\n view\n returns (uint256 purchases, bytes memory purchaseData);\n\n function availableUnits(uint256 slicerId, uint256 productId)\n external\n view\n returns (uint256 units, bool isInfinite);\n\n function isProductOwner(\n uint256 slicerId,\n uint256 productId,\n address account\n ) external view returns (bool isAllowed);\n\n // function categoryAddress(uint256 categoryIndex) external view returns (address);\n}\n"
|
|
},
|
|
"src/Slice/interfaces/ISliceCore.sol": {
|
|
"content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.0;\n\nimport \"./ISlicerManager.sol\";\nimport \"../structs/SliceParams.sol\";\nimport \"../structs/SlicerParams.sol\";\nimport \"@openzeppelin-upgradeable/interfaces/IERC1155Upgradeable.sol\";\nimport \"@openzeppelin-upgradeable/interfaces/IERC2981Upgradeable.sol\";\n\ninterface ISliceCore is IERC1155Upgradeable, IERC2981Upgradeable {\n function slicerManager()\n external\n view\n returns (ISlicerManager slicerManagerAddress);\n\n function slice(SliceParams calldata params) external;\n\n function reslice(\n uint256 tokenId,\n address payable[] calldata accounts,\n int32[] calldata tokensDiffs\n ) external;\n\n function slicerBatchTransfer(\n address from,\n address[] memory recipients,\n uint256 id,\n uint256[] memory amounts,\n bool release\n ) external;\n\n function safeTransferFromUnreleased(\n address from,\n address to,\n uint256 id,\n uint256 amount,\n bytes memory data\n ) external;\n\n function setController(uint256 id, address newController) external;\n\n function setRoyalty(\n uint256 tokenId,\n bool isSlicer,\n bool isActive,\n uint256 royaltyPercentage\n ) external;\n\n function slicers(uint256 id) external view returns (address);\n\n function controller(uint256 id) external view returns (address);\n\n function totalSupply(uint256 id) external view returns (uint256);\n\n function supply() external view returns (uint256);\n\n function exists(uint256 id) external view returns (bool);\n\n function owner() external view returns (address owner);\n\n function _setBasePath(string calldata basePath_) external;\n\n function _togglePause() external;\n}\n"
|
|
},
|
|
"src/Slice/interfaces/ISlicer.sol": {
|
|
"content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.0;\n\nimport \"@openzeppelin-upgradeable/token/ERC1155/IERC1155ReceiverUpgradeable.sol\";\nimport \"@openzeppelin-upgradeable/token/ERC721/IERC721ReceiverUpgradeable.sol\";\n\ninterface ISlicer is IERC721ReceiverUpgradeable, IERC1155ReceiverUpgradeable {\n function release(\n address account,\n address currency,\n bool withdraw\n ) external;\n\n function batchReleaseAccounts(\n address[] memory accounts,\n address currency,\n bool withdraw\n ) external;\n\n function unreleased(address account, address currency)\n external\n view\n returns (uint256 unreleasedAmount);\n\n function getFee() external view returns (uint256 fee);\n\n function getFeeForAccount(address account)\n external\n view\n returns (uint256 fee);\n\n function slicerInfo()\n external\n view\n returns (\n uint256 tokenId,\n uint256 minimumShares,\n address creator,\n bool isImmutable,\n bool currenciesControlled,\n bool productsControlled,\n bool acceptsAllCurrencies,\n address[] memory currencies\n );\n\n function isPayeeAllowed(address payee) external view returns (bool);\n\n function acceptsCurrency(address currency) external view returns (bool);\n\n function _updatePayees(\n address payable sender,\n address receiver,\n bool toRelease,\n uint256 senderShares,\n uint256 transferredShares\n ) external;\n\n function _updatePayeesReslice(\n address payable[] memory accounts,\n int32[] memory tokensDiffs,\n uint32 totalSupply\n ) external;\n\n function _setChildSlicer(uint256 id, bool addChildSlicerMode) external;\n\n function _setTotalShares(uint256 totalShares) external;\n\n function _addCurrencies(address[] memory currencies) external;\n\n function _setCustomFee(bool customFeeActive, uint256 customFee) external;\n\n function _releaseFromSliceCore(\n address account,\n address currency,\n uint256 accountSlices\n ) external;\n\n function _releaseFromFundsModule(address account, address currency)\n external\n returns (uint256 amount, uint256 protocolPayment);\n\n function _handle721Purchase(\n address buyer,\n address contractAddress,\n uint256 tokenId\n ) external;\n\n function _handle1155Purchase(\n address buyer,\n address contractAddress,\n uint256 quantity,\n uint256 tokenId\n ) external;\n}\n"
|
|
},
|
|
"src/Slice/interfaces/ISlicerManager.sol": {
|
|
"content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.0;\nimport \"../structs/SliceParams.sol\";\n\ninterface ISlicerManager {\n function implementation() external view returns (address);\n\n function _createSlicer(\n address creator,\n uint256 id,\n SliceParams calldata params\n ) external returns (address);\n\n function _upgradeSlicers(address newLogicImpl) external;\n}\n"
|
|
},
|
|
"src/Slice/interfaces/utils/ISliceProductPrice.sol": {
|
|
"content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.0;\n\ninterface ISliceProductPrice {\n function productPrice(\n uint256 slicerId,\n uint256 productId,\n address currency,\n uint256 quantity,\n address buyer,\n bytes memory data\n ) external view returns (uint256 ethPrice, uint256 currencyPrice);\n}\n"
|
|
},
|
|
"src/Slice/structs/CurrencyPrice.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nstruct CurrencyPrice {\n uint248 value;\n bool dynamicPricing;\n address externalAddress;\n address currency;\n}\n"
|
|
},
|
|
"src/Slice/structs/Function.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n/**\n * @param data data sent to `externalAddress`\n * @param value Amount or percentage of ETH / token forwarded to `externalAddress`\n * @param externalAddress Address to be called during external call\n * @param checkFunctionSignature The timestamp when the slicer becomes releasable\n * @param execFunctionSignature The timestamp when the slicer becomes transferable\n */\n\nstruct Function {\n bytes data;\n uint256 value;\n address externalAddress;\n bytes4 checkFunctionSignature;\n bytes4 execFunctionSignature;\n}\n"
|
|
},
|
|
"src/Slice/structs/Payee.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nstruct Payee {\n address account;\n uint32 shares;\n bool transfersAllowedWhileLocked;\n}\n"
|
|
},
|
|
"src/Slice/structs/Price.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nstruct Price {\n uint256 eth;\n uint256 currency;\n uint256 ethExternalCall;\n uint256 currencyExternalCall;\n}\n"
|
|
},
|
|
"src/Slice/structs/ProductParams.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport \"./SubSlicerProduct.sol\";\nimport \"./CurrencyPrice.sol\";\n\nstruct ProductParams {\n SubSlicerProduct[] subSlicerProducts;\n CurrencyPrice[] currencyPrices;\n bytes data;\n bytes purchaseData;\n uint32 availableUnits;\n // uint32 categoryIndex;\n uint8 maxUnitsPerBuyer;\n bool isFree;\n bool isInfinite;\n bool isExternalCallPaymentRelative;\n bool isExternalCallPreferredToken;\n}\n"
|
|
},
|
|
"src/Slice/structs/PurchaseParams.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nstruct PurchaseParams {\n uint128 slicerId;\n uint32 quantity;\n address currency;\n uint32 productId;\n bytes buyerCustomData;\n}\n"
|
|
},
|
|
"src/Slice/structs/SliceParams.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport \"../structs/Payee.sol\";\n\n/**\n * @param payees Addresses and shares of the initial payees\n * @param minimumShares Amount of shares that gives an account access to restricted\n * @param currencies Array of tokens accepted by the slicer\n * @param releaseTimelock The timestamp when the slicer becomes releasable\n * @param transferTimelock The timestamp when the slicer becomes transferable\n * @param controller The address of the slicer controller\n * @param slicerFlags See `_flags` in {Slicer}\n * @param sliceCoreFlags See `flags` in {SlicerParams} struct\n */\nstruct SliceParams {\n Payee[] payees;\n uint256 minimumShares;\n address[] currencies;\n uint256 releaseTimelock;\n uint40 transferTimelock;\n address controller;\n uint8 slicerFlags;\n uint8 sliceCoreFlags;\n}\n"
|
|
},
|
|
"src/Slice/structs/SlicerParams.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport \"../interfaces/ISlicer.sol\";\n\n/**\n * @param slicer ISlicer instance\n * @param controller Address of slicer controller\n * @param transferTimelock The timestamp when the slicer becomes transferable\n * @param totalSupply Total supply of slices\n * @param royaltyPercentage Percentage of royalty to claim (up to 100, ie 10%)\n * @param flags Boolean flags in the following order from the right: [isCustomRoyaltyActive, isRoyaltyReceiverSlicer,\n * isResliceAllowed, isControlledTransferAllowed]\n * @param transferAllowlist Mapping from address to permission to transfer slices during transferTimelock period\n */\nstruct SlicerParams {\n ISlicer slicer;\n address controller;\n uint40 transferTimelock;\n uint32 totalSupply;\n uint8 royaltyPercentage;\n uint8 flags;\n uint8 FREE_SLOT_1;\n mapping(address => bool) transferAllowlist;\n}\n"
|
|
},
|
|
"src/Slice/structs/SubSlicerProduct.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nstruct SubSlicerProduct {\n uint128 subSlicerId;\n uint32 subProductId;\n}\n"
|
|
},
|
|
"src/VRGDA/LinearVRGDAPrices.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.0;\n\nimport { wadLn, unsafeWadDiv, toDaysWadUnsafe } from \"../utils/SignedWadMath.sol\";\nimport { IProductsModule } from \"../Slice/interfaces/IProductsModule.sol\";\nimport { LinearProductParams } from \"./structs/LinearProductParams.sol\";\nimport { LinearVRGDAParams } from \"./structs/LinearVRGDAParams.sol\";\n\nimport { VRGDAPrices } from \"./VRGDAPrices.sol\";\n\n/// @title Linear Variable Rate Gradual Dutch Auction - Slice pricing strategy\n/// @author jacopo <jacopo@slice.so>\n/// @notice VRGDA with a linear issuance curve - Price library with different params for each Slice product.\ncontract LinearVRGDAPrices is VRGDAPrices {\n /*//////////////////////////////////////////////////////////////\n STORAGE\n //////////////////////////////////////////////////////////////*/\n\n // Mapping from slicerId to productId to ProductParams\n mapping(uint256 => mapping(uint256 => LinearProductParams))\n private _productParams;\n\n /*//////////////////////////////////////////////////////////////\n CONSTRUCTOR\n //////////////////////////////////////////////////////////////*/\n\n constructor(address productsModuleAddress)\n VRGDAPrices(productsModuleAddress)\n {}\n\n /*//////////////////////////////////////////////////////////////\n VRGDA PARAMETERS\n //////////////////////////////////////////////////////////////*/\n\n /// @notice Set LinearProductParams for product.\n /// @param slicerId ID of the slicer to set the price params for.\n /// @param productId ID of the product to set the price params for.\n /// @param currencies currencies of the product to set the price params for.\n /// @param linearParams see `LinearVRGDAParams`.\n /// @param priceDecayPercent The percent price decays per unit of time with no sales, scaled by 1e18.\n function setProductPrice(\n uint256 slicerId,\n uint256 productId,\n address[] calldata currencies,\n LinearVRGDAParams[] calldata linearParams,\n int256 priceDecayPercent\n ) external onlyProductOwner(slicerId, productId) {\n require(linearParams.length == currencies.length, \"INVALID_INPUTS\");\n\n int256 decayConstant = wadLn(1e18 - priceDecayPercent);\n // The decay constant must be negative for VRGDAs to work.\n require(decayConstant < 0, \"NON_NEGATIVE_DECAY_CONSTANT\");\n require(decayConstant >= type(int184).min, \"MIN_DECAY_CONSTANT_EXCEEDED\");\n\n /// Get product availability and isInfinite\n /// @dev available units is a uint32\n (uint256 availableUnits, bool isInfinite) = IProductsModule(\n _productsModuleAddress\n ).availableUnits(slicerId, productId);\n\n // Product must not have infinite availability\n require(!isInfinite, \"NOT_FINITE_AVAILABILITY\");\n\n // Set product params\n _productParams[slicerId][productId].startTime = uint40(block.timestamp);\n _productParams[slicerId][productId].startUnits = uint32(availableUnits);\n _productParams[slicerId][productId].decayConstant = int184(decayConstant);\n\n // Set currency params\n for (uint256 i; i < currencies.length; ) {\n _productParams[slicerId][productId].pricingParams[\n currencies[i]\n ] = linearParams[i];\n\n unchecked {\n ++i;\n }\n }\n }\n\n /*//////////////////////////////////////////////////////////////\n PRICING LOGIC\n //////////////////////////////////////////////////////////////*/\n\n /// @dev Given a number of products sold, return the target time that number of products should be sold by.\n /// @param sold A number of products sold, scaled by 1e18, to get the corresponding target sale time for.\n /// @param timeFactor Time-dependent factor used to calculate target sale time.\n /// @return The target time the products should be sold by, scaled by 1e18, where the time is\n /// relative, such that 0 means the products should be sold immediately when the VRGDA begins.\n function getTargetSaleTime(int256 sold, int256 timeFactor)\n public\n pure\n override\n returns (int256)\n {\n return unsafeWadDiv(sold, timeFactor);\n }\n\n /**\n * @notice Function called by Slice protocol to calculate current product price.\n * @param slicerId ID of the slicer being queried\n * @param productId ID of the product being queried\n * @param currency Currency chosen for the purchase\n * @param quantity Number of units purchased\n * @return ethPrice and currencyPrice of product.\n */\n function productPrice(\n uint256 slicerId,\n uint256 productId,\n address currency,\n uint256 quantity,\n address,\n bytes memory\n ) public view override returns (uint256 ethPrice, uint256 currencyPrice) {\n // Add reference for product and pricing params\n LinearProductParams storage productParams = _productParams[slicerId][\n productId\n ];\n LinearVRGDAParams memory pricingParams = productParams.pricingParams[\n currency\n ];\n\n require(productParams.startTime != 0, \"PRODUCT_UNSET\");\n\n // Get available units\n (uint256 availableUnits, ) = IProductsModule(_productsModuleAddress)\n .availableUnits(slicerId, productId);\n\n // Calculate sold units from availableUnits\n uint256 soldUnits = productParams.startUnits - availableUnits;\n\n // Set ethPrice or currencyPrice based on chosen currency\n if (currency == address(0)) {\n ethPrice = getAdjustedVRGDAPrice(\n pricingParams.targetPrice,\n productParams.decayConstant,\n toDaysWadUnsafe(block.timestamp - productParams.startTime),\n soldUnits,\n pricingParams.perTimeUnit,\n pricingParams.min,\n quantity\n );\n } else {\n currencyPrice = getAdjustedVRGDAPrice(\n pricingParams.targetPrice,\n productParams.decayConstant,\n toDaysWadUnsafe(block.timestamp - productParams.startTime),\n soldUnits,\n pricingParams.perTimeUnit,\n pricingParams.min,\n quantity\n );\n }\n }\n}\n"
|
|
},
|
|
"src/VRGDA/VRGDAPrices.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.0;\n\nimport { wadExp, wadMul, unsafeWadMul, toWadUnsafe } from \"../utils/SignedWadMath.sol\";\nimport { ISliceProductPrice } from \"../Slice/interfaces/utils/ISliceProductPrice.sol\";\nimport { IProductsModule } from \"../Slice/interfaces/IProductsModule.sol\";\n\n/// @title Variable Rate Gradual Dutch Auction - Slice pricing strategy\n/// @author jacopo <jacopo@slice.so>\n/// @notice Price library with configurable params for each Slice product.\n\nabstract contract VRGDAPrices is ISliceProductPrice {\n /*//////////////////////////////////////////////////////////////\n STORAGE\n //////////////////////////////////////////////////////////////*/\n\n address internal immutable _productsModuleAddress;\n\n /*//////////////////////////////////////////////////////////////\n CONSTRUCTOR\n //////////////////////////////////////////////////////////////*/\n\n constructor(address productsModuleAddress) {\n _productsModuleAddress = productsModuleAddress;\n }\n\n /*//////////////////////////////////////////////////////////////\n MODIFIERS\n //////////////////////////////////////////////////////////////*/\n\n /// @notice Check if msg.sender is owner of a product. Used to manage access of `setProductPrice`\n /// in implementations of this contract.\n modifier onlyProductOwner(uint256 slicerId, uint256 productId) {\n require(\n IProductsModule(_productsModuleAddress).isProductOwner(\n slicerId,\n productId,\n msg.sender\n ),\n \"NOT_PRODUCT_OWNER\"\n );\n _;\n }\n\n /*//////////////////////////////////////////////////////////////\n PRICING LOGIC\n //////////////////////////////////////////////////////////////*/\n\n /// @notice Calculate the price of a product according to the VRGDA formula.\n /// @param targetPrice The target price for a product if sold on pace, scaled by 1e18.\n /// @param decayConstant Precomputed constant that allows us to rewrite a pow() as an exp().\n /// @param timeSinceStart Time passed since the VRGDA began, scaled by 1e18.\n /// @param sold The total number of products sold so far.\n /// @param timeFactor Time-dependent factor used to calculate target sale time.\n /// @param min minimum price to be paid for a token, scaled by 1e18\n /// @return The price of a product according to VRGDA, scaled by 1e18.\n function getVRGDAPrice(\n int256 targetPrice,\n int256 decayConstant,\n int256 timeSinceStart,\n uint256 sold,\n int256 timeFactor,\n uint256 min\n ) public view virtual returns (uint256) {\n unchecked {\n // prettier-ignore\n uint256 VRGDAPrice = uint256(wadMul(targetPrice, wadExp(unsafeWadMul(decayConstant,\n // We use sold + 1 as the VRGDA formula's n param represents the nth product and sold is the \n // n-1th product.\n timeSinceStart - getTargetSaleTime(\n toWadUnsafe(sold + 1), timeFactor\n )\n ))));\n\n return VRGDAPrice > min ? VRGDAPrice : min;\n }\n }\n\n /// @dev Given a number of products sold, return the target time that number of products should be sold by.\n /// @param sold A number of products sold, scaled by 1e18, to get the corresponding target sale time for.\n /// @param timeFactor Time-dependent factor used to calculate target sale time.\n /// @return The target time the products should be sold by, scaled by 1e18, where the time is\n /// relative, such that 0 means the products should be sold immediately when the VRGDA begins.\n function getTargetSaleTime(int256 sold, int256 timeFactor)\n public\n view\n virtual\n returns (int256)\n {}\n\n /// @notice Get product price adjusted to quantity purchased.\n /// @param targetPrice The target price for a product if sold on pace, scaled by 1e18.\n /// @param decayConstant Precomputed constant that allows us to rewrite a pow() as an exp().\n /// @param timeSinceStart Time passed since the VRGDA began, scaled by 1e18.\n /// @param sold The total number of products sold so far.\n /// @param timeFactor Time-dependent factor used to calculate target sale time.\n /// @param min minimum price to be paid for a token, scaled by 1e18\n /// @param quantity Number of units purchased\n /// @return price of product * quantity according to VRGDA, scaled by 1e18.\n function getAdjustedVRGDAPrice(\n int256 targetPrice,\n int256 decayConstant,\n int256 timeSinceStart,\n uint256 sold,\n int256 timeFactor,\n uint256 min,\n uint256 quantity\n ) public view virtual returns (uint256 price) {\n for (uint256 i; i < quantity; ) {\n price += getVRGDAPrice(\n targetPrice,\n decayConstant,\n timeSinceStart,\n sold + i,\n timeFactor,\n min\n );\n\n unchecked {\n ++i;\n }\n }\n }\n\n /**\n * @notice Function called by Slice protocol to calculate current product price.\n * @param slicerId ID of the slicer being queried\n * @param productId ID of the product being queried\n * @param currency Currency chosen for the purchase\n * @param quantity Number of units purchased\n * @param buyer Address of the buyer\n * @param data Custom data sent along with the purchase transaction by the buyer\n * @return ethPrice and currencyPrice of product.\n */\n function productPrice(\n uint256 slicerId,\n uint256 productId,\n address currency,\n uint256 quantity,\n address buyer,\n bytes memory data\n )\n public\n view\n virtual\n override\n returns (uint256 ethPrice, uint256 currencyPrice)\n {}\n}\n"
|
|
},
|
|
"src/VRGDA/structs/LinearProductParams.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport { LinearVRGDAParams } from \"./LinearVRGDAParams.sol\";\n\n/// @param startTime Time when the VRGDA began.\n/// @param startUnits Units available at the time when product is set up.\n/// @param decayConstant Precomputed constant that allows us to rewrite a pow() as an exp().\n/// @param pricingParams See `LinearVRGDAParams`\nstruct LinearProductParams {\n uint40 startTime;\n uint32 startUnits;\n int184 decayConstant;\n mapping(address => LinearVRGDAParams) pricingParams;\n}\n"
|
|
},
|
|
"src/VRGDA/structs/LinearVRGDAParams.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n/// @param targetPrice Target price for a product, to be scaled according to sales pace.\n/// @param min minimum price to be paid for a token, scaled by 1e18\n/// @param perTimeUnit The total number of products to target selling every full unit of time.\nstruct LinearVRGDAParams {\n int128 targetPrice;\n uint128 min;\n int256 perTimeUnit;\n}\n"
|
|
},
|
|
"src/utils/SignedWadMath.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.0;\n\n/// @title Signed Wad Math\n/// @author transmissions11 <t11s@paradigm.xyz>\n/// @author FrankieIsLost <frankie@paradigm.xyz>\n/// @author Remco Bloemen <remco@wicked.ventures>\n/// @notice Efficient signed wad arithmetic.\n\n/// @dev Will not revert on overflow, only use where overflow is not possible.\nfunction toWadUnsafe(uint256 x) pure returns (int256 r) {\n assembly {\n // Multiply x by 1e18.\n r := mul(x, 1000000000000000000)\n }\n}\n\n/// @dev Takes an integer amount of seconds and converts it to a wad amount of days.\n/// @dev Will not revert on overflow, only use where overflow is not possible.\nfunction toDaysWadUnsafe(uint256 x) pure returns (int256 r) {\n assembly {\n // Multiply x by 1e18 and then divide it by 86400.\n r := div(mul(x, 1000000000000000000), 86400)\n }\n}\n\n/// @dev Takes a wad amount of days and converts it to an integer amount of seconds.\n/// @dev Will not revert on overflow, only use where overflow is not possible.\n/// @dev Not compatible with negative day amounts, it assumes x is positive.\nfunction fromDaysWadUnsafe(int256 x) pure returns (uint256 r) {\n assembly {\n // Multiply x by 86400 and then divide it by 1e18.\n r := div(mul(x, 86400), 1000000000000000000)\n }\n}\n\n/// @dev Will not revert on overflow, only use where overflow is not possible.\nfunction unsafeWadMul(int256 x, int256 y) pure returns (int256 r) {\n assembly {\n // Multiply x by y and divide by 1e18.\n r := sdiv(mul(x, y), 1000000000000000000)\n }\n}\n\n/// @dev Will return 0 instead of reverting if y is zero and will\n/// not revert on overflow, only use where overflow is not possible.\nfunction unsafeWadDiv(int256 x, int256 y) pure returns (int256 r) {\n assembly {\n // Multiply x by 1e18 and divide it by y.\n r := sdiv(mul(x, 1000000000000000000), y)\n }\n}\n\nfunction wadMul(int256 x, int256 y) pure returns (int256 r) {\n assembly {\n // Store x * y in r for now.\n r := mul(x, y)\n\n // Equivalent to require(x == 0 || (x * y) / x == y)\n if iszero(or(iszero(x), eq(sdiv(r, x), y))) {\n revert(0, 0)\n }\n\n // Scale the result down by 1e18.\n r := sdiv(r, 1000000000000000000)\n }\n}\n\nfunction wadDiv(int256 x, int256 y) pure returns (int256 r) {\n assembly {\n // Store x * 1e18 in r for now.\n r := mul(x, 1000000000000000000)\n\n // Equivalent to require(y != 0 && ((x * 1e18) / 1e18 == x))\n if iszero(and(iszero(iszero(y)), eq(sdiv(r, 1000000000000000000), x))) {\n revert(0, 0)\n }\n\n // Divide r by y.\n r := sdiv(r, y)\n }\n}\n\nfunction wadExp(int256 x) pure returns (int256 r) {\n unchecked {\n // When the result is < 0.5 we return zero. This happens when\n // x <= floor(log(0.5e18) * 1e18) ~ -42e18\n if (x <= -42139678854452767551) return 0;\n\n // When the result is > (2**255 - 1) / 1e18 we can not represent it as an\n // int. This happens when x >= floor(log((2**255 - 1) / 1e18) * 1e18) ~ 135.\n if (x >= 135305999368893231589) revert(\"EXP_OVERFLOW\");\n\n // x is now in the range (-42, 136) * 1e18. Convert to (-42, 136) * 2**96\n // for more intermediate precision and a binary basis. This base conversion\n // is a multiplication by 1e18 / 2**96 = 5**18 / 2**78.\n x = (x << 78) / 5**18;\n\n // Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers\n // of two such that exp(x) = exp(x') * 2**k, where k is an integer.\n // Solving this gives k = round(x / log(2)) and x' = x - k * log(2).\n int256 k = ((x << 96) / 54916777467707473351141471128 + 2**95) >> 96;\n x = x - k * 54916777467707473351141471128;\n\n // k is in the range [-61, 195].\n\n // Evaluate using a (6, 7)-term rational approximation.\n // p is made monic, we'll multiply by a scale factor later.\n int256 y = x + 1346386616545796478920950773328;\n y = ((y * x) >> 96) + 57155421227552351082224309758442;\n int256 p = y + x - 94201549194550492254356042504812;\n p = ((p * y) >> 96) + 28719021644029726153956944680412240;\n p = p * x + (4385272521454847904659076985693276 << 96);\n\n // We leave p in 2**192 basis so we don't need to scale it back up for the division.\n int256 q = x - 2855989394907223263936484059900;\n q = ((q * x) >> 96) + 50020603652535783019961831881945;\n q = ((q * x) >> 96) - 533845033583426703283633433725380;\n q = ((q * x) >> 96) + 3604857256930695427073651918091429;\n q = ((q * x) >> 96) - 14423608567350463180887372962807573;\n q = ((q * x) >> 96) + 26449188498355588339934803723976023;\n\n assembly {\n // Div in assembly because solidity adds a zero check despite the unchecked.\n // The q polynomial won't have zeros in the domain as all its roots are complex.\n // No scaling is necessary because p is already 2**96 too large.\n r := sdiv(p, q)\n }\n\n // r should be in the range (0.09, 0.25) * 2**96.\n\n // We now need to multiply r by:\n // * the scale factor s = ~6.031367120.\n // * the 2**k factor from the range reduction.\n // * the 1e18 / 2**96 factor for base conversion.\n // We do this all at once, with an intermediate result in 2**213\n // basis, so the final right shift is always by a positive amount.\n r = int256((uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k));\n }\n}\n\nfunction wadLn(int256 x) pure returns (int256 r) {\n unchecked {\n require(x > 0, \"UNDEFINED\");\n\n // We want to convert x from 10**18 fixed point to 2**96 fixed point.\n // We do this by multiplying by 2**96 / 10**18. But since\n // ln(x * C) = ln(x) + ln(C), we can simply do nothing here\n // and add ln(2**96 / 10**18) at the end.\n\n assembly {\n r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\n r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))\n r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\n r := or(r, shl(4, lt(0xffff, shr(r, x))))\n r := or(r, shl(3, lt(0xff, shr(r, x))))\n r := or(r, shl(2, lt(0xf, shr(r, x))))\n r := or(r, shl(1, lt(0x3, shr(r, x))))\n r := or(r, lt(0x1, shr(r, x)))\n }\n\n // Reduce range of x to (1, 2) * 2**96\n // ln(2^k * x) = k * ln(2) + ln(x)\n int256 k = r - 96;\n x <<= uint256(159 - k);\n x = int256(uint256(x) >> 159);\n\n // Evaluate using a (8, 8)-term rational approximation.\n // p is made monic, we will multiply by a scale factor later.\n int256 p = x + 3273285459638523848632254066296;\n p = ((p * x) >> 96) + 24828157081833163892658089445524;\n p = ((p * x) >> 96) + 43456485725739037958740375743393;\n p = ((p * x) >> 96) - 11111509109440967052023855526967;\n p = ((p * x) >> 96) - 45023709667254063763336534515857;\n p = ((p * x) >> 96) - 14706773417378608786704636184526;\n p = p * x - (795164235651350426258249787498 << 96);\n\n // We leave p in 2**192 basis so we don't need to scale it back up for the division.\n // q is monic by convention.\n int256 q = x + 5573035233440673466300451813936;\n q = ((q * x) >> 96) + 71694874799317883764090561454958;\n q = ((q * x) >> 96) + 283447036172924575727196451306956;\n q = ((q * x) >> 96) + 401686690394027663651624208769553;\n q = ((q * x) >> 96) + 204048457590392012362485061816622;\n q = ((q * x) >> 96) + 31853899698501571402653359427138;\n q = ((q * x) >> 96) + 909429971244387300277376558375;\n assembly {\n // Div in assembly because solidity adds a zero check despite the unchecked.\n // The q polynomial is known not to have zeros in the domain.\n // No scaling required because p is already 2**96 too large.\n r := sdiv(p, q)\n }\n\n // r is in the range (0, 0.125) * 2**96\n\n // Finalization, we need to:\n // * multiply by the scale factor s = 5.549…\n // * add ln(2**96 / 10**18)\n // * add k * ln(2)\n // * multiply by 10**18 / 2**96 = 5**18 >> 78\n\n // mul s * 5e18 * 2**96, base is now 5**18 * 2**192\n r *= 1677202110996718588342820967067443963516166;\n // add ln(2) * k * 5e18 * 2**192\n r += 16597577552685614221487285958193947469193820559219878177908093499208371 * k;\n // add ln(2**96 / 10**18) * 5e18 * 2**192\n r += 600920179829731861736702779321621459595472258049074101567377883020018308;\n // base conversion: mul 2**18 / 2**192\n r >>= 174;\n }\n}\n\n/// @dev Will return 0 instead of reverting if y is zero.\nfunction unsafeDiv(int256 x, int256 y) pure returns (int256 r) {\n assembly {\n // Divide x by y.\n r := sdiv(x, y)\n }\n}\n"
|
|
}
|
|
},
|
|
"settings": {
|
|
"remappings": [
|
|
"@openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
|
|
"@openzeppelin/=node_modules/@openzeppelin/",
|
|
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
|
|
"create3-factory/=lib/create3-factory/src/",
|
|
"ds-test/=lib/ds-test/src/",
|
|
"forge-std/=lib/forge-std/src/",
|
|
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
|
|
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
|
|
"solmate/=lib/solmate/src/"
|
|
],
|
|
"optimizer": {
|
|
"enabled": true,
|
|
"runs": 1000000
|
|
},
|
|
"metadata": {
|
|
"bytecodeHash": "none"
|
|
},
|
|
"outputSelection": {
|
|
"*": {
|
|
"*": [
|
|
"evm.bytecode",
|
|
"evm.deployedBytecode",
|
|
"devdoc",
|
|
"userdoc",
|
|
"metadata",
|
|
"abi"
|
|
]
|
|
}
|
|
},
|
|
"evmVersion": "london",
|
|
"libraries": {}
|
|
}
|
|
} |