MarketplaceFacet

Git Source

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

NameTypeDescription
tokenaddressThe token being listed
amountuint256The amount to be listed
unitPriceuint256The unit price in USDC to list. Should be provided in full form so a price of 2.5 USDC = input of 2500000
minFillAmountuint256The minimum number of tons needed to be purchased to fill this listing
deadlineuint256The block timestamp at which this listing will expire

Returns

NameTypeDescription
idbytes32The 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

NameTypeDescription
tokenaddressThe token being listed
tokenIduint256
amountuint256The amount to be listed
unitPriceuint256The unit price in USDC to list. Should be provided in full form so a price of 2.5 USDC = input of 2500000
minFillAmountuint256The minimum number of tons needed to be purchased to fill this listing
deadlineuint256The block timestamp at which this listing will expire

Returns

NameTypeDescription
idbytes32The 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

NameTypeDescription
idbytes32The listing ID to update
newAmountuint256The amount for the new listing
newUnitPriceuint256The unit price for the new listing
newMinFillAmountuint256The minFillAmount for the new listing
newDeadlineuint256The deadline for the new listing

cancelListing

This function cancels an existing listing

function cancelListing(bytes32 id) external override nonReentrant;

Parameters

NameTypeDescription
idbytes32The 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

NameTypeDescription
idbytes32The listing ID to update
listingAccountaddressThe account that created the listing you are filling
listingTokenaddressThe token you are swapping for
listingUnitPriceuint256The unit price per token to fill the listing
amountuint256Amount of the listing to fill
maxCostuint256Maximum 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);