@opensea/sdk 10.3.1 → 10.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/lib/api/api.d.ts +28 -41
  2. package/lib/api/api.js +35 -48
  3. package/lib/api/api.js.map +1 -1
  4. package/lib/api/apiPaths.d.ts +7 -2
  5. package/lib/api/apiPaths.js +25 -6
  6. package/lib/api/apiPaths.js.map +1 -1
  7. package/lib/api/listings.d.ts +9 -14
  8. package/lib/api/listings.js +12 -30
  9. package/lib/api/listings.js.map +1 -1
  10. package/lib/api/offers.d.ts +2 -2
  11. package/lib/api/offers.js +2 -9
  12. package/lib/api/offers.js.map +1 -1
  13. package/lib/api/orders.d.ts +4 -21
  14. package/lib/api/orders.js +15 -96
  15. package/lib/api/orders.js.map +1 -1
  16. package/lib/api/tokens.d.ts +6 -1
  17. package/lib/api/tokens.js +7 -0
  18. package/lib/api/tokens.js.map +1 -1
  19. package/lib/api/transactions.d.ts +16 -0
  20. package/lib/api/transactions.js +24 -0
  21. package/lib/api/transactions.js.map +1 -0
  22. package/lib/api/types.d.ts +32 -10
  23. package/lib/api/types.js.map +1 -1
  24. package/lib/orders/types.d.ts +0 -67
  25. package/lib/orders/types.js.map +1 -1
  26. package/lib/orders/utils.d.ts +1 -19
  27. package/lib/orders/utils.js +1 -62
  28. package/lib/orders/utils.js.map +1 -1
  29. package/lib/sdk/base.d.ts +6 -6
  30. package/lib/sdk/base.js +2 -2
  31. package/lib/sdk/orders.d.ts +13 -10
  32. package/lib/sdk/orders.js +6 -22
  33. package/lib/sdk/orders.js.map +1 -1
  34. package/lib/types.d.ts +0 -6
  35. package/package.json +2 -2
  36. package/src/api/api.ts +54 -86
  37. package/src/api/apiPaths.ts +26 -8
  38. package/src/api/listings.ts +19 -41
  39. package/src/api/offers.ts +8 -16
  40. package/src/api/orders.ts +40 -177
  41. package/src/api/tokens.ts +11 -0
  42. package/src/api/transactions.ts +28 -0
  43. package/src/api/types.ts +43 -15
  44. package/src/orders/types.ts +0 -74
  45. package/src/orders/utils.ts +2 -73
  46. package/src/sdk/base.ts +6 -6
  47. package/src/sdk/orders.ts +31 -32
  48. package/src/types.ts +0 -6
@@ -1,13 +1,8 @@
1
1
  import { CROSS_CHAIN_SEAPORT_V1_6_ADDRESS } from "@opensea/seaport-js/lib/constants"
2
2
  import { API_V2_PREFIX } from "../api/apiPaths"
3
3
  import { type Chain, OrderSide } from "../types"
4
- import { accountFromJSON, getSeaportAddress } from "../utils"
5
- import type {
6
- OrdersQueryOptions,
7
- OrderV2,
8
- ProtocolData,
9
- SerializedOrderV2,
10
- } from "./types"
4
+ import { getSeaportAddress } from "../utils"
5
+ import type { ProtocolData } from "./types"
11
6
 
12
7
  export const DEFAULT_SEAPORT_CONTRACT_ADDRESS = CROSS_CHAIN_SEAPORT_V1_6_ADDRESS
13
8
 
@@ -192,69 +187,3 @@ export const getFulfillOfferPayload = (
192
187
 
193
188
  return payload
194
189
  }
