IMarketplace

Git Source

Title: IMarketplace

Interface for NFT marketplace with listings and offers

Supports both ERC-721 and ERC-1155 tokens with platform fees and royalties

Functions

initialize

Initializes the Marketplace contract (proxy pattern)

Sets up admin roles. Platform fees are managed by RevenueDistributor.

function initialize(address admin, address revenueDistributor) external;

Parameters

NameTypeDescription
adminaddressAddress to receive admin role
revenueDistributoraddressAddress of RevenueDistributor contract

createListing

Creates a new NFT listing

Seller must approve marketplace contract before listing

function createListing(address nftContract, uint256 tokenId, uint256 price, bool isERC721)
    external
    returns (bytes32 listingId);

Parameters

NameTypeDescription
nftContractaddressAddress of NFT contract
tokenIduint256Token ID to list
priceuint256Listing price in wei
isERC721boolWhether the NFT is ERC-721 (true) or ERC-1155 (false)

Returns

NameTypeDescription
listingIdbytes32Unique identifier for the listing

cancelListing

Cancels an active listing

Only seller can cancel their own listing

function cancelListing(bytes32 listingId) external;

Parameters

NameTypeDescription
listingIdbytes32The listing to cancel

buyListing

Buys an NFT from a listing

Transfers NFT, distributes payment with fees/royalties

function buyListing(bytes32 listingId) external payable;

Parameters

NameTypeDescription
listingIdbytes32The listing to purchase

createOffer

Creates an offer for an NFT

Offer price is held in escrow

function createOffer(address nftContract, uint256 tokenId, uint256 expiryTime)
    external
    payable
    returns (bytes32 offerId);

Parameters

NameTypeDescription
nftContractaddressAddress of NFT contract
tokenIduint256Token ID to make offer for
expiryTimeuint256Unix timestamp when offer expires

Returns

NameTypeDescription
offerIdbytes32Unique identifier for the offer

acceptOffer

Accepts an offer for an NFT

Only NFT owner can accept. Transfers NFT and distributes payment.

function acceptOffer(bytes32 offerId) external;

Parameters

NameTypeDescription
offerIdbytes32The offer to accept

cancelOffer

Cancels an offer and refunds escrowed funds

Only offer creator can cancel

function cancelOffer(bytes32 offerId) external;

Parameters

NameTypeDescription
offerIdbytes32The offer to cancel

pause

Pauses all marketplace operations

Only callable by PAUSER_ROLE

function pause() external;

unpause

Unpauses all marketplace operations

Only callable by PAUSER_ROLE

function unpause() external;

setPenaltyRate

Sets the penalty rate for late recurring payments

Only callable by admin. Penalty is calculated pro-rata per second.

function setPenaltyRate(uint256 basisPoints) external;

Parameters

NameTypeDescription
basisPointsuint256Penalty rate in basis points per month (e.g., 500 = 5% per month)

getMissedPayments

Calculates the number of missed payments for a recurring license

Returns 0 for ONE_TIME licenses

function getMissedPayments(address licenseContract, uint256 licenseId)
    external
    view
    returns (uint256 missedPayments);

Parameters

NameTypeDescription
licenseContractaddressAddress of the license token contract
licenseIduint256The license ID to check

Returns

NameTypeDescription
missedPaymentsuint256Number of missed payment periods

makeRecurringPayment

Makes a recurring payment for a subscription license

Calculates penalty for late payments, auto-revokes after 3 missed payments

function makeRecurringPayment(address licenseContract, uint256 licenseId) external payable;

Parameters

NameTypeDescription
licenseContractaddressAddress of the license token contract
licenseIduint256The license ID to pay for

getRecurringPaymentAmount

Gets the base amount for a recurring payment

function getRecurringPaymentAmount(uint256 licenseId) external view returns (uint256 baseAmount);

Parameters

NameTypeDescription
licenseIduint256The license ID

Returns

NameTypeDescription
baseAmountuint256The base payment amount (without penalty)

calculatePenalty

Calculates the current penalty for late payment

Returns 0 if payment is not overdue or for ONE_TIME licenses

No penalty if within PENALTY_GRACE_PERIOD (3 days) of dueDate

Penalties only start accruing after dueDate + PENALTY_GRACE_PERIOD

function calculatePenalty(address licenseContract, uint256 licenseId) external view returns (uint256 penalty);

Parameters

NameTypeDescription
licenseContractaddressAddress of the license token contract
licenseIduint256The license ID

Returns

NameTypeDescription
penaltyuint256Penalty amount in wei (0 if within grace period)

getTotalPaymentDue

Gets the total amount due for next recurring payment (base + penalty)

Useful for frontends to know exact amount before creating transaction

function getTotalPaymentDue(address licenseContract, uint256 licenseId)
    external
    view
    returns (uint256 baseAmount, uint256 penalty, uint256 total);

Parameters

NameTypeDescription
licenseContractaddressAddress of the license token contract
licenseIduint256The license ID

Returns

NameTypeDescription
baseAmountuint256The base payment amount
penaltyuint256The penalty amount if overdue
totaluint256The total amount due (baseAmount + penalty)

Events

ListingCreated

Emitted when a new listing is created

