编译器
0.8.19+commit.7dd6d404
文件 1 的 26:BaseCafe_Compass.sol
pragma solidity 0.8.19;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import "../../extensions/Purchasable/SlicerPurchasable.sol";
import "../../utils/sliceV1/interfaces/ISliceProductPrice.sol";
import "../interfaces/ITokenERC1155.sol";
import "../../utils/sliceV1/interfaces/IProductsModule.sol";
import {IERC1155} from "@openzeppelin/contracts/interfaces/IERC1155.sol";
struct ClaimableDiscount {
bool discountClaimable;
bool discountClaimed;
}
contract BaseCafe_Compass_SliceHook is SlicerPurchasable, Ownable, ISliceProductPrice {
ITokenERC1155 public constant MINT_NFT_COLLECTION = ITokenERC1155(0x185169058E83CC5Ae9fc1bc758eEA7098a2557CF);
uint256 public constant MINT_NFT_TOKEN_ID = 0;
mapping(uint256 slicerId => bool allowed) public allowedSlicerIds;
mapping(uint256 slicerId => mapping(uint256 productId => ClaimableDiscount)) public productsDiscount;
mapping(uint256 slicerId => mapping(uint256 productId => uint64 usdcPrice)) public productPrices;
constructor(address productsModuleAddress_, uint256 slicerId_) {
_productsModuleAddress = productsModuleAddress_;
_slicerId = slicerId_;
allowedSlicerIds[425] = true;
allowedSlicerIds[426] = true;
}
function onProductPurchase(
uint256 slicerId,
uint256 productId,
address buyer,
uint256 quantity,
bytes memory,
bytes memory
) public payable override {
if (!allowedSlicerIds[slicerId]) revert NotAllowed();
ClaimableDiscount memory discount = productsDiscount[slicerId][productId];
if (
discount.discountClaimable && !discount.discountClaimed
&& IERC1155(address(MINT_NFT_COLLECTION)).balanceOf(buyer, MINT_NFT_TOKEN_ID) != 0
) {
productsDiscount[slicerId][productId].discountClaimed = true;
}
MINT_NFT_COLLECTION.mintTo(buyer, MINT_NFT_TOKEN_ID, "", quantity);
}
function setPrice(uint256 slicerId, uint256 productId, uint64 price) external onlyOwner {
productPrices[slicerId][productId] = price;
}
function setAllowedSlicerId(uint256 slicerId, bool allowed) external onlyOwner {
allowedSlicerIds[slicerId] = allowed;
}
function setProductDiscount(uint256 slicerId, uint256 productId, bool isDiscounted) external onlyOwner {
productsDiscount[slicerId][productId].discountClaimable = isDiscounted;
}
function productPrice(uint256 slicerId, uint256 productId, address, uint256 quantity, address buyer, bytes memory)
external
view
returns (uint256 ethPrice, uint256 currencyPrice)
{
ClaimableDiscount memory discount = productsDiscount[slicerId][productId];
if (
discount.discountClaimable && !discount.discountClaimed
&& IERC1155(address(MINT_NFT_COLLECTION)).balanceOf(buyer, MINT_NFT_TOKEN_ID) != 0
) {
quantity--;
}
currencyPrice = productPrices[slicerId][productId] * quantity;
ethPrice = 0;
}
}
文件 2 的 26:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 3 的 26:CurrencyPrice.sol
pragma solidity ^0.8.0;
struct CurrencyPrice {
uint248 value;
bool dynamicPricing;
address currency;
}
文件 4 的 26:Function.sol
pragma solidity ^0.8.0;
struct Function {
bytes data;
uint256 value;
address externalAddress;
bytes4 checkFunctionSignature;
bytes4 execFunctionSignature;
}
文件 5 的 26:IERC1155.sol
pragma solidity ^0.8.0;
import "../token/ERC1155/IERC1155.sol";
文件 6 的 26:IERC1155Receiver.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC1155Receiver is IERC165 {
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}
文件 7 的 26:IERC1155Upgradeable.sol
pragma solidity ^0.8.0;
import "../token/ERC1155/IERC1155Upgradeable.sol";
文件 8 的 26:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 9 的 26:IERC165Upgradeable.sol
pragma solidity ^0.8.0;
interface IERC165Upgradeable {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 10 的 26:IERC2981Upgradeable.sol
pragma solidity ^0.8.0;
import "../utils/introspection/IERC165Upgradeable.sol";
interface IERC2981Upgradeable is IERC165Upgradeable {
function royaltyInfo(
uint256 tokenId,
uint256 salePrice
) external view returns (address receiver, uint256 royaltyAmount);
}
文件 11 的 26:IERC721Receiver.sol
pragma solidity ^0.8.0;
import "../token/ERC721/IERC721Receiver.sol";
文件 12 的 26:IFundsModule.sol
pragma solidity ^0.8.0;
import "./ISlicer.sol";
interface IFundsModule {
function depositEth(address account, uint256 protocolPayment) external payable;
function depositTokenFromSlicer(
uint256 tokenId,
address account,
address currency,
uint256 amount,
uint256 protocolPayment
) external;
function withdraw(address account, address currency) external;
function batchWithdraw(address account, address[] memory currencies) external;
function withdrawOnRelease(
uint256 tokenId,
address account,
address currency,
uint256 amount,
uint256 protocolPayment
) external payable;
function batchReleaseSlicers(
ISlicer[] memory slicers,
address account,
address currency,
bool triggerWithdraw
) external;
function balance(address account, address currency)
external
view
returns (uint256 accountBalance, uint256 protocolPayment);
}
文件 13 的 26:IOwnable.sol
pragma solidity ^0.8.0;
interface IOwnable {
function owner() external view returns (address);
function transferOwnership(address newOwner) external;
function renounceOwnership() external;
}
文件 14 的 26:IProductsModule.sol
pragma solidity ^0.8.0;
import "../structs/Function.sol";
import "../structs/Price.sol";
import "../structs/ProductParams.sol";
import "../structs/PurchaseParams.sol";
import "./ISliceCore.sol";
import "./IFundsModule.sol";
interface IProductsModule {
function sliceCore() external view returns (ISliceCore sliceCoreAddress);
function fundsModule() external view returns (IFundsModule fundsModuleAddress);
function addProduct(uint256 slicerId, ProductParams memory params, Function memory externalCall_) external;
function setProductInfo(
uint256 slicerId,
uint256 productId,
uint8 newMaxUnits,
bool isFree,
bool isInfinite,
uint32 newUnits,
CurrencyPrice[] memory currencyPrices
) external;
function removeProduct(uint256 slicerId, uint256 productId) external;
function payProducts(PurchaseParams[] calldata purchases) external payable;
function releaseEthToSlicer(uint256 slicerId) external;
function ethBalance(uint256 slicerId) external view returns (uint256);
function productPrice(
uint256 slicerId,
uint256 productId,
address currency,
uint256 quantity,
address buyer,
bytes memory data
) external view returns (Price memory price);
function validatePurchaseUnits(address account, uint256 slicerId, uint256 productId)
external
view
returns (uint256 purchases);
function validatePurchase(uint256 slicerId, uint256 productId)
external
view
returns (uint256 purchases, bytes memory purchaseData);
function availableUnits(uint256 slicerId, uint256 productId)
external
view
returns (uint256 units, bool isInfinite);
function isProductOwner(uint256 slicerId, uint256 productId, address account)
external
view
returns (bool isAllowed);
}
文件 15 的 26:ISliceCore.sol
pragma solidity ^0.8.0;
import "../structs/Payee.sol";
import "./utils/IOwnable.sol";
import "@openzeppelin/contracts-upgradeable/interfaces/IERC1155Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/interfaces/IERC2981Upgradeable.sol";
interface ISliceCore is IOwnable, IERC1155Upgradeable, IERC2981Upgradeable {
function slice(
Payee[] calldata payees,
uint256 minimumShares,
address[] calldata currencies,
uint256 releaseTimelock,
uint40 transferableTimelock,
bool isImmutable,
bool isControlled
) external;
function reslice(
uint256 tokenId,
address payable[] calldata accounts,
int32[] calldata tokensDiffs
) external;
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) external override;
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) external override;
function slicerBatchTransfer(
address from,
address[] memory recipients,
uint256 id,
uint256[] memory amounts,
bool release
) external;
function safeTransferFromUnreleased(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) external;
function setController(uint256 id, address newController) external;
function setRoyalty(
uint256 tokenId,
bool isSlicer,
bool isActive,
uint256 royaltyPercentage
) external;
function royaltyInfo(uint256 tokenId, uint256 salePrice)
external
view
override
returns (address receiver, uint256 royaltyAmount);
function slicers(uint256 id) external view returns (address);
function controller(uint256 id) external view returns (address);
function totalSupply(uint256 id) external view returns (uint256);
function supply() external view returns (uint256);
function exists(uint256 id) external view returns (bool);
function _setBasePath(string calldata basePath_) external;
function _togglePause() external;
}
文件 16 的 26:ISliceProductPrice.sol
pragma solidity ^0.8.0;
interface ISliceProductPrice {
function productPrice(
uint256 slicerId,
uint256 productId,
address currency,
uint256 quantity,
address buyer,
bytes memory data
) external view returns (uint256 ethPrice, uint256 currencyPrice);
}
文件 17 的 26:ISlicer.sol
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/interfaces/IERC1155Receiver.sol";
import "@openzeppelin/contracts/interfaces/IERC721Receiver.sol";
interface ISlicer is IERC721Receiver, IERC1155Receiver {
function release(
address account,
address currency,
bool withdraw
) external;
function batchReleaseAccounts(
address[] memory accounts,
address currency,
bool withdraw
) external;
function unreleased(address account, address currency)
external
view
returns (uint256 unreleasedAmount);
function getFee() external view returns (uint256 fee);
function slicerInfo()
external
view
returns (
uint256 tokenId,
uint256 minimumShares,
address creator,
bool isImmutable,
bool isControlled,
address[] memory currencies
);
function isPayeeAllowed(address payee) external view returns (bool);
function acceptsCurrency(address currency) external view returns (bool);
function _updatePayees(
address payable sender,
address receiver,
bool toRelease,
uint256 senderShares,
uint256 transferredShares
) external;
function _updatePayeesReslice(
address payable[] memory accounts,
int32[] memory tokensDiffs,
uint32 totalSupply
) external;
function _setChildSlicer(uint256 id, bool addChildSlicerMode) external;
function _setTotalShares(uint256 totalShares) external;
function _addCurrencies(address[] memory currencies) external;
function _setCustomFee(bool customFeeActive, uint256 customFee) external;
function _releaseFromSliceCore(
address account,
address currency,
uint256 accountSlices
) external;
function _releaseFromFundsModule(address account, address currency)
external
returns (uint256 amount, uint256 protocolPayment);
function _handle721Purchase(
address buyer,
address contractAddress,
uint256 tokenId
) external;
function _handle1155Purchase(
address buyer,
address contractAddress,
uint256 quantity,
uint256 tokenId
) external;
}
文件 18 的 26:ISlicerPurchasable.sol
pragma solidity ^0.8.0;
interface ISlicerPurchasable {
function isPurchaseAllowed(
uint256 slicerId,
uint256 productId,
address account,
uint256 quantity,
bytes memory slicerCustomData,
bytes memory buyerCustomData
) external view returns (bool);
function onProductPurchase(
uint256 slicerId,
uint256 productId,
address account,
uint256 quantity,
bytes memory slicerCustomData,
bytes memory buyerCustomData
) external payable;
}
文件 19 的 26:ITokenERC1155.sol
pragma solidity ^0.8.0;
interface ITokenERC1155 {
function mintTo(address to, uint256 tokenId, string calldata uri, uint256 amount) external;
function setTokenURI(uint256 tokenId, string calldata uri) external;
}
文件 20 的 26:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 21 的 26:Payee.sol
pragma solidity ^0.8.0;
struct Payee {
address account;
uint32 shares;
}
文件 22 的 26:Price.sol
pragma solidity ^0.8.0;
struct Price {
uint256 eth;
uint256 currency;
uint256 ethExternalCall;
uint256 currencyExternalCall;
}
文件 23 的 26:ProductParams.sol
pragma solidity ^0.8.0;
import "./SubSlicerProduct.sol";
import "./CurrencyPrice.sol";
struct ProductParams {
SubSlicerProduct[] subSlicerProducts;
CurrencyPrice[] currencyPrices;
bytes data;
bytes purchaseData;
uint32 availableUnits;
uint8 maxUnitsPerBuyer;
bool isFree;
bool isInfinite;
}
文件 24 的 26:PurchaseParams.sol
pragma solidity ^0.8.0;
struct PurchaseParams {
uint128 slicerId;
uint32 quantity;
address currency;
uint32 productId;
bytes buyerCustomData;
}
文件 25 的 26:SlicerPurchasable.sol
pragma solidity ^0.8.0;
import "./interfaces/ISlicerPurchasable.sol";
abstract contract SlicerPurchasable is ISlicerPurchasable {
error WrongSlicer();
error NotPurchase();
error NotAllowed();
error NotSuccessful();
address internal _productsModuleAddress;
uint256 internal _slicerId;
modifier onlyOnPurchaseFrom(uint256 slicerId) {
_onlyOnPurchaseFrom(slicerId);
_;
}
function _onlyOnPurchaseFrom(uint256 slicerId) internal view virtual {
if (_slicerId != slicerId) revert WrongSlicer();
if (msg.sender != _productsModuleAddress) revert NotPurchase();
}
function isPurchaseAllowed(uint256, uint256, address, uint256, bytes memory, bytes memory)
public
view
virtual
override
returns (bool)
{
return true;
}
function onProductPurchase(
uint256 slicerId,
uint256 productId,
address buyer,
uint256 quantity,
bytes memory slicerCustomData,
bytes memory buyerCustomData
) public payable virtual override onlyOnPurchaseFrom(slicerId) {
if (!isPurchaseAllowed(slicerId, productId, buyer, quantity, slicerCustomData, buyerCustomData)) {
revert NotAllowed();
}
}
}
文件 26 的 26:SubSlicerProduct.sol
pragma solidity ^0.8.0;
struct SubSlicerProduct {
uint128 subSlicerId;
uint32 subProductId;
}
{
"compilationTarget": {
"src/onchainSummer/BasedMerch/BaseCafe_Compass.sol": "BaseCafe_Compass_SliceHook"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [
":@erc721a-upgradeable/=lib/ERC721A-Upgradeable/",
":@erc721a/=lib/ERC721A/",
":@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":@solady/=lib/solady/src/",
":@solmate/=lib/solmate/src/",
":ERC721A-Upgradeable/=lib/ERC721A-Upgradeable/contracts/",
":ERC721A/=lib/ERC721A/contracts/",
":dn404/=lib/dn404/src/",
":ds-test/=lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":murky/=lib/dn404/lib/murky/",
":openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/",
":solady/=lib/solady/src/",
":solmate/=lib/solmate/src/"
],
"viaIR": true
}
[{"inputs":[{"internalType":"address","name":"productsModuleAddress_","type":"address"},{"internalType":"uint256","name":"slicerId_","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"NotAllowed","type":"error"},{"inputs":[],"name":"NotPurchase","type":"error"},{"inputs":[],"name":"NotSuccessful","type":"error"},{"inputs":[],"name":"WrongSlicer","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"MINT_NFT_COLLECTION","outputs":[{"internalType":"contract ITokenERC1155","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MINT_NFT_TOKEN_ID","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"slicerId","type":"uint256"}],"name":"allowedSlicerIds","outputs":[{"internalType":"bool","name":"allowed","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"isPurchaseAllowed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"slicerId","type":"uint256"},{"internalType":"uint256","name":"productId","type":"uint256"},{"internalType":"address","name":"buyer","type":"address"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onProductPurchase","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"slicerId","type":"uint256"},{"internalType":"uint256","name":"productId","type":"uint256"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"address","name":"buyer","type":"address"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"productPrice","outputs":[{"internalType":"uint256","name":"ethPrice","type":"uint256"},{"internalType":"uint256","name":"currencyPrice","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"slicerId","type":"uint256"},{"internalType":"uint256","name":"productId","type":"uint256"}],"name":"productPrices","outputs":[{"internalType":"uint64","name":"usdcPrice","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"slicerId","type":"uint256"},{"internalType":"uint256","name":"productId","type":"uint256"}],"name":"productsDiscount","outputs":[{"internalType":"bool","name":"discountClaimable","type":"bool"},{"internalType":"bool","name":"discountClaimed","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"slicerId","type":"uint256"},{"internalType":"bool","name":"allowed","type":"bool"}],"name":"setAllowedSlicerId","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"slicerId","type":"uint256"},{"internalType":"uint256","name":"productId","type":"uint256"},{"internalType":"uint64","name":"price","type":"uint64"}],"name":"setPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"slicerId","type":"uint256"},{"internalType":"uint256","name":"productId","type":"uint256"},{"internalType":"bool","name":"isDiscounted","type":"bool"}],"name":"setProductDiscount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]