Crossbell xShop contracts

Docs lint tests checks codecov MythXBadge

⚙ Development

Install foundry if you don't have one:

# install foundry
curl -L https://foundry.paradigm.xyz | bash
foundryup

Compile and run tests:

yarn
yarn test

Deploy

forge script scripts/Deploy.s.sol:Deploy --private-key $PRIVATE_KEY --broadcast --legacy --rpc-url $RPC_URL --ffi                   
forge script scripts/Deploy.s.sol:Deploy --sig 'sync()' --private-key $PRIVATE_KEY --broadcast --legacy --rpc-url $RPC_URL --ffi

Contents

IERC20Mintable

Git Source

Functions

mint

function mint(address to, uint256 amount) external;

IMarketPlace

Git Source

Functions

initialize

Initializes the MarketPlace, setting the WCSB contract address.

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

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;

unpause

Resumes interaction with the contract. Requirements:

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

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
    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;

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;

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;

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
    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;

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;

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;

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 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 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 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 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 returns (address);

Returns

NameTypeDescription
<none>addressThe address of WCSB contract.

mira

Returns the address of MIRA contract.

function mira() external view returns (address);

Returns

NameTypeDescription
<none>addressThe address of MIRA contract.

ISwap

Git Source

Functions

initialize

Initializes the MarketPlace, setting the WCSB contract address.

function initialize(address mira_, uint256 minCsb_, uint256 minMira_, address admin) external;

Parameters

NameTypeDescription
mira_addressThe address of MIRA contract.
minCsb_uint256The minimum amount of CSB to sell.
minMira_uint256The minimum amount of MIRA to sell.
adminaddressThe address of the contract admin.

pause

Pauses interaction with the contract. Requirements:

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

unpause

Resumes interaction with the contract. Requirements:

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

setMinMira

Sets the minimum amount of MIRA to sell.

function setMinMira(uint256 minMira_) external;

Parameters

NameTypeDescription
minMira_uint256The minimum amount of MIRA to sell.

setMinCsb

Sets the minimum amount of CSB to sell.

function setMinCsb(uint256 minCsb_) external;

Parameters

NameTypeDescription
minCsb_uint256The minimum amount of CSB to sell.

sellMIRA

Sells MIRA for CSB. Creates a SellOrder and emits the SellMIRA event.

function sellMIRA(uint256 miraAmount, uint256 expectedCsbAmount) external returns (uint256 orderId);

Parameters

NameTypeDescription
miraAmountuint256The amount of MIRA to sell.
expectedCsbAmountuint256The expected amount of CSB to receive.

Returns

NameTypeDescription
orderIduint256The new created order id.

sellCSB

Sells CSB for MIRA. Creates a SellOrder and emits the SellCSB event.

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

function sellCSB(uint256 expectedMiraAmount) external payable returns (uint256 orderId);

Parameters

NameTypeDescription
expectedMiraAmountuint256The expected amount of MIRA to receive.

Returns

NameTypeDescription
orderIduint256The new created order id.

cancelOrder

Cancels a sell order and refunds to the seller. Deletes a given SellOrder and emits the SellOrderCanceled event.

function cancelOrder(uint256 orderId) external;

Parameters

NameTypeDescription
orderIduint256The order id to cancel.

acceptOrder

Accepts a sell order and transfers the tokens to the traders. Deletes a given SellOrder and emits the SellOrderMatched event.

function acceptOrder(uint256 orderId) external payable;

Parameters

NameTypeDescription
orderIduint256The order id to accept.

getOrder

Returns the SellOrder struct of a given order id.

function getOrder(uint256 orderId) external view returns (DataTypes.SellOrder memory);

Parameters

NameTypeDescription
orderIduint256The order id to get.

Returns

NameTypeDescription
<none>DataTypes.SellOrderorder The SellOrder struct.

mira

Returns the address of MIRA contract.

function mira() external view returns (address);

Returns

NameTypeDescription
<none>addressThe address of MIRA contract.

getMinMira

Returns the minimum amount of MIRA to sell.

function getMinMira() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256The minimum amount of MIRA to sell.

getMinCsb

Returns the minimum amount of CSB to sell.

function getMinCsb() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256The minimum amount of CSB to sell.

IWCSB

Git Source

Functions

deposit

function deposit() external payable;

transfer

function transfer(address to, uint256 value) external returns (bool);

withdraw

function withdraw(uint256) external;

Contents

DataTypes

Git Source

A standard library of data types.

Structs

Order

A struct containing the information of an NFT order.