event ListingCreated(
    bytes32 indexed listingId, address indexed seller, address nftContract, uint256 tokenId, uint256 price
);

Parameters

NameTypeDescription
listingIdbytes32Unique identifier for the listing
selleraddressAddress of the seller
nftContractaddressNFT contract address
tokenIduint256Token ID being listed
priceuint256Listing price

ListingCancelled

Emitted when a listing is cancelled

event ListingCancelled(bytes32 indexed listingId);

Parameters

NameTypeDescription
listingIdbytes32The listing that was cancelled

OfferCreated

Emitted when an offer is created

event OfferCreated(
    bytes32 indexed offerId, address indexed buyer, address nftContract, uint256 tokenId, uint256 price
);

Parameters

NameTypeDescription
offerIdbytes32Unique identifier for the offer
buyeraddressAddress making the offer
nftContractaddressNFT contract address
tokenIduint256Token ID for the offer
priceuint256Offer price

OfferAccepted

Emitted when an offer is accepted

event OfferAccepted(bytes32 indexed offerId, address indexed seller);

Parameters

NameTypeDescription
offerIdbytes32The offer that was accepted
selleraddressAddress of the seller who accepted

OfferCancelled

Emitted when an offer is cancelled

event OfferCancelled(bytes32 indexed offerId);

Parameters

NameTypeDescription
offerIdbytes32The offer that was cancelled

Sale

Emitted when a sale is completed

event Sale(bytes32 indexed saleId, address indexed buyer, address indexed seller, uint256 price);

Parameters

NameTypeDescription
saleIdbytes32Unique sale identifier
buyeraddressAddress of the buyer
selleraddressAddress of the seller
priceuint256Total sale price

RecurringPaymentMade

Emitted when a recurring payment is made

event RecurringPaymentMade(
    uint256 indexed licenseId, address indexed payer, uint256 baseAmount, uint256 penalty, uint256 timestamp
);

Parameters

NameTypeDescription
licenseIduint256The license ID for the recurring payment
payeraddressAddress making the payment
baseAmountuint256Base payment amount (without penalty)
penaltyuint256Penalty amount for late payment
timestampuint256Time of payment

PenaltyRateUpdated

Emitted when penalty rate is updated

event PenaltyRateUpdated(uint256 newRate);

Parameters

NameTypeDescription
newRateuint256New penalty rate in basis points per day

Errors

InvalidPrice

Thrown when price is zero or invalid

error InvalidPrice();

NotTokenOwner

Thrown when caller is not the token owner

error NotTokenOwner();

NotSeller

Thrown when caller is not the seller

error NotSeller();

ListingNotActive

Thrown when listing is not active

error ListingNotActive();

InsufficientPayment

Thrown when payment amount is insufficient

error InsufficientPayment();

NotOfferBuyer

Thrown when caller is not the offer buyer

error NotOfferBuyer();

OfferNotActive

Thrown when offer is not active

error OfferNotActive();

OfferExpired

Thrown when offer has expired

error OfferExpired();

NotRecurringLicense

Thrown when operation requires recurring license but license is one-time

error NotRecurringLicense();

LicenseNotActive

Thrown when license is not active

error LicenseNotActive();

InsufficientMissedPaymentsForRevocation

Thrown when attempting revocation without sufficient missed payments

error InsufficientMissedPaymentsForRevocation();

LicenseRevokedForMissedPayments

Thrown when license has been revoked for missed payments

error LicenseRevokedForMissedPayments();

InvalidPenaltyRate

Thrown when penalty rate exceeds maximum allowed

error InvalidPenaltyRate();

TransferFailed

Thrown when native token transfer fails

error TransferFailed();

PaymentNotDueYet

Thrown when attempting to make a payment before it is due

error PaymentNotDueYet();

Structs

Listing

Marketplace listing configuration

struct Listing {
    address seller;
    address nftContract;
    uint256 tokenId;
    uint256 price;
    bool isActive;
    bool isERC721;
}

Properties

NameTypeDescription
selleraddressAddress of the seller
nftContractaddressAddress of the NFT contract (ERC-721 or ERC-1155)
tokenIduint256Token ID being listed
priceuint256Listing price in wei
isActiveboolWhether the listing is currently active
isERC721boolWhether the NFT is ERC-721 (true) or ERC-1155 (false)

Offer

Offer configuration for NFT purchase

struct Offer {
    address buyer;
    address nftContract;
    uint256 tokenId;
    uint256 price;
    bool isActive;
    uint256 expiryTime;
}

Properties

NameTypeDescription
buyeraddressAddress making the offer
nftContractaddressAddress of the NFT contract
tokenIduint256Token ID for the offer
priceuint256Offer price in wei (held in escrow)
isActiveboolWhether the offer is currently active
expiryTimeuint256Unix timestamp when offer expires

RecurringPayment

Recurring payment tracking for subscription licenses

struct RecurringPayment {
    uint256 lastPaymentTime;
    address currentOwner;
    uint256 baseAmount;
}

Properties

NameTypeDescription
lastPaymentTimeuint256Timestamp of the last payment made
currentOwneraddressCurrent owner of the license (tracks transfers)
baseAmountuint256Base payment amount for recurring payments