11import { ethers } from "ethers" ;
22import {
33 getCollectionPath ,
4+ getCollectionsPath ,
45 getOrdersAPIPath ,
56 getPostCollectionOfferPath ,
67 getBuildOfferPath ,
@@ -18,10 +19,12 @@ import {
1819 getAccountPath ,
1920 getCollectionStatsPath ,
2021 getBestListingsAPIPath ,
22+ getCancelOrderPath ,
2123} from "./apiPaths" ;
2224import {
2325 BuildOfferResponse ,
2426 GetCollectionResponse ,
27+ GetCollectionsResponse ,
2528 ListNFTsResponse ,
2629 GetNFTResponse ,
2730 ListCollectionOffersResponse ,
@@ -31,6 +34,9 @@ import {
3134 GetOffersResponse ,
3235 GetListingsResponse ,
3336 CollectionOffer ,
37+ CollectionOrderByOption ,
38+ CancelOrderResponse ,
39+ GetCollectionsArgs ,
3440} from "./types" ;
3541import { API_BASE_MAINNET , API_BASE_TESTNET } from "../constants" ;
3642import {
@@ -532,6 +538,40 @@ export class OpenSeaAPI {
532538 return collectionFromJSON ( response ) ;
533539 }
534540
541+ /**
542+ * Fetch a list of OpenSea collections.
543+ * @param orderBy The order to return the collections in. Default: CREATED_DATE
544+ * @param chain The chain to filter the collections on. Default: all chains
545+ * @param creatorUsername The creator's OpenSea username to filter the collections on.
546+ * @param includeHidden If hidden collections should be returned. Default: false
547+ * @param limit The limit of collections to return.
548+ * @param next The cursor for the next page of results. This is returned from a previous request.
549+ * @returns List of {@link OpenSeaCollection} returned by the API.
550+ */
551+ public async getCollections (
552+ orderBy : CollectionOrderByOption = CollectionOrderByOption . CREATED_DATE ,
553+ chain ?: Chain ,
554+ creatorUsername ?: string ,
555+ includeHidden : boolean = false ,
556+ limit ?: number ,
557+ next ?: string ,
558+ ) : Promise < GetCollectionsResponse > {
559+ const path = getCollectionsPath ( ) ;
560+ const args : GetCollectionsArgs = {
561+ order_by : orderBy ,
562+ chain,
563+ creator_username : creatorUsername ,
564+ include_hidden : includeHidden ,
565+ limit,
566+ next,
567+ } ;
568+ const response = await this . get < GetCollectionsResponse > ( path , args ) ;
569+ response . collections = response . collections . map ( ( collection ) =>
570+ collectionFromJSON ( collection ) ,
571+ ) ;
572+ return response ;
573+ }
574+
535575 /**
536576 * Fetch stats for an OpenSea collection.
537577 * @param slug The slug (identifier) of the collection.
@@ -592,6 +632,27 @@ export class OpenSeaAPI {
592632 return response ;
593633 }
594634
635+ /**
636+ * Offchain cancel an order, offer or listing, by its order hash when protected by the SignedZone.
637+ * Protocol and Chain are required to prevent hash collisions.
638+ * Please note cancellation is only assured if a fulfillment signature was not vended prior to cancellation.
639+ * @param protocolAddress The Seaport address for the order.
640+ * @param orderHash The order hash, or external identifier, of the order.
641+ * @param chain The chain where the order is located.
642+ * @returns The response from the API.
643+ */
644+ public async offchainCancelOrder (
645+ protocolAddress : string ,
646+ orderHash : string ,
647+ chain : Chain = this . chain ,
648+ ) : Promise < CancelOrderResponse > {
649+ const response = await this . post < CancelOrderResponse > (
650+ getCancelOrderPath ( chain , protocolAddress , orderHash ) ,
651+ { } ,
652+ ) ;
653+ return response ;
654+ }
655+
595656 /**
596657 * Generic fetch method for any API endpoint
597658 * @param apiPath Path to URL endpoint under API
0 commit comments