@opensea/sdk 10.3.0 → 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 +30 -43
  2. package/lib/api/api.js +36 -49
  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 +10 -15
  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 +33 -66
  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 +9 -7
  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 +59 -91
  37. package/src/api/apiPaths.ts +26 -8
  38. package/src/api/listings.ts +24 -46
  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 +55 -72
  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
package/src/api/orders.ts CHANGED
@@ -1,32 +1,20 @@
1
- import type {
2
- FulfillmentDataResponse,
3
- ListingPostQueryResponse,
4
- OfferPostQueryResponse,
5
- OrderAPIOptions,
6
- OrdersPostQueryResponse,
7
- OrdersQueryOptions,
8
- OrdersQueryResponse,
9
- OrderV2,
10
- ProtocolData,
11
- } from "../orders/types"
1
+ import type { FulfillmentDataResponse, ProtocolData } from "../orders/types"
12
2
  import {
13
- deserializeOrder,
14
3
  getFulfillListingPayload,
15
4
  getFulfillmentDataPath,
16
5
  getFulfillOfferPayload,
17
- serializeOrdersQueryOptions,
18
6
  } from "../orders/utils"
19
7
  import { type Chain, OrderSide } from "../types"
20
8
  import {
21
9
  getCancelOrderPath,
22
10
  getOrderByHashPath,
23
- getOrdersAPIPath,
11
+ getPostListingPath,
12
+ getPostOfferPath,
24
13
  } from "./apiPaths"
25
14
  import type { Fetcher } from "./fetcher"
26
15
  import type {
27
16
  CancelOrderResponse,
28
17
  GetOrderByHashResponse,
29
- GetOrdersResponse,
30
18
  Listing,
31
19
  Offer,
32
20
  } from "./types"
@@ -40,44 +28,6 @@ export class OrdersAPI {
40
28
  private chain: Chain,
41
29
  ) {}
42
30
 
43
- /**
44
- * Gets an order from API based on query options.
45
- * @deprecated Use collection-based endpoints instead: getAllOffers, getAllListings, getBestOffer, getBestListing.
46
- */
47
- async getOrder({
48
- side,
49
- protocol = "seaport",
50
- orderDirection = "desc",
51
- orderBy = "created_date",
52
- ...restOptions
53
- }: Omit<OrdersQueryOptions, "limit">): Promise<OrderV2> {
54
- // Validate eth_price orderBy requires additional parameters
55
- if (orderBy === "eth_price") {
56
- const hasTokenId =
57
- (restOptions.tokenIds?.length ?? 0) > 0 ||
58
- restOptions.tokenId !== undefined
59
- if (!restOptions.assetContractAddress || !hasTokenId) {
60
- throw new Error(
61
- 'When using orderBy: "eth_price", you must provide both assetContractAddress and tokenIds (or tokenId) parameters',
62
- )
63
- }
64
- }
65
-
66
- const { orders } = await this.fetcher.get<OrdersQueryResponse>(
67
- getOrdersAPIPath(this.chain, protocol, side),
68
- serializeOrdersQueryOptions({
69
- limit: 1,
70
- orderBy,
71
- orderDirection,
72
- ...restOptions,
73
- }),
74
- )
75
- if (orders.length === 0) {
76
- throw new Error("Not found: no matching order found")
77
- }
78
- return deserializeOrder(orders[0])
79
- }
80
-
81
31
  /**
82
32
  * Gets a single order by its order hash.
83
33
  * Returns the raw API response which can be either an Offer or Listing.
@@ -93,47 +43,6 @@ export class OrdersAPI {
93
43
  return response.order
94
44
  }
95
45
 
96
- /**
97
- * Gets a list of orders from API based on query options.
98
- * @deprecated Use collection-based endpoints instead: getAllOffers, getAllListings, getBestOffer, getBestListing.
99
- */
100
- async getOrders({
101
- side,
102
- protocol = "seaport",
103
- orderDirection = "desc",
104
- orderBy = "created_date",
105
- pageSize = 20,
106
- ...restOptions
107
- }: Omit<OrdersQueryOptions, "limit"> & {
108
- pageSize?: number
109
- }): Promise<GetOrdersResponse> {
110
- // Validate eth_price orderBy requires additional parameters
111
- if (orderBy === "eth_price") {
112
- const hasTokenId =
113
- (restOptions.tokenIds?.length ?? 0) > 0 ||
114
- restOptions.tokenId !== undefined
115
- if (!restOptions.assetContractAddress || !hasTokenId) {
116
- throw new Error(
117
- 'When using orderBy: "eth_price", you must provide both assetContractAddress and tokenIds (or tokenId) parameters',
118
- )
119
- }
120
- }
121
-
122
- const response = await this.fetcher.get<OrdersQueryResponse>(
123
- getOrdersAPIPath(this.chain, protocol, side),
124
- serializeOrdersQueryOptions({
125
- limit: pageSize,
126
- orderBy,
127
- orderDirection,
128
- ...restOptions,
129
- }),
130
- )
131
- return {
132
- ...response,
133
- orders: response.orders.map(deserializeOrder),
134
- }
135
- }
136
-
137
46
  /**
138
47
  * Generate the data needed to fulfill a listing or an offer onchain.
139
48
  */