struct Order {
    address owner;
    address nftAddress;
    uint256 tokenId;
    address payToken;
    uint256 price;
    uint256 deadline;
}

SellOrder

A struct containing the information of a token sell order.

struct SellOrder {
    address owner;
    uint8 orderType;
    uint256 miraAmount;
    uint256 csbAmount;
}

Events

Git Source

Events

AskCreated

Emitted when an ask order is created.

event AskCreated(
    uint256 indexed orderId,
    address indexed owner,
    address indexed nftAddress,
    uint256 tokenId,
    address payToken,
    uint256 price,
    uint256 deadline
);

AskUpdated

Emitted when an ask order is updated.

event AskUpdated(uint256 indexed orderId, address indexed payToken, uint256 indexed price, uint256 deadline);

AskCanceled

Emitted when an ask order is canceled.

event AskCanceled(uint256 indexed orderId);

BidCreated

Emitted when a bid order is created.

event BidCreated(
    uint256 indexed orderId,
    address indexed owner,
    address indexed nftAddress,
    uint256 tokenId,
    address payToken,
    uint256 price,
    uint256 deadline
);

BidCanceled

Emitted when a bid order is canceled.

event BidCanceled(uint256 indexed orderId);

BidUpdated

Emitted when a bid order is updated.

event BidUpdated(uint256 indexed orderId, address indexed payToken, uint256 indexed price, uint256 deadline);

AskMatched

Emitted when a ask order is accepted(matched).

event AskMatched(
    uint256 indexed orderId,
    address indexed owner,
    address indexed buyer,
    address nftAddress,
    uint256 tokenId,
    address payToken,
    uint256 price,
    address royaltyReceiver,
    uint256 royaltyAmount
);

BidMatched

Emitted when a bid order is accepted(matched).

event BidMatched(
    uint256 indexed orderId,
    address indexed owner,
    address indexed seller,
    address nftAddress,
    uint256 tokenId,
    address payToken,
    uint256 price,
    address royaltyReceiver,
    uint256 royaltyAmount
);

SellMIRA

event SellMIRA(address indexed owner, uint256 indexed miraAmount, uint256 indexed csbAmount, uint256 orderId);

SellCSB

event SellCSB(address indexed owner, uint256 indexed csbAmount, uint256 indexed miraAmount, uint256 orderId);

SellOrderCanceled

event SellOrderCanceled(uint256 indexed orderId);

SellOrderMatched

event SellOrderMatched(uint256 indexed orderId, address indexed buyer);

Contents

MiraToken

Git Source

Inherits: AccessControlEnumerable, IERC20Mintable, ERC777

State Variables

BLOCK_ROLE

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

Functions

constructor

constructor(string memory name_, string memory symbol_, address admin) ERC777(name_, symbol_, new address[](0));

mint

*Creates amount new tokens for to. Requirements:

  • the caller must have the DEFAULT_ADMIN_ROLE.*
function mint(address to, uint256 amount) external override onlyRole(DEFAULT_ADMIN_ROLE);

renounceRole

*Revokes role from the calling account. Requirements:

  • the caller must have the DEFAULT_ADMIN_ROLE.*
function renounceRole(bytes32 role, address account)
    public
    override(AccessControl, IAccessControl)
    onlyRole(DEFAULT_ADMIN_ROLE);

_send

Blocks send tokens from account from who has the BLOCK_ROLE.

function _send(
    address from,
    address to,
    uint256 amount,
    bytes memory userData,
    bytes memory operatorData,
    bool requireReceptionAck
) internal override;

_burn

Disables burn

function _burn(address, uint256, bytes memory, bytes memory) internal pure override;

NFT

Git Source

Inherits: ERC721Enumerable, ERC2981

State Variables

_tokenCounter

uint256 internal _tokenCounter;

Functions

constructor

constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_);

mint

function mint(address to) external returns (uint256 tokenId);

setTokenRoyalty

function setTokenRoyalty(uint256 tokenId, address recipient, uint96 fraction) external;

setDefaultRoyalty

function setDefaultRoyalty(address recipient, uint96 fraction) external;

deleteDefaultRoyalty

function deleteDefaultRoyalty() external;

supportsInterface

function supportsInterface(bytes4 interfaceId) public view virtual override(ERC2981, ERC721Enumerable) returns (bool);

totalSupply

function totalSupply() public view override returns (uint256);

NFT1155

Git Source

Inherits: ERC1155

Functions

constructor

constructor() ERC1155("https://ipfsxxxx");

mint

function mint(address to) public;

WCSB

