diff --git a/package.json b/package.json index ef0ef46e3..3052eae27 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "opensea-js", - "version": "7.0.0", + "version": "7.0.1", "description": "TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs and our marketplace data", "license": "MIT", "author": "OpenSea Developers", diff --git a/src/api/types.ts b/src/api/types.ts index 7693d9184..13cf09006 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -22,10 +22,28 @@ type PartialParameters = { zoneHash: string; }; +/** + * Criteria for collection or trait offers. + * @category API Response Types + */ type Criteria = { + /** The collection for the criteria */ collection: CollectionCriteria; - contract?: ContractCriteria; + /** The contract for the criteria */ + contract: ContractCriteria; + /** Represents a list of token ids which can be used to fulfill the criteria offer. */ encoded_token_ids?: string; + /** The trait for the criteria */ + trait?: TraitCriteria; +}; + +/** + * Criteria for trait offers. + * @category API Response Types + */ +type TraitCriteria = { + type: string; + value: string; }; type CollectionCriteria = { @@ -66,16 +84,16 @@ export type Order = { * Offer type. * @category API Models */ -export type Offer = Order; +export type Offer = Order & { + /** The criteria for the offer if it is a collection or trait offer. */ + criteria?: Criteria; +}; /** * Collection Offer type. * @category API Models */ -export type CollectionOffer = Offer & { - /** Defines which NFTs meet the criteria to fulfill the offer. */ - criteria: Criteria; -}; +export type CollectionOffer = Required> & Offer; /** * Price response. diff --git a/src/orders/types.ts b/src/orders/types.ts index 81deacda5..c64fd0241 100644 --- a/src/orders/types.ts +++ b/src/orders/types.ts @@ -10,8 +10,12 @@ export type OrderProtocol = keyof OrderProtocolToProtocolData; export type ProtocolData = OrderProtocolToProtocolData[keyof OrderProtocolToProtocolData]; -// Protocol agnostic order data -export type OrderType = "basic" | "english" | "criteria"; +export enum OrderType { + BASIC = "basic", + ENGLISH = "english", + CRITERIA = "criteria", +} + type OrderFee = { account: OpenSeaAccount; basisPoints: string; diff --git a/src/sdk.ts b/src/sdk.ts index 3b49106c7..5ef500bcb 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -18,7 +18,7 @@ import { JsonRpcProvider, } from "ethers"; import { OpenSeaAPI } from "./api/api"; -import { CollectionOffer, NFT } from "./api/types"; +import { CollectionOffer, Listing, NFT, Order } from "./api/types"; import { INVERSE_BASIS_POINT, DEFAULT_ZONE, @@ -30,7 +30,7 @@ import { getPrivateListingConsiderations, getPrivateListingFulfillments, } from "./orders/privateListings"; -import { OrderV2 } from "./orders/types"; +import { OrderType, OrderV2 } from "./orders/types"; import { DEFAULT_SEAPORT_CONTRACT_ADDRESS } from "./orders/utils"; import { ERC1155__factory, @@ -686,23 +686,38 @@ export class OpenSeaSDK { domain, overrides, }: { - order: OrderV2; + order: OrderV2 | Order; accountAddress: string; recipientAddress?: string; domain?: string; overrides?: Overrides; }): Promise { await this._requireAccountIsAvailable(accountAddress); - requireValidProtocol(order.protocolAddress); + + const protocolAddress = + (order as OrderV2).protocolAddress ?? (order as Order).protocol_address; + requireValidProtocol(protocolAddress); + + const orderHash = + (order as OrderV2).orderHash ?? (order as Order).order_hash; + + const side = + (order as OrderV2).side ?? + ([OrderType.BASIC, OrderType.ENGLISH].includes((order as Listing).type) + ? OrderSide.ASK + : OrderSide.BID); let extraData: string | undefined = undefined; - if (order.orderHash) { + const protocolData = + (order as OrderV2).protocolData ?? (order as Order).protocol_data; + + if (orderHash) { const result = await this.api.generateFulfillmentData( accountAddress, - order.orderHash, - order.protocolAddress, - order.side, + orderHash, + protocolAddress, + side, ); // If the order is using offer protection, the extraData @@ -711,13 +726,11 @@ export class OpenSeaSDK { if ("orders" in inputData && "extraData" in inputData.orders[0]) { extraData = (inputData.orders[0] as AdvancedOrder).extraData; } - const signature = result.fulfillment_data.orders[0].signature; - order.clientSignature = signature; - order.protocolData.signature = signature; + protocolData.signature = signature; } - const isPrivateListing = !!order.taker; + const isPrivateListing = "taker" in order ? !!order.taker : false; if (isPrivateListing) { if (recipientAddress) { throw new Error( @@ -725,7 +738,7 @@ export class OpenSeaSDK { ); } return this.fulfillPrivateOrder({ - order, + order: order as OrderV2, accountAddress, domain, overrides, @@ -733,7 +746,7 @@ export class OpenSeaSDK { } const { executeAllActions } = await this.seaport_v1_5.fulfillOrder({ - order: order.protocolData, + order: protocolData, accountAddress, recipientAddress, extraData,