// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
mapping(bytes32 role => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with an {AccessControlUnauthorizedAccount} error including the required role.
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
return _roles[role].hasRole[account];
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
* is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
* is missing `role`.
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
if (!hasRole(role, account)) {
_roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
/**
* @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/IAccessControl.sol)
pragma solidity ^0.8.20;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev The `account` is missing a role.
*/
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
/**
* @dev The caller of a function is not the expected one.
*
* NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
*/
error AccessControlBadConfirmation();
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*/
function renounceRole(bytes32 role, address callerConfirmation) external;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
error PriceMustBeAboveZero();
error AlreadyListed(address collectionAddress, address tokenAddress, uint256 tokenId);
error NotListed(address collectionAddress, address tokenAddress, uint256 tokenId);
error CallerNotAdmin(address caller);
error CallerNotOperator(address caller);
error InvalidAddress(address _address);
error DuplicateListId();
error ListAlreadyExists();
error ListingCannotBeCancelled();
error ListingNotAvailable(bytes32 _listingId);
address constant ZEROADDRESS = address(0x0);
enum ListingState {
NONE,
LISTED,
PAID,
RELEASED,
CANCELLED
}
contract StackrListings is AccessControl {
struct Listing {
bytes32 listingId;
address collectionAddress;
address tokenAddress;
uint256 tokenId;
address seller;
uint256 price;
address payToken;
uint256 payTokenPrice;
address buyer;
ListingState state;
uint256 sellerBurnFeeRate;
uint256 buyerBurnFeeRate;
}
//////////////////////
// Events //
//////////////////////
event ItemListed(
bytes32 listingId,
address indexed collectionAddress,
address tokenAddress,
uint256 tokenId,
address indexed seller,
string sellerAuthToken,
uint256 price,
address indexed payToken,
uint256 payTokenPrice,
string pricingSource
);
event ItemBought(bytes32 listingId, address indexed buyer, string buyerAuthToken, uint256 price, address indexed payToken);
event ItemCanceled(bytes32 listingId, address indexed seller, bool priceReturned);
event BuyCanceled(bytes32 listingId, address indexed buyer, uint256 amountReturned);
event ItemReleased(bytes32 listingId, address indexed seller, uint256 price, address payToken);
event feePaid(bytes32 listingId, address wallet, uint256 fee, address payToken);
event royaltyFeePaid(bytes32 listingId, address wallet, uint256 fee, address payToken);
event burnFeePaid(bytes32 listingId, address wallet, uint256 fee, address payToken);
event SellerBurnRateChanged(uint256 oldRate, uint256 newRate);
event BuyerBurnRateChanged(uint256 oldRate, uint256 newRate);
//////////////////////
// Variables //
//////////////////////
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
address public feeWallet;
address public burnWallet;
uint256 public sellerBurnFeeRate;
uint256 public buyerBurnFeeRate;
mapping(bytes32 _listingId => Listing) public allListings;
mapping(bytes32 hash => bytes32) public listingsRegistry;
modifier isListed(bytes32 _listingId) {
Listing memory listing = allListings[_listingId];
if (listing.state != ListingState.LISTED && listing.state != ListingState.PAID) {
revert NotListed(listing.collectionAddress, listing.tokenAddress, listing.tokenId);
}
_;
}
modifier onlyAdmin() {
if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {
revert CallerNotAdmin(msg.sender);
}
_;
}
modifier onlyOperator() {
if (!hasRole(OPERATOR_ROLE, msg.sender)) {
revert CallerNotOperator(msg.sender);
}
_;
}
constructor(
address _feeWallet,
address _burnWallet,
uint256 _sellerBurnFeeRate,
uint256 _buyerBurnFeeRate
) {
feeWallet = _feeWallet;
burnWallet = _burnWallet;
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(OPERATOR_ROLE, msg.sender);
sellerBurnFeeRate = _sellerBurnFeeRate;
buyerBurnFeeRate = _buyerBurnFeeRate;
}
////////////////////////
// Action Functions ///
///////////////////////
function listItem(
bytes32 listingId,
address collectionAddress,
address tokenAddress,
uint256 tokenId,
address seller,
string memory sellerAuthToken,
uint256 price,
address payToken,
uint256 payTokenPrice,
string memory pricingSource
) external onlyOperator {
if (collectionAddress == ZEROADDRESS) revert InvalidAddress(collectionAddress);
if (tokenAddress == ZEROADDRESS) revert InvalidAddress(tokenAddress);
if (payToken == ZEROADDRESS) revert InvalidAddress(payToken);
if (duplicateListId(listingId)) {
revert DuplicateListId();
}
bytes32 listHash = keccak256(abi.encodePacked(collectionAddress, tokenAddress, tokenId));
if (listingExists(listHash)) {
revert ListAlreadyExists();
}
if (price <= 0) {
revert PriceMustBeAboveZero();
}
allListings[listingId] = Listing(
listingId,
collectionAddress,
tokenAddress,
tokenId,
seller,
price,
payToken,
payTokenPrice,
ZEROADDRESS,
ListingState.LISTED,
sellerBurnFeeRate,
buyerBurnFeeRate
);
listingsRegistry[listHash] = listingId;
emit ItemListed(
listingId,
collectionAddress,
tokenAddress,
tokenId,
seller,
sellerAuthToken,
price,
payToken,
payTokenPrice,
pricingSource
);
}
function cancelListing(bytes32 _listingId) external onlyOperator isListed(_listingId) {
Listing memory listedItem = allListings[_listingId];
if (listedItem.state != ListingState.LISTED && listedItem.state != ListingState.PAID) {
revert ListingCannotBeCancelled();
}
if (listedItem.state == ListingState.PAID) {
allListings[_listingId].state = ListingState.CANCELLED;
uint256 buyerBurnFeeAmount = (listedItem.buyerBurnFeeRate * listedItem.price) / 10000;
require(
IERC20(listedItem.payToken).transfer(listedItem.buyer, listedItem.price + buyerBurnFeeAmount),
"Transfer failed"
);
} else {
allListings[_listingId].state = ListingState.CANCELLED;
}
emit ItemCanceled(listedItem.listingId, listedItem.seller, true);
resetHash(listedItem.collectionAddress, listedItem.tokenAddress, listedItem.tokenId);
}
function cancelBuy(bytes32 _listingId) external onlyOperator isListed(_listingId) {
Listing memory listedItem = allListings[_listingId];
if(listedItem.state != ListingState.PAID) revert ListingCannotBeCancelled();
uint256 buyerBurnFeeAmount = (listedItem.buyerBurnFeeRate * listedItem.price) / 10000;
allListings[_listingId].state = ListingState.LISTED;
require(
IERC20(listedItem.payToken).transfer(listedItem.buyer, listedItem.price + buyerBurnFeeAmount),
"Transfer failed"
);
emit BuyCanceled(listedItem.listingId, listedItem.buyer, listedItem.price);
}
function buyItem(bytes32 _listingId, string memory buyerAuthToken) external payable isListed(_listingId) {
Listing memory listedItem = allListings[_listingId];
if(listedItem.state != ListingState.LISTED) revert ListingNotAvailable(_listingId);
allListings[_listingId].state = ListingState.PAID;
allListings[_listingId].buyer = msg.sender;
uint256 burnFeeAmount = (listedItem.buyerBurnFeeRate * listedItem.price) / 10000;
require(
IERC20(listedItem.payToken).transferFrom(msg.sender, address(this), listedItem.price + burnFeeAmount),
"Transfer from buyer failed"
);
emit ItemBought(listedItem.listingId, msg.sender, buyerAuthToken, listedItem.price, listedItem.payToken);
}
function releaseProceeds(
bytes32 _listingId,
uint256 feeRate,
uint256 royaltyFeeRate,
address royaltyWallet
) external onlyOperator {
Listing memory listedItem = allListings[_listingId];
require(listedItem.state == ListingState.PAID, "Hasn't been paid or already released");
allListings[_listingId].state = ListingState.RELEASED;
uint256 fee = feeRate > 0 ? (listedItem.price * feeRate) / 10000 : 0;
if (fee > 0) {
require(IERC20(listedItem.payToken).transfer(feeWallet, fee), "Transfer of fee failed");
emit feePaid(listedItem.listingId, feeWallet, fee, listedItem.payToken);
}
uint256 royaltyFee = royaltyFeeRate > 0 ? (listedItem.price * royaltyFeeRate) / 10000 : 0;
if (royaltyFee > 0) {
require(IERC20(listedItem.payToken).transfer(royaltyWallet, royaltyFee), "Transfer of royaltyFee failed");
emit royaltyFeePaid(listedItem.listingId, royaltyWallet, royaltyFee, listedItem.payToken);
}
uint256 selletBurnFee = sellerBurnFeeRate > 0 ? (listedItem.price * sellerBurnFeeRate) / 10000 : 0;
if (selletBurnFee > 0) {
require(IERC20(listedItem.payToken).transfer(burnWallet, selletBurnFee), "Transfer of burnFee failed");
emit burnFeePaid(listedItem.listingId, burnWallet, selletBurnFee, listedItem.payToken);
}
uint256 buyerBurnFeeAmount = (listedItem.buyerBurnFeeRate * listedItem.price) / 10000;
if (buyerBurnFeeAmount > 0) {
require(
IERC20(listedItem.payToken).transfer(burnWallet, buyerBurnFeeAmount),
"Transfer of burn fee failed"
);
emit burnFeePaid(listedItem.listingId, burnWallet, buyerBurnFeeAmount, listedItem.payToken);
}
require(
IERC20(listedItem.payToken).transfer(listedItem.seller, listedItem.price - fee - royaltyFee - selletBurnFee),
"Transfer to seller failed"
);
emit ItemReleased(listedItem.listingId, listedItem.seller, listedItem.price, listedItem.payToken);
resetHash(listedItem.collectionAddress, listedItem.tokenAddress, listedItem.tokenId);
}
function resetHash(
address collectionAddress,
address tokenAddress,
uint256 tokenId
) internal {
bytes32 listHash = keccak256(abi.encodePacked(collectionAddress, tokenAddress, tokenId));
delete listingsRegistry[listHash];
}
/////////////////////
// Admin Functions //
/////////////////////
function changeSellerBurnFee(uint256 _sellerBurnFeeRate) external onlyAdmin {
uint256 oldRate = sellerBurnFeeRate;
sellerBurnFeeRate = _sellerBurnFeeRate;
emit SellerBurnRateChanged(oldRate, _sellerBurnFeeRate);
}
function changeBuyerBurnFee(uint256 _buyerBurnFeeRate) external onlyAdmin {
uint256 oldRate = buyerBurnFeeRate;
buyerBurnFeeRate = _buyerBurnFeeRate;
emit BuyerBurnRateChanged(oldRate, _buyerBurnFeeRate);
}
function changeFeeWallet(address _feeWallet) external onlyAdmin {
feeWallet = _feeWallet;
}
function changeBurnWallet(address _burnWallet) external onlyAdmin {
burnWallet = _burnWallet;
}
function withdraw() external onlyAdmin {
payable(msg.sender).transfer(address(this).balance);
}
//////////////////////
// Getter Functions //
//////////////////////
function getListingById(bytes32 _listingId) external view returns (Listing memory) {
return allListings[_listingId];
}
function getListingByToken(address collectionAddress, address tokenAddress, uint256 tokenId)
external
view
returns (Listing memory)
{
bytes32 hash = keccak256(abi.encodePacked(collectionAddress, tokenAddress, tokenId));
bytes32 listId = listingsRegistry[hash];
return allListings[listId];
}
function listingExists(bytes32 listHash) public view returns (bool) {
return listingsRegistry[listHash] != bytes32(0);
}
function duplicateListId(bytes32 listingId) public view returns (bool) {
return allListings[listingId].listingId == listingId;
}
}
{
"compilationTarget": {
"src/Listing.sol": "StackrListings"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [
":@openzeppelin-contracts/=lib/openzeppelin-contracts/",
":@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":foundry-devops/=lib/foundry-devops/",
":openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
":solidity-stringutils/=lib/openzeppelin-foundry-upgrades/lib/solidity-stringutils/"
]
}
[{"inputs":[{"internalType":"address","name":"_feeWallet","type":"address"},{"internalType":"address","name":"_burnWallet","type":"address"},{"internalType":"uint256","name":"_sellerBurnFeeRate","type":"uint256"},{"internalType":"uint256","name":"_buyerBurnFeeRate","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessControlBadConfirmation","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}],"name":"AccessControlUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"CallerNotAdmin","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"CallerNotOperator","type":"error"},{"inputs":[],"name":"DuplicateListId","type":"error"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"InvalidAddress","type":"error"},{"inputs":[],"name":"ListAlreadyExists","type":"error"},{"inputs":[],"name":"ListingCannotBeCancelled","type":"error"},{"inputs":[{"internalType":"bytes32","name":"_listingId","type":"bytes32"}],"name":"ListingNotAvailable","type":"error"},{"inputs":[{"internalType":"address","name":"collectionAddress","type":"address"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"NotListed","type":"error"},{"inputs":[],"name":"PriceMustBeAboveZero","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"listingId","type":"bytes32"},{"indexed":true,"internalType":"address","name":"buyer","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountReturned","type":"uint256"}],"name":"BuyCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newRate","type":"uint256"}],"name":"BuyerBurnRateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"listingId","type":"bytes32"},{"indexed":true,"internalType":"address","name":"buyer","type":"address"},{"indexed":false,"internalType":"string","name":"buyerAuthToken","type":"string"},{"indexed":false,"internalType":"uint256","name":"price","type":"uint256"},{"indexed":true,"internalType":"address","name":"payToken","type":"address"}],"name":"ItemBought","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"listingId","type":"bytes32"},{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":false,"internalType":"bool","name":"priceReturned","type":"bool"}],"name":"ItemCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"listingId","type":"bytes32"},{"indexed":true,"internalType":"address","name":"collectionAddress","type":"address"},{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":false,"internalType":"string","name":"sellerAuthToken","type":"string"},{"indexed":false,"internalType":"uint256","name":"price","type":"uint256"},{"indexed":true,"internalType":"address","name":"payToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"payTokenPrice","type":"uint256"},{"indexed":false,"internalType":"string","name":"pricingSource","type":"string"}],"name":"ItemListed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"listingId","type":"bytes32"},{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":false,"internalType":"uint256","name":"price","type":"uint256"},{"indexed":false,"internalType":"address","name":"payToken","type":"address"}],"name":"ItemReleased","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newRate","type":"uint256"}],"name":"SellerBurnRateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"listingId","type":"bytes32"},{"indexed":false,"internalType":"address","name":"wallet","type":"address"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"},{"indexed":false,"internalType":"address","name":"payToken","type":"address"}],"name":"burnFeePaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"listingId","type":"bytes32"},{"indexed":false,"internalType":"address","name":"wallet","type":"address"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"},{"indexed":false,"internalType":"address","name":"payToken","type":"address"}],"name":"feePaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"listingId","type":"bytes32"},{"indexed":false,"internalType":"address","name":"wallet","type":"address"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"},{"indexed":false,"internalType":"address","name":"payToken","type":"address"}],"name":"royaltyFeePaid","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OPERATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_listingId","type":"bytes32"}],"name":"allListings","outputs":[{"internalType":"bytes32","name":"listingId","type":"bytes32"},{"internalType":"address","name":"collectionAddress","type":"address"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"address","name":"payToken","type":"address"},{"internalType":"uint256","name":"payTokenPrice","type":"uint256"},{"internalType":"address","name":"buyer","type":"address"},{"internalType":"enum ListingState","name":"state","type":"uint8"},{"internalType":"uint256","name":"sellerBurnFeeRate","type":"uint256"},{"internalType":"uint256","name":"buyerBurnFeeRate","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"burnWallet","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_listingId","type":"bytes32"},{"internalType":"string","name":"buyerAuthToken","type":"string"}],"name":"buyItem","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"buyerBurnFeeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_listingId","type":"bytes32"}],"name":"cancelBuy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_listingId","type":"bytes32"}],"name":"cancelListing","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_burnWallet","type":"address"}],"name":"changeBurnWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_buyerBurnFeeRate","type":"uint256"}],"name":"changeBuyerBurnFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeWallet","type":"address"}],"name":"changeFeeWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_sellerBurnFeeRate","type":"uint256"}],"name":"changeSellerBurnFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"listingId","type":"bytes32"}],"name":"duplicateListId","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeWallet","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_listingId","type":"bytes32"}],"name":"getListingById","outputs":[{"components":[{"internalType":"bytes32","name":"listingId","type":"bytes32"},{"internalType":"address","name":"collectionAddress","type":"address"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"address","name":"payToken","type":"address"},{"internalType":"uint256","name":"payTokenPrice","type":"uint256"},{"internalType":"address","name":"buyer","type":"address"},{"internalType":"enum ListingState","name":"state","type":"uint8"},{"internalType":"uint256","name":"sellerBurnFeeRate","type":"uint256"},{"internalType":"uint256","name":"buyerBurnFeeRate","type":"uint256"}],"internalType":"struct StackrListings.Listing","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"collectionAddress","type":"address"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getListingByToken","outputs":[{"components":[{"internalType":"bytes32","name":"listingId","type":"bytes32"},{"internalType":"address","name":"collectionAddress","type":"address"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"address","name":"payToken","type":"address"},{"internalType":"uint256","name":"payTokenPrice","type":"uint256"},{"internalType":"address","name":"buyer","type":"address"},{"internalType":"enum ListingState","name":"state","type":"uint8"},{"internalType":"uint256","name":"sellerBurnFeeRate","type":"uint256"},{"internalType":"uint256","name":"buyerBurnFeeRate","type":"uint256"}],"internalType":"struct StackrListings.Listing","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"listingId","type":"bytes32"},{"internalType":"address","name":"collectionAddress","type":"address"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"},{"internalType":"string","name":"sellerAuthToken","type":"string"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"address","name":"payToken","type":"address"},{"internalType":"uint256","name":"payTokenPrice","type":"uint256"},{"internalType":"string","name":"pricingSource","type":"string"}],"name":"listItem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"listHash","type":"bytes32"}],"name":"listingExists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"hash","type":"bytes32"}],"name":"listingsRegistry","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_listingId","type":"bytes32"},{"internalType":"uint256","name":"feeRate","type":"uint256"},{"internalType":"uint256","name":"royaltyFeeRate","type":"uint256"},{"internalType":"address","name":"royaltyWallet","type":"address"}],"name":"releaseProceeds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"callerConfirmation","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sellerBurnFeeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]