Git Source

State Variables

name

string public name = "Wrapped CSB";

symbol

string public symbol = "WCSB";

decimals

uint8 public decimals = 18;

balanceOf

mapping(address => uint256) public balanceOf;

allowance

mapping(address => mapping(address => uint256)) public allowance;

Functions

receive

receive() external payable;

deposit

function deposit() public payable;

withdraw

function withdraw(uint256 wad) public;

totalSupply

function totalSupply() public view returns (uint256);

approve

function approve(address guy, uint256 wad) public returns (bool);

transfer

function transfer(address dst, uint256 wad) public returns (bool);

transferFrom

function transferFrom(address src, address dst, uint256 wad) public returns (bool);

Events

Approval

event Approval(address indexed src, address indexed guy, uint256 wad);

Transfer

event Transfer(address indexed src, address indexed dst, uint256 wad);

Deposit

event Deposit(address indexed dst, uint256 wad);

Withdrawal

event Withdrawal(address indexed src, uint256 wad);

Contents

MarketPlaceStorage

Git Source

State Variables

_wcsb

address internal _wcsb;

_mira

address internal _mira;

_askOrderCount

uint256 internal _askOrderCount;

_askOrders

mapping(uint256 askOrderId => DataTypes.Order askOrder) internal _askOrders;

_askOrderIds

mapping(address nftAddress => mapping(uint256 tokenId => mapping(address owner => uint256 askOrderId))) internal
    _askOrderIds;

_bidOrderCount

uint256 internal _bidOrderCount;

_bidOrders

mapping(uint256 bidOrderId => DataTypes.Order bidOrder) internal _bidOrders;

_bidOrderIds

mapping(address nftAddress => mapping(uint256 tokenId => mapping(address owner => uint256 bidOrderId))) internal
    _bidOrderIds;

Contents

TransparentUpgradeableProxy

Git Source

Inherits: ERC1967Proxy

*This contract implements a proxy that is upgradeable by an admin. To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector clashing], which can potentially be used in an attack, this contract uses the https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two things that go hand in hand:

  1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if that call matches one of the admin functions exposed by the proxy itself.
  2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the implementation. If the admin tries to call a function on the implementation it will fail with an error that says "admin cannot fallback to proxy target". These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changing the admin, so it's best if it's a dedicated account that is not used for anything else. This will avoid headaches due to sudden errors when trying to call a function from the proxy implementation. Our recommendation is for the dedicated account to be an instance of the {ProxyAdmin} contract. If set up this way, you should think of the ProxyAdmin instance as the real administrative interface of your proxy.*

Functions

constructor

Initializes an upgradeable proxy managed by _admin, backed by the implementation at _logic, and optionally initialized with _data as explained in {ERC1967Proxy-constructor}.

constructor(address _logic, address admin_, bytes memory _data) payable ERC1967Proxy(_logic, _data);

ifAdmin

Modifier used internally that will delegate the call to the implementation unless the sender is the admin.

modifier ifAdmin();

admin

Returns the current admin. NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyAdmin}. TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the https://eth.wiki/json-rpc/API#eth_getstorageat[eth_getStorageAt] RPC call. 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103

function admin() external ifAdmin returns (address admin_);

implementation

Returns the current implementation. NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyImplementation}. TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the https://eth.wiki/json-rpc/API#eth_getstorageat[eth_getStorageAt] RPC call. 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc

function implementation() external ifAdmin returns (address implementation_);

changeAdmin

Changes the admin of the proxy. Emits an {AdminChanged} event. NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}.

function changeAdmin(address newAdmin) external virtual ifAdmin;

upgradeTo

Upgrade the implementation of the proxy. NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}.

function upgradeTo(address newImplementation) external ifAdmin;

upgradeToAndCall

Upgrade the implementation of the proxy, and then call a function from the new implementation as specified by data, which should be an encoded function call. This is useful to initialize new storage variables in the proxied contract. NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}.

function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin;

_admin

Returns the current admin.

function _admin() internal view virtual returns (address);

_beforeFallback

Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}.

function _beforeFallback() internal virtual override;

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);

Swap

Git Source

Inherits: ISwap, Context, IERC777Recipient, Initializable, ReentrancyGuard, Pausable, AccessControlEnumerable

State Variables

_mira

address internal _mira;

_minCsb

uint256 internal _minCsb;

_minMira

uint256 internal _minMira;

_orders

mapping(uint256 orderId => DataTypes.SellOrder sellOrder) internal _orders;

_orderCount

uint256 internal _orderCount;

