import { Marketplace } from "3rdweb-contracts"; import { BigNumber, BigNumberish } from "ethers"; import { ModuleType, Role } from "../common"; import { ModuleWithRoles } from "../core/module"; import { IMarketplace } from "../interfaces/modules"; import { AuctionListing, NewAuctionListing, NewDirectListing, Offer } from "../types"; import { DirectListing } from "../types/marketplace/DirectListing"; export interface MarketplaceFilter { seller?: string; tokenContract?: string; tokenId?: number; start?: number; count?: number; } /** * Create your own whitelabel marketplace that enables users to buy and sell any digital assets. * * @example * * ```javascript * import { ThirdwebSDK } from "@3rdweb/sdk"; * * // You can switch out this provider with any wallet or provider setup you like. * const provider = ethers.Wallet.createRandom(); * const sdk = new ThirdwebSDK(provider); * const module = sdk.getMarketplaceModule("{{module_address}}"); * ``` * * @public */ export declare class MarketplaceModule extends ModuleWithRoles implements IMarketplace { private _shouldCheckVersion; private _isNewBuy; static moduleType: ModuleType; static roles: readonly ["admin", "lister"]; /** * @override * @internal */ protected getModuleRoles(): readonly Role[]; /** * @internal */ protected connectContract(): Marketplace; /** * @internal */ protected getModuleType(): ModuleType; /** * Create Direct Listing * * @remarks Create a new listing on the marketplace where people can buy an asset directly. * * @example * ```javascript * // Data of the listing you want to create * const listing = { * // address of the contract the asset you want to list is on * assetContractAddress: "0x...", * // token ID of the asset you want to list * tokenId: "0", * // in how many seconds with the listing open up * startTimeInSeconds: 0, * // how long the listing will be open for * listingDurationInSeconds: 86400, * // how many of the asset you want to list * quantity: 1, * // address of the currency contract that will be used to pay for the listing * currencyContractAddress: "0x0000000000000000000000000000000000000000", * // how much the asset will be sold for * buyoutPricePerToken: "1", * } * * await module.createDirectListing(listing); * ``` */ createDirectListing(listing: NewDirectListing): Promise; /** * Create Auction * * @remarks Create a new auction where people can bid on an asset. * * @example * ```javascript * // Data of the auction you want to create * const auction = { * // address of the contract the asset you want to list is on * assetContractAddress: "0x...", * // token ID of the asset you want to list * tokenId: "0", * // in how many seconds with the listing open up * startTimeInSeconds: 0, * // how long the listing will be open for * listingDurationInSeconds: 86400, * // how many of the asset you want to list * quantity: 1, * // address of the currency contract that will be used to pay for the listing * currencyContractAddress: "0x0000000000000000000000000000000000000000", * // how much people would have to bid to instantly buy the asset * buyoutPricePerToken: "10", * // the minimum bid that will be accepted for the token * reservePricePerToken: "1", * } * * await module.createAuctionListing(auction); * ``` */ createAuctionListing(listing: NewAuctionListing): Promise; makeDirectListingOffer(offer: { listingId: BigNumberish; quantityDesired: BigNumberish; currencyContractAddress: string; pricePerToken: BigNumberish; }): Promise; private setAllowance; /** * Bid On Auction * * @remarks Make a bid on an auction listings * * @example * ```javascript * // The listing ID of the asset you want to bid on * const listingId = 0; * // The price you are willing to bid for a single token of the listing * const pricePerToken = 1; * * await module.makeAuctionListingBid({ listingId, pricePerToken }); * ``` */ makeAuctionListingBid(bid: { listingId: BigNumberish; pricePerToken: BigNumberish; }): Promise; isWinningBid(winningPrice: BigNumberish, newBidPrice: BigNumberish, bidBuffer: BigNumberish): Promise; /** * Get Auction Winner * * @remarks Get the winner of the auction after an auction ends. * * @example * ```javascript * // The listing ID of the auction that closed * const listingId = 0; * * module * .getAuctionWinner(listingId) * .then((auctionWinner) => console.log(auctionWinner)) * .catch((err) => console.error(err)); * ``` */ getAuctionWinner(listingId: BigNumberish): Promise; getDirectListing(listingId: BigNumberish): Promise; getAuctionListing(listingId: BigNumberish): Promise; /** * Helper method maps the auction listing to the direct listing interface. * * @internal * @param listing - The listing to map, as returned from the contract. * @returns - The mapped interface. */ private mapDirectListing; /** * Helper method maps the auction listing to the auction listing interface. * * @internal * @param listing - The listing to map, as returned from the contract. * @returns - The mapped interface. */ private mapAuctionListing; private handleTokenApproval; /** * This method checks if the given token is approved for the marketplace module. * This is particularly useful for direct listings where the token * being listed may be moved before the listing is actually closed. * * TODO: Ask Jake/Krishang: do we need to also check the owners balance of the token, * based on the listing quantity? I.e. query the balance of the tokenId, and check if * the seller holds enough of the token * * @internal * @param assetContract - The address of the asset contract. * @param tokenId - The token id of the token. * @param from - The address of the account that owns the token. * @returns - True if the marketplace is approved on the token, false otherwise. */ private isTokenApprovedForMarketplace; /** * Use this method to check if a direct listing is still valid. * * Ways a direct listing can become invalid: * 1. The asset holder transferred the asset to another wallet * 2. The asset holder burned the asset * 3. The asset holder removed the approval on the marketplace * * @internal * @param listing - The listing to check. * @returns - True if the listing is valid, false otherwise. */ private isStillValidDirectListing; /** * Used to verify fields in new listing. * @internal */ private validateNewListingParam; /** * Throws error if listing could not be found * * @param listingId - Listing to check for */ private validateDirectListing; /** * Throws error if listing could not be found * * @param listingId - Listing to check for */ private validateAuctionListing; /** * Maps a contract offer to the strict interface * * @internal * @param offer * @returns - An `Offer` object */ private mapOffer; getActiveOffer(listingId: BigNumberish, address: string): Promise; /** * Get Highest Bid * * @remarks Get the current highest bid of an active auction. * * @example * ```javascript * // The listing ID of the auction that closed * const listingId = 0; * * module * .getWinningBid(listingId) * .then((offer) => console.log(offer)) * .catch((err) => console.error(err)); * ``` */ getWinningBid(listingId: BigNumberish): Promise; getBidBufferBps(): Promise; getTimeBufferInSeconds(): Promise; acceptDirectListingOffer(listingId: BigNumberish, addressOfOfferor: string): Promise; /** * Buyout Auction * * @remarks Buy a specific direct listing from the marketplace. * * @example * ```javascript * // The listing ID of the asset you want to buy * const listingId = 0; * * await module.buyoutAuctionListing(listingId); * ``` */ buyoutAuctionListing(listingId: BigNumberish): Promise; /** * Buy Listing * * @remarks Buy a specific direct listing from the marketplace. * * @example * ```javascript * // The listing ID of the asset you want to buy * const listingId = 0; * // Quantity of the asset you want to buy * const quantityDesired = 1; * * await module.buyoutDirectListing({ listingId, quantityDesired }); * ``` */ buyoutDirectListing(_buyout: { listingId: BigNumberish; quantityDesired: BigNumberish; }): Promise; updateDirectListing(listing: DirectListing): Promise; updateAuctionListing(listing: AuctionListing): Promise; /** * Cancel Direct Listing * * @remarks Cancel a direct listing on the marketplace * * @example * ```javascript * // The listing ID of the direct listing you want to cancel * const listingId = "0" * * await module.cancelDirectListing(listingId); * ``` */ cancelDirectListing(listingId: BigNumberish): Promise; /** * Cancel Auction Listing * * @remarks Cancel an auction listing on the marketplace * * @example * ```javascript * // The listing ID of the auction listing you want to cancel * const listingId = "0" * * await module.cancelAuctionListing(listingId); * ``` */ cancelAuctionListing(listingId: BigNumberish): Promise; closeAuctionListing(listingId: BigNumberish, closeFor?: string): Promise; setBidBufferBps(buffer: BigNumberish): Promise; setTimeBufferInSeconds(buffer: BigNumberish): Promise; buyoutListing(listingId: BigNumberish, quantityDesired?: BigNumberish): Promise; getListing(listingId: BigNumberish): Promise; getAllListings(filter?: MarketplaceFilter): Promise<(AuctionListing | DirectListing)[]>; private getAllListingsNoFilter; isRestrictedListerRoleOnly(): Promise; setRestrictedListerRoleOnly(isRestricted: boolean): Promise; /** * @internal */ private isNewBuy; /** * @internal */ private checkVersion; }