@opensea/sdk 12.0.0 → 12.1.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 (52) hide show
  1. package/README.md +31 -0
  2. package/lib/api/api.d.ts +17 -1
  3. package/lib/api/api.js +26 -2
  4. package/lib/api/api.js.map +1 -1
  5. package/lib/api/apiPaths.d.ts +4 -0
  6. package/lib/api/apiPaths.js +18 -2
  7. package/lib/api/apiPaths.js.map +1 -1
  8. package/lib/api/listings.d.ts +5 -1
  9. package/lib/api/listings.js +6 -0
  10. package/lib/api/listings.js.map +1 -1
  11. package/lib/api/offers.d.ts +9 -1
  12. package/lib/api/offers.js +12 -0
  13. package/lib/api/offers.js.map +1 -1
  14. package/lib/api/orders.d.ts +5 -1
  15. package/lib/api/orders.js +6 -0
  16. package/lib/api/orders.js.map +1 -1
  17. package/lib/api/types.d.ts +9 -1
  18. package/lib/api/walletAuth.d.ts +21 -1
  19. package/lib/api/walletAuth.js +24 -5
  20. package/lib/api/walletAuth.js.map +1 -1
  21. package/lib/orders/erc20Fulfillment.js +67 -4
  22. package/lib/orders/erc20Fulfillment.js.map +1 -1
  23. package/lib/provider/seaport-bridge.js +2 -2
  24. package/lib/provider/seaport-bridge.js.map +1 -1
  25. package/lib/provider/viem-adapter.js +3 -3
  26. package/lib/provider/viem-adapter.js.map +1 -1
  27. package/lib/sdk/assets.js +8 -0
  28. package/lib/sdk/assets.js.map +1 -1
  29. package/lib/sdk/base.d.ts +1 -0
  30. package/lib/sdk/cancellation.js +6 -1
  31. package/lib/sdk/cancellation.js.map +1 -1
  32. package/lib/utils/eip712.d.ts +21 -0
  33. package/lib/utils/eip712.js +54 -0
  34. package/lib/utils/eip712.js.map +1 -0
  35. package/lib/utils/rateLimit.d.ts +6 -0
  36. package/lib/utils/rateLimit.js +22 -5
  37. package/lib/utils/rateLimit.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/api/api.ts +54 -2
  40. package/src/api/apiPaths.ts +20 -0
  41. package/src/api/listings.ts +15 -0
  42. package/src/api/offers.ts +30 -0
  43. package/src/api/orders.ts +18 -0
  44. package/src/api/types.ts +21 -0
  45. package/src/api/walletAuth.ts +29 -2
  46. package/src/orders/erc20Fulfillment.ts +74 -4
  47. package/src/provider/seaport-bridge.ts +2 -3
  48. package/src/provider/viem-adapter.ts +3 -4
  49. package/src/sdk/assets.ts +9 -0
  50. package/src/sdk/cancellation.ts +6 -1
  51. package/src/utils/eip712.ts +57 -0
  52. package/src/utils/rateLimit.ts +29 -4
@@ -16,11 +16,28 @@ const MILLISECONDS_PER_SECOND = 1000;
16
16
  const RATE_LIMIT_STATUS_CODE = 429;
17
17
  const CUSTOM_RATE_LIMIT_STATUS_CODE = 599;
18
18
  /**
19
- * Sleep for a specified duration
19
+ * Sleep for a specified duration, optionally cancellable.
20
20
  * @param ms Duration in milliseconds
21
+ * @param signal Optional signal that rejects the sleep early
21
22
  */