SELL_MIRA

uint8 public constant SELL_MIRA = 1;

SELL_CSB

uint8 public constant SELL_CSB = 2;

OPERATION_TYPE_ACCEPT_ORDER

uint256 public constant OPERATION_TYPE_ACCEPT_ORDER = 1;

OPERATION_TYPE_SELL_MIRA

uint256 public constant OPERATION_TYPE_SELL_MIRA = 2;

ERC1820_REGISTRY

IERC1820Registry public constant ERC1820_REGISTRY = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);

TOKENS_RECIPIENT_INTERFACE_HASH

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

ADMIN_ROLE

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

Functions

constructor

constructor();

initialize

Initializes the MarketPlace, setting the WCSB contract address.

function initialize(address mira_, uint256 minCsb_, uint256 minMira_, address admin) external override initializer;

Parameters

NameTypeDescription
mira_addressThe address of MIRA contract.
minCsb_uint256The minimum amount of CSB to sell.
minMira_uint256The minimum amount of MIRA to sell.
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);

setMinMira

Sets the minimum amount of MIRA to sell.

function setMinMira(uint256 minMira_) external override onlyRole(ADMIN_ROLE);

Parameters

NameTypeDescription
minMira_uint256The minimum amount of MIRA to sell.

setMinCsb

Sets the minimum amount of CSB to sell.

function setMinCsb(uint256 minCsb_) external override onlyRole(ADMIN_ROLE);

Parameters

NameTypeDescription
minCsb_uint256The minimum amount of CSB to sell.

tokensReceived

Called by an {IERC777} token contract whenever tokens are being moved or created into a registered account to (this contract).
The userData/operatorData should be an abi encoded bytes of two uint256, the first uint256 represents operation type.
opType = 1: accept an order.
opType = 2: sell MIRA for CSB.

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

Parameters

NameTypeDescription
<none>address
fromaddressThe address sending the tokens.
toaddressThe address of the recipient.
amountuint256The amount of tokens being transferred.
userDatabytesThe data provided by the token holder.
operatorDatabytesThe data provided by the operator (if any).

sellMIRA

Sells MIRA for CSB. Creates a SellOrder and emits the SellMIRA event.

function sellMIRA(uint256 miraAmount, uint256 expectedCsbAmount) external override returns (uint256 orderId);

Parameters

NameTypeDescription
miraAmountuint256The amount of MIRA to sell.
expectedCsbAmountuint256The expected amount of CSB to receive.

Returns

NameTypeDescription
orderIduint256The new created order id.

sellCSB

Sells CSB for MIRA. Creates a SellOrder and emits the SellCSB event.

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

function sellCSB(uint256 expectedMiraAmount) external payable override whenNotPaused returns (uint256 orderId);

Parameters

NameTypeDescription
expectedMiraAmountuint256The expected amount of MIRA to receive.

Returns

NameTypeDescription
orderIduint256The new created order id.

cancelOrder

Cancels a sell order and refunds to the seller. Deletes a given SellOrder and emits the SellOrderCanceled event.

function cancelOrder(uint256 orderId) external override whenNotPaused nonReentrant;

Parameters

NameTypeDescription
orderIduint256The order id to cancel.

acceptOrder

Accepts a sell order and transfers the tokens to the traders. Deletes a given SellOrder and emits the SellOrderMatched event.

function acceptOrder(uint256 orderId) external payable override;

Parameters

NameTypeDescription
orderIduint256The order id to accept.

getOrder

Returns the SellOrder struct of a given order id.

function getOrder(uint256 orderId) external view override returns (DataTypes.SellOrder memory);

Parameters

NameTypeDescription
orderIduint256The order id to get.

Returns

NameTypeDescription
<none>DataTypes.SellOrderorder The SellOrder struct.

mira

Returns the address of MIRA contract.

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

Returns

NameTypeDescription
<none>addressThe address of MIRA contract.

getMinMira

Returns the minimum amount of MIRA to sell.

function getMinMira() external view override returns (uint256);

Returns

NameTypeDescription
<none>uint256The minimum amount of MIRA to sell.

getMinCsb

Returns the minimum amount of CSB to sell.

function getMinCsb() external view override returns (uint256);

Returns

NameTypeDescription
<none>uint256The minimum amount of CSB to sell.

_sellMIRA

function _sellMIRA(address owner, uint256 miraAmount, uint256 expectedCsbAmount, bool onTokensReceived)
    internal
    nonReentrant
    whenNotPaused
    returns (uint256 orderId);

_acceptOrder

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