MarketplaceFacet
Inherits: ReentrancyGuard, IMarketplace
Author: Cujo, Tufnel_Enterprises
Contains the logic for creating and interacting with listings for the marketplace.
Functions
createListing
This function creates a new listing and returns the resulting listing ID
function createListing(
address token,
uint256 amount,
uint256 unitPrice,
uint256 minFillAmount,
uint256 deadline
)
external
override
nonReentrant
returns (bytes32 id);
Parameters
| Name | Type | Description |
|---|---|---|
token | address | The token being listed |
amount | uint256 | The amount to be listed |
unitPrice | uint256 | The unit price in USDC to list. Should be provided in full form so a price of 2.5 USDC = input of 2500000 |
minFillAmount | uint256 | The minimum number of tons needed to be purchased to fill this listing |
deadline | uint256 | The block timestamp at which this listing will expire |
Returns
| Name | Type | Description |
|---|---|---|
id | bytes32 | The ID of the listing that was created |
createListing
This function creates a new listing and returns the resulting listing ID
function createListing(
address token,
uint256 tokenId,
uint256 amount,
uint256 unitPrice,
uint256 minFillAmount,
uint256 deadline
)
external
override
nonReentrant
returns (bytes32 id);
Parameters
| Name | Type | Description |
|---|---|---|
token | address | The token being listed |
tokenId | uint256 | |
amount | uint256 | The amount to be listed |
unitPrice | uint256 | The unit price in USDC to list. Should be provided in full form so a price of 2.5 USDC = input of 2500000 |
minFillAmount | uint256 | The minimum number of tons needed to be purchased to fill this listing |
deadline | uint256 | The block timestamp at which this listing will expire |
Returns
| Name | Type | Description |
|---|---|---|
id | bytes32 | The ID of the listing that was created |
_createListing
function _createListing(
address token,
uint256 tokenId,
uint256 amount,
uint256 unitPrice,
uint256 minFillAmount,
uint256 deadline,
Storage.TokenType tokenType
)
internal
returns (bytes32 id);
updateListing
This function takes an old listing and replaces it with an updated listing
function updateListing(
bytes32 id,
uint256 newAmount,
uint256 newUnitPrice,
uint256 newMinFillAmount,
uint256 newDeadline
)
external
override
nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
id | bytes32 | The listing ID to update |
newAmount | uint256 | The amount for the new listing |
newUnitPrice | uint256 | The unit price for the new listing |
newMinFillAmount | uint256 | The minFillAmount for the new listing |
newDeadline | uint256 | The deadline for the new listing |
cancelListing
This function cancels an existing listing
function cancelListing(bytes32 id) external override nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
id | bytes32 | The listing ID to cancel |
fillListing
This function fills an existing listing
function fillListing(
bytes32 id,
address listingAccount,
address listingToken,
uint256 listingUnitPrice,
uint256 amount,
uint256 maxCost
)
external
override
nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
id | bytes32 | The listing ID to update |
listingAccount | address | The account that created the listing you are filling |
listingToken | address | The token you are swapping for |
listingUnitPrice | uint256 | The unit price per token to fill the listing |
amount | uint256 | Amount of the listing to fill |
maxCost | uint256 | Maximum cost in USDC for filling this listing |
_hashListing
function _hashListing(
address account,
uint256 tokenId,
address token,
uint256 increment
)
internal
pure
returns (bytes32 lHash);
_checkListingToken
function _checkListingToken(address token) internal returns (Storage.TokenType);
_getERC20BalanceAndAllowance
function _getERC20BalanceAndAllowance(
address token,
address account,
uint256 potentialListingAmount
)
internal
view
returns (uint256 balance, uint256 allowance);
_getERC1155BalanceAndAllowance
function _getERC1155BalanceAndAllowance(
address token,
address account,
uint256 tokenId,
uint256 potentialListingAmount
)
internal
view
returns (uint256 balance, bool approval);
getListingOwner
function getListingOwner(bytes32 id) external view returns (address);
getUnitPrice
function getUnitPrice(bytes32 id) external view returns (uint256);
getRemainingAmount
function getRemainingAmount(bytes32 id) external view returns (uint256);
getListingDeadline
function getListingDeadline(bytes32 id) external view returns (uint256);
getListingTotalByCredit
function getListingTotalByCredit(address account, address token, uint256 tokenId) external view returns (uint256);