195
-
196
- type OrdersQueryPathOptions = "protocol" | "side"
197
- export const serializeOrdersQueryOptions = (
198
- options: Omit<OrdersQueryOptions, OrdersQueryPathOptions>,
199
- ) => {
200
- const tokenIds =
201
- options.tokenIds && options.tokenIds.length > 0
202
- ? options.tokenIds
203
- : options.tokenId !== undefined
204
- ? [options.tokenId]
205
- : options.tokenIds
206
-
207
- return {
208
- limit: options.limit,
209
- cursor: options.cursor ?? options.next,
210
-
211
- payment_token_address: options.paymentTokenAddress,
212
- maker: options.maker,
213
- taker: options.taker,
214
- owner: options.owner,
215
- listed_after: options.listedAfter,
216
- listed_before: options.listedBefore,
217
- token_ids: tokenIds,
218
- asset_contract_address: options.assetContractAddress,
219
- order_by: options.orderBy,
220
- order_direction: options.orderDirection,
221
- only_english: options.onlyEnglish,
222
- }
223
- }
224
-
225
- /** Map API side values ("ask"/"bid") to SDK OrderSide enum values */
226
- const mapApiSide = (side: string): OrderSide => {
227
- if (side === "ask" || side === OrderSide.LISTING) return OrderSide.LISTING
228
- if (side === "bid" || side === OrderSide.OFFER) return OrderSide.OFFER
229
- return side as OrderSide
230
- }
231
-
232
- export const deserializeOrder = (order: SerializedOrderV2): OrderV2 => {
233
- return {
234
- createdDate: order.created_date,
235
- closingDate: order.closing_date,
236
- listingTime: order.listing_time,
237
- expirationTime: order.expiration_time,
238
- orderHash: order.order_hash,
239
- maker: accountFromJSON(order.maker),
240
- taker: order.taker ? accountFromJSON(order.taker) : null,
241
- protocolData: order.protocol_data,
242
- protocolAddress: order.protocol_address,
243
- currentPrice: BigInt(order.current_price),
244
- makerFees: (order.maker_fees ?? []).map(({ account, basis_points }) => ({
245
- account: accountFromJSON(account),
246
- basisPoints: basis_points,
247
- })),
248
- takerFees: (order.taker_fees ?? []).map(({ account, basis_points }) => ({
249
- account: accountFromJSON(account),
250
- basisPoints: basis_points,
251
- })),
252
- side: mapApiSide(order.side as string),
253
- orderType: order.order_type,
254
- cancelled: order.cancelled,
255
- finalized: order.finalized,
256
- markedInvalid: order.marked_invalid,
257
- clientSignature: order.client_signature,
258
- remainingQuantity: order.remaining_quantity,
259
- }
260
- }
package/src/sdk/base.ts CHANGED
@@ -207,7 +207,7 @@ export class BaseOpenSeaSDK {
207
207
  * @param options.salt Arbitrary salt. Auto-generated if not provided.
208
208
  * @param options.expirationTime Expiration time for the order, in UTC seconds
209
209
  * @param options.zone Zone for order protection. Defaults to chain's signed zone.
210
- * @returns The {@link OrderV2} that was created.
210
+ * @returns The {@link Offer} that was created.
211
211
  */
212
212
  public async createOffer(options: {
213
213
  asset: AssetWithTokenId
@@ -218,7 +218,7 @@ export class BaseOpenSeaSDK {
218
218
  salt?: Amount
219
219
  expirationTime?: Amount
220
220
  zone?: string
221
- }): Promise<OrderV2> {
221
+ }): Promise<Offer> {
222
222
  return this._ordersManager.createOffer(options)
223
223
  }
224
224
 
@@ -236,7 +236,7 @@ export class BaseOpenSeaSDK {
236
236
  * @param options.buyerAddress Optional address that's allowed to purchase this item.
237
237
  * @param options.includeOptionalCreatorFees If true, optional creator fees will be included. Default: false.
238
238
  * @param options.zone Zone for order protection. Defaults to no zone.
239
- * @returns The {@link OrderV2} that was created.
239
+ * @returns The {@link Listing} that was created.
240
240
  */
241
241
  public async createListing(options: {
242
242
  asset: AssetWithTokenId
@@ -250,7 +250,7 @@ export class BaseOpenSeaSDK {
250
250
  buyerAddress?: string
251
251
  includeOptionalCreatorFees?: boolean
252
252
  zone?: string
253
- }): Promise<OrderV2> {
253
+ }): Promise<Listing> {
254
254
  return this._ordersManager.createListing(options)
255
255
  }
256
256
 
@@ -271,7 +271,7 @@ export class BaseOpenSeaSDK {
271
271
  accountAddress: string
272
272
  continueOnError?: boolean
273
273
  onProgress?: (completed: number, total: number) => void
274
- }): Promise<BulkOrderResult> {
274
+ }): Promise<BulkOrderResult<Listing>> {
275
275
  return this._ordersManager.createBulkListings(options)
276
276
  }
277
277
 