22
- function sleep(ms) {
23
- return new Promise(resolve => setTimeout(resolve, ms));
23
+ function sleep(ms, signal) {
24
+ if (!signal) {
25
+ return new Promise(resolve => setTimeout(resolve, ms));
26
+ }
27
+ if (signal.aborted) {
28
+ return Promise.reject(new Error("Request aborted"));
29
+ }
30
+ return new Promise((resolve, reject) => {
31
+ const onAbort = () => {
32
+ clearTimeout(timeoutId);
33
+ reject(new Error("Request aborted"));
34
+ };
35
+ const timeoutId = setTimeout(() => {
36
+ signal.removeEventListener("abort", onAbort);
37
+ resolve();
38
+ }, ms);
39
+ signal.addEventListener("abort", onAbort, { once: true });
40
+ });
24
41
  }
25
42
  /**
26
43
  * Execute an async operation with automatic retry on rate limit errors.
@@ -32,7 +49,7 @@ function sleep(ms) {
32
49
  * @throws The last error encountered if all retries are exhausted
33
50
  */
34
51
  async function executeWithRateLimit(operation, options = {}) {
35
- const { logger = () => { }, maxRetries = DEFAULT_MAX_RETRIES, baseRetryDelay = DEFAULT_BASE_RETRY_DELAY_MS, } = options;
52
+ const { logger = () => { }, signal, maxRetries = DEFAULT_MAX_RETRIES, baseRetryDelay = DEFAULT_BASE_RETRY_DELAY_MS, } = options;
36
53
  let lastError;
37
54
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
38
55
  try {
@@ -61,7 +78,7 @@ async function executeWithRateLimit(operation, options = {}) {
61
78
  const delaySeconds = delayMs / MILLISECONDS_PER_SECOND;
62
79
  logger(`Rate limit hit. Waiting ${delaySeconds} seconds before retry (attempt ${attempt + 1}/${maxRetries})...`);
63
80
  }
64
- await sleep(delayMs);
81
+ await sleep(delayMs, signal);
65
82
  logger(`Retrying operation...`);
66
83
  }
67
84
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rateLimit.js","sourceRoot":"","sources":["../../src/utils/rateLimit.ts"],"names":[],"mappings":";;AAgDA,oDAqDC;AAUD,wEAmCC;AAjJD,iDAA0C;AAE1C;;GAEG;AACH,MAAM,mBAAmB,GAAG,CAAC,CAAA;AAC7B,MAAM,2BAA2B,GAAG,IAAI,CAAA;AACxC,MAAM,wBAAwB,GAAG,CAAC,CAAA;AAClC,MAAM,uBAAuB,GAAG,IAAI,CAAA;AAEpC;;GAEG;AACH,MAAM,sBAAsB,GAAG,GAAG,CAAA;AAClC,MAAM,6BAA6B,GAAG,GAAG,CAAA;AAgBzC;;;GAGG;AACH,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AACxD,CAAC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,oBAAoB,CACxC,SAA2B,EAC3B,UAA4B,EAAE;IAE9B,MAAM,EACJ,MAAM,GAAG,GAAG,EAAE,GAAE,CAAC,EACjB,UAAU,GAAG,mBAAmB,EAChC,cAAc,GAAG,2BAA2B,GAC7C,GAAG,OAAO,CAAA;IAEX,IAAI,SAA4B,CAAA;IAEhC,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,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J,MAAM,GAAG,GAAG,EAAE,GAAE,CAAC,EACjB,aAAa,GAAG,WAAW,EAC3B,GAAG,gBAAgB,EACpB,GAAG,OAAO,CAAA;IAEX,MAAM,OAAO,GAAQ,EAAE,CAAA;IACvB,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAA;IAE/B,MAAM,CAAC,YAAY,KAAK,IAAI,IAAA,wBAAS,EAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAAA;IAEjE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3C,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;QAC/B,MAAM,CAAC,aAAa,aAAa,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,CAAC,CAAA;QAEzD,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,SAAS,EAAE;YACnD,GAAG,gBAAgB;YACnB,MAAM;SACP,CAAC,CAAA;QAEF,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACpB,MAAM,CAAC,aAAa,aAAa,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,CAAA;IACxD,CAAC;IAED,MAAM,CACJ,OAAO,KAAK,IAAI,IAAA,wBAAS,EAAC,KAAK,EAAE,aAAa,CAAC,yBAAyB,CACzE,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opensea/sdk",
3
- "version": "12.0.0",
3
+ "version": "12.1.0",
4
4
  "description": "TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs, tokens, and our marketplace data",
5
5
  "license": "MIT",
6
6
  "author": "OpenSea Developers",
@@ -47,7 +47,7 @@
47
47
  "types": "lib/index.d.ts",
48
48
  "dependencies": {
49
49
  "@noble/hashes": "^2.0.1",
50
- "@opensea/api-types": "^0.8.10",
50
+ "@opensea/api-types": "^0.9.1",
51
51
  "@opensea/seaport-js": "^4.2.0",
52
52
  "ethers": "^6.16.0"
53
53
  },
package/src/api/api.ts CHANGED
@@ -47,8 +47,16 @@ import {
47
47
  type CollectionOffer,
48
48
  type CollectionOfferAggregatesPaginatedResponse,
49
49
  CollectionOrderByOption,
50
+ type CreateCancelOrderActionsRequest,
51
+ type CreateCancelOrderActionsResponse,
50
52
  type CreateListingActionsRequest,
51
53
  type CreateListingActionsResponse,
54
+ type CreateListingFulfillmentActionsRequest,
55
+ type CreateListingFulfillmentActionsResponse,
56
+ type CreateOfferActionsRequest,
57
+ type CreateOfferActionsResponse,
58
+ type CreateOfferFulfillmentActionsRequest,
59
+ type CreateOfferFulfillmentActionsResponse,
52
60
  type CrossChainDropMintRequest,
53
61
  type CrossChainDropMintResponse,
54
62
  type CrossChainFulfillmentRequest,
@@ -698,6 +706,23 @@ export class OpenSeaAPI {
698
706
  )
699
707
  }
700
708
 
709
+ /**
710
+ * Get ordered actions to cancel an order onchain.
711
+ */
712
+ public async createCancelOrderActions(
713
+ protocolAddress: string,
714
+ orderIdentifier: string,
715
+ request: CreateCancelOrderActionsRequest,
716
+ chain: Chain = this.chain,
717
+ ): Promise<CreateCancelOrderActionsResponse> {
718
+ return this.ordersAPI.createCancelOrderActions(
719
+ protocolAddress,
720
+ orderIdentifier,
721
+ request,
722
+ chain,
723
+ )
724
+ }
725
+
701
726
  /**
702
727
  * Gets a list of events based on query parameters.
703
728
  * @param args Query parameters for filtering events.
@@ -1256,6 +1281,33 @@ export class OpenSeaAPI {
1256
1281
  return this.listingsAPI.createListingActions(request)
1257
1282
  }
1258
1283
 
1284
+ /**
1285
+ * Get ordered actions to fulfill a listing.
1286
+ */
1287
+ public async createListingFulfillmentActions(
1288
+ request: CreateListingFulfillmentActionsRequest,
1289
+ ): Promise<CreateListingFulfillmentActionsResponse> {
1290
+ return this.listingsAPI.createListingFulfillmentActions(request)
1291
+ }
1292
+
1293
+ /**
1294
+ * Get ordered actions to create an offer.
1295
+ */
1296
+ public async createOfferActions(
1297
+ request: CreateOfferActionsRequest,
1298
+ ): Promise<CreateOfferActionsResponse> {
1299
+ return this.offersAPI.createOfferActions(request)
1300
+ }
1301
+
1302
+ /**
1303
+ * Get ordered actions to fulfill an offer.
1304
+ */
1305
+ public async createOfferFulfillmentActions(
1306
+ request: CreateOfferFulfillmentActionsRequest,
1307
+ ): Promise<CreateOfferFulfillmentActionsResponse> {
1308
+ return this.offersAPI.createOfferFulfillmentActions(request)
1309
+ }
1310
+
1259
1311
  /**
1260
1312
  * Build a deploy-contract transaction for a new drop.
1261
1313
  */
@@ -1404,7 +1456,7 @@ export class OpenSeaAPI {
1404
1456
  const raw = await this._fetch(url, "GET", undefined, undefined, options)
1405
1457
  return this.camelizeResponseBody<T>(raw, options)
1406
1458
  },
1407
- { logger: this.logger },
1459
+ { logger: this.logger, signal: options?.signal },
1408
1460
  )
1409
1461
  }
