MarketPlace

Git Source

Inherits: IMarketPlace, Context, ReentrancyGuard, Initializable, IERC777Recipient, Pausable, AccessControlEnumerable, MarketPlaceStorage

State Variables

INTERFACE_ID_ERC721

bytes4 public constant INTERFACE_ID_ERC721 = 0x80ac58cd;

INTERFACE_ID_ERC2981

bytes4 public constant INTERFACE_ID_ERC2981 = 0x2a55205a;

ADMIN_ROLE

bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");

ERC1820_REGISTRY

IERC1820Registry public constant ERC1820_REGISTRY = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);

TOKENS_RECIPIENT_INTERFACE_HASH

bytes32 public constant TOKENS_RECIPIENT_INTERFACE_HASH = keccak256("ERC777TokensRecipient");

Functions

validPayToken

modifier validPayToken(address payToken);

validDeadline

modifier validDeadline(uint256 deadline);

validPrice

modifier validPrice(uint256 price);

constructor

constructor();

initialize

Initializes the MarketPlace, setting the WCSB contract address.

function initialize(address wcsb_, address mira_, address admin) external override initializer;

Parameters

NameTypeDescription
wcsb_addressThe address of WCSB contract.
mira_addressThe address of MIRA contract.
adminaddressThe address of the contract admin.

pause

Pauses interaction with the contract. Requirements:

  • The caller must have the ADMIN_ROLE.
function pause() external override whenNotPaused onlyRole(ADMIN_ROLE);

unpause

Resumes interaction with the contract. Requirements:

  • The caller must have the ADMIN_ROLE.
function unpause() external override whenPaused onlyRole(ADMIN_ROLE);

tokensReceived

Called by an {IERC777} token contract whenever tokens are being moved or created into a registered account to (this contract).
Users can directly send MIRA tokens to this contract to accept an ask order, the tokensReceived method will be called by MIRA token. The userData/operatorData should be an abi encoded bytes of uint256, which represents orderId of the ask order.

function tokensReceived(
    address,
    address from,
    address to,
    uint256 amount,
    bytes calldata userData,
    bytes calldata operatorData
) external override(IERC777Recipient);

ask

Creates an ask order for an NFT. Emits the AskCreated event.

function ask(address nftAddress, uint256 tokenId, address payToken, uint256 price, uint256 deadline)
    external
    override
    whenNotPaused
    validPayToken(payToken)
    validDeadline(deadline)
    validPrice(price)
    returns (uint256 orderId);

Parameters

NameTypeDescription
nftAddressaddressThe contract address of the NFT.
tokenIduint256The token id of the NFT to be sold.
payTokenaddressThe ERC20 token address for buyers to pay.
priceuint256The sale price for the NFT.
deadlineuint256The expiration timestamp of the ask order.

Returns

NameTypeDescription
orderIduint256The id of the new generated ask order.

updateAsk

Updates an ask order. Emits the AskUpdated event.

function updateAsk(uint256 orderId, address payToken, uint256 price, uint256 deadline)
    external
    override
    whenNotPaused
    validPayToken(payToken)
    validDeadline(deadline)
    validPrice(price);

Parameters

NameTypeDescription
orderIduint256The id of the ask order to be updated.
payTokenaddressThe ERC20 token address for buyers to pay.
priceuint256The new sale price for the NFT.
deadlineuint256The new expiration timestamp of the ask order.

cancelAsk

Cancels an ask order. Emits the AskCanceled event.

function cancelAsk(uint256 orderId) external override;

Parameters

NameTypeDescription
orderIduint256The id of the ask order to be canceled.

acceptAsk

Accepts an ask order. Emits the OrdersMatched event.

The amount of CSB to send must be specified in the msg.value.

function acceptAsk(uint256 orderId) external payable override nonReentrant whenNotPaused;

Parameters

NameTypeDescription
orderIduint256The id of the ask order to be accepted.

bid

Creates a bid order for an NFT. Emits the BidCreated event.

function bid(address nftAddress, uint256 tokenId, address payToken, uint256 price, uint256 deadline)
    external
    override
    whenNotPaused
    validPayToken(payToken)
    validDeadline(deadline)
    validPrice(price)
    returns (uint256 orderId);