@@ -289,7 +289,7 @@ export class BaseOpenSeaSDK {
289
289
  accountAddress: string
290
290
  continueOnError?: boolean
291
291
  onProgress?: (completed: number, total: number) => void
292
- }): Promise<BulkOrderResult> {
292
+ }): Promise<BulkOrderResult<Offer>> {
293
293
  return this._ordersManager.createBulkOffers(options)
294
294
  }
295
295
 
package/src/sdk/orders.ts CHANGED
@@ -3,9 +3,9 @@ import type {
3
3
  CreateInputItem,
4
4
  OrderComponents,
5
5
  } from "@opensea/seaport-js/lib/types"
6
- import type { CollectionOffer, NFT } from "../api/types"
6
+ import type { CollectionOffer, Listing, NFT, Offer } from "../api/types"
7
7
  import { INVERSE_BASIS_POINT, ZERO_ADDRESS } from "../constants"
8
- import type { OrderV2, ProtocolData } from "../orders/types"
8
+ import type { ProtocolData } from "../orders/types"
9
9
  import {
10
10
  type Amount,
11
11
  type AssetWithTokenId,
@@ -31,10 +31,13 @@ import type { SDKContext } from "./context"
31
31
  /**
32
32
  * Result type for bulk operations that may partially succeed.
33
33
  * Contains successfully submitted orders and any failures with error information.
34
+ *
35
+ * Generic in the success type so listing-side callers see {@link Listing}[] and
36
+ * offer-side callers see {@link Offer}[].
34
37
  */
35
- export interface BulkOrderResult {
38
+ export interface BulkOrderResult<T extends Listing | Offer = Listing | Offer> {
36
39
  /** Successfully submitted orders */
37
- successful: OrderV2[]
40
+ successful: T[]
38
41
  /** Failed order submissions with error information */
39
42
  failed: Array<{
40
43
  /** Index of the failed order in the original input array */
@@ -405,7 +408,7 @@ export class OrdersManager {
405
408
  * @param options.expirationTime Expiration time for the order, in UTC seconds
406
409
  * @param options.zone Zone for order protection. Defaults to chain's signed zone.
407
410
  *
408
- * @returns The {@link OrderV2} that was created.
411
+ * @returns The {@link Offer} that was created.
409
412
  *
410
413
  * @throws Error if the asset does not contain a token id.
411
414
  * @throws Error if the accountAddress is not available through wallet or provider.
@@ -429,7 +432,7 @@ export class OrdersManager {
429
432
  salt?: Amount
430
433
  expirationTime?: Amount
431
434
  zone?: string
432
- }): Promise<OrderV2> {
435
+ }): Promise<Offer> {
433
436
  const order = await this._buildOfferOrder({
434
437
  asset,
435
438
  accountAddress,
@@ -441,11 +444,10 @@ export class OrdersManager {
441
444
  zone,
442
445
  })
443
446
 
444
- return this.context.api.postOrder(order, {
445
- protocol: "seaport",
446
- protocolAddress: this.context.seaport.contract.target as string,
447
- side: OrderSide.OFFER,
448
- })
447
+ return this.context.api.postOffer(
448
+ order,
449
+ this.context.seaport.contract.target as string,
450
+ )
449
451
  }
450
452
 
451
453
  /**
@@ -462,7 +464,7 @@ export class OrdersManager {
462
464
  * @param options.buyerAddress Optional address that's allowed to purchase this item. If specified, no other address will be able to take the order, unless its value is the null address.
463
465
  * @param options.includeOptionalCreatorFees If true, optional creator fees will be included in the listing. Default: false.
464
466
  * @param options.zone Zone for order protection. Defaults to no zone.
465
- * @returns The {@link OrderV2} that was created.
467
+ * @returns The {@link Listing} that was created.
466
468
  *
467
469
  * @throws Error if the asset does not contain a token id.
468
470
  * @throws Error if the accountAddress is not available through wallet or provider.
@@ -492,7 +494,7 @@ export class OrdersManager {
492
494
  buyerAddress?: string
493
495
  includeOptionalCreatorFees?: boolean
494
496
  zone?: string
495
- }): Promise<OrderV2> {
497
+ }): Promise<Listing> {
496
498
  const order = await this._buildListingOrder({
497
499
  asset,
498
500
  accountAddress,
@@ -507,11 +509,10 @@ export class OrdersManager {
507
509
  zone,
508
510
  })
509
511
 
510
- return this.context.api.postOrder(order, {
511
- protocol: "seaport",
512
- protocolAddress: this.context.seaport.contract.target as string,
513
- side: OrderSide.LISTING,
514
- })
512
+ return this.context.api.postListing(
513
+ order,
514
+ this.context.seaport.contract.target as string,
515
+ )
515
516
  }
516
517
 
517
518
  /**
@@ -555,7 +556,7 @@ export class OrdersManager {
555
556
  accountAddress: string
556
557
  continueOnError?: boolean
557
558
  onProgress?: (completed: number, total: number) => void
558
- }): Promise<BulkOrderResult> {
559
+ }): Promise<BulkOrderResult<Listing>> {
559
560
  if (listings.length === 0) {
560
561
  throw new Error("Listings array cannot be empty")
561
562
  }
@@ -743,17 +744,16 @@ export class OrdersManager {
743
744
  `Starting submission of ${orders.length} bulk-signed ${pluralize(orders.length, "listing")} to OpenSea API...`,
744
745
  )
745
746
 
746
- const submittedOrders: OrderV2[] = []
747
+ const submittedOrders: Listing[] = []
747
748
  const failedOrders: BulkOrderResult["failed"] = []
748
749
 
749
750
  for (let i = 0; i < orders.length; i++) {
750
751
  this.context.logger(`Submitting listing ${i + 1}/${orders.length}...`)
751
752
  try {
752
- const submittedOrder = await this.context.api.postOrder(orders[i], {
753
- protocol: "seaport",
754
- protocolAddress: this.context.seaport.contract.target as string,
755
- side: OrderSide.LISTING,
756
- })
753
+ const submittedOrder = await this.context.api.postListing(
754
+ orders[i],
755
+ this.context.seaport.contract.target as string,
756
+ )
757
757
  submittedOrders.push(submittedOrder)
758
758
  this.context.logger(`Completed listing ${i + 1}/${orders.length}`)
759
759
  } catch (error) {
@@ -833,7 +833,7 @@ export class OrdersManager {
833
833
  accountAddress: string
834
834
  continueOnError?: boolean
835
835
  onProgress?: (completed: number, total: number) => void
836
- }): Promise<BulkOrderResult> {
836
+ }): Promise<BulkOrderResult<Offer>> {
837
837
  if (offers.length === 0) {
838
838
  throw new Error("Offers array cannot be empty")
839
839
  }
@@ -975,17 +975,16 @@ export class OrdersManager {
975
975
  `Starting submission of ${orders.length} bulk-signed ${pluralize(orders.length, "offer")} to OpenSea API...`,
976
976
  )
977
977
 
978
- const submittedOrders: OrderV2[] = []
978
+ const submittedOrders: Offer[] = []
979
979
  const failedOrders: BulkOrderResult["failed"] = []
980
980
 
981
981
  for (let i = 0; i < orders.length; i++) {
982
982
  this.context.logger(`Submitting offer ${i + 1}/${orders.length}...`)
983
983
  try {
984
- const submittedOrder = await this.context.api.postOrder(orders[i], {
985
- protocol: "seaport",
986
- protocolAddress: this.context.seaport.contract.target as string,
987
- side: OrderSide.OFFER,
988
- })
984
+ const submittedOrder = await this.context.api.postOffer(
985
+ orders[i],
986
+ this.context.seaport.contract.target as string,
987
+ )
989
988
  submittedOrders.push(submittedOrder)
990
989
  this.context.logger(`Completed offer ${i + 1}/${orders.length}`)
991
990
  } catch (error) {
package/src/types.ts CHANGED
@@ -243,11 +243,7 @@ export interface AssetWithTokenStandard extends Asset {
243
243
  interface OpenSeaCollectionStatsIntervalData {
244
244
  interval: "one_day" | "seven_day" | "thirty_day"
245
245
  volume: number
246
- volume_diff: number
247
- volume_change: number
248
246
  sales: number
249
- sales_diff: number
250
- average_price: number
251
247
  }
252
248
 
253
249
  /**
@@ -258,9 +254,7 @@ export interface OpenSeaCollectionStats {
258
254
  total: {
259
255
  volume: number
260
256
  sales: number
261
- average_price: number
262
257
  num_owners: number
263
- market_cap: number
264
258
  floor_price: number
265
259
  floor_price_symbol: string
266
260
  }