1410
1462
 
@@ -1449,7 +1501,7 @@ export class OpenSeaAPI {
1449
1501
  const raw = await this._fetch(url, method, headers, wireBody, options)
1450
1502
  return this.camelizeResponseBody<T>(raw, options)
1451
1503
  },
1452
- { logger: this.logger },
1504
+ { logger: this.logger, signal: options?.signal },
1453
1505
  )
1454
1506
  }
1455
1507
 
@@ -118,6 +118,26 @@ export const getCancelOrderPath = (
118
118
  return `${API_V2_PREFIX}/orders/chain/${chain}/protocol/${protocolAddress}/${orderHash}/cancel`
119
119
  }
120
120
 
121
+ export const getCreateCancelOrderActionsPath = (
122
+ chain: Chain,
123
+ protocolAddress: string,
124
+ orderIdentifier: string,
125
+ ) => {
126
+ return `${API_V2_PREFIX}/orders/chain/${chain}/protocol/${protocolAddress}/${orderIdentifier}/cancel/actions`
127
+ }
128
+
129
+ export const getCreateListingFulfillmentActionsPath = () => {
130
+ return `${API_V2_PREFIX}/listings/fulfillment/actions`
131
+ }
132
+
133
+ export const getCreateOfferActionsPath = () => {
134
+ return `${API_V2_PREFIX}/offers/actions`
135
+ }
136
+
137
+ export const getCreateOfferFulfillmentActionsPath = () => {
138
+ return `${API_V2_PREFIX}/offers/fulfillment/actions`
139
+ }
140
+
121
141
  export const getTraitOffersPath = (collectionSlug: string) => {
122
142
  return `${API_V2_PREFIX}/offers/collection/${collectionSlug}/traits`
123
143
  }