Parameters

NameTypeDescription
nftAddressaddressThe contract address of the NFT.
tokenIduint256The token id of the NFT to bid.
payTokenaddressThe ERC20 token address for buyers to pay.
priceuint256The bid price for the NFT.
deadlineuint256The expiration timestamp of the bid order.

Returns

NameTypeDescription
orderIduint256The id of the new generated bid order.

cancelBid

Cancels a bid order. Emits the BidCanceled event.

function cancelBid(uint256 orderId) external override;

Parameters

NameTypeDescription
orderIduint256The id of the bid order to be canceled.

updateBid

Updates a bid order. Emits the BidUpdated event.

function updateBid(uint256 orderId, address payToken, uint256 price, uint256 deadline)
    external
    override
    whenNotPaused
    validPayToken(payToken)
    validDeadline(deadline)
    validPrice(price);

Parameters

NameTypeDescription
orderIduint256The id of the bid order to be updated.
payTokenaddressThe ERC20 token address for buyers to pay.
priceuint256The new bid price for the NFT.
deadlineuint256The new expiration timestamp of the ask order.

acceptBid

Accepts a bid order. Emits the OrdersMatched event.

function acceptBid(uint256 orderId) external override nonReentrant whenNotPaused;

Parameters

NameTypeDescription
orderIduint256The id of the bid order to be accepted.

getAskOrder

Gets the detail info of an ask order.

function getAskOrder(uint256 orderId) external view override returns (DataTypes.Order memory);

Parameters

NameTypeDescription
orderIduint256The id of the ask order to query.

getBidOrder

Gets the detail info of a bid order.

function getBidOrder(uint256 orderId) external view override returns (DataTypes.Order memory);

Parameters

NameTypeDescription
orderIduint256The id of the bid order to query.

getAskOrderId

Gets ID of an ask order .

function getAskOrderId(address nftAddress, uint256 tokenId, address owner)
    external
    view
    override
    returns (uint256 orderId);

Parameters

NameTypeDescription
nftAddressaddressThe contract address of the NFT.
tokenIduint256The token id of the NFT to be sold.
owneraddressThe owner who creates the order.

getBidOrderId

Gets ID of a bid order.

function getBidOrderId(address nftAddress, uint256 tokenId, address owner)
    external
    view
    override
    returns (uint256 orderId);

Parameters

NameTypeDescription
nftAddressaddressThe contract address of the NFT.
tokenIduint256The token id of the NFT to bid.
owneraddressThe owner who creates the order.

wcsb

Returns the address of WCSB contract.

function wcsb() external view override returns (address);

Returns

NameTypeDescription
<none>addressThe address of WCSB contract.

mira

Returns the address of MIRA contract.

function mira() external view override returns (address);

Returns

NameTypeDescription
<none>addressThe address of MIRA contract.

_pay

function _pay(
    address from,
    address to,
    address payToken,
    uint256 amount,
    address royaltyReceiver,
    uint256 royaltyAmount,
    uint256 erc777Amount
) internal;

_acceptAsk

function _acceptAsk(uint256 orderId, address buyer, uint256 erc777Amount) internal whenNotPaused;

_payCSBWithRoyalty

function _payCSBWithRoyalty(address to, uint256 amount, address royaltyReceiver, uint256 royaltyAmount) internal;

_payERC777WithRoyalty

function _payERC777WithRoyalty(
    address to,
    address token,
    uint256 amount,
    address royaltyReceiver,
    uint256 royaltyAmount,
    uint256 erc777Amount
) internal;

_payERC20WithRoyalty

function _payERC20WithRoyalty(
    address from,
    address to,
    address token,
    uint256 amount,
    address royaltyReceiver,
    uint256 royaltyAmount
) internal;

_royaltyInfo

function _royaltyInfo(address nftAddress, uint256 tokenId, uint256 salePrice)
    internal
    view
    returns (address royaltyReceiver, uint256 royaltyAmount);

_now

function _now() internal view virtual returns (uint256);