@@ -148,83 +57,37 @@ export class OrdersAPI {
148
57
  recipientAddress?: string,
149
58
  includeOptionalCreatorFees: boolean = false,
150
59
  ): Promise<FulfillmentDataResponse> {
151
- let payload: object | null = null
152
- if (side === OrderSide.LISTING) {
153
- payload = getFulfillListingPayload(
154
- fulfillerAddress,
155
- orderHash,
156
- protocolAddress,
157
- this.chain,
158
- assetContractAddress,
159
- tokenId,
160
- unitsToFill,
161
- recipientAddress,
162
- includeOptionalCreatorFees,
163
- )
164
- } else {
165
- payload = getFulfillOfferPayload(
166
- fulfillerAddress,
167
- orderHash,
168
- protocolAddress,
169
- this.chain,
170
- assetContractAddress,
171
- tokenId,
172
- unitsToFill,
173
- includeOptionalCreatorFees,
174
- )
175
- }
176
- const response = await this.fetcher.post<FulfillmentDataResponse>(
60
+ const payload =
61
+ side === OrderSide.LISTING
62
+ ? getFulfillListingPayload(
63
+ fulfillerAddress,
64
+ orderHash,
65
+ protocolAddress,
66
+ this.chain,
67
+ assetContractAddress,
68
+ tokenId,
69
+ unitsToFill,
70
+ recipientAddress,
71
+ includeOptionalCreatorFees,
72
+ )
73
+ : getFulfillOfferPayload(
74
+ fulfillerAddress,
75
+ orderHash,
76
+ protocolAddress,
77
+ this.chain,
78
+ assetContractAddress,
79
+ tokenId,
80
+ unitsToFill,
81
+ includeOptionalCreatorFees,
82
+ )
83
+ return this.fetcher.post<FulfillmentDataResponse>(
177
84
  getFulfillmentDataPath(side),
178
85
  payload,
179
86
  )
180
- return response
181
87
  }
182
88
 
183
89
  /**
184
- * Post an order to OpenSea.
185
- * @deprecated Use postListing or postOffer instead.
186
- */
187
- async postOrder(
188
- order: ProtocolData,
189
- apiOptions: OrderAPIOptions,
190
- ): Promise<OrderV2> {
191
- const { protocol = "seaport", side, protocolAddress } = apiOptions
192
-
193
- // Validate required fields
194
- if (!side) {
195
- throw new Error("apiOptions.side is required")
196
- }
197
- if (!protocolAddress) {
198
- throw new Error("apiOptions.protocolAddress is required")
199
- }
200
- if (!order) {
201
- throw new Error("order data is required")
202
- }
203
-
204
- // Validate protocol value
205
- if (protocol !== "seaport") {
206
- throw new Error("Currently only 'seaport' protocol is supported")
207
- }
208
-
209
- // Validate side value
210
- if (side !== "listing" && side !== "offer") {
211
- throw new Error("side must be either 'listing' or 'offer'")
212
- }
213
-
214
- // Validate protocolAddress format
215
- if (!/^0x[a-fA-F0-9]{40}$/.test(protocolAddress)) {
216
- throw new Error("Invalid protocol address format")
217
- }
218
-
219
- const response = await this.fetcher.post<OrdersPostQueryResponse>(
220
- getOrdersAPIPath(this.chain, protocol, side),
221
- { ...order, protocol_address: protocolAddress },
222
- )
223
- return deserializeOrder(response.order)
224
- }
225
-
226
- /**
227
- * Post a listing to OpenSea. Returns the new Listing response format.
90
+ * Post a listing to OpenSea.
228
91
  */
229
92
  async postListing(
230
93
  order: ProtocolData,
@@ -237,15 +100,17 @@ export class OrdersAPI {
237
100
  throw new Error("Invalid protocol address format")
238
101
  }
239
102
 
240
- const response = await this.fetcher.post<ListingPostQueryResponse>(
241
- getOrdersAPIPath(this.chain, "seaport", OrderSide.LISTING),
242
- { ...order, protocol_address: protocolAddress },
103
+ return this.fetcher.post<Listing>(
104
+ getPostListingPath(this.chain, "seaport"),
105
+ {
106
+ ...order,
107
+ protocol_address: protocolAddress,
108
+ },
243
109
  )
244
- return response.listing
245
110
  }
246
111
 
247
112
  /**
248
- * Post an offer to OpenSea. Returns the new Offer response format.
113
+ * Post an offer to OpenSea.
249
114
  */
250
115
  async postOffer(
251
116
  order: ProtocolData,
@@ -258,11 +123,10 @@ export class OrdersAPI {
258
123
  throw new Error("Invalid protocol address format")
259
124
  }
260
125
 
261
- const response = await this.fetcher.post<OfferPostQueryResponse>(
262
- getOrdersAPIPath(this.chain, "seaport", OrderSide.OFFER),
263
- { ...order, protocol_address: protocolAddress },
264
- )
265
- return response.offer
126
+ return this.fetcher.post<Offer>(getPostOfferPath(this.chain, "seaport"), {
127
+ ...order,
128
+ protocol_address: protocolAddress,
129
+ })
266
130
  }
267
131
 
268
132
  /**
@@ -274,10 +138,9 @@ export class OrdersAPI {
274
138
  chain: Chain = this.chain,
275
139
  offererSignature?: string,
276
140
  ): Promise<CancelOrderResponse> {
277
- const response = await this.fetcher.post<CancelOrderResponse>(
141
+ return this.fetcher.post<CancelOrderResponse>(
278
142
  getCancelOrderPath(chain, protocolAddress, orderHash),
279
143
  { offererSignature },
280
144
  )
281
- return response
282
145
  }
283
146
  }
package/src/api/tokens.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ getSwapExecutePath,
2
3
  getSwapQuotePath,
3
4
  getTokenGroupPath,
4
5
  getTokenGroupsPath,
@@ -17,6 +18,8 @@ import type {
17
18
  GetTokensArgs,
18
19
  GetTopTokensResponse,
19
20
  GetTrendingTokensResponse,
21
+ SwapExecuteRequest,
22
+ SwapExecuteResponse,
20
23
  } from "./types"
21
24
 
22
25
  /**
@@ -60,6 +63,14 @@ export class TokensAPI {
60
63
  return response
61
64
  }
62
65
 
66
+ /**
67
+ * Get executable transactions for a token swap.
68
+ * Supports same-chain and cross-chain swaps with multiple from/to assets.
69
+ */
70
+ async executeSwap(request: SwapExecuteRequest): Promise<SwapExecuteResponse> {
71
+ return this.fetcher.post<SwapExecuteResponse>(getSwapExecutePath(), request)
72
+ }
73
+
63
74
  /**
64
75
  * Gets details for a specific token.
65
76
  */
@@ -0,0 +1,28 @@
1
+ import { getTransactionReceiptPath } from "./apiPaths"
2
+ import type { Fetcher } from "./fetcher"
3
+ import type {
4
+ TransactionReceiptRequest,
5
+ TransactionReceiptResponse,
6
+ } from "./types"
7
+
8
+ /**
9
+ * Transaction-related API operations
10
+ */
11
+ export class TransactionsAPI {
12
+ constructor(private fetcher: Fetcher) {}
13
+
14
+ /**
15
+ * Get the receipt/status for a submitted transaction.
16
+ * Works for all transaction types: listing fulfillments, cross-chain buys,
17
+ * sweeps, offer fulfillments, and token swaps. Poll this endpoint to check
18
+ * completion status.
19
+ */
20
+ async getTransactionReceipt(
21
+ request: TransactionReceiptRequest,
22
+ ): Promise<TransactionReceiptResponse> {
23
+ return this.fetcher.post<TransactionReceiptResponse>(
24
+ getTransactionReceiptPath(),
25
+ request,
26
+ )
27
+ }
28
+ }
package/src/api/types.ts CHANGED
@@ -1,16 +1,17 @@
1
1
  import type {
2
+ SwapExecuteRequest as ApiSwapExecuteRequest,
3
+ SwapExecuteResponse as ApiSwapExecuteResponse,
4
+ SweepCollectionRequest as ApiSweepCollectionRequest,
5
+ SweepCollectionResponse as ApiSweepCollectionResponse,
6
+ TransactionReceiptRequest as ApiTransactionReceiptRequest,
7
+ TransactionReceiptResponse as ApiTransactionReceiptResponse,
2
8
  AssetMetadataResponse,
3
9
  InstantApiKeyResponse,
4
10
  TokenGroupPaginatedResponse,
5
11
  TokenGroupResponse,
6
12
  } from "@opensea/api-types"
7
13
  import type { ConsiderationItem } from "@opensea/seaport-js/lib/types"
8
- import type {
9
- OrderType,
10
- OrderV2,
11
- ProtocolData,
12
- QueryCursors,
13
- } from "../orders/types"
14
+ import type { OrderType, ProtocolData } from "../orders/types"
14
15
  import type { OpenSeaCollection } from "../types"
15
16
 
16
17
  /**
@@ -260,15 +261,6 @@ export type GetNFTResponse = {
260
261
  nft: NFT
261
262
  }
262
263
 
263
- /**
264
- * Response from OpenSea API for fetching Orders.
265
- * @category API Response Types
266
- */
267
- export type GetOrdersResponse = QueryCursors & {
268
- /** List of {@link OrderV2} */
269
- orders: OrderV2[]
270
- }
271
-
272
264
  /**
273
265
  * Base query cursors response from OpenSea API.
274
266
  * @category API Response Types
@@ -320,6 +312,42 @@ export type CancelOrderResponse = {
320
312
  last_signature_issued_valid_until: string | null
321
313
  }
322
314
 
315
+ /**
316
+ * Request body for sweeping (bulk-buying) items from a collection.
317
+ * @category API Query Args
318
+ */
319
+ export type SweepCollectionRequest = ApiSweepCollectionRequest
320
+
321
+ /**
322
+ * Response from sweeping a collection.
323
+ * @category API Response Types
324
+ */
325
+ export type SweepCollectionResponse = ApiSweepCollectionResponse
326
+
327
+ /**
328
+ * Request body for executing a token swap.
329
+ * @category API Query Args
330
+ */
331
+ export type SwapExecuteRequest = ApiSwapExecuteRequest
332
+
333
+ /**
334
+ * Response from executing a token swap.
335
+ * @category API Response Types
336
+ */
337
+ export type SwapExecuteResponse = ApiSwapExecuteResponse
338
+
339
+ /**
340
+ * Request body for fetching a transaction receipt.
341
+ * @category API Query Args
342
+ */
343
+ export type TransactionReceiptRequest = ApiTransactionReceiptRequest
344
+
345
+ /**
346
+ * Response from fetching a transaction receipt.
347
+ * @category API Response Types
348
+ */
349
+ export type TransactionReceiptResponse = ApiTransactionReceiptResponse
350
+
323
351
  /**
324
352
  * NFT type returned by OpenSea API.
325
353
  * @category API Models
@@ -1298,60 +1326,15 @@ export type ValidateMetadataResponse = {
1298
1326
  export type GetNFTMetadataResponse = AssetMetadataResponse
1299
1327
 
1300
1328
  // ─── Cross-chain fulfillment types ──────────────────────────────────
1301
-
1302
- /**
1303
- * A single listing to fulfill in a cross-chain fulfillment request.
1304
- * @category API Models
1305
- */
1306
- export type CrossChainListing = {
1307
- /** Order hash (66 chars, starts with 0x) */
1308
- hash: string
1309
- /** Chain slug where the listing lives (must be EVM) */
1310
- chain: string
1311
- /** Seaport contract address */
1312
- protocol_address: string
1313
- }
1314
-
1315
- /**
1316
- * Request body for the cross-chain fulfillment endpoint.
1317
- * @category API Query Args
1318
- */
1319
- export type CrossChainFulfillmentDataRequest = {
1320
- /** Array of listings to fulfill (up to 50) */
1321
- listings: CrossChainListing[]
1322
- /** The buyer's wallet */
1323
- fulfiller: { address: string }
1324
- /** Payment token details */
1325
- payment: {
1326
- /** Chain slug of the payment token (EVM or SVM) */
1327
- chain: string
1328
- /** Payment token contract address (0x0...0 for native, Base58 for Solana) */
1329
- token_address: string
1330
- }
1331
- /** Optional: different recipient address for the NFTs */
1332
- recipient?: string
1333
- }
1334
-
1335
- /**
1336
- * A single transaction returned by the cross-chain fulfillment endpoint.
1337
- * @category API Response Types
1338
- */
1339
- export type CrossChainTransaction = {
1340
- /** Chain slug for the transaction */
1341
- chain: string
1342
- /** Contract address to call */
1343
- to: string
1344
- /** Encoded calldata */
1345
- data: string
1346
- /** Wei amount as string */
1347
- value: string
1348
- }
1349
-
1350
- /**
1351
- * Response from the cross-chain fulfillment endpoint.
1352
- * @category API Response Types
1353
- */
1354
- export type CrossChainFulfillmentDataResponse = {
1355
- /** Ordered list of transactions to sign and submit */
1356
- transactions: CrossChainTransaction[]
1357
- }
1329
+ // Re-exported from @opensea/api-types so consumers can keep importing them
1330
+ // from @opensea/sdk. See packages/api-types — these are generated from the
1331
+ // OpenSea v2 OpenAPI spec.
1332
+
1333
+ export type {
1334
+ CrossChainFulfillmentRequest,
1335
+ CrossChainFulfillmentResponse,
1336
+ CrossChainPaymentToken,
1337
+ FulfillerObject,
1338
+ ListingObject,
1339
+ SwapTransactionResponse,
1340
+ } from "@opensea/api-types"
@@ -3,7 +3,6 @@ import type {
3
3
  AdvancedOrder,
4
4
  OrderWithCounter,
5
5
  } from "@opensea/seaport-js/lib/types"
6
- import type { Listing, Offer } from "../api/types"
7
6
  import type { OpenSeaAccount, OrderSide } from "../types"
8
7
 
9
8
  // Protocol data
@@ -112,80 +111,7 @@ type Transaction = {
112
111
  }
113
112
 
114
113
  // API query types
115
- type OpenOrderOrderingOption = "created_date" | "eth_price"
116
- type OrderByDirection = "asc" | "desc"
117
-
118
- export type OrderAPIOptions = {
119
- protocol?: OrderProtocol
120
- protocolAddress?: string
121
- side: OrderSide
122
- }
123
-
124
- export type OrdersQueryOptions = OrderAPIOptions & {
125
- limit?: number
126
- cursor?: string
127
- next?: string
128
-
129
- paymentTokenAddress?: string
130
- maker?: string
131
- taker?: string
132
- owner?: string
133
- listedAfter?: number | string
134
- listedBefore?: number | string
135
- tokenId?: string
136
- tokenIds?: string[]
137
- assetContractAddress?: string
138
- orderBy?: OpenOrderOrderingOption
139
- orderDirection?: OrderByDirection
140
- onlyEnglish?: boolean
141
- }
142
-
143
- export type SerializedOrderV2 = {
144
- created_date: string
145
- closing_date: string | null
146
- listing_time: number
147
- expiration_time: number
148
- order_hash: string | null
149
- maker: unknown
150
- taker: unknown | null
151
- protocol_data: ProtocolData
152
- protocol_address: string
153
- current_price: string
154
- maker_fees: {
155
- account: unknown
156
- basis_points: string
157
- }[]
158
- taker_fees: {
159
- account: unknown
160
- basis_points: string
161
- }[]
162
- side: OrderSide
163
- order_type: OrderType
164
- cancelled: boolean
165
- finalized: boolean
166
- marked_invalid: boolean
167
- client_signature: string | null
168
- remaining_quantity: number
169
- }
170
-
171
114
  export type QueryCursors = {
172
115
  next: string | null
173
116
  previous: string | null
174
117
  }
175
-
176
- export type OrdersQueryResponse = QueryCursors & {
177
- orders: SerializedOrderV2[]
178
- }
179
-
180
- /** @deprecated Use ListingPostQueryResponse or OfferPostQueryResponse instead. */
181
- export type OrdersPostQueryResponse = { order: SerializedOrderV2 }
182
-
183
- export type ListingPostQueryResponse = {
184
- order: SerializedOrderV2
185
- listing: Listing
186
- }
187
-
188
- export type OfferPostQueryResponse = {
189
- order: SerializedOrderV2
190
- offer: Offer
191
- }
@@ -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
- }