@@ -3,6 +3,7 @@ import {
3
3
  getBestListingAPIPath,
4
4
  getBestListingsAPIPath,
5
5
  getCreateListingActionsPath,
6
+ getCreateListingFulfillmentActionsPath,
6
7
  getCrossChainFulfillmentDataPath,
7
8
  getSweepListingsPath,
8
9
  } from "./apiPaths"
@@ -10,6 +11,8 @@ import type { Fetcher } from "./fetcher"
10
11
  import {
11
12
  type CreateListingActionsRequest,
12
13
  type CreateListingActionsResponse,
14
+ type CreateListingFulfillmentActionsRequest,
15
+ type CreateListingFulfillmentActionsResponse,
13
16
  type CrossChainFulfillmentRequest,
14
17
  type CrossChainFulfillmentResponse,
15
18
  encodeTraitsParam,
@@ -140,4 +143,16 @@ export class ListingsAPI {
140
143
  request,
141
144
  )
142
145
  }
146
+
147
+ /**
148
+ * Get the ordered actions required to fulfill a listing.
149
+ */
150
+ async createListingFulfillmentActions(
151
+ request: CreateListingFulfillmentActionsRequest,
152
+ ): Promise<CreateListingFulfillmentActionsResponse> {
153
+ return this.fetcher.post<CreateListingFulfillmentActionsResponse>(
154
+ getCreateListingFulfillmentActionsPath(),
155
+ request,
156
+ )
157
+ }
143
158
  }
package/src/api/offers.ts CHANGED
@@ -9,6 +9,8 @@ import {
9
9
  getBestOfferAPIPath,
10
10
  getBuildOfferPath,
11
11
  getCollectionOffersPath,
12
+ getCreateOfferActionsPath,
13
+ getCreateOfferFulfillmentActionsPath,
12
14
  getOffersByNFTPath,
13
15
  getPostCollectionOfferPath,
14
16
  getTraitOffersPath,
@@ -17,6 +19,10 @@ import type { Fetcher } from "./fetcher"
17
19
  import type {
18
20
  BuildOfferResponse,
19
21
  CollectionOffer,
22
+ CreateOfferActionsRequest,
23
+ CreateOfferActionsResponse,
24
+ CreateOfferFulfillmentActionsRequest,
25
+ CreateOfferFulfillmentActionsResponse,
20
26
  GetBestOfferResponse,
21
27
  GetOffersResponse,
22
28
  } from "./types"
@@ -238,4 +244,28 @@ export class OffersAPI {
238
244
  { limit, next },
239
245
  )
240
246
  }
247
+
248
+ /**
249
+ * Get the ordered actions required to create an offer.
250
+ */
251
+ async createOfferActions(
252
+ request: CreateOfferActionsRequest,
253
+ ): Promise<CreateOfferActionsResponse> {
254
+ return this.fetcher.post<CreateOfferActionsResponse>(
255
+ getCreateOfferActionsPath(),
256
+ request,
257
+ )
258
+ }
259
+
260
+ /**
261
+ * Get the ordered actions required to fulfill an offer.
262
+ */
263
+ async createOfferFulfillmentActions(
264
+ request: CreateOfferFulfillmentActionsRequest,
265
+ ): Promise<CreateOfferFulfillmentActionsResponse> {
266
+ return this.fetcher.post<CreateOfferFulfillmentActionsResponse>(
267
+ getCreateOfferFulfillmentActionsPath(),
268
+ request,
269
+ )
270
+ }
241
271
  }
package/src/api/orders.ts CHANGED
@@ -8,6 +8,7 @@ import { type Chain, OrderSide } from "../types"
8
8
  import type { Camelize } from "../utils/case"
9
9
  import {
10
10
  getCancelOrderPath,
11
+ getCreateCancelOrderActionsPath,
11
12
  getOrderByHashPath,
12
13
  getPostListingPath,
13
14
  getPostOfferPath,
@@ -15,6 +16,8 @@ import {
15
16
  import type { Fetcher } from "./fetcher"
16
17
  import type {
17
18
  CancelOrderResponse,
19
+ CreateCancelOrderActionsRequest,
20
+ CreateCancelOrderActionsResponse,
18
21
  GetOrderByHashResponse,
19
22
  Listing,
20
23
  Offer,
@@ -167,4 +170,19 @@ export class OrdersAPI {
167
170
  { snakeizeBody: false },
168
171
  )
169
172
  }
173
+
174
+ /**
175
+ * Get the ordered actions required to cancel an order onchain.
176
+ */
177
+ async createCancelOrderActions(
178
+ protocolAddress: string,
179
+ orderIdentifier: string,
180
+ request: CreateCancelOrderActionsRequest,
181
+ chain: Chain = this.chain,
182
+ ): Promise<CreateCancelOrderActionsResponse> {
183
+ return this.fetcher.post<CreateCancelOrderActionsResponse>(
184
+ getCreateCancelOrderActionsPath(chain, protocolAddress, orderIdentifier),
185
+ request,
186
+ )
187
+ }
170
188
  }
package/src/api/types.ts CHANGED
@@ -1168,12 +1168,16 @@ import type {
1168
1168
  BatchCollectionsRequest as ApiBatchCollectionsRequest,
1169
1169
  BatchNftsRequest as ApiBatchNftsRequest,
1170
1170
  BatchTokensRequest as ApiBatchTokensRequest,
1171
+ CancelOrderActionsRequest as ApiCancelOrderActionsRequest,
1172
+ CancelOrderActionsResponse as ApiCancelOrderActionsResponse,
1171
1173
  ClosedPositionsResponse as ApiClosedPositionsResponse,
1172
1174
  CollectionBatchResponse as ApiCollectionBatchResponse,
1173
1175
  CollectionHoldersPaginatedResponse as ApiCollectionHoldersPaginatedResponse,
1174
1176
  CollectionOfferAggregatesPaginatedResponse as ApiCollectionOfferAggregatesPaginatedResponse,
1175
1177
  CreateListingActionsRequest as ApiCreateListingActionsRequest,
1176
1178
  CreateListingActionsResponse as ApiCreateListingActionsResponse,
1179
+ CreateOfferActionsRequest as ApiCreateOfferActionsRequest,
1180
+ CreateOfferActionsResponse as ApiCreateOfferActionsResponse,
1177
1181
  CrossChainDropMintRequest as ApiCrossChainDropMintRequest,
1178
1182
  CrossChainDropMintResponse as ApiCrossChainDropMintResponse,
1179
1183
  CrossChainFulfillmentRequest as ApiCrossChainFulfillmentRequest,
@@ -1184,6 +1188,9 @@ import type {
1184
1188
  DropDeployResponse as ApiDropDeployResponse,
1185
1189
  FloorPriceHistoryResponse as ApiFloorPriceHistoryResponse,
1186
1190
  FulfillerObject as ApiFulfillerObject,
1191
+ FulfillmentActionsResponse as ApiFulfillmentActionsResponse,
1192
+ FullfillListingRequest as ApiFullfillListingRequest,
1193
+ FullfillmentDataRequest as ApiFullfillmentDataRequest,
1187
1194
  ListingObject as ApiListingObject,
1188
1195
  NftAnalyticsResponse as ApiNftAnalyticsResponse,
1189
1196
  NftBatchResponse as ApiNftBatchResponse,
@@ -1211,8 +1218,15 @@ import type {
1211
1218
  export type BatchCollectionsRequest = Camelize<ApiBatchCollectionsRequest>
1212
1219
  export type BatchNftsRequest = Camelize<ApiBatchNftsRequest>
1213
1220
  export type BatchTokensRequest = Camelize<ApiBatchTokensRequest>
1221
+ export type CreateCancelOrderActionsRequest =
1222
+ Camelize<ApiCancelOrderActionsRequest>
1214
1223
  export type CreateListingActionsRequest =
1215
1224
  Camelize<ApiCreateListingActionsRequest>
1225
+ export type CreateListingFulfillmentActionsRequest =
1226
+ Camelize<ApiFullfillListingRequest>
1227
+ export type CreateOfferActionsRequest = Camelize<ApiCreateOfferActionsRequest>
1228
+ export type CreateOfferFulfillmentActionsRequest =
1229
+ Camelize<ApiFullfillmentDataRequest>
1216
1230
  export type CrossChainDropMintRequest = Camelize<ApiCrossChainDropMintRequest>
1217
1231
  export type CrossChainFulfillmentRequest =
1218
1232
  Camelize<ApiCrossChainFulfillmentRequest>
@@ -1227,8 +1241,15 @@ export type CollectionHoldersPaginatedResponse =
1227
1241
  Camelize<ApiCollectionHoldersPaginatedResponse>
1228
1242
  export type CollectionOfferAggregatesPaginatedResponse =
1229
1243
  Camelize<ApiCollectionOfferAggregatesPaginatedResponse>
1244
+ export type CreateCancelOrderActionsResponse =
1245
+ Camelize<ApiCancelOrderActionsResponse>
1230
1246
  export type CreateListingActionsResponse =
1231
1247
  Camelize<ApiCreateListingActionsResponse>
1248
+ export type CreateListingFulfillmentActionsResponse =
1249
+ Camelize<ApiFulfillmentActionsResponse>
1250
+ export type CreateOfferActionsResponse = Camelize<ApiCreateOfferActionsResponse>
1251
+ export type CreateOfferFulfillmentActionsResponse =
1252
+ Camelize<ApiFulfillmentActionsResponse>
1232
1253
  export type CrossChainDropMintResponse = Camelize<ApiCrossChainDropMintResponse>
1233
1254
  export type CrossChainFulfillmentResponse =
1234
1255
  Camelize<ApiCrossChainFulfillmentResponse>
@@ -224,6 +224,12 @@ export class WalletAuthAPI {
224
224
  )
225
225
  }
226
226
 
227
+ /**
228
+ * `UploadContext.fields` is an opaque signed multipart field map that the
229
+ * caller must submit unchanged, so the response is not camelized. Otherwise a
230
+ * legitimate field name such as S3's `success_action_status` comes back as
231
+ * `successActionStatus` and the form no longer matches the signed policy.
232
+ */
227
233
  createDropItemMediaUpload(
228
234
  slug: string,
229
235
  body: WalletAuthRequest<"upload_drop_item_media">,
@@ -232,6 +238,8 @@ export class WalletAuthAPI {
232
238
  "POST",
233
239
  `/api/v2/drops/${segment(slug)}/items/media`,
234
240
  body,
241
+ undefined,
242
+ { camelizeResponse: false },
235
243
  )
236
244
  }
237
245
 
@@ -246,10 +254,19 @@ export class WalletAuthAPI {
246
254
  )
247
255
  }
248
256
 
257
+ /**
258
+ * `UploadContext.fields` is an opaque signed multipart field map that the
259
+ * caller must submit unchanged, so the response is not camelized. Otherwise a
260
+ * legitimate field name such as S3's `success_action_status` comes back as
261
+ * `successActionStatus` and the form no longer matches the signed policy.
262
+ */
249
263
  createDropAllowlistUpload(slug: string) {
250
264
  return this.fetcher.request<OperationResponse<"upload_drop_allowlist">>(
251
265
  "POST",
252
266
  `/api/v2/drops/${segment(slug)}/allowlist`,
267
+ undefined,
268
+ undefined,
269
+ { camelizeResponse: false },
253
270
  )
254
271
  }
255
272
 
@@ -292,6 +309,12 @@ export class WalletAuthAPI {
292
309
  )
293
310
  }
294
311
 
312
+ /**
313
+ * `UploadContext.fields` is an opaque signed multipart field map that the
314
+ * caller must submit unchanged, so the response is not camelized. Otherwise a
315
+ * legitimate field name such as S3's `success_action_status` comes back as
316
+ * `successActionStatus` and the form no longer matches the signed policy.
317
+ */
295
318
  createCollectionImageUpload(
296
319
  slug: string,
297
320
  imageType: string,
@@ -301,6 +324,9 @@ export class WalletAuthAPI {
301
324
  return this.fetcher.request<OperationResponse<"upload_collection_image">>(
302
325
  "POST",
303
326
  `/api/v2/collections/${segment(slug)}/images/${segment(imageType)}?${query}`,
327
+ undefined,
328
+ undefined,
329
+ { camelizeResponse: false },
304
330
  )
305
331
  }
306
332
 
@@ -332,7 +358,8 @@ export class WalletAuthAPI {
332
358
  /**
333
359
  * `UploadProfileImageRequest` is camelCase on the wire (`imageType`,
334
360
  * `contentType`) and both are required, so snake-casing the body made this
335
- * call fail validation every time. Sent verbatim.
361
+ * call fail validation every time. Sent verbatim. The response is not
362
+ * camelized either, for the `UploadContext.fields` reason above.
336
363
  */
337
364
  createProfileImageUpload(body: WalletAuthRequest<"upload_profile_image">) {
338
365
  return this.fetcher.request<OperationResponse<"upload_profile_image">>(
@@ -340,7 +367,7 @@ export class WalletAuthAPI {
340
367
  "/api/v2/profile/images",
341
368
  body,
342
369
  undefined,
343
- { snakeizeBody: false },
370
+ { snakeizeBody: false, camelizeResponse: false },
344
371
  )
345
372
  }
346
373
 
@@ -34,6 +34,7 @@ type ConsiderationItemLike = {
34
34
  itemType?: unknown
35
35
  token?: unknown
36
36
  startAmount?: unknown
37
+ endAmount?: unknown
37
38
  }
38
39
 
39
40
  /**
@@ -101,6 +102,13 @@ function sumErc20Consideration(consideration: unknown): Erc20Payment | null {
101
102
  if (amount === null) {
102
103
  return null
103
104
  }
105
+ // A time-interpolated item (declining or ascending price) is charged at a
106
+ // value between startAmount and endAmount, so startAmount is only an upper
107
+ // bound and there is no confident figure to check a balance against.
108
+ const endAmount = toBigInt(rawItem.endAmount)
109
+ if (endAmount === null || endAmount !== amount) {
110
+ return null
111
+ }
104
112
  total += amount
105
113
  }
106
114
 
@@ -157,6 +165,54 @@ function basicOrderErc20Payment(
157
165
  return { token, amount: total }
158
166
  }
159
167
 
168
+ /**
169
+ * Top-level `input_data` keys that can carry the flattened basic-order struct,
170
+ * in precedence order.
171
+ *
172
+ * `parameters` is the name the API sends, per the `FulfillBasicOrder` schema in
173
+ * the OpenAPI spec. `basicOrderParameters` is a tolerated alias and appears in
174
+ * no real response; reading only that name is what made this preflight inert in
175
+ * production (opensea-sdk#1997).
176
+ */
177
+ const BASIC_ORDER_STRUCT_KEYS = ["parameters", "basicOrderParameters"] as const
178
+
179
+ /**
180
+ * Find the flattened basic-order struct in a fulfillment response.
181
+ *
182
+ * `basicOrderType` is the discriminator, because only the flattened
183
+ * basic-order struct carries it. An `OrderComponents`-shaped `parameters` from
184
+ * a standard `fulfillOrder` response has `offer` and `consideration` arrays
185
+ * instead, so it cannot be mistaken for a basic order.
186
+ */
187
+ function findBasicOrderStruct(
188
+ inputData: Record<string, unknown>,
189
+ ): Record<string, unknown> | null {
190
+ for (const key of BASIC_ORDER_STRUCT_KEYS) {
191
+ const candidate = inputData[key]
192
+ if (isRecord(candidate) && candidate.basicOrderType !== undefined) {
193
+ return candidate
194
+ }
195
+ }
196
+ return null
197
+ }
198
+
199
+ /**
200
+ * Whether an advanced order's numerator/denominator fraction is a full fill.
201
+ * A full fill is the only case where summing the consideration items'
202
+ * `startAmount`s is the exact payment: for a partial fill Seaport scales each
203
+ * item by the fraction and requires exact divisibility, which is not modelled
204
+ * here. Returns false for a missing, unparsable, non-positive, or unequal
205
+ * fraction, so the caller fails open and skips the preflight.
206
+ */
207
+ function isFullFillFraction(order: Record<string, unknown>): boolean {
208
+ const numerator = toBigInt(order.numerator)
209
+ const denominator = toBigInt(order.denominator)
210
+ if (numerator === null || denominator === null) {
211
+ return false
212
+ }
213
+ return numerator > 0n && numerator === denominator
214
+ }
215
+
160
216
  /**
161
217
  * Read the ERC20 payment a fulfiller owes from the `inputData` of an OpenSea
162
218
  * fulfillment response.
@@ -171,8 +227,9 @@ export function getErc20Payment(inputData: unknown): Erc20Payment | null {
171
227
  return null
172
228
  }
173
229
 
174
- if ("basicOrderParameters" in inputData) {
175
- return basicOrderErc20Payment(inputData.basicOrderParameters)
230
+ const basicOrder = findBasicOrderStruct(inputData)
231
+ if (basicOrder) {
232
+ return basicOrderErc20Payment(basicOrder)
176
233
  }
177
234
 
178
235
  const order = isRecord(inputData.advancedOrder)
@@ -184,6 +241,14 @@ export function getErc20Payment(inputData: unknown): Erc20Payment | null {
184
241
  return null
185
242
  }
186
243
 
244
+ // An AdvancedOrder may carry a numerator/denominator fraction for a partial
245
+ // fill. Seaport applies that fraction to each consideration item, so the
246
+ // summed full-order consideration is only the real payment for a full fill.
247
+ // For anything else, fail open rather than falsely blocking a purchase.
248
+ if (isRecord(inputData.advancedOrder) && !isFullFillFraction(order)) {
249
+ return null
250
+ }
251
+
187
252
  return sumErc20Consideration(order.parameters.consideration)
188
253
  }
189
254
 
@@ -200,8 +265,13 @@ export function getFulfillerConduitKey(inputData: unknown): string | null {
200
265
  if (typeof direct === "string") {
201
266
  return direct
202
267
  }
203
- if (isRecord(inputData.basicOrderParameters)) {
204
- const fromBasicOrder = inputData.basicOrderParameters.fulfillerConduitKey
268
+ // A basic order carries its conduit key inside the struct, not at the top
269
+ // level. Reading the amount without this would resolve the spender to Seaport
270
+ // for an order the buyer approved the conduit for, and the preflight would
271
+ // then report a working purchase as unapproved.
272
+ const basicOrder = findBasicOrderStruct(inputData)
273
+ if (basicOrder) {
274
+ const fromBasicOrder = basicOrder.fulfillerConduitKey
205
275
  if (typeof fromBasicOrder === "string") {
206
276
  return fromBasicOrder
207
277
  }
@@ -8,6 +8,7 @@ import {
8
8
  type TransactionRequest,
9
9
  type TransactionResponse,
10
10
  } from "ethers"
11
+ import { inferPrimaryType } from "../utils/eip712"
11
12
  import type { ViemAdapterParams } from "./viem-adapter"
12
13
 
13
14
  /**
@@ -145,9 +146,7 @@ class ViemEthersSigner extends AbstractSigner {
145
146
  }
146
147
 
147
148
  async signTypedData(domain: any, types: any, value: any): Promise<string> {
148
- const primaryType =
149
- Object.keys(types).find(key => key !== "EIP712Domain") ||
150
- Object.keys(types)[0]
149
+ const primaryType = inferPrimaryType(types)
151
150
 
152
151
  return this._walletClient.signTypedData({
153
152
  domain: {
@@ -10,6 +10,7 @@ import {
10
10
  encodeFunctionData as viemEncodeFunctionData,
11
11
  type WalletClient,
12
12
  } from "viem"
13
+ import { inferPrimaryType } from "../utils/eip712"
13
14
  import type {
14
15
  ContractCaller,
15
16
  OpenSeaProvider,
@@ -89,15 +90,13 @@ function createViemSigner(
89
90
  }
90
91
  return walletClient.signTypedData({
91
92
  domain: {
92
- chainId: Number(domain.chainId),
93
+ chainId: domain.chainId != null ? Number(domain.chainId) : undefined,
93
94
  name: domain.name,
94
95
  version: domain.version,
95
96
  verifyingContract: domain.verifyingContract as `0x${string}`,
96
97
  },
97
98
  types,
98
- primaryType:
99
- Object.keys(types).find(key => key !== "EIP712Domain") ||
100
- Object.keys(types)[0],
99
+ primaryType: inferPrimaryType(types),
101
100
  message: value,
102
101
  account: walletClient.account,
103
102
  })
package/src/sdk/assets.ts CHANGED
@@ -416,6 +416,15 @@ export class AssetsManager {
416
416
  callData,
417
417
  })
418
418
  } else if (asset.tokenStandard === TokenStandard.ERC20) {
419
+ // One approval per contract, same as the ERC721/ERC1155 branch above.
420
+ // The amount is always max uint256, so a second entry for the same
421
+ // token would send an identical, wasted approval.
422
+ const contractAddress = asset.tokenAddress.toLowerCase()
423
+ if (processedContracts.has(contractAddress)) {
424
+ continue
425
+ }
426
+ processedContracts.add(contractAddress)
427
+
419
428
  // approve(spender, amount) - use max uint256 for unlimited
420
429
  const callData = cc.encodeFunctionData({
421
430
  abi: APPROVE_ABI,
@@ -3,6 +3,7 @@ import type { Listing, Offer } from "../api/types"
3
3
  import type { OrderV2 } from "../orders/types"
4
4
  import { DEFAULT_SEAPORT_CONTRACT_ADDRESS } from "../orders/utils"
5
5
  import { type Chain, EventType } from "../types"
6
+ import { checksumAddress } from "../utils/address"
6
7
  import {
7
8
  getChainId,
8
9
  getSeaportInstance,
@@ -179,7 +180,11 @@ export class CancellationManager {
179
180
 
180
181
  const addProtocolAddress = (value: string) => {
181
182
  requireValidProtocol(value)
182
- protocolAddresses.add(value)
183
+ // Keyed by checksummed form. An address is the same protocol whatever
184
+ // case it arrives in, and orders from different sources arrive in
185
+ // different cases, so a raw-string Set counted one protocol as several
186
+ // and rejected a batch that was fine.
187
+ protocolAddresses.add(checksumAddress(value))
183
188
  }
184
189
 
185
190
  if